feat: 增加透明主题背景缓存

This commit is contained in:
HuanChengFly 2020-08-15 22:26:17 +08:00
parent 41102c36ce
commit ecc70507d4
5 changed files with 40 additions and 16 deletions

View File

@ -4,11 +4,11 @@ import android.app.Activity
import android.app.Application import android.app.Application
import android.content.ClipboardManager import android.content.ClipboardManager
import android.content.Context import android.content.Context
import android.content.DialogInterface
import android.content.Intent import android.content.Intent
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.content.res.Configuration import android.content.res.Configuration
import android.graphics.Color import android.graphics.Color
import android.graphics.drawable.Drawable
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.text.TextUtils import android.text.TextUtils
@ -226,6 +226,9 @@ class BaseApplication : Application() {
companion object { companion object {
val TAG = BaseApplication::class.java.simpleName val TAG = BaseApplication::class.java.simpleName
@JvmStatic
var translucentBackground: Drawable? = null
private val packageName: String private val packageName: String
get() = instance.packageName get() = instance.packageName

View File

@ -32,32 +32,31 @@ import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager; import androidx.viewpager.widget.ViewPager;
import com.google.android.material.tabs.TabLayout; import com.google.android.material.tabs.TabLayout;
import com.huanchengfly.tieba.post.widgets.edittext.widget.UndoableEditText;
import com.huanchengfly.tieba.post.api.TiebaApi;
import com.huanchengfly.tieba.post.api.interfaces.CommonCallback;
import com.huanchengfly.tieba.post.api.models.WebReplyResultBean;
import com.huanchengfly.tieba.post.api.retrofit.exception.TiebaException;
import com.huanchengfly.tieba.post.R; import com.huanchengfly.tieba.post.R;
import com.huanchengfly.tieba.post.adapters.InsertPhotoAdapter; import com.huanchengfly.tieba.post.adapters.InsertPhotoAdapter;
import com.huanchengfly.tieba.post.adapters.TabViewPagerAdapter; import com.huanchengfly.tieba.post.adapters.TabViewPagerAdapter;
import com.huanchengfly.tieba.post.adapters.TextWatcherAdapter; import com.huanchengfly.tieba.post.adapters.TextWatcherAdapter;
import com.huanchengfly.tieba.post.api.TiebaApi;
import com.huanchengfly.tieba.post.api.interfaces.CommonCallback;
import com.huanchengfly.tieba.post.api.models.WebReplyResultBean;
import com.huanchengfly.tieba.post.api.retrofit.exception.TiebaException;
import com.huanchengfly.tieba.post.components.EmotionViewFactory; import com.huanchengfly.tieba.post.components.EmotionViewFactory;
import com.huanchengfly.tieba.post.components.dialogs.LoadingDialog; import com.huanchengfly.tieba.post.components.dialogs.LoadingDialog;
import com.huanchengfly.tieba.post.components.transformations.RadiusTransformation;
import com.huanchengfly.tieba.post.interfaces.ReplyContentCallback; import com.huanchengfly.tieba.post.interfaces.ReplyContentCallback;
import com.huanchengfly.tieba.post.interfaces.UploadCallback; import com.huanchengfly.tieba.post.interfaces.UploadCallback;
import com.huanchengfly.tieba.post.models.PhotoInfoBean; import com.huanchengfly.tieba.post.models.PhotoInfoBean;
import com.huanchengfly.tieba.post.models.ReplyInfoBean; import com.huanchengfly.tieba.post.models.ReplyInfoBean;
import com.huanchengfly.tieba.post.models.database.Draft; import com.huanchengfly.tieba.post.models.database.Draft;
import com.huanchengfly.tieba.post.utils.AssetUtil;
import com.huanchengfly.tieba.post.utils.EmotionUtil; import com.huanchengfly.tieba.post.utils.EmotionUtil;
import com.huanchengfly.tieba.post.utils.GsonUtil;
import com.huanchengfly.tieba.post.utils.StringUtil; import com.huanchengfly.tieba.post.utils.StringUtil;
import com.huanchengfly.tieba.post.utils.ThemeUtil; import com.huanchengfly.tieba.post.utils.ThemeUtil;
import com.huanchengfly.tieba.post.utils.UploadHelper; import com.huanchengfly.tieba.post.utils.UploadHelper;
import com.huanchengfly.tieba.post.utils.Util; import com.huanchengfly.tieba.post.utils.Util;
import com.huanchengfly.tieba.post.widgets.edittext.widget.UndoableEditText;
import com.huanchengfly.tieba.post.widgets.theme.TintConstraintLayout; import com.huanchengfly.tieba.post.widgets.theme.TintConstraintLayout;
import com.huanchengfly.tieba.post.widgets.theme.TintImageView; import com.huanchengfly.tieba.post.widgets.theme.TintImageView;
import com.huanchengfly.tieba.post.utils.AssetUtil;
import com.huanchengfly.tieba.post.utils.GsonUtil;
import com.zhihu.matisse.Matisse; import com.zhihu.matisse.Matisse;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -125,9 +124,7 @@ public class ReplyActivity extends BaseActivity implements View.OnClickListener
if (ThemeUtil.THEME_TRANSLUCENT.equals(ThemeUtil.getTheme(this))) { if (ThemeUtil.THEME_TRANSLUCENT.equals(ThemeUtil.getTheme(this))) {
TintConstraintLayout constraintLayout = (TintConstraintLayout) findViewById(R.id.activity_reply_layout); TintConstraintLayout constraintLayout = (TintConstraintLayout) findViewById(R.id.activity_reply_layout);
constraintLayout.setBackgroundTintResId(0); constraintLayout.setBackgroundTintResId(0);
ThemeUtil.setTranslucentThemeBackground(constraintLayout, ThemeUtil.setTranslucentBackground(constraintLayout);
false,
new RadiusTransformation(this, 8, RadiusTransformation.CORNER_TOP_LEFT | RadiusTransformation.CORNER_TOP_RIGHT));
} }
Util.setStatusBarTransparent(this); Util.setStatusBarTransparent(this);
getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

View File

@ -82,6 +82,12 @@ public class ThemeActivity extends BaseActivity {
ThemeUtil.setTranslucentThemeBackground(findViewById(R.id.background)); ThemeUtil.setTranslucentThemeBackground(findViewById(R.id.background));
} }
@Override
protected void onResume() {
super.onResume();
ThemeUtil.setTranslucentThemeBackground(findViewById(R.id.background));
}
@SuppressLint("ApplySharedPref") @SuppressLint("ApplySharedPref")
private void setTheme(String theme) { private void setTheme(String theme) {
ThemeUtil.getSharedPreferences(ThemeActivity.this).edit().putString(ThemeUtil.SP_THEME, theme).commit(); ThemeUtil.getSharedPreferences(ThemeActivity.this).edit().putString(ThemeUtil.SP_THEME, theme).commit();

View File

@ -33,17 +33,17 @@ import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.SimpleTarget; import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition; import com.bumptech.glide.request.transition.Transition;
import com.gyf.immersionbar.ImmersionBar; import com.gyf.immersionbar.ImmersionBar;
import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils;
import com.huanchengfly.tieba.post.BaseApplication; import com.huanchengfly.tieba.post.BaseApplication;
import com.huanchengfly.tieba.post.R; import com.huanchengfly.tieba.post.R;
import com.huanchengfly.tieba.post.adapters.ThemeColorAdapter; import com.huanchengfly.tieba.post.adapters.ThemeColorAdapter;
import com.huanchengfly.tieba.post.components.MyImageEngine; import com.huanchengfly.tieba.post.components.MyImageEngine;
import com.huanchengfly.tieba.post.components.MyLinearLayoutManager; import com.huanchengfly.tieba.post.components.MyLinearLayoutManager;
import com.huanchengfly.tieba.post.components.transformations.BlurTransformation; import com.huanchengfly.tieba.post.components.transformations.BlurTransformation;
import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils;
import com.huanchengfly.tieba.post.utils.ImageUtil; import com.huanchengfly.tieba.post.utils.ImageUtil;
import com.huanchengfly.tieba.post.utils.PermissionUtil;
import com.huanchengfly.tieba.post.utils.SharedPreferencesUtil; import com.huanchengfly.tieba.post.utils.SharedPreferencesUtil;
import com.huanchengfly.tieba.post.utils.ThemeUtil; import com.huanchengfly.tieba.post.utils.ThemeUtil;
import com.huanchengfly.tieba.post.utils.PermissionUtil;
import com.jrummyapps.android.colorpicker.ColorPickerDialog; import com.jrummyapps.android.colorpicker.ColorPickerDialog;
import com.jrummyapps.android.colorpicker.ColorPickerDialogListener; import com.jrummyapps.android.colorpicker.ColorPickerDialogListener;
import com.yalantis.ucrop.UCrop; import com.yalantis.ucrop.UCrop;
@ -55,9 +55,9 @@ import com.zhihu.matisse.MimeType;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
import static com.huanchengfly.tieba.post.utils.ColorUtils.getDarkerColor;
import static com.huanchengfly.tieba.post.utils.ThemeUtil.SP_TRANSLUCENT_PRIMARY_COLOR; import static com.huanchengfly.tieba.post.utils.ThemeUtil.SP_TRANSLUCENT_PRIMARY_COLOR;
import static com.huanchengfly.tieba.post.utils.ThemeUtil.THEME_TRANSLUCENT; import static com.huanchengfly.tieba.post.utils.ThemeUtil.THEME_TRANSLUCENT;
import static com.huanchengfly.tieba.post.utils.ColorUtils.getDarkerColor;
public class TranslucentThemeActivity extends BaseActivity implements View.OnClickListener, SeekBar.OnSeekBarChangeListener, ColorPickerDialogListener { public class TranslucentThemeActivity extends BaseActivity implements View.OnClickListener, SeekBar.OnSeekBarChangeListener, ColorPickerDialogListener {
public static final String TAG = TranslucentThemeActivity.class.getSimpleName(); public static final String TAG = TranslucentThemeActivity.class.getSimpleName();
@ -274,6 +274,7 @@ public class TranslucentThemeActivity extends BaseActivity implements View.OnCli
.putString(ThemeUtil.SP_OLD_THEME, THEME_TRANSLUCENT) .putString(ThemeUtil.SP_OLD_THEME, THEME_TRANSLUCENT)
.commit(); .commit();
Toast.makeText(TranslucentThemeActivity.this, R.string.toast_save_pic_success, Toast.LENGTH_SHORT).show(); Toast.makeText(TranslucentThemeActivity.this, R.string.toast_save_pic_success, Toast.LENGTH_SHORT).show();
BaseApplication.setTranslucentBackground(null);
mProgress.setVisibility(View.GONE); mProgress.setVisibility(View.GONE);
finish(); finish();
}); });

View File

@ -28,9 +28,10 @@ import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.CustomViewTarget; import com.bumptech.glide.request.target.CustomViewTarget;
import com.bumptech.glide.request.transition.Transition; import com.bumptech.glide.request.transition.Transition;
import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.appbar.AppBarLayout;
import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils; import com.huanchengfly.tieba.post.BaseApplication;
import com.huanchengfly.tieba.post.R; import com.huanchengfly.tieba.post.R;
import com.huanchengfly.tieba.post.activities.BaseActivity; import com.huanchengfly.tieba.post.activities.BaseActivity;
import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils;
import com.huanchengfly.tieba.post.widgets.theme.TintSwipeRefreshLayout; import com.huanchengfly.tieba.post.widgets.theme.TintSwipeRefreshLayout;
import java.io.File; import java.io.File;
@ -218,6 +219,17 @@ public class ThemeUtil {
} }
} }
public static void setTranslucentBackground(View view) {
if (view == null) {
return;
}
if (!THEME_TRANSLUCENT.equals(ThemeUtil.getTheme(view.getContext()))) {
return;
}
view.setBackgroundTintList(null);
view.setBackgroundColor(Color.TRANSPARENT);
}
public static void setTranslucentThemeBackground(View view, boolean setFitsSystemWindow, BitmapTransformation... transformations) { public static void setTranslucentThemeBackground(View view, boolean setFitsSystemWindow, BitmapTransformation... transformations) {
if (view == null) { if (view == null) {
return; return;
@ -248,6 +260,10 @@ public class ThemeUtil {
view.setBackgroundColor(Color.BLACK); view.setBackgroundColor(Color.BLACK);
return; return;
} }
if (BaseApplication.getTranslucentBackground() != null && (transformations == null || transformations.length == 0)) {
view.setBackground(BaseApplication.getTranslucentBackground());
return;
}
RequestOptions bgOptions = RequestOptions.centerCropTransform() RequestOptions bgOptions = RequestOptions.centerCropTransform()
.skipMemoryCache(true) .skipMemoryCache(true)
.diskCacheStrategy(DiskCacheStrategy.NONE); .diskCacheStrategy(DiskCacheStrategy.NONE);
@ -266,6 +282,7 @@ public class ThemeUtil {
@Override @Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) { public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
BaseApplication.setTranslucentBackground(resource);
getView().setBackground(resource); getView().setBackground(resource);
} }