public void readData() { mNotifyRunBackgroundSwitch.setChecked( PreferenceUtils.getPrefBoolean(getActivity(), PreferenceConstants.FOREGROUND, true)); mNewMsgSoundSwitch.setChecked( PreferenceUtils.getPrefBoolean(getActivity(), PreferenceConstants.SCLIENTNOTIFY, false)); mNewMsgVibratorSwitch.setChecked( PreferenceUtils.getPrefBoolean(getActivity(), PreferenceConstants.VIBRATIONNOTIFY, true)); mVisiableNewMsgSwitch.setChecked( PreferenceUtils.getPrefBoolean(getActivity(), PreferenceConstants.TICKER, true)); }
@Override protected void onRestoreInstanceState(Parcelable state) { SavedState ss = (SavedState) state; super.onRestoreInstanceState(ss.getSuperState()); setChecked(ss.checked); requestLayout(); }
@Override public boolean onTouchEvent(@NonNull MotionEvent event) { super.onTouchEvent(event); getRippleManager().onTouchEvent(this, event); float x = event.getX(); if (mIsRtl) x = 2 * mDrawRect.centerX() - x; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: if (getParent() != null) getParent().requestDisallowInterceptTouchEvent(true); mMemoX = x; mStartX = mMemoX; mStartTime = SystemClock.uptimeMillis(); break; case MotionEvent.ACTION_MOVE: float offset = (x - mMemoX) / (mDrawRect.width() - mThumbRadius * 2); mThumbPosition = Math.min(1f, Math.max(0f, mThumbPosition + offset)); mMemoX = x; invalidate(); break; case MotionEvent.ACTION_UP: if (getParent() != null) getParent().requestDisallowInterceptTouchEvent(false); float velocity = (x - mStartX) / (SystemClock.uptimeMillis() - mStartTime) * 1000; if (Math.abs(velocity) >= mFlingVelocity) setChecked(velocity > 0); else if ((!mChecked && mThumbPosition < 0.1f) || (mChecked && mThumbPosition > 0.9f)) toggle(); else setChecked(mThumbPosition > 0.5f); break; case MotionEvent.ACTION_CANCEL: if (getParent() != null) getParent().requestDisallowInterceptTouchEvent(false); setChecked(mThumbPosition > 0.5f); break; } return true; }
@Override public void toggle() { if (isEnabled()) setChecked(!mChecked); }