Skip to content

Commit

Permalink
add support to suppress vibration
Browse files Browse the repository at this point in the history
  • Loading branch information
rburgstaller committed Jan 8, 2017
1 parent 79036a2 commit 7f71753
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 11 deletions.
34 changes: 28 additions & 6 deletions library/GoogleDateTimePickers/build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
}
}
apply plugin: 'com.android.library'
apply plugin: 'maven'

version = "1.0.1"
group="org.unknown"
archivesBaseName = "googledatetimepickers"

dependencies {
compile fileTree(dir: 'libs', include: '*.jar', exclude: ['android-support-v4.jar', 'nineoldandroids*.jar'])
compile 'com.android.support:support-v4:22.1.1'
// compile fileTree(dir: 'libs', include: '*.jar', exclude: ['android-support-v4.jar', 'nineoldandroids*.jar'])
compile 'com.android.support:support-v4:25.1.0'
}

android {
compileSdkVersion 21
buildToolsVersion "22.0.1"
compileSdkVersion 22
buildToolsVersion '24.0.2'

defaultConfig {
minSdkVersion 9
targetSdkVersion 21
minSdkVersion 14
targetSdkVersion 22
}
sourceSets {
main {
Expand All @@ -27,3 +40,12 @@ android {
instrumentTest.setRoot('tests')
}
}


uploadArchives {
repositories {
mavenDeployer {
repository(url: uri(project.repositoryUrl))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class DatePickerDialog extends DialogFragment implements
private static final String KEY_SELECTED_MONTH = "month";
private static final String KEY_SELECTED_DAY = "day";
private static final String KEY_ENABLE_CLEAR_BUTTON = "enableClear";
private static final String KEY_ALLOW_VIBRATION = "allowVibration";
private static final String KEY_LIST_POSITION = "list_position";
private static final String KEY_WEEK_START = "week_start";
private static final String KEY_YEAR_START = "year_start";
Expand Down Expand Up @@ -117,6 +118,7 @@ public class DatePickerDialog extends DialogFragment implements
private boolean mEnableClearButton;

private Button mClearButton;
private boolean mAllowVibration = true;

/**
* The callback used to indicate the user is done filling in the date.
Expand Down Expand Up @@ -169,6 +171,10 @@ public void initialize(OnDateSetListener callBack, int year, int monthOfYear, in
mEnableClearButton = enableClear;
}

public void setAllowVibration(boolean allowVibration) {
this.mAllowVibration = allowVibration;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -181,6 +187,7 @@ public void onCreate(Bundle savedInstanceState) {
mCalendar.set(Calendar.MONTH, savedInstanceState.getInt(KEY_SELECTED_MONTH));
mCalendar.set(Calendar.DAY_OF_MONTH, savedInstanceState.getInt(KEY_SELECTED_DAY));
mEnableClearButton = savedInstanceState.getBoolean(KEY_ENABLE_CLEAR_BUTTON, false);
mAllowVibration = savedInstanceState.getBoolean(KEY_ALLOW_VIBRATION, true);
}
}

Expand All @@ -195,6 +202,7 @@ public void onSaveInstanceState(Bundle outState) {
outState.putInt(KEY_YEAR_END, mMaxYear);
outState.putInt(KEY_CURRENT_VIEW, mCurrentView);
outState.putBoolean(KEY_ENABLE_CLEAR_BUTTON, mEnableClearButton);
outState.putBoolean(KEY_ALLOW_VIBRATION, mAllowVibration);
int listPosition = -1;
if (mCurrentView == MONTH_AND_DAY_VIEW) {
listPosition = mDayPickerView.getMostVisiblePosition();
Expand Down Expand Up @@ -492,7 +500,7 @@ public void unregisterOnDateChangedListener(OnDateChangedListener listener) {
*/
@Override
public void tryVibrate() {
if (mVibrator != null) {
if (mAllowVibration && mVibrator != null) {
long now = SystemClock.uptimeMillis();
// We want to try to vibrate each individual tick discretely.
if (now - mLastVibrate >= 125) {
Expand All @@ -501,4 +509,4 @@ public void tryVibrate() {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Parcelable;
import android.os.SystemClock;
import android.os.Vibrator;
import android.text.format.DateUtils;
Expand Down Expand Up @@ -93,6 +94,7 @@ public class RadialPickerLayout extends FrameLayout implements OnTouchListener {

private AnimatorSet mTransition;
private Handler mHandler = new Handler();
private boolean mAllowVibration = true;

public interface OnValueSelectedListener {
void onValueSelected(int pickerIndex, int newValue, boolean autoAdvance);
Expand Down Expand Up @@ -160,6 +162,10 @@ public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
MeasureSpec.makeMeasureSpec(minDimension, heightMode));
}

public void setAllowVibration(boolean mAllowVibration) {
this.mAllowVibration = mAllowVibration;
}

public void setOnValueSelectedListener(OnValueSelectedListener listener) {
mListener = listener;
}
Expand Down Expand Up @@ -727,7 +733,7 @@ public void run() {
* happen if we have vibrated very recently.
*/
public void tryVibrate() {
if (mVibrator != null) {
if (mAllowVibration && mVibrator != null) {
long now = SystemClock.uptimeMillis();
// We want to try to vibrate each individual tick discretely.
if (now - mLastVibrate >= 125) {
Expand Down Expand Up @@ -842,4 +848,4 @@ public boolean performAccessibilityAction(int action, Bundle arguments) {

return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class TimePickerDialog extends DialogFragment implements OnValueSelectedL
private static final String KEY_IN_KB_MODE = "in_kb_mode";
private static final String KEY_TYPED_TIMES = "typed_times";
private static final String KEY_ENABLE_CLEAR_BUTTON = "enableClearButton";
private static final String KEY_ALLOW_VIBRATION = "allowVibration";

public static final int HOUR_INDEX = 0;
public static final int MINUTE_INDEX = 1;
Expand Down Expand Up @@ -105,6 +106,7 @@ public class TimePickerDialog extends DialogFragment implements OnValueSelectedL
private String mSelectHours;
private String mMinutePickerDescription;
private String mSelectMinutes;
private boolean mAllowVibration = true;

private boolean mEnableClearButton;

Expand Down Expand Up @@ -150,6 +152,13 @@ public void initialize(OnTimeSetListener callback,
mEnableClearButton = enableClearButton;
}

public void setAllowVibration(boolean allowVibration) {
this.mAllowVibration = allowVibration;
if (mTimePicker != null) {
mTimePicker.setAllowVibration(allowVibration);
}
}

public void setOnTimeSetListener(OnTimeSetListener callback) {
mCallback = callback;
}
Expand All @@ -171,6 +180,7 @@ public void onCreate(Bundle savedInstanceState) {
mIs24HourMode = savedInstanceState.getBoolean(KEY_IS_24_HOUR_VIEW);
mInKbMode = savedInstanceState.getBoolean(KEY_IN_KB_MODE);
mEnableClearButton = savedInstanceState.getBoolean(KEY_ENABLE_CLEAR_BUTTON, false);
mAllowVibration = savedInstanceState.getBoolean(KEY_ALLOW_VIBRATION, true);
}
}

Expand Down Expand Up @@ -205,6 +215,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
mPmText = amPmTexts[1];

mTimePicker = (RadialPickerLayout) view.findViewById(R.id.time_picker);
mTimePicker.setAllowVibration(mAllowVibration);
mTimePicker.setOnValueSelectedListener(this);
mTimePicker.setOnKeyListener(keyboardListener);
mTimePicker.initialize(getActivity(), mInitialHourOfDay, mInitialMinute, mIs24HourMode);
Expand Down Expand Up @@ -328,6 +339,7 @@ public void onSaveInstanceState(Bundle outState) {
outState.putInt(KEY_CURRENT_ITEM_SHOWING, mTimePicker.getCurrentItemShowing());
outState.putBoolean(KEY_IN_KB_MODE, mInKbMode);
outState.putBoolean(KEY_ENABLE_CLEAR_BUTTON, mEnableClearButton);
outState.putBoolean(KEY_ALLOW_VIBRATION, mAllowVibration);
if (mInKbMode) {
outState.putIntegerArrayList(KEY_TYPED_TIMES, mTypedTimes);
}
Expand Down Expand Up @@ -927,4 +939,4 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
return false;
}
}
}
}

0 comments on commit 7f71753

Please sign in to comment.