From c4b9d82768674ffbd641f3fe1bd0402a52888fea Mon Sep 17 00:00:00 2001 From: NekoInverter <7741672-NekoInverter@users.noreply.gitlab.com> Date: Tue, 22 Dec 2020 16:48:01 +0800 Subject: [PATCH] Fix deprecated warning --- .../main/java/com/hippo/ehviewer/Crash.java | 8 ++-- .../java/com/hippo/ehviewer/Settings.java | 3 +- .../com/hippo/ehviewer/client/EhEngine.java | 22 ++++----- .../ehviewer/download/DownloadService.java | 7 +-- .../ui/annotation/DrawerLifeCircle.java | 3 +- .../ui/annotation/ViewLifeCircle.java | 3 +- .../ui/annotation/WholeLifeCircle.java | 3 +- .../ui/fragment/SetSecurityFragment.java | 2 +- .../java/com/hippo/util/ExceptionUtils.java | 5 +- .../main/java/com/hippo/widget/Slider.java | 47 ++++++++----------- 10 files changed, 47 insertions(+), 56 deletions(-) diff --git a/app/src/main/java/com/hippo/ehviewer/Crash.java b/app/src/main/java/com/hippo/ehviewer/Crash.java index b4f021d86..f77de3d1b 100644 --- a/app/src/main/java/com/hippo/ehviewer/Crash.java +++ b/app/src/main/java/com/hippo/ehviewer/Crash.java @@ -36,6 +36,7 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; +import java.util.Arrays; public final class Crash { private Crash() { @@ -109,11 +110,8 @@ public final class Crash { fw.write("BOOTLOADER="); fw.write(Build.BOOTLOADER); fw.write("\r\n"); - fw.write("CPU_ABI="); - fw.write(Build.CPU_ABI); - fw.write("\r\n"); - fw.write("CPU_ABI2="); - fw.write(Build.CPU_ABI2); + fw.write("SUPPORTED_ABIS="); + fw.write(Arrays.toString(Build.SUPPORTED_ABIS)); fw.write("\r\n"); fw.write("DEVICE="); fw.write(Build.DEVICE); diff --git a/app/src/main/java/com/hippo/ehviewer/Settings.java b/app/src/main/java/com/hippo/ehviewer/Settings.java index 5a330cb01..0faae9a5e 100755 --- a/app/src/main/java/com/hippo/ehviewer/Settings.java +++ b/app/src/main/java/com/hippo/ehviewer/Settings.java @@ -19,8 +19,6 @@ package com.hippo.ehviewer; import android.content.Context; import android.content.SharedPreferences; import android.net.Uri; -import android.os.Build; -import android.preference.PreferenceManager; import android.util.Log; import android.view.Display; import android.view.WindowManager; @@ -28,6 +26,7 @@ import android.view.WindowManager; import androidx.annotation.DimenRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.preference.PreferenceManager; import com.hippo.ehviewer.client.EhConfig; import com.hippo.ehviewer.client.EhUtils; diff --git a/app/src/main/java/com/hippo/ehviewer/client/EhEngine.java b/app/src/main/java/com/hippo/ehviewer/client/EhEngine.java index 519631712..cca704094 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/EhEngine.java +++ b/app/src/main/java/com/hippo/ehviewer/client/EhEngine.java @@ -302,7 +302,7 @@ public class EhEngine { String origin = EhUrl.getOrigin(); Log.d(TAG, url); Request request = new EhRequestBuilder(url, referer, origin) - .post(RequestBody.create(MEDIA_TYPE_JSON, json.toString())) + .post(RequestBody.create(json.toString(), MEDIA_TYPE_JSON)) .build(); Call call = okHttpClient.newCall(request); @@ -395,7 +395,7 @@ public class EhEngine { json.put("gid", gid); json.put("token", token); json.put("rating", (int) Math.ceil(rating * 2)); - final RequestBody requestBody = RequestBody.create(MEDIA_TYPE_JSON, json.toString()); + final RequestBody requestBody = RequestBody.create(json.toString(), MEDIA_TYPE_JSON); String url = EhUrl.getApiUrl(); String referer = EhUrl.getGalleryDetailUrl(gid, token); String origin = EhUrl.getOrigin(); @@ -476,7 +476,7 @@ public class EhEngine { .put("method", "gtoken") .put("pagelist", new JSONArray().put( new JSONArray().put(gid).put(gtoken).put(page + 1))); - final RequestBody requestBody = RequestBody.create(MEDIA_TYPE_JSON, json.toString()); + final RequestBody requestBody = RequestBody.create(json.toString(), MEDIA_TYPE_JSON); String url = EhUrl.getApiUrl(); String referer = EhUrl.getReferer(); String origin = EhUrl.getOrigin(); @@ -823,7 +823,7 @@ public class EhEngine { json.put("token", token); json.put("comment_id", commentId); json.put("comment_vote", commentVote); - final RequestBody requestBody = RequestBody.create(MEDIA_TYPE_JSON, json.toString()); + final RequestBody requestBody = RequestBody.create(json.toString(), MEDIA_TYPE_JSON); String url = EhUrl.getApiUrl(); String referer = EhUrl.getReferer(); String origin = EhUrl.getOrigin(); @@ -864,7 +864,7 @@ public class EhEngine { json.put("token", token); json.put("tags", tags); json.put("vote", vote); - final RequestBody requestBody = RequestBody.create(MEDIA_TYPE_JSON, json.toString()); + final RequestBody requestBody = RequestBody.create(json.toString(), MEDIA_TYPE_JSON); String url = EhUrl.getApiUrl(); String referer = EhUrl.getReferer(); String origin = EhUrl.getOrigin(); @@ -904,29 +904,29 @@ public class EhEngine { builder.setType(MultipartBody.FORM); builder.addPart( Headers.of("Content-Disposition", "form-data; name=\"sfile\"; filename=\"a.jpg\""), - RequestBody.create(MEDIA_TYPE_JPEG, image) + RequestBody.create(image, MEDIA_TYPE_JPEG) ); if (uss) { builder.addPart( Headers.of("Content-Disposition", "form-data; name=\"fs_similar\""), - RequestBody.create(null, "on") + RequestBody.create("on", null) ); } if (osc) { builder.addPart( Headers.of("Content-Disposition", "form-data; name=\"fs_covers\""), - RequestBody.create(null, "on") + RequestBody.create("on", null) ); } if (se) { builder.addPart( Headers.of("Content-Disposition", "form-data; name=\"fs_exp\""), - RequestBody.create(null, "on") + RequestBody.create("on", null) ); } builder.addPart( Headers.of("Content-Disposition", "form-data; name=\"f_sfile\""), - RequestBody.create(null, "File Search") + RequestBody.create("File Search", null) ); String url = EhUrl.getImageSearchUrl(); String referer = EhUrl.getReferer(); @@ -1002,7 +1002,7 @@ public class EhEngine { json.put("page", index + 1); json.put("imgkey", pToken); json.put("showkey", showKey); - final RequestBody requestBody = RequestBody.create(MEDIA_TYPE_JSON, json.toString()); + final RequestBody requestBody = RequestBody.create(json.toString(), MEDIA_TYPE_JSON); String url = EhUrl.getApiUrl(); String referer = null; if (index > 0 && previousPToken != null) { diff --git a/app/src/main/java/com/hippo/ehviewer/download/DownloadService.java b/app/src/main/java/com/hippo/ehviewer/download/DownloadService.java index 55dd917e8..9e602fa81 100644 --- a/app/src/main/java/com/hippo/ehviewer/download/DownloadService.java +++ b/app/src/main/java/com/hippo/ehviewer/download/DownloadService.java @@ -31,6 +31,7 @@ import android.util.Log; import androidx.annotation.IntDef; import androidx.annotation.Nullable; import androidx.core.app.NotificationCompat; +import androidx.core.content.ContextCompat; import com.hippo.ehviewer.EhApplication; import com.hippo.ehviewer.R; @@ -216,7 +217,7 @@ public class DownloadService extends Service implements DownloadManager.Download .setOngoing(true) .setAutoCancel(false) .setCategory(NotificationCompat.CATEGORY_PROGRESS) - .setColor(getResources().getColor(R.color.colorPrimary)) + .setColor(ContextCompat.getColor(this, R.color.colorPrimary)) .setColorized(true) .addAction(R.drawable.ic_baseline_pause_24, getString(R.string.stat_download_action_stop_all), piStopAll) .setShowWhen(false) @@ -246,7 +247,7 @@ public class DownloadService extends Service implements DownloadManager.Download mDownloadedBuilder = new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID) .setSmallIcon(android.R.drawable.stat_sys_download_done) .setContentTitle(getString(R.string.stat_download_done_title)) - .setColor(getResources().getColor(R.color.colorPrimary)) + .setColor(ContextCompat.getColor(this, R.color.colorPrimary)) .setDeleteIntent(piClear) .setOngoing(false) .setAutoCancel(true) @@ -265,7 +266,7 @@ public class DownloadService extends Service implements DownloadManager.Download .setContentText(getString(R.string.stat_509_alert_title)) .setContentText(getString(R.string.stat_509_alert_text)) .setStyle(new NotificationCompat.BigTextStyle().bigText(getString(R.string.stat_509_alert_text))) - .setColor(getResources().getColor(R.color.colorPrimary)) + .setColor(ContextCompat.getColor(this, R.color.colorPrimary)) .setAutoCancel(true) .setOngoing(false) .setCategory(NotificationCompat.CATEGORY_ERROR); diff --git a/app/src/main/java/com/hippo/ehviewer/ui/annotation/DrawerLifeCircle.java b/app/src/main/java/com/hippo/ehviewer/ui/annotation/DrawerLifeCircle.java index 0c6f7568c..43c211151 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/annotation/DrawerLifeCircle.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/annotation/DrawerLifeCircle.java @@ -16,11 +16,12 @@ package com.hippo.ehviewer.ui.annotation; -import android.app.Fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.ViewGroup; +import androidx.fragment.app.Fragment; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/app/src/main/java/com/hippo/ehviewer/ui/annotation/ViewLifeCircle.java b/app/src/main/java/com/hippo/ehviewer/ui/annotation/ViewLifeCircle.java index 4120fbd1b..23291438e 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/annotation/ViewLifeCircle.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/annotation/ViewLifeCircle.java @@ -16,11 +16,12 @@ package com.hippo.ehviewer.ui.annotation; -import android.app.Fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.ViewGroup; +import androidx.fragment.app.Fragment; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/app/src/main/java/com/hippo/ehviewer/ui/annotation/WholeLifeCircle.java b/app/src/main/java/com/hippo/ehviewer/ui/annotation/WholeLifeCircle.java index efebf6151..f9aca5533 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/annotation/WholeLifeCircle.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/annotation/WholeLifeCircle.java @@ -17,9 +17,10 @@ package com.hippo.ehviewer.ui.annotation; import android.app.Activity; -import android.app.Fragment; import android.os.Bundle; +import androidx.fragment.app.Fragment; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/app/src/main/java/com/hippo/ehviewer/ui/fragment/SetSecurityFragment.java b/app/src/main/java/com/hippo/ehviewer/ui/fragment/SetSecurityFragment.java index caaa29dcf..8beeb740c 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/fragment/SetSecurityFragment.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/fragment/SetSecurityFragment.java @@ -44,7 +44,7 @@ public class SetSecurityFragment extends BaseFragment implements View.OnClickLis LockPatternUtils.stringToPattern(pattern)); } - if (BiometricManager.from(requireContext()).canAuthenticate() == BiometricManager.BIOMETRIC_SUCCESS) { + if (BiometricManager.from(requireContext()).canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_WEAK) == BiometricManager.BIOMETRIC_SUCCESS) { mFingerprint.setVisibility(View.VISIBLE); mFingerprint.setChecked(Settings.getEnableFingerprint()); } diff --git a/app/src/main/java/com/hippo/util/ExceptionUtils.java b/app/src/main/java/com/hippo/util/ExceptionUtils.java index 3e7ea59db..148ae22a0 100644 --- a/app/src/main/java/com/hippo/util/ExceptionUtils.java +++ b/app/src/main/java/com/hippo/util/ExceptionUtils.java @@ -23,8 +23,6 @@ import com.hippo.ehviewer.R; import com.hippo.ehviewer.client.exception.EhException; import com.hippo.network.StatusCodeException; -import org.apache.http.conn.ConnectTimeoutException; - import java.net.MalformedURLException; import java.net.ProtocolException; import java.net.SocketException; @@ -42,8 +40,7 @@ public final class ExceptionUtils { e.printStackTrace(); if (e instanceof MalformedURLException) { return GetText.getString(R.string.error_invalid_url); - } else if (e instanceof ConnectTimeoutException || - e instanceof SocketTimeoutException) { + } else if (e instanceof SocketTimeoutException) { return GetText.getString(R.string.error_timeout); } else if (e instanceof UnknownHostException) { return GetText.getString(R.string.error_unknown_host); diff --git a/app/src/main/java/com/hippo/widget/Slider.java b/app/src/main/java/com/hippo/widget/Slider.java index b6c3ee865..289a9217f 100644 --- a/app/src/main/java/com/hippo/widget/Slider.java +++ b/app/src/main/java/com/hippo/widget/Slider.java @@ -32,8 +32,8 @@ import android.view.Gravity; import android.view.MotionEvent; import android.view.View; import android.view.ViewConfiguration; -import android.widget.AbsoluteLayout; import android.widget.PopupWindow; +import android.widget.RelativeLayout; import androidx.annotation.NonNull; import androidx.appcompat.widget.AppCompatImageView; @@ -116,10 +116,10 @@ public class Slider extends View { mBubble = new BubbleView(context, textPaint); mBubble.setScaleX(0.0f); mBubble.setScaleY(0.0f); - AbsoluteLayout absoluteLayout = new AbsoluteLayout(context); - absoluteLayout.addView(mBubble); - absoluteLayout.setBackgroundDrawable(null); - mPopup = new PopupWindow(absoluteLayout); + RelativeLayout relativeLayout = new RelativeLayout(context); + relativeLayout.addView(mBubble); + relativeLayout.setBackgroundDrawable(null); + mPopup = new PopupWindow(relativeLayout); mPopup.setOutsideTouchable(false); mPopup.setTouchable(false); mPopup.setFocusable(false); @@ -143,28 +143,22 @@ public class Slider extends View { mProgressAnimation = new ValueAnimator(); mProgressAnimation.setInterpolator(AnimationUtils.FAST_SLOW_INTERPOLATOR); - mProgressAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(@NonNull ValueAnimator animation) { - float value = (Float) animation.getAnimatedValue(); - mDrawPercent = value; - mDrawProgress = Math.round(MathUtils.lerp((float) mStart, mEnd, value)); - updateBubblePosition(); - mBubble.setProgress(mDrawProgress); - invalidate(); - } + mProgressAnimation.addUpdateListener(animation -> { + float value = (Float) animation.getAnimatedValue(); + mDrawPercent = value; + mDrawProgress = Math.round(MathUtils.lerp((float) mStart, mEnd, value)); + updateBubblePosition(); + mBubble.setProgress(mDrawProgress); + invalidate(); }); mBubbleScaleAnimation = new ValueAnimator(); - mBubbleScaleAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(@NonNull ValueAnimator animation) { - float value = (Float) animation.getAnimatedValue(); - mDrawBubbleScale = value; - mBubble.setScaleX(value); - mBubble.setScaleY(value); - invalidate(); - } + mBubbleScaleAnimation.addUpdateListener(animation -> { + float value = (Float) animation.getAnimatedValue(); + mDrawBubbleScale = value; + mBubble.setScaleX(value); + mBubble.setScaleY(value); + invalidate(); }); } @@ -190,8 +184,7 @@ public class Slider extends View { mCharHeight + LayoutUtils.dp2pix(mContext, 8)); if (oldWidth != mBubbleWidth && oldHeight != mBubbleHeight) { - //noinspection deprecation - AbsoluteLayout.LayoutParams lp = (AbsoluteLayout.LayoutParams) mBubble.getLayoutParams(); + RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) mBubble.getLayoutParams(); lp.width = mBubbleWidth; lp.height = mBubbleHeight; mBubble.setLayoutParams(lp); @@ -386,6 +379,7 @@ public class Slider extends View { } } + @SuppressLint("ClickableViewAccessibility") @Override public boolean onTouchEvent(@NonNull MotionEvent event) { int action = event.getAction(); @@ -473,7 +467,6 @@ public class Slider extends View { private final Rect mRect = new Rect(); private String mProgressStr = ""; - @SuppressWarnings("deprecation") public BubbleView(Context context, Paint paint) { super(context); setImageResource(R.drawable.v_slider_bubble);