Merge pull request #2534 from AntennaPod/sdk_int_lt_14

Replace code for SDK version lower than 14
This commit is contained in:
H. Lehmann 2018-01-10 18:26:54 +01:00 committed by GitHub
commit 2c9582c947
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 49 additions and 130 deletions

View File

@ -39,7 +39,6 @@ import de.test.antennapod.util.syndication.feedgenerator.RSS2Generator;
* Utility methods for UI tests.
* Starts a web server that hosts feeds, episodes and images.
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class UITestUtils {
private static final String TAG = UITestUtils.class.getSimpleName();
@ -49,7 +48,6 @@ public class UITestUtils {
public static final int NUM_FEEDS = 5;
public static final int NUM_ITEMS_PER_FEED = 10;
public static final int HOME_VIEW = (Build.VERSION.SDK_INT >= 11) ? android.R.id.home : R.id.home;
public static final String TEST_FILE_NAME = "3sec.mp3";

View File

@ -41,10 +41,8 @@ public class PodcastApp extends Application {
.detectLeakedSqlLiteObjects()
.penaltyLog()
.penaltyDropBox();
if (Build.VERSION.SDK_INT >= 11) {
builder.detectActivityLeaks();
builder.detectLeakedClosableObjects();
}
builder.detectActivityLeaks();
builder.detectLeakedClosableObjects();
if(Build.VERSION.SDK_INT >= 16) {
builder.detectLeakedRegistrationObjects();
}

View File

@ -88,16 +88,10 @@ public class FeedInfoActivity extends AppCompatActivity {
public void onClick(View v) {
if(feed != null && feed.getDownload_url() != null) {
String url = feed.getDownload_url();
if (android.os.Build.VERSION.SDK_INT >= 11) {
ClipData clipData = ClipData.newPlainText(url, url);
android.content.ClipboardManager cm = (android.content.ClipboardManager) FeedInfoActivity.this
.getSystemService(Context.CLIPBOARD_SERVICE);
cm.setPrimaryClip(clipData);
} else {
android.text.ClipboardManager cm = (android.text.ClipboardManager) FeedInfoActivity.this
.getSystemService(Context.CLIPBOARD_SERVICE);
cm.setText(url);
}
ClipData clipData = ClipData.newPlainText(url, url);
android.content.ClipboardManager cm = (android.content.ClipboardManager) FeedInfoActivity.this
.getSystemService(Context.CLIPBOARD_SERVICE);
cm.setPrimaryClip(clipData);
Toast t = Toast.makeText(FeedInfoActivity.this, R.string.copied_url_msg, Toast.LENGTH_SHORT);
t.show();
}

View File

@ -112,9 +112,7 @@ public class ItemDescriptionFragment extends Fragment implements MediaplayerInfo
Bundle savedInstanceState) {
Log.d(TAG, "Creating view");
webvDescription = new WebView(getActivity().getApplicationContext());
if (Build.VERSION.SDK_INT >= 11) {
webvDescription.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
webvDescription.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
TypedArray ta = getActivity().getTheme().obtainStyledAttributes(new int[]
{android.R.attr.colorBackground});
int backgroundColor = ta.getColor(0, UserPreferences.getTheme() ==
@ -238,17 +236,11 @@ public class ItemDescriptionFragment extends Fragment implements MediaplayerInfo
ShareUtils.shareLink(getActivity(), selectedURL);
break;
case R.id.copy_url_item:
if (android.os.Build.VERSION.SDK_INT >= 11) {
ClipData clipData = ClipData.newPlainText(selectedURL,
selectedURL);
android.content.ClipboardManager cm = (android.content.ClipboardManager) getActivity()
.getSystemService(Context.CLIPBOARD_SERVICE);
cm.setPrimaryClip(clipData);
} else {
android.text.ClipboardManager cm = (android.text.ClipboardManager) getActivity()
.getSystemService(Context.CLIPBOARD_SERVICE);
cm.setText(selectedURL);
}
ClipData clipData = ClipData.newPlainText(selectedURL,
selectedURL);
android.content.ClipboardManager cm = (android.content.ClipboardManager) getActivity()
.getSystemService(Context.CLIPBOARD_SERVICE);
cm.setPrimaryClip(clipData);
Toast t = Toast.makeText(getActivity(),
R.string.copied_url_msg, Toast.LENGTH_SHORT);
t.show();

View File

@ -184,8 +184,7 @@ public class ItemFragment extends Fragment implements OnSwipeGesture {
}
webvDescription = (WebView) layout.findViewById(R.id.webvDescription);
if (UserPreferences.getTheme() == R.style.Theme_AntennaPod_Dark) {
if (Build.VERSION.SDK_INT >= 11
&& Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
webvDescription.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
webvDescription.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.black));
@ -483,17 +482,11 @@ public class ItemFragment extends Fragment implements OnSwipeGesture {
ShareUtils.shareLink(getActivity(), selectedURL);
break;
case R.id.copy_url_item:
if (android.os.Build.VERSION.SDK_INT >= 11) {
ClipData clipData = ClipData.newPlainText(selectedURL,
selectedURL);
android.content.ClipboardManager cm = (android.content.ClipboardManager) getActivity()
.getSystemService(Context.CLIPBOARD_SERVICE);
cm.setPrimaryClip(clipData);
} else {
android.text.ClipboardManager cm = (android.text.ClipboardManager) getActivity()
.getSystemService(Context.CLIPBOARD_SERVICE);
cm.setText(selectedURL);
}
ClipData clipData = ClipData.newPlainText(selectedURL,
selectedURL);
android.content.ClipboardManager cm = (android.content.ClipboardManager) getActivity()
.getSystemService(Context.CLIPBOARD_SERVICE);
cm.setPrimaryClip(clipData);
Toast t = Toast.makeText(getActivity(),
R.string.copied_url_msg, Toast.LENGTH_SHORT);
t.show();

View File

@ -350,16 +350,6 @@ public class ItemlistFragment extends ListFragment {
}
}
@Override
public void setListAdapter(ListAdapter adapter) {
// This workaround prevents the ListFragment from setting a list adapter when its state is restored.
// This is only necessary on API 10 because addFooterView throws an internal exception in this case.
if (Build.VERSION.SDK_INT > 10 || insideOnFragmentLoaded) {
super.setListAdapter(adapter);
}
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

View File

@ -269,10 +269,8 @@ public class PlaybackService extends MediaBrowserServiceCompat {
Intent.ACTION_HEADSET_PLUG));
registerReceiver(shutdownReceiver, new IntentFilter(
ACTION_SHUTDOWN_PLAYBACK_SERVICE));
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
registerReceiver(bluetoothStateUpdated, new IntentFilter(
BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED));
}
registerReceiver(bluetoothStateUpdated, new IntentFilter(
BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED));
registerReceiver(audioBecomingNoisy, new IntentFilter(
AudioManager.ACTION_AUDIO_BECOMING_NOISY));
registerReceiver(skipCurrentEpisodeReceiver, new IntentFilter(
@ -342,9 +340,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
unregisterReceiver(autoStateUpdated);
unregisterReceiver(headsetDisconnected);
unregisterReceiver(shutdownReceiver);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
unregisterReceiver(bluetoothStateUpdated);
}
unregisterReceiver(bluetoothStateUpdated);
unregisterReceiver(audioBecomingNoisy);
unregisterReceiver(skipCurrentEpisodeReceiver);
unregisterReceiver(pausePlayCurrentEpisodeReceiver);
@ -1196,21 +1192,19 @@ public class PlaybackService extends MediaBrowserServiceCompat {
@Override
public void run() {
Log.d(TAG, "Starting background work");
if (android.os.Build.VERSION.SDK_INT >= 11) {
if (info.playable != null) {
int iconSize = getResources().getDimensionPixelSize(
android.R.dimen.notification_large_icon_width);
try {
icon = Glide.with(PlaybackService.this)
.load(info.playable.getImageLocation())
.asBitmap()
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
.centerCrop()
.into(iconSize, iconSize)
.get();
} catch (Throwable tr) {
Log.e(TAG, "Error loading the media icon for the notification", tr);
}
if (info.playable != null) {
int iconSize = getResources().getDimensionPixelSize(
android.R.dimen.notification_large_icon_width);
try {
icon = Glide.with(PlaybackService.this)
.load(info.playable.getImageLocation())
.asBitmap()
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
.centerCrop()
.into(iconSize, iconSize)
.get();
} catch (Throwable tr) {
Log.e(TAG, "Error loading the media icon for the notification", tr);
}
}
if (icon == null) {
@ -1471,13 +1465,11 @@ public class PlaybackService extends MediaBrowserServiceCompat {
private final BroadcastReceiver bluetoothStateUpdated = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
if (TextUtils.equals(intent.getAction(), BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED)) {
int state = intent.getIntExtra(BluetoothA2dp.EXTRA_STATE, -1);
if (state == BluetoothA2dp.STATE_CONNECTED) {
Log.d(TAG, "Received bluetooth connection intent");
unpauseIfPauseOnDisconnect(true);
}
if (TextUtils.equals(intent.getAction(), BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED)) {
int state = intent.getIntExtra(BluetoothA2dp.EXTRA_STATE, -1);
if (state == BluetoothA2dp.STATE_CONNECTED) {
Log.d(TAG, "Received bluetooth connection intent");
unpauseIfPauseOnDisconnect(true);
}
}
}

View File

@ -350,9 +350,7 @@ public class PodDBAdapter {
SQLiteDatabase newDb = null;
try {
newDb = dbHelper.getWritableDatabase();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
newDb.enableWriteAheadLogging();
}
newDb.enableWriteAheadLogging();
} catch (SQLException ex) {
Log.e(TAG, Log.getStackTraceString(ex));
newDb = dbHelper.getReadableDatabase();
@ -473,11 +471,7 @@ public class PodDBAdapter {
try {
if (!db.inTransaction()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
db.beginTransactionNonExclusive();
} else {
db.beginTransaction();
}
db.beginTransactionNonExclusive();
startedTransaction = true;
}
@ -580,11 +574,7 @@ public class PodDBAdapter {
*/
public void setCompleteFeed(Feed... feeds) {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
db.beginTransactionNonExclusive();
} else {
db.beginTransaction();
}
db.beginTransactionNonExclusive();
for (Feed feed : feeds) {
setFeed(feed);
if (feed.getItems() != null) {
@ -665,11 +655,7 @@ public class PodDBAdapter {
public void setFeedItemlist(List<FeedItem> items) {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
db.beginTransactionNonExclusive();
} else {
db.beginTransaction();
}
db.beginTransactionNonExclusive();
for (FeedItem item : items) {
setFeedItem(item, true);
}
@ -684,11 +670,7 @@ public class PodDBAdapter {
public long setSingleFeedItem(FeedItem item) {
long result = 0;
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
db.beginTransactionNonExclusive();
} else {
db.beginTransaction();
}
db.beginTransactionNonExclusive();
result = setFeedItem(item, true);
db.setTransactionSuccessful();
} catch (SQLException e) {
@ -814,11 +796,7 @@ public class PodDBAdapter {
public void setFeedItemRead(int played, long itemId, long mediaId,
boolean resetMediaPosition) {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
db.beginTransactionNonExclusive();
} else {
db.beginTransaction();
}
db.beginTransactionNonExclusive();
ContentValues values = new ContentValues();
values.put(KEY_READ, played);
@ -846,11 +824,7 @@ public class PodDBAdapter {
*/
public void setFeedItemRead(int read, long... itemIds) {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
db.beginTransactionNonExclusive();
} else {
db.beginTransaction();
}
db.beginTransactionNonExclusive();
ContentValues values = new ContentValues();
for (long id : itemIds) {
values.clear();
@ -933,11 +907,7 @@ public class PodDBAdapter {
public void setFavorites(List<FeedItem> favorites) {
ContentValues values = new ContentValues();
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
db.beginTransactionNonExclusive();
} else {
db.beginTransaction();
}
db.beginTransactionNonExclusive();
db.delete(TABLE_NAME_FAVORITES, null, null);
for (int i = 0; i < favorites.size(); i++) {
FeedItem item = favorites.get(i);
@ -1000,11 +970,7 @@ public class PodDBAdapter {
public void setQueue(List<FeedItem> queue) {
ContentValues values = new ContentValues();
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
db.beginTransactionNonExclusive();
} else {
db.beginTransaction();
}
db.beginTransactionNonExclusive();
db.delete(TABLE_NAME_QUEUE, null, null);
for (int i = 0; i < queue.size(); i++) {
FeedItem item = queue.get(i);
@ -1066,11 +1032,7 @@ public class PodDBAdapter {
*/
public void removeFeed(Feed feed) {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
db.beginTransactionNonExclusive();
} else {
db.beginTransaction();
}
db.beginTransactionNonExclusive();
if (feed.getImage() != null) {
removeFeedImage(feed.getImage());
}