From a4444026444c75678db1663e01de05df225cd9ed Mon Sep 17 00:00:00 2001 From: steckbrief Date: Fri, 11 Mar 2016 23:44:59 +0100 Subject: Fixes FS#51: Change toggle in Account Management back to standard --- .../conversationsplus/ui/XmppActivity.java | 10 ++-- .../ui/adapter/AccountAdapter.java | 9 +-- .../conversationsplus/ui/widget/Switch.java | 68 ---------------------- 3 files changed, 10 insertions(+), 77 deletions(-) delete mode 100644 src/main/java/de/thedevstack/conversationsplus/ui/widget/Switch.java (limited to 'src/main/java') diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java index cf029ee3..15e9d173 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java @@ -49,6 +49,7 @@ import android.widget.CompoundButton; import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; +import android.widget.Switch; import android.widget.TextView; import android.widget.Toast; @@ -82,7 +83,6 @@ import de.thedevstack.conversationsplus.entities.MucOptions; import de.thedevstack.conversationsplus.entities.Presences; import de.thedevstack.conversationsplus.services.XmppConnectionService; import de.thedevstack.conversationsplus.services.XmppConnectionService.XmppConnectionBinder; -import de.thedevstack.conversationsplus.ui.widget.Switch; import de.thedevstack.conversationsplus.utils.CryptoHelper; import de.thedevstack.conversationsplus.utils.ExceptionHelper; import de.thedevstack.conversationsplus.xmpp.OnKeyStatusUpdated; @@ -743,7 +743,7 @@ public abstract class XmppActivity extends Activity { case UNTRUSTED: case TRUSTED: case TRUSTED_X509: - trustToggle.setChecked(trust.trusted(), false); + trustToggle.setChecked(trust.trusted()); trustToggle.setEnabled(trust != XmppAxolotlSession.Trust.TRUSTED_X509); if (trust == XmppAxolotlSession.Trust.TRUSTED_X509) { trustToggle.setOnClickListener(null); @@ -752,7 +752,7 @@ public abstract class XmppActivity extends Activity { keyType.setTextColor(getSecondaryTextColor()); break; case UNDECIDED: - trustToggle.setChecked(false, false); + trustToggle.setChecked(false); trustToggle.setEnabled(false); key.setTextColor(getPrimaryTextColor()); keyType.setTextColor(getSecondaryTextColor()); @@ -760,7 +760,7 @@ public abstract class XmppActivity extends Activity { case INACTIVE_UNTRUSTED: case INACTIVE_UNDECIDED: trustToggle.setOnClickListener(null); - trustToggle.setChecked(false, false); + trustToggle.setChecked(false); trustToggle.setEnabled(false); key.setTextColor(getTertiaryTextColor()); keyType.setTextColor(getTertiaryTextColor()); @@ -768,7 +768,7 @@ public abstract class XmppActivity extends Activity { case INACTIVE_TRUSTED: case INACTIVE_TRUSTED_X509: trustToggle.setOnClickListener(null); - trustToggle.setChecked(true, false); + trustToggle.setChecked(true); trustToggle.setEnabled(false); key.setTextColor(getTertiaryTextColor()); keyType.setTextColor(getTertiaryTextColor()); diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/AccountAdapter.java b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/AccountAdapter.java index eb0344bc..b6caa019 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/AccountAdapter.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/AccountAdapter.java @@ -7,6 +7,7 @@ import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.CompoundButton; import android.widget.ImageView; +import android.widget.Switch; import android.widget.TextView; import java.util.List; @@ -17,7 +18,6 @@ import de.thedevstack.conversationsplus.entities.Account; import de.thedevstack.conversationsplus.services.AvatarService; import de.thedevstack.conversationsplus.ui.ManageAccountActivity; import de.thedevstack.conversationsplus.ui.XmppActivity; -import de.thedevstack.conversationsplus.ui.widget.Switch; public class AccountAdapter extends ArrayAdapter { @@ -60,12 +60,13 @@ public class AccountAdapter extends ArrayAdapter { } final Switch tglAccountState = (Switch) view.findViewById(R.id.tgl_account_status); final boolean isDisabled = (account.getStatus() == Account.State.DISABLED); - tglAccountState.setChecked(!isDisabled,false); + tglAccountState.setChecked(!isDisabled); tglAccountState.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { - if (b == isDisabled && activity instanceof ManageAccountActivity) { - ((ManageAccountActivity) activity).onClickTglAccountState(account,b); + // Condition compoundButton.isPressed() added because of http://stackoverflow.com/a/28219410 + if (compoundButton.isPressed() && b == isDisabled && activity instanceof ManageAccountActivity) { + ((ManageAccountActivity) activity).onClickTglAccountState(account, b); } } }); diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/widget/Switch.java b/src/main/java/de/thedevstack/conversationsplus/ui/widget/Switch.java deleted file mode 100644 index e5a4f0dc..00000000 --- a/src/main/java/de/thedevstack/conversationsplus/ui/widget/Switch.java +++ /dev/null @@ -1,68 +0,0 @@ -package de.thedevstack.conversationsplus.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); - } -} -- cgit v1.2.3