Example usage for android.os HandlerThread start

List of usage examples for android.os HandlerThread start

Introduction

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

Prototype

public synchronized void start() 

Source Link

Document

Causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.

Usage

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);/*from   ww  w .  java2 s  . c  o  m*/
    }
    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:nl.dobots.presence.PresenceDetectionApp.java

@Override
public void onCreate() {
    super.onCreate();
    instance = this;

    // load settings from persistent storage
    _settings = Settings.getInstance();/*from  w w  w .j av a  2  s.  c om*/
    _settings.readPersistentStorage(getApplicationContext());

    _settings.readPersistentLocations(getApplicationContext());

    // get localization algo
    _localization = new SimpleLocalization(_settings.getLocationsList(), _settings.getDetectionDistance());

    // get ask wrapper (wraps login and presence functions)
    _ask = AskWrapper.getInstance();

    _notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    // watchdog handler checks for non-presence and handles manual override
    HandlerThread watchdogThread = new HandlerThread("Watchdog");
    watchdogThread.start();
    _watchdogHandler = new Handler(watchdogThread.getLooper());
    _watchdogHandler.postDelayed(_watchdogRunner, Config.WATCHDOG_INTERVAL);

    // network handler used for network operations (login, updatePresence, etc.)
    HandlerThread networkThread = new HandlerThread("NetworkHandler");
    networkThread.start();
    _networkHandler = new Handler(networkThread.getLooper());

    // filter for connectivity broadcasts
    IntentFilter filter = new IntentFilter();
    filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    registerReceiver(_receiver, filter);

    //      Intent startServiceIntent = new Intent(this, BleScanService.class);
    //      this.startService(startServiceIntent);

    Intent intent = new Intent(this, BleScanService.class);
    bindService(intent, _connection, Context.BIND_AUTO_CREATE);

    // set expiration time for RSSI measurements. keeps measurements of 5 scan intervals
    // before throwing them out. i.e. averages over all measurements received in the last 5
    // scan intervals
    BleDevice.setExpirationTime(5 * (Config.LOW_SCAN_PAUSE + Config.LOW_SCAN_INTERVAL));

}

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

/**
 * Service initialization// w  w w. j a va 2 s . c om
 */
@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:org.alljoyn.bus.samples.simpleclient.DevicesActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_devices);
    mContext = this;

    //        mEditText = (EditText) findViewById(R.id.EditText);
    //        mEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    //                public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
    //                    if (actionId == EditorInfo.IME_NULL
    //                        && event.getAction() == KeyEvent.ACTION_UP) {
    //                        /* Call the remote object's Ping method. */
    //                        Message msg = mBusHandler.obtainMessage(BusHandler.PING, 
    //                                                                view.getText().toString());
    //                        mBusHandler.sendMessage(msg);
    //                    }
    //                    return true;
    //                }
    //            });

    //Master data list Fragment

    String fullName = SERVICE_NAME + ".coffeemaker.Beagle_Bone";
    String[] tokens = fullName.split("[.]");
    for (String token : tokens) {
        Log.i("token:", token);
    }// w  ww.  ja  v  a  2s.com

    mDeviceListFragment = new DeviceListFragment();
    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.add(R.id.myFragmentContainer, mDeviceListFragment, "DeviceListFragment");
    fragmentTransaction.commit();

    /* Make all AllJoyn calls through a separate handler thread to prevent blocking the UI. */
    HandlerThread busThread = new HandlerThread("BusHandler");
    busThread.start();
    mBusHandler = new BusHandler(busThread.getLooper());

    /* Connect to an AllJoyn object. */
    mBusHandler.sendEmptyMessage(BusHandler.CONNECT);
    mHandler.sendEmptyMessage(MESSAGE_START_PROGRESS_DIALOG);
}

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

@Override
public void onCreate() {
    mCR = getContentResolver();//from  w w  w .ja v a2 s  . co 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.odk.collect.android.fragments.Camera2VideoFragment.java

/**
 * Update the camera preview. {@link #startPreview()} needs to be called in advance.
 *///from ww  w .  j av  a2  s.com
private void updatePreview() {
    if (null == cameraDevice) {
        return;
    }
    try {
        setUpCaptureRequestBuilder(previewBuilder);
        HandlerThread thread = new HandlerThread("CameraPreview");
        thread.start();
        previewSession.setRepeatingRequest(previewBuilder.build(), null, backgroundHandler);
    } catch (CameraAccessException e) {
        Timber.e(e);
    }
}

From source file:com.ubergeek42.WeechatAndroid.service.RelayServiceBackbone.java

@Override
public void onCreate() {
    if (DEBUG)//from w  w w  .  ja  v a2 s.co  m
        logger.debug("onCreate()");
    super.onCreate();

    prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    prefs.registerOnSharedPreferenceChangeListener(this);
    notificationManger = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    // prepare handler that will run on a separate thread
    HandlerThread handler_thread = new HandlerThread("doge");
    handler_thread.start();
    thandler = new Handler(handler_thread.getLooper());

    startForeground(NOTIFICATION_ID, buildNotification(null, "Tap to connect", null));

    disconnected = false;
    already_had_intent = false;
    network_unavailable = false;

    // Prepare for dealing with SSL certs
    certmanager = new SSLHandler(new File(getDir("sslDir", Context.MODE_PRIVATE), "keystore.jks"));

    registerReceiver(connectivityActionReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));

    alarmMgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
}

From source file:cz.muni.fi.japanesedictionary.parser.ParserService.java

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

    HandlerThread thread = new HandlerThread("IntentService[Dictionary_parser]");
    thread.start();

    mServiceLooper = thread.getLooper();
    mServiceHandler = new ServiceHandler(mServiceLooper);
    setIntentRedelivery(true);/*from w w  w.  j ava2s  .  c o m*/

}

From source file:com.android.rahul.myselfieapp.Fragment.CamVideoFragment.java

/**
 * Update the camera preview. {@link #startPreview()} needs to be called in advance.
 *//* w w w .  j  a  v a  2 s  .c  o m*/
private void updatePreview() {
    if (null == mCameraDevice) {
        return;
    }
    try {
        setUpCaptureRequestBuilder(mPreviewBuilder);
        HandlerThread thread = new HandlerThread("CameraPreview");
        thread.start();
        mPreviewSession.setRepeatingRequest(mPreviewBuilder.build(), null, mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

From source file:com.wbtech.ums.UmsAgent.java

private UmsAgent() {
    HandlerThread localHandlerThread = new HandlerThread("UmsAgent");
    localHandlerThread.start();
    this.handler = new Handler(localHandlerThread.getLooper());
}