Java Code Examples for com.facebook.react.bridge.SoftAssertions

The following are top voted examples for showing how to use com.facebook.react.bridge.SoftAssertions. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: RNLearn_Project1   File: FlatViewGroup.java   View source code 6 votes vote down vote up
@Override
public int reactTagForTouch(float touchX, float touchY) {
  /*
   * Make sure we don't find any children if the pointer events are set to BOX_ONLY.
   * There is no need to special-case any other modes, because if PointerEvents are set to:
   * a) PointerEvents.AUTO - all children are included, nothing to exclude
   * b) PointerEvents.NONE - this method will NOT be executed, because the View will be filtered
   *    out by TouchTargetHelper.
   * c) PointerEvents.BOX_NONE - TouchTargetHelper will make sure that {@link #reactTagForTouch()}
   *     doesn't return getId().
   */
  SoftAssertions.assertCondition(
      mPointerEvents != PointerEvents.NONE,
      "TouchTargetHelper should not allow calling this method when pointer events are NONE");

  if (mPointerEvents != PointerEvents.BOX_ONLY) {
    NodeRegion nodeRegion = virtualNodeRegionWithinBounds(touchX, touchY);
    if (nodeRegion != null) {
      return nodeRegion.getReactTag(touchX, touchY);
    }
  }

  // no children found
  return getId();
}
 
Example 2
Project: RNLearn_Project1   File: UIViewOperationQueue.java   View source code 6 votes vote down vote up
public void addRootView(
    final int tag,
    final SizeMonitoringFrameLayout rootView,
    final ThemedReactContext themedRootContext) {
  if (UiThreadUtil.isOnUiThread()) {
    mNativeViewHierarchyManager.addRootView(tag, rootView, themedRootContext);
  } else {
    final Semaphore semaphore = new Semaphore(0);
    mReactApplicationContext.runOnUiQueueThread(
        new Runnable() {
          @Override
          public void run() {
            mNativeViewHierarchyManager.addRootView(tag, rootView, themedRootContext);
            semaphore.release();
          }
        });
    try {
      SoftAssertions.assertCondition(
          semaphore.tryAcquire(5000, TimeUnit.MILLISECONDS),
          "Timed out adding root view");
    } catch (InterruptedException e) {
      throw new RuntimeException(e);
    }
  }
}
 
Example 3
Project: RNLearn_Project1   File: NativeViewHierarchyManager.java   View source code 6 votes vote down vote up
public void setJSResponder(int reactTag, int initialReactTag, boolean blockNativeResponder) {
  if (!blockNativeResponder) {
    mJSResponderHandler.setJSResponder(initialReactTag, null);
    return;
  }

  View view = mTagsToViews.get(reactTag);
  if (initialReactTag != reactTag && view instanceof ViewParent) {
    // In this case, initialReactTag corresponds to a virtual/layout-only View, and we already
    // have a parent of that View in reactTag, so we can use it.
    mJSResponderHandler.setJSResponder(initialReactTag, (ViewParent) view);
    return;
  }

  if (mRootTags.get(reactTag)) {
    SoftAssertions.assertUnreachable(
        "Cannot block native responder on " + reactTag + " that is a root view");
  }
  mJSResponderHandler
      .setJSResponder(initialReactTag, view.getParent());
}
 
Example 4
Project: RNLearn_Project1   File: ReactIntegrationTestCase.java   View source code 6 votes vote down vote up
protected static void initializeJavaModule(final BaseJavaModule javaModule) {
  final Semaphore semaphore = new Semaphore(0);
  UiThreadUtil.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          javaModule.initialize();
          if (javaModule instanceof LifecycleEventListener) {
            ((LifecycleEventListener) javaModule).onHostResume();
          }
          semaphore.release();
        }
      });
  try {
    SoftAssertions.assertCondition(
        semaphore.tryAcquire(5000, TimeUnit.MILLISECONDS),
        "Timed out initializing timing module");
  } catch (InterruptedException e) {
    throw new RuntimeException(e);
  }
}
 
Example 5
Project: RNLearn_Project1   File: FlatViewGroup.java   View source code 6 votes vote down vote up
@Override
public int reactTagForTouch(float touchX, float touchY) {
  /*
   * Make sure we don't find any children if the pointer events are set to BOX_ONLY.
   * There is no need to special-case any other modes, because if PointerEvents are set to:
   * a) PointerEvents.AUTO - all children are included, nothing to exclude
   * b) PointerEvents.NONE - this method will NOT be executed, because the View will be filtered
   *    out by TouchTargetHelper.
   * c) PointerEvents.BOX_NONE - TouchTargetHelper will make sure that {@link #reactTagForTouch()}
   *     doesn't return getId().
   */
  SoftAssertions.assertCondition(
      mPointerEvents != PointerEvents.NONE,
      "TouchTargetHelper should not allow calling this method when pointer events are NONE");

  if (mPointerEvents != PointerEvents.BOX_ONLY) {
    NodeRegion nodeRegion = virtualNodeRegionWithinBounds(touchX, touchY);
    if (nodeRegion != null) {
      return nodeRegion.getReactTag(touchX, touchY);
    }
  }

  // no children found
  return getId();
}
 
Example 6
Project: RNLearn_Project1   File: UIViewOperationQueue.java   View source code 6 votes vote down vote up
public void addRootView(
    final int tag,
    final SizeMonitoringFrameLayout rootView,
    final ThemedReactContext themedRootContext) {
  if (UiThreadUtil.isOnUiThread()) {
    mNativeViewHierarchyManager.addRootView(tag, rootView, themedRootContext);
  } else {
    final Semaphore semaphore = new Semaphore(0);
    mReactApplicationContext.runOnUiQueueThread(
        new Runnable() {
          @Override
          public void run() {
            mNativeViewHierarchyManager.addRootView(tag, rootView, themedRootContext);
            semaphore.release();
          }
        });
    try {
      SoftAssertions.assertCondition(
          semaphore.tryAcquire(5000, TimeUnit.MILLISECONDS),
          "Timed out adding root view");
    } catch (InterruptedException e) {
      throw new RuntimeException(e);
    }
  }
}
 
Example 7
Project: RNLearn_Project1   File: NativeViewHierarchyManager.java   View source code 6 votes vote down vote up
public void setJSResponder(int reactTag, int initialReactTag, boolean blockNativeResponder) {
  if (!blockNativeResponder) {
    mJSResponderHandler.setJSResponder(initialReactTag, null);
    return;
  }

  View view = mTagsToViews.get(reactTag);
  if (initialReactTag != reactTag && view instanceof ViewParent) {
    // In this case, initialReactTag corresponds to a virtual/layout-only View, and we already
    // have a parent of that View in reactTag, so we can use it.
    mJSResponderHandler.setJSResponder(initialReactTag, (ViewParent) view);
    return;
  }

  if (mRootTags.get(reactTag)) {
    SoftAssertions.assertUnreachable(
        "Cannot block native responder on " + reactTag + " that is a root view");
  }
  mJSResponderHandler
      .setJSResponder(initialReactTag, view.getParent());
}
 
Example 8
Project: RNLearn_Project1   File: ReactIntegrationTestCase.java   View source code 6 votes vote down vote up
protected static void initializeJavaModule(final BaseJavaModule javaModule) {
  final Semaphore semaphore = new Semaphore(0);
  UiThreadUtil.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          javaModule.initialize();
          if (javaModule instanceof LifecycleEventListener) {
            ((LifecycleEventListener) javaModule).onHostResume();
          }
          semaphore.release();
        }
      });
  try {
    SoftAssertions.assertCondition(
        semaphore.tryAcquire(5000, TimeUnit.MILLISECONDS),
        "Timed out initializing timing module");
  } catch (InterruptedException e) {
    throw new RuntimeException(e);
  }
}
 
Example 9
Project: ReactNativeSignatureExample   File: UIViewOperationQueue.java   View source code 6 votes vote down vote up
public void addRootView(
    final int tag,
    final SizeMonitoringFrameLayout rootView,
    final ThemedReactContext themedRootContext) {
  if (UiThreadUtil.isOnUiThread()) {
    mNativeViewHierarchyManager.addRootView(tag, rootView, themedRootContext);
  } else {
    final Semaphore semaphore = new Semaphore(0);
    mReactApplicationContext.runOnUiQueueThread(
        new Runnable() {
          @Override
          public void run() {
            mNativeViewHierarchyManager.addRootView(tag, rootView, themedRootContext);
            semaphore.release();
          }
        });
    try {
      SoftAssertions.assertCondition(
          semaphore.tryAcquire(5000, TimeUnit.MILLISECONDS),
          "Timed out adding root view");
    } catch (InterruptedException e) {
      throw new RuntimeException(e);
    }
  }
}
 
Example 10
Project: ReactNativeSignatureExample   File: NativeViewHierarchyManager.java   View source code 6 votes vote down vote up
public void setJSResponder(int reactTag, int initialReactTag, boolean blockNativeResponder) {
  if (!blockNativeResponder) {
    mJSResponderHandler.setJSResponder(initialReactTag, null);
    return;
  }

  View view = mTagsToViews.get(reactTag);
  if (initialReactTag != reactTag && view instanceof ViewParent) {
    // In this case, initialReactTag corresponds to a virtual/layout-only View, and we already
    // have a parent of that View in reactTag, so we can use it.
    mJSResponderHandler.setJSResponder(initialReactTag, (ViewParent) view);
    return;
  }

  if (mRootTags.get(reactTag)) {
    SoftAssertions.assertUnreachable(
        "Cannot block native responder on " + reactTag + " that is a root view");
  }
  mJSResponderHandler
      .setJSResponder(initialReactTag, view.getParent());
}
 
Example 11
Project: ReactNativeSignatureExample   File: ReactIntegrationTestCase.java   View source code 6 votes vote down vote up
protected static void initializeJavaModule(final BaseJavaModule javaModule) {
  final Semaphore semaphore = new Semaphore(0);
  UiThreadUtil.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          javaModule.initialize();
          if (javaModule instanceof LifecycleEventListener) {
            ((LifecycleEventListener) javaModule).onHostResume();
          }
          semaphore.release();
        }
      });
  try {
    SoftAssertions.assertCondition(
        semaphore.tryAcquire(5000, TimeUnit.MILLISECONDS),
        "Timed out initializing timing module");
  } catch (InterruptedException e) {
    throw new RuntimeException(e);
  }
}
 
Example 12
Project: react-native-ibeacon-android   File: UIViewOperationQueue.java   View source code 6 votes vote down vote up
public void addRootView(
    final int tag,
    final SizeMonitoringFrameLayout rootView,
    final ThemedReactContext themedRootContext) {
  if (UiThreadUtil.isOnUiThread()) {
    mNativeViewHierarchyManager.addRootView(tag, rootView, themedRootContext);
  } else {
    final Semaphore semaphore = new Semaphore(0);
    mReactApplicationContext.runOnUiQueueThread(
        new Runnable() {
          @Override
          public void run() {
            mNativeViewHierarchyManager.addRootView(tag, rootView, themedRootContext);
            semaphore.release();
          }
        });
    try {
      SoftAssertions.assertCondition(
          semaphore.tryAcquire(5000, TimeUnit.MILLISECONDS),
          "Timed out adding root view");
    } catch (InterruptedException e) {
      throw new RuntimeException(e);
    }
  }
}
 
Example 13
Project: react-native-ibeacon-android   File: NativeViewHierarchyManager.java   View source code 6 votes vote down vote up
public void setJSResponder(int reactTag, int initialReactTag, boolean blockNativeResponder) {
  if (!blockNativeResponder) {
    mJSResponderHandler.setJSResponder(initialReactTag, null);
    return;
  }

  View view = mTagsToViews.get(reactTag);
  if (initialReactTag != reactTag && view instanceof ViewParent) {
    // In this case, initialReactTag corresponds to a virtual/layout-only View, and we already
    // have a parent of that View in reactTag, so we can use it.
    mJSResponderHandler.setJSResponder(initialReactTag, (ViewParent) view);
    return;
  }

  if (mRootTags.get(reactTag)) {
    SoftAssertions.assertUnreachable(
        "Cannot block native responder on " + reactTag + " that is a root view");
  }
  mJSResponderHandler
      .setJSResponder(initialReactTag, view.getParent());
}
 
Example 14
Project: react-native-ibeacon-android   File: ReactIntegrationTestCase.java   View source code 6 votes vote down vote up
protected static void initializeJavaModule(final BaseJavaModule javaModule) {
  final Semaphore semaphore = new Semaphore(0);
  UiThreadUtil.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          javaModule.initialize();
          if (javaModule instanceof LifecycleEventListener) {
            ((LifecycleEventListener) javaModule).onHostResume();
          }
          semaphore.release();
        }
      });
  try {
    SoftAssertions.assertCondition(
        semaphore.tryAcquire(5000, TimeUnit.MILLISECONDS),
        "Timed out initializing timing module");
  } catch (InterruptedException e) {
    throw new RuntimeException(e);
  }
}
 
Example 15
Project: react-native-box-loaders   File: UIViewOperationQueue.java   View source code 6 votes vote down vote up
public void addRootView(
    final int tag,
    final SizeMonitoringFrameLayout rootView,
    final ThemedReactContext themedRootContext) {
  if (UiThreadUtil.isOnUiThread()) {
    mNativeViewHierarchyManager.addRootView(tag, rootView, themedRootContext);
  } else {
    final Semaphore semaphore = new Semaphore(0);
    mReactApplicationContext.runOnUiQueueThread(
        new Runnable() {
          @Override
          public void run() {
            mNativeViewHierarchyManager.addRootView(tag, rootView, themedRootContext);
            semaphore.release();
          }
        });
    try {
      SoftAssertions.assertCondition(
          semaphore.tryAcquire(5000, TimeUnit.MILLISECONDS),
          "Timed out adding root view");
    } catch (InterruptedException e) {
      throw new RuntimeException(e);
    }
  }
}
 
Example 16
Project: react-native-box-loaders   File: NativeViewHierarchyManager.java   View source code 6 votes vote down vote up
public void setJSResponder(int reactTag, int initialReactTag, boolean blockNativeResponder) {
  if (!blockNativeResponder) {
    mJSResponderHandler.setJSResponder(initialReactTag, null);
    return;
  }

  View view = mTagsToViews.get(reactTag);
  if (initialReactTag != reactTag && view instanceof ViewParent) {
    // In this case, initialReactTag corresponds to a virtual/layout-only View, and we already
    // have a parent of that View in reactTag, so we can use it.
    mJSResponderHandler.setJSResponder(initialReactTag, (ViewParent) view);
    return;
  }

  if (mRootTags.get(reactTag)) {
    SoftAssertions.assertUnreachable(
        "Cannot block native responder on " + reactTag + " that is a root view");
  }
  mJSResponderHandler
      .setJSResponder(initialReactTag, view.getParent());
}
 
Example 17
Project: react-native-box-loaders   File: ReactIntegrationTestCase.java   View source code 6 votes vote down vote up
protected static void initializeJavaModule(final BaseJavaModule javaModule) {
  final Semaphore semaphore = new Semaphore(0);
  UiThreadUtil.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          javaModule.initialize();
          if (javaModule instanceof LifecycleEventListener) {
            ((LifecycleEventListener) javaModule).onHostResume();
          }
          semaphore.release();
        }
      });
  try {
    SoftAssertions.assertCondition(
        semaphore.tryAcquire(5000, TimeUnit.MILLISECONDS),
        "Timed out initializing timing module");
  } catch (InterruptedException e) {
    throw new RuntimeException(e);
  }
}
 
Example 18
Project: Ironman   File: UIViewOperationQueue.java   View source code 6 votes vote down vote up
public void addRootView(
    final int tag,
    final SizeMonitoringFrameLayout rootView,
    final ThemedReactContext themedRootContext) {
  if (UiThreadUtil.isOnUiThread()) {
    mNativeViewHierarchyManager.addRootView(tag, rootView, themedRootContext);
  } else {
    final Semaphore semaphore = new Semaphore(0);
    mReactApplicationContext.runOnUiQueueThread(
        new Runnable() {
          @Override
          public void run() {
            mNativeViewHierarchyManager.addRootView(tag, rootView, themedRootContext);
            semaphore.release();
          }
        });
    try {
      SoftAssertions.assertCondition(
          semaphore.tryAcquire(5000, TimeUnit.MILLISECONDS),
          "Timed out adding root view");
    } catch (InterruptedException e) {
      throw new RuntimeException(e);
    }
  }
}
 
Example 19
Project: Ironman   File: NativeViewHierarchyManager.java   View source code 6 votes vote down vote up
public void setJSResponder(int reactTag, int initialReactTag, boolean blockNativeResponder) {
  if (!blockNativeResponder) {
    mJSResponderHandler.setJSResponder(initialReactTag, null);
    return;
  }

  View view = mTagsToViews.get(reactTag);
  if (initialReactTag != reactTag && view instanceof ViewParent) {
    // In this case, initialReactTag corresponds to a virtual/layout-only View, and we already
    // have a parent of that View in reactTag, so we can use it.
    mJSResponderHandler.setJSResponder(initialReactTag, (ViewParent) view);
    return;
  }

  if (mRootTags.get(reactTag)) {
    SoftAssertions.assertUnreachable(
        "Cannot block native responder on " + reactTag + " that is a root view");
  }
  mJSResponderHandler
      .setJSResponder(initialReactTag, view.getParent());
}
 
Example 20
Project: Ironman   File: ReactIntegrationTestCase.java   View source code 6 votes vote down vote up
protected static void initializeJavaModule(final BaseJavaModule javaModule) {
  final Semaphore semaphore = new Semaphore(0);
  UiThreadUtil.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          javaModule.initialize();
          if (javaModule instanceof LifecycleEventListener) {
            ((LifecycleEventListener) javaModule).onHostResume();
          }
          semaphore.release();
        }
      });
  try {
    SoftAssertions.assertCondition(
        semaphore.tryAcquire(5000, TimeUnit.MILLISECONDS),
        "Timed out initializing timing module");
  } catch (InterruptedException e) {
    throw new RuntimeException(e);
  }
}
 
Example 21
Project: RNLearn_Project1   File: MessageQueueThreadImpl.java   View source code 5 votes vote down vote up
/**
 * Asserts {@link #isOnThread()}, throwing a {@link AssertionException} (NOT an
 * {@link AssertionError}) if the assertion fails.
 */
@DoNotStrip
@Override
public void assertIsOnThread(String message) {
  SoftAssertions.assertCondition(
    isOnThread(),
    new StringBuilder().append(mAssertionErrorMessage).append(" ").append(message).toString());
}
 
Example 22
Project: RNLearn_Project1   File: NativeViewHierarchyManager.java   View source code 5 votes vote down vote up
public void removeRootView(int rootViewTag) {
  UiThreadUtil.assertOnUiThread();
  if (!mRootTags.get(rootViewTag)) {
      SoftAssertions.assertUnreachable(
          "View with tag " + rootViewTag + " is not registered as a root view");
  }
  View rootView = mTagsToViews.get(rootViewTag);
  dropView(rootView);
  mRootTags.delete(rootViewTag);
}
 
Example 23
Project: RNLearn_Project1   File: MessageQueueThreadImpl.java   View source code 5 votes vote down vote up
/**
 * Asserts {@link #isOnThread()}, throwing a {@link AssertionException} (NOT an
 * {@link AssertionError}) if the assertion fails.
 */
@DoNotStrip
@Override
public void assertIsOnThread(String message) {
  SoftAssertions.assertCondition(
    isOnThread(),
    new StringBuilder().append(mAssertionErrorMessage).append(" ").append(message).toString());
}
 
Example 24
Project: RNLearn_Project1   File: NativeViewHierarchyManager.java   View source code 5 votes vote down vote up
public void removeRootView(int rootViewTag) {
  UiThreadUtil.assertOnUiThread();
  if (!mRootTags.get(rootViewTag)) {
      SoftAssertions.assertUnreachable(
          "View with tag " + rootViewTag + " is not registered as a root view");
  }
  View rootView = mTagsToViews.get(rootViewTag);
  dropView(rootView);
  mRootTags.delete(rootViewTag);
}
 
Example 25
Project: ReactNativeSignatureExample   File: NativeViewHierarchyManager.java   View source code 5 votes vote down vote up
public void removeRootView(int rootViewTag) {
  UiThreadUtil.assertOnUiThread();
  if (!mRootTags.get(rootViewTag)) {
      SoftAssertions.assertUnreachable(
          "View with tag " + rootViewTag + " is not registered as a root view");
  }
  View rootView = mTagsToViews.get(rootViewTag);
  dropView(rootView);
  mRootTags.delete(rootViewTag);
}
 
Example 26
Project: react-native-ibeacon-android   File: NativeViewHierarchyManager.java   View source code 5 votes vote down vote up
public void removeRootView(int rootViewTag) {
  UiThreadUtil.assertOnUiThread();
  if (!mRootTags.get(rootViewTag)) {
      SoftAssertions.assertUnreachable(
          "View with tag " + rootViewTag + " is not registered as a root view");
  }
  View rootView = mTagsToViews.get(rootViewTag);
  dropView(rootView);
  mRootTags.delete(rootViewTag);
}
 
Example 27
Project: react-native-box-loaders   File: NativeViewHierarchyManager.java   View source code 5 votes vote down vote up
public void removeRootView(int rootViewTag) {
  UiThreadUtil.assertOnUiThread();
  if (!mRootTags.get(rootViewTag)) {
      SoftAssertions.assertUnreachable(
          "View with tag " + rootViewTag + " is not registered as a root view");
  }
  View rootView = mTagsToViews.get(rootViewTag);
  dropView(rootView);
  mRootTags.delete(rootViewTag);
}
 
Example 28
Project: Ironman   File: NativeViewHierarchyManager.java   View source code 5 votes vote down vote up
public void removeRootView(int rootViewTag) {
  UiThreadUtil.assertOnUiThread();
  if (!mRootTags.get(rootViewTag)) {
      SoftAssertions.assertUnreachable(
          "View with tag " + rootViewTag + " is not registered as a root view");
  }
  View rootView = mTagsToViews.get(rootViewTag);
  dropView(rootView);
  mRootTags.delete(rootViewTag);
}
 
Example 29
Project: RNLearn_Project1   File: MessageQueueThreadImpl.java   View source code 4 votes vote down vote up
/**
 * Asserts {@link #isOnThread()}, throwing a {@link AssertionException} (NOT an
 * {@link AssertionError}) if the assertion fails.
 */
@DoNotStrip
@Override
public void assertIsOnThread() {
  SoftAssertions.assertCondition(isOnThread(), mAssertionErrorMessage);
}
 
Example 30
Project: RNLearn_Project1   File: UIViewOperationQueue.java   View source code 4 votes vote down vote up
/**
 * Enqueues a UIOperation to be executed in UI thread. This method should only be used by a
 * subclass to support UIOperations not provided by UIViewOperationQueue.
 */
protected void enqueueUIOperation(UIOperation operation) {
  SoftAssertions.assertNotNull(operation);
  mOperations.add(operation);
}
 
Example 31
Project: RNLearn_Project1   File: TouchEvent.java   View source code 4 votes vote down vote up
private void init(
    int viewTag,
    TouchEventType touchEventType,
    MotionEvent motionEventToCopy,
    long gestureStartTime,
    float viewX,
    float viewY,
    TouchEventCoalescingKeyHelper touchEventCoalescingKeyHelper) {
  super.init(viewTag);

  SoftAssertions.assertCondition(gestureStartTime != UNSET,
      "Gesture start time must be initialized");
  short coalescingKey = 0;
  int action = (motionEventToCopy.getAction() & MotionEvent.ACTION_MASK);
  switch (action) {
    case MotionEvent.ACTION_DOWN:
      touchEventCoalescingKeyHelper.addCoalescingKey(gestureStartTime);
      break;
    case MotionEvent.ACTION_UP:
      touchEventCoalescingKeyHelper.removeCoalescingKey(gestureStartTime);
      break;
    case MotionEvent.ACTION_POINTER_DOWN:
    case MotionEvent.ACTION_POINTER_UP:
      touchEventCoalescingKeyHelper.incrementCoalescingKey(gestureStartTime);
      break;
    case MotionEvent.ACTION_MOVE:
      coalescingKey =
        touchEventCoalescingKeyHelper.getCoalescingKey(gestureStartTime);
      break;
    case MotionEvent.ACTION_CANCEL:
      touchEventCoalescingKeyHelper.removeCoalescingKey(gestureStartTime);
      break;
    default:
      throw new RuntimeException("Unhandled MotionEvent action: " + action);
  }
  mTouchEventType = touchEventType;
  mMotionEvent = MotionEvent.obtain(motionEventToCopy);
  mCoalescingKey = coalescingKey;
  mViewX = viewX;
  mViewY = viewY;
}
 
Example 32
Project: RNLearn_Project1   File: MessageQueueThreadImpl.java   View source code 4 votes vote down vote up
/**
 * Asserts {@link #isOnThread()}, throwing a {@link AssertionException} (NOT an
 * {@link AssertionError}) if the assertion fails.
 */
@DoNotStrip
@Override
public void assertIsOnThread() {
  SoftAssertions.assertCondition(isOnThread(), mAssertionErrorMessage);
}
 
Example 33
Project: RNLearn_Project1   File: UIViewOperationQueue.java   View source code 4 votes vote down vote up
/**
 * Enqueues a UIOperation to be executed in UI thread. This method should only be used by a
 * subclass to support UIOperations not provided by UIViewOperationQueue.
 */
protected void enqueueUIOperation(UIOperation operation) {
  SoftAssertions.assertNotNull(operation);
  mOperations.add(operation);
}
 
Example 34
Project: RNLearn_Project1   File: TouchEvent.java   View source code 4 votes vote down vote up
private void init(
    int viewTag,
    TouchEventType touchEventType,
    MotionEvent motionEventToCopy,
    long gestureStartTime,
    float viewX,
    float viewY,
    TouchEventCoalescingKeyHelper touchEventCoalescingKeyHelper) {
  super.init(viewTag);

  SoftAssertions.assertCondition(gestureStartTime != UNSET,
      "Gesture start time must be initialized");
  short coalescingKey = 0;
  int action = (motionEventToCopy.getAction() & MotionEvent.ACTION_MASK);
  switch (action) {
    case MotionEvent.ACTION_DOWN:
      touchEventCoalescingKeyHelper.addCoalescingKey(gestureStartTime);
      break;
    case MotionEvent.ACTION_UP:
      touchEventCoalescingKeyHelper.removeCoalescingKey(gestureStartTime);
      break;
    case MotionEvent.ACTION_POINTER_DOWN:
    case MotionEvent.ACTION_POINTER_UP:
      touchEventCoalescingKeyHelper.incrementCoalescingKey(gestureStartTime);
      break;
    case MotionEvent.ACTION_MOVE:
      coalescingKey =
        touchEventCoalescingKeyHelper.getCoalescingKey(gestureStartTime);
      break;
    case MotionEvent.ACTION_CANCEL:
      touchEventCoalescingKeyHelper.removeCoalescingKey(gestureStartTime);
      break;
    default:
      throw new RuntimeException("Unhandled MotionEvent action: " + action);
  }
  mTouchEventType = touchEventType;
  mMotionEvent = MotionEvent.obtain(motionEventToCopy);
  mCoalescingKey = coalescingKey;
  mViewX = viewX;
  mViewY = viewY;
}
 
Example 35
Project: ReactNativeSignatureExample   File: ReactDrawableHelper.java   View source code 4 votes vote down vote up
public static Drawable createDrawableFromJSDescription(
    Context context,
    ReadableMap drawableDescriptionDict) {
  String type = drawableDescriptionDict.getString("type");
  if ("ThemeAttrAndroid".equals(type)) {
    String attr = drawableDescriptionDict.getString("attribute");
    SoftAssertions.assertNotNull(attr);
    int attrID = context.getResources().getIdentifier(attr, "attr", "android");
    if (attrID == 0) {
      throw new JSApplicationIllegalArgumentException("Attribute " + attr +
          " couldn't be found in the resource list");
    }
    if (context.getTheme().resolveAttribute(attrID, sResolveOutValue, true)) {
      final int version = Build.VERSION.SDK_INT;
      if (version >= 21) {
        return context.getResources()
            .getDrawable(sResolveOutValue.resourceId, context.getTheme());
      } else {
        return context.getResources().getDrawable(sResolveOutValue.resourceId);
      }
    } else {
      throw new JSApplicationIllegalArgumentException("Attribute " + attr +
          " couldn't be resolved into a drawable");
    }
  } else if ("RippleAndroid".equals(type)) {
    if (Build.VERSION.SDK_INT < 21) {
      throw new JSApplicationIllegalArgumentException("Ripple drawable is not available on " +
          "android API <21");
    }
    int color;
    if (drawableDescriptionDict.hasKey(ViewProps.COLOR) &&
        !drawableDescriptionDict.isNull(ViewProps.COLOR)) {
      color = drawableDescriptionDict.getInt(ViewProps.COLOR);
    } else {
      if (context.getTheme().resolveAttribute(
          android.R.attr.colorControlHighlight,
          sResolveOutValue,
          true)) {
        color = context.getResources().getColor(sResolveOutValue.resourceId);
      } else {
        throw new JSApplicationIllegalArgumentException("Attribute colorControlHighlight " +
            "couldn't be resolved into a drawable");
      }
    }
    Drawable mask = null;
    if (!drawableDescriptionDict.hasKey("borderless") ||
        drawableDescriptionDict.isNull("borderless") ||
        !drawableDescriptionDict.getBoolean("borderless")) {
      mask = new ColorDrawable(Color.WHITE);
    }
    ColorStateList colorStateList = new ColorStateList(
        new int[][] {new int[]{}},
        new int[] {color});
    return new RippleDrawable(colorStateList, null, mask);
  } else {
    throw new JSApplicationIllegalArgumentException(
        "Invalid type for android drawable: " + type);
  }
}
 
Example 36
Project: ReactNativeSignatureExample   File: MessageQueueThreadImpl.java   View source code 4 votes vote down vote up
/**
 * Asserts {@link #isOnThread()}, throwing a {@link AssertionException} (NOT an
 * {@link AssertionError}) if the assertion fails.
 */
@DoNotStrip
@Override
public void assertIsOnThread() {
  SoftAssertions.assertCondition(isOnThread(), mAssertionErrorMessage);
}
 
Example 37
Project: react-native-ibeacon-android   File: ReactDrawableHelper.java   View source code 4 votes vote down vote up
public static Drawable createDrawableFromJSDescription(
    Context context,
    ReadableMap drawableDescriptionDict) {
  String type = drawableDescriptionDict.getString("type");
  if ("ThemeAttrAndroid".equals(type)) {
    String attr = drawableDescriptionDict.getString("attribute");
    SoftAssertions.assertNotNull(attr);
    int attrID = context.getResources().getIdentifier(attr, "attr", "android");
    if (attrID == 0) {
      throw new JSApplicationIllegalArgumentException("Attribute " + attr +
          " couldn't be found in the resource list");
    }
    if (context.getTheme().resolveAttribute(attrID, sResolveOutValue, true)) {
      final int version = Build.VERSION.SDK_INT;
      if (version >= 21) {
        return context.getResources()
            .getDrawable(sResolveOutValue.resourceId, context.getTheme());
      } else {
        return context.getResources().getDrawable(sResolveOutValue.resourceId);
      }
    } else {
      throw new JSApplicationIllegalArgumentException("Attribute " + attr +
          " couldn't be resolved into a drawable");
    }
  } else if ("RippleAndroid".equals(type)) {
    if (Build.VERSION.SDK_INT < 21) {
      throw new JSApplicationIllegalArgumentException("Ripple drawable is not available on " +
          "android API <21");
    }
    int color;
    if (drawableDescriptionDict.hasKey(ViewProps.COLOR) &&
        !drawableDescriptionDict.isNull(ViewProps.COLOR)) {
      color = drawableDescriptionDict.getInt(ViewProps.COLOR);
    } else {
      if (context.getTheme().resolveAttribute(
          android.R.attr.colorControlHighlight,
          sResolveOutValue,
          true)) {
        color = context.getResources().getColor(sResolveOutValue.resourceId);
      } else {
        throw new JSApplicationIllegalArgumentException("Attribute colorControlHighlight " +
            "couldn't be resolved into a drawable");
      }
    }
    Drawable mask = null;
    if (!drawableDescriptionDict.hasKey("borderless") ||
        drawableDescriptionDict.isNull("borderless") ||
        !drawableDescriptionDict.getBoolean("borderless")) {
      mask = new ColorDrawable(Color.WHITE);
    }
    ColorStateList colorStateList = new ColorStateList(
        new int[][] {new int[]{}},
        new int[] {color});
    return new RippleDrawable(colorStateList, null, mask);
  } else {
    throw new JSApplicationIllegalArgumentException(
        "Invalid type for android drawable: " + type);
  }
}
 
Example 38
Project: react-native-ibeacon-android   File: MessageQueueThreadImpl.java   View source code 4 votes vote down vote up
/**
 * Asserts {@link #isOnThread()}, throwing a {@link AssertionException} (NOT an
 * {@link AssertionError}) if the assertion fails.
 */
@DoNotStrip
@Override
public void assertIsOnThread() {
  SoftAssertions.assertCondition(isOnThread(), mAssertionErrorMessage);
}
 
Example 39
Project: react-native-box-loaders   File: ReactDrawableHelper.java   View source code 4 votes vote down vote up
public static Drawable createDrawableFromJSDescription(
    Context context,
    ReadableMap drawableDescriptionDict) {
  String type = drawableDescriptionDict.getString("type");
  if ("ThemeAttrAndroid".equals(type)) {
    String attr = drawableDescriptionDict.getString("attribute");
    SoftAssertions.assertNotNull(attr);
    int attrID = context.getResources().getIdentifier(attr, "attr", "android");
    if (attrID == 0) {
      throw new JSApplicationIllegalArgumentException("Attribute " + attr +
          " couldn't be found in the resource list");
    }
    if (context.getTheme().resolveAttribute(attrID, sResolveOutValue, true)) {
      final int version = Build.VERSION.SDK_INT;
      if (version >= 21) {
        return context.getResources()
            .getDrawable(sResolveOutValue.resourceId, context.getTheme());
      } else {
        return context.getResources().getDrawable(sResolveOutValue.resourceId);
      }
    } else {
      throw new JSApplicationIllegalArgumentException("Attribute " + attr +
          " couldn't be resolved into a drawable");
    }
  } else if ("RippleAndroid".equals(type)) {
    if (Build.VERSION.SDK_INT < 21) {
      throw new JSApplicationIllegalArgumentException("Ripple drawable is not available on " +
          "android API <21");
    }
    int color;
    if (drawableDescriptionDict.hasKey(ViewProps.COLOR) &&
        !drawableDescriptionDict.isNull(ViewProps.COLOR)) {
      color = drawableDescriptionDict.getInt(ViewProps.COLOR);
    } else {
      if (context.getTheme().resolveAttribute(
          android.R.attr.colorControlHighlight,
          sResolveOutValue,
          true)) {
        color = context.getResources().getColor(sResolveOutValue.resourceId);
      } else {
        throw new JSApplicationIllegalArgumentException("Attribute colorControlHighlight " +
            "couldn't be resolved into a drawable");
      }
    }
    Drawable mask = null;
    if (!drawableDescriptionDict.hasKey("borderless") ||
        drawableDescriptionDict.isNull("borderless") ||
        !drawableDescriptionDict.getBoolean("borderless")) {
      mask = new ColorDrawable(Color.WHITE);
    }
    ColorStateList colorStateList = new ColorStateList(
        new int[][] {new int[]{}},
        new int[] {color});
    return new RippleDrawable(colorStateList, null, mask);
  } else {
    throw new JSApplicationIllegalArgumentException(
        "Invalid type for android drawable: " + type);
  }
}
 
Example 40
Project: react-native-box-loaders   File: MessageQueueThreadImpl.java   View source code 4 votes vote down vote up
/**
 * Asserts {@link #isOnThread()}, throwing a {@link AssertionException} (NOT an
 * {@link AssertionError}) if the assertion fails.
 */
@DoNotStrip
@Override
public void assertIsOnThread() {
  SoftAssertions.assertCondition(isOnThread(), mAssertionErrorMessage);
}