From 6ab893f552a88bc75ff8c71d4a61ea059b1d12d5 Mon Sep 17 00:00:00 2001 From: Jerey-Jobs <610315802@qq.com> Date: Thu, 8 Jun 2017 17:40:02 +0800 Subject: [PATCH] =?UTF-8?q?TextView=20=E6=94=B9=E4=B8=BA=E5=BC=B1=E5=BC=95?= =?UTF-8?q?=E7=94=A8,=20=E4=BD=86=E6=9C=AA=E8=83=BD=E8=A7=A3=E5=86=B3TextV?= =?UTF-8?q?iew=E5=9C=A8=E5=86=85=E5=AD=98=E4=B8=AD=E4=B8=8D=E6=96=AD?= =?UTF-8?q?=E5=A2=9E=E5=A4=9A=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jerey/keepgank/fragment/ListFragment.java | 1 - .../keepgank/fragment/TodayFragment.java | 1 - .../themelib/loader/TextViewRepository.java | 28 ++++++++++++------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/jerey/keepgank/fragment/ListFragment.java b/app/src/main/java/com/jerey/keepgank/fragment/ListFragment.java index 36768b3..1502915 100644 --- a/app/src/main/java/com/jerey/keepgank/fragment/ListFragment.java +++ b/app/src/main/java/com/jerey/keepgank/fragment/ListFragment.java @@ -120,7 +120,6 @@ protected void afterCreate(Bundle savedInstanceState) { mAdapter.notifyDataSetChanged(); } - } catch (IOException e) { e.printStackTrace(); } diff --git a/app/src/main/java/com/jerey/keepgank/fragment/TodayFragment.java b/app/src/main/java/com/jerey/keepgank/fragment/TodayFragment.java index e892b53..0904b70 100644 --- a/app/src/main/java/com/jerey/keepgank/fragment/TodayFragment.java +++ b/app/src/main/java/com/jerey/keepgank/fragment/TodayFragment.java @@ -75,7 +75,6 @@ protected void afterCreate(Bundle savedInstanceState) { initUI(); dynamicAddView(mToolbarLayout, "ContentScrimColor", R.color.app_main_color); mAdapter = new DayFragmentAdapter(getActivity()); - Calendar c = null; java.util.Calendar calendar = java.util.Calendar.getInstance(); calendar.setTime(new Date()); year = calendar.get(java.util.Calendar.YEAR); diff --git a/themelib/src/main/java/com/jerey/themelib/loader/TextViewRepository.java b/themelib/src/main/java/com/jerey/themelib/loader/TextViewRepository.java index 0aea0ef..82e2e47 100644 --- a/themelib/src/main/java/com/jerey/themelib/loader/TextViewRepository.java +++ b/themelib/src/main/java/com/jerey/themelib/loader/TextViewRepository.java @@ -1,38 +1,46 @@ package com.jerey.themelib.loader; import android.graphics.Typeface; +import android.util.Log; import android.widget.TextView; import com.jerey.themelib.utils.TypefaceUtils; +import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; - /** - * Created by _SOLID - * Date:2016/7/12 - * Time:17:58 + * 字体改变工厂 */ public class TextViewRepository { - private static List mTextViews = new ArrayList<>(); + private static final String TAG = "TextViewRepository"; + /** + * 虽使用了弱引用来解决TextView得不到释放的问题,但是没有效果,内存中的TextView依旧在不断增多. + * 即使不加入列表里面,TextView数量依旧是在使用过程中中变多 + */ + private static ArrayList> mTextViewsWeakList = new ArrayList<>(); public static void add(TextView textView) { - mTextViews.add(textView); + mTextViewsWeakList.add(new WeakReference(textView)); textView.setTypeface(TypefaceUtils.CURRENT_TYPEFACE); + Log.d(TAG, "TextViewRepository mTextViews count: " + mTextViewsWeakList.size()); } public static void clear() { - mTextViews.clear(); + mTextViewsWeakList.clear(); } public static void remove(TextView textView) { - mTextViews.remove(textView); + mTextViewsWeakList.remove(new WeakReference(textView)); } public static void applyFont(Typeface tf) { - for (TextView textView : mTextViews) { - textView.setTypeface(tf); + for (WeakReference textViewWeak : mTextViewsWeakList) { + TextView textView = textViewWeak.get(); + if (textView != null) { + textView.setTypeface(tf); + } } } }