Skip to content

Commit

Permalink
修改视频库稳定版、增加自动定义控件ZTSwitchbutton
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhetengDashen committed Mar 25, 2020
1 parent 5c2bd8b commit a7eba78
Show file tree
Hide file tree
Showing 10 changed files with 224 additions and 13 deletions.
Expand Up @@ -53,7 +53,8 @@ protected DataBinDingPresenter<IDataBinDingView> createPresenter() {
public void onClick(View view) {
if(view.getId()==R.id.rv_item_bt){
// editText.setText("123");
// dataBinding.getRventity().setMsg("456456");
dataBinding.getRventity().setTitle("456456");
// dataBinding.getRventity().setIschick(!dataBinding.getRventity().getIschick());
Toast.makeText(this, dataBinding.getRventity().getMsg(), Toast.LENGTH_SHORT).show();
}
}
Expand Down
Expand Up @@ -22,8 +22,9 @@ public class RVDemoEntity extends BaseObservable implements MultiItemEntity {
String image;
String type;
String title;


@Bindable
Boolean ischick;
@Bindable
public String msg;
int index;
ObservableField<String> content = new ObservableField<>();
Expand All @@ -39,6 +40,15 @@ public void setContent(String content) {
public RVDemoEntity() {
}

public Boolean getIschick() {
return ischick;
}

public void setIschick(Boolean ischick) {
this.ischick = ischick;
notifyChange();
}

public RVDemoEntity(String image, String type, String title, String msg, int index) {
this.image = image;
this.type = type;
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/com/test/TestUser.java
@@ -1,5 +1,8 @@
package com.test;

import androidx.databinding.BaseObservable;
import androidx.databinding.Bindable;

/**
* 作者:WangZhiQiang
* 时间:2019/3/14
Expand All @@ -8,6 +11,7 @@
*/

public class TestUser {

String name;
String id;
String gender;
Expand All @@ -27,6 +31,7 @@ public String getName() {

public void setName(String name) {
this.name = name;

}

public String getId() {
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Expand Up @@ -10,6 +10,8 @@
android:layout_height="match_parent"
tools:context=".MainActivity">



<Button

android:id="@+id/bt_arouter"
Expand Down Expand Up @@ -159,5 +161,8 @@
app:layout_constraintEnd_toEndOf="@+id/button_http"
app:layout_constraintStart_toEndOf="@+id/binding"
app:layout_constraintTop_toBottomOf="@+id/button_http" />



</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
22 changes: 17 additions & 5 deletions app/src/main/res/layout/activitydatabinding.xml
@@ -1,13 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
xmlns:tools="http://schemas.android.com/tools"

tools:ignore="NamespaceTypo">

<data class="TestDataBinding" >
<import type="com.baseeasy.baseframework.demoactivity.entity.RVDemoEntity"/>

<variable
name="rventity"
type="RVDemoEntity" />
type="com.baseeasy.baseframework.demoactivity.entity.RVDemoEntity" />
</data>

<androidx.cardview.widget.CardView
Expand All @@ -18,10 +20,20 @@
android:layout_marginLeft="12dp"
android:layout_width="match_parent"
android:layout_height="150dp">

<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.baseeasy.commonlibrary.weight.ZTSwitchButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/qianming"
app:ztswchecked="@{rventity.ischick}"
app:ztswcontent="@{rventity.msg}"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="5dp" />

<ImageView
android:scaleType="centerCrop"
android:id="@+id/rv_item_image"
Expand Down Expand Up @@ -54,7 +66,7 @@
android:layout_marginStart="6dp"
android:layout_marginLeft="6dp"
android:layout_marginTop="8dp"
android:text="@={rventity.msg,default=默认文本内容}"
android:text="@{rventity.title,default=默认文本内容}"
android:textColor="@android:color/darker_gray"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="parent"
Expand Down Expand Up @@ -86,7 +98,7 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/rv_item_tx2"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

</LinearLayout>

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values/colors.xml
Expand Up @@ -2,8 +2,8 @@
<resources>
<color name="colorPrimary">#2c97df</color>
<color name="colorPrimaryDark">#2c97df</color>
<color name="colorAccent">#FF730F</color>
<color name="colorAV1">#FFFF730F</color>
<color name="colorAccent">#2c97df</color>
<color name="colorAV1">#2c97df</color>
<color name="colorbtbg">#3B427C</color>
<color name="colorbtstroke">#72d7b5</color>
</resources>
3 changes: 2 additions & 1 deletion commonlibrary/build.gradle
Expand Up @@ -101,7 +101,8 @@ dependencies {
// implementation project(':media')

// api 'com.gitee.wzq0607:ALVideoRecorder:1.2'
api 'com.github.ZhetengDashen:ALVideoRecorder:2.0.1'
api 'com.github.ZhetengDashen:ALVideoRecorder:2.0.3'
api 'com.kyleduo.switchbutton:library:2.0.0'
// implementation 'com.gitee.wzq0607:ALVideoRecorder:1.0'

}
@@ -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 commonlibrary/src/main/res/layout/ztswitch_button_layout.xml
@@ -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>
8 changes: 6 additions & 2 deletions commonlibrary/src/main/res/values/attrs.xml
Expand Up @@ -2,8 +2,12 @@
<resources>

<declare-styleable name="squareframelayout">
<attr name="reltiveWidth" format="float"/>
<attr name="reltiveHeight" format="float"/>
<attr name="reltiveWidth" format="float" />
<attr name="reltiveHeight" format="float" />
</declare-styleable>
<declare-styleable name="ztswitchbutton">

<attr name="ztswcontent" format="string"></attr>
<attr name="ztswchecked" format="boolean"></attr>
</declare-styleable>
</resources>

0 comments on commit a7eba78

Please sign in to comment.