List of usage examples for android.os Looper getMainLooper
public static Looper getMainLooper()
From source file:com.icecream.snorlax.module.feature.encounter.EncounterNotification.java
@SuppressWarnings("deprecation") void show(int pokemonNumber, String pokemonName, double iv, int attack, int defense, int stamina, int cp, double level, int hp, String move1, String move1Type, int move1Power, String move2, String move2Type, int move2Power, double pokeRate, double greatRate, double ultraRate, String type1, String type2, String pokemonClass) {// w ww . ja v a 2 s .com new Handler(Looper.getMainLooper()).post(() -> { Notification notification = new NotificationCompat.Builder(mContext) .setSmallIcon(R.drawable.ic_pokeball) .setLargeIcon(Bitmap.createScaledBitmap( BitmapFactory.decodeResource(mResources, getPokemonResourceId(pokemonNumber)), getLargeIconWidth(), getLargeIconHeight(), false)) .setContentTitle(mContext.getString(R.string.notification_title, pokemonName, cp, level)) .setContentText(mContext.getString(R.string.notification_content, iv, attack, defense, stamina)) .setStyle(new NotificationCompat.InboxStyle() .addLine(mContext.getString(R.string.notification_categoty_stats_content_iv, iv, attack, defense, stamina)) .addLine(mContext.getString(R.string.notification_categoty_stats_content_hp, hp)) .addLine(getBoldSpannable( mContext.getString(R.string.notification_categoty_moves_title))) .addLine(mContext.getString(R.string.notification_categoty_moves_fast, move1, move1Type, move1Power)) .addLine(mContext.getString(R.string.notification_categoty_moves_charge, move2, move2Type, move2Power)) .addLine(getBoldSpannable( mContext.getString(R.string.notification_categoty_catch_title))) .addLine(mContext.getString(R.string.notification_categoty_catch_content, pokeRate, greatRate, ultraRate)) .setSummaryText(getFooter(type1, type2, pokemonClass))) .setColor(ContextCompat.getColor(mContext, R.color.red_700)).setAutoCancel(true) .setVibrate(new long[] { 0 }).setPriority(Notification.PRIORITY_MAX) .setCategory(NotificationCompat.CATEGORY_ALARM).build(); hideIcon(notification); mNotificationManager.notify(NOTIFICATION_ID, notification); }); }
From source file:com.miz.service.IdentifyTvShowEpisodeService.java
@Override protected void onHandleIntent(Intent intent) { if (MizLib.isTvShowLibraryBeingUpdated(this)) { Handler mHandler = new Handler(Looper.getMainLooper()); mHandler.post(new Runnable() { @Override/*from w ww. ja va 2 s . c om*/ public void run() { Toast.makeText(IdentifyTvShowEpisodeService.this, R.string.cant_identify_while_updating, Toast.LENGTH_LONG).show(); } }); return; } log("clear()"); clear(); log("setup()"); setup(); log("Intent extras"); Bundle b = intent.getExtras(); mNewShowId = b.getString("newShowId"); mOldShowId = b.getString("oldShowId"); mLanguage = b.getString("language", "all"); mFilepaths = b.getStringArrayList("filepaths"); if (mFilepaths != null) { log("setupList()"); setupList(); log("removeOldDatabaseEntries()"); removeOldDatabaseEntries(); log("start()"); start(); } }
From source file:com.iiitd.networking.UDPMessenger.java
/** * Class constructor/* ww w. j av a 2 s.co m*/ * @param context the application's context * @param tag a valid string, used to filter the UDP broadcast messages (in and out). It can't be null or 0-characters long. * @param multicastPort the port to multicast to. Must be between 1025 and 49151 (inclusive) * @param connectionPort the port to get the connection back. Must be between 1025 and 49151 */ public UDPMessenger(Context context, String tag, int multicastPort) throws IllegalArgumentException { if (context == null || tag == null || tag.length() == 0 || multicastPort <= 1024 || multicastPort > 49151) throw new IllegalArgumentException(); this.context = context.getApplicationContext(); TAG = tag; MULTICAST_PORT = multicastPort; incomingMessageHandler = new Handler(Looper.getMainLooper()); }
From source file:com.miz.service.IdentifyTvShowService.java
@Override protected void onHandleIntent(Intent intent) { if (MizLib.isTvShowLibraryBeingUpdated(this)) { Handler mHandler = new Handler(Looper.getMainLooper()); mHandler.post(new Runnable() { @Override/*from w ww . ja va 2 s.c o m*/ public void run() { Toast.makeText(IdentifyTvShowService.this, R.string.cant_identify_while_updating, Toast.LENGTH_LONG).show(); } }); return; } log("clear()"); clear(); log("setup()"); setup(); log("Intent extras"); Bundle b = intent.getExtras(); mNewShowId = b.getString("newShowId"); mOldShowId = b.getString("oldShowId"); mLanguage = b.getString("language", "all"); log("setupList()"); setupList(); log("removeOldDatabaseEntries()"); removeOldDatabaseEntries(); log("start()"); start(); }
From source file:com.kescoode.android.yong.volley.toolbox.HurlStack.java
/** * @param urlRewriter Rewriter to use for request URLs *///from w w w .java 2 s . c o m public HurlStack(UrlRewriter urlRewriter) { this(urlRewriter, null, new ExecutorDelivery(new Handler(Looper.getMainLooper()))); }
From source file:com.nuvolect.securesuite.data.SqlIncSync.java
public SqlIncSync() { /**//from w w w .ja v a2 s.c om * Use the main looper to create the handler. Without the main looper * the handler will fail when initialized from a non-UI thread, such as when * called from the web server. */ mHandler = new Handler(Looper.getMainLooper()); mSyncSuspended = false; mSyncEnabled = WebUtil.companionServerAssigned(); }
From source file:com.vk.sdk.api.httpClient.VKImageOperation.java
/** * Set listener for current operation/*ww w .j a va2 s .com*/ * @param listener Listener subclasses VKHTTPOperationCompleteListener */ public void setImageOperationListener(final VKImageOperationListener listener) { this.setCompleteListener(new VKOperationCompleteListener() { @Override public void onComplete() { if (VKImageOperation.this.state() != VKOperationState.Finished || mLastException != null) { listener.onError(VKImageOperation.this, generateError(mLastException)); } else { byte[] response = getResponseData(); Bitmap captchaImage = BitmapFactory.decodeByteArray(response, 0, response.length); if (imageDensity > 0) { captchaImage = Bitmap.createScaledBitmap(captchaImage, (int) (captchaImage.getWidth() * imageDensity), (int) (captchaImage.getHeight() * imageDensity), true); } final Bitmap result = captchaImage; new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { listener.onComplete(VKImageOperation.this, result); } }); } } }); }
From source file:com.amazonaws.mobileconnectors.s3.transferutility.TransferStatusUpdater.java
/** * This class is instantiated by TransferService. *///from w w w . j a va2s . c o m TransferStatusUpdater(TransferDBUtil dbUtil) { this.dbUtil = dbUtil; mainHandler = new Handler(Looper.getMainLooper()); transfers = new HashMap<Integer, TransferRecord>(); lastUpdateTime = new HashMap<Integer, Long>(); }
From source file:com.campusconnect.gcm.GcmIntentService.java
@Override protected final void onHandleIntent(final Intent intent) { Bundle extras = intent.getExtras();// w w w. ja v a 2 s .c o m GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); if (!extras.isEmpty()) { // has effect of unpacking Bundle /* * Filter messages based on message type. Since it is likely that * GCM will be extended in the future with new message types, * just ignore any message types you're not interested in, or that * you don't recognize. */ switch (messageType) { case GoogleCloudMessaging.MESSAGE_TYPE_DELETED: sendNotification("Deleted messages on server: " + extras.toString()); // If it's a regular GCM message, do some work. break; case GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE: if (intent.getStringExtra("NotificationKind").equals("PriceCheckLowerPrices1")) { final String message = getUserMessageForPriceCheckLowerPricesNotif(intent); Handler h = new Handler(Looper.getMainLooper()); h.post(new Runnable() { @Override public void run() { Toast toast = Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG); toast.show(); } }); } break; case GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR: default: sendNotification("Send error: " + extras.toString()); break; } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:com.packpublishing.asynchronousandroid.chapter5.Sha1HashBroadCastUnhService.java
private void broadcastResult(final String text, final String digest) { Looper mainLooper = Looper.getMainLooper(); Handler handler = new Handler(mainLooper); handler.post(new Runnable() { @Override//from w w w. j a v a 2 s . c o m public void run() { Intent intent = new Intent(DIGEST_BROADCAST); intent.putExtra(RESULT, digest); LocalBroadcastManager.getInstance(Sha1HashBroadCastUnhService.this).sendBroadcastSync(intent); boolean handled = intent.getBooleanExtra(HANDLED, false); if (!handled) { notifyUser(text, digest); } } }); }