Home | History | Annotate | Download | only in com.example.android.lnotifications
      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.os.Bundle;
     20 import android.support.design.widget.TabLayout;
     21 import android.support.v4.app.Fragment;
     22 import android.support.v4.app.FragmentActivity;
     23 import android.support.v4.app.FragmentManager;
     24 import android.support.v4.app.FragmentPagerAdapter;
     25 import android.support.v4.view.ViewPager;
     26 
     27 import static com.example.android.lnotifications.R.id.pager;
     28 
     29 /**
     30  * Launcher Activity for the L Notification samples application.
     31  */
     32 public class LNotificationActivity extends FragmentActivity {
     33 
     34     @Override
     35     protected void onCreate(Bundle savedInstanceState) {
     36         super.onCreate(savedInstanceState);
     37         setContentView(R.layout.activity_notification);
     38 
     39         // Show 3 tabs with the different notification options.
     40         ViewPager viewPager = (ViewPager) findViewById(pager);
     41         TabLayout tabs = (TabLayout) findViewById(R.id.tabs);
     42 
     43         NotificationsPagerAdapter pagerAdapter =
     44                 new NotificationsPagerAdapter(getSupportFragmentManager());
     45         viewPager.setAdapter(pagerAdapter);
     46         tabs.setupWithViewPager(viewPager);
     47     }
     48 
     49     private static class NotificationsPagerAdapter extends FragmentPagerAdapter {
     50 
     51         NotificationsPagerAdapter(FragmentManager fm) {
     52             super(fm);
     53         }
     54 
     55         @Override
     56         public Fragment getItem(int position) {
     57             switch (position) {
     58                 case 0:
     59                     return HeadsUpNotificationFragment.newInstance();
     60                 case 1:
     61                     return VisibilityMetadataFragment.newInstance();
     62                 case 2:
     63                     return OtherMetadataFragment.newInstance();
     64                 default:
     65                     break;
     66             }
     67             return null;
     68         }
     69 
     70         @Override
     71         public int getCount() {
     72             return 3;
     73         }
     74 
     75         @Override
     76         public CharSequence getPageTitle(int position) {
     77             switch (position) {
     78                 case 0:
     79                     return "Heads Up";
     80                 case 1:
     81                     return "Visibility";
     82                 case 2:
     83                     return "Others";
     84                 default:
     85                     return super.getPageTitle(position);
     86             }
     87         }
     88     }
     89 }
     90