Search in sources :

Example 16 with HandlerThread

use of android.os.HandlerThread in project Bitocle by mthli.

the class SplashActivity method showSignInDialog.

private void showSignInDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(SplashActivity.this);
    LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(R.layout.splash_dialog, null);
    final EditText userText = (EditText) layout.findViewById(R.id.splash_sign_in_dialog_username);
    final EditText passText = (EditText) layout.findViewById(R.id.splash_sign_in_dialog_password);
    passText.setTypeface(Typeface.DEFAULT);
    passText.setTransformationMethod(new PasswordTransformationMethod());
    builder.setView(layout);
    builder.setPositiveButton(getString(R.string.splash_sign_in_dialog_ok), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            username = userText.getText().toString();
            password = passText.getText().toString();
            if (username.length() == 0 || password.length() == 0) {
                Toast.makeText(SplashActivity.this, R.string.splash_input_error, Toast.LENGTH_SHORT).show();
            } else {
                progress = new ProgressDialog(SplashActivity.this);
                progress.setMessage(getString(R.string.splash_sign_in_authenticating));
                progress.setCancelable(false);
                progress.show();
                HandlerThread thread = new HandlerThread(getString(R.string.splash_sign_in_thread));
                thread.start();
                Handler handler = new Handler(thread.getLooper());
                handler.post(signInThread);
            }
        }
    });
    builder.setNegativeButton(getString(R.string.splash_sign_in_dialog_cancel), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
        /* Do nothing */
        }
    });
    builder.show();
}
Also used : AlertDialog(android.app.AlertDialog) EditText(android.widget.EditText) DialogInterface(android.content.DialogInterface) Handler(android.os.Handler) ProgressDialog(android.app.ProgressDialog) PasswordTransformationMethod(android.text.method.PasswordTransformationMethod) HandlerThread(android.os.HandlerThread) LinearLayout(android.widget.LinearLayout)

Example 17 with HandlerThread

use of android.os.HandlerThread in project Timber by naman14.

the class MusicService method onCreate.

@Override
public void onCreate() {
    if (D)
        Log.d(TAG, "Creating service");
    super.onCreate();
    mNotificationManager = NotificationManagerCompat.from(this);
    // gets a pointer to the playback state store
    mPlaybackStateStore = MusicPlaybackState.getInstance(this);
    mSongPlayCount = SongPlayCount.getInstance(this);
    mRecentStore = RecentStore.getInstance(this);
    mHandlerThread = new HandlerThread("MusicPlayerHandler", android.os.Process.THREAD_PRIORITY_BACKGROUND);
    mHandlerThread.start();
    mPlayerHandler = new MusicPlayerHandler(this, mHandlerThread.getLooper());
    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mMediaButtonReceiverComponent = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName());
    mAudioManager.registerMediaButtonEventReceiver(mMediaButtonReceiverComponent);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        setUpMediaSession();
    mPreferences = getSharedPreferences("Service", 0);
    mCardId = getCardId();
    registerExternalStorageListener();
    mPlayer = new MultiPlayer(this);
    mPlayer.setHandler(mPlayerHandler);
    // Initialize the intent filter and each action
    final IntentFilter filter = new IntentFilter();
    filter.addAction(SERVICECMD);
    filter.addAction(TOGGLEPAUSE_ACTION);
    filter.addAction(PAUSE_ACTION);
    filter.addAction(STOP_ACTION);
    filter.addAction(NEXT_ACTION);
    filter.addAction(PREVIOUS_ACTION);
    filter.addAction(PREVIOUS_FORCE_ACTION);
    filter.addAction(REPEAT_ACTION);
    filter.addAction(SHUFFLE_ACTION);
    // Attach the broadcast listener
    registerReceiver(mIntentReceiver, filter);
    mMediaStoreObserver = new MediaStoreObserver(mPlayerHandler);
    getContentResolver().registerContentObserver(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, true, mMediaStoreObserver);
    getContentResolver().registerContentObserver(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, mMediaStoreObserver);
    // Initialize the wake lock
    final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName());
    mWakeLock.setReferenceCounted(false);
    final Intent shutdownIntent = new Intent(this, MusicService.class);
    shutdownIntent.setAction(SHUTDOWN);
    mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    mShutdownIntent = PendingIntent.getService(this, 0, shutdownIntent, 0);
    scheduleDelayedShutdown();
    reloadQueueAfterPermissionCheck();
    notifyChange(QUEUE_CHANGED);
    notifyChange(META_CHANGED);
}
Also used : PowerManager(android.os.PowerManager) IntentFilter(android.content.IntentFilter) HandlerThread(android.os.HandlerThread) ComponentName(android.content.ComponentName) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

Example 18 with HandlerThread

use of android.os.HandlerThread in project mobile-android by photo.

the class AbstractUploaderService method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    HandlerThread thread = new HandlerThread(TAG);
    thread.start();
    mServiceLooper = thread.getLooper();
    mServiceHandler = new ServiceHandler(mServiceLooper, this);
    mApi = CommonConfigurationUtils.getApi();
    setUpConnectivityWatcher();
    CommonUtils.debug(TAG, "Service created");
    mUploadRemovedReceiver = UploaderServiceUtils.getAndRegisterOnPhotoUploadRemovedActionBroadcastReceiver(TAG, this, this);
}
Also used : HandlerThread(android.os.HandlerThread)

Example 19 with HandlerThread

use of android.os.HandlerThread in project android by owncloud.

the class FileDownloader method onCreate.

/**
     * Service initialization
     */
@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);
}
Also used : HandlerThread(android.os.HandlerThread) AccountManager(android.accounts.AccountManager)

Example 20 with HandlerThread

use of android.os.HandlerThread in project android by owncloud.

the class OperationsService method onCreate.

/**
     * Service initialization
     */
@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);
}
Also used : HandlerThread(android.os.HandlerThread)

Aggregations

HandlerThread (android.os.HandlerThread)292 Handler (android.os.Handler)128 Message (android.os.Message)26 IntentFilter (android.content.IntentFilter)24 Intent (android.content.Intent)22 Context (android.content.Context)20 Test (org.junit.Test)20 PowerManager (android.os.PowerManager)15 Runnable (java.lang.Runnable)15 ComponentName (android.content.ComponentName)14 View (android.view.View)14 PendingIntent (android.app.PendingIntent)12 MediumTest (android.test.suitebuilder.annotation.MediumTest)12 Looper (android.os.Looper)11 RemoteException (android.os.RemoteException)11 MediaFormat (android.media.MediaFormat)10 Pair (android.util.Pair)10 SmallTest (android.test.suitebuilder.annotation.SmallTest)9 Uri (android.net.Uri)8 IOException (java.io.IOException)8