diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-03-14 20:41:49 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-03-14 20:41:49 +0100 |
commit | dfabf192a0ef3da114c6765a5202affe66076984 (patch) | |
tree | 760ad674edc4cfb88f3974efa29ff9e43466ec7c /src/main/java/de/pixart/messenger | |
parent | 7e0d33197a972c26f57e3c63df42c3f9dc779220 (diff) |
switch to switchcompat
Diffstat (limited to 'src/main/java/de/pixart/messenger')
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/OmemoActivity.java | 66 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/widget/Switch.java | 68 |
2 files changed, 17 insertions, 117 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/OmemoActivity.java b/src/main/java/de/pixart/messenger/ui/OmemoActivity.java index a1a156fb9..e304a64ee 100644 --- a/src/main/java/de/pixart/messenger/ui/OmemoActivity.java +++ b/src/main/java/de/pixart/messenger/ui/OmemoActivity.java @@ -1,11 +1,12 @@ package de.pixart.messenger.ui; -import android.support.v7.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.support.v4.content.ContextCompat; +import android.support.v7.app.AlertDialog; +import android.support.v7.widget.SwitchCompat; import android.view.ContextMenu; import android.view.MenuItem; import android.view.View; @@ -23,7 +24,6 @@ import de.pixart.messenger.R; import de.pixart.messenger.crypto.axolotl.FingerprintStatus; import de.pixart.messenger.crypto.axolotl.XmppAxolotlSession; import de.pixart.messenger.entities.Account; -import de.pixart.messenger.ui.widget.Switch; import de.pixart.messenger.utils.CryptoHelper; import de.pixart.messenger.utils.XmppUri; import de.pixart.messenger.utils.zxing.IntentIntegrator; @@ -116,12 +116,7 @@ public abstract class OmemoActivity extends XmppActivity { session.getTrust(), true, true, - new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - account.getAxolotlService().setFingerprintTrust(fingerprint, FingerprintStatus.createActive(isChecked)); - } - }); + (buttonView, isChecked) -> account.getAxolotlService().setFingerprintTrust(fingerprint, FingerprintStatus.createActive(isChecked))); } protected void addFingerprintRowWithListeners(LinearLayout keys, final Account account, @@ -137,16 +132,10 @@ public abstract class OmemoActivity extends XmppActivity { TextView key = view.findViewById(R.id.key); TextView keyType = view.findViewById(R.id.key_type); if (Config.X509_VERIFICATION && status.getTrust() == FingerprintStatus.Trust.VERIFIED_X509) { - View.OnClickListener listener = new View.OnClickListener() { - @Override - public void onClick(View v) { - showX509Certificate(account, fingerprint); - } - }; - key.setOnClickListener(listener); - keyType.setOnClickListener(listener); + key.setOnClickListener(v -> showX509Certificate(account, fingerprint)); + keyType.setOnClickListener(v -> showX509Certificate(account, fingerprint)); } - Switch trustToggle = view.findViewById(R.id.tgl_trust); + SwitchCompat trustToggle = view.findViewById(R.id.tgl_trust); ImageView verifiedFingerprintSymbol = view.findViewById(R.id.verified_fingerprint); trustToggle.setVisibility(View.VISIBLE); registerForContextMenu(view); @@ -155,7 +144,7 @@ public abstract class OmemoActivity extends XmppActivity { view.setTag(R.id.TAG_FINGERPRINT_STATUS, status); boolean x509 = Config.X509_VERIFICATION && status.getTrust() == FingerprintStatus.Trust.VERIFIED_X509; final View.OnClickListener toast; - trustToggle.setChecked(status.isTrusted(), false); + trustToggle.setChecked(status.isTrusted()); if (status.isActive()) { key.setTextColor(getPrimaryTextColor()); @@ -164,47 +153,29 @@ public abstract class OmemoActivity extends XmppActivity { verifiedFingerprintSymbol.setVisibility(View.VISIBLE); verifiedFingerprintSymbol.setAlpha(1.0f); trustToggle.setVisibility(View.GONE); - verifiedFingerprintSymbol.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - replaceToast(getString(R.string.this_device_has_been_verified), false); - } - }); + verifiedFingerprintSymbol.setOnClickListener(v -> replaceToast(getString(R.string.this_device_has_been_verified), false)); toast = null; } else { verifiedFingerprintSymbol.setVisibility(View.GONE); trustToggle.setVisibility(View.VISIBLE); trustToggle.setOnCheckedChangeListener(onCheckedChangeListener); if (status.getTrust() == FingerprintStatus.Trust.UNDECIDED && undecidedNeedEnablement) { - trustToggle.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - account.getAxolotlService().setFingerprintTrust(fingerprint, FingerprintStatus.createActive(false)); - v.setEnabled(true); - v.setOnClickListener(null); - } + trustToggle.setOnClickListener(v -> { + account.getAxolotlService().setFingerprintTrust(fingerprint, FingerprintStatus.createActive(false)); + v.setEnabled(true); + v.setOnClickListener(null); }); trustToggle.setEnabled(false); } else { trustToggle.setOnClickListener(null); trustToggle.setEnabled(true); } - toast = new View.OnClickListener() { - @Override - public void onClick(View v) { - hideToast(); - } - }; + toast = v -> hideToast(); } } else { key.setTextColor(getTertiaryTextColor()); keyType.setTextColor(getTertiaryTextColor()); - toast = new View.OnClickListener() { - @Override - public void onClick(View v) { - replaceToast(getString(R.string.this_device_is_no_longer_in_use), false); - } - }; + toast = v -> replaceToast(getString(R.string.this_device_is_no_longer_in_use), false); if (status.isVerified()) { trustToggle.setVisibility(View.GONE); verifiedFingerprintSymbol.setVisibility(View.VISIBLE); @@ -245,12 +216,9 @@ public abstract class OmemoActivity extends XmppActivity { builder.setMessage(R.string.distrust_omemo_key_text); builder.setNegativeButton(getString(R.string.cancel), null); builder.setPositiveButton(R.string.confirm, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - account.getAxolotlService().distrustFingerprint(fingerprint); - refreshUi(); - } + (dialog, which) -> { + account.getAxolotlService().distrustFingerprint(fingerprint); + refreshUi(); }); builder.create().show(); } diff --git a/src/main/java/de/pixart/messenger/ui/widget/Switch.java b/src/main/java/de/pixart/messenger/ui/widget/Switch.java deleted file mode 100644 index 40d8f4c99..000000000 --- a/src/main/java/de/pixart/messenger/ui/widget/Switch.java +++ /dev/null @@ -1,68 +0,0 @@ -package de.pixart.messenger.ui.widget; - -import android.content.Context; -import android.util.AttributeSet; -import android.view.MotionEvent; -import android.view.ViewConfiguration; - -import com.kyleduo.switchbutton.SwitchButton; - -public class Switch extends SwitchButton { - - private int mTouchSlop; - private int mClickTimeout; - private float mStartX; - private float mStartY; - private OnClickListener mOnClickListener; - - public Switch(Context context) { - super(context); - mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop(); - mClickTimeout = ViewConfiguration.getPressedStateDuration() + ViewConfiguration.getTapTimeout(); - } - - public Switch(Context context, AttributeSet attrs) { - super(context, attrs); - mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop(); - mClickTimeout = ViewConfiguration.getPressedStateDuration() + ViewConfiguration.getTapTimeout(); - } - - public Switch(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop(); - mClickTimeout = ViewConfiguration.getPressedStateDuration() + ViewConfiguration.getTapTimeout(); - } - - @Override - public void setOnClickListener(OnClickListener onClickListener) { - this.mOnClickListener = onClickListener; - } - - @Override - public boolean onTouchEvent(MotionEvent event) { - if (!isEnabled()) { - float deltaX = event.getX() - mStartX; - float deltaY = event.getY() - mStartY; - int action = event.getAction(); - switch (action) { - case MotionEvent.ACTION_DOWN: - mStartX = event.getX(); - mStartY = event.getY(); - break; - case MotionEvent.ACTION_CANCEL: - case MotionEvent.ACTION_UP: - float time = event.getEventTime() - event.getDownTime(); - if (deltaX < mTouchSlop && deltaY < mTouchSlop && time < mClickTimeout) { - if (mOnClickListener != null) { - this.mOnClickListener.onClick(this); - } - } - break; - default: - break; - } - return true; - } - return super.onTouchEvent(event); - } -} |