diff --git a/app/src/main/java/com/hippo/beerbelly/DiskLruCache.java b/app/src/main/java/com/hippo/beerbelly/DiskLruCache.java index 1d722273c..8e87c076f 100644 --- a/app/src/main/java/com/hippo/beerbelly/DiskLruCache.java +++ b/app/src/main/java/com/hippo/beerbelly/DiskLruCache.java @@ -231,6 +231,21 @@ public final class DiskLruCache implements Closeable { cache = new DiskLruCache(directory, appVersion, valueCount, maxSize); cache.rebuildJournal(); return cache; + } + + private static void deleteIfExists(File file) throws IOException { + if (file.exists() && !file.delete()) { + throw new IOException(); + } + } + + private static void renameTo(File from, File to, boolean deleteDestination) throws IOException { + if (deleteDestination) { + deleteIfExists(to); + } + if (!from.renameTo(to)) { + throw new IOException(); + } } private final Callable cleanupCallable = new Callable<>() { public Void call() throws Exception { synchronized (DiskLruCache.this) { @@ -247,21 +262,6 @@ public final class DiskLruCache implements Closeable { } }; - private static void deleteIfExists(File file) throws IOException { - if (file.exists() && !file.delete()) { - throw new IOException(); - } - } - - private static void renameTo(File from, File to, boolean deleteDestination) throws IOException { - if (deleteDestination) { - deleteIfExists(to); - } - if (!from.renameTo(to)) { - throw new IOException(); - } - } - private static String inputStreamToString(InputStream in) throws IOException { return Util.readFully(new InputStreamReader(in, Util.UTF_8)); } diff --git a/app/src/main/java/com/hippo/beerbelly/StrictLineReader.java b/app/src/main/java/com/hippo/beerbelly/StrictLineReader.java index 5368841e5..9f7c885d0 100644 --- a/app/src/main/java/com/hippo/beerbelly/StrictLineReader.java +++ b/app/src/main/java/com/hippo/beerbelly/StrictLineReader.java @@ -23,7 +23,6 @@ import java.io.Closeable; import java.io.EOFException; import java.io.IOException; import java.io.InputStream; -import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; /** @@ -140,7 +139,7 @@ class StrictLineReader implements Closeable { for (int i = pos; i != end; ++i) { if (buf[i] == LF) { int lineEnd = (i != pos && buf[i - 1] == CR) ? i - 1 : i; - String res = new String(buf, pos, lineEnd - pos, charset.name()); + String res = new String(buf, pos, lineEnd - pos, charset); pos = i + 1; return res; } @@ -152,11 +151,7 @@ class StrictLineReader implements Closeable { @Override public String toString() { int length = (count > 0 && buf[count - 1] == CR) ? count - 1 : count; - try { - return new String(buf, 0, length, charset.name()); - } catch (UnsupportedEncodingException e) { - throw new AssertionError(e); // Since we control the charset this will never happen. - } + return new String(buf, 0, length, charset); } }; diff --git a/app/src/main/java/com/hippo/conaco/ConacoTask.java b/app/src/main/java/com/hippo/conaco/ConacoTask.java index bd9ed496b..629f97cae 100644 --- a/app/src/main/java/com/hippo/conaco/ConacoTask.java +++ b/app/src/main/java/com/hippo/conaco/ConacoTask.java @@ -25,7 +25,6 @@ import androidx.annotation.UiThread; import com.hippo.beerbelly.SimpleDiskCache; import com.hippo.okhttp.ChromeRequestBuilder; -import com.hippo.streampipe.InputStreamPipe; import com.hippo.streampipe.OutputStreamPipe; import java.io.IOException; @@ -35,8 +34,6 @@ import java.lang.ref.WeakReference; import java.util.concurrent.Executor; import okhttp3.Call; -import okhttp3.HttpUrl; -import okhttp3.MediaType; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; diff --git a/app/src/main/java/com/hippo/easyrecyclerview/LayoutManagerUtils.java b/app/src/main/java/com/hippo/easyrecyclerview/LayoutManagerUtils.java index 07d045f71..dec9169d8 100644 --- a/app/src/main/java/com/hippo/easyrecyclerview/LayoutManagerUtils.java +++ b/app/src/main/java/com/hippo/easyrecyclerview/LayoutManagerUtils.java @@ -64,8 +64,7 @@ public final class LayoutManagerUtils { RecyclerView.LayoutManager layoutManager, Context context, int position, int millisecondsPerInch) { SimpleSmoothScroller smoothScroller; - if (layoutManager instanceof LinearLayoutManager) { - final LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager; + if (layoutManager instanceof final LinearLayoutManager linearLayoutManager) { smoothScroller = new SimpleSmoothScroller(context, millisecondsPerInch) { @Override public PointF computeScrollVectorForPosition(int targetPosition) { @@ -73,8 +72,7 @@ public final class LayoutManagerUtils { } }; - } else if (layoutManager instanceof StaggeredGridLayoutManager) { - final StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager; + } else if (layoutManager instanceof final StaggeredGridLayoutManager staggeredGridLayoutManager) { smoothScroller = new SimpleSmoothScroller(context, millisecondsPerInch) { @Override public PointF computeScrollVectorForPosition(int targetPosition) { diff --git a/app/src/main/java/com/hippo/ehviewer/EhApplication.java b/app/src/main/java/com/hippo/ehviewer/EhApplication.java index d86cad842..895af0990 100644 --- a/app/src/main/java/com/hippo/ehviewer/EhApplication.java +++ b/app/src/main/java/com/hippo/ehviewer/EhApplication.java @@ -62,7 +62,6 @@ import com.hippo.ehviewer.download.DownloadManager; import com.hippo.ehviewer.spider.SpiderDen; import com.hippo.ehviewer.ui.CommonOperations; import com.hippo.ehviewer.ui.EhActivity; -import com.hippo.image.Image; import com.hippo.image.ImageBitmap; import com.hippo.network.StatusCodeException; import com.hippo.scene.SceneApplication; @@ -187,10 +186,9 @@ public class EhApplication extends SceneApplication { TrustManagerFactory.getDefaultAlgorithm()); trustManagerFactory.init((KeyStore) null); TrustManager[] trustManagers = trustManagerFactory.getTrustManagers(); - if (trustManagers.length != 1 || !(trustManagers[0] instanceof X509TrustManager)) { + if (trustManagers.length != 1 || !(trustManagers[0] instanceof X509TrustManager trustManager)) { throw new IllegalStateException("Unexpected default trust managers:" + Arrays.toString(trustManagers)); } - X509TrustManager trustManager = (X509TrustManager) trustManagers[0]; builder.sslSocketFactory(new EhSSLSocketFactory(), trustManager); } catch (Exception e) { e.printStackTrace(); diff --git a/app/src/main/java/com/hippo/ehviewer/EhDB.java b/app/src/main/java/com/hippo/ehviewer/EhDB.java index c7178172e..d9e23e454 100644 --- a/app/src/main/java/com/hippo/ehviewer/EhDB.java +++ b/app/src/main/java/com/hippo/ehviewer/EhDB.java @@ -495,13 +495,15 @@ public class EhDB { try { List downloadLabelList = oldRoomDatabase.downloadLabelDao().list(); manager.addDownloadLabel(downloadLabelList); - } catch (Exception ignored) {} + } catch (Exception ignored) { + } // Downloads try { List downloadInfoList = oldRoomDatabase.downloadsDao().list(); manager.addDownload(downloadInfoList, false); - } catch (Exception ignored) {} + } catch (Exception ignored) { + } // Download dirname try { @@ -509,13 +511,15 @@ public class EhDB { for (DownloadDirname dirname : downloadDirnameList) { putDownloadDirname(dirname.getGid(), dirname.getDirname()); } - } catch (Exception ignored) {} + } catch (Exception ignored) { + } // History try { List historyInfoList = oldRoomDatabase.historyDao().list(); putHistoryInfo(historyInfoList); - } catch (Exception ignored) {} + } catch (Exception ignored) { + } // QuickSearch try { @@ -537,7 +541,8 @@ public class EhDB { importList.add(quickSearch); } importQuickSearch(importList); - } catch (Exception ignored) {} + } catch (Exception ignored) { + } // LocalFavorites try { @@ -545,7 +550,8 @@ public class EhDB { for (LocalFavoriteInfo info : localFavoriteInfoList) { putLocalFavorites(info); } - } catch (Exception ignored) {} + } catch (Exception ignored) { + } // Filter try { @@ -556,7 +562,8 @@ public class EhDB { addFilter(filter); } } - } catch (Exception ignored) {} + } catch (Exception ignored) { + } return null; } catch (Throwable e) { diff --git a/app/src/main/java/com/hippo/ehviewer/Settings.java b/app/src/main/java/com/hippo/ehviewer/Settings.java index ac49a3f34..5623c1fea 100755 --- a/app/src/main/java/com/hippo/ehviewer/Settings.java +++ b/app/src/main/java/com/hippo/ehviewer/Settings.java @@ -100,16 +100,13 @@ public class Settings { public static final String KEY_BUILT_IN_HOSTS = "built_in_hosts_2"; public static final String KEY_DOMAIN_FRONTING = "domain_fronting"; public static final String KEY_APP_LANGUAGE = "app_language"; + public static final String KEY_LIST_THUMB_SIZE = "list_tile_size"; private static final String TAG = Settings.class.getSimpleName(); private static final String KEY_VERSION_CODE = "version_code"; private static final int DEFAULT_VERSION_CODE = 0; private static final String KEY_DISPLAY_NAME = "display_name"; private static final String DEFAULT_DISPLAY_NAME = null; - public static final String KEY_LIST_THUMB_SIZE = "list_tile_size"; private static final int DEFAULT_LIST_THUMB_SIZE = 40; - private static int LIST_THUMB_SIZE = 40; - - public static boolean LIST_THUMB_SIZE_INITED = false; private static final String KEY_AVATAR = "avatar"; private static final String DEFAULT_AVATAR = null; private static final String KEY_SHOW_WARNING = "show_warning"; @@ -280,11 +277,9 @@ public class Settings { private static final int DEFAULT_DOWNLOAD_DELAY = 0; private static final String KEY_REQUEST_NEWS = "request_news"; private static final boolean DEFAULT_REQUEST_NEWS = true; - - private static final String KEY_ARCHIVE_PASSWDS = "archive_passwds"; - - + public static boolean LIST_THUMB_SIZE_INITED = false; + private static int LIST_THUMB_SIZE = 40; private static Context sContext; private static SharedPreferences sSettingsPre; private static EhConfig sEhConfig; @@ -973,11 +968,11 @@ public class Settings { boolean writeFile = false; String userID = getString(KEY_USER_ID, null); File file = AppConfig.getFileInExternalAppDir(FILENAME_USER_ID); - if (null == userID || !isValidUserID(userID)) { + if (!isValidUserID(userID)) { writeXml = true; // Get use ID from out sd card file userID = FileUtils.read(file); - if (null == userID || !isValidUserID(userID)) { + if (!isValidUserID(userID)) { writeFile = true; userID = generateUserID(); } @@ -1061,6 +1056,7 @@ public class Settings { public static void putSecurity(boolean value) { putBoolean(KEY_SECURITY, value); } + public static int getSecurityDelay() { return getInt(KEY_SECURITY_DELAY, 0); } diff --git a/app/src/main/java/com/hippo/ehviewer/client/data/FavListUrlBuilder.java b/app/src/main/java/com/hippo/ehviewer/client/data/FavListUrlBuilder.java index 35f904239..834544d05 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/data/FavListUrlBuilder.java +++ b/app/src/main/java/com/hippo/ehviewer/client/data/FavListUrlBuilder.java @@ -16,16 +16,17 @@ package com.hippo.ehviewer.client.data; +import android.os.Build; import android.os.Parcel; import android.os.Parcelable; import android.text.TextUtils; -import android.util.Log; import com.hippo.ehviewer.client.EhUrl; import com.hippo.network.UrlBuilder; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; public class FavListUrlBuilder implements Parcelable { @@ -105,17 +106,21 @@ public class FavListUrlBuilder implements Parcelable { ub.addQuery("favcat", "all"); } if (!TextUtils.isEmpty(mKeyword)) { - try { - ub.addQuery("f_search", URLEncoder.encode(mKeyword, "UTF-8")); - // Name - ub.addQuery("sn", "on"); - // Tags - ub.addQuery("st", "on"); - // Note - ub.addQuery("sf", "on"); - } catch (UnsupportedEncodingException e) { - Log.e(TAG, "Can't URLEncoder.encode " + mKeyword); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + ub.addQuery("f_search", URLEncoder.encode(mKeyword, StandardCharsets.UTF_8)); + } else { + try { + ub.addQuery("f_search", URLEncoder.encode(mKeyword, StandardCharsets.UTF_8.displayName())); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } } + // Name + ub.addQuery("sn", "on"); + // Tags + ub.addQuery("st", "on"); + // Note + ub.addQuery("sf", "on"); } if (mPrev != null && !mPrev.isEmpty()) { ub.addQuery("prev", mPrev); diff --git a/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryListParser.java b/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryListParser.java index f241d91cf..9a62a7ccc 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryListParser.java +++ b/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryListParser.java @@ -309,8 +309,10 @@ public class GalleryListParser { assert next != null; Matcher matcherPrev = PATTERN_PREV_PAGE.matcher(prev.attr("href")); Matcher matcherNext = PATTERN_NEXT_PAGE.matcher(next.attr("href")); - if (matcherPrev.find()) result.prevGid = NumberUtils.parseIntSafely(matcherPrev.group(1), 0); - if (matcherNext.find()) result.nextGid = NumberUtils.parseIntSafely(matcherNext.group(1), 0); + if (matcherPrev.find()) + result.prevGid = NumberUtils.parseIntSafely(matcherPrev.group(1), 0); + if (matcherNext.find()) + result.nextGid = NumberUtils.parseIntSafely(matcherNext.group(1), 0); result.founds = Integer.MAX_VALUE; } catch (Throwable e) { ExceptionUtils.throwIfFatal(e); diff --git a/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryListUrlParser.java b/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryListUrlParser.java index efc024344..3a17e66a9 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryListUrlParser.java +++ b/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryListUrlParser.java @@ -17,6 +17,7 @@ package com.hippo.ehviewer.client.parser; import android.net.Uri; +import android.os.Build; import android.text.TextUtils; import com.hippo.ehviewer.client.EhUrl; @@ -27,6 +28,7 @@ import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; public final class GalleryListUrlParser { @@ -91,10 +93,15 @@ public final class GalleryListUrlParser { uploader = path.substring(prefixLength, index); } - try { - uploader = URLDecoder.decode(uploader, "utf-8"); - } catch (UnsupportedEncodingException e) { - return null; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + uploader = URLDecoder.decode(uploader, StandardCharsets.UTF_8); + } else { + try { + uploader = URLDecoder.decode(uploader, StandardCharsets.UTF_8.displayName()); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + return null; + } } if (TextUtils.isEmpty(uploader)) { @@ -120,10 +127,15 @@ public final class GalleryListUrlParser { tag = path.substring(prefixLength, index); } - try { - tag = URLDecoder.decode(tag, "utf-8"); - } catch (UnsupportedEncodingException e) { - return null; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + tag = URLDecoder.decode(tag, StandardCharsets.UTF_8); + } else { + try { + tag = URLDecoder.decode(tag, StandardCharsets.UTF_8.displayName()); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + return null; + } } if (TextUtils.isEmpty(tag)) { diff --git a/app/src/main/java/com/hippo/ehviewer/dao/BasicDao.java b/app/src/main/java/com/hippo/ehviewer/dao/BasicDao.java index 0e774bb5a..511bf3f22 100644 --- a/app/src/main/java/com/hippo/ehviewer/dao/BasicDao.java +++ b/app/src/main/java/com/hippo/ehviewer/dao/BasicDao.java @@ -4,5 +4,6 @@ import java.util.List; public interface BasicDao { List list(); + long insert(T t); } diff --git a/app/src/main/java/com/hippo/ehviewer/dao/Filter.java b/app/src/main/java/com/hippo/ehviewer/dao/Filter.java index ede60ee24..6128f8c1c 100644 --- a/app/src/main/java/com/hippo/ehviewer/dao/Filter.java +++ b/app/src/main/java/com/hippo/ehviewer/dao/Filter.java @@ -58,10 +58,9 @@ public class Filter { @Override public boolean equals(Object o) { - if (!(o instanceof Filter)) { + if (!(o instanceof Filter filter)) { return false; } - Filter filter = (Filter) o; return filter.mode == mode && ObjectUtils.equal(filter.text, text); } } diff --git a/app/src/main/java/com/hippo/ehviewer/download/DownloadService.kt b/app/src/main/java/com/hippo/ehviewer/download/DownloadService.kt index 52d58f032..426f6266c 100644 --- a/app/src/main/java/com/hippo/ehviewer/download/DownloadService.kt +++ b/app/src/main/java/com/hippo/ehviewer/download/DownloadService.kt @@ -498,6 +498,7 @@ class DownloadService : Service(), DownloadManager.DownloadListener { } mNotifyManager.notify(mId, mBuilder.build()) } + OPS_CANCEL -> mNotifyManager.cancel(mId) OPS_START_FOREGROUND -> mService.startForeground(mId, mBuilder.build()) } diff --git a/app/src/main/java/com/hippo/ehviewer/gallery/ArchiveGalleryProvider.java b/app/src/main/java/com/hippo/ehviewer/gallery/ArchiveGalleryProvider.java index 9690a617e..c5093fc36 100644 --- a/app/src/main/java/com/hippo/ehviewer/gallery/ArchiveGalleryProvider.java +++ b/app/src/main/java/com/hippo/ehviewer/gallery/ArchiveGalleryProvider.java @@ -36,7 +36,6 @@ import com.hippo.yorozuya.FileUtils; import com.hippo.yorozuya.thread.PVLock; import com.hippo.yorozuya.thread.PriorityThread; -import java.io.FileDescriptor; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; @@ -55,14 +54,13 @@ public class ArchiveGalleryProvider extends GalleryProvider2 { private final UriArchiveAccessor archiveAccessor; private final Stack requests = new Stack<>(); private final LinkedHashMap streams = new LinkedHashMap<>(); - private Thread archiveThread; - private Thread[] decodeThread = new Thread[] { + private final Thread[] decodeThread = new Thread[]{ new Thread(new DecodeTask()), new Thread(new DecodeTask()), new Thread(new DecodeTask()), new Thread(new DecodeTask()) }; - + private Thread archiveThread; private volatile int size = STATE_WAIT; private String error; @@ -164,7 +162,7 @@ public class ArchiveGalleryProvider extends GalleryProvider2 { int fd; FileOutputStream stream; try { - stream = (FileOutputStream)file.openOutputStream(); + stream = (FileOutputStream) file.openOutputStream(); fd = Native.getFd(stream.getFD()); } catch (IOException e) { e.printStackTrace(); @@ -190,7 +188,7 @@ public class ArchiveGalleryProvider extends GalleryProvider2 { } private class ArchiveHostTask implements Runnable { - public final Thread[] archiveThreads = new Thread[] { + public final Thread[] archiveThreads = new Thread[]{ new Thread(new ArchiveTask()), new Thread(new ArchiveTask()), new Thread(new ArchiveTask()), diff --git a/app/src/main/java/com/hippo/ehviewer/preference/AccountPreference.kt b/app/src/main/java/com/hippo/ehviewer/preference/AccountPreference.kt index 4a7fca324..f93199804 100644 --- a/app/src/main/java/com/hippo/ehviewer/preference/AccountPreference.kt +++ b/app/src/main/java/com/hippo/ehviewer/preference/AccountPreference.kt @@ -15,7 +15,8 @@ */ package com.hippo.ehviewer.preference -import android.content.* +import android.content.Context +import android.content.DialogInterface import android.text.Html import android.util.AttributeSet import androidx.appcompat.app.AlertDialog @@ -28,10 +29,9 @@ import com.hippo.ehviewer.ui.SettingsActivity import com.hippo.ehviewer.ui.scene.BaseScene import com.hippo.preference.MessagePreference import com.hippo.util.addTextToClipboard -import com.hippo.util.getClipboardManager import okhttp3.Cookie import okhttp3.HttpUrl.Companion.toHttpUrl -import java.util.* +import java.util.LinkedList class AccountPreference @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null diff --git a/app/src/main/java/com/hippo/ehviewer/ui/GalleryActivity.java b/app/src/main/java/com/hippo/ehviewer/ui/GalleryActivity.java index d178586dc..f9e0020a1 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/GalleryActivity.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/GalleryActivity.java @@ -303,16 +303,7 @@ public class GalleryActivity extends EhActivity implements SeekBar.OnSeekBarChan break; } super.attachBaseContext(newBase); - } ActivityResultLauncher requestStoragePermissionLauncher = registerForActivityResult( - new ActivityResultContracts.RequestPermission(), - result -> { - if (result && mSavingPage != -1) { - saveImage(mSavingPage); - } else { - Toast.makeText(this, R.string.error_cant_save_image, Toast.LENGTH_SHORT).show(); - } - mSavingPage = -1; - }); + } @Override @SuppressWarnings({"WrongConstant"}) @@ -404,26 +395,25 @@ public class GalleryActivity extends EhActivity implements SeekBar.OnSeekBarChan if (mGalleryView == null) { return false; } - switch (event.getAction()) { - case MotionEvent.ACTION_SCROLL: - float scroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL) * 300; - if (scroll < 0.0f) { - if (mLayoutMode == GalleryView.LAYOUT_RIGHT_TO_LEFT) { - mGalleryView.pageLeft(); - } else if (mLayoutMode == GalleryView.LAYOUT_LEFT_TO_RIGHT) { - mGalleryView.pageRight(); - } else if (mLayoutMode == GalleryView.LAYOUT_TOP_TO_BOTTOM) { - mGalleryView.onScroll(0, -scroll, 0, -scroll, 0, -scroll); - } - } else { - if (mLayoutMode == GalleryView.LAYOUT_RIGHT_TO_LEFT) { - mGalleryView.pageRight(); - } else if (mLayoutMode == GalleryView.LAYOUT_LEFT_TO_RIGHT) { - mGalleryView.pageLeft(); - } else if (mLayoutMode == GalleryView.LAYOUT_TOP_TO_BOTTOM) { - mGalleryView.onScroll(0, -scroll, 0, -scroll, 0, -scroll); - } + if (event.getAction() == MotionEvent.ACTION_SCROLL) { + float scroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL) * 300; + if (scroll < 0.0f) { + if (mLayoutMode == GalleryView.LAYOUT_RIGHT_TO_LEFT) { + mGalleryView.pageLeft(); + } else if (mLayoutMode == GalleryView.LAYOUT_LEFT_TO_RIGHT) { + mGalleryView.pageRight(); + } else if (mLayoutMode == GalleryView.LAYOUT_TOP_TO_BOTTOM) { + mGalleryView.onScroll(0, -scroll, 0, -scroll, 0, -scroll); } + } else { + if (mLayoutMode == GalleryView.LAYOUT_RIGHT_TO_LEFT) { + mGalleryView.pageRight(); + } else if (mLayoutMode == GalleryView.LAYOUT_LEFT_TO_RIGHT) { + mGalleryView.pageLeft(); + } else if (mLayoutMode == GalleryView.LAYOUT_TOP_TO_BOTTOM) { + mGalleryView.onScroll(0, -scroll, 0, -scroll, 0, -scroll); + } + } } return false; }); @@ -521,7 +511,16 @@ public class GalleryActivity extends EhActivity implements SeekBar.OnSeekBarChan mSeekBar = null; SimpleHandler.getInstance().removeCallbacks(mHideSliderRunnable); - } + } ActivityResultLauncher requestStoragePermissionLauncher = registerForActivityResult( + new ActivityResultContracts.RequestPermission(), + result -> { + if (result && mSavingPage != -1) { + saveImage(mSavingPage); + } else { + Toast.makeText(this, R.string.error_cant_save_image, Toast.LENGTH_SHORT).show(); + } + mSavingPage = -1; + }); @Override protected void onPause() { diff --git a/app/src/main/java/com/hippo/ehviewer/ui/GalleryInfoBottomSheet.kt b/app/src/main/java/com/hippo/ehviewer/ui/GalleryInfoBottomSheet.kt index 5e0a06264..38bf42f54 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/GalleryInfoBottomSheet.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/GalleryInfoBottomSheet.kt @@ -32,7 +32,6 @@ import com.hippo.ehviewer.client.EhUrl import com.hippo.ehviewer.client.EhUtils import com.hippo.ehviewer.client.data.GalleryDetail import com.hippo.util.addTextToClipboard -import com.hippo.util.getClipboardManager class GalleryInfoBottomSheet(detail: GalleryDetail) : BottomSheetDialogFragment() { private var mKeys: ArrayList = arrayListOf() diff --git a/app/src/main/java/com/hippo/ehviewer/ui/MainActivity.java b/app/src/main/java/com/hippo/ehviewer/ui/MainActivity.java index fe3ab7df4..8b220235e 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/MainActivity.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/MainActivity.java @@ -477,8 +477,7 @@ public final class MainActivity extends StageActivity @SuppressLint("RtlHardcoded") public void createDrawerView(SceneFragment scene) { - if (scene instanceof BaseScene && mRightDrawer != null && mDrawerLayout != null) { - BaseScene baseScene = (BaseScene) scene; + if (scene instanceof BaseScene baseScene && mRightDrawer != null && mDrawerLayout != null) { mRightDrawer.removeAllViews(); View drawerView = baseScene.createDrawerView( baseScene.getLayoutInflater(), mRightDrawer, null); @@ -495,8 +494,7 @@ public final class MainActivity extends StageActivity public void onSceneViewDestroyed(SceneFragment scene) { super.onSceneViewDestroyed(scene); - if (scene instanceof BaseScene) { - BaseScene baseScene = (BaseScene) scene; + if (scene instanceof BaseScene baseScene) { baseScene.destroyDrawerView(); } } diff --git a/app/src/main/java/com/hippo/ehviewer/ui/fragment/AdvancedFragment.java b/app/src/main/java/com/hippo/ehviewer/ui/fragment/AdvancedFragment.java index d5f20156a..00dbae68d 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/fragment/AdvancedFragment.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/fragment/AdvancedFragment.java @@ -35,15 +35,15 @@ import androidx.preference.Preference; import com.hippo.app.BaseDialogBuilder; import com.hippo.ehviewer.AppConfig; import com.hippo.ehviewer.BuildConfig; -import com.hippo.ehviewer.client.data.FavListUrlBuilder; -import com.hippo.ehviewer.client.EhClient; -import com.hippo.ehviewer.client.EhRequest; -import com.hippo.ehviewer.client.parser.FavoritesParser; import com.hippo.ehviewer.EhApplication; import com.hippo.ehviewer.EhDB; import com.hippo.ehviewer.GetText; import com.hippo.ehviewer.R; import com.hippo.ehviewer.Settings; +import com.hippo.ehviewer.client.EhClient; +import com.hippo.ehviewer.client.EhRequest; +import com.hippo.ehviewer.client.data.FavListUrlBuilder; +import com.hippo.ehviewer.client.parser.FavoritesParser; import com.hippo.ehviewer.ui.scene.BaseScene; import com.hippo.util.ExceptionUtils; import com.hippo.util.IoThreadPoolExecutor; @@ -69,9 +69,6 @@ public class AdvancedFragment extends BasePreferenceFragment { private static final String KEY_EXPORT_DATA = "export_data"; private static final String KEY_OPEN_BY_DEFAULT = "open_by_default"; private static final String KEY_BACKUP_FAVORITE = "backup_favorite"; - private int favTotal; - private int favIndex; - ActivityResultLauncher exportLauncher = registerForActivityResult( new ActivityResultContracts.CreateDocument(), uri -> { @@ -227,6 +224,8 @@ public class AdvancedFragment extends BasePreferenceFragment { } } }); + private int favTotal; + private int favIndex; @Override public void onCreatePreferences(@Nullable Bundle savedInstanceState, String rootKey) { @@ -340,7 +339,7 @@ public class AdvancedFragment extends BasePreferenceFragment { } catch (InterruptedException e) { e.printStackTrace(); } - favIndex ++; + favIndex++; favListUrlBuilder.setNext(favResult.nextPage); request.setArgs(favListUrlBuilder.build(), Settings.getShowJpnTitle()); mClient.execute(request); diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/BaseScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/BaseScene.java index 066e17dd9..0712283fb 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/BaseScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/BaseScene.java @@ -42,8 +42,6 @@ import androidx.fragment.app.FragmentActivity; import com.hippo.ehviewer.ui.MainActivity; import com.hippo.scene.SceneFragment; -import kotlin.Unit; - public abstract class BaseScene extends SceneFragment { public static final int LENGTH_SHORT = 0; diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/CollapsingToolbarScene.kt b/app/src/main/java/com/hippo/ehviewer/ui/scene/CollapsingToolbarScene.kt index 47252c725..306d746d9 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/CollapsingToolbarScene.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/CollapsingToolbarScene.kt @@ -11,7 +11,8 @@ abstract class CollapsingToolbarScene : ToolbarScene() { inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - val view = inflater.inflate(R.layout.scene_collapsing_toolbar, container, false) as ViewGroup + val view = + inflater.inflate(R.layout.scene_collapsing_toolbar, container, false) as ViewGroup mToolbar = view.findViewById(R.id.toolbar) mAppBarLayout = view.findViewById(R.id.appbar) val contentView = onCreateViewWithToolbar(inflater, view, savedInstanceState) diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/FavoritesScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/FavoritesScene.java index 82d9c06f0..b193d54ed 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/FavoritesScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/FavoritesScene.java @@ -118,21 +118,6 @@ public class FavoritesScene extends BaseScene implements @Nullable @ViewLifeCircle private FabLayout mFabLayout; - private final Runnable showNormalFabsRunnable = new Runnable() { - @Override - public void run() { - if (mFabLayout != null) { - mFabLayout.setSecondaryFabVisibilityAt(0, true); - mFabLayout.setSecondaryFabVisibilityAt(1, true); - mFabLayout.setSecondaryFabVisibilityAt(2, true); - mFabLayout.setSecondaryFabVisibilityAt(3, false); - mFabLayout.setSecondaryFabVisibilityAt(4, false); - mFabLayout.setSecondaryFabVisibilityAt(5, false); - mFabLayout.setSecondaryFabVisibilityAt(6, false); - } - updateJumpFab(); - } - }; @Nullable @ViewLifeCircle private FavoritesAdapter mAdapter; @@ -163,6 +148,21 @@ public class FavoritesScene extends BaseScene implements @Nullable @WholeLifeCircle private FavListUrlBuilder mUrlBuilder; + private final Runnable showNormalFabsRunnable = new Runnable() { + @Override + public void run() { + if (mFabLayout != null) { + mFabLayout.setSecondaryFabVisibilityAt(0, true); + mFabLayout.setSecondaryFabVisibilityAt(1, true); + mFabLayout.setSecondaryFabVisibilityAt(2, true); + mFabLayout.setSecondaryFabVisibilityAt(3, false); + mFabLayout.setSecondaryFabVisibilityAt(4, false); + mFabLayout.setSecondaryFabVisibilityAt(5, false); + mFabLayout.setSecondaryFabVisibilityAt(6, false); + } + updateJumpFab(); + } + }; private int mFavLocalCount = 0; private int mFavCountSum = 0; private boolean mHasFirstRefresh; diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryCommentsScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryCommentsScene.java index 7e958661b..419f2a40c 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryCommentsScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryCommentsScene.java @@ -387,8 +387,7 @@ public final class GalleryCommentsScene extends ToolbarScene } RecyclerView.ViewHolder holder = parent.getChildViewHolder(view); - if (holder instanceof ActualCommentHolder) { - ActualCommentHolder commentHolder = (ActualCommentHolder) holder; + if (holder instanceof ActualCommentHolder commentHolder) { ClickableSpan span = commentHolder.comment.getCurrentSpan(); commentHolder.comment.clearCurrentSpan(); diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.java index 8705aa385..75b9f1303 100755 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.java @@ -41,15 +41,12 @@ import android.util.Pair; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; -import android.view.ViewAnimationUtils; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; -import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.RatingBar; -import android.widget.ScrollView; import android.widget.TextView; import androidx.activity.result.ActivityResultLauncher; @@ -135,6 +132,7 @@ import java.util.List; import okhttp3.HttpUrl; import rikka.core.res.ResourcesKt; + public class GalleryDetailScene extends CollapsingToolbarScene implements View.OnClickListener, com.hippo.ehviewer.download.DownloadManager.DownloadInfoListener, View.OnLongClickListener { @@ -284,6 +282,21 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O return null; } + private static void deleteFileAsync(UniFile... files) { + //noinspection deprecation + new AsyncTask() { + @Override + protected Void doInBackground(UniFile... params) { + for (UniFile file : params) { + if (file != null) { + file.delete(); + } + } + return null; + } + }.executeOnExecutor(IoThreadPoolExecutor.getInstance(), files); + } + @StringRes private int getRatingText(float rating) { int resId; @@ -424,21 +437,6 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O } } - private static void deleteFileAsync(UniFile... files) { - //noinspection deprecation - new AsyncTask() { - @Override - protected Void doInBackground(UniFile... params) { - for (UniFile file : params) { - if (file != null) { - file.delete(); - } - } - return null; - } - }.executeOnExecutor(IoThreadPoolExecutor.getInstance(), files); - } - @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -1294,8 +1292,7 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O } } else { Object o = v.getTag(R.id.tag); - if (o instanceof String) { - String tag = (String) o; + if (o instanceof String tag) { ListUrlBuilder lub = new ListUrlBuilder(); lub.setMode(ListUrlBuilder.MODE_TAG); lub.setKeyword(tag); @@ -2113,7 +2110,8 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O EhApplication.getEhClient(context).execute(request); } } - private class DeleteDialogHelper implements DialogInterface.OnClickListener{ + + private class DeleteDialogHelper implements DialogInterface.OnClickListener { private final com.hippo.ehviewer.download.DownloadManager mDownloadManager; private final GalleryInfo mGalleryInfo; private final CheckBoxDialogBuilder mBuilder; diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java index 4270811cb..117f90718 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java @@ -143,6 +143,8 @@ public final class GalleryListScene extends BaseScene private final static int STATE_SEARCH = 2; private final static int STATE_SEARCH_SHOW_LIST = 3; private static final long ANIMATE_TIME = 300L; + // Double click back exit + private final long mPressBackTime = 0; /*--------------- Whole life cycle ---------------*/ @@ -223,8 +225,6 @@ public final class GalleryListScene extends BaseScene } } }; - // Double click back exit - private final long mPressBackTime = 0; private boolean mHasFirstRefresh = false; private int mNavCheckedId = 0; private DownloadManager mDownloadManager; @@ -1235,7 +1235,7 @@ public final class GalleryListScene extends BaseScene break; } } - ((StageActivity)requireActivity()).updateBackPressCallBackStatus(); + ((StageActivity) requireActivity()).updateBackPressCallBackStatus(); } @Override diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryPreviewsScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryPreviewsScene.java index 173e684e8..937260e14 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryPreviewsScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryPreviewsScene.java @@ -191,7 +191,7 @@ public class GalleryPreviewsScene extends ToolbarScene { super.onViewCreated(view, savedInstanceState); setTitle(R.string.gallery_previews); setNavigationIcon(R.drawable.v_arrow_left_dark_x24); - if (((GalleryDetail)mGalleryInfo).previewPages > 2) + if (((GalleryDetail) mGalleryInfo).previewPages > 2) showMenu(R.menu.scene_gallery_previews); } diff --git a/app/src/main/java/com/hippo/ehviewer/widget/AdvanceSearchTable.kt b/app/src/main/java/com/hippo/ehviewer/widget/AdvanceSearchTable.kt index 4c2da71a1..bd68f69f6 100644 --- a/app/src/main/java/com/hippo/ehviewer/widget/AdvanceSearchTable.kt +++ b/app/src/main/java/com/hippo/ehviewer/widget/AdvanceSearchTable.kt @@ -20,7 +20,12 @@ import android.util.AttributeSet import android.view.KeyEvent import android.view.LayoutInflater import android.view.ViewGroup -import android.widget.* +import android.widget.AutoCompleteTextView +import android.widget.CheckBox +import android.widget.CompoundButton +import android.widget.EditText +import android.widget.LinearLayout +import android.widget.TextView import com.google.android.material.textfield.TextInputLayout import com.hippo.ehviewer.R import com.hippo.yorozuya.NumberUtils diff --git a/app/src/main/java/com/hippo/ehviewer/widget/GalleryInfoContentHelper.kt b/app/src/main/java/com/hippo/ehviewer/widget/GalleryInfoContentHelper.kt index ddc131ae2..abad4a399 100644 --- a/app/src/main/java/com/hippo/ehviewer/widget/GalleryInfoContentHelper.kt +++ b/app/src/main/java/com/hippo/ehviewer/widget/GalleryInfoContentHelper.kt @@ -30,10 +30,12 @@ import java.util.Locale abstract class GalleryInfoContentHelper : ContentHelper() { @JvmField var maxGid = -1 + @JvmField var minGid = -1 + @JvmField - var jumpTo : String? = null + var jumpTo: String? = null private val listener: FavouriteStatusRouter.Listener @SuppressLint("UseSparseArrays") diff --git a/app/src/main/java/com/hippo/ehviewer/widget/SearchBar.java b/app/src/main/java/com/hippo/ehviewer/widget/SearchBar.java index 1dd48bb6e..64561d937 100644 --- a/app/src/main/java/com/hippo/ehviewer/widget/SearchBar.java +++ b/app/src/main/java/com/hippo/ehviewer/widget/SearchBar.java @@ -476,8 +476,7 @@ public class SearchBar extends MaterialCardView implements View.OnClickListener, @Override public void onRestoreInstanceState(Parcelable state) { - if (state instanceof Bundle) { - final Bundle savedState = (Bundle) state; + if (state instanceof final Bundle savedState) { super.onRestoreInstanceState(savedState.getParcelable(STATE_KEY_SUPER)); setState(savedState.getInt(STATE_KEY_STATE), false); } diff --git a/app/src/main/java/com/hippo/ehviewer/widget/SearchDatabase.java b/app/src/main/java/com/hippo/ehviewer/widget/SearchDatabase.java index a1054333e..d06bd05cf 100644 --- a/app/src/main/java/com/hippo/ehviewer/widget/SearchDatabase.java +++ b/app/src/main/java/com/hippo/ehviewer/widget/SearchDatabase.java @@ -113,7 +113,7 @@ public final class SearchDatabase { * * @param maxEntries Max entries to leave in the table. 0 means remove all entries. */ - protected void truncateHistory(int maxEntries) { + private void truncateHistory(int maxEntries) { if (maxEntries < 0) { throw new IllegalArgumentException(); } diff --git a/app/src/main/java/com/hippo/ehviewer/widget/SearchLayout.kt b/app/src/main/java/com/hippo/ehviewer/widget/SearchLayout.kt index 55e44d015..05e0c5acc 100644 --- a/app/src/main/java/com/hippo/ehviewer/widget/SearchLayout.kt +++ b/app/src/main/java/com/hippo/ehviewer/widget/SearchLayout.kt @@ -187,12 +187,15 @@ class SearchLayout @JvmOverloads constructor( R.id.search_subscription_search -> { urlBuilder.mode = ListUrlBuilder.MODE_SUBSCRIPTION } + R.id.search_specify_uploader -> { urlBuilder.mode = ListUrlBuilder.MODE_UPLOADER } + R.id.search_specify_tag -> { urlBuilder.mode = ListUrlBuilder.MODE_TAG } + else -> { urlBuilder.mode = ListUrlBuilder.MODE_NORMAL } @@ -208,6 +211,7 @@ class SearchLayout @JvmOverloads constructor( urlBuilder.pageTo = mTableAdvanceSearch.pageTo } } + SEARCH_MODE_IMAGE -> { urlBuilder.mode = ListUrlBuilder.MODE_IMAGE_SEARCH mImageView.formatListUrlBuilder(urlBuilder) @@ -242,7 +246,7 @@ class SearchLayout @JvmOverloads constructor( override fun onTabReselected(tab: TabLayout.Tab) {} @IntDef(SEARCH_MODE_NORMAL, SEARCH_MODE_IMAGE) - @kotlin.annotation.Retention(AnnotationRetention.SOURCE) + @Retention(AnnotationRetention.SOURCE) private annotation class SearchMode interface Helper { fun onChangeSearchMode() @@ -291,11 +295,13 @@ class SearchLayout @JvmOverloads constructor( ViewUtils.removeFromParent(mNormalView) content.addView(mNormalView) } + ITEM_TYPE_NORMAL_ADVANCE -> { title.setText(R.string.search_advance) ViewUtils.removeFromParent(mAdvanceView) content.addView(mAdvanceView) } + ITEM_TYPE_IMAGE -> { title.setText(R.string.search_image) ViewUtils.removeFromParent(mImageView) diff --git a/app/src/main/java/com/hippo/glgallery/GalleryView.java b/app/src/main/java/com/hippo/glgallery/GalleryView.java index 2c614d1bb..ebb533a61 100644 --- a/app/src/main/java/com/hippo/glgallery/GalleryView.java +++ b/app/src/main/java/com/hippo/glgallery/GalleryView.java @@ -983,15 +983,13 @@ public final class GalleryView extends GLView implements GestureRecognizer.Liste private final Context mContext; private final Adapter mAdapter; + private final int mEdgeColor = Color.WHITE; private Listener mListener; - private int mLayoutMode = LAYOUT_LEFT_TO_RIGHT; private int mScaleMode = SCALE_FIT; private int mStartPosition = START_POSITION_TOP_LEFT; private int mStartPage = 0; - private int mBackgroundColor = Color.BLACK; - private int mEdgeColor = Color.WHITE; private int mPagerInterval = 48; private int mScrollInterval = 24; private int mPageMinHeight = 256; diff --git a/app/src/main/java/com/hippo/glview/glrenderer/GLES11Canvas.java b/app/src/main/java/com/hippo/glview/glrenderer/GLES11Canvas.java index eee4d4b8e..55c9ffcc9 100644 --- a/app/src/main/java/com/hippo/glview/glrenderer/GLES11Canvas.java +++ b/app/src/main/java/com/hippo/glview/glrenderer/GLES11Canvas.java @@ -62,8 +62,8 @@ public class GLES11Canvas implements GLCanvas { private static final int MSKEW_Y = 1; private static final int MSCALE_X = 0; private static final int MSCALE_Y = 5; - private static float[] sCropRect = new float[4]; - private static GLId mGLId = new GLES11IdImpl(); + private static final float[] sCropRect = new float[4]; + private static final GLId mGLId = new GLES11IdImpl(); static { float[] temp = { @@ -87,23 +87,23 @@ public class GLES11Canvas implements GLCanvas { float value = (float) Math.sin(MathUtils.radians(90f / n * i)) / 2; float positive = value + 0.5f; float negative = -value + 0.5f; - BOX_COORDINATES[arrayOffset + n * 0 + i * 2 + 1] = positive; - BOX_COORDINATES[arrayOffset + n * 2 - i * 2 + 0] = positive; - BOX_COORDINATES[arrayOffset + n * 2 + i * 2 + 0] = negative; + BOX_COORDINATES[arrayOffset + i * 2 + 1] = positive; + BOX_COORDINATES[arrayOffset + n * 2 - i * 2] = positive; + BOX_COORDINATES[arrayOffset + n * 2 + i * 2] = negative; BOX_COORDINATES[arrayOffset + n * 4 - i * 2 + 1] = positive; BOX_COORDINATES[arrayOffset + n * 4 + i * 2 + 1] = negative; - BOX_COORDINATES[arrayOffset + n * 6 - i * 2 + 0] = negative; - BOX_COORDINATES[arrayOffset + n * 6 + i * 2 + 0] = positive; + BOX_COORDINATES[arrayOffset + n * 6 - i * 2] = negative; + BOX_COORDINATES[arrayOffset + n * 6 + i * 2] = positive; BOX_COORDINATES[arrayOffset + n * 8 - i * 2 + 1] = negative; } } - private final float mMatrixValues[] = new float[16]; - private final float mTextureMatrixValues[] = new float[16]; + private final float[] mMatrixValues = new float[16]; + private final float[] mTextureMatrixValues = new float[16]; // The results of mapPoints are stored in this buffer, and the order is // x1, y1, x2, y2. - private final float mMapPointsBuffer[] = new float[4]; - private final float mTextureColor[] = new float[4]; + private final float[] mMapPointsBuffer = new float[4]; + private final float[] mTextureColor = new float[4]; private final ArrayList mTargetStack = new ArrayList(); private final ArrayList mRestoreStack = new ArrayList(); private final RectF mDrawTextureSourceRect = new RectF(); @@ -111,21 +111,21 @@ public class GLES11Canvas implements GLCanvas { private final float[] mTempMatrix = new float[32]; private final IntList mUnboundTextures = new IntList(); private final IntList mDeleteBuffers = new IntList(); + private final GL11 mGL; + private final int mBoxCoords; + private final GLState mGLState; + private final boolean mBlendEnabled = true; + private final int[] mFrameBuffer = new int[1]; // Drawing statistics int mCountDrawLine; int mCountFillRect; int mCountDrawMesh; int mCountTextureRect; int mCountTextureOES; - private GL11 mGL; - private int mBoxCoords; - private GLState mGLState; private float mAlpha; private ConfigState mRecycledRestoreAction; private int mScreenWidth; private int mScreenHeight; - private boolean mBlendEnabled = true; - private int mFrameBuffer[] = new int[1]; private RawTexture mTargetTexture; public GLES11Canvas(GL11 gl) { @@ -191,7 +191,7 @@ public class GLES11Canvas implements GLCanvas { } } - private static boolean isMatrixRotatedOrFlipped(float matrix[]) { + private static boolean isMatrixRotatedOrFlipped(float[] matrix) { final float eps = 1e-5f; return Math.abs(matrix[MSKEW_X]) > eps || Math.abs(matrix[MSKEW_Y]) > eps @@ -247,7 +247,7 @@ public class GLES11Canvas implements GLCanvas { gl.glMatrixMode(GL11.GL_MODELVIEW); gl.glLoadIdentity(); - float matrix[] = mMatrixValues; + float[] matrix = mMatrixValues; Matrix.setIdentityM(matrix, 0); // to match the graphic coordinate system in android, we flip it vertically. if (mTargetTexture == null) { @@ -408,7 +408,7 @@ public class GLES11Canvas implements GLCanvas { } @Override - public void multiplyMatrix(float matrix[], int offset) { + public void multiplyMatrix(float[] matrix, int offset) { float[] temp = mTempMatrix; Matrix.multiplyMM(temp, 0, mMatrixValues, 0, matrix, offset); System.arraycopy(temp, 0, mMatrixValues, 0, 16); @@ -467,7 +467,7 @@ public class GLES11Canvas implements GLCanvas { // Transforms two points by the given matrix m. The result // {x1', y1', x2', y2'} are stored in mMapPointsBuffer and also returned. - private float[] mapPoints(float m[], int x1, int y1, int x2, int y2) { + private float[] mapPoints(float[] m, int x1, int y1, int x2, int y2) { float[] r = mMapPointsBuffer; // Multiply m and (x1 y1 0 1) to produce (x3 y3 z3 w3). z3 is unused. @@ -506,7 +506,7 @@ public class GLES11Canvas implements GLCanvas { textureRect(x, y, width, height); } else { // draw the rect from bottom-left to top-right - float points[] = mapPoints( + float[] points = mapPoints( mMatrixValues, x, y + height, x + width, y); x = (int) (points[0] + 0.5f); y = (int) (points[1] + 0.5f); @@ -958,13 +958,12 @@ public class GLES11Canvas implements GLCanvas { private static class GLState { private final GL11 mGL; - + private final boolean mLineSmooth = false; private int mTexEnvMode = GL11.GL_REPLACE; private float mTextureAlpha = 1.0f; private int mTextureTarget = GL11.GL_TEXTURE_2D; private boolean mBlendEnabled = true; private float mLineWidth = 1.0f; - private boolean mLineSmooth = false; public GLState(GL11 gl) { mGL = gl; @@ -1059,7 +1058,7 @@ public class GLES11Canvas implements GLCanvas { private static class ConfigState { float mAlpha; - float mMatrix[] = new float[16]; + float[] mMatrix = new float[16]; ConfigState mNextFree; public void restore(GLES11Canvas canvas) { diff --git a/app/src/main/java/com/hippo/glview/glrenderer/GLES20Canvas.java b/app/src/main/java/com/hippo/glview/glrenderer/GLES20Canvas.java index ead425565..58c801292 100644 --- a/app/src/main/java/com/hippo/glview/glrenderer/GLES20Canvas.java +++ b/app/src/main/java/com/hippo/glview/glrenderer/GLES20Canvas.java @@ -146,13 +146,13 @@ public class GLES20Canvas implements GLCanvas { float value = (float) Math.sin(MathUtils.radians(90f / n * i)) / 2; float positive = value + 0.5f; float negative = -value + 0.5f; - BOX_COORDINATES[arrayOffset + n * 0 + i * 2 + 1] = positive; - BOX_COORDINATES[arrayOffset + n * 2 - i * 2 + 0] = positive; - BOX_COORDINATES[arrayOffset + n * 2 + i * 2 + 0] = negative; + BOX_COORDINATES[arrayOffset + i * 2 + 1] = positive; + BOX_COORDINATES[arrayOffset + n * 2 - i * 2] = positive; + BOX_COORDINATES[arrayOffset + n * 2 + i * 2] = negative; BOX_COORDINATES[arrayOffset + n * 4 - i * 2 + 1] = positive; BOX_COORDINATES[arrayOffset + n * 4 + i * 2 + 1] = negative; - BOX_COORDINATES[arrayOffset + n * 6 - i * 2 + 0] = negative; - BOX_COORDINATES[arrayOffset + n * 6 + i * 2 + 0] = positive; + BOX_COORDINATES[arrayOffset + n * 6 - i * 2] = negative; + BOX_COORDINATES[arrayOffset + n * 6 + i * 2] = positive; BOX_COORDINATES[arrayOffset + n * 8 - i * 2 + 1] = negative; } } @@ -433,7 +433,7 @@ public class GLES20Canvas implements GLCanvas { public void translate(float x, float y) { int index = mCurrentMatrixIndex; float[] m = mMatrices; - m[index + 12] += m[index + 0] * x + m[index + 4] * y; + m[index + 12] += m[index] * x + m[index + 4] * y; m[index + 13] += m[index + 1] * x + m[index + 5] * y; m[index + 14] += m[index + 2] * x + m[index + 6] * y; m[index + 15] += m[index + 3] * x + m[index + 7] * y; diff --git a/app/src/main/java/com/hippo/glview/glrenderer/MovableTextTexture.java b/app/src/main/java/com/hippo/glview/glrenderer/MovableTextTexture.java index f4cfcd6bb..c6ac505fa 100644 --- a/app/src/main/java/com/hippo/glview/glrenderer/MovableTextTexture.java +++ b/app/src/main/java/com/hippo/glview/glrenderer/MovableTextTexture.java @@ -96,7 +96,7 @@ public final class MovableTextTexture extends SpriteTexture { int y = 0; for (int i = 0; i < length; i++) { int offset = i * 4; - rects[offset + 0] = x; + rects[offset] = x; rects[offset + 1] = y; rects[offset + 2] = (int) widths[i]; rects[offset + 3] = height; diff --git a/app/src/main/java/com/hippo/glview/glrenderer/NinePatchChunk.java b/app/src/main/java/com/hippo/glview/glrenderer/NinePatchChunk.java index fb6bf3f64..dd1ad6c8c 100644 --- a/app/src/main/java/com/hippo/glview/glrenderer/NinePatchChunk.java +++ b/app/src/main/java/com/hippo/glview/glrenderer/NinePatchChunk.java @@ -30,9 +30,9 @@ class NinePatchChunk { public Rect mPaddings = new Rect(); - public int mDivX[]; - public int mDivY[]; - public int mColor[]; + public int[] mDivX; + public int[] mDivY; + public int[] mColor; private static void readIntArray(int[] data, ByteBuffer buffer) { for (int i = 0, n = data.length; i < n; ++i) { diff --git a/app/src/main/java/com/hippo/glview/glrenderer/NinePatchTexture.java b/app/src/main/java/com/hippo/glview/glrenderer/NinePatchTexture.java index ecb43017a..4d055f15f 100644 --- a/app/src/main/java/com/hippo/glview/glrenderer/NinePatchTexture.java +++ b/app/src/main/java/com/hippo/glview/glrenderer/NinePatchTexture.java @@ -35,9 +35,9 @@ import java.nio.FloatBuffer; public class NinePatchTexture extends ResourceTexture { @SuppressWarnings("unused") private static final String TAG = "NinePatchTexture"; - private NinePatchChunk mChunk; - private SmallCache mInstanceCache + private final SmallCache mInstanceCache = new SmallCache(); + private NinePatchChunk mChunk; public NinePatchTexture(Context context, int resId) { super(context, resId); @@ -120,8 +120,8 @@ public class NinePatchTexture extends ResourceTexture { private static class SmallCache { private static final int CACHE_SIZE = 16; private static final int CACHE_SIZE_START_MOVE = CACHE_SIZE / 2; - private int[] mKey = new int[CACHE_SIZE]; - private V[] mValue = (V[]) new Object[CACHE_SIZE]; + private final int[] mKey = new int[CACHE_SIZE]; + private final V[] mValue = (V[]) new Object[CACHE_SIZE]; private int mCount; // number of items in this cache // Puts a value into the cache. If the cache is full, also returns @@ -217,10 +217,10 @@ class NinePatchInstance { throw new RuntimeException("unsupported nine patch"); } - float divX[] = new float[4]; - float divY[] = new float[4]; - float divU[] = new float[4]; - float divV[] = new float[4]; + float[] divX = new float[4]; + float[] divY = new float[4]; + float[] divU = new float[4]; + float[] divV = new float[4]; int nx = stretch(divX, divU, chunk.mDivX, tex.getWidth(), width); int ny = stretch(divY, divV, chunk.mDivY, tex.getHeight(), height); @@ -261,7 +261,7 @@ class NinePatchInstance { * @return the number of these dividers. */ private static int stretch( - float x[], float u[], int div[], int source, int target) { + float[] x, float[] u, int[] div, int source, int target) { int textureSize = MathUtils.nextPowerOf2(source); float textureBound = (float) source / textureSize; @@ -313,7 +313,7 @@ class NinePatchInstance { return ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder()); } - private void prepareVertexData(float x[], float y[], float u[], float v[], + private void prepareVertexData(float[] x, float[] y, float[] u, float[] v, int nx, int ny, int[] color) { /* * Given a 3x3 nine-patch image, the vertex order is defined as the @@ -335,8 +335,8 @@ class NinePatchInstance { * index: 04152637B6A5948C9DAEBF */ int pntCount = 0; - float xy[] = new float[VERTEX_BUFFER_SIZE]; - float uv[] = new float[VERTEX_BUFFER_SIZE]; + float[] xy = new float[VERTEX_BUFFER_SIZE]; + float[] uv = new float[VERTEX_BUFFER_SIZE]; for (int j = 0; j < ny; ++j) { for (int i = 0; i < nx; ++i) { int xIndex = (pntCount++) << 1; @@ -350,7 +350,7 @@ class NinePatchInstance { int idxCount = 1; boolean isForward = false; - byte index[] = new byte[INDEX_BUFFER_SIZE]; + byte[] index = new byte[INDEX_BUFFER_SIZE]; for (int row = 0; row < ny - 1; row++) { --idxCount; isForward = !isForward; diff --git a/app/src/main/java/com/hippo/glview/glrenderer/UploadedTexture.java b/app/src/main/java/com/hippo/glview/glrenderer/UploadedTexture.java index cf9b2eef8..a1e791475 100644 --- a/app/src/main/java/com/hippo/glview/glrenderer/UploadedTexture.java +++ b/app/src/main/java/com/hippo/glview/glrenderer/UploadedTexture.java @@ -279,8 +279,7 @@ public abstract class UploadedTexture extends BasicTexture { @Override public boolean equals(Object object) { - if (!(object instanceof BorderKey)) return false; - BorderKey o = (BorderKey) object; + if (!(object instanceof BorderKey o)) return false; return vertical == o.vertical && config == o.config && length == o.length; } diff --git a/app/src/main/java/com/hippo/glview/image/ImageMovableTextTexture.java b/app/src/main/java/com/hippo/glview/image/ImageMovableTextTexture.java index b48e6a940..54740d39c 100644 --- a/app/src/main/java/com/hippo/glview/image/ImageMovableTextTexture.java +++ b/app/src/main/java/com/hippo/glview/image/ImageMovableTextTexture.java @@ -95,7 +95,7 @@ public class ImageMovableTextTexture extends ImageSpriteTexture { int y = 0; for (int i = 0; i < length; i++) { int offset = i * 4; - rects[offset + 0] = x; + rects[offset] = x; rects[offset + 1] = y; rects[offset + 2] = (int) widths[i]; rects[offset + 3] = height; diff --git a/app/src/main/java/com/hippo/glview/widget/GLProgressView.java b/app/src/main/java/com/hippo/glview/widget/GLProgressView.java index 175cb6316..bffb8b639 100644 --- a/app/src/main/java/com/hippo/glview/widget/GLProgressView.java +++ b/app/src/main/java/com/hippo/glview/widget/GLProgressView.java @@ -54,21 +54,17 @@ public class GLProgressView extends GLView { } private final GLPaint mGLPaint; - + private final List mAnimations; private float mCx; private float mCy; private float mRadiusX; private float mRadiusY; - private float mTrimStart = 0.0f; private float mTrimEnd = 0.0f; private float mTrimOffset = 0.0f; private float mTrimRotation = 0.0f; - private boolean mIndeterminate = false; - private List mAnimations; - public GLProgressView() { mGLPaint = new GLPaint(); mGLPaint.setColor(Color.WHITE); diff --git a/app/src/main/java/com/hippo/image/Image.kt b/app/src/main/java/com/hippo/image/Image.kt index f47d99ff1..d0dcda288 100644 --- a/app/src/main/java/com/hippo/image/Image.kt +++ b/app/src/main/java/com/hippo/image/Image.kt @@ -32,18 +32,20 @@ import androidx.core.graphics.drawable.toDrawable import java.io.FileInputStream import java.nio.channels.FileChannel -class Image private constructor(source: Source?, drawable: Drawable? = null, - val hardware: Boolean = true +class Image private constructor( + source: Source?, drawable: Drawable? = null, + val hardware: Boolean = true ) { internal var mObtainedDrawable: Drawable? private var mBitmap: Bitmap? = null + init { mObtainedDrawable = null source?.let { mObtainedDrawable = ImageDecoder.decodeDrawable(source) { decoder: ImageDecoder, _, _ -> decoder.allocator = if (hardware) ALLOCATOR_DEFAULT else ALLOCATOR_SOFTWARE - // Sadly we must use software memory since we need copy it to tile buffer, fuck glgallery - // Idk it will cause how much performance regression + // Sadly we must use software memory since we need copy it to tile buffer, fuck glgallery + // Idk it will cause how much performance regression } // Should we lazy decode it? } if (mObtainedDrawable == null) { diff --git a/app/src/main/java/com/hippo/scene/StageActivity.java b/app/src/main/java/com/hippo/scene/StageActivity.java index b68900d40..029b73367 100644 --- a/app/src/main/java/com/hippo/scene/StageActivity.java +++ b/app/src/main/java/com/hippo/scene/StageActivity.java @@ -589,31 +589,6 @@ public abstract class StageActivity extends EhActivity { callback.setEnabled(shouldEnable); } - class BackPressCallBack extends OnBackPressedCallback { - public BackPressCallBack(boolean enabled) { - super(enabled); - } - - @Override - public void handleOnBackPressed() { - int size = mSceneTagList.size(); - String tag = mSceneTagList.get(size - 1); - SceneFragment scene; - Fragment fragment = getSupportFragmentManager().findFragmentByTag(tag); - if (fragment == null) { - Log.e(TAG, "onBackPressed: Can't find scene by tag: " + tag); - return; - } - if (!(fragment instanceof SceneFragment)) { - Log.e(TAG, "onBackPressed: The fragment is not SceneFragment"); - return; - } - - scene = (SceneFragment) fragment; - scene.onBackPressed(); - } - } - @Override public void onProvideAssistContent(AssistContent outContent) { super.onProvideAssistContent(outContent); @@ -656,6 +631,31 @@ public abstract class StageActivity extends EhActivity { return fragment.getClass(); } + class BackPressCallBack extends OnBackPressedCallback { + public BackPressCallBack(boolean enabled) { + super(enabled); + } + + @Override + public void handleOnBackPressed() { + int size = mSceneTagList.size(); + String tag = mSceneTagList.get(size - 1); + SceneFragment scene; + Fragment fragment = getSupportFragmentManager().findFragmentByTag(tag); + if (fragment == null) { + Log.e(TAG, "onBackPressed: Can't find scene by tag: " + tag); + return; + } + if (!(fragment instanceof SceneFragment)) { + Log.e(TAG, "onBackPressed: The fragment is not SceneFragment"); + return; + } + + scene = (SceneFragment) fragment; + scene.onBackPressed(); + } + } + private final class SceneViewComparator implements Comparator { private int getIndex(View view) { diff --git a/app/src/main/java/com/hippo/unifile/DocumentsContractApi19.java b/app/src/main/java/com/hippo/unifile/DocumentsContractApi19.java index a0c2bcd7f..4a2747fbf 100644 --- a/app/src/main/java/com/hippo/unifile/DocumentsContractApi19.java +++ b/app/src/main/java/com/hippo/unifile/DocumentsContractApi19.java @@ -104,17 +104,13 @@ final class DocumentsContractApi19 { return true; } + // Writable normal files considered writable if (DocumentsContract.Document.MIME_TYPE_DIR.equals(type) && (flags & DocumentsContract.Document.FLAG_DIR_SUPPORTS_CREATE) != 0) { // Directories that allow create considered writable return true; - } else if (!TextUtils.isEmpty(type) - && (flags & DocumentsContract.Document.FLAG_SUPPORTS_WRITE) != 0) { - // Writable normal files considered writable - return true; - } - - return false; + } else return !TextUtils.isEmpty(type) + && (flags & DocumentsContract.Document.FLAG_SUPPORTS_WRITE) != 0; } public static boolean delete(Context context, Uri self) { diff --git a/app/src/main/java/com/hippo/unifile/RawRandomAccessFile.java b/app/src/main/java/com/hippo/unifile/RawRandomAccessFile.java index 52bb14eb2..e9114fa43 100644 --- a/app/src/main/java/com/hippo/unifile/RawRandomAccessFile.java +++ b/app/src/main/java/com/hippo/unifile/RawRandomAccessFile.java @@ -25,7 +25,7 @@ import java.io.RandomAccessFile; class RawRandomAccessFile implements UniRandomAccessFile { - private RandomAccessFile mFile; + private final RandomAccessFile mFile; RawRandomAccessFile(RandomAccessFile file) { mFile = file; diff --git a/app/src/main/java/com/hippo/unifile/UriOutputStream.java b/app/src/main/java/com/hippo/unifile/UriOutputStream.java index 4c9a3978a..0a04052d3 100644 --- a/app/src/main/java/com/hippo/unifile/UriOutputStream.java +++ b/app/src/main/java/com/hippo/unifile/UriOutputStream.java @@ -38,7 +38,7 @@ import java.io.OutputStream; // TODO need more test class UriOutputStream extends FileOutputStream { - private ParcelFileDescriptor mPfd; + private final ParcelFileDescriptor mPfd; private UriOutputStream(ParcelFileDescriptor pfd, FileDescriptor fd) { super(fd); diff --git a/app/src/main/java/com/hippo/util/BitmapUtils.java b/app/src/main/java/com/hippo/util/BitmapUtils.java index ca04a3f9e..5992e85ef 100644 --- a/app/src/main/java/com/hippo/util/BitmapUtils.java +++ b/app/src/main/java/com/hippo/util/BitmapUtils.java @@ -42,7 +42,7 @@ public final class BitmapUtils { final Runtime runtime = Runtime.getRuntime(); final long used = runtime.totalMemory() - runtime.freeMemory(); - final long total = activityManager.getMemoryClass() * 1024 * 1024; + final long total = (long) activityManager.getMemoryClass() * 1024 * 1024; return total - used; } @@ -87,7 +87,7 @@ public final class BitmapUtils { } return null; } - if (width * height * 3 > m) { + if ((long) width * height * 3 > m) { scaleM = (int) Math.ceil(Math.sqrt(width * height * 3 / (float) m)); } } diff --git a/app/src/main/java/com/hippo/util/ExceptionUtils.java b/app/src/main/java/com/hippo/util/ExceptionUtils.java index e0b9a67ca..f629ab215 100644 --- a/app/src/main/java/com/hippo/util/ExceptionUtils.java +++ b/app/src/main/java/com/hippo/util/ExceptionUtils.java @@ -42,8 +42,7 @@ public final class ExceptionUtils { return GetText.getString(R.string.error_timeout); } else if (e instanceof UnknownHostException) { return GetText.getString(R.string.error_unknown_host); - } else if (e instanceof StatusCodeException) { - StatusCodeException sce = (StatusCodeException) e; + } else if (e instanceof StatusCodeException sce) { StringBuilder sb = new StringBuilder(); sb.append(GetText.getString(R.string.error_bad_status_code, sce.getResponseCode())); if (sce.isIdentifiedResponseCode()) { diff --git a/app/src/main/java/com/hippo/widget/BatteryView.java b/app/src/main/java/com/hippo/widget/BatteryView.java index bd06395a3..b5b5ada84 100644 --- a/app/src/main/java/com/hippo/widget/BatteryView.java +++ b/app/src/main/java/com/hippo/widget/BatteryView.java @@ -89,20 +89,7 @@ public class BatteryView extends AppCompatTextView { getHandler().post(mCharger); mIsChargerWorking = true; } - } private final Runnable mCharger = new Runnable() { - - private int level = 0; - - @Override - public void run() { - level += 2; - if (level > 100) { - level = 0; - } - mDrawable.setElect(level, false); - getHandler().postDelayed(mCharger, 200); - } - }; + } private void stopCharger() { if (mIsChargerWorking) { @@ -120,7 +107,20 @@ public class BatteryView extends AppCompatTextView { registerReceiver(); } - } + } private final Runnable mCharger = new Runnable() { + + private int level = 0; + + @Override + public void run() { + level += 2; + if (level > 100) { + level = 0; + } + mDrawable.setElect(level, false); + getHandler().postDelayed(mCharger, 200); + } + }; @Override protected void onDetachedFromWindow() { diff --git a/app/src/main/java/com/hippo/widget/ContentLayout.java b/app/src/main/java/com/hippo/widget/ContentLayout.java index 6d12537e0..c5584976a 100644 --- a/app/src/main/java/com/hippo/widget/ContentLayout.java +++ b/app/src/main/java/com/hippo/widget/ContentLayout.java @@ -18,7 +18,6 @@ package com.hippo.widget; import android.app.Activity; import android.content.Context; -import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.Parcelable; @@ -915,8 +914,7 @@ public class ContentLayout extends FrameLayout { } protected Parcelable restoreInstanceState(Parcelable state) { - if (state instanceof Bundle) { - Bundle bundle = (Bundle) state; + if (state instanceof Bundle bundle) { mViewTransition.showView(bundle.getInt(KEY_SHOWN_VIEW), false); mTipView.setText(bundle.getString(KEY_TIP)); diff --git a/app/src/main/java/com/hippo/widget/FabLayout.java b/app/src/main/java/com/hippo/widget/FabLayout.java index 0acd34f21..045b9a69b 100644 --- a/app/src/main/java/com/hippo/widget/FabLayout.java +++ b/app/src/main/java/com/hippo/widget/FabLayout.java @@ -299,7 +299,7 @@ public class FabLayout extends ViewGroup implements View.OnClickListener { mOnExpandListener.onExpand(expanded); } } - ((StageActivity)getContext()).updateBackPressCallBackStatus(); + ((StageActivity) getContext()).updateBackPressCallBackStatus(); } @@ -427,8 +427,7 @@ public class FabLayout extends ViewGroup implements View.OnClickListener { @Override public void onRestoreInstanceState(Parcelable state) { - if (state instanceof Bundle) { - final Bundle savedState = (Bundle) state; + if (state instanceof final Bundle savedState) { super.onRestoreInstanceState(savedState.getParcelable(STATE_KEY_SUPER)); setAutoCancel(savedState.getBoolean(STATE_KEY_AUTO_CANCEL)); setExpanded(savedState.getBoolean(STATE_KEY_EXPANDED), false); diff --git a/app/src/main/java/com/hippo/widget/RadioGridGroup.java b/app/src/main/java/com/hippo/widget/RadioGridGroup.java index 7a9c52057..3c25fd036 100644 --- a/app/src/main/java/com/hippo/widget/RadioGridGroup.java +++ b/app/src/main/java/com/hippo/widget/RadioGridGroup.java @@ -94,8 +94,7 @@ public class RadioGridGroup extends SimpleGridLayout { @Override public void addView(View child, int index, ViewGroup.LayoutParams params) { - if (child instanceof RadioButton) { - final RadioButton button = (RadioButton) child; + if (child instanceof final RadioButton button) { if (button.isChecked()) { mProtectFromCheckedChange = true; if (mCheckedId != -1) { diff --git a/app/src/main/java/com/hippo/widget/TextClock.java b/app/src/main/java/com/hippo/widget/TextClock.java index 02c152b58..c6b3ec9cc 100644 --- a/app/src/main/java/com/hippo/widget/TextClock.java +++ b/app/src/main/java/com/hippo/widget/TextClock.java @@ -101,6 +101,17 @@ public class TextClock extends AppCompatTextView { public CharSequence getFormat12Hour() { return mFormat12; + } + + public void setFormat12Hour(CharSequence format) { + mFormat12 = format; + + chooseFormat(); + onTimeChanged(); + } + + public CharSequence getFormat24Hour() { + return mFormat24; } private final Runnable mTicker = new Runnable() { @Override public void run() { @@ -113,17 +124,6 @@ public class TextClock extends AppCompatTextView { } }; - public void setFormat12Hour(CharSequence format) { - mFormat12 = format; - - chooseFormat(); - onTimeChanged(); - } - - public CharSequence getFormat24Hour() { - return mFormat24; - } - public void setFormat24Hour(CharSequence format) { mFormat24 = format; @@ -158,19 +158,7 @@ public class TextClock extends AppCompatTextView { public CharSequence getFormat() { return mFormat; - } private final ContentObserver mFormatChangeObserver = new ContentObserver(new Handler()) { - @Override - public void onChange(boolean selfChange) { - chooseFormat(); - onTimeChanged(); - } - - @Override - public void onChange(boolean selfChange, Uri uri) { - chooseFormat(); - onTimeChanged(); - } - }; + } /** * Selects either one of {@link #getFormat12Hour()} or {@link #getFormat24Hour()} @@ -239,7 +227,19 @@ public class TextClock extends AppCompatTextView { filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); getContext().registerReceiver(mIntentReceiver, filter, null, getHandler()); - } + } private final ContentObserver mFormatChangeObserver = new ContentObserver(new Handler()) { + @Override + public void onChange(boolean selfChange) { + chooseFormat(); + onTimeChanged(); + } + + @Override + public void onChange(boolean selfChange, Uri uri) { + chooseFormat(); + onTimeChanged(); + } + }; private void registerObserver() { final ContentResolver resolver = getContext().getContentResolver(); diff --git a/app/src/main/java/com/hippo/yorozuya/FileUtils.java b/app/src/main/java/com/hippo/yorozuya/FileUtils.java index 4b1cc0bec..7dc16feb6 100644 --- a/app/src/main/java/com/hippo/yorozuya/FileUtils.java +++ b/app/src/main/java/com/hippo/yorozuya/FileUtils.java @@ -27,6 +27,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.nio.charset.StandardCharsets; import java.util.Locale; public final class FileUtils { @@ -154,7 +155,7 @@ public final class FileUtils { OutputStream os = null; try { os = new FileOutputStream(file); - os.write(str.getBytes("utf-8")); + os.write(str.getBytes(StandardCharsets.UTF_8)); return true; } catch (IOException e) { e.printStackTrace(); diff --git a/app/src/main/java/com/hippo/yorozuya/ObjectUtils.java b/app/src/main/java/com/hippo/yorozuya/ObjectUtils.java index 904ddb54e..3cf5eb030 100644 --- a/app/src/main/java/com/hippo/yorozuya/ObjectUtils.java +++ b/app/src/main/java/com/hippo/yorozuya/ObjectUtils.java @@ -23,6 +23,7 @@ import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; public final class ObjectUtils { @@ -33,7 +34,7 @@ public final class ObjectUtils { * Returns true if two possibly-null objects are equal. */ public static boolean equal(@Nullable Object a, @Nullable Object b) { - return a == b || (a != null && a.equals(b)); + return Objects.equals(a, b); } /** @@ -109,48 +110,39 @@ public final class ObjectUtils { writer.write('['); writer.write('\n'); - if (array instanceof Object[]) { - Object[] a = (Object[]) array; + if (array instanceof Object[] a) { for (int i = 0, l = a.length; i < l; i++) { dump(a[i], writer, newPrefix, false); } - } else if (array instanceof boolean[]) { - boolean[] a = (boolean[]) array; + } else if (array instanceof boolean[] a) { for (int i = 0, l = a.length; i < l; i++) { dumpBoolean(a[i], writer, newPrefix); } - } else if (array instanceof byte[]) { - byte[] a = (byte[]) array; + } else if (array instanceof byte[] a) { for (int i = 0, l = a.length; i < l; i++) { dumpByte(a[i], writer, newPrefix); } - } else if (array instanceof char[]) { - char[] a = (char[]) array; + } else if (array instanceof char[] a) { for (int i = 0, l = a.length; i < l; i++) { dumpChar(a[i], writer, newPrefix); } - } else if (array instanceof short[]) { - short[] a = (short[]) array; + } else if (array instanceof short[] a) { for (int i = 0, l = a.length; i < l; i++) { dumpShort(a[i], writer, newPrefix); } - } else if (array instanceof int[]) { - int[] a = (int[]) array; + } else if (array instanceof int[] a) { for (int i = 0, l = a.length; i < l; i++) { dumpInt(a[i], writer, newPrefix); } - } else if (array instanceof long[]) { - long[] a = (long[]) array; + } else if (array instanceof long[] a) { for (int i = 0, l = a.length; i < l; i++) { dumpLong(a[i], writer, newPrefix); } - } else if (array instanceof float[]) { - float[] a = (float[]) array; + } else if (array instanceof float[] a) { for (int i = 0, l = a.length; i < l; i++) { dumpFloat(a[i], writer, newPrefix); } - } else if (array instanceof double[]) { - double[] a = (double[]) array; + } else if (array instanceof double[] a) { for (int i = 0, l = a.length; i < l; i++) { dumpDouble(a[i], writer, newPrefix); } @@ -162,8 +154,7 @@ public final class ObjectUtils { for (Object o : (Set) array) { dump(o, writer, newPrefix); } - } else if (array instanceof Map) { - Map map = (Map) array; + } else if (array instanceof Map map) { for (Object key : map.keySet()) { Object value = map.get(key); writer.write(newPrefix); diff --git a/app/src/main/java/com/hippo/yorozuya/ViewUtils.java b/app/src/main/java/com/hippo/yorozuya/ViewUtils.java index 2106e96d4..ff9a72a54 100644 --- a/app/src/main/java/com/hippo/yorozuya/ViewUtils.java +++ b/app/src/main/java/com/hippo/yorozuya/ViewUtils.java @@ -202,8 +202,7 @@ public final class ViewUtils { return view; } - if (view instanceof ViewGroup) { - ViewGroup viewGroup = (ViewGroup) view; + if (view instanceof ViewGroup viewGroup) { for (int i = 0, n = viewGroup.getChildCount(); i < n; i++) { View child = viewGroup.getChildAt(i); View result = getChild(child, id); @@ -379,8 +378,7 @@ public final class ViewUtils { */ public static int getIndexInParent(View view) { ViewParent parent = view.getParent(); - if (parent instanceof ViewGroup) { - ViewGroup viewParent = (ViewGroup) parent; + if (parent instanceof ViewGroup viewParent) { int count = viewParent.getChildCount(); for (int i = 0; i < count; i++) { View v = viewParent.getChildAt(i); @@ -405,8 +403,7 @@ public final class ViewUtils { } public static void setEnabledRecursively(View view, boolean enabled) { - if (view instanceof ViewGroup) { - ViewGroup viewGroup = (ViewGroup) view; + if (view instanceof ViewGroup viewGroup) { for (int i = 0, n = viewGroup.getChildCount(); i < n; i++) { setEnabledRecursively(viewGroup.getChildAt(i), enabled); } @@ -422,9 +419,8 @@ public final class ViewUtils { writer.write(prefix); writer.write(view.getClass().getName()); writer.write('\n'); - if (view instanceof ViewGroup) { + if (view instanceof ViewGroup viewGroup) { String newPrefix = prefix + " "; - ViewGroup viewGroup = (ViewGroup) view; for (int i = 0, count = viewGroup.getChildCount(); i < count; i++) { View child = viewGroup.getChildAt(i); dumpViewHierarchy(child, writer, newPrefix); diff --git a/app/src/main/java/com/hippo/yorozuya/thread/PriorityThread.java b/app/src/main/java/com/hippo/yorozuya/thread/PriorityThread.java index afdbc7752..e10452c6e 100644 --- a/app/src/main/java/com/hippo/yorozuya/thread/PriorityThread.java +++ b/app/src/main/java/com/hippo/yorozuya/thread/PriorityThread.java @@ -20,7 +20,7 @@ import android.os.Process; public class PriorityThread extends Thread { - private int mPriority; + private final int mPriority; public PriorityThread(Runnable runnable, int priority) { super(runnable); diff --git a/app/src/main/java/com/hippo/yorozuya/thread/SerialThreadExecutor.java b/app/src/main/java/com/hippo/yorozuya/thread/SerialThreadExecutor.java index 177b8b7c7..94a35563e 100644 --- a/app/src/main/java/com/hippo/yorozuya/thread/SerialThreadExecutor.java +++ b/app/src/main/java/com/hippo/yorozuya/thread/SerialThreadExecutor.java @@ -28,9 +28,9 @@ public class SerialThreadExecutor implements Executor, Runnable { private final Lock mThreadLock = new ReentrantLock(); private final Object mWaitLock = new Object(); - private long mKeepAliveMillis; - private Queue mWorkQueue; - private ThreadFactory mThreadFactory; + private final long mKeepAliveMillis; + private final Queue mWorkQueue; + private final ThreadFactory mThreadFactory; // The worker private Thread mThread;