Cleanup fragment api demos
* Cleaned up extra whitespace & made vertical whitespace more consistent * 100col wrap * Remove unused imports * Add @Override where necessary Change-Id: I1ad404ffc4ce7fa9c4b661f7cc1783c86356316b
This commit is contained in:
@@ -30,6 +30,7 @@ import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class FragmentAlertDialog extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -53,21 +54,26 @@ public class FragmentAlertDialog extends Activity {
|
||||
}
|
||||
|
||||
public static class MyAlertDialogFragment extends DialogFragment {
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
return new AlertDialog.Builder(getActivity())
|
||||
.setIcon(R.drawable.alert_dialog_icon)
|
||||
.setTitle(R.string.alert_dialog_two_buttons_title)
|
||||
.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
|
||||
.setPositiveButton(R.string.alert_dialog_ok,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int whichButton) {
|
||||
/* User clicked OK so do some stuff */
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() {
|
||||
}
|
||||
)
|
||||
.setNegativeButton(R.string.alert_dialog_cancel,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int whichButton) {
|
||||
/* User clicked Cancel so do some stuff */
|
||||
}
|
||||
})
|
||||
}
|
||||
)
|
||||
.create();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import android.widget.TextView;
|
||||
* Demonstration of animations when changing fragment states.
|
||||
*/
|
||||
public class FragmentAnim extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -66,6 +67,7 @@ public class FragmentAnim extends Activity {
|
||||
public static class FirstFragment extends Fragment {
|
||||
TextView mTextView;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View v = inflater.inflate(R.layout.labeled_text_edit, container, false);
|
||||
@@ -90,6 +92,8 @@ public class FragmentAnim extends Activity {
|
||||
}
|
||||
|
||||
public static class SecondFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View v = inflater.inflate(R.layout.labeled_text_edit, container, false);
|
||||
|
||||
@@ -34,6 +34,7 @@ import android.view.ContextMenu.ContextMenuInfo;
|
||||
* Demonstration of displaying a context menu from a fragment.
|
||||
*/
|
||||
public class FragmentContextMenu extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -44,6 +45,7 @@ public class FragmentContextMenu extends Activity {
|
||||
}
|
||||
|
||||
public static class ContextMenuFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
||||
@@ -132,6 +132,7 @@ public class FragmentDialog extends Activity {
|
||||
outState.putInt("num", mNum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View v = inflater.inflate(R.layout.fragment_dialog, container, false);
|
||||
|
||||
@@ -21,18 +21,14 @@ import com.example.android.apis.Shakespeare;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
@@ -43,6 +39,7 @@ import android.widget.TextView;
|
||||
* landscape.
|
||||
*/
|
||||
public class FragmentLayout extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -56,6 +53,7 @@ public class FragmentLayout extends Activity {
|
||||
* when the screen is not large enough to show it all in one activity.
|
||||
*/
|
||||
public static class DialogActivity extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -76,6 +74,7 @@ public class FragmentLayout extends Activity {
|
||||
|
||||
public static class TitlesFragment extends Fragment
|
||||
implements AdapterView.OnItemClickListener {
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
ListView list = new ListView(getActivity());
|
||||
@@ -125,6 +124,7 @@ public class FragmentLayout extends Activity {
|
||||
outState.putInt("text", mDisplayedText);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
ScrollView scroller = new ScrollView(getActivity());
|
||||
|
||||
@@ -31,6 +31,7 @@ import android.widget.ListView;
|
||||
* from a canned array.
|
||||
*/
|
||||
public class FragmentListArray extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -43,6 +44,7 @@ public class FragmentListArray extends Activity {
|
||||
}
|
||||
|
||||
public static class ArrayListFragment extends ListFragment {
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
@@ -23,7 +23,6 @@ import android.content.CursorLoader;
|
||||
import android.content.Loader;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Contacts.Phones;
|
||||
import android.provider.ContactsContract.Contacts;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
@@ -36,6 +35,7 @@ import android.widget.SimpleCursorAdapter;
|
||||
* an empty view and loading progress.
|
||||
*/
|
||||
public class FragmentListCursorLoader extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
@@ -6,15 +6,11 @@ import android.app.Activity;
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* Demonstrates how fragments can participate in the options menu.
|
||||
@@ -84,6 +80,7 @@ public class FragmentMenu extends Activity {
|
||||
* have one if it wanted.
|
||||
*/
|
||||
public static class MenuFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -101,6 +98,7 @@ public class FragmentMenu extends Activity {
|
||||
* Second fragment with a menu.
|
||||
*/
|
||||
public static class Menu2Fragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.example.android.apis.app;
|
||||
|
||||
import com.example.android.apis.R;
|
||||
import com.example.android.apis.app.FragmentStack.CountingFragment;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Fragment;
|
||||
@@ -11,13 +10,14 @@ import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class FragmentReceiveResult extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -61,6 +61,7 @@ public class FragmentReceiveResult extends Activity {
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View v = inflater.inflate(R.layout.receive_result, container, false);
|
||||
@@ -112,6 +113,5 @@ public class FragmentReceiveResult extends Activity {
|
||||
text.append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,15 +20,11 @@ import com.example.android.apis.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* This example shows how you can use a Fragment to easily propagate state
|
||||
|
||||
@@ -96,6 +96,7 @@ public class FragmentStack extends Activity {
|
||||
outState.putInt("num", mNum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View v = inflater.inflate(R.layout.hello_world, container, false);
|
||||
|
||||
@@ -33,6 +33,7 @@ import android.widget.ListView;
|
||||
*/
|
||||
//BEGIN_INCLUDE(activity)
|
||||
public class FragmentPreferences extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -47,6 +48,7 @@ public class FragmentPreferences extends Activity {
|
||||
* pick one, the corresponding preferences fragment is created and shown.
|
||||
*/
|
||||
public static class CategoriesFragment extends ListFragment {
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
@@ -72,6 +74,7 @@ public class FragmentPreferences extends Activity {
|
||||
|
||||
//BEGIN_INCLUDE(fragment)
|
||||
public static class Prefs1Fragment extends PreferenceFragment {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -83,6 +86,7 @@ public class FragmentPreferences extends Activity {
|
||||
//END_INCLUDE(fragment)
|
||||
|
||||
public static class Prefs2Fragment extends PreferenceFragment {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Reference in New Issue
Block a user