ソースを参照

定位工具类修改,自定义CommonUserItemView修改

niusongtao@dl-cg.com 5 年 前
コミット
3c85f0f7e6

+ 13 - 0
base_library/src/main/java/com/mgtech/base_library/custom/CommonUserItemView.java

@@ -3,6 +3,7 @@ package com.mgtech.base_library.custom;
 import android.content.Context;
 import android.content.res.TypedArray;
 import android.graphics.Typeface;
+import android.graphics.drawable.Drawable;
 import android.util.AttributeSet;
 import android.util.TypedValue;
 import android.view.View;
@@ -73,6 +74,10 @@ public class CommonUserItemView extends ConstraintLayout {
                 ,typedArray.getDimension(R.styleable.CommonUserItemView_item_title_text_size, titleText.getTextSize()));
         detailText.setTextSize(TypedValue.COMPLEX_UNIT_PX
                 ,typedArray.getDimension(R.styleable.CommonUserItemView_item_detail_text_size,detailText.getTextSize()));
+
+        setDetailTextDrawable(typedArray.getDrawable(R.styleable.CommonUserItemView_item_detail_text_drawable)
+                ,typedArray.getDimensionPixelSize(R.styleable.CommonUserItemView_item_detail_text_drawable_padding,0));
+
         int titleType = typedArray.getInt(R.styleable.CommonUserItemView_item_title_text_style,10);
         if (titleType == 10){//normal
             titleText.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
@@ -95,6 +100,14 @@ public class CommonUserItemView extends ConstraintLayout {
         typedArray.recycle();
     }
 
+    private void setDetailTextDrawable(Drawable drawable,int padding){
+        if (drawable == null)
+            return;
+        drawable.setBounds(0,0,drawable.getMinimumWidth(),drawable.getMinimumHeight());
+        detailText.setCompoundDrawables(drawable,null,null,null);
+        detailText.setCompoundDrawablePadding(padding);
+    }
+
     public void setTitleText(String title){
         titleText.setText(title);
     }

+ 25 - 19
base_library/src/main/java/com/mgtech/base_library/util/CustomDialog.java

@@ -4,6 +4,7 @@ import android.app.AlertDialog;
 import android.app.Dialog;
 import android.content.Context;
 import android.content.DialogInterface;
+import android.graphics.drawable.ColorDrawable;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.widget.LinearLayout;
@@ -11,6 +12,7 @@ import android.widget.TextView;
 
 import androidx.annotation.NonNull;
 
+import com.coorchice.library.SuperTextView;
 import com.mgtech.base_library.R;
 /**
  * @ProjectName: TUA
@@ -133,17 +135,20 @@ public class CustomDialog extends Dialog {
                     .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
             // instantiate the dialog with the custom Theme
             final CustomDialog dialog = new CustomDialog(context, R.style.Theme_AppCompat_Light_Dialog_Alert);
-            View layout = inflater.inflate(R.layout.dialog_ask, null);
-            dialog.addContentView(layout, new LinearLayout.LayoutParams(
-                    LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
+            if (dialog.getWindow() != null)
+                dialog.getWindow().setBackgroundDrawableResource(R.color.transparent);
+            if (contentView == null)
+                contentView = inflater.inflate(R.layout.dialog_ask, null);
+//            dialog.addContentView(layout, new LinearLayout.LayoutParams(
+//                    LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
             // set the dialog title
-            ((TextView) layout.findViewById(R.id.dialog_title)).setText(title);
+            ((TextView) contentView.findViewById(R.id.dialog_title)).setText(title);
             // set the confirm button
             if (positiveButtonText != null) {
-                ((TextView) layout.findViewById(R.id.dialog_positive))
+                ((SuperTextView) contentView.findViewById(R.id.dialog_positive))
                         .setText(positiveButtonText);
                 if (positiveButtonClickListener != null) {
-                    layout.findViewById(R.id.dialog_positive)
+                    contentView.findViewById(R.id.dialog_positive)
                             .setOnClickListener(new View.OnClickListener() {
                                 public void onClick(View v) {
                                     positiveButtonClickListener.onClick(dialog,
@@ -153,15 +158,15 @@ public class CustomDialog extends Dialog {
                 }
             } else {
                 // if no confirm button just set the visibility to GONE
-                layout.findViewById(R.id.dialog_positive).setVisibility(
+                contentView.findViewById(R.id.dialog_positive).setVisibility(
                         View.GONE);
             }
             // set the cancel button
             if (negativeButtonText != null) {
-                ((TextView) layout.findViewById(R.id.dialog_negative))
+                ((SuperTextView) contentView.findViewById(R.id.dialog_negative))
                         .setText(negativeButtonText);
                 if (negativeButtonClickListener != null) {
-                    layout.findViewById(R.id.dialog_negative)
+                    contentView.findViewById(R.id.dialog_negative)
                             .setOnClickListener(new View.OnClickListener() {
                                 public void onClick(View v) {
                                     negativeButtonClickListener.onClick(dialog,
@@ -171,21 +176,22 @@ public class CustomDialog extends Dialog {
                 }
             } else {
                 // if no confirm button just set the visibility to GONE
-                layout.findViewById(R.id.dialog_negative).setVisibility(
+                contentView.findViewById(R.id.dialog_negative).setVisibility(
                         View.GONE);
             }
             // set the content message
             if (message != null) {
-                ((TextView) layout.findViewById(R.id.dialog_message)).setText(message);
-            } else if (contentView != null) {
-                // if no message set
-                // add the contentView to the dialog body
-                ((LinearLayout) layout.findViewById(R.id.content))
-                        .removeAllViews();
-                ((LinearLayout) layout.findViewById(R.id.content))
-                        .addView(contentView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
+                ((TextView) contentView.findViewById(R.id.dialog_message)).setText(message);
             }
-            dialog.setContentView(layout,new LinearLayout.LayoutParams(
+//            else if (contentView != null) {
+//                // if no message set
+//                // add the contentView to the dialog body
+//                ((LinearLayout) layout.findViewById(R.id.content))
+//                        .removeAllViews();
+//                ((LinearLayout) layout.findViewById(R.id.content))
+//                        .addView(contentView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
+//            }
+            dialog.setContentView(contentView,new LinearLayout.LayoutParams(
                     LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
             return dialog;
         }

+ 2 - 2
base_library/src/main/res/layout/dialog_ask.xml

@@ -53,7 +53,7 @@
         app:layout_constraintStart_toStartOf="@id/dialog_bg"
         app:layout_constraintTop_toBottomOf="@id/dialog_message" />
 
-    <TextView
+    <com.coorchice.library.SuperTextView
         android:id="@+id/dialog_negative"
         android:layout_width="@dimen/dp_0"
         android:layout_height="wrap_content"
@@ -74,7 +74,7 @@
         app:layout_constraintStart_toEndOf="@id/dialog_negative"
         app:layout_constraintTop_toTopOf="@id/dialog_negative" />
 
-    <TextView
+    <com.coorchice.library.SuperTextView
         android:id="@+id/dialog_positive"
         android:layout_width="@dimen/dp_0"
         android:layout_height="wrap_content"

+ 1 - 0
base_library/src/main/res/layout/layout_common_user_item.xml

@@ -58,4 +58,5 @@
         android:layout_height="@dimen/dp_1"
         android:background="@color/bg_color"
         app:layout_constraintBottom_toBottomOf="parent" />
+
 </merge>

+ 2 - 0
base_library/src/main/res/values/attrs.xml

@@ -89,6 +89,8 @@
         <attr name="item_line_height" format="dimension"/>
         <attr name="item_title_text_size" format="dimension"/>
         <attr name="item_detail_text_size" format="dimension"/>
+        <attr name="item_detail_text_drawable" format="reference"/>
+        <attr name="item_detail_text_drawable_padding" format="dimension"/>
         <attr name="item_detail_text_style">
             <flag name="normal" value="10" />
             <flag name="bold" value="20" />