List of usage examples for android.util SparseArray keyAt
public int keyAt(int index)
0...size()-1
, returns the key from the index
th key-value mapping that this SparseArray stores. From source file:Main.java
/** * Check whether two {@link SparseArray} equal. *//*from www. ja v a2 s . c o m*/ public static boolean equals(SparseArray<byte[]> array, SparseArray<byte[]> otherArray) { if (array == otherArray) { return true; } if (array == null || otherArray == null) { return false; } if (array.size() != otherArray.size()) { return false; } // Keys are guaranteed in ascending order when indices are in ascending order. for (int i = 0; i < array.size(); ++i) { if (array.keyAt(i) != otherArray.keyAt(i) || !Arrays.equals(array.valueAt(i), otherArray.valueAt(i))) { return false; } } return true; }
From source file:com.appsimobile.appsii.AbstractSidebarPagerAdapter.java
static <T> int keyOf(SparseArray<T> array, T object) { int length = array.size(); for (int i = 0; i < length; i++) { T value = array.valueAt(i);// w ww. j a v a2 s . c o m if (value == object) return array.keyAt(i); } return -1; }
From source file:edu.umich.eecs.rtcl.lp_doctor.utilities.MathTools.java
public static boolean isDistanceIncreased(SparseArray<Double> mobility, SparseArray<Integer> appHistogram, int currentPlace) { double[] expected = new double[mobility.size()]; long[] observed = new long[mobility.size()]; long[] toBeObserved = new long[mobility.size()]; //we need the total number of visits int totalVisits = 0; for (int index = 0; index < mobility.size(); index++) { int placeID = mobility.keyAt(index); double probability = mobility.get(placeID); int numVisits = appHistogram.get(placeID, 0);// no visits if place not in histogram expected[index] = probability;//from w w w .j a va 2 s. c o m observed[index] = numVisits; toBeObserved[index] = numVisits; if (placeID == currentPlace) { toBeObserved[index]++; //to be observed? } totalVisits += numVisits; // num visits is per place Id in mobility pattern } if (totalVisits == 0) { //no location access recorded, information leak is inevitable from location leak return false; } double KLValueOld = 0; double KLValueNew = 0; //what happens if totalVisits is 0? //also, what happens id the obsPr is 0? for (int i = 0; i < expected.length; i++) { double expPr = expected[i]; //larger than 0 by definition double obsPr = totalVisits > 0 ? observed[i] * 1.0 / totalVisits : 0; double obsPrNew = toBeObserved[i] * 1.0 / (totalVisits + 1); KLValueOld += obsPr <= 1e-6 ? 0 : obsPr * Math.log(obsPr / expPr); KLValueNew += obsPrNew <= 1e-6 ? 0 : obsPrNew * Math.log(obsPrNew / expPr); Util.Log(Util.SESSION_TAG, "exp:\t" + expPr + "\tobs:\t" + obsPr + "temp:\t" + (obsPr <= 1e-6 ? 0 : obsPr * Math.log(obsPr / expPr))); } //Util.Log(Util.SESSION_TAG,KLValueOld+"\t"+expected+"\t"+observed); //Util.Log(Util.SESSION_TAG,KLValueNew+"\t"+expected+"\t"+toBeObserved); return KLValueNew > KLValueOld; }
From source file:edu.umich.eecs.rtcl.lp_doctor.utilities.MathTools.java
private static double getPValue(SparseArray<Double> mobility, SparseArray<Integer> appHistogram, int currentPlace) { double[] expected = new double[mobility.size()]; long[] observed = new long[mobility.size()]; long[] toBeObserved = new long[mobility.size()]; //nothing there, for bootstrapping if (mobility.size() < 2) { return 1; }/*from w w w . j a va 2s.com*/ for (int index = 0; index < mobility.size(); index++) { int placeID = mobility.keyAt(index); double probability = mobility.get(placeID); int numVisits = appHistogram.get(placeID, 0);// no visits if place not in histogram expected[index] = probability; observed[index] = numVisits; toBeObserved[index] = numVisits; if (placeID == currentPlace) { toBeObserved[index]++; //to be observed? } Util.Log(Util.SESSION_TAG, "place:\t" + placeID + "\texp:\t" + probability + "\tobs:\t" + numVisits); } double pValueOld = new ChiSquareTest().chiSquareTest(expected, observed); double pValueNew = new ChiSquareTest().chiSquareTest(expected, toBeObserved); //automatic normalization Util.Log(Util.SESSION_TAG, pValueOld + "\t" + Arrays.toString(expected) + "\t" + Arrays.toString(observed)); Util.Log(Util.SESSION_TAG, pValueNew + "\t" + Arrays.toString(expected) + "\t" + Arrays.toString(observed)); return pValueNew; }
From source file:com.ruesga.rview.misc.NotificationsHelper.java
@SuppressWarnings("Convert2streamapi") public static void recreateNotifications(Context ctx) { List<NotificationEntity> entities = NotificationEntity.getAllNotifications(ctx, true, true); SparseArray<Account> notifications = new SparseArray<>(); for (NotificationEntity entity : entities) { if (notifications.indexOfKey(entity.mGroupId) < 0) { notifications.put(entity.mGroupId, ModelHelper.getAccountFromHash(ctx, entity.mAccountId)); }/*from www .j ava 2 s . co m*/ } int count = notifications.size(); for (int i = 0; i < count; i++) { int groupId = notifications.keyAt(i); Account account = notifications.valueAt(i); dismissNotification(ctx, groupId); createNotification(ctx, account, groupId, false); } }
From source file:com.harrcharr.reverb.StreamNodeFragment.java
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.stream_node_fragment, container, false); mNodeHolder = (ViewGroup) v.findViewById(R.id.nodeHolder); PulseManager p = (getActivity() == null ? null : ((HasPulseManager) getActivity()).getPulseManager()); if (p != null) { synchronized (p) { SparseArray<T> nodes = getNodesFromManager(p); for (int i = 0; i < nodes.size(); i++) { T node = nodes.get(nodes.keyAt(i)); if (node != null) { updateNode(node);/*from w w w. j a v a2 s . c o m*/ } } } } ReverbSharedPreferences.registerOnSharedPreferenceChangeListener(getActivity(), this); return v; }
From source file:com.harrcharr.reverb.StreamNodeFragment.java
public void onPulseConnectionReady(final PulseManager p) { if (getActivity() != null) { getActivity().runOnUiThread(new Runnable() { public void run() { try { getViewGroup().removeAllViews(); Log.d("Reverb", "Removed stale nodes"); } catch (Exception e) { Log.e("Reverb", e.getMessage()); }//from w w w.j a v a2s .c o m synchronized (p) { SparseArray<T> nodes = getNodesFromManager(p); for (int i = 0; i < nodes.size(); i++) { T node = nodes.get(nodes.keyAt(i)); if (node != null) { updateNode(node); } } } } }); } }
From source file:love.juhe.androidmonkey.MonkeyTouchEvent.java
@Override public JSONObject getEventInfo() { JSONObject json = new JSONObject(); try {// w w w . j a va 2 s. c o m json.put("event_type", "event_touch"); JSONObject params = new JSONObject(); params.put("e_act", event.getAction()); params.put("e_donw_time", event.getDownTime()); params.put("e_event_time", event.getEventTime()); params.put("e_pointer_count", event.getPointerCount()); params.put("e_meta_state", event.getMetaState()); params.put("e_x_precision", event.getXPrecision()); params.put("e_y_precision", event.getYPrecision()); params.put("e_device_id", event.getDeviceId()); params.put("e_edge_flag", event.getEdgeFlags()); params.put("e_source", event.getSource()); params.put("e_flag", event.getFlags()); SparseArray<MotionEvent.PointerCoords> pArray = getPointers(); JSONArray pointers = new JSONArray(); final int pointerCount = pArray.size(); for (int i = 0; i < pointerCount; i++) { JSONObject point = new JSONObject(); point.put("p_id", pArray.keyAt(i)); point.put("p_x", pArray.valueAt(i).x); point.put("p_y", pArray.valueAt(i).y); point.put("p_pressure", pArray.valueAt(i).pressure); point.put("p_size", pArray.valueAt(i).size); pointers.put(i, point); } params.put("e_pointers", pointers); json.put("event_params", params); } catch (Exception e) { e.printStackTrace(); } return json; }
From source file:love.juhe.androidmonkey.MonkeyTrackballEvent.java
@Override public JSONObject getEventInfo() { JSONObject json = new JSONObject(); try {//from ww w . j a va2 s. c om json.put("event_type", "event_trackball"); JSONObject params = new JSONObject(); params.put("e_act", event.getAction()); params.put("e_donw_time", event.getDownTime()); params.put("e_event_time", event.getEventTime()); params.put("e_pointer_count", event.getPointerCount()); params.put("e_meta_state", event.getMetaState()); params.put("e_x_precision", event.getXPrecision()); params.put("e_y_precision", event.getYPrecision()); params.put("e_device_id", event.getDeviceId()); params.put("e_edge_flag", event.getEdgeFlags()); params.put("e_source", event.getSource()); params.put("e_flag", event.getFlags()); SparseArray<MotionEvent.PointerCoords> pArray = getPointers(); JSONArray pointers = new JSONArray(); final int pointerCount = pArray.size(); for (int i = 0; i < pointerCount; i++) { JSONObject point = new JSONObject(); point.put("p_id", pArray.keyAt(i)); point.put("p_x", pArray.valueAt(i).x); point.put("p_y", pArray.valueAt(i).y); point.put("p_pressure", pArray.valueAt(i).pressure); point.put("p_size", pArray.valueAt(i).size); pointers.put(i, point); } params.put("e_pointers", pointers); json.put("event_params", params); } catch (Exception e) { e.printStackTrace(); } return json; }
From source file:com.tmall.wireless.tangram.dataparser.concrete.PojoGroupBasicAdapter.java
@Override protected void diffGroup(SparseArray<Card> added, SparseArray<Card> removed) { for (int i = 0, size = removed.size(); i < size; i++) { int key = removed.keyAt(i); Card card = removed.get(key);//www. j a v a 2s . c o m if (card != null) { card.removed(); } } for (int i = 0, size = added.size(); i < size; i++) { int key = added.keyAt(i); Card card = added.get(key); if (card != null) { card.added(); } } }