diff --git a/.classpath b/.classpath index 5af07391..5777aed3 100644 --- a/.classpath +++ b/.classpath @@ -1,9 +1,10 @@ - - - - - - - - - + + + + + + + + + + diff --git a/hello.txt b/hello.txt new file mode 100644 index 00000000..e69de29b diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index 11ccac36..8de17376 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -5,43 +5,43 @@ android:key="setting_instances" android:title="Manage XBMC Hosts" android:summary="Add, edit and remove the XBMC instances in your LAN."> - + - + android:enabled="false" /--> - - + - - - + + android:enabled="true" android:defaultValue="true" /> + android:enabled="true" + android:defaultValue="false" /> + android:dependency="setting_send_repeats" + android:defaultValue="false" /> \ No newline at end of file diff --git a/src/org/xbmc/android/remote/presentation/activity/ConfigurationManager.java b/src/org/xbmc/android/remote/presentation/activity/ConfigurationManager.java index de17723a..c8ba0bbd 100644 --- a/src/org/xbmc/android/remote/presentation/activity/ConfigurationManager.java +++ b/src/org/xbmc/android/remote/presentation/activity/ConfigurationManager.java @@ -21,11 +21,17 @@ package org.xbmc.android.remote.presentation.activity; +import static org.xbmc.android.remote.presentation.controller.SettingsController.PREF_AUTO_ROTATE; + +import java.util.ArrayList; import android.app.Activity; import android.app.KeyguardManager; import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; +import android.content.pm.ActivityInfo; +import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; import android.media.AudioManager; import android.preference.PreferenceManager; @@ -33,6 +39,7 @@ class ConfigurationManager implements OnSharedPreferenceChangeListener { public final static String PREF_KEYGUARD_DISABLED = "setting_disable_keyguard"; + public final static String KEYGUARD_STATUS_ENABLED = "0"; public final static String KEYGUARD_STATUS_REMOTE_ONLY = "1"; public final static String KEYGUARD_STATUS_ALL = "2"; @@ -40,7 +47,7 @@ class ConfigurationManager implements OnSharedPreferenceChangeListener { public final static int INT_KEYGUARD_STATUS_ENABLED = 0; public final static int INT_KEYGUARD_STATUS_REMOTE_ONLY = 1; public final static int INT_KEYGUARD_STATUS_ALL = 2; - + public final static String KEYGUARD_TAG = "xbmc_remote_keyguard_lock"; private static ConfigurationManager sInstance; @@ -48,7 +55,9 @@ class ConfigurationManager implements OnSharedPreferenceChangeListener { private Activity mActivity; private int mKeyguardState = 0; - + private int mOrientation; + private ArrayList portraitList; + private KeyguardManager.KeyguardLock mKeyguardLock = null; private ConfigurationManager(Activity activity) { @@ -56,6 +65,20 @@ private ConfigurationManager(Activity activity) { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mActivity); prefs.registerOnSharedPreferenceChangeListener(this); mKeyguardState = Integer.parseInt(prefs.getString(PREF_KEYGUARD_DISABLED, KEYGUARD_STATUS_ENABLED)); + portraitList = new ArrayList(); + try { + ActivityInfo[] info = mActivity.getPackageManager().getPackageInfo(mActivity.getPackageName(), PackageManager.GET_ACTIVITIES).activities; + for (int i = 0; i < info.length; i++) { + if(info[i].screenOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { + portraitList.add(info[i].name); + } + } + } catch (NameNotFoundException e) { + e.printStackTrace(); + } + + mOrientation = (prefs.getBoolean(PREF_AUTO_ROTATE, true)) ? ActivityInfo.SCREEN_ORIENTATION_SENSOR : + ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; } public static ConfigurationManager getInstance(Activity activity) { @@ -68,15 +91,15 @@ public static ConfigurationManager getInstance(Activity activity) { } //Use with extreme care! this could return null, so you need to null-check - //in the calling code! + //in the calling code! public static ConfigurationManager getInstance() { return sInstance; } - + public Context getActiveContext() { return sInstance.mActivity; } - + public void disableKeyguard(Activity activity) { if (mKeyguardLock != null) { mKeyguardLock.disableKeyguard(); @@ -86,7 +109,7 @@ public void disableKeyguard(Activity activity) { mKeyguardLock.disableKeyguard(); } } - + public void enableKeyguard() { if (mKeyguardLock != null) { mKeyguardLock.reenableKeyguard(); @@ -102,9 +125,12 @@ public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { disableKeyguard(mActivity); else enableKeyguard(); + } else if(key.equals(PREF_AUTO_ROTATE)) { + mOrientation = (prefs.getBoolean(PREF_AUTO_ROTATE, true)) ? ActivityInfo.SCREEN_ORIENTATION_SENSOR : + ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; } } - + public void onActivityResume(Activity activity) { switch (mKeyguardState) { case INT_KEYGUARD_STATUS_REMOTE_ONLY: @@ -120,16 +146,19 @@ public void onActivityResume(Activity activity) { enableKeyguard(); break; } - + activity.setVolumeControlStream(AudioManager.STREAM_MUSIC); mActivity = activity; + if(!portraitList.contains(mActivity.getComponentName().getClassName())) { + mActivity.setRequestedOrientation(mOrientation); + } } - + public void onActivityPause() { if (mKeyguardLock != null){ mKeyguardLock.reenableKeyguard(); mKeyguardLock = null; } } - + } \ No newline at end of file diff --git a/src/org/xbmc/android/remote/presentation/activity/GestureRemoteActivity.java b/src/org/xbmc/android/remote/presentation/activity/GestureRemoteActivity.java index 7319e718..260cbb7b 100644 --- a/src/org/xbmc/android/remote/presentation/activity/GestureRemoteActivity.java +++ b/src/org/xbmc/android/remote/presentation/activity/GestureRemoteActivity.java @@ -41,16 +41,16 @@ /** * Gesture mode. Let's see how this works out... - * + * * @author Team XBMC */ public class GestureRemoteActivity extends Activity { - + private final static String TAG = "GestureRemoteActivity"; - + private ConfigurationManager mConfigurationManager; private RemoteController mRemoteController; - + private static final int MENU_NOW_PLAYING = 401; private static final int MENU_SWITCH_BUTTONS = 402; // private static final int MENU_SWITCH_MOUSE = 403; @@ -59,7 +59,7 @@ public class GestureRemoteActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - + Display d = getWindowManager().getDefaultDisplay(); final int w = d.getWidth(); final int h = d.getHeight(); @@ -71,15 +71,15 @@ public void onCreate(Bundle savedInstanceState) { Log.i(TAG, "AR = " + ar + ", normal layout."); setContentView(R.layout.remote_gesture); } - + // remove nasty top fading edge FrameLayout topFrame = (FrameLayout)findViewById(android.R.id.content); topFrame.setForeground(null); - - GestureRemoteView view = (GestureRemoteView)findViewById(R.id.RemoteXboxGestureZone); + + GestureRemoteView view = (GestureRemoteView)findViewById(R.id.RemoteXboxGestureZone); mRemoteController = new RemoteController(getApplicationContext()); view.setGestureListener(mRemoteController.startGestureThread(this.getApplicationContext())); - + mConfigurationManager = ConfigurationManager.getInstance(this); // mConfigurationManager.initKeyguard(true); setupButtons(); @@ -101,12 +101,12 @@ public void onPrepareDialog(int id, Dialog dialog) { public boolean onTrackballEvent(MotionEvent event) { return mRemoteController.onTrackballEvent(event); } - + @Override public boolean onKeyDown(int keyCode, KeyEvent event) { return mRemoteController.onKeyDown(keyCode, event) ? true : super.onKeyDown(keyCode, event); } - + @Override protected void onResume() { super.onResume(); @@ -114,7 +114,7 @@ protected void onResume() { mRemoteController.onActivityResume(this); mConfigurationManager.onActivityResume(this); } - + @Override protected void onPause() { super.onPause(); @@ -128,7 +128,7 @@ protected void onPause() { private void setupButtons() { // display mRemoteController.setupButton(findViewById(R.id.RemoteXboxImgBtnDisplay), ButtonCodes.REMOTE_DISPLAY); - + // seek back mRemoteController.setupButton(findViewById(R.id.RemoteXboxImgBtnSeekBack), ButtonCodes.REMOTE_REVERSE); // play @@ -145,7 +145,7 @@ private void setupButtons() { // next mRemoteController.setupButton(findViewById(R.id.RemoteXboxImgBtnNext), ButtonCodes.REMOTE_SKIP_PLUS); } - + public boolean onCreateOptionsMenu(Menu menu) { menu.add(0, MENU_SWITCH_BUTTONS, 0, "Switch to buttons").setIcon(R.drawable.menu_remote); menu.add(0, MENU_NOW_PLAYING, 0, "Now playing").setIcon(R.drawable.menu_nowplaying); @@ -162,7 +162,7 @@ public boolean onOptionsItemSelected(MenuItem item) { break; case MENU_SWITCH_BUTTONS: intent = new Intent(this, RemoteActivity.class); - intent.addFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NO_HISTORY); + intent.addFlags(intent.getFlags()); break; case MENU_ENTER_TEXT: showDialog(RemoteController.DIALOG_SENDTEXT); diff --git a/src/org/xbmc/android/remote/presentation/controller/RemoteController.java b/src/org/xbmc/android/remote/presentation/controller/RemoteController.java index d3cc601e..d34509d3 100644 --- a/src/org/xbmc/android/remote/presentation/controller/RemoteController.java +++ b/src/org/xbmc/android/remote/presentation/controller/RemoteController.java @@ -62,7 +62,7 @@ public class RemoteController extends AbstractController implements INotifiableC public static final int LAST_REMOTE_BUTTON = 0; public static final int LAST_REMOTE_GESTURE = 1; public static final String LAST_REMOTE_PREFNAME = "last_remote_type"; - + private static final int MENU_NOW_PLAYING = 401; private static final int MENU_XBMC_EXIT = 402; private static final int MENU_XBMC_S = 403; @@ -75,27 +75,27 @@ public class RemoteController extends AbstractController implements INotifiableC private static final int DPAD_DOWN_MIN_DELTA_TIME = 100; private static final int MOTION_EVENT_MIN_DELTA_TIME = 250; private static final float MOTION_EVENT_MIN_DELTA_POSITION = 0.15f; - + private static final long VIBRATION_LENGTH = 45; - + IEventClientManager mEventClientManager; IInfoManager mInfoManager; IControlManager mControl; GestureThread mGestureThread; - + /** * timestamp since last trackball use. */ private long mTimestamp = 0; private final Vibrator mVibrator; private final boolean mDoVibrate; - + private int mEventServerInitialDelay = 750; - + private Timer tmrKeyPress; - + final SharedPreferences prefs; - + public RemoteController(Context context) { prefs = PreferenceManager.getDefaultSharedPreferences(context); @@ -168,7 +168,7 @@ private void scroll(String button, double amount) { mScrolling = false; } } - + public void onScrollDown(double amount) { Log.d(TAG, "onScrollDown(" + amount + ")"); scroll(ButtonCodes.GAMEPAD_RIGHT_ANALOG_TRIGGER, amount); @@ -203,7 +203,7 @@ public void onTitle() { }; return listener; } - + private static class GestureThread extends Thread { public static final int ACTION_UP = 1; public static final int ACTION_RIGHT = 2; @@ -257,7 +257,7 @@ public synchronized void quit() { mQuit = true; } } - + public void showVolume() { } @@ -283,11 +283,11 @@ public boolean onKeyDown(int keyCode, KeyEvent event) { return onDirectionalPadDown(keyCode); case KeyEvent.KEYCODE_DPAD_CENTER: return onDirectionalPadDown(keyCode); - default: + default: return false; } } - + private boolean onDirectionalPadDown(int keyCode){ long newstamp = System.currentTimeMillis(); if (newstamp - mTimestamp > DPAD_DOWN_MIN_DELTA_TIME){ @@ -307,14 +307,14 @@ private boolean onDirectionalPadDown(int keyCode){ return true; case KeyEvent.KEYCODE_DPAD_CENTER: mEventClientManager.sendButton("R1", ButtonCodes.REMOTE_ENTER, false, true, true, (short)0, (byte)0); - return true; + return true; default: return false; } } return true; - } - + } + public boolean onTrackballEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) return keyboardAction(ButtonCodes.KEYBOARD_ENTER); @@ -332,7 +332,7 @@ public boolean onTrackballEvent(MotionEvent event) { } return true; } - + public boolean onCreateOptionsMenu(Menu menu) { menu.add(0, MENU_NOW_PLAYING, 0, "Now playing").setIcon(R.drawable.menu_nowplaying); menu.add(0, MENU_SWITCH_GESTURE, 0, "Gesture mode").setIcon(R.drawable.menu_gesture_mode); @@ -392,7 +392,7 @@ public boolean onOptionsItemSelected(MenuItem item) { break; case MENU_SWITCH_GESTURE: intent = new Intent(mActivity, GestureRemoteActivity.class); - intent.addFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NO_HISTORY); + intent.addFlags(intent.getFlags()); break; case MENU_XBMC_EXIT: mEventClientManager.sendButton("R1", ButtonCodes.REMOTE_POWER, false, true, true, (short)0, (byte)0); @@ -405,13 +405,14 @@ public boolean onOptionsItemSelected(MenuItem item) { break; } if (intent != null) { - intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_CLEAR_TOP); + intent.setFlags(intent.getFlags()); mActivity.startActivity(intent); + mActivity.finish(); return true; } return true; } - + /** * Sends a keyboard event * @param button @@ -436,7 +437,7 @@ public void setupButton(View btn, String action) { ((Button)btn).setClickable(true); } } - + /** * Handles the push- release button code. Switches image of the pressed * button, vibrates and executes command. @@ -453,37 +454,37 @@ public boolean onTouch(View v, MotionEvent event) { mVibrator.vibrate(VIBRATION_LENGTH); } mEventClientManager.sendButton("R1", mAction, !prefs.getBoolean("setting_send_repeats", false), true, true, (short)0, (byte)0); - + if (prefs.getBoolean("setting_send_repeats", false) && !prefs.getBoolean("setting_send_single_click", false)) { - + if (tmrKeyPress != null) { - tmrKeyPress.cancel(); + tmrKeyPress.cancel(); } - + int RepeatDelay = Integer.parseInt(prefs.getString("setting_repeat_rate", "250")); - + tmrKeyPress = new Timer(); - tmrKeyPress.schedule(new KeyPressTask(mAction), RepeatDelay, RepeatDelay); + tmrKeyPress.schedule(new KeyPressTask(mAction), RepeatDelay, RepeatDelay); } - - + + } else if (event.getAction() == MotionEvent.ACTION_UP) { Log.d(TAG, "onTouch - ACTION_UP"); v.playSoundEffect(AudioManager.FX_KEY_CLICK); mEventClientManager.sendButton("R1", mAction, false, false, true, (short)0, (byte)0); - + if (tmrKeyPress != null) { - tmrKeyPress.cancel(); - } + tmrKeyPress.cancel(); + } } return false; - } + } } - + private class KeyPressTask extends TimerTask { - + private String mKeyPressAction = ""; - + public KeyPressTask(String mAction) { mKeyPressAction = mAction; } @@ -491,10 +492,10 @@ public KeyPressTask(String mAction) { public void run() { if (mKeyPressAction.length() > 0){ mEventClientManager.sendButton("R1", mKeyPressAction, false, true, true, (short)0, (byte)0); - } + } } } - + public void onActivityPause() { mEventClientManager.setController(null); mInfoManager.setController(null); diff --git a/src/org/xbmc/android/remote/presentation/controller/SettingsController.java b/src/org/xbmc/android/remote/presentation/controller/SettingsController.java index b4909ec9..dce93d31 100644 --- a/src/org/xbmc/android/remote/presentation/controller/SettingsController.java +++ b/src/org/xbmc/android/remote/presentation/controller/SettingsController.java @@ -37,6 +37,8 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; +import android.content.pm.ActivityInfo; +import android.graphics.Bitmap.Config; import android.os.Handler; import android.preference.Preference; import android.preference.PreferenceActivity; @@ -46,21 +48,23 @@ import android.view.MenuItem; public class SettingsController extends AbstractController implements INotifiableController, IController, OnSharedPreferenceChangeListener { - + public static final int MENU_ADD_HOST = 1; public static final int MENU_EXIT = 2; public static final int MENU_ADD_HOST_WIZARD = 3; - - private PreferenceActivity mPreferenceActivity; + + public static final String PREF_AUTO_ROTATE = "setting_auto_rotate"; + + private PreferenceActivity mPreferenceActivity; private final Hashtable mSummaries = new Hashtable(); - + public SettingsController(PreferenceActivity activity, Handler handler) { mPreferenceActivity = activity; super.onCreate(activity, handler); } - + /** - * Used in SettingsActivity in order to update the %value% placeholder in + * Used in SettingsActivity in order to update the %value% placeholder in * the summaries. * @param activity Reference to activity */ @@ -77,12 +81,12 @@ public void registerOnSharedPreferenceChangeListener(PreferenceActivity activity } updateSummaries(); } - + /** * Creates the preference screen that contains all the listed hosts. * @param root Root node * @param activity Reference to activity - * @return + * @return */ public PreferenceScreen createHostsPreferences(PreferenceScreen root, Activity activity) { final ArrayList hosts = HostFactory.getHosts(activity.getApplicationContext()); @@ -107,7 +111,7 @@ public void onClick(DialogInterface dialog, int which) { } return root; } - + /** * Updates summaries of all known keys with the updated value. */ @@ -123,7 +127,7 @@ public void updateSummaries() { } } } - + /** * Used in order to replace the %value% placeholders with real values. */ @@ -134,6 +138,11 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin if (origSummary != null && origSummary.contains(SettingsActivity.SUMMARY_VALUE_PLACEHOLDER)) { pref.setSummary(origSummary.replaceAll(SettingsActivity.SUMMARY_VALUE_PLACEHOLDER, sharedPreferences.getString(key, ""))); } + if(key.equals( PREF_AUTO_ROTATE)) { + int mOrientation = (sharedPreferences.getBoolean(PREF_AUTO_ROTATE, true)) ? ActivityInfo.SCREEN_ORIENTATION_SENSOR : + ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; + mActivity.setRequestedOrientation(mOrientation); + } } public void onCreateOptionsMenu(Menu menu) { @@ -141,7 +150,7 @@ public void onCreateOptionsMenu(Menu menu) { menu.addSubMenu(0, MENU_ADD_HOST_WIZARD, 0, "Host Wizard").setIcon(R.drawable.menu_add_host); menu.addSubMenu(0, MENU_EXIT, 0, "Exit").setIcon(R.drawable.menu_exit); } - + public void onMenuItemSelected(int featureId, MenuItem item) { switch (item.getItemId()) { case MENU_ADD_HOST: @@ -159,14 +168,14 @@ public void onMenuItemSelected(int featureId, MenuItem item) { break; } } - + public void onActivityPause() { super.onActivityPause(); } - + public void onActivityResume(Activity activity) { super.onActivityResume(activity); - final ArrayList hosts = HostFactory.getHosts(activity.getApplicationContext()); + final ArrayList hosts = HostFactory.getHosts(activity.getApplicationContext()); if (hosts.size() == 1) { final Host host = hosts.get(0); Log.i(TAG, "Setting host to " + (host == null ? "" : host.addr) + "."); @@ -176,5 +185,5 @@ public void onActivityResume(Activity activity) { Log.i(TAG, "Resetting host to ."); HostFactory.saveHost(activity.getApplicationContext(), null); } - } + } } \ No newline at end of file