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.support.annotation.RequiresApi; 27 28 @RequiresApi(18) 29 class ActionBarDrawerToggleJellybeanMR2 { 30 private static final String TAG = "ActionBarDrawerToggleImplJellybeanMR2"; 31 32 private static final int[] THEME_ATTRS = new int[] { 33 R.attr.homeAsUpIndicator 34 }; 35 36 public static Object setActionBarUpIndicator(Object info, Activity activity, 37 Drawable drawable, int contentDescRes) { 38 final ActionBar actionBar = activity.getActionBar(); 39 if (actionBar != null) { 40 actionBar.setHomeAsUpIndicator(drawable); 41 actionBar.setHomeActionContentDescription(contentDescRes); 42 } 43 return info; 44 } 45 46 public static Object setActionBarDescription(Object info, Activity activity, 47 int contentDescRes) { 48 final ActionBar actionBar = activity.getActionBar(); 49 if (actionBar != null) { 50 actionBar.setHomeActionContentDescription(contentDescRes); 51 } 52 return info; 53 } 54 55 public static Drawable getThemeUpIndicator(Activity activity) { 56 final ActionBar actionBar = activity.getActionBar(); 57 final Context context; 58 if (actionBar != null) { 59 context = actionBar.getThemedContext(); 60 } else { 61 context = activity; 62 } 63 64 final TypedArray a = context.obtainStyledAttributes(null, THEME_ATTRS, 65 R.attr.actionBarStyle, 0); 66 final Drawable result = a.getDrawable(0); 67 a.recycle(); 68 return result; 69 } 70 } 71