diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2015-07-18 19:38:52 +0200 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2015-07-18 19:38:52 +0200 |
commit | f58b2afcaaf1977f02c590a8832bb67f77ee7be3 (patch) | |
tree | c4f22a8d1228dac4647203570936d8ba11b79f70 /src/main | |
parent | 451345f8ed050cf446f848368807a99981d8ab44 (diff) |
changed switch widget
Diffstat (limited to 'src/main')
32 files changed, 131 insertions, 7 deletions
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 782a1231..226b1920 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<Account> { @@ -53,8 +54,7 @@ public class AccountAdapter extends ArrayAdapter<Account> { } 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 00000000..c72e760e --- /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 Binary files differnew file mode 100644 index 00000000..1e9b151b --- /dev/null +++ b/src/main/res/drawable-hdpi/switch_thumb_disable.png diff --git a/src/main/res/drawable-hdpi/switch_thumb_off_normal.png b/src/main/res/drawable-hdpi/switch_thumb_off_normal.png Binary files differnew file mode 100644 index 00000000..b7c1fc11 --- /dev/null +++ b/src/main/res/drawable-hdpi/switch_thumb_off_normal.png diff --git a/src/main/res/drawable-hdpi/switch_thumb_off_pressed.png b/src/main/res/drawable-hdpi/switch_thumb_off_pressed.png Binary files differnew file mode 100644 index 00000000..ca6e4909 --- /dev/null +++ b/src/main/res/drawable-hdpi/switch_thumb_off_pressed.png diff --git a/src/main/res/drawable-hdpi/switch_thumb_on_normal.png b/src/main/res/drawable-hdpi/switch_thumb_on_normal.png Binary files differnew file mode 100644 index 00000000..cbcda5d4 --- /dev/null +++ b/src/main/res/drawable-hdpi/switch_thumb_on_normal.png diff --git a/src/main/res/drawable-hdpi/switch_thumb_on_pressed.png b/src/main/res/drawable-hdpi/switch_thumb_on_pressed.png Binary files differnew file mode 100644 index 00000000..234b12dc --- /dev/null +++ b/src/main/res/drawable-hdpi/switch_thumb_on_pressed.png diff --git a/src/main/res/drawable-mdpi/switch_thumb_disable.png b/src/main/res/drawable-mdpi/switch_thumb_disable.png Binary files differnew file mode 100644 index 00000000..968de345 --- /dev/null +++ b/src/main/res/drawable-mdpi/switch_thumb_disable.png diff --git a/src/main/res/drawable-mdpi/switch_thumb_off_normal.png b/src/main/res/drawable-mdpi/switch_thumb_off_normal.png Binary files differnew file mode 100644 index 00000000..51fb4d7a --- /dev/null +++ b/src/main/res/drawable-mdpi/switch_thumb_off_normal.png diff --git a/src/main/res/drawable-mdpi/switch_thumb_off_pressed.png b/src/main/res/drawable-mdpi/switch_thumb_off_pressed.png Binary files differnew file mode 100644 index 00000000..ca788445 --- /dev/null +++ b/src/main/res/drawable-mdpi/switch_thumb_off_pressed.png diff --git a/src/main/res/drawable-mdpi/switch_thumb_on_normal.png b/src/main/res/drawable-mdpi/switch_thumb_on_normal.png Binary files differnew file mode 100644 index 00000000..6a93d5f7 --- /dev/null +++ b/src/main/res/drawable-mdpi/switch_thumb_on_normal.png diff --git a/src/main/res/drawable-mdpi/switch_thumb_on_pressed.png b/src/main/res/drawable-mdpi/switch_thumb_on_pressed.png Binary files differnew file mode 100644 index 00000000..e8d7bd0f --- /dev/null +++ b/src/main/res/drawable-mdpi/switch_thumb_on_pressed.png diff --git a/src/main/res/drawable-xhdpi/switch_thumb_disable.png b/src/main/res/drawable-xhdpi/switch_thumb_disable.png Binary files differnew file mode 100644 index 00000000..7f677324 --- /dev/null +++ b/src/main/res/drawable-xhdpi/switch_thumb_disable.png diff --git a/src/main/res/drawable-xhdpi/switch_thumb_off_normal.png b/src/main/res/drawable-xhdpi/switch_thumb_off_normal.png Binary files differnew file mode 100644 index 00000000..4199d322 --- /dev/null +++ b/src/main/res/drawable-xhdpi/switch_thumb_off_normal.png diff --git a/src/main/res/drawable-xhdpi/switch_thumb_off_pressed.png b/src/main/res/drawable-xhdpi/switch_thumb_off_pressed.png Binary files differnew file mode 100644 index 00000000..2b86888f --- /dev/null +++ b/src/main/res/drawable-xhdpi/switch_thumb_off_pressed.png diff --git a/src/main/res/drawable-xhdpi/switch_thumb_on_normal.png b/src/main/res/drawable-xhdpi/switch_thumb_on_normal.png Binary files differnew file mode 100644 index 00000000..daa30990 --- /dev/null +++ b/src/main/res/drawable-xhdpi/switch_thumb_on_normal.png diff --git a/src/main/res/drawable-xhdpi/switch_thumb_on_pressed.png b/src/main/res/drawable-xhdpi/switch_thumb_on_pressed.png Binary files differnew file mode 100644 index 00000000..6aab47c9 --- /dev/null +++ b/src/main/res/drawable-xhdpi/switch_thumb_on_pressed.png diff --git a/src/main/res/drawable-xxhdpi/switch_thumb_disable.png b/src/main/res/drawable-xxhdpi/switch_thumb_disable.png Binary files differnew file mode 100644 index 00000000..db7c1df4 --- /dev/null +++ b/src/main/res/drawable-xxhdpi/switch_thumb_disable.png diff --git a/src/main/res/drawable-xxhdpi/switch_thumb_off_normal.png b/src/main/res/drawable-xxhdpi/switch_thumb_off_normal.png Binary files differnew file mode 100644 index 00000000..f747b559 --- /dev/null +++ b/src/main/res/drawable-xxhdpi/switch_thumb_off_normal.png diff --git a/src/main/res/drawable-xxhdpi/switch_thumb_off_pressed.png b/src/main/res/drawable-xxhdpi/switch_thumb_off_pressed.png Binary files differnew file mode 100644 index 00000000..b9fe6d46 --- /dev/null +++ b/src/main/res/drawable-xxhdpi/switch_thumb_off_pressed.png diff --git a/src/main/res/drawable-xxhdpi/switch_thumb_on_normal.png b/src/main/res/drawable-xxhdpi/switch_thumb_on_normal.png Binary files differnew file mode 100644 index 00000000..88199024 --- /dev/null +++ b/src/main/res/drawable-xxhdpi/switch_thumb_on_normal.png diff --git a/src/main/res/drawable-xxhdpi/switch_thumb_on_pressed.png b/src/main/res/drawable-xxhdpi/switch_thumb_on_pressed.png Binary files differnew file mode 100644 index 00000000..7a4fed54 --- /dev/null +++ b/src/main/res/drawable-xxhdpi/switch_thumb_on_pressed.png diff --git a/src/main/res/drawable-xxxhdpi/switch_thumb_disable.png b/src/main/res/drawable-xxxhdpi/switch_thumb_disable.png Binary files differnew file mode 100644 index 00000000..3970168c --- /dev/null +++ b/src/main/res/drawable-xxxhdpi/switch_thumb_disable.png diff --git a/src/main/res/drawable-xxxhdpi/switch_thumb_off_normal.png b/src/main/res/drawable-xxxhdpi/switch_thumb_off_normal.png Binary files differnew file mode 100644 index 00000000..ea8d4f89 --- /dev/null +++ b/src/main/res/drawable-xxxhdpi/switch_thumb_off_normal.png diff --git a/src/main/res/drawable-xxxhdpi/switch_thumb_off_pressed.png b/src/main/res/drawable-xxxhdpi/switch_thumb_off_pressed.png Binary files differnew file mode 100644 index 00000000..84d667b1 --- /dev/null +++ b/src/main/res/drawable-xxxhdpi/switch_thumb_off_pressed.png diff --git a/src/main/res/drawable-xxxhdpi/switch_thumb_on_normal.png b/src/main/res/drawable-xxxhdpi/switch_thumb_on_normal.png Binary files differnew file mode 100644 index 00000000..06b190eb --- /dev/null +++ b/src/main/res/drawable-xxxhdpi/switch_thumb_on_normal.png diff --git a/src/main/res/drawable-xxxhdpi/switch_thumb_on_pressed.png b/src/main/res/drawable-xxxhdpi/switch_thumb_on_pressed.png Binary files differnew file mode 100644 index 00000000..79c30d1e --- /dev/null +++ b/src/main/res/drawable-xxxhdpi/switch_thumb_on_pressed.png 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 00000000..20d2fb14 --- /dev/null +++ b/src/main/res/drawable/switch_back_off.xml @@ -0,0 +1,15 @@ +<?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>
\ 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 00000000..45117a98 --- /dev/null +++ b/src/main/res/drawable/switch_back_on.xml @@ -0,0 +1,16 @@ +<?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>
\ 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 00000000..ba3d1c45 --- /dev/null +++ b/src/main/res/drawable/switch_thumb.xml @@ -0,0 +1,12 @@ +<?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>
\ 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 06716a10..077170b2 100644 --- a/src/main/res/layout/account_row.xml +++ b/src/main/res/layout/account_row.xml @@ -45,13 +45,14 @@ android:textStyle="bold" /> </LinearLayout> - <Switch + <eu.siacs.conversations.ui.widget.Switch + style="@style/MD" android:id="@+id/tgl_account_status" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" - android:padding="8dp" + android:padding="16dp" android:focusable="false"/> </RelativeLayout>
\ No newline at end of file diff --git a/src/main/res/values/styles.xml b/src/main/res/values/styles.xml index b98a37fc..e8572d9d 100644 --- a/src/main/res/values/styles.xml +++ b/src/main/res/values/styles.xml @@ -4,8 +4,18 @@ <item name="android:layout_height">1.5dp</item> <item name="android:background">@color/black12</item> </style> - <style name="Tag"> - + <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>
\ No newline at end of file |