diff --git a/art/md_switch_thumb_disable.svg b/art/md_switch_thumb_disable.svg
new file mode 100644
index 000000000..efd83c2d0
--- /dev/null
+++ b/art/md_switch_thumb_disable.svg
@@ -0,0 +1,156 @@
+
+
+
+
diff --git a/art/md_switch_thumb_off_normal.svg b/art/md_switch_thumb_off_normal.svg
new file mode 100644
index 000000000..25d1761db
--- /dev/null
+++ b/art/md_switch_thumb_off_normal.svg
@@ -0,0 +1,153 @@
+
+
+
+
diff --git a/art/md_switch_thumb_off_pressed.svg b/art/md_switch_thumb_off_pressed.svg
new file mode 100644
index 000000000..002b47815
--- /dev/null
+++ b/art/md_switch_thumb_off_pressed.svg
@@ -0,0 +1,159 @@
+
+
+
+
diff --git a/art/md_switch_thumb_on_normal.svg b/art/md_switch_thumb_on_normal.svg
new file mode 100644
index 000000000..5e8f90f39
--- /dev/null
+++ b/art/md_switch_thumb_on_normal.svg
@@ -0,0 +1,146 @@
+
+
+
+
diff --git a/art/md_switch_thumb_on_pressed.svg b/art/md_switch_thumb_on_pressed.svg
new file mode 100644
index 000000000..e0331e7b7
--- /dev/null
+++ b/art/md_switch_thumb_on_pressed.svg
@@ -0,0 +1,162 @@
+
+
+
+
diff --git a/art/render.rb b/art/render.rb
index 698abea5b..312dd06b1 100755
--- a/art/render.rb
+++ b/art/render.rb
@@ -33,7 +33,12 @@ images = {
'ic_send_picture_online.svg' => ['ic_send_picture_online', 36],
'ic_send_picture_offline.svg' => ['ic_send_picture_offline', 36],
'ic_send_picture_away.svg' => ['ic_send_picture_away', 36],
- 'ic_send_picture_dnd.svg' => ['ic_send_picture_dnd', 36]
+ 'ic_send_picture_dnd.svg' => ['ic_send_picture_dnd', 36],
+ 'md_switch_thumb_disable.svg' => ['switch_thumb_disable', 48],
+ 'md_switch_thumb_off_normal.svg' => ['switch_thumb_off_normal', 48],
+ 'md_switch_thumb_off_pressed.svg' => ['switch_thumb_off_pressed', 48],
+ 'md_switch_thumb_on_normal.svg' => ['switch_thumb_on_normal', 48],
+ 'md_switch_thumb_on_pressed.svg' => ['switch_thumb_on_pressed', 48],
}
images.each do |source, result|
resolutions.each do |name, factor|
diff --git a/build.gradle b/build.gradle
index 4e23c5224..09ad7161f 100644
--- a/build.gradle
+++ b/build.gradle
@@ -36,6 +36,7 @@ dependencies {
compile 'de.measite.minidns:minidns:0.1.3'
compile 'de.timroes.android:EnhancedListView:0.3.4'
compile 'me.leolin:ShortcutBadger:1.1.1@aar'
+ compile 'com.kyleduo.switchbutton:library:1.2.8'
}
android {
diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/AccountAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/AccountAdapter.java
index 782a1231b..226b1920e 100644
--- a/src/main/java/eu/siacs/conversations/ui/adapter/AccountAdapter.java
+++ b/src/main/java/eu/siacs/conversations/ui/adapter/AccountAdapter.java
@@ -6,6 +6,8 @@ import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.ui.XmppActivity;
import eu.siacs.conversations.ui.ManageAccountActivity;
+import eu.siacs.conversations.ui.widget.Switch;
+
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
@@ -14,7 +16,6 @@ import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;
-import android.widget.Switch;
public class AccountAdapter extends ArrayAdapter {
@@ -53,8 +54,7 @@ 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.setOnCheckedChangeListener(null);
- tglAccountState.setChecked(!isDisabled);
+ tglAccountState.setChecked(!isDisabled,false);
tglAccountState.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
diff --git a/src/main/java/eu/siacs/conversations/ui/widget/Switch.java b/src/main/java/eu/siacs/conversations/ui/widget/Switch.java
new file mode 100644
index 000000000..c72e760ef
--- /dev/null
+++ b/src/main/java/eu/siacs/conversations/ui/widget/Switch.java
@@ -0,0 +1,70 @@
+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;
+
+import eu.siacs.conversations.Config;
+
+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);
+ }
+}
diff --git a/src/main/res/drawable-hdpi/switch_thumb_disable.png b/src/main/res/drawable-hdpi/switch_thumb_disable.png
new file mode 100644
index 000000000..1e9b151b6
Binary files /dev/null and b/src/main/res/drawable-hdpi/switch_thumb_disable.png differ
diff --git a/src/main/res/drawable-hdpi/switch_thumb_off_normal.png b/src/main/res/drawable-hdpi/switch_thumb_off_normal.png
new file mode 100644
index 000000000..b7c1fc11a
Binary files /dev/null and b/src/main/res/drawable-hdpi/switch_thumb_off_normal.png differ
diff --git a/src/main/res/drawable-hdpi/switch_thumb_off_pressed.png b/src/main/res/drawable-hdpi/switch_thumb_off_pressed.png
new file mode 100644
index 000000000..ca6e49096
Binary files /dev/null and b/src/main/res/drawable-hdpi/switch_thumb_off_pressed.png differ
diff --git a/src/main/res/drawable-hdpi/switch_thumb_on_normal.png b/src/main/res/drawable-hdpi/switch_thumb_on_normal.png
new file mode 100644
index 000000000..cbcda5d47
Binary files /dev/null and b/src/main/res/drawable-hdpi/switch_thumb_on_normal.png differ
diff --git a/src/main/res/drawable-hdpi/switch_thumb_on_pressed.png b/src/main/res/drawable-hdpi/switch_thumb_on_pressed.png
new file mode 100644
index 000000000..234b12dc4
Binary files /dev/null and b/src/main/res/drawable-hdpi/switch_thumb_on_pressed.png differ
diff --git a/src/main/res/drawable-mdpi/switch_thumb_disable.png b/src/main/res/drawable-mdpi/switch_thumb_disable.png
new file mode 100644
index 000000000..968de345d
Binary files /dev/null and b/src/main/res/drawable-mdpi/switch_thumb_disable.png differ
diff --git a/src/main/res/drawable-mdpi/switch_thumb_off_normal.png b/src/main/res/drawable-mdpi/switch_thumb_off_normal.png
new file mode 100644
index 000000000..51fb4d7a2
Binary files /dev/null and b/src/main/res/drawable-mdpi/switch_thumb_off_normal.png differ
diff --git a/src/main/res/drawable-mdpi/switch_thumb_off_pressed.png b/src/main/res/drawable-mdpi/switch_thumb_off_pressed.png
new file mode 100644
index 000000000..ca7884453
Binary files /dev/null and b/src/main/res/drawable-mdpi/switch_thumb_off_pressed.png differ
diff --git a/src/main/res/drawable-mdpi/switch_thumb_on_normal.png b/src/main/res/drawable-mdpi/switch_thumb_on_normal.png
new file mode 100644
index 000000000..6a93d5f75
Binary files /dev/null and b/src/main/res/drawable-mdpi/switch_thumb_on_normal.png differ
diff --git a/src/main/res/drawable-mdpi/switch_thumb_on_pressed.png b/src/main/res/drawable-mdpi/switch_thumb_on_pressed.png
new file mode 100644
index 000000000..e8d7bd0f0
Binary files /dev/null and b/src/main/res/drawable-mdpi/switch_thumb_on_pressed.png differ
diff --git a/src/main/res/drawable-xhdpi/switch_thumb_disable.png b/src/main/res/drawable-xhdpi/switch_thumb_disable.png
new file mode 100644
index 000000000..7f6773248
Binary files /dev/null and b/src/main/res/drawable-xhdpi/switch_thumb_disable.png differ
diff --git a/src/main/res/drawable-xhdpi/switch_thumb_off_normal.png b/src/main/res/drawable-xhdpi/switch_thumb_off_normal.png
new file mode 100644
index 000000000..4199d322b
Binary files /dev/null and b/src/main/res/drawable-xhdpi/switch_thumb_off_normal.png differ
diff --git a/src/main/res/drawable-xhdpi/switch_thumb_off_pressed.png b/src/main/res/drawable-xhdpi/switch_thumb_off_pressed.png
new file mode 100644
index 000000000..2b86888f3
Binary files /dev/null and b/src/main/res/drawable-xhdpi/switch_thumb_off_pressed.png differ
diff --git a/src/main/res/drawable-xhdpi/switch_thumb_on_normal.png b/src/main/res/drawable-xhdpi/switch_thumb_on_normal.png
new file mode 100644
index 000000000..daa309900
Binary files /dev/null and b/src/main/res/drawable-xhdpi/switch_thumb_on_normal.png differ
diff --git a/src/main/res/drawable-xhdpi/switch_thumb_on_pressed.png b/src/main/res/drawable-xhdpi/switch_thumb_on_pressed.png
new file mode 100644
index 000000000..6aab47c99
Binary files /dev/null and b/src/main/res/drawable-xhdpi/switch_thumb_on_pressed.png differ
diff --git a/src/main/res/drawable-xxhdpi/switch_thumb_disable.png b/src/main/res/drawable-xxhdpi/switch_thumb_disable.png
new file mode 100644
index 000000000..db7c1df41
Binary files /dev/null and b/src/main/res/drawable-xxhdpi/switch_thumb_disable.png differ
diff --git a/src/main/res/drawable-xxhdpi/switch_thumb_off_normal.png b/src/main/res/drawable-xxhdpi/switch_thumb_off_normal.png
new file mode 100644
index 000000000..f747b5596
Binary files /dev/null and b/src/main/res/drawable-xxhdpi/switch_thumb_off_normal.png differ
diff --git a/src/main/res/drawable-xxhdpi/switch_thumb_off_pressed.png b/src/main/res/drawable-xxhdpi/switch_thumb_off_pressed.png
new file mode 100644
index 000000000..b9fe6d469
Binary files /dev/null and b/src/main/res/drawable-xxhdpi/switch_thumb_off_pressed.png differ
diff --git a/src/main/res/drawable-xxhdpi/switch_thumb_on_normal.png b/src/main/res/drawable-xxhdpi/switch_thumb_on_normal.png
new file mode 100644
index 000000000..881990248
Binary files /dev/null and b/src/main/res/drawable-xxhdpi/switch_thumb_on_normal.png differ
diff --git a/src/main/res/drawable-xxhdpi/switch_thumb_on_pressed.png b/src/main/res/drawable-xxhdpi/switch_thumb_on_pressed.png
new file mode 100644
index 000000000..7a4fed540
Binary files /dev/null and b/src/main/res/drawable-xxhdpi/switch_thumb_on_pressed.png differ
diff --git a/src/main/res/drawable-xxxhdpi/switch_thumb_disable.png b/src/main/res/drawable-xxxhdpi/switch_thumb_disable.png
new file mode 100644
index 000000000..3970168ca
Binary files /dev/null and b/src/main/res/drawable-xxxhdpi/switch_thumb_disable.png differ
diff --git a/src/main/res/drawable-xxxhdpi/switch_thumb_off_normal.png b/src/main/res/drawable-xxxhdpi/switch_thumb_off_normal.png
new file mode 100644
index 000000000..ea8d4f894
Binary files /dev/null and b/src/main/res/drawable-xxxhdpi/switch_thumb_off_normal.png differ
diff --git a/src/main/res/drawable-xxxhdpi/switch_thumb_off_pressed.png b/src/main/res/drawable-xxxhdpi/switch_thumb_off_pressed.png
new file mode 100644
index 000000000..84d667b13
Binary files /dev/null and b/src/main/res/drawable-xxxhdpi/switch_thumb_off_pressed.png differ
diff --git a/src/main/res/drawable-xxxhdpi/switch_thumb_on_normal.png b/src/main/res/drawable-xxxhdpi/switch_thumb_on_normal.png
new file mode 100644
index 000000000..06b190eb9
Binary files /dev/null and b/src/main/res/drawable-xxxhdpi/switch_thumb_on_normal.png differ
diff --git a/src/main/res/drawable-xxxhdpi/switch_thumb_on_pressed.png b/src/main/res/drawable-xxxhdpi/switch_thumb_on_pressed.png
new file mode 100644
index 000000000..79c30d1e5
Binary files /dev/null and b/src/main/res/drawable-xxxhdpi/switch_thumb_on_pressed.png differ
diff --git a/src/main/res/drawable/switch_back_off.xml b/src/main/res/drawable/switch_back_off.xml
new file mode 100644
index 000000000..20d2fb146
--- /dev/null
+++ b/src/main/res/drawable/switch_back_off.xml
@@ -0,0 +1,15 @@
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/res/drawable/switch_back_on.xml b/src/main/res/drawable/switch_back_on.xml
new file mode 100644
index 000000000..45117a98e
--- /dev/null
+++ b/src/main/res/drawable/switch_back_on.xml
@@ -0,0 +1,16 @@
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/res/drawable/switch_thumb.xml b/src/main/res/drawable/switch_thumb.xml
new file mode 100644
index 000000000..ba3d1c456
--- /dev/null
+++ b/src/main/res/drawable/switch_thumb.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/res/layout/account_row.xml b/src/main/res/layout/account_row.xml
index 06716a10a..077170b29 100644
--- a/src/main/res/layout/account_row.xml
+++ b/src/main/res/layout/account_row.xml
@@ -45,13 +45,14 @@
android:textStyle="bold" />
-
\ No newline at end of file
diff --git a/src/main/res/values/styles.xml b/src/main/res/values/styles.xml
index b98a37fcb..e8572d9d4 100644
--- a/src/main/res/values/styles.xml
+++ b/src/main/res/values/styles.xml
@@ -4,8 +4,18 @@
- 1.5dp
- @color/black12
-
\ No newline at end of file