List of usage examples for android.os HandlerThread getLooper
public Looper getLooper()
From source file:org.anhonesteffort.flock.ExportService.java
@Override public void onCreate() { HandlerThread thread = new HandlerThread(getClass().getSimpleName(), HandlerThread.NORM_PRIORITY); thread.start();//from w w w .j ava 2 s .c o m serviceHandler = new ServiceHandler(thread.getLooper()); notifyManager = (NotificationManager) getBaseContext().getSystemService(Context.NOTIFICATION_SERVICE); notificationBuilder = new NotificationCompat.Builder(getBaseContext()); }
From source file:com.bitants.wally.fragments.RandomImagesFragment.java
private void setupHandlers() { HandlerThread handlerThread = new HandlerThread("RandomImages.background"); handlerThread.start();/*from w ww. j av a 2 s . c om*/ backgroundHandler = new Handler(handlerThread.getLooper(), this); uiHandler = new Handler(getActivity().getMainLooper(), this); }
From source file:com.android.camera.v2.uimanager.ThumbnailManager.java
/** * Create a thumbnail manager controller. * @param appcontroller controller used to get service for storage. * @param activity the current activity. * @param parent view group./* www.j a va2s . co m*/ * @param secureCamera whether the current camera is secure camera or not. */ public ThumbnailManager(AppController appcontroller, Activity activity, ViewGroup parent, boolean secureCamera) { super(activity, parent); mIsSecureCamera = secureCamera; setFilterEnable(false); mStorageService = appcontroller.getAppControllerAdapter().getServices().getStorageService(); mActivity = activity; mContentResolver = activity.getContentResolver(); mMaiHandler = new Handler(activity.getMainLooper()); HandlerThread t = new HandlerThread("thumbnail-creation-thread"); t.start(); mHandler = new ThumbnailCreatorHandler(t.getLooper()); mThumbnailAnimation = new ThumbnailAnimation(); LocalBroadcastManager manager = LocalBroadcastManager.getInstance(mActivity); manager.registerReceiver(mUpdatePictureReceiver, mUpdatePictureFilter); mActivity.registerReceiver(mIpoShutdownReceiver, mIpoShutdownFilter); mIntent = activity.getIntent(); String action = null; if (mIntent != null) { action = mIntent.getAction(); } if (MediaStore.ACTION_IMAGE_CAPTURE.equals(action) || MediaStore.ACTION_VIDEO_CAPTURE.equals(action) || CameraUtil.ACTION_STEREO3D.equals(action)) { mShownByIntent = false; } }
From source file:org.compose.mobilesdk.android.COMPOSESubService.java
@Override public void onCreate() { super.onCreate(); mDeviceId = String.format(DEVICE_ID_FORMAT, Secure.getString(getContentResolver(), Secure.ANDROID_ID)); HandlerThread thread = new HandlerThread(MQTT_THREAD_NAME); thread.start();// w ww . jav a 2s . com mConnHandler = new Handler(thread.getLooper()); try { mDataStore = new MqttDefaultFilePersistence(getCacheDir().getAbsolutePath()); } catch (Exception e) { e.printStackTrace(); mDataStore = null; mMemStore = new MemoryPersistence(); } mOpts = new MqttConnectOptions(); mOpts.setCleanSession(MQTT_CLEAN_SESSION); // Do not set keep alive interval on mOpts we keep track of it with alarm's mAlarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); mConnectivityManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); }
From source file:paulscode.android.mupen64plusae.task.CacheRomInfoService.java
@Override public void onCreate() { // Start up the thread running the service. Note that we create a // separate thread because the service normally runs in the process's // main thread, which we don't want to block. We also make it // background priority so CPU-intensive work will not disrupt our UI. HandlerThread thread = new HandlerThread("ServiceStartArguments", Process.THREAD_PRIORITY_BACKGROUND); thread.start();/*from w w w . j a v a2 s .co m*/ // Get the HandlerThread's Looper and use it for our Handler mServiceLooper = thread.getLooper(); mServiceHandler = new ServiceHandler(mServiceLooper); //Show the notification Intent notificationIntent = new Intent(this, GalleryActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.icon) .setContentTitle(getString(R.string.scanning_title)) .setContentText(getString(R.string.toast_pleaseWait)).setContentIntent(pendingIntent); startForeground(ONGOING_NOTIFICATION_ID, builder.build()); }
From source file:com.cssweb.android.quote.KLine2Activity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); HandlerThread mHandlerThread = new HandlerThread("CSSWEB_THREAD"); mHandlerThread.start();/*from w ww . j a va2 s .c o m*/ mHandler = new MessageHandler(mHandlerThread.getLooper()); this.activityKind = Global.QUOTE_KLINE; Bundle bundle = getIntent().getExtras(); this.exchange = bundle.getString("exchange"); this.stockcode = bundle.getString("stockcode"); this.stockname = bundle.getString("stockname"); CssSystem.exchange = bundle.getString("exchange"); CssSystem.stockcode = bundle.getString("stockcode"); CssSystem.stockname = bundle.getString("stockname"); cssStock = new CssStock(); cssStock.setMarket(this.exchange); cssStock.setStkcode(this.stockcode); cssStock.setStkname(this.stockname); setContentView(R.layout.zr_klineview2); // toolbarname = new String[]{ // Global.TOOLBAR_MENU, Global.TOOLBAR_ZHIBIAO, // Global.TOOLBAR_ZHOUQI, Global.TOOLBAR_F10, // Global.TOOLBAR_ZOOMOUT, Global.TOOLBAR_ZOOMIN }; toolbarname = new String[] { Global.TOOLBAR_MENU, Global.TOOLBAR_FENSHI, Global.TOOLBAR_ZHOUQI, Global.TOOLBAR_ZHIBIAO, Global.TOOLBAR_F10, Global.TOOLBAR_REFRESH }; if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { setToolbarByScreen(2); } else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { setToolbarByScreen(1); } initTitle(R.drawable.njzq_title_left_back, 0, "K"); setTitleText(stockname + " " + peroidN); initKlineView(); getZhibiao(); getZhouqi(); }
From source file:de.stadtrallye.rallyesoft.services.UploadService.java
@Override public void onCreate() { super.onCreate(); notes = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); connection = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); telephony = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); connection.getActiveNetworkInfo();/* w w w .j a va 2s . c om*/ Storage.aquireStorage(getApplicationContext(), this); dbProvider = Storage.getDatabaseProvider(); pictureManager = Storage.getPictureManager(); pref = Storage.getAppPreferences(); pref.registerOnSharedPreferenceChangeListener(this); readPrefs(); HandlerThread thread = new HandlerThread("UploadService [UploadThread]"); thread.start(); looper = thread.getLooper(); handler = new UploaderHandler(looper); }
From source file:com.digitalarx.android.files.services.FileDownloader.java
/** * Service initialization//from w ww.j a v a 2 s . com */ @Override public void onCreate() { super.onCreate(); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); HandlerThread thread = new HandlerThread("FileDownloaderThread", Process.THREAD_PRIORITY_BACKGROUND); thread.start(); mServiceLooper = thread.getLooper(); mServiceHandler = new ServiceHandler(mServiceLooper, this); mBinder = new FileDownloaderBinder(); }
From source file:com.longle1.facedetection.MainActivity.java
public FaceDetect(MainActivity context) throws IOException { super(context); // Create a private directory and file File classifierFile = new File(context.getDir("cascade", Context.MODE_PRIVATE), "haarcascade_frontalface_alt.xml"); FileOutputStream os = new FileOutputStream(classifierFile); // load cascade file from application resources InputStream is = getResources().openRawResource(R.raw.haarcascade_frontalface_alt); // copy from is to os byte[] buffer = new byte[4096]; int bytesRead; while ((bytesRead = is.read(buffer)) != -1) { os.write(buffer, 0, bytesRead);/*w w w . ja v a2 s .c o m*/ } is.close(); os.close(); if (classifierFile == null || classifierFile.length() <= 0) { throw new IOException("Could not extract the classifier file from Java resource."); } // Preload the opencv_objdetect module to work around a known bug. Loader.load(opencv_objdetect.class); classifier = new CvHaarClassifierCascade(cvLoad(classifierFile.getAbsolutePath())); classifierFile.delete(); if (classifier.isNull()) { throw new IOException("Could not load the classifier file."); } storage = CvMemStorage.create(); // Preload the module to work around a known bug in FFmpegFrameRecorder Loader.load(swresample.class); // Create looper for asyncHttp HandlerThread thread2 = new HandlerThread("AsyncHttpResponseHandler", android.os.Process.THREAD_PRIORITY_BACKGROUND); mAsyncHttpLooper = thread2.getLooper(); thread2.start(); // temp video file File folder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM); filePath = folder.getAbsolutePath() + "/Camera/" + "tmp" + ".mp4"; // Create location mLocationData = new LocationData(getContext()); }
From source file:org.disrupted.rumble.network.NetworkCoordinator.java
@Override public void onCreate() { super.onCreate(); synchronized (lock) { Log.d(TAG, "[+] Starting NetworkCoordinator"); HandlerThread serviceThread = new HandlerThread("NetworkCoordinatorThread", android.os.Process.THREAD_PRIORITY_BACKGROUND); serviceThread.start();/*ww w .j a v a 2 s . c o m*/ serviceLooper = serviceThread.getLooper(); serviceHandler = new Handler(serviceLooper); serviceHandler.post(new Runnable() { @Override public void run() { neighbourManager = new NeighbourManager(); scannerList = new LinkedList<Scanner>(); // register link layers and their pool adapters = new LinkedList<LinkLayerAdapter>(); workerPools = new HashMap<String, WorkerPool>(); BluetoothLinkLayerAdapter bluetoothLinkLayerAdapter = BluetoothLinkLayerAdapter .getInstance(NetworkCoordinator.this); adapters.add(bluetoothLinkLayerAdapter); workerPools.put(BluetoothLinkLayerAdapter.LinkLayerIdentifier, new WorkerPool(5)); WifiLinkLayerAdapter wifiAdapter = new WifiLinkLayerAdapter(); adapters.add(wifiAdapter); workerPools.put(wifiAdapter.getLinkLayerIdentifier(), new WorkerPool(10)); // register protocols protocols = new LinkedList<Protocol>(); protocols.add(RumbleProtocol.getInstance(NetworkCoordinator.this)); //protocols.add(FirechatProtocol.getInstance(this)); // register services services = new LinkedList<ServiceLayer>(); services.add(PushService.getInstance(NetworkCoordinator.this)); services.add(ChatService.getInstance(NetworkCoordinator.this)); networkingStarted = false; EventBus.getDefault().register(NetworkCoordinator.this); } }); } }