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.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import android.widget.TextView;

import org.apache.http.util.EncodingUtils;

import java.io.InputStream;

public class ApexHistoryActivity 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("Apex History");
		setTitle("Apex History");
		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)
	{
		Log.d("AboutActivity", "onCreate");

		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_history);

		setCustomActionBar();
		WebView wv = (WebView) findViewById(R.id.webView1);

		wv.setBackgroundColor(Color.TRANSPARENT); // 设置背景色
//		wv.getBackground().setAlpha(); // 设置填充透明度 范围：0-255

		String content = "";
		try
		{
			InputStream in = getResources().openRawResource(R.raw.about);
			// 获取文件的字节数
			int lenght = in.available();
			// 创建byte数组
			byte[] buffer = new byte[lenght];
			// 将文件中的数据读到byte数组中
			in.read(buffer);
			content = EncodingUtils.getString(buffer, "UTF-8");
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		wv.getSettings().setDefaultTextEncodingName("UTF-8");
		wv.loadData(content, "text/html", null);
		
	}
}
