Search in sources :

Example 1 with LongSparseArray

use of android.support.v4.util.LongSparseArray in project SeriesGuide by UweTrottmann.

the class SectionedHistoryAdapter method generateHeaderList.

protected List<HeaderData> generateHeaderList() {
    int count = getCount();
    if (count == 0) {
        return null;
    }
    LongSparseArray<HeaderData> mapping = new LongSparseArray<>();
    List<HeaderData> headers = new ArrayList<>();
    for (int position = 0; position < count; position++) {
        long headerId = getHeaderId(position);
        HeaderData headerData = mapping.get(headerId);
        if (headerData == null) {
            headerData = new HeaderData(position);
            headers.add(headerData);
        }
        headerData.incrementCount();
        mapping.put(headerId, headerData);
    }
    return headers;
}
Also used : LongSparseArray(android.support.v4.util.LongSparseArray) ArrayList(java.util.ArrayList) HeaderData(com.battlelancer.seriesguide.adapters.model.HeaderData)

Example 2 with LongSparseArray

use of android.support.v4.util.LongSparseArray in project Klyph by jonathangerbaud.

the class AbsHListView method onSaveInstanceState.

@Override
public Parcelable onSaveInstanceState() {
    /*
		 * This doesn't really make sense as the place to dismiss the popups, but there don't seem to be any other useful hooks that
		 * happen early enough to keep from getting complaints about having leaked the window.
		 */
    Parcelable superState = super.onSaveInstanceState();
    SavedState ss = new SavedState(superState);
    if (mPendingSync != null) {
        // Just keep what we last restored.
        ss.selectedId = mPendingSync.selectedId;
        ss.firstId = mPendingSync.firstId;
        ss.viewLeft = mPendingSync.viewLeft;
        ss.position = mPendingSync.position;
        ss.width = mPendingSync.width;
        ss.filter = mPendingSync.filter;
        ss.inActionMode = mPendingSync.inActionMode;
        ss.checkedItemCount = mPendingSync.checkedItemCount;
        ss.checkState = mPendingSync.checkState;
        ss.checkIdState = mPendingSync.checkIdState;
        return ss;
    }
    boolean haveChildren = getChildCount() > 0 && mItemCount > 0;
    long selectedId = getSelectedItemId();
    ss.selectedId = selectedId;
    ss.width = getWidth();
    if (selectedId >= 0) {
        // Remember the selection
        ss.viewLeft = mSelectedLeft;
        ss.position = getSelectedItemPosition();
        ss.firstId = INVALID_POSITION;
    } else {
        if (haveChildren && mFirstPosition > 0) {
            // Remember the position of the first child.
            // We only do this if we are not currently at the top of
            // the list, for two reasons:
            // (1) The list may be in the process of becoming empty, in
            // which case mItemCount may not be 0, but if we try to
            // ask for any information about position 0 we will crash.
            // (2) Being "at the top" seems like a special case, anyway,
            // and the user wouldn't expect to end up somewhere else when
            // they revisit the list even if its content has changed.
            View v = getChildAt(0);
            ss.viewLeft = v.getLeft();
            int firstPos = mFirstPosition;
            if (firstPos >= mItemCount) {
                firstPos = mItemCount - 1;
            }
            ss.position = firstPos;
            ss.firstId = mAdapter.getItemId(firstPos);
        } else {
            ss.viewLeft = 0;
            ss.firstId = INVALID_POSITION;
            ss.position = 0;
        }
    }
    ss.filter = null;
    ss.inActionMode = android.os.Build.VERSION.SDK_INT >= 11 && mChoiceMode == ListView.CHOICE_MODE_MULTIPLE_MODAL && mChoiceActionMode != null;
    if (mCheckStates != null) {
        try {
            ss.checkState = mCheckStates.clone();
        } catch (NoSuchMethodError e) {
            e.printStackTrace();
            ss.checkState = new SparseBooleanArray();
        }
    }
    if (mCheckedIdStates != null) {
        final LongSparseArray<Integer> idState = new LongSparseArray<Integer>();
        final int count = mCheckedIdStates.size();
        for (int i = 0; i < count; i++) {
            idState.put(mCheckedIdStates.keyAt(i), mCheckedIdStates.valueAt(i));
        }
        ss.checkIdState = idState;
    }
    ss.checkedItemCount = mCheckedItemCount;
    return ss;
}
Also used : LongSparseArray(android.support.v4.util.LongSparseArray) SparseBooleanArray(android.util.SparseBooleanArray) Parcelable(android.os.Parcelable) View(android.view.View) ListView(android.widget.ListView) SuppressLint(android.annotation.SuppressLint)

Example 3 with LongSparseArray

use of android.support.v4.util.LongSparseArray in project android-maps-utils by googlemaps.

the class HeatmapTileProvider method getMaxValue.

/**
     * Calculate a reasonable maximum intensity value to map to maximum color intensity
     *
     * @param points    Collection of LatLngs to put into buckets
     * @param bounds    Bucket boundaries
     * @param radius    radius of convolution
     * @param screenDim larger dimension of screen in pixels (for scale)
     * @return Approximate max value
     */
static double getMaxValue(Collection<WeightedLatLng> points, Bounds bounds, int radius, int screenDim) {
    // Approximate scale as if entire heatmap is on the screen
    // ie scale dimensions to larger of width or height (screenDim)
    double minX = bounds.minX;
    double maxX = bounds.maxX;
    double minY = bounds.minY;
    double maxY = bounds.maxY;
    double boundsDim = (maxX - minX > maxY - minY) ? maxX - minX : maxY - minY;
    // Number of buckets: have diameter sized buckets
    int nBuckets = (int) (screenDim / (2 * radius) + 0.5);
    // Scaling factor to convert width in terms of point distance, to which bucket
    double scale = nBuckets / boundsDim;
    // Make buckets
    // Use a sparse array - use LongSparseArray just in case
    LongSparseArray<LongSparseArray<Double>> buckets = new LongSparseArray<LongSparseArray<Double>>();
    //double[][] buckets = new double[nBuckets][nBuckets];
    // Assign into buckets + find max value as we go along
    double x, y;
    double max = 0;
    for (WeightedLatLng l : points) {
        x = l.getPoint().x;
        y = l.getPoint().y;
        int xBucket = (int) ((x - minX) * scale);
        int yBucket = (int) ((y - minY) * scale);
        // Check if x bucket exists, if not make it
        LongSparseArray<Double> column = buckets.get(xBucket);
        if (column == null) {
            column = new LongSparseArray<Double>();
            buckets.put(xBucket, column);
        }
        // Check if there is already a y value there
        Double value = column.get(yBucket);
        if (value == null) {
            value = 0.0;
        }
        value += l.getIntensity();
        // Yes, do need to update it, despite it being a Double.
        column.put(yBucket, value);
        if (value > max)
            max = value;
    }
    return max;
}
Also used : LongSparseArray(android.support.v4.util.LongSparseArray) Point(com.google.maps.android.geometry.Point)

Example 4 with LongSparseArray

use of android.support.v4.util.LongSparseArray in project android-maps-utils by googlemaps.

the class GridBasedAlgorithm method getClusters.

@Override
public Set<? extends Cluster<T>> getClusters(double zoom) {
    long numCells = (long) Math.ceil(256 * Math.pow(2, zoom) / GRID_SIZE);
    SphericalMercatorProjection proj = new SphericalMercatorProjection(numCells);
    HashSet<Cluster<T>> clusters = new HashSet<Cluster<T>>();
    LongSparseArray<StaticCluster<T>> sparseArray = new LongSparseArray<StaticCluster<T>>();
    synchronized (mItems) {
        for (T item : mItems) {
            Point p = proj.toPoint(item.getPosition());
            long coord = getCoord(numCells, p.x, p.y);
            StaticCluster<T> cluster = sparseArray.get(coord);
            if (cluster == null) {
                cluster = new StaticCluster<T>(proj.toLatLng(new Point(Math.floor(p.x) + .5, Math.floor(p.y) + .5)));
                sparseArray.put(coord, cluster);
                clusters.add(cluster);
            }
            cluster.add(item);
        }
    }
    return clusters;
}
Also used : LongSparseArray(android.support.v4.util.LongSparseArray) Cluster(com.google.maps.android.clustering.Cluster) Point(com.google.maps.android.geometry.Point) SphericalMercatorProjection(com.google.maps.android.projection.SphericalMercatorProjection) HashSet(java.util.HashSet)

Example 5 with LongSparseArray

use of android.support.v4.util.LongSparseArray in project orWall by EthACKdotOrg.

the class AppFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view;
    view = inflater.inflate(R.layout.fragment_tabbed_apps, container, false);
    Iptables iptables = new Iptables(getActivity());
    // Do we have root access ?
    if (RootCommands.rootAccessGiven()) {
        view.findViewById(R.id.warn_root).setVisibility(View.GONE);
    } else {
        view.findViewById(R.id.warn_root).setVisibility(View.VISIBLE);
    }
    // Hopefully there IS iptables on this deviceā€¦
    if (Iptables.iptablesExists()) {
        view.findViewById(R.id.warn_iptables).setVisibility(View.GONE);
    } else {
        view.findViewById(R.id.warn_iptables).setVisibility(View.VISIBLE);
    }
    if (Iptables.initSupported() && !iptables.isInitialized()) {
        view.findViewById(R.id.warn_init).setVisibility(View.VISIBLE);
    }
    ListView listView = (ListView) view.findViewById(R.id.id_enabled_apps);
    // Toggle hint layer
    boolean hide_hint = Preferences.isHidePressHint(getActivity());
    if (hide_hint) {
        view.findViewById(R.id.hint_press).setVisibility(View.GONE);
    } else {
        view.findViewById(R.id.id_hide_hint).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                ((View) view.getParent()).setVisibility(View.GONE);
                Preferences.setHidePressHint(getActivity(), true);
            }
        });
    }
    // get enabled apps
    NatRules natRules = new NatRules(this.getActivity());
    List<AppRule> enabledApps = natRules.getAllRules();
    LongSparseArray<AppRule> rulesIndex = new LongSparseArray<>();
    for (AppRule app : enabledApps) rulesIndex.put(app.getAppUID(), app);
    // get disabled apps (filtered with enabled)
    List<AppRule> disabledApps = listDisabledApps(rulesIndex);
    // Get special, disabled apps
    List<AppRule> specialDisabled = listSpecialApps(rulesIndex);
    // Merge both disabled apps
    disabledApps.addAll(specialDisabled);
    // Sort collection using a dedicated method
    Collections.sort(enabledApps, new AppRuleComparator(getActivity().getPackageManager()));
    Collections.sort(disabledApps, new AppRuleComparator(getActivity().getPackageManager()));
    // merge both collections so that enabled apps are above disabled
    enabledApps.addAll(disabledApps);
    listView.setAdapter(new AppListAdapter(this.getActivity(), enabledApps));
    return view;
}
Also used : LongSparseArray(android.support.v4.util.LongSparseArray) Iptables(org.ethack.orwall.lib.Iptables) View(android.view.View) ListView(android.widget.ListView) AppRuleComparator(org.ethack.orwall.lib.AppRuleComparator) NatRules(org.ethack.orwall.lib.NatRules) ListView(android.widget.ListView) AppRule(org.ethack.orwall.lib.AppRule) AppListAdapter(org.ethack.orwall.adapter.AppListAdapter)

Aggregations

LongSparseArray (android.support.v4.util.LongSparseArray)6 View (android.view.View)2 ListView (android.widget.ListView)2 HeaderData (com.battlelancer.seriesguide.adapters.model.HeaderData)2 Point (com.google.maps.android.geometry.Point)2 ArrayList (java.util.ArrayList)2 SuppressLint (android.annotation.SuppressLint)1 Parcelable (android.os.Parcelable)1 SparseBooleanArray (android.util.SparseBooleanArray)1 Cluster (com.google.maps.android.clustering.Cluster)1 SphericalMercatorProjection (com.google.maps.android.projection.SphericalMercatorProjection)1 HashSet (java.util.HashSet)1 AppListAdapter (org.ethack.orwall.adapter.AppListAdapter)1 AppRule (org.ethack.orwall.lib.AppRule)1 AppRuleComparator (org.ethack.orwall.lib.AppRuleComparator)1 Iptables (org.ethack.orwall.lib.Iptables)1 NatRules (org.ethack.orwall.lib.NatRules)1