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);
}
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;
}
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--));
}
}
}
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;
}
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) {
}
}
}
}
Aggregations