purge all code blocks for < android-14, except installer stuff

The installer stuff should hopefully become a standalone library, so that
might as well keep the old support in place.

#1379
This commit is contained in:
Hans-Christoph Steiner 2018-04-19 13:00:10 +02:00
parent e923427232
commit 2a9c3fee5b
18 changed files with 70 additions and 214 deletions

View File

@ -7,7 +7,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;
@ -511,11 +510,6 @@ public final class AppUpdateStatusManager {
}
break;
}
if (Build.VERSION.SDK_INT < 11 && entry.intent == null) {
Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
entry.intent = PendingIntent.getActivity(context, 0, intent, 0);
}
}
/**

View File

@ -16,16 +16,10 @@ public class NfcHelper {
private static final String TAG = "NfcHelper";
@TargetApi(14)
private static NfcAdapter getAdapter(Context context) {
if (Build.VERSION.SDK_INT < 14) {
return null;
}
return NfcAdapter.getDefaultAdapter(context.getApplicationContext());
}
@TargetApi(14)
public static boolean setPushMessage(Activity activity, Uri toShare) {
NfcAdapter adapter = getAdapter(activity);
if (adapter != null) {

View File

@ -46,12 +46,8 @@ public class NfcNotEnabledActivity extends AppCompatActivity {
final Intent intent = new Intent();
if (Build.VERSION.SDK_INT >= 16) {
doOnJellybean(intent);
} else if (Build.VERSION.SDK_INT >= 14) {
doOnIceCreamSandwich(intent);
} else {
// no NFC support, so nothing to do here
finish();
return;
doOnIceCreamSandwich(intent);
}
startActivity(intent);
finish();

View File

@ -117,7 +117,7 @@ class NotificationHelper {
}
private boolean useStackedNotifications() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N;
return Build.VERSION.SDK_INT >= 24;
}
/**
@ -481,15 +481,8 @@ class NotificationHelper {
}
private Point getLargeIconSize() {
int w;
int h;
if (Build.VERSION.SDK_INT >= 11) {
w = context.getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width);
h = context.getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_height);
} else {
w = context.getResources().getDimensionPixelSize(android.R.dimen.app_icon_size);
h = w;
}
int w = context.getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width);
int h = context.getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_height);
return new Point(w, h);
}

View File

@ -5,11 +5,9 @@ import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.os.AsyncTask;
import android.os.Build;
import android.util.Log;
import android.view.Display;
import android.widget.ImageView;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.WriterException;
import com.google.zxing.encode.Contents;
@ -39,15 +37,9 @@ public class QrGenAsyncTask extends AsyncTask<String, Void, Void> {
Display display = activity.getWindowManager().getDefaultDisplay();
Point outSize = new Point();
int x, y, qrCodeDimension;
/* lame, got to use both the new and old APIs here */
if (Build.VERSION.SDK_INT >= 13) {
display.getSize(outSize);
x = outSize.x;
y = outSize.y;
} else {
x = display.getWidth();
y = display.getHeight();
}
display.getSize(outSize);
x = outSize.x;
y = outSize.y;
if (x < y) {
qrCodeDimension = x;
} else {

View File

@ -1,49 +0,0 @@
package org.fdroid.fdroid.compat;
import android.annotation.TargetApi;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.os.Build;
public abstract class ClipboardCompat {
public abstract String getText();
public static ClipboardCompat create(Context context) {
if (Build.VERSION.SDK_INT >= 11) {
return new HoneycombClipboard(context);
}
return new OldClipboard();
}
@TargetApi(11)
private static class HoneycombClipboard extends ClipboardCompat {
private final ClipboardManager manager;
HoneycombClipboard(Context context) {
this.manager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
}
@Override
public String getText() {
CharSequence text = null;
if (manager.hasPrimaryClip()) {
ClipData data = manager.getPrimaryClip();
if (data.getItemCount() > 0) {
text = data.getItemAt(0).getText();
}
}
return text != null ? text.toString() : null;
}
}
private static class OldClipboard extends ClipboardCompat {
@Override
public String getText() {
return null;
}
}
}

View File

@ -1,21 +0,0 @@
package org.fdroid.fdroid.compat;
import android.net.Uri;
import android.os.Build;
public class UriCompat {
/**
* Uri#getQueryParameter(String) has the following warning:
*
* > Prior to Ice Cream Sandwich, this decoded the '+' character as '+' rather than ' '.
*/
public static String getQueryParameter(Uri uri, String key) {
String value = uri.getQueryParameter(key);
if (value != null && Build.VERSION.SDK_INT < 14) {
value = value.replaceAll("\\+", " ");
}
return value;
}
}

View File

@ -1,9 +1,6 @@
package org.fdroid.fdroid.net.bluetooth;
import android.annotation.TargetApi;
import android.bluetooth.BluetoothSocket;
import android.os.Build;
import org.fdroid.fdroid.Utils;
import java.io.BufferedInputStream;
@ -32,15 +29,14 @@ public class BluetoothConnection {
return output;
}
@TargetApi(14)
public void open() throws IOException {
if (Build.VERSION.SDK_INT >= 14 && !socket.isConnected()) {
if (!socket.isConnected()) {
// Server sockets will already be connected when they are passed to us,
// client sockets require us to call connect().
socket.connect();
}
input = new BufferedInputStream(socket.getInputStream());
input = new BufferedInputStream(socket.getInputStream());
output = new BufferedOutputStream(socket.getOutputStream());
Utils.debugLog(TAG, "Opened connection to Bluetooth device");
}

View File

@ -20,6 +20,8 @@
package org.fdroid.fdroid.views;
import android.annotation.SuppressLint;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
@ -55,7 +57,6 @@ import org.fdroid.fdroid.FDroidApp;
import org.fdroid.fdroid.R;
import org.fdroid.fdroid.UpdateService;
import org.fdroid.fdroid.Utils;
import org.fdroid.fdroid.compat.ClipboardCompat;
import org.fdroid.fdroid.compat.CursorAdapterCompat;
import org.fdroid.fdroid.data.NewRepoConfig;
import org.fdroid.fdroid.data.Repo;
@ -158,13 +159,24 @@ public class ManageReposActivity extends AppCompatActivity
return super.onOptionsItemSelected(item);
}
public String getPrimaryClipAsText() {
CharSequence text = null;
ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
if (clipboardManager.hasPrimaryClip()) {
ClipData data = clipboardManager.getPrimaryClip();
if (data.getItemCount() > 0) {
text = data.getItemAt(0).getText();
}
}
return text != null ? text.toString() : null;
}
private void showAddRepo() {
/*
* If there is text in the clipboard, and it looks like a URL, use that.
* Otherwise use "https://" as default repo string.
*/
ClipboardCompat clipboard = ClipboardCompat.create(this);
String text = clipboard.getText();
String text = getPrimaryClipAsText();
String fingerprint = null;
String username = null;
String password = null;

View File

@ -2,14 +2,12 @@ package org.fdroid.fdroid.views;
import android.content.Context;
import android.database.Cursor;
import android.os.Build;
import android.support.v4.widget.CursorAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.TextView;
import org.fdroid.fdroid.R;
import org.fdroid.fdroid.data.Repo;
@ -24,10 +22,7 @@ public class RepoAdapter extends CursorAdapter {
private EnabledListener enabledListener;
public static RepoAdapter create(Context context, Cursor cursor, int flags) {
if (Build.VERSION.SDK_INT >= 11) {
return new RepoAdapter(context, cursor, flags);
}
return new RepoAdapter(context, cursor);
return new RepoAdapter(context, cursor, flags);
}
private RepoAdapter(Context context, Cursor c, int flags) {

View File

@ -223,9 +223,7 @@ public class RepoDetailsActivity extends AppCompatActivity {
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
if (Build.VERSION.SDK_INT >= 14) {
prepareNfcMenuItems(menu);
}
prepareNfcMenuItems(menu);
return true;
}

View File

@ -3,7 +3,6 @@ package org.fdroid.fdroid.views;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
@ -65,10 +64,8 @@ public class ScreenShotsActivity extends AppCompatActivity {
viewPager.setAdapter(adapter);
viewPager.setCurrentItem(startPosition);
if (Build.VERSION.SDK_INT >= 11) {
// display some nice animation while swiping
viewPager.setPageTransformer(true, new DepthPageTransformer());
}
// display some nice animation while swiping
viewPager.setPageTransformer(true, new DepthPageTransformer());
}
@Override

View File

@ -1,7 +1,6 @@
package org.fdroid.fdroid.views.apps;
import android.animation.ValueAnimator;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
@ -10,7 +9,6 @@ import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.graphics.PorterDuff;
import android.os.Build;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@ -20,12 +18,10 @@ import android.support.v7.widget.AppCompatImageView;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
import org.fdroid.fdroid.R;
import java.util.Random;
@ -34,7 +30,7 @@ import java.util.Random;
* A feature image can have a {@link android.graphics.drawable.Drawable} or a {@link Palette}. If
* a Drawable is available, then it will draw that, otherwise it will attempt to fall back to the
* Palette you gave it. If a Palette is given, it will draw a series of triangles like so:
*
* <p>
* +_----+----_+_----+----_+
* | \_ | _/ | \_ | _/ |
* | \_|_/ | \_|_/ |
@ -42,12 +38,12 @@ import java.util.Random;
* | \_ | _/ | \_ | _/ |
* | \_|_/ | \_|_/ |
* +-----+-----+-----+-----+
*
* <p>
* where each triangle is filled with one of two variations of the {@link Palette#getDominantColor(int)}
* that is chosen randomly. The randomness is first seeded with the colour that has been selected.
* This is so that if this repaints itself in the future, it will have the same unique pattern rather
* than picking a new random pattern each time.
*
* <p>
* It is suggested that you obtain the Palette from the icon of an app.
*/
@SuppressWarnings("LineLength")
@ -143,12 +139,7 @@ public class FeatureImage extends AppCompatImageView {
private int currentAlpha = 255;
private ValueAnimator alphaAnimator = null;
@TargetApi(11)
private void animateColourChange() {
if (Build.VERSION.SDK_INT < 11) {
return;
}
if (alphaAnimator == null) {
alphaAnimator = ValueAnimator.ofInt(0, 255);
} else {
@ -294,12 +285,15 @@ public class FeatureImage extends AppCompatImageView {
private abstract static class ImageLoadingAdapter implements ImageLoadingListener {
@Override
public void onLoadingStarted(String imageUri, View view) { }
public void onLoadingStarted(String imageUri, View view) {
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) { }
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
}
@Override
public void onLoadingCancelled(String imageUri, View view) { }
public void onLoadingCancelled(String imageUri, View view) {
}
}
}

View File

@ -28,7 +28,6 @@ import org.fdroid.fdroid.Preferences;
import org.fdroid.fdroid.R;
import org.fdroid.fdroid.UpdateService;
import org.fdroid.fdroid.Utils;
import org.fdroid.fdroid.compat.UriCompat;
import org.fdroid.fdroid.data.NewRepoConfig;
import org.fdroid.fdroid.views.ManageReposActivity;
import org.fdroid.fdroid.views.apps.AppListActivity;
@ -232,29 +231,29 @@ public class MainActivity extends AppCompatActivity implements BottomNavigationB
packageName = data.getLastPathSegment();
} else if (path.startsWith("/repository/browse")) {
// http://f-droid.org/repository/browse?fdfilter=search+query
query = UriCompat.getQueryParameter(data, "fdfilter");
query = data.getQueryParameter("fdfilter");
// http://f-droid.org/repository/browse?fdid=packageName
packageName = UriCompat.getQueryParameter(data, "fdid");
packageName = data.getQueryParameter("fdid");
} else if ("/app".equals(data.getPath()) || "/packages".equals(data.getPath())) {
packageName = null;
}
break;
case "details":
// market://details?id=app.id
packageName = UriCompat.getQueryParameter(data, "id");
packageName = data.getQueryParameter("id");
break;
case "search":
// market://search?q=query
query = UriCompat.getQueryParameter(data, "q");
query = data.getQueryParameter("q");
break;
case "play.google.com":
if (path.startsWith("/store/apps/details")) {
// http://play.google.com/store/apps/details?id=app.id
packageName = UriCompat.getQueryParameter(data, "id");
packageName = data.getQueryParameter("id");
} else if (path.startsWith("/store/search")) {
// http://play.google.com/store/search?q=foo
query = UriCompat.getQueryParameter(data, "q");
query = data.getQueryParameter("q");
}
break;
case "apps":
@ -262,8 +261,8 @@ public class MainActivity extends AppCompatActivity implements BottomNavigationB
case "www.amazon.com":
// amzn://apps/android?p=app.id
// http://amazon.com/gp/mas/dl/android?s=app.id
packageName = UriCompat.getQueryParameter(data, "p");
query = UriCompat.getQueryParameter(data, "s");
packageName = data.getQueryParameter("p");
query = data.getQueryParameter("s");
break;
}
} else if ("fdroid.app".equals(scheme)) {

View File

@ -11,7 +11,6 @@ import android.content.res.Resources;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
@ -23,16 +22,14 @@ import android.support.v4.preference.PreferenceFragment;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.util.TypedValue;
import info.guardianproject.panic.Panic;
import info.guardianproject.panic.PanicResponder;
import org.fdroid.fdroid.Preferences;
import org.fdroid.fdroid.R;
import org.fdroid.fdroid.views.hiding.HidingManager;
import java.util.ArrayList;
import info.guardianproject.panic.Panic;
import info.guardianproject.panic.PanicResponder;
public class PanicPreferencesFragment extends PreferenceFragment implements SharedPreferences
.OnSharedPreferenceChangeListener {
@ -148,16 +145,16 @@ public class PanicPreferencesFragment extends PreferenceFragment implements Shar
// no panic app set
prefApp.setValue(Panic.PACKAGE_NAME_NONE);
prefApp.setSummary(getString(R.string.panic_app_setting_summary));
if (Build.VERSION.SDK_INT >= 11) {
prefApp.setIcon(null); // otherwise re-setting view resource doesn't work
Drawable icon = ContextCompat.getDrawable(getContext(), R.drawable.ic_cancel);
TypedValue typedValue = new TypedValue();
Resources.Theme theme = getContext().getTheme();
theme.resolveAttribute(R.attr.appListItem, typedValue, true);
@ColorInt int color = typedValue.data;
icon.setColorFilter(color, PorterDuff.Mode.SRC_IN);
prefApp.setIcon(icon);
}
prefApp.setIcon(null); // otherwise re-setting view resource doesn't work
Drawable icon = ContextCompat.getDrawable(getContext(), R.drawable.ic_cancel);
TypedValue typedValue = new TypedValue();
Resources.Theme theme = getContext().getTheme();
theme.resolveAttribute(R.attr.appListItem, typedValue, true);
@ColorInt int color = typedValue.data;
icon.setColorFilter(color, PorterDuff.Mode.SRC_IN);
prefApp.setIcon(icon);
// disable destructive panic actions
prefHide.setEnabled(false);
} else {
@ -165,9 +162,7 @@ public class PanicPreferencesFragment extends PreferenceFragment implements Shar
try {
prefApp.setValue(packageName);
prefApp.setSummary(pm.getApplicationLabel(pm.getApplicationInfo(packageName, 0)));
if (Build.VERSION.SDK_INT >= 11) {
prefApp.setIcon(pm.getApplicationIcon(packageName));
}
prefApp.setIcon(pm.getApplicationIcon(packageName));
prefHide.setEnabled(true);
} catch (PackageManager.NameNotFoundException e) {
// revert back to no app, just to be safe

View File

@ -7,7 +7,6 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.LightingColorFilter;
import android.net.Uri;
import android.os.Build;
import android.support.annotation.ColorRes;
import android.support.annotation.NonNull;
import android.support.v4.content.LocalBroadcastManager;
@ -148,20 +147,18 @@ public class WifiQrView extends ScrollView implements SwapWorkflowActivity.Inner
qrUrlBuilder.append(sharingUri.getPath());
boolean first = true;
if (Build.VERSION.SDK_INT > 10) {
Set<String> names = sharingUri.getQueryParameterNames();
for (String name : names) {
if (!"ssid".equals(name)) {
if (first) {
qrUrlBuilder.append('?');
first = false;
} else {
qrUrlBuilder.append('&');
}
qrUrlBuilder.append(name.toUpperCase(Locale.ENGLISH));
qrUrlBuilder.append('=');
qrUrlBuilder.append(sharingUri.getQueryParameter(name).toUpperCase(Locale.ENGLISH));
Set<String> names = sharingUri.getQueryParameterNames();
for (String name : names) {
if (!"ssid".equals(name)) {
if (first) {
qrUrlBuilder.append('?');
first = false;
} else {
qrUrlBuilder.append('&');
}
qrUrlBuilder.append(name.toUpperCase(Locale.ENGLISH));
qrUrlBuilder.append('=');
qrUrlBuilder.append(sharingUri.getQueryParameter(name).toUpperCase(Locale.ENGLISH));
}
}

View File

@ -4,7 +4,7 @@ import android.content.Context;
public abstract class CameraCharacteristicsChecker {
public static CameraCharacteristicsChecker getInstance(final Context context) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
if (android.os.Build.VERSION.SDK_INT >= 21) {
return new CameraCharacteristicsMinApiLevel21(context);
} else {
return new CameraCharacteristicsMaxApiLevel20();

View File

@ -1,26 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="SwapTheme.Wizard" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorButtonNormal">@color/swap_bright_blue</item>
<item name="android:actionBarStyle">@style/Widget.AppCompat.ActionBar.Solid</item>
<item name="android:actionButtonStyle">@style/SwapTheme.Wizard.ActionButton</item>
</style>
<style name="AlertDialogBaseThemeDark" parent="Theme.AppCompat.Dialog.Alert">
<item name="android:windowMinWidthMajor">@android:dimen/dialog_min_width_major</item>
<item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_minor</item>
<item name="android:actionOverflowButtonStyle">@style/ActionButtonOverflow</item>
</style>
<style name="AlertDialogBaseThemeLight" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:windowMinWidthMajor">@android:dimen/dialog_min_width_major</item>
<item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_minor</item>
<item name="android:actionOverflowButtonStyle">@style/ActionButtonOverflow</item>
</style>
<style name="AppDetailsLink" parent="AppDetailsLinkBase">
<item name="android:background">?android:attr/selectableItemBackground</item>
</style>
</resources>