MediaPlayerActivity now handles orientation changes correctly
This commit is contained in:
parent
3932e09089
commit
6bde1e99d1
|
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
// 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
|
||||
|
|
|
@ -48,7 +48,6 @@ public class ItemDescriptionFragment extends SherlockFragment {
|
|||
return webvDescription;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
|
@ -95,7 +94,10 @@ public class ItemDescriptionFragment extends SherlockFragment {
|
|||
@Override
|
||||
protected void onCancelled() {
|
||||
super.onCancelled();
|
||||
getSherlockActivity().setSupportProgressBarIndeterminateVisibility(false);
|
||||
if (getSherlockActivity() != null) {
|
||||
getSherlockActivity()
|
||||
.setSupportProgressBarIndeterminateVisibility(false);
|
||||
}
|
||||
webViewLoader = null;
|
||||
}
|
||||
|
||||
|
@ -105,7 +107,8 @@ public class ItemDescriptionFragment extends SherlockFragment {
|
|||
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,8 +131,8 @@ public class ItemDescriptionFragment extends SherlockFragment {
|
|||
} else {
|
||||
url = URLEncoder.encode(
|
||||
StringEscapeUtils.unescapeHtml4(item
|
||||
.getContentEncoded()), "utf-8").replaceAll(
|
||||
"\\+", " ");
|
||||
.getContentEncoded()), "utf-8")
|
||||
.replaceAll("\\+", " ");
|
||||
}
|
||||
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
|
|
Loading…
Reference in New Issue