Make FramementLayout demo better... and, um actually work.
Also some other small cleanup.
Change-Id: Iaaf5d4a85113b4a01a4bd3986e2334972e1096ad
diff --git a/samples/ApiDemos/res/layout-land/fragment_layout.xml b/samples/ApiDemos/res/layout-land/fragment_layout.xml
index 9a4fbc5..5c512f0 100644
--- a/samples/ApiDemos/res/layout-land/fragment_layout.xml
+++ b/samples/ApiDemos/res/layout-land/fragment_layout.xml
@@ -26,8 +26,8 @@
android:id="@+id/titles" android:layout_weight="1"
android:layout_width="0px" android:layout_height="match_parent" />
- <fragment class="com.example.android.apis.app.FragmentLayout$DialogFragment"
- android:id="@+id/dialog" android:layout_weight="1"
+ <fragment class="com.example.android.apis.app.FragmentLayout$DetailsFragment"
+ android:id="@+id/details" android:layout_weight="1"
android:layout_width="0px" android:layout_height="match_parent" />
</LinearLayout>
diff --git a/samples/ApiDemos/res/layout/fragment_layout.xml b/samples/ApiDemos/res/layout/fragment_layout.xml
index 114f626..b693c96 100644
--- a/samples/ApiDemos/res/layout/fragment_layout.xml
+++ b/samples/ApiDemos/res/layout/fragment_layout.xml
@@ -20,8 +20,7 @@
<!-- BEGIN_INCLUDE(layout) -->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
- <fragment
- class="com.example.android.apis.app.FragmentLayout$TitlesFragment"
+ <fragment class="com.example.android.apis.app.FragmentLayout$TitlesFragment"
android:id="@+id/titles"
android:layout_width="match_parent" android:layout_height="match_parent" />
</FrameLayout>
diff --git a/samples/ApiDemos/src/com/example/android/apis/app/FragmentLayout.java b/samples/ApiDemos/src/com/example/android/apis/app/FragmentLayout.java
index dc338dd..a63685e 100644
--- a/samples/ApiDemos/src/com/example/android/apis/app/FragmentLayout.java
+++ b/samples/ApiDemos/src/com/example/android/apis/app/FragmentLayout.java
@@ -26,10 +26,10 @@
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
+import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.ScrollView;
@@ -82,29 +82,52 @@
//BEGIN_INCLUDE(titles)
public static class TitlesFragment extends ListFragment {
+ DetailsFragment mDetails;
+ int mCurCheckPosition = 0;
+
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// Populate list with our static array of titles.
setListAdapter(new ArrayAdapter<String>(getActivity(),
- android.R.layout.simple_list_item_1, Shakespeare.TITLES));
+ android.R.layout.simple_list_item_activated_1, Shakespeare.TITLES));
+
+ // Restore last state for checked position.
+ if (savedInstanceState != null) {
+ mCurCheckPosition = savedInstanceState.getInt("curChoice", 0);
+ }
+
+ // If we are showing details in the screen, set up the list to highlight.
+ mDetails = (DetailsFragment)getFragmentManager().findFragmentById(R.id.details);
+ if (mDetails != null && mDetails.isInLayout()) {
+ getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
+ getListView().setItemChecked(mCurCheckPosition, true);
+ mDetails.setText(mCurCheckPosition);
+ }
+ }
+
+ @Override
+ public void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ outState.putInt("curChoice", mCurCheckPosition);
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
- DetailsFragment frag = (DetailsFragment)
- getFragmentManager().findFragmentById(R.id.dialog);
- if (frag != null && frag.isVisible()) {
+ mCurCheckPosition = position;
+
+ if (mDetails != null && mDetails.isVisible()) {
// If the activity has a fragment to display the dialog,
// point it to what the user has selected.
- frag.setText((int)id);
+ mDetails.setText(position);
+ getListView().setItemChecked(position, true);
} else {
// Otherwise we need to launch a new activity to display
// the dialog fragment with selected text.
Intent intent = new Intent();
intent.setClass(getActivity(), DetailsActivity.class);
- intent.putExtra("text", (int)id);
+ intent.putExtra("text", position);
startActivity(intent);
}
}
@@ -142,8 +165,13 @@
Bundle savedInstanceState) {
ScrollView scroller = new ScrollView(getActivity());
mText = new TextView(getActivity());
+ int padding = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
+ 4, getActivity().getResources().getDisplayMetrics());
+ mText.setPadding(padding, padding, padding, padding);
scroller.addView(mText);
- setText(mDisplayedText);
+ if (mDisplayedText >= 0) {
+ mText.setText(Shakespeare.DIALOGUE[mDisplayedText]);
+ }
return scroller;
}
}
diff --git a/samples/ApiDemos/src/com/example/android/apis/app/FragmentRetainInstance.java b/samples/ApiDemos/src/com/example/android/apis/app/FragmentRetainInstance.java
index 383242a..1879090 100644
--- a/samples/ApiDemos/src/com/example/android/apis/app/FragmentRetainInstance.java
+++ b/samples/ApiDemos/src/com/example/android/apis/app/FragmentRetainInstance.java
@@ -63,9 +63,7 @@
Button button = (Button)v.findViewById(R.id.restart);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
- if (mWorkFragment != null) {
- mWorkFragment.restart();
- }
+ mWorkFragment.restart();
}
});
diff --git a/samples/ApiDemos/src/com/example/android/apis/view/List16.java b/samples/ApiDemos/src/com/example/android/apis/view/List16.java
index 8e19a7f..041a9bb 100644
--- a/samples/ApiDemos/src/com/example/android/apis/view/List16.java
+++ b/samples/ApiDemos/src/com/example/android/apis/view/List16.java
@@ -29,7 +29,8 @@
/**
* This demo illustrates the use of CHOICE_MODE_MULTIPLE_MODAL, a.k.a. selection mode on ListView
- * couple with the new simple_selectable_list_item which uses a highligted border for selected items.
+ * couple with the new simple_list_item_activated_1 which uses a highlighted border for selected
+ * items.
*/
public class List16 extends ListActivity {
@Override
@@ -39,7 +40,7 @@
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
lv.setMultiChoiceModeListener(new ModeCallback());
setListAdapter(new ArrayAdapter<String>(this,
- android.R.layout.simple_selectable_list_item, mStrings));
+ android.R.layout.simple_list_item_activated_1, mStrings));
}
@Override