diff options
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/hoopajoo/android/SoftKeys/ConfigureExtra.java | 59 | ||||
-rw-r--r-- | src/net/hoopajoo/android/SoftKeys/Generator.java | 29 | ||||
-rw-r--r-- | src/net/hoopajoo/android/SoftKeys/Globals.java | 23 | ||||
-rw-r--r-- | src/net/hoopajoo/android/SoftKeys/Keys.java | 71 | ||||
-rw-r--r-- | src/net/hoopajoo/android/SoftKeys/Prefs.java | 16 | ||||
-rw-r--r-- | src/net/hoopajoo/android/SoftKeys/SoftKeysService.java | 91 |
6 files changed, 210 insertions, 79 deletions
diff --git a/src/net/hoopajoo/android/SoftKeys/ConfigureExtra.java b/src/net/hoopajoo/android/SoftKeys/ConfigureExtra.java index 85bd35a..51f9fa6 100644 --- a/src/net/hoopajoo/android/SoftKeys/ConfigureExtra.java +++ b/src/net/hoopajoo/android/SoftKeys/ConfigureExtra.java @@ -44,7 +44,6 @@ import android.widget.Button; import android.widget.Spinner; public class ConfigureExtra extends Activity implements OnClickListener { - /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -52,17 +51,7 @@ public class ConfigureExtra extends Activity implements OnClickListener { SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences( this ); - List<CustomKey> items = new ArrayList<CustomKey>(); - - 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<CustomKey> items = CustomKey.getCustomKeyList(); ArrayAdapter<CustomKey> adapter = new ArrayAdapter<CustomKey>( 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<String> display = new ArrayList<String>(); + ArrayList<String> values = new ArrayList<String>(); + + 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(); } |