diff --git a/app/src/main/java/com/huanchengfly/tieba/post/BaseApplication.kt b/app/src/main/java/com/huanchengfly/tieba/post/BaseApplication.kt index b7ff461c..5a7daa6b 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/BaseApplication.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/BaseApplication.kt @@ -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 @@ -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 diff --git a/app/src/main/java/com/huanchengfly/tieba/post/activities/ReplyActivity.java b/app/src/main/java/com/huanchengfly/tieba/post/activities/ReplyActivity.java index 5e553342..d2076af5 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/activities/ReplyActivity.java +++ b/app/src/main/java/com/huanchengfly/tieba/post/activities/ReplyActivity.java @@ -32,32 +32,31 @@ import androidx.recyclerview.widget.RecyclerView; 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; @@ -125,9 +124,7 @@ public class ReplyActivity extends BaseActivity implements View.OnClickListener 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); diff --git a/app/src/main/java/com/huanchengfly/tieba/post/activities/ThemeActivity.java b/app/src/main/java/com/huanchengfly/tieba/post/activities/ThemeActivity.java index 2e77a263..aab258b7 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/activities/ThemeActivity.java +++ b/app/src/main/java/com/huanchengfly/tieba/post/activities/ThemeActivity.java @@ -82,6 +82,12 @@ public class ThemeActivity extends BaseActivity { 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(); diff --git a/app/src/main/java/com/huanchengfly/tieba/post/activities/TranslucentThemeActivity.java b/app/src/main/java/com/huanchengfly/tieba/post/activities/TranslucentThemeActivity.java index 8b52ec5c..ed2a601c 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/activities/TranslucentThemeActivity.java +++ b/app/src/main/java/com/huanchengfly/tieba/post/activities/TranslucentThemeActivity.java @@ -33,17 +33,17 @@ import com.bumptech.glide.request.RequestOptions; 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; @@ -55,9 +55,9 @@ import com.zhihu.matisse.MimeType; 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(); @@ -274,6 +274,7 @@ public class TranslucentThemeActivity extends BaseActivity implements View.OnCli .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(); }); diff --git a/app/src/main/java/com/huanchengfly/tieba/post/utils/ThemeUtil.java b/app/src/main/java/com/huanchengfly/tieba/post/utils/ThemeUtil.java index 0635e108..d18149b2 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/utils/ThemeUtil.java +++ b/app/src/main/java/com/huanchengfly/tieba/post/utils/ThemeUtil.java @@ -28,9 +28,10 @@ import com.bumptech.glide.request.RequestOptions; 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; @@ -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) { if (view == null) { return; @@ -248,6 +260,10 @@ public class ThemeUtil { 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); @@ -266,6 +282,7 @@ public class ThemeUtil { @Override public void onResourceReady(@NonNull Drawable resource, @Nullable Transition transition) { + BaseApplication.setTranslucentBackground(resource); getView().setBackground(resource); }