1 /*
2  * Copyright (C) 2013 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 
18 package android.support.v4.app;
19 
20 import android.R;
21 import android.app.ActionBar;
22 import android.app.Activity;
23 import android.content.Context;
24 import android.content.res.TypedArray;
25 import android.graphics.drawable.Drawable;
26 import android.util.Log;
27 
28 class ActionBarDrawerToggleJellybeanMR2 {
29     private static final String TAG = "ActionBarDrawerToggleImplJellybeanMR2";
30 
31     private static final int[] THEME_ATTRS = new int[] {
32             R.attr.homeAsUpIndicator
33     };
34 
setActionBarUpIndicator(Object info, Activity activity, Drawable drawable, int contentDescRes)35     public static Object setActionBarUpIndicator(Object info, Activity activity,
36             Drawable drawable, int contentDescRes) {
37         final ActionBar actionBar = activity.getActionBar();
38         if (actionBar != null) {
39             actionBar.setHomeAsUpIndicator(drawable);
40             actionBar.setHomeActionContentDescription(contentDescRes);
41         }
42         return info;
43     }
44 
setActionBarDescription(Object info, Activity activity, int contentDescRes)45     public static Object setActionBarDescription(Object info, Activity activity,
46             int contentDescRes) {
47         final ActionBar actionBar = activity.getActionBar();
48         if (actionBar != null) {
49             actionBar.setHomeActionContentDescription(contentDescRes);
50         }
51         return info;
52     }
53 
getThemeUpIndicator(Activity activity)54     public static Drawable getThemeUpIndicator(Activity activity) {
55         final ActionBar actionBar = activity.getActionBar();
56         final Context context;
57         if (actionBar != null) {
58             context = actionBar.getThemedContext();
59         } else {
60             context = activity;
61         }
62 
63         final TypedArray a = context.obtainStyledAttributes(null, THEME_ATTRS,
64                 R.attr.actionBarStyle, 0);
65         final Drawable result = a.getDrawable(0);
66         a.recycle();
67         return result;
68     }
69 }
70