Example usage for android.os HandlerThread HandlerThread

List of usage examples for android.os HandlerThread HandlerThread

Introduction

In this page you can find the example usage for android.os HandlerThread HandlerThread.

Prototype

public HandlerThread(String name, int priority) 

Source Link

Document

Constructs a HandlerThread.

Usage

From source file:io.n7.calendar.caldav.CalDAVService.java

@Override
public void onCreate() {
    mCR = getContentResolver();/*from   ww  w. j  a va2  s  . c  o m*/
    // Check if there are any CalDAV accounts setup.
    // Check if the CalDAV calendars are present in the provider DB. If not, create.
    // Start Sync for all CalDAV calendars.
    mContext = this;
    HandlerThread thread = new HandlerThread("CalDAVService", Process.THREAD_PRIORITY_BACKGROUND);
    thread.start();

    mServiceLooper = thread.getLooper();
    mServiceHandler = new IncomingHandler(mServiceLooper);
    mMessenger = new Messenger(mServiceHandler);

}

From source file:org.opensilk.video.playback.PlaybackService.java

public void onCreate() {
    mPlaybackThread = new HandlerThread("SilkPlayback", Process.THREAD_PRIORITY_MORE_FAVORABLE);
    mPlaybackThread.start();//from w  w w.  j av  a2 s  .co m
    mPlaybackHandler = new Handler(mPlaybackThread.getLooper());
    mMainHandler = new Handler(Looper.getMainLooper());

    mMediaSession = newMediaSession();
    mMediaSession.setCallback(mMediaSessionCallback, mPlaybackHandler);

    mMediaPlayer = newMediaPlayer();
    mMediaPlayer.setEventListener(mMediaPlayerEventListener);
    mMediaPlayer.setEqualizer(VLCOptions.getEqualizer(mContext));

    mCreated = true;

    updateState(STATE_NONE);

}

From source file:com.cerema.cloud2.files.services.FileUploader.java

/**
 * Service initialization/*  ww w  .j  a v a2 s  .  c  o m*/
 */
@Override
public void onCreate() {
    super.onCreate();
    Log_OC.d(TAG, "Creating service");
    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    HandlerThread thread = new HandlerThread("FileUploaderThread", Process.THREAD_PRIORITY_BACKGROUND);
    thread.start();
    mServiceLooper = thread.getLooper();
    mServiceHandler = new ServiceHandler(mServiceLooper, this);
    mBinder = new FileUploaderBinder();

    // add AccountsUpdatedListener
    AccountManager am = AccountManager.get(getApplicationContext());
    am.addOnAccountsUpdatedListener(this, null, false);
}

From source file:de.pixart.messenger.ui.ScanActivity.java

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

    setContentView(R.layout.activity_scan);
    scannerView = findViewById(R.id.scan_activity_mask);
    previewView = findViewById(R.id.scan_activity_preview);
    previewView.setSurfaceTextureListener(this);

    cameraThread = new HandlerThread("cameraThread", Process.THREAD_PRIORITY_BACKGROUND);
    cameraThread.start();/*from   w  w  w  . j av a  2  s  .  c om*/
    cameraHandler = new Handler(cameraThread.getLooper());
}

From source file:com.digitalarx.android.files.services.FileUploader.java

/**
 * Service initialization/*  w  w w. ja va2  s  . com*/
 */
@Override
public void onCreate() {
    super.onCreate();
    Log_OC.i(TAG, "mPendingUploads size:" + mPendingUploads.size());
    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    HandlerThread thread = new HandlerThread("FileUploaderThread", Process.THREAD_PRIORITY_BACKGROUND);
    thread.start();
    mServiceLooper = thread.getLooper();
    mServiceHandler = new ServiceHandler(mServiceLooper, this);
    mBinder = new FileUploaderBinder();
}

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 . j av a2  s. c om
    }
    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:de.schildbach.wallet.ui.scan.ScanActivity.java

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

    viewModel = ViewModelProviders.of(this).get(ScanViewModel.class);
    viewModel.showPermissionWarnDialog.observe(this, new Observer<Void>() {
        @Override/*w  w w .j  av a 2 s. c o  m*/
        public void onChanged(final Void v) {
            WarnDialogFragment.show(getSupportFragmentManager(), R.string.scan_camera_permission_dialog_title,
                    getString(R.string.scan_camera_permission_dialog_message));
        }
    });
    viewModel.showProblemWarnDialog.observe(this, new Observer<Void>() {
        @Override
        public void onChanged(final Void v) {
            WarnDialogFragment.show(getSupportFragmentManager(), R.string.scan_camera_problem_dialog_title,
                    getString(R.string.scan_camera_problem_dialog_message));
        }
    });

    // Stick to the orientation the activity was started with. We cannot declare this in the
    // AndroidManifest.xml, because it's not allowed in combination with the windowIsTranslucent=true
    // theme attribute.
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
    // Draw under navigation and status bars.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
                WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

    setContentView(R.layout.scan_activity);
    contentView = findViewById(android.R.id.content);
    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();
    cameraHandler = new Handler(cameraThread.getLooper());

    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED)
        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.CAMERA }, 0);

    if (savedInstanceState == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        final Intent intent = getIntent();
        final int x = intent.getIntExtra(INTENT_EXTRA_SCENE_TRANSITION_X, -1);
        final int y = intent.getIntExtra(INTENT_EXTRA_SCENE_TRANSITION_Y, -1);
        if (x != -1 || y != -1) {
            // Using alpha rather than visibility because 'invisible' will cause the surface view to never
            // start up, so the animation will never start.
            contentView.setAlpha(0);
            getWindow().setBackgroundDrawable(
                    new ColorDrawable(getResources().getColor(android.R.color.transparent)));
            OnFirstPreDraw.listen(contentView, new OnFirstPreDraw.Callback() {
                @Override
                public boolean onFirstPreDraw() {
                    float finalRadius = (float) (Math.max(contentView.getWidth(), contentView.getHeight()));
                    final int duration = getResources().getInteger(android.R.integer.config_mediumAnimTime);
                    sceneTransition = ViewAnimationUtils.createCircularReveal(contentView, x, y, 0,
                            finalRadius);
                    sceneTransition.setDuration(duration);
                    sceneTransition.setInterpolator(new AccelerateInterpolator());
                    // TODO Here, the transition should start in a paused state, showing the first frame
                    // of the animation. Sadly, RevealAnimator doesn't seem to support this, unlike
                    // (subclasses of) ValueAnimator.
                    return false;
                }
            });
        }
    }
}

From source file:com.owncloud.android.services.OperationsService.java

/**
 * Service initialization/*w w w  .  ja  v a 2s  . com*/
 */
@Override
public void onCreate() {
    super.onCreate();
    Log_OC.d(TAG, "Creating service");

    /// First worker thread for most of operations 
    HandlerThread thread = new HandlerThread("Operations thread", Process.THREAD_PRIORITY_BACKGROUND);
    thread.start();
    mOperationsHandler = new ServiceHandler(thread.getLooper(), this);
    mOperationsBinder = new OperationsServiceBinder(mOperationsHandler);

    /// Separated worker thread for download of folders (WIP)
    thread = new HandlerThread("Syncfolder thread", Process.THREAD_PRIORITY_BACKGROUND);
    thread.start();
    mSyncFolderHandler = new SyncFolderHandler(thread.getLooper(), this);

    // create manager for local broadcasts
    mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);
}

From source file:org.anhonesteffort.flock.ContactCopyService.java

@Override
public void onCreate() {
    HandlerThread thread = new HandlerThread("ContactCopyService", HandlerThread.NORM_PRIORITY);
    thread.start();/*  w ww.  j  a  v  a  2  s  .c  o m*/

    serviceLooper = thread.getLooper();
    serviceHandler = new ServiceHandler(serviceLooper);

    notifyManager = (NotificationManager) getBaseContext().getSystemService(Context.NOTIFICATION_SERVICE);
    notificationBuilder = new NotificationCompat.Builder(getBaseContext());
    accountErrors = new LinkedList<Bundle>();
}