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;
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.widget.SwitchCompat;
import android.view.ContextMenu;
import android.view.MenuItem;
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.XmppAxolotlSession;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.ui.widget.Switch;
import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.utils.XmppUri;
import eu.siacs.conversations.utils.zxing.IntentIntegrator;
@ -117,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,
@ -134,20 +128,14 @@ public abstract class OmemoActivity extends XmppActivity {
CompoundButton.OnCheckedChangeListener
onCheckedChangeListener) {
View view = getLayoutInflater().inflate(R.layout.contact_key, keys, false);
TextView key = (TextView) view.findViewById(R.id.key);
TextView keyType = (TextView) view.findViewById(R.id.key_type);
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 = (Switch) view.findViewById(R.id.tgl_trust);
ImageView verifiedFingerprintSymbol = (ImageView) view.findViewById(R.id.verified_fingerprint);
SwitchCompat trustToggle = view.findViewById(R.id.tgl_trust);
ImageView verifiedFingerprintSymbol = view.findViewById(R.id.verified_fingerprint);
trustToggle.setVisibility(View.VISIBLE);
registerForContextMenu(view);
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);
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 +152,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 +215,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();
}

View File

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

View File

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

View File

@ -4,18 +4,4 @@
<item name="android:layout_height">1.5dp</item>
<item name="android:background">@color/black12</item>
</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>