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
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* 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.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,6 @@ import com.example.android.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 {
|
||||
@@ -30,17 +28,6 @@ public class ContentCategoryActivity extends Activity {
|
||||
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) {
|
||||
|
||||
@@ -21,11 +21,6 @@ import com.example.android.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 {
|
||||
@@ -36,8 +31,6 @@ public class ContentViewActivity extends Activity {
|
||||
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);
|
||||
@@ -47,21 +40,4 @@ public class ContentViewActivity extends Activity {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,9 @@ package com.example.android.appnavigation.app;
|
||||
import com.example.android.appnavigation.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.TaskStackBuilder;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.TaskStackBuilder;
|
||||
import android.view.View;
|
||||
|
||||
public class InterstitialMessageActivity extends Activity {
|
||||
|
||||
@@ -19,14 +19,12 @@ package com.example.android.appnavigation.app;
|
||||
import com.example.android.appnavigation.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.TaskStackBuilder;
|
||||
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 {
|
||||
@@ -34,21 +32,10 @@ public class NotificationsActivity extends Activity {
|
||||
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)
|
||||
Notification.Builder builder = new Notification.Builder(this)
|
||||
.setTicker("Direct Notification")
|
||||
.setSmallIcon(android.R.drawable.stat_notify_chat)
|
||||
.setContentTitle("Direct Notification")
|
||||
@@ -64,7 +51,7 @@ public class NotificationsActivity extends Activity {
|
||||
}
|
||||
|
||||
public void onPostInterstitial(View v) {
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
|
||||
Notification.Builder builder = new Notification.Builder(this)
|
||||
.setTicker("Interstitial Notification")
|
||||
.setSmallIcon(android.R.drawable.stat_notify_chat)
|
||||
.setContentTitle("Interstitial Notification")
|
||||
|
||||
@@ -18,12 +18,9 @@ package com.example.android.appnavigation.app;
|
||||
|
||||
import com.example.android.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;
|
||||
|
||||
@@ -38,22 +35,11 @@ public class PeerActivity extends Activity {
|
||||
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);
|
||||
|
||||
@@ -18,27 +18,13 @@ package com.example.android.appnavigation.app;
|
||||
|
||||
import com.example.android.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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,6 @@ import com.example.android.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 {
|
||||
@@ -30,17 +28,6 @@ public class ViewFromOtherTaskActivity extends Activity {
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user