More fragment lifecycle cleanup.
Change-Id: I93a19a080cc73bfa49b04f19b6e290ff9cd1b8bc
This commit is contained in:
@@ -1,7 +1,13 @@
|
|||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/framelayout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent" >
|
||||||
android:id="@+id/framelayout" >
|
|
||||||
|
|
||||||
</FrameLayout>
|
<view
|
||||||
|
android:id="@+id/presentation_interceptor"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
class="org.libreoffice.impressremote.PresentationActivity$InterceptorLayout" />
|
||||||
|
|
||||||
|
</FrameLayout>
|
@@ -1,9 +0,0 @@
|
|||||||
<?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>
|
|
@@ -20,6 +20,7 @@ import android.preference.PreferenceManager;
|
|||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.app.FragmentTransaction;
|
import android.support.v4.app.FragmentTransaction;
|
||||||
import android.text.format.DateFormat;
|
import android.text.format.DateFormat;
|
||||||
|
import android.util.AttributeSet;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
@@ -40,7 +41,7 @@ public class PresentationActivity extends SherlockFragmentActivity {
|
|||||||
private FrameLayout mOuterLayout;
|
private FrameLayout mOuterLayout;
|
||||||
private ThumbnailFragment mThumbnailFragment;
|
private ThumbnailFragment mThumbnailFragment;
|
||||||
private PresentationFragment mPresentationFragment;
|
private PresentationFragment mPresentationFragment;
|
||||||
private ActionBarManager mActionBarManager;
|
private static ActionBarManager mActionBarManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -49,32 +50,22 @@ public class PresentationActivity extends SherlockFragmentActivity {
|
|||||||
bindService(new Intent(this, CommunicationService.class), mConnection,
|
bindService(new Intent(this, CommunicationService.class), mConnection,
|
||||||
Context.BIND_IMPORTANT);
|
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);
|
//((FrameLayout) findViewById(R.id.framelayout)).addView(mLayout);
|
||||||
|
setContentView(R.layout.activity_presentation);
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
mThumbnailFragment = new ThumbnailFragment();
|
|
||||||
mPresentationFragment = new PresentationFragment();
|
mPresentationFragment = new PresentationFragment();
|
||||||
|
|
||||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||||
|
|
||||||
FragmentTransaction fragmentTransaction = fragmentManager
|
FragmentTransaction fragmentTransaction = fragmentManager
|
||||||
.beginTransaction();
|
.beginTransaction();
|
||||||
fragmentTransaction.add(R.id.presentation_innerFrame,
|
fragmentTransaction.add(R.id.presentation_interceptor,
|
||||||
mPresentationFragment, "fragment_presentation");
|
mPresentationFragment, "fragment_presentation");
|
||||||
fragmentTransaction.commit();
|
fragmentTransaction.commit();
|
||||||
}
|
}
|
||||||
}
|
mOuterLayout = (FrameLayout) findViewById(R.id.framelayout);
|
||||||
|
mLayout = (FrameLayout) findViewById(R.id.presentation_interceptor);
|
||||||
@Override
|
|
||||||
protected void onSaveInstanceState(Bundle outState) {
|
|
||||||
super.onSaveInstanceState(outState);
|
|
||||||
outState.putBoolean("thumbnail_enabled", mThumbnailFragment.isVisible());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -90,8 +81,10 @@ public class PresentationActivity extends SherlockFragmentActivity {
|
|||||||
.getDefaultSharedPreferences(this);
|
.getDefaultSharedPreferences(this);
|
||||||
boolean aVolumeSwitching = aPref.getBoolean("option_volumeswitching",
|
boolean aVolumeSwitching = aPref.getBoolean("option_volumeswitching",
|
||||||
false);
|
false);
|
||||||
boolean aRelevantFragmentVisible = mPresentationFragment.isVisible()
|
boolean aRelevantFragmentVisible = ((mPresentationFragment != null) && mPresentationFragment
|
||||||
|| mThumbnailFragment.isVisible();
|
.isVisible())
|
||||||
|
|| ((mThumbnailFragment != null) && mThumbnailFragment
|
||||||
|
.isVisible());
|
||||||
if (aVolumeSwitching && aRelevantFragmentVisible) {
|
if (aVolumeSwitching && aRelevantFragmentVisible) {
|
||||||
|
|
||||||
int action = event.getAction();
|
int action = event.getAction();
|
||||||
@@ -119,7 +112,9 @@ public class PresentationActivity extends SherlockFragmentActivity {
|
|||||||
mCommunicationService = ((CommunicationService.CBinder) aService)
|
mCommunicationService = ((CommunicationService.CBinder) aService)
|
||||||
.getService();
|
.getService();
|
||||||
|
|
||||||
mThumbnailFragment.setCommunicationService(mCommunicationService);
|
if (mThumbnailFragment != null)
|
||||||
|
mThumbnailFragment
|
||||||
|
.setCommunicationService(mCommunicationService);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,8 +144,10 @@ public class PresentationActivity extends SherlockFragmentActivity {
|
|||||||
startActivity(aIntent);
|
startActivity(aIntent);
|
||||||
return true;
|
return true;
|
||||||
case R.id.actionbar_presentation_submenu_blank:
|
case R.id.actionbar_presentation_submenu_blank:
|
||||||
boolean aRelevantFragmentVisible = mPresentationFragment
|
boolean aRelevantFragmentVisible = (mPresentationFragment != null && mPresentationFragment
|
||||||
.isVisible() || mThumbnailFragment.isVisible();
|
.isVisible())
|
||||||
|
|| (mThumbnailFragment != null && mThumbnailFragment
|
||||||
|
.isVisible());
|
||||||
if (aRelevantFragmentVisible) {
|
if (aRelevantFragmentVisible) {
|
||||||
|
|
||||||
BlankScreenFragment aFragment = new BlankScreenFragment(
|
BlankScreenFragment aFragment = new BlankScreenFragment(
|
||||||
@@ -158,7 +155,7 @@ public class PresentationActivity extends SherlockFragmentActivity {
|
|||||||
|
|
||||||
FragmentTransaction ft = getSupportFragmentManager()
|
FragmentTransaction ft = getSupportFragmentManager()
|
||||||
.beginTransaction();
|
.beginTransaction();
|
||||||
ft.replace(R.id.presentation_innerFrame, aFragment);
|
ft.replace(R.id.presentation_interceptor, aFragment);
|
||||||
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
|
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
|
||||||
ft.addToBackStack(null);
|
ft.addToBackStack(null);
|
||||||
ft.commit();
|
ft.commit();
|
||||||
@@ -372,10 +369,20 @@ public class PresentationActivity extends SherlockFragmentActivity {
|
|||||||
Timer aTimer = mCommunicationService.getSlideShow().getTimer();
|
Timer aTimer = mCommunicationService.getSlideShow().getTimer();
|
||||||
// --------------------------------- ACTIONBAR BUTTONS -------------
|
// --------------------------------- ACTIONBAR BUTTONS -------------
|
||||||
if (aSource == mThumbnailButton) {
|
if (aSource == mThumbnailButton) {
|
||||||
|
if (mThumbnailFragment == null) {
|
||||||
|
mThumbnailFragment = (ThumbnailFragment) getSupportFragmentManager()
|
||||||
|
.findFragmentByTag("ThumbnailFragment");
|
||||||
|
if (mThumbnailFragment == null) {
|
||||||
|
mThumbnailFragment = new ThumbnailFragment();
|
||||||
|
mThumbnailFragment
|
||||||
|
.setCommunicationService(mCommunicationService);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!mThumbnailFragment.isVisible()) {
|
if (!mThumbnailFragment.isVisible()) {
|
||||||
FragmentTransaction ft = getSupportFragmentManager()
|
FragmentTransaction ft = getSupportFragmentManager()
|
||||||
.beginTransaction();
|
.beginTransaction();
|
||||||
ft.replace(R.id.presentation_innerFrame, mThumbnailFragment);
|
ft.replace(R.id.presentation_interceptor,
|
||||||
|
mThumbnailFragment, "ThumbnailFragment");
|
||||||
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
|
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
|
||||||
ft.addToBackStack(null);
|
ft.addToBackStack(null);
|
||||||
ft.commit();
|
ft.commit();
|
||||||
@@ -480,10 +487,10 @@ public class PresentationActivity extends SherlockFragmentActivity {
|
|||||||
* @author andy
|
* @author andy
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private class InterceptorLayout extends FrameLayout {
|
public static class InterceptorLayout extends FrameLayout {
|
||||||
|
|
||||||
public InterceptorLayout(Context context) {
|
public InterceptorLayout(Context context, AttributeSet aAttrs) {
|
||||||
super(context);
|
super(context, aAttrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -59,7 +59,8 @@ public class PresentationFragment extends SherlockFragment {
|
|||||||
if (mTopView != null) {
|
if (mTopView != null) {
|
||||||
mTopView.setAdapter(new ThumbnailAdapter(mContext,
|
mTopView.setAdapter(new ThumbnailAdapter(mContext,
|
||||||
mCommunicationService.getSlideShow()));
|
mCommunicationService.getSlideShow()));
|
||||||
mTopView.setSelection(mCommunicationService.getSlideShow().getCurrentSlide(), true);
|
mTopView.setSelection(mCommunicationService.getSlideShow()
|
||||||
|
.getCurrentSlide(), true);
|
||||||
mTopView.setOnItemSelectedListener(new ClickListener());
|
mTopView.setOnItemSelectedListener(new ClickListener());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,12 +76,13 @@ public class PresentationFragment extends SherlockFragment {
|
|||||||
|
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
|
setRetainInstance(true);
|
||||||
getActivity().bindService(
|
getActivity().bindService(
|
||||||
new Intent(getActivity().getApplicationContext(),
|
new Intent(getActivity().getApplicationContext(),
|
||||||
CommunicationService.class),
|
CommunicationService.class),
|
||||||
mConnection, Context.BIND_IMPORTANT);
|
mConnection, Context.BIND_IMPORTANT);
|
||||||
mContext = getActivity().getApplicationContext();
|
mContext = getActivity().getApplicationContext();
|
||||||
container.removeAllViews();
|
// container.removeAllViews();
|
||||||
View v = inflater.inflate(R.layout.fragment_presentation, container,
|
View v = inflater.inflate(R.layout.fragment_presentation, container,
|
||||||
false);
|
false);
|
||||||
|
|
||||||
|
@@ -46,7 +46,8 @@ public class ThumbnailFragment extends SherlockFragment {
|
|||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
// Inflate the layout for this fragment
|
// Inflate the layout for this fragment
|
||||||
container.removeAllViews();
|
// container.removeAllViews();
|
||||||
|
setRetainInstance(true);
|
||||||
View v = inflater
|
View v = inflater
|
||||||
.inflate(R.layout.fragment_thumbnail, container, false);
|
.inflate(R.layout.fragment_thumbnail, container, false);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user