List of usage examples for com.facebook.react.common ReactConstants TAG
String TAG
To view the source code for com.facebook.react.common ReactConstants TAG.
Click Source Link
From source file:co.rewen.statex.StateXModule.java
License:Open Source License
@Override public void clearSensitiveData() { // Clear local storage. If fails, crash, since the app is potentially in a bad state and could // cause a privacy violation. We're still not recovering from this well, but at least the error // will be reported to the server. clear(new Callback() { @Override/* ww w . j a v a 2 s . c o m*/ public void invoke(Object... args) { if (args.length == 0) { FLog.d(ReactConstants.TAG, "Cleaned StateX."); return; } // Clearing the database has failed, delete it instead. if (mStateXDatabaseSupplier.deleteDatabase()) { FLog.d(ReactConstants.TAG, "Deleted Local Database StateX."); return; } // Everything failed, crash the app throw new RuntimeException("Clearing and deleting database failed: " + args[0]); } }); }
From source file:co.rewen.statex.StateXModule.java
License:Open Source License
/** * Given an array of keys, this returns a map of (key, value) pairs for the keys found, and * (key, null) for the keys that haven't been found. *///from w w w .j a v a 2 s .c o m @ReactMethod public void multiGet(final ReadableArray keys, final Callback callback) { if (keys == null) { callback.invoke(AsyncStorageErrorUtil.getInvalidKeyError(null), null); return; } new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) { @Override protected void doInBackgroundGuarded(Void... params) { if (!ensureDatabase()) { callback.invoke(AsyncStorageErrorUtil.getDBError(null), null); return; } String[] columns = { KEY_COLUMN, VALUE_COLUMN }; HashSet<String> keysRemaining = SetBuilder.newHashSet(); WritableArray data = Arguments.createArray(); for (int keyStart = 0; keyStart < keys.size(); keyStart += MAX_SQL_KEYS) { int keyCount = Math.min(keys.size() - keyStart, MAX_SQL_KEYS); Cursor cursor = mStateXDatabaseSupplier.get().query(TABLE_STATE, columns, AsyncLocalStorageUtil.buildKeySelection(keyCount), AsyncLocalStorageUtil.buildKeySelectionArgs(keys, keyStart, keyCount), null, null, null); keysRemaining.clear(); try { if (cursor.getCount() != keys.size()) { // some keys have not been found - insert them with null into the final array for (int keyIndex = keyStart; keyIndex < keyStart + keyCount; keyIndex++) { keysRemaining.add(keys.getString(keyIndex)); } } if (cursor.moveToFirst()) { do { WritableArray row = Arguments.createArray(); row.pushString(cursor.getString(0)); row.pushString(cursor.getString(1)); data.pushArray(row); keysRemaining.remove(cursor.getString(0)); } while (cursor.moveToNext()); } } catch (Exception e) { FLog.w(ReactConstants.TAG, e.getMessage(), e); callback.invoke(AsyncStorageErrorUtil.getError(null, e.getMessage()), null); return; } finally { cursor.close(); } for (String key : keysRemaining) { WritableArray row = Arguments.createArray(); row.pushString(key); row.pushNull(); data.pushArray(row); } keysRemaining.clear(); } callback.invoke(null, data); } }.execute(); }
From source file:co.rewen.statex.StateXModule.java
License:Open Source License
/** * Inserts multiple (key, value) pairs. If one or more of the pairs cannot be inserted, this will * return StateXFailure, but all other pairs will have been inserted. * The insertion will replace conflicting (key, value) pairs. *///from ww w .j av a 2 s. c o m @ReactMethod public void multiSet(final ReadableArray keyValueArray, final Callback callback) { if (keyValueArray.size() == 0) { callback.invoke(AsyncStorageErrorUtil.getInvalidKeyError(null)); return; } new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) { @Override protected void doInBackgroundGuarded(Void... params) { if (!ensureDatabase()) { callback.invoke(AsyncStorageErrorUtil.getDBError(null)); return; } String sql = "INSERT OR REPLACE INTO " + TABLE_STATE + " VALUES (?, ?);"; SQLiteStatement statement = mStateXDatabaseSupplier.get().compileStatement(sql); WritableMap error = null; ArrayList<String> keys = new ArrayList<>(); try { mStateXDatabaseSupplier.get().beginTransaction(); for (int idx = 0; idx < keyValueArray.size(); idx++) { if (keyValueArray.getArray(idx).size() != 2) { error = AsyncStorageErrorUtil.getInvalidValueError(null); break; } String key = keyValueArray.getArray(idx).getString(0); if (key == null) { error = AsyncStorageErrorUtil.getInvalidKeyError(null); break; } String value = keyValueArray.getArray(idx).getString(1); if (value == null) { error = AsyncStorageErrorUtil.getInvalidValueError(null); break; } keys.add(key); statement.clearBindings(); statement.bindString(1, key); statement.bindString(2, value); statement.execute(); } mStateXDatabaseSupplier.get().setTransactionSuccessful(); } catch (Exception e) { FLog.w(ReactConstants.TAG, e.getMessage(), e); error = AsyncStorageErrorUtil.getError(null, e.getMessage()); } finally { try { mStateXDatabaseSupplier.get().endTransaction(); } catch (Exception e) { FLog.w(ReactConstants.TAG, e.getMessage(), e); if (error == null) { error = AsyncStorageErrorUtil.getError(null, e.getMessage()); } } } if (error != null) { callback.invoke(error); } else { callback.invoke(); notifyStateChanged(keys); } } }.execute(); }
From source file:co.rewen.statex.StateXModule.java
License:Open Source License
/** * Removes all rows of the keys given./*from www .j a v a 2 s . co m*/ */ @ReactMethod public void multiRemove(final ReadableArray keys, final Callback callback) { if (keys.size() == 0) { callback.invoke(AsyncStorageErrorUtil.getInvalidKeyError(null)); return; } new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) { @Override protected void doInBackgroundGuarded(Void... params) { if (!ensureDatabase()) { callback.invoke(AsyncStorageErrorUtil.getDBError(null)); return; } WritableMap error = null; try { mStateXDatabaseSupplier.get().beginTransaction(); for (int keyStart = 0; keyStart < keys.size(); keyStart += MAX_SQL_KEYS) { int keyCount = Math.min(keys.size() - keyStart, MAX_SQL_KEYS); mStateXDatabaseSupplier.get().delete(TABLE_STATE, AsyncLocalStorageUtil.buildKeySelection(keyCount), AsyncLocalStorageUtil.buildKeySelectionArgs(keys, keyStart, keyCount)); } mStateXDatabaseSupplier.get().setTransactionSuccessful(); } catch (Exception e) { FLog.w(ReactConstants.TAG, e.getMessage(), e); error = AsyncStorageErrorUtil.getError(null, e.getMessage()); } finally { try { mStateXDatabaseSupplier.get().endTransaction(); } catch (Exception e) { FLog.w(ReactConstants.TAG, e.getMessage(), e); if (error == null) { error = AsyncStorageErrorUtil.getError(null, e.getMessage()); } } } if (error != null) { callback.invoke(error); } else { callback.invoke(); notifyStateChanged(StateX.toStringArray(keys)); } } }.execute(); }
From source file:co.rewen.statex.StateXModule.java
License:Open Source License
/** * Given an array of (key, value) pairs, this will merge the given values with the stored values * of the given keys, if they exist.//w w w.ja v a 2s . c o m */ @ReactMethod public void multiMerge(final ReadableArray keyValueArray, final Callback callback) { new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) { @Override protected void doInBackgroundGuarded(Void... params) { if (!ensureDatabase()) { callback.invoke(AsyncStorageErrorUtil.getDBError(null)); return; } WritableMap error = null; ArrayList<String> keys = new ArrayList<>(); try { mStateXDatabaseSupplier.get().beginTransaction(); for (int idx = 0; idx < keyValueArray.size(); idx++) { if (keyValueArray.getArray(idx).size() != 2) { error = AsyncStorageErrorUtil.getInvalidValueError(null); return; } String key = keyValueArray.getArray(idx).getString(0); if (key == null) { error = AsyncStorageErrorUtil.getInvalidKeyError(null); return; } else { keys.add(key); } if (keyValueArray.getArray(idx).getString(1) == null) { error = AsyncStorageErrorUtil.getInvalidValueError(null); return; } if (!AsyncLocalStorageUtil.mergeImpl(mStateXDatabaseSupplier.get(), key, keyValueArray.getArray(idx).getString(1))) { error = AsyncStorageErrorUtil.getDBError(null); return; } } mStateXDatabaseSupplier.get().setTransactionSuccessful(); } catch (Exception e) { FLog.w(ReactConstants.TAG, e.getMessage(), e); error = AsyncStorageErrorUtil.getError(null, e.getMessage()); } finally { try { mStateXDatabaseSupplier.get().endTransaction(); } catch (Exception e) { FLog.w(ReactConstants.TAG, e.getMessage(), e); if (error == null) { error = AsyncStorageErrorUtil.getError(null, e.getMessage()); } } } if (error != null) { callback.invoke(error); } else { callback.invoke(); notifyStateChanged(keys); } } }.execute(); }
From source file:co.rewen.statex.StateXModule.java
License:Open Source License
/** * Clears the database./*w ww.ja va2s. c o m*/ */ @ReactMethod public void clear(final Callback callback) { new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) { @Override protected void doInBackgroundGuarded(Void... params) { if (!mStateXDatabaseSupplier.ensureDatabase()) { callback.invoke(AsyncStorageErrorUtil.getDBError(null)); return; } try { mStateXDatabaseSupplier.get().delete(TABLE_STATE, null, null); callback.invoke(); } catch (Exception e) { FLog.w(ReactConstants.TAG, e.getMessage(), e); callback.invoke(AsyncStorageErrorUtil.getError(null, e.getMessage())); } } }.execute(); }
From source file:co.rewen.statex.StateXModule.java
License:Open Source License
/** * Returns an array with all keys from the database. *//*from w w w . j av a 2 s . c o m*/ @ReactMethod public void getAllKeys(final Callback callback) { new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) { @Override protected void doInBackgroundGuarded(Void... params) { if (!ensureDatabase()) { callback.invoke(AsyncStorageErrorUtil.getDBError(null), null); return; } WritableArray data = Arguments.createArray(); String[] columns = { KEY_COLUMN }; Cursor cursor = mStateXDatabaseSupplier.get().query(TABLE_STATE, columns, null, null, null, null, null); try { if (cursor.moveToFirst()) { do { data.pushString(cursor.getString(0)); } while (cursor.moveToNext()); } } catch (Exception e) { FLog.w(ReactConstants.TAG, e.getMessage(), e); callback.invoke(AsyncStorageErrorUtil.getError(null, e.getMessage()), null); return; } finally { cursor.close(); } callback.invoke(null, data); } }.execute(); }
From source file:com.bottomsheetbehavior.ReactNestedScrollView.java
License:Open Source License
public ReactNestedScrollView(ReactContext context, @Nullable FpsListener fpsListener) { super(context); this.setTag(TAG); mFpsListener = fpsListener;/*w ww. jav a 2 s. c o m*/ if (!sTriedToGetScrollerField) { sTriedToGetScrollerField = true; try { sScrollerField = NestedScrollView.class.getDeclaredField("mScroller"); sScrollerField.setAccessible(true); } catch (NoSuchFieldException e) { Log.w(ReactConstants.TAG, "Failed to get mScroller field for ScrollView! " + "This app will exhibit the bounce-back scrolling bug :("); } } if (sScrollerField != null) { try { Object scroller = sScrollerField.get(this); if (scroller instanceof OverScroller) { mScroller = (OverScroller) scroller; } else { Log.w(ReactConstants.TAG, "Failed to cast mScroller field in ScrollView (probably due to OEM changes to AOSP)! " + "This app will exhibit the bounce-back scrolling bug :("); mScroller = null; } } catch (IllegalAccessException e) { throw new RuntimeException("Failed to get mScroller from ScrollView!", e); } } else { mScroller = null; } }
From source file:com.dylanvann.cameraroll.ImageEditingManager.java
License:Open Source License
private static void copyExif(Context context, Uri oldImage, File newFile) throws IOException { File oldFile = getFileFromUri(context, oldImage); if (oldFile == null) { FLog.w(ReactConstants.TAG, "Couldn't get real path for uri: " + oldImage); return;//from ww w. j av a 2 s .c om } ExifInterface oldExif = new ExifInterface(oldFile.getAbsolutePath()); ExifInterface newExif = new ExifInterface(newFile.getAbsolutePath()); for (String attribute : EXIF_ATTRIBUTES) { String value = oldExif.getAttribute(attribute); if (value != null) { newExif.setAttribute(attribute, value); } } newExif.saveAttributes(); }
From source file:com.dzhyun.sdk.DzhChannel.java
License:Open Source License
@ReactMethod public void connect(final String url, final int id) { OkHttpClient client = new OkHttpClient(); client.setConnectTimeout(10, TimeUnit.SECONDS); client.setWriteTimeout(10, TimeUnit.SECONDS); // Disable timeouts for read client.setReadTimeout(0, TimeUnit.MINUTES); Request request = new Request.Builder().tag(id).url(url).build(); WebSocketCall.create(client, request).enqueue(new WebSocketListener() { @Override//w w w. j a va 2 s. c om public void onOpen(WebSocket webSocket, Response response) { mWebSocketConnections.put(id, webSocket); WritableMap params = Arguments.createMap(); params.putInt("id", id); sendEvent("dzhChannelOpen", params); } @Override public void onClose(int code, String reason) { WritableMap params = Arguments.createMap(); params.putInt("id", id); params.putInt("code", code); params.putString("reason", reason); sendEvent("dzhChannelClosed", params); } @Override public void onFailure(IOException e, Response response) { notifyWebSocketFailed(id, e.getMessage()); } @Override public void onPong(Buffer buffer) { } @Override public void onMessage(BufferedSource bufferedSource, WebSocket.PayloadType payloadType) { String message; if (payloadType == WebSocket.PayloadType.BINARY) { try { message = Pb2Json.toJson(bufferedSource.readByteArray()); bufferedSource.close(); } catch (IOException e) { FLog.e(ReactConstants.TAG, "decode pb failed " + id, e); return; } } else { try { message = bufferedSource.readUtf8(); } catch (IOException e) { notifyWebSocketFailed(id, e.getMessage()); return; } try { bufferedSource.close(); } catch (IOException e) { FLog.e(ReactConstants.TAG, "Could not close BufferedSource for WebSocket id " + id, e); } } WritableMap params = Arguments.createMap(); params.putInt("id", id); params.putString("data", message); sendEvent("dzhChannelMessage", params); } }); // Trigger shutdown of the dispatcher's executor so this process can exit cleanly client.getDispatcher().getExecutorService().shutdown(); }