Search in sources :

Example 1 with SparseArray

use of android.util.SparseArray in project cw-omnibus by commonsguy.

the class MenuBuilder method dispatchSaveInstanceState.

private void dispatchSaveInstanceState(Bundle outState) {
    if (mPresenters.isEmpty())
        return;
    SparseArray<Parcelable> presenterStates = new SparseArray<Parcelable>();
    for (WeakReference<MenuPresenter> ref : mPresenters) {
        final MenuPresenter presenter = ref.get();
        if (presenter == null) {
            mPresenters.remove(ref);
        } else {
            final int id = presenter.getId();
            if (id > 0) {
                final Parcelable state = presenter.onSaveInstanceState();
                if (state != null) {
                    presenterStates.put(id, state);
                }
            }
        }
    }
    outState.putSparseParcelableArray(PRESENTER_KEY, presenterStates);
}
Also used : SparseArray(android.util.SparseArray) Parcelable(android.os.Parcelable)

Example 2 with SparseArray

use of android.util.SparseArray in project SuperSLiM by TonicArtos.

the class LayoutManager method getFractionOfContentAbove.

private float getFractionOfContentAbove(RecyclerView.State state, boolean ignorePosition) {
    float fractionOffscreen = 0;
    View child = getChildAt(0);
    final int anchorPosition = getPosition(child);
    int numBeforeAnchor = 0;
    float top = getDecoratedTop(child);
    float bottom = getDecoratedBottom(child);
    if (bottom < 0) {
        fractionOffscreen = 1;
    } else if (0 <= top) {
        fractionOffscreen = 0;
    } else {
        float height = getDecoratedMeasuredHeight(child);
        fractionOffscreen = -top / height;
    }
    SectionData sd = new SectionData(this, child);
    if (sd.headerParams.isHeader && sd.headerParams.isHeaderInline()) {
        // Header must not be stickied as it is not attached after section items.
        return fractionOffscreen;
    }
    // Run through all views in the section and add up values offscreen.
    int firstPosition = -1;
    SparseArray<Boolean> positionsOffscreen = new SparseArray<>();
    for (int i = 1; i < getChildCount(); i++) {
        child = getChildAt(i);
        LayoutParams lp = (LayoutParams) child.getLayoutParams();
        if (!sd.sameSectionManager(lp)) {
            break;
        }
        final int position = getPosition(child);
        if (!ignorePosition && position < anchorPosition) {
            numBeforeAnchor += 1;
        }
        top = getDecoratedTop(child);
        bottom = getDecoratedBottom(child);
        if (bottom < 0) {
            fractionOffscreen += 1;
        } else if (0 <= top) {
            continue;
        } else {
            float height = getDecoratedMeasuredHeight(child);
            fractionOffscreen += -top / height;
        }
        if (!lp.isHeader) {
            if (firstPosition == -1) {
                firstPosition = position;
            }
            positionsOffscreen.put(position, true);
        }
    }
    return fractionOffscreen - numBeforeAnchor - getSlm(sd).howManyMissingAbove(firstPosition, positionsOffscreen);
}
Also used : SparseArray(android.util.SparseArray) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView)

Example 3 with SparseArray

use of android.util.SparseArray in project android_frameworks_base by ParanoidAndroid.

the class ActivityManagerService method cleanUpRemovedTaskLocked.

private void cleanUpRemovedTaskLocked(TaskRecord tr, int flags) {
    final boolean killProcesses = (flags & ActivityManager.REMOVE_TASK_KILL_PROCESS) != 0;
    Intent baseIntent = new Intent(tr.intent != null ? tr.intent : tr.affinityIntent);
    ComponentName component = baseIntent.getComponent();
    if (component == null) {
        Slog.w(TAG, "Now component for base intent of task: " + tr);
        return;
    }
    // Find any running services associated with this app.
    mServices.cleanUpRemovedTaskLocked(tr, component, baseIntent);
    if (killProcesses) {
        // Find any running processes associated with this app.
        final String pkg = component.getPackageName();
        ArrayList<ProcessRecord> procs = new ArrayList<ProcessRecord>();
        HashMap<String, SparseArray<ProcessRecord>> pmap = mProcessNames.getMap();
        for (SparseArray<ProcessRecord> uids : pmap.values()) {
            for (int i = 0; i < uids.size(); i++) {
                ProcessRecord proc = uids.valueAt(i);
                if (proc.userId != tr.userId) {
                    continue;
                }
                if (!proc.pkgList.contains(pkg)) {
                    continue;
                }
                procs.add(proc);
            }
        }
        // Kill the running processes.
        for (int i = 0; i < procs.size(); i++) {
            ProcessRecord pr = procs.get(i);
            if (pr.setSchedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE) {
                Slog.i(TAG, "Killing " + pr.toShortString() + ": remove task");
                EventLog.writeEvent(EventLogTags.AM_KILL, pr.userId, pr.pid, pr.processName, pr.setAdj, "remove task");
                pr.killedBackground = true;
                Process.killProcessQuiet(pr.pid);
            } else {
                pr.waitingToKill = "remove task";
            }
        }
    }
}
Also used : SparseArray(android.util.SparseArray) ArrayList(java.util.ArrayList) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) ComponentName(android.content.ComponentName)

Example 4 with SparseArray

use of android.util.SparseArray in project android_frameworks_base by ParanoidAndroid.

the class StringBlock method get.

public CharSequence get(int idx) {
    synchronized (this) {
        if (mStrings != null) {
            CharSequence res = mStrings[idx];
            if (res != null) {
                return res;
            }
        } else if (mSparseStrings != null) {
            CharSequence res = mSparseStrings.get(idx);
            if (res != null) {
                return res;
            }
        } else {
            final int num = nativeGetSize(mNative);
            if (mUseSparse && num > 250) {
                mSparseStrings = new SparseArray<CharSequence>();
            } else {
                mStrings = new CharSequence[num];
            }
        }
        String str = nativeGetString(mNative, idx);
        CharSequence res = str;
        int[] style = nativeGetStyle(mNative, idx);
        if (localLOGV)
            Log.v(TAG, "Got string: " + str);
        if (localLOGV)
            Log.v(TAG, "Got styles: " + Arrays.toString(style));
        if (style != null) {
            if (mStyleIDs == null) {
                mStyleIDs = new StyleIDs();
            }
            // the magic constant 3.
            for (int styleIndex = 0; styleIndex < style.length; styleIndex += 3) {
                int styleId = style[styleIndex];
                if (styleId == mStyleIDs.boldId || styleId == mStyleIDs.italicId || styleId == mStyleIDs.underlineId || styleId == mStyleIDs.ttId || styleId == mStyleIDs.bigId || styleId == mStyleIDs.smallId || styleId == mStyleIDs.subId || styleId == mStyleIDs.supId || styleId == mStyleIDs.strikeId || styleId == mStyleIDs.listItemId || styleId == mStyleIDs.marqueeId) {
                    // id already found skip to next style
                    continue;
                }
                String styleTag = nativeGetString(mNative, styleId);
                if (styleTag.equals("b")) {
                    mStyleIDs.boldId = styleId;
                } else if (styleTag.equals("i")) {
                    mStyleIDs.italicId = styleId;
                } else if (styleTag.equals("u")) {
                    mStyleIDs.underlineId = styleId;
                } else if (styleTag.equals("tt")) {
                    mStyleIDs.ttId = styleId;
                } else if (styleTag.equals("big")) {
                    mStyleIDs.bigId = styleId;
                } else if (styleTag.equals("small")) {
                    mStyleIDs.smallId = styleId;
                } else if (styleTag.equals("sup")) {
                    mStyleIDs.supId = styleId;
                } else if (styleTag.equals("sub")) {
                    mStyleIDs.subId = styleId;
                } else if (styleTag.equals("strike")) {
                    mStyleIDs.strikeId = styleId;
                } else if (styleTag.equals("li")) {
                    mStyleIDs.listItemId = styleId;
                } else if (styleTag.equals("marquee")) {
                    mStyleIDs.marqueeId = styleId;
                }
            }
            res = applyStyles(str, style, mStyleIDs);
        }
        if (mStrings != null)
            mStrings[idx] = res;
        else
            mSparseStrings.put(idx, res);
        return res;
    }
}
Also used : SparseArray(android.util.SparseArray) Paint(android.graphics.Paint)

Example 5 with SparseArray

use of android.util.SparseArray in project android_frameworks_base by ParanoidAndroid.

the class BatteryStats method dumpCheckinLocked.

@SuppressWarnings("unused")
public void dumpCheckinLocked(PrintWriter pw, String[] args, List<ApplicationInfo> apps) {
    prepareForDumpLocked();
    boolean isUnpluggedOnly = false;
    for (String arg : args) {
        if ("-u".equals(arg)) {
            if (LOCAL_LOGV)
                Log.v("BatteryStats", "Dumping unplugged data");
            isUnpluggedOnly = true;
        }
    }
    if (apps != null) {
        SparseArray<ArrayList<String>> uids = new SparseArray<ArrayList<String>>();
        for (int i = 0; i < apps.size(); i++) {
            ApplicationInfo ai = apps.get(i);
            ArrayList<String> pkgs = uids.get(ai.uid);
            if (pkgs == null) {
                pkgs = new ArrayList<String>();
                uids.put(ai.uid, pkgs);
            }
            pkgs.add(ai.packageName);
        }
        SparseArray<? extends Uid> uidStats = getUidStats();
        final int NU = uidStats.size();
        String[] lineArgs = new String[2];
        for (int i = 0; i < NU; i++) {
            int uid = uidStats.keyAt(i);
            ArrayList<String> pkgs = uids.get(uid);
            if (pkgs != null) {
                for (int j = 0; j < pkgs.size(); j++) {
                    lineArgs[0] = Integer.toString(uid);
                    lineArgs[1] = pkgs.get(j);
                    dumpLine(pw, 0, /* uid */
                    "i", /* category */
                    UID_DATA, (Object[]) lineArgs);
                }
            }
        }
    }
    if (isUnpluggedOnly) {
        dumpCheckinLocked(pw, STATS_SINCE_UNPLUGGED, -1);
    } else {
        dumpCheckinLocked(pw, STATS_SINCE_CHARGED, -1);
        dumpCheckinLocked(pw, STATS_SINCE_UNPLUGGED, -1);
    }
}
Also used : SparseArray(android.util.SparseArray) ArrayList(java.util.ArrayList) ApplicationInfo(android.content.pm.ApplicationInfo)

Aggregations

SparseArray (android.util.SparseArray)414 ArrayList (java.util.ArrayList)105 Test (org.junit.Test)71 ProcessState (com.android.internal.app.procstats.ProcessState)46 View (android.view.View)44 Parcelable (android.os.Parcelable)43 UserInfo (android.content.pm.UserInfo)40 RemoteException (android.os.RemoteException)37 ServiceState (com.android.internal.app.procstats.ServiceState)36 Drawable (android.graphics.drawable.Drawable)35 Bitmap (android.graphics.Bitmap)30 Preference (android.support.v7.preference.Preference)30 StorageStatsSource (com.android.settingslib.applications.StorageStatsSource)28 UserHandle (android.os.UserHandle)27 HashMap (java.util.HashMap)23 ArrayMap (android.util.ArrayMap)22 Point (android.graphics.Point)21 UserIconDrawable (com.android.settingslib.drawable.UserIconDrawable)21 ProcessStats (com.android.internal.app.procstats.ProcessStats)20 Bundle (android.os.Bundle)18