Commit 41a1858b by Wyh

1、供應鏈收貨sn碼數據修改 2、編輯商品提示保存 3、軟鍵盤遮擋問題 4、單位頁面點擊其他地方隱藏軟鍵盤 5、單位換算倍數輸入小數限制

6、採購單詳情顯示商品名稱 7、庫存消耗頁面不顯示商品圖片問題 8、收貨彈窗不消失問題 9、心跳預警修改
parent 84221077
...@@ -397,7 +397,6 @@ class DeliveryOrderMainActivity : BaseActivity<IPresenter>(), View.OnClickListen ...@@ -397,7 +397,6 @@ class DeliveryOrderMainActivity : BaseActivity<IPresenter>(), View.OnClickListen
if (!notification.areNotificationsEnabled()) { if (!notification.areNotificationsEnabled()) {
//未開啟通知權限 //未開啟通知權限
AppDialog().showTipDialog(this, "檢測到通知權限未打開,建議打開,否則會影響正常使用!") { _, d -> AppDialog().showTipDialog(this, "檢測到通知權限未打開,建議打開,否則會影響正常使用!") { _, d ->
d.dismiss()
val intent = Intent() val intent = Intent()
when { when {
SDK_INT >= Build.VERSION_CODES.O -> { SDK_INT >= Build.VERSION_CODES.O -> {
......
...@@ -12,7 +12,8 @@ ...@@ -12,7 +12,8 @@
<uses-permission android:name="android.permission.FLASHLIGHT" /> <uses-permission android:name="android.permission.FLASHLIGHT" />
<application android:networkSecurityConfig="@xml/network_android"> <application android:networkSecurityConfig="@xml/network_android">
<activity android:name=".mvp.ui.activity.SupplyChainMainActivity" /> <activity android:name=".mvp.ui.activity.SupplyChainMainActivity"
android:windowSoftInputMode="adjustResize|stateVisible"/>
<meta-data <meta-data
android:name="com.gingersoft.gsa.cloud.common.config.globalconfig.GlobalConfiguration" android:name="com.gingersoft.gsa.cloud.common.config.globalconfig.GlobalConfiguration"
......
...@@ -15,9 +15,12 @@ import lombok.Data; ...@@ -15,9 +15,12 @@ import lombok.Data;
public class OrderWareHouseBean { public class OrderWareHouseBean {
private int status; private int status;
private int orderId; private int orderId;
private List<String> encodeFoodNos; // private List<String> encodeFoodNos;
private List<PurchaseConsumeVerifyEncodeSn> purchaseConsumeVerifyEncodeSn;
private PurchaseWarehousingOrder purchaseWarehousingOrder; private PurchaseWarehousingOrder purchaseWarehousingOrder;
private List<PurchaseWarehousingOrderDetail> purchaseWarehousingOrderDetailsTOS; private List<PurchaseWarehousingOrderDetail> purchaseWarehousingOrderDetailsTOS;
@Data @Data
public static class PurchaseWarehousingOrder { public static class PurchaseWarehousingOrder {
/** /**
...@@ -55,4 +58,16 @@ public class OrderWareHouseBean { ...@@ -55,4 +58,16 @@ public class OrderWareHouseBean {
*/ */
private List<PurchaseFoodEncodeSn> purchaseFoodEncodeSn; private List<PurchaseFoodEncodeSn> purchaseFoodEncodeSn;
} }
@Data
public static class PurchaseConsumeVerifyEncodeSn {
public PurchaseConsumeVerifyEncodeSn(String encodeFoodNo, List<String> encodeSnNos) {
this.encodeFoodNo = encodeFoodNo;
this.encodeSnNos = encodeSnNos;
}
private String encodeFoodNo;
private List<String> encodeSnNos;
}
} }
...@@ -213,7 +213,7 @@ public class NewFoodIngredientsPresenter extends BasePresenter<NewFoodIngredient ...@@ -213,7 +213,7 @@ public class NewFoodIngredientsPresenter extends BasePresenter<NewFoodIngredient
infoMultiBeans.add(new MultiSelectBean(InfoMultiBean.EDIT_FOOD_ITEM_SELECT, "食材類別", true, "請選擇食材類別", SELECT_FOOD_CATEGORY_REQUEST_CODE, CategorySelectFragment.class)); infoMultiBeans.add(new MultiSelectBean(InfoMultiBean.EDIT_FOOD_ITEM_SELECT, "食材類別", true, "請選擇食材類別", SELECT_FOOD_CATEGORY_REQUEST_CODE, CategorySelectFragment.class));
infoMultiBeans.add(new MultiSelectBean(InfoMultiBean.EDIT_FOOD_ITEM_SELECT, "基本單位", true, "請選擇食材單位", SELECT_PACKAGE_SPECIFICATION_REQUEST_CODE, FoodUnitPageFragment.class)); infoMultiBeans.add(new MultiSelectBean(InfoMultiBean.EDIT_FOOD_ITEM_SELECT, "基本單位", true, "請選擇食材單位", SELECT_PACKAGE_SPECIFICATION_REQUEST_CODE, FoodUnitPageFragment.class));
infoMultiBeans.add(new MultiInputBean(InfoMultiBean.ITEM_TYPE_INPUT, "包裝說明", false, "請輸入包裝說明", new InputFilter[]{InputFilterUtils.getLengthFilter(context, 10), InputFilterUtils.getTypeFilter(context, InputFilterUtils.chAndEnAndNumAndSlash)})); infoMultiBeans.add(new MultiInputBean(InfoMultiBean.ITEM_TYPE_INPUT, "包裝說明", false, "請輸入包裝說明", new InputFilter[]{InputFilterUtils.getLengthFilter(context, 10), InputFilterUtils.getTypeFilter(context, InputFilterUtils.chAndEnAndNumAndSlash)}));
infoMultiBeans.add(new MultiInputBean(InfoMultiBean.ITEM_TYPE_INPUT, "食材編號", false, "請輸入食材編號", new InputFilter[]{InputFilterUtils.getLengthFilter(context, 11), InputFilterUtils.getEnAndNumInputFilter(context)})); infoMultiBeans.add(new MultiInputBean(InfoMultiBean.ITEM_TYPE_INPUT, "食材編號", false, "請輸入食材編號", new InputFilter[]{InputFilterUtils.getLengthFilter(context, 32), InputFilterUtils.getEnAndNumInputFilter(context)}));
infoMultiBeans.add(new InfoMultiBean(InfoMultiBean.ITEM_MULTIPLE_BOOLEAN, "是否有SN碼", false, false)); infoMultiBeans.add(new InfoMultiBean(InfoMultiBean.ITEM_MULTIPLE_BOOLEAN, "是否有SN碼", false, false));
infoMultiBeans.add(new MultiInputBean(InfoMultiBean.ITEM_TYPE_INPUT, "單價($)", false, "請輸入單價,保留2位小數", new InputFilter[]{InputFilterUtils.getLengthFilter(context, 9), new DecimalDigitsInputFilter(context, 2)}, InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL)); infoMultiBeans.add(new MultiInputBean(InfoMultiBean.ITEM_TYPE_INPUT, "單價($)", false, "請輸入單價,保留2位小數", new InputFilter[]{InputFilterUtils.getLengthFilter(context, 9), new DecimalDigitsInputFilter(context, 2)}, InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL));
infoMultiBeans.add(new InfoMultiBean(InfoMultiBean.ITEM_TYPE_LINE)); infoMultiBeans.add(new InfoMultiBean(InfoMultiBean.ITEM_TYPE_LINE));
...@@ -251,8 +251,14 @@ public class NewFoodIngredientsPresenter extends BasePresenter<NewFoodIngredient ...@@ -251,8 +251,14 @@ public class NewFoodIngredientsPresenter extends BasePresenter<NewFoodIngredient
foodNoInputBean.setEdit(false); foodNoInputBean.setEdit(false);
foodNoInputBean.setShowValue(purchaseFoodBean.getFoodNo()); foodNoInputBean.setShowValue(purchaseFoodBean.getFoodNo());
} }
//sn食材 //sn食材,新增食材,是否是sn為-1,如果不是-1,則不是新增。就不能修改
infoMultiBeans.get(foodSnIndex).setChecked(purchaseFoodBean.getFoodMarkSn() == PurchaseFoodBean.HAS_SN); if (purchaseFoodBean.getFoodMarkSn() != -1) {
infoMultiBeans.set(foodSnIndex, new MultiInputBean(InfoMultiBean.ITEM_TYPE_INPUT, "是否有SN碼", false, purchaseFoodBean.getFoodMarkSn() == PurchaseFoodBean.HAS_SN ? "是" : "否").setEdit(false));
} else {
//默認不是SN食材
purchaseFoodBean.setFoodMarkSn(0);
}
// infoMultiBeans.get(foodSnIndex).setChecked(purchaseFoodBean.getFoodMarkSn() == PurchaseFoodBean.HAS_SN);
//單價 //單價
if (purchaseFoodBean.getUnitPrice() != null) { if (purchaseFoodBean.getUnitPrice() != null) {
infoMultiBeans.get(foodIngredientPriceIndex).setShowValue(purchaseFoodBean.getUnitPrice() + ""); infoMultiBeans.get(foodIngredientPriceIndex).setShowValue(purchaseFoodBean.getUnitPrice() + "");
......
...@@ -154,7 +154,7 @@ public class NewSupplierPresenter extends BasePresenter<NewSupplierContract.Mode ...@@ -154,7 +154,7 @@ public class NewSupplierPresenter extends BasePresenter<NewSupplierContract.Mode
// childInfoMulti.add(new MultiInputBean(InfoMultiBean.ITEM_TYPE_INPUT, "Kakao Talk", false, "請輸入Kakao Talk")); // childInfoMulti.add(new MultiInputBean(InfoMultiBean.ITEM_TYPE_INPUT, "Kakao Talk", false, "請輸入Kakao Talk"));
// receivingMode.setInfoMultiBeans(childInfoMulti); // receivingMode.setInfoMultiBeans(childInfoMulti);
// infoMultiBeans.add(receivingMode); // infoMultiBeans.add(receivingMode);
MultiCheckInputBean emailInputBean = new MultiCheckInputBean(InfoMultiBean.ITEM_MULTIPLE_CHECKBOX, "Email", false, "請輸入Email", new InputFilter[]{InputFilterUtils.getLengthFilter(mContext, 20)}, R.drawable.ic_email, false); MultiCheckInputBean emailInputBean = new MultiCheckInputBean(InfoMultiBean.ITEM_MULTIPLE_CHECKBOX, "Email", false, "請輸入Email", new InputFilter[]{InputFilterUtils.getLengthFilter(mContext, 40)}, R.drawable.ic_email, false);
emailInputBean.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); emailInputBean.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
contactInfo.add(emailInputBean); contactInfo.add(emailInputBean);
contactInfo.add(new MultiCheckInputBean(InfoMultiBean.ITEM_MULTIPLE_CHECKBOX, "WhatsApp", false, "請輸入WhatsApp", new InputFilter[]{InputFilterUtils.getLengthFilter(mContext, 20), InputFilterUtils.getChAndEnAndNumInputFilter(mContext)}, R.drawable.ic_whatsapp, false).setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES)); contactInfo.add(new MultiCheckInputBean(InfoMultiBean.ITEM_MULTIPLE_CHECKBOX, "WhatsApp", false, "請輸入WhatsApp", new InputFilter[]{InputFilterUtils.getLengthFilter(mContext, 20), InputFilterUtils.getChAndEnAndNumInputFilter(mContext)}, R.drawable.ic_whatsapp, false).setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES));
......
...@@ -372,7 +372,8 @@ public class OrderDetailsPresenter extends BasePresenter<OrderDetailsContract.Mo ...@@ -372,7 +372,8 @@ public class OrderDetailsPresenter extends BasePresenter<OrderDetailsContract.Mo
mRootView.showMessage(NULL_INFO_ERROR); mRootView.showMessage(NULL_INFO_ERROR);
return null; return null;
} }
List<OrderWareHouseBean.PurchaseWarehousingOrderDetail> purchaseWarehousingOrderDetails = new ArrayList<>(); List<OrderWareHouseBean.PurchaseWarehousingOrderDetail> purchaseWarehousingOrderDetails = new ArrayList<>(purchaseOrderDetailsInfoVosBeans.size());
List<OrderWareHouseBean.PurchaseConsumeVerifyEncodeSn> purchaseConsumeVerifyEncodeSns = new ArrayList<>(purchaseOrderDetailsInfoVosBeans.size());
for (PurchaseOrderDetailsBean.PurchaseOrderDetailsInfoVosBean purchaseOrderDetailsInfoVosBean : purchaseOrderDetailsInfoVosBeans) { for (PurchaseOrderDetailsBean.PurchaseOrderDetailsInfoVosBean purchaseOrderDetailsInfoVosBean : purchaseOrderDetailsInfoVosBeans) {
if (purchaseOrderDetailsInfoVosBean.getStatus() != PurchaseOrderDetailsBean.COMPLETE_RECEIVED && purchaseOrderDetailsInfoVosBean.isChecked()) { if (purchaseOrderDetailsInfoVosBean.getStatus() != PurchaseOrderDetailsBean.COMPLETE_RECEIVED && purchaseOrderDetailsInfoVosBean.isChecked()) {
//新的入庫類 //新的入庫類
...@@ -397,10 +398,10 @@ public class OrderDetailsPresenter extends BasePresenter<OrderDetailsContract.Mo ...@@ -397,10 +398,10 @@ public class OrderDetailsPresenter extends BasePresenter<OrderDetailsContract.Mo
purchaseWarehousingOrderDetail.setPurchaseWarehousingUnit(wareHousingUnitBean); purchaseWarehousingOrderDetail.setPurchaseWarehousingUnit(wareHousingUnitBean);
//sn碼 //sn碼
List<PurchaseFoodEncodeSn> snList = null; List<PurchaseFoodEncodeSn> snList = null;
List<String> snCodes = null; List<String> snCodes;
if (purchaseOrderDetailsInfoVosBean.getPurchaseFoodEncodeSns() != null) { if (purchaseOrderDetailsInfoVosBean.getPurchaseFoodEncodeSns() != null) {
snList = new ArrayList<>(); snList = new ArrayList<>(purchaseOrderDetailsInfoVosBean.getPurchaseFoodEncodeSns().size());
snCodes = new ArrayList<>(); snCodes = new ArrayList<>(purchaseOrderDetailsInfoVosBean.getPurchaseFoodEncodeSns().size());
//只遍歷出新增的 //只遍歷出新增的
for (PurchaseFoodEncodeSn purchaseFoodEncodeSn : purchaseOrderDetailsInfoVosBean.getPurchaseFoodEncodeSns()) { for (PurchaseFoodEncodeSn purchaseFoodEncodeSn : purchaseOrderDetailsInfoVosBean.getPurchaseFoodEncodeSns()) {
if (purchaseFoodEncodeSn.newAdd) { if (purchaseFoodEncodeSn.newAdd) {
...@@ -408,12 +409,13 @@ public class OrderDetailsPresenter extends BasePresenter<OrderDetailsContract.Mo ...@@ -408,12 +409,13 @@ public class OrderDetailsPresenter extends BasePresenter<OrderDetailsContract.Mo
snCodes.add(purchaseFoodEncodeSn.getEncodeSnNo()); snCodes.add(purchaseFoodEncodeSn.getEncodeSnNo());
} }
} }
purchaseConsumeVerifyEncodeSns.add(new OrderWareHouseBean.PurchaseConsumeVerifyEncodeSn(purchaseOrderDetailsInfoVosBean.getFoodNo(), snCodes));
} }
wareHouseBean.setEncodeFoodNos(snCodes);
purchaseWarehousingOrderDetail.setPurchaseFoodEncodeSn(snList); purchaseWarehousingOrderDetail.setPurchaseFoodEncodeSn(snList);
purchaseWarehousingOrderDetails.add(purchaseWarehousingOrderDetail); purchaseWarehousingOrderDetails.add(purchaseWarehousingOrderDetail);
} }
} }
wareHouseBean.setPurchaseConsumeVerifyEncodeSn(purchaseConsumeVerifyEncodeSns);
return purchaseWarehousingOrderDetails; return purchaseWarehousingOrderDetails;
} }
......
...@@ -11,7 +11,6 @@ import android.widget.EditText; ...@@ -11,7 +11,6 @@ import android.widget.EditText;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;
import com.gingersoft.gsa.cloud.ui.widget.dialog.LoadingDialog; import com.gingersoft.gsa.cloud.ui.widget.dialog.LoadingDialog;
import com.gingersoft.supply_chain.R; import com.gingersoft.supply_chain.R;
...@@ -20,11 +19,11 @@ import com.gingersoft.supply_chain.mvp.content.SupplyShoppingCart; ...@@ -20,11 +19,11 @@ import com.gingersoft.supply_chain.mvp.content.SupplyShoppingCart;
import com.gingersoft.supply_chain.mvp.contract.SupplyChainMainContract; import com.gingersoft.supply_chain.mvp.contract.SupplyChainMainContract;
import com.gingersoft.supply_chain.mvp.presenter.SupplyChainMainPresenter; import com.gingersoft.supply_chain.mvp.presenter.SupplyChainMainPresenter;
import com.gingersoft.supply_chain.mvp.ui.fragment.FunctionListFragment; import com.gingersoft.supply_chain.mvp.ui.fragment.FunctionListFragment;
import com.gingersoft.supply_chain.mvp.utils.HideUtil;
import com.gingersoft.supply_chain.mvp.utils.NotDispatchListener; import com.gingersoft.supply_chain.mvp.utils.NotDispatchListener;
import com.jess.arms.base.BaseFragmentActivity; import com.jess.arms.base.BaseFragmentActivity;
import com.jess.arms.di.component.AppComponent; import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils; import com.jess.arms.utils.ArmsUtils;
import com.jess.arms.utils.SoftHideKeyBoardUtil;
import static com.jess.arms.utils.Preconditions.checkNotNull; import static com.jess.arms.utils.Preconditions.checkNotNull;
...@@ -45,13 +44,19 @@ public class SupplyChainMainActivity extends BaseFragmentActivity<SupplyChainMai ...@@ -45,13 +44,19 @@ public class SupplyChainMainActivity extends BaseFragmentActivity<SupplyChainMai
} }
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SoftHideKeyBoardUtil.assistActivity(this);
}
@Override
public int initView(@Nullable Bundle savedInstanceState) { public int initView(@Nullable Bundle savedInstanceState) {
return R.layout.activity_supply_chain_main; return R.layout.activity_supply_chain_main;
} }
@Override @Override
public void initData(@Nullable Bundle savedInstanceState) { public void initData(@Nullable Bundle savedInstanceState) {
// HideUtil.init(this);
loadRootFragment(R.id.layout_supply_chain_content, FunctionListFragment.newInstance()); loadRootFragment(R.id.layout_supply_chain_content, FunctionListFragment.newInstance());
} }
...@@ -75,6 +80,28 @@ public class SupplyChainMainActivity extends BaseFragmentActivity<SupplyChainMai ...@@ -75,6 +80,28 @@ public class SupplyChainMainActivity extends BaseFragmentActivity<SupplyChainMai
return super.dispatchTouchEvent(event); return super.dispatchTouchEvent(event);
} }
// @Override // @Override
// public boolean onTouchEvent(@NonNull MotionEvent event) {
// if (getCurrentFocus() != null) {
// //点击EditText以外区域隐藏软键盘
// InputMethodManager mInputMethodManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
// mInputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
// }
// //对dialog区域外进行监听,数值按照实际情况调整
// if (event.getAction() == MotionEvent.ACTION_DOWN) {
// if (!(event.getX() >= -10 && event.getY() >= -10)
// || event.getX() >= calendarLayout.getWidth() + 10
// || event.getY() >= calendarLayout.getHeight() + 20) {
// //若有软键盘则关闭,无则关闭dialog
// if (SoftKeyBoardListener.softKeyFlag) {
// SoftKeyBoardListener.hideSoftKeyboard(getContext(), getCurrentFocus());
// } else {
// dismiss();
// }
// }
// }
// return super.onTouchEvent(event);
// }
// @Override
// public boolean dispatchTouchEvent(MotionEvent ev) { // public boolean dispatchTouchEvent(MotionEvent ev) {
// if (getTopFragment() instanceof NotDispatchListener) { // if (getTopFragment() instanceof NotDispatchListener) {
// return super.dispatchTouchEvent(ev); // return super.dispatchTouchEvent(ev);
...@@ -182,4 +209,5 @@ public class SupplyChainMainActivity extends BaseFragmentActivity<SupplyChainMai ...@@ -182,4 +209,5 @@ public class SupplyChainMainActivity extends BaseFragmentActivity<SupplyChainMai
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
} }
} }
...@@ -74,7 +74,6 @@ public class BuyIngredientsAdapter extends GroupedRecyclerViewAdapter<BuyIngredi ...@@ -74,7 +74,6 @@ public class BuyIngredientsAdapter extends GroupedRecyclerViewAdapter<BuyIngredi
return getLayoutId(); return getLayoutId();
} }
@Override @Override
public void onBindHeaderViewHolder(BaseViewHolder holder, int groupPosition, BuyIngredientsBean data) { public void onBindHeaderViewHolder(BaseViewHolder holder, int groupPosition, BuyIngredientsBean data) {
holder.setText(R.id.tv_buy_food_header, data.categoryName + ""); holder.setText(R.id.tv_buy_food_header, data.categoryName + "");
......
package com.gingersoft.supply_chain.mvp.ui.adapter;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.TextView;
import androidx.cardview.widget.CardView;
import androidx.core.content.ContextCompat;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.gingersoft.gsa.cloud.common.R;
import com.gingersoft.supply_chain.mvp.bean.OrderCategoryBean;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
/**
* @author 宇航.
* User: admin
* Date: 2020/11/28
* Time: 11:45
* Use: 編輯分類,一級分類適配器
*/
public class CategoryAdapter extends BaseQuickAdapter<OrderCategoryBean.FoodCategoryTrees, BaseViewHolder> {
private int selectedIndex = 0;
private Drawable selectedBg;
private Drawable unSelectedBg;
private int selectColor = -1;
private int unSelectColor = -1;
private boolean showDelete = false;
public CategoryAdapter(@Nullable List<OrderCategoryBean.FoodCategoryTrees> data, Context context) {
super(R.layout.item_base_category, data);
addChildClickViewIds(R.id.iv_category_delete);
selectedBg = ContextCompat.getDrawable(context, R.drawable.shape_left_radio_shadow);
unSelectedBg = ContextCompat.getDrawable(context, R.color.trans);
}
@Override
protected void convert(@NotNull BaseViewHolder viewHolder, OrderCategoryBean.FoodCategoryTrees categoryBean) {
TextView tvCategoryName = viewHolder.getView(R.id.tv_category_name);
tvCategoryName.setText(categoryBean.getName());
CardView view = viewHolder.getView(R.id.layout_category);
if (viewHolder.getAdapterPosition() == selectedIndex) {
if (selectedBg != null) {
view.setBackground(selectedBg);
}
if (selectColor != -1) {
tvCategoryName.setTextColor(selectColor);
}
tvCategoryName.setSelected(true);
} else {
tvCategoryName.setSelected(false);
if (unSelectedBg != null) {
view.setBackground(unSelectedBg);
}
if (unSelectColor != -1) {
tvCategoryName.setTextColor(unSelectColor);
}
}
viewHolder.setGone(R.id.iv_category_delete, !showDelete);
}
public void setShowDelete(boolean showDelete) {
this.showDelete = showDelete;
notifyDataSetChanged();
}
public CategoryAdapter setSelectedBg(Drawable selectedBg) {
this.selectedBg = selectedBg;
return this;
}
public CategoryAdapter setUnSelectedBg(Drawable unSelectedBg) {
this.unSelectedBg = unSelectedBg;
return this;
}
public CategoryAdapter setSelectColor(int selectColor) {
this.selectColor = selectColor;
return this;
}
public CategoryAdapter setUnSelectColor(int unSelectColor) {
this.unSelectColor = unSelectColor;
return this;
}
public void setSelectedIndex(int selectedIndex) {
this.selectedIndex = selectedIndex;
notifyDataSetChanged();
}
public int getSelectedIndex() {
return selectedIndex;
}
}
...@@ -3,15 +3,14 @@ package com.gingersoft.supply_chain.mvp.ui.adapter; ...@@ -3,15 +3,14 @@ package com.gingersoft.supply_chain.mvp.ui.adapter;
import android.text.Editable; import android.text.Editable;
import android.text.InputFilter; import android.text.InputFilter;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText; import android.widget.EditText;
import com.chad.library.adapter.base.BaseQuickAdapter; import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder; import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.gingersoft.gsa.cloud.common.utils.MoneyUtil;
import com.gingersoft.gsa.cloud.common.utils.inputFilter.InputFilterUtils; import com.gingersoft.gsa.cloud.common.utils.inputFilter.InputFilterUtils;
import com.gingersoft.gsa.cloud.common.utils.other.TextUtil; import com.gingersoft.gsa.cloud.common.utils.other.TextUtil;
import com.gingersoft.supply_chain.R; import com.gingersoft.supply_chain.R;
import com.gingersoft.supply_chain.mvp.bean.BasicUnitBean;
import com.gingersoft.supply_chain.mvp.bean.DeputyUnitBean; import com.gingersoft.supply_chain.mvp.bean.DeputyUnitBean;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
...@@ -39,7 +38,7 @@ public class DeputyUnitAdapter extends BaseQuickAdapter<DeputyUnitBean, BaseView ...@@ -39,7 +38,7 @@ public class DeputyUnitAdapter extends BaseQuickAdapter<DeputyUnitBean, BaseView
EditText edConversionMultiple = viewHolder.getView(R.id.ed_deputy_unit_conversion_multiple); EditText edConversionMultiple = viewHolder.getView(R.id.ed_deputy_unit_conversion_multiple);
viewHolder.setText(R.id.tv_deputy_unit_title, "副單位" + (viewHolder.getAdapterPosition() + 1)); viewHolder.setText(R.id.tv_deputy_unit_title, "副單位" + (viewHolder.getAdapterPosition() + 1));
viewHolder.setText(R.id.ed_deputy_unit_name, item.getDeputyUnit()); viewHolder.setText(R.id.ed_deputy_unit_name, item.getDeputyUnit());
viewHolder.setText(R.id.ed_deputy_unit_conversion_multiple, item.getConversionMultiple() + ""); viewHolder.setText(R.id.ed_deputy_unit_conversion_multiple, MoneyUtil.formatDouble(item.getConversionMultiple()));
//副單位換算倍數 //副單位換算倍數
TextWatcher deputyUnitNameWatcher = new TextWatcher() { TextWatcher deputyUnitNameWatcher = new TextWatcher() {
@Override @Override
...@@ -77,11 +76,14 @@ public class DeputyUnitAdapter extends BaseQuickAdapter<DeputyUnitBean, BaseView ...@@ -77,11 +76,14 @@ public class DeputyUnitAdapter extends BaseQuickAdapter<DeputyUnitBean, BaseView
DeputyUnitBean deputyUnitBean = getData().get(viewHolder.getAdapterPosition()); DeputyUnitBean deputyUnitBean = getData().get(viewHolder.getAdapterPosition());
if (TextUtil.isNotEmptyOrNullOrUndefined(s + "")) { if (TextUtil.isNotEmptyOrNullOrUndefined(s + "")) {
deputyUnitBean.setConversionMultiple(Double.parseDouble(s + "")); deputyUnitBean.setConversionMultiple(Double.parseDouble(s + ""));
} else {
deputyUnitBean.setConversionMultiple(Double.parseDouble("0"));
edConversionMultiple.setText("0");
} }
} }
}; };
setFocusChangeListener(edConversionMultiple, conversionMultipleWatcher); setFocusChangeListener(edConversionMultiple, conversionMultipleWatcher);
edConversionMultiple.setFilters(new InputFilter[]{InputFilterUtils.getNumberFilter(edDeputyUnitName.getContext())});
if (TextUtil.isEmptyOrNullOrUndefined(item.getDeputyUnit())) { if (TextUtil.isEmptyOrNullOrUndefined(item.getDeputyUnit())) {
edDeputyUnitName.requestFocus(); edDeputyUnitName.requestFocus();
} }
......
package com.gingersoft.supply_chain.mvp.ui.adapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.gingersoft.gsa.cloud.ui.R;
import com.gingersoft.gsa.cloud.ui.adapter.BaseSelectorAdapter;
import com.gingersoft.gsa.cloud.ui.bean.view.CategoryBean;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
/**
* @author 宇航.
* User: admin
* Date: 2020/11/28
* Time: 11:45
* Use:
*/
public class LeftCategoryAdapter extends BaseSelectorAdapter<CategoryBean, BaseViewHolder> {
private boolean showDelete = false;
public LeftCategoryAdapter(@Nullable List<CategoryBean> data) {
super(R.layout.item_base_category, data);
addChildClickViewIds(R.id.iv_category_delete);
}
@Override
protected void convert(@NotNull BaseViewHolder viewHolder, CategoryBean categoryBean) {
viewHolder.setText(R.id.tv_base_item_title, categoryBean.getCategoryName());
notifyCheckState(viewHolder.getAdapterPosition(), viewHolder.getView(R.id.tv_base_item_title), viewHolder.getView(R.id.item_layout_root));
viewHolder.setGone(R.id.iv_category_delete, !showDelete);
}
@Override
public void onBindViewHolder(@NotNull BaseViewHolder holder, int position, @NotNull List<Object> payloads) {
super.onBindViewHolder(holder, position, payloads);
//list为空时,必须调用两个参数的onBindViewHolder(@NonNull LabelHolder holder, int position)
if (payloads.isEmpty()) {
onBindViewHolder(holder, position);
} else {
notifyCheckState(position, holder.getView(R.id.tv_base_item_title), holder.getView(R.id.item_layout_root));
}
}
public void setShowDelete(boolean showDelete) {
this.showDelete = showDelete;
notifyDataSetChanged();
}
}
package com.gingersoft.supply_chain.mvp.ui.adapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.cardview.widget.CardView;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.gingersoft.gsa.cloud.common.utils.CollectionUtils;
import com.gingersoft.gsa.cloud.ui.adapter.BaseSelectorAdapter;
import com.gingersoft.gsa.cloud.ui.view.textview.SuperTextView;
import com.gingersoft.supply_chain.R;
import com.gingersoft.supply_chain.mvp.bean.PurchaseFoodBean;
import com.gingersoft.supply_chain.mvp.bean.PurchaseOrderDetailsBean;
import com.qmuiteam.qmui.alpha.QMUIAlphaTextView;
import com.qmuiteam.qmui.util.QMUIDisplayHelper;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
/**
* @author 宇航.
* User: admin
* Date: 2021/4/20
* Time: 12:16
* Use:
*/
public class SnNameAdapter extends BaseSelectorAdapter<PurchaseOrderDetailsBean.PurchaseOrderDetailsInfoVosBean, BaseViewHolder> {
public SnNameAdapter(@Nullable List<PurchaseOrderDetailsBean.PurchaseOrderDetailsInfoVosBean> data) {
super(R.layout.item_base_selector, data);
if (CollectionUtils.isNotNullOrEmpty(data)) {
setSelectedIndex(0);
}
}
@Override
protected void convert(@NotNull BaseViewHolder viewHolder, PurchaseOrderDetailsBean.PurchaseOrderDetailsInfoVosBean purchaseOrderDetailsInfoVosBean) {
AppCompatTextView superTextView = viewHolder.getView(R.id.tv_base_select_title);
AppCompatTextView tvSn = viewHolder.getView(R.id.tv_sn);
CardView cardView = viewHolder.getView(R.id.card_base_select_layout);
if (purchaseOrderDetailsInfoVosBean.getFoodMarkSn() == PurchaseFoodBean.HAS_SN) {
//SN食材
tvSn.setVisibility(View.VISIBLE);
} else {
tvSn.setVisibility(View.GONE);
}
superTextView.setText(purchaseOrderDetailsInfoVosBean.getName());
switch (purchaseOrderDetailsInfoVosBean.getStatus()) {
case PurchaseOrderDetailsBean.PART_RECEIVED:
//部分收貨
cardView.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.shape_orange_twelve_radius));
tvSn.setTextColor(ContextCompat.getColor(getContext(), R.color.white));
superTextView.setTextColor(ContextCompat.getColor(getContext(), R.color.white));
break;
case PurchaseOrderDetailsBean.COMPLETE_RECEIVED:
//全部
cardView.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.shape_red_twelve_radius));
tvSn.setTextColor(ContextCompat.getColor(getContext(), R.color.white));
superTextView.setTextColor(ContextCompat.getColor(getContext(), R.color.white));
break;
default:
//默認
cardView.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.shape_them_border_twelve_white_bg));
tvSn.setTextColor(ContextCompat.getColor(getContext(), R.color.required_color));
superTextView.setTextColor(ContextCompat.getColor(getContext(), R.color.color_3c));
break;
}
RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) cardView.getLayoutParams();
//bottom留3dp。陰影好看些
if (viewHolder.getAdapterPosition() == 0) {
//第一個
//左間距為15
layoutParams.setMargins(QMUIDisplayHelper.dp2px(getContext(), 15), 0, 0, QMUIDisplayHelper.dp2px(getContext(), 3));
cardView.setLayoutParams(layoutParams);
} else if (viewHolder.getAdapterPosition() == getItemCount() - 1) {
//最後一個
//左間距為8,右間距為15
layoutParams.setMargins(QMUIDisplayHelper.dp2px(getContext(), 8), 0, QMUIDisplayHelper.dp2px(getContext(), 15), QMUIDisplayHelper.dp2px(getContext(), 3));
cardView.setLayoutParams(layoutParams);
} else {
//左間距為8,右間距為0
layoutParams.setMargins(QMUIDisplayHelper.dp2px(getContext(), 8), 0, 0, QMUIDisplayHelper.dp2px(getContext(), 3));
cardView.setLayoutParams(layoutParams);
}
}
}
...@@ -17,7 +17,6 @@ import androidx.recyclerview.widget.RecyclerView; ...@@ -17,7 +17,6 @@ import androidx.recyclerview.widget.RecyclerView;
import com.gingersoft.gsa.cloud.common.loadsir.EmptyCallback; import com.gingersoft.gsa.cloud.common.loadsir.EmptyCallback;
import com.gingersoft.gsa.cloud.common.loadsir.ErrorCallback; import com.gingersoft.gsa.cloud.common.loadsir.ErrorCallback;
import com.gingersoft.gsa.cloud.common.utils.other.TextUtil; import com.gingersoft.gsa.cloud.common.utils.other.TextUtil;
import com.gingersoft.gsa.cloud.ui.adapter.BaseCategoryAdapter;
import com.gingersoft.gsa.cloud.ui.bean.view.CategoryBean; import com.gingersoft.gsa.cloud.ui.bean.view.CategoryBean;
import com.gingersoft.gsa.cloud.ui.utils.AppDialog; import com.gingersoft.gsa.cloud.ui.utils.AppDialog;
import com.gingersoft.supply_chain.R; import com.gingersoft.supply_chain.R;
...@@ -29,6 +28,7 @@ import com.gingersoft.supply_chain.mvp.content.SupplyShoppingCart; ...@@ -29,6 +28,7 @@ import com.gingersoft.supply_chain.mvp.content.SupplyShoppingCart;
import com.gingersoft.supply_chain.mvp.contract.FoodIngredientsContract; import com.gingersoft.supply_chain.mvp.contract.FoodIngredientsContract;
import com.gingersoft.supply_chain.mvp.presenter.FoodIngredientsPresenter; import com.gingersoft.supply_chain.mvp.presenter.FoodIngredientsPresenter;
import com.gingersoft.supply_chain.mvp.ui.adapter.FoodListAdapter; import com.gingersoft.supply_chain.mvp.ui.adapter.FoodListAdapter;
import com.gingersoft.supply_chain.mvp.ui.adapter.LeftCategoryAdapter;
import com.gingersoft.supply_chain.mvp.ui.adapter.OrderCategoryAdapter; import com.gingersoft.supply_chain.mvp.ui.adapter.OrderCategoryAdapter;
import com.gingersoft.supply_chain.mvp.ui.fragment.BaseSupplyChainFragment; import com.gingersoft.supply_chain.mvp.ui.fragment.BaseSupplyChainFragment;
import com.gingersoft.supply_chain.mvp.ui.fragment.order.ShoppingCatFragment; import com.gingersoft.supply_chain.mvp.ui.fragment.order.ShoppingCatFragment;
...@@ -146,7 +146,7 @@ public class FoodIngredientsFragment extends BaseSupplyChainFragment<FoodIngredi ...@@ -146,7 +146,7 @@ public class FoodIngredientsFragment extends BaseSupplyChainFragment<FoodIngredi
*/ */
private int currentLevelCategory = OrderCategoryAdapter.PRIMARY_CATEGORY; private int currentLevelCategory = OrderCategoryAdapter.PRIMARY_CATEGORY;
private BaseCategoryAdapter listSelectAdapter; private LeftCategoryAdapter listSelectAdapter;
public static FoodIngredientsFragment newInstance(int pageType) { public static FoodIngredientsFragment newInstance(int pageType) {
FoodIngredientsFragment fragment = new FoodIngredientsFragment(); FoodIngredientsFragment fragment = new FoodIngredientsFragment();
...@@ -362,7 +362,7 @@ public class FoodIngredientsFragment extends BaseSupplyChainFragment<FoodIngredi ...@@ -362,7 +362,7 @@ public class FoodIngredientsFragment extends BaseSupplyChainFragment<FoodIngredi
supplierId = categoryBeans.get(0).getId(); supplierId = categoryBeans.get(0).getId();
} }
if (listSelectAdapter == null) { if (listSelectAdapter == null) {
listSelectAdapter = new BaseCategoryAdapter(R.layout.item_base_category, categoryBeans); listSelectAdapter = new LeftCategoryAdapter(categoryBeans);
listSelectAdapter.setUnSelectColor(ContextCompat.getColor(mContext, R.color.color_3c)) listSelectAdapter.setUnSelectColor(ContextCompat.getColor(mContext, R.color.color_3c))
.setSelectColor(ContextCompat.getColor(mContext, R.color.theme_color)); .setSelectColor(ContextCompat.getColor(mContext, R.color.theme_color));
listSelectAdapter.setOnItemClickListener((adapter, view, position) -> { listSelectAdapter.setOnItemClickListener((adapter, view, position) -> {
......
package com.gingersoft.supply_chain.mvp.ui.fragment.food; package com.gingersoft.supply_chain.mvp.ui.fragment.food;
import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.text.InputFilter; import android.text.InputFilter;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window; import android.view.Window;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
...@@ -28,12 +27,10 @@ import com.gingersoft.supply_chain.mvp.presenter.FoodUnitPagePresenter; ...@@ -28,12 +27,10 @@ import com.gingersoft.supply_chain.mvp.presenter.FoodUnitPagePresenter;
import com.gingersoft.supply_chain.mvp.ui.adapter.BasicUnitAdapter; import com.gingersoft.supply_chain.mvp.ui.adapter.BasicUnitAdapter;
import com.gingersoft.supply_chain.mvp.ui.adapter.DeputyUnitAdapter; import com.gingersoft.supply_chain.mvp.ui.adapter.DeputyUnitAdapter;
import com.gingersoft.supply_chain.mvp.ui.fragment.BaseSupplyChainFragment; import com.gingersoft.supply_chain.mvp.ui.fragment.BaseSupplyChainFragment;
import com.gingersoft.supply_chain.mvp.ui.fragment.order.OrderDetailsFragment;
import com.gingersoft.supply_chain.mvp.ui.widget.EditTextPopup; import com.gingersoft.supply_chain.mvp.ui.widget.EditTextPopup;
import com.gingersoft.supply_chain.mvp.utils.NotDispatchListener; import com.gingersoft.supply_chain.mvp.utils.NotDispatchListener;
import com.jess.arms.di.component.AppComponent; import com.jess.arms.di.component.AppComponent;
import com.lxj.xpopup.XPopup; import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.interfaces.OnCancelListener;
import com.qmuiteam.qmui.alpha.QMUIAlphaTextView; import com.qmuiteam.qmui.alpha.QMUIAlphaTextView;
import com.qmuiteam.qmui.widget.QMUITopBar; import com.qmuiteam.qmui.widget.QMUITopBar;
...@@ -116,11 +113,16 @@ public class FoodUnitPageFragment extends BaseSupplyChainFragment<FoodUnitPagePr ...@@ -116,11 +113,16 @@ public class FoodUnitPageFragment extends BaseSupplyChainFragment<FoodUnitPagePr
@Override @Override
public void initData(@Nullable Bundle savedInstanceState) { public void initData(@Nullable Bundle savedInstanceState) {
getView().setOnTouchListener((v, event) -> {
hideSoftInput();
return false;
});
mPresenter.initData(getArguments()); mPresenter.initData(getArguments());
edBasicUnit.setFilters(new InputFilter[]{InputFilterUtils.getLengthFilter(requireContext(), 5), InputFilterUtils.getChAndEnAndNumInputFilter(requireContext())}); edBasicUnit.setFilters(new InputFilter[]{InputFilterUtils.getLengthFilter(requireContext(), 5), InputFilterUtils.getChAndEnAndNumInputFilter(requireContext())});
edBasicUnit.requestFocus(); edBasicUnit.requestFocus();
} }
@OnClick({R2.id.tv_add_deputy, R2.id.tv_food_unit_complete}) @OnClick({R2.id.tv_add_deputy, R2.id.tv_food_unit_complete})
public void onClick(View view) { public void onClick(View view) {
int viewId = view.getId(); int viewId = view.getId();
...@@ -134,6 +136,7 @@ public class FoodUnitPageFragment extends BaseSupplyChainFragment<FoodUnitPagePr ...@@ -134,6 +136,7 @@ public class FoodUnitPageFragment extends BaseSupplyChainFragment<FoodUnitPagePr
if (TextUtil.isEmptyOrNullOrUndefined(basicUnit)) { if (TextUtil.isEmptyOrNullOrUndefined(basicUnit)) {
showMessage("請輸入基本單位"); showMessage("請輸入基本單位");
edBasicUnit.setError("請輸入基本單位"); edBasicUnit.setError("請輸入基本單位");
edBasicUnit.requestFocus();
return; return;
} }
if (deputyUnitAdapter != null && deputyUnitAdapter.getItemCount() > 0) { if (deputyUnitAdapter != null && deputyUnitAdapter.getItemCount() > 0) {
......
...@@ -142,6 +142,7 @@ public class NewFoodIngredientsFragment extends BaseSupplyChainFragment<NewFoodI ...@@ -142,6 +142,7 @@ public class NewFoodIngredientsFragment extends BaseSupplyChainFragment<NewFoodI
isUpdate = false; isUpdate = false;
initTopBar(topbarNewFoodIngredients, "新增食材"); initTopBar(topbarNewFoodIngredients, "新增食材");
purchaseFoodBean = new PurchaseFoodBean(); purchaseFoodBean = new PurchaseFoodBean();
purchaseFoodBean.setFoodMarkSn(-1);
//拿到分類集合 //拿到分類集合
String categoryName = arguments.getString(CATEGORY_NAME_KEY); String categoryName = arguments.getString(CATEGORY_NAME_KEY);
if (TextUtil.isNotEmptyOrNullOrUndefined(categoryName)) { if (TextUtil.isNotEmptyOrNullOrUndefined(categoryName)) {
...@@ -300,8 +301,7 @@ public class NewFoodIngredientsFragment extends BaseSupplyChainFragment<NewFoodI ...@@ -300,8 +301,7 @@ public class NewFoodIngredientsFragment extends BaseSupplyChainFragment<NewFoodI
public boolean onBackPressedSupport() { public boolean onBackPressedSupport() {
if (mPresenter.isUpdate(infoMultiAdapter.getData()) && !isLeave) { if (mPresenter.isUpdate(infoMultiAdapter.getData()) && !isLeave) {
//用戶修改了數據,提示是否保存 //用戶修改了數據,提示是否保存
AppDialog.getInstance().showTipDialog(requireContext(), getString(R.string.str_info_no_save_leave), getString(R.string.str_save), getString(R.string.str_leave), (view, dialog) -> { AppDialog.getInstance().showTipDialog(requireContext(), getString(R.string.str_about_to_leave), getString(R.string.str_yes), getString(R.string.str_no), (view, dialog) -> {
dialog.dismiss();
saveGoodsInfo(); saveGoodsInfo();
}, (view, dialog) -> { }, (view, dialog) -> {
isLeave = true; isLeave = true;
......
package com.gingersoft.supply_chain.mvp.ui.fragment.order; package com.gingersoft.supply_chain.mvp.ui.fragment.order;
import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Color; import android.graphics.Color;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.text.InputFilter; import android.text.InputFilter;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
...@@ -20,18 +20,18 @@ import android.widget.TextView; ...@@ -20,18 +20,18 @@ import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.Target; import com.bumptech.glide.request.target.Target;
import com.chad.library.adapter.base.BaseQuickAdapter; import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemChildClickListener;
import com.gingersoft.gsa.cloud.common.utils.CollectionUtils; import com.gingersoft.gsa.cloud.common.utils.CollectionUtils;
import com.gingersoft.gsa.cloud.common.utils.FileUtils; import com.gingersoft.gsa.cloud.common.utils.FileUtils;
import com.gingersoft.gsa.cloud.common.utils.MoneyUtil; import com.gingersoft.gsa.cloud.common.utils.MoneyUtil;
import com.gingersoft.gsa.cloud.common.utils.glide.GlideUtils;
import com.gingersoft.gsa.cloud.common.utils.inputFilter.InputFilterUtils; import com.gingersoft.gsa.cloud.common.utils.inputFilter.InputFilterUtils;
import com.gingersoft.gsa.cloud.common.utils.other.TextUtil; import com.gingersoft.gsa.cloud.common.utils.other.TextUtil;
import com.gingersoft.gsa.cloud.common.utils.time.TimeUtils; import com.gingersoft.gsa.cloud.common.utils.time.TimeUtils;
...@@ -45,30 +45,26 @@ import com.gingersoft.supply_chain.mvp.bean.DeputyUnitBean; ...@@ -45,30 +45,26 @@ import com.gingersoft.supply_chain.mvp.bean.DeputyUnitBean;
import com.gingersoft.supply_chain.mvp.bean.PurchaseFoodBean; import com.gingersoft.supply_chain.mvp.bean.PurchaseFoodBean;
import com.gingersoft.supply_chain.mvp.bean.PurchaseFoodEncodeSn; import com.gingersoft.supply_chain.mvp.bean.PurchaseFoodEncodeSn;
import com.gingersoft.supply_chain.mvp.bean.PurchaseOrderDetailsBean; import com.gingersoft.supply_chain.mvp.bean.PurchaseOrderDetailsBean;
import com.gingersoft.supply_chain.mvp.bean.WareHousingUnitBean;
import com.gingersoft.supply_chain.mvp.contract.OrderDetailsContract; import com.gingersoft.supply_chain.mvp.contract.OrderDetailsContract;
import com.gingersoft.supply_chain.mvp.presenter.OrderDetailsPresenter; import com.gingersoft.supply_chain.mvp.presenter.OrderDetailsPresenter;
import com.gingersoft.supply_chain.mvp.ui.adapter.ImageAdapter; import com.gingersoft.supply_chain.mvp.ui.adapter.ImageAdapter;
import com.gingersoft.supply_chain.mvp.ui.adapter.OrderDetailsFoodAdapter; import com.gingersoft.supply_chain.mvp.ui.adapter.OrderDetailsFoodAdapter;
import com.gingersoft.supply_chain.mvp.ui.adapter.SnNameAdapter;
import com.gingersoft.supply_chain.mvp.ui.fragment.BaseSupplyChainFragment; import com.gingersoft.supply_chain.mvp.ui.fragment.BaseSupplyChainFragment;
import com.gingersoft.supply_chain.mvp.ui.widget.CenterLayoutManager;
import com.gingersoft.supply_chain.mvp.ui.widget.ChooseUnitPopup; import com.gingersoft.supply_chain.mvp.ui.widget.ChooseUnitPopup;
import com.gingersoft.supply_chain.mvp.ui.widget.PurchaseListMorePopup; import com.gingersoft.supply_chain.mvp.ui.widget.PurchaseListMorePopup;
import com.gingersoft.supply_chain.mvp.ui.widget.ScanSnPopup; import com.gingersoft.supply_chain.mvp.ui.widget.ScanSnPopup;
import com.gingersoft.supply_chain.mvp.ui.widget.ScanSnView;
import com.gingersoft.supply_chain.mvp.utils.SelectPicture; import com.gingersoft.supply_chain.mvp.utils.SelectPicture;
import com.gingersoft.supply_chain.mvp.utils.ViewUtils;
import com.google.android.material.checkbox.MaterialCheckBox; import com.google.android.material.checkbox.MaterialCheckBox;
import com.google.android.material.textfield.TextInputLayout; import com.google.android.material.textfield.TextInputLayout;
import com.jess.arms.di.component.AppComponent; import com.jess.arms.di.component.AppComponent;
import com.jess.arms.http.imageloader.ImageLoader;
import com.lxj.xpopup.XPopup; import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.BasePopupView;
import com.lxj.xpopup.core.ImageViewerPopupView;
import com.lxj.xpopup.enums.PopupPosition; import com.lxj.xpopup.enums.PopupPosition;
import com.lxj.xpopup.interfaces.OnSelectListener; import com.lxj.xpopup.interfaces.OnSelectListener;
import com.lxj.xpopup.interfaces.XPopupCallback;
import com.lxj.xpopup.interfaces.XPopupImageLoader; import com.lxj.xpopup.interfaces.XPopupImageLoader;
import com.qmuiteam.qmui.alpha.QMUIAlphaTextView; import com.qmuiteam.qmui.alpha.QMUIAlphaTextView;
import com.qmuiteam.qmui.util.QMUIDisplayHelper;
import com.qmuiteam.qmui.widget.QMUITopBar; import com.qmuiteam.qmui.widget.QMUITopBar;
import com.yalantis.ucrop.UCrop; import com.yalantis.ucrop.UCrop;
...@@ -76,7 +72,6 @@ import java.io.File; ...@@ -76,7 +72,6 @@ import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import butterknife.BindView; import butterknife.BindView;
import butterknife.OnClick; import butterknife.OnClick;
...@@ -124,8 +119,8 @@ public class OrderDetailsFragment extends BaseSupplyChainFragment<OrderDetailsPr ...@@ -124,8 +119,8 @@ public class OrderDetailsFragment extends BaseSupplyChainFragment<OrderDetailsPr
TextInputLayout layoutInputRemark; TextInputLayout layoutInputRemark;
@BindView(R2.id.ed_warehouse_order_remark) @BindView(R2.id.ed_warehouse_order_remark)
EditText edRemark; EditText edRemark;
// @BindView(R2.id.layout_ed_remark) @BindView(R2.id.card_show_more_food_name)
// LinearLayout layoutEdRemark; CardView cardMoreFoodName;
private OrderDetailsFoodAdapter orderDetailsFoodAdapter; private OrderDetailsFoodAdapter orderDetailsFoodAdapter;
...@@ -186,7 +181,7 @@ public class OrderDetailsFragment extends BaseSupplyChainFragment<OrderDetailsPr ...@@ -186,7 +181,7 @@ public class OrderDetailsFragment extends BaseSupplyChainFragment<OrderDetailsPr
} }
@OnClick({R2.id.tv_order_details_partial_receipt, R2.id.tv_order_details_receipt, R2.id.layout_remarks}) @OnClick({R2.id.tv_order_details_partial_receipt, R2.id.tv_order_details_receipt, R2.id.layout_remarks, R2.id.card_show_more_food_name})
@Override @Override
public void onClick(View v) { public void onClick(View v) {
int viewId = v.getId(); int viewId = v.getId();
...@@ -222,6 +217,9 @@ public class OrderDetailsFragment extends BaseSupplyChainFragment<OrderDetailsPr ...@@ -222,6 +217,9 @@ public class OrderDetailsFragment extends BaseSupplyChainFragment<OrderDetailsPr
} else if (viewId == R.id.layout_remarks) { } else if (viewId == R.id.layout_remarks) {
//備註,顯示備註輸入框 //備註,顯示備註輸入框
layoutInputRemark.setVisibility(layoutInputRemark.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE); layoutInputRemark.setVisibility(layoutInputRemark.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE);
} else if (viewId == R.id.card_show_more_food_name) {
//展開食品名稱彈窗
} }
} }
...@@ -311,6 +309,7 @@ public class OrderDetailsFragment extends BaseSupplyChainFragment<OrderDetailsPr ...@@ -311,6 +309,7 @@ public class OrderDetailsFragment extends BaseSupplyChainFragment<OrderDetailsPr
break; break;
} }
setTypesOfFood(); setTypesOfFood();
initRecyclerView(orderDetailsBean); initRecyclerView(orderDetailsBean);
//全選按鈕狀態切換 //全選按鈕狀態切換
cbOrderDetailsAllSelected.setOnCheckedChangeListener((buttonView, isChecked) -> { cbOrderDetailsAllSelected.setOnCheckedChangeListener((buttonView, isChecked) -> {
...@@ -450,8 +449,14 @@ public class OrderDetailsFragment extends BaseSupplyChainFragment<OrderDetailsPr ...@@ -450,8 +449,14 @@ public class OrderDetailsFragment extends BaseSupplyChainFragment<OrderDetailsPr
} }
private void initRecyclerView(PurchaseOrderDetailsBean orderDetailsBean) { private void initRecyclerView(PurchaseOrderDetailsBean orderDetailsBean) {
rvOrderDetailsFoodName.setLayoutManager(new CenterLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
SnNameAdapter snNameAdapter = new SnNameAdapter(orderDetailsBean.getPurchaseOrderDetailsInfoVOS());
rvOrderDetailsFoodName.setAdapter(snNameAdapter);
orderDetailsFoodAdapter = new OrderDetailsFoodAdapter(mContext, orderDetailsBean.getPurchaseOrderDetailsInfoVOS()); orderDetailsFoodAdapter = new OrderDetailsFoodAdapter(mContext, orderDetailsBean.getPurchaseOrderDetailsInfoVOS());
rvOrderDetailsFoodList.setAdapter(orderDetailsFoodAdapter); rvOrderDetailsFoodList.setAdapter(orderDetailsFoodAdapter);
rvOrderDetailsFoodList.setLayoutManager(new CenterLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false));
orderDetailsFoodAdapter.setOnAmountChangeListener((position, value) -> { orderDetailsFoodAdapter.setOnAmountChangeListener((position, value) -> {
totalAmount = MoneyUtil.sum(totalAmount, value); totalAmount = MoneyUtil.sum(totalAmount, value);
setTotalAmount(); setTotalAmount();
...@@ -474,6 +479,7 @@ public class OrderDetailsFragment extends BaseSupplyChainFragment<OrderDetailsPr ...@@ -474,6 +479,7 @@ public class OrderDetailsFragment extends BaseSupplyChainFragment<OrderDetailsPr
}); });
orderDetailsFoodAdapter.setOnItemChildClickListener((adapter, view, position) -> { orderDetailsFoodAdapter.setOnItemChildClickListener((adapter, view, position) -> {
int id = view.getId(); int id = view.getId();
//食材單位點擊事件
if (id == R.id.layout_order_details_unit) { if (id == R.id.layout_order_details_unit) {
//切換單位 //切換單位
PurchaseOrderDetailsBean.PurchaseOrderDetailsInfoVosBean purchaseOrderDetailsInfoVosBean = orderDetailsFoodAdapter.getData().get(position); PurchaseOrderDetailsBean.PurchaseOrderDetailsInfoVosBean purchaseOrderDetailsInfoVosBean = orderDetailsFoodAdapter.getData().get(position);
...@@ -504,6 +510,37 @@ public class OrderDetailsFragment extends BaseSupplyChainFragment<OrderDetailsPr ...@@ -504,6 +510,37 @@ public class OrderDetailsFragment extends BaseSupplyChainFragment<OrderDetailsPr
} }
} }
}); });
// setMoreNameCard();
snNameAdapter.setOnItemClickListener((adapter, view, position) -> {
//點擊滑動到對應的食品
rvOrderDetailsFoodList.smoothScrollToPosition(position);
ViewUtils.moveToCenterByHorizontal(rvOrderDetailsFoodName, position);
// ViewUtils.moveToCenterByVertical(rvOrderDetailsFoodList, position);
LinearLayoutManager layoutManager = (LinearLayoutManager) rvOrderDetailsFoodList.getLayoutManager();
layoutManager.scrollToPositionWithOffset(position, 0);
View childAt = layoutManager.findViewByPosition(position);
if (childAt != null) {
Animation alphaAnimation = new AlphaAnimation(1.0f, 0.2f);
alphaAnimation.setDuration(600);
alphaAnimation.setFillBefore(true);
alphaAnimation.setInterpolator(new LinearInterpolator());
alphaAnimation.setRepeatCount(2);
alphaAnimation.setRepeatMode(Animation.REVERSE);
childAt.startAnimation(alphaAnimation);
}
});
}
/**
* 設置展開更多名稱的view高度
*/
private void setMoreNameCard() {
cardMoreFoodName.post(() -> {
int measuredHeight = cardMoreFoodName.getMeasuredHeight();
ViewGroup.LayoutParams layoutParams = cardMoreFoodName.getLayoutParams();
layoutParams.width = measuredHeight;
cardMoreFoodName.setLayoutParams(layoutParams);
});
} }
/** /**
......
...@@ -120,7 +120,6 @@ public class ShoppingCatFragment extends BaseSupplyChainFragment<ShoppingCatPres ...@@ -120,7 +120,6 @@ public class ShoppingCatFragment extends BaseSupplyChainFragment<ShoppingCatPres
if (mPresenter.filterData(shoppingCartAdapter.getData())) { if (mPresenter.filterData(shoppingCartAdapter.getData())) {
AppDialog.getInstance().showTipDialog(requireContext(), "確認創建訂單?", (view, dialog) -> { AppDialog.getInstance().showTipDialog(requireContext(), "確認創建訂單?", (view, dialog) -> {
mPresenter.createOrder(shoppingCartAdapter.getData()); mPresenter.createOrder(shoppingCartAdapter.getData());
dialog.dismiss();
}); });
} }
} else if (viewId == R.id.btn_order_content_order_template) { } else if (viewId == R.id.btn_order_content_order_template) {
......
...@@ -2,10 +2,8 @@ package com.gingersoft.supply_chain.mvp.ui.fragment.supplier; ...@@ -2,10 +2,8 @@ package com.gingersoft.supply_chain.mvp.ui.fragment.supplier;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.EditText;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
...@@ -17,12 +15,10 @@ import com.gingersoft.supply_chain.R; ...@@ -17,12 +15,10 @@ import com.gingersoft.supply_chain.R;
import com.gingersoft.supply_chain.R2; import com.gingersoft.supply_chain.R2;
import com.gingersoft.supply_chain.di.component.DaggerNewSupplierComponent; import com.gingersoft.supply_chain.di.component.DaggerNewSupplierComponent;
import com.gingersoft.supply_chain.mvp.bean.SupplierInfoBean; import com.gingersoft.supply_chain.mvp.bean.SupplierInfoBean;
import com.gingersoft.supply_chain.mvp.content.Constant;
import com.gingersoft.supply_chain.mvp.contract.NewSupplierContract; import com.gingersoft.supply_chain.mvp.contract.NewSupplierContract;
import com.gingersoft.supply_chain.mvp.presenter.NewSupplierPresenter; import com.gingersoft.supply_chain.mvp.presenter.NewSupplierPresenter;
import com.gingersoft.supply_chain.mvp.ui.fragment.BaseSupplyChainFragment; import com.gingersoft.supply_chain.mvp.ui.fragment.BaseSupplyChainFragment;
import com.jess.arms.di.component.AppComponent; import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.DeviceUtils;
import com.qmuiteam.qmui.alpha.QMUIAlphaButton; import com.qmuiteam.qmui.alpha.QMUIAlphaButton;
import com.qmuiteam.qmui.widget.QMUITopBar; import com.qmuiteam.qmui.widget.QMUITopBar;
......
...@@ -3,7 +3,6 @@ package com.gingersoft.supply_chain.mvp.ui.fragment.warehouse; ...@@ -3,7 +3,6 @@ package com.gingersoft.supply_chain.mvp.ui.fragment.warehouse;
import android.animation.LayoutTransition; import android.animation.LayoutTransition;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.os.Bundle; import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -142,6 +141,7 @@ public class WarehouseDetailsFragment extends BaseSupplyChainFragment<WarehouseD ...@@ -142,6 +141,7 @@ public class WarehouseDetailsFragment extends BaseSupplyChainFragment<WarehouseD
public void initData(@Nullable Bundle savedInstanceState) { public void initData(@Nullable Bundle savedInstanceState) {
Bundle arguments = getArguments(); Bundle arguments = getArguments();
smartRefreshLayout.setPrimaryColorsId(R.color.trans, R.color.black); smartRefreshLayout.setPrimaryColorsId(R.color.trans, R.color.black);
loadService = LoadSir.getDefault().register(smartRefreshLayout); loadService = LoadSir.getDefault().register(smartRefreshLayout);
LayoutTransition layoutTransition = new LayoutTransition(); LayoutTransition layoutTransition = new LayoutTransition();
layoutTransition.enableTransitionType(LayoutTransition.CHANGING); layoutTransition.enableTransitionType(LayoutTransition.CHANGING);
...@@ -156,7 +156,7 @@ public class WarehouseDetailsFragment extends BaseSupplyChainFragment<WarehouseD ...@@ -156,7 +156,7 @@ public class WarehouseDetailsFragment extends BaseSupplyChainFragment<WarehouseD
initTopBar(supplyTopBar, purchaseWarehousingOrderDetailsVO.getName()); initTopBar(supplyTopBar, purchaseWarehousingOrderDetailsVO.getName());
tvUnit.setText(purchaseWarehousingOrderDetailsVO.getUnitName()); tvUnit.setText(purchaseWarehousingOrderDetailsVO.getUnitName());
String foodImageUrl = arguments.getString(purchaseWarehousingOrderDetailsVO.getImages()); String foodImageUrl = purchaseWarehousingOrderDetailsVO.getImages();
if (TextUtil.isNotEmptyOrNullOrUndefined(foodImageUrl)) { if (TextUtil.isNotEmptyOrNullOrUndefined(foodImageUrl)) {
GlideUtils.display(requireContext(), ivFoodImg, foodImageUrl); GlideUtils.display(requireContext(), ivFoodImg, foodImageUrl);
} else { } else {
...@@ -419,7 +419,7 @@ public class WarehouseDetailsFragment extends BaseSupplyChainFragment<WarehouseD ...@@ -419,7 +419,7 @@ public class WarehouseDetailsFragment extends BaseSupplyChainFragment<WarehouseD
restaurantName.setText(String.format(getString(R.string.str_restaurant_outbound_order), RestaurantInfoManager.newInstance().getRestaurantName())); restaurantName.setText(String.format(getString(R.string.str_restaurant_outbound_order), RestaurantInfoManager.newInstance().getRestaurantName()));
tvDate.setText(TimeUtils.getCurrentDate(TimeUtils.DEFAULT_DATE_FORMAT_YMDHM)); tvDate.setText(TimeUtils.getCurrentDate(TimeUtils.DEFAULT_DATE_FORMAT_YMDHM));
tvFoodNo.setText(String.format(getString(R.string.str_no), purchaseWarehousingOrderDetailsVO.getFoodNo())); tvFoodNo.setText(String.format(getString(R.string.str_goods_no), purchaseWarehousingOrderDetailsVO.getFoodNo()));
tvUserName.setText(String.format(getString(R.string.str_prepared), UserContext.newInstance().getMemberName())); tvUserName.setText(String.format(getString(R.string.str_prepared), UserContext.newInstance().getMemberName()));
List<OutboundOrderBean> outboundOrderBeans = new ArrayList<>(); List<OutboundOrderBean> outboundOrderBeans = new ArrayList<>();
outboundOrderBeans.add(new OutboundOrderBean(getString(R.string.str_product_name), purchaseWarehousingOrderDetailsVO.getName())); outboundOrderBeans.add(new OutboundOrderBean(getString(R.string.str_product_name), purchaseWarehousingOrderDetailsVO.getName()));
...@@ -530,4 +530,5 @@ public class WarehouseDetailsFragment extends BaseSupplyChainFragment<WarehouseD ...@@ -530,4 +530,5 @@ public class WarehouseDetailsFragment extends BaseSupplyChainFragment<WarehouseD
} }
} }
} }
} }
...@@ -7,6 +7,7 @@ import android.view.View; ...@@ -7,6 +7,7 @@ import android.view.View;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.widget.EditText; import android.widget.EditText;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
...@@ -51,6 +52,7 @@ public class ScanSnView extends FrameLayout { ...@@ -51,6 +52,7 @@ public class ScanSnView extends FrameLayout {
@BindView(R2.id.rv_sn_code) @BindView(R2.id.rv_sn_code)
RecyclerView rvSnCode; RecyclerView rvSnCode;
int recyclerHeight = 0;
private SnCodeAdapter adapter; private SnCodeAdapter adapter;
@BindView(R2.id.btn_confirm_sn) @BindView(R2.id.btn_confirm_sn)
QMUIAlphaButton btnFoodIngredientsConfirm; QMUIAlphaButton btnFoodIngredientsConfirm;
...@@ -181,6 +183,14 @@ public class ScanSnView extends FrameLayout { ...@@ -181,6 +183,14 @@ public class ScanSnView extends FrameLayout {
btnScanSn.setVisibility(GONE); btnScanSn.setVisibility(GONE);
tvScanSn.setText(R.string.str_enter_sn); tvScanSn.setText(R.string.str_enter_sn);
} }
rvSnCode.post(() -> {
if (recyclerHeight == 0) {
recyclerHeight = rvSnCode.getMeasuredHeight();
}
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) rvSnCode.getLayoutParams();
layoutParams.height = recyclerHeight;
rvSnCode.setLayoutParams(layoutParams);
});
edInputSn.setOnEditorActionListener((v, actionId, event) -> { edInputSn.setOnEditorActionListener((v, actionId, event) -> {
if (actionId == EditorInfo.IME_ACTION_UNSPECIFIED) { if (actionId == EditorInfo.IME_ACTION_UNSPECIFIED) {
//響應回車按鈕 //響應回車按鈕
......
package com.gingersoft.supply_chain.mvp.ui.widget; package com.gingersoft.supply_chain.mvp.ui.widget;
import android.content.Context; import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.billy.cc.core.component.CC;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.gingersoft.gsa.cloud.common.utils.XPermissionUtils;
import com.gingersoft.gsa.cloud.common.utils.other.TextUtil;
import com.gingersoft.gsa.cloud.common.utils.toast.ToastUtils;
import com.gingersoft.gsa.cloud.component.ComponentName;
import com.gingersoft.gsa.cloud.ui.utils.AppDialog;
import com.gingersoft.supply_chain.R; import com.gingersoft.supply_chain.R;
import com.gingersoft.supply_chain.R2; import com.gingersoft.supply_chain.R2;
import com.gingersoft.supply_chain.mvp.bean.PurchaseFoodEncodeSn; import com.gingersoft.supply_chain.mvp.bean.PurchaseFoodEncodeSn;
import com.qmuiteam.qmui.alpha.QMUIAlphaButton;
import com.qmuiteam.qmui.alpha.QMUIAlphaImageButton;
import com.qmuiteam.qmui.alpha.QMUIAlphaTextView;
import org.jetbrains.annotations.NotNull;
import java.util.List; import java.util.List;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import cn.bingoogolapple.qrcode.core.BarcodeType;
import me.yokeyword.fragmentation.SupportHelper;
/** /**
* @author 宇航. * @author 宇航.
...@@ -50,6 +29,8 @@ public class ShowSnView extends FrameLayout { ...@@ -50,6 +29,8 @@ public class ShowSnView extends FrameLayout {
@BindView(R2.id.rv_sn_code) @BindView(R2.id.rv_sn_code)
RecyclerView rvSnCode; RecyclerView rvSnCode;
@BindView(R2.id.frame_sn_list)
FrameLayout snListLayout;
public ShowSnView(Context context, List<PurchaseFoodEncodeSn> snCodes) { public ShowSnView(Context context, List<PurchaseFoodEncodeSn> snCodes) {
super(context); super(context);
......
...@@ -39,7 +39,8 @@ public class ViewUtils { ...@@ -39,7 +39,8 @@ public class ViewUtils {
} }
//取得中間位置的item //取得中間位置的item
Log.e("eee", "需要選中:" + sectionPosition + "顯示的:" + layoutManager.findFirstVisibleItemPosition() + "子數量:" + recyclerView.getChildCount()); Log.e("eee", "需要選中:" + sectionPosition + "顯示的:" + layoutManager.findFirstVisibleItemPosition() + "子數量:" + recyclerView.getChildCount());
View childAt = recyclerView.getChildAt(sectionPosition - layoutManager.findFirstVisibleItemPosition()); // View childAt = recyclerView.getChildAt(sectionPosition - layoutManager.findFirstVisibleItemPosition());
View childAt = layoutManager.findViewByPosition(sectionPosition - layoutManager.findFirstVisibleItemPosition());
//拿到列表一半的寬度 //拿到列表一半的寬度
int halfLeftRvWidth = recyclerView.getWidth() / 2; int halfLeftRvWidth = recyclerView.getWidth() / 2;
Log.e("eee", childAt + "一半寬度:" + halfLeftRvWidth + "第一個:" + recyclerView.getChildAt(0)); Log.e("eee", childAt + "一半寬度:" + halfLeftRvWidth + "第一個:" + recyclerView.getChildAt(0));
......
...@@ -4,20 +4,31 @@ ...@@ -4,20 +4,31 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/color_f0"
android:orientation="vertical"> android:orientation="vertical">
<include layout="@layout/supply_chain_top_bar" /> <include layout="@layout/supply_chain_top_bar" />
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_f0"
android:orientation="vertical">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/dp_8"
android:background="@color/white" android:background="@color/white"
android:orientation="vertical" android:orientation="vertical"
android:paddingLeft="@dimen/dp_18" android:paddingLeft="@dimen/dp_18"
android:paddingRight="@dimen/dp_18" android:paddingRight="@dimen/dp_18"
android:paddingBottom="@dimen/dp_6" android:paddingBottom="@dimen/dp_6"
app:layout_collapseMode="parallax"> app:layout_scrollFlags="scroll|enterAlways">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
...@@ -142,30 +153,55 @@ ...@@ -142,30 +153,55 @@
android:layout_marginTop="@dimen/dp_10" /> android:layout_marginTop="@dimen/dp_10" />
</LinearLayout> </LinearLayout>
<HorizontalScrollView <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_10" android:orientation="horizontal">
android:visibility="gone">
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_order_details_food_name" android:id="@+id/rv_order_details_food_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/white"
android:paddingTop="@dimen/dp_7"
android:paddingBottom="@dimen/dp_7" />
<androidx.cardview.widget.CardView
android:id="@+id/card_show_more_food_name"
android:layout_width="@dimen/dp_38"
android:layout_height="match_parent"
android:background="@color/white"
android:visibility="gone"
app:cardElevation="@dimen/dp_10">
<ImageView
android:id="@+id/iv_unfold_arrow"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" /> android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/ic_inverted_triangle_66" />
</androidx.cardview.widget.CardView>
</LinearLayout>
</com.google.android.material.appbar.AppBarLayout>
</HorizontalScrollView>
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_order_details_food_list" android:id="@+id/rv_order_details_food_list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="match_parent"
android:layout_marginTop="@dimen/dp_10" app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:layout_weight="1" app:layout_behavior="@string/appbar_scrolling_view_behavior" />
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@color/white" android:background="@color/white"
android:elevation="@dimen/dp_10" android:elevation="@dimen/dp_10"
android:orientation="vertical"> android:orientation="vertical">
...@@ -225,14 +261,12 @@ ...@@ -225,14 +261,12 @@
tools:text="$300.00" /> tools:text="$300.00" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_horizontal" android:gravity="center_horizontal"
android:orientation="horizontal"> android:orientation="horizontal">
<com.qmuiteam.qmui.alpha.QMUIAlphaTextView <com.qmuiteam.qmui.alpha.QMUIAlphaTextView
android:id="@+id/tv_order_details_partial_receipt" android:id="@+id/tv_order_details_partial_receipt"
android:layout_width="0dp" android:layout_width="0dp"
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/supply_chain_bg_color"> android:background="@color/supply_chain_bg_color"
android:orientation="vertical">
<include layout="@layout/supply_chain_top_bar" />
<com.google.android.material.appbar.AppBarLayout <ScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:background="@color/trans"> android:fillViewport="true">
<include <LinearLayout
layout="@layout/supply_chain_top_bar" android:layout_width="match_parent"
app:layout_scrollFlags="scroll|enterAlways" /> android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
...@@ -110,8 +114,7 @@ ...@@ -110,8 +114,7 @@
android:layout_marginLeft="@dimen/dp_10" android:layout_marginLeft="@dimen/dp_10"
android:layout_marginTop="@dimen/dp_10" android:layout_marginTop="@dimen/dp_10"
android:layout_marginRight="@dimen/dp_10" android:layout_marginRight="@dimen/dp_10"
android:orientation="horizontal" android:orientation="horizontal">
app:layout_scrollFlags="scroll|enterAlwaysCollapsed">
<TextView <TextView
android:id="@+id/tv_warehousing_record" android:id="@+id/tv_warehousing_record"
...@@ -139,13 +142,11 @@ ...@@ -139,13 +142,11 @@
android:textColor="@color/color_3c" android:textColor="@color/color_3c"
android:textSize="@dimen/dp_17" /> android:textSize="@dimen/dp_17" />
</LinearLayout> </LinearLayout>
</com.google.android.material.appbar.AppBarLayout>
<com.scwang.smartrefresh.layout.SmartRefreshLayout <com.scwang.smartrefresh.layout.SmartRefreshLayout
android:id="@+id/srl_warehouse_details_list" android:id="@+id/srl_warehouse_details_list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:srlAccentColor="@color/theme_333_color" app:srlAccentColor="@color/theme_333_color"
app:srlEnablePreviewInEditMode="true" app:srlEnablePreviewInEditMode="true"
app:srlPrimaryColor="@color/trans"> app:srlPrimaryColor="@color/trans">
...@@ -154,6 +155,7 @@ ...@@ -154,6 +155,7 @@
android:id="@+id/layout_warehousing_root" android:id="@+id/layout_warehousing_root"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:orientation="vertical"> android:orientation="vertical">
<androidx.viewpager2.widget.ViewPager2 <androidx.viewpager2.widget.ViewPager2
...@@ -163,4 +165,7 @@ ...@@ -163,4 +165,7 @@
android:layout_marginTop="@dimen/dp_10" /> android:layout_marginTop="@dimen/dp_10" />
</LinearLayout> </LinearLayout>
</com.scwang.smartrefresh.layout.SmartRefreshLayout> </com.scwang.smartrefresh.layout.SmartRefreshLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout> </LinearLayout>
</ScrollView>
</LinearLayout>
...@@ -9,8 +9,7 @@ ...@@ -9,8 +9,7 @@
android:layout_height="@dimen/dp_58" android:layout_height="@dimen/dp_58"
android:layout_marginTop="@dimen/dp_8" android:layout_marginTop="@dimen/dp_8"
android:layout_marginRight="@dimen/dp_8" android:layout_marginRight="@dimen/dp_8"
android:scaleType="fitXY" android:scaleType="fitXY" />
android:src="@drawable/awe" />
<ImageView <ImageView
android:id="@+id/iv_img_delete" android:id="@+id/iv_img_delete"
......
...@@ -8,8 +8,10 @@ ...@@ -8,8 +8,10 @@
<include layout="@layout/item_show_sn_code" /> <include layout="@layout/item_show_sn_code" />
<FrameLayout <FrameLayout
android:id="@+id/frame_sn_list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:minHeight="@dimen/dp_50"
android:layout_weight="1"> android:layout_weight="1">
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/head_height" android:layout_height="@dimen/head_height"
android:background="@color/theme_color" android:background="@color/theme_color"
app:layout_scrollFlags="scroll|enterAlways"
app:qmui_topbar_text_btn_color_state_list="@color/white" app:qmui_topbar_text_btn_color_state_list="@color/white"
app:qmui_topbar_title_color="@color/theme_white_color" /> app:qmui_topbar_title_color="@color/theme_white_color" />
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
<string name="str_sn_code">SN碼</string> <string name="str_sn_code">SN碼</string>
<string name="str_restaurant_outbound_order">%1$s-出庫單</string> <string name="str_restaurant_outbound_order">%1$s-出庫單</string>
<string name="str_no">NO:%1$s</string> <string name="str_goods_no">NO:%1$s</string>
<string name="str_prepared">製單人:%1$s</string> <string name="str_prepared">製單人:%1$s</string>
<string name="str_device_not_print">您的設備不支持打印</string> <string name="str_device_not_print">您的設備不支持打印</string>
<string name="str_sn_codes">SN碼:%1$s</string> <string name="str_sn_codes">SN碼:%1$s</string>
...@@ -51,5 +51,5 @@ ...@@ -51,5 +51,5 @@
<string name="str_number">數量</string> <string name="str_number">數量</string>
<string name="str_amount">金額</string> <string name="str_amount">金額</string>
<string name="str_inventory_reason">消耗原因</string> <string name="str_inventory_reason">消耗原因</string>
<string name="str_only_allowed_input_number">只允許輸入數字</string>
</resources> </resources>
\ No newline at end of file
...@@ -23,6 +23,7 @@ import android.os.Bundle; ...@@ -23,6 +23,7 @@ import android.os.Bundle;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.WindowManager;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
...@@ -36,6 +37,7 @@ import com.jess.arms.integration.lifecycle.ActivityLifecycleable; ...@@ -36,6 +37,7 @@ import com.jess.arms.integration.lifecycle.ActivityLifecycleable;
import com.jess.arms.mvp.IPresenter; import com.jess.arms.mvp.IPresenter;
import com.jess.arms.utils.ArmsUtils; import com.jess.arms.utils.ArmsUtils;
import com.jess.arms.utils.DeviceUtils; import com.jess.arms.utils.DeviceUtils;
import com.jess.arms.utils.SoftHideKeyBoardUtil;
import com.qmuiteam.qmui.arch.QMUIActivity; import com.qmuiteam.qmui.arch.QMUIActivity;
import com.qmuiteam.qmui.arch.QMUIFragmentActivity; import com.qmuiteam.qmui.arch.QMUIFragmentActivity;
import com.qmuiteam.qmui.util.QMUIDeviceHelper; import com.qmuiteam.qmui.util.QMUIDeviceHelper;
......
package com.jess.arms.utils;
import android.app.Activity;
import android.graphics.Rect;
import android.os.Build;
import android.util.Log;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
/**
* @author 宇航.
* User: admin
* Date: 2021/4/20
* Time: 18:59
* Use:
*/
public class SoftHideKeyBoardUtil {
public static void assistActivity(Activity activity) {
new SoftHideKeyBoardUtil(activity);
}
private View mChildOfContent;
private int usableHeightPrevious;
private FrameLayout.LayoutParams frameLayoutParams;
//为适应华为小米等手机键盘上方出现黑条或不适配
private int contentHeight;//获取setContentView本来view的高度
private boolean isFirst = true;//只用获取一次
private int statusBarHeight;//状态栏高度
private SoftHideKeyBoardUtil(Activity activity) {
//1、找到Activity的最外层布局控件,它其实是一个DecorView,它所用的控件就是FrameLayout
FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content);
//2、获取到setContentView放进去的View
mChildOfContent = content.getChildAt(0);
//3、给Activity的xml布局设置View树监听,当布局有变化,如键盘弹出或收起时,都会回调此监听
//4、软键盘弹起会使GlobalLayout发生变化
mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
if (isFirst) {
contentHeight = mChildOfContent.getHeight();//兼容华为等机型
isFirst = false;
}
//5、当前布局发生变化时,对Activity的xml布局进行重绘
possiblyResizeChildOfContent();
});
//6、获取到Activity的xml布局的放置参数
frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams();
}
/**
* 获取界面可用高度,如果软键盘弹起后,Activity的xml布局可用高度需要减去键盘高度
*/
private void possiblyResizeChildOfContent() {
//1、获取当前界面可用高度,键盘弹起后,当前界面可用布局会减少键盘的高度
int usableHeightNow = computeUsableHeight();
//2、如果当前可用高度和原始值不一样
if (usableHeightNow != usableHeightPrevious) {
//3、获取Activity中xml中布局在当前界面显示的高度
int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight();
Log.e("eee", "顯示高度:" + usableHeightSansKeyboard);
//4、Activity中xml布局的高度-当前可用高度
int heightDifference = usableHeightSansKeyboard - usableHeightNow;
Log.e("eee", "鍵盤高度:" + heightDifference);
//5、高度差大于屏幕1/4时,说明键盘弹出
if (heightDifference > (usableHeightSansKeyboard / 4)) {
// 6、键盘弹出了,Activity的xml布局高度应当减去键盘高度
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
frameLayoutParams.height = usableHeightSansKeyboard - heightDifference + statusBarHeight;
} else {
frameLayoutParams.height = usableHeightSansKeyboard - heightDifference;
}
Log.e("eee", "頁面高度:" + frameLayoutParams.height);
} else {
frameLayoutParams.height = contentHeight;
}
//7、 重绘Activity的xml布局
mChildOfContent.requestLayout();
usableHeightPrevious = usableHeightNow;
}
}
private int computeUsableHeight() {
Rect r = new Rect();
mChildOfContent.getWindowVisibleDisplayFrame(r);
// 全屏模式下:直接返回r.bottom,r.top其实是状态栏的高度
return (r.bottom - r.top);
}
/**
* 软键盘弹出布局向上滑动
*
* @param rootView 根布局
* @param bottomView 需要显示的最下方View,
*/
public static void layoutSlideListener(final View rootView, final View bottomView) {
rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect rect = new Rect();
rootView.getWindowVisibleDisplayFrame(rect);//获取rootView的可视区域
int invisibleHeight = rootView.getRootView().getHeight() - rect.bottom;//获取rootView的不可视区域高度
if (invisibleHeight > 150) { //键盘显示
int[] location = new int[2];
bottomView.getLocationInWindow(location); //获取bottomView的坐标
int scrollHeight = (location[1] + bottomView.getHeight()) - rect.bottom + 40;//算出需要滚动的高度(与初始布局的偏移量,可调整)
if (scrollHeight != 0) {//防止界面元素改变调用监听,使界面上下跳动,如验证码倒计时
rootView.scrollTo(0, scrollHeight);
}
} else {
rootView.scrollTo(0, 0);
}
}
});
}
}
...@@ -44,7 +44,9 @@ class ICommandService : Service() { ...@@ -44,7 +44,9 @@ class ICommandService : Service() {
/** /**
* 心跳检测时间 * 心跳检测时间
*/ */
private val heartBeatRate = (30 * 1000).toLong()//每隔30秒进行一次对长连接的心跳检测 private val heartBeatRate = 30L//每隔30秒进行一次对长连接的心跳检测
private val warningTime = 60L//超過六十秒還未重連,報警推送
/** /**
* 可替换为自己的主机名和端口号 * 可替换为自己的主机名和端口号
...@@ -288,18 +290,19 @@ class ICommandService : Service() { ...@@ -288,18 +290,19 @@ class ICommandService : Service() {
// 初始化socket // 初始化socket
private fun initSocket() { private fun initSocket() {
putTimeLog("取消心跳") putTimeLog("initSocket開始輪詢")
heartPolling?.dispose()
heartPolling = RxJavaUtils.polling(0, heartBeatRate) { heartPolling = RxJavaUtils.polling(0, heartBeatRate) {
run { run {
//保持設備喚醒 //保持設備喚醒
newWakeLock?.acquire(10 * 60 * 1000L /*10 minutes*/) newWakeLock?.acquire(10 * 60 * 1000L /*10 minutes*/)
putTimeLog("開啟心跳")
//先斷開之前的 //先斷開之前的
client?.let { it -> client?.let { it ->
mWebSocket?.let { mWebSocket?.let {
it.cancel() it.cancel()
it.send("-1") it.send("-1")
it.close(1000, null) it.close(1000, "手動斷開")
putTimeLog("開啟之前先斷開心跳")
} }
it.dispatcher().cancelAll() it.dispatcher().cancelAll()
} }
...@@ -314,7 +317,7 @@ class ICommandService : Service() { ...@@ -314,7 +317,7 @@ class ICommandService : Service() {
if (!this@ICommandService.isDestroy) { if (!this@ICommandService.isDestroy) {
mWebSocket = webSocket mWebSocket = webSocket
send(mCurrConnectionType) send(mCurrConnectionType)
putTimeLog("連接成功") putTimeLog("onOpen心跳連接成功")
warningDelay?.dispose() warningDelay?.dispose()
myBind?.block?.invoke(false) myBind?.block?.invoke(false)
} }
...@@ -328,7 +331,7 @@ class ICommandService : Service() { ...@@ -328,7 +331,7 @@ class ICommandService : Service() {
postCallBack!!.callBack(type) postCallBack!!.callBack(type)
} }
//收到服务器端传过来的消息text //收到服务器端传过来的消息text
putTimeLog("收到回調:$text") putTimeLog("onMessage收到回調:$text")
//-1斷開連接, //-1斷開連接,
// \n-2:消息傳輸錯誤, // \n-2:消息傳輸錯誤,
// \n0:連接消息, // \n0:連接消息,
...@@ -362,7 +365,7 @@ class ICommandService : Service() { ...@@ -362,7 +365,7 @@ class ICommandService : Service() {
override fun onMessage(webSocket: WebSocket, bytes: ByteString) { override fun onMessage(webSocket: WebSocket, bytes: ByteString) {
super.onMessage(webSocket, bytes) super.onMessage(webSocket, bytes)
val json = JSONObject(bytes.toString()) val json = JSONObject(bytes.toString())
putTimeLog("onMessage2:$bytes") putTimeLog("收到消息onMessage:$bytes")
if (postCallBack != null) { if (postCallBack != null) {
postCallBack!!.callBack(json.optInt("type")) postCallBack!!.callBack(json.optInt("type"))
} }
...@@ -371,27 +374,31 @@ class ICommandService : Service() { ...@@ -371,27 +374,31 @@ class ICommandService : Service() {
override fun onClosing(webSocket: WebSocket, code: Int, reason: String) { override fun onClosing(webSocket: WebSocket, code: Int, reason: String) {
super.onClosing(webSocket, code, reason) super.onClosing(webSocket, code, reason)
//連接斷開, //連接斷開,
putTimeLog("onClosing關閉連接") putTimeLog("onClosing關閉連接,code:$code——reason:$reason")
} }
override fun onClosed(webSocket: WebSocket, code: Int, reason: String) { override fun onClosed(webSocket: WebSocket, code: Int, reason: String) {
super.onClosed(webSocket, code, reason) super.onClosed(webSocket, code, reason)
putTimeLog("onClosed斷開連接") putTimeLog("onClosed斷開連接,Code:$code——reason:$reason")
webSocket.cancel() webSocket.cancel()
} }
override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) {//长连接连接失败的回调 override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) {//长连接连接失败的回调
super.onFailure(webSocket, t, response) super.onFailure(webSocket, t, response)
Log.e(TAG, "onFailure " + t.message) putTimeLog("onFailure連接失敗,——reason:$t")
if (!this@ICommandService.isDestroy) { if (!this@ICommandService.isDestroy) {
//連接斷開,定時五秒,如果未重連,播放提示音 //連接斷開,定時五秒,如果未重連,播放提示音
warningDelay = RxJavaUtils.delay(60) { putTimeLog("onFailure連接失敗,延時任務狀態${warningDelay?.isDisposed}")
if (warningDelay == null || warningDelay!!.isDisposed) {
warningDelay = RxJavaUtils.delay(warningTime) {
putTimeLog("執行心跳斷開六十秒報警延時任務")
initSoundPool(R.raw.raw_disconnect) initSoundPool(R.raw.raw_disconnect)
myBind?.block?.invoke(true) myBind?.block?.invoke(true)
//推送給相關人員 //推送給相關人員
OkHttp3Utils.noticePersonnel(AppConstans.RP_HEART_ERROR, "心跳斷開十秒以上未連接成功:" + t.message) OkHttp3Utils.noticePersonnel(AppConstans.RP_HEART_ERROR, "心跳斷開六十秒以上未連接成功:" + t.message)
}
putTimeLog("onFailure連接失敗,開始等待一分鐘後重新連接")
} }
putTimeLog("onFailure連接失敗,等待一分鐘後重新連接")
} else { } else {
webSocket.cancel() webSocket.cancel()
it.dispatcher().cancelAll() it.dispatcher().cancelAll()
......
...@@ -36,10 +36,20 @@ public class InputFilterUtils { ...@@ -36,10 +36,20 @@ public class InputFilterUtils {
* 只能輸入英文和數字 * 只能輸入英文和數字
*/ */
public static final Pattern enAndNum = Pattern.compile("[a-zA-Z0-9]+"); public static final Pattern enAndNum = Pattern.compile("[a-zA-Z0-9]+");
/**
* 只允許輸入小寫字母
*/
public static final Pattern enPattern = Pattern.compile("[a-z]"); public static final Pattern enPattern = Pattern.compile("[a-z]");
/**
* 只允許輸入數字
*/
private final static Pattern pattern = Pattern.compile("[0-9]*");
/** /**
* 驗證小數,兩位
*/
private final static Pattern decimalPattern = Pattern.compile("^[0-9]*\\.?[0-9]{0,2}");
/**
* 只能輸入中英文和數字還有一些標點符號 * 只能輸入中英文和數字還有一些標點符號
* Punctuation * Punctuation
*/ */
...@@ -65,9 +75,11 @@ public class InputFilterUtils { ...@@ -65,9 +75,11 @@ public class InputFilterUtils {
public static InputFilter getChAndEnAndNumAndPtInputFilter(Context mContext) { public static InputFilter getChAndEnAndNumAndPtInputFilter(Context mContext) {
return InputFilterUtils.getTypeFilter(mContext, "請輸入正確的字符", chAndEnAndNumAndPt); return InputFilterUtils.getTypeFilter(mContext, "請輸入正確的字符", chAndEnAndNumAndPt);
} }
public static InputFilter getChAndEnNumPtWrapInputFilter(Context mContext) { public static InputFilter getChAndEnNumPtWrapInputFilter(Context mContext) {
return InputFilterUtils.getTypeFilter(mContext, "請輸入正確的字符", chAndEnNumPtWrap); return InputFilterUtils.getTypeFilter(mContext, "請輸入正確的字符", chAndEnNumPtWrap);
} }
public static InputFilter getTypeFilter(Context mContext, Pattern p) { public static InputFilter getTypeFilter(Context mContext, Pattern p) {
return InputFilterUtils.getTypeFilter(mContext, "不支持輸入此內容", p); return InputFilterUtils.getTypeFilter(mContext, "不支持輸入此內容", p);
} }
...@@ -88,6 +100,10 @@ public class InputFilterUtils { ...@@ -88,6 +100,10 @@ public class InputFilterUtils {
return InputFilterUtils.getMaxLengthFilter(mContext, "最多輸入" + maxLength + "個字", maxLength); return InputFilterUtils.getMaxLengthFilter(mContext, "最多輸入" + maxLength + "個字", maxLength);
} }
public static InputFilter getNumberFilter(Context context) {
return getNumberFilter(context, "只允許輸入數字");
}
/** /**
* source 新输入的字符串 * source 新输入的字符串
* start 新输入的字符串起始下标,一般为0 * start 新输入的字符串起始下标,一般为0
...@@ -229,8 +245,8 @@ public class InputFilterUtils { ...@@ -229,8 +245,8 @@ public class InputFilterUtils {
public void onTextChanged(CharSequence s, int start, int before, int count) { public void onTextChanged(CharSequence s, int start, int before, int count) {
Log.e("eee", "onTextChanged:" + s + "——start:" + start + "——count:" + count + "——before:" + before); Log.e("eee", "onTextChanged:" + s + "——start:" + start + "——count:" + count + "——before:" + before);
if (s.length() > 0) { if (s.length() > 0) {
String str = s.toString().trim().charAt(0)+""; String str = s.toString().trim().charAt(0) + "";
if(enPattern.matcher( str).matches()){ if (enPattern.matcher(str).matches()) {
} }
} }
...@@ -242,5 +258,61 @@ public class InputFilterUtils { ...@@ -242,5 +258,61 @@ public class InputFilterUtils {
} }
}; };
} }
/**
* 輸入小數
*
* @param context
* @param tipString 超過最大長度限制的提示
* @return source 當前輸入內容
* dest 輸入框中的內容
*/
public static InputFilter getNumberFilter(Context context, String tipString) {
return (source, start, end, dest, dstart, dend) -> {
if (source.equals(".")) {
if (dstart == 0 || !(dest.charAt(dstart - 1) >= '0' && dest.charAt(dstart - 1) <= '9') || dest.charAt(0) == '0') {
return "";
}
}
if (source.equals("0") && (dest.toString()).contains(".") && dstart == 0) { //防止在369.369的最前面输入0变成0369.369这种不合法的形式
return "";
}
StringBuilder builder = new StringBuilder(dest);
builder.delete(dstart, dend);
builder.insert(dstart, source);
if (!decimalPattern.matcher(builder.toString()).matches()) {
ToastUtils.show(context, tipString);
return "";
}
// if (TextUtils.isEmpty(source)) {
// return null;
// }
// if (!isNumeric(source + "")) {
// return "";
// }
// String dValue = dest.toString();
// String[] splitArray = dValue.split("\\.");
// if (splitArray.length > 1) {
// String dotValue = splitArray[1];
// // 2 表示输入框的小数位数
// int diff = dotValue.length() + 1 - 2;
// if (diff > 0) {
// return source.subSequence(start, end - diff);
// }
// }
return null;
};
}
/**
* 是否是數字
*
* @param str
* @return
*/
public static boolean isNumeric(String str) {
return pattern.matcher(str).matches();
}
} }
...@@ -201,4 +201,6 @@ public class TextUtil { ...@@ -201,4 +201,6 @@ public class TextUtil {
} }
return null; return null;
} }
} }
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="@dimen/dp_12" />
<solid android:color="@color/other_order_details_print_btn_color" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="@dimen/dp_12" />
<solid android:color="@color/brick_red" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="@dimen/dp_12" />
<stroke
android:width="@dimen/dp_1"
android:color="@color/theme_color" />
<solid android:color="@color/white" />
</shape>
\ No newline at end of file
...@@ -479,6 +479,7 @@ ...@@ -479,6 +479,7 @@
<color name="color_48">#484848</color> <color name="color_48">#484848</color>
<color name="color_75">#757575</color> <color name="color_75">#757575</color>
<color name="color_b8">#B8B8B8</color> <color name="color_b8">#B8B8B8</color>
<color name="common_pressed">#20000000</color> <!--白色背景按下去的颜色-->
<color name="tran_twenty_send_order_btn_bg_color">#331196DB</color> <color name="tran_twenty_send_order_btn_bg_color">#331196DB</color>
<color name="tran_fifty_order_state0_color">#7F009788</color> <color name="tran_fifty_order_state0_color">#7F009788</color>
<!-- 待確認背景色--> <!-- 待確認背景色-->
......
...@@ -237,7 +237,11 @@ ...@@ -237,7 +237,11 @@
<string name="str_operating">操作</string> <string name="str_operating">操作</string>
<string name="str_serial_number">序號</string> <string name="str_serial_number">序號</string>
<string name="str_info_no_save_leave">信息未保存,是否離開?</string> <string name="str_info_no_save_leave">信息未保存,是否離開?</string>
<string name="str_about_to_leave">即將離開,信息是否保存?</string>
<string name="str_save_and_leave">保存並離開</string> <string name="str_save_and_leave">保存並離開</string>
<string name="str_leave">離開</string> <string name="str_leave">離開</string>
<string name="str_yes"></string>
<string name="str_no"></string>
</resources> </resources>
package com.gingersoft.gsa.cloud.ui;
import android.content.Context;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.gingersoft.gsa.cloud.ui.test", appContext.getPackageName());
}
}
\ No newline at end of file
...@@ -20,9 +20,9 @@ import java.util.List; ...@@ -20,9 +20,9 @@ import java.util.List;
* User: admin * User: admin
* Date: 2020/11/28 * Date: 2020/11/28
* Time: 11:45 * Time: 11:45
* Use: * Use: 繼承重寫自己的layout
*/ */
public class BaseCategoryAdapter extends BaseQuickAdapter<CategoryBean, BaseViewHolder> { public abstract class BaseSelectorAdapter<T, VH extends BaseViewHolder> extends BaseQuickAdapter<T, VH> {
private int selectedIndex = 0; private int selectedIndex = 0;
private int selectedBg; private int selectedBg;
...@@ -30,45 +30,16 @@ public class BaseCategoryAdapter extends BaseQuickAdapter<CategoryBean, BaseView ...@@ -30,45 +30,16 @@ public class BaseCategoryAdapter extends BaseQuickAdapter<CategoryBean, BaseView
private int selectColor; private int selectColor;
private int unSelectColor; private int unSelectColor;
private boolean showDelete = false;
public BaseCategoryAdapter(@Nullable List<CategoryBean> data) { public BaseSelectorAdapter(int layoutRes, @Nullable List<T> data) {
super(R.layout.item_base_category, data);
addChildClickViewIds(R.id.iv_category_delete);
selectedBg = R.drawable.shape_left_radio_shadow;
unSelectedBg = R.color.trans;
selectColor = R.color.s_btn_blue_3c_text;
unSelectColor = R.color.color_ccc;
}
public BaseCategoryAdapter(int layoutRes, @Nullable List<CategoryBean> data) {
super(layoutRes, data); super(layoutRes, data);
addChildClickViewIds(R.id.iv_category_delete); selectedBg = R.drawable.shape_white_eight_corners_bg;
selectedBg = R.drawable.shape_left_radio_shadow; unSelectedBg = R.drawable.shape_theme_eight_corners_bg;
unSelectedBg = R.color.trans;
selectColor = R.color.s_btn_blue_3c_text; selectColor = R.color.s_btn_blue_3c_text;
unSelectColor = R.color.color_ccc; unSelectColor = R.color.color_ccc;
} }
@Override protected void notifyCheckState(int position, TextView tvName, View view) {
protected void convert(@NotNull BaseViewHolder viewHolder, CategoryBean categoryBean) {
viewHolder.setText(R.id.tv_base_item_title, categoryBean.getCategoryName());
notifyCheckState(viewHolder.getAdapterPosition(), viewHolder.getView(R.id.tv_base_item_title), viewHolder.getView(R.id.item_layout_root));
viewHolder.setGone(R.id.iv_category_delete, !showDelete);
}
@Override
public void onBindViewHolder(@NotNull BaseViewHolder holder, int position, @NotNull List<Object> payloads) {
super.onBindViewHolder(holder, position, payloads);
//list为空时,必须调用两个参数的onBindViewHolder(@NonNull LabelHolder holder, int position)
if (payloads.isEmpty()) {
onBindViewHolder(holder, position);
} else {
notifyCheckState(position, holder.getView(R.id.tv_base_item_title), holder.getView(R.id.item_layout_root));
}
}
private void notifyCheckState(int position, TextView tvName, View view) {
if (position == selectedIndex) { if (position == selectedIndex) {
view.setBackground(ContextCompat.getDrawable(getContext(), selectedBg)); view.setBackground(ContextCompat.getDrawable(getContext(), selectedBg));
tvName.setTextColor(selectColor); tvName.setTextColor(selectColor);
...@@ -80,32 +51,27 @@ public class BaseCategoryAdapter extends BaseQuickAdapter<CategoryBean, BaseView ...@@ -80,32 +51,27 @@ public class BaseCategoryAdapter extends BaseQuickAdapter<CategoryBean, BaseView
} }
} }
public void setShowDelete(boolean showDelete) { public BaseSelectorAdapter setSelectedBg(int selectedBg) {
this.showDelete = showDelete;
notifyDataSetChanged();
}
public BaseCategoryAdapter setSelectedBg(int selectedBg) {
this.selectedBg = selectedBg; this.selectedBg = selectedBg;
return this; return this;
} }
public BaseCategoryAdapter setUnSelectedBg(int unSelectedBg) { public BaseSelectorAdapter setUnSelectedBg(int unSelectedBg) {
this.unSelectedBg = unSelectedBg; this.unSelectedBg = unSelectedBg;
return this; return this;
} }
public BaseCategoryAdapter setSelectColor(int selectColor) { public BaseSelectorAdapter setSelectColor(int selectColor) {
this.selectColor = selectColor; this.selectColor = selectColor;
return this; return this;
} }
public BaseCategoryAdapter setUnSelectColor(int unSelectColor) { public BaseSelectorAdapter setUnSelectColor(int unSelectColor) {
this.unSelectColor = unSelectColor; this.unSelectColor = unSelectColor;
return this; return this;
} }
public BaseCategoryAdapter setSelectedIndex(int selectedIndex) { public BaseSelectorAdapter setSelectedIndex(int selectedIndex) {
this.selectedIndex = selectedIndex; this.selectedIndex = selectedIndex;
notifyDataSetChanged(); notifyDataSetChanged();
return this; return this;
......
...@@ -227,8 +227,9 @@ public class InfoMultiBean { ...@@ -227,8 +227,9 @@ public class InfoMultiBean {
return maxLength; return maxLength;
} }
public void setMaxLength(int maxLength) { public InfoMultiBean setMaxLength(int maxLength) {
this.maxLength = maxLength; this.maxLength = maxLength;
return this;
} }
public List<InfoMultiBean> getInfoMultiBeans() { public List<InfoMultiBean> getInfoMultiBeans() {
......
...@@ -99,24 +99,27 @@ public class MultiInputBean extends InfoMultiBean { ...@@ -99,24 +99,27 @@ public class MultiInputBean extends InfoMultiBean {
} }
@Override @Override
public void setMaxLength(int maxLength) { public MultiInputBean setMaxLength(int maxLength) {
this.maxLength = maxLength; this.maxLength = maxLength;
return this;
} }
public TextWatcher getTextWatcher() { public TextWatcher getTextWatcher() {
return textWatcher; return textWatcher;
} }
public void setTextWatcher(TextWatcher textWatcher) { public MultiInputBean setTextWatcher(TextWatcher textWatcher) {
this.textWatcher = textWatcher; this.textWatcher = textWatcher;
return this;
} }
public boolean isEdit() { public boolean isEdit() {
return isEdit; return isEdit;
} }
public void setEdit(boolean edit) { public MultiInputBean setEdit(boolean edit) {
isEdit = edit; isEdit = edit;
return this;
} }
public View.OnFocusChangeListener getOnFocusChangeListener() { public View.OnFocusChangeListener getOnFocusChangeListener() {
......
...@@ -32,5 +32,6 @@ public class BooleanItemProvider<T extends InfoMultiBean> extends MyBaseItemProv ...@@ -32,5 +32,6 @@ public class BooleanItemProvider<T extends InfoMultiBean> extends MyBaseItemProv
SwitchCompat sw = baseViewHolder.getView(R.id.switch_multi_boolean_state); SwitchCompat sw = baseViewHolder.getView(R.id.switch_multi_boolean_state);
sw.setChecked(infoMultiBean.isChecked()); sw.setChecked(infoMultiBean.isChecked());
sw.setOnCheckedChangeListener((buttonView, isChecked) -> infoMultiBean.setChecked(isChecked)); sw.setOnCheckedChangeListener((buttonView, isChecked) -> infoMultiBean.setChecked(isChecked));
baseViewHolder.itemView.setOnClickListener(v -> sw.toggle());
} }
} }
package com.gingersoft.gsa.cloud.ui.bean
import android.graphics.Color
/**
* <pre>
* @author : Allen
* e-mail : lygttpod@163.com
* date : 2019/09/22
* desc :
* </pre>
*/
class AttributeSetData {
var shapeType = -1
var solidColor = -1
var strokeWidth = -1
var strokeColor = -1
var strokeDashWidth = 0.0f
var strokeDashGap = 0.0f
var cornersRadius = 0.0f
var cornersTopLeftRadius = 0.0f
var cornersTopRightRadius = 0.0f
var cornersBottomLeftRadius = 0.0f
var cornersBottomRightRadius = 0.0f
var gradientAngle = -1
var gradientCenterX: Int = 0
var gradientCenterY: Int = 0
var gradientGradientRadius: Int = 0
var gradientStartColor = -1
var gradientCenterColor = -1
var gradientEndColor = -1
var gradientType: Int = 0
var gradientUseLevel: Boolean = false
var sizeWidth = -1
var sizeHeight = -1
var selectorPressedColor: Int = 0
var selectorDisableColor: Int = 0
var selectorNormalColor: Int = 0
var useSelector: Boolean = false
//////////阴影相关////////
var showShadow: Boolean = false
var shadowColor: Int = Color.GRAY
var shadowColorAlpha: Float = 0.2f
var shadowLeftWidth: Float = 0f
var shadowTopWidth: Float = 0f
var shadowRightWidth: Float = 0f
var shadowBottomWidth: Float = 0f
var shadowCornersRadius: Float = 0f
var shadowCornersTopLeftRadius: Float = 0f
var shadowCornersTopRightRadius: Float = 0f
var shadowCornersBottomLeftRadius: Float = 0f
var shadowCornersBottomRightRadius: Float = 0f
}
\ No newline at end of file
...@@ -122,6 +122,7 @@ public class AppDialog { ...@@ -122,6 +122,7 @@ public class AppDialog {
if (sureOnclickListener != null) { if (sureOnclickListener != null) {
sureOnclickListener.onclick(v, dialog); sureOnclickListener.onclick(v, dialog);
} }
dialog.dismiss();
}); });
hepler.getView(R.id.tv_dialog_cancel).setOnClickListener(v -> { hepler.getView(R.id.tv_dialog_cancel).setOnClickListener(v -> {
dismiss(); dismiss();
......
package com.gingersoft.gsa.cloud.ui.view;
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PaintFlagsDrawFilter;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.animation.Animation;
import android.view.animation.CycleInterpolator;
import android.view.animation.TranslateAnimation;
import androidx.appcompat.widget.AppCompatEditText;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat;
import com.gingersoft.gsa.cloud.ui.R;
/**
* @author 宇航.
* User: admin
* Date: 2021/1/28
* Time: 12:28
* Use:
*/
public class ClearEditText extends AppCompatEditText {
//按钮资源
private final int CLEAR = R.drawable.ic_clear_text;
//动画时长
private final int ANIMATOR_TIME = 200;
//按钮左右间隔,单位DP
private final int INTERVAL = 5;
//清除按钮宽度,单位DP
private final int WIDTH_OF_CLEAR = 23;
//间隔记录
private int Interval;
//清除按钮宽度记录
private int mWidth_clear;
//右内边距
private int mPaddingRight;
//清除按钮的bitmap
private Bitmap mBitmap_clear;
//清除按钮出现动画
private ValueAnimator mAnimator_visible;
//消失动画
private ValueAnimator mAnimator_gone;
//是否显示的记录
private boolean isVisible = false;
//右边添加其他按钮时使用
private int mRight = 0;
public ClearEditText(final Context context) {
super(context);
init(context);
}
public ClearEditText(final Context context, final AttributeSet attrs) {
super(context, attrs);
init(context);
}
public ClearEditText(final Context context, final AttributeSet attrs, final int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
private void init(Context context) {
mBitmap_clear = createBitmap(CLEAR, context);
Interval = dp2px(INTERVAL);
mWidth_clear = dp2px(WIDTH_OF_CLEAR);
mPaddingRight = Interval + mWidth_clear + Interval;
mAnimator_gone = ValueAnimator.ofFloat(1f, 0f).setDuration(ANIMATOR_TIME);
mAnimator_visible = ValueAnimator.ofInt(mWidth_clear + Interval, 0).setDuration(ANIMATOR_TIME);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
//设置内边距
// setPadding(getPaddingLeft(), getPaddingTop(), mPaddingRight + mRight, getPaddingBottom());
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));//抗锯齿
if (mAnimator_visible.isRunning()) {
int x = (int) mAnimator_visible.getAnimatedValue();
drawClear(x, canvas);
invalidate();
} else if (isVisible) {
drawClear(0, canvas);
}
if (mAnimator_gone.isRunning()) {
float scale = (float) mAnimator_gone.getAnimatedValue();
drawClearGone(scale, canvas);
invalidate();
}
}
/**
* 绘制清除按钮出现的图案
*
* @param translationX 水平移动距离
* @param canvas
*/
protected void drawClear(int translationX, Canvas canvas) {
int right = getWidth() + getScrollX() - Interval - mRight + translationX;
int left = right - mWidth_clear;
int top = (getHeight() - mWidth_clear) / 2;
int bottom = top + mWidth_clear;
Rect rect = new Rect(left, top, right, bottom);
canvas.drawBitmap(mBitmap_clear, null, rect, null);
}
/**
* 绘制清除按钮消失的图案
*
* @param scale 缩放比例
* @param canvas
*/
protected void drawClearGone(float scale, Canvas canvas) {
int right = (int) (getWidth() + getScrollX() - Interval - mRight - mWidth_clear * (1f - scale) / 2f);
int left = (int) (getWidth() + getScrollX() - Interval - mRight - mWidth_clear * (scale + (1f - scale) / 2f));
int top = (int) ((getHeight() - mWidth_clear * scale) / 2);
int bottom = (int) (top + mWidth_clear * scale);
Rect rect = new Rect(left, top, right, bottom);
canvas.drawBitmap(mBitmap_clear, null, rect, null);
}
/**
* 开始清除按钮的显示动画
*/
private void startVisibleAnimator() {
endAnimator();
mAnimator_visible.start();
invalidate();
}
/**
* 开始清除按钮的消失动画
*/
private void startGoneAnimator() {
endAnimator();
mAnimator_gone.start();
invalidate();
}
/**
* 结束所有动画
*/
private void endAnimator() {
mAnimator_gone.end();
mAnimator_visible.end();
}
/**
* Edittext内容变化的监听
*/
@Override
protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
super.onTextChanged(text, start, lengthBefore, lengthAfter);
if (text.length() > 0) {
if (!isVisible) {
isVisible = true;
startVisibleAnimator();
}
} else {
if (isVisible) {
isVisible = false;
startGoneAnimator();
}
}
}
/**
* 触控执行的监听
*
* @param event
* @return
*/
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
boolean touchable = (getWidth() - Interval - mRight - mWidth_clear < event.getX()) && (event.getX() < getWidth() - Interval - mRight);
if (touchable) {
setError(null);
this.setText("");
}
}
return super.onTouchEvent(event);
}
/**
* 开始晃动动画
*/
public void startShakeAnimation() {
if (getAnimation() == null) {
this.setAnimation(shakeAnimation(4));
}
this.startAnimation(getAnimation());
}
/**
* 晃动动画
*
* @param counts 0.5秒钟晃动多少下
* @return
*/
private Animation shakeAnimation(int counts) {
Animation translateAnimation = new TranslateAnimation(0, 10, 0, 0);
translateAnimation.setInterpolator(new CycleInterpolator(counts));
translateAnimation.setDuration(500);
return translateAnimation;
}
/**
* 给图标染上当前提示文本的颜色并且转出Bitmap
*
* @param resources
* @param context
* @return
*/
public Bitmap createBitmap(int resources, Context context) {
final Drawable drawable = ContextCompat.getDrawable(context, resources);
final Drawable wrappedDrawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTint(wrappedDrawable, getCurrentHintTextColor());
return drawableToBitamp(wrappedDrawable);
}
/**
* drawable转换成bitmap
*
* @param drawable
* @return
*/
private Bitmap drawableToBitamp(Drawable drawable) {
int w = drawable.getIntrinsicWidth();
int h = drawable.getIntrinsicHeight();
Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
Bitmap bitmap = Bitmap.createBitmap(w, h, config);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, w, h);
drawable.draw(canvas);
return bitmap;
}
public int dp2px(float dipValue) {
final float scale = getResources().getDisplayMetrics().density;
return (int) (dipValue * scale + 0.5f);
}
}
\ No newline at end of file
package com.gingersoft.gsa.cloud.ui.view.helper
import android.annotation.TargetApi
import android.os.Build
import android.widget.EditText
import android.widget.TextView
import androidx.annotation.DrawableRes
import java.lang.reflect.Field
/**
* @name SuperTextView
* @author Realmo
* @email momo.weiye@gmail.com
* @version 1.0.0
* @time 2020/12/14 10:27
* @describe
*/
object EditTextHelper {
@TargetApi(Build.VERSION_CODES.O)
fun setCursorDrawable(editText:EditText,@DrawableRes drawableRes:Int){
try { //修改光标的颜色(反射)
val f: Field = TextView::class.java.getDeclaredField("mCursorDrawableRes")
f.setAccessible(true)
f.set(editText, drawableRes)
} catch (e: Exception) {
e.printStackTrace()
}
}
}
\ No newline at end of file
package com.gingersoft.gsa.cloud.ui.view.helper
import android.content.Context
import android.graphics.drawable.GradientDrawable
import android.graphics.drawable.StateListDrawable
import android.os.Build
import android.view.View
import androidx.core.view.ViewCompat
import com.gingersoft.gsa.cloud.ui.bean.AttributeSetData
/**
* <pre>
* @author : Allen
* e-mail : lygttpod@163.com
* date : 2019/05/27
* desc : shape构造器
</pre> *
*/
class ShapeBuilder {
companion object {
/**
* shape的样式
*/
const val RECTANGLE = 0
const val OVAL = 1
const val LINE = 2
const val RING = 3
/**
* <gradient android:angle="integer" android:centerX="integer" android:centerY="integer" android:centerColor="integer" android:endColor="color" android:gradientRadius="integer" android:startColor="color" android:type=["linear" |></gradient> "radial" | "sweep"]
* android:useLevel=["true" | "false"] />
* 参数对应关系
*/
//渐变色的显示方式
const val TOP_BOTTOM = 0
const val TR_BL = 1
const val RIGHT_LEFT = 2
const val BR_TL = 3
const val BOTTOM_TOP = 4
const val BL_TR = 5
const val LEFT_RIGHT = 6
const val TL_BR = 7
const val LINEAR = 0
const val RADIAL = 1
const val SWEEP = 2
}
/**
* android:shape=["rectangle" | "oval" | "line" | "ring"]
*/
private var shapeType = -1
/**
* <solid android:color="color"></solid>
*/
private var solidColor = -1
/**
* <stroke android:width="integer" android:color="color" android:dashWidth="integer" android:dashGap="integer"></stroke>
*/
private var strokeWidth = -1
private var strokeColor = -1
private var strokeDashWidth = 0.0f
private var strokeDashGap = 0.0f
/**
* <corners android:radius="integer" android:topLeftRadius="integer" android:topRightRadius="integer" android:bottomLeftRadius="integer" android:bottomRightRadius="integer"></corners>
*/
private var cornersRadius = 0.0f
private var cornersTopLeftRadius = 0.0f
private var cornersTopRightRadius = 0.0f
private var cornersBottomLeftRadius = 0.0f
private var cornersBottomRightRadius = 0.0f
private var gradientAngle = -1
private var gradientCenterX: Int = 0
private var gradientCenterY: Int = 0
private var gradientGradientRadius: Int = 0
private var gradientStartColor = -1
private var gradientCenterColor = -1
private var gradientEndColor = -1
private var gradientType: Int = 0
private var gradientUseLevel: Boolean = false
/**
* <size android:width="integer" android:height="integer"></size>
*/
private var sizeWidth = -1
private var sizeHeight = -1
/**
* <selector xmlns:android="http://schemas.android.com/apk/res/android" android:constantSize=["true" |></selector> "false"]
* android:dither=["true" | "false"]
* android:variablePadding=["true" | "false"] >
* <item android:drawable="@[package:]drawable/drawable_resource" android:state_pressed=["true" |></item> "false"]
* android:state_focused=["true" | "false"]
* android:state_hovered=["true" | "false"]
* android:state_selected=["true" | "false"]
* android:state_checkable=["true" | "false"]
* android:state_checked=["true" | "false"]
* android:state_enabled=["true" | "false"]
* android:state_activated=["true" | "false"]
* android:state_window_focused=["true" | "false"] />
*
*/
private var selectorPressedColor: Int = 0
private var selectorDisableColor: Int = 0
private var selectorNormalColor: Int = 0
private var useSelector: Boolean = false
private var targetView: View? = null
fun setShapeType(shapeType: Int): ShapeBuilder {
this.shapeType = shapeType
return this
}
fun setShapeSolidColor(color: Int): ShapeBuilder {
this.solidColor = color
return this
}
fun setShapeCornersRadius(radius: Float): ShapeBuilder {
this.cornersRadius = radius
return this
}
fun setShapeCornersTopLeftRadius(radius: Float): ShapeBuilder {
this.cornersTopLeftRadius = radius
return this
}
fun setShapeCornersTopRightRadius(radius: Float): ShapeBuilder {
this.cornersTopRightRadius = radius
return this
}
fun setShapeCornersBottomRightRadius(radius: Float): ShapeBuilder {
this.cornersBottomRightRadius = radius
return this
}
fun setShapeCornersBottomLeftRadius(radius: Float): ShapeBuilder {
this.cornersBottomLeftRadius = radius
return this
}
fun setShapeStrokeWidth(strokeWidth: Int): ShapeBuilder {
this.strokeWidth = strokeWidth
return this
}
fun setShapeStrokeColor(strokeColor: Int): ShapeBuilder {
this.strokeColor = strokeColor
return this
}
fun setShapeStrokeDashWidth(strokeDashWidth: Float): ShapeBuilder {
this.strokeDashWidth = strokeDashWidth
return this
}
fun setShapeStrokeDashGap(strokeDashGap: Float): ShapeBuilder {
this.strokeDashGap = strokeDashGap
return this
}
fun setShapeUseSelector(useSelector: Boolean): ShapeBuilder {
this.useSelector = useSelector
return this
}
fun setShapeSelectorPressedColor(color: Int): ShapeBuilder {
this.selectorPressedColor = color
return this
}
fun setShapeSelectorNormalColor(color: Int): ShapeBuilder {
this.selectorNormalColor = color
return this
}
fun setShapeSelectorDisableColor(color: Int): ShapeBuilder {
this.selectorDisableColor = color
return this
}
fun setShapeSizeWidth(sizeWidth: Int): ShapeBuilder {
this.sizeWidth = sizeWidth
return this
}
fun setShapeSizeHeight(sizeHeight: Int): ShapeBuilder {
this.sizeHeight = sizeHeight
return this
}
fun setShapeGradientAngle(gradientAngle: Int): ShapeBuilder {
this.gradientAngle = gradientAngle
return this
}
fun setShapeGradientCenterX(gradientCenterX: Int): ShapeBuilder {
this.gradientCenterX = gradientCenterX
return this
}
fun setShapeGradientCenterY(gradientCenterY: Int): ShapeBuilder {
this.gradientCenterY = gradientCenterY
return this
}
fun setShapeGradientGradientRadius(gradientGradientRadius: Int): ShapeBuilder {
this.gradientGradientRadius = gradientGradientRadius
return this
}
fun setShapeGradientStartColor(gradientStartColor: Int): ShapeBuilder {
this.gradientStartColor = gradientStartColor
return this
}
fun setShapeGradientCenterColor(gradientCenterColor: Int): ShapeBuilder {
this.gradientCenterColor = gradientCenterColor
return this
}
fun setShapeGradientEndColor(gradientEndColor: Int): ShapeBuilder {
this.gradientEndColor = gradientEndColor
return this
}
fun setShapeGradientType(gradientType: Int): ShapeBuilder {
this.gradientType = gradientType
return this
}
fun setShapeGradientUseLevel(gradientUseLevel: Boolean): ShapeBuilder {
this.gradientUseLevel = gradientUseLevel
return this
}
fun init(targetView: View, attributeSetData: AttributeSetData) {
setShapeType(attributeSetData.shapeType)
setShapeCornersRadius(attributeSetData.cornersRadius)
setShapeCornersTopLeftRadius(attributeSetData.cornersTopLeftRadius)
setShapeCornersTopRightRadius(attributeSetData.cornersTopRightRadius)
setShapeCornersBottomRightRadius(attributeSetData.cornersBottomRightRadius)
setShapeCornersBottomLeftRadius(attributeSetData.cornersBottomLeftRadius)
setShapeSolidColor(attributeSetData.solidColor)
setShapeStrokeColor(attributeSetData.strokeColor)
setShapeStrokeWidth(attributeSetData.strokeWidth)
setShapeStrokeDashWidth(attributeSetData.strokeDashWidth)
setShapeStrokeDashGap(attributeSetData.strokeDashGap)
setShapeUseSelector(attributeSetData.useSelector)
setShapeSelectorNormalColor(attributeSetData.selectorNormalColor)
setShapeSelectorPressedColor(attributeSetData.selectorPressedColor)
setShapeSelectorDisableColor(attributeSetData.selectorDisableColor)
setShapeSizeWidth(attributeSetData.sizeWidth)
setShapeSizeHeight(attributeSetData.sizeHeight)
setShapeGradientType(attributeSetData.gradientType)
setShapeGradientAngle(attributeSetData.gradientAngle)
setShapeGradientGradientRadius(attributeSetData.gradientGradientRadius)
setShapeGradientUseLevel(attributeSetData.gradientUseLevel)
setShapeGradientCenterX(attributeSetData.gradientCenterX)
setShapeGradientCenterY(attributeSetData.gradientCenterY)
setShapeGradientStartColor(attributeSetData.gradientStartColor)
setShapeGradientCenterColor(attributeSetData.gradientCenterColor)
setShapeGradientEndColor(attributeSetData.gradientEndColor)
into(targetView)
}
private fun setShapeType(gradientDrawable: GradientDrawable) {
if (shapeType != -1) {
when (shapeType) {
RECTANGLE -> gradientDrawable.shape = GradientDrawable.RECTANGLE
OVAL -> gradientDrawable.shape = GradientDrawable.OVAL
LINE -> gradientDrawable.shape = GradientDrawable.LINE
RING -> gradientDrawable.shape = GradientDrawable.RING
}
}
}
private fun setSize(gradientDrawable: GradientDrawable) {
if (sizeWidth > 0 || sizeHeight > 0) {
gradientDrawable.setSize(sizeWidth, sizeHeight)
}
}
/**
* 设置边框 宽度 颜色 虚线 间隙
*/
private fun setBorder(gradientDrawable: GradientDrawable) {
if (strokeWidth >= 0) {
gradientDrawable.setStroke(strokeWidth, strokeColor, strokeDashWidth, strokeDashGap)
}
}
/**
* 只有类型是矩形的时候设置圆角半径才有效
*/
private fun setRadius(gradientDrawable: GradientDrawable) {
if (shapeType == RECTANGLE) {
if (cornersRadius != 0f) {
gradientDrawable.cornerRadius = cornersRadius
} else {
if (cornersTopLeftRadius != 0f || cornersTopRightRadius != 0f || cornersBottomRightRadius != 0f || cornersBottomLeftRadius != 0f) {
//1、2两个参数表示左上角,3、4表示右上角,5、6表示右下角,7、8表示左下角
gradientDrawable.cornerRadii = floatArrayOf(cornersTopLeftRadius, cornersTopLeftRadius, cornersTopRightRadius, cornersTopRightRadius, cornersBottomRightRadius, cornersBottomRightRadius, cornersBottomLeftRadius, cornersBottomLeftRadius)
}
}
}
}
private fun setSolidColor(gradientDrawable: GradientDrawable) {
if (gradientStartColor == -1 && gradientEndColor == -1) {
gradientDrawable.setColor(solidColor)
}
}
/**
* 设置Selector的不同状态的颜色
*
* @param state 按钮状态
*/
private fun setSelectorColor(gradientDrawable: GradientDrawable, state: Int) {
if (useSelector && state != 0) {
when (state) {
android.R.attr.state_pressed -> gradientDrawable.setColor(selectorPressedColor)
-android.R.attr.state_enabled -> gradientDrawable.setColor(selectorDisableColor)
android.R.attr.state_enabled -> gradientDrawable.setColor(selectorNormalColor)
}
}
}
/**
* 设置背景颜色
* 如果设定的有Orientation 就默认为是渐变色的Button,否则就是纯色的Button
*/
private fun setGradient(gradientDrawable: GradientDrawable) {
if (gradientStartColor != -1 || gradientEndColor != -1) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
if (gradientCenterColor == -1) {
gradientDrawable.colors = intArrayOf(gradientStartColor, gradientEndColor)
} else {
gradientDrawable.colors = intArrayOf(gradientStartColor, gradientCenterColor, gradientEndColor)
}
when (gradientType) {
LINEAR -> {
gradientDrawable.gradientType = GradientDrawable.LINEAR_GRADIENT
if (gradientAngle != -1) {
gradientDrawable.orientation = getGradientOrientationByAngle(gradientAngle)
}
}
RADIAL -> {
gradientDrawable.gradientType = GradientDrawable.RADIAL_GRADIENT
gradientDrawable.gradientRadius = gradientGradientRadius.toFloat()
}
SWEEP -> gradientDrawable.gradientType = GradientDrawable.SWEEP_GRADIENT
}
if (gradientCenterX != 0 || gradientCenterY != 0) {
gradientDrawable.setGradientCenter(gradientCenterX.toFloat(), gradientCenterY.toFloat())
}
gradientDrawable.useLevel = gradientUseLevel
}
}
}
/**
* 设置颜色渐变类型
*
* @param gradientAngle gradientAngle
* @return Orientation
*/
private fun getGradientOrientationByAngle(gradientAngle: Int): GradientDrawable.Orientation? {
var orientation: GradientDrawable.Orientation? = null
when (gradientAngle) {
0 -> orientation = GradientDrawable.Orientation.LEFT_RIGHT
45 -> orientation = GradientDrawable.Orientation.BL_TR
90 -> orientation = GradientDrawable.Orientation.BOTTOM_TOP
135 -> orientation = GradientDrawable.Orientation.BR_TL
180 -> orientation = GradientDrawable.Orientation.RIGHT_LEFT
225 -> orientation = GradientDrawable.Orientation.TR_BL
270 -> orientation = GradientDrawable.Orientation.TOP_BOTTOM
315 -> orientation = GradientDrawable.Orientation.TL_BR
}
return orientation
}
/**
* 获取设置之后的Selector
* 注意该处的顺序,只要有一个状态与之相配,背景就会被换掉 所以不要把大范围放在前面了,
* 如果sd.addState(new[]{},normal)放在第一个的话,就没有什么效果了
* @return stateListDrawable
*/
private val selectorDrawable: StateListDrawable
get() {
val stateListDrawable = StateListDrawable()
stateListDrawable.addState(intArrayOf(android.R.attr.state_pressed, android.R.attr.state_enabled), getDrawable(android.R.attr.state_pressed))
stateListDrawable.addState(intArrayOf(-android.R.attr.state_enabled), getDrawable(-android.R.attr.state_enabled))
stateListDrawable.addState(intArrayOf(), getDrawable(android.R.attr.state_enabled))
return stateListDrawable
}
private fun getDrawable(state: Int): GradientDrawable {
val gradientDrawable = GradientDrawable()
setShapeType(gradientDrawable)
setGradient(gradientDrawable)
setSolidColor(gradientDrawable)
setBorder(gradientDrawable)
setRadius(gradientDrawable)
setSize(gradientDrawable)
setSelectorColor(gradientDrawable, state)
return gradientDrawable
}
fun into(view: View?) {
if (view == null) return
ViewCompat.setBackground(view, if (useSelector) selectorDrawable else getDrawable(0))
}
/**
* 单位转换工具类
*
* @param context 上下文对象
* @param dipValue 值
* @return 返回值
*/
private fun dip2px(context: Context, dipValue: Float): Int {
val scale = context.resources.displayMetrics.density
return (dipValue * scale + 0.5f).toInt()
}
}
package com.gingersoft.gsa.cloud.ui.view; package com.gingersoft.gsa.cloud.ui.view.textview;
import android.content.Context; import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
......
package com.gingersoft.gsa.cloud.ui.view.textview;
import android.content.Context;
import android.text.InputFilter;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.appcompat.widget.AppCompatTextView;
/**
* Created by Allen on 2017/6/29.
* <p>
* 基础TextView
*/
public class BaseTextView extends LinearLayout {
private Context mContext;
private AppCompatTextView topTextView, centerTextView, bottomTextView;
private LinearLayout.LayoutParams topTVParams, centerTVParams, bottomTVParams;
public BaseTextView(Context context) {
this(context, null);
}
public BaseTextView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public BaseTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.setOrientation(VERTICAL);
mContext = context;
initView();
}
private void initView() {
initTopView();
initCenterView();
initBottomView();
}
private void initTopView() {
if (topTVParams == null) {
topTVParams = getParams(topTVParams);
}
if (topTextView == null) {
topTextView = initTextView(topTVParams, topTextView);
}
}
private void initCenterView() {
if (centerTVParams == null) {
centerTVParams = getParams(centerTVParams);
}
if (centerTextView == null) {
centerTextView = initTextView(centerTVParams, centerTextView);
}
}
private void initBottomView() {
if (bottomTVParams == null) {
bottomTVParams = getParams(bottomTVParams);
}
if (bottomTextView == null) {
bottomTextView = initTextView(bottomTVParams, bottomTextView);
}
}
private AppCompatTextView initTextView(LinearLayout.LayoutParams params, AppCompatTextView textView) {
textView = getTextView(textView, params);
// textView.setGravity(Gravity.CENTER);
addView(textView);
return textView;
}
/**
* 初始化textView
*
* @param textView 对象
* @param layoutParams 对象
* @return 返回
*/
public AppCompatTextView getTextView(AppCompatTextView textView, LinearLayout.LayoutParams layoutParams) {
if (textView == null) {
textView = new AppCompatTextView(mContext);
textView.setLayoutParams(layoutParams);
textView.setVisibility(GONE);
}
return textView;
}
/**
* 初始化Params
*
* @param params 对象
* @return 返回
*/
public LayoutParams getParams(LayoutParams params) {
if (params == null) {
// TODO: 2017/7/21 问题记录 :之前设置 MATCH_PARENT导致每次重新设置string的时候,textView的宽度都已第一次为准,在列表中使用的时候服用出现混乱,特此记录一下,以后处理好布局之间套用时候设置WRAP_CONTENT和MATCH_PARENT出现问题
params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
}
return params;
}
private void setTextString(AppCompatTextView textView, CharSequence textString) {
textView.setText(textString);
if (!TextUtils.isEmpty(textString)) {
textView.setVisibility(VISIBLE);
}
}
public void setTopTextString(CharSequence s) {
setTextString(topTextView, s);
}
public void setCenterTextString(CharSequence s) {
setTextString(centerTextView, s);
}
public void setBottomTextString(CharSequence s) {
setTextString(bottomTextView, s);
}
public AppCompatTextView getTopTextView() {
return topTextView;
}
public AppCompatTextView getCenterTextView() {
return centerTextView;
}
public AppCompatTextView getBottomTextView() {
return bottomTextView;
}
public void setMaxEms(int topMaxEms, int centerMaxEms, int bottomMaxEms) {
if (topMaxEms != 0) {
topTextView.setEllipsize(TextUtils.TruncateAt.END);
topTextView.setFilters(new InputFilter[]{new InputFilter.LengthFilter(topMaxEms)});
}
if (centerMaxEms != 0) {
centerTextView.setEllipsize(TextUtils.TruncateAt.END);
centerTextView.setFilters(new InputFilter[]{new InputFilter.LengthFilter(centerMaxEms)});
}
if (bottomMaxEms != 0) {
bottomTextView.setEllipsize(TextUtils.TruncateAt.END);
bottomTextView.setFilters(new InputFilter[]{new InputFilter.LengthFilter(bottomMaxEms)});
}
}
public void setFakeBoldText(TextView textView, boolean isBold) {
if (textView != null) {
textView.getPaint().setFakeBoldText(isBold);
//在点击事件里边设置setFakeBoldText是无效的,必须调用invalidate刷新一下view
textView.invalidate();
}
}
public void setCenterSpaceHeight(int centerSpaceHeight) {
topTVParams.setMargins(0, 0, 0, centerSpaceHeight);
centerTVParams.setMargins(0, 0, 0, 0);
bottomTVParams.setMargins(0, centerSpaceHeight, 0, 0);
}
}
package com.gingersoft.gsa.cloud.ui.view.textview;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.os.Build;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import androidx.annotation.DrawableRes;
import androidx.appcompat.widget.AppCompatCheckBox;
import androidx.appcompat.widget.AppCompatEditText;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.appcompat.widget.SwitchCompat;
import com.gingersoft.gsa.cloud.ui.R;
import com.gingersoft.gsa.cloud.ui.view.helper.EditTextHelper;
import com.gingersoft.gsa.cloud.ui.view.helper.ShapeBuilder;
import com.gingersoft.gsa.cloud.ui.view.imageview.CircleImageView;
/**
* Created by Allen on 2017/7/1.
* <p>
* 打造万能的布局满足市面常见的样式
*/
public class SuperTextView extends RelativeLayout {
private Context mContext;
private BaseTextView leftView, centerView, rightView;
private LayoutParams leftBaseViewParams, centerBaseViewParams, rightBaseViewParams;
private CircleImageView leftIconIV, rightIconIV;
private LayoutParams leftImgParams, rightImgParams;
private int leftIconWidth;//左边图标的宽
private int leftIconHeight;//左边图标的高
private int rightIconWidth;//右边图标的宽
private int rightIconHeight;//右边图标的高
private int leftIconMarginLeft;//左边图标的左边距
private int rightIconMarginRight;//右边图标的右边距
private Drawable leftIconRes;//左边图标资源
private Drawable rightIconRes;//右边图标资源
private int defaultColor = 0xFF373737;//文字默认颜色
private int defaultSize = 15;//默认字体大小
private int defaultMaxEms = 0;
private int defaultMaxLines = 0;
private String mLeftTextString;
private String mLeftTopTextString;
private String mLeftBottomTextString;
private String mRightTextString;
private String mRightTopTextString;
private String mRightBottomTextString;
private String mCenterTextString;
private String mCenterTopTextString;
private String mCenterBottomTextString;
private ColorStateList mLeftTextColor;
private ColorStateList mLeftTopTextColor;
private ColorStateList mLeftBottomTextColor;
private ColorStateList mCenterTextColor;
private ColorStateList mCenterTopTextColor;
private ColorStateList mCenterBottomTextColor;
private ColorStateList mRightTextColor;
private ColorStateList mRightTopTextColor;
private ColorStateList mRightBottomTextColor;
private ColorStateList mRightEditHintTextColor;
private ColorStateList mRightEditTextColor;
private int mLeftTextSize;
private int mLeftTopTextSize;
private int mLeftBottomTextSize;
private int mRightTextSize;
private int mRightTopTextSize;
private int mRightBottomTextSize;
private int mCenterTextSize;
private int mCenterTopTextSize;
private int mCenterBottomTextSize;
private int mLeftTopLines;
private int mLeftLines;
private int mLeftBottomLines;
private int mCenterTopLines;
private int mCenterLines;
private int mCenterBottomLines;
private int mRightTopLines;
private int mRightLines;
private int mRightBottomLines;
private int mLeftTopMaxEms;
private int mLeftMaxEms;
private int mLeftBottomMaxEms;
private int mCenterTopMaxEms;
private int mCenterMaxEms;
private int mCenterBottomMaxEms;
private int mRightTopMaxEms;
private int mRightMaxEms;
private int mRightBottomMaxEms;
// private boolean mLeftTopTextBold;
// private boolean mLeftTextBold;
// private boolean mLeftBottomTextBold;
//
// private boolean mCenterTopTextBold;
// private boolean mCenterTextBold;
// private boolean mCenterBottomTextBold;
//
// private boolean mRightTopTextBold;
// private boolean mRightTextBold;
// private boolean mRightBottomTextBold;
private Drawable mLeftTextBackground;
private Drawable mCenterTextBackground;
private Drawable mRightTextBackground;
private Drawable mLeftTvDrawableLeft;
private Drawable mLeftTvDrawableRight;
private Drawable mCenterTvDrawableLeft;
private Drawable mCenterTvDrawableRight;
private Drawable mRightTvDrawableLeft;
private Drawable mRightTvDrawableRight;
private int mLeftTvDrawableWidth;
private int mLeftTvDrawableHeight;
private int mCenterTvDrawableWidth;
private int mCenterTvDrawableHeight;
private int mRightTvDrawableWidth;
private int mRightTvDrawableHeight;
private int mTextViewDrawablePadding;
private static final int gravity_Left_Center = 0;
private static final int gravity_Center = 1;
private static final int gravity_Right_Center = 2;
private static final int default_Gravity = 1;
private int mLeftGravity;
private int mCenterGravity;
private int mRightGravity;
private int mLeftTextGravity;
private int mCenterTextGravity;
private int mRightTextGravity;
private static final int text_gravity_Left = 0;
private static final int text_gravity_center = 1;
private static final int text_gravity_right = 2;
private static final int default_text_gravity = -1;
private int mLeftViewWidth;
private int mTopDividerLineMarginLR;
private int mTopDividerLineMarginLeft;
private int mTopDividerLineMarginRight;
private int mBottomDividerLineMarginLR;
private int mBottomDividerLineMarginLeft;
private int mBottomDividerLineMarginRight;
private int mDividerLineType;
private int mDividerLineColor;
private int mDividerLineHeight;
private int mDefaultDividerLineColor = 0xFFE8E8E8;//分割线默认颜色
/**
* 分割线的类型
*/
public static final int NONE = 0;
public static final int TOP = 1;
public static final int BOTTOM = 2;
public static final int BOTH = 3;
private static final int default_Divider = BOTTOM;
private int default_Margin = 10;
private int mLeftViewMarginLeft;
private int mLeftViewMarginRight;
private int mCenterViewMarginLeft;
private int mCenterViewMarginRight;
private int mRightViewMarginLeft;
private int mRightViewMarginRight;
private boolean useRipple;
private Drawable mBackground_drawable;
private OnSuperTextViewClickListener superTextViewClickListener;
private OnLeftTopTvClickListener leftTopTvClickListener;
private OnLeftTvClickListener leftTvClickListener;
private OnLeftBottomTvClickListener leftBottomTvClickListener;
private OnCenterTopTvClickListener centerTopTvClickListener;
private OnCenterTvClickListener centerTvClickListener;
private OnCenterBottomTvClickListener centerBottomTvClickListener;
private OnRightTopTvClickListener rightTopTvClickListener;
private OnRightTvClickListener rightTvClickListener;
private OnRightBottomTvClickListener rightBottomTvClickListener;
private OnSwitchCheckedChangeListener switchCheckedChangeListener;
private OnCheckBoxCheckedChangeListener checkBoxCheckedChangeListener;
private OnEditTextChangeListener editTextChangeListener;
private OnLeftImageViewClickListener leftImageViewClickListener;
private OnRightImageViewClickListener rightImageViewClickListener;
private static final int TYPE_CHECKBOX = 0;
private static final int TYPE_SWITCH = 1;
private static final int TYPE_EDIT = 2;
private static int mRightViewType;
private AppCompatCheckBox rightCheckBox;//右边checkbox
private LayoutParams rightCheckBoxParams;//右边checkbox
private Drawable rightCheckBoxBg;//checkBox的背景
private int rightCheckBoxMarginRight;//右边checkBox的右边距
private boolean isChecked;//是否默认选中
private int centerSpaceHeight;//中间空间的高度
private SwitchCompat mSwitch;
private LayoutParams mSwitchParams;//右边switch
private int rightSwitchMarginRight;
private boolean switchIsChecked = true;
private AppCompatEditText mEditText;
private LayoutParams mEditParams;
private int mEditMinWidth;
private int mEditImeOption;
private int mEditInputType;
private int rightEditMarginRight;
private int editActiveLineColor = -1;
private int mEditTextSize;
private int mEditCusorDrawableRes;
private boolean mEditCusorVisible;
private String mEditHintText;
private String mTextOff;
private String mTextOn;
private int mSwitchMinWidth;
private int mSwitchPadding;
private int mThumbTextPadding;
private Drawable mThumbResource;
private Drawable mTrackResource;
/////////////////////一下是shape相关属性
private int defaultShapeColor = 0xffffffff;
private int selectorPressedColor;
private int selectorNormalColor;
private int solidColor;
private float cornersRadius;
private float cornersTopLeftRadius;
private float cornersTopRightRadius;
private float cornersBottomLeftRadius;
private float cornersBottomRightRadius;
private int strokeWidth;
private int strokeColor;
private float strokeDashWidth;
private float strokeDashGap;
private boolean useShape;
private boolean mLeftIconShowCircle;
private boolean mRightIconShowCircle;
private GradientDrawable gradientDrawable;
private Paint mTopDividerPaint;
private Paint mBottomDividerPaint;
private boolean mIsShowTopDivider;
private boolean mIsShowBottomDivider;
private ShapeBuilder shapeBuilder;
public SuperTextView(Context context) {
this(context, null);
}
public SuperTextView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public SuperTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mContext = context;
defaultSize = sp2px(context, defaultSize);
default_Margin = dip2px(context, default_Margin);
shapeBuilder = new ShapeBuilder();
getAttr(attrs);
initPaint();
initView();
}
private void getAttr(AttributeSet attrs) {
TypedArray typedArray = mContext.obtainStyledAttributes(attrs, R.styleable.SuperTextView);
/////////////////////////////////////////////////
mLeftTextString = typedArray.getString(R.styleable.SuperTextView_sLeftTextString);
mLeftTopTextString = typedArray.getString(R.styleable.SuperTextView_sLeftTopTextString);
mLeftBottomTextString = typedArray.getString(R.styleable.SuperTextView_sLeftBottomTextString);
mCenterTextString = typedArray.getString(R.styleable.SuperTextView_sCenterTextString);
mCenterTopTextString = typedArray.getString(R.styleable.SuperTextView_sCenterTopTextString);
mCenterBottomTextString = typedArray.getString(R.styleable.SuperTextView_sCenterBottomTextString);
mRightTextString = typedArray.getString(R.styleable.SuperTextView_sRightTextString);
mRightTopTextString = typedArray.getString(R.styleable.SuperTextView_sRightTopTextString);
mRightBottomTextString = typedArray.getString(R.styleable.SuperTextView_sRightBottomTextString);
//////////////////////////////////////////////////
mLeftTextColor = typedArray.getColorStateList(R.styleable.SuperTextView_sLeftTextColor);
mLeftTopTextColor = typedArray.getColorStateList(R.styleable.SuperTextView_sLeftTopTextColor);
mLeftBottomTextColor = typedArray.getColorStateList(R.styleable.SuperTextView_sLeftBottomTextColor);
mCenterTextColor = typedArray.getColorStateList(R.styleable.SuperTextView_sCenterTextColor);
mCenterTopTextColor = typedArray.getColorStateList(R.styleable.SuperTextView_sCenterTopTextColor);
mCenterBottomTextColor = typedArray.getColorStateList(R.styleable.SuperTextView_sCenterBottomTextColor);
mRightTextColor = typedArray.getColorStateList(R.styleable.SuperTextView_sRightTextColor);
mRightTopTextColor = typedArray.getColorStateList(R.styleable.SuperTextView_sRightTopTextColor);
mRightBottomTextColor = typedArray.getColorStateList(R.styleable.SuperTextView_sRightBottomTextColor);
//////////////////////////////////////////////////
mLeftTextSize = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sLeftTextSize, defaultSize);
mLeftTopTextSize = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sLeftTopTextSize, defaultSize);
mLeftBottomTextSize = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sLeftBottomTextSize, defaultSize);
mCenterTextSize = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sCenterTextSize, defaultSize);
mCenterTopTextSize = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sCenterTopTextSize, defaultSize);
mCenterBottomTextSize = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sCenterBottomTextSize, defaultSize);
mRightTextSize = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sRightTextSize, defaultSize);
mRightTopTextSize = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sRightTopTextSize, defaultSize);
mRightBottomTextSize = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sRightBottomTextSize, defaultSize);
//////////////////////////////////////////////////
mLeftTopLines = typedArray.getInt(R.styleable.SuperTextView_sLeftTopLines, defaultMaxLines);
mLeftLines = typedArray.getInt(R.styleable.SuperTextView_sLeftLines, defaultMaxLines);
mLeftBottomLines = typedArray.getInt(R.styleable.SuperTextView_sLeftBottomLines, defaultMaxLines);
mCenterTopLines = typedArray.getInt(R.styleable.SuperTextView_sCenterTopLines, defaultMaxLines);
mCenterLines = typedArray.getInt(R.styleable.SuperTextView_sCenterLines, defaultMaxLines);
mCenterBottomLines = typedArray.getInt(R.styleable.SuperTextView_sCenterBottomLines, defaultMaxLines);
mRightTopLines = typedArray.getInt(R.styleable.SuperTextView_sRightTopLines, defaultMaxLines);
mRightLines = typedArray.getInt(R.styleable.SuperTextView_sRightLines, defaultMaxLines);
mRightBottomLines = typedArray.getInt(R.styleable.SuperTextView_sRightBottomLines, defaultMaxLines);
//////////////////////////////////////////////////
mLeftTopMaxEms = typedArray.getInt(R.styleable.SuperTextView_sLeftTopMaxEms, defaultMaxEms);
mLeftMaxEms = typedArray.getInt(R.styleable.SuperTextView_sLeftMaxEms, defaultMaxEms);
mLeftBottomMaxEms = typedArray.getInt(R.styleable.SuperTextView_sLeftBottomMaxEms, defaultMaxEms);
mCenterTopMaxEms = typedArray.getInt(R.styleable.SuperTextView_sCenterTopMaxEms, defaultMaxEms);
mCenterMaxEms = typedArray.getInt(R.styleable.SuperTextView_sCenterMaxEms, defaultMaxEms);
mCenterBottomMaxEms = typedArray.getInt(R.styleable.SuperTextView_sCenterBottomMaxEms, defaultMaxEms);
mRightTopMaxEms = typedArray.getInt(R.styleable.SuperTextView_sRightTopMaxEms, defaultMaxEms);
mRightMaxEms = typedArray.getInt(R.styleable.SuperTextView_sRightMaxEms, defaultMaxEms);
mRightBottomMaxEms = typedArray.getInt(R.styleable.SuperTextView_sRightBottomMaxEms, defaultMaxEms);
////////////////////////////////////////////////
mLeftGravity = typedArray.getInt(R.styleable.SuperTextView_sLeftViewGravity, default_Gravity);
mCenterGravity = typedArray.getInt(R.styleable.SuperTextView_sCenterViewGravity, default_Gravity);
mRightGravity = typedArray.getInt(R.styleable.SuperTextView_sRightViewGravity, default_Gravity);
mLeftTextGravity = typedArray.getInt(R.styleable.SuperTextView_sLeftTextGravity, default_text_gravity);
mCenterTextGravity = typedArray.getInt(R.styleable.SuperTextView_sCenterTextGravity, default_text_gravity);
mRightTextGravity = typedArray.getInt(R.styleable.SuperTextView_sRightTextGravity, default_text_gravity);
////////////////////////////////////////////////
mLeftTvDrawableLeft = typedArray.getDrawable(R.styleable.SuperTextView_sLeftTvDrawableLeft);
mLeftTvDrawableRight = typedArray.getDrawable(R.styleable.SuperTextView_sLeftTvDrawableRight);
mCenterTvDrawableLeft = typedArray.getDrawable(R.styleable.SuperTextView_sCenterTvDrawableLeft);
mCenterTvDrawableRight = typedArray.getDrawable(R.styleable.SuperTextView_sCenterTvDrawableRight);
mRightTvDrawableLeft = typedArray.getDrawable(R.styleable.SuperTextView_sRightTvDrawableLeft);
mRightTvDrawableRight = typedArray.getDrawable(R.styleable.SuperTextView_sRightTvDrawableRight);
mTextViewDrawablePadding = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sTextViewDrawablePadding, default_Margin);
////////////////////////////////////////////////
mLeftTvDrawableWidth = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sLeftTvDrawableWidth, -1);
mLeftTvDrawableHeight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sLeftTvDrawableHeight, -1);
mCenterTvDrawableWidth = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sCenterTvDrawableWidth, -1);
mCenterTvDrawableHeight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sCenterTvDrawableHeight, -1);
mRightTvDrawableWidth = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sRightTvDrawableWidth, -1);
mRightTvDrawableHeight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sRightTvDrawableHeight, -1);
mLeftViewWidth = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sLeftViewWidth, 0);
///////////////////////////////////////////////
mTopDividerLineMarginLR = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sTopDividerLineMarginLR, 0);
mTopDividerLineMarginLeft = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sTopDividerLineMarginLeft, 0);
mTopDividerLineMarginRight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sTopDividerLineMarginRight, 0);
mBottomDividerLineMarginLR = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sBottomDividerLineMarginLR, 0);
mBottomDividerLineMarginLeft = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sBottomDividerLineMarginLeft, 0);
mBottomDividerLineMarginRight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sBottomDividerLineMarginRight, 0);
///////////////////////////////////////////////
mDividerLineType = typedArray.getInt(R.styleable.SuperTextView_sDividerLineType, default_Divider);
mDividerLineColor = typedArray.getColor(R.styleable.SuperTextView_sDividerLineColor, mDefaultDividerLineColor);
mDividerLineHeight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sDividerLineHeight, dip2px(mContext, 0.5f));
////////////////////////////////////////////////
mLeftViewMarginLeft = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sLeftViewMarginLeft, default_Margin);
mLeftViewMarginRight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sLeftViewMarginRight, default_Margin);
mCenterViewMarginLeft = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sCenterViewMarginLeft, 0);
mCenterViewMarginRight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sCenterViewMarginRight, 0);
mRightViewMarginLeft = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sRightViewMarginLeft, default_Margin);
mRightViewMarginRight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sRightViewMarginRight, default_Margin);
///////////////////////////////////////////////
leftIconWidth = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sLeftIconWidth, 0);
leftIconHeight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sLeftIconHeight, 0);
rightIconWidth = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sRightIconWidth, 0);
rightIconHeight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sRightIconHeight, 0);
leftIconMarginLeft = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sLeftIconMarginLeft, default_Margin);
rightIconMarginRight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sRightIconMarginRight, default_Margin);
leftIconRes = typedArray.getDrawable(R.styleable.SuperTextView_sLeftIconRes);
rightIconRes = typedArray.getDrawable(R.styleable.SuperTextView_sRightIconRes);
////////////////////////由于自定义方法数达到最大限度128个,暂时关闭不常用属性改为代码控制//////////////////////
// mLeftTopTextBold = typedArray.getBoolean(R.styleable.SuperTextView_sLeftTopTextIsBold, false);
// mLeftTextBold = typedArray.getBoolean(R.styleable.SuperTextView_sLeftTextIsBold, false);
// mLeftBottomTextBold = typedArray.getBoolean(R.styleable.SuperTextView_sLeftBottomTextIsBold, false);
//
// mCenterTopTextBold = typedArray.getBoolean(R.styleable.SuperTextView_sCenterTopTextIsBold, false);
// mCenterTextBold = typedArray.getBoolean(R.styleable.SuperTextView_sCenterTextIsBold, false);
// mCenterBottomTextBold = typedArray.getBoolean(R.styleable.SuperTextView_sCenterBottomTextIsBold, false);
//
// mRightTopTextBold = typedArray.getBoolean(R.styleable.SuperTextView_sRightTopTextIsBold, false);
// mRightTextBold = typedArray.getBoolean(R.styleable.SuperTextView_sRightTextIsBold, false);
// mRightBottomTextBold = typedArray.getBoolean(R.styleable.SuperTextView_sRightBottomTextIsBold, false);
mLeftTextBackground = typedArray.getDrawable(R.styleable.SuperTextView_sLeftTextBackground);
mCenterTextBackground = typedArray.getDrawable(R.styleable.SuperTextView_sCenterTextBackground);
mRightTextBackground = typedArray.getDrawable(R.styleable.SuperTextView_sRightTextBackground);
//////////////////////////////////////////////
useRipple = typedArray.getBoolean(R.styleable.SuperTextView_sUseRipple, true);
mBackground_drawable = typedArray.getDrawable(R.styleable.SuperTextView_sBackgroundDrawableRes);
///////////////////////////////////////////////
mRightViewType = typedArray.getInt(R.styleable.SuperTextView_sRightViewType, -1);
////////////////////////////////////////////////
switch (mRightViewType){
case TYPE_CHECKBOX:{
isChecked = typedArray.getBoolean(R.styleable.SuperTextView_sIsChecked, false);
rightCheckBoxMarginRight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sRightCheckBoxMarginRight, default_Margin);
rightCheckBoxBg = typedArray.getDrawable(R.styleable.SuperTextView_sRightCheckBoxRes);
}break;
case TYPE_SWITCH:{
rightSwitchMarginRight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sRightSwitchMarginRight, default_Margin);
switchIsChecked = typedArray.getBoolean(R.styleable.SuperTextView_sSwitchIsChecked, false);
mTextOff = typedArray.getString(R.styleable.SuperTextView_sTextOff);
mTextOn = typedArray.getString(R.styleable.SuperTextView_sTextOn);
mSwitchMinWidth = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sSwitchMinWidth, 0);
mSwitchPadding = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sSwitchPadding, 0);
mThumbTextPadding = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sThumbTextPadding, 0);
mThumbResource = typedArray.getDrawable(R.styleable.SuperTextView_sThumbResource);
mTrackResource = typedArray.getDrawable(R.styleable.SuperTextView_sTrackResource);
}break;
case TYPE_EDIT:{
rightEditMarginRight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sEditMarginRight, 0);
mEditMinWidth = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sEditMinWidth, 0);
mEditImeOption = typedArray.getInt(R.styleable.SuperTextView_android_imeOptions, EditorInfo.IME_NULL);
mEditInputType = typedArray.getInt(R.styleable.SuperTextView_android_inputType, EditorInfo.TYPE_NULL);
mRightEditTextColor = typedArray.getColorStateList(R.styleable.SuperTextView_sEditTextColor);
mRightEditHintTextColor = typedArray.getColorStateList(R.styleable.SuperTextView_sEditHintTextColor);
mEditHintText = typedArray.getString(R.styleable.SuperTextView_sEditHint);
editActiveLineColor = typedArray.getColor(R.styleable.SuperTextView_sEditActiveLineColor, editActiveLineColor);
mEditTextSize = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sEditTextSize, defaultSize);
mEditCusorDrawableRes = typedArray.getResourceId(R.styleable.SuperTextView_sEditCursorDrawable,0);
mEditCusorVisible = typedArray.getBoolean(R.styleable.SuperTextView_sEditCursorVisible,true);
}break;
}
centerSpaceHeight = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sCenterSpaceHeight, dip2px(mContext, 5));
////////////////////////////////////////////////////
selectorPressedColor = typedArray.getColor(R.styleable.SuperTextView_sShapeSelectorPressedColor, defaultShapeColor);
selectorNormalColor = typedArray.getColor(R.styleable.SuperTextView_sShapeSelectorNormalColor, defaultShapeColor);
solidColor = typedArray.getColor(R.styleable.SuperTextView_sShapeSolidColor, defaultShapeColor);
cornersRadius = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sShapeCornersRadius, 0);
cornersTopLeftRadius = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sShapeCornersTopLeftRadius, 0);
cornersTopRightRadius = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sShapeCornersTopRightRadius, 0);
cornersBottomLeftRadius = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sShapeCornersBottomLeftRadius, 0);
cornersBottomRightRadius = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sShapeCornersBottomRightRadius, 0);
strokeWidth = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sShapeStrokeWidth, 0);
strokeDashWidth = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sShapeStrokeDashWidth, 0);
strokeDashGap = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sShapeStrokeDashGap, 0);
strokeColor = typedArray.getColor(R.styleable.SuperTextView_sShapeStrokeColor, defaultShapeColor);
useShape = typedArray.getBoolean(R.styleable.SuperTextView_sUseShape, false);
mLeftIconShowCircle = typedArray.getBoolean(R.styleable.SuperTextView_sLeftIconShowCircle, false);
mRightIconShowCircle = typedArray.getBoolean(R.styleable.SuperTextView_sRightIconShowCircle, false);
typedArray.recycle();
}
/**
* 初始化Params
*
* @param params params
* @return params
*/
private LayoutParams getParams(LayoutParams params) {
if (params == null) {
params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
}
return params;
}
/**
* 初始化View
*/
private void initView() {
initSuperTextView();
initShape();
initLeftIcon();
switch (mRightViewType) {
case TYPE_CHECKBOX:
initRightCheckBox();
break;
case TYPE_SWITCH:
initRightSwitch();
break;
}
initRightIcon();
if(mRightViewType == TYPE_EDIT){
initRightEditText();
}
initLeftTextView();
initCenterTextView();
initRightTextView();
}
private void initShape() {
if (useShape) {
shapeBuilder
.setShapeType(ShapeBuilder.RECTANGLE)
.setShapeCornersRadius(cornersRadius)
.setShapeCornersTopLeftRadius(cornersTopLeftRadius)
.setShapeCornersTopRightRadius(cornersTopRightRadius)
.setShapeCornersBottomRightRadius(cornersBottomRightRadius)
.setShapeCornersBottomLeftRadius(cornersBottomLeftRadius)
.setShapeSolidColor(solidColor)
.setShapeStrokeColor(strokeColor)
.setShapeStrokeWidth(strokeWidth)
.setShapeStrokeDashWidth(strokeDashWidth)
.setShapeStrokeDashGap(strokeDashGap)
.setShapeUseSelector(true)
.setShapeSelectorNormalColor(selectorNormalColor)
.setShapeSelectorPressedColor(selectorPressedColor)
.into(this);
}
}
private void initPaint() {
mTopDividerPaint = new Paint();
mTopDividerPaint.setColor(mDividerLineColor);
mTopDividerPaint.setAntiAlias(true);
mTopDividerPaint.setStrokeWidth(mDividerLineHeight);
mBottomDividerPaint = new Paint();
mBottomDividerPaint.setColor(mDividerLineColor);
mBottomDividerPaint.setAntiAlias(true);
mBottomDividerPaint.setStrokeWidth(mDividerLineHeight);
}
/**
* onDraw和dispatchDraw的区别请自行google
*
* @param canvas 画笔
*/
@Override
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
if (!useShape) {
mIsShowTopDivider = (TOP == mDividerLineType || BOTH == mDividerLineType);
mIsShowBottomDivider = (BOTTOM == mDividerLineType || BOTH == mDividerLineType);
if (mIsShowTopDivider) {
drawTopDivider(canvas);
}
if (mIsShowBottomDivider) {
drawBottomDivider(canvas);
}
}
}
/**
* 绘制上边的分割线
*
* @param canvas canvas
*/
private void drawTopDivider(Canvas canvas) {
drawDivider(canvas, true, mTopDividerLineMarginLR, mTopDividerLineMarginLeft, mTopDividerLineMarginRight, mTopDividerPaint);
}
/**
* 绘制底部的分割线
*
* @param canvas canvas
*/
private void drawBottomDivider(Canvas canvas) {
drawDivider(canvas, false, mBottomDividerLineMarginLR, mBottomDividerLineMarginLeft, mBottomDividerLineMarginRight, mBottomDividerPaint);
}
/**
* 绘制分割线
*
* @param canvas canvas
* @param marginLR 左右间距
* @param marginLeft 左间距
* @param marginRight 右间距
* @param paint 画笔
*/
private void drawDivider(Canvas canvas, boolean isTopDivider, int marginLR, int marginLeft, int marginRight, Paint paint) {
if (marginLR != 0) {
marginLeft = marginRight = marginLR;
}
canvas.drawLine(marginLeft, isTopDivider ? 0 : getHeight(), this.getWidth() - marginRight, isTopDivider ? 0 : getHeight(), paint);
}
private void initSuperTextView() {
if (useRipple) {
this.setBackgroundResource(R.drawable.selector_white);
this.setClickable(true);
}
if (mBackground_drawable != null) {
this.setBackgroundDrawable(mBackground_drawable);
}
}
/**
* 初始化左边图标
*/
private void initLeftIcon() {
if (leftIconIV == null) {
leftIconIV = new CircleImageView(mContext);
}
leftImgParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
leftImgParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, TRUE);
leftImgParams.addRule(RelativeLayout.CENTER_VERTICAL, TRUE);
if (leftIconHeight != 0 && leftIconWidth != 0) {
leftImgParams.width = leftIconWidth;
leftImgParams.height = leftIconHeight;
}
// leftIconIV.setScaleType(ImageView.ScaleType.FIT_CENTER);
leftIconIV.setId(R.id.sLeftImgId);
leftIconIV.setLayoutParams(leftImgParams);
if (leftIconRes != null) {
leftImgParams.setMargins(leftIconMarginLeft, 0, 0, 0);
leftIconIV.setImageDrawable(leftIconRes);
}
setCircleImage(leftIconIV, mLeftIconShowCircle);
addView(leftIconIV);
}
/**
* 初始化右边图标
*/
private void initRightIcon() {
if (rightIconIV == null) {
rightIconIV = new CircleImageView(mContext);
}
rightImgParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
rightImgParams.addRule(RelativeLayout.CENTER_VERTICAL, TRUE);
switch (mRightViewType) {
case TYPE_CHECKBOX:
rightImgParams.addRule(RelativeLayout.LEFT_OF, R.id.sRightCheckBoxId);
break;
case TYPE_SWITCH:
rightImgParams.addRule(RelativeLayout.LEFT_OF, R.id.sRightSwitchId);
break;
default:
rightImgParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, TRUE);
}
if (rightIconHeight != 0 && rightIconWidth != 0) {
rightImgParams.width = rightIconWidth;
rightImgParams.height = rightIconHeight;
}
// rightIconIV.setScaleType(ImageView.ScaleType.FIT_CENTER);
rightIconIV.setId(R.id.sRightImgId);
rightIconIV.setLayoutParams(rightImgParams);
if (rightIconRes != null) {
rightImgParams.setMargins(0, 0, rightIconMarginRight, 0);
rightIconIV.setImageDrawable(rightIconRes);
}
setCircleImage(rightIconIV, mRightIconShowCircle);
addView(rightIconIV);
}
/**
* 初始化LeftTextView
*/
private void initLeftTextView() {
if (leftView == null) {
leftView = initBaseView(R.id.sLeftViewId);
}
leftBaseViewParams = getParams(leftBaseViewParams);
leftBaseViewParams.addRule(RelativeLayout.RIGHT_OF, R.id.sLeftImgId);
leftBaseViewParams.addRule(RelativeLayout.CENTER_VERTICAL, TRUE);
if (mLeftViewWidth != 0) {
leftBaseViewParams.width = mLeftViewWidth;
}
leftBaseViewParams.setMargins(mLeftViewMarginLeft, 0, mLeftViewMarginRight, 0);
leftView.setLayoutParams(leftBaseViewParams);
leftView.setCenterSpaceHeight(centerSpaceHeight);
setDefaultColor(leftView, mLeftTopTextColor, mLeftTextColor, mLeftBottomTextColor);
setDefaultSize(leftView, mLeftTopTextSize, mLeftTextSize, mLeftBottomTextSize);
setDefaultLines(leftView, mLeftTopLines, mLeftLines, mLeftBottomLines);
setDefaultMaxEms(leftView, mLeftTopMaxEms, mLeftMaxEms, mLeftBottomMaxEms);
// setDefaultTextIsBold(leftView, mLeftTopTextBold, mLeftTextBold, mLeftBottomTextBold);
setDefaultGravity(leftView, mLeftGravity);
setDefaultTextGravity(leftView, mLeftTextGravity);
setDefaultDrawable(leftView.getCenterTextView(), mLeftTvDrawableLeft, mLeftTvDrawableRight, mTextViewDrawablePadding, mLeftTvDrawableWidth, mLeftTvDrawableHeight);
setDefaultBackground(leftView.getCenterTextView(), mLeftTextBackground);
setDefaultString(leftView, mLeftTopTextString, mLeftTextString, mLeftBottomTextString);
addView(leftView);
}
/**
* 初始化CenterTextView
*/
private void initCenterTextView() {
if (centerView == null) {
centerView = initBaseView(R.id.sCenterViewId);
}
centerBaseViewParams = getParams(centerBaseViewParams);
centerBaseViewParams.addRule(RelativeLayout.CENTER_IN_PARENT, TRUE);
centerBaseViewParams.addRule(RelativeLayout.CENTER_VERTICAL, TRUE);
//默认情况下 中间的View整体剧中显示,设置左对齐或者右对齐的话使用下边属性
if (mCenterGravity != default_Gravity) {
centerBaseViewParams.addRule(RIGHT_OF, R.id.sLeftViewId);
centerBaseViewParams.addRule(LEFT_OF, R.id.sRightViewId);
}
centerBaseViewParams.setMargins(mCenterViewMarginLeft, 0, mCenterViewMarginRight, 0);
centerView.setLayoutParams(centerBaseViewParams);
centerView.setCenterSpaceHeight(centerSpaceHeight);
setDefaultColor(centerView, mCenterTopTextColor, mCenterTextColor, mCenterBottomTextColor);
setDefaultSize(centerView, mCenterTopTextSize, mCenterTextSize, mCenterBottomTextSize);
setDefaultLines(centerView, mCenterTopLines, mCenterLines, mCenterBottomLines);
setDefaultMaxEms(centerView, mCenterTopMaxEms, mCenterMaxEms, mCenterBottomMaxEms);
// setDefaultTextIsBold(centerView, mCenterTopTextBold, mCenterTextBold, mCenterBottomTextBold);
setDefaultGravity(centerView, mCenterGravity);
setDefaultTextGravity(centerView, mCenterTextGravity);
setDefaultDrawable(centerView.getCenterTextView(), mCenterTvDrawableLeft, mCenterTvDrawableRight, mTextViewDrawablePadding, mCenterTvDrawableWidth, mCenterTvDrawableHeight);
setDefaultBackground(centerView.getCenterTextView(), mCenterTextBackground);
setDefaultString(centerView, mCenterTopTextString, mCenterTextString, mCenterBottomTextString);
addView(centerView);
}
/**
* 初始化RightTextView
*/
private void initRightTextView() {
if (rightView == null) {
rightView = initBaseView(R.id.sRightViewId);
}
rightBaseViewParams = getParams(rightBaseViewParams);
rightBaseViewParams.addRule(RelativeLayout.CENTER_VERTICAL, TRUE);
rightBaseViewParams.addRule(RelativeLayout.LEFT_OF, R.id.sRightImgId);
rightBaseViewParams.setMargins(mRightViewMarginLeft, 0, mRightViewMarginRight, 0);
rightView.setLayoutParams(rightBaseViewParams);
rightView.setCenterSpaceHeight(centerSpaceHeight);
setDefaultColor(rightView, mRightTopTextColor, mRightTextColor, mRightBottomTextColor);
setDefaultSize(rightView, mRightTopTextSize, mRightTextSize, mRightBottomTextSize);
setDefaultLines(rightView, mRightTopLines, mRightLines, mRightBottomLines);
setDefaultMaxEms(rightView, mRightTopMaxEms, mRightMaxEms, mRightBottomMaxEms);
// setDefaultTextIsBold(rightView, mRightTopTextBold, mRightTextBold, mRightBottomTextBold);
setDefaultGravity(rightView, mRightGravity);
setDefaultTextGravity(rightView, mRightTextGravity);
setDefaultDrawable(rightView.getCenterTextView(), mRightTvDrawableLeft, mRightTvDrawableRight, mTextViewDrawablePadding, mRightTvDrawableWidth, mRightTvDrawableHeight);
setDefaultBackground(rightView.getCenterTextView(), mRightTextBackground);
setDefaultString(rightView, mRightTopTextString, mRightTextString, mRightBottomTextString);
addView(rightView);
}
/**
* 初始化RightCheckBox
*/
private void initRightCheckBox() {
if (rightCheckBox == null) {
rightCheckBox = new AppCompatCheckBox(mContext);
}
rightCheckBoxParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
rightCheckBoxParams.addRule(ALIGN_PARENT_RIGHT, TRUE);
rightCheckBoxParams.addRule(RelativeLayout.CENTER_VERTICAL, TRUE);
rightCheckBoxParams.setMargins(0, 0, rightCheckBoxMarginRight, 0);
rightCheckBox.setId(R.id.sRightCheckBoxId);
rightCheckBox.setLayoutParams(rightCheckBoxParams);
if (rightCheckBoxBg != null) {
rightCheckBox.setGravity(CENTER_IN_PARENT);
rightCheckBox.setButtonDrawable(rightCheckBoxBg);
}
rightCheckBox.setChecked(isChecked);
rightCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (checkBoxCheckedChangeListener != null) {
checkBoxCheckedChangeListener.onCheckedChanged(buttonView, isChecked);
}
}
});
addView(rightCheckBox);
}
/**
* 初始化RightSwitch
*/
private void initRightSwitch() {
if (mSwitch == null) {
mSwitch = new SwitchCompat(mContext);
}
mSwitchParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
mSwitchParams.addRule(ALIGN_PARENT_RIGHT, TRUE);
mSwitchParams.addRule(RelativeLayout.CENTER_VERTICAL, TRUE);
mSwitchParams.setMargins(0, 0, rightSwitchMarginRight, 0);
mSwitch.setId(R.id.sRightSwitchId);
mSwitch.setLayoutParams(mSwitchParams);
mSwitch.setChecked(switchIsChecked);
if (!TextUtils.isEmpty(mTextOff)) {
mSwitch.setTextOff(mTextOff);
mSwitch.setShowText(true);
}
if (!TextUtils.isEmpty(mTextOn)) {
mSwitch.setTextOn(mTextOn);
mSwitch.setShowText(true);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
if (mSwitchMinWidth != 0) {
mSwitch.setSwitchMinWidth(mSwitchMinWidth);
}
if (mSwitchPadding != 0) {
mSwitch.setSwitchPadding(mSwitchPadding);
}
if (mThumbResource != null) {
mSwitch.setThumbDrawable(mThumbResource);
}
if (mThumbResource != null) {
mSwitch.setTrackDrawable(mTrackResource);
}
if (mThumbTextPadding != 0) {
mSwitch.setThumbTextPadding(mThumbTextPadding);
}
}
mSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (switchCheckedChangeListener != null) {
switchCheckedChangeListener.onCheckedChanged(buttonView, isChecked);
}
}
});
addView(mSwitch);
}
private void initRightEditText() {
if (mEditText == null) {
mEditText = new AppCompatEditText(mContext);
mEditText.setSingleLine(true);
mEditText.setGravity(Gravity.END);
mEditText.setImeOptions(mEditImeOption);
mEditText.setInputType(mEditInputType);
mEditText.setBackgroundDrawable(null);
mEditText.setTextSize(TypedValue.COMPLEX_UNIT_PX,mEditTextSize);
mEditText.setCursorVisible(mEditCusorVisible);
//setFocusable(true);
//setFocusableInTouchMode(true);
EditTextHelper.INSTANCE.setCursorDrawable(mEditText,mEditCusorDrawableRes);
}
if(mRightEditHintTextColor!=null){
mEditText.setHintTextColor(mRightEditHintTextColor);
}
if(mRightEditTextColor!=null){
mEditText.setTextColor(mRightEditTextColor);
}
if(mEditHintText!=null){
mEditText.setHint(mEditHintText);
}
if(mEditMinWidth==0){
mEditParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
}else{
mEditText.setMinWidth(mEditMinWidth);
mEditParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
}
mEditParams.addRule(RelativeLayout.LEFT_OF, R.id.sRightImgId);
mEditParams.addRule(RelativeLayout.CENTER_VERTICAL, TRUE);
mEditParams.setMargins(0, 0, rightEditMarginRight, 0);
mEditText.setId(R.id.sRightEditTextId);
mEditText.setLayoutParams(mEditParams);
addView(mEditText);
//setFocusable(false);
//setFocusableInTouchMode(false);
mEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
if (editTextChangeListener != null) {
editTextChangeListener.beforeTextChanged(s,start,count,after);
}
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (editTextChangeListener != null) {
editTextChangeListener.onTextChanged(s,start,before,count);
}
}
@Override
public void afterTextChanged(Editable s) {
if (editTextChangeListener != null) {
editTextChangeListener.afterTextChanged(s);
}
}
});
if(editActiveLineColor!=-1){
mEditText.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
setBottomDividerLineColor(editActiveLineColor);
}else{
setBottomDividerLineColor(mDividerLineColor);
}
}
});
}
}
/////////////////////////////////////默认属性设置----begin/////////////////////////////////
/**
* 设置圆形ImageView属性
*
* @param circleImageView view
* @param disableCircularTransformation 是否允许圆形转换 默认true
*/
private void setCircleImage(CircleImageView circleImageView, boolean disableCircularTransformation) {
circleImageView.setDisableCircularTransformation(!disableCircularTransformation);
}
/**
* 初始化BaseTextView
*
* @param id id
* @return baseTextView
*/
private BaseTextView initBaseView(int id) {
BaseTextView baseTextView = new BaseTextView(mContext);
baseTextView.setId(id);
return baseTextView;
}
/**
* 设置默认值
*
* @param baseTextView baseTextView
* @param topTextString topTextString
* @param leftTextString leftTextString
* @param bottomTextString bottomTextString
*/
private void setDefaultString(BaseTextView baseTextView, String topTextString, String leftTextString, String bottomTextString) {
if (baseTextView != null) {
baseTextView.setTopTextString(topTextString);
baseTextView.setCenterTextString(leftTextString);
baseTextView.setBottomTextString(bottomTextString);
}
}
/**
* 设置默认
*
* @param baseTextView baseTextView
* @param topTextColor topTextColor
* @param textColor textColor
* @param bottomTextColor bottomTextColor
*/
private void setDefaultColor(BaseTextView baseTextView, ColorStateList topTextColor, ColorStateList textColor, ColorStateList bottomTextColor) {
if (baseTextView != null) {
if (topTextColor == null) {
topTextColor = ColorStateList.valueOf(defaultColor);
}
if (textColor == null) {
textColor = ColorStateList.valueOf(defaultColor);
}
if (bottomTextColor == null) {
bottomTextColor = ColorStateList.valueOf(defaultColor);
}
baseTextView.getTopTextView().setTextColor(topTextColor);
baseTextView.getCenterTextView().setTextColor(textColor);
baseTextView.getBottomTextView().setTextColor(bottomTextColor);
}
}
/**
* 设置默认字体大小
*
* @param baseTextView baseTextView
* @param leftTextSize leftTextSize
* @param topTextSize topTextSize
* @param bottomTextSize bottomTextSize
*/
private void setDefaultSize(BaseTextView baseTextView, int topTextSize, int leftTextSize, int bottomTextSize) {
if (baseTextView != null) {
baseTextView.getTopTextView().setTextSize(TypedValue.COMPLEX_UNIT_PX, topTextSize);
baseTextView.getCenterTextView().setTextSize(TypedValue.COMPLEX_UNIT_PX, leftTextSize);
baseTextView.getBottomTextView().setTextSize(TypedValue.COMPLEX_UNIT_PX, bottomTextSize);
}
}
/**
* 设置默认maxEms
*
* @param baseTextView baseTextView
* @param topMaxEms topMaxEms
* @param centerMaxEms centerMaxEms
* @param bottomMaxEms bottomMaxEms
*/
private void setDefaultMaxEms(BaseTextView baseTextView, int topMaxEms, int centerMaxEms, int bottomMaxEms) {
if (baseTextView != null) {
baseTextView.setMaxEms(topMaxEms, centerMaxEms, bottomMaxEms);
}
}
/**
* 设置默认lines
*
* @param baseTextView baseTextView
* @param leftTopLines leftTopLines
* @param leftLines leftLines
* @param bottomLines bottomLines
*/
private void setDefaultLines(BaseTextView baseTextView, int leftTopLines, int leftLines, int bottomLines) {
if (baseTextView != null) {
if (leftTopLines != 0) {
baseTextView.getTopTextView().setMaxLines(leftTopLines);
}
if (leftLines != 0) {
baseTextView.getCenterTextView().setMaxLines(leftLines);
}
if (bottomLines != 0) {
baseTextView.getBottomTextView().setMaxLines(bottomLines);
}
}
}
/**
* 设置文字对其方式
*
* @param baseTextView baseTextView
* @param gravity 对其方式
*/
private void setDefaultGravity(BaseTextView baseTextView, int gravity) {
if (baseTextView != null) {
setGravity(baseTextView, gravity);
}
}
/**
* 文字对其方式
*
* @param baseTextView textView
* @param gravity 对其方式
*/
private void setGravity(BaseTextView baseTextView, int gravity) {
switch (gravity) {
case gravity_Left_Center:
baseTextView.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
break;
case gravity_Center:
baseTextView.setGravity(Gravity.CENTER);
break;
case gravity_Right_Center:
baseTextView.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
break;
}
}
/**
* 设置文字对其方式
*
* @param baseTextView baseTextView
* @param gravity 对其方式
*/
private void setDefaultTextGravity(BaseTextView baseTextView, int gravity) {
if (baseTextView != null) {
switch (gravity) {
case text_gravity_Left:
setTextGravity(baseTextView, Gravity.LEFT);
break;
case text_gravity_center:
setTextGravity(baseTextView, Gravity.CENTER);
break;
case text_gravity_right:
setTextGravity(baseTextView, Gravity.RIGHT);
break;
}
}
}
/**
* 设置textView的drawable
*
* @param textView 对象
* @param drawableLeft 左边图标
* @param drawableRight 右边图标
* @param drawablePadding 图标距离文字的间距
*/
public void setDefaultDrawable(AppCompatTextView textView, Drawable drawableLeft, Drawable drawableRight, int drawablePadding, int drawableWidth, int drawableHeight) {
if (drawableLeft != null || drawableRight != null) {
textView.setVisibility(VISIBLE);
}
//可以指定drawable的宽高
if (drawableWidth != -1 && drawableHeight != -1) {
if (drawableLeft != null) {
drawableLeft.setBounds(0, 0, drawableWidth, drawableHeight);
}
if (drawableRight != null) {
drawableRight.setBounds(0, 0, drawableWidth, drawableHeight);
}
textView.setCompoundDrawables(drawableLeft, null, drawableRight, null);
} else {
textView.setCompoundDrawablesWithIntrinsicBounds(drawableLeft, null, drawableRight, null);
}
textView.setCompoundDrawablePadding(drawablePadding);
}
/**
* 设置textView的背景,用户传入drawable实现圆角之类的样式
*
* @param textView
* @param background
*/
private void setDefaultBackground(AppCompatTextView textView, Drawable background) {
if (background != null) {
textView.setVisibility(VISIBLE);
if (Build.VERSION.SDK_INT < 16) {
textView.setBackgroundDrawable(background);
} else {
textView.setBackground(background);
}
}
}
/**
* 左边点击事件
*
* @param baseTextView baseTextView
*/
private void setDefaultLeftViewClickListener(BaseTextView baseTextView) {
if (baseTextView != null) {
if (leftTopTvClickListener != null) {
baseTextView.getTopTextView().setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
leftTopTvClickListener.onClickListener();
}
});
}
if (leftTvClickListener != null) {
baseTextView.getCenterTextView().setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
leftTvClickListener.onClickListener();
}
});
}
if (leftBottomTvClickListener != null) {
baseTextView.getBottomTextView().setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
leftBottomTvClickListener.onClickListener();
}
});
}
}
}
/**
* 中间点击事件
*
* @param baseTextView baseTextView
*/
private void setDefaultCenterViewClickListener(BaseTextView baseTextView) {
if (baseTextView != null) {
if (centerTopTvClickListener != null) {
baseTextView.getTopTextView().setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
centerTopTvClickListener.onClickListener();
}
});
}
if (centerTvClickListener != null) {
baseTextView.getCenterTextView().setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
centerTvClickListener.onClickListener();
}
});
}
if (centerBottomTvClickListener != null) {
baseTextView.getBottomTextView().setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
centerBottomTvClickListener.onClickListener();
}
});
}
}
}
/**
* 右边点击事件
*
* @param baseTextView baseTextView
*/
private void setDefaultRightViewClickListener(BaseTextView baseTextView) {
if (baseTextView != null) {
if (rightTopTvClickListener != null) {
baseTextView.getTopTextView().setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
rightTopTvClickListener.onClickListener();
}
});
}
if (rightTvClickListener != null) {
baseTextView.getCenterTextView().setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
rightTvClickListener.onClickListener();
}
});
}
if (rightBottomTvClickListener != null) {
baseTextView.getBottomTextView().setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
rightBottomTvClickListener.onClickListener();
}
});
}
}
}
/**
* 字体是否加粗
*
* @param baseTextView baseTextView
* @param topTextBold 上边字体加粗
* @param centerTextBold 中间字体加粗
* @param bottomTextBold 下边字体加粗
*/
private void setDefaultTextIsBold(BaseTextView baseTextView, boolean topTextBold, boolean centerTextBold, boolean bottomTextBold) {
if (baseTextView != null) {
baseTextView.getTopTextView().getPaint().setFakeBoldText(topTextBold);
baseTextView.getCenterTextView().getPaint().setFakeBoldText(centerTextBold);
baseTextView.getBottomTextView().getPaint().setFakeBoldText(bottomTextBold);
}
}
/////////////////////////////////////默认属性设置----end/////////////////////////////////
/////////////////////////////////////对外暴露的方法---begin/////////////////////////////////
/**
* 设置左上字符串
*
* @param string 字符串
* @return 方便链式调用
*/
public SuperTextView setLeftTopString(CharSequence string) {
if (leftView != null) {
leftView.setTopTextString(string);
}
return this;
}
/**
* 设置左中字符串
*
* @param string 字符串
* @return 方便链式调用
*/
public SuperTextView setLeftString(CharSequence string) {
if (leftView != null) {
leftView.setCenterTextString(string);
}
return this;
}
/**
* 设置左下字符串
*
* @param string 字符串
* @return 方便链式调用
*/
public SuperTextView setLeftBottomString(CharSequence string) {
if (leftView != null) {
leftView.setBottomTextString(string);
}
return this;
}
/**
* 设置中上字符串
*
* @param string 字符串
* @return 方便链式调用
*/
public SuperTextView setCenterTopString(CharSequence string) {
if (centerView != null) {
centerView.setTopTextString(string);
}
return this;
}
/**
* 设置中间字符串
*
* @param string 字符串
* @return 方便链式调用
*/
public SuperTextView setCenterString(CharSequence string) {
if (centerView != null) {
centerView.setCenterTextString(string);
}
return this;
}
/**
* 设置中下字符串
*
* @param string 字符串
* @return 方便链式调用
*/
public SuperTextView setCenterBottomString(CharSequence string) {
if (centerView != null) {
centerView.setBottomTextString(string);
}
return this;
}
/**
* 设置右上字符串
*
* @param string 字符串
* @return 方便链式调用
*/
public SuperTextView setRightTopString(CharSequence string) {
if (rightView != null) {
rightView.setTopTextString(string);
}
return this;
}
/**
* 设置右中字符串
*
* @param string 字符串
* @return 方便链式调用
*/
public SuperTextView setRightString(CharSequence string) {
if (rightView != null) {
rightView.setCenterTextString(string);
}
return this;
}
/**
* 设置右下字符串
*
* @param string 字符串
* @return 方便链式调用
*/
public SuperTextView setRightBottomString(CharSequence string) {
if (rightView != null) {
rightView.setBottomTextString(string);
}
return this;
}
/**
* 设置左上文字颜色
*
* @param color 颜色值
* @return SuperTextView
*/
public SuperTextView setLeftTopTextColor(int color) {
ColorStateList colorStateList = ColorStateList.valueOf(color);
setLeftTopTextColor(colorStateList);
return this;
}
/**
* 设置左上文字颜色
*
* @param color 颜色值
* @return SuperTextView
*/
public SuperTextView setLeftTopTextColor(ColorStateList color) {
if (leftView != null) {
if (color == null) {
throw new NullPointerException();
}
leftView.getTopTextView().setTextColor(color);
}
return this;
}
/**
* 设置左中文字颜色
*
* @param color 颜色值
* @return SuperTextView
*/
public SuperTextView setLeftTextColor(int color) {
ColorStateList colorStateList = ColorStateList.valueOf(color);
setLeftTextColor(colorStateList);
return this;
}
/**
* 设置左中文字颜色
*
* @param color 颜色值
* @return SuperTextView
*/
public SuperTextView setLeftTextColor(ColorStateList color) {
if (leftView != null) {
if (color == null) {
throw new NullPointerException();
}
leftView.getCenterTextView().setTextColor(color);
}
return this;
}
/**
* 设置左下文字颜色
*
* @param color 颜色值
* @return SuperTextView
*/
public SuperTextView setLeftBottomTextColor(int color) {
ColorStateList colorStateList = ColorStateList.valueOf(color);
setLeftBottomTextColor(colorStateList);
return this;
}
/**
* 设置左下文字颜色
*
* @param color 颜色值
* @return SuperTextView
*/
public SuperTextView setLeftBottomTextColor(ColorStateList color) {
if (leftView != null) {
if (color == null) {
throw new NullPointerException();
}
leftView.getBottomTextView().setTextColor(color);
}
return this;
}
/**
* 设置中上文字颜色
*
* @param color 颜色值
* @return SuperTextView
*/
public SuperTextView setCenterTopTextColor(int color) {
ColorStateList colorStateList = ColorStateList.valueOf(color);
setCenterTopTextColor(colorStateList);
return this;
}
/**
* 设置中上文字颜色
*
* @param color 颜色值
* @return SuperTextView
*/
public SuperTextView setCenterTopTextColor(ColorStateList color) {
if (centerView != null) {
if (color == null) {
throw new NullPointerException();
}
centerView.getTopTextView().setTextColor(color);
}
return this;
}
/**
* 设置中间文字颜色
*
* @param color 颜色值
* @return SuperTextView
*/
public SuperTextView setCenterTextColor(int color) {
ColorStateList colorStateList = ColorStateList.valueOf(color);
setCenterTextColor(colorStateList);
return this;
}
/**
* 设置中间文字颜色
*
* @param color 颜色值
* @return SuperTextView
*/
public SuperTextView setCenterTextColor(ColorStateList color) {
if (centerView != null) {
if (color == null) {
throw new NullPointerException();
}
centerView.getCenterTextView().setTextColor(color);
}
return this;
}
/**
* 设置中下文字颜色
*
* @param color 颜色值
* @return SuperTextView
*/
public SuperTextView setCenterBottomTextColor(int color) {
ColorStateList colorStateList = ColorStateList.valueOf(color);
setCenterBottomTextColor(colorStateList);
return this;
}
/**
* 设置中下文字颜色
*
* @param color 颜色值
* @return SuperTextView
*/
public SuperTextView setCenterBottomTextColor(ColorStateList color) {
if (centerView != null) {
if (color == null) {
throw new NullPointerException();
}
centerView.getBottomTextView().setTextColor(color);
}
return this;
}
/**
* 设置右上文字颜色
*
* @param color 颜色值
* @return SuperTextView
*/
public SuperTextView setRightTopTextColor(int color) {
ColorStateList colorStateList = ColorStateList.valueOf(color);
setRightTopTextColor(colorStateList);
return this;
}
/**
* 设置右上文字颜色
*
* @param color 颜色值
* @return SuperTextView
*/
public SuperTextView setRightTopTextColor(ColorStateList color) {
if (rightView != null) {
if (color == null) {
throw new NullPointerException();
}
rightView.getTopTextView().setTextColor(color);
}
return this;
}
/**
* 设置右中文字颜色
*
* @param color 颜色值
* @return SuperTextView
*/
public SuperTextView setRightTextColor(int color) {
ColorStateList colorStateList = ColorStateList.valueOf(color);
setRightTextColor(colorStateList);
return this;
}
/**
* 设置右中文字颜色
*
* @param color 颜色值
* @return SuperTextView
*/
public SuperTextView setRightTextColor(ColorStateList color) {
if (rightView != null) {
if (color == null) {
throw new NullPointerException();
}
rightView.getCenterTextView().setTextColor(color);
}
return this;
}
/**
* 设置右下文字颜色
*
* @param color 颜色值
* @return SuperTextView
*/
public SuperTextView setRightBottomTextColor(int color) {
ColorStateList colorStateList = ColorStateList.valueOf(color);
setRightBottomTextColor(colorStateList);
return this;
}
/**
* 设置右下文字颜色
*
* @param color 颜色值
* @return SuperTextView
*/
public SuperTextView setRightBottomTextColor(ColorStateList color) {
if (rightView != null) {
if (color == null) {
throw new NullPointerException();
}
rightView.getBottomTextView().setTextColor(color);
}
return this;
}
/**
* 设置左上文字字体为粗体
*
* @return SuperTextView
*/
public SuperTextView setLeftTopTextIsBold(boolean isBold) {
if (leftView != null) {
leftView.setFakeBoldText(leftView.getTopTextView(), isBold);
}
return this;
}
/**
* 设置左中文字字体为粗体
*
* @return SuperTextView
*/
public SuperTextView setLeftTextIsBold(boolean isBold) {
if (leftView != null) {
leftView.setFakeBoldText(leftView.getCenterTextView(), isBold);
}
return this;
}
/**
* 设置左下文字字体为粗体
*
* @return SuperTextView
*/
public SuperTextView setLeftBottomTextIsBold(boolean isBold) {
if (leftView != null) {
leftView.setFakeBoldText(leftView.getBottomTextView(), isBold);
}
return this;
}
/**
* 设置中上文字字体为粗体
*
* @return SuperTextView
*/
public SuperTextView setCenterTopTextIsBold(boolean isBold) {
if (centerView != null) {
centerView.setFakeBoldText(centerView.getTopTextView(), isBold);
}
return this;
}
/**
* 设置中中文字字体为粗体
*
* @return SuperTextView
*/
public SuperTextView setCenterTextIsBold(boolean isBold) {
if (centerView != null) {
centerView.setFakeBoldText(centerView.getCenterTextView(), isBold);
}
return this;
}
/**
* 设置中下文字字体为粗体
*
* @return SuperTextView
*/
public SuperTextView setCenterBottomTextIsBold(boolean isBold) {
if (centerView != null) {
centerView.setFakeBoldText(centerView.getBottomTextView(), isBold);
}
return this;
}
/**
* 设置右上文字字体为粗体
*
* @return SuperTextView
*/
public SuperTextView setRightTopTextIsBold(boolean isBold) {
if (rightView != null) {
rightView.setFakeBoldText(rightView.getTopTextView(), isBold);
}
return this;
}
/**
* 设置右中文字字体为粗体
*
* @return SuperTextView
*/
public SuperTextView setRightTextIsBold(boolean isBold) {
if (rightView != null) {
rightView.setFakeBoldText(rightView.getCenterTextView(), isBold);
}
return this;
}
/**
* 设置右下文字字体为粗体
*
* @return SuperTextView
*/
public SuperTextView setRightBottomTextIsBold(boolean isBold) {
if (rightView != null) {
rightView.setFakeBoldText(rightView.getBottomTextView(), isBold);
}
return this;
}
/**
* 获取左上字符串
*
* @return 返回字符串
*/
public String getLeftTopString() {
return leftView != null ? leftView.getTopTextView().getText().toString().trim() : "";
}
/**
* 获取左中字符串
*
* @return 返回字符串
*/
public String getLeftString() {
return leftView != null ? leftView.getCenterTextView().getText().toString().trim() : "";
}
/**
* 获取左下字符串
*
* @return 返回字符串
*/
public String getLeftBottomString() {
return leftView != null ? leftView.getBottomTextView().getText().toString().trim() : "";
}
////////////////////////////////////////////
/**
* 获取中上字符串
*
* @return 返回字符串
*/
public String getCenterTopString() {
return centerView != null ? centerView.getTopTextView().getText().toString().trim() : "";
}
/**
* 获取中间字符串
*
* @return 返回字符串
*/
public String getCenterString() {
return centerView != null ? centerView.getCenterTextView().getText().toString().trim() : "";
}
/**
* 获取中下字符串
*
* @return 返回字符串
*/
public String getCenterBottomString() {
return centerView != null ? centerView.getBottomTextView().getText().toString().trim() : "";
}
/**
* 获取右上字符串
*
* @return 返回字符串
*/
public String getRightTopString() {
return rightView != null ? rightView.getTopTextView().getText().toString().trim() : "";
}
/**
* 获取右中字符串
*
* @return 返回字符串
*/
public String getRightString() {
return rightView != null ? rightView.getCenterTextView().getText().toString().trim() : "";
}
/**
* 获取右下字符串
*
* @return 返回字符串
*/
public String getRightBottomString() {
return rightView != null ? rightView.getBottomTextView().getText().toString().trim() : "";
}
/**
* 获取左边ImageView
*
* @return ImageView
*/
public ImageView getLeftIconIV() {
leftImgParams.setMargins(leftIconMarginLeft, 0, 0, 0);
return leftIconIV;
}
/**
* 获取右边ImageView
*
* @return ImageView
*/
public ImageView getRightIconIV() {
rightImgParams.setMargins(0, 0, rightIconMarginRight, 0);
return rightIconIV;
}
/**
* 获取rightCheckBox
*
* @return rightCheckBox
*/
public CheckBox getCheckBox() {
return rightCheckBox;
}
/**
* @param checked 是否选中
* @return 返回值
*/
public SuperTextView setCbChecked(boolean checked) {
isChecked = checked;
if (rightCheckBox != null) {
rightCheckBox.setChecked(checked);
}
return this;
}
/**
* @param clickable 是否允许点击
* @return 返回值
*/
public SuperTextView setCbClickable(boolean clickable) {
if (rightCheckBox != null) {
rightCheckBox.setClickable(clickable);
}
return this;
}
/**
* 设置checkbox的背景图
*
* @param drawable drawable对象
* @return 返回对象
*/
public SuperTextView setCbBackground(Drawable drawable) {
rightCheckBoxBg = drawable;
if (rightCheckBox != null) {
rightCheckBox.setBackgroundDrawable(drawable);
}
return this;
}
/**
* 获取checkbox状态
*
* @return 返回选择框当前选中状态
*/
public boolean getCbisChecked() {
boolean isChecked = false;
if (rightCheckBox != null) {
isChecked = rightCheckBox.isChecked();
}
return isChecked;
}
/**
* @param checked Switch是否选中
* @return 返回值
*/
public SuperTextView setSwitchIsChecked(boolean checked) {
switchIsChecked = checked;
if (mSwitch != null) {
mSwitch.setChecked(checked);
}
return this;
}
/**
* @param clickable Switch是否允许点击
* @return 返回值
*/
public SuperTextView setSwitchClickable(boolean clickable) {
if (mSwitch != null) {
mSwitch.setClickable(clickable);
}
return this;
}
/**
* 获取switch状态
*
* @return 返回switch当前选中状态
*/
public boolean getSwitchIsChecked() {
boolean isChecked = false;
if (mSwitch != null) {
isChecked = mSwitch.isChecked();
}
return isChecked;
}
/**
* 获取switchView
*
* @return Switch
*/
public SwitchCompat getSwitch() {
return mSwitch;
}
/**
* 获取Edittext View
*
* @return AppCompatEditText
*/
public AppCompatEditText getEditText(){
return mEditText;
}
public SuperTextView setEditImeOptions(int option){
if (mEditText != null) {
mEditText.setImeOptions(option);
}
return this;
}
public SuperTextView setEditInputType(int inputType){
if (mEditText != null) {
mEditText.setInputType(inputType);
}
return this;
}
public SuperTextView setEditHintText(String hintText){
if (mEditText != null) {
mEditText.setHint(hintText);
}
return this;
}
public SuperTextView setEditHintTextColor(int color){
if (mEditText != null) {
setEditHintTextColor(ColorStateList.valueOf(color));
}
return this;
}
public SuperTextView setEditHintTextColor(ColorStateList color){
if (mEditText != null) {
if (color == null) {
throw new NullPointerException();
}
mEditText.setHintTextColor(color);
}
return this;
}
public SuperTextView setEditTextColor(int color){
if (mEditText != null) {
setEditTextColor(ColorStateList.valueOf(color));
}
return this;
}
public SuperTextView setEditTextColor(ColorStateList color){
if (mEditText != null) {
if (color == null) {
throw new NullPointerException();
}
mEditText.setTextColor(color);
}
return this;
}
public SuperTextView setEditCursorVisible(boolean visible){
if (mEditText != null) {
mEditText.setCursorVisible(visible);
}
return this;
}
public SuperTextView setEditCursorDrawableRes(@DrawableRes int drawableRes){
if (mEditText != null) {
EditTextHelper.INSTANCE.setCursorDrawable(mEditText,drawableRes);
}
return this;
}
/**
* 设置左边tv的左侧图片
*
* @param drawableLeft 左边图片资源
*/
public SuperTextView setLeftTvDrawableLeft(Drawable drawableLeft) {
setDefaultDrawable(leftView.getCenterTextView(), drawableLeft, null, mTextViewDrawablePadding, mLeftTvDrawableWidth, mLeftTvDrawableHeight);
return this;
}
/**
* 设置左边tv的右侧图片
*
* @param drawableRight 右边图片资源
*/
public SuperTextView setLeftTvDrawableRight(Drawable drawableRight) {
setDefaultDrawable(leftView.getCenterTextView(), null, drawableRight, mTextViewDrawablePadding, mLeftTvDrawableWidth, mLeftTvDrawableHeight);
return this;
}
/**
* 设置中间tv的左侧图片
*
* @param drawableLeft 左边图片资源
*/
public SuperTextView setCenterTvDrawableLeft(Drawable drawableLeft) {
setDefaultDrawable(centerView.getCenterTextView(), drawableLeft, null, mTextViewDrawablePadding, mCenterTvDrawableWidth, mCenterTvDrawableHeight);
return this;
}
/**
* 设置中间tv的右侧图片
*
* @param drawableRight 右边图片资源
*/
public SuperTextView setCenterTvDrawableRight(Drawable drawableRight) {
setDefaultDrawable(centerView.getCenterTextView(), null, drawableRight, mTextViewDrawablePadding, mCenterTvDrawableWidth, mCenterTvDrawableHeight);
return this;
}
/**
* 设置右边tv的左侧图片
*
* @param drawableLeft 左边图片资源
*/
public SuperTextView setRightTvDrawableLeft(Drawable drawableLeft) {
setDefaultDrawable(rightView.getCenterTextView(), drawableLeft, null, mTextViewDrawablePadding, mRightTvDrawableWidth, mRightTvDrawableHeight);
return this;
}
/**
* 设置右边tv的右侧图片
*
* @param drawableRight 右边图片资源
*/
public SuperTextView setRightTvDrawableRight(Drawable drawableRight) {
setDefaultDrawable(rightView.getCenterTextView(), null, drawableRight, mTextViewDrawablePadding, mRightTvDrawableWidth, mRightTvDrawableHeight);
return this;
}
/**
* 设置左边图标
*
* @param leftIcon 左边图标
* @return 返回对象
*/
public SuperTextView setLeftIcon(Drawable leftIcon) {
if (leftIconIV != null) {
leftImgParams.setMargins(leftIconMarginLeft, 0, 0, 0);
leftIconIV.setImageDrawable(leftIcon);
}
return this;
}
/**
* 设置左边图标
*
* @param resId 左边图标资源id
* @return 返回对象
*/
public SuperTextView setLeftIcon(int resId) {
if (leftIconIV != null) {
leftImgParams.setMargins(leftIconMarginLeft, 0, 0, 0);
leftIconIV.setImageResource(resId);
}
return this;
}
/**
* 设置右边图标
*
* @param rightIcon 右边图标
* @return 返回对象
*/
public SuperTextView setRightIcon(Drawable rightIcon) {
if (rightIconIV != null) {
rightImgParams.setMargins(0, 0, rightIconMarginRight, 0);
rightIconIV.setImageDrawable(rightIcon);
}
return this;
}
/**
* 设置右边图标资源Id
*
* @param resId 右边图标
* @return 返回对象
*/
public SuperTextView setRightIcon(int resId) {
if (rightIconIV != null) {
rightImgParams.setMargins(0, 0, rightIconMarginRight, 0);
rightIconIV.setImageResource(resId);
}
return this;
}
/**
* 设置背景
*
* @param drawable 背景资源
* @return 对象
*/
public SuperTextView setSBackground(Drawable drawable) {
if (drawable != null) {
this.setBackgroundDrawable(drawable);
}
return this;
}
/**
* 获取左上的TextView
*
* @return textView
*/
public AppCompatTextView getLeftTopTextView() {
if (leftView == null) {
initLeftTextView();
}
return leftView.getTopTextView();
}
/**
* 获取左中的TextView
*
* @return textView
*/
public AppCompatTextView getLeftTextView() {
if (leftView == null) {
initLeftTextView();
}
return leftView.getCenterTextView();
}
/**
* 获取左下的TextView
*
* @return textView
*/
public AppCompatTextView getLeftBottomTextView() {
if (leftView == null) {
initLeftTextView();
}
return leftView.getBottomTextView();
}
/**
* 获取中上的TextView
*
* @return textView
*/
public AppCompatTextView getCenterTopTextView() {
if (centerView == null) {
initCenterTextView();
}
return centerView.getTopTextView();
}
/**
* 获取中中的TextView
*
* @return textView
*/
public AppCompatTextView getCenterTextView() {
if (centerView == null) {
initCenterTextView();
}
return centerView.getCenterTextView();
}
/**
* 获取中下的TextView
*
* @return textView
*/
public AppCompatTextView getCenterBottomTextView() {
if (centerView == null) {
initCenterTextView();
}
return centerView.getBottomTextView();
}
/**
* 获取右上的TextView
*
* @return textView
*/
public AppCompatTextView getRightTopTextView() {
if (rightView == null) {
initRightTextView();
}
return rightView.getTopTextView();
}
/**
* 获取右中的TextView
*
* @return textView
*/
public AppCompatTextView getRightTextView() {
if (rightView == null) {
initRightTextView();
}
return rightView.getCenterTextView();
}
/**
* 获取右下的TextView
*
* @return textView
*/
public AppCompatTextView getRightBottomTextView() {
if (rightView == null) {
initRightTextView();
}
return rightView.getBottomTextView();
}
/**
* 设置左边textView文字对齐方式
*
* @param gravity 对齐方式
* @return SuperTextView
*/
public SuperTextView setLeftTextGravity(int gravity) {
setTextGravity(leftView, gravity);
return this;
}
/**
* 设置中间textView文字对齐方式
*
* @param gravity 对齐方式
* @return SuperTextView
*/
public SuperTextView setCenterTextGravity(int gravity) {
setTextGravity(centerView, gravity);
return this;
}
/**
* 设置右边textView文字对齐方式
*
* @param gravity 对齐方式
* @return SuperTextView
*/
public SuperTextView setRightTextGravity(int gravity) {
setTextGravity(rightView, gravity);
return this;
}
/**
* 文字对齐方式
*
* @param baseTextView view
* @param gravity 对齐方式
*/
private void setTextGravity(BaseTextView baseTextView, int gravity) {
if (baseTextView != null) {
baseTextView.getTopTextView().setGravity(gravity);
baseTextView.getCenterTextView().setGravity(gravity);
baseTextView.getBottomTextView().setGravity(gravity);
}
}
/**
* 代码动态设置分割线显示类型
*
* @param dividerType TOP、BOTTOM、BOTH、NONE
* @return this
*/
public SuperTextView setDividerLineType(int dividerType) {
mDividerLineType = dividerType;
invalidate();
return this;
}
public SuperTextView setTopDividerLineColor(int lineColor) {
mTopDividerPaint.setColor(lineColor);
invalidate();
return this;
}
public SuperTextView setBottomDividerLineColor(int lineColor) {
mBottomDividerPaint.setColor(lineColor);
invalidate();
return this;
}
/////////////////////////////////////对外暴露的方法---end/////////////////////////////////
/**
* 点击事件
*
* @param onSuperTextViewClickListener ClickListener
* @return SuperTextView
*/
public SuperTextView setOnSuperTextViewClickListener(OnSuperTextViewClickListener onSuperTextViewClickListener) {
this.superTextViewClickListener = onSuperTextViewClickListener;
if (superTextViewClickListener != null) {
this.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
superTextViewClickListener.onClickListener(SuperTextView.this);
}
});
}
return this;
}
public SuperTextView setLeftTopTvClickListener(OnLeftTopTvClickListener leftTopTvClickListener) {
this.leftTopTvClickListener = leftTopTvClickListener;
setDefaultLeftViewClickListener(leftView);
return this;
}
public SuperTextView setLeftTvClickListener(OnLeftTvClickListener leftTvClickListener) {
this.leftTvClickListener = leftTvClickListener;
setDefaultLeftViewClickListener(leftView);
return this;
}
public SuperTextView setLeftBottomTvClickListener(OnLeftBottomTvClickListener leftBottomTvClickListener) {
this.leftBottomTvClickListener = leftBottomTvClickListener;
setDefaultLeftViewClickListener(leftView);
return this;
}
public SuperTextView setCenterTopTvClickListener(OnCenterTopTvClickListener centerTopTvClickListener) {
this.centerTopTvClickListener = centerTopTvClickListener;
setDefaultCenterViewClickListener(centerView);
return this;
}
public SuperTextView setCenterTvClickListener(OnCenterTvClickListener centerTvClickListener) {
this.centerTvClickListener = centerTvClickListener;
setDefaultCenterViewClickListener(centerView);
return this;
}
public SuperTextView setCenterBottomTvClickListener(OnCenterBottomTvClickListener centerBottomTvClickListener) {
this.centerBottomTvClickListener = centerBottomTvClickListener;
setDefaultCenterViewClickListener(centerView);
return this;
}
public SuperTextView setRightTopTvClickListener(OnRightTopTvClickListener rightTopTvClickListener) {
this.rightTopTvClickListener = rightTopTvClickListener;
setDefaultRightViewClickListener(rightView);
return this;
}
public SuperTextView setRightTvClickListener(OnRightTvClickListener rightTvClickListener) {
this.rightTvClickListener = rightTvClickListener;
setDefaultRightViewClickListener(rightView);
return this;
}
public SuperTextView setRightBottomTvClickListener(OnRightBottomTvClickListener rightBottomTvClickListener) {
this.rightBottomTvClickListener = rightBottomTvClickListener;
setDefaultRightViewClickListener(rightView);
return this;
}
public SuperTextView setLeftImageViewClickListener(OnLeftImageViewClickListener listener) {
this.leftImageViewClickListener = listener;
if (leftIconIV != null) {
leftIconIV.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
leftImageViewClickListener.onClickListener(leftIconIV);
}
});
}
return this;
}
public SuperTextView setRightImageViewClickListener(final OnRightImageViewClickListener listener) {
this.rightImageViewClickListener = listener;
if (rightIconIV != null) {
rightIconIV.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
rightImageViewClickListener.onClickListener(rightIconIV);
}
});
}
return this;
}
public SuperTextView setSwitchCheckedChangeListener(OnSwitchCheckedChangeListener switchCheckedChangeListener) {
this.switchCheckedChangeListener = switchCheckedChangeListener;
return this;
}
public SuperTextView setCheckBoxCheckedChangeListener(OnCheckBoxCheckedChangeListener checkBoxCheckedChangeListener) {
this.checkBoxCheckedChangeListener = checkBoxCheckedChangeListener;
return this;
}
public SuperTextView setEditTextChangeListener(OnEditTextChangeListener editTextChangeListener) {
this.editTextChangeListener = editTextChangeListener;
return this;
}
public SuperTextView setLeftTextGroupClickListener(final OnLeftTextGroupClickListener leftTextGroupClickListener) {
if (leftTextGroupClickListener != null) {
leftView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
leftTextGroupClickListener.onClickListener(v);
}
});
}
return this;
}
public SuperTextView setCenterTextGroupClickListener(final OnCenterTextGroupClickListener centerTextGroupClickListener) {
if (centerTextGroupClickListener != null) {
centerView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
centerTextGroupClickListener.onClickListener(v);
}
});
}
return this;
}
public SuperTextView setRightTextGroupClickListener(final OnRightTextGroupClickListener rightTextGroupClickListener) {
if (rightTextGroupClickListener != null) {
rightView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
rightTextGroupClickListener.onClickListener(v);
}
});
}
return this;
}
////////////////////////////////////////////////////////////////////////////////////
public interface OnSuperTextViewClickListener {
void onClickListener(SuperTextView superTextView);
}
public interface OnLeftTopTvClickListener {
void onClickListener();
}
public interface OnLeftTvClickListener {
void onClickListener();
}
public interface OnLeftBottomTvClickListener {
void onClickListener();
}
public interface OnCenterTopTvClickListener {
void onClickListener();
}
public interface OnCenterTvClickListener {
void onClickListener();
}
public interface OnCenterBottomTvClickListener {
void onClickListener();
}
public interface OnRightTopTvClickListener {
void onClickListener();
}
public interface OnRightTvClickListener {
void onClickListener();
}
public interface OnRightBottomTvClickListener {
void onClickListener();
}
public interface OnLeftImageViewClickListener {
void onClickListener(ImageView imageView);
}
public interface OnRightImageViewClickListener {
void onClickListener(ImageView imageView);
}
public interface OnSwitchCheckedChangeListener {
void onCheckedChanged(CompoundButton buttonView, boolean isChecked);
}
public interface OnCheckBoxCheckedChangeListener {
void onCheckedChanged(CompoundButton buttonView, boolean isChecked);
}
public interface OnEditTextChangeListener{
void beforeTextChanged(CharSequence s, int start, int count, int after);
void onTextChanged(CharSequence s, int start, int before, int count);
void afterTextChanged(Editable s);
}
public interface OnLeftTextGroupClickListener {
void onClickListener(View view);
}
public interface OnCenterTextGroupClickListener {
void onClickListener(View view);
}
public interface OnRightTextGroupClickListener {
void onClickListener(View view);
}
// TODO: 2019/6/4 以下是获取shapeBuilder进行相关shape属性的配置
/**
* 获取shapeBuilder进行配置
*
* @return ShapeBuilder
*/
public ShapeBuilder getShapeBuilder() {
return shapeBuilder;
}
/**
* 单位转换工具类
*
* @param context 上下文对象
* @param spValue 值
* @return 返回值
*/
private int sp2px(Context context, float spValue) {
final float scale = context.getResources().getDisplayMetrics().scaledDensity;
return (int) (spValue * scale + 0.5f);
}
/**
* 单位转换工具类
*
* @param context 上下文对象
* @param dipValue 值
* @return 返回值
*/
private int dip2px(Context context, float dipValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dipValue * scale + 0.5f);
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@color/common_pressed"
android:state_pressed="true" />
<item
android:drawable="@color/white" />
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView 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"
android:id="@+id/card_base_select_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardCornerRadius="@dimen/dp_12"
app:cardElevation="@dimen/dp_3">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_sn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_8"
android:layout_marginTop="@dimen/dp_5"
android:layout_marginBottom="@dimen/dp_5"
android:gravity="center"
android:textSize="@dimen/dp_10"
android:textStyle="bold"
android:text="SN" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_base_select_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_8"
android:layout_marginTop="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_8"
android:layout_marginBottom="@dimen/dp_5"
android:gravity="center"
android:textSize="@dimen/dp_12"
tools:text="掛果類" />
</LinearLayout>
</androidx.cardview.widget.CardView>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
style="@style/Multi_Layout_Style" style="@style/Multi_Layout_Style"
android:layout_width="match_parent" android:layout_width="match_parent"
android:gravity="center_vertical"> android:gravity="center_vertical">
......
...@@ -571,4 +571,245 @@ ...@@ -571,4 +571,245 @@
<attr name="siStrokeJoin" /> <attr name="siStrokeJoin" />
<attr name="siStrokeMiter" format="dimension" /> <attr name="siStrokeMiter" format="dimension" />
</declare-styleable> </declare-styleable>
<declare-styleable name="SuperTextView">
<attr name="sLeftTextString" format="string" />
<attr name="sLeftTopTextString" format="string" />
<attr name="sLeftBottomTextString" format="string" />
<attr name="sCenterTextString" format="string" />
<attr name="sCenterTopTextString" format="string" />
<attr name="sCenterBottomTextString" format="string" />
<attr name="sRightTextString" format="string" />
<attr name="sRightTopTextString" format="string" />
<attr name="sRightBottomTextString" format="string" />
<!-- -->
<attr name="sLeftTextColor" format="color" />
<attr name="sLeftTopTextColor" format="color" />
<attr name="sLeftBottomTextColor" format="color" />
<attr name="sCenterTextColor" format="color" />
<attr name="sCenterTopTextColor" format="color" />
<attr name="sCenterBottomTextColor" format="color" />
<attr name="sRightTextColor" format="color" />
<attr name="sRightTopTextColor" format="color" />
<attr name="sRightBottomTextColor" format="color" />
<!-- -->
<attr name="sLeftTextSize" format="dimension" />
<attr name="sLeftTopTextSize" format="dimension" />
<attr name="sLeftBottomTextSize" format="dimension" />
<attr name="sCenterTextSize" format="dimension" />
<attr name="sCenterTopTextSize" format="dimension" />
<attr name="sCenterBottomTextSize" format="dimension" />
<attr name="sRightTextSize" format="dimension" />
<attr name="sRightTopTextSize" format="dimension" />
<attr name="sRightBottomTextSize" format="dimension" />
<!-- -->
<attr name="sLeftTopLines" format="integer" />
<attr name="sLeftLines" format="integer" />
<attr name="sLeftBottomLines" format="integer" />
<attr name="sCenterTopLines" format="integer" />
<attr name="sCenterLines" format="integer" />
<attr name="sCenterBottomLines" format="integer" />
<attr name="sRightTopLines" format="integer" />
<attr name="sRightLines" format="integer" />
<attr name="sRightBottomLines" format="integer" />
<!-- -->
<attr name="sLeftTopMaxEms" format="integer" />
<attr name="sLeftMaxEms" format="integer" />
<attr name="sLeftBottomMaxEms" format="integer" />
<attr name="sCenterTopMaxEms" format="integer" />
<attr name="sCenterMaxEms" format="integer" />
<attr name="sCenterBottomMaxEms" format="integer" />
<attr name="sRightTopMaxEms" format="integer" />
<attr name="sRightMaxEms" format="integer" />
<attr name="sRightBottomMaxEms" format="integer" />
<!-- -->
<attr name="sLeftViewGravity" format="enum">
<enum name="left_center" value="0" />
<enum name="center" value="1" />
<enum name="right_center" value="2" />
</attr>
<attr name="sCenterViewGravity" format="enum">
<enum name="left_center" value="0" />
<enum name="center" value="1" />
<enum name="right_center" value="2" />
</attr>
<attr name="sRightViewGravity" format="enum">
<enum name="left_center" value="0" />
<enum name="center" value="1" />
<enum name="right_center" value="2" />
</attr>
<!-- -->
<attr name="sLeftTvDrawableLeft" format="reference" />
<attr name="sLeftTvDrawableRight" format="reference" />
<attr name="sCenterTvDrawableLeft" format="reference" />
<attr name="sCenterTvDrawableRight" format="reference" />
<attr name="sRightTvDrawableLeft" format="reference" />
<attr name="sRightTvDrawableRight" format="reference" />
<attr name="sLeftTvDrawableWidth" format="dimension" />
<attr name="sLeftTvDrawableHeight" format="dimension" />
<attr name="sCenterTvDrawableWidth" format="dimension" />
<attr name="sCenterTvDrawableHeight" format="dimension" />
<attr name="sRightTvDrawableWidth" format="dimension" />
<attr name="sRightTvDrawableHeight" format="dimension" />
<!-- -->
<attr name="sTextViewDrawablePadding" format="dimension" />
<!-- -->
<attr name="sLeftViewWidth" format="dimension" />
<!-- -->
<attr name="sTopDividerLineMarginLR" format="dimension" />
<attr name="sTopDividerLineMarginLeft" format="dimension" />
<attr name="sTopDividerLineMarginRight" format="dimension" />
<attr name="sBottomDividerLineMarginLR" format="dimension" />
<attr name="sBottomDividerLineMarginLeft" format="dimension" />
<attr name="sBottomDividerLineMarginRight" format="dimension" />
<!-- -->
<attr name="sDividerLineColor" format="color" />
<attr name="sDividerLineHeight" format="dimension" />
<attr name="sDividerLineType" format="enum">
<enum name="none" value="0" />
<enum name="top" value="1" />
<enum name="bottom" value="2" />
<enum name="both" value="3" />
</attr>
<!-- -->
<attr name="sLeftViewMarginLeft" format="dimension" />
<attr name="sLeftViewMarginRight" format="dimension" />
<attr name="sCenterViewMarginLeft" format="dimension" />
<attr name="sCenterViewMarginRight" format="dimension" />
<attr name="sRightViewMarginLeft" format="dimension" />
<attr name="sRightViewMarginRight" format="dimension" />
<!-- 自定义属性超过128个导致布局无法预览,故暂时去除不重要的属性 -->
<!--<attr name="sLeftTopTextIsBold" format="boolean" />-->
<!--<attr name="sLeftTextIsBold" format="boolean" />-->
<!--<attr name="sLeftBottomTextIsBold" format="boolean" />-->
<!--<attr name="sCenterTopTextIsBold" format="boolean" />-->
<!--<attr name="sCenterTextIsBold" format="boolean" />-->
<!--<attr name="sCenterBottomTextIsBold" format="boolean" />-->
<!--<attr name="sRightTopTextIsBold" format="boolean" />-->
<!--<attr name="sRightTextIsBold" format="boolean" />-->
<!--<attr name="sRightBottomTextIsBold" format="boolean" />-->
<attr name="sLeftTextBackground" format="reference" />
<attr name="sCenterTextBackground" format="reference" />
<attr name="sRightTextBackground" format="reference" />
<!-- -->
<attr name="sLeftIconRes" format="reference" />
<attr name="sRightIconRes" format="reference" />
<attr name="sLeftIconWidth" format="dimension" />
<attr name="sLeftIconHeight" format="dimension" />
<attr name="sRightIconWidth" format="dimension" />
<attr name="sRightIconHeight" format="dimension" />
<attr name="sCenterSpaceHeight" format="dimension" />
<attr name="sLeftIconMarginLeft" format="dimension" />
<attr name="sRightIconMarginRight" format="dimension" />
<attr name="sRightViewType" format="enum">
<enum name="checkbox" value="0" />
<enum name="switchBtn" value="1" />
<enum name="edittext" value="2" />
</attr>
<attr name="sRightCheckBoxRes" format="reference" />
<attr name="sRightCheckBoxMarginRight" format="dimension" />
<attr name="sIsChecked" format="boolean" />
<attr name="sRightSwitchMarginRight" format="dimension" />
<attr name="sSwitchIsChecked" format="boolean" />
<attr name="sTextOff" format="string" />
<attr name="sTextOn" format="string" />
<attr name="sSwitchMinWidth" format="dimension" />
<attr name="sSwitchPadding" format="dimension" />
<attr name="sThumbTextPadding" format="dimension" />
<attr name="sThumbResource" format="reference" />
<attr name="sTrackResource" format="reference" />
<attr name="sUseRipple" format="boolean" />
<attr name="sBackgroundDrawableRes" format="reference" />
<!-- -->
<attr name="sShapeSolidColor" format="color" />
<attr name="sShapeSelectorPressedColor" format="color" />
<attr name="sShapeSelectorNormalColor" format="color" />
<attr name="sShapeCornersRadius" format="dimension" />
<attr name="sShapeCornersTopLeftRadius" format="dimension" />
<attr name="sShapeCornersTopRightRadius" format="dimension" />
<attr name="sShapeCornersBottomLeftRadius" format="dimension" />
<attr name="sShapeCornersBottomRightRadius" format="dimension" />
<attr name="sShapeStrokeWidth" format="dimension" />
<attr name="sShapeStrokeDashWidth" format="dimension" />
<attr name="sShapeStrokeDashGap" format="dimension" />
<attr name="sShapeStrokeColor" format="color" />
<attr name="sUseShape" format="boolean" />
<attr name="sLeftTextGravity" format="enum">
<enum name="left" value="0" />
<enum name="center" value="1" />
<enum name="right" value="2" />
</attr>
<attr name="sCenterTextGravity" format="enum">
<enum name="left" value="0" />
<enum name="center" value="1" />
<enum name="right" value="2" />
</attr>
<attr name="sRightTextGravity" format="enum">
<enum name="left" value="0" />
<enum name="center" value="1" />
<enum name="right" value="2" />
</attr>
<attr name="sLeftIconShowCircle" format="boolean" />
<attr name="sRightIconShowCircle" format="boolean" />
<attr name="sEditMinWidth" format="dimension"/>
<attr name="sEditMarginRight" format="dimension" />
<attr name="android:imeOptions"/>
<attr name="android:inputType"/>
<attr name="sEditCursorDrawable" format="reference"/>
<attr name="sEditCursorVisible" format="boolean"/>
<attr name="sEditHint" format="string"/>
<attr name="sEditHintTextColor" format="color"/>
<attr name="sEditTextColor" format="color"/>
<attr name="sEditTextSize" format="dimension"/>
<attr name="sEditActiveLineColor" format="color" />
</declare-styleable>
</resources> </resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="sLeftViewId" type="id" />
<item name="sCenterViewId" type="id" />
<item name="sRightViewId" type="id" />
<item name="sLeftImgId" type="id" />
<item name="sRightImgId" type="id" />
<item name="sRightCheckBoxId" type="id" />
<item name="sRightSwitchId" type="id" />
<item name="sRightEditTextId" type="id" />
</resources>
\ No newline at end of file
package com.gingersoft.gsa.cloud.ui;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment