1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.example.android.appnavigation.app; 18 19 import com.example.android.appnavigation.R; 20 21 import android.app.ActionBar; 22 import android.app.Activity; 23 import android.content.Intent; 24 import android.os.Bundle; 25 import android.support.v4.app.NavUtils; 26 import android.view.MenuItem; 27 import android.view.View; 28 import android.widget.TextView; 29 30 public class PeerActivity extends Activity { 31 private static final String EXTRA_PEER_COUNT = 32 "com.example.android.appnavigation.EXTRA_PEER_COUNT"; 33 34 private int mPeerCount; 35 36 @Override 37 protected void onCreate(Bundle savedInstanceState) { 38 super.onCreate(savedInstanceState); 39 setContentView(R.layout.peer); 40 41 ActionBarCompat.setDisplayHomeAsUpEnabled(this, true); 42 43 mPeerCount = getIntent().getIntExtra(EXTRA_PEER_COUNT, 0) + 1; 44 TextView tv = (TextView) findViewById(R.id.peer_counter); 45 tv.setText(getResources().getText(R.string.peer_count).toString() + mPeerCount); 46 } 47 48 @Override 49 public boolean onOptionsItemSelected(MenuItem item) { 50 if (item.getItemId() == android.R.id.home) { 51 NavUtils.navigateUpFromSameTask(this); 52 return true; 53 } 54 return super.onOptionsItemSelected(item); 55 } 56 57 public void onLaunchPeer(View v) { 58 Intent target = new Intent(this, PeerActivity.class); 59 target.putExtra(EXTRA_PEER_COUNT, mPeerCount); 60 startActivity(target); 61 } 62 } 63