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 context = null; |
| 21 |
| 22 public AboutDialog(Context context) |
| 23 { |
| 24 super(context); |
| 25 AboutDialog.context = 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 = context.getPackageManager().getPackageInfo(context.getPac
kageName(), 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(context.getString(R.string.app_name)); |
| 52 info.append("</h3>"); |
| 53 info.append("<p>"); |
| 54 info.append(context.getString(R.string.version)); |
| 55 info.append(": "); |
| 56 info.append(versionName); |
| 57 info.append(" "); |
| 58 info.append(context.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 = context.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 { |
| 84 e.printStackTrace(); |
| 85 } |
| 86 } |
| 87 } |
OLD | NEW |