Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c2bd8b
commit a7eba78
Showing
10 changed files
with
224 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
commonlibrary/src/main/java/com/baseeasy/commonlibrary/weight/ZTSwitchButton.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
package com.baseeasy.commonlibrary.weight; | ||
|
||
import android.content.Context; | ||
import android.content.res.TypedArray; | ||
import android.os.Build; | ||
import android.text.Editable; | ||
import android.text.TextWatcher; | ||
import android.util.AttributeSet; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.CompoundButton; | ||
import android.widget.FrameLayout; | ||
import android.widget.TextView; | ||
|
||
import androidx.annotation.RequiresApi; | ||
import androidx.databinding.BindingAdapter; | ||
import androidx.databinding.InverseBindingAdapter; | ||
import androidx.databinding.InverseBindingListener; | ||
import androidx.databinding.InverseBindingMethod; | ||
import androidx.databinding.InverseBindingMethods; | ||
import androidx.databinding.InverseMethod; | ||
import androidx.databinding.adapters.ListenerUtil; | ||
import androidx.databinding.adapters.TextViewBindingAdapter; | ||
|
||
import com.baseeasy.commonlibrary.R; | ||
import com.kyleduo.switchbutton.SwitchButton; | ||
|
||
/** | ||
* 作者:WangZhiQiang | ||
* 时间:2020/3/24 | ||
* 邮箱:sos181@163.com | ||
* 描述:开关按钮 暂时不支持DataBinDing双向绑定 | ||
*/ | ||
|
||
public class ZTSwitchButton extends FrameLayout { | ||
private TextView contentTextView; | ||
private SwitchButton switchButton; | ||
private String content = ""; | ||
private Boolean checked = false; | ||
private static InverseBindingListener mInverseBindingListener_content; | ||
public ZTSwitchButton(Context context) { | ||
super(context); | ||
initView(); | ||
} | ||
|
||
public ZTSwitchButton(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ztswitchbutton); | ||
initByAttributes(typedArray); | ||
initView(); | ||
typedArray.recycle(); | ||
} | ||
|
||
public ZTSwitchButton(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ztswitchbutton); | ||
initByAttributes(typedArray); | ||
initView(); | ||
typedArray.recycle(); | ||
} | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) | ||
public ZTSwitchButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { | ||
super(context, attrs, defStyleAttr, defStyleRes); | ||
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ztswitchbutton); | ||
initByAttributes(typedArray); | ||
initView(); | ||
typedArray.recycle(); | ||
} | ||
|
||
protected void initByAttributes(TypedArray attributes) { | ||
content = attributes.getString(R.styleable.ztswitchbutton_ztswcontent); | ||
checked = attributes.getBoolean(R.styleable.ztswitchbutton_ztswchecked, false); | ||
|
||
} | ||
|
||
public void initView() { | ||
View view = View.inflate(getContext(), R.layout.ztswitch_button_layout, this); | ||
contentTextView = view.findViewById(R.id.tv_ztsw_content); | ||
switchButton = view.findViewById(R.id.swbt); | ||
contentTextView.setText(content); | ||
switchButton.setChecked(checked); | ||
|
||
} | ||
|
||
public void setOnCheckedChangeListener(CompoundButton.OnCheckedChangeListener onCheckedChangeListener){ | ||
switchButton.setOnCheckedChangeListener(onCheckedChangeListener); | ||
}; | ||
public TextView getContentTextView() { | ||
return contentTextView; | ||
} | ||
|
||
public SwitchButton getSwitchButton() { | ||
return switchButton; | ||
} | ||
|
||
|
||
public String getContent() { | ||
return contentTextView.getText().toString(); | ||
} | ||
|
||
public void setContent(CharSequence content) { | ||
contentTextView.setText(content); | ||
} | ||
|
||
public Boolean getChecked() { | ||
return switchButton.isChecked(); | ||
} | ||
|
||
public void setChecked(Boolean checked) { | ||
switchButton.setChecked(checked); | ||
} | ||
|
||
|
||
@BindingAdapter(value = "ztswcontent", requireAll = false) | ||
public static void setSwitchButtonContent(ZTSwitchButton ztSwitchButton, String content) { | ||
ztSwitchButton.setContent(content); | ||
} | ||
|
||
@BindingAdapter(value = "ztswchecked", requireAll = false) | ||
public static void setSwitchButtonChecked(ZTSwitchButton ztSwitchButton, boolean isChecked) { | ||
ztSwitchButton.setChecked(isChecked); | ||
} | ||
|
||
// @InverseBindingAdapter(attribute = "ztswcontent", event="contentAttrChanged") | ||
// public static String getSwitchButtonContent(ZTSwitchButton ztSwitchButton) { | ||
// return ztSwitchButton.getContent(); | ||
// } | ||
// | ||
// @BindingAdapter(value = {"contentAttrChanged"},requireAll = false) | ||
// public static void setContentAttrChanged(ZTSwitchButton ztSwitchButton, InverseBindingListener mInverseBindingListener){ | ||
// if(mInverseBindingListener_content==null){ | ||
// Log.e("kk","mInverseBindingListener_content--------null"); | ||
// }else { | ||
// Log.e("kk","mInverseBindingListener_content--------"); | ||
// mInverseBindingListener_content = mInverseBindingListener; | ||
// | ||
// } | ||
// | ||
// } | ||
// | ||
// | ||
// | ||
// @BindingAdapter({"ztswchecked"}) | ||
// public static void setSwitchButtonChecked(ZTSwitchButton ztSwitchButton, Boolean isChecked) { | ||
// ztSwitchButton.setChecked(isChecked); | ||
// } | ||
|
||
|
||
} |
22 changes: 22 additions & 0 deletions
22
commonlibrary/src/main/res/layout/ztswitch_button_layout.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="wrap_content" | ||
android:orientation="horizontal" | ||
android:layout_gravity="center" | ||
android:id="@+id/ztll" | ||
android:layout_height="wrap_content"> | ||
<TextView | ||
|
||
android:id="@+id/tv_ztsw_content" | ||
android:layout_gravity="center" | ||
android:gravity="center" | ||
android:text="" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content"></TextView> | ||
<com.kyleduo.switchbutton.SwitchButton | ||
android:id="@+id/swbt" | ||
android:checked="true" | ||
android:layout_marginLeft="12dp" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content"></com.kyleduo.switchbutton.SwitchButton> | ||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters