package au.com.newint.newinternationalist; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.net.Uri; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.TextView; import com.google.firebase.iid.FirebaseInstanceId; public class AboutActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_about); // Send Google Analytics if the user allows it Helpers.sendGoogleAnalytics(getResources().getString(R.string.title_activity_about)); // Set the version number PackageInfo pInfo = null; try { pInfo = getPackageManager().getPackageInfo(getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } String version = pInfo.versionName + String.format(" (%1$d)",pInfo.versionCode); TextView versionTextView = (TextView) this.findViewById(R.id.about_version); versionTextView.setText(version); // Load the about html WebView webview = (WebView) findViewById(R.id.about_web_view); webview.setBackgroundColor(0x00000000); webview.loadUrl("file:///android_asset/about.html"); // Handle web links in webView webview.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { // An external link tapped Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(browserIntent); return true; } }); // Display Parse Id for debugging versionTextView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { // get the GCM token/id String parseID = FirebaseInstanceId.getInstance().getToken(); AlertDialog.Builder builder = new AlertDialog.Builder(AboutActivity.this); builder.setMessage(parseID).setTitle(R.string.parse_id_dialog_title); builder.setPositiveButton(R.string.parse_id_dialog_ok_button, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // User clicked OK button } }); AlertDialog dialog = builder.create(); dialog.show(); return true; } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_about, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } else if (id == android.R.id.home) { finish(); return true; } return super.onOptionsItemSelected(item); } }