Optimize wallpaper

pull/123/head
FongMi 3 years ago
parent 3ae616f9da
commit 1bbc29bc83
  1. 3
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/DetailActivity.java
  2. 2
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/HomeActivity.java
  3. 7
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/KeepActivity.java
  4. 2
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/LiveActivity.java
  5. 17
      app/src/main/java/com/fongmi/android/tv/api/WallConfig.java
  6. 22
      app/src/main/java/com/fongmi/android/tv/ui/activity/BaseActivity.java
  7. 17
      app/src/main/java/com/fongmi/android/tv/utils/ImgUtil.java

@ -53,9 +53,7 @@ import com.fongmi.android.tv.utils.Prefers;
import com.fongmi.android.tv.utils.ResUtil;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.ui.StyledPlayerView;
import com.google.android.exoplayer2.util.Log;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
@ -688,6 +686,5 @@ public class DetailActivity extends BaseActivity implements CustomKeyDownVod.Lis
protected void onDestroy() {
super.onDestroy();
mPlayers.release();
EventBus.getDefault().unregister(this);
}
}

@ -46,7 +46,6 @@ import com.fongmi.android.tv.utils.Updater;
import com.fongmi.android.tv.utils.Utils;
import com.google.common.collect.Lists;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
@ -321,6 +320,5 @@ public class HomeActivity extends BaseActivity implements CustomTitleView.Listen
protected void onDestroy() {
super.onDestroy();
Server.get().stop();
EventBus.getDefault().unregister(this);
}
}

@ -16,7 +16,6 @@ import com.fongmi.android.tv.ui.adapter.KeepAdapter;
import com.fongmi.android.tv.ui.custom.SpaceItemDecoration;
import com.fongmi.android.tv.utils.Prefers;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
@ -102,10 +101,4 @@ public class KeepActivity extends BaseActivity implements KeepAdapter.OnClickLis
if (mAdapter.isDelete()) mAdapter.setDelete(false);
else super.onBackPressed();
}
@Override
protected void onDestroy() {
super.onDestroy();
EventBus.getDefault().unregister(this);
}
}

@ -39,7 +39,6 @@ import com.fongmi.android.tv.utils.ResUtil;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.ui.StyledPlayerView;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
@ -435,6 +434,5 @@ public class LiveActivity extends BaseActivity implements GroupPresenter.OnClick
super.onDestroy();
mPlayers.release();
Force.get().stop();
EventBus.getDefault().unregister(this);
}
}

@ -1,5 +1,6 @@
package com.fongmi.android.tv.api;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Looper;
@ -8,6 +9,7 @@ import com.fongmi.android.tv.event.RefreshEvent;
import com.fongmi.android.tv.net.Callback;
import com.fongmi.android.tv.net.OKHttp;
import com.fongmi.android.tv.utils.FileUtil;
import com.fongmi.android.tv.utils.ImgUtil;
import com.fongmi.android.tv.utils.Prefers;
import java.io.File;
@ -15,6 +17,7 @@ import java.io.IOException;
public class WallConfig {
private Drawable drawable;
private Handler handler;
private String url;
@ -30,9 +33,15 @@ public class WallConfig {
return get().url;
}
public static Drawable drawable(Drawable drawable) {
if (get().drawable != null) return drawable;
get().setDrawable(drawable);
return drawable;
}
public WallConfig init() {
setUrl(Config.wall().getUrl());
this.handler = new Handler(Looper.getMainLooper());
this.url = Config.wall().getUrl();
return this;
}
@ -50,6 +59,10 @@ public class WallConfig {
this.url = url;
}
public void setDrawable(Drawable drawable) {
this.drawable = drawable;
}
public void load() {
load(new Callback());
}
@ -73,7 +86,7 @@ public class WallConfig {
private File write(File file) throws IOException {
if (url.startsWith("file")) FileUtil.copy(FileUtil.getLocal(url), file);
else if (url.startsWith("http")) FileUtil.write(file, OKHttp.newCall(url).execute().body().bytes());
else if (url.startsWith("http")) FileUtil.write(file, ImgUtil.resize(OKHttp.newCall(url).execute().body().bytes()));
else file.delete();
return file;
}

@ -11,6 +11,7 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.viewbinding.ViewBinding;
import com.fongmi.android.tv.R;
import com.fongmi.android.tv.api.WallConfig;
import com.fongmi.android.tv.event.RefreshEvent;
import com.fongmi.android.tv.utils.FileUtil;
import com.fongmi.android.tv.utils.Prefers;
@ -51,10 +52,13 @@ public abstract class BaseActivity extends AppCompatActivity {
}
private void setWall() {
File file = FileUtil.getWall(Prefers.getWall());
if (file.exists() && file.length() > 0) getWindow().setBackgroundDrawable(Drawable.createFromPath(file.getPath()));
else if (Prefers.getWall() > 0) getWindow().setBackgroundDrawableResource(ResUtil.getDrawable(file.getName()));
else getWindow().setBackgroundDrawableResource(R.drawable.wallpaper_1);
try {
File file = FileUtil.getWall(Prefers.getWall());
if (file.exists() && file.length() > 0) getWindow().setBackgroundDrawable(WallConfig.drawable(Drawable.createFromPath(file.getPath())));
else getWindow().setBackgroundDrawableResource(ResUtil.getDrawable(file.getName()));
} catch (Exception e) {
getWindow().setBackgroundDrawableResource(R.drawable.wallpaper_1);
}
}
private void hackResources() {
@ -66,7 +70,9 @@ public abstract class BaseActivity extends AppCompatActivity {
@Subscribe(threadMode = ThreadMode.MAIN)
public void onRefreshEvent(RefreshEvent event) {
if (event.getType() == RefreshEvent.Type.WALL) setWall();
if (event.getType() != RefreshEvent.Type.WALL) return;
WallConfig.get().setDrawable(null);
setWall();
}
@Override
@ -86,4 +92,10 @@ public abstract class BaseActivity extends AppCompatActivity {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) Utils.hideSystemUI(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
EventBus.getDefault().unregister(this);
}
}

@ -1,6 +1,8 @@
package com.fongmi.android.tv.utils;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.text.TextUtils;
import android.widget.ImageView;
@ -15,6 +17,8 @@ import com.bumptech.glide.signature.ObjectKey;
import com.fongmi.android.tv.App;
import com.fongmi.android.tv.R;
import java.io.ByteArrayOutputStream;
public class ImgUtil {
public static void load(String url, ImageView view) {
@ -39,4 +43,17 @@ public class ImgUtil {
}
};
}
public static byte[] resize(byte[] bytes) {
int width = ResUtil.getScreenWidthPx();
int height = ResUtil.getScreenHeightPx();
Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
if (bitmap.getWidth() < width && bitmap.getHeight() < height) return bytes;
Matrix matrix = new Matrix();
matrix.postScale((float) width / bitmap.getWidth(), (float) height / bitmap.getHeight());
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
return baos.toByteArray();
}
}

Loading…
Cancel
Save