1
1
package protect .card_locker ;
2
2
3
+ import android .content .DialogInterface ;
3
4
import android .content .Intent ;
5
+ import android .content .pm .PackageInfo ;
6
+ import android .content .pm .PackageManager ;
4
7
import android .database .Cursor ;
5
8
import android .os .Bundle ;
9
+ import android .support .v7 .app .AlertDialog ;
6
10
import android .support .v7 .app .AppCompatActivity ;
7
11
import android .support .v7 .widget .Toolbar ;
12
+ import android .util .Log ;
8
13
import android .view .Menu ;
9
14
import android .view .MenuItem ;
10
15
import android .view .View ;
16
+ import android .webkit .WebView ;
11
17
import android .widget .AdapterView ;
12
18
import android .widget .ListView ;
13
19
import android .widget .TextView ;
14
20
21
+ import java .util .Calendar ;
22
+
15
23
public class MainActivity extends AppCompatActivity
16
24
{
25
+ private static final String TAG = "LoyaltyCardLocker" ;
26
+
17
27
@ Override
18
28
protected void onCreate (Bundle savedInstanceState )
19
29
{
@@ -99,6 +109,80 @@ public boolean onOptionsItemSelected(MenuItem item)
99
109
return true ;
100
110
}
101
111
112
+ if (id == R .id .action_about )
113
+ {
114
+ displayAboutDialog ();
115
+ }
116
+
102
117
return super .onOptionsItemSelected (item );
103
118
}
119
+
120
+ private void displayAboutDialog ()
121
+ {
122
+ final String [][] USED_LIBRARIES = new String [][]
123
+ {
124
+ new String [] {"Commons CSV" , "https://commons.apache.org/proper/commons-csv/" },
125
+ new String [] {"ZXing" , "https://github.com/zxing/zxing" },
126
+ new String [] {"ZXing Android Embedded" , "https://github.com/journeyapps/zxing-android-embedded" },
127
+ };
128
+
129
+ StringBuilder libs = new StringBuilder ().append ("<ul>" );
130
+ for (String [] library : USED_LIBRARIES )
131
+ {
132
+ libs .append ("<li><a href=\" " ).append (library [1 ]).append ("\" >" ).append (library [0 ]).append ("</a></li>" );
133
+ }
134
+ libs .append ("</ul>" );
135
+
136
+ String appName = getString (R .string .app_name );
137
+ int year = Calendar .getInstance ().get (Calendar .YEAR );
138
+
139
+ String version = "?" ;
140
+ try
141
+ {
142
+ PackageInfo pi = getPackageManager ().getPackageInfo (getPackageName (), 0 );
143
+ version = pi .versionName ;
144
+ }
145
+ catch (PackageManager .NameNotFoundException e )
146
+ {
147
+ Log .w (TAG , "Package name not found" , e );
148
+ }
149
+
150
+ WebView wv = new WebView (this );
151
+ String html =
152
+ "<meta http-equiv=\" content-type\" content=\" text/html; charset=utf-8\" />" +
153
+ "<img src=\" file:///android_res/mipmap/ic_launcher.png\" alt=\" " + appName + "\" />" +
154
+ "<h1>" +
155
+ String .format (getString (R .string .about_title_fmt ),
156
+ "<a href=\" " + getString (R .string .app_webpage_url )) + "\" >" +
157
+ appName +
158
+ "</a>" +
159
+ "</h1><p>" +
160
+ appName +
161
+ " " +
162
+ String .format (getString (R .string .debug_version_fmt ), version ) +
163
+ "</p><p>" +
164
+ String .format (getString (R .string .app_revision_fmt ),
165
+ "<a href=\" " + getString (R .string .app_revision_url ) + "\" >" +
166
+ getString (R .string .app_revision_url ) +
167
+ "</a>" ) +
168
+ "</p><hr/><p>" +
169
+ String .format (getString (R .string .app_copyright_fmt ), year ) +
170
+ "</p><hr/><p>" +
171
+ getString (R .string .app_license ) +
172
+ "</p><hr/><p>" +
173
+ String .format (getString (R .string .app_libraries ), appName , libs .toString ());
174
+
175
+ wv .loadDataWithBaseURL ("file:///android_res/drawable/" , html , "text/html" , "utf-8" , null );
176
+ new AlertDialog .Builder (this )
177
+ .setView (wv )
178
+ .setCancelable (true )
179
+ .setPositiveButton (R .string .ok , new DialogInterface .OnClickListener ()
180
+ {
181
+ public void onClick (DialogInterface dialog , int which )
182
+ {
183
+ dialog .dismiss ();
184
+ }
185
+ })
186
+ .show ();
187
+ }
104
188
}
0 commit comments