AboutActivity.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. package com.usai.apex;
  2. import android.content.Intent;
  3. import android.content.pm.PackageManager.NameNotFoundException;
  4. import android.os.Bundle;
  5. import android.support.v7.app.ActionBar;
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.util.Log;
  8. import android.view.Gravity;
  9. import android.view.LayoutInflater;
  10. import android.view.MenuItem;
  11. import android.view.View;
  12. import android.widget.TextView;
  13. import java.io.BufferedReader;
  14. import java.io.IOException;
  15. import java.io.InputStream;
  16. import java.io.InputStreamReader;
  17. public class AboutActivity extends AppCompatActivity
  18. {
  19. @Override
  20. public boolean onOptionsItemSelected(MenuItem item)
  21. {
  22. Intent intent = new Intent();
  23. switch (item.getItemId())
  24. {
  25. case android.R.id.home:
  26. finish();
  27. break;
  28. default:
  29. break;
  30. }
  31. return super.onOptionsItemSelected(item);
  32. }
  33. private void setCustomActionBar() {
  34. ActionBar.LayoutParams lp =new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT, Gravity.CENTER);
  35. View mActionBarView = LayoutInflater.from(this).inflate(R.layout.actionbar_customtitle, null);
  36. TextView titleview = mActionBarView.findViewById(R.id.title);
  37. titleview.setText("About");
  38. setTitle("About");
  39. ActionBar actionBar = getSupportActionBar();
  40. actionBar.setCustomView(mActionBarView, lp);
  41. // actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
  42. // actionBar.setDisplayShowCustomEnabled(true);
  43. actionBar.setDisplayHomeAsUpEnabled(true);
  44. actionBar.setDisplayShowTitleEnabled(true);
  45. }
  46. @Override
  47. protected void onCreate(Bundle savedInstanceState)
  48. {
  49. Log.d("AboutActivity", "onCreate");
  50. super.onCreate(savedInstanceState);
  51. setContentView(R.layout.activity_about);
  52. setCustomActionBar();
  53. final TextView tv_ver = (TextView) findViewById(R.id.about_ver_value_tv);
  54. TextView tv_pdfpreview = (TextView) findViewById(R.id.tv_androidpdfviewer);
  55. tv_pdfpreview.setOnClickListener(new View.OnClickListener() {
  56. @Override
  57. public void onClick(View v) {
  58. InputStream is = getResources().openRawResource(R.raw.license_androidpdfviewer);//把文件转换为输入流
  59. StringBuffer response = new StringBuffer(); //创建StringBuffer实例
  60. BufferedReader br = new BufferedReader(new InputStreamReader(is)); //根据is创建缓冲字符输入流
  61. String s = null; //创建s变量
  62. try { //try语句捕获异常
  63. while ((s = br.readLine()) != null) { //把这一行的值赋值给变量s,并判断是否有值
  64. response.append(s); //把值添加进StringBuffer
  65. response.append("\n"); //再添加一个换行符
  66. }
  67. } catch (IOException e) {
  68. // TODO Auto-generated catch block //catch异常处理
  69. e.printStackTrace(); //得到错误的实例, 调用方法在命令行打印程序出错的位置及原因
  70. } finally { //finally try语句大多数情况下都会执行的代码块
  71. try {
  72. if (is != null) { //如果文件输入流不为空
  73. is.close(); //调用close函数关掉输入流
  74. }
  75. if (br != null) { //如果缓冲字符输入流不为空
  76. br.close(); //调用close函数关掉缓冲字符输入流
  77. }
  78. } catch (IOException e) {
  79. // TODO Auto-generated catch block
  80. e.printStackTrace();
  81. }
  82. }
  83. Intent intent = new Intent();
  84. intent.setClass(AboutActivity.this, LicenseActivity.class);
  85. intent.putExtra("function_name", "barteksc/AndroidPdfViewer");
  86. intent.putExtra("content", response.toString());
  87. startActivity(intent);
  88. }
  89. });
  90. // String str =
  91. // "<a href='https://ra.apexshipping.com/main.php?action=handset_search&action_type=download_doc&sessionid=hjqvgilu0o64d22qfqgat1afk2&url=QVRwVUswa3ZFNlBFTzhLbFpYcC9rVEhSZ1h0MGd6ekpwZ2ZqTkhXNnN2SytGM0FhRkhyNG5QbkdtV2tPMXZrK2p3' target=_blank>A1303540085F.pdf</a>";
  92. // WebView wv = (WebView) findViewById(R.id.webView1);
  93. // String content = "";
  94. // try
  95. // {
  96. // InputStream in = getResources().openRawResource(R.raw.about);
  97. // // 获取文件的字节数
  98. // int lenght = in.available();
  99. // // 创建byte数组
  100. // byte[] buffer = new byte[lenght];
  101. // // 将文件中的数据读到byte数组中
  102. // in.read(buffer);
  103. // content = EncodingUtils.getString(buffer, "UTF-8");
  104. // }
  105. // catch (Exception e)
  106. // {
  107. // e.printStackTrace();
  108. // }
  109. // wv.getSettings().setDefaultTextEncodingName("UTF-8");
  110. // wv.loadData(content, "text/html", null);
  111. //
  112. try
  113. {
  114. tv_ver.setText(ApexTrackingApplication.get_instance()
  115. .getPackageManager()
  116. .getPackageInfo("com.usai.apex", 0).versionName);
  117. }
  118. catch (NameNotFoundException e1)
  119. {
  120. // TODO Auto-generated catch block
  121. e1.printStackTrace();
  122. }
  123. }
  124. //
  125. // @Override
  126. // public boolean onCreateOptionsMenu(Menu menu) {
  127. // // Inflate the menu; this adds items to the action bar if it is present.
  128. // getMenuInflater().inflate(R.menu.about, menu);
  129. // return true;
  130. // }
  131. }