mirror of
https://github.com/ankidroid/Anki-Android.git
synced 2024-09-20 20:03:05 +02:00
lint: CompatV21
* Fix copyright header * Fix imports * Fix "'new File' is redundant" * Fix erroneous warning saying "deprecated" is redundant * Add KotlinCleanup for remaining issues
This commit is contained in:
parent
a0dea229bc
commit
ae0911d35c
@ -1,18 +1,18 @@
|
||||
/***************************************************************************************
|
||||
* Copyright (c) 2015 Timothy Rae <perceptualchaos2@gmail.com> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify it under *
|
||||
* the terms of the GNU General Public License as published by the Free Software *
|
||||
* Foundation; either version 3 of the License, or (at your option) any later *
|
||||
* version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License along with *
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
****************************************************************************************/
|
||||
/*
|
||||
* Copyright (c) 2015 Timothy Rae <perceptualchaos2@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation; either version 3 of the License, or (at your option) any later
|
||||
* version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.ichi2.compat;
|
||||
|
||||
@ -32,6 +32,7 @@ import android.widget.TimePicker;
|
||||
|
||||
import com.ichi2.async.ProgressSenderAndCancelListener;
|
||||
import com.ichi2.utils.FileUtil;
|
||||
import com.ichi2.utils.KotlinCleanup;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@ -43,10 +44,10 @@ import java.io.OutputStream;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.FileProvider;
|
||||
import timber.log.Timber;
|
||||
|
||||
/** Baseline implementation of {@link Compat}. Check {@link Compat}'s for more detail. */
|
||||
@KotlinCleanup("add extension method logging file.delete() failure")
|
||||
public class CompatV21 implements Compat {
|
||||
|
||||
// Update to PendingIntent.FLAG_MUTABLE once available (API 31)
|
||||
@ -61,7 +62,7 @@ public class CompatV21 implements Compat {
|
||||
|
||||
// Until API 23 the methods have "current" in the name
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
@SuppressWarnings({"deprecation", "RedundantSuppression"})
|
||||
public void setTime(TimePicker picker, int hour, int minute) {
|
||||
picker.setCurrentHour(hour);
|
||||
picker.setCurrentMinute(minute);
|
||||
@ -69,7 +70,7 @@ public class CompatV21 implements Compat {
|
||||
|
||||
// Until API 26 just specify time, after that specify effect also
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
@SuppressWarnings({"deprecation", "RedundantSuppression"})
|
||||
public void vibrate(Context context, long durationMillis) {
|
||||
Vibrator vibratorManager = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
if (vibratorManager != null) {
|
||||
@ -79,14 +80,14 @@ public class CompatV21 implements Compat {
|
||||
|
||||
// Until API31 the MediaRecorder constructor was default, ignoring the Context
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
@SuppressWarnings({"deprecation", "RedundantSuppression"})
|
||||
public MediaRecorder getMediaRecorder(Context context) {
|
||||
return new MediaRecorder();
|
||||
}
|
||||
|
||||
// Until API 26 do the copy using streams
|
||||
public void copyFile(@NonNull String source, @NonNull String target) throws IOException {
|
||||
try (InputStream fileInputStream = new FileInputStream(new File(source))) {
|
||||
try (InputStream fileInputStream = new FileInputStream(source)) {
|
||||
copyFile(fileInputStream, target);
|
||||
} catch (IOException e) {
|
||||
Timber.e(e, "copyFile() error copying source %s", source);
|
||||
@ -98,7 +99,7 @@ public class CompatV21 implements Compat {
|
||||
public long copyFile(@NonNull String source, @NonNull OutputStream target) throws IOException {
|
||||
long count;
|
||||
|
||||
try (InputStream fileInputStream = new FileInputStream(new File(source))) {
|
||||
try (InputStream fileInputStream = new FileInputStream(source)) {
|
||||
count = copyFile(fileInputStream, target);
|
||||
} catch (IOException e) {
|
||||
Timber.e(e, "copyFile() error copying source %s", source);
|
||||
@ -198,22 +199,22 @@ public class CompatV21 implements Compat {
|
||||
|
||||
// Until API 23 the methods have "current" in the name
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
@SuppressWarnings({"deprecation", "RedundantSuppression"})
|
||||
public int getHour(TimePicker picker) { return picker.getCurrentHour(); }
|
||||
|
||||
// Until API 23 the methods have "current" in the name
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
@SuppressWarnings({"deprecation", "RedundantSuppression"})
|
||||
public int getMinute(TimePicker picker) { return picker.getCurrentMinute(); }
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
@SuppressWarnings({"deprecation", "RedundantSuppression"})
|
||||
public boolean hasVideoThumbnail(@NonNull String path) {
|
||||
return ThumbnailUtils.createVideoThumbnail(path, MediaStore.Images.Thumbnails.MINI_KIND) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
@SuppressWarnings({"deprecation", "RedundantSuppression"})
|
||||
public void requestAudioFocus(AudioManager audioManager, AudioManager.OnAudioFocusChangeListener audioFocusChangeListener,
|
||||
@Nullable AudioFocusRequest audioFocusRequest) {
|
||||
audioManager.requestAudioFocus(audioFocusChangeListener, AudioManager.STREAM_MUSIC,
|
||||
@ -221,7 +222,7 @@ public class CompatV21 implements Compat {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
@SuppressWarnings({"deprecation", "RedundantSuppression"})
|
||||
public void abandonAudioFocus(AudioManager audioManager, AudioManager.OnAudioFocusChangeListener audioFocusChangeListener,
|
||||
@Nullable AudioFocusRequest audioFocusRequest) {
|
||||
audioManager.abandonAudioFocus(audioFocusChangeListener);
|
||||
|
Loading…
Reference in New Issue
Block a user