List of usage examples for android.os Looper myLooper
public static @Nullable Looper myLooper()
From source file:android.app.FragmentManager.java
/** * Only call from main thread!/*w w w . j a v a2 s . c o m*/ */ public boolean execPendingActions() { if (mExecutingActions) { throw new IllegalStateException("Recursive entry to executePendingTransactions"); } if (Looper.myLooper() != mActivity.mHandler.getLooper()) { throw new IllegalStateException("Must be called from main thread of process"); } boolean didSomething = false; while (true) { int numActions; synchronized (this) { if (mPendingActions == null || mPendingActions.size() == 0) { break; } numActions = mPendingActions.size(); if (mTmpActions == null || mTmpActions.length < numActions) { mTmpActions = new Runnable[numActions]; } mPendingActions.toArray(mTmpActions); mPendingActions.clear(); mActivity.mHandler.removeCallbacks(mExecCommit); } mExecutingActions = true; for (int i = 0; i < numActions; i++) { mTmpActions[i].run(); mTmpActions[i] = null; } mExecutingActions = false; didSomething = true; } if (mHavePendingDeferredStart) { boolean loadersRunning = false; for (int i = 0; i < mActive.size(); i++) { Fragment f = mActive.get(i); if (f != null && f.mLoaderManager != null) { loadersRunning |= f.mLoaderManager.hasRunningLoaders(); } } if (!loadersRunning) { mHavePendingDeferredStart = false; startPendingDeferredFragments(); } } return didSomething; }
From source file:com.irccloud.android.NetworkConnection.java
public void request_backlog(int cid, int bid, long beforeId) { try {/*from ww w .j av a 2 s . c o m*/ if (oobTasks.containsKey(bid)) { Crashlytics.log(Log.WARN, TAG, "Ignoring duplicate backlog request for BID: " + bid); return; } if (session == null || session.length() == 0) { Crashlytics.log(Log.WARN, TAG, "Not fetching backlog before session is set"); return; } if (Looper.myLooper() == null) Looper.prepare(); OOBIncludeTask task = new OOBIncludeTask(bid); oobTasks.put(bid, task); if (beforeId > 0) task.execute(new URL("https://" + IRCCLOUD_HOST + "/chat/backlog?cid=" + cid + "&bid=" + bid + "&beforeid=" + beforeId)); else task.execute(new URL("https://" + IRCCLOUD_HOST + "/chat/backlog?cid=" + cid + "&bid=" + bid)); } catch (MalformedURLException e) { e.printStackTrace(); } }
From source file:gov.wa.wsdot.android.wsdot.ui.trafficmap.TrafficMapActivity.java
/** * Request location updates after checking permissions first. *///w w w . java2 s .c o m private void requestLocationUpdates() { Log.e(TAG, "requesting location updates"); if (checkPermission(false)) { if (mGoogleApiClient.isConnected()) { getFusedLocationProviderClient(this).requestLocationUpdates(createLocationRequest(), mLocationCallback, Looper.myLooper()); } } }
From source file:io.realm.Realm.java
/** * Manually trigger a migration on a RealmMigration. * * @param configuration {@link RealmConfiguration} * @param migration {@link RealmMigration} to run on the Realm. This will override any migration set on the * configuration./*from w w w. j a va 2 s .co m*/ */ public static void migrateRealm(RealmConfiguration configuration, RealmMigration migration) { if (configuration == null) { throw new IllegalArgumentException("RealmConfiguration must be provided"); } if (migration == null && configuration.getMigration() == null) { throw new RealmMigrationNeededException(configuration.getPath(), "RealmMigration must be provided"); } RealmMigration realmMigration = (migration == null) ? configuration.getMigration() : migration; Realm realm = null; try { realm = Realm.createAndValidate(configuration, false, Looper.myLooper() != null); realm.beginTransaction(); realm.setVersion(realmMigration.execute(realm, realm.getVersion())); realm.commitTransaction(); } finally { if (realm != null) { realm.close(); realmsCache.remove(); } } }
From source file:com.android.mail.utils.NotificationUtils.java
private static ContactIconInfo getContactIcon(final Context context, String accountName, final String displayName, final String senderAddress, final Folder folder, final ContactFetcher contactFetcher) { if (Looper.myLooper() == Looper.getMainLooper()) { throw new IllegalStateException("getContactIcon should not be called on the main thread."); }/*from w w w .ja va2 s.com*/ final ContactIconInfo contactIconInfo; if (TextUtils.isEmpty(senderAddress)) { contactIconInfo = new ContactIconInfo(); } else { // Get the ideal size for this icon. final Resources res = context.getResources(); final int idealIconHeight = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_height); final int idealIconWidth = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_width); final int idealWearableBgWidth = res.getDimensionPixelSize(R.dimen.wearable_background_width); final int idealWearableBgHeight = res.getDimensionPixelSize(R.dimen.wearable_background_height); if (contactFetcher != null) { contactIconInfo = contactFetcher.getContactPhoto(context, accountName, senderAddress, idealIconWidth, idealIconHeight, idealWearableBgWidth, idealWearableBgHeight); } else { contactIconInfo = getContactInfo(context, senderAddress, idealIconWidth, idealIconHeight, idealWearableBgWidth, idealWearableBgHeight); } if (contactIconInfo.icon == null) { // Make a colorful tile! final Dimensions dimensions = new Dimensions(idealIconWidth, idealIconHeight, Dimensions.SCALE_ONE); contactIconInfo.icon = new LetterTileProvider(context.getResources()).getLetterTile(dimensions, displayName, senderAddress); } // Only turn the square photo/letter tile into a circle for L and later if (Utils.isRunningLOrLater()) { contactIconInfo.icon = BitmapUtil.frameBitmapInCircle(contactIconInfo.icon); } } if (contactIconInfo.icon == null) { // Use anonymous icon due to lack of sender contactIconInfo.icon = getIcon(context, R.drawable.ic_notification_anonymous_avatar_32dp); } if (contactIconInfo.wearableBg == null) { contactIconInfo.wearableBg = getDefaultWearableBg(context); } return contactIconInfo; }
From source file:com.tct.mail.utils.NotificationUtils.java
private static ContactIconInfo getContactIcon(final Context context, final Folder folder, final ContactPhotoFetcher photoFetcher) { if (Looper.myLooper() == Looper.getMainLooper()) { throw new IllegalStateException("getContactIcon should not be called on the main thread."); }/*from w ww. jav a 2s.c o m*/ final ContactIconInfo contactIconInfo; // Get the ideal size for this icon. final Resources res = context.getResources(); final int idealIconHeight = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_height); final int idealIconWidth = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_width); final int idealWearableBgWidth = res.getDimensionPixelSize(R.dimen.wearable_background_width); final int idealWearableBgHeight = res.getDimensionPixelSize(R.dimen.wearable_background_height); if (photoFetcher != null) { contactIconInfo = photoFetcher.getContactPhoto(context, "", "", idealIconWidth, idealIconHeight, idealWearableBgWidth, idealWearableBgHeight); } else { contactIconInfo = getContactInfo(context, "", idealIconWidth, idealIconHeight, idealWearableBgWidth, idealWearableBgHeight); } if (contactIconInfo.icon == null) { // Make a colorful tile! final Dimensions dimensions = new Dimensions(idealIconWidth, idealIconHeight, Dimensions.SCALE_ONE); contactIconInfo.icon = new LetterTileProvider(context).getMultiTile(dimensions); } contactIconInfo.icon = cropSquareIconToCircle(contactIconInfo.icon); if (contactIconInfo.icon == null) { // Icon should be the default mail icon. contactIconInfo.icon = getDefaultNotificationIcon(context, folder, false /* single new message */); } if (contactIconInfo.wearableBg == null) { contactIconInfo.wearableBg = getDefaultWearableBg(context); } return contactIconInfo; }
From source file:com.tct.mail.utils.NotificationUtils.java
private static ContactIconInfo getContactIcon(final Context context, String accountName, final String displayName, final String senderAddress, final Folder folder, final ContactPhotoFetcher photoFetcher) { if (Looper.myLooper() == Looper.getMainLooper()) { throw new IllegalStateException("getContactIcon should not be called on the main thread."); }/*from w ww . ja v a 2 s .c om*/ final ContactIconInfo contactIconInfo; if (senderAddress == null) { contactIconInfo = new ContactIconInfo(); } else { // Get the ideal size for this icon. final Resources res = context.getResources(); final int idealIconHeight = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_height); final int idealIconWidth = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_width); final int idealWearableBgWidth = res.getDimensionPixelSize(R.dimen.wearable_background_width); final int idealWearableBgHeight = res.getDimensionPixelSize(R.dimen.wearable_background_height); if (photoFetcher != null) { contactIconInfo = photoFetcher.getContactPhoto(context, accountName, senderAddress, idealIconWidth, idealIconHeight, idealWearableBgWidth, idealWearableBgHeight); } else { contactIconInfo = getContactInfo(context, senderAddress, idealIconWidth, idealIconHeight, idealWearableBgWidth, idealWearableBgHeight); } if (contactIconInfo.icon == null) { // Make a colorful tile! final Dimensions dimensions = new Dimensions(idealIconWidth, idealIconHeight, Dimensions.SCALE_ONE); contactIconInfo.icon = new LetterTileProvider(context).getLetterTile(dimensions, displayName, senderAddress); } contactIconInfo.icon = cropSquareIconToCircle(contactIconInfo.icon); } if (contactIconInfo.icon == null) { // Icon should be the default mail icon. contactIconInfo.icon = getDefaultNotificationIcon(context, folder, false /* single new message */); } if (contactIconInfo.wearableBg == null) { contactIconInfo.wearableBg = getDefaultWearableBg(context); } return contactIconInfo; }
From source file:com.rener.sea.DBHelper.java
public void syncDB() { if (Looper.myLooper() == null) Looper.prepare();// ww w . j a va 2 s . c o m new ServerCalls().execute("SYNC"); // String device_id = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); // // Log.i(this.toString(), "HTTP Sync called "); // //Create AsycHttpClient object // AsyncHttpClient client = new AsyncHttpClient(); // RequestParams params = new RequestParams(); // params.put(DBSchema.POST_DEVICE_ID, device_id); // // if (!isEmpty() || userSW) { // initial sync is FULL // params.put(DBSchema.POST_SYNC_TYPE, DBSchema.SYNC_FULL); // client.post(DBSchema.SYNC_URL, params, new JsonHttpResponseHandler() { // @Override // public void onSuccess(int statusCode, Header[] headers, JSONObject response) { // // Log.i(this.toString(), "HTTP Sync success : i = " + statusCode + ", Header = " + headers.toString() + ", JSONObject = " + response.toString()); // SQLiteDatabase db = getWritableDatabase(); // try { // // JSONObject status = response.getJSONObject(DBSchema.POST_SYNC_INF); // if (status.getInt(DBSchema.SYNC_STATUS) == DBSchema.STATUS_SUCCESS) { // setLocalData(response.getJSONObject(DBSchema.POST_SERVER_DATA_NEW)); // } else { // // Log.i(this.toString(), "HTTP Sync success Transaction fail FULL"); // } // // } catch (JSONException e) { // // e.printStackTrace(); // } // try { // JSONObject localJSONObject = response.getJSONObject(DBSchema.POST_SYNC_INF); // Log.i(this.toString(), "HTTP Sync success : i = " + statusCode + ", Header = " + headers.toString() + ", localJSON = " + localJSONObject.toString()); // } catch (JSONException e) { // e.printStackTrace(); // } // Intent intent = new Intent(); // intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); // intent.setAction("SYNC"); // intent.putExtra("SYNC_RESULT", DBSchema.SYNC_SUCCESS); // context.sendBroadcast(intent); // // } // // @Override // public void onSuccess(int statusCode, Header[] headers, JSONArray response) { // Log.i(this.toString(), "HTTP Sync success : i = " + statusCode + ", Header = " + headers.toString() + ", JSONArray = " + response.toString()); // // } // // @Override // public void onFailure(int statusCode, Header[] headers, String response, Throwable error) { // Log.i(this.toString(), "HTTP Sync failure : statusCode = " + statusCode + ", Header = " + headers.toString() + ", response = " + response); // switch (statusCode) { // case 404: // Intent intent404 = new Intent(); // intent404.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); // intent404.setAction("SYNC"); // intent404.putExtra("SYNC_RESULT", 404); // context.sendBroadcast(intent404); // Toast.makeText(context, "Requested resource not found", Toast.LENGTH_LONG).show();// resource Not Found // break; // case 500: // Intent intent500 = new Intent(); // intent500.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); // intent500.setAction("SYNC"); // intent500.putExtra("SYNC_RESULT", 500); // context.sendBroadcast(intent500); // Toast.makeText(context, "Internal server error", Toast.LENGTH_LONG).show();// Internal Server Error // break; // default: // Intent intent = new Intent(); // intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); // intent.setAction("SYNC"); // intent.putExtra("SYNC_RESULT", DBSchema.STATUS_ERROR); // context.sendBroadcast(intent); // Toast.makeText(context, "NPI", Toast.LENGTH_LONG).show();// no se que paso // break; // // // } // } // // // }); // //// result.isFinished(); //// setSyncDone(data); // // } else { // database incremental // String prefKey = context.getResources().getString(R.string.preference_file_key); // String usernameKey = context.getResources().getString(R.string.key_saved_username); // SharedPreferences sharedPref = context.getSharedPreferences(prefKey, Context.MODE_PRIVATE); // String sUsername = sharedPref.getString(usernameKey, null); // User currentUser = findUserByUsername(sUsername); // long userID = currentUser.getId(); // String type = currentUser.getType(); // Log.i(this.toString(), "DEVICE ID = " + String.valueOf(device_id)); // params.put(DBSchema.POST_SYNC_TYPE, DBSchema.SYNC_INC); // params.put(DBSchema.POST_USER_ID, userID); // params.put(DBSchema.POST_USER_TYPE, type); // // dataSync = getData(); // // params.put(DBSchema.POST_LOCAL_DATA, dataSync); // // client.post(DBSchema.SYNC_URL, params, new JsonHttpResponseHandler() { // @Override // public void onSuccess(int statusCode, Header[] headers, JSONObject response) { // // Log.i(this.toString(), "HTTP Sync success : i = " + statusCode + ", Header = " + headers.toString() + ", JSONObject = " + response.toString()); // SQLiteDatabase db = getWritableDatabase(); // // try { // // // JSONObject status = response.getJSONObject(DBSchema.POST_SYNC_INF); // if (status.getInt(DBSchema.SYNC_STATUS) == DBSchema.STATUS_SUCCESS) { // // setLocalData(response.getJSONObject(DBSchema.POST_SERVER_DATA_NEW)); // if (!userSW) // deleteLocalData(response.getJSONObject(DBSchema.POST_SERVER_DATA_DELETED)); // // } else { // // Log.i(this.toString(), "HTTP Sync success Transaction fail INCREMENTAL"); // } // // // } catch (JSONException e) { // // e.printStackTrace(); // } // // Intent intent = new Intent(); // intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); // intent.setAction("SYNC"); // intent.putExtra("SYNC_RESULT", DBSchema.SYNC_SUCCESS); // context.sendBroadcast(intent); // try { // JSONObject syncInf = response.getJSONObject(DBSchema.POST_SYNC_INF); // long status = syncInf.getLong(DBSchema.SYNC_STATUS); // Log.i(this.toString(), "HTTP Sync success : i = " + statusCode + "server sync status response = " + status); // String local_data = syncInf.getString("local_data"); // Log.i(this.toString(), "HTTP Sync success : i = " + statusCode + "JSON of local data from server = " + local_data); // if (status == DBSchema.STATUS_SUCCESS) { // setSyncDone(); // } // } catch (JSONException e) { // e.printStackTrace(); // } // try { // JSONObject syncJSONObject = response.getJSONObject(DBSchema.POST_SYNC_INF); // Log.i(this.toString(), "HTTP Sync success : i = " + statusCode + ", Header = " + headers.toString() + ", sysncJSON = " + syncJSONObject.toString()); // } catch (JSONException e) { // // e.printStackTrace(); // } // // } // // @Override // public void onSuccess(int statusCode, Header[] headers, JSONArray response) { // Log.i(this.toString(), "HTTP Sync success : i = " + statusCode + ", Header = " + headers.toString() + ", JSONArray = " + response.toString()); // // } // // @Override // public void onFailure(int statusCode, Header[] headers, String response, Throwable error) { // Log.i(this.toString(), "HTTP Sync failure : statusCode = " + statusCode + ", Header = " + headers.toString() + ", response = " + response); // switch (statusCode) { // case 404: // Intent intent404 = new Intent(); // intent404.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); // intent404.setAction("SYNC"); // intent404.putExtra("SYNC_RESULT", 404); // context.sendBroadcast(intent404); // Toast.makeText(context, "Requested resource not found", Toast.LENGTH_LONG).show();// resource Not Found // break; // case 500: // Intent intent500 = new Intent(); // intent500.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); // intent500.setAction("SYNC"); // intent500.putExtra("SYNC_RESULT", 500); // context.sendBroadcast(intent500); // Toast.makeText(context, "Internal server error", Toast.LENGTH_LONG).show();// Internal Server Error // break; // default: // Intent intent = new Intent(); // intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); // intent.setAction("SYNC"); // intent.putExtra("SYNC_RESULT", DBSchema.STATUS_ERROR); // context.sendBroadcast(intent); // Toast.makeText(context, "NPI", Toast.LENGTH_LONG).show();// no se que paso // break; // // // } // } // // // }); // // } }
From source file:com.rener.sea.DBHelper.java
public void syncDBFull() { deleteDB();// w ww . j av a 2s. c o m getDummy(); if (Looper.myLooper() == null) Looper.prepare(); new ServerCalls().execute("SYNC_FULL"); // String device_id = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); // String prefKey = context.getResources().getString(R.string.preference_file_key); // String usernameKey = context.getResources().getString(R.string.key_saved_username); // SharedPreferences sharedPref = context.getSharedPreferences(prefKey, Context.MODE_PRIVATE); // String sUsername = sharedPref.getString(usernameKey, null); // long userID = findUserByUsername(sUsername).getId(); // Log.i(this.toString(), "HTTP Sync called "); // // AsyncHttpClient client = new AsyncHttpClient(); // RequestParams params = new RequestParams(); // // params.put(DBSchema.POST_SYNC_TYPE, DBSchema.SYNC_FULL); // params.put(DBSchema.POST_DEVICE_ID, device_id); // // client.post(DBSchema.SYNC_URL, params, new JsonHttpResponseHandler() { // @Override // public void onSuccess(int statusCode, Header[] headers, JSONObject response) { // // Log.i(this.toString(), "HTTP Sync success : i = " + statusCode + ", Header = " + headers.toString() + ", JSONObject = " + response.toString()); // // // try { // setUsers(response.getJSONObject(DBSchema.POST_SERVER_DATA_NEW).getJSONArray(DBSchema.TABLE_USERS)); // } catch (JSONException e) { // e.printStackTrace(); // } // // initialize sequences // try { // JSONObject status = response.getJSONObject(DBSchema.POST_SYNC_INF); // if (status.getInt(DBSchema.SYNC_STATUS) == DBSchema.STATUS_SUCCESS) { // // setLocalData(response.getJSONObject(DBSchema.POST_SERVER_DATA_NEW)); // // } else { // // Log.i(this.toString(), "HTTP Sync success Transaction fail syncDBFull"); // } // // } catch (JSONException e) { // // e.printStackTrace(); // } // // Intent intent = new Intent(); // intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); // intent.setAction("SYNC_FULL"); // intent.putExtra("SYNC_RESULT", DBSchema.SYNC_SUCCESS); // context.sendBroadcast(intent); // // } // // @Override // public void onSuccess(int statusCode, Header[] headers, JSONArray response) { // Log.i(this.toString(), "HTTP Sync success : i = " + statusCode + ", Header = " + headers.toString() + ", JSONArray = " + response.toString()); // // } // // @Override // public void onFailure(int statusCode, Header[] headers, String response, Throwable error) { //// Log.i(this.toString(), "HTTP Sync failure : statusCode = " + statusCode + ", Header = " + headers.toString() + ", response = " + response); // switch (statusCode) { // case 404: // Intent intent404 = new Intent(); // intent404.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); // intent404.setAction("SYNC_FULL"); // intent404.putExtra("SYNC_RESULT", 404); // context.sendBroadcast(intent404); // Toast.makeText(context, "Requested resource not found", Toast.LENGTH_LONG).show();// resource Not Found // break; // case 500: // Intent intent500 = new Intent(); // intent500.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); // intent500.setAction("SYNC_FULL"); // intent500.putExtra("SYNC_RESULT", 500); // context.sendBroadcast(intent500); // Toast.makeText(context, "Internal server error", Toast.LENGTH_LONG).show();// Internal Server Error // break; // default: // Intent intent = new Intent(); // intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); // intent.setAction("SYNC_FULL"); // intent.putExtra("SYNC_RESULT", DBSchema.STATUS_ERROR); // context.sendBroadcast(intent); // Toast.makeText(context, "NPI", Toast.LENGTH_LONG).show();// no se que paso // break; // // // } // } // // // }); }