Skip to content

Commit

Permalink
Bump min SDK to 24 (#990)
Browse files Browse the repository at this point in the history
* Bump min SDK to 24, remove version checks where no longer needed

* Clean up imports

* One last import cleanup
  • Loading branch information
bherbst authored Dec 13, 2024
1 parent d709dd4 commit bc8639c
Show file tree
Hide file tree
Showing 21 changed files with 48 additions and 190 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ android {
defaultConfig {
applicationId "com.thebluealliance.androidclient"
compileSdk 35
minSdkVersion 19
minSdkVersion 24
targetSdkVersion 35
versionCode versionNum
versionName version.toString()
Expand Down
10 changes: 0 additions & 10 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@

<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

<!-- This is not needed with android 6.0 (API 23) anymore, since we only need this to
interact with our own Authenticator to create a TBA system account
https://developer.android.com/reference/android/Manifest.permission.html#GET_ACCOUNTS -->
<uses-permission android:name="android.permission.GET_ACCOUNTS"
android:maxSdkVersion="22"/>

<!-- Used so we can save images taken with the camera -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18"/>

<application
android:name=".TbaAndroid"
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import android.text.SpannableStringBuilder;
import android.text.format.DateFormat;
import android.text.style.StyleSpan;
import android.util.ArrayMap;
import android.util.TypedValue;
import android.view.View;
import android.view.Window;
Expand Down Expand Up @@ -48,9 +47,7 @@
import java.text.Format;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
Expand Down Expand Up @@ -388,18 +385,6 @@ public static String sha256(String input) {
return hash;
}

public static boolean hasKApis() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
}

public static boolean hasLApis() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
}

public static boolean hasMApis() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
}

public static String getDeviceUUID(Context context) {
return Settings.Secure.getString(context.getApplicationContext().getContentResolver(), Settings.Secure.ANDROID_ID);
}
Expand Down Expand Up @@ -433,17 +418,6 @@ public static String getVersionNumber() {
}
}

/**
* {@link ArrayMap} is more memory efficient than {@link HashMap}, so prefer that if possible
*/
public static <K, V> Map<K, V> getMapForPlatform(Class<K> key, Class<V> value) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
return new ArrayMap<>();
} else {
return new HashMap<>();
}
}

/**
* On API 23+, this allows us to set the color of the status bar icons (either light or dark)
* to look better with the status bar background. If the background is light, the icons will be
Expand All @@ -456,10 +430,6 @@ public static <K, V> Map<K, V> getMapForPlatform(Class<K> key, Class<V> value) {
* @param lightBackground if the background of the status bar is light
*/
public static void setLightStatusBar(Window window, boolean lightBackground) {
if (!hasMApis()) {
return;
}

int vis = window.getDecorView().getSystemUiVisibility();
// Set light
if (lightBackground) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.thebluealliance.androidclient;

import android.os.Build;
import android.view.View;
import android.view.ViewTreeObserver;

Expand All @@ -23,11 +22,7 @@ public void onGlobalLayout() {
run.run();

ViewTreeObserver obs = view.getViewTreeObserver();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
obs.removeOnGlobalLayoutListener(this);
} else {
obs.removeGlobalOnLayoutListener(this);
}
obs.removeOnGlobalLayoutListener(this);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.widget.FrameLayout;
Expand Down Expand Up @@ -246,19 +245,10 @@ protected void openSettingsPanel(boolean animate) {
float finalRadius = (float) Math.sqrt(Math.pow(centerOfButtonOutsideX - mSettingsContainer.getLeft(), 2) + Math.pow(centerOfButtonOutsideY - mSettingsContainer.getTop(), 2));

Animator settingsPanelAnimator;
// Only show the circular reveal on API >= 5.0
mSettingsContainer.setVisibility(View.VISIBLE);
if (Utilities.hasLApis()) {
settingsPanelAnimator = ViewAnimationUtils.createCircularReveal(mSettingsContainer, centerOfButtonOutsideX, centerOfButtonOutsideY, 0, finalRadius);
settingsPanelAnimator.setDuration(ANIMATION_DURATION);
settingsPanelAnimator.setInterpolator(new DecelerateInterpolator());
} else {
settingsPanelAnimator = ValueAnimator.ofFloat(1, 0);
final int settingsContainerHeight = mSettingsContainer.getHeight();
((ValueAnimator) settingsPanelAnimator).addUpdateListener(animation -> mSettingsContainer.setTranslationY((float) settingsContainerHeight * (float) animation.getAnimatedValue()));
settingsPanelAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
settingsPanelAnimator.setDuration(ANIMATION_DURATION);
}
settingsPanelAnimator = ViewAnimationUtils.createCircularReveal(mSettingsContainer, centerOfButtonOutsideX, centerOfButtonOutsideY, 0, finalRadius);
settingsPanelAnimator.setDuration(ANIMATION_DURATION);
settingsPanelAnimator.setInterpolator(new DecelerateInterpolator());

ValueAnimator toggleButtonScaleUpAnimation = ValueAnimator.ofFloat(0, 1).setDuration(ANIMATION_DURATION);
toggleButtonScaleUpAnimation.addListener(new AnimatorListenerAdapter() {
Expand Down Expand Up @@ -343,25 +333,16 @@ protected void closeSettingsPanel(boolean animate) {
float finalRadius = (float) Math.sqrt(Math.pow(centerOfButtonOutsideX - mSettingsContainer.getLeft(), 2) + Math.pow(centerOfButtonOutsideY - mSettingsContainer.getTop(), 2));

Animator settingsPanelAnimator;
if (Utilities.hasLApis()) {
settingsPanelAnimator = ViewAnimationUtils.createCircularReveal(mSettingsContainer, centerOfButtonOutsideX, centerOfButtonOutsideY, finalRadius, 0);
settingsPanelAnimator.addListener(new AnimatorListenerAdapter() {
settingsPanelAnimator = ViewAnimationUtils.createCircularReveal(mSettingsContainer, centerOfButtonOutsideX, centerOfButtonOutsideY, finalRadius, 0);
settingsPanelAnimator.addListener(new AnimatorListenerAdapter() {

@Override
public void onAnimationEnd(Animator animation) {
mSettingsContainer.setVisibility(View.INVISIBLE);
}
});
settingsPanelAnimator.setDuration(ANIMATION_DURATION);
settingsPanelAnimator.setInterpolator(new AccelerateInterpolator());
} else {
settingsPanelAnimator = ValueAnimator.ofFloat(0, 1);
final int settingsContainerHeight = mSettingsContainer.getHeight();
((ValueAnimator) settingsPanelAnimator).addUpdateListener(animation -> mSettingsContainer.setTranslationY((float) settingsContainerHeight * (float) animation.getAnimatedValue()));
settingsPanelAnimator.setDuration(ANIMATION_DURATION);
settingsPanelAnimator.setInterpolator(new AccelerateInterpolator());
settingsPanelAnimator.start();
}
@Override
public void onAnimationEnd(Animator animation) {
mSettingsContainer.setVisibility(View.INVISIBLE);
}
});
settingsPanelAnimator.setDuration(ANIMATION_DURATION);
settingsPanelAnimator.setInterpolator(new AccelerateInterpolator());

ValueAnimator toggleButtonScaleDownAnimation = ValueAnimator.ofFloat(1, 0).setDuration(ANIMATION_DURATION);
toggleButtonScaleDownAnimation.addUpdateListener(animation -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
Expand Down Expand Up @@ -511,13 +510,7 @@ private File createImageFile() throws IOException {
}

private boolean checkHasStoragePermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
return PERMISSION_GRANTED == checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
} else {
// No runtime permissions before API 23, so everything is "granted" as it's declared
// in the app Manifest
return true;
}
return PERMISSION_GRANTED == checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
}

private void markMediaSnackbarAsDismissed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.thebluealliance.androidclient.R;
import com.thebluealliance.androidclient.Utilities;
import com.thebluealliance.androidclient.accounts.UpdateUserModelSettingsWorker;
import com.thebluealliance.androidclient.activities.BaseActivity;
import com.thebluealliance.androidclient.fragments.mytba.MyTBASettingsFragment;
Expand Down Expand Up @@ -85,9 +84,7 @@ public void onClick(View v) {
});
toolbar.setNavigationContentDescription(R.string.close);

if (Utilities.hasLApis()) {
getWindow().setStatusBarColor(getResources().getColor(R.color.accent_dark));
}
getWindow().setStatusBarColor(getResources().getColor(R.color.accent_dark));

saveModelPreferencesFab = (FloatingActionButton) findViewById(R.id.close_settings_button);
saveModelPreferencesFab.setOnClickListener(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable S
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
addPreferencesFromResource(R.xml.notification_preferences_lollipop);
}
addPreferencesFromResource(R.xml.notification_preferences_lollipop);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU) {
addPreferencesFromResource(R.xml.notification_preferences_tiramisu);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,7 @@ private static void setNotificationParams(Notification built, Context c, String
built.priority = Notification.PRIORITY_DEFAULT;
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
built.visibility = Notification.VISIBILITY_PUBLIC;
built.category = Notification.CATEGORY_SOCIAL;
}
built.visibility = Notification.VISIBILITY_PUBLIC;
built.category = Notification.CATEGORY_SOCIAL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
Expand Down Expand Up @@ -113,8 +112,7 @@ protected PendingIntent makeNotificationIntent(Context context, Intent activityI
clickIntent.setAction(NotificationChangedReceiver.ACTION_NOTIFICATION_CLICKED);
clickIntent.putExtra(NotificationChangedReceiver.EXTRA_INTENT, activityIntent);
clickIntent.putExtra(NotificationChangedReceiver.EXTRA_NOTIFICATION_ID, notificationId);
int intentFlags = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.FLAG_IMMUTABLE : 0;
return PendingIntent.getBroadcast(context, notificationId, clickIntent, intentFlags);
return PendingIntent.getBroadcast(context, notificationId, clickIntent, PendingIntent.FLAG_IMMUTABLE);
}

/**
Expand All @@ -124,8 +122,7 @@ public NotificationCompat.Builder getBaseBuilder(Context context) {
Intent dismissIntent = NotificationChangedReceiver.newIntent(context);
dismissIntent.setAction(NotificationChangedReceiver.ACTION_NOTIFICATION_DELETED);
dismissIntent.putExtra(NotificationChangedReceiver.EXTRA_NOTIFICATION_ID, getNotificationId());
int intentFlags = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.FLAG_IMMUTABLE : 0;
PendingIntent onDismiss = PendingIntent.getBroadcast(context, 0, dismissIntent, intentFlags);
PendingIntent onDismiss = PendingIntent.getBroadcast(context, 0, dismissIntent, PendingIntent.FLAG_IMMUTABLE);

NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender();
wearableExtender.setBackground(BitmapFactory.decodeResource(context.getResources(), R.drawable.tba_blue_background));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Build;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -101,21 +100,13 @@ public Notification buildNotification(Context context, FollowsChecker followsChe
int redScore = Match.getRedScore(alliances);
int blueScore = Match.getBlueScore(alliances);

// Boldify the team numbers that the user is following, but only if the system supports
// java 8 language features
CharSequence firstTeams;
CharSequence secondTeams;
// Boldify the team numbers that the user is following
ArrayList<String> redTeams = Match.teamNumbers(Match.getRedTeams(alliances));
ArrayList<String> blueTeams = Match.teamNumbers(Match.getBlueTeams(alliances));
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
Predicate<String> isFollowing = teamNumber -> followsChecker.followsTeam(context,
teamNumber, matchKey, NotificationTypes.MATCH_SCORE);
firstTeams = Utilities.boldNameList(redTeams, isFollowing);
secondTeams = Utilities.boldNameList(blueTeams, isFollowing);
} else {
firstTeams = Utilities.stringifyListOfStrings(context, redTeams);
secondTeams = Utilities.stringifyListOfStrings(context, blueTeams);
}
Predicate<String> isFollowing = teamNumber -> followsChecker.followsTeam(context,
teamNumber, matchKey, NotificationTypes.MATCH_SCORE);
CharSequence firstTeams = Utilities.boldNameList(redTeams, isFollowing);
CharSequence secondTeams = Utilities.boldNameList(blueTeams, isFollowing);

// Make sure the score string is formatted properly with the winning score first
String scoreString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Build;

import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
Expand Down Expand Up @@ -61,8 +60,7 @@ public Notification buildNotification(Context context, FollowsChecker followsChe

Intent dismissIntent = NotificationChangedReceiver.newIntent(context);
dismissIntent.setAction(NotificationChangedReceiver.ACTION_NOTIFICATION_DELETED);
int dismissFlags = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.FLAG_IMMUTABLE : 0;
PendingIntent onDismiss = PendingIntent.getBroadcast(context, 0, dismissIntent, dismissFlags);
PendingIntent onDismiss = PendingIntent.getBroadcast(context, 0, dismissIntent, PendingIntent.FLAG_IMMUTABLE);

return getBaseBuilder(context)
.setContentTitle(notificationTitle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Build;

import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
Expand Down Expand Up @@ -78,14 +77,10 @@ public Notification buildNotification(Context context, FollowsChecker followsChe

ArrayList<String> teamNumbers = Match.teamNumbers(mMatchTeamKeys);
CharSequence teamNumberString;
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
Predicate<String> isFollowing =
teamNumber -> followsChecker.followsTeam(context, teamNumber, mMatchKey,
NotificationTypes.MATCH_VIDEO);
teamNumberString = Utilities.boldNameList(teamNumbers, isFollowing);
} else {
teamNumberString = Utilities.stringifyListOfStrings(context, teamNumbers);
}
Predicate<String> isFollowing =
teamNumber -> followsChecker.followsTeam(context, teamNumber, mMatchKey,
NotificationTypes.MATCH_VIDEO);
teamNumberString = Utilities.boldNameList(teamNumbers, isFollowing);

String matchTitle = MatchHelper.getAbbrevMatchTitleFromMatchKey(context, mMatchKey);
String eventCode = EventHelper.getEventCode(mMatchKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,11 @@ public Notification buildNotification(Context context, FollowsChecker followsChe
scheduledStartTimeString = format.format(scheduledStartTime);
}

// Boldify the team numbers that the user is following, but only if the system supports
// java 8 language features
CharSequence redTeamNumbers;
CharSequence blueTeamNumbers;
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
Predicate<String> isFollowing = teamNumber -> followsChecker.followsTeam(context,
teamNumber, matchKey, NotificationTypes.UPCOMING_MATCH);
redTeamNumbers = Utilities.boldNameList(Arrays.asList(redTeams), isFollowing);
blueTeamNumbers = Utilities.boldNameList(Arrays.asList(blueTeams), isFollowing);
} else {
redTeamNumbers = Utilities.stringifyListOfStrings(context, Arrays.asList(redTeams));
blueTeamNumbers = Utilities.stringifyListOfStrings(context, Arrays.asList(blueTeams));
}
// Boldify the team numbers that the user is following
Predicate<String> isFollowing = teamNumber -> followsChecker.followsTeam(context,
teamNumber, matchKey, NotificationTypes.UPCOMING_MATCH);
CharSequence redTeamNumbers = Utilities.boldNameList(Arrays.asList(redTeams), isFollowing);
CharSequence blueTeamNumbers = Utilities.boldNameList(Arrays.asList(blueTeams), isFollowing);

String matchTitle = MatchHelper.getMatchTitleFromMatchKey(context, matchKey);
String matchAbbrevTitle = MatchHelper.getAbbrevMatchTitleFromMatchKey(context, matchKey);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.thebluealliance.androidclient.subscribers;

import com.thebluealliance.androidclient.Utilities;
import android.util.ArrayMap;

import com.thebluealliance.androidclient.comparators.AwardSortComparator;
import com.thebluealliance.androidclient.database.Database;
import com.thebluealliance.androidclient.eventbus.EventAwardsEvent;
Expand Down Expand Up @@ -40,7 +41,7 @@ public void setTeamKey(String teamKey) {
@Override
public void parseData() {
mDataToBind.clear();
Map<String, Team> teams = Utilities.getMapForPlatform(String.class, Team.class);
Map<String, Team> teams = new ArrayMap<String, Team>();
ArrayList<Award> sortedAwards = new ArrayList<>(mAPIData);
Collections.sort(sortedAwards, AWARD_COMPARATOR);
for (int i = 0; i < sortedAwards.size(); i++) {
Expand Down
Loading

0 comments on commit bc8639c

Please sign in to comment.