86 lines
3.6 KiB
Java
86 lines
3.6 KiB
Java
package androidx.appcompat.app;
|
|
|
|
import android.app.ActionBar;
|
|
import android.app.Activity;
|
|
import android.content.res.TypedArray;
|
|
import android.graphics.drawable.Drawable;
|
|
import android.util.Log;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.ImageView;
|
|
import java.lang.reflect.Method;
|
|
public class ActionBarDrawerToggleHoneycomb {
|
|
private static final String TAG = "ActionBarDrawerToggleHC";
|
|
private static final int[] THEME_ATTRS = {16843531};
|
|
|
|
public static class SetIndicatorInfo {
|
|
public Method setHomeActionContentDescription;
|
|
public Method setHomeAsUpIndicator;
|
|
public ImageView upIndicatorView;
|
|
|
|
public SetIndicatorInfo(Activity activity) {
|
|
try {
|
|
this.setHomeAsUpIndicator = ActionBar.class.getDeclaredMethod("setHomeAsUpIndicator", Drawable.class);
|
|
this.setHomeActionContentDescription = ActionBar.class.getDeclaredMethod("setHomeActionContentDescription", Integer.TYPE);
|
|
} catch (NoSuchMethodException unused) {
|
|
View findViewById = activity.findViewById(16908332);
|
|
if (findViewById != null) {
|
|
ViewGroup viewGroup = (ViewGroup) findViewById.getParent();
|
|
if (viewGroup.getChildCount() == 2) {
|
|
View childAt = viewGroup.getChildAt(0);
|
|
childAt = childAt.getId() == 16908332 ? viewGroup.getChildAt(1) : childAt;
|
|
if (childAt instanceof ImageView) {
|
|
this.upIndicatorView = (ImageView) childAt;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private ActionBarDrawerToggleHoneycomb() {
|
|
}
|
|
|
|
public static Drawable getThemeUpIndicator(Activity activity) {
|
|
TypedArray obtainStyledAttributes = activity.obtainStyledAttributes(THEME_ATTRS);
|
|
Drawable drawable = obtainStyledAttributes.getDrawable(0);
|
|
obtainStyledAttributes.recycle();
|
|
return drawable;
|
|
}
|
|
|
|
public static SetIndicatorInfo setActionBarDescription(SetIndicatorInfo setIndicatorInfo, Activity activity, int i) {
|
|
if (setIndicatorInfo == null) {
|
|
setIndicatorInfo = new SetIndicatorInfo(activity);
|
|
}
|
|
if (setIndicatorInfo.setHomeAsUpIndicator != null) {
|
|
try {
|
|
setIndicatorInfo.setHomeActionContentDescription.invoke(activity.getActionBar(), Integer.valueOf(i));
|
|
} catch (Exception e) {
|
|
Log.w(TAG, "Couldn't set content description via JB-MR2 API", e);
|
|
}
|
|
}
|
|
return setIndicatorInfo;
|
|
}
|
|
|
|
public static SetIndicatorInfo setActionBarUpIndicator(Activity activity, Drawable drawable, int i) {
|
|
SetIndicatorInfo setIndicatorInfo = new SetIndicatorInfo(activity);
|
|
if (setIndicatorInfo.setHomeAsUpIndicator != null) {
|
|
try {
|
|
ActionBar actionBar = activity.getActionBar();
|
|
setIndicatorInfo.setHomeAsUpIndicator.invoke(actionBar, drawable);
|
|
setIndicatorInfo.setHomeActionContentDescription.invoke(actionBar, Integer.valueOf(i));
|
|
} catch (Exception e) {
|
|
Log.w(TAG, "Couldn't set home-as-up indicator via JB-MR2 API", e);
|
|
}
|
|
} else {
|
|
ImageView imageView = setIndicatorInfo.upIndicatorView;
|
|
if (imageView != null) {
|
|
imageView.setImageDrawable(drawable);
|
|
} else {
|
|
Log.w(TAG, "Couldn't set home-as-up indicator");
|
|
}
|
|
}
|
|
return setIndicatorInfo;
|
|
}
|
|
}
|