3

I'm developing an app with actionbarsherlock and the ABS project is currently using android-support-v4 library (Version 18). Now I want to extend my project to support Android 6.0 and in order to use some of the methods like

ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.WRITE_CALENDAR)

or

ActivityCompat.shouldShowRequestPermissionRationale(thisActivity, Manifest.permission.READ_CONTACTS)

I require support library version 23. But ABS project is not compatible with this latest library and gives error like mAdded cannot be resolved or is not a field in Watson.java

Also, please don't suggest me to use AppCompatActivity instead of ABS as I tried it but getting stuck in a web of other mess as my project is quite big.

Vishal Afre
  • 1,013
  • 3
  • 12
  • 39

1 Answers1

8

I'm facing the same problem. Here's my solution:

Clone ActionBarSherlock

No instance field mFragments of type Landroid/support/v4/app/FragmentManagerImpl;

// android.support.v4.app.FragmentActivity

// com.android.support:support-v4:22.+
final FragmentManagerImpl mFragments = new FragmentManagerImpl();

// com.android.support:support-v4:23.+
final FragmentController mFragments = FragmentController.createController(new HostCallbacks());

// android.support.v4.app.FragmentManager.FragmentManagerImpl
ArrayList<Fragment> mAdded;

So we need to get instance of FragmentManagerImpl to access mAdded field

// android.support.v4.app.FragmentActivity
public FragmentManager getSupportFragmentManager() {
    return mFragments.getSupportFragmentManager();
}

// android.support.v4.app.FragmentController
public FragmentManager getSupportFragmentManager() {
    return mHost.getFragmentManagerImpl();
}

Add the following method to the android.support.v4.app.Watson class

@Nullable
private List<Fragment> getAddedFragments() {
    return ((FragmentManagerImpl) getSupportFragmentManager()).mAdded;
}

Add the following code to onCreatePanelMenu, onPreparePanel and onMenuItemSelected methods and replace mFragments.mAdded with fragments

List<Fragment> fragments = getAddedFragments();

FloatMath

Historically these methods were faster than the equivalent double-based {java.lang.Math} methods. On versions of Android with a JIT they became slower and have since been re-implemented to wrap calls to {java.lang.Math}. {java.lang.Math} should be used in preference.

All methods were removed from the public API in version 23.

@deprecated Use {java.lang.Math} instead.

Replace all of occurrences of FloatMath with Math in com.actionbarsherlock.internal.nineoldandroids.view.animation.AnimatorProxy

  • For the poor souls having to deal with such a task in 2019 and beyond, note that most recent versions of the Android Support library have deprecated and then removed the KeyEventCompat class that is used in the SearchView widget of ABS. You will have to choose something that is lower than v28.0.0. – Giulio Piancastelli Jun 13 '19 at 15:44