Index: src/org/adblockplus/android/AboutDialog.java |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/src/org/adblockplus/android/AboutDialog.java |
@@ -0,0 +1,86 @@ |
+package org.adblockplus.android; |
+ |
+import java.io.BufferedReader; |
+import java.io.IOException; |
+import java.io.InputStream; |
+import java.io.InputStreamReader; |
+ |
+import android.app.Dialog; |
+import android.content.Context; |
+import android.content.pm.PackageInfo; |
+import android.content.pm.PackageManager.NameNotFoundException; |
+import android.os.Bundle; |
+import android.text.Html; |
+import android.text.method.LinkMovementMethod; |
+import android.view.Window; |
+import android.widget.TextView; |
+ |
+public class AboutDialog extends Dialog |
+{ |
+ private static Context mContext = null; |
Felix Dahlke
2012/10/09 14:27:29
What's with the "m"? The rest of the code base doe
Andrey Novikov
2012/10/12 13:19:14
Done.
|
+ |
+ public AboutDialog(Context context) |
+ { |
+ super(context); |
+ mContext = context; |
+ } |
+ |
+ @Override |
+ public void onCreate(Bundle savedInstanceState) |
+ { |
+ requestWindowFeature(Window.FEATURE_NO_TITLE); |
+ setContentView(R.layout.about); |
+ |
+ // Get package version code and name |
+ String versionName = "--"; |
+ int versionCode = -1; |
+ try |
+ { |
+ PackageInfo pi = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0); |
+ versionName = pi.versionName; |
+ versionCode = pi.versionCode; |
+ } |
+ catch (NameNotFoundException ex) |
+ { |
+ // ignore - it can not happen because we query information about ourselves |
+ } |
+ |
+ // Construct html |
+ StringBuilder info = new StringBuilder(); |
+ info.append("<h3>"); |
+ info.append(mContext.getString(R.string.app_name)); |
+ info.append("</h3>"); |
+ info.append("<p>"); |
+ info.append(mContext.getString(R.string.version)); |
+ info.append(": "); |
+ info.append(versionName); |
+ info.append(" "); |
+ info.append(mContext.getString(R.string.build)); |
+ info.append(" "); |
+ info.append(versionCode); |
+ info.append("</p>"); |
+ appendRawTextFile(info, R.raw.info); |
+ appendRawTextFile(info, R.raw.legal); |
+ |
+ // Show text |
+ TextView tv = (TextView) findViewById(R.id.about_text); |
+ tv.setText(Html.fromHtml(info.toString())); |
+ tv.setMovementMethod(LinkMovementMethod.getInstance()); |
+ } |
+ |
+ public static void appendRawTextFile(StringBuilder text, int id) |
+ { |
+ InputStream inputStream = mContext.getResources().openRawResource(id); |
+ InputStreamReader in = new InputStreamReader(inputStream); |
+ BufferedReader buf = new BufferedReader(in); |
+ String line; |
+ try |
+ { |
+ while ((line = buf.readLine()) != null) |
+ text.append(line); |
+ } |
+ catch (IOException e) |
+ { |
Felix Dahlke
2012/10/09 14:27:29
I don't think we can be sure that reading the file
Andrey Novikov
2012/10/12 13:19:14
Ok, whould log.
|
+ } |
+ } |
+} |