From 191db14398d7069bbfd65330bd2cbd27d4650701 Mon Sep 17 00:00:00 2001 From: tarsin Date: Mon, 18 Jul 2022 20:47:04 +0800 Subject: [PATCH] app: Do code cleanup --- app/src/main/AndroidManifest.xml | 12 +- .../com/hippo/beerbelly/DiskLruCache.java | 23 +- .../com/hippo/ehviewer/EhApplication.java | 14 +- .../ehviewer/preference/ProxyPreference.kt | 21 +- .../hippo/ehviewer/ui/GalleryActivity.java | 22 +- .../ui/fragment/AdvancedFragment.java | 1 - .../ui/fragment/BasePreferenceFragment.java | 2 +- .../ehviewer/ui/fragment/FilterFragment.kt | 2 - .../ehviewer/ui/fragment/HostsFragment.java | 3 - .../ui/fragment/SettingsFragment.java | 3 - .../ui/scene/GalleryCommentsScene.java | 2 - .../ehviewer/ui/scene/GalleryInfoScene.java | 3 - .../ehviewer/widget/GalleryGuideView.java | 2 - .../com/hippo/ehviewer/widget/SearchBar.java | 3 - .../java/com/hippo/unifile/Contracts.java | 13 +- .../hippo/unifile/DocumentsContractApi19.java | 9 +- .../hippo/unifile/DocumentsContractApi21.java | 12 +- .../FileDescriptorRandomAccessFile.java | 360 +++++++++--------- .../com/hippo/unifile/FilenameFilter.java | 12 +- .../java/com/hippo/unifile/MediaContract.java | 3 +- .../java/com/hippo/unifile/MediaFile.java | 9 +- .../main/java/com/hippo/unifile/RawFile.java | 60 +-- .../com/hippo/unifile/SingleDocumentFile.java | 1 - .../main/java/com/hippo/unifile/UniFile.java | 26 +- .../hippo/unifile/UniRandomAccessFile.java | 12 +- .../com/hippo/unifile/UriOutputStream.java | 12 +- .../java/com/hippo/widget/BatteryView.java | 22 +- .../main/java/com/hippo/widget/TextClock.java | 38 +- .../yorozuya/collect/AbstractMultimap.java | 10 +- .../yorozuya/collect/CollectionUtils.java | 13 +- .../yorozuya/collect/ContainerHelpers.java | 2 +- .../com/hippo/yorozuya/collect/IntList.java | 46 ++- .../com/hippo/yorozuya/collect/LongList.java | 46 ++- .../com/hippo/yorozuya/collect/Multimap.java | 8 +- .../hippo/yorozuya/collect/MultimapSet.java | 8 +- .../hippo/yorozuya/collect/SparseIJArray.java | 2 +- .../hippo/yorozuya/collect/SparseILArray.java | 4 +- .../hippo/yorozuya/collect/SparseJBArray.java | 10 +- .../hippo/yorozuya/collect/SparseJLArray.java | 4 +- .../res/drawable-v26/ic_shortcut_start.xml | 3 +- .../res/drawable-v26/ic_shortcut_stop.xml | 3 +- .../res/drawable/file_upload_black_24dp.xml | 6 +- .../ic_baseline_format_list_numbered_24.xml | 3 +- .../res/drawable/ic_baseline_label_24.xml | 3 +- .../main/res/drawable/ic_baseline_menu_24.xml | 3 +- .../res/drawable/ic_baseline_reorder_24.xml | 3 +- .../res/drawable/ic_baseline_warning_24.xml | 3 +- .../res/drawable/ic_launcher_foreground.xml | 3 +- app/src/main/res/drawable/ic_pause_108dp.xml | 3 +- .../main/res/drawable/ic_play_arrow_108dp.xml | 3 +- .../drawable/navigation_item_foreground.xml | 3 +- app/src/main/res/drawable/round_side_rect.xml | 3 +- .../main/res/drawable/v_filter_dark_x24.xml | 3 +- .../main/res/drawable/v_sec_primary_x24.xml | 3 +- .../scene_cookie_sign_in.xml | 14 +- .../main/res/layout/activity_preference.xml | 3 +- app/src/main/res/layout/item_drawer_list.xml | 3 +- .../main/res/layout/item_gallery_comment.xml | 3 +- .../res/layout/preference_recyclerview.xml | 3 +- .../res/layout/scene_gallery_comments.xml | 2 +- .../main/res/menu/download_label_option.xml | 3 +- app/src/main/res/menu/drawer_gallery_list.xml | 4 +- app/src/main/res/menu/quicksearch_option.xml | 3 +- .../res/mipmap-anydpi-v26/ic_launcher.xml | 3 +- .../mipmap-anydpi-v26/ic_launcher_round.xml | 3 +- app/src/main/res/values/attrs.xml | 4 +- app/src/main/res/values/color_launcher.xml | 3 +- app/src/main/res/values/styles.xml | 2 +- app/src/main/res/xml-v25/shortcuts.xml | 3 +- .../main/res/xml/network_security_config.xml | 3 +- app/src/main/res/xml/privacy_settings.xml | 3 +- app/src/main/res/xml/settings_headers.xml | 12 +- 72 files changed, 471 insertions(+), 506 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 75a423b4a..ece3e403c 100755 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -15,8 +15,14 @@ --> - - + + + + @@ -44,10 +50,10 @@ diff --git a/app/src/main/java/com/hippo/beerbelly/DiskLruCache.java b/app/src/main/java/com/hippo/beerbelly/DiskLruCache.java index 4d8630963..8d1baec07 100644 --- a/app/src/main/java/com/hippo/beerbelly/DiskLruCache.java +++ b/app/src/main/java/com/hippo/beerbelly/DiskLruCache.java @@ -166,7 +166,16 @@ public final class DiskLruCache implements Closeable { * a sequence number each time an edit is committed. A snapshot is stale if * its sequence number is not equal to its entry's sequence number. */ - private long nextSequenceNumber = 0; private final Callable cleanupCallable = new Callable<>() { + private long nextSequenceNumber = 0; + private DiskLruCache(File directory, int appVersion, int valueCount, long maxSize) { + this.directory = directory; + this.appVersion = appVersion; + this.journalFile = new File(directory, JOURNAL_FILE); + this.journalFileTmp = new File(directory, JOURNAL_FILE_TEMP); + this.journalFileBackup = new File(directory, JOURNAL_FILE_BACKUP); + this.valueCount = valueCount; + this.maxSize = maxSize; + } private final Callable cleanupCallable = new Callable<>() { public Void call() throws Exception { synchronized (DiskLruCache.this) { if (journalWriter == null) { @@ -182,16 +191,6 @@ public final class DiskLruCache implements Closeable { } }; - private DiskLruCache(File directory, int appVersion, int valueCount, long maxSize) { - this.directory = directory; - this.appVersion = appVersion; - this.journalFile = new File(directory, JOURNAL_FILE); - this.journalFileTmp = new File(directory, JOURNAL_FILE_TEMP); - this.journalFileBackup = new File(directory, JOURNAL_FILE_BACKUP); - this.valueCount = valueCount; - this.maxSize = maxSize; - } - /** * Opens the cache in {@code directory}, creating a cache if none exists * there. @@ -980,4 +979,6 @@ public final class DiskLruCache implements Closeable { } + + } diff --git a/app/src/main/java/com/hippo/ehviewer/EhApplication.java b/app/src/main/java/com/hippo/ehviewer/EhApplication.java index 031a76533..3760e721d 100644 --- a/app/src/main/java/com/hippo/ehviewer/EhApplication.java +++ b/app/src/main/java/com/hippo/ehviewer/EhApplication.java @@ -302,13 +302,6 @@ public class EhApplication extends SceneApplication { return application.mFavouriteStatusRouter; } - static class EhlifecycleObserver implements DefaultLifecycleObserver { - @Override - public void onPause(@NonNull LifecycleOwner owner) { - locked = true; - } - } - @SuppressLint("StaticFieldLeak") @Override public void onCreate() { @@ -593,4 +586,11 @@ public class EhApplication extends SceneApplication { return null; } } + + static class EhlifecycleObserver implements DefaultLifecycleObserver { + @Override + public void onPause(@NonNull LifecycleOwner owner) { + locked = true; + } + } } diff --git a/app/src/main/java/com/hippo/ehviewer/preference/ProxyPreference.kt b/app/src/main/java/com/hippo/ehviewer/preference/ProxyPreference.kt index 1118cfb1e..342f43322 100644 --- a/app/src/main/java/com/hippo/ehviewer/preference/ProxyPreference.kt +++ b/app/src/main/java/com/hippo/ehviewer/preference/ProxyPreference.kt @@ -15,25 +15,24 @@ */ package com.hippo.ehviewer.preference -import com.google.android.material.textfield.TextInputLayout -import android.widget.EditText -import com.hippo.ehviewer.R -import com.hippo.ehviewer.EhProxySelector -import android.text.TextUtils -import com.hippo.network.InetValidator import android.annotation.SuppressLint import android.content.Context import android.content.DialogInterface +import android.text.TextUtils import android.util.AttributeSet import android.view.View import android.widget.AutoCompleteTextView +import android.widget.EditText import androidx.appcompat.app.AlertDialog +import com.google.android.material.textfield.TextInputLayout import com.hippo.ehviewer.EhApplication +import com.hippo.ehviewer.EhProxySelector +import com.hippo.ehviewer.R import com.hippo.ehviewer.Settings +import com.hippo.network.InetValidator import com.hippo.preference.DialogPreference import com.hippo.yorozuya.MathUtils import com.hippo.yorozuya.ViewUtils -import java.lang.NumberFormatException class ProxyPreference @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null @@ -95,7 +94,13 @@ class ProxyPreference @JvmOverloads constructor( mPortInputLayout = ViewUtils.`$$`(dialog, R.id.port_input_layout) as TextInputLayout mPort = ViewUtils.`$$`(dialog, R.id.port) as EditText val type = Settings.getProxyType() - (mType!!.editText as AutoCompleteTextView).setText(array[MathUtils.clamp(type, 0, array.size)], false) + (mType!!.editText as AutoCompleteTextView).setText( + array[MathUtils.clamp( + type, + 0, + array.size + )], false + ) mIp!!.setText(Settings.getProxyIp()) val portString: String? val port = Settings.getProxyPort() 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 4ff1aa418..5ae904dc8 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/GalleryActivity.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/GalleryActivity.java @@ -296,16 +296,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"}) @@ -473,7 +464,16 @@ public class GalleryActivity extends EhActivity implements SeekBar.OnSeekBarChan FrameLayout mainLayout = (FrameLayout) ViewUtils.$$(this, R.id.main); mainLayout.addView(new GalleryGuideView(this)); } - } + } 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 onDestroy() { 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 1b46b68de..c4e26770a 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 @@ -53,7 +53,6 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.ArrayList; import java.util.Arrays; -import java.util.Locale; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; diff --git a/app/src/main/java/com/hippo/ehviewer/ui/fragment/BasePreferenceFragment.java b/app/src/main/java/com/hippo/ehviewer/ui/fragment/BasePreferenceFragment.java index 386bbce26..335d080ad 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/fragment/BasePreferenceFragment.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/fragment/BasePreferenceFragment.java @@ -63,7 +63,7 @@ public class BasePreferenceFragment extends PreferenceFragmentCompat public boolean onPreferenceTreeClick(Preference preference) { String key = preference.getKey(); try { - Fragment classObj = (Fragment)Class.forName(key).newInstance(); + Fragment classObj = (Fragment) Class.forName(key).newInstance(); requireActivity().getSupportFragmentManager() .beginTransaction() .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE) diff --git a/app/src/main/java/com/hippo/ehviewer/ui/fragment/FilterFragment.kt b/app/src/main/java/com/hippo/ehviewer/ui/fragment/FilterFragment.kt index e1be640a7..f8de56ccc 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/fragment/FilterFragment.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/fragment/FilterFragment.kt @@ -39,9 +39,7 @@ import com.hippo.ehviewer.R import com.hippo.ehviewer.client.EhFilter import com.hippo.ehviewer.dao.Filter import com.hippo.view.ViewTransition -import com.hippo.yorozuya.LayoutUtils import com.hippo.yorozuya.ViewUtils -import rikka.core.res.resolveColor class FilterFragment : BaseFragment() { private var mViewTransition: ViewTransition? = null diff --git a/app/src/main/java/com/hippo/ehviewer/ui/fragment/HostsFragment.java b/app/src/main/java/com/hippo/ehviewer/ui/fragment/HostsFragment.java index 8fcd031a7..6fafe3314 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/fragment/HostsFragment.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/fragment/HostsFragment.java @@ -41,14 +41,11 @@ import com.hippo.ehviewer.EhApplication; import com.hippo.ehviewer.Hosts; import com.hippo.ehviewer.R; import com.hippo.view.ViewTransition; -import com.hippo.yorozuya.LayoutUtils; import com.hippo.yorozuya.ViewUtils; import java.util.List; import java.util.Locale; -import rikka.core.res.ResourcesKt; - public class HostsFragment extends BaseFragment implements View.OnClickListener { diff --git a/app/src/main/java/com/hippo/ehviewer/ui/fragment/SettingsFragment.java b/app/src/main/java/com/hippo/ehviewer/ui/fragment/SettingsFragment.java index 98d34ae5e..3dc6dd419 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/fragment/SettingsFragment.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/fragment/SettingsFragment.java @@ -21,9 +21,6 @@ package com.hippo.ehviewer.ui.fragment; import android.os.Bundle; import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentTransaction; -import androidx.preference.Preference; import com.hippo.ehviewer.R; 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 aee49c0f8..40d4fff2e 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 @@ -82,8 +82,6 @@ import com.hippo.widget.LinkifyTextView; import com.hippo.widget.ObservedTextView; import com.hippo.yorozuya.AnimationUtils; import com.hippo.yorozuya.AssertUtils; -import com.hippo.yorozuya.LayoutUtils; -import com.hippo.yorozuya.ResourcesUtils; import com.hippo.yorozuya.SimpleAnimatorListener; import com.hippo.yorozuya.StringUtils; import com.hippo.yorozuya.ViewUtils; diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryInfoScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryInfoScene.java index 592f68a26..3fa51e013 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryInfoScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryInfoScene.java @@ -37,13 +37,10 @@ import com.hippo.ehviewer.client.EhUtils; import com.hippo.ehviewer.client.data.GalleryDetail; import com.hippo.util.ClipboardUtil; import com.hippo.yorozuya.AssertUtils; -import com.hippo.yorozuya.LayoutUtils; import com.hippo.yorozuya.ViewUtils; import java.util.ArrayList; -import rikka.core.res.ResourcesKt; - public final class GalleryInfoScene extends ToolbarScene { public static final String KEY_GALLERY_DETAIL = "gallery_detail"; diff --git a/app/src/main/java/com/hippo/ehviewer/widget/GalleryGuideView.java b/app/src/main/java/com/hippo/ehviewer/widget/GalleryGuideView.java index 7ee47f1d8..189a051f4 100644 --- a/app/src/main/java/com/hippo/ehviewer/widget/GalleryGuideView.java +++ b/app/src/main/java/com/hippo/ehviewer/widget/GalleryGuideView.java @@ -30,8 +30,6 @@ import com.hippo.ehviewer.R; import com.hippo.ehviewer.Settings; import com.hippo.yorozuya.ViewUtils; -import rikka.core.res.ResourcesKt; - public class GalleryGuideView extends ViewGroup implements View.OnClickListener { private final float[] mPoints = new float[3 * 4]; 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 327f66ff9..59208c784 100644 --- a/app/src/main/java/com/hippo/ehviewer/widget/SearchBar.java +++ b/app/src/main/java/com/hippo/ehviewer/widget/SearchBar.java @@ -52,7 +52,6 @@ import com.hippo.ehviewer.R; import com.hippo.ehviewer.client.EhTagDatabase; import com.hippo.view.ViewTransition; import com.hippo.yorozuya.AnimationUtils; -import com.hippo.yorozuya.LayoutUtils; import com.hippo.yorozuya.MathUtils; import com.hippo.yorozuya.SimpleAnimatorListener; import com.hippo.yorozuya.ViewUtils; @@ -60,8 +59,6 @@ import com.hippo.yorozuya.ViewUtils; import java.util.ArrayList; import java.util.List; -import rikka.core.res.ResourcesKt; - public class SearchBar extends MaterialCardView implements View.OnClickListener, TextView.OnEditorActionListener, TextWatcher, SearchEditText.SearchEditTextListener { diff --git a/app/src/main/java/com/hippo/unifile/Contracts.java b/app/src/main/java/com/hippo/unifile/Contracts.java index 8bed9fc7a..82f0e0433 100644 --- a/app/src/main/java/com/hippo/unifile/Contracts.java +++ b/app/src/main/java/com/hippo/unifile/Contracts.java @@ -28,15 +28,16 @@ import java.io.InputStream; import java.io.OutputStream; final class Contracts { - private Contracts() {} + private Contracts() { + } static String queryForString(Context context, Uri self, String column, - String defaultValue) { + String defaultValue) { final ContentResolver resolver = context.getContentResolver(); Cursor c = null; try { - c = resolver.query(self, new String[] { column }, null, null, null); + c = resolver.query(self, new String[]{column}, null, null, null); if (c != null && c.moveToFirst() && !c.isNull(0)) { return c.getString(0); } else { @@ -51,17 +52,17 @@ final class Contracts { } static int queryForInt(Context context, Uri self, String column, - int defaultValue) { + int defaultValue) { return (int) queryForLong(context, self, column, defaultValue); } static long queryForLong(Context context, Uri self, String column, - long defaultValue) { + long defaultValue) { final ContentResolver resolver = context.getContentResolver(); Cursor c = null; try { - c = resolver.query(self, new String[] { column }, null, null, null); + c = resolver.query(self, new String[]{column}, null, null, null); if (c != null && c.moveToFirst() && !c.isNull(0)) { return c.getLong(0); } else { diff --git a/app/src/main/java/com/hippo/unifile/DocumentsContractApi19.java b/app/src/main/java/com/hippo/unifile/DocumentsContractApi19.java index f6d1b7e4b..a0c2bcd7f 100644 --- a/app/src/main/java/com/hippo/unifile/DocumentsContractApi19.java +++ b/app/src/main/java/com/hippo/unifile/DocumentsContractApi19.java @@ -30,10 +30,11 @@ import android.util.Log; @TargetApi(Build.VERSION_CODES.KITKAT) final class DocumentsContractApi19 { - private DocumentsContractApi19() {} - private static final String TAG = DocumentsContractApi19.class.getSimpleName(); + private DocumentsContractApi19() { + } + public static boolean isDocumentUri(Context context, Uri self) { return DocumentsContract.isDocumentUri(context, self); } @@ -132,8 +133,8 @@ final class DocumentsContractApi19 { Cursor c = null; try { - c = resolver.query(self, new String[] { - DocumentsContract.Document.COLUMN_DOCUMENT_ID }, null, null, null); + c = resolver.query(self, new String[]{ + DocumentsContract.Document.COLUMN_DOCUMENT_ID}, null, null, null); return null != c && c.getCount() > 0; } catch (Throwable e) { Utils.throwIfFatal(e); diff --git a/app/src/main/java/com/hippo/unifile/DocumentsContractApi21.java b/app/src/main/java/com/hippo/unifile/DocumentsContractApi21.java index 2b77a90a7..0a351fe45 100644 --- a/app/src/main/java/com/hippo/unifile/DocumentsContractApi21.java +++ b/app/src/main/java/com/hippo/unifile/DocumentsContractApi21.java @@ -24,20 +24,20 @@ import android.net.Uri; import android.os.Build; import android.provider.DocumentsContract; import android.util.Log; + import java.util.ArrayList; import java.util.List; @TargetApi(Build.VERSION_CODES.LOLLIPOP) final class DocumentsContractApi21 { - private DocumentsContractApi21() {} - private static final String TAG = DocumentsContractApi21.class.getSimpleName(); - private static final String PATH_DOCUMENT = "document"; private static final String PATH_TREE = "tree"; + private DocumentsContractApi21() { + } public static Uri createFile(Context context, Uri self, String mimeType, - String displayName) { + String displayName) { try { return DocumentsContract.createDocument(context.getContentResolver(), self, mimeType, displayName); @@ -79,8 +79,8 @@ final class DocumentsContractApi21 { Cursor c = null; try { - c = resolver.query(childrenUri, new String[] { - DocumentsContract.Document.COLUMN_DOCUMENT_ID }, null, null, null); + c = resolver.query(childrenUri, new String[]{ + DocumentsContract.Document.COLUMN_DOCUMENT_ID}, null, null, null); if (null != c) { while (c.moveToNext()) { final String documentId = c.getString(0); diff --git a/app/src/main/java/com/hippo/unifile/FileDescriptorRandomAccessFile.java b/app/src/main/java/com/hippo/unifile/FileDescriptorRandomAccessFile.java index 2591fc159..12f983a6d 100644 --- a/app/src/main/java/com/hippo/unifile/FileDescriptorRandomAccessFile.java +++ b/app/src/main/java/com/hippo/unifile/FileDescriptorRandomAccessFile.java @@ -18,7 +18,6 @@ package com.hippo.unifile; import android.content.Context; import android.net.Uri; -import android.os.Build; import android.os.ParcelFileDescriptor; import android.system.ErrnoException; import android.system.Os; @@ -34,196 +33,195 @@ import java.lang.annotation.RetentionPolicy; class FileDescriptorRandomAccessFile implements UniRandomAccessFile { - @IntDef({FLUSH_NONE, FLUSH_FSYNC, FLUSH_FDATASYNC}) - @Retention(RetentionPolicy.SOURCE) - public @interface FlushMode {} + public static final int FLUSH_NONE = 0; + public static final int FLUSH_FSYNC = 1; + public static final int FLUSH_FDATASYNC = 2; + private final ParcelFileDescriptor pfd; + private final FileDescriptor fd; + private final int flushAfterWrite; + private final Object closeLock = new Object(); + private volatile boolean closed = false; + private FileDescriptorRandomAccessFile(ParcelFileDescriptor pfd, FileDescriptor fd, String mode) { + this.pfd = pfd; + this.fd = fd; - public static final int FLUSH_NONE = 0; - public static final int FLUSH_FSYNC = 1; - public static final int FLUSH_FDATASYNC = 2; - - private final ParcelFileDescriptor pfd; - private final FileDescriptor fd; - private final int flushAfterWrite; - private final Object closeLock = new Object(); - private volatile boolean closed = false; - - private FileDescriptorRandomAccessFile(ParcelFileDescriptor pfd, FileDescriptor fd, String mode) { - this.pfd = pfd; - this.fd = fd; - - switch (mode) { - case "rws": - flushAfterWrite = FLUSH_FSYNC; - break; - case "rwd": - flushAfterWrite = FLUSH_FDATASYNC; - break; - default: - flushAfterWrite = FLUSH_NONE; - break; - } - } - - private void maybeSync() { - if (flushAfterWrite == FLUSH_FSYNC) { - try { - fd.sync(); - } catch (IOException e) { - // Ignored - } - } else if (flushAfterWrite == FLUSH_FDATASYNC) { - try { - Os.fdatasync(fd); - } catch (ErrnoException e) { - // Ignored - } - } - } - - @Override - public void close() throws IOException { - synchronized (closeLock) { - if (closed) { - return; - } - closed = true; + switch (mode) { + case "rws": + flushAfterWrite = FLUSH_FSYNC; + break; + case "rwd": + flushAfterWrite = FLUSH_FDATASYNC; + break; + default: + flushAfterWrite = FLUSH_NONE; + break; + } } - pfd.close(); + @NonNull + static FileDescriptorRandomAccessFile create(Context context, Uri uri, String mode) throws IOException { + // Get FileDescriptor + ParcelFileDescriptor pfd; + try { + pfd = context.getContentResolver().openFileDescriptor(uri, mode); + } catch (Throwable e) { + Utils.throwIfFatal(e); + throw new IOException("Can't get ParcelFileDescriptor", e); + } + if (pfd == null) { + throw new IOException("Can't get ParcelFileDescriptor"); + } + FileDescriptor fd; + try { + fd = pfd.getFileDescriptor(); + } catch (SecurityException e) { + pfd.close(); + throw new IOException("Can't get FileDescriptor", e); + } + if (fd == null) { + pfd.close(); + throw new IOException("Can't get FileDescriptor"); + } - try { - Os.close(fd); - } catch (ErrnoException e) { - throw new IOException("An ErrnoException occurs", e); - } - } - - @Override - public long getFilePointer() throws IOException { - try { - return Os.lseek(fd, 0L, OsConstants.SEEK_CUR); - } catch (ErrnoException e) { - throw new IOException("An ErrnoException occurs", e); - } - } - - @Override - public void seek(long pos) throws IOException { - if (pos < 0) { - throw new IOException("offset < 0: " + pos); - } else { - try { - Os.lseek(fd, pos, OsConstants.SEEK_SET); - } catch (ErrnoException e) { - throw new IOException("An ErrnoException occurs", e); - } - } - } - - @Override - public int skipBytes(int n) throws IOException { - long pos; - long len; - long newpos; - - if (n <= 0) { - return 0; - } - pos = getFilePointer(); - len = length(); - newpos = pos + n; - if (newpos > len) { - newpos = len; - } - seek(newpos); - - /* return the actual number of bytes skipped */ - return (int) (newpos - pos); - } - - @Override - public long length() throws IOException { - try { - return Os.fstat(fd).st_size; - } catch (ErrnoException e) { - throw new IOException("An ErrnoException occurs", e); - } - } - - @Override - public void setLength(long newLength) throws IOException { - if (newLength < 0) { - throw new IllegalArgumentException("newLength < 0"); - } - try { - Os.ftruncate(fd, newLength); - } catch (ErrnoException e) { - throw new IOException("An ErrnoException occurs", e); + return new FileDescriptorRandomAccessFile(pfd, fd, mode); } - long filePointer = getFilePointer(); - if (filePointer > newLength) { - seek(newLength); + private void maybeSync() { + if (flushAfterWrite == FLUSH_FSYNC) { + try { + fd.sync(); + } catch (IOException e) { + // Ignored + } + } else if (flushAfterWrite == FLUSH_FDATASYNC) { + try { + Os.fdatasync(fd); + } catch (ErrnoException e) { + // Ignored + } + } } - maybeSync(); - } + @Override + public void close() throws IOException { + synchronized (closeLock) { + if (closed) { + return; + } + closed = true; + } - @Override - public int read(byte[] b) throws IOException { - return read(b, 0, b.length); - } + pfd.close(); - @Override - public int read(byte[] b, int off, int len) throws IOException { - try { - return Os.read(fd, b, off, len); - } catch (ErrnoException e) { - throw new IOException("An ErrnoException occurs", e); - } - } - - @Override - public void write(byte[] b) throws IOException { - write(b, 0, b.length); - } - - @Override - public void write(byte[] b, int off, int len) throws IOException { - try { - Os.write(fd, b, off, len); - } catch (ErrnoException e) { - throw new IOException("An ErrnoException occurs", e); - } - maybeSync(); - } - - @NonNull - static FileDescriptorRandomAccessFile create(Context context, Uri uri, String mode) throws IOException { - // Get FileDescriptor - ParcelFileDescriptor pfd; - try { - pfd = context.getContentResolver().openFileDescriptor(uri, mode); - } catch (Throwable e) { - Utils.throwIfFatal(e); - throw new IOException("Can't get ParcelFileDescriptor", e); - } - if (pfd == null) { - throw new IOException("Can't get ParcelFileDescriptor"); - } - FileDescriptor fd; - try { - fd = pfd.getFileDescriptor(); - } catch (SecurityException e) { - pfd.close(); - throw new IOException("Can't get FileDescriptor", e); - } - if (fd == null) { - pfd.close(); - throw new IOException("Can't get FileDescriptor"); + try { + Os.close(fd); + } catch (ErrnoException e) { + throw new IOException("An ErrnoException occurs", e); + } } - return new FileDescriptorRandomAccessFile(pfd, fd, mode); - } + @Override + public long getFilePointer() throws IOException { + try { + return Os.lseek(fd, 0L, OsConstants.SEEK_CUR); + } catch (ErrnoException e) { + throw new IOException("An ErrnoException occurs", e); + } + } + + @Override + public void seek(long pos) throws IOException { + if (pos < 0) { + throw new IOException("offset < 0: " + pos); + } else { + try { + Os.lseek(fd, pos, OsConstants.SEEK_SET); + } catch (ErrnoException e) { + throw new IOException("An ErrnoException occurs", e); + } + } + } + + @Override + public int skipBytes(int n) throws IOException { + long pos; + long len; + long newpos; + + if (n <= 0) { + return 0; + } + pos = getFilePointer(); + len = length(); + newpos = pos + n; + if (newpos > len) { + newpos = len; + } + seek(newpos); + + /* return the actual number of bytes skipped */ + return (int) (newpos - pos); + } + + @Override + public long length() throws IOException { + try { + return Os.fstat(fd).st_size; + } catch (ErrnoException e) { + throw new IOException("An ErrnoException occurs", e); + } + } + + @Override + public void setLength(long newLength) throws IOException { + if (newLength < 0) { + throw new IllegalArgumentException("newLength < 0"); + } + try { + Os.ftruncate(fd, newLength); + } catch (ErrnoException e) { + throw new IOException("An ErrnoException occurs", e); + } + + long filePointer = getFilePointer(); + if (filePointer > newLength) { + seek(newLength); + } + + maybeSync(); + } + + @Override + public int read(byte[] b) throws IOException { + return read(b, 0, b.length); + } + + @Override + public int read(byte[] b, int off, int len) throws IOException { + try { + return Os.read(fd, b, off, len); + } catch (ErrnoException e) { + throw new IOException("An ErrnoException occurs", e); + } + } + + @Override + public void write(byte[] b) throws IOException { + write(b, 0, b.length); + } + + @Override + public void write(byte[] b, int off, int len) throws IOException { + try { + Os.write(fd, b, off, len); + } catch (ErrnoException e) { + throw new IOException("An ErrnoException occurs", e); + } + maybeSync(); + } + + @IntDef({FLUSH_NONE, FLUSH_FSYNC, FLUSH_FDATASYNC}) + @Retention(RetentionPolicy.SOURCE) + public @interface FlushMode { + } } diff --git a/app/src/main/java/com/hippo/unifile/FilenameFilter.java b/app/src/main/java/com/hippo/unifile/FilenameFilter.java index 253228057..04d3f779a 100644 --- a/app/src/main/java/com/hippo/unifile/FilenameFilter.java +++ b/app/src/main/java/com/hippo/unifile/FilenameFilter.java @@ -28,13 +28,11 @@ public interface FilenameFilter { /** * Indicates if a specific filename matches this filter. * - * @param dir - * the directory in which the {@code filename} was found. - * @param filename - * the name of the file in {@code dir} to test. - * @return {@code true} if the filename matches the filter - * and can be included in the list, {@code false} - * otherwise. + * @param dir the directory in which the {@code filename} was found. + * @param filename the name of the file in {@code dir} to test. + * @return {@code true} if the filename matches the filter + * and can be included in the list, {@code false} + * otherwise. */ boolean accept(UniFile dir, String filename); } diff --git a/app/src/main/java/com/hippo/unifile/MediaContract.java b/app/src/main/java/com/hippo/unifile/MediaContract.java index 044779c54..7203925c9 100644 --- a/app/src/main/java/com/hippo/unifile/MediaContract.java +++ b/app/src/main/java/com/hippo/unifile/MediaContract.java @@ -21,7 +21,8 @@ import android.net.Uri; import android.provider.MediaStore; final class MediaContract { - private MediaContract() {} + private MediaContract() { + } public static String getName(Context context, Uri self) { return Contracts.queryForString(context, self, MediaStore.MediaColumns.DISPLAY_NAME, null); diff --git a/app/src/main/java/com/hippo/unifile/MediaFile.java b/app/src/main/java/com/hippo/unifile/MediaFile.java index 97f224242..7e3045015 100644 --- a/app/src/main/java/com/hippo/unifile/MediaFile.java +++ b/app/src/main/java/com/hippo/unifile/MediaFile.java @@ -18,7 +18,6 @@ package com.hippo.unifile; import android.content.Context; import android.net.Uri; -import android.os.Build; import androidx.annotation.NonNull; @@ -38,6 +37,10 @@ class MediaFile extends UniFile { mUri = uri; } + static boolean isMediaUri(Context context, Uri uri) { + return null != MediaContract.getName(context, uri); + } + @Override public UniFile createFile(String displayName) { return null; @@ -54,10 +57,6 @@ class MediaFile extends UniFile { return mUri; } - static boolean isMediaUri(Context context, Uri uri) { - return null != MediaContract.getName(context, uri); - } - @Override public String getName() { return MediaContract.getName(mContext, mUri); diff --git a/app/src/main/java/com/hippo/unifile/RawFile.java b/app/src/main/java/com/hippo/unifile/RawFile.java index 3391b33da..bc4207397 100644 --- a/app/src/main/java/com/hippo/unifile/RawFile.java +++ b/app/src/main/java/com/hippo/unifile/RawFile.java @@ -43,6 +43,36 @@ class RawFile extends UniFile { mFile = file; } + private static String getTypeForName(String name) { + final int lastDot = name.lastIndexOf('.'); + if (lastDot >= 0) { + final String extension = name.substring(lastDot + 1).toLowerCase(); + final String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); + if (mime != null) { + return mime; + } + } + + return "application/octet-stream"; + } + + private static boolean deleteContents(File dir) { + File[] files = dir.listFiles(); + boolean success = true; + if (files != null) { + for (File file : files) { + if (file.isDirectory()) { + success &= deleteContents(file); + } + if (!file.delete()) { + Log.w(TAG, "Failed to delete " + file); + success = false; + } + } + } + return success; + } + @Override public UniFile createFile(String displayName) { final File target = new File(mFile, displayName); @@ -239,34 +269,4 @@ class RawFile extends UniFile { public UniRandomAccessFile createRandomAccessFile(String mode) throws FileNotFoundException { return new RawRandomAccessFile(new RandomAccessFile(mFile, mode)); } - - private static String getTypeForName(String name) { - final int lastDot = name.lastIndexOf('.'); - if (lastDot >= 0) { - final String extension = name.substring(lastDot + 1).toLowerCase(); - final String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); - if (mime != null) { - return mime; - } - } - - return "application/octet-stream"; - } - - private static boolean deleteContents(File dir) { - File[] files = dir.listFiles(); - boolean success = true; - if (files != null) { - for (File file : files) { - if (file.isDirectory()) { - success &= deleteContents(file); - } - if (!file.delete()) { - Log.w(TAG, "Failed to delete " + file); - success = false; - } - } - } - return success; - } } diff --git a/app/src/main/java/com/hippo/unifile/SingleDocumentFile.java b/app/src/main/java/com/hippo/unifile/SingleDocumentFile.java index 80c47b46a..9c93ed4c4 100644 --- a/app/src/main/java/com/hippo/unifile/SingleDocumentFile.java +++ b/app/src/main/java/com/hippo/unifile/SingleDocumentFile.java @@ -18,7 +18,6 @@ package com.hippo.unifile; import android.content.Context; import android.net.Uri; -import android.os.Build; import androidx.annotation.NonNull; diff --git a/app/src/main/java/com/hippo/unifile/UniFile.java b/app/src/main/java/com/hippo/unifile/UniFile.java index 39251efda..543be1c9d 100644 --- a/app/src/main/java/com/hippo/unifile/UniFile.java +++ b/app/src/main/java/com/hippo/unifile/UniFile.java @@ -67,7 +67,7 @@ public abstract class UniFile { /** * Create a {@link UniFile} representing the given {@link File}. - + * * @param file the file to wrap * @return the {@link UniFile} representing the given {@link File}. */ @@ -83,8 +83,8 @@ public abstract class UniFile { * {@code null} when called on earlier platform versions. * * @param singleUri the {@link Intent#getData()} from a successful - * {@link Intent#ACTION_OPEN_DOCUMENT} or - * {@link Intent#ACTION_CREATE_DOCUMENT} request. + * {@link Intent#ACTION_OPEN_DOCUMENT} or + * {@link Intent#ACTION_CREATE_DOCUMENT} request. * @return the {@link UniFile} representing the given {@link Uri}. */ public static UniFile fromSingleUri(Context context, Uri singleUri) { @@ -103,7 +103,7 @@ public abstract class UniFile { * {@code null} when called on earlier platform versions. * * @param treeUri the {@link Intent#getData()} from a successful - * {@link Intent#ACTION_OPEN_DOCUMENT_TREE} request. + * {@link Intent#ACTION_OPEN_DOCUMENT_TREE} request. * @return the {@link UniFile} representing the given {@link Uri}. */ public static UniFile fromTreeUri(Context context, Uri treeUri) { @@ -198,7 +198,7 @@ public abstract class UniFile { * @param displayName name of new file * @return file representing newly created document, or null if failed * @see android.provider.DocumentsContract#createDocument(ContentResolver, - * Uri, String, String) + * Uri, String, String) */ public abstract UniFile createFile(String displayName); @@ -208,7 +208,7 @@ public abstract class UniFile { * @param displayName name of new directory * @return file representing newly created directory, or null if failed * @see android.provider.DocumentsContract#createDocument(ContentResolver, - * Uri, String, String) + * Uri, String, String) */ public abstract UniFile createDirectory(String displayName); @@ -267,7 +267,7 @@ public abstract class UniFile { * Indicates if this file represents a directory. * * @return {@code true} if this file is a directory, {@code false} - * otherwise. + * otherwise. * @see android.provider.DocumentsContract.Document#MIME_TYPE_DIR */ public abstract boolean isDirectory(); @@ -311,7 +311,7 @@ public abstract class UniFile { * Indicates whether the current context is allowed to write to this file. * * @return {@code true} if this file can be written, {@code false} - * otherwise. + * otherwise. * @see android.provider.DocumentsContract.Document#COLUMN_FLAGS * @see android.provider.DocumentsContract.Document#FLAG_SUPPORTS_DELETE * @see android.provider.DocumentsContract.Document#FLAG_SUPPORTS_WRITE @@ -323,7 +323,7 @@ public abstract class UniFile { * It works like mkdirs, but it will return true if the UniFile is directory * * @return {@code true} if the directory was created - * or if the directory already existed. + * or if the directory already existed. */ public abstract boolean ensureDir(); @@ -331,7 +331,7 @@ public abstract class UniFile { * Make sure the UniFile is file * * @return {@code true} if the file can be created - * or if the file already existed. + * or if the file already existed. */ public abstract boolean ensureFile(); @@ -351,7 +351,7 @@ public abstract class UniFile { * * @return {@code true} if this file was deleted, {@code false} otherwise. * @see android.provider.DocumentsContract#deleteDocument(ContentResolver, - * Uri) + * Uri) */ public abstract boolean delete(); @@ -368,7 +368,7 @@ public abstract class UniFile { * * @return an array of files or {@code null}. * @see android.provider.DocumentsContract#buildChildDocumentsUriUsingTree(Uri, - * String) + * String) */ @Nullable public abstract UniFile[] listFiles(); @@ -408,7 +408,7 @@ public abstract class UniFile { * @param displayName the new display name. * @return true on success. * @see android.provider.DocumentsContract#renameDocument(ContentResolver, - * Uri, String) + * Uri, String) */ public abstract boolean renameTo(String displayName); diff --git a/app/src/main/java/com/hippo/unifile/UniRandomAccessFile.java b/app/src/main/java/com/hippo/unifile/UniRandomAccessFile.java index 4f31c57d1..defb72dc4 100644 --- a/app/src/main/java/com/hippo/unifile/UniRandomAccessFile.java +++ b/app/src/main/java/com/hippo/unifile/UniRandomAccessFile.java @@ -80,8 +80,8 @@ public interface UniRandomAccessFile { * * @param b the buffer into which the data is read * @return the total number of bytes read into the buffer, or - * {@code -1} if there is no more data because the end of - * the file has been reached. + * {@code -1} if there is no more data because the end of + * the file has been reached. * @throws IOException if an I/O error occurs */ int read(byte[] b) throws IOException; @@ -90,12 +90,12 @@ public interface UniRandomAccessFile { * Reads exactly len bytes from this file into the byte array, * starting at the current file pointer. * - * @param b the buffer into which the data is read + * @param b the buffer into which the data is read * @param off the start offset of the data * @param len the number of bytes to read * @return the total number of bytes read into the buffer, or - * {@code -1} if there is no more data because the end of - * the file has been reached. + * {@code -1} if there is no more data because the end of + * the file has been reached. * @throws IOException */ int read(byte[] b, int off, int len) throws IOException; @@ -112,7 +112,7 @@ public interface UniRandomAccessFile { /** * Writes len bytes from the specified byte array starting at offset off to this file. * - * @param b the data + * @param b the data * @param off the start offset in the data * @param len the number of bytes to write * @throws IOException diff --git a/app/src/main/java/com/hippo/unifile/UriOutputStream.java b/app/src/main/java/com/hippo/unifile/UriOutputStream.java index 791954fc2..4c9a3978a 100644 --- a/app/src/main/java/com/hippo/unifile/UriOutputStream.java +++ b/app/src/main/java/com/hippo/unifile/UriOutputStream.java @@ -45,12 +45,6 @@ class UriOutputStream extends FileOutputStream { mPfd = pfd; } - @Override - public void close() throws IOException { - mPfd.close(); - super.close(); - } - @NonNull static OutputStream create(Context context, Uri uri, String mode) throws IOException { ParcelFileDescriptor pfd; @@ -70,4 +64,10 @@ class UriOutputStream extends FileOutputStream { return new UriOutputStream(pfd, fd); } + + @Override + public void close() throws IOException { + mPfd.close(); + super.close(); + } } diff --git a/app/src/main/java/com/hippo/widget/BatteryView.java b/app/src/main/java/com/hippo/widget/BatteryView.java index f83d3ad79..e379f41ae 100644 --- a/app/src/main/java/com/hippo/widget/BatteryView.java +++ b/app/src/main/java/com/hippo/widget/BatteryView.java @@ -73,6 +73,15 @@ public class BatteryView extends AppCompatTextView { int height = (int) getTextSize(); mDrawable.setBounds(0, 0, (int) (height / 0.618f), height); setCompoundDrawables(mDrawable, null, null, null); + } + + @Override + public void setTextColor(int color) { + if (mCurrentColor == color) { + return; + } + mCurrentColor = color; + super.setTextColor(color); } private final Runnable mCharger = new Runnable() { private int level = 0; @@ -88,15 +97,6 @@ public class BatteryView extends AppCompatTextView { } }; - @Override - public void setTextColor(int color) { - if (mCurrentColor == color) { - return; - } - mCurrentColor = color; - super.setTextColor(color); - } - private void startCharger() { if (!mIsChargerWorking) { getHandler().post(mCharger); @@ -143,6 +143,8 @@ public class BatteryView extends AppCompatTextView { getContext().unregisterReceiver(mIntentReceiver); } + + private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { @Override @@ -175,6 +177,4 @@ public class BatteryView extends AppCompatTextView { }; - - } diff --git a/app/src/main/java/com/hippo/widget/TextClock.java b/app/src/main/java/com/hippo/widget/TextClock.java index 2574f4522..806734695 100644 --- a/app/src/main/java/com/hippo/widget/TextClock.java +++ b/app/src/main/java/com/hippo/widget/TextClock.java @@ -89,6 +89,14 @@ public class TextClock extends AppCompatTextView { createTime(mTimeZone); // Wait until onAttachedToWindow() to handle the ticker chooseFormat(false); + } + + private void createTime(String timeZone) { + if (timeZone != null) { + mTime = Calendar.getInstance(TimeZone.getTimeZone(timeZone)); + } else { + mTime = Calendar.getInstance(); + } } private final Runnable mTicker = new Runnable() { @Override public void run() { @@ -101,14 +109,6 @@ public class TextClock extends AppCompatTextView { } }; - private void createTime(String timeZone) { - if (timeZone != null) { - mTime = Calendar.getInstance(TimeZone.getTimeZone(timeZone)); - } else { - mTime = Calendar.getInstance(); - } - } - public CharSequence getFormat12Hour() { return mFormat12; } @@ -133,6 +133,17 @@ public class TextClock extends AppCompatTextView { public boolean is24HourModeEnabled() { return DateFormat.is24HourFormat(getContext()); + } + + public String getTimeZone() { + return mTimeZone; + } + + public void setTimeZone(String timeZone) { + mTimeZone = timeZone; + + createTime(timeZone); + onTimeChanged(); } private final ContentObserver mFormatChangeObserver = new ContentObserver(new Handler()) { @Override public void onChange(boolean selfChange) { @@ -147,17 +158,6 @@ public class TextClock extends AppCompatTextView { } }; - public String getTimeZone() { - return mTimeZone; - } - - public void setTimeZone(String timeZone) { - mTimeZone = timeZone; - - createTime(timeZone); - onTimeChanged(); - } - /** * Selects either one of {@link #getFormat12Hour()} or {@link #getFormat24Hour()} * depending on whether the user has selected 24-hour format. diff --git a/app/src/main/java/com/hippo/yorozuya/collect/AbstractMultimap.java b/app/src/main/java/com/hippo/yorozuya/collect/AbstractMultimap.java index 32e0604df..cdbddad0d 100644 --- a/app/src/main/java/com/hippo/yorozuya/collect/AbstractMultimap.java +++ b/app/src/main/java/com/hippo/yorozuya/collect/AbstractMultimap.java @@ -27,8 +27,8 @@ import java.util.Set; */ public abstract class AbstractMultimap> implements Map { - protected Map map; protected final boolean threadSafeCollections; + protected Map map; protected AbstractMultimap(Map map, boolean threadSafeCollections) { this.map = map; @@ -120,7 +120,9 @@ public abstract class AbstractMultimap> implements return map.entrySet(); } - /** @return true if the collection was changed. */ + /** + * @return true if the collection was changed. + */ public synchronized boolean putElements(K key, Collection values) { C collection = map.get(key); if (collection == null) { @@ -130,7 +132,9 @@ public abstract class AbstractMultimap> implements return collection.addAll(values); } - /** @return true if the given element was removed. */ + /** + * @return true if the given element was removed. + */ public synchronized boolean removeElement(K key, V value) { C collection = map.get(key); if (collection == null) { diff --git a/app/src/main/java/com/hippo/yorozuya/collect/CollectionUtils.java b/app/src/main/java/com/hippo/yorozuya/collect/CollectionUtils.java index 11bfcd070..7e3123610 100644 --- a/app/src/main/java/com/hippo/yorozuya/collect/CollectionUtils.java +++ b/app/src/main/java/com/hippo/yorozuya/collect/CollectionUtils.java @@ -42,12 +42,13 @@ public class CollectionUtils { /** * Appends an element to the end of the array, growing the array if there is no more room. - * @param array The array to which to append the element. This must NOT be null. + * + * @param array The array to which to append the element. This must NOT be null. * @param currentSize The number of elements in the array. Must be less than or equal to * array.length. - * @param element The element to append. + * @param element The element to append. * @return the array to which the element was appended. This may be different than the given - * array. + * array. */ public static T[] append(T[] array, int currentSize, T element) { if (currentSize + 1 > array.length) { @@ -103,12 +104,12 @@ public class CollectionUtils { * Inserts an element into the array at the specified index, growing the array if there is no * more room. * - * @param array The array to which to append the element. Must NOT be null. + * @param array The array to which to append the element. Must NOT be null. * @param currentSize The number of elements in the array. Must be less than or equal to * array.length. - * @param element The element to insert. + * @param element The element to insert. * @return the array to which the element was appended. This may be different than the given - * array. + * array. */ public static T[] insert(T[] array, int currentSize, int index, T element) { if (currentSize + 1 <= array.length) { diff --git a/app/src/main/java/com/hippo/yorozuya/collect/ContainerHelpers.java b/app/src/main/java/com/hippo/yorozuya/collect/ContainerHelpers.java index bbcae1afa..ddc20ea9b 100644 --- a/app/src/main/java/com/hippo/yorozuya/collect/ContainerHelpers.java +++ b/app/src/main/java/com/hippo/yorozuya/collect/ContainerHelpers.java @@ -60,7 +60,7 @@ public class ContainerHelpers { } public static int binarySearch(T[] array, int size, T value, - Comparator comparator) { + Comparator comparator) { int lo = 0; int hi = size - 1; diff --git a/app/src/main/java/com/hippo/yorozuya/collect/IntList.java b/app/src/main/java/com/hippo/yorozuya/collect/IntList.java index 178d765a5..b2e204681 100644 --- a/app/src/main/java/com/hippo/yorozuya/collect/IntList.java +++ b/app/src/main/java/com/hippo/yorozuya/collect/IntList.java @@ -21,8 +21,19 @@ import android.os.Parcelable; public class IntList implements Parcelable { - private static final int MIN_CAPACITY_INCREMENT = 12; + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + @Override + public IntList createFromParcel(Parcel source) { + return new IntList(source); + } + + @Override + public IntList[] newArray(int size) { + return new IntList[size]; + } + }; + private static final int MIN_CAPACITY_INCREMENT = 12; private int[] mArray; private int mSize = 0; @@ -34,6 +45,16 @@ public class IntList implements Parcelable { mArray = new int[capacity]; } + protected IntList(Parcel in) { + this(in.readInt()); + mSize = in.readInt(); + int s = mSize; + int[] a = mArray; + for (int i = 0; i < s; i++) { + a[i] = in.readInt(); + } + } + static void throwIndexOutOfBoundsException(int index, int size) { throw new IndexOutOfBoundsException("Invalid index " + index + ", size is " + size); } @@ -193,27 +214,4 @@ public class IntList implements Parcelable { dest.writeInt(a[i]); } } - - protected IntList(Parcel in) { - this(in.readInt()); - mSize = in.readInt(); - int s = mSize; - int[] a = mArray; - for (int i = 0; i < s; i++) { - a[i] = in.readInt(); - } - } - - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - - @Override - public IntList createFromParcel(Parcel source) { - return new IntList(source); - } - - @Override - public IntList[] newArray(int size) { - return new IntList[size]; - } - }; } diff --git a/app/src/main/java/com/hippo/yorozuya/collect/LongList.java b/app/src/main/java/com/hippo/yorozuya/collect/LongList.java index 6486a74c0..d019eaca4 100644 --- a/app/src/main/java/com/hippo/yorozuya/collect/LongList.java +++ b/app/src/main/java/com/hippo/yorozuya/collect/LongList.java @@ -21,8 +21,19 @@ import android.os.Parcelable; public class LongList implements Parcelable { - private static final int MIN_CAPACITY_INCREMENT = 12; + public static final Creator CREATOR = new Creator() { + @Override + public LongList createFromParcel(Parcel source) { + return new LongList(source); + } + + @Override + public LongList[] newArray(int size) { + return new LongList[size]; + } + }; + private static final int MIN_CAPACITY_INCREMENT = 12; private long[] mArray; private int mSize = 0; @@ -34,6 +45,16 @@ public class LongList implements Parcelable { mArray = new long[capacity]; } + protected LongList(Parcel in) { + this(in.readInt()); + mSize = in.readInt(); + int s = mSize; + long[] a = mArray; + for (int i = 0; i < s; i++) { + a[i] = in.readLong(); + } + } + static void throwIndexOutOfBoundsException(int index, int size) { throw new IndexOutOfBoundsException("Invalid index " + index + ", size is " + size); } @@ -193,27 +214,4 @@ public class LongList implements Parcelable { dest.writeLong(a[i]); } } - - protected LongList(Parcel in) { - this(in.readInt()); - mSize = in.readInt(); - int s = mSize; - long[] a = mArray; - for (int i = 0; i < s; i++) { - a[i] = in.readLong(); - } - } - - public static final Creator CREATOR = new Creator() { - - @Override - public LongList createFromParcel(Parcel source) { - return new LongList(source); - } - - @Override - public LongList[] newArray(int size) { - return new LongList[size]; - } - }; } diff --git a/app/src/main/java/com/hippo/yorozuya/collect/Multimap.java b/app/src/main/java/com/hippo/yorozuya/collect/Multimap.java index 05e072cfc..731458e7f 100644 --- a/app/src/main/java/com/hippo/yorozuya/collect/Multimap.java +++ b/app/src/main/java/com/hippo/yorozuya/collect/Multimap.java @@ -29,6 +29,10 @@ import java.util.concurrent.CopyOnWriteArrayList; */ // Top level class to get rid of 3rd generic collection parameter for more convenient usage. public class Multimap extends AbstractMultimap> { + protected Multimap(Map> map, boolean threadSafeCollections) { + super(map, threadSafeCollections); + } + public static Multimap create() { return new Multimap<>(new HashMap>(), false); } @@ -37,10 +41,6 @@ public class Multimap extends AbstractMultimap> { return new Multimap<>(new HashMap>(), true); } - protected Multimap(Map> map, boolean threadSafeCollections) { - super(map, threadSafeCollections); - } - protected List createNewCollection() { return threadSafeCollections ? new CopyOnWriteArrayList() : new ArrayList(); } diff --git a/app/src/main/java/com/hippo/yorozuya/collect/MultimapSet.java b/app/src/main/java/com/hippo/yorozuya/collect/MultimapSet.java index f3bebbce6..c76c398f1 100644 --- a/app/src/main/java/com/hippo/yorozuya/collect/MultimapSet.java +++ b/app/src/main/java/com/hippo/yorozuya/collect/MultimapSet.java @@ -31,6 +31,10 @@ import java.util.concurrent.CopyOnWriteArraySet; // Top level class to get rid of 3rd generic collection parameter for more convenient usage. public class MultimapSet extends AbstractMultimap> { + protected MultimapSet(Map> map, boolean threadSafeSets) { + super(map, threadSafeSets); + } + public static MultimapSet create() { return new MultimapSet<>(new HashMap>(), false); } @@ -39,10 +43,6 @@ public class MultimapSet extends AbstractMultimap> { return new MultimapSet<>(new HashMap>(), true); } - protected MultimapSet(Map> map, boolean threadSafeSets) { - super(map, threadSafeSets); - } - protected Set createNewCollection() { return threadSafeCollections ? new CopyOnWriteArraySet() : new HashSet(); } diff --git a/app/src/main/java/com/hippo/yorozuya/collect/SparseIJArray.java b/app/src/main/java/com/hippo/yorozuya/collect/SparseIJArray.java index 6b8891592..0451131c3 100644 --- a/app/src/main/java/com/hippo/yorozuya/collect/SparseIJArray.java +++ b/app/src/main/java/com/hippo/yorozuya/collect/SparseIJArray.java @@ -238,7 +238,7 @@ public class SparseIJArray { StringBuilder buffer = new StringBuilder(mSize * 28); buffer.append('{'); - for (int i=0; i 0) { buffer.append(", "); } diff --git a/app/src/main/java/com/hippo/yorozuya/collect/SparseILArray.java b/app/src/main/java/com/hippo/yorozuya/collect/SparseILArray.java index 8be12bc01..4d232b8bb 100644 --- a/app/src/main/java/com/hippo/yorozuya/collect/SparseILArray.java +++ b/app/src/main/java/com/hippo/yorozuya/collect/SparseILArray.java @@ -172,7 +172,7 @@ public class SparseILArray implements Cloneable { * Remove a range of mappings as a batch. * * @param index Index to begin at - * @param size Number of mappings to remove + * @param size Number of mappings to remove */ public void removeAtRange(int index, int size) { final int end = Math.min(mSize, index + size); @@ -388,7 +388,7 @@ public class SparseILArray implements Cloneable { StringBuilder buffer = new StringBuilder(mSize * 28); buffer.append('{'); - for (int i=0; i 0) { buffer.append(", "); } diff --git a/app/src/main/java/com/hippo/yorozuya/collect/SparseJBArray.java b/app/src/main/java/com/hippo/yorozuya/collect/SparseJBArray.java index b836399c6..c7a2872f2 100644 --- a/app/src/main/java/com/hippo/yorozuya/collect/SparseJBArray.java +++ b/app/src/main/java/com/hippo/yorozuya/collect/SparseJBArray.java @@ -39,6 +39,10 @@ package com.hippo.yorozuya.collect; * order in the case of valueAt(int).

*/ public class SparseJBArray implements Cloneable { + private long[] mKeys; + private boolean[] mValues; + private int mSize; + /** * Creates a new SparseJBArray containing no mappings. */ @@ -238,7 +242,7 @@ public class SparseJBArray implements Cloneable { StringBuilder buffer = new StringBuilder(mSize * 28); buffer.append('{'); - for (int i=0; i 0) { buffer.append(", "); } @@ -251,8 +255,4 @@ public class SparseJBArray implements Cloneable { buffer.append('}'); return buffer.toString(); } - - private long[] mKeys; - private boolean[] mValues; - private int mSize; } diff --git a/app/src/main/java/com/hippo/yorozuya/collect/SparseJLArray.java b/app/src/main/java/com/hippo/yorozuya/collect/SparseJLArray.java index 9af7b8073..54b871184 100644 --- a/app/src/main/java/com/hippo/yorozuya/collect/SparseJLArray.java +++ b/app/src/main/java/com/hippo/yorozuya/collect/SparseJLArray.java @@ -172,7 +172,7 @@ public class SparseJLArray { * Remove a range of mappings as a batch. * * @param index Index to begin at - * @param size Number of mappings to remove + * @param size Number of mappings to remove */ public void removeAtRange(int index, int size) { final int end = Math.min(mSize, index + size); @@ -388,7 +388,7 @@ public class SparseJLArray { StringBuilder buffer = new StringBuilder(mSize * 28); buffer.append('{'); - for (int i=0; i 0) { buffer.append(", "); } diff --git a/app/src/main/res/drawable-v26/ic_shortcut_start.xml b/app/src/main/res/drawable-v26/ic_shortcut_start.xml index 2bf1222e2..c280ec214 100644 --- a/app/src/main/res/drawable-v26/ic_shortcut_start.xml +++ b/app/src/main/res/drawable-v26/ic_shortcut_start.xml @@ -1,5 +1,4 @@ - - - - - + -