Added vibrations to remote buttons
This commit is contained in:
parent
4427ca0dbc
commit
a90349ec49
|
@ -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"
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
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;
|
||||
|
@ -25,6 +26,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.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
|
@ -140,6 +142,9 @@ 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;
|
||||
|
||||
|
@ -149,6 +154,8 @@ 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);
|
||||
|
||||
|
@ -308,7 +315,7 @@ 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,
|
||||
|
@ -344,7 +351,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,9 @@ public class RepeatListener implements View.OnTouchListener {
|
|||
|
||||
private View downView;
|
||||
|
||||
private Context context;
|
||||
private Vibrator vibrator;
|
||||
|
||||
/**
|
||||
* Constructor for a repeat listener
|
||||
*
|
||||
|
@ -69,26 +77,37 @@ 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;
|
||||
|
||||
if (context != null) {
|
||||
this.context = context;
|
||||
this.vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -103,6 +122,7 @@ public class RepeatListener implements View.OnTouchListener {
|
|||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||||
switch (motionEvent.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
handleVibration();
|
||||
repeatHandler.removeCallbacks(handlerRunnable);
|
||||
if (initialInterval >= 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue