List of usage examples for android.os HandlerThread HandlerThread
public HandlerThread(String name, int priority)
From source file:de.schildbach.wallet.ui.send.MaintenanceDialogFragment.java
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); backgroundThread = new HandlerThread("backgroundThread", Process.THREAD_PRIORITY_BACKGROUND); backgroundThread.start();/*from ww w.j a v a 2 s . c o m*/ backgroundHandler = new Handler(backgroundThread.getLooper()); }
From source file:com.fillerino.wallet.ui.ScanActivity.java
@Override protected void onResume() { super.onResume(); cameraThread = new HandlerThread("cameraThread", Process.THREAD_PRIORITY_BACKGROUND); cameraThread.start();// www . j a va 2 s . co m cameraHandler = new Handler(cameraThread.getLooper()); final SurfaceView surfaceView = (SurfaceView) findViewById(com.fillerino.wallet.R.id.scan_activity_preview); surfaceHolder = surfaceView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); if (!hasCameraPermission()) { askCameraPermission(); } else { openCamera(); } }
From source file:com.coinomi.wallet.ui.ScanActivity.java
@Override protected void onResume() { super.onResume(); cameraThread = new HandlerThread("cameraThread", Process.THREAD_PRIORITY_BACKGROUND); cameraThread.start();//from ww w . j a v a2 s .c o m cameraHandler = new Handler(cameraThread.getLooper()); final SurfaceView surfaceView = (SurfaceView) findViewById(R.id.scan_activity_preview); surfaceHolder = surfaceView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); if (!hasCameraPermission()) { askCameraPermission(); } else { openCamera(); } }
From source file:net.xisberto.phonetodesktop.GoogleTasksActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Configure a background thread HandlerThread thread = new HandlerThread("PhoneToDesktopThread", Process.THREAD_PRIORITY_BACKGROUND); thread.start();/*from w ww . j a v a 2s.c o m*/ looper = thread.getLooper(); handler = new Handler(looper); // Configure app's preferences settings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); accountManager = new GoogleAccountManager(getApplicationContext()); // Configure GoogleCredential. loadAuthToken can return null credential = new GoogleCredential(); log("Current saved token: " + loadAuthToken()); // Configure and build the Tasks object tasksService = new Tasks.Builder(transport, jsonFactory, credential).setApplicationName("PhoneToDesktop") .setJsonHttpRequestInitializer(new GoogleKeyInitializer(my_credentials.getAPIKey())).build(); if (getIntent().getAction().equals(ACTION_AUTHENTICATE)) { broadcastUpdatingStatus(ACTION_AUTHENTICATE, true); authorize(); } else if (getIntent().getAction().equals(Intent.ACTION_SEND)) { addTask(loadWhatToSend(), getIntent().getStringExtra(Intent.EXTRA_TEXT)); } else if (getIntent().getAction().equals(ACTION_LIST_TASKS)) { broadcastUpdatingStatus(ACTION_LIST_TASKS, true); getTaskList(); } else if (getIntent().getAction().equals(ACTION_REMOVE_TASKS)) { removeTask(getIntent().getStringExtra("task_id")); } }
From source file:de.schildbach.wallet.ui.ScanActivity.java
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); setContentView(R.layout.scan_activity); scannerView = (ScannerView) findViewById(R.id.scan_activity_mask); previewView = (TextureView) findViewById(R.id.scan_activity_preview); previewView.setSurfaceTextureListener(this); cameraThread = new HandlerThread("cameraThread", Process.THREAD_PRIORITY_BACKGROUND); cameraThread.start();//w w w . j a v a2s . c o m cameraHandler = new Handler(cameraThread.getLooper()); if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.CAMERA }, 0); }
From source file:im.neon.util.VectorRoomMediasSender.java
/** * Constructor// w ww . j av a 2s.c o m * @param roomActivity the room activity. */ public VectorRoomMediasSender(VectorRoomActivity roomActivity, VectorMessageListFragment vectorMessageListFragment, MXMediasCache mediasCache) { mVectorRoomActivity = roomActivity; mVectorMessageListFragment = vectorMessageListFragment; mMediasCache = mediasCache; if (null == mHandlerThread) { mHandlerThread = new HandlerThread("VectorRoomMediasSender", Thread.MIN_PRIORITY); mHandlerThread.start(); mMediasSendingHandler = new android.os.Handler(mHandlerThread.getLooper()); } }
From source file:com.location.philippweiher.test.SendMockLocationService.java
@Override public void onCreate() { /*// w w w . j a v a 2 s .c om * Prepare to send status updates back to the main activity. * Get a local broadcast manager instance; broadcast intents sent via this * manager are only available within the this app. */ mLocalBroadcastManager = LocalBroadcastManager.getInstance(this); /* * Create a new background thread with an associated Looper that processes Message objects * from a MessageQueue. The Looper allows test Activities to send repeated requests to * inject mock locations from this Service. */ mWorkThread = new HandlerThread("UpdateThread", Process.THREAD_PRIORITY_BACKGROUND); /* * Start the thread. Nothing actually runs until the Looper for this thread dispatches a * Message to the Handler. */ mWorkThread.start(); // Get the Looper for the thread mUpdateLooper = mWorkThread.getLooper(); /* * Create a Handler object and pass in the Looper for the thread. * The Looper can now dispatch Message objects to the Handler's handleMessage() method. */ mUpdateHandler = new UpdateHandler(mUpdateLooper); // Indicate that testing has not yet started mTestStarted = false; }
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();/*w w w . java 2 s .co 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); } }); } }
From source file:org.fdroid.fdroid.net.DownloaderService.java
@Override public void onCreate() { super.onCreate(); Utils.debugLog(TAG, "Creating downloader service."); HandlerThread thread = new HandlerThread(TAG, Process.THREAD_PRIORITY_BACKGROUND); thread.start();/* ww w . j a va 2s. c o m*/ serviceLooper = thread.getLooper(); serviceHandler = new ServiceHandler(serviceLooper); localBroadcastManager = LocalBroadcastManager.getInstance(this); }
From source file:org.xbmc.kore.service.LibrarySyncService.java
@Override public void onCreate() { // Create a Handler Thread to process callback calls after the Xbmc method call handlerThread = new HandlerThread("LibrarySyncService", Process.THREAD_PRIORITY_BACKGROUND); handlerThread.start();//from ww w. ja va 2 s . c o m // Get the HandlerThread's Looper and use it for our Handler callbackHandler = new Handler(handlerThread.getLooper()); // Check which libraries to update and call the corresponding methods on Xbmc syncOrchestrators = new ArrayList<>(); }