From 4427ca0dbc5de75061d5f6c9193885768f8533a8 Mon Sep 17 00:00:00 2001 From: Akshay Zade Date: Sun, 19 Jul 2015 14:23:29 +0530 Subject: [PATCH 1/8] Added setting item for vibrate on remote press --- app/src/main/java/org/xbmc/kore/Settings.java | 4 ++++ app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/preferences.xml | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/app/src/main/java/org/xbmc/kore/Settings.java b/app/src/main/java/org/xbmc/kore/Settings.java index fa1cbb0..97dd5b8 100644 --- a/app/src/main/java/org/xbmc/kore/Settings.java +++ b/app/src/main/java/org/xbmc/kore/Settings.java @@ -88,6 +88,10 @@ public interface Settings { public static final String KEY_PREF_USE_HARDWARE_VOLUME_KEYS = "pref_use_hardware_volume_keys"; public static final boolean DEFAULT_PREF_USE_HARDWARE_VOLUME_KEYS = true; + // Vibrate on remote button press + public static final String KEY_PREF_VIBRATE_REMOTE_BUTTONS = "pref_vibrate_remote_buttons"; + public static final boolean DEFAULT_PREF_VIBRATE_REMOTE_BUTTONS = false; + // Current host id public static final String KEY_PREF_CURRENT_HOST_ID = "current_host_id"; public static final int DEFAULT_PREF_CURRENT_HOST_ID = -1; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a69b867..31dfd89 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -302,6 +302,7 @@ Switch to remote after media start Show notification while playing Use volume keys to control volume + Vibrate on remote button press About + + From a90349ec49b2bd1e29eac96b415625eb6462c4c6 Mon Sep 17 00:00:00 2001 From: Akshay Zade Date: Sun, 19 Jul 2015 16:15:01 +0530 Subject: [PATCH 2/8] Added vibrations to remote buttons --- app/src/main/AndroidManifest.xml | 3 +- .../java/org/xbmc/kore/ui/RemoteFragment.java | 11 +++++- .../org/xbmc/kore/utils/RepeatListener.java | 39 +++++++++++++++++-- 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4fbdc96..a1dd610 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -6,7 +6,8 @@ - /> + + = 0) { repeatHandler.postDelayed(handlerRunnable, initialInterval); @@ -131,4 +151,17 @@ public class RepeatListener implements View.OnTouchListener { return !((view instanceof Button) || (view instanceof ImageButton)); } + private void handleVibration() { + if(context != null) { + //Check if we should vibrate + boolean vibrateOnPress = PreferenceManager + .getDefaultSharedPreferences(context) + .getBoolean(Settings.KEY_PREF_VIBRATE_REMOTE_BUTTONS, + Settings.DEFAULT_PREF_VIBRATE_REMOTE_BUTTONS); + if (vibrateOnPress) { + vibrator.vibrate(500); + } + } + } + } \ No newline at end of file From c65ae70b99c2be273cf70740890d860d4e73ae58 Mon Sep 17 00:00:00 2001 From: Akshay Zade Date: Sun, 19 Jul 2015 20:19:37 +0530 Subject: [PATCH 3/8] Reduced vibration duration to 100ms and added it to UIUtils --- app/src/main/java/org/xbmc/kore/utils/RepeatListener.java | 2 +- app/src/main/java/org/xbmc/kore/utils/UIUtils.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/xbmc/kore/utils/RepeatListener.java b/app/src/main/java/org/xbmc/kore/utils/RepeatListener.java index 221923f..a136042 100644 --- a/app/src/main/java/org/xbmc/kore/utils/RepeatListener.java +++ b/app/src/main/java/org/xbmc/kore/utils/RepeatListener.java @@ -159,7 +159,7 @@ public class RepeatListener implements View.OnTouchListener { .getBoolean(Settings.KEY_PREF_VIBRATE_REMOTE_BUTTONS, Settings.DEFAULT_PREF_VIBRATE_REMOTE_BUTTONS); if (vibrateOnPress) { - vibrator.vibrate(500); + vibrator.vibrate(UIUtils.buttonVibrationDuration); } } } diff --git a/app/src/main/java/org/xbmc/kore/utils/UIUtils.java b/app/src/main/java/org/xbmc/kore/utils/UIUtils.java index 02caf45..34e1987 100644 --- a/app/src/main/java/org/xbmc/kore/utils/UIUtils.java +++ b/app/src/main/java/org/xbmc/kore/utils/UIUtils.java @@ -52,6 +52,7 @@ public class UIUtils { public static final int initialButtonRepeatInterval = 400; // ms public static final int buttonRepeatInterval = 80; // ms + public static final int buttonVibrationDuration = 100; //ms /** * Formats time based on seconds From bc08f5cfd4612e393a109ebc8f4bf2ab61769a34 Mon Sep 17 00:00:00 2001 From: Akshay Zade Date: Thu, 23 Jul 2015 20:18:01 +0530 Subject: [PATCH 4/8] Fixed spelling mistakes on RemoteFragment --- app/src/main/java/org/xbmc/kore/ui/RemoteFragment.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/xbmc/kore/ui/RemoteFragment.java b/app/src/main/java/org/xbmc/kore/ui/RemoteFragment.java index f62b063..bc4368a 100644 --- a/app/src/main/java/org/xbmc/kore/ui/RemoteFragment.java +++ b/app/src/main/java/org/xbmc/kore/ui/RemoteFragment.java @@ -136,8 +136,8 @@ public class RemoteFragment extends Fragment private Animation buttonInAnim; private Animation buttonOutAnim; - // Touch listener that provides touch feedbacl - private View.OnTouchListener feedbackTouckListener; + // Touch listener that provides touch feedback + private View.OnTouchListener feedbackTouchListener; // EventServer connection private EventServerConnection eventServerConnection = null; @@ -161,7 +161,7 @@ public class RemoteFragment extends Fragment createEventServerConnection(); - feedbackTouckListener = new View.OnTouchListener() { + feedbackTouchListener = new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { @@ -322,7 +322,7 @@ public class RemoteFragment extends Fragment final ApiMethod clickAction, final ApiMethod longClickAction) { // Set animation - button.setOnTouchListener(feedbackTouckListener); + button.setOnTouchListener(feedbackTouchListener); if (clickAction != null) { button.setOnClickListener(new View.OnClickListener() { @Override From cf0f76b5bd85e6842dfa9f12c42939a748e2946c Mon Sep 17 00:00:00 2001 From: Akshay Zade Date: Thu, 23 Jul 2015 20:46:06 +0530 Subject: [PATCH 5/8] Added vibrations to other remote buttons --- app/src/main/java/org/xbmc/kore/ui/RemoteFragment.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/java/org/xbmc/kore/ui/RemoteFragment.java b/app/src/main/java/org/xbmc/kore/ui/RemoteFragment.java index bc4368a..f204ee0 100644 --- a/app/src/main/java/org/xbmc/kore/ui/RemoteFragment.java +++ b/app/src/main/java/org/xbmc/kore/ui/RemoteFragment.java @@ -28,6 +28,7 @@ import android.os.Bundle; import android.os.Handler; import android.os.Vibrator; import android.support.v4.app.Fragment; +import android.util.Log; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; @@ -327,6 +328,8 @@ public class RemoteFragment extends Fragment button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + vibrator.vibrate(UIUtils.buttonVibrationDuration); + Log.e("Vibrator", "Vibrated!"); clickAction.execute(hostManager.getConnection(), defaultActionCallback, callbackHandler); } }); @@ -335,6 +338,8 @@ public class RemoteFragment extends Fragment button.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { + vibrator.vibrate(UIUtils.buttonVibrationDuration); + Log.e("Vibrator", "Vibrated!"); longClickAction.execute(hostManager.getConnection(), defaultActionCallback, callbackHandler); return true; } From 7170dc9548be72adf6b34efc729d12ea8a6c9ce9 Mon Sep 17 00:00:00 2001 From: Akshay Zade Date: Thu, 23 Jul 2015 20:59:46 +0530 Subject: [PATCH 6/8] Moved vibration handling to UIUtils --- .../org/xbmc/kore/utils/RepeatListener.java | 22 ++----------------- .../java/org/xbmc/kore/utils/UIUtils.java | 16 ++++++++++++++ 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/org/xbmc/kore/utils/RepeatListener.java b/app/src/main/java/org/xbmc/kore/utils/RepeatListener.java index a136042..7d2f182 100644 --- a/app/src/main/java/org/xbmc/kore/utils/RepeatListener.java +++ b/app/src/main/java/org/xbmc/kore/utils/RepeatListener.java @@ -67,7 +67,6 @@ public class RepeatListener implements View.OnTouchListener { private View downView; private Context context; - private Vibrator vibrator; /** * Constructor for a repeat listener @@ -104,10 +103,7 @@ public class RepeatListener implements View.OnTouchListener { this.animDown = animDown; this.animUp = animUp; - if (context != null) { - this.context = context; - this.vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); - } + this.context = context; } /** @@ -122,7 +118,7 @@ public class RepeatListener implements View.OnTouchListener { public boolean onTouch(View view, MotionEvent motionEvent) { switch (motionEvent.getAction()) { case MotionEvent.ACTION_DOWN: - handleVibration(); + UIUtils.handleVibration(context); repeatHandler.removeCallbacks(handlerRunnable); if (initialInterval >= 0) { repeatHandler.postDelayed(handlerRunnable, initialInterval); @@ -150,18 +146,4 @@ public class RepeatListener implements View.OnTouchListener { // Consume the event for views other than buttons return !((view instanceof Button) || (view instanceof ImageButton)); } - - private void handleVibration() { - if(context != null) { - //Check if we should vibrate - boolean vibrateOnPress = PreferenceManager - .getDefaultSharedPreferences(context) - .getBoolean(Settings.KEY_PREF_VIBRATE_REMOTE_BUTTONS, - Settings.DEFAULT_PREF_VIBRATE_REMOTE_BUTTONS); - if (vibrateOnPress) { - vibrator.vibrate(UIUtils.buttonVibrationDuration); - } - } - } - } \ No newline at end of file diff --git a/app/src/main/java/org/xbmc/kore/utils/UIUtils.java b/app/src/main/java/org/xbmc/kore/utils/UIUtils.java index 34e1987..0df3962 100644 --- a/app/src/main/java/org/xbmc/kore/utils/UIUtils.java +++ b/app/src/main/java/org/xbmc/kore/utils/UIUtils.java @@ -21,6 +21,8 @@ import android.content.Context; import android.content.Intent; import android.content.res.Resources; import android.content.res.TypedArray; +import android.os.Vibrator; +import android.preference.PreferenceManager; import android.text.TextUtils; import android.util.DisplayMetrics; import android.view.LayoutInflater; @@ -395,6 +397,20 @@ public class UIUtils { } } + public static void handleVibration(Context context) { + if(context != null) { + Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); + //Check if we should vibrate + boolean vibrateOnPress = PreferenceManager + .getDefaultSharedPreferences(context) + .getBoolean(Settings.KEY_PREF_VIBRATE_REMOTE_BUTTONS, + Settings.DEFAULT_PREF_VIBRATE_REMOTE_BUTTONS); + if (vibrateOnPress) { + vibrator.vibrate(UIUtils.buttonVibrationDuration); + } + } + } + /** * Launches the remote activity, performing a circular reveal animation if * Lollipop or later From 1bf525d6925b825043c30c454b600d64ba7b4ad5 Mon Sep 17 00:00:00 2001 From: Akshay Zade Date: Thu, 23 Jul 2015 21:20:09 +0530 Subject: [PATCH 7/8] Added vibrations to all remote buttons --- .../java/org/xbmc/kore/ui/RemoteFragment.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/org/xbmc/kore/ui/RemoteFragment.java b/app/src/main/java/org/xbmc/kore/ui/RemoteFragment.java index f204ee0..4d929b4 100644 --- a/app/src/main/java/org/xbmc/kore/ui/RemoteFragment.java +++ b/app/src/main/java/org/xbmc/kore/ui/RemoteFragment.java @@ -16,7 +16,6 @@ package org.xbmc.kore.ui; import android.annotation.TargetApi; -import android.content.Context; import android.content.res.ColorStateList; import android.content.res.Resources; import android.content.res.TypedArray; @@ -26,9 +25,7 @@ import android.graphics.PorterDuffColorFilter; import android.graphics.drawable.BitmapDrawable; import android.os.Bundle; import android.os.Handler; -import android.os.Vibrator; import android.support.v4.app.Fragment; -import android.util.Log; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; @@ -143,9 +140,6 @@ public class RemoteFragment extends Fragment // EventServer connection private EventServerConnection eventServerConnection = null; - //Vibrator reference for remote buttons - private Vibrator vibrator; - // Icons for fastForward/Rewind or skipPrevious/skipNext int fastForwardIcon, rewindIcon, skipPreviousIcon, skipNextIcon; @@ -155,8 +149,6 @@ public class RemoteFragment extends Fragment hostManager = HostManager.getInstance(getActivity()); hostConnectionObserver = hostManager.getHostConnectionObserver(); - vibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE); - buttonInAnim = AnimationUtils.loadAnimation(getActivity(), R.anim.button_in); buttonOutAnim = AnimationUtils.loadAnimation(getActivity(), R.anim.button_out); @@ -328,8 +320,7 @@ public class RemoteFragment extends Fragment button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - vibrator.vibrate(UIUtils.buttonVibrationDuration); - Log.e("Vibrator", "Vibrated!"); + UIUtils.handleVibration(getActivity()); clickAction.execute(hostManager.getConnection(), defaultActionCallback, callbackHandler); } }); @@ -338,8 +329,7 @@ public class RemoteFragment extends Fragment button.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { - vibrator.vibrate(UIUtils.buttonVibrationDuration); - Log.e("Vibrator", "Vibrated!"); + UIUtils.handleVibration(getActivity()); longClickAction.execute(hostManager.getConnection(), defaultActionCallback, callbackHandler); return true; } @@ -405,30 +395,35 @@ public class RemoteFragment extends Fragment */ @OnClick(R.id.home) public void onHomeClicked(View v) { + UIUtils.handleVibration(getActivity()); GUI.ActivateWindow action = new GUI.ActivateWindow(GUI.ActivateWindow.HOME); action.execute(hostManager.getConnection(), defaultActionCallback, callbackHandler); } @OnClick(R.id.movies) public void onMoviedClicked(View v) { + UIUtils.handleVibration(getActivity()); GUI.ActivateWindow action = new GUI.ActivateWindow(GUI.ActivateWindow.VIDEOS, GUI.ActivateWindow.PARAM_MOVIE_TITLES); action.execute(hostManager.getConnection(), defaultActionCallback, callbackHandler); } @OnClick(R.id.tv_shows) public void onTvShowsClicked(View v) { + UIUtils.handleVibration(getActivity()); GUI.ActivateWindow action = new GUI.ActivateWindow(GUI.ActivateWindow.VIDEOS, GUI.ActivateWindow.PARAM_TV_SHOWS_TITLES); action.execute(hostManager.getConnection(), defaultActionCallback, callbackHandler); } @OnClick(R.id.music) public void onMusicClicked(View v) { + UIUtils.handleVibration(getActivity()); GUI.ActivateWindow action = new GUI.ActivateWindow(GUI.ActivateWindow.MUSICLIBRARY); action.execute(hostManager.getConnection(), defaultActionCallback, callbackHandler); } @OnClick(R.id.pictures) public void onPicturesClicked(View v) { + UIUtils.handleVibration(getActivity()); GUI.ActivateWindow action = new GUI.ActivateWindow(GUI.ActivateWindow.PICTURES); action.execute(hostManager.getConnection(), defaultActionCallback, callbackHandler); } @@ -438,6 +433,7 @@ public class RemoteFragment extends Fragment */ @OnClick(R.id.fast_forward) public void onFastForwardClicked(View v) { + UIUtils.handleVibration(getActivity()); if (ListType.ItemsAll.TYPE_SONG.equals(currentNowPlayingItemType)) { Player.GoTo action = new Player.GoTo(currentActivePlayerId, Player.GoTo.NEXT); action.execute(hostManager.getConnection(), defaultActionCallback, callbackHandler); @@ -449,6 +445,7 @@ public class RemoteFragment extends Fragment @OnClick(R.id.rewind) public void onRewindClicked(View v) { + UIUtils.handleVibration(getActivity()); if (ListType.ItemsAll.TYPE_SONG.equals(currentNowPlayingItemType)) { Player.GoTo action = new Player.GoTo(currentActivePlayerId, Player.GoTo.PREVIOUS); action.execute(hostManager.getConnection(), defaultActionCallback, callbackHandler); @@ -460,12 +457,14 @@ public class RemoteFragment extends Fragment @OnClick(R.id.play) public void onPlayClicked(View v) { + UIUtils.handleVibration(getActivity()); Player.PlayPause action = new Player.PlayPause(currentActivePlayerId); action.execute(hostManager.getConnection(), defaultPlaySpeedChangedCallback, callbackHandler); } @OnClick(R.id.stop) public void onStopClicked(View v) { + UIUtils.handleVibration(getActivity()); Player.Stop action = new Player.Stop(currentActivePlayerId); action.execute(hostManager.getConnection(), defaultActionCallback, callbackHandler); } From 1268c4450ee4b48768957adabda2676981d75496 Mon Sep 17 00:00:00 2001 From: Akshay Zade Date: Sat, 25 Jul 2015 12:14:14 +0530 Subject: [PATCH 8/8] Removed vibrations from non-D-pad buttons --- app/src/main/java/org/xbmc/kore/ui/RemoteFragment.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/app/src/main/java/org/xbmc/kore/ui/RemoteFragment.java b/app/src/main/java/org/xbmc/kore/ui/RemoteFragment.java index 4d929b4..718d3d4 100644 --- a/app/src/main/java/org/xbmc/kore/ui/RemoteFragment.java +++ b/app/src/main/java/org/xbmc/kore/ui/RemoteFragment.java @@ -395,35 +395,30 @@ public class RemoteFragment extends Fragment */ @OnClick(R.id.home) public void onHomeClicked(View v) { - UIUtils.handleVibration(getActivity()); GUI.ActivateWindow action = new GUI.ActivateWindow(GUI.ActivateWindow.HOME); action.execute(hostManager.getConnection(), defaultActionCallback, callbackHandler); } @OnClick(R.id.movies) public void onMoviedClicked(View v) { - UIUtils.handleVibration(getActivity()); GUI.ActivateWindow action = new GUI.ActivateWindow(GUI.ActivateWindow.VIDEOS, GUI.ActivateWindow.PARAM_MOVIE_TITLES); action.execute(hostManager.getConnection(), defaultActionCallback, callbackHandler); } @OnClick(R.id.tv_shows) public void onTvShowsClicked(View v) { - UIUtils.handleVibration(getActivity()); GUI.ActivateWindow action = new GUI.ActivateWindow(GUI.ActivateWindow.VIDEOS, GUI.ActivateWindow.PARAM_TV_SHOWS_TITLES); action.execute(hostManager.getConnection(), defaultActionCallback, callbackHandler); } @OnClick(R.id.music) public void onMusicClicked(View v) { - UIUtils.handleVibration(getActivity()); GUI.ActivateWindow action = new GUI.ActivateWindow(GUI.ActivateWindow.MUSICLIBRARY); action.execute(hostManager.getConnection(), defaultActionCallback, callbackHandler); } @OnClick(R.id.pictures) public void onPicturesClicked(View v) { - UIUtils.handleVibration(getActivity()); GUI.ActivateWindow action = new GUI.ActivateWindow(GUI.ActivateWindow.PICTURES); action.execute(hostManager.getConnection(), defaultActionCallback, callbackHandler); } @@ -433,7 +428,6 @@ public class RemoteFragment extends Fragment */ @OnClick(R.id.fast_forward) public void onFastForwardClicked(View v) { - UIUtils.handleVibration(getActivity()); if (ListType.ItemsAll.TYPE_SONG.equals(currentNowPlayingItemType)) { Player.GoTo action = new Player.GoTo(currentActivePlayerId, Player.GoTo.NEXT); action.execute(hostManager.getConnection(), defaultActionCallback, callbackHandler); @@ -445,7 +439,6 @@ public class RemoteFragment extends Fragment @OnClick(R.id.rewind) public void onRewindClicked(View v) { - UIUtils.handleVibration(getActivity()); if (ListType.ItemsAll.TYPE_SONG.equals(currentNowPlayingItemType)) { Player.GoTo action = new Player.GoTo(currentActivePlayerId, Player.GoTo.PREVIOUS); action.execute(hostManager.getConnection(), defaultActionCallback, callbackHandler); @@ -457,14 +450,12 @@ public class RemoteFragment extends Fragment @OnClick(R.id.play) public void onPlayClicked(View v) { - UIUtils.handleVibration(getActivity()); Player.PlayPause action = new Player.PlayPause(currentActivePlayerId); action.execute(hostManager.getConnection(), defaultPlaySpeedChangedCallback, callbackHandler); } @OnClick(R.id.stop) public void onStopClicked(View v) { - UIUtils.handleVibration(getActivity()); Player.Stop action = new Player.Stop(currentActivePlayerId); action.execute(hostManager.getConnection(), defaultActionCallback, callbackHandler); }