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.scalac.locationprovider.SendMockLocationService.java

@Override
public void onCreate() {
    /*/* ww  w .j a v  a 2 s .co  m*/
     * Load the mock location data from MockLocationConstants.java
     */
    mLocationArray = buildTestLocationArray(LocationUtils.WAYPOINTS_LAT, LocationUtils.WAYPOINTS_LNG,
            LocationUtils.WAYPOINTS_ACCURACY);

    /*
     * 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:com.cerema.cloud2.files.services.FileDownloader.java

/**
 * Service initialization/*from w w w  .  jav  a  2  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("FileDownloaderThread", Process.THREAD_PRIORITY_BACKGROUND);
    thread.start();
    mServiceLooper = thread.getLooper();
    mServiceHandler = new ServiceHandler(mServiceLooper, this);
    mBinder = new FileDownloaderBinder();

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

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

/**
 * Service initialization/* ww  w.j  a v a  2 s .c  o  m*/
 */
@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:org.peercast.core.PeerCastService.java

@Override
public void onCreate() {
    super.onCreate();

    HandlerThread thread = new HandlerThread("PeerCastService", Thread.MIN_PRIORITY);
    thread.start();/*from w  w w  .  ja  v a2s  .  co  m*/

    serviceLooper = thread.getLooper();
    serviceHandler = new ServiceHandler(serviceLooper);
    serviceMessenger = new Messenger(serviceHandler);
}

From source file:cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.data.service.OrgSyncService.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();/*w ww.  j a v  a 2  s. c  om*/

    // Get the HandlerThread's Looper and use it for our Handler
    serviceLooper = thread.getLooper();
    serviceHandler = new SyncHandler(serviceLooper);
}

From source file:org.hopestarter.wallet.ui.send.SweepWalletFragment.java

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

    setRetainInstance(true);/*  w w w.  j  av a 2 s  . c  o  m*/
    setHasOptionsMenu(true);

    backgroundThread = new HandlerThread("backgroundThread", Process.THREAD_PRIORITY_BACKGROUND);
    backgroundThread.start();
    backgroundHandler = new Handler(backgroundThread.getLooper());

    if (savedInstanceState != null) {
        restoreInstanceState(savedInstanceState);
    } else {
        final Intent intent = activity.getIntent();

        if (intent.hasExtra(SweepWalletActivity.INTENT_EXTRA_KEY)) {
            privateKeyToSweep = (VersionedChecksummedBytes) intent
                    .getSerializableExtra(SweepWalletActivity.INTENT_EXTRA_KEY);

            // delay until fragment is resumed
            handler.post(maybeDecodeKeyRunnable);
        }
    }
}

From source file:de.schildbach.wallet.ui.EncryptKeysDialogFragment.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  va 2 s  .  c  o  m
    backgroundHandler = new Handler(backgroundThread.getLooper());
    fingerprintHelper = new FingerprintHelper(getActivity());
}

From source file:de.schildbach.wallet.ui.send.RaiseFeeDialogFragment.java

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    viewModel = ViewModelProviders.of(this).get(ViewModel.class);
    viewModel.getDynamicFees().observe(this, new Observer<Map<FeeCategory, Coin>>() {
        @Override// w ww.ja va 2s .c  o m
        public void onChanged(final Map<FeeCategory, Coin> dynamicFees) {
            // We basically have to pay fee for two transactions:
            // The transaction to raise the fee of and the CPFP transaction we're about to create.
            final int size = transaction.getMessageSize() + 192;
            feeRaise = dynamicFees.get(FeeCategory.PRIORITY).multiply(size).divide(1000);
            updateView();
        }
    });

    final Bundle args = getArguments();
    final byte[] txHash = (byte[]) args.getSerializable(KEY_TRANSACTION);
    transaction = checkNotNull(wallet.getTransaction(Sha256Hash.wrap(txHash)));

    backgroundThread = new HandlerThread("backgroundThread", Process.THREAD_PRIORITY_BACKGROUND);
    backgroundThread.start();
    backgroundHandler = new Handler(backgroundThread.getLooper());
}

From source file:de.schildbach.wallet.ui.BackupWalletToSeedDialogFragment.java

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final View view = LayoutInflater.from(activity).inflate(R.layout.backup_wallet_to_seed_dialog, null);

    seedView = (TextView) view.findViewById(R.id.backup_wallet_dialog_seed);
    privateKeyPasswordViewGroup = view.findViewById(R.id.backup_wallet_seed_private_key_password_group);
    privateKeyPasswordView = (EditText) view.findViewById(R.id.backup_wallet_seed_private_key_password);
    privateKeyBadPasswordView = (TextView) view.findViewById(R.id.backup_wallet_seed_private_key_bad_password);
    showMnemonicSeedButton = (Button) view.findViewById(R.id.backup_wallet_seed_private_key_enter);
    seedViewGroup = view.findViewById(R.id.backup_wallet_seed_group);
    writtenDown = (CheckBox) view.findViewById(R.id.backup_wallet_seed_private_key_written_down);

    fingerprintView = view.findViewById(R.id.fingerprint_view);
    privateKeyPasswordViewGroup.setVisibility(wallet.isEncrypted() ? View.VISIBLE : View.GONE);

    privateKeyPasswordView.addTextChangedListener(privateKeyPasswordListener);
    showMnemonicSeedButton.setOnClickListener(new OnClickListener() {
        @Override// ww w  .j  a  va2s .  c o  m
        public void onClick(View v) {
            handleDecryptPIN();
        }
    });
    if (wallet.isEncrypted()) {
        backgroundThread = new HandlerThread("backgroundThread", Process.THREAD_PRIORITY_BACKGROUND);
        backgroundThread.start();
        backgroundHandler = new Handler(backgroundThread.getLooper());
        showPasswordViewGroup(true);
        updateView(false);
    } else {
        showMnemonicSeed(wallet.getActiveKeyChain().getSeed());
        updateView(true);
    }

    final DialogBuilder builder = new DialogBuilder(activity);
    builder.setTitle(R.string.export_keys_dialog_title);
    builder.setView(view);
    builder.setCancelable(false);
    builder.setPositiveButton(R.string.button_dismiss, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (writtenDown.isChecked()) {
                config.disarmBackupSeedReminder();
            }
            privateKeyPasswordView.removeTextChangedListener(privateKeyPasswordListener);
            if (getArguments().getBoolean(ARGS_IS_UPGRADING, false)
                    && activity instanceof UpgradeWalletDisclaimerDialog.OnUpgradeConfirmedListener) {
                ((UpgradeWalletDisclaimerDialog.OnUpgradeConfirmedListener) activity).onUpgradeConfirmed();
            }
        }
    });

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        initFingerprintHelper();
    }

    return builder.create();
}

From source file:paulscode.android.mupen64plusae.task.ExtractTexturesService.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();//  w w w .  j  a  va2  s.c  om

    // 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.pathHiResTexturesTask_title))
            .setContentText(getString(R.string.toast_pleaseWait)).setContentIntent(pendingIntent);
    startForeground(ONGOING_NOTIFICATION_ID, builder.build());
}