• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.android.dialer.main.impl;
18 
19 import android.content.Context;
20 import android.support.annotation.IntDef;
21 import android.support.v4.app.Fragment;
22 import android.support.v4.app.FragmentManager;
23 import android.support.v4.app.FragmentStatePagerAdapter;
24 import com.android.dialer.common.Assert;
25 import java.lang.annotation.Retention;
26 import java.lang.annotation.RetentionPolicy;
27 
28 /** Adapter for {@link MainActivity} ViewPager. */
29 final class MainPagerAdapter extends FragmentStatePagerAdapter {
30 
31   @Retention(RetentionPolicy.SOURCE)
32   @IntDef({
33     TabIndex.SPEED_DIAL,
34     TabIndex.HISTORY,
35     TabIndex.VOICEMAIL,
36   })
37   private @interface TabIndex {
38     int SPEED_DIAL = 0;
39     int HISTORY = 1;
40     int VOICEMAIL = 2;
41   }
42 
43   private final Context context;
44 
MainPagerAdapter(Context context, FragmentManager fragmentManager)45   MainPagerAdapter(Context context, FragmentManager fragmentManager) {
46     super(fragmentManager);
47     this.context = context;
48   }
49 
50   @Override
getCount()51   public int getCount() {
52     // TODO: add logic to hide/show voicemail tab
53     return 3;
54   }
55 
56   @Override
getItem(int position)57   public Fragment getItem(int position) {
58     // TODO: implement tabs
59     return new StubFragment();
60   }
61 
62   @Override
getPageTitle(int position)63   public CharSequence getPageTitle(int position) {
64     switch (position) {
65       case TabIndex.SPEED_DIAL:
66         return context.getString(R.string.tab_title_speed_dial);
67       case TabIndex.HISTORY:
68         return context.getString(R.string.tab_title_call_history);
69       case TabIndex.VOICEMAIL:
70         return context.getString(R.string.tab_title_voicemail);
71       default:
72         throw Assert.createIllegalStateFailException("Tab position with no title: " + position);
73     }
74   }
75 }
76