From 884278de9c26d441fb2371ac2fd1a4d343e77eec Mon Sep 17 00:00:00 2001 From: Steve Slaven Date: Wed, 26 Jan 2011 20:09:02 -0800 Subject: Add power/volume up/volume down keys to service and home screen, add connect bot shortcuts diff --git a/assets/input/RemoteContext.jar b/assets/input/RemoteContext.jar index 64b4764..90ad29a 100644 Binary files a/assets/input/RemoteContext.jar and b/assets/input/RemoteContext.jar differ diff --git a/res/layout/buttonids.xml b/res/layout/buttonids.xml index 6a06552..05bea58 100644 --- a/res/layout/buttonids.xml +++ b/res/layout/buttonids.xml @@ -29,6 +29,11 @@ + + + + + diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 1d82e75..231e449 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -57,4 +57,20 @@ tiny + + Horizontal, Adjustable + Horizontal, Locked + Vertical, Adjustable + Vertical, Locked + Last Orientation, Adjustable + + + + horizontal_adjust + horizontal + vertical_adjust + vertical + save_adjust + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 412f8d2..dfea6a7 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -31,6 +31,17 @@ Transparent Background Background is Transparent, Buttons are Floating Normal Background Containing Buttons + Orientation + Choose Vertical or Horizontal and if Long Press Toggles + + Extra Custom Keys + Set Custom Keys Under D-Pad + Custom Key 1 + Custom Key 2 + Custom Key 3 + Custom Key 4 + Custom Key 5 + Custom Key 6 Virtual Home Button Select Launcher @@ -75,6 +86,21 @@ Prefs Button Show Prefs Button Hide Prefs Button + Volume Up Button + Show Volume Up Button + Hide Volume Up Button + Volume Down Button + Show Volume Down Button + Hide Volume Down Button + Sleep Button + Show Sleep Button + Hide Sleep Button + Custom 1 Button + Show Custom 1 Button + Hide Custom 1 Button + Custom 2 Button + Show Custom 2 Button + Hide Custom 2 Button Change Button Order Menu Button Position diff --git a/res/xml/prefs.xml b/res/xml/prefs.xml index 7a1b07b..fddc692 100644 --- a/res/xml/prefs.xml +++ b/res/xml/prefs.xml @@ -85,7 +85,51 @@ android:defaultValue="false" android:key="service_no_background" /> - + + + + + + + + + + + + + + + + + + - - + + + + + + items = new ArrayList(); - - items.add( new CustomKey( 0, "NONE" ) ); - items.add( new CustomKey( -1, "SLEEP" ) ); - - for( int cnt = 1; cnt < 100; cnt++ ) { - String name = K.keyIdToName( cnt ); - if( name != null ) { - items.add( new CustomKey( cnt, name ) ); - } - } + List items = CustomKey.getCustomKeyList(); ArrayAdapter adapter = new ArrayAdapter( this, android.R.layout.simple_spinner_item, items ); @@ -73,8 +62,8 @@ public class ConfigureExtra extends Activity implements OnClickListener { R.id.extra_custom5, R.id.extra_custom6 } ) { i++; - String pref_name = "service_extra_custom" + i + "_keyid"; - int keycode = settings.getInt( pref_name, 0 ); + String pref_name = "service_extra_custom_keyid" + i; + int keycode = Integer.parseInt( settings.getString( pref_name, "0" ) ); Spinner s = (Spinner)findViewById( id ); s.setAdapter( adapter ); @@ -103,52 +92,14 @@ public class ConfigureExtra extends Activity implements OnClickListener { R.id.extra_custom5, R.id.extra_custom6 } ) { i++; - String pref_name = "service_extra_custom" + i + "_keyid"; + String pref_name = "service_extra_custom_keyid" + i; Spinner s = (Spinner)findViewById( id ); CustomKey k = (CustomKey)s.getSelectedItem(); - e.putInt( pref_name, k.mId ); + e.putString( pref_name, Integer.toString( k.mId ) ); } e.commit(); ((Globals)getApplication()).restartService(); } this.finish(); } - - private class CustomKey { - public String mName; - public int mId; - - CustomKey( int id, String name ) { - mName = prettyPrint( name ); - mId = id; - } - - public String toString() { - return mName; - } - } - - public static String prettyPrint( String n ) { - // replace _ with space, initcap - String s = n.replace( "_", " " ); - - boolean bound = true; - StringBuilder r = new StringBuilder(); - for( int i = 0; i < s.length(); i++ ) { - if( bound ) { - // cap - r.append( Character.toUpperCase( s.charAt( i ) ) ); - bound = false; - }else{ - r.append( Character.toLowerCase( s.charAt( i ) ) ); - } - - // check for boundry - if( Character.isSpace( s.charAt( i ) ) ) { - bound = true; - } - } - - return r.toString(); - } } diff --git a/src/net/hoopajoo/android/SoftKeys/Generator.java b/src/net/hoopajoo/android/SoftKeys/Generator.java index 99ea772..715a104 100644 --- a/src/net/hoopajoo/android/SoftKeys/Generator.java +++ b/src/net/hoopajoo/android/SoftKeys/Generator.java @@ -98,8 +98,12 @@ public class Generator { // now we add the buttons if( buttons == null ) { - buttons = new int[] { R.id.menu, R.id.home, R.id.back, - R.id.search, R.id.settings, R.id.exit }; + buttons = new int[] { + R.id.menu, R.id.home, + R.id.back, R.id.search, + R.id.volume_down, R.id.volume_up, + R.id.sleep, + R.id.settings, R.id.exit }; } for( int i : buttons ) { @@ -125,6 +129,26 @@ public class Generator { name = "settings"; break; + case R.id.sleep: + name = "sleep"; + break; + + case R.id.volume_up: + name = "volume_up"; + break; + + case R.id.volume_down: + name = "volume_down"; + break; + + case R.id.custom1: + name = "custom1"; + break; + + case R.id.custom2: + name = "custom2"; + break; + case R.id.exit: name = "exit"; break; @@ -161,7 +185,6 @@ public class Generator { applyButtonExtras( b, prefix, name, theme, iconSize ); - container.addView( orig_b ); } diff --git a/src/net/hoopajoo/android/SoftKeys/Globals.java b/src/net/hoopajoo/android/SoftKeys/Globals.java index 703b32c..31d3f95 100644 --- a/src/net/hoopajoo/android/SoftKeys/Globals.java +++ b/src/net/hoopajoo/android/SoftKeys/Globals.java @@ -92,7 +92,28 @@ public class Globals extends Application { try { Globals.RootContext cmd = getRootContext(); for( int id : keyids ) { - cmd.runCommand( "keycode " + id ); + if( id > 0 ) { + cmd.runCommand( "keycode " + id ); + }else{ + // special keys/commands + switch( id ) { + case -1: + cmd.runCommand( "sleep" ); + break; + + case -2: + // connectbot tab = dpad ball + i + cmd.runCommand( "keycode " + K.KEYID_DPAD_CENTER ); + cmd.runCommand( "keycode " + K.KEYID_I ); + break; + + case -3: + // connectbot escape = dpad ball + dpad ball + cmd.runCommand( "keycode " + K.KEYID_DPAD_CENTER ); + cmd.runCommand( "keycode " + K.KEYID_DPAD_CENTER ); + break; + } + } } }catch( Exception e ) { Log.e( LOG, "Error: " + e.getMessage() ); diff --git a/src/net/hoopajoo/android/SoftKeys/Keys.java b/src/net/hoopajoo/android/SoftKeys/Keys.java index 9a28721..ddb87dc 100644 --- a/src/net/hoopajoo/android/SoftKeys/Keys.java +++ b/src/net/hoopajoo/android/SoftKeys/Keys.java @@ -122,8 +122,13 @@ public class Keys extends Activity implements OnClickListener, OnLongClickListen // reorder the buttons, they will be in the order of the buttons[] array // default is the order from my captivate: // menu, home, back, search - int[] buttons = { R.id.menu, R.id.home, R.id.back, - R.id.search, R.id.settings, R.id.exit }; + int[] buttons = { + R.id.menu, R.id.home, + R.id.back, R.id.search, + R.id.extra_custom1, R.id.extra_custom2, + R.id.volume_down, R.id.volume_up, + R.id.sleep, + R.id.settings, R.id.exit }; // now sort the buttons, we loop from 1 to 4, find the stuff with the same // index as our index we're using, and add them to the list. This should pick @@ -149,6 +154,11 @@ public class Keys extends Activity implements OnClickListener, OnLongClickListen } } // now add choose and exit, always last + buttons[ button_index++ ] = R.id.extra_custom1; + buttons[ button_index++ ] = R.id.extra_custom2; + buttons[ button_index++ ] = R.id.volume_down; + buttons[ button_index++ ] = R.id.volume_up; + buttons[ button_index++ ] = R.id.sleep; buttons[ button_index++ ] = R.id.settings; buttons[ button_index++ ] = R.id.exit; @@ -169,11 +179,46 @@ public class Keys extends Activity implements OnClickListener, OnLongClickListen b.setVisibility( settings.getBoolean( "exitbutton", true ) ? View.VISIBLE : View.GONE ); } - - if( i == R.id.settings ) { - b.setVisibility( - settings.getBoolean( "choosebutton", true ) ? View.VISIBLE : View.GONE ); - } + } + + String pref = null; + boolean def = false; + + switch( i ) { + case R.id.settings: + pref = "choosebutton"; + def = true; + break; + + case R.id.extra_custom1: + pref = "show_extra_custom1"; + def = false; + break; + + case R.id.extra_custom2: + pref = "show_extra_custom2"; + def = false; + break; + + case R.id.volume_down: + pref = "show_volume_down"; + def = false; + break; + + case R.id.volume_up: + pref = "show_volume_up"; + def = false; + break; + + case R.id.sleep: + pref = "show_sleep"; + def = false; + break; + } + + if( pref != null ) { + b.setVisibility( + settings.getBoolean( pref, def ) ? View.VISIBLE : View.GONE ); } } } @@ -574,6 +619,18 @@ public class Keys extends Activity implements OnClickListener, OnLongClickListen this.finish(); return true; + case R.id.volume_down: + keyids.add( K.KEYID_VOLUME_DOWN ); + break; + + case R.id.volume_up: + keyids.add( K.KEYID_VOLUME_UP ); + break; + + case R.id.sleep: + keyids.add( -1 ); + break; + default: d( "Unknown click event: " + id ); return true; diff --git a/src/net/hoopajoo/android/SoftKeys/Prefs.java b/src/net/hoopajoo/android/SoftKeys/Prefs.java index 4a93b15..e24cb3c 100644 --- a/src/net/hoopajoo/android/SoftKeys/Prefs.java +++ b/src/net/hoopajoo/android/SoftKeys/Prefs.java @@ -49,6 +49,22 @@ public class Prefs extends PreferenceActivity { i = new Intent( "net.hoopajoo.android.SoftKeys.THEMES" ); i.addCategory( Intent.CATEGORY_DEFAULT ); fillListFromIntent( (ListPreference)findPreference( "theme" ), i, "Default", "" ); + + // add the custom keys here too + ArrayList display = new ArrayList(); + ArrayList values = new ArrayList(); + + for( CustomKey k : CustomKey.getCustomKeyList() ) { + display.add( k.mName ); + values.add( Integer.toString( k.mId ) ); + } + + for( int num = 0; num < 5; num++ ) { + String s = "service_extra_custom_keyid" + (num + 1); + ListPreference list = (ListPreference)findPreference( s ); + list.setEntries( display.toArray( new CharSequence[ display.size() ] ) ); + list.setEntryValues( values.toArray( new CharSequence[ values.size() ] ) ); + } String ver = "unknown"; try { diff --git a/src/net/hoopajoo/android/SoftKeys/SoftKeysService.java b/src/net/hoopajoo/android/SoftKeys/SoftKeysService.java index 9371814..e75cbf5 100644 --- a/src/net/hoopajoo/android/SoftKeys/SoftKeysService.java +++ b/src/net/hoopajoo/android/SoftKeys/SoftKeysService.java @@ -64,6 +64,8 @@ public class SoftKeysService extends Service { private View mBumpView; private boolean auto_hide; private boolean auto_hide_after_back; + private boolean mOrientationAdjustable = true; + private boolean mRestoreOrientation = true; private boolean mDraggingView; private View mDraggingViewObj; private int mDraggingOrigX, mDraggingOrigY; @@ -117,12 +119,14 @@ public class SoftKeysService extends Service { return false; } - // rotate - LinearLayout l = (LinearLayout)mView.findViewById( R.id.button_container ); - if( l.getOrientation() == LinearLayout.HORIZONTAL ) { - l.setOrientation( LinearLayout.VERTICAL ); - }else{ - l.setOrientation( LinearLayout.HORIZONTAL ); + if( mOrientationAdjustable ) { + // rotate + LinearLayout l = (LinearLayout)mView.findViewById( R.id.button_container ); + if( l.getOrientation() == LinearLayout.HORIZONTAL ) { + l.setOrientation( LinearLayout.VERTICAL ); + }else{ + l.setOrientation( LinearLayout.HORIZONTAL ); + } } savePosition(); @@ -428,21 +432,24 @@ public class SoftKeysService extends Service { R.id.extra_custom5, R.id.extra_custom6 } ) { i++; - String pref_name = "service_extra_custom" + i + "_keyid"; - int keycode = settings.getInt( pref_name, 0 ); + String pref_name = "service_extra_custom_keyid" + i; + int keycode = Integer.parseInt( settings.getString( pref_name, "0" ) ); String keyname = K.keyIdToName( keycode ); if( keycode > 0 ) { if( keyname == null ) { keyname = "NONE"; }else{ - keyname = ConfigureExtra.prettyPrint( keyname ); + keyname = CustomKey.prettyPrint( keyname ); } }else{ if( keycode == 0 ) { keyname = "NONE"; - } - if( keycode == -1 ) { + }else if( keycode == -1 ) { keyname = "SLEEP"; + }else if( keycode == -2 ) { + keyname = "CB: TAB"; + }else if( keycode == -3 ) { + keyname = "CB: ESCAPE"; } } @@ -464,6 +471,25 @@ public class SoftKeysService extends Service { wm.addView( mView, makeOverlayParams() ); wm.addView( mExtraView, makeOverlayParams() ); + // initialize preference orientation + LinearLayout ll = (LinearLayout)mView.findViewById( R.id.button_container ); + String orientation = settings.getString( "service_orientation", "horizontal_adjust" ); + if( orientation.contains( "adjust" ) ) { + mOrientationAdjustable = true; + }else{ + mOrientationAdjustable = false; + } + + mRestoreOrientation = false; + if( orientation.contains( "save" ) ) { + // init to last saved value + mRestoreOrientation = true; + }else if( orientation.contains( "horizontal" ) ) { + ll.setOrientation( LinearLayout.HORIZONTAL ); + }else{ + ll.setOrientation( LinearLayout.VERTICAL ); + } + mOrientationListener = new OrientationEventListener( this, SensorManager.SENSOR_DELAY_NORMAL ) { @Override public void onOrientationChanged( int orientation ) { @@ -522,6 +548,16 @@ public class SoftKeysService extends Service { params.y = settings.getInt( "service_extra_last_y_" + mOrientation, 0 ); params.gravity = Gravity.TOP | Gravity.LEFT; wm.updateViewLayout( mExtraView, params ); + + if( mRestoreOrientation ) { + String last_orientation = settings.getString( "service_last_orientation_" + mOrientation, "horizontal" ); + LinearLayout l = (LinearLayout)mView.findViewById( R.id.button_container ); + if( last_orientation.equals( "vertical" ) ) { + l.setOrientation( LinearLayout.VERTICAL ); + }else{ + l.setOrientation( LinearLayout.HORIZONTAL ); + } + } } private boolean genericClick( View v, boolean longClick ) { @@ -565,6 +601,18 @@ public class SoftKeysService extends Service { } break; + case R.id.sleep: + keyid = -1; + break; + + case R.id.volume_down: + keyid = K.KEYID_VOLUME_DOWN; + break; + + case R.id.volume_up: + keyid = K.KEYID_VOLUME_UP; + break; + case R.id.exit: hide = true; break; @@ -627,11 +675,19 @@ public class SoftKeysService extends Service { } if( keyid != 0 ) { - if( keyid == -1 ) { - // sleep + if( false && keyid < 0 ) { + // dead, move special keys up to globals + String[] cmds = new String[] {}; + if( keyid == -1 ) { + // sleep + cmds = new String[] { "sleep" }; + } + try { Globals.RootContext cmd = ((Globals)getApplication()).getRootContext(); - cmd.runCommand( "sleep" ); + for( String command : cmds ) { + cmd.runCommand( command ); + } }catch( Exception e ) { // we don't really care if this fails, they should have gotten a shell // error from the sendkeys @@ -751,6 +807,13 @@ public class SoftKeysService extends Service { e.putBoolean( "service_extra_enabled", mExtraEnabled ); + LinearLayout ll = (LinearLayout)mView.findViewById( R.id.button_container ); + String orientation = "horizontal"; + if( ll.getOrientation() == LinearLayout.VERTICAL ) { + orientation = "vertical"; + } + e.putString( "service_last_orientation_" + mOrientation, orientation ); + e.commit(); } -- cgit v0.10.2