[tor-commits] [orbot/master] updates to notification for Android O / SDK26

n8fr8 at torproject.org n8fr8 at torproject.org
Fri Jan 5 04:01:50 UTC 2018


commit fec853c939ecd1fea46dbc46dc4633976a1f4607
Author: n8fr8 <nathan at freitas.net>
Date:   Thu Jan 4 22:30:05 2018 -0500

    updates to notification for Android O / SDK26
---
 app/src/main/res/layout/layout_main.xml            |  7 +++--
 .../org/torproject/android/service/TorService.java | 34 +++++++++++++++++++++-
 .../res/layout/layout_notification_expanded.xml    |  2 +-
 orbotservice/src/main/res/values-cs/colors.xml     |  9 ++++++
 4 files changed, 47 insertions(+), 5 deletions(-)

diff --git a/app/src/main/res/layout/layout_main.xml b/app/src/main/res/layout/layout_main.xml
index f729a500..84d3156c 100644
--- a/app/src/main/res/layout/layout_main.xml
+++ b/app/src/main/res/layout/layout_main.xml
@@ -137,7 +137,7 @@
         >
         <android.support.v7.widget.SwitchCompat
             android:id="@+id/btnVPN"
-            android:layout_width="140dp"
+            android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="@string/apps_mode"
             android:layout_margin="9dp"
@@ -257,9 +257,10 @@
             android:layout_height="wrap_content"
             android:text="@string/use_bridges"
             android:layout_margin="3dp"
-            android:singleLine="true"
             app:switchPadding="3dp"
-            android:gravity="center_vertical"
+            android:layout_marginTop="10dp"
+            android:layout_centerHorizontal="true"
+            android:layout_centerVertical="true"
             />
     </LinearLayout>
     <LinearLayout
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 73983895..e4f7f13a 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/TorService.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/TorService.java
@@ -12,6 +12,7 @@ import android.annotation.SuppressLint;
 import android.annotation.TargetApi;
 import android.app.Application;
 import android.app.Notification;
+import android.app.NotificationChannel;
 import android.app.NotificationManager;
 import android.app.PendingIntent;
 import android.app.Service;
@@ -26,6 +27,7 @@ import android.content.SharedPreferences;
 import android.content.pm.PackageManager;
 import android.content.res.Configuration;
 import android.database.Cursor;
+import android.graphics.Color;
 import android.net.ConnectivityManager;
 import android.net.NetworkInfo;
 import android.net.Uri;
@@ -33,6 +35,7 @@ import android.os.Build;
 import android.os.IBinder;
 import android.os.RemoteException;
 import android.provider.BaseColumns;
+import android.support.annotation.RequiresApi;
 import android.support.v4.app.NotificationCompat;
 import android.support.v4.content.LocalBroadcastManager;
 import android.text.TextUtils;
@@ -241,7 +244,31 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
 
         mNotificationShowing = false;
     }
-	        
+
+    private final static String NOTIFICATION_CHANNEL_ID = "orbot_channel_1";
+
+    @RequiresApi(api = Build.VERSION_CODES.O)
+    private void createNotificationChannel ()
+    {
+        NotificationManager mNotificationManager =
+                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
+// The id of the channel.
+
+// The user-visible name of the channel.
+        CharSequence name = getString(R.string.app_name);
+// The user-visible description of the channel.
+        String description = getString(R.string.app_description);
+        int importance = NotificationManager.IMPORTANCE_LOW;
+        NotificationChannel mChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, name, importance);
+// Configure the notification channel.
+        mChannel.setDescription(description);
+        mChannel.enableLights(false);
+        mChannel.enableVibration(false);
+        mChannel.setShowBadge(false);
+        mChannel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);
+        mNotificationManager.createNotificationChannel(mChannel);
+    }
+
     @SuppressLint("NewApi")
     protected void showToolbarNotification (String notifyMsg, int notifyType, int icon)
      {        
@@ -287,6 +314,8 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
 
          mNotifyBuilder.setCategory(Notification.CATEGORY_SERVICE);
 
+         mNotifyBuilder.setChannelId(NOTIFICATION_CHANNEL_ID);
+
          mNotification = mNotifyBuilder.build();
         
         if (Build.VERSION.SDK_INT >= 16 && Prefs.expandedNotifications()) {
@@ -557,6 +586,9 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
             mActionBroadcastReceiver = new ActionBroadcastReceiver();
             registerReceiver(mActionBroadcastReceiver, filter);
 
+            if (Build.VERSION.SDK_INT >= 26)
+                createNotificationChannel();
+
             new Thread(new Runnable ()
             {
                 public void run ()
diff --git a/orbotservice/src/main/res/layout/layout_notification_expanded.xml b/orbotservice/src/main/res/layout/layout_notification_expanded.xml
index 1fa25227..0afa156b 100644
--- a/orbotservice/src/main/res/layout/layout_notification_expanded.xml
+++ b/orbotservice/src/main/res/layout/layout_notification_expanded.xml
@@ -19,7 +19,7 @@
     android:id="@+id/status_bar_latest_event_content"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
-    android:background="@android:color/holo_purple"
+    android:background="@color/dark_purple"
     >
     <LinearLayout
         android:layout_width="match_parent"
diff --git a/orbotservice/src/main/res/values-cs/colors.xml b/orbotservice/src/main/res/values-cs/colors.xml
new file mode 100644
index 00000000..af92426f
--- /dev/null
+++ b/orbotservice/src/main/res/values-cs/colors.xml
@@ -0,0 +1,9 @@
+
+    <resources>
+        <color name="panel_background">#ffffff</color>
+        <color name="panel_background_dark">#efefef</color>
+        <color name="panel_background_main">#efefef</color>
+        <color name="bright_green">#ccff2a</color>
+        <color name="dark_green">#669901</color>
+        <color name="dark_purple">#3f2b4f</color>
+    </resources>





More information about the tor-commits mailing list