Browse Source

Merge branch 'master' of http://git.wmzhubo.com/guadoutech/PartTimeJob_CN_Android

 Conflicts:
	cs_baselib/src/main/java/com/guadou/lib_baselib/font_text_view/TypefaceUtil.java
Administrator 2 years ago
parent
commit
106808c574

+ 4 - 3
cpt_ewallet/src/main/res/layout/fragment_ewallet_main.xml

@@ -271,7 +271,8 @@
                             android:layout_marginLeft="@dimen/d_8dp"
                             android:text="支付密码设置"
                             android:textColor="@color/gray_76"
-                            android:textSize="@dimen/d_15sp" />
+                            android:textSize="@dimen/d_15sp"
+                            binding:typefaceRegular="@{true}" />
 
                         <View
                             android:layout_width="0dp"
@@ -313,7 +314,8 @@
                             android:layout_marginLeft="@dimen/d_8dp"
                             android:text="电子钱包交易记录"
                             android:textColor="@color/gray_76"
-                            android:textSize="@dimen/d_15sp" />
+                            android:textSize="@dimen/d_15sp"
+                            binding:typefaceRegular="@{true}" />
 
                         <View
                             android:layout_width="0dp"
@@ -394,5 +396,4 @@
 
     </LinearLayout>
 
-
 </layout>

+ 0 - 29
cs_baselib/src/main/java/com/guadou/lib_baselib/font_text_view/FontCache.java

@@ -1,29 +0,0 @@
-package com.guadou.lib_baselib.font_text_view;
-
-import android.content.Context;
-import android.graphics.Typeface;
-
-import java.util.HashMap;
-
-
-public class FontCache {
-
-    private static HashMap<String, Typeface> fontCache = new HashMap<>();
-
-    public static Typeface getTypeface(String fontname, Context context) {
-        Typeface typeface = fontCache.get(fontname);
-
-        if (typeface == null) {
-            try {
-                typeface = Typeface.createFromAsset(context.getAssets(), "SF-UI-Text/" + fontname);
-            } catch (Exception e) {
-                return null;
-            }
-
-            fontCache.put(fontname, typeface);
-        }
-
-        return typeface;
-    }
-
-}

+ 2 - 2
cs_baselib/src/main/java/com/guadou/lib_baselib/font_text_view/TextViewBold.java

@@ -1,6 +1,7 @@
 package com.guadou.lib_baselib.font_text_view;
 
 import android.content.Context;
+import android.graphics.Typeface;
 import android.util.AttributeSet;
 
 import androidx.annotation.Nullable;
@@ -27,7 +28,6 @@ public class TextViewBold extends AppCompatTextView {
     }
 
     private void applyCustomFont(Context context) {
-//        Typeface customFont = FontCache.getTypeface("PingFang_Bold.ttf", context);
-//        setTypeface(customFont);
+        setTypeface(TypefaceUtil.getBold());
     }
 }

+ 34 - 0
cs_baselib/src/main/java/com/guadou/lib_baselib/font_text_view/TextViewLight.java

@@ -0,0 +1,34 @@
+package com.guadou.lib_baselib.font_text_view;
+
+import android.content.Context;
+import android.graphics.Typeface;
+import android.util.AttributeSet;
+
+import androidx.annotation.Nullable;
+import androidx.appcompat.widget.AppCompatTextView;
+
+/**
+ * Custom TextView for Light
+ */
+
+public class TextViewLight extends AppCompatTextView {
+
+    public TextViewLight(Context context) {
+        super(context);
+        applyCustomFont(context);
+    }
+
+    public TextViewLight(Context context, @Nullable AttributeSet attrs) {
+        super(context, attrs);
+        applyCustomFont(context);
+    }
+
+    public TextViewLight(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
+        super(context, attrs, defStyleAttr);
+        applyCustomFont(context);
+    }
+
+    private void applyCustomFont(Context context) {
+        setTypeface(TypefaceUtil.getLight());
+    }
+}

+ 1 - 2
cs_baselib/src/main/java/com/guadou/lib_baselib/font_text_view/TextViewMedium.java

@@ -28,7 +28,6 @@ public class TextViewMedium extends AppCompatTextView {
     }
 
     private void applyCustomFont(Context context) {
-//        Typeface customFont = FontCache.getTypeface("PingFang_Medium.ttf", context);
-//        setTypeface(customFont);
+        setTypeface(TypefaceUtil.getMedium());
     }
 }

+ 33 - 0
cs_baselib/src/main/java/com/guadou/lib_baselib/font_text_view/TextViewRegular.java

@@ -0,0 +1,33 @@
+package com.guadou.lib_baselib.font_text_view;
+
+import android.content.Context;
+import android.util.AttributeSet;
+
+import androidx.annotation.Nullable;
+import androidx.appcompat.widget.AppCompatTextView;
+
+/**
+ * Custom TextView for Light
+ */
+
+public class TextViewRegular extends AppCompatTextView {
+
+    public TextViewRegular(Context context) {
+        super(context);
+        applyCustomFont(context);
+    }
+
+    public TextViewRegular(Context context, @Nullable AttributeSet attrs) {
+        super(context, attrs);
+        applyCustomFont(context);
+    }
+
+    public TextViewRegular(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
+        super(context, attrs, defStyleAttr);
+        applyCustomFont(context);
+    }
+
+    private void applyCustomFont(Context context) {
+        setTypeface(TypefaceUtil.getRegular());
+    }
+}

+ 14 - 0
cs_baselib/src/main/java/com/guadou/lib_baselib/font_text_view/TypefaceUtil.java

@@ -9,6 +9,13 @@ import android.graphics.Typeface;
 
 public class TypefaceUtil {
 
+    public static Typeface getLight() {
+        return Typeface.create("sans-serif-light", Typeface.NORMAL);
+    }
+
+    public static Typeface getRegular() {
+        return Typeface.create("sans-serif", Typeface.NORMAL);
+    }
 
     public static Typeface getSFMedium(Context context) {
         return FontCache.getTypeface("PingFang_Medium.ttf", context);
@@ -17,6 +24,13 @@ public class TypefaceUtil {
     public static Typeface getSFBold(Context context) {
         return FontCache.getTypeface("PingFang_Bold.ttf", context);
     }
+    public static Typeface getMedium() {
+        return Typeface.create("sans-serif-medium", Typeface.NORMAL);
+    }
+
+    public static Typeface getBold() {
+        return Typeface.create("sans-serif", Typeface.BOLD);
+    }
 
 
 }

+ 18 - 7
cs_cptServices/src/main/java/com/guadou/cs_cptservices/binding/BindingTextView.kt

@@ -7,6 +7,7 @@ import android.text.Html
 import android.text.TextUtils
 import android.widget.TextView
 import androidx.databinding.BindingAdapter
+import com.guadou.lib_baselib.font_text_view.TypefaceUtil
 
 /**
  * 文本的设置
@@ -65,23 +66,33 @@ fun isCenterLine(textView: TextView, isUnderline: Boolean) {
 /**
  * 设置字体
  */
+@BindingAdapter("typefaceLight")
+fun typefaceLight(textView: TextView, boolean: Boolean) {
+    textView.typeface = TypefaceUtil.getLight()
+}
+
+@BindingAdapter("typefaceRegular")
+fun typefaceRegular(textView: TextView, boolean: Boolean) {
+    textView.typeface = TypefaceUtil.getRegular()
+}
+
 @BindingAdapter("typefaceMedium")
 fun typefaceMedium(textView: TextView, boolean: Boolean) {
-//    textView.typeface = TypefaceUtil.getSFMedium(textView.context)
+    textView.typeface = TypefaceUtil.getMedium()
 }
 
 @BindingAdapter("typefaceBold")
 fun typefaceSFBold(textView: TextView, boolean: Boolean) {
-//    textView.typeface = TypefaceUtil.getSFBold(textView.context)
+    textView.typeface = TypefaceUtil.getBold()
 }
 
 @BindingAdapter("typefaceMediumOrBold")
 fun typefaceMediumOrBold(textView: TextView, boolean: Boolean) {
-//    if (boolean) {  //true为粗体
-//        textView.typeface = TypefaceUtil.getSFBold(textView.context)
-//    } else {
-//        textView.typeface = TypefaceUtil.getSFMedium(textView.context)
-//    }
+    if (boolean) {  //true为粗体
+        textView.typeface = TypefaceUtil.getBold()
+    } else {
+        textView.typeface = TypefaceUtil.getMedium()
+    }
 }
 
 /**