• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright 2014 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.lnotifications;
18 
19 import android.app.ActionBar;
20 import android.app.Activity;
21 import android.app.Fragment;
22 import android.app.FragmentTransaction;
23 import android.os.Bundle;
24 
25 /**
26  * Launcher Activity for the L Notification samples application.
27  */
28 public class LNotificationActivity extends Activity {
29 
30     @Override
onCreate(Bundle savedInstanceState)31     protected void onCreate(Bundle savedInstanceState) {
32         super.onCreate(savedInstanceState);
33         setContentView(R.layout.activity_notification);
34         setTitle(R.string.title_lnotification_activity);
35         ActionBar actionBar = getActionBar();
36 
37         // Use ViewPager in the support library where possible.
38         // At this time, the support library for L is not ready so using the deprecated method
39         // to create tabs.
40         actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
41         ActionBar.Tab tabHeadsUpNotification = actionBar.newTab().setText("Heads Up");
42         ActionBar.Tab tabVisibilityMetadata = actionBar.newTab().setText("Visibility");
43         ActionBar.Tab tabOtherMetadata = actionBar.newTab().setText("Others");
44         tabHeadsUpNotification.setTabListener(new FragmentTabListener(HeadsUpNotificationFragment
45                 .newInstance()));
46         tabVisibilityMetadata.setTabListener(new FragmentTabListener(VisibilityMetadataFragment
47                 .newInstance()));
48         tabOtherMetadata.setTabListener(new FragmentTabListener(OtherMetadataFragment.newInstance
49                 ()));
50         actionBar.addTab(tabHeadsUpNotification, 0);
51         actionBar.addTab(tabVisibilityMetadata, 1);
52         actionBar.addTab(tabOtherMetadata, 2);
53     }
54 
55     /**
56      * TabListener that replaces a Fragment when a tab is clicked.
57      */
58     private static class FragmentTabListener implements ActionBar.TabListener {
59         public Fragment fragment;
60 
FragmentTabListener(Fragment fragment)61         public FragmentTabListener(Fragment fragment) {
62             this.fragment = fragment;
63         }
64 
65         @Override
onTabReselected(ActionBar.Tab tab, FragmentTransaction ft)66         public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
67             //do nothing.
68         }
69 
70         @Override
onTabSelected(ActionBar.Tab tab, FragmentTransaction ft)71         public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
72             ft.replace(R.id.container, fragment);
73         }
74 
75         @Override
onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft)76         public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
77             ft.remove(fragment);
78         }
79     }
80 }
81