diff options
author | Steve Slaven <bpk@hoopajoo.net> | 2011-01-11 17:53:43 (GMT) |
---|---|---|
committer | Steve Slaven <bpk@hoopajoo.net> | 2011-01-11 17:53:43 (GMT) |
commit | 616b68b9469c4a4a39bf13c0a356f52f91514aa8 (patch) | |
tree | 3892f66d6f67d5d8fdc906e13e377b7d60d2babd | |
parent | b63863af4481996d696e0898ca90a651f660dc1a (diff) | |
download | SoftKeys-616b68b9469c4a4a39bf13c0a356f52f91514aa8.zip SoftKeys-616b68b9469c4a4a39bf13c0a356f52f91514aa8.tar.gz SoftKeys-616b68b9469c4a4a39bf13c0a356f52f91514aa8.tar.bz2 |
Use explicit actions for notification buttons, extras are getting mangled,
remove global intents
-rw-r--r-- | AndroidManifest.xml | 3 | ||||
-rw-r--r-- | src/net/hoopajoo/android/SoftKeys/Keys.java | 17 | ||||
-rw-r--r-- | src/net/hoopajoo/android/SoftKeys/SendInput.java | 42 |
3 files changed, 48 insertions, 14 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index c833456..3d3ca0e 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -59,11 +59,12 @@ <activity android:name=".SendInput" android:label="@string/app_name"> - + <!-- <intent-filter> <action android:name="net.hoopajoo.android.SoftKeys.KEY_CODE" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> + --> </activity> <service android:name=".SoftKeysService"/> diff --git a/src/net/hoopajoo/android/SoftKeys/Keys.java b/src/net/hoopajoo/android/SoftKeys/Keys.java index 8312317..424c7f6 100644 --- a/src/net/hoopajoo/android/SoftKeys/Keys.java +++ b/src/net/hoopajoo/android/SoftKeys/Keys.java @@ -94,7 +94,11 @@ public class Keys extends Activity implements OnClickListener, OnLongClickListen mAction = act; mExtraString = extra; } - + + NotificationButton( String text, String pref, RemoteViews view, Drawable d, int icon, String act ) { + this( text, pref, view, d, icon, act, null ); + } + NotificationButton( String text, String pref, int icon, String act ) { this( text, pref, null, null, icon, act, null ); } @@ -250,22 +254,22 @@ public class Keys extends Activity implements OnClickListener, OnLongClickListen theme.getRemoteViews( new String[] { "notification_menu" } ), theme.getDrawable( new String[] { "notification_menu" } ), R.drawable.button_menu, - SendInput.ACTION_CODE, "menu" ); + SendInput.ACTION_MENU ); nb[ 2 ] = new NotificationButton( "Home", "nb_home", theme.getRemoteViews( new String[] { "notification_home" } ), theme.getDrawable( new String[] { "notification_home" } ), R.drawable.button_home, - SendInput.ACTION_CODE, "home" ); + SendInput.ACTION_HOME ); nb[ 3 ] = new NotificationButton( "Back", "nb_back", theme.getRemoteViews( new String[] { "notification_back" } ), theme.getDrawable( new String[] { "notification_back" } ), R.drawable.button_back, - SendInput.ACTION_CODE, "back" ); + SendInput.ACTION_BACK ); nb[ 4 ] = new NotificationButton( "Search", "nb_search", theme.getRemoteViews( new String[] { "notification_search" } ), theme.getDrawable( new String[] { "notification_search" } ), R.drawable.button_search, - SendInput.ACTION_CODE, "back" ); + SendInput.ACTION_SEARCH ); for( NotificationButton b : nb ) { if( settings.getBoolean( b.mPrefKey, false ) ) { @@ -274,6 +278,9 @@ public class Keys extends Activity implements OnClickListener, OnLongClickListen si.putExtra( "keyname", b.mExtraString ); if( b.mAction == Intent.ACTION_MAIN ) { si.setPackage( getPackageName() ); + }else{ + //si.setPackage( getPackageName() ); + si.setClass( this, SendInput.class ); } PendingIntent i = PendingIntent.getActivity( this, 0, si, 0 ); diff --git a/src/net/hoopajoo/android/SoftKeys/SendInput.java b/src/net/hoopajoo/android/SoftKeys/SendInput.java index aa30d62..32d3a92 100644 --- a/src/net/hoopajoo/android/SoftKeys/SendInput.java +++ b/src/net/hoopajoo/android/SoftKeys/SendInput.java @@ -60,6 +60,10 @@ import android.widget.Toast; // this is just a stub to handle intent calls public class SendInput extends Activity { public static String ACTION_CODE = "net.hoopajoo.android.SoftKeys.KEY_CODE"; + public static String ACTION_HOME = "net.hoopajoo.android.SoftKeys.KEY_HOME"; + public static String ACTION_MENU = "net.hoopajoo.android.SoftKeys.KEY_MENU"; + public static String ACTION_SEARCH = "net.hoopajoo.android.SoftKeys.KEY_SEARCH"; + public static String ACTION_BACK = "net.hoopajoo.android.SoftKeys.KEY_BACK"; /** Called when the activity is first created. */ @Override @@ -73,15 +77,17 @@ public class SendInput extends Activity { Globals app = (Globals)getApplication(); String action = i.getAction(); + int keyid = 0; if( action.equals( ACTION_CODE ) ) { // by key name? - int keyid = 0; Bundle e = i.getExtras(); boolean longClick = e.getBoolean( "longclick", false ); if( e.getString( "keyname" ) != null ) { String key = e.getString( "keyname" ); + //Log.d( "SoftKeys.SendInput", "resolving: " + key ); if( key.equals( "home" ) ) { ((Globals)getApplication()).doHomeAction( longClick ); + this.finish(); return; }else{ // run through resolver @@ -90,14 +96,34 @@ public class SendInput extends Activity { }else if( e.getInt( "keyid", 0 ) != 0 ) { keyid = e.getInt( "keyid", 0 ); } + } - if( keyid != 0 ) { - ((Globals)getApplication()).sendKeys( new int[] { keyid } ); - } - - // todo: make me a broadcast receiver.. or maybe this should be removed all together? - // any good reasons to allow other apps to call hw keys? - this.finish(); + if( action.equals( ACTION_HOME ) ) { + ((Globals)getApplication()).doHomeAction( false ); + this.finish(); + return; + } + + if( action.equals( ACTION_BACK ) ) { + keyid = K.KEYID_BACK; + } + + if( action.equals( ACTION_MENU ) ) { + keyid = K.KEYID_MENU; } + + if( action.equals( ACTION_SEARCH ) ) { + keyid = K.KEYID_SEARCH; + } + + if( keyid != 0 ) { + Log.d( "SoftKeys.SendInput", "resolved key: " + keyid ); + ((Globals)getApplication()).sendKeys( new int[] { keyid } ); + } + + // todo: make me a broadcast receiver.. or maybe this should be removed all together? + // any good reasons to allow other apps to call hw keys? + this.finish(); + } } |