List of usage examples for android.os HandlerThread HandlerThread
public HandlerThread(String name)
From source file:sssemil.com.wifiapmanager.MainService.java
@Override public void onCreate() { super.onCreate(); mContext = this; IntentFilter intentFilter = new IntentFilter("android.net.wifi.WIFI_AP_STATE_CHANGED"); intentFilter.addAction("android.net.conn.TETHER_STATE_CHANGED"); intentFilter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED); intentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); mIcon = R.drawable.ic_tt;/*from w w w. j a v a 2s. com*/ mContext.registerReceiver(mReceiver, intentFilter); mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); mSharedPreferences.registerOnSharedPreferenceChangeListener(this); mLooper = getMainLooper(); mScanThread = new HandlerThread("WifiClientScanner"); if (!mScanThread.isAlive()) { mScanThread.start(); mScanHandler = new WifiClientScanner(mScanThread.getLooper()); mScanHandler.sendEmptyMessage(0); } }
From source file:com.lithiumli.fiction.NowPlayingActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.now_playing); initializeDrawer(false);// w ww . j av a 2 s .c o m mCoverPager = (AlbumSwiper) findViewById(R.id.cover_pager); mCoverPager.setListener(this); mSongName = (TextView) findViewById(R.id.np_song_name); mSongAlbum = (TextView) findViewById(R.id.np_song_album); mSongArtist = (TextView) findViewById(R.id.np_song_artist); mSongArtist.setSelected(true); ActionBar ab = getActionBar(); ab.setDisplayHomeAsUpEnabled(true); ab.setTitle("Now Playing"); mCache = ArtistImageCache.getInstance(this); setQueueMargin(); HandlerThread thread = new HandlerThread("thread"); thread.start(); mLooper = thread.getLooper(); mHandler = new Handler(mLooper); mFadeOut = new FadeOut(); mHandler.postDelayed(mFadeOut, 2000); }
From source file:com.twp.music.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Logger.i(TAG, "onCreate ---- "); setContentView(R.layout.activity_main); fm = getFragmentManager();/*from w w w . ja va2 s. c o m*/ initView(); token = MusicUtils.bindToService(this, this); //start ? ?? ?looperhandler HandlerThread alnumArtThread = new HandlerThread("Album Art HandlerThread "); alnumArtThread.start(); albumArtHandler = new AlbumArtHandler(alnumArtThread.getLooper()); }
From source file:com.flipkart.batchdemo.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); HandlerThread handlerThread = new HandlerThread("bg"); handlerThread.start();/* www . j a v a2 s . c om*/ Handler backgroundHandler = new Handler(handlerThread.getLooper()); GsonSerializationStrategy<CustomTagData, SizeBatch<CustomTagData>> serializationStrategy = new GsonSerializationStrategy<>( new CustomTagDataAdapter(), null); debugTag = new Tag(DEBUG_LOGGER_GROUPID); perfTag = new Tag(PERF_LOGGER_GROUPID); dgTag = new Tag(DG_LOGGER_GROUPID); final NetworkPersistedBatchReadyListener perfListener = new NetworkPersistedBatchReadyListener( getApplicationContext(), getCacheDir() + "/" + "perf", serializationStrategy, backgroundHandler, new NetworkPersistedBatchReadyListener.NetworkBatchListener() { @Override public void performNetworkRequest(Batch batch, ValueCallback callback) { } }, 5, 100, 90, TRIM_MEMORY_BACKGROUND, new TrimmedBatchCallback() { @Override public void onTrimmed(int oldSize, int newSize) { } }); perfListener.setListener(new PersistedBatchCallback() { @Override public void onPersistFailure(Batch batch, Exception e) { } @Override public void onPersistSuccess(Batch batch) { //SystemClock.sleep(2000); perfListener.finish(batch); Log.e("Perf", "Finish Called"); ArrayList<CustomTagData> dataArrayList = (ArrayList<CustomTagData>) batch.getDataCollection(); for (CustomTagData data : dataArrayList) { Log.e("OUT", data.getEvent().toString()); } } @Override public void onFinish() { } }); final NetworkPersistedBatchReadyListener debugListener = new NetworkPersistedBatchReadyListener( getApplicationContext(), getCacheDir() + "/" + "debug", serializationStrategy, backgroundHandler, new NetworkPersistedBatchReadyListener.NetworkBatchListener() { @Override public void performNetworkRequest(Batch batch, ValueCallback callback) { } }, 5, 100, 90, TRIM_MEMORY_BACKGROUND, new TrimmedBatchCallback() { @Override public void onTrimmed(int oldSize, int newSize) { } }); debugListener.setListener(new PersistedBatchCallback<TagBatch<TagData>>() { @Override public void onPersistFailure(TagBatch<TagData> batch, Exception e) { } @Override public void onPersistSuccess(TagBatch<TagData> batch) { // SystemClock.sleep(2000); debugListener.finish(batch); Log.e("Debug", "Finish Called"); } @Override public void onFinish() { } }); final NetworkPersistedBatchReadyListener dgListener = new NetworkPersistedBatchReadyListener( getApplicationContext(), getCacheDir() + "/" + "dg", serializationStrategy, backgroundHandler, new NetworkPersistedBatchReadyListener.NetworkBatchListener() { @Override public void performNetworkRequest(Batch batch, ValueCallback callback) { } }, 5, 100, 90, TRIM_MEMORY_BACKGROUND, new TrimmedBatchCallback() { @Override public void onTrimmed(int oldSize, int newSize) { } }); dgListener.setListener(new PersistedBatchCallback<TagBatch<TagData>>() { @Override public void onPersistFailure(TagBatch<TagData> batch, Exception e) { } @Override public void onPersistSuccess(TagBatch<TagData> batch) { //SystemClock.sleep(2000); dgListener.finish(batch); Log.e("Dg", "Finish Called"); } @Override public void onFinish() { } }); batchManager = new TagBatchManager.Builder<>().setSerializationStrategy(serializationStrategy) .setHandler(backgroundHandler) .addTag(perfTag, new SizeBatchingStrategy(3, new TapePersistenceStrategy(getCacheDir() + "/perf1", serializationStrategy)), perfListener) .addTag(debugTag, new SizeBatchingStrategy(3, new TapePersistenceStrategy(getCacheDir() + "/debug1", serializationStrategy)), debugListener) .addTag(dgTag, new SizeBatchingStrategy(3, new TapePersistenceStrategy(getCacheDir() + "/dg1", serializationStrategy)), dgListener) .build(getApplicationContext()); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Log.e("IN", TrackingHelper.getProductPageViewEvent(String.valueOf(count), "dfg", "fgh").toString()); batchManager.addToBatch(Collections.singleton(new CustomTagData(perfTag, TrackingHelper.getProductPageViewEvent(String.valueOf(count), "dfg", "fgh")))); Snackbar.make(view, "Replace with your own action " + count, Snackbar.LENGTH_LONG) .setAction("Action", null).show(); count++; } }); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); }
From source file:com.kogitune.launcher3.LauncherAppWidgetHostView.java
@Override public void updateAppWidget(RemoteViews remoteViews) { if (EXPERIMENTAL) { if (remoteViews != null) { Handler mH = null;//from w w w. java 2 s . c o m Field queueField = null; MessageQueue messageQueue = null; try { Class<?> activityThreadClass = Class.forName("android.app.ActivityThread"); Class[] params = new Class[0]; Method currentActivityThread = activityThreadClass.getDeclaredMethod("currentActivityThread", params); Boolean accessible = currentActivityThread.isAccessible(); currentActivityThread.setAccessible(true); Object obj = currentActivityThread.invoke(activityThreadClass); if (obj == null) { Log.d("ERROR", "The current activity thread is null!"); } currentActivityThread.setAccessible(accessible); Field mHField = activityThreadClass.getDeclaredField("mH"); mHField.setAccessible(true); mH = (Handler) mHField.get(obj); queueField = Handler.class.getDeclaredField("mQueue"); queueField.setAccessible(true); messageQueue = (MessageQueue) queueField.get(mH); HandlerThread handlerThread = new HandlerThread("other"); handlerThread.start(); handlerThread.quit(); queueField.set(mH, null); } catch (Exception e) { Log.d("ERROR", Log.getStackTraceString(e)); } Context context = getContext().getApplicationContext(); NotificationManager notificationManager = (NotificationManager) context.getApplicationContext() .getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setContent(remoteViews).setSmallIcon(R.drawable.ic_launcher_info_normal_holo) .setContentTitle("My notification") // ? .setContentText("Hello Notification!!"); // ? Notification notification = builder.build(); notificationManager.notify(getAppWidgetId(), notification); final Field finalQueueField = queueField; final Handler finalMH = mH; final MessageQueue finalMessageQueue = messageQueue; new Thread(new Runnable() { @Override public void run() { try { Thread.sleep(50L); if (finalMessageQueue != null) finalQueueField.set(finalMH, finalMessageQueue); } catch (Exception e) { e.printStackTrace(); } } }).start(); } } // Store the orientation in which the widget was inflated mPreviousOrientation = mContext.getResources().getConfiguration().orientation; super.updateAppWidget(remoteViews); }
From source file:com.musenkishi.atelier.Atelier.java
private static void setupHandlers(Context context) { HandlerThread handlerThread = new HandlerThread("palette-loader-background"); handlerThread.start();/*from w w w . ja v a2s . co m*/ backgroundHandler = new Handler(handlerThread.getLooper(), callback); uiHandler = new Handler(context.getMainLooper(), callback); }
From source file:org.sufficientlysecure.keychain.service.PassphraseCacheService.java
/** * Gets a cached passphrase from memory by sending an intent to the service. This method is * designed to wait until the service returns the passphrase. * * @param context//from w w w . j a v a2s . co m * @param keyId * @return passphrase or null (if no passphrase is cached for this keyId) */ public static String getCachedPassphrase(Context context, long keyId) { Log.d(TAG, "getCachedPassphrase() get masterKeyId for " + keyId); Intent intent = new Intent(context, PassphraseCacheService.class); intent.setAction(ACTION_PASSPHRASE_CACHE_GET); final Object mutex = new Object(); final Bundle returnBundle = new Bundle(); HandlerThread handlerThread = new HandlerThread("getPassphraseThread"); handlerThread.start(); Handler returnHandler = new Handler(handlerThread.getLooper()) { @Override public void handleMessage(Message message) { if (message.obj != null) { String passphrase = ((Bundle) message.obj).getString(EXTRA_PASSPHRASE); returnBundle.putString(EXTRA_PASSPHRASE, passphrase); } synchronized (mutex) { mutex.notify(); } // quit handlerThread getLooper().quit(); } }; // Create a new Messenger for the communication back Messenger messenger = new Messenger(returnHandler); intent.putExtra(EXTRA_KEY_ID, keyId); intent.putExtra(EXTRA_MESSENGER, messenger); // send intent to this service context.startService(intent); // Wait on mutex until passphrase is returned to handlerThread synchronized (mutex) { try { mutex.wait(3000); } catch (InterruptedException e) { } } if (returnBundle.containsKey(EXTRA_PASSPHRASE)) { return returnBundle.getString(EXTRA_PASSPHRASE); } else { return null; } }
From source file:it.polimi.proximityapi.TechnologyManager.java
public TechnologyManager(Context ctx) { appCtx = ctx;//from ww w . ja v a 2 s .c om //register "this" as BroadcastReceiver for geofence events ctx.registerReceiver(this, new IntentFilter(appCtx.getPackageName() + "." + GeofenceProvider.POI_EVENT_BROADCAST_ACTION)); bleProvider = new BLEProximityProvider(appCtx); bleProvider.setTechListener(this); geofenceProvider = new GeofenceProvider(ctx); proximityProviders = new ArrayList<BaseProvider>(); proximityProviders.add(bleProvider); proximityProviders.add(geofenceProvider); proximityData = new ArrayList<ProximityData>(); //Initialize the worker thread workerThread = new HandlerThread("MyLocMgrWorker"); workerThread.start(); mHandler = new Handler(workerThread.getLooper()); //Call init method of each provider used for (BaseProvider p : proximityProviders) p.init(); }
From source file:com.vk.sdk.payments.VKPaymentsServerSender.java
private VKPaymentsServerSender(@NonNull Context ctx) { mAppCtx = ctx;/* w w w . ja v a 2 s . co m*/ mCheckUserInstallAnswer = restoreAnswer(ctx); HandlerThread handlerThread = new HandlerThread(getClass().getName()); handlerThread.start(); mHandler = new Handler(handlerThread.getLooper()); // !!! WARNING !!! this for wait reference url from vk client mHandler.post(new Runnable() { @Override public void run() { try { Thread.sleep(1000); // time for wait reference url } catch (Exception e) { // nothing } } }); }
From source file:sssemil.com.wifiapmanager.MainService.java
private void handleWifiApStateChanged() { WifiApManager wifiApManager = new WifiApManager(mContext); if (wifiApManager.isWifiApEnabled() && mSharedPreferences.getBoolean("show_notification", false)) { showTetheredNotification();/*from w ww .j a v a 2 s. co m*/ if (!mScanThread.isAlive()) { mScanThread = new HandlerThread("WifiClientScanner"); mScanThread.start(); mScanHandler = new WifiClientScanner(mScanThread.getLooper()); mScanHandler.sendEmptyMessage(0); } } else { clearTetheredNotification(); if (mScanThread.isAlive()) { mScanThread.quit(); } } }