MediaPlayerActivity now handles orientation changes correctly

This commit is contained in:
daniel oeh 2012-07-01 19:21:22 +02:00
parent 3932e09089
commit 6bde1e99d1
2 changed files with 43 additions and 24 deletions

View File

@ -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;
}
}

View File

@ -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;
}