Skip to content

Commit 4b2c2c7

Browse files
committed
About dialog and Toast verbosity
1 parent d872cec commit 4b2c2c7

File tree

12 files changed

+167
-26
lines changed

12 files changed

+167
-26
lines changed

app/src/main/java/com/prismaqf/callblocker/CallBlockerManager.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.app.ActivityManager;
44
import android.app.AlertDialog;
5+
import android.app.Dialog;
56
import android.content.BroadcastReceiver;
67
import android.content.ComponentName;
78
import android.content.Context;
@@ -10,6 +11,8 @@
1011
import android.content.IntentFilter;
1112
import android.content.ServiceConnection;
1213
import android.content.SharedPreferences;
14+
import android.content.pm.PackageInfo;
15+
import android.content.pm.PackageManager;
1316
import android.os.Bundle;
1417
import android.os.IBinder;
1518
import android.support.v7.app.AppCompatActivity;
@@ -35,6 +38,7 @@ public class CallBlockerManager extends AppCompatActivity {
3538
private Button buttonReceived;
3639
private Button buttonTriggered;
3740
private boolean isBound;
41+
private Dialog aboutDlg;
3842

3943
private final ServiceConnection myConnection = new ServiceConnection() {
4044

@@ -151,6 +155,8 @@ protected void onStart() {
151155
@Override
152156
protected void onStop() {
153157
super.onStop();
158+
if (aboutDlg!=null && aboutDlg.isShowing())
159+
aboutDlg.dismiss();
154160
if (isBound){
155161
unbindService(myConnection);
156162
isBound = false;
@@ -200,6 +206,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
200206
case R.id.action_help:
201207
showHelp();
202208
return true;
209+
case R.id.action_about:
210+
showAbout();
211+
return true;
203212
}
204213

205214
return super.onOptionsItemSelected(item);
@@ -319,4 +328,33 @@ public void onClick(DialogInterface dialog, int id) {
319328
alert.show();
320329
}
321330

331+
private void showAbout() {
332+
String version = "Unknown";
333+
try {
334+
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
335+
version = pInfo.versionName;
336+
} catch (PackageManager.NameNotFoundException e) {
337+
Log.w(TAG,"Could not get package info");
338+
}
339+
View messageView = getLayoutInflater().inflate(R.layout.about, null, false);
340+
341+
TextView versionView = (TextView) messageView.findViewById(R.id.about_version);
342+
versionView.setText(String.format(Locale.getDefault(),"Version: %s",version));
343+
344+
AlertDialog.Builder builder = new AlertDialog.Builder(this);
345+
builder.setIcon(R.mipmap.police_launcher);
346+
builder.setTitle(R.string.app_name);
347+
builder.setView(messageView);
348+
builder.create();
349+
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
350+
@Override
351+
public void onClick(DialogInterface dialog, int which) {
352+
dialog.dismiss();
353+
}
354+
});
355+
aboutDlg = builder.create();
356+
aboutDlg.show();
357+
}
358+
359+
322360
}

app/src/main/java/com/prismaqf/callblocker/CallHelper.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.prismaqf.callblocker.sql.DbHelper;
2222
import com.prismaqf.callblocker.sql.FilterProvider;
2323
import com.prismaqf.callblocker.sql.ServiceRunProvider;
24+
import com.prismaqf.callblocker.utils.PreferenceHelper;
2425

2526
import java.util.ArrayList;
2627
import java.util.List;
@@ -108,7 +109,8 @@ public void onCallStateChanged(int state, final String incomingNumber) {
108109
intent.putExtra(ctx.getString(R.string.ky_received),getNumReceived());
109110
intent.putExtra(ctx.getString(R.string.ky_triggered), getNumTriggered());
110111
ctx.sendBroadcast(intent);
111-
Toast.makeText(ctx, "Incoming: " + incomingNumber, Toast.LENGTH_LONG).show();
112+
if (PreferenceHelper.GetToastVerbosity(ctx) > 0)
113+
Toast.makeText(ctx, "Incoming: " + incomingNumber, Toast.LENGTH_LONG).show();
112114
if (!logging) {
113115
new LogIncoming().act(ctx,incomingNumber,info);
114116
}
@@ -127,7 +129,8 @@ public OutgoingReceiver() {}
127129
@Override
128130
public void onReceive(Context context, Intent intent) {
129131
String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
130-
Toast.makeText(ctx, "Outgoing: "+number, Toast.LENGTH_LONG).show();
132+
if (PreferenceHelper.GetToastVerbosity(ctx) > 1)
133+
Toast.makeText(ctx, "Outgoing: "+number, Toast.LENGTH_LONG).show();
131134
}
132135
}
133136

@@ -163,7 +166,8 @@ protected void onPostExecute (Void v) {
163166
String msg = myFilters.size() > 1 ?
164167
String.format(Locale.getDefault(),"%d filters loaded", myFilters.size()):
165168
String.format(Locale.getDefault(),"%d filter loaded", myFilters.size());
166-
Toast.makeText(myContext, msg, Toast.LENGTH_LONG).show();
169+
if (PreferenceHelper.GetToastVerbosity(ctx) > 1)
170+
Toast.makeText(myContext, msg, Toast.LENGTH_LONG).show();
167171
}
168172
}
169173

@@ -198,7 +202,8 @@ protected void onPostExecute (Integer purged) {
198202
String msg = purged > 0 ?
199203
String.format(Locale.getDefault(),"%d service run records purged", purged):
200204
"No service run records purged";
201-
Toast.makeText(myContext, msg, Toast.LENGTH_LONG).show();
205+
if (PreferenceHelper.GetToastVerbosity(ctx) > 1)
206+
Toast.makeText(myContext, msg, Toast.LENGTH_LONG).show();
202207
}
203208
}
204209

@@ -216,7 +221,8 @@ private CallHelper(Context ctx) {
216221
public void start() {
217222
if (isRunning) {
218223
Log.e(TAG,"The service is already running");
219-
Toast.makeText(ctx,"The service is already running",Toast.LENGTH_LONG).show();
224+
if (PreferenceHelper.GetToastVerbosity(ctx) > 0)
225+
Toast.makeText(ctx,"The service is already running",Toast.LENGTH_LONG).show();
220226
return;
221227
}
222228
purgeLogs(ctx);

app/src/main/java/com/prismaqf/callblocker/ShowLoggedCalls.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@
44
import android.content.CursorLoader;
55
import android.content.Intent;
66
import android.content.Loader;
7-
import android.content.SharedPreferences;
87
import android.database.Cursor;
98
import android.os.Bundle;
10-
import android.preference.PreferenceManager;
119
import android.view.View;
1210
import android.widget.ListView;
1311
import android.widget.SimpleCursorAdapter;
1412

1513
import com.prismaqf.callblocker.sql.DbContract;
1614
import com.prismaqf.callblocker.sql.LoggedCallProvider;
15+
import com.prismaqf.callblocker.utils.PreferenceHelper;
1716

1817
/**
1918
* Activity to show a list of recent logged calls with
@@ -40,9 +39,7 @@ public Loader<Cursor> onCreateLoader(int loaderID, Bundle args) {
4039
{
4140
@Override
4241
public Cursor loadInBackground() {
43-
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
44-
String key = getString(R.string.pk_sql_limit);
45-
int limit = Integer.parseInt(prefs.getString(key,"10"));
42+
int limit = PreferenceHelper.GetSqlQueryLimit(getContext());
4643
return LoggedCallProvider.LatestCalls(myDbConnection, limit);
4744
}
4845
};

app/src/main/java/com/prismaqf/callblocker/ShowServiceRuns.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
import android.content.CursorLoader;
44
import android.content.Loader;
5-
import android.content.SharedPreferences;
65
import android.database.Cursor;
76
import android.os.Bundle;
8-
import android.preference.PreferenceManager;
97
import android.widget.SimpleCursorAdapter;
108

119
import com.prismaqf.callblocker.sql.DbContract;
1210
import com.prismaqf.callblocker.sql.ServiceRunProvider;
11+
import com.prismaqf.callblocker.utils.PreferenceHelper;
1312

1413
/**
1514
* Activity to show a list of recent service runs with
@@ -37,9 +36,7 @@ public Loader<Cursor> onCreateLoader(int loaderID, Bundle args) {
3736
{
3837
@Override
3938
public Cursor loadInBackground() {
40-
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
41-
String key = getString(R.string.pk_sql_limit);
42-
int limit = Integer.parseInt(prefs.getString(key, "10"));
39+
int limit = PreferenceHelper.GetSqlQueryLimit(getContext());
4340
return ServiceRunProvider.LatestRuns(myDbConnection, limit);
4441
}
4542
};

app/src/main/java/com/prismaqf/callblocker/ShowTriggerEvents.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
import android.content.CursorLoader;
44
import android.content.Loader;
5-
import android.content.SharedPreferences;
65
import android.database.Cursor;
76
import android.os.Bundle;
8-
import android.preference.PreferenceManager;
97

108
import com.prismaqf.callblocker.sql.LoggedCallProvider;
9+
import com.prismaqf.callblocker.utils.PreferenceHelper;
1110

1211
/**
1312
* Activity to show a list of recent triggered events
@@ -39,9 +38,7 @@ public Loader<Cursor> onCreateLoader(int loaderID, Bundle args) {
3938
{
4039
@Override
4140
public Cursor loadInBackground() {
42-
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
43-
String key = getString(R.string.pk_sql_limit);
44-
int limit = Integer.parseInt(prefs.getString(key,"10"));
41+
int limit = PreferenceHelper.GetSqlQueryLimit(getContext());
4542
return LoggedCallProvider.LatestTriggered(myDbConnection, limit, true);
4643
}
4744
};

app/src/main/java/com/prismaqf/callblocker/sql/ServiceRunProvider.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
import android.content.ContentValues;
44
import android.content.Context;
5-
import android.content.SharedPreferences;
65
import android.database.Cursor;
76
import android.database.sqlite.SQLiteDatabase;
8-
import android.preference.PreferenceManager;
97
import android.util.Log;
108

11-
import com.prismaqf.callblocker.R;
9+
import com.prismaqf.callblocker.utils.PreferenceHelper;
1210

1311
import java.text.DateFormat;
1412
import java.text.ParseException;
@@ -245,9 +243,7 @@ private static synchronized void DeleteServiceRun(SQLiteDatabase db, long runid)
245243
}
246244

247245
public static synchronized int PurgeLog(SQLiteDatabase db, Context context, String longevity) {
248-
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
249-
String key = context.getString(R.string.pk_log_longevity);
250-
String theLongevity = longevity!=null ? longevity : prefs.getString(key, "no limit");
246+
String theLongevity = longevity!=null ? longevity : PreferenceHelper.GetLogLongevity(context);
251247
if (theLongevity.equals("no limit")) return 0;
252248
Calendar cal = Calendar.getInstance(Locale.getDefault());
253249
cal.setTime(new Date());
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.prismaqf.callblocker.utils;
2+
3+
import android.content.Context;
4+
import android.content.SharedPreferences;
5+
import android.preference.PreferenceManager;
6+
7+
import com.prismaqf.callblocker.R;
8+
9+
/**
10+
* Created by ConteDiMonteCristo.
11+
*/
12+
public class PreferenceHelper {
13+
14+
public static int GetToastVerbosity(Context context) {
15+
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
16+
String key = context.getString(R.string.pk_toast_verbosity);
17+
String verbosity = prefs.getString(key, "medium verbosity");
18+
switch (verbosity){
19+
case "no toast messages":
20+
return 0;
21+
case "medium verbosity":
22+
return 1;
23+
default:
24+
return 2;
25+
}
26+
}
27+
28+
public static int GetSqlQueryLimit(Context context) {
29+
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
30+
String key = context.getString(R.string.pk_sql_limit);
31+
return Integer.parseInt(prefs.getString(key,"10"));
32+
}
33+
34+
public static String GetLogLongevity(Context context) {
35+
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
36+
String key = context.getString(R.string.pk_log_longevity);
37+
return prefs.getString(key, "no limit");
38+
}
39+
}

app/src/main/res/layout/about.xml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:orientation="vertical"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
android:padding="20dp"
7+
android:background="@android:color/black">
8+
9+
<TextView
10+
android:layout_width="match_parent"
11+
android:layout_height="wrap_content"
12+
android:textAppearance="?android:attr/textAppearanceLarge"
13+
android:text="@string/about_title"
14+
android:textColor="@android:color/holo_red_dark"
15+
android:gravity="center_horizontal" />
16+
17+
<TextView
18+
android:id = "@+id/about_version"
19+
android:layout_width="match_parent"
20+
android:layout_height="wrap_content"
21+
android:layout_marginTop="10dp"
22+
android:textAppearance="?android:attr/textAppearanceMedium"
23+
android:text="@string/about_version"
24+
android:textColor="@android:color/holo_blue_dark"
25+
android:gravity="start" />
26+
27+
<TextView
28+
android:layout_width="match_parent"
29+
android:layout_height="wrap_content"
30+
android:layout_marginTop="10dp"
31+
android:textAppearance="?android:attr/textAppearanceMedium"
32+
android:text="@string/about_email"
33+
android:textColor="@android:color/holo_blue_dark"
34+
android:gravity="start" />
35+
36+
<TextView
37+
android:layout_width="match_parent"
38+
android:layout_height="wrap_content"
39+
android:layout_marginTop="10dp"
40+
android:textAppearance="?android:attr/textAppearanceMedium"
41+
android:text="@string/about_description"
42+
android:textColor="@android:color/holo_blue_dark"
43+
android:gravity="start" />
44+
45+
46+
</LinearLayout>

app/src/main/res/menu/menu_call_blocker_manager.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@
2828
android:icon="@drawable/ic_help_circle"
2929
android:orderInCategory="80"
3030
com.prismaqf.callblocker:showAsAction="ifRoom"/>
31+
<item
32+
android:id="@+id/action_about"
33+
android:orderInCategory="200"
34+
android:title="@string/ac_about"
35+
app:showAsAction="never" />
3136
</menu>

app/src/main/res/values/arrays.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,10 @@
3131
<item>no limit</item>
3232
</string-array>
3333

34+
<string-array name="toast_verbosity">
35+
<item>no toast messages</item>
36+
<item>medium verbosity</item>
37+
<item>all toast messages</item>
38+
</string-array>
39+
3440
</resources>

0 commit comments

Comments
 (0)