Skip to content

Commit

Permalink
activity no longer required to derive from ABS activities, now it onl…
Browse files Browse the repository at this point in the history
…y needs to have a method called 'getSupportActionBar'
  • Loading branch information
ManuelPeinado committed Jun 15, 2013
1 parent 1631e1c commit f340e5f
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*/
package com.manuelpeinado.fadingactionbar;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
Expand Down Expand Up @@ -155,7 +158,7 @@ public void initActionBar(Activity activity) {
mActionBarBackgroundDrawable.setAlpha(0);
}

private ActionBar getActionBar(Activity activity) {
protected ActionBar getActionBar(Activity activity) {
if (activity instanceof SherlockActivity) {
return ((SherlockActivity) activity).getSupportActionBar();
}
Expand All @@ -165,7 +168,20 @@ private ActionBar getActionBar(Activity activity) {
if (activity instanceof SherlockListActivity) {
return ((SherlockListActivity) activity).getSupportActionBar();
}
throw new RuntimeException("Activity should derive from one of the ActionBarSherlock");
try {
Method method = activity.getClass().getMethod("getSupportActionBar");
return (ActionBar) method.invoke(activity);
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
throw new RuntimeException("Activity should derive from one of the ActionBarSherlock activities "
+ "or implement a method called getSupportActionBar");
}

private Drawable.Callback mDrawableCallback = new Drawable.Callback() {
Expand Down

0 comments on commit f340e5f

Please sign in to comment.