Java Code Examples for android.os.Handler#getLooper()

The following examples show how to use android.os.Handler#getLooper() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExtractorRendererBuilder.java    From AndroidTvDemo with Apache License 2.0 6 votes vote down vote up
@Override
public void buildRenderers(DemoPlayer player) {
  Allocator allocator = new DefaultAllocator(BUFFER_SEGMENT_SIZE);
  Handler mainHandler = player.getMainHandler();

  // Build the video and audio renderers.
  DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(mainHandler, null);
  DataSource dataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
  ExtractorSampleSource sampleSource = new ExtractorSampleSource(uri, dataSource, allocator,
      BUFFER_SEGMENT_COUNT * BUFFER_SEGMENT_SIZE, mainHandler, player, 0);
  MediaCodecVideoTrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(context,
      sampleSource, MediaCodecSelector.DEFAULT, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT, 5000,
      mainHandler, player, 50);
  MediaCodecAudioTrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource,
      MediaCodecSelector.DEFAULT, null, true, mainHandler, player,
      AudioCapabilities.getCapabilities(context), AudioManager.STREAM_MUSIC);
  TrackRenderer textRenderer = new TextTrackRenderer(sampleSource, player,
      mainHandler.getLooper());

  // Invoke the callback.
  TrackRenderer[] renderers = new TrackRenderer[DemoPlayer.RENDERER_COUNT];
  renderers[DemoPlayer.TYPE_VIDEO] = videoRenderer;
  renderers[DemoPlayer.TYPE_AUDIO] = audioRenderer;
  renderers[DemoPlayer.TYPE_TEXT] = textRenderer;
  player.onRenderers(renderers, bandwidthMeter);
}
 
Example 2
Source File: SurfaceView.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void runOnUiThread(Runnable runnable) {
    Handler handler = getHandler();
    if (handler != null && handler.getLooper() != Looper.myLooper()) {
        handler.post(runnable);
    } else {
        runnable.run();
    }
}
 
Example 3
Source File: MediaSourceEventListener.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void postOrRun(Handler handler, Runnable runnable) {
  if (handler.getLooper() == Looper.myLooper()) {
    runnable.run();
  } else {
    handler.post(runnable);
  }
}
 
Example 4
Source File: AppWebMessagePort.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void setMessageCallback(MessageCallback messageCallback, Handler handler) {
    if (isClosed() || isTransferred()) {
        throw new IllegalStateException("Port is already closed or transferred");
    }
    mStarted = true;
    synchronized (mLock) {
        mMessageCallback = messageCallback;
        if (handler != null) {
            mHandler = new MessageHandler(handler.getLooper());
        }
    }
    nativeStartReceivingMessages(mNativeAppWebMessagePort);
}
 
Example 5
Source File: IntentFirewall.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public IntentFirewall(AMSInterface ams, Handler handler) {
    mAms = ams;
    mHandler = new FirewallHandler(handler.getLooper());
    File rulesDir = getRulesDir();
    rulesDir.mkdirs();

    readRulesDir(rulesDir);

    mObserver = new RuleObserver(rulesDir);
    mObserver.startWatching();
}
 
Example 6
Source File: WifiDisplayAdapter.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public WifiDisplayAdapter(DisplayManagerService.SyncRoot syncRoot,
        Context context, Handler handler, Listener listener,
        PersistentDataStore persistentDataStore) {
    super(syncRoot, context, handler, listener, TAG);
    mHandler = new WifiDisplayHandler(handler.getLooper());
    mPersistentDataStore = persistentDataStore;
    mSupportsProtectedBuffers = context.getResources().getBoolean(
            com.android.internal.R.bool.config_wifiDisplaySupportsProtectedBuffers);
}
 
Example 7
Source File: InputManager.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public OnTabletModeChangedListenerDelegate(
        OnTabletModeChangedListener listener, Handler handler) {
    super(handler != null ? handler.getLooper() : Looper.myLooper());
    mListener = listener;
}
 
Example 8
Source File: DashRendererBuilder.java    From ShareBox with Apache License 2.0 4 votes vote down vote up
private void buildRenderers() {
  Period period = manifest.getPeriod(0);
  Handler mainHandler = player.getMainHandler();
  LoadControl loadControl = new DefaultLoadControl(new DefaultAllocator(BUFFER_SEGMENT_SIZE));
  DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(mainHandler, player);

  boolean hasContentProtection = false;
  for (int i = 0; i < period.adaptationSets.size(); i++) {
    AdaptationSet adaptationSet = period.adaptationSets.get(i);
    if (adaptationSet.type != AdaptationSet.TYPE_UNKNOWN) {
      hasContentProtection |= adaptationSet.hasContentProtection();
    }
  }

  // Check drm support if necessary.
  boolean filterHdContent = false;
  StreamingDrmSessionManager<FrameworkMediaCrypto> drmSessionManager = null;
  if (hasContentProtection) {
    if (Util.SDK_INT < 18) {
      player.onRenderersError(
          new UnsupportedDrmException(UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME));
      return;
    }
    try {
      drmSessionManager = StreamingDrmSessionManager.newWidevineInstance(
          player.getPlaybackLooper(), drmCallback, null, player.getMainHandler(), player);
      filterHdContent = getWidevineSecurityLevel(drmSessionManager) != SECURITY_LEVEL_1;
    } catch (UnsupportedDrmException e) {
      player.onRenderersError(e);
      return;
    }
  }

  // Build the video renderer.
  DataSource videoDataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
  ChunkSource videoChunkSource = new DashChunkSource(manifestFetcher,
      DefaultDashTrackSelector.newVideoInstance(context, true, filterHdContent),
      videoDataSource, new AdaptiveEvaluator(bandwidthMeter), LIVE_EDGE_LATENCY_MS,
      elapsedRealtimeOffset, mainHandler, player, DemoPlayer.TYPE_VIDEO);
  ChunkSampleSource videoSampleSource = new ChunkSampleSource(videoChunkSource, loadControl,
      VIDEO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
      DemoPlayer.TYPE_VIDEO);
  TrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(context, videoSampleSource,
      MediaCodecSelector.DEFAULT, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT, 5000,
      drmSessionManager, true, mainHandler, player, 50);

  // Build the audio renderer.
  DataSource audioDataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
  ChunkSource audioChunkSource = new DashChunkSource(manifestFetcher,
      DefaultDashTrackSelector.newAudioInstance(), audioDataSource, null, LIVE_EDGE_LATENCY_MS,
      elapsedRealtimeOffset, mainHandler, player, DemoPlayer.TYPE_AUDIO);
  ChunkSampleSource audioSampleSource = new ChunkSampleSource(audioChunkSource, loadControl,
      AUDIO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
      DemoPlayer.TYPE_AUDIO);
  TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(audioSampleSource,
      MediaCodecSelector.DEFAULT, drmSessionManager, true, mainHandler, player,
      AudioCapabilities.getCapabilities(context), AudioManager.STREAM_MUSIC);

  // Build the text renderer.
  DataSource textDataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
  ChunkSource textChunkSource = new DashChunkSource(manifestFetcher,
      DefaultDashTrackSelector.newTextInstance(), textDataSource, null, LIVE_EDGE_LATENCY_MS,
      elapsedRealtimeOffset, mainHandler, player, DemoPlayer.TYPE_TEXT);
  ChunkSampleSource textSampleSource = new ChunkSampleSource(textChunkSource, loadControl,
      TEXT_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
      DemoPlayer.TYPE_TEXT);
  TrackRenderer textRenderer = new TextTrackRenderer(textSampleSource, player,
      mainHandler.getLooper());

  // Invoke the callback.
  TrackRenderer[] renderers = new TrackRenderer[DemoPlayer.RENDERER_COUNT];
  renderers[DemoPlayer.TYPE_VIDEO] = videoRenderer;
  renderers[DemoPlayer.TYPE_AUDIO] = audioRenderer;
  renderers[DemoPlayer.TYPE_TEXT] = textRenderer;
  player.onRenderers(renderers, bandwidthMeter);
}
 
Example 9
Source File: GestureDetectorCompat.java    From guideshow with MIT License 4 votes vote down vote up
GestureHandler(Handler handler) {
    super(handler.getLooper());
}
 
Example 10
Source File: DashRendererBuilder.java    From androidtv-sample-inputs with Apache License 2.0 4 votes vote down vote up
private void buildRenderers() {
    Period period = manifest.getPeriod(0);
    Handler mainHandler = player.getMainHandler();
    LoadControl loadControl = new DefaultLoadControl(new DefaultAllocator(
            BUFFER_SEGMENT_SIZE));
    DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(mainHandler, player);

    boolean hasContentProtection = false;
    for (int i = 0; i < period.adaptationSets.size(); i++) {
        AdaptationSet adaptationSet = period.adaptationSets.get(i);
        if (adaptationSet.type != AdaptationSet.TYPE_UNKNOWN) {
            hasContentProtection |= adaptationSet.hasContentProtection();
        }
    }

    // Check drm support if necessary.
    boolean filterHdContent = false;
    StreamingDrmSessionManager drmSessionManager = null;
    if (hasContentProtection) {
        if (Util.SDK_INT < 18) {
            player.onRenderersError(
                    new UnsupportedDrmException(
                            UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME));
            return;
        }
        try {
            drmSessionManager = StreamingDrmSessionManager.newWidevineInstance(
                    player.getPlaybackLooper(), drmCallback, null, player.getMainHandler(),
                    player);
            filterHdContent =
                    getWidevineSecurityLevel(drmSessionManager) != SECURITY_LEVEL_1;
        } catch (UnsupportedDrmException e) {
            player.onRenderersError(e);
            return;
        }
    }

    // Build the video renderer.
    DataSource videoDataSource =
            new DefaultUriDataSource(context, bandwidthMeter, userAgent);
    ChunkSource videoChunkSource = new DashChunkSource(manifestFetcher,
            DefaultDashTrackSelector.newVideoInstance(context, true, filterHdContent),
            videoDataSource, new AdaptiveEvaluator(bandwidthMeter), LIVE_EDGE_LATENCY_MS,
            elapsedRealtimeOffset, mainHandler, player, DemoPlayer.TYPE_VIDEO);
    ChunkSampleSource videoSampleSource =
            new ChunkSampleSource(videoChunkSource, loadControl,
                    VIDEO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
                    DemoPlayer.TYPE_VIDEO);
    TrackRenderer videoRenderer =
            new MediaCodecVideoTrackRenderer(context, videoSampleSource,
                    MediaCodecSelector.DEFAULT, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT,
                    5000,
                    drmSessionManager, true, mainHandler, player, 50);

    // Build the audio renderer.
    DataSource audioDataSource =
            new DefaultUriDataSource(context, bandwidthMeter, userAgent);
    ChunkSource audioChunkSource = new DashChunkSource(manifestFetcher,
            DefaultDashTrackSelector.newAudioInstance(), audioDataSource, null,
            LIVE_EDGE_LATENCY_MS,
            elapsedRealtimeOffset, mainHandler, player, DemoPlayer.TYPE_AUDIO);
    ChunkSampleSource audioSampleSource =
            new ChunkSampleSource(audioChunkSource, loadControl,
                    AUDIO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
                    DemoPlayer.TYPE_AUDIO);
    TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(audioSampleSource,
            MediaCodecSelector.DEFAULT, drmSessionManager, true, mainHandler, player,
            AudioCapabilities.getCapabilities(context), AudioManager.STREAM_MUSIC);

    // Build the text renderer.
    DataSource textDataSource =
            new DefaultUriDataSource(context, bandwidthMeter, userAgent);
    ChunkSource textChunkSource = new DashChunkSource(manifestFetcher,
            DefaultDashTrackSelector.newTextInstance(), textDataSource, null,
            LIVE_EDGE_LATENCY_MS,
            elapsedRealtimeOffset, mainHandler, player, DemoPlayer.TYPE_TEXT);
    ChunkSampleSource textSampleSource = new ChunkSampleSource(textChunkSource, loadControl,
            TEXT_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
            DemoPlayer.TYPE_TEXT);
    TrackRenderer textRenderer = new TextTrackRenderer(textSampleSource, player,
            mainHandler.getLooper());

    // Invoke the callback.
    TrackRenderer[] renderers = new TrackRenderer[DemoPlayer.RENDERER_COUNT];
    renderers[DemoPlayer.TYPE_VIDEO] = videoRenderer;
    renderers[DemoPlayer.TYPE_AUDIO] = audioRenderer;
    renderers[DemoPlayer.TYPE_TEXT] = textRenderer;
    player.onRenderers(renderers, bandwidthMeter);
}
 
Example 11
Source File: VoiceInteractionSession.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public VoiceInteractionSession(Context context, Handler handler) {
    mContext = context;
    mHandlerCaller = new HandlerCaller(context, handler.getLooper(),
            mCallbacks, true);
}
 
Example 12
Source File: GestureDetectorCompat.java    From letv with Apache License 2.0 4 votes vote down vote up
GestureHandler(Handler handler) {
    super(handler.getLooper());
}
 
Example 13
Source File: MediaControllerCompat.java    From letv with Apache License 2.0 4 votes vote down vote up
private void setHandler(Handler handler) {
    this.mHandler = new MessageHandler(handler.getLooper());
}
 
Example 14
Source File: HlsRendererBuilder.java    From WliveTV with Apache License 2.0 4 votes vote down vote up
@Override
public void onSingleManifest(HlsPlaylist manifest) {
  if (canceled) {
    return;
  }

  Handler mainHandler = player.getMainHandler();
  LoadControl loadControl = new DefaultLoadControl(new DefaultAllocator(BUFFER_SEGMENT_SIZE));
  DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();

  int[] variantIndices = null;
  if (manifest instanceof HlsMasterPlaylist) {
    HlsMasterPlaylist masterPlaylist = (HlsMasterPlaylist) manifest;
    try {
      variantIndices = VideoFormatSelectorUtil.selectVideoFormatsForDefaultDisplay(
          context, masterPlaylist.variants, null, false);
    } catch (DecoderQueryException e) {
      player.onRenderersError(e);
      return;
    }
    if (variantIndices.length == 0) {
      player.onRenderersError(new IllegalStateException("No variants selected."));
      return;
    }
  }

  DataSource dataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
  HlsChunkSource chunkSource = new HlsChunkSource(dataSource, url, manifest, bandwidthMeter,
      variantIndices, HlsChunkSource.ADAPTIVE_MODE_SPLICE);
  HlsSampleSource sampleSource = new HlsSampleSource(chunkSource, loadControl,
      BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player, DemoPlayer.TYPE_VIDEO);
  MediaCodecVideoTrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(context,
      sampleSource, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT, 5000, mainHandler, player, 50);
  MediaCodecAudioTrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource,
      null, true, player.getMainHandler(), player, AudioCapabilities.getCapabilities(context));
  MetadataTrackRenderer<Map<String, Object>> id3Renderer = new MetadataTrackRenderer<>(
      sampleSource, new Id3Parser(), player, mainHandler.getLooper());
  Eia608TrackRenderer closedCaptionRenderer = new Eia608TrackRenderer(sampleSource, player,
      mainHandler.getLooper());

  TrackRenderer[] renderers = new TrackRenderer[DemoPlayer.RENDERER_COUNT];
  renderers[DemoPlayer.TYPE_VIDEO] = videoRenderer;
  renderers[DemoPlayer.TYPE_AUDIO] = audioRenderer;
  renderers[DemoPlayer.TYPE_METADATA] = id3Renderer;
  renderers[DemoPlayer.TYPE_TEXT] = closedCaptionRenderer;
  player.onRenderers(renderers, bandwidthMeter);
}
 
Example 15
Source File: SmoothStreamingRendererBuilder.java    From ShareBox with Apache License 2.0 4 votes vote down vote up
@Override
public void onSingleManifest(SmoothStreamingManifest manifest) {
  if (canceled) {
    return;
  }

  Handler mainHandler = player.getMainHandler();
  LoadControl loadControl = new DefaultLoadControl(new DefaultAllocator(BUFFER_SEGMENT_SIZE));
  DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(mainHandler, player);

  // Check drm support if necessary.
  DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = null;
  if (manifest.protectionElement != null) {
    if (Util.SDK_INT < 18) {
      player.onRenderersError(
          new UnsupportedDrmException(UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME));
      return;
    }
    try {
      drmSessionManager = StreamingDrmSessionManager.newFrameworkInstance(
          manifest.protectionElement.uuid, player.getPlaybackLooper(), drmCallback, null,
          player.getMainHandler(), player);
    } catch (UnsupportedDrmException e) {
      player.onRenderersError(e);
      return;
    }
  }

  // Build the video renderer.
  DataSource videoDataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
  ChunkSource videoChunkSource = new SmoothStreamingChunkSource(manifestFetcher,
      DefaultSmoothStreamingTrackSelector.newVideoInstance(context, true, false),
      videoDataSource, new AdaptiveEvaluator(bandwidthMeter), LIVE_EDGE_LATENCY_MS);
  ChunkSampleSource videoSampleSource = new ChunkSampleSource(videoChunkSource, loadControl,
      VIDEO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
      DemoPlayer.TYPE_VIDEO);
  TrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(context, videoSampleSource,
      MediaCodecSelector.DEFAULT, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT, 5000,
      drmSessionManager, true, mainHandler, player, 50);

  // Build the audio renderer.
  DataSource audioDataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
  ChunkSource audioChunkSource = new SmoothStreamingChunkSource(manifestFetcher,
      DefaultSmoothStreamingTrackSelector.newAudioInstance(),
      audioDataSource, null, LIVE_EDGE_LATENCY_MS);
  ChunkSampleSource audioSampleSource = new ChunkSampleSource(audioChunkSource, loadControl,
      AUDIO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
      DemoPlayer.TYPE_AUDIO);
  TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(audioSampleSource,
      MediaCodecSelector.DEFAULT, drmSessionManager, true, mainHandler, player,
      AudioCapabilities.getCapabilities(context), AudioManager.STREAM_MUSIC);

  // Build the text renderer.
  DataSource textDataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
  ChunkSource textChunkSource = new SmoothStreamingChunkSource(manifestFetcher,
      DefaultSmoothStreamingTrackSelector.newTextInstance(),
      textDataSource, null, LIVE_EDGE_LATENCY_MS);
  ChunkSampleSource textSampleSource = new ChunkSampleSource(textChunkSource, loadControl,
      TEXT_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
      DemoPlayer.TYPE_TEXT);
  TrackRenderer textRenderer = new TextTrackRenderer(textSampleSource, player,
      mainHandler.getLooper());

  // Invoke the callback.
  TrackRenderer[] renderers = new TrackRenderer[DemoPlayer.RENDERER_COUNT];
  renderers[DemoPlayer.TYPE_VIDEO] = videoRenderer;
  renderers[DemoPlayer.TYPE_AUDIO] = audioRenderer;
  renderers[DemoPlayer.TYPE_TEXT] = textRenderer;
  player.onRenderers(renderers, bandwidthMeter);
}
 
Example 16
Source File: GestureDetectorCompat.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
GestureHandler(Handler handler) {
    super(handler.getLooper());
}
 
Example 17
Source File: SoundTriggerModule.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
NativeEventHandlerDelegate(final SoundTrigger.StatusListener listener,
                           Handler handler) {
    // find the looper for our new event handler
    Looper looper;
    if (handler != null) {
        looper = handler.getLooper();
    } else {
        looper = Looper.getMainLooper();
    }

    // construct the event handler with this looper
    if (looper != null) {
        // implement the event handler delegate
        mHandler = new Handler(looper) {
            @Override
            public void handleMessage(Message msg) {
                switch(msg.what) {
                case EVENT_RECOGNITION:
                    if (listener != null) {
                        listener.onRecognition(
                                (SoundTrigger.RecognitionEvent)msg.obj);
                    }
                    break;
                case EVENT_SOUNDMODEL:
                    if (listener != null) {
                        listener.onSoundModelUpdate(
                                (SoundTrigger.SoundModelEvent)msg.obj);
                    }
                    break;
                case EVENT_SERVICE_STATE_CHANGE:
                    if (listener != null) {
                        listener.onServiceStateChange(msg.arg1);
                    }
                    break;
                case EVENT_SERVICE_DIED:
                    if (listener != null) {
                        listener.onServiceDied();
                    }
                    break;
                default:
                    break;
                }
            }
        };
    } else {
        mHandler = null;
    }
}
 
Example 18
Source File: BlockingCameraManager.java    From Camera2 with Apache License 2.0 3 votes vote down vote up
/**
 * Open the camera, blocking it until it succeeds or fails.
 *
 * <p>Note that the Handler provided must not be null. Furthermore, if there is a handler,
 * its Looper must not be the current thread's Looper. Otherwise we'd never receive
 * the callbacks from the CameraDevice since this function would prevent them from being
 * processed.</p>
 *
 * <p>Throws {@link CameraAccessException} for the same reason {@link CameraManager#openCamera}
 * does.</p>
 *
 * <p>Throws {@link BlockingOpenException} when the open fails asynchronously (due to
 * {@link CameraDevice.StateCallback#onDisconnected(CameraDevice)} or
 * ({@link CameraDevice.StateCallback#onError(CameraDevice)}.</p>
 *
 * <p>Throws {@link TimeoutRuntimeException} if opening times out. This is usually
 * highly unrecoverable, and all future calls to opening that camera will fail since the
 * service will think it's busy. This class will do its best to clean up eventually.</p>
 *
 * @param cameraId
 *            Id of the camera
 * @param listener
 *            Listener to the camera. onOpened, onDisconnected, onError need not be implemented.
 * @param handler
 *            Handler which to run the listener on. Must not be null.
 *
 * @return CameraDevice
 *
 * @throws IllegalArgumentException
 *            If the handler is null, or if the handler's looper is current.
 * @throws CameraAccessException
 *            If open fails immediately.
 * @throws BlockingOpenException
 *            If open fails after blocking for some amount of time.
 * @throws TimeoutRuntimeException
 *            If opening times out. Typically unrecoverable.
 */
public CameraDevice openCamera(String cameraId, CameraDevice.StateCallback listener,
        Handler handler) throws CameraAccessException, BlockingOpenException {

    if (handler == null) {
        throw new IllegalArgumentException("handler must not be null");
    } else if (handler.getLooper() == Looper.myLooper()) {
        throw new IllegalArgumentException("handler's looper must not be the current looper");
    }

    return (new OpenListener(mManager, cameraId, listener, handler)).blockUntilOpen();
}
 
Example 19
Source File: HandlerUtil.java    From weex with Apache License 2.0 2 votes vote down vote up
/**
 * Checks whether the current thread is the same thread that the {@link Handler} is associated
 * with.
 * @return true if the current thread is the same thread that the {@link Handler} is associated
 * with; otherwise false.
 */
public static boolean checkThreadAccess(Handler handler) {
  return Looper.myLooper() == handler.getLooper();
}
 
Example 20
Source File: ThreadUtils.java    From xdroid with Apache License 2.0 2 votes vote down vote up
/**
 * Creates new {@link Handler} with the same {@link Looper} as the original handler.
 *
 * @param original original handler, can not be null
 * @param callback message handling callback, may be null
 * @return new instance
 */
public static Handler newHandler(Handler original, Handler.Callback callback) {
    return new Handler(original.getLooper(), callback);
}