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();
}
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);
}
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);
}
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);
}
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);
}
Aggregations