| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 package org.adblockplus.android; | |
| 2 | |
| 3 import java.io.BufferedReader; | |
| 4 import java.io.IOException; | |
| 5 import java.io.InputStream; | |
| 6 import java.io.InputStreamReader; | |
| 7 | |
| 8 import android.app.Dialog; | |
| 9 import android.content.Context; | |
| 10 import android.content.pm.PackageInfo; | |
| 11 import android.content.pm.PackageManager.NameNotFoundException; | |
| 12 import android.os.Bundle; | |
| 13 import android.text.Html; | |
| 14 import android.text.method.LinkMovementMethod; | |
| 15 import android.view.Window; | |
| 16 import android.widget.TextView; | |
| 17 | |
| 18 public class AboutDialog extends Dialog | |
| 19 { | |
| 20 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.
| |
| 21 | |
| 22 public AboutDialog(Context context) | |
| 23 { | |
| 24 super(context); | |
| 25 mContext = context; | |
| 26 } | |
| 27 | |
| 28 @Override | |
| 29 public void onCreate(Bundle savedInstanceState) | |
| 30 { | |
| 31 requestWindowFeature(Window.FEATURE_NO_TITLE); | |
| 32 setContentView(R.layout.about); | |
| 33 | |
| 34 // Get package version code and name | |
| 35 String versionName = "--"; | |
| 36 int versionCode = -1; | |
| 37 try | |
| 38 { | |
| 39 PackageInfo pi = mContext.getPackageManager().getPackageInfo(mContext.getP ackageName(), 0); | |
| 40 versionName = pi.versionName; | |
| 41 versionCode = pi.versionCode; | |
| 42 } | |
| 43 catch (NameNotFoundException ex) | |
| 44 { | |
| 45 // ignore - it can not happen because we query information about ourselves | |
| 46 } | |
| 47 | |
| 48 // Construct html | |
| 49 StringBuilder info = new StringBuilder(); | |
| 50 info.append("<h3>"); | |
| 51 info.append(mContext.getString(R.string.app_name)); | |
| 52 info.append("</h3>"); | |
| 53 info.append("<p>"); | |
| 54 info.append(mContext.getString(R.string.version)); | |
| 55 info.append(": "); | |
| 56 info.append(versionName); | |
| 57 info.append(" "); | |
| 58 info.append(mContext.getString(R.string.build)); | |
| 59 info.append(" "); | |
| 60 info.append(versionCode); | |
| 61 info.append("</p>"); | |
| 62 appendRawTextFile(info, R.raw.info); | |
| 63 appendRawTextFile(info, R.raw.legal); | |
| 64 | |
| 65 // Show text | |
| 66 TextView tv = (TextView) findViewById(R.id.about_text); | |
| 67 tv.setText(Html.fromHtml(info.toString())); | |
| 68 tv.setMovementMethod(LinkMovementMethod.getInstance()); | |
| 69 } | |
| 70 | |
| 71 public static void appendRawTextFile(StringBuilder text, int id) | |
| 72 { | |
| 73 InputStream inputStream = mContext.getResources().openRawResource(id); | |
| 74 InputStreamReader in = new InputStreamReader(inputStream); | |
| 75 BufferedReader buf = new BufferedReader(in); | |
| 76 String line; | |
| 77 try | |
| 78 { | |
| 79 while ((line = buf.readLine()) != null) | |
| 80 text.append(line); | |
| 81 } | |
| 82 catch (IOException e) | |
| 83 { | |
|
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.
| |
| 84 } | |
| 85 } | |
| 86 } | |
| OLD | NEW |