Example usage for android.os HandlerThread getLooper

List of usage examples for android.os HandlerThread getLooper

Introduction

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

Prototype

public Looper getLooper() 

Source Link

Document

This method returns the Looper associated with this thread.

Usage

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();/*from  w ww.  j  av  a 2  s  .c  o m*/

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

From source file:com.nolanlawson.cordova.sqlite.SQLitePlugin.java

private Handler createBackgroundHandler() {
    HandlerThread thread = new HandlerThread("SQLitePlugin BG Thread");
    thread.start();/*from ww w .ja  v a 2  s .co m*/
    return new Handler(thread.getLooper());
}

From source file:com.google.android.gms.location.sample.locationupdatesforegroundservice.LocationUpdatesService.java

@Override
public void onCreate() {
    mGoogleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this).addApi(LocationServices.API).build();
    mGoogleApiClient.connect();// w w w.  j ava 2 s  . co  m
    createLocationRequest();

    HandlerThread handlerThread = new HandlerThread(TAG);
    handlerThread.start();
    mServiceHandler = new Handler(handlerThread.getLooper());
    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
}

From source file:MainActivity.java

protected void takePicture(View view) {
    if (null == mCameraDevice) {
        return;/*www.  j  a  v  a 2s.c  o  m*/
    }
    CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
    try {
        CameraCharacteristics characteristics = manager.getCameraCharacteristics(mCameraDevice.getId());
        StreamConfigurationMap configurationMap = characteristics
                .get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
        if (configurationMap == null)
            return;
        Size largest = Collections.max(Arrays.asList(configurationMap.getOutputSizes(ImageFormat.JPEG)),
                new CompareSizesByArea());
        ImageReader reader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(), ImageFormat.JPEG,
                1);
        List<Surface> outputSurfaces = new ArrayList<Surface>(2);
        outputSurfaces.add(reader.getSurface());
        outputSurfaces.add(new Surface(mTextureView.getSurfaceTexture()));
        final CaptureRequest.Builder captureBuilder = mCameraDevice
                .createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
        captureBuilder.addTarget(reader.getSurface());
        captureBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
        ImageReader.OnImageAvailableListener readerListener = new ImageReader.OnImageAvailableListener() {
            @Override
            public void onImageAvailable(ImageReader reader) {
                Image image = null;
                try {
                    image = reader.acquireLatestImage();
                    ByteBuffer buffer = image.getPlanes()[0].getBuffer();
                    byte[] bytes = new byte[buffer.capacity()];
                    buffer.get(bytes);
                    OutputStream output = new FileOutputStream(getPictureFile());
                    output.write(bytes);
                    output.close();
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    if (image != null) {
                        image.close();
                    }
                }
            }
        };
        HandlerThread thread = new HandlerThread("CameraPicture");
        thread.start();
        final Handler backgroudHandler = new Handler(thread.getLooper());
        reader.setOnImageAvailableListener(readerListener, backgroudHandler);
        final CameraCaptureSession.CaptureCallback captureCallback = new CameraCaptureSession.CaptureCallback() {
            @Override
            public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request,
                    TotalCaptureResult result) {
                super.onCaptureCompleted(session, request, result);
                Toast.makeText(MainActivity.this, "Picture Saved", Toast.LENGTH_SHORT).show();
                startPreview(session);
            }
        };
        mCameraDevice.createCaptureSession(outputSurfaces, new CameraCaptureSession.StateCallback() {
            @Override
            public void onConfigured(CameraCaptureSession session) {
                try {
                    session.capture(captureBuilder.build(), captureCallback, backgroudHandler);
                } catch (CameraAccessException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onConfigureFailed(CameraCaptureSession session) {
            }
        }, backgroudHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

From source file:org.teleportr.ConnectorService.java

@Override
public void onCreate() {
    HandlerThread thread = new HandlerThread(WORKER);
    thread.start();/*from w w  w  .  ja v  a 2  s. co m*/
    worker = new Handler(thread.getLooper());
    reporter = new Handler();
    try {
        fahrgemeinschaft = (Connector) Class.forName(FAHRGEMEINSCHAFT).newInstance();
        fahrgemeinschaft.setContext(this);
        gplaces = (Connector) Class.forName(GPLACES).newInstance();
        gplaces.setContext(this);
    } catch (Exception e) {
        e.printStackTrace();
    }
    search = new Search(getContext());
    resolve = new Resolve(getContext());
    publish = new Publish(getContext());
    myrides = new Myrides(getContext());
    retries = new HashMap<Long, Integer>();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefs.registerOnSharedPreferenceChangeListener(this);
    onSharedPreferenceChanged(prefs, VERBOSE);
    cleanUp(prefs);
    super.onCreate();
}

From source file:com.cssweb.android.quote.DaPan.java

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

    HandlerThread mHandlerThread = new HandlerThread("CSSWEB_THREAD");
    mHandlerThread.start();//from www.  j a v a  2 s  . com
    mHandler = new MessageHandler(mHandlerThread.getLooper());

    this.activityKind = Global.QUOTE_DAPAN;

    setContentView(R.layout.zr_table);

    String[] toolbarname = new String[] { Global.TOOLBAR_MENU, Global.TOOLBAR_SHANGYE, Global.TOOLBAR_XIAYIYE,
            Global.TOOLBAR_REFRESH };

    initTitle(R.drawable.njzq_title_left_back, 0, "");
    initToolBar(toolbarname, Global.BAR_TAG);

    cols = getResources().getStringArray(R.array.index_cols);

    //????
    pageNum = CssSystem.getTablePageSize(mContext);
    rowHeight = CssSystem.getTableRowHeight(mContext);

    begin = 1;
    end = pageNum;
    allStockNums = StockInfo.getStockInfoSize(20);
    setToolBar(1, false, R.color.zr_newlightgray);
    init(2);
}

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  ww w . ja v a 2 s  .c  o  m

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

From source file:com.vk.sdk.payments.VKPaymentsServerSender.java

private VKPaymentsServerSender(@NonNull Context ctx) {
    mAppCtx = ctx;/*from w  w  w  . java  2s. c  om*/

    mCheckUserInstallAnswer = restoreAnswer(ctx);

    HandlerThread handlerThread = new HandlerThread(getClass().getName());
    handlerThread.start();
    mHandler = new Handler(handlerThread.getLooper());

    // !!! WARNING !!! this for wait reference url from vk client
    mHandler.post(new Runnable() {
        @Override
        public void run() {
            try {
                Thread.sleep(1000); // time for wait reference url
            } catch (Exception e) {
                // nothing
            }
        }
    });
}

From source file:ch.carteggio.provider.sync.NotificationService.java

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

    HandlerThread thread = new HandlerThread("NotificationService");
    thread.start();/* w  w w  .ja v  a2 s  .  co  m*/

    mServiceLooper = thread.getLooper();
    mServiceHandler = new ServiceHandler(mServiceLooper);

    mObserver = new Observer();

    getContentResolver().registerContentObserver(CarteggioContract.Messages.CONTENT_URI, true, mObserver);

}

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

@Override
public void onCreate() {
    HandlerThread thread = new HandlerThread("CalendarCopyService", HandlerThread.NORM_PRIORITY);
    thread.start();//from   ww w  . j  a  va 2s .  c  om

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

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