From 1b44b66b0aca6142aa85d19861473925b4db029e Mon Sep 17 00:00:00 2001 From: Steve Slaven Date: Mon, 10 Jan 2011 10:25:26 -0800 Subject: Pretty print key names, long press to toggle dpad view diff --git a/src/net/hoopajoo/android/SoftKeys/ConfigureExtra.java b/src/net/hoopajoo/android/SoftKeys/ConfigureExtra.java index 811ffff..85bd35a 100644 --- a/src/net/hoopajoo/android/SoftKeys/ConfigureExtra.java +++ b/src/net/hoopajoo/android/SoftKeys/ConfigureExtra.java @@ -75,10 +75,7 @@ public class ConfigureExtra extends Activity implements OnClickListener { i++; String pref_name = "service_extra_custom" + i + "_keyid"; int keycode = settings.getInt( pref_name, 0 ); - String keyname = K.keyIdToName( keycode ); - if( keyname == null ) { - keyname = "NONE"; - } + Spinner s = (Spinner)findViewById( id ); s.setAdapter( adapter ); @@ -122,7 +119,7 @@ public class ConfigureExtra extends Activity implements OnClickListener { public int mId; CustomKey( int id, String name ) { - mName = name; + mName = prettyPrint( name ); mId = id; } @@ -130,4 +127,28 @@ public class ConfigureExtra extends Activity implements OnClickListener { 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/Keys.java b/src/net/hoopajoo/android/SoftKeys/Keys.java index c5b98bc..33615b3 100644 --- a/src/net/hoopajoo/android/SoftKeys/Keys.java +++ b/src/net/hoopajoo/android/SoftKeys/Keys.java @@ -398,6 +398,11 @@ public class Keys extends Activity implements OnClickListener, OnLongClickListen generic_click( R.id.settings, false ); return true; + case R.id.menu_quit: + ((Globals)getApplication()).stopService( new Intent( this, SoftKeysService.class ) ); + this.finish(); + return true; + default: return super.onOptionsItemSelected( item ); } @@ -540,8 +545,8 @@ public class Keys extends Activity implements OnClickListener, OnLongClickListen // if we sent back, and didn't backout (so it was from main ui) and they // want to return, run am to get us back if( id == R.id.back && backout && return_after_back ) { - Globals.CommandShell cmd = ((Globals)getApplication()).getCommandShell(); - cmd.system( "am start -a android.intent.action.MAIN -n net.hoopajoo.android.SoftKeys/.Keys" ); + Globals.RootContext cmd = ((Globals)getApplication()).getRootContext(); + cmd.runCommand( "system am start -a android.intent.action.MAIN -n net.hoopajoo.android.SoftKeys/.Keys" ); } }catch( Exception e ) { // we don't really care if this fails, they should have gotten a shell diff --git a/src/net/hoopajoo/android/SoftKeys/SoftKeysService.java b/src/net/hoopajoo/android/SoftKeys/SoftKeysService.java index 3ba62ba..8184ef1 100644 --- a/src/net/hoopajoo/android/SoftKeys/SoftKeysService.java +++ b/src/net/hoopajoo/android/SoftKeys/SoftKeysService.java @@ -66,9 +66,8 @@ public class SoftKeysService extends Service { private View mDraggingViewObj; private int mDraggingOrigX, mDraggingOrigY; private int mDraggingViewX, mDraggingViewY; - private boolean mPendingDragEvent; private boolean mDidDrag; - private boolean mExtraEnabled = true; + private boolean mExtraEnabled = false; private int mNumDrags; private OrientationEventListener mOrientationListener; private Runnable mUpdateDrag; @@ -244,8 +243,6 @@ public class SoftKeysService extends Service { WindowManager wm = (WindowManager)getSystemService(WINDOW_SERVICE); wm.updateViewLayout( root, l ); - - mPendingDragEvent = false; } }; @@ -325,6 +322,15 @@ public class SoftKeysService extends Service { } } ); + b.setOnLongClickListener( new OnLongClickListener() { + @Override + public boolean onLongClick( View v ) { + mExtraEnabled = ! mExtraEnabled; + matchExtraView(); + return true; + } + } ); + // extra view (dpad, customizable buttons) mExtraView = l.inflate( R.layout.service_extra, null ); Generator.applyContainerExtras( mExtraView, "service_extra", @@ -419,6 +425,8 @@ public class SoftKeysService extends Service { if( keycode > 0 ) { if( keyname == null ) { keyname = "NONE"; + }else{ + keyname = ConfigureExtra.prettyPrint( keyname ); } }else{ if( keycode == 0 ) { -- cgit v0.10.2