Search in sources :

Example 6 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 7 with SparseArray

use of android.util.SparseArray in project ViewPagerIndicator by LuckyJayce.

the class RecycleBin method setViewTypeCount.

public void setViewTypeCount(int viewTypeCount) {
    if (viewTypeCount < 1) {
        throw new IllegalArgumentException("Can't have a viewTypeCount < 1");
    }
    // noinspection unchecked
    @SuppressWarnings("unchecked") SparseArray<View>[] scrapViews = new SparseArray[viewTypeCount];
    for (int i = 0; i < viewTypeCount; i++) {
        scrapViews[i] = new SparseArray<View>();
    }
    this.viewTypeCount = viewTypeCount;
    currentScrapViews = scrapViews[0];
    this.scrapViews = scrapViews;
}
Also used : SparseArray(android.util.SparseArray) View(android.view.View) SuppressLint(android.annotation.SuppressLint)

Example 8 with SparseArray

use of android.util.SparseArray in project ViewPagerIndicator by LuckyJayce.

the class RecycleBin method pruneScrapViews.

/**
	 * Makes sure that the size of scrapViews does not exceed the size of
	 * activeViews. (This can happen if an adapter does not recycle its views).
	 */
private void pruneScrapViews() {
    final int maxViews = activeViews.length;
    final int viewTypeCount = this.viewTypeCount;
    final SparseArray<View>[] scrapViews = this.scrapViews;
    for (int i = 0; i < viewTypeCount; ++i) {
        final SparseArray<View> scrapPile = scrapViews[i];
        int size = scrapPile.size();
        final int extras = size - maxViews;
        size--;
        for (int j = 0; j < extras; j++) {
            scrapPile.remove(scrapPile.keyAt(size--));
        }
    }
}
Also used : SparseArray(android.util.SparseArray) View(android.view.View) SuppressLint(android.annotation.SuppressLint)

Example 9 with SparseArray

use of android.util.SparseArray in project XPrivacy by M66B.

the class ApplicationInfoEx method getXApplicationList.

public static List<ApplicationInfoEx> getXApplicationList(Context context, ProgressDialog dialog) {
    // Get references
    PackageManager pm = context.getPackageManager();
    // Get app list
    SparseArray<ApplicationInfoEx> mapApp = new SparseArray<ApplicationInfoEx>();
    List<ApplicationInfoEx> listApp = new ArrayList<ApplicationInfoEx>();
    List<ApplicationInfo> listAppInfo = pm.getInstalledApplications(PackageManager.GET_META_DATA);
    if (dialog != null)
        dialog.setMax(listAppInfo.size());
    for (int app = 0; app < listAppInfo.size(); app++) {
        if (dialog != null)
            dialog.setProgress(app + 1);
        ApplicationInfo appInfo = listAppInfo.get(app);
        Util.log(null, Log.INFO, "package=" + appInfo.packageName + " uid=" + appInfo.uid);
        ApplicationInfoEx appInfoEx = new ApplicationInfoEx(context, appInfo.uid);
        if (mapApp.get(appInfoEx.getUid()) == null) {
            mapApp.put(appInfoEx.getUid(), appInfoEx);
            listApp.add(appInfoEx);
        }
    }
    // Sort result
    Collections.sort(listApp);
    return listApp;
}
Also used : SparseArray(android.util.SparseArray) PackageManager(android.content.pm.PackageManager) ArrayList(java.util.ArrayList) ApplicationInfo(android.content.pm.ApplicationInfo) SuppressLint(android.annotation.SuppressLint)

Example 10 with SparseArray

use of android.util.SparseArray in project cornerstone by Onskreen.

the class ActivityManagerService method profileControl.

public boolean profileControl(String process, boolean start, String path, ParcelFileDescriptor fd, int profileType) throws RemoteException {
    try {
        synchronized (this) {
            // its own permission.
            if (checkCallingPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER) != PackageManager.PERMISSION_GRANTED) {
                throw new SecurityException("Requires permission " + android.Manifest.permission.SET_ACTIVITY_WATCHER);
            }
            if (start && fd == null) {
                throw new IllegalArgumentException("null fd");
            }
            ProcessRecord proc = null;
            if (process != null) {
                try {
                    int pid = Integer.parseInt(process);
                    synchronized (mPidsSelfLocked) {
                        proc = mPidsSelfLocked.get(pid);
                    }
                } catch (NumberFormatException e) {
                }
                if (proc == null) {
                    HashMap<String, SparseArray<ProcessRecord>> all = mProcessNames.getMap();
                    SparseArray<ProcessRecord> procs = all.get(process);
                    if (procs != null && procs.size() > 0) {
                        proc = procs.valueAt(0);
                    }
                }
            }
            if (start && (proc == null || proc.thread == null)) {
                throw new IllegalArgumentException("Unknown process: " + process);
            }
            if (start) {
                stopProfilerLocked(null, null, 0);
                setProfileApp(proc.info, proc.processName, path, fd, false);
                mProfileProc = proc;
                mProfileType = profileType;
                try {
                    fd = fd.dup();
                } catch (IOException e) {
                    fd = null;
                }
                proc.thread.profilerControl(start, path, fd, profileType);
                fd = null;
                mProfileFd = null;
            } else {
                stopProfilerLocked(proc, path, profileType);
                if (fd != null) {
                    try {
                        fd.close();
                    } catch (IOException e) {
                    }
                }
            }
            return true;
        }
    } catch (RemoteException e) {
        throw new IllegalStateException("Process disappeared");
    } finally {
        if (fd != null) {
            try {
                fd.close();
            } catch (IOException e) {
            }
        }
    }
}
Also used : IllegalStateException(java.lang.IllegalStateException) SparseArray(android.util.SparseArray) IOException(java.io.IOException) RemoteException(android.os.RemoteException)

Aggregations

SparseArray (android.util.SparseArray)250 ArrayList (java.util.ArrayList)75 ProcessState (com.android.internal.app.procstats.ProcessState)41 Parcelable (android.os.Parcelable)37 View (android.view.View)35 ServiceState (com.android.internal.app.procstats.ServiceState)31 RemoteException (android.os.RemoteException)24 Point (android.graphics.Point)19 ArraySet (android.util.ArraySet)17 HashMap (java.util.HashMap)17 ComponentName (android.content.ComponentName)15 ProcessStats (com.android.internal.app.procstats.ProcessStats)15 UserHandle (android.os.UserHandle)14 ArrayMap (android.util.ArrayMap)14 UserInfo (android.content.pm.UserInfo)13 Paint (android.graphics.Paint)13 Bitmap (android.graphics.Bitmap)12 IOException (java.io.IOException)12 ApplicationInfo (android.content.pm.ApplicationInfo)11 SparseIntArray (android.util.SparseIntArray)11