if (mColorHoldHandler == null) return true; if (!mLongClickPerformed) clickButton(); setBackground(mNormalDrawable); else setBackgroundDrawable(mNormalDrawable); postInvalidate(); break;
public AnimatedHoldButton(Context context, AttributeSet attrs) { super(context, attrs); CLICK_HOLD_TIME = ViewUtils.getLongClickTimeout(context); mPrimaryText = ""; mNormalDrawable = getBackground(); TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.AnimatedHoldButton, 0, 0); try { mPrimaryText = ta.getString(R.styleable.AnimatedHoldButton_primary_text); mPressedColor = ta.getColor(R.styleable.AnimatedHoldButton_pressed_color, ContextCompat.getColor(context, R.color.op_button_pressed)); } finally { ta.recycle(); } //this is needed for so paint knows what to measure in layoutText setText(mPrimaryText); }
/** * Helper method so colors only get initialed once */ private void initializeColors() { if (mGradStartCol == null){ mGradStartCol = mPressedColor; mGradEndCol = ContextCompat.getColor(getContext(), R.color.op_button_long_press_accent); mAccentColor = mPressedColor; mFinalColor = mPressedColor; } } };
@Override public void onExtraLongClick(View view) { int buttonId = view.getId(); if (buttonId == R.id.percent_button){ //TODO add code to pop up dialog to switch buttons //TODO dialog reads "Set primary button function:" //TODO options will be %, E, ^, 1/x, and +/- //simple swap String main = mCalc.mPreferences.getPercentButMain(); String sec = mCalc.mPreferences.getPercentButSec(); mCalc.mPreferences.setPercentButMain(sec); mCalc.mPreferences.setPercentButSec(main); ViewUtils.toastLong("Button changed to " + sec, mAppContext); ahb.setPrimaryText(sec); ahb.setSecondaryText(main); ahb.invalidate(); } } });
.setPrimaryText(mCalc.mPreferences.getPercentButMain()); ((AnimatedHoldButton) button) .setSecondaryText(mCalc.mPreferences.getPercentButSec()); ahb.setOnExtraLongClickListener(new AnimatedHoldButton.OnExtraLongClickListener() { @Override public void onExtraLongClick(View view) {
setBackgroundColor(mFinalColor); longClickButton(); mLongClickPerformed = true; setBackgroundColor(mAccentColor); float deltaBlue = (float) Color.blue(mGradStartCol) + ((float) Color.blue(mGradEndCol) - (float) Color.blue(mGradStartCol)) * ((float) mHoldInc) / ((float) NUM_COLOR_CHANGES); setBackgroundColor(Color.argb(255, (int) deltaRed, (int) deltaGreen, (int) deltaBlue)); mHoldInc++;