當前位置: 首頁>>代碼示例>>Java>>正文


Java HandlerThread類代碼示例

本文整理匯總了Java中android.os.HandlerThread的典型用法代碼示例。如果您正苦於以下問題:Java HandlerThread類的具體用法?Java HandlerThread怎麽用?Java HandlerThread使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HandlerThread類屬於android.os包,在下文中一共展示了HandlerThread類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: WebRTCModule

import android.os.HandlerThread; //導入依賴的package包/類
public WebRTCModule(ReactApplicationContext reactContext) {
    super(reactContext);

    imageProcessingThread = new HandlerThread("PictureProcessing");
    imageProcessingThread.start();
    imagePorcessingHandler = new Handler(imageProcessingThread.getLooper());

    mPeerConnectionObservers = new SparseArray<PeerConnectionObserver>();
    mMediaStreams = new HashMap<String, MediaStream>();
    mMediaStreamTracks = new HashMap<String, MediaStreamTrack>();
    mVideoCapturers = new HashMap<String, VideoCapturer>();
    mCameras = new HashMap<>();

    pcConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveAudio", "true"));
    pcConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveVideo", "true"));
    pcConstraints.optional.add(new MediaConstraints.KeyValuePair("DtlsSrtpKeyAgreement", "true"));

    PeerConnectionFactory.initializeAndroidGlobals(reactContext, true, true, true);
    mFactory = new PeerConnectionFactory();
}
 
開發者ID:angellsl10,項目名稱:react-native-webrtc,代碼行數:21,代碼來源:WebRTCModule.java

示例2: stopDraw

import android.os.HandlerThread; //導入依賴的package包/類
private void stopDraw() {
    DrawHandler handler = this.handler;
    this.handler = null;
    unlockCanvasAndPost();
    if (handler != null) {
        handler.quit();
    }
    if (this.mHandlerThread != null) {
        HandlerThread handlerThread = this.mHandlerThread;
        this.mHandlerThread = null;
        try {
            handlerThread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        handlerThread.quit();
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:19,代碼來源:DanmakuView.java

示例3: init

import android.os.HandlerThread; //導入依賴的package包/類
private void init() {
    if (isAndroidThingsDevice(this)) {
        initPIO();
    }

    mBackgroundThread = new HandlerThread("BackgroundThread");
    mBackgroundThread.start();
    mBackgroundHandler = new Handler(mBackgroundThread.getLooper());
    mBackgroundHandler.post(mInitializeOnBackground);

    // Let the user touch the screen to take a photo
    findViewById(R.id.container).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mReady.get()) {
                Log.i(TAG, "Taking photo");
                setReady(false);
                mBackgroundHandler.post(mBackgroundClickHandler);
            } else {
                Log.i(TAG, "Sorry, processing hasn't finished. Try again in a few seconds");
            }
        }
    });
}
 
開發者ID:androidthings,項目名稱:sample-tensorflow-imageclassifier,代碼行數:25,代碼來源:ImageClassifierActivity.java

示例4: stopDraw

import android.os.HandlerThread; //導入依賴的package包/類
private void stopDraw() {
    if (this.handler != null) {
        this.handler.quit();
        this.handler = null;
    }
    if (this.mHandlerThread != null) {
        HandlerThread handlerThread = this.mHandlerThread;
        this.mHandlerThread = null;
        try {
            handlerThread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        handlerThread.quit();
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:17,代碼來源:DanmakuTextureView.java

示例5: onCreate

import android.os.HandlerThread; //導入依賴的package包/類
@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

    setContentView(R.layout.scan_activity);
    scannerView = (ScannerView) findViewById(R.id.scan_activity_mask);
    previewView = (TextureView) findViewById(R.id.scan_activity_preview);
    previewView.setSurfaceTextureListener(this);

    cameraThread = new HandlerThread("cameraThread", Process.THREAD_PRIORITY_BACKGROUND);
    cameraThread.start();
    cameraHandler = new Handler(cameraThread.getLooper());

    if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED)
        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.CAMERA }, 0);
}
 
開發者ID:guodroid,項目名稱:okwallet,代碼行數:19,代碼來源:ScanActivity.java

示例6: onCreate

import android.os.HandlerThread; //導入依賴的package包/類
@Override
public void onCreate() {
    super.onCreate();
    mHandlerThread = new HandlerThread(getClass().getSimpleName());
    mHandlerThread.start();
    mDbHandler = new Handler(mHandlerThread.getLooper());
    mCaptioningManager = (CaptioningManager) getSystemService(Context.CAPTIONING_SERVICE);

    setTheme(android.R.style.Theme_Holo_Light_NoActionBar);

    mSessions = new ArrayList<>();
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(TvInputManager.ACTION_BLOCKED_RATINGS_CHANGED);
    intentFilter.addAction(TvInputManager.ACTION_PARENTAL_CONTROLS_ENABLED_CHANGED);
    registerReceiver(mParentalControlsBroadcastReceiver, intentFilter);
}
 
開發者ID:nejtv,項目名稱:androidtv-sample,代碼行數:17,代碼來源:RichTvInputService.java

示例7: startBackgroundThread

import android.os.HandlerThread; //導入依賴的package包/類
/**
 * Starts a background thread and its {@link Handler}.
 */
private void startBackgroundThread() {
    mBackgroundThread = new HandlerThread("CameraBackground");
    mBackgroundThread.start();
    mBackgroundHandler = new Handler(mBackgroundThread.getLooper()) {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case MSG_CAPTURE_PICTURE_WHEN_FOCUS_TIMEOUT:
                    mState = STATE_PICTURE_TAKEN;
                    captureStillPicture();
                    break;
                default:
                    break;
            }

        }
    };
}
 
開發者ID:lytcom,項目名稱:CameraKitView,代碼行數:23,代碼來源:Camera2Fragment.java

示例8: a

import android.os.HandlerThread; //導入依賴的package包/類
public a(int i, boolean z, h hVar, b bVar) {
    super(i, z, hVar);
    this.i = false;
    a(bVar);
    this.e = new g();
    this.f = new g();
    this.g = this.e;
    this.h = this.f;
    this.d = new char[bVar.f()];
    bVar.b();
    g();
    this.j = new HandlerThread(bVar.c(), bVar.h());
    if (this.j != null) {
        this.j.start();
    }
    if (this.j.isAlive() && this.j.getLooper() != null) {
        this.k = new Handler(this.j.getLooper(), this);
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:20,代碼來源:a.java

示例9: open

import android.os.HandlerThread; //導入依賴的package包/類
public void open() {
    try {
        CameraManager manager = (CameraManager) mActivity.getSystemService(Context.CAMERA_SERVICE);
        for (String cameraId : manager.getCameraIdList()) {
            CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);
            if (characteristics.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_BACK) {
                StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
                mCameraSize = map.getOutputSizes(SurfaceTexture.class)[0];

                HandlerThread thread = new HandlerThread("OpenCamera");
                thread.start();
                Handler backgroundHandler = new Handler(thread.getLooper());

                manager.openCamera(cameraId, mCameraDeviceCallback, null);

                // カメラの物理的な情報を得る
                mCameraCharacteristics = manager.getCameraCharacteristics( cameraId );
                return;
            }
        }
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
開發者ID:jphacks,項目名稱:TK_1701,代碼行數:25,代碼來源:Camera2.java

示例10: UltrasonicSensorDriver

import android.os.HandlerThread; //導入依賴的package包/類
/**
 * Public constructor.
 *
 * @param triggerPin Name of the trigger pin
 * @param echoPin    Name of the echo pin
 * @param listener   {@link DistanceListener} to get callbacks when distance changes.
 */
public UltrasonicSensorDriver(@NonNull String triggerPin, @NonNull String echoPin, DistanceListener listener) {
    PeripheralManagerService service = new PeripheralManagerService();

    try {
        setTriggerPin(service, triggerPin);
        setEchoPin(service, echoPin);
    } catch (IOException e) {
        e.printStackTrace();
        throw new IllegalArgumentException("Invalid pin name.");
    }

    //Set callback listener.
    mListener = listener;
    if (mListener == null)
        throw new IllegalArgumentException("DistanceListener cannot be null.");

    //Start sending pulses
    //We are using different thread for sending pulses to increase time accuracy.
    HandlerThread triggerHandlerThread = new HandlerThread("TriggerHandlerThread");
    triggerHandlerThread.start();
    mTriggerHandler = new Handler(triggerHandlerThread.getLooper());
    mTriggerHandler.post(mTriggerRunnable);
}
 
開發者ID:kevalpatel2106,項目名稱:collision-detector-android-things,代碼行數:31,代碼來源:UltrasonicSensorDriver.java

示例11: onCreate

import android.os.HandlerThread; //導入依賴的package包/類
@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();

    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    mNotificationMap = new SparseIntArray();

    // Get the HandlerThread's Looper and use it for our Handler
    mServiceLooper = thread.getLooper();
    //mServiceHandler = new ServiceHandler(mServiceLooper);
    mServiceHandler = new ServiceHandler(mServiceLooper, this);
    setPrefs(PreferenceManager.getDefaultSharedPreferences(this));
}
 
開發者ID:SalmanTKhan,項目名稱:MyAnimeViewer,代碼行數:20,代碼來源:ManualAnimeUpdaterService.java

示例12: onCreate

import android.os.HandlerThread; //導入依賴的package包/類
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.zcps = getSharedPreferences("reg", 0);
    setContentView(R.layout.activity_main);
    findView();
    this.shouquanqqTextView.setText("正版注冊授權QQ:" + getString(R.string.zhuceqq));
    getPrefparas();
    showPrefparas();
    startService(new Intent(this, PhoneService.class));
    this.startLayout.setVisibility(View.VISIBLE);
    new HandlerThread("myHandlerThread").start();
    this.handler = new Handler() {
        public void handleMessage(Message msg) {
            if (msg.what == 0) {
                MainActivity.this.startLayout.setVisibility(View.INVISIBLE);
                MainActivity.this.gonggaoLayout.setVisibility(View.VISIBLE);
                MainActivity.this.mainlLayout.setVisibility(View.INVISIBLE);
            }
        }
    };
    this.tt.run();
}
 
開發者ID:JamesLiAndroid,項目名稱:AndroidKillerService,代碼行數:23,代碼來源:MainActivity.java

示例13: d

import android.os.HandlerThread; //導入依賴的package包/類
private d() {
    try {
        HandlerThread handlerThread = new HandlerThread("StatDispatcher");
        handlerThread.start();
        d = handlerThread.getId();
        this.b = new Handler(handlerThread.getLooper());
        HttpParams basicHttpParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(basicHttpParams, 10000);
        HttpConnectionParams.setSoTimeout(basicHttpParams, 10000);
        this.a = new DefaultHttpClient(basicHttpParams);
        this.a.setKeepAliveStrategy(new e(this));
        if (StatConfig.b() != null) {
            this.a.getParams().setParameter("http.route.default-proxy", StatConfig.b());
        }
    } catch (Object th) {
        c.e(th);
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:19,代碼來源:d.java

示例14: LCIMLocalStorage

import android.os.HandlerThread; //導入依賴的package包/類
public LCIMLocalStorage(Context context, String clientId, String tableName) {
  super(context, DB_NAME_PREFIX, null, DB_VERSION);

  if (TextUtils.isEmpty(tableName)) {
    throw new IllegalArgumentException("tableName can not be null");
  }
  if (TextUtils.isEmpty(clientId)) {
    throw new IllegalArgumentException("clientId can not be null");
  }

  final String md5ClientId = AVUtils.md5(clientId);
  this.tableName = tableName + "_" + md5ClientId;

  createTable();

  readDbThread = new HandlerThread("LCIMLocalStorageReadThread");
  readDbThread.start();
  readDbHandler = new Handler(readDbThread.getLooper());
}
 
開發者ID:linsir6,項目名稱:TripBuyer,代碼行數:20,代碼來源:LCIMLocalStorage.java

示例15: onCreate

import android.os.HandlerThread; //導入依賴的package包/類
@Override
public void onCreate() {
    super.onCreate();
    log("onCreate");

    // First init the Client
    Application application = getApplication();
    if (application instanceof OSCApplication) {
        OSCApplication.reInit();
    }

    HandlerThread thread = new HandlerThread(TweetPublishService.class.getSimpleName());
    thread.start();

    mServiceLooper = thread.getLooper();
    mServiceHandler = new ServiceHandler(mServiceLooper);
    mReceiver = ListenAccountChangeReceiver.start(this);
}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:19,代碼來源:TweetPublishService.java


注:本文中的android.os.HandlerThread類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。