commit 546310a4965408bfb5fa445d566f59479935bfa3 Author: n8fr8 nathan@freitas.net Date: Wed Dec 13 15:07:52 2017 -0500
improve notifications, add refresh/newnym button --- .../android/settings/SettingsPreferences.java | 9 +- .../res/layout/layout_notification_expanded.xml | 106 --------------------- .../org/torproject/android/service/TorService.java | 87 +++++++++-------- .../res/drawable-hdpi/ic_refresh_white_24dp.png | Bin 0 -> 387 bytes .../res/drawable-mdpi/ic_refresh_white_24dp.png | Bin 0 -> 254 bytes .../res/drawable-xhdpi/ic_refresh_white_24dp.png | Bin 0 -> 509 bytes .../res/drawable-xxhdpi/ic_refresh_white_24dp.png | Bin 0 -> 734 bytes .../res/drawable-xxxhdpi/ic_refresh_white_24dp.png | Bin 0 -> 967 bytes .../res/layout/layout_notification_expanded.xml | 42 ++++---- 9 files changed, 71 insertions(+), 173 deletions(-)
diff --git a/app/src/main/java/org/torproject/android/settings/SettingsPreferences.java b/app/src/main/java/org/torproject/android/settings/SettingsPreferences.java index a51c1097..42e09da1 100644 --- a/app/src/main/java/org/torproject/android/settings/SettingsPreferences.java +++ b/app/src/main/java/org/torproject/android/settings/SettingsPreferences.java @@ -14,6 +14,7 @@ import android.preference.PreferenceActivity;
import org.torproject.android.OrbotApp; import org.torproject.android.R; +import org.torproject.android.service.util.Prefs; import org.torproject.android.service.util.TorServiceUtils;
import java.util.Locale; @@ -43,15 +44,9 @@ public class SettingsPreferences public boolean onPreferenceChange(Preference preference, Object newValue) { String language = (String) newValue; if (preference == prefLocale) { - SharedPreferences settings = TorServiceUtils - .getSharedPrefs(getApplicationContext()); - - String lang = settings.getString("pref_default_locale", - Locale.getDefault().getLanguage()); OrbotApp app = (OrbotApp) getApplication(); Languages.setLanguage(app, language, true); - lang = settings.getString("pref_default_locale", - Locale.getDefault().getLanguage()); + Prefs.setDefaultLocale(language); OrbotApp.forceChangeLanguage(SettingsPreferences.this); } return false; diff --git a/app/src/main/res/layout/layout_notification_expanded.xml b/app/src/main/res/layout/layout_notification_expanded.xml deleted file mode 100644 index aab1d6de..00000000 --- a/app/src/main/res/layout/layout_notification_expanded.xml +++ /dev/null @@ -1,106 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Copyright (C) 2012 The Android Open Source Project - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> - -<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:internal="http://schemas.android.com/apk/prv/res/android" - android:id="@+id/status_bar_latest_event_content" - android:layout_width="match_parent" - android:layout_height="wrap_content" - > - <ImageView android:id="@+id/icon" - android:layout_width="@dimen/notification_large_icon_width" - android:layout_height="@dimen/notification_large_icon_height" - android:scaleType="center" - /> - <LinearLayout - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_gravity="fill_vertical" - android:layout_marginStart="@dimen/notification_large_icon_width" - android:layout_marginLeft="@dimen/notification_large_icon_width" - - android:minHeight="@dimen/notification_large_icon_height" - android:orientation="vertical" - android:paddingEnd="8dp" - android:paddingRight="8dp" - android:paddingTop="2dp" - android:paddingBottom="2dp" - android:gravity="top" - > - <LinearLayout - android:id="@+id/line1" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:paddingTop="6dp" - android:layout_marginStart="8dp" - android:layout_marginLeft="8dp" - android:orientation="horizontal" - > - <TextView android:id="@+id/title" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:singleLine="true" - android:ellipsize="marquee" - android:fadingEdge="horizontal" - android:layout_weight="1" - android:textStyle="bold" - /> - - </LinearLayout> - <LinearLayout - android:id="@+id/line3" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:orientation="horizontal" - android:layout_marginStart="8dp" - android:layout_marginLeft="8dp" - > - <TextView android:id="@+id/text" - android:layout_width="0dp" - android:layout_height="wrap_content" - android:layout_weight="1" - android:layout_gravity="center" - android:singleLine="true" - android:ellipsize="marquee" - android:fadingEdge="horizontal" - /> - <TextView android:id="@+id/info" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_gravity="center" - android:layout_weight="0" - android:singleLine="true" - android:gravity="center" - android:paddingStart="8dp" - android:paddingLeft="8dp" - /> - <ImageButton - android:id="@+id/action_refresh" - android:layout_width="24dp" - android:layout_height="24dp" - android:src="@drawable/ic_autorenew_black_36dp" /> - </LinearLayout> - <TextView android:id="@+id/text2" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_marginTop="-2dp" - android:layout_marginBottom="-2dp" - android:layout_marginStart="8dp" - android:layout_marginLeft="8dp" - android:fadingEdge="horizontal" - /> - </LinearLayout> -</FrameLayout> diff --git a/orbotservice/src/main/java/org/torproject/android/service/TorService.java b/orbotservice/src/main/java/org/torproject/android/service/TorService.java index 4898b006..77fa1cdf 100644 --- a/orbotservice/src/main/java/org/torproject/android/service/TorService.java +++ b/orbotservice/src/main/java/org/torproject/android/service/TorService.java @@ -24,6 +24,7 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.pm.PackageManager; +import android.content.res.Configuration; import android.database.Cursor; import android.net.ConnectivityManager; import android.net.NetworkInfo; @@ -37,6 +38,7 @@ import android.support.v4.content.LocalBroadcastManager; import android.text.TextUtils; import android.util.Log; import android.widget.RemoteViews; +import android.widget.Toast;
import com.jrummyapps.android.shell.CommandResult; import com.jrummyapps.android.shell.Shell; @@ -262,19 +264,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
mNotifyBuilder.setContentIntent(pendIntent);
- /** - //Restart intent - Intent yesReceive = new Intent(); - yesReceive.setAction("Restart"); - PendingIntent pendingIntentYes = PendingIntent.getBroadcast(this, 12345, yesReceive, PendingIntent.FLAG_UPDATE_CURRENT); - mNotifyBuilder.addAction(R.drawable.ic_stat_tor_off, "Restart", pendingIntentYes); - //Maybe intent - **/ - - Intent maybeReceive = new Intent(); - maybeReceive.setAction("Identity"); - PendingIntent pendingIntentMaybe = PendingIntent.getBroadcast(this, 12345, maybeReceive, PendingIntent.FLAG_UPDATE_CURRENT); - mNotifyBuilder.addAction(R.drawable.ic_stat_tor_xfer, "New Identity", pendingIntentMaybe); }
} @@ -344,10 +333,9 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon expandedView.setImageViewResource(R.id.icon, icon);
Intent intentRefresh = new Intent(); - intentRefresh.setAction("Identity"); - PendingIntent pendingIntentMaybe = PendingIntent.getBroadcast(this, 12345, intentRefresh, PendingIntent.FLAG_UPDATE_CURRENT); - expandedView.setOnClickFillInIntent(R.id.action_refresh,intentRefresh); - + intentRefresh.setAction(CMD_NEWNYM); + PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intentRefresh, PendingIntent.FLAG_UPDATE_CURRENT); + expandedView.setOnClickPendingIntent(R.id.action_refresh,pendingIntent); mNotification.bigContentView = expandedView; }
@@ -436,6 +424,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
try { unregisterReceiver(mNetworkStateReceiver); + unregisterReceiver(mActionBroadcastReceiver); } catch (IllegalArgumentException iae) { @@ -444,16 +433,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
stopTor();
- /** - try - { - mShell.close(); - } - catch (IOException ioe) - { - Log.d(TAG, "Error closing shell",ioe); - }**/ - super.onDestroy(); }
@@ -493,6 +472,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
}
+ private void killAllDaemons() throws Exception { if (conn != null) { logNotice("Using control port to shutdown Tor"); @@ -508,14 +488,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon conn = null; }
- /** - if (mShellPolipo != null) - { - mShellPolipo.close(); - //logNotice("Polipo exited with value: " + exitValue); - - }**/ - }
private void requestTorRereadConfig() { @@ -578,6 +550,10 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon IntentFilter mNetworkStateFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); registerReceiver(mNetworkStateReceiver , mNetworkStateFilter);
+ IntentFilter filter = new IntentFilter(); + filter.addAction(CMD_NEWNYM); + mActionBroadcastReceiver = new ActionBroadcastReceiver(); + registerReceiver(mActionBroadcastReceiver, filter);
new Thread(new Runnable () { @@ -1285,9 +1261,15 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon { public void run () { - try { - - conn.signal("NEWNYM"); + try { + + + int iconId = R.drawable.ic_stat_tor; + + if (hasConnectivity() && Prefs.expandedNotifications()) + showToolbarNotification(getString(R.string.newnym), getNotifyId(), iconId); + + conn.signal("NEWNYM");
} catch (Exception ioe){ @@ -1810,10 +1792,18 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon }
@Override - public IBinder onBind(Intent arg0) { - // TODO Auto-generated method stub + public IBinder onBind(Intent intent) { + Log.e( "CustomNotificationService", "onBind" ); + handleIntent( intent ); return null; } + + private void handleIntent( Intent intent ) { + if( intent != null && intent.getAction() != null ) { + Log.e( "CustomNotificationService", intent.getAction().toString() ); + } + } +
private void setExitNode (String newExits) { @@ -1982,4 +1972,21 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
}
+ ActionBroadcastReceiver mActionBroadcastReceiver; + + private class ActionBroadcastReceiver extends BroadcastReceiver + { + public void onReceive(Context context, Intent intent) + { + switch (intent.getAction()) + { + case CMD_NEWNYM: + { + newIdentity(); + break; + } + } + } + } + } diff --git a/orbotservice/src/main/res/drawable-hdpi/ic_refresh_white_24dp.png b/orbotservice/src/main/res/drawable-hdpi/ic_refresh_white_24dp.png new file mode 100644 index 00000000..ffa7be93 Binary files /dev/null and b/orbotservice/src/main/res/drawable-hdpi/ic_refresh_white_24dp.png differ diff --git a/orbotservice/src/main/res/drawable-mdpi/ic_refresh_white_24dp.png b/orbotservice/src/main/res/drawable-mdpi/ic_refresh_white_24dp.png new file mode 100644 index 00000000..97e42b52 Binary files /dev/null and b/orbotservice/src/main/res/drawable-mdpi/ic_refresh_white_24dp.png differ diff --git a/orbotservice/src/main/res/drawable-xhdpi/ic_refresh_white_24dp.png b/orbotservice/src/main/res/drawable-xhdpi/ic_refresh_white_24dp.png new file mode 100644 index 00000000..1989184b Binary files /dev/null and b/orbotservice/src/main/res/drawable-xhdpi/ic_refresh_white_24dp.png differ diff --git a/orbotservice/src/main/res/drawable-xxhdpi/ic_refresh_white_24dp.png b/orbotservice/src/main/res/drawable-xxhdpi/ic_refresh_white_24dp.png new file mode 100644 index 00000000..1692d8a2 Binary files /dev/null and b/orbotservice/src/main/res/drawable-xxhdpi/ic_refresh_white_24dp.png differ diff --git a/orbotservice/src/main/res/drawable-xxxhdpi/ic_refresh_white_24dp.png b/orbotservice/src/main/res/drawable-xxxhdpi/ic_refresh_white_24dp.png new file mode 100644 index 00000000..f5beca25 Binary files /dev/null and b/orbotservice/src/main/res/drawable-xxxhdpi/ic_refresh_white_24dp.png differ diff --git a/orbotservice/src/main/res/layout/layout_notification_expanded.xml b/orbotservice/src/main/res/layout/layout_notification_expanded.xml index aab1d6de..1fa25227 100644 --- a/orbotservice/src/main/res/layout/layout_notification_expanded.xml +++ b/orbotservice/src/main/res/layout/layout_notification_expanded.xml @@ -18,26 +18,16 @@ xmlns:internal="http://schemas.android.com/apk/prv/res/android" android:id="@+id/status_bar_latest_event_content" android:layout_width="match_parent" - android:layout_height="wrap_content" + android:layout_height="wrap_content" + android:background="@android:color/holo_purple" > - <ImageView android:id="@+id/icon" - android:layout_width="@dimen/notification_large_icon_width" - android:layout_height="@dimen/notification_large_icon_height" - android:scaleType="center" - /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="fill_vertical" - android:layout_marginStart="@dimen/notification_large_icon_width" - android:layout_marginLeft="@dimen/notification_large_icon_width" - android:minHeight="@dimen/notification_large_icon_height" android:orientation="vertical" - android:paddingEnd="8dp" - android:paddingRight="8dp" - android:paddingTop="2dp" - android:paddingBottom="2dp" + android:padding="12dp" android:gravity="top" > <LinearLayout @@ -49,15 +39,25 @@ android:layout_marginLeft="8dp" android:orientation="horizontal" > + <ImageView + android:layout_width="20dp" + android:layout_height="20dp" + android:src="@drawable/ic_stat_tor" + /> <TextView android:id="@+id/title" - android:layout_width="match_parent" + android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:ellipsize="marquee" android:fadingEdge="horizontal" android:layout_weight="1" android:textStyle="bold" - /> + android:textColor="@android:color/white" + android:layout_marginStart="6dp" + android:layout_marginLeft="6dp" + android:layout_gravity="center_vertical" + android:text="@string/app_name" + />
</LinearLayout> <LinearLayout @@ -76,6 +76,7 @@ android:singleLine="true" android:ellipsize="marquee" android:fadingEdge="horizontal" + android:textColor="@android:color/white" /> <TextView android:id="@+id/info" android:layout_width="wrap_content" @@ -87,11 +88,11 @@ android:paddingStart="8dp" android:paddingLeft="8dp" /> - <ImageButton + <ImageView android:id="@+id/action_refresh" - android:layout_width="24dp" - android:layout_height="24dp" - android:src="@drawable/ic_autorenew_black_36dp" /> + android:layout_width="32dp" + android:layout_height="32dp" + android:src="@drawable/ic_refresh_white_24dp" /> </LinearLayout> <TextView android:id="@+id/text2" android:layout_width="match_parent" @@ -100,7 +101,8 @@ android:layout_marginBottom="-2dp" android:layout_marginStart="8dp" android:layout_marginLeft="8dp" - android:fadingEdge="horizontal" + android:fadingEdge="horizontal" + android:textColor="@android:color/white" /> </LinearLayout> </FrameLayout>