Skip to content

Commit

Permalink
feat: 增加透明主题背景缓存
Browse files Browse the repository at this point in the history
  • Loading branch information
HuanCheng65 committed Aug 15, 2020
1 parent 41102c3 commit ecc7050
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import android.app.Activity
import android.app.Application
import android.content.ClipboardManager
import android.content.Context
import android.content.DialogInterface
import android.content.Intent
import android.content.res.ColorStateList
import android.content.res.Configuration
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.net.Uri
import android.os.Bundle
import android.text.TextUtils
Expand Down Expand Up @@ -226,6 +226,9 @@ class BaseApplication : Application() {
companion object {
val TAG = BaseApplication::class.java.simpleName

@JvmStatic
var translucentBackground: Drawable? = null

private val packageName: String
get() = instance.packageName

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,31 @@
import androidx.viewpager.widget.ViewPager;

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.adapters.InsertPhotoAdapter;
import com.huanchengfly.tieba.post.adapters.TabViewPagerAdapter;
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.dialogs.LoadingDialog;
import com.huanchengfly.tieba.post.components.transformations.RadiusTransformation;
import com.huanchengfly.tieba.post.interfaces.ReplyContentCallback;
import com.huanchengfly.tieba.post.interfaces.UploadCallback;
import com.huanchengfly.tieba.post.models.PhotoInfoBean;
import com.huanchengfly.tieba.post.models.ReplyInfoBean;
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.GsonUtil;
import com.huanchengfly.tieba.post.utils.StringUtil;
import com.huanchengfly.tieba.post.utils.ThemeUtil;
import com.huanchengfly.tieba.post.utils.UploadHelper;
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.TintImageView;
import com.huanchengfly.tieba.post.utils.AssetUtil;
import com.huanchengfly.tieba.post.utils.GsonUtil;
import com.zhihu.matisse.Matisse;

import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -125,9 +124,7 @@ protected void onCreate(Bundle savedInstanceState) {
if (ThemeUtil.THEME_TRANSLUCENT.equals(ThemeUtil.getTheme(this))) {
TintConstraintLayout constraintLayout = (TintConstraintLayout) findViewById(R.id.activity_reply_layout);
constraintLayout.setBackgroundTintResId(0);
ThemeUtil.setTranslucentThemeBackground(constraintLayout,
false,
new RadiusTransformation(this, 8, RadiusTransformation.CORNER_TOP_LEFT | RadiusTransformation.CORNER_TOP_RIGHT));
ThemeUtil.setTranslucentBackground(constraintLayout);
}
Util.setStatusBarTransparent(this);
getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ protected void onCreate(Bundle savedInstanceState) {
ThemeUtil.setTranslucentThemeBackground(findViewById(R.id.background));
}

@Override
protected void onResume() {
super.onResume();
ThemeUtil.setTranslucentThemeBackground(findViewById(R.id.background));
}

@SuppressLint("ApplySharedPref")
private void setTheme(String theme) {
ThemeUtil.getSharedPreferences(ThemeActivity.this).edit().putString(ThemeUtil.SP_THEME, theme).commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
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.R;
import com.huanchengfly.tieba.post.adapters.ThemeColorAdapter;
import com.huanchengfly.tieba.post.components.MyImageEngine;
import com.huanchengfly.tieba.post.components.MyLinearLayoutManager;
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.PermissionUtil;
import com.huanchengfly.tieba.post.utils.SharedPreferencesUtil;
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.ColorPickerDialogListener;
import com.yalantis.ucrop.UCrop;
Expand All @@ -55,9 +55,9 @@
import java.io.File;
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.THEME_TRANSLUCENT;
import static com.huanchengfly.tieba.post.utils.ColorUtils.getDarkerColor;

public class TranslucentThemeActivity extends BaseActivity implements View.OnClickListener, SeekBar.OnSeekBarChangeListener, ColorPickerDialogListener {
public static final String TAG = TranslucentThemeActivity.class.getSimpleName();
Expand Down Expand Up @@ -274,6 +274,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
.putString(ThemeUtil.SP_OLD_THEME, THEME_TRANSLUCENT)
.commit();
Toast.makeText(TranslucentThemeActivity.this, R.string.toast_save_pic_success, Toast.LENGTH_SHORT).show();
BaseApplication.setTranslucentBackground(null);
mProgress.setVisibility(View.GONE);
finish();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
import com.bumptech.glide.request.target.CustomViewTarget;
import com.bumptech.glide.request.transition.Transition;
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.activities.BaseActivity;
import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils;
import com.huanchengfly.tieba.post.widgets.theme.TintSwipeRefreshLayout;

import java.io.File;
Expand Down Expand Up @@ -218,6 +219,17 @@ public static void setAppBarFitsSystemWindow(View view, boolean appBarFitsSystem
}
}

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) {
if (view == null) {
return;
Expand Down Expand Up @@ -248,6 +260,10 @@ public static void setTranslucentThemeBackground(View view, boolean setFitsSyste
view.setBackgroundColor(Color.BLACK);
return;
}
if (BaseApplication.getTranslucentBackground() != null && (transformations == null || transformations.length == 0)) {
view.setBackground(BaseApplication.getTranslucentBackground());
return;
}
RequestOptions bgOptions = RequestOptions.centerCropTransform()
.skipMemoryCache(true)
.diskCacheStrategy(DiskCacheStrategy.NONE);
Expand All @@ -266,6 +282,7 @@ public void onLoadFailed(@Nullable Drawable errorDrawable) {

@Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
BaseApplication.setTranslucentBackground(resource);
getView().setBackground(resource);
}

Expand Down

0 comments on commit ecc7050

Please sign in to comment.