List of usage examples for android.util SparseArray put
public void put(int key, E value)
From source file:net.eledge.android.toolkit.db.internal.TableBuilder.java
public String[] update(Class<?> clazz, int oldVersion, int newVersion) { SparseArray<List<String>> versionUpdates = new SparseArray<>(); versionUpdates.put(-1, new ArrayList<String>()); for (int i = oldVersion + 1; i <= newVersion; i++) { versionUpdates.put(i, new ArrayList<String>()); }//from w ww . ja v a 2s. c o m if (!doesTableExists(clazz)) { versionUpdates.get(-1).add(create(clazz)); } else { versionUpdates.get(-1).addAll(createTableUpdates(clazz)); } collectTableUpdatesAnnotations(versionUpdates, clazz); collectFieldUpdatesAnnotations(versionUpdates, clazz); return StringArrayUtils.toArray(versionUpdates); }
From source file:com.facebook.litho.ComponentsPools.java
@ThreadSafe(enableChecks = false) static void release(Context context, ComponentLifecycle lifecycle, Object mountContent) { if (context instanceof ComponentContext) { context = ((ComponentContext) context).getBaseContext(); if (context instanceof ComponentContext) { throw new IllegalStateException("Double wrapped ComponentContext."); }/*from w w w . j a v a 2 s . c o m*/ } RecyclePool pool = null; synchronized (mountContentLock) { SparseArray<RecyclePool> poolsArray = sMountContentPoolsByContext.get(context); if (poolsArray != null) { pool = poolsArray.get(lifecycle.getId()); if (pool == null) { pool = new RecyclePool("MountContent - " + lifecycle.getClass().getSimpleName(), lifecycle.poolSize(), true); poolsArray.put(lifecycle.getId(), pool); } } if (pool != null) { pool.release(mountContent); } } }
From source file:codetoanalyze.java.checkers.ContainerWrapper.java
public void addToSparseArrayBad(SparseArray sparseArray) { sparseArray.put(0, new Object()); }
From source file:codetoanalyze.java.checkers.ContainerWrapper.java
public void addToSparseArrayOk() { SparseArray sparseArray = new SparseArray(); sparseArray.put(0, new Object()); }
From source file:com.svpino.longhorn.artifacts.StockTileProcessor.java
private static int createFixedHeaderRow(Fragment fragment, TableLayout tableLayout, List<Stock> stocks, SparseArray<View> tiles, int height, int margin) { View view = tableLayout.getChildAt(0); if (view == null || view.getTag() != "fixed-header") { TableRow indexesTableRow = new TableRow(fragment.getActivity()); TableRow.LayoutParams indixesLayoutParams = new TableRow.LayoutParams(); indixesLayoutParams.topMargin = margin; indixesLayoutParams.rightMargin = margin; indixesLayoutParams.bottomMargin = margin; indixesLayoutParams.height = height; TableRow.LayoutParams lastIndexLayoutParams = new TableRow.LayoutParams(); lastIndexLayoutParams.topMargin = margin; lastIndexLayoutParams.bottomMargin = margin; lastIndexLayoutParams.height = height; View tile1 = createTile(fragment, stocks.get(0), 0, false); View tile2 = createTile(fragment, stocks.get(1), 1, false); View tile3 = createTile(fragment, stocks.get(2), 2, false); tiles.put(0, tile1); tiles.put(1, tile2);/*from w ww.j av a2 s . co m*/ tiles.put(2, tile3); indexesTableRow.addView(tile1, indixesLayoutParams); indexesTableRow.addView(tile2, indixesLayoutParams); indexesTableRow.addView(tile3, lastIndexLayoutParams); indexesTableRow.setTag("fixed-header"); tableLayout.addView(indexesTableRow); } return 3; }
From source file:com.android.talkback.CollectionState.java
private static boolean updateSingleTableHeader(@Nullable AccessibilityNodeInfoCompat node, CollectionInfoCompat collectionInfo, SparseArray<CharSequence> rowHeaders, SparseArray<CharSequence> columnHeaders) { if (node == null) { return false; }/*from ww w. jav a 2 s .co m*/ CharSequence headingName = getHeaderText(node); CollectionItemInfoCompat itemInfo = node.getCollectionItemInfo(); if (itemInfo != null && headingName != null) { @RowColumnTransition int headingType = getTableHeading(itemInfo, collectionInfo); if ((headingType & TYPE_ROW) != 0) { rowHeaders.put(itemInfo.getRowIndex(), headingName); } if ((headingType & TYPE_COLUMN) != 0) { columnHeaders.put(itemInfo.getColumnIndex(), headingName); } return headingType != TYPE_NONE; } return false; }
From source file:android.databinding.ViewDataBinding.java
/** @hide */ protected static <T> void setTo(SparseArray<T> list, int index, T value) { if (list == null || index < 0 || index >= list.size()) { return;/* ww w . j a v a2 s.co m*/ } list.put(index, value); }
From source file:ee.ioc.phon.android.speak.RecognizerIntentActivity.java
private SparseArray<String> createErrorMessages() { SparseArray<String> errorMessages = new SparseArray<String>(); errorMessages.put(RecognizerIntent.RESULT_AUDIO_ERROR, getString(R.string.errorResultAudioError)); errorMessages.put(RecognizerIntent.RESULT_CLIENT_ERROR, getString(R.string.errorResultClientError)); errorMessages.put(RecognizerIntent.RESULT_NETWORK_ERROR, getString(R.string.errorResultNetworkError)); errorMessages.put(RecognizerIntent.RESULT_SERVER_ERROR, getString(R.string.errorResultServerError)); errorMessages.put(RecognizerIntent.RESULT_NO_MATCH, getString(R.string.errorResultNoMatch)); return errorMessages; }
From source file:org.akvo.caddisfly.sensor.colorimetry.liquid.ColorimetryLiquidActivity.java
private void setResultIntent() { // Get the average color across the results int color = SwatchHelper.getAverageColor(mResults); // If this is a test and it was successful then build the result to return if (!mIsCalibration && (mResult > -1 || color != Color.TRANSPARENT)) { Intent intent = getIntent();// ww w . jav a 2s .c o m String resultText = String.format(Locale.getDefault(), "%.2f", mResult); // Add 'greater than' symbol if result could be an unknown high value if (mHighLevelsFound) { resultText = "> " + resultText; } Intent resultIntent = new Intent(intent); resultIntent.putExtra(SensorConstants.RESULT, resultText); resultIntent.putExtra(SensorConstants.COLOR, color); String resultImageUrl = EMPTY_STRING; if (getIntent().getBooleanExtra(Constant.SEND_IMAGE_IN_RESULT, false)) { // Save photo taken during the test resultImageUrl = UUID.randomUUID().toString() + ".png"; String path = FileUtil.writeBitmapToExternalStorage(mCroppedBitmap, "/result-images", resultImageUrl); resultIntent.putExtra(SensorConstants.IMAGE, path); } TestInfo testInfo = CaddisflyApp.getApp().getCurrentTestInfo(); SparseArray<String> results = new SparseArray<>(); results.put(testInfo.getSubTests().get(0).getId(), resultText); JSONObject resultJson = TestConfigHelper.getJsonResult(testInfo, results, color, resultImageUrl, null); resultIntent.putExtra(SensorConstants.RESPONSE, resultJson.toString()); // TODO: Remove this when obsolete // Backward compatibility. Return plain text result resultIntent.putExtra(SensorConstants.RESPONSE_COMPAT, resultText); setResult(Activity.RESULT_OK, resultIntent); } }
From source file:org.ale.scanner.zotero.MainActivity.java
public void loadGroups() { if (mAccountAccess.getGroupCount() == 0 && mAccountAccess.canWriteLibrary()) { mGroups = new SparseArray<PString>(); mGroups.put(Group.GROUP_LIBRARY, new PString(getString(R.string.my_library))); return;//from w w w .j a v a 2 s .c o m } // Check that we have all the group titles new Thread(new Runnable() { public void run() { final SparseArray<PString> newGroupList = new SparseArray<PString>(); Set<Integer> groups = mAccountAccess.getGroupIds(); if (mAccountAccess.canWriteLibrary()) { newGroupList.put(Group.GROUP_LIBRARY, new PString(getString(R.string.my_library))); } String[] selection = new String[] { TextUtils.join(",", groups) }; Cursor c = getContentResolver().query(Database.GROUP_URI, new String[] { Group._ID, Group.COL_TITLE }, Group._ID + " IN (?)", selection, null); // Figure out which groups we don't have c.moveToFirst(); while (!c.isAfterLast()) { int haveGroupId = c.getInt(0); groups.remove(haveGroupId); newGroupList.put(haveGroupId, new PString(c.getString(1))); c.moveToNext(); } c.close(); // Update the group list mUIThreadHandler.post(new Runnable() { public void run() { mGroups = newGroupList; } }); // If we have any unknown groups, do a group lookup. if (groups.size() > 0) { // Make new database entries for new groups. Mapping each // id to "<Group ID>" temporarily. ContentValues[] values = new ContentValues[groups.size()]; int i = 0; for (Integer gid : groups) { values[i] = new ContentValues(); values[i].put(Group._ID, gid); values[i].put(Group.COL_TITLE, "<" + gid + ">"); i++; } getContentResolver().bulkInsert(Database.GROUP_URI, values); mZAPI.getGroups(); } } }).start(); }