switch to switchcompat

This commit is contained in:
Daniel Gultsch 2018-02-17 11:18:23 +01:00
parent 54dadfd7cd
commit 1307cfe728
34 changed files with 31 additions and 193 deletions

View File

@ -1,10 +1,10 @@
package eu.siacs.conversations.ui; package eu.siacs.conversations.ui;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v7.widget.SwitchCompat;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -22,7 +22,6 @@ import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.axolotl.FingerprintStatus; import eu.siacs.conversations.crypto.axolotl.FingerprintStatus;
import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession; import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.ui.widget.Switch;
import eu.siacs.conversations.utils.CryptoHelper; import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.utils.XmppUri; import eu.siacs.conversations.utils.XmppUri;
import eu.siacs.conversations.utils.zxing.IntentIntegrator; import eu.siacs.conversations.utils.zxing.IntentIntegrator;
@ -117,12 +116,7 @@ public abstract class OmemoActivity extends XmppActivity {
session.getTrust(), session.getTrust(),
true, true,
true, true,
new CompoundButton.OnCheckedChangeListener() { (buttonView, isChecked) -> account.getAxolotlService().setFingerprintTrust(fingerprint, FingerprintStatus.createActive(isChecked)));
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
account.getAxolotlService().setFingerprintTrust(fingerprint, FingerprintStatus.createActive(isChecked));
}
});
} }
protected void addFingerprintRowWithListeners(LinearLayout keys, final Account account, protected void addFingerprintRowWithListeners(LinearLayout keys, final Account account,
@ -134,20 +128,14 @@ public abstract class OmemoActivity extends XmppActivity {
CompoundButton.OnCheckedChangeListener CompoundButton.OnCheckedChangeListener
onCheckedChangeListener) { onCheckedChangeListener) {
View view = getLayoutInflater().inflate(R.layout.contact_key, keys, false); View view = getLayoutInflater().inflate(R.layout.contact_key, keys, false);
TextView key = (TextView) view.findViewById(R.id.key); TextView key = view.findViewById(R.id.key);
TextView keyType = (TextView) view.findViewById(R.id.key_type); TextView keyType = view.findViewById(R.id.key_type);
if (Config.X509_VERIFICATION && status.getTrust() == FingerprintStatus.Trust.VERIFIED_X509) { if (Config.X509_VERIFICATION && status.getTrust() == FingerprintStatus.Trust.VERIFIED_X509) {
View.OnClickListener listener = new View.OnClickListener() { key.setOnClickListener(v -> showX509Certificate(account,fingerprint));
@Override keyType.setOnClickListener(v -> showX509Certificate(account,fingerprint));
public void onClick(View v) {
showX509Certificate(account,fingerprint);
}
};
key.setOnClickListener(listener);
keyType.setOnClickListener(listener);
} }
Switch trustToggle = (Switch) view.findViewById(R.id.tgl_trust); SwitchCompat trustToggle = view.findViewById(R.id.tgl_trust);
ImageView verifiedFingerprintSymbol = (ImageView) view.findViewById(R.id.verified_fingerprint); ImageView verifiedFingerprintSymbol = view.findViewById(R.id.verified_fingerprint);
trustToggle.setVisibility(View.VISIBLE); trustToggle.setVisibility(View.VISIBLE);
registerForContextMenu(view); registerForContextMenu(view);
view.setTag(R.id.TAG_ACCOUNT,account); view.setTag(R.id.TAG_ACCOUNT,account);
@ -155,7 +143,7 @@ public abstract class OmemoActivity extends XmppActivity {
view.setTag(R.id.TAG_FINGERPRINT_STATUS,status); view.setTag(R.id.TAG_FINGERPRINT_STATUS,status);
boolean x509 = Config.X509_VERIFICATION && status.getTrust() == FingerprintStatus.Trust.VERIFIED_X509; boolean x509 = Config.X509_VERIFICATION && status.getTrust() == FingerprintStatus.Trust.VERIFIED_X509;
final View.OnClickListener toast; final View.OnClickListener toast;
trustToggle.setChecked(status.isTrusted(), false); trustToggle.setChecked(status.isTrusted());
if (status.isActive()){ if (status.isActive()){
key.setTextColor(getPrimaryTextColor()); key.setTextColor(getPrimaryTextColor());
@ -164,47 +152,29 @@ public abstract class OmemoActivity extends XmppActivity {
verifiedFingerprintSymbol.setVisibility(View.VISIBLE); verifiedFingerprintSymbol.setVisibility(View.VISIBLE);
verifiedFingerprintSymbol.setAlpha(1.0f); verifiedFingerprintSymbol.setAlpha(1.0f);
trustToggle.setVisibility(View.GONE); trustToggle.setVisibility(View.GONE);
verifiedFingerprintSymbol.setOnClickListener(new View.OnClickListener() { verifiedFingerprintSymbol.setOnClickListener(v -> replaceToast(getString(R.string.this_device_has_been_verified), false));
@Override
public void onClick(View v) {
replaceToast(getString(R.string.this_device_has_been_verified), false);
}
});
toast = null; toast = null;
} else { } else {
verifiedFingerprintSymbol.setVisibility(View.GONE); verifiedFingerprintSymbol.setVisibility(View.GONE);
trustToggle.setVisibility(View.VISIBLE); trustToggle.setVisibility(View.VISIBLE);
trustToggle.setOnCheckedChangeListener(onCheckedChangeListener); trustToggle.setOnCheckedChangeListener(onCheckedChangeListener);
if (status.getTrust() == FingerprintStatus.Trust.UNDECIDED && undecidedNeedEnablement) { if (status.getTrust() == FingerprintStatus.Trust.UNDECIDED && undecidedNeedEnablement) {
trustToggle.setOnClickListener(new View.OnClickListener() { trustToggle.setOnClickListener(v -> {
@Override account.getAxolotlService().setFingerprintTrust(fingerprint,FingerprintStatus.createActive(false));
public void onClick(View v) { v.setEnabled(true);
account.getAxolotlService().setFingerprintTrust(fingerprint,FingerprintStatus.createActive(false)); v.setOnClickListener(null);
v.setEnabled(true);
v.setOnClickListener(null);
}
}); });
trustToggle.setEnabled(false); trustToggle.setEnabled(false);
} else { } else {
trustToggle.setOnClickListener(null); trustToggle.setOnClickListener(null);
trustToggle.setEnabled(true); trustToggle.setEnabled(true);
} }
toast = new View.OnClickListener() { toast = v -> hideToast();
@Override
public void onClick(View v) {
hideToast();
}
};
} }
} else { } else {
key.setTextColor(getTertiaryTextColor()); key.setTextColor(getTertiaryTextColor());
keyType.setTextColor(getTertiaryTextColor()); keyType.setTextColor(getTertiaryTextColor());
toast = new View.OnClickListener() { toast = v -> replaceToast(getString(R.string.this_device_is_no_longer_in_use), false);
@Override
public void onClick(View v) {
replaceToast(getString(R.string.this_device_is_no_longer_in_use), false);
}
};
if (status.isVerified()) { if (status.isVerified()) {
trustToggle.setVisibility(View.GONE); trustToggle.setVisibility(View.GONE);
verifiedFingerprintSymbol.setVisibility(View.VISIBLE); verifiedFingerprintSymbol.setVisibility(View.VISIBLE);
@ -245,12 +215,9 @@ public abstract class OmemoActivity extends XmppActivity {
builder.setMessage(R.string.distrust_omemo_key_text); builder.setMessage(R.string.distrust_omemo_key_text);
builder.setNegativeButton(getString(R.string.cancel), null); builder.setNegativeButton(getString(R.string.cancel), null);
builder.setPositiveButton(R.string.confirm, builder.setPositiveButton(R.string.confirm,
new DialogInterface.OnClickListener() { (dialog, which) -> {
@Override account.getAxolotlService().distrustFingerprint(fingerprint);
public void onClick(DialogInterface dialog, int which) { refreshUi();
account.getAxolotlService().distrustFingerprint(fingerprint);
refreshUi();
}
}); });
builder.create().show(); builder.create().show();
} }

View File

@ -6,6 +6,7 @@ import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.v7.widget.SwitchCompat;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -23,7 +24,6 @@ import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.ui.ManageAccountActivity; import eu.siacs.conversations.ui.ManageAccountActivity;
import eu.siacs.conversations.ui.XmppActivity; import eu.siacs.conversations.ui.XmppActivity;
import eu.siacs.conversations.ui.widget.Switch;
import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.UIHelper;
public class AccountAdapter extends ArrayAdapter<Account> { public class AccountAdapter extends ArrayAdapter<Account> {
@ -51,14 +51,14 @@ public class AccountAdapter extends ArrayAdapter<Account> {
.getSystemService(Context.LAYOUT_INFLATER_SERVICE); .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.account_row, parent, false); view = inflater.inflate(R.layout.account_row, parent, false);
} }
TextView jid = (TextView) view.findViewById(R.id.account_jid); TextView jid = view.findViewById(R.id.account_jid);
if (Config.DOMAIN_LOCK != null) { if (Config.DOMAIN_LOCK != null) {
jid.setText(account.getJid().getLocalpart()); jid.setText(account.getJid().getLocalpart());
} else { } else {
jid.setText(account.getJid().toBareJid().toString()); jid.setText(account.getJid().toBareJid().toString());
} }
TextView statusView = (TextView) view.findViewById(R.id.account_status); TextView statusView = view.findViewById(R.id.account_status);
ImageView imageView = (ImageView) view.findViewById(R.id.account_image); ImageView imageView = view.findViewById(R.id.account_image);
loadAvatar(account,imageView); loadAvatar(account,imageView);
statusView.setText(getContext().getString(account.getStatus().getReadableId())); statusView.setText(getContext().getString(account.getStatus().getReadableId()));
switch (account.getStatus()) { switch (account.getStatus()) {
@ -73,20 +73,18 @@ public class AccountAdapter extends ArrayAdapter<Account> {
statusView.setTextColor(activity.getWarningTextColor()); statusView.setTextColor(activity.getWarningTextColor());
break; break;
} }
final Switch tglAccountState = (Switch) view.findViewById(R.id.tgl_account_status); final SwitchCompat tglAccountState = view.findViewById(R.id.tgl_account_status);
final boolean isDisabled = (account.getStatus() == Account.State.DISABLED); final boolean isDisabled = (account.getStatus() == Account.State.DISABLED);
tglAccountState.setChecked(!isDisabled,false); tglAccountState.setOnCheckedChangeListener(null);
tglAccountState.setChecked(!isDisabled);
if (this.showStateButton) { if (this.showStateButton) {
tglAccountState.setVisibility(View.VISIBLE); tglAccountState.setVisibility(View.VISIBLE);
} else { } else {
tglAccountState.setVisibility(View.GONE); tglAccountState.setVisibility(View.GONE);
} }
tglAccountState.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { tglAccountState.setOnCheckedChangeListener((compoundButton, b) -> {
@Override if (b == isDisabled && activity instanceof ManageAccountActivity) {
public void onCheckedChanged(CompoundButton compoundButton, boolean b) { ((ManageAccountActivity) activity).onClickTglAccountState(account,b);
if (b == isDisabled && activity instanceof ManageAccountActivity) {
((ManageAccountActivity) activity).onClickTglAccountState(account,b);
}
} }
}); });
return view; return view;

View File

@ -1,68 +0,0 @@
package eu.siacs.conversations.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);
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

View File

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false"><shape android:shape="rectangle">
<solid android:color="#D5D5D5" />
<corners android:radius="99dp" />
</shape></item>
<item android:state_enabled="true"><shape android:shape="rectangle">
<solid android:color="#939393" />
<corners android:radius="99dp" />
</shape></item>
</selector>

View File

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false">
<shape android:shape="rectangle">
<solid android:color="#D5D5D5"/>
<corners android:radius="99dp"/>
</shape>
</item>
<item android:state_enabled="true">
<shape android:shape="rectangle">
<!-- 30% accent on white -->
<solid android:color="#b3ddf7"/>
<corners android:radius="99dp"/>
</shape>
</item>
</selector>

View File

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/switch_thumb_disable" android:state_enabled="false"/>
<item android:drawable="@drawable/switch_thumb_on_pressed" android:state_checked="true" android:state_pressed="true"/>
<item android:drawable="@drawable/switch_thumb_on_pressed" android:state_checked="true" android:state_focused="true"/>
<item android:drawable="@drawable/switch_thumb_on_normal" android:state_checked="true"/>
<item android:drawable="@drawable/switch_thumb_off_pressed" android:state_checked="false" android:state_pressed="true"/>
<item android:drawable="@drawable/switch_thumb_off_pressed" android:state_checked="false" android:state_focused="true"/>
<item android:drawable="@drawable/switch_thumb_off_normal" android:state_checked="false"/>
</selector>

View File

@ -46,8 +46,7 @@
android:textStyle="bold" /> android:textStyle="bold" />
</LinearLayout> </LinearLayout>
<eu.siacs.conversations.ui.widget.Switch <android.support.v7.widget.SwitchCompat
style="@style/MD"
android:id="@+id/tgl_account_status" android:id="@+id/tgl_account_status"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@ -77,9 +77,8 @@
android:layout_marginRight="16dp" android:layout_marginRight="16dp"
android:src="@drawable/ic_verified_fingerprint" /> android:src="@drawable/ic_verified_fingerprint" />
<eu.siacs.conversations.ui.widget.Switch <android.support.v7.widget.SwitchCompat
android:id="@+id/tgl_trust" android:id="@+id/tgl_trust"
style="@style/MD"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:visibility="gone" /> android:visibility="gone" />

View File

@ -4,18 +4,4 @@
<item name="android:layout_height">1.5dp</item> <item name="android:layout_height">1.5dp</item>
<item name="android:background">@color/black12</item> <item name="android:background">@color/black12</item>
</style> </style>
<style name="MD">
<item name="animationVelocity">6</item>
<item name="insetBottom">16dp</item>
<item name="insetTop">16dp</item>
<item name="insetLeft">16dp</item>
<item name="insetRight">16dp</item>
<item name="measureFactor">1.4</item>
<item name="offDrawable">@drawable/switch_back_off</item>
<item name="onDrawable">@drawable/switch_back_on</item>
<item name="thumbDrawable">@drawable/switch_thumb</item>
<item name="thumb_margin">-17dp</item>
<item name="android:padding">16dp</item>
</style>
</resources> </resources>