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,81 @@ public boolean onOptionsItemSelected(MenuItem item)
99
109
return true ;
100
110
}
101
111
112
+ if (id == R .id .action_about )
113
+ {
114
+ displayAboutDialog ();
115
+ return true ;
116
+ }
117
+
102
118
return super .onOptionsItemSelected (item );
103
119
}
120
+
121
+ private void displayAboutDialog ()
122
+ {
123
+ final String [][] USED_LIBRARIES = new String [][]
124
+ {
125
+ new String [] {"Commons CSV" , "https://commons.apache.org/proper/commons-csv/" },
126
+ new String [] {"ZXing" , "https://github.com/zxing/zxing" },
127
+ new String [] {"ZXing Android Embedded" , "https://github.com/journeyapps/zxing-android-embedded" },
128
+ };
129
+
130
+ StringBuilder libs = new StringBuilder ().append ("<ul>" );
131
+ for (String [] library : USED_LIBRARIES )
132
+ {
133
+ libs .append ("<li><a href=\" " ).append (library [1 ]).append ("\" >" ).append (library [0 ]).append ("</a></li>" );
134
+ }
135
+ libs .append ("</ul>" );
136
+
137
+ String appName = getString (R .string .app_name );
138
+ int year = Calendar .getInstance ().get (Calendar .YEAR );
139
+
140
+ String version = "?" ;
141
+ try
142
+ {
143
+ PackageInfo pi = getPackageManager ().getPackageInfo (getPackageName (), 0 );
144
+ version = pi .versionName ;
145
+ }
146
+ catch (PackageManager .NameNotFoundException e )
147
+ {
148
+ Log .w (TAG , "Package name not found" , e );
149
+ }
150
+
151
+ WebView wv = new WebView (this );
152
+ String html =
153
+ "<meta http-equiv=\" content-type\" content=\" text/html; charset=utf-8\" />" +
154
+ "<img src=\" file:///android_res/mipmap/ic_launcher.png\" alt=\" " + appName + "\" />" +
155
+ "<h1>" +
156
+ String .format (getString (R .string .about_title_fmt ),
157
+ "<a href=\" " + getString (R .string .app_webpage_url )) + "\" >" +
158
+ appName +
159
+ "</a>" +
160
+ "</h1><p>" +
161
+ appName +
162
+ " " +
163
+ String .format (getString (R .string .debug_version_fmt ), version ) +
164
+ "</p><p>" +
165
+ String .format (getString (R .string .app_revision_fmt ),
166
+ "<a href=\" " + getString (R .string .app_revision_url ) + "\" >" +
167
+ getString (R .string .app_revision_url ) +
168
+ "</a>" ) +
169
+ "</p><hr/><p>" +
170
+ String .format (getString (R .string .app_copyright_fmt ), year ) +
171
+ "</p><hr/><p>" +
172
+ getString (R .string .app_license ) +
173
+ "</p><hr/><p>" +
174
+ String .format (getString (R .string .app_libraries ), appName , libs .toString ());
175
+
176
+ wv .loadDataWithBaseURL ("file:///android_res/drawable/" , html , "text/html" , "utf-8" , null );
177
+ new AlertDialog .Builder (this )
178
+ .setView (wv )
179
+ .setCancelable (true )
180
+ .setPositiveButton (R .string .ok , new DialogInterface .OnClickListener ()
181
+ {
182
+ public void onClick (DialogInterface dialog , int which )
183
+ {
184
+ dialog .dismiss ();
185
+ }
186
+ })
187
+ .show ();
188
+ }
104
189
}
0 commit comments