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