diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 7a79c26a3..e495e129a 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -75,9 +75,7 @@ android:label="@string/downloads_label" /> + android:launchMode="singleTask" > @@ -362,6 +360,7 @@ + diff --git a/res/layout-land/audioplayer_activity.xml b/res/layout-land/audioplayer_activity.xml new file mode 100644 index 000000000..521dbc68a --- /dev/null +++ b/res/layout-land/audioplayer_activity.xml @@ -0,0 +1,164 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/layout-land/mediaplayer_activity.xml b/res/layout-land/videoplayer_activity.xml similarity index 100% rename from res/layout-land/mediaplayer_activity.xml rename to res/layout-land/videoplayer_activity.xml diff --git a/res/layout/mediaplayer_activity.xml b/res/layout/audioplayer_activity.xml similarity index 100% rename from res/layout/mediaplayer_activity.xml rename to res/layout/audioplayer_activity.xml diff --git a/res/layout/cover_fragment.xml b/res/layout/cover_fragment.xml index f897d318c..9602f1ebc 100644 --- a/res/layout/cover_fragment.xml +++ b/res/layout/cover_fragment.xml @@ -11,6 +11,7 @@ android:layout_height="match_parent" android:layout_gravity="center" android:layout_marginTop="8dp" + android:layout_marginBottom="8dp" android:adjustViewBounds="true" android:scaleType="centerInside" /> diff --git a/src/de/danoeh/antennapod/activity/AudioplayerActivity.java b/src/de/danoeh/antennapod/activity/AudioplayerActivity.java index 2809d638f..6231e2a22 100644 --- a/src/de/danoeh/antennapod/activity/AudioplayerActivity.java +++ b/src/de/danoeh/antennapod/activity/AudioplayerActivity.java @@ -1,6 +1,7 @@ package de.danoeh.antennapod.activity; import android.content.Intent; +import android.content.res.Configuration; import android.content.res.TypedArray; import android.os.Bundle; import android.support.v4.app.Fragment; @@ -47,6 +48,8 @@ public class AudioplayerActivity extends MediaplayerActivity { private Fragment currentlyShownFragment; private int currentlyShownPosition = -1; + /** Saved and restored on orientation change. */ + private int savedPosition = -1; private TextView txtvTitle; private TextView txtvFeed; @@ -54,6 +57,37 @@ public class AudioplayerActivity extends MediaplayerActivity { private ImageButton butNavRight; private void resetFragmentView() { + FragmentTransaction fT = getSupportFragmentManager().beginTransaction(); + + if (coverFragment != null) { + if (AppConfig.DEBUG) + Log.d(TAG, "Removing cover fragment"); + fT.remove(coverFragment); + } + if (descriptionFragment != null) { + if (AppConfig.DEBUG) + Log.d(TAG, "Removing description fragment"); + fT.remove(descriptionFragment); + } + if (chapterFragment != null) { + if (AppConfig.DEBUG) + Log.d(TAG, "Removing chapter fragment"); + fT.remove(chapterFragment); + } + if (currentlyShownFragment != null) { + if (AppConfig.DEBUG) + Log.d(TAG, "Removing currently shown fragment"); + fT.remove(currentlyShownFragment); + } + for (int i = 0; i < detachedFragments.length; i++) { + Fragment f = detachedFragments[i]; + if (f != null) { + if (AppConfig.DEBUG) + Log.d(TAG, "Removing detached fragment"); + fT.remove(f); + } + } + fT.commit(); currentlyShownFragment = null; coverFragment = null; descriptionFragment = null; @@ -65,7 +99,7 @@ public class AudioplayerActivity extends MediaplayerActivity { @Override protected void onStop() { super.onStop(); - resetFragmentView(); + if (AppConfig.DEBUG) Log.d(TAG, "onStop"); } @@ -77,6 +111,33 @@ public class AudioplayerActivity extends MediaplayerActivity { detachedFragments = new Fragment[NUM_CONTENT_FRAGMENTS]; } + @Override + public void onConfigurationChanged(Configuration newConfig) { + + super.onConfigurationChanged(newConfig); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + outState.putInt("selectedPosition", currentlyShownPosition); + resetFragmentView(); + super.onSaveInstanceState(outState); + } + + @Override + protected void onRestoreInstanceState(Bundle savedInstanceState) { + super.onRestoreInstanceState(savedInstanceState); + if (AppConfig.DEBUG) + Log.d(TAG, "Restoring instance state"); + if (savedInstanceState != null) { + int p = savedInstanceState.getInt("selectedPosition", -1); + if (p != -1) { + savedPosition = p; + switchToFragment(savedPosition); + } + } + } + @Override protected void onResume() { super.onResume(); @@ -187,6 +248,7 @@ public class AudioplayerActivity extends MediaplayerActivity { ft.add(R.id.contentView, currentlyShownFragment); } ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); + ft.disallowAddToBackStack(); ft.commit(); updateNavButtonDrawable(); } @@ -211,8 +273,8 @@ public class AudioplayerActivity extends MediaplayerActivity { @Override public void run() { - ImageLoader.getInstance().loadThumbnailBitmap( - media, butNavLeft); + ImageLoader.getInstance().loadThumbnailBitmap(media, + butNavLeft); } }); butNavRight.setImageDrawable(drawables.getDrawable(1)); @@ -223,8 +285,8 @@ public class AudioplayerActivity extends MediaplayerActivity { @Override public void run() { - ImageLoader.getInstance().loadThumbnailBitmap( - media, butNavLeft); + ImageLoader.getInstance().loadThumbnailBitmap(media, + butNavLeft); } }); butNavRight.setImageDrawable(drawables.getDrawable(0)); @@ -291,7 +353,12 @@ public class AudioplayerActivity extends MediaplayerActivity { } if (currentlyShownPosition == -1) { - switchToFragment(POS_COVER); + if (savedPosition != -1) { + switchToFragment(savedPosition); + savedPosition = -1; + } else { + switchToFragment(POS_COVER); + } } if (currentlyShownFragment instanceof AudioplayerContentFragment) { ((AudioplayerContentFragment) currentlyShownFragment) @@ -333,4 +400,9 @@ public class AudioplayerActivity extends MediaplayerActivity { public void onDataSetChanged(Playable media); } + @Override + protected int getContentViewResourceId() { + return R.layout.audioplayer_activity; + } + } diff --git a/src/de/danoeh/antennapod/activity/MediaplayerActivity.java b/src/de/danoeh/antennapod/activity/MediaplayerActivity.java index 6d27a82e0..16b03809a 100644 --- a/src/de/danoeh/antennapod/activity/MediaplayerActivity.java +++ b/src/de/danoeh/antennapod/activity/MediaplayerActivity.java @@ -3,7 +3,6 @@ package de.danoeh.antennapod.activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; -import android.content.res.Configuration; import android.graphics.PixelFormat; import android.net.Uri; import android.os.Bundle; @@ -331,13 +330,6 @@ public abstract class MediaplayerActivity extends SherlockFragmentActivity controller.init(); } - @Override - public void onConfigurationChanged(Configuration newConfig) { - super.onConfigurationChanged(newConfig); - // ignore orientation change - - } - /** * Called by 'handleStatus()' when the PlaybackService is in the * AWAITING_VIDEO_SURFACE state. @@ -399,7 +391,7 @@ public abstract class MediaplayerActivity extends SherlockFragmentActivity } protected void setupGUI() { - setContentView(R.layout.mediaplayer_activity); + setContentView(getContentViewResourceId()); sbPosition = (SeekBar) findViewById(R.id.sbPosition); txtvPosition = (TextView) findViewById(R.id.txtvPosition); txtvLength = (TextView) findViewById(R.id.txtvLength); @@ -421,6 +413,8 @@ public abstract class MediaplayerActivity extends SherlockFragmentActivity } + protected abstract int getContentViewResourceId(); + void handleError(int errorCode) { final AlertDialog.Builder errorDialog = new AlertDialog.Builder(this); errorDialog.setTitle(R.string.error_label); diff --git a/src/de/danoeh/antennapod/activity/VideoplayerActivity.java b/src/de/danoeh/antennapod/activity/VideoplayerActivity.java index 2d9834a3e..b3567e417 100644 --- a/src/de/danoeh/antennapod/activity/VideoplayerActivity.java +++ b/src/de/danoeh/antennapod/activity/VideoplayerActivity.java @@ -287,4 +287,9 @@ public class VideoplayerActivity extends MediaplayerActivity implements videoOverlay.setVisibility(View.GONE); } + @Override + protected int getContentViewResourceId() { + return R.layout.videoplayer_activity; + } + }