summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2012-07-01 19:21:22 +0200
committerdaniel oeh <daniel.oeh@gmail.com>2012-07-01 19:21:22 +0200
commit6bde1e99d112b0fd111e0f3e657cb88f71294391 (patch)
tree394e93228c27a41e8255773c87ae0be808a1629b
parent3932e09089032fc91ce2d361443e5c3df5de6b41 (diff)
downloadAntennaPod-6bde1e99d112b0fd111e0f3e657cb88f71294391.zip
MediaPlayerActivity now handles orientation changes correctly
-rw-r--r--src/de/podfetcher/activity/MediaplayerActivity.java29
-rw-r--r--src/de/podfetcher/fragment/ItemDescriptionFragment.java38
2 files changed, 43 insertions, 24 deletions
diff --git a/src/de/podfetcher/activity/MediaplayerActivity.java b/src/de/podfetcher/activity/MediaplayerActivity.java
index 5e9f90aa5..6353f8ad8 100644
--- a/src/de/podfetcher/activity/MediaplayerActivity.java
+++ b/src/de/podfetcher/activity/MediaplayerActivity.java
@@ -127,6 +127,7 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
setContentView(R.layout.mediaplayer_activity);
}
setupGUI();
+ handleStatus();
}
@@ -144,9 +145,10 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
super.onCreate(savedInstanceState);
Log.d(TAG, "Creating Activity");
orientation = getResources().getConfiguration().orientation;
+ manager = FeedManager.getInstance();
getWindow().setFormat(PixelFormat.TRANSPARENT);
this.setContentView(R.layout.mediaplayer_activity);
- manager = FeedManager.getInstance();
+
setupGUI();
bindToService();
}
@@ -272,7 +274,7 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
getSupportActionBar().setTitle(
media.getItem().getFeed().getTitle());
pagerAdapter.notifyDataSetChanged();
-
+
}
txtvPosition.setText(Converter.getDurationStringLong((player
@@ -389,16 +391,27 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
public void onServiceConnected(ComponentName className, IBinder service) {
playbackService = ((PlaybackService.LocalBinder) service)
.getService();
+ int requestedOrientation;
status = playbackService.getStatus();
media = playbackService.getMedia();
registerReceiver(statusUpdate, new IntentFilter(
PlaybackService.ACTION_PLAYER_STATUS_CHANGED));
if (playbackService.isPlayingVideo()) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
+ requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
+ requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
}
- handleStatus();
+ // check if orientation is correct
+ if ((requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE && orientation == Configuration.ORIENTATION_LANDSCAPE)
+ || (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT && orientation == Configuration.ORIENTATION_PORTRAIT)) {
+ Log.d(TAG, "Orientation correct");
+ handleStatus();
+ } else {
+ Log.d(TAG, "Orientation incorrect, waiting for orientation change");
+ }
+
Log.d(TAG, "Connection to Service established");
}
@@ -474,7 +487,8 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
holderCreated = false;
}
- public static class MediaPlayerPagerAdapter extends FragmentStatePagerAdapter {
+ public static class MediaPlayerPagerAdapter extends
+ FragmentStatePagerAdapter {
private int numItems;
private MediaplayerActivity activity;
@@ -494,7 +508,8 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
if (activity.media != null) {
switch (position) {
case POS_COVER:
- activity.coverFragment = CoverFragment.newInstance(activity.media.getItem());
+ activity.coverFragment = CoverFragment
+ .newInstance(activity.media.getItem());
return activity.coverFragment;
case POS_DESCR:
activity.descriptionFragment = ItemDescriptionFragment
@@ -524,10 +539,10 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
public int getCount() {
return numItems;
}
-
+
@Override
public int getItemPosition(Object object) {
- return POSITION_NONE;
+ return POSITION_NONE;
}
}
diff --git a/src/de/podfetcher/fragment/ItemDescriptionFragment.java b/src/de/podfetcher/fragment/ItemDescriptionFragment.java
index 0c4f4f9b0..205a40170 100644
--- a/src/de/podfetcher/fragment/ItemDescriptionFragment.java
+++ b/src/de/podfetcher/fragment/ItemDescriptionFragment.java
@@ -22,16 +22,16 @@ import de.podfetcher.feed.FeedManager;
/** Displays the description of a FeedItem in a Webview. */
public class ItemDescriptionFragment extends SherlockFragment {
-
+
private static final String TAG = "ItemDescriptionFragment";
private static final String ARG_FEED_ID = "arg.feedId";
private static final String ARG_FEEDITEM_ID = "arg.feedItemId";
-
+
private WebView webvDescription;
private FeedItem item;
-
+
private AsyncTask<Void, Void, Void> webViewLoader;
-
+
public static ItemDescriptionFragment newInstance(FeedItem item) {
ItemDescriptionFragment f = new ItemDescriptionFragment();
Bundle args = new Bundle();
@@ -40,7 +40,7 @@ public class ItemDescriptionFragment extends SherlockFragment {
f.setArguments(args);
return f;
}
-
+
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
@@ -48,7 +48,6 @@ public class ItemDescriptionFragment extends SherlockFragment {
return webvDescription;
}
-
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
@@ -65,7 +64,7 @@ public class ItemDescriptionFragment extends SherlockFragment {
webViewLoader.cancel(true);
}
}
-
+
@Override
public void onDestroy() {
super.onDestroy();
@@ -87,25 +86,29 @@ public class ItemDescriptionFragment extends SherlockFragment {
} else {
Log.e(TAG, TAG + " was called with invalid arguments");
}
-
+
}
-
+
private AsyncTask<Void, Void, Void> createLoader() {
return new AsyncTask<Void, Void, Void>() {
@Override
protected void onCancelled() {
super.onCancelled();
- getSherlockActivity().setSupportProgressBarIndeterminateVisibility(false);
+ if (getSherlockActivity() != null) {
+ getSherlockActivity()
+ .setSupportProgressBarIndeterminateVisibility(false);
+ }
webViewLoader = null;
}
String url;
-
+
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
webvDescription.loadData(url, "text/html", "utf-8");
- getSherlockActivity().setSupportProgressBarIndeterminateVisibility(false);
+ getSherlockActivity()
+ .setSupportProgressBarIndeterminateVisibility(false);
Log.d(TAG, "Webview loaded");
webViewLoader = null;
}
@@ -113,7 +116,8 @@ public class ItemDescriptionFragment extends SherlockFragment {
@Override
protected void onPreExecute() {
super.onPreExecute();
- getSherlockActivity().setSupportProgressBarIndeterminateVisibility(true);
+ getSherlockActivity()
+ .setSupportProgressBarIndeterminateVisibility(true);
}
@Override
@@ -127,15 +131,15 @@ public class ItemDescriptionFragment extends SherlockFragment {
} else {
url = URLEncoder.encode(
StringEscapeUtils.unescapeHtml4(item
- .getContentEncoded()), "utf-8").replaceAll(
- "\\+", " ");
+ .getContentEncoded()), "utf-8")
+ .replaceAll("\\+", " ");
}
} catch (UnsupportedEncodingException e) {
url = "Page could not be loaded";
e.printStackTrace();
- }
-
+ }
+
return null;
}