Home | History | Annotate | Download | only in app
      1 /*
      2  * Copyright (C) 2010 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 package com.example.android.apis.app;
     17 
     18 import android.app.ActionBar;
     19 import android.app.Activity;
     20 import android.content.Intent;
     21 import android.os.Bundle;
     22 import android.view.Menu;
     23 import android.view.MenuItem;
     24 import android.view.View;
     25 import android.view.Window;
     26 import android.widget.TextView;
     27 import android.widget.Toast;
     28 import com.example.android.apis.R;
     29 
     30 /**
     31  * This demonstrates implementing common navigation flows with the action bar.
     32  */
     33 public class ActionBarNavigation extends Activity {
     34     @Override
     35     protected void onCreate(Bundle savedInstanceState) {
     36         super.onCreate(savedInstanceState);
     37 
     38         // Turn on the up affordance.
     39         final ActionBar bar = getActionBar();
     40         bar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP, ActionBar.DISPLAY_HOME_AS_UP);
     41 
     42         setContentView(R.layout.action_bar_navigation);
     43         TextView text = (TextView)findViewById(R.id.launchedfrom);
     44         if (getIntent().hasCategory(Intent.CATEGORY_SAMPLE_CODE)) {
     45             text.setText("This was launched from ApiDemos");
     46         } else {
     47             text.setText("This was created from up navigation");
     48         }
     49     }
     50 
     51     public void onNewActivity(View button) {
     52         Intent intent = new Intent(this, ActionBarNavigationTarget.class);
     53         startActivity(intent);
     54     }
     55 
     56     public void onNewDocument(View button) {
     57         Intent intent = new Intent(this, ActionBarNavigationTarget.class);
     58         intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
     59         startActivity(intent);
     60     }
     61 }
     62