summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorAndrzej J.R. Hunt <andrzej@ahunt.org>2012-09-04 11:08:33 +0200
committerAndrzej J.R. Hunt <andrzej@ahunt.org>2012-09-04 11:09:36 +0200
commitd23759f1b84dbd550c933dd2d8b9b80a431af2c6 (patch)
treefd6d0e3c65902e5902af523089c440f1d44adaf9 /android
parentc79b998a59d84198e02c8f2496740643689c2c4b (diff)
More fragment lifecycle cleanup.
Change-Id: I93a19a080cc73bfa49b04f19b6e290ff9cd1b8bc
Diffstat (limited to 'android')
-rw-r--r--android/sdremote/res/layout/activity_presentation.xml12
-rw-r--r--android/sdremote/res/layout/idlayout.xml9
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/PresentationActivity.java59
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/PresentationFragment.java6
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/ThumbnailFragment.java3
5 files changed, 48 insertions, 41 deletions
diff --git a/android/sdremote/res/layout/activity_presentation.xml b/android/sdremote/res/layout/activity_presentation.xml
index f482b3c246ef..23b615a95fe4 100644
--- a/android/sdremote/res/layout/activity_presentation.xml
+++ b/android/sdremote/res/layout/activity_presentation.xml
@@ -1,7 +1,13 @@
<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
diff --git a/android/sdremote/res/layout/idlayout.xml b/android/sdremote/res/layout/idlayout.xml
deleted file mode 100644
index 6288cbbb7144..000000000000
--- a/android/sdremote/res/layout/idlayout.xml
+++ /dev/null
@@ -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> \ No newline at end of file
diff --git a/android/sdremote/src/org/libreoffice/impressremote/PresentationActivity.java b/android/sdremote/src/org/libreoffice/impressremote/PresentationActivity.java
index a99b9cc869c5..767bec5a4f57 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/PresentationActivity.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/PresentationActivity.java
@@ -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
diff --git a/android/sdremote/src/org/libreoffice/impressremote/PresentationFragment.java b/android/sdremote/src/org/libreoffice/impressremote/PresentationFragment.java
index 2ca4a2114d11..2d5dfacb0243 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/PresentationFragment.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/PresentationFragment.java
@@ -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);
diff --git a/android/sdremote/src/org/libreoffice/impressremote/ThumbnailFragment.java b/android/sdremote/src/org/libreoffice/impressremote/ThumbnailFragment.java
index 4532177f9fde..c7731ee56e6b 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/ThumbnailFragment.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/ThumbnailFragment.java
@@ -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);