use of com.codetroopers.betterpickers.HapticFeedbackController in project android-betterpickers by code-troopers.
the class CalendarDatePickerDialogFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Log.d(TAG, "onCreateView: ");
if (getShowsDialog()) {
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
}
View view = inflater.inflate(R.layout.calendar_date_picker_dialog, container, false);
mSelectedDateLayout = (LinearLayout) view.findViewById(R.id.day_picker_selected_date_layout);
mDayOfWeekView = (TextView) view.findViewById(R.id.date_picker_header);
mMonthAndDayView = (LinearLayout) view.findViewById(R.id.date_picker_month_and_day);
mMonthAndDayView.setOnClickListener(this);
mSelectedMonthTextView = (TextView) view.findViewById(R.id.date_picker_month);
mSelectedDayTextView = (TextView) view.findViewById(R.id.date_picker_day);
mYearView = (TextView) view.findViewById(R.id.date_picker_year);
mYearView.setOnClickListener(this);
int listPosition = -1;
int listPositionOffset = 0;
int currentView = MONTH_AND_DAY_VIEW;
if (savedInstanceState != null) {
mWeekStart = savedInstanceState.getInt(KEY_WEEK_START);
mMinDate = new CalendarDay(savedInstanceState.getLong(KEY_DATE_START));
mMaxDate = new CalendarDay(savedInstanceState.getLong(KEY_DATE_END));
currentView = savedInstanceState.getInt(KEY_CURRENT_VIEW);
listPosition = savedInstanceState.getInt(KEY_LIST_POSITION);
listPositionOffset = savedInstanceState.getInt(KEY_LIST_POSITION_OFFSET);
mStyleResId = savedInstanceState.getInt(KEY_THEME);
mDisabledDays = savedInstanceState.getSparseParcelableArray(KEY_DISABLED_DAYS);
}
final Activity activity = getActivity();
mDayPickerView = new SimpleDayPickerView(activity, this);
mYearPickerView = new YearPickerView(activity, this);
Resources res = getResources();
TypedArray themeColors = getActivity().obtainStyledAttributes(mStyleResId, R.styleable.BetterPickersDialogs);
mDayPickerDescription = res.getString(R.string.day_picker_description);
mSelectDay = res.getString(R.string.select_day);
mYearPickerDescription = res.getString(R.string.year_picker_description);
mSelectYear = res.getString(R.string.select_year);
int headerBackgroundColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpHeaderBackgroundColor, ContextCompat.getColor(getActivity(), R.color.bpWhite));
int preHeaderBackgroundColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpPreHeaderBackgroundColor, ContextCompat.getColor(getActivity(), R.color.bpWhite));
int bodyBgColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpBodyBackgroundColor, ContextCompat.getColor(getActivity(), R.color.bpWhite));
int buttonBgColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpButtonsBackgroundColor, ContextCompat.getColor(getActivity(), R.color.bpWhite));
int buttonTextColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpButtonsTextColor, ContextCompat.getColor(getActivity(), R.color.bpBlue));
mSelectedColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpHeaderSelectedTextColor, ContextCompat.getColor(getActivity(), R.color.bpWhite));
mUnselectedColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpHeaderUnselectedTextColor, ContextCompat.getColor(getActivity(), R.color.radial_gray_light));
mAnimator = (AccessibleDateAnimator) view.findViewById(R.id.animator);
mAnimator.addView(mDayPickerView);
mAnimator.addView(mYearPickerView);
mAnimator.setDateMillis(mCalendar.getTimeInMillis());
// TODO: Replace with animation decided upon by the design team.
Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(ANIMATION_DURATION);
mAnimator.setInAnimation(animation);
// TODO: Replace with animation decided upon by the design team.
Animation animation2 = new AlphaAnimation(1.0f, 0.0f);
animation2.setDuration(ANIMATION_DURATION);
mAnimator.setOutAnimation(animation2);
Button doneButton = (Button) view.findViewById(R.id.done_button);
if (mDoneText != null) {
doneButton.setText(mDoneText);
}
doneButton.setTextColor(buttonTextColor);
doneButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
tryVibrate();
if (mCallBack != null) {
mCallBack.onDateSet(CalendarDatePickerDialogFragment.this, mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH));
}
dismiss();
}
});
Button cancelButton = (Button) view.findViewById(R.id.cancel_button);
if (mCancelText != null) {
cancelButton.setText(mCancelText);
}
cancelButton.setTextColor(buttonTextColor);
cancelButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
tryVibrate();
dismiss();
}
});
view.findViewById(R.id.ok_cancel_buttons_layout).setBackgroundColor(buttonBgColor);
updateDisplay(false);
setCurrentView(currentView);
if (listPosition != -1) {
if (currentView == MONTH_AND_DAY_VIEW) {
mDayPickerView.postSetSelection(listPosition);
} else if (currentView == YEAR_VIEW) {
mYearPickerView.postSetSelectionFromTop(listPosition, listPositionOffset);
}
}
mHapticFeedbackController = new HapticFeedbackController(activity);
mDayPickerView.setTheme(themeColors);
mYearPickerView.setTheme(themeColors);
mSelectedDateLayout.setBackgroundColor(headerBackgroundColor);
mYearView.setBackgroundColor(headerBackgroundColor);
mMonthAndDayView.setBackgroundColor(headerBackgroundColor);
if (mDayOfWeekView != null) {
mDayOfWeekView.setBackgroundColor(preHeaderBackgroundColor);
}
view.setBackgroundColor(bodyBgColor);
mYearPickerView.setBackgroundColor(bodyBgColor);
mDayPickerView.setBackgroundColor(bodyBgColor);
return view;
}
use of com.codetroopers.betterpickers.HapticFeedbackController in project android-betterpickers by code-troopers.
the class RadialTimePickerDialogFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (getShowsDialog()) {
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
}
View view = inflater.inflate(R.layout.radial_time_picker_dialog, container, false);
KeyboardListener keyboardListener = new KeyboardListener();
view.findViewById(R.id.time_picker_dialog).setOnKeyListener(keyboardListener);
Resources res = getResources();
TypedArray themeColors = getActivity().obtainStyledAttributes(mStyleResId, R.styleable.BetterPickersDialogs);
// Prepare some colors to use.
int headerBgColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpHeaderBackgroundColor, ContextCompat.getColor(getActivity(), R.color.bpBlue));
int bodyBgColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpBodyBackgroundColor, ContextCompat.getColor(getActivity(), R.color.bpWhite));
int buttonBgColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpButtonsBackgroundColor, ContextCompat.getColor(getActivity(), R.color.bpWhite));
int buttonTextColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpButtonsTextColor, ContextCompat.getColor(getActivity(), R.color.bpBlue));
mSelectedColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpHeaderSelectedTextColor, ContextCompat.getColor(getActivity(), R.color.bpWhite));
mUnselectedColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpHeaderUnselectedTextColor, ContextCompat.getColor(getActivity(), R.color.radial_gray_light));
mHourPickerDescription = res.getString(R.string.hour_picker_description);
mSelectHours = res.getString(R.string.select_hours);
mMinutePickerDescription = res.getString(R.string.minute_picker_description);
mSelectMinutes = res.getString(R.string.select_minutes);
mHourView = (TextView) view.findViewById(R.id.hours);
mHourView.setOnKeyListener(keyboardListener);
mHourSpaceView = (TextView) view.findViewById(R.id.hour_space);
mMinuteSpaceView = (TextView) view.findViewById(R.id.minutes_space);
mMinuteView = (TextView) view.findViewById(R.id.minutes);
mMinuteView.setOnKeyListener(keyboardListener);
mAmPmTextView = (TextView) view.findViewById(R.id.ampm_label);
mAmPmTextView.setOnKeyListener(keyboardListener);
String[] amPmTexts = new DateFormatSymbols().getAmPmStrings();
mAmText = amPmTexts[0];
mPmText = amPmTexts[1];
mHapticFeedbackController = new HapticFeedbackController(getActivity());
mTimePicker = (RadialPickerLayout) view.findViewById(R.id.time_picker);
mTimePicker.setOnValueSelectedListener(this);
mTimePicker.setOnKeyListener(keyboardListener);
mTimePicker.initialize(getActivity(), mHapticFeedbackController, mInitialHourOfDay, mInitialMinute, mIs24HourMode);
int currentItemShowing = HOUR_INDEX;
if (savedInstanceState != null && savedInstanceState.containsKey(KEY_CURRENT_ITEM_SHOWING)) {
currentItemShowing = savedInstanceState.getInt(KEY_CURRENT_ITEM_SHOWING);
}
setCurrentItemShowing(currentItemShowing, false, true, true);
mTimePicker.invalidate();
mHourView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
setCurrentItemShowing(HOUR_INDEX, true, false, true);
tryVibrate();
}
});
mMinuteView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
setCurrentItemShowing(MINUTE_INDEX, true, false, true);
tryVibrate();
}
});
mTitleTextView = (TextView) view.findViewById(R.id.time_picker_header);
if (mTitleText != null) {
mTitleTextView.setVisibility(View.VISIBLE);
mTitleTextView.setText(mTitleText);
} else {
mTitleTextView.setVisibility(View.GONE);
}
mError = (NumberPickerErrorTextView) view.findViewById(R.id.error);
if (hasTimeLimits()) {
mError.setVisibility(View.INVISIBLE);
} else {
mError.setVisibility(View.GONE);
}
mDoneButton = (Button) view.findViewById(R.id.done_button);
if (mDoneText != null) {
mDoneButton.setText(mDoneText);
}
mDoneButton.setTextColor(buttonTextColor);
mDoneButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mInKbMode && isTypedTimeFullyLegal()) {
finishKbMode(false);
} else {
tryVibrate();
}
doneClickValidateAndCallback();
}
});
mDoneButton.setOnKeyListener(keyboardListener);
Button cancelButton = (Button) view.findViewById(R.id.cancel_button);
if (mCancelText != null) {
cancelButton.setText(mCancelText);
}
cancelButton.setTextColor(buttonTextColor);
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tryVibrate();
dismiss();
}
});
// Enable or disable the AM/PM view.
mAmPmHitspace = view.findViewById(R.id.ampm_hitspace);
if (mIs24HourMode) {
mAmPmTextView.setVisibility(View.GONE);
RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
paramsSeparator.addRule(RelativeLayout.CENTER_IN_PARENT);
TextView separatorView = (TextView) view.findViewById(R.id.separator);
separatorView.setLayoutParams(paramsSeparator);
} else {
mAmPmTextView.setVisibility(View.VISIBLE);
updateAmPmDisplay(mInitialHourOfDay < 12 ? AM : PM);
mAmPmHitspace.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
tryVibrate();
int amOrPm = mTimePicker.getIsCurrentlyAmOrPm();
if (amOrPm == AM) {
amOrPm = PM;
} else if (amOrPm == PM) {
amOrPm = AM;
}
updateAmPmDisplay(amOrPm);
mTimePicker.setAmOrPm(amOrPm);
}
});
}
mAllowAutoAdvance = true;
setHour(mInitialHourOfDay, true);
setMinute(mInitialMinute);
// Set up for keyboard mode.
mDoublePlaceholderText = res.getString(R.string.time_placeholder);
mDeletedKeyFormat = res.getString(R.string.deleted_key);
mPlaceholderText = mDoublePlaceholderText.charAt(0);
mAmKeyCode = mPmKeyCode = -1;
generateLegalTimesTree();
if (mInKbMode) {
mTypedTimes = savedInstanceState.getIntegerArrayList(KEY_TYPED_TIMES);
tryStartingKbMode(-1);
mHourView.invalidate();
} else if (mTypedTimes == null) {
mTypedTimes = new ArrayList<Integer>();
}
// Set the theme at the end so that the initialize()s above don't counteract the theme.
mTimePicker.setTheme(themeColors);
// Set the colors for each view based on the theme.
view.findViewById(R.id.time_display_background).setBackgroundColor(headerBgColor);
view.findViewById(R.id.ok_cancel_buttons_layout).setBackgroundColor(buttonBgColor);
view.findViewById(R.id.time_display).setBackgroundColor(headerBgColor);
view.findViewById(R.id.time_picker_error_holder).setBackgroundColor(headerBgColor);
((TextView) view.findViewById(R.id.separator)).setTextColor(mUnselectedColor);
((TextView) view.findViewById(R.id.ampm_label)).setTextColor(mUnselectedColor);
mTimePicker.setBackgroundColor(bodyBgColor);
return view;
}
Aggregations