2015-07-26 17:21:54 +02:00
|
|
|
package net.simonvt.menudrawer.compat;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.os.Build;
|
2020-09-30 14:47:59 +02:00
|
|
|
import timber.log.Timber;
|
2015-07-26 17:21:54 +02:00
|
|
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
|
|
|
public final class ActionBarHelper {
|
|
|
|
static final boolean DEBUG = false;
|
|
|
|
|
|
|
|
private Activity mActivity;
|
|
|
|
|
|
|
|
private Object mIndicatorInfo;
|
|
|
|
|
|
|
|
private boolean mUsesCompat;
|
|
|
|
|
|
|
|
public ActionBarHelper(Activity activity) {
|
|
|
|
mActivity = activity;
|
|
|
|
|
|
|
|
try {
|
|
|
|
Class clazz = activity.getClass();
|
|
|
|
Method m = clazz.getMethod("getSupportActionBar");
|
|
|
|
mUsesCompat = true;
|
|
|
|
} catch (NoSuchMethodException e) {
|
|
|
|
if (DEBUG) {
|
2020-09-30 14:47:59 +02:00
|
|
|
Timber.e(e,
|
|
|
|
"Activity " + activity.getClass().getSimpleName() + " does not use a compatibility action bar");
|
2015-07-26 17:21:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mIndicatorInfo = getIndicatorInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
private Object getIndicatorInfo() {
|
|
|
|
if (mUsesCompat && Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
|
|
|
return ActionBarHelperCompat.getIndicatorInfo(mActivity);
|
|
|
|
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
|
|
|
return ActionBarHelperNative.getIndicatorInfo(mActivity);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setActionBarUpIndicator(Drawable drawable, int contentDesc) {
|
|
|
|
if (mUsesCompat && Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
|
|
|
ActionBarHelperCompat.setActionBarUpIndicator(mIndicatorInfo, mActivity, drawable, contentDesc);
|
|
|
|
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
|
|
|
ActionBarHelperNative.setActionBarUpIndicator(mIndicatorInfo, mActivity, drawable, contentDesc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setActionBarDescription(int contentDesc) {
|
|
|
|
if (mUsesCompat && Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
|
|
|
ActionBarHelperCompat.setActionBarDescription(mIndicatorInfo, mActivity, contentDesc);
|
|
|
|
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
|
|
|
ActionBarHelperNative.setActionBarDescription(mIndicatorInfo, mActivity, contentDesc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Drawable getThemeUpIndicator() {
|
|
|
|
if (mUsesCompat && Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
|
|
|
return ActionBarHelperCompat.getThemeUpIndicator(mIndicatorInfo);
|
|
|
|
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
|
|
|
return ActionBarHelperNative.getThemeUpIndicator(mIndicatorInfo, mActivity);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDisplayShowHomeAsUpEnabled(boolean enabled) {
|
|
|
|
if (mUsesCompat && Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
|
|
|
ActionBarHelperCompat.setDisplayHomeAsUpEnabled(mIndicatorInfo, enabled);
|
|
|
|
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
|
|
|
ActionBarHelperNative.setDisplayHomeAsUpEnabled(mActivity, enabled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|