1 /*
2  * Copyright 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 
17 package com.example.android.tabcompat.lib;
18 
19 import android.graphics.drawable.Drawable;
20 import android.support.v4.app.Fragment;
21 import android.support.v4.app.FragmentActivity;
22 
23 /**
24  * A base implementation of the {@link CompatTab} interface.
25  */
26 public class CompatTabEclair extends CompatTab {
27     private CompatTabListener mCallback;
28     private CharSequence mText;
29     private Drawable mIcon;
30     private Fragment mFragment;
31 
CompatTabEclair(FragmentActivity activity, String tag)32     protected CompatTabEclair(FragmentActivity activity, String tag) {
33         super(activity, tag);
34     }
35 
36     @Override
setText(int resId)37     public CompatTab setText(int resId) {
38         mText = mActivity.getResources().getText(resId);
39         return this;
40     }
41 
42     @Override
setIcon(int resId)43     public CompatTab setIcon(int resId) {
44         mIcon = mActivity.getResources().getDrawable(resId);
45         return this;
46     }
47 
48     @Override
setTabListener(CompatTabListener callback)49     public CompatTab setTabListener(CompatTabListener callback) {
50         mCallback = callback;
51         return this;
52     }
53 
54     @Override
setFragment(Fragment fragment)55     public CompatTab setFragment(Fragment fragment) {
56         mFragment = fragment;
57         return this;
58     }
59 
60     @Override
getFragment()61     public Fragment getFragment() {
62         return mFragment;
63     }
64 
65     @Override
getText()66     public CharSequence getText() {
67         return mText;
68     }
69 
70     @Override
getIcon()71     public Drawable getIcon() {
72         return mIcon;
73     }
74 
75     @Override
getTab()76     public Object getTab() {
77         return null;
78     }
79 
80     @Override
getCallback()81     public CompatTabListener getCallback() {
82         return mCallback;
83     }
84 }
85