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
17package com.example.android.support.appnavigation.app;
18
19import com.example.android.support.appnavigation.R;
20
21import android.app.ActionBar;
22import android.app.Activity;
23import android.content.Intent;
24import android.os.Bundle;
25import android.support.v4.app.NavUtils;
26import android.view.MenuItem;
27import android.view.View;
28import android.widget.TextView;
29
30public 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