Update API demos to mark up for java doc insertion.
Change-Id: Ib0147af6c82f7781fd50f9a5f85c34c140973909
This commit is contained in:
@@ -251,7 +251,7 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity android:name=".app.FragmentLayout$DialogActivity" />
|
<activity android:name=".app.FragmentLayout$DetailsActivity" />
|
||||||
|
|
||||||
<activity android:name=".app.FragmentListCursorLoader"
|
<activity android:name=".app.FragmentListCursorLoader"
|
||||||
android:theme="@android:style/Theme.WithActionBar"
|
android:theme="@android:style/Theme.WithActionBar"
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
<!-- Top-level content view for the layout fragment sample. This version is
|
<!-- Top-level content view for the layout fragment sample. This version is
|
||||||
for display when in landscape: we can fit both titles and dialog. -->
|
for display when in landscape: we can fit both titles and dialog. -->
|
||||||
|
|
||||||
|
<!-- BEGIN_INCLUDE(layout) -->
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:layout_width="match_parent" android:layout_height="match_parent">
|
android:layout_width="match_parent" android:layout_height="match_parent">
|
||||||
@@ -30,3 +31,4 @@
|
|||||||
android:layout_width="0px" android:layout_height="match_parent" />
|
android:layout_width="0px" android:layout_height="match_parent" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
<!-- END_INCLUDE(layout) -->
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
<!-- Top-level content view for the layout fragment sample. This version is
|
<!-- Top-level content view for the layout fragment sample. This version is
|
||||||
for display when not in landscape: we can only fit the list of titles. -->
|
for display when not in landscape: we can only fit the list of titles. -->
|
||||||
|
|
||||||
|
<!-- BEGIN_INCLUDE(layout) -->
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent" android:layout_height="match_parent">
|
android:layout_width="match_parent" android:layout_height="match_parent">
|
||||||
<fragment
|
<fragment
|
||||||
@@ -24,3 +25,4 @@
|
|||||||
android:id="@+id/titles"
|
android:id="@+id/titles"
|
||||||
android:layout_width="match_parent" android:layout_height="match_parent" />
|
android:layout_width="match_parent" android:layout_height="match_parent" />
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
<!-- END_INCLUDE(layout) -->
|
||||||
|
|||||||
@@ -21,9 +21,11 @@ import com.example.android.apis.Shakespeare;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
|
import android.app.ListFragment;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@@ -40,19 +42,21 @@ import android.widget.TextView;
|
|||||||
*/
|
*/
|
||||||
public class FragmentLayout extends Activity {
|
public class FragmentLayout extends Activity {
|
||||||
|
|
||||||
|
//BEGIN_INCLUDE(main)
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
// This layout varies depending on the screen size.
|
|
||||||
setContentView(R.layout.fragment_layout);
|
setContentView(R.layout.fragment_layout);
|
||||||
}
|
}
|
||||||
|
//END_INCLUDE(main)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a secondary activity, to show what the user has selected
|
* This is a secondary activity, to show what the user has selected
|
||||||
* when the screen is not large enough to show it all in one activity.
|
* when the screen is not large enough to show it all in one activity.
|
||||||
*/
|
*/
|
||||||
public static class DialogActivity extends Activity {
|
//BEGIN_INCLUDE(details_activity)
|
||||||
|
public static class DetailsActivity extends Activity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -66,40 +70,49 @@ public class FragmentLayout extends Activity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DialogFragment dialog = new DialogFragment();
|
if (savedInstanceState == null) {
|
||||||
openFragmentTransaction().add(android.R.id.content, dialog).commit();
|
// During initial setup, plug in the details fragment.
|
||||||
dialog.setText(getIntent().getIntExtra("text", -1));
|
DetailsFragment details = new DetailsFragment();
|
||||||
|
getFragmentManager().openTransaction().add(android.R.id.content, details).commit();
|
||||||
|
details.setText(getIntent().getIntExtra("text", -1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//END_INCLUDE(details_activity)
|
||||||
|
|
||||||
public static class TitlesFragment extends Fragment
|
//BEGIN_INCLUDE(titles)
|
||||||
implements AdapterView.OnItemClickListener {
|
public static class TitlesFragment extends ListFragment {
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
Bundle savedInstanceState) {
|
super.onActivityCreated(savedInstanceState);
|
||||||
ListView list = new ListView(getActivity());
|
|
||||||
list.setDrawSelectorOnTop(false);
|
// Populate list with our static array of titles.
|
||||||
list.setAdapter(new ArrayAdapter<String>(getActivity(),
|
setListAdapter(new ArrayAdapter<String>(getActivity(),
|
||||||
android.R.layout.simple_list_item_1, Shakespeare.TITLES));
|
android.R.layout.simple_list_item_1, Shakespeare.TITLES));
|
||||||
list.setOnItemClickListener(this);
|
|
||||||
list.setId(android.R.id.list); // set id to allow state save/restore.
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
@Override
|
||||||
DialogFragment frag = (DialogFragment)getActivity().findFragmentById(R.id.dialog);
|
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||||
|
DetailsFragment frag = (DetailsFragment)
|
||||||
|
getFragmentManager().findFragmentById(R.id.dialog);
|
||||||
if (frag != null && frag.isVisible()) {
|
if (frag != null && frag.isVisible()) {
|
||||||
|
// If the activity has a fragment to display the dialog,
|
||||||
|
// point it to what the user has selected.
|
||||||
frag.setText((int)id);
|
frag.setText((int)id);
|
||||||
} else {
|
} else {
|
||||||
|
// Otherwise we need to launch a new activity to display
|
||||||
|
// the dialog fragment with selected text.
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.setClass(getActivity(), DialogActivity.class);
|
intent.setClass(getActivity(), DetailsActivity.class);
|
||||||
intent.putExtra("text", (int)id);
|
intent.putExtra("text", (int)id);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//END_INCLUDE(titles)
|
||||||
|
|
||||||
public static class DialogFragment extends Fragment {
|
//BEGIN_INCLUDE(details)
|
||||||
|
public static class DetailsFragment extends Fragment {
|
||||||
int mDisplayedText = -1;
|
int mDisplayedText = -1;
|
||||||
TextView mText;
|
TextView mText;
|
||||||
|
|
||||||
@@ -134,4 +147,5 @@ public class FragmentLayout extends Activity {
|
|||||||
return scroller;
|
return scroller;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//END_INCLUDE(details)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,9 +37,9 @@ public class FragmentListArray extends Activity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
// Create the list fragment and add it as our sole content.
|
// Create the list fragment and add it as our sole content.
|
||||||
if (findFragmentById(android.R.id.content) == null) {
|
if (getFragmentManager().findFragmentById(android.R.id.content) == null) {
|
||||||
ArrayListFragment list = new ArrayListFragment();
|
ArrayListFragment list = new ArrayListFragment();
|
||||||
openFragmentTransaction().add(android.R.id.content, list).commit();
|
getFragmentManager().openTransaction().add(android.R.id.content, list).commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ public class FragmentStack extends Activity {
|
|||||||
outState.putInt("level", mStackLevel);
|
outState.putInt("level", mStackLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//BEGIN_INCLUDE(add_stack)
|
||||||
void addFragmentToStack() {
|
void addFragmentToStack() {
|
||||||
mStackLevel++;
|
mStackLevel++;
|
||||||
|
|
||||||
@@ -75,7 +76,9 @@ public class FragmentStack extends Activity {
|
|||||||
ft.addToBackStack(null);
|
ft.addToBackStack(null);
|
||||||
ft.commit();
|
ft.commit();
|
||||||
}
|
}
|
||||||
|
//END_INCLUDE(add_stack)
|
||||||
|
|
||||||
|
//BEGIN_INCLUDE(fragment)
|
||||||
public static class CountingFragment extends Fragment {
|
public static class CountingFragment extends Fragment {
|
||||||
int mNum;
|
int mNum;
|
||||||
|
|
||||||
@@ -94,12 +97,19 @@ public class FragmentStack extends Activity {
|
|||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When creating, retrieve this instance's number from its arguments.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
mNum = getArguments().getInt("num");
|
mNum = getArguments().getInt("num");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Fragment's UI is just a simple text view showing its
|
||||||
|
* instance number.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
@@ -109,4 +119,5 @@ public class FragmentStack extends Activity {
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//END_INCLUDE(fragment)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user