Merge pull request #100 from akshay2000/master
Added Vibration on Remote Arrow Press
This commit is contained in:
commit
4a88eadd50
|
@ -6,7 +6,8 @@
|
|||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.VIBRATE"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -134,8 +134,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;
|
||||
|
@ -154,7 +154,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()) {
|
||||
|
@ -308,18 +308,19 @@ public class RemoteFragment extends Fragment
|
|||
public void onClick(View v) {
|
||||
action.execute(hostManager.getConnection(), defaultActionCallback, callbackHandler);
|
||||
}
|
||||
}, buttonInAnim, buttonOutAnim));
|
||||
}, buttonInAnim, buttonOutAnim, getActivity().getApplicationContext()));
|
||||
}
|
||||
|
||||
private void setupDefaultButton(View button,
|
||||
final ApiMethod<String> clickAction,
|
||||
final ApiMethod<String> longClickAction) {
|
||||
// Set animation
|
||||
button.setOnTouchListener(feedbackTouckListener);
|
||||
button.setOnTouchListener(feedbackTouchListener);
|
||||
if (clickAction != null) {
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
UIUtils.handleVibration(getActivity());
|
||||
clickAction.execute(hostManager.getConnection(), defaultActionCallback, callbackHandler);
|
||||
}
|
||||
});
|
||||
|
@ -328,6 +329,7 @@ public class RemoteFragment extends Fragment
|
|||
button.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
UIUtils.handleVibration(getActivity());
|
||||
longClickAction.execute(hostManager.getConnection(), defaultActionCallback, callbackHandler);
|
||||
return true;
|
||||
}
|
||||
|
@ -344,7 +346,7 @@ public class RemoteFragment extends Fragment
|
|||
public void onClick(View v) {
|
||||
eventServerConnection.sendPacket(packet);
|
||||
}
|
||||
}, buttonInAnim, buttonOutAnim));
|
||||
}, buttonInAnim, buttonOutAnim, getActivity().getApplicationContext()));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -15,7 +15,10 @@
|
|||
*/
|
||||
package org.xbmc.kore.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Vibrator;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.SoundEffectConstants;
|
||||
import android.view.View;
|
||||
|
@ -23,6 +26,8 @@ import android.view.animation.Animation;
|
|||
import android.widget.Button;
|
||||
import android.widget.ImageButton;
|
||||
|
||||
import org.xbmc.kore.Settings;
|
||||
|
||||
/**
|
||||
* A class, that can be used as a TouchListener on any view (e.g. a Button).
|
||||
* It cyclically runs a clickListener, emulating keyboard-like behaviour. First
|
||||
|
@ -61,6 +66,8 @@ public class RepeatListener implements View.OnTouchListener {
|
|||
|
||||
private View downView;
|
||||
|
||||
private Context context;
|
||||
|
||||
/**
|
||||
* Constructor for a repeat listener
|
||||
*
|
||||
|
@ -69,26 +76,34 @@ public class RepeatListener implements View.OnTouchListener {
|
|||
* @param clickListener The OnClickListener, that will be called periodically
|
||||
*/
|
||||
public RepeatListener(int initialInterval, int repeatInterval, View.OnClickListener clickListener) {
|
||||
this(initialInterval, repeatInterval, clickListener, null, null);
|
||||
this(initialInterval, repeatInterval, clickListener, null, null, null);
|
||||
}
|
||||
|
||||
public RepeatListener(int initialInterval, int repeatInterval, View.OnClickListener clickListener,
|
||||
Animation animDown, Animation animUp) {
|
||||
this(initialInterval, repeatInterval, clickListener, animUp, animDown, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for a repeat listener, with animation
|
||||
* Constructor for a repeat listener, with animation and vibration
|
||||
*
|
||||
* @param initialInterval The interval after first click event. If negative, no repeat will occur
|
||||
* @param repeatInterval The interval after second and subsequent click events. If negative, no repeat will occur
|
||||
* @param clickListener The OnClickListener, that will be called periodically
|
||||
* @param animDown Animation to play on touch
|
||||
* @param animUp Animation to play on release
|
||||
* @param context Context used to access preferences and services
|
||||
*/
|
||||
public RepeatListener(int initialInterval, int repeatInterval, View.OnClickListener clickListener,
|
||||
Animation animDown, Animation animUp) {
|
||||
Animation animDown, Animation animUp, Context context) {
|
||||
this.initialInterval = initialInterval;
|
||||
this.repeatInterval = repeatInterval;
|
||||
this.clickListener = clickListener;
|
||||
|
||||
this.animDown = animDown;
|
||||
this.animUp = animUp;
|
||||
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -103,6 +118,7 @@ public class RepeatListener implements View.OnTouchListener {
|
|||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||||
switch (motionEvent.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
UIUtils.handleVibration(context);
|
||||
repeatHandler.removeCallbacks(handlerRunnable);
|
||||
if (initialInterval >= 0) {
|
||||
repeatHandler.postDelayed(handlerRunnable, initialInterval);
|
||||
|
@ -130,5 +146,4 @@ public class RepeatListener implements View.OnTouchListener {
|
|||
// Consume the event for views other than buttons
|
||||
return !((view instanceof Button) || (view instanceof ImageButton));
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
@ -52,6 +54,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
|
||||
|
@ -455,6 +458,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
|
||||
|
|
|
@ -304,6 +304,7 @@
|
|||
<string name="switch_to_remote">Switch to remote after media start</string>
|
||||
<string name="show_notification">Show notification while playing</string>
|
||||
<string name="use_hardware_volume_keys">Use volume keys to control volume</string>
|
||||
<string name="vibrate_on_remote">Vibrate on remote button press</string>
|
||||
|
||||
<string name="about">About</string>
|
||||
<string name="about_desc"><![CDATA[
|
||||
|
|
|
@ -39,6 +39,11 @@
|
|||
android:title="@string/use_hardware_volume_keys"
|
||||
android:defaultValue="true"/>
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="pref_vibrate_remote_buttons"
|
||||
android:title="@string/vibrate_on_remote"
|
||||
android:defaultValue="false"/>
|
||||
|
||||
<Preference
|
||||
android:key="pref_about"
|
||||
android:title="@string/about"/>
|
||||
|
|
Loading…
Reference in New Issue