Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3e82ba1a authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Make ArrayMap public! :)

Also do some tweaking of the various container classes
to synchronize them with the support lib and make it
easier to copy code between the two.

And update activity/fragment to use ArrayMap.

Change-Id: I3cfe82392a17119dfc72c3d9961f64e1914f42be
parent cdae0f3c
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -24781,6 +24781,33 @@ package android.util {
    ctor public AndroidRuntimeException(java.lang.Exception);
  }
  public final class ArrayMap implements java.util.Map {
    ctor public ArrayMap();
    ctor public ArrayMap(int);
    ctor public ArrayMap(android.util.ArrayMap);
    method public void clear();
    method public boolean containsAll(java.util.Collection<?>);
    method public boolean containsKey(java.lang.Object);
    method public boolean containsValue(java.lang.Object);
    method public void ensureCapacity(int);
    method public java.util.Set<java.util.Map.Entry<K, V>> entrySet();
    method public V get(java.lang.Object);
    method public boolean isEmpty();
    method public K keyAt(int);
    method public java.util.Set<K> keySet();
    method public V put(K, V);
    method public void putAll(android.util.ArrayMap<? extends K, ? extends V>);
    method public void putAll(java.util.Map<? extends K, ? extends V>);
    method public V remove(java.lang.Object);
    method public boolean removeAll(java.util.Collection<?>);
    method public V removeAt(int);
    method public boolean retainAll(java.util.Collection<?>);
    method public V setValueAt(int, V);
    method public int size();
    method public V valueAt(int);
    method public java.util.Collection<V> values();
  }
  public class AtomicFile {
    ctor public AtomicFile(java.io.File);
    method public void delete();
@@ -25134,6 +25161,7 @@ package android.util {
    method public void put(int, E);
    method public void remove(int);
    method public void removeAt(int);
    method public void removeAtRange(int, int);
    method public void setValueAt(int, E);
    method public int size();
    method public E valueAt(int);
+27 −24
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.app;

import android.util.ArrayMap;
import com.android.internal.app.ActionBarImpl;
import com.android.internal.policy.PolicyManager;

@@ -700,7 +701,7 @@ public class Activity extends ContextThemeWrapper
        Object activity;
        HashMap<String, Object> children;
        ArrayList<Fragment> fragments;
        HashMap<String, LoaderManagerImpl> loaders;
        ArrayMap<String, LoaderManagerImpl> loaders;
    }
    /* package */ NonConfigurationInstances mLastNonConfigurationInstances;
    
@@ -725,7 +726,7 @@ public class Activity extends ContextThemeWrapper
        }
    };
    
    HashMap<String, LoaderManagerImpl> mAllLoaderManagers;
    ArrayMap<String, LoaderManagerImpl> mAllLoaderManagers;
    LoaderManagerImpl mLoaderManager;
    
    private static final class ManagedCursor {
@@ -819,13 +820,13 @@ public class Activity extends ContextThemeWrapper
            return mLoaderManager;
        }
        mCheckedForLoaderManager = true;
        mLoaderManager = getLoaderManager(null, mLoadersStarted, true);
        mLoaderManager = getLoaderManager("(root)", mLoadersStarted, true);
        return mLoaderManager;
    }
    
    LoaderManagerImpl getLoaderManager(String who, boolean started, boolean create) {
        if (mAllLoaderManagers == null) {
            mAllLoaderManagers = new HashMap<String, LoaderManagerImpl>();
            mAllLoaderManagers = new ArrayMap<String, LoaderManagerImpl>();
        }
        LoaderManagerImpl lm = mAllLoaderManagers.get(who);
        if (lm == null) {
@@ -1036,7 +1037,7 @@ public class Activity extends ContextThemeWrapper
            if (mLoaderManager != null) {
                mLoaderManager.doStart();
            } else if (!mCheckedForLoaderManager) {
                mLoaderManager = getLoaderManager(null, mLoadersStarted, false);
                mLoaderManager = getLoaderManager("(root)", mLoadersStarted, false);
            }
            mCheckedForLoaderManager = true;
        }
@@ -1648,10 +1649,12 @@ public class Activity extends ContextThemeWrapper
        if (mAllLoaderManagers != null) {
            // prune out any loader managers that were already stopped and so
            // have nothing useful to retain.
            LoaderManagerImpl loaders[] = new LoaderManagerImpl[mAllLoaderManagers.size()];
            mAllLoaderManagers.values().toArray(loaders);
            if (loaders != null) {
                for (int i=0; i<loaders.length; i++) {
            final int N = mAllLoaderManagers.size();
            LoaderManagerImpl loaders[] = new LoaderManagerImpl[N];
            for (int i=N-1; i>=0; i--) {
                loaders[i] = mAllLoaderManagers.valueAt(i);
            }
            for (int i=0; i<N; i++) {
                LoaderManagerImpl lm = loaders[i];
                if (lm.mRetaining) {
                    retainLoaders = true;
@@ -1661,7 +1664,6 @@ public class Activity extends ContextThemeWrapper
                }
            }
        }
        }
        if (activity == null && children == null && fragments == null && !retainLoaders) {
            return null;
        }
@@ -5236,17 +5238,18 @@ public class Activity extends ContextThemeWrapper
        }
        mFragments.dispatchStart();
        if (mAllLoaderManagers != null) {
            LoaderManagerImpl loaders[] = new LoaderManagerImpl[mAllLoaderManagers.size()];
            mAllLoaderManagers.values().toArray(loaders);
            if (loaders != null) {
                for (int i=0; i<loaders.length; i++) {
            final int N = mAllLoaderManagers.size();
            LoaderManagerImpl loaders[] = new LoaderManagerImpl[N];
            for (int i=N-1; i>=0; i--) {
                loaders[i] = mAllLoaderManagers.valueAt(i);
            }
            for (int i=0; i<N; i++) {
                LoaderManagerImpl lm = loaders[i];
                lm.finishRetain();
                lm.doReportStart();
            }
        }
    }
    }
    
    final void performRestart() {
        mFragments.noteStateNotSaved();
+3 −4
Original line number Diff line number Diff line
@@ -16,12 +16,11 @@

package android.app;

import android.Manifest;
import android.util.ArrayMap;
import com.android.internal.app.IAppOpsService;
import com.android.internal.app.IAppOpsCallback;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.content.Context;
@@ -53,8 +52,8 @@ import android.os.RemoteException;
public class AppOpsManager {
    final Context mContext;
    final IAppOpsService mService;
    final HashMap<Callback, IAppOpsCallback> mModeWatchers
            = new HashMap<Callback, IAppOpsCallback>();
    final ArrayMap<Callback, IAppOpsCallback> mModeWatchers
            = new ArrayMap<Callback, IAppOpsCallback>();

    public static final int MODE_ALLOWED = 0;
    public static final int MODE_IGNORED = 1;
+3 −3
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AndroidRuntimeException;
import android.util.ArrayMap;
import android.util.AttributeSet;
import android.util.DebugUtils;
import android.util.Log;
@@ -43,7 +44,6 @@ import android.widget.AdapterView;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.HashMap;

final class FragmentState implements Parcelable {
    final String mClassName;
@@ -342,8 +342,8 @@ final class FragmentState implements Parcelable {
 * the activity UI was in.
 */
public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListener {
    private static final HashMap<String, Class<?>> sClassMap =
            new HashMap<String, Class<?>>();
    private static final ArrayMap<String, Class<?>> sClassMap =
            new ArrayMap<String, Class<?>>();
    
    static final int INVALID_STATE = -1;   // Invalid state used as a null value.
    static final int INITIALIZING = 0;     // Not yet created.
+9 −11
Original line number Diff line number Diff line
@@ -44,8 +44,6 @@ import java.util.Set;
 * you have no control over this shrinking -- if you set a capacity and then remove an
 * item, it may reduce the capacity to better match the current size.  In the future an
 * explicit call to set the capacity should turn off this aggressive shrinking behavior.</p>
 *
 * @hide
 */
public final class ArrayMap<K, V> implements Map<K, V> {
    private static final boolean DEBUG = false;
@@ -86,7 +84,7 @@ public final class ArrayMap<K, V> implements Map<K, V> {
            return ~0;
        }

        int index = SparseArray.binarySearch(mHashes, N, hash);
        int index = ContainerHelpers.binarySearch(mHashes, N, hash);

        // If the hash code wasn't found, then we have no entry for this key.
        if (index < 0) {
@@ -188,8 +186,8 @@ public final class ArrayMap<K, V> implements Map<K, V> {
     * will grow once items are added to it.
     */
    public ArrayMap() {
        mHashes = SparseArray.EMPTY_INTS;
        mArray = SparseArray.EMPTY_OBJECTS;
        mHashes = ContainerHelpers.EMPTY_INTS;
        mArray = ContainerHelpers.EMPTY_OBJECTS;
        mSize = 0;
    }

@@ -198,8 +196,8 @@ public final class ArrayMap<K, V> implements Map<K, V> {
     */
    public ArrayMap(int capacity) {
        if (capacity == 0) {
            mHashes = SparseArray.EMPTY_INTS;
            mArray = SparseArray.EMPTY_OBJECTS;
            mHashes = ContainerHelpers.EMPTY_INTS;
            mArray = ContainerHelpers.EMPTY_OBJECTS;
        } else {
            allocArrays(capacity);
        }
@@ -223,8 +221,8 @@ public final class ArrayMap<K, V> implements Map<K, V> {
    public void clear() {
        if (mSize != 0) {
            freeArrays(mHashes, mArray, mSize);
            mHashes = SparseArray.EMPTY_INTS;
            mArray = SparseArray.EMPTY_OBJECTS;
            mHashes = ContainerHelpers.EMPTY_INTS;
            mArray = ContainerHelpers.EMPTY_OBJECTS;
            mSize = 0;
        }
    }
@@ -439,8 +437,8 @@ public final class ArrayMap<K, V> implements Map<K, V> {
            // Now empty.
            if (DEBUG) Log.d(TAG, "remove: shrink from " + mHashes.length + " to 0");
            freeArrays(mHashes, mArray, mSize);
            mHashes = SparseArray.EMPTY_INTS;
            mArray = SparseArray.EMPTY_OBJECTS;
            mHashes = ContainerHelpers.EMPTY_INTS;
            mArray = ContainerHelpers.EMPTY_OBJECTS;
            mSize = 0;
        } else {
            if (mHashes.length > (BASE_SIZE*2) && mSize < mHashes.length/3) {
Loading