summaryrefslogtreecommitdiffstats
path: root/samples/SupportAppNavigation/src
diff options
context:
space:
mode:
authorAdam Powell <adamp@google.com>2012-04-05 17:07:02 -0700
committerAdam Powell <adamp@google.com>2012-04-05 18:03:24 -0700
commite331666e3ed0726c1f165224c803705c78b0e927 (patch)
tree637caa63d9a67f69b5ffaa0fdd7a7a2d12eb7b46 /samples/SupportAppNavigation/src
parenta5a83d57e71cbfa3a7dea48c1b588d643149fd90 (diff)
downloadandroid_development-e331666e3ed0726c1f165224c803705c78b0e927.tar.gz
android_development-e331666e3ed0726c1f165224c803705c78b0e927.tar.bz2
android_development-e331666e3ed0726c1f165224c803705c78b0e927.zip
Move AppNavigation samples around
Move AppNavigation to SupportAppNavigation - this one uses the support lib navigation helpers. Add AppNavigation as an implementation of the same sample using the framework features in JB. Change-Id: I59e0f2e3e11ccccc277b177aee87bd88da8eb2c6
Diffstat (limited to 'samples/SupportAppNavigation/src')
-rw-r--r--samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/ActionBarCompat.java42
-rw-r--r--samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/AppNavHomeActivity.java121
-rw-r--r--samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/ContentCategoryActivity.java50
-rw-r--r--samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/ContentViewActivity.java67
-rw-r--r--samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/InterstitialMessageActivity.java42
-rw-r--r--samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/NotificationsActivity.java80
-rw-r--r--samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/OutsideTaskActivity.java38
-rw-r--r--samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/PeerActivity.java62
-rw-r--r--samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/SimpleUpActivity.java44
-rw-r--r--samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/ViewFromOtherTaskActivity.java52
10 files changed, 598 insertions, 0 deletions
diff --git a/samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/ActionBarCompat.java b/samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/ActionBarCompat.java
new file mode 100644
index 000000000..6f222805c
--- /dev/null
+++ b/samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/ActionBarCompat.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.support.appnavigation.app;
+
+import android.app.Activity;
+import android.os.Build;
+
+/**
+ * Very limited shim for enabling the action bar's up button on devices that support it.
+ */
+public class ActionBarCompat {
+ /**
+ * This class will only ever be loaded if the version check succeeds,
+ * keeping the verifier from rejecting the use of framework classes that
+ * don't exist on older platform versions.
+ */
+ static class ActionBarCompatImpl {
+ static void setDisplayHomeAsUpEnabled(Activity activity, boolean enable) {
+ activity.getActionBar().setDisplayHomeAsUpEnabled(enable);
+ }
+ }
+
+ public static void setDisplayHomeAsUpEnabled(Activity activity, boolean enable) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
+ ActionBarCompatImpl.setDisplayHomeAsUpEnabled(activity, enable);
+ }
+ }
+}
diff --git a/samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/AppNavHomeActivity.java b/samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/AppNavHomeActivity.java
new file mode 100644
index 000000000..17f4d5bf3
--- /dev/null
+++ b/samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/AppNavHomeActivity.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.support.appnavigation.app;
+
+import android.app.ListActivity;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.os.Bundle;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.ListView;
+import android.widget.TextView;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Home activity for app navigation code samples.
+ */
+public class AppNavHomeActivity extends ListActivity {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setListAdapter(new SampleAdapter(querySampleActivities()));
+ }
+
+ @Override
+ protected void onListItemClick(ListView lv, View v, int pos, long id) {
+ SampleInfo info = (SampleInfo) getListAdapter().getItem(pos);
+ startActivity(info.intent);
+ }
+
+ protected List<SampleInfo> querySampleActivities() {
+ Intent intent = new Intent(Intent.ACTION_MAIN, null);
+ intent.setPackage(getPackageName());
+ intent.addCategory(Intent.CATEGORY_SAMPLE_CODE);
+
+ PackageManager pm = getPackageManager();
+ List<ResolveInfo> infos = pm.queryIntentActivities(intent, 0);
+
+ ArrayList<SampleInfo> samples = new ArrayList<SampleInfo>();
+
+ final int count = infos.size();
+ for (int i = 0; i < count; i++) {
+ final ResolveInfo info = infos.get(i);
+ final CharSequence labelSeq = info.loadLabel(pm);
+ String label = labelSeq != null ? labelSeq.toString() : info.activityInfo.name;
+
+ Intent target = new Intent();
+ target.setClassName(info.activityInfo.applicationInfo.packageName,
+ info.activityInfo.name);
+ SampleInfo sample = new SampleInfo(label, target);
+ samples.add(sample);
+ }
+
+ return samples;
+ }
+
+ static class SampleInfo {
+ String name;
+ Intent intent;
+
+ SampleInfo(String name, Intent intent) {
+ this.name = name;
+ this.intent = intent;
+ }
+ }
+
+ class SampleAdapter extends BaseAdapter {
+ private List<SampleInfo> mItems;
+
+ public SampleAdapter(List<SampleInfo> items) {
+ mItems = items;
+ }
+
+ @Override
+ public int getCount() {
+ return mItems.size();
+ }
+
+ @Override
+ public Object getItem(int position) {
+ return mItems.get(position);
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return position;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ if (convertView == null) {
+ convertView = getLayoutInflater().inflate(android.R.layout.simple_list_item_1,
+ parent, false);
+ convertView.setTag(convertView.findViewById(android.R.id.text1));
+ }
+ TextView tv = (TextView) convertView.getTag();
+ tv.setText(mItems.get(position).name);
+ return convertView;
+ }
+
+ }
+}
diff --git a/samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/ContentCategoryActivity.java b/samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/ContentCategoryActivity.java
new file mode 100644
index 000000000..d93482c71
--- /dev/null
+++ b/samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/ContentCategoryActivity.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.support.appnavigation.app;
+
+import com.example.android.support.appnavigation.R;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.v4.app.NavUtils;
+import android.view.MenuItem;
+import android.view.View;
+
+public class ContentCategoryActivity extends Activity {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.content_category);
+
+ ActionBarCompat.setDisplayHomeAsUpEnabled(this, true);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (item.getItemId() == android.R.id.home) {
+ NavUtils.navigateUpFromSameTask(this);
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ public void onViewContent(View v) {
+ Intent target = new Intent(this, ContentViewActivity.class);
+ startActivity(target);
+ }
+}
diff --git a/samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/ContentViewActivity.java b/samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/ContentViewActivity.java
new file mode 100644
index 000000000..42e25ea98
--- /dev/null
+++ b/samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/ContentViewActivity.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.support.appnavigation.app;
+
+import com.example.android.support.appnavigation.R;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.v4.app.NavUtils;
+import android.support.v4.app.ShareCompat;
+import android.support.v4.app.TaskStackBuilder;
+import android.text.TextUtils;
+import android.view.MenuItem;
+import android.widget.TextView;
+
+public class ContentViewActivity extends Activity {
+ public static final String EXTRA_TEXT = "com.example.android.appnavigation.EXTRA_TEXT";
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.content_view);
+
+ ActionBarCompat.setDisplayHomeAsUpEnabled(this, true);
+
+ Intent intent = getIntent();
+ if (Intent.ACTION_VIEW.equals(intent.getAction())) {
+ TextView tv = (TextView) findViewById(R.id.status_text);
+ tv.setText("Viewing content from ACTION_VIEW");
+ } else if (intent.hasExtra(EXTRA_TEXT)) {
+ TextView tv = (TextView) findViewById(R.id.status_text);
+ tv.setText(intent.getStringExtra(EXTRA_TEXT));
+ }
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (item.getItemId() == android.R.id.home) {
+ Intent upIntent = NavUtils.getParentActivityIntent(this);
+ if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
+ TaskStackBuilder.from(this)
+ .addParentStack(this)
+ .startActivities();
+ finish();
+ } else {
+ NavUtils.navigateUpTo(this, upIntent);
+ }
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+}
diff --git a/samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/InterstitialMessageActivity.java b/samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/InterstitialMessageActivity.java
new file mode 100644
index 000000000..72c356519
--- /dev/null
+++ b/samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/InterstitialMessageActivity.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.support.appnavigation.app;
+
+import com.example.android.support.appnavigation.R;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.v4.app.TaskStackBuilder;
+import android.view.View;
+
+public class InterstitialMessageActivity extends Activity {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.interstitial_message);
+ }
+
+ public void onViewContent(View v) {
+ TaskStackBuilder.from(this)
+ .addParentStack(ContentViewActivity.class)
+ .addNextIntent(new Intent(this, ContentViewActivity.class)
+ .putExtra(ContentViewActivity.EXTRA_TEXT, "From Interstitial Notification"))
+ .startActivities();
+ finish();
+ }
+}
diff --git a/samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/NotificationsActivity.java b/samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/NotificationsActivity.java
new file mode 100644
index 000000000..0f8093823
--- /dev/null
+++ b/samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/NotificationsActivity.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.support.appnavigation.app;
+
+import com.example.android.support.appnavigation.R;
+
+import android.app.Activity;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.v4.app.NavUtils;
+import android.support.v4.app.NotificationCompat;
+import android.support.v4.app.TaskStackBuilder;
+import android.view.MenuItem;
+import android.view.View;
+
+public class NotificationsActivity extends Activity {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.notifications);
+
+ ActionBarCompat.setDisplayHomeAsUpEnabled(this, true);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (item.getItemId() == android.R.id.home) {
+ NavUtils.navigateUpFromSameTask(this);
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ public void onPostDirect(View v) {
+ NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
+ .setTicker("Direct Notification")
+ .setSmallIcon(android.R.drawable.stat_notify_chat)
+ .setContentTitle("Direct Notification")
+ .setContentText("This will open the content viewer")
+ .setAutoCancel(true)
+ .setContentIntent(TaskStackBuilder.from(this)
+ .addParentStack(ContentViewActivity.class)
+ .addNextIntent(new Intent(this, ContentViewActivity.class)
+ .putExtra(ContentViewActivity.EXTRA_TEXT, "From Notification"))
+ .getPendingIntent(0, 0));
+ NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+ nm.notify("direct_tag", R.id.direct_notification, builder.getNotification());
+ }
+
+ public void onPostInterstitial(View v) {
+ NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
+ .setTicker("Interstitial Notification")
+ .setSmallIcon(android.R.drawable.stat_notify_chat)
+ .setContentTitle("Interstitial Notification")
+ .setContentText("This will show a detail page")
+ .setAutoCancel(true)
+ .setContentIntent(PendingIntent.getActivity(this, 0,
+ new Intent(this, InterstitialMessageActivity.class)
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
+ Intent.FLAG_ACTIVITY_CLEAR_TASK), 0));
+ NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+ nm.notify("interstitial_tag", R.id.interstitial_notification, builder.getNotification());
+ }
+}
diff --git a/samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/OutsideTaskActivity.java b/samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/OutsideTaskActivity.java
new file mode 100644
index 000000000..2f75d6bb0
--- /dev/null
+++ b/samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/OutsideTaskActivity.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.example.android.support.appnavigation.app;
+
+import com.example.android.support.appnavigation.R;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+
+public class OutsideTaskActivity extends Activity {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.outside_task);
+ }
+
+ public void onViewContent(View v) {
+ Intent intent = new Intent(Intent.ACTION_VIEW)
+ .setType("application/x-example")
+ .addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
+ startActivity(intent);
+ }
+}
diff --git a/samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/PeerActivity.java b/samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/PeerActivity.java
new file mode 100644
index 000000000..a6dbca490
--- /dev/null
+++ b/samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/PeerActivity.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.support.appnavigation.app;
+
+import com.example.android.support.appnavigation.R;
+
+import android.app.ActionBar;
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.v4.app.NavUtils;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.TextView;
+
+public class PeerActivity extends Activity {
+ private static final String EXTRA_PEER_COUNT =
+ "com.example.android.appnavigation.EXTRA_PEER_COUNT";
+
+ private int mPeerCount;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.peer);
+
+ ActionBarCompat.setDisplayHomeAsUpEnabled(this, true);
+
+ mPeerCount = getIntent().getIntExtra(EXTRA_PEER_COUNT, 0) + 1;
+ TextView tv = (TextView) findViewById(R.id.peer_counter);
+ tv.setText(getResources().getText(R.string.peer_count).toString() + mPeerCount);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (item.getItemId() == android.R.id.home) {
+ NavUtils.navigateUpFromSameTask(this);
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ public void onLaunchPeer(View v) {
+ Intent target = new Intent(this, PeerActivity.class);
+ target.putExtra(EXTRA_PEER_COUNT, mPeerCount);
+ startActivity(target);
+ }
+}
diff --git a/samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/SimpleUpActivity.java b/samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/SimpleUpActivity.java
new file mode 100644
index 000000000..7c09051ca
--- /dev/null
+++ b/samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/SimpleUpActivity.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.support.appnavigation.app;
+
+import com.example.android.support.appnavigation.R;
+
+import android.app.ActionBar;
+import android.app.Activity;
+import android.os.Bundle;
+import android.support.v4.app.NavUtils;
+import android.view.MenuItem;
+
+public class SimpleUpActivity extends Activity {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.simple_up);
+
+ ActionBarCompat.setDisplayHomeAsUpEnabled(this, true);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (item.getItemId() == android.R.id.home) {
+ NavUtils.navigateUpFromSameTask(this);
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+}
diff --git a/samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/ViewFromOtherTaskActivity.java b/samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/ViewFromOtherTaskActivity.java
new file mode 100644
index 000000000..46e6349c7
--- /dev/null
+++ b/samples/SupportAppNavigation/src/com/example/android/support/appnavigation/app/ViewFromOtherTaskActivity.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.support.appnavigation.app;
+
+import com.example.android.support.appnavigation.R;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.v4.app.NavUtils;
+import android.view.MenuItem;
+import android.view.View;
+
+public class ViewFromOtherTaskActivity extends Activity {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.view_from_other_task);
+
+ ActionBarCompat.setDisplayHomeAsUpEnabled(this, true);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (item.getItemId() == android.R.id.home) {
+ NavUtils.navigateUpFromSameTask(this);
+ return true;
+ }
+ return false;
+ }
+
+ public void onLaunchOtherTask(View v) {
+ Intent target = new Intent(this, OutsideTaskActivity.class)
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
+ Intent.FLAG_ACTIVITY_TASK_ON_HOME);
+ startActivity(target);
+ }
+}