Kaydet (Commit) d23759f1 authored tarafından Andrzej J.R. Hunt's avatar Andrzej J.R. Hunt

More fragment lifecycle cleanup.

Change-Id: I93a19a080cc73bfa49b04f19b6e290ff9cd1b8bc
üst c79b998a
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/framelayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/framelayout" >
android:layout_height="match_parent" >
</FrameLayout>
<view
android:id="@+id/presentation_interceptor"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
class="org.libreoffice.impressremote.PresentationActivity$InterceptorLayout" />
</FrameLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/presentation_innerFrame">
</LinearLayout>
\ No newline at end of file
......@@ -20,6 +20,7 @@ import android.preference.PreferenceManager;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.text.format.DateFormat;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
......@@ -40,7 +41,7 @@ public class PresentationActivity extends SherlockFragmentActivity {
private FrameLayout mOuterLayout;
private ThumbnailFragment mThumbnailFragment;
private PresentationFragment mPresentationFragment;
private ActionBarManager mActionBarManager;
private static ActionBarManager mActionBarManager;
@Override
public void onCreate(Bundle savedInstanceState) {
......@@ -49,32 +50,22 @@ public class PresentationActivity extends SherlockFragmentActivity {
bindService(new Intent(this, CommunicationService.class), mConnection,
Context.BIND_IMPORTANT);
setContentView(R.layout.activity_presentation);
mOuterLayout = (FrameLayout) findViewById(R.id.framelayout);
mOuterLayout.removeAllViews();
mLayout = new InterceptorLayout(this);
mOuterLayout.addView(mLayout);
mLayout.setId(R.id.presentation_innerFrame);
//((FrameLayout) findViewById(R.id.framelayout)).addView(mLayout);
setContentView(R.layout.activity_presentation);
if (savedInstanceState == null) {
mThumbnailFragment = new ThumbnailFragment();
mPresentationFragment = new PresentationFragment();
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager
.beginTransaction();
fragmentTransaction.add(R.id.presentation_innerFrame,
fragmentTransaction.add(R.id.presentation_interceptor,
mPresentationFragment, "fragment_presentation");
fragmentTransaction.commit();
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean("thumbnail_enabled", mThumbnailFragment.isVisible());
mOuterLayout = (FrameLayout) findViewById(R.id.framelayout);
mLayout = (FrameLayout) findViewById(R.id.presentation_interceptor);
}
@Override
......@@ -90,8 +81,10 @@ public class PresentationActivity extends SherlockFragmentActivity {
.getDefaultSharedPreferences(this);
boolean aVolumeSwitching = aPref.getBoolean("option_volumeswitching",
false);
boolean aRelevantFragmentVisible = mPresentationFragment.isVisible()
|| mThumbnailFragment.isVisible();
boolean aRelevantFragmentVisible = ((mPresentationFragment != null) && mPresentationFragment
.isVisible())
|| ((mThumbnailFragment != null) && mThumbnailFragment
.isVisible());
if (aVolumeSwitching && aRelevantFragmentVisible) {
int action = event.getAction();
......@@ -119,7 +112,9 @@ public class PresentationActivity extends SherlockFragmentActivity {
mCommunicationService = ((CommunicationService.CBinder) aService)
.getService();
mThumbnailFragment.setCommunicationService(mCommunicationService);
if (mThumbnailFragment != null)
mThumbnailFragment
.setCommunicationService(mCommunicationService);
}
......@@ -149,8 +144,10 @@ public class PresentationActivity extends SherlockFragmentActivity {
startActivity(aIntent);
return true;
case R.id.actionbar_presentation_submenu_blank:
boolean aRelevantFragmentVisible = mPresentationFragment
.isVisible() || mThumbnailFragment.isVisible();
boolean aRelevantFragmentVisible = (mPresentationFragment != null && mPresentationFragment
.isVisible())
|| (mThumbnailFragment != null && mThumbnailFragment
.isVisible());
if (aRelevantFragmentVisible) {
BlankScreenFragment aFragment = new BlankScreenFragment(
......@@ -158,7 +155,7 @@ public class PresentationActivity extends SherlockFragmentActivity {
FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction();
ft.replace(R.id.presentation_innerFrame, aFragment);
ft.replace(R.id.presentation_interceptor, aFragment);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.addToBackStack(null);
ft.commit();
......@@ -372,10 +369,20 @@ public class PresentationActivity extends SherlockFragmentActivity {
Timer aTimer = mCommunicationService.getSlideShow().getTimer();
// --------------------------------- ACTIONBAR BUTTONS -------------
if (aSource == mThumbnailButton) {
if (mThumbnailFragment == null) {
mThumbnailFragment = (ThumbnailFragment) getSupportFragmentManager()
.findFragmentByTag("ThumbnailFragment");
if (mThumbnailFragment == null) {
mThumbnailFragment = new ThumbnailFragment();
mThumbnailFragment
.setCommunicationService(mCommunicationService);
}
}
if (!mThumbnailFragment.isVisible()) {
FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction();
ft.replace(R.id.presentation_innerFrame, mThumbnailFragment);
ft.replace(R.id.presentation_interceptor,
mThumbnailFragment, "ThumbnailFragment");
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.addToBackStack(null);
ft.commit();
......@@ -480,10 +487,10 @@ public class PresentationActivity extends SherlockFragmentActivity {
* @author andy
*
*/
private class InterceptorLayout extends FrameLayout {
public static class InterceptorLayout extends FrameLayout {
public InterceptorLayout(Context context) {
super(context);
public InterceptorLayout(Context context, AttributeSet aAttrs) {
super(context, aAttrs);
}
@Override
......
......@@ -59,7 +59,8 @@ public class PresentationFragment extends SherlockFragment {
if (mTopView != null) {
mTopView.setAdapter(new ThumbnailAdapter(mContext,
mCommunicationService.getSlideShow()));
mTopView.setSelection(mCommunicationService.getSlideShow().getCurrentSlide(), true);
mTopView.setSelection(mCommunicationService.getSlideShow()
.getCurrentSlide(), true);
mTopView.setOnItemSelectedListener(new ClickListener());
}
......@@ -75,12 +76,13 @@ public class PresentationFragment extends SherlockFragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
setRetainInstance(true);
getActivity().bindService(
new Intent(getActivity().getApplicationContext(),
CommunicationService.class),
mConnection, Context.BIND_IMPORTANT);
mContext = getActivity().getApplicationContext();
container.removeAllViews();
// container.removeAllViews();
View v = inflater.inflate(R.layout.fragment_presentation, container,
false);
......
......@@ -46,7 +46,8 @@ public class ThumbnailFragment extends SherlockFragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
container.removeAllViews();
// container.removeAllViews();
setRetainInstance(true);
View v = inflater
.inflate(R.layout.fragment_thumbnail, container, false);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment