|
|
|
|
@ -1,6 +1,7 @@ |
|
|
|
|
package com.fongmi.android.tv.ui.base; |
|
|
|
|
|
|
|
|
|
import android.app.Activity; |
|
|
|
|
import android.content.res.Configuration; |
|
|
|
|
import android.content.res.Resources; |
|
|
|
|
import android.graphics.Color; |
|
|
|
|
import android.graphics.drawable.Drawable; |
|
|
|
|
@ -12,9 +13,17 @@ import android.view.ViewGroup; |
|
|
|
|
import android.view.WindowManager; |
|
|
|
|
|
|
|
|
|
import androidx.activity.OnBackPressedCallback; |
|
|
|
|
import androidx.annotation.NonNull; |
|
|
|
|
import androidx.annotation.Nullable; |
|
|
|
|
import androidx.appcompat.app.AppCompatActivity; |
|
|
|
|
import androidx.viewbinding.ViewBinding; |
|
|
|
|
|
|
|
|
|
import com.bumptech.glide.Glide; |
|
|
|
|
import com.bumptech.glide.load.engine.DiskCacheStrategy; |
|
|
|
|
import com.bumptech.glide.request.RequestOptions; |
|
|
|
|
import com.bumptech.glide.request.target.CustomTarget; |
|
|
|
|
import com.bumptech.glide.request.transition.Transition; |
|
|
|
|
import com.fongmi.android.tv.App; |
|
|
|
|
import com.fongmi.android.tv.R; |
|
|
|
|
import com.fongmi.android.tv.Setting; |
|
|
|
|
import com.fongmi.android.tv.api.config.WallConfig; |
|
|
|
|
@ -39,12 +48,17 @@ public abstract class BaseActivity extends AppCompatActivity { |
|
|
|
|
if (transparent()) setTransparent(this); |
|
|
|
|
setContentView(getBinding().getRoot()); |
|
|
|
|
EventBus.getDefault().register(this); |
|
|
|
|
setBackCallback(); |
|
|
|
|
setWall(); |
|
|
|
|
initView(savedInstanceState); |
|
|
|
|
setBackCallback(); |
|
|
|
|
initEvent(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void setContentView(View view) { |
|
|
|
|
super.setContentView(view); |
|
|
|
|
refreshWall(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected Activity getActivity() { |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
@ -107,24 +121,24 @@ public abstract class BaseActivity extends AppCompatActivity { |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void setWall() { |
|
|
|
|
private void setTransparent(Activity activity) { |
|
|
|
|
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); |
|
|
|
|
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); |
|
|
|
|
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); |
|
|
|
|
activity.getWindow().setStatusBarColor(Color.TRANSPARENT); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void refreshWall() { |
|
|
|
|
try { |
|
|
|
|
if (!customWall()) return; |
|
|
|
|
File file = FileUtil.getWall(Setting.getWall()); |
|
|
|
|
if (file.exists() && file.length() > 0) getWindow().setBackgroundDrawable(WallConfig.drawable(Drawable.createFromPath(file.getAbsolutePath()))); |
|
|
|
|
if (file.exists() && file.length() > 0) loadWall(file); |
|
|
|
|
else getWindow().setBackgroundDrawableResource(ResUtil.getDrawable(file.getName())); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
getWindow().setBackgroundDrawableResource(R.drawable.wallpaper_1); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void setTransparent(Activity activity) { |
|
|
|
|
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); |
|
|
|
|
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); |
|
|
|
|
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); |
|
|
|
|
activity.getWindow().setStatusBarColor(Color.TRANSPARENT); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Resources hackResources(Resources resources) { |
|
|
|
|
try { |
|
|
|
|
LanguageUtil.setLanguage(resources, Setting.getLanguage()); |
|
|
|
|
@ -139,11 +153,33 @@ public abstract class BaseActivity extends AppCompatActivity { |
|
|
|
|
return hackResources(super.getResources()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void loadWall(File file) { |
|
|
|
|
Glide.with(App.get()).load(file).centerCrop().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).apply(new RequestOptions().override(ResUtil.getScreenWidth(), ResUtil.getScreenHeight())).into(new CustomTarget<Drawable>() { |
|
|
|
|
@Override |
|
|
|
|
public void onResourceReady(@NonNull Drawable drawable, @Nullable Transition<? super Drawable> transition) { |
|
|
|
|
getWindow().setBackgroundDrawable(drawable); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onLoadFailed(@Nullable Drawable error) { |
|
|
|
|
getWindow().setBackgroundDrawableResource(R.drawable.wallpaper_1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onLoadCleared(@Nullable Drawable drawable) { |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onConfigurationChanged(@NonNull Configuration newConfig) { |
|
|
|
|
if (getRequestedOrientation() != newConfig.orientation) refreshWall(); |
|
|
|
|
super.onConfigurationChanged(newConfig); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Subscribe(threadMode = ThreadMode.MAIN) |
|
|
|
|
public void onRefreshEvent(RefreshEvent event) { |
|
|
|
|
if (event.getType() != RefreshEvent.Type.WALL) return; |
|
|
|
|
WallConfig.get().setDrawable(null); |
|
|
|
|
setWall(); |
|
|
|
|
if (event.getType() == RefreshEvent.Type.WALL) refreshWall(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|