package com.usai.apex;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.TextView;

public class WebActivity extends AppCompatActivity
{
	@Override
	public boolean onOptionsItemSelected(MenuItem item)
	{
		Intent intent = new Intent();
		switch (item.getItemId())
		{
			case android.R.id.home:
				finish();
				break;

			default:
				break;
		}
		return super.onOptionsItemSelected(item);
	}

	private void setCustomActionBar() {
		ActionBar.LayoutParams lp =new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT, Gravity.CENTER);
		View mActionBarView = LayoutInflater.from(this).inflate(R.layout.actionbar_customtitle, null);

		TextView titleview = mActionBarView.findViewById(R.id.title);
		titleview.setText(getTitle());

		ActionBar actionBar = getSupportActionBar();
		actionBar.setCustomView(mActionBarView, lp);
//		actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
//		actionBar.setDisplayShowCustomEnabled(true);
		actionBar.setDisplayHomeAsUpEnabled(true);


		actionBar.setDisplayShowTitleEnabled(true);
	}
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{

		// setTitle("Booking Result");

		super.onCreate(savedInstanceState);

		String title = getIntent().getStringExtra("title");

		setTitle(title);
		setContentView(R.layout.fragment_web);


		setCustomActionBar();
		String url = getIntent().getStringExtra("url");
		WebView wv = (WebView) findViewById(R.id.wv_content);

		wv.setBackgroundColor(Color.TRANSPARENT); // 设置背景色


		WebSettings settings=wv.getSettings();
		// 设置可以支持缩放
//		settings.setSupportZoom(true);
// 设置出现缩放工具
//		settings.setBuiltInZoomControls(true);
//扩大比例的缩放
//		settings.setUseWideViewPort(true);
		//自适应屏幕
		settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
		settings.setLoadWithOverviewMode(true);
		settings.setTextZoom(150);

		wv.loadUrl(url);

	}

}
