[tor-commits] [orbot/master] notification layout for the expanded notification, still in testing. Also includes integration of remote view for the big layout

n8fr8 at torproject.org n8fr8 at torproject.org
Mon Jul 14 17:40:20 UTC 2014


commit a787fdf8cdda2374af61ee6477409ab672b52415
Author: Amogh Pradeep <amoghbl1 at gmail.com>
Date:   Thu May 29 04:25:28 2014 +0530

    notification layout for the expanded notification, still in testing. Also includes integration of remote view for the big layout
---
 res/layout/layout_notification_expanded.xml        |   46 ++++++++++++++++++++
 src/org/torproject/android/Orbot.java              |    7 ++-
 src/org/torproject/android/service/TorService.java |   33 ++++++++++----
 3 files changed, 76 insertions(+), 10 deletions(-)

diff --git a/res/layout/layout_notification_expanded.xml b/res/layout/layout_notification_expanded.xml
new file mode 100644
index 0000000..8bf0a9d
--- /dev/null
+++ b/res/layout/layout_notification_expanded.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:orientation="vertical"
+                android:gravity="center_horizontal">
+	<RelativeLayout 
+	    android:layout_width="wrap_content"
+	    android:layout_height="wrap_content">
+	    
+	    <ImageView 
+	        android:id="@+id/img"
+	        android:layout_height="64dp"
+	        android:layout_width="64dp"
+	        android:src="@drawable/torerror"/>
+	    
+	    <TextView 
+	        android:id="@+id/orb"
+	        android:layout_height="wrap_content"
+	        android:layout_width="fill_parent"
+	        android:textSize="20sp"
+	        android:paddingLeft="10dp"
+	        android:paddingTop="5dp"
+	        android:layout_toRightOf="@+id/img"
+	        android:text="Orbot"/>
+	    
+    	<TextView
+        	android:id="@+id/tv"
+        	android:layout_toRightOf="@+id/img"
+        	android:layout_below="@+id/orb"
+        	android:paddingLeft="15dp"
+        	android:textSize="10sp"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"/>
+
+		<Button
+		    android:id="@+id/but"
+		    android:layout_width="wrap_content"
+		    android:layout_height="wrap_content"
+		    android:layout_alignParentRight="true"
+		    android:layout_below="@+id/tv"
+		    android:text="test" />
+		
+    </RelativeLayout>
+
+</LinearLayout>
\ No newline at end of file
diff --git a/src/org/torproject/android/Orbot.java b/src/org/torproject/android/Orbot.java
index 94300d1..90b8e74 100644
--- a/src/org/torproject/android/Orbot.java
+++ b/src/org/torproject/android/Orbot.java
@@ -532,7 +532,12 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
 	protected void onNewIntent(Intent intent) {
 		
 		super.onNewIntent(intent);
-		
+		try {
+			Log.d("lala", ""+mService.getStatus());
+		} catch (RemoteException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
 		updateStatus("");
 		handleIntents();
 	}
diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java
index 1a90258..5d52cde 100644
--- a/src/org/torproject/android/service/TorService.java
+++ b/src/org/torproject/android/service/TorService.java
@@ -39,6 +39,7 @@ import org.torproject.android.settings.AppManager;
 
 import android.annotation.SuppressLint;
 import android.app.Application;
+import android.app.Notification;
 import android.app.NotificationManager;
 import android.app.PendingIntent;
 import android.app.Service;
@@ -58,6 +59,9 @@ import android.os.RemoteException;
 import android.support.v4.app.NotificationCompat;
 import android.support.v4.app.NotificationCompat.Builder;
 import android.util.Log;
+import android.view.View;
+import android.widget.Button;
+import android.widget.RemoteViews;
 
 public class TorService extends Service implements TorServiceConstants, TorConstants, EventHandler
 {
@@ -106,6 +110,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
 	
 	private NotificationManager mNotificationManager = null;
 	private Builder mNotifyBuilder;
+	private Notification mNotification;
 
     private boolean mHasRoot = false;
     private boolean mEnableTransparentProxy = false;
@@ -219,9 +224,18 @@ public class TorService extends Service implements TorServiceConstants, TorConst
 		
 	}
    
- 	private void showToolbarNotification (String notifyMsg, int notifyId, int icon, boolean isOngoing)
- 	{
- 				    
+ 	@SuppressLint("NewApi")
+	private void showToolbarNotification (String notifyMsg, int notifyId, int icon, boolean isOngoing)
+ 	{	    
+ 		 
+ 		PendingIntent pendingIntent = PendingIntent.getActivity(TorService.this, 0, new Intent(TorService.this , Orbot.class), 0);
+ 		// Create remote view that needs to be set as bigContentView for the notification.
+ 		RemoteViews expandedView = new RemoteViews(this.getPackageName(), 
+ 		        R.layout.layout_notification_expanded);
+ 		expandedView.setTextViewText(R.id.tv, notifyMsg);
+ 		expandedView.setOnClickPendingIntent(R.id.but, pendingIntent);
+ 		expandedView.setImageViewResource(R.id.img, icon);
+ 		
 		if (mNotifyBuilder == null)
 		{
 			
@@ -246,6 +260,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
 		mNotifyBuilder.setContentText(notifyMsg);
 		mNotifyBuilder.setSmallIcon(icon);
 		
+		
 		if (notifyId == ERROR_NOTIFY_ID)
 		{
 			mNotifyBuilder.setTicker(notifyMsg);
@@ -254,19 +269,19 @@ public class TorService extends Service implements TorServiceConstants, TorConst
 			mNotifyBuilder.setSmallIcon(R.drawable.ic_stat_notifyerr);
 		}
 		
+		mNotification = mNotifyBuilder.build();
+		mNotification.bigContentView = expandedView;
+		
 		if (isOngoing)
 		{
-			startForeground(notifyId,
-	    			mNotifyBuilder.build());
+			startForeground(notifyId, mNotification);
 		
 		}
 		else
 		{
-			mNotificationManager.notify(
-						notifyId,
-		    			mNotifyBuilder.build());
+			mNotificationManager.notify(notifyId, mNotification);
 		}	
-		
+ 		
  	}
     
     /* (non-Javadoc)





More information about the tor-commits mailing list