List of usage examples for android.util SparseArray size
public int size()
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 w w w . j ava2 s . c o 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.guanqing.hao.OcrDetectorProcessor.java
/** * Called by the detector to deliver detection results. * If your application called for it, this could be a place to check for * equivalent detections by tracking TextBlocks that are similar in location and content from * previous frames, or reduce noise by eliminating TextBlocks that have not persisted through * multiple detections./* w ww .j a va 2 s . com*/ */ @Override public void receiveDetections(Detector.Detections<TextBlock> detections) { // TODO mGraphicOverlay.clear(); SparseArray<TextBlock> items = detections.getDetectedItems(); for (int i = 0; i < items.size(); ++i) { TextBlock item = items.valueAt(i); final String key = item.getValue().trim().toLowerCase(); final boolean success = mDict.get().containsKey(key); if (success) { final String translation = mDict.get().get(key); final OcrGraphic graphic = new OcrGraphic(mGraphicOverlay, item, success, translation); mGraphicOverlay.add(graphic); } } }
From source file:com.marpies.ane.facedetection.functions.DetectFacesFunction.java
private JSONArray getFacesJSONArray(SparseArray<Face> faces) { int numFaces = faces.size(); JSONArray facesResult = new JSONArray(); for (int i = 0; i < numFaces; i++) { Face face = faces.valueAt(i);//from w ww . j a v a2s . c om String faceJSON = getFaceJSON(face); if (faceJSON != null) { facesResult.put(faceJSON); } else { AIR.log("Error making JSON out of Face object"); } } AIR.log("Parsed " + facesResult.length() + " faces"); return facesResult; }
From source file:love.juhe.androidmonkey.MonkeyTouchEvent.java
@Override public JSONObject getEventInfo() { JSONObject json = new JSONObject(); try {// w w w. j ava 2 s . com 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 {// w ww . j a v a2s.c o m 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:ru.annin.store.presentation.ui.viewholder.MainViewHolder.java
public MainViewHolder refreshChart() { SparseArray<Fragment> fragments = chartPagerAdapter.getRegisteredFragments(); for (int i = 0; i < fragments.size(); ++i) { Fragment fragment = fragments.get(i); if (fragment != null && fragment instanceof BaseChartFragment) { ((BaseChartFragment) fragment).updateChart(); }//from w w w.java2 s. c om } return this; }
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 ww .ja v a 2 s. com*/ } } } } ReverbSharedPreferences.registerOnSharedPreferenceChangeListener(getActivity(), this); return v; }
From source file:com.example.lenny.barcodevison.ScanBarcodeActivity.java
private void createCameraSource() { BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(this) .setBarcodeFormats(UPC_A | UPC_E | EAN_13).build(); cameraSource = new CameraSource.Builder(this, barcodeDetector).setAutoFocusEnabled(true) .setRequestedPreviewSize(1600, 1024).setFacing(CameraSource.CAMERA_FACING_BACK).build(); cameraPreview.getHolder().addCallback(new SurfaceHolder.Callback() { @Override//from w w w .j a v a 2 s. c o m public void surfaceCreated(SurfaceHolder holder) { try { if (ActivityCompat.checkSelfPermission(ScanBarcodeActivity.this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(ScanBarcodeActivity.this, new String[] { Manifest.permission.CAMERA }, 1); return; } cameraSource.start(cameraPreview.getHolder()); } catch (IOException e) { } } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { } @Override public void surfaceDestroyed(SurfaceHolder holder) { cameraSource.stop(); } }); barcodeDetector.setProcessor(new Detector.Processor<Barcode>() { @Override public void release() { } @Override public void receiveDetections(Detector.Detections<Barcode> detections) { final SparseArray<Barcode> barcodes = detections.getDetectedItems(); if (barcodes.size() > 0) { Intent intent = new Intent(); intent.putExtra("barcode", barcodes.valueAt(0)); setResult(CommonStatusCodes.SUCCESS, intent); finish(); } } }); }
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()); }/* www .j a va 2 s . 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:org.openmrs.mobile.activities.formdisplay.FormDisplayMainPresenter.java
@Override public void createEncounter() { List<InputField> inputFields = new ArrayList<>(); List<SelectOneField> radioGroupFields = new ArrayList<>(); mFormDisplayView.enableSubmitButton(false); Encountercreate encountercreate = new Encountercreate(); encountercreate.setPatient(mPatient.getUuid()); encountercreate.setEncounterType(mEncountertype); List<Obscreate> observations = new ArrayList<>(); SparseArray<Fragment> activefrag = mPageAdapter.getRegisteredFragments(); boolean valid = true; for (int i = 0; i < activefrag.size(); i++) { FormDisplayPageFragment formPageFragment = (FormDisplayPageFragment) activefrag.get(i); if (!formPageFragment.checkInputFields()) { valid = false;//w w w .j a v a 2s .co m break; } inputFields.addAll(formPageFragment.getInputFields()); radioGroupFields.addAll(formPageFragment.getSelectOneFields()); } if (valid) { for (InputField input : inputFields) { if (input.getValue() != -1.0) { Obscreate obscreate = new Obscreate(); obscreate.setConcept(input.getConcept()); obscreate.setValue(String.valueOf(input.getValue())); LocalDateTime localDateTime = new LocalDateTime(); obscreate.setObsDatetime(localDateTime.toString()); obscreate.setPerson(mPatient.getUuid()); observations.add(obscreate); } } for (SelectOneField radioGroupField : radioGroupFields) { if (radioGroupField.getChosenAnswer() != null) { Obscreate obscreate = new Obscreate(); obscreate.setConcept(radioGroupField.getConcept()); obscreate.setValue(radioGroupField.getChosenAnswer().getConcept()); LocalDateTime localDateTime = new LocalDateTime(); obscreate.setObsDatetime(localDateTime.toString()); obscreate.setPerson(mPatient.getUuid()); observations.add(obscreate); } } encountercreate.setObservations(observations); encountercreate.setFormname(mFormname); encountercreate.setPatientId(mPatientID); encountercreate.setFormUuid(getFormResourceByName(mFormname).getUuid()); encountercreate.setObslist(); encountercreate.save(); if (!mPatient.isSynced()) { mPatient.addEncounters(encountercreate.getId()); new PatientDAO().updatePatient(mPatient.getId(), mPatient); ToastUtil.error("Patient not yet registered. Form data is saved locally " + "and will sync when internet connection is restored. "); mFormDisplayView.enableSubmitButton(true); } else { new EncounterService().addEncounter(encountercreate, new DefaultResponseCallbackListener() { @Override public void onResponse() { mFormDisplayView.enableSubmitButton(true); } @Override public void onErrorResponse(String errorMessage) { mFormDisplayView.showToast(errorMessage); mFormDisplayView.enableSubmitButton(true); } }); mFormDisplayView.quitFormEntry(); } } else { mFormDisplayView.enableSubmitButton(true); } }