当前位置: 首页>>代码示例>>Java>>正文


Java UiThreadUtil.runOnUiThread方法代码示例

本文整理汇总了Java中com.facebook.react.bridge.UiThreadUtil.runOnUiThread方法的典型用法代码示例。如果您正苦于以下问题:Java UiThreadUtil.runOnUiThread方法的具体用法?Java UiThreadUtil.runOnUiThread怎么用?Java UiThreadUtil.runOnUiThread使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.facebook.react.bridge.UiThreadUtil的用法示例。


在下文中一共展示了UiThreadUtil.runOnUiThread方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onMeasure

import com.facebook.react.bridge.UiThreadUtil; //导入方法依赖的package包/类
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  setMeasuredDimension(
      MeasureSpec.getSize(widthMeasureSpec),
      MeasureSpec.getSize(heightMeasureSpec));

  mWasMeasured = true;
  // Check if we were waiting for onMeasure to attach the root view
  if (mReactInstanceManager != null && !mIsAttachedToInstance) {
    // Enqueue it to UIThread not to block onMeasure waiting for the catalyst instance creation
    UiThreadUtil.runOnUiThread(new Runnable() {
      @Override
      public void run() {
        attachToReactInstanceManager();
      }
    });
  }
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:19,代码来源:ReactRootView.java

示例2: setHidden

import com.facebook.react.bridge.UiThreadUtil; //导入方法依赖的package包/类
@ReactMethod
public void setHidden(final boolean hidden) {
  final Activity activity = getCurrentActivity();
  if (activity == null) {
    FLog.w(ReactConstants.TAG, "StatusBarModule: Ignored status bar change, current activity is null.");
    return;
  }
  UiThreadUtil.runOnUiThread(
    new Runnable() {
      @Override
      public void run() {
        if (hidden) {
          activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
          activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        } else {
          activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
          activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }
      }
    });
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:22,代码来源:StatusBarModule.java

示例3: createTimingModule

import com.facebook.react.bridge.UiThreadUtil; //导入方法依赖的package包/类
/**
 * Timing module needs to be created on the main thread so that it gets the correct Choreographer.
 */
protected Timing createTimingModule() {
  final SimpleSettableFuture<Timing> simpleSettableFuture = new SimpleSettableFuture<Timing>();
  UiThreadUtil.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          Timing timing = new Timing(getContext(), mock(DevSupportManager.class));
          simpleSettableFuture.set(timing);
        }
      });
  try {
    return simpleSettableFuture.get(5000, TimeUnit.MILLISECONDS);
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:20,代码来源:ReactIntegrationTestCase.java

示例4: createForMainThread

import com.facebook.react.bridge.UiThreadUtil; //导入方法依赖的package包/类
/**
 * @return a MessageQueueThreadImpl corresponding to Android's main UI thread.
 */
private static MessageQueueThreadImpl createForMainThread(
    String name,
    QueueThreadExceptionHandler exceptionHandler) {
  Looper mainLooper = Looper.getMainLooper();
  final MessageQueueThreadImpl mqt =
      new MessageQueueThreadImpl(name, mainLooper, exceptionHandler);

  if (UiThreadUtil.isOnUiThread()) {
    Process.setThreadPriority(Process.THREAD_PRIORITY_DISPLAY);
    MessageQueueThreadRegistry.register(mqt);
  } else {
    UiThreadUtil.runOnUiThread(
        new Runnable() {
          @Override
          public void run() {
            Process.setThreadPriority(Process.THREAD_PRIORITY_DISPLAY);
            MessageQueueThreadRegistry.register(mqt);
          }
        });
  }
  return mqt;
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:26,代码来源:MessageQueueThreadImpl.java

示例5: finishTask

import com.facebook.react.bridge.UiThreadUtil; //导入方法依赖的package包/类
/**
 * Finish a JS task. Doesn't actually stop the task on the JS side, only removes it from the list
 * of active tasks and notifies listeners. A task can only be finished once.
 *
 * @param taskId the unique id returned by {@link #startTask}.
 */
public synchronized void finishTask(final int taskId) {
  Assertions.assertCondition(
    mActiveTasks.remove(taskId),
    "Tried to finish non-existent task with id " + taskId + ".");
  Runnable timeout = mTaskTimeouts.get(taskId);
  if (timeout != null) {
    mHandler.removeCallbacks(timeout);
    mTaskTimeouts.remove(taskId);
  }
  UiThreadUtil.runOnUiThread(new Runnable() {
    @Override
    public void run() {
      for (HeadlessJsTaskEventListener listener : mHeadlessJsTaskEventListeners) {
        listener.onHeadlessJsTaskFinish(taskId);
      }
    }
  });
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:25,代码来源:HeadlessJsTaskContext.java

示例6: setSendIdleEvents

import com.facebook.react.bridge.UiThreadUtil; //导入方法依赖的package包/类
@ReactMethod
public void setSendIdleEvents(ExecutorToken executorToken, boolean sendIdleEvents) {
  synchronized (mIdleCallbackGuard) {
    if (sendIdleEvents) {
      mSendIdleEventsExecutorTokens.add(executorToken);
    } else {
      mSendIdleEventsExecutorTokens.remove(executorToken);
    }
  }

  UiThreadUtil.runOnUiThread(new Runnable() {
    @Override
    public void run() {
      synchronized (mIdleCallbackGuard) {
        if (mSendIdleEventsExecutorTokens.size() > 0) {
          setChoreographerIdleCallback();
        } else {
          clearChoreographerIdleCallback();
        }
      }
    }
  });
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:24,代码来源:Timing.java

示例7: setColor

import com.facebook.react.bridge.UiThreadUtil; //导入方法依赖的package包/类
@ReactMethod
public void setColor(final int color, final boolean animated) {
  final Activity activity = getCurrentActivity();
  if (activity == null) {
    FLog.w(ReactConstants.TAG, "StatusBarModule: Ignored status bar change, current activity is null.");
    return;
  }

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    UiThreadUtil.runOnUiThread(
      new GuardedRunnable(getReactApplicationContext()) {
        @TargetApi(Build.VERSION_CODES.LOLLIPOP)
        @Override
        public void runGuarded() {
          if (animated) {
            int curColor = activity.getWindow().getStatusBarColor();
            ValueAnimator colorAnimation = ValueAnimator.ofObject(
              new ArgbEvaluator(), curColor, color);

            colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
              @Override
              public void onAnimationUpdate(ValueAnimator animator) {
                activity.getWindow().setStatusBarColor((Integer) animator.getAnimatedValue());
              }
            });
            colorAnimation
              .setDuration(300)
              .setStartDelay(0);
            colorAnimation.start();
          } else {
            activity.getWindow().setStatusBarColor(color);
          }
        }
      });
  }
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:37,代码来源:StatusBarModule.java

示例8: show

import com.facebook.react.bridge.UiThreadUtil; //导入方法依赖的package包/类
@ReactMethod
public void show(final String message, final int duration) {
  UiThreadUtil.runOnUiThread(new Runnable() {
    @Override
    public void run() {
      Toast.makeText(getReactApplicationContext(), message, duration).show();
    }
  });
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:10,代码来源:ToastModule.java

示例9: showWithGravity

import com.facebook.react.bridge.UiThreadUtil; //导入方法依赖的package包/类
@ReactMethod
public void showWithGravity(final String message, final int duration, final int gravity) {
  UiThreadUtil.runOnUiThread(new Runnable() {
    @Override
    public void run() {
      Toast toast = Toast.makeText(getReactApplicationContext(), message, duration);
      toast.setGravity(gravity, 0, 0);
      toast.show();
    }
  });
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:12,代码来源:ToastModule.java

示例10: showNewError

import com.facebook.react.bridge.UiThreadUtil; //导入方法依赖的package包/类
private void showNewError(
    final String message,
    final StackFrame[] stack,
    final int errorCookie,
    final ErrorType errorType) {
  UiThreadUtil.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          if (mRedBoxDialog == null) {
            mRedBoxDialog = new RedBoxDialog(mApplicationContext, DevSupportManagerImpl.this, mRedBoxHandler);
            mRedBoxDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
          }
          if (mRedBoxDialog.isShowing()) {
            // Sometimes errors cause multiple errors to be thrown in JS in quick succession. Only
            // show the first and most actionable one.
            return;
          }
          mRedBoxDialog.setExceptionDetails(message, stack);
          updateLastErrorInfo(message, stack, errorCookie, errorType);
          // Only report native errors here. JS errors are reported
          // inside {@link #updateJSError} after source mapping.
          if (mRedBoxHandler != null && errorType == ErrorType.NATIVE) {
            mRedBoxHandler.handleRedbox(message, stack, RedBoxHandler.ErrorType.NATIVE);
            mRedBoxDialog.resetReporting(true);
          } else {
            mRedBoxDialog.resetReporting(false);
          }
          mRedBoxDialog.show();
        }
      });
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:33,代码来源:DevSupportManagerImpl.java

示例11: waitForChoreographer

import com.facebook.react.bridge.UiThreadUtil; //导入方法依赖的package包/类
private static void waitForChoreographer(long timeToWait) {
  final int waitFrameCount = 2;
  final CountDownLatch latch = new CountDownLatch(1);
  UiThreadUtil.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          ChoreographerCompat.getInstance().postFrameCallback(
              new ChoreographerCompat.FrameCallback() {

                private int frameCount = 0;

                @Override
                public void doFrame(long frameTimeNanos) {
                  frameCount++;
                  if (frameCount == waitFrameCount) {
                    latch.countDown();
                  } else {
                    ChoreographerCompat.getInstance().postFrameCallback(this);
                  }
                }
              });
        }
      });
  try {
    if (!latch.await(timeToWait, TimeUnit.MILLISECONDS)) {
      throw new RuntimeException("Timed out waiting for Choreographer");
    }
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:33,代码来源:ReactIdleDetectionUtil.java

示例12: setUp

import com.facebook.react.bridge.UiThreadUtil; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
  super.setUp();

  List<ViewManager> viewManagers = Arrays.<ViewManager>asList(
      new ReactViewManager());
  final UIManagerModule mUIManager = new UIManagerModule(
      getContext(),
      viewManagers,
      new UIImplementationProvider(),
      false);
  UiThreadUtil.runOnUiThread(
      new Runnable() {
        @Override
        public void run() {
          mUIManager.onHostResume();
        }
      });
  waitForIdleSync();

  mStringRecordingModule = new StringRecordingModule();
  mInstance = ReactTestHelper.catalystInstanceBuilder(this)
      .addNativeModule(mStringRecordingModule)
      .addNativeModule(mUIManager)
      .addNativeModule(new DeviceInfoModule(getContext()))
      .addNativeModule(new AppStateModule(getContext()))
      .addNativeModule(new FakeWebSocketModule())
      .addJSModule(TestJSLocaleModule.class)
      .build();
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:31,代码来源:JSLocaleTest.java

示例13: onPackagerReloadCommand

import com.facebook.react.bridge.UiThreadUtil; //导入方法依赖的package包/类
@Override
public void onPackagerReloadCommand() {
  UiThreadUtil.runOnUiThread(new Runnable() {
    @Override
    public void run() {
      handleReloadJS();
    }
  });
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:10,代码来源:DevSupportManagerImpl.java

示例14: dispatchViewUpdates

import com.facebook.react.bridge.UiThreadUtil; //导入方法依赖的package包/类
void dispatchViewUpdates(final int batchId) {
  // Store the current operation queues to dispatch and create new empty ones to continue
  // receiving new operations
  final ArrayList<UIOperation> operations = mOperations.isEmpty() ? null : mOperations;
  if (operations != null) {
    mOperations = new ArrayList<>();
  }

  final UIOperation[] nonBatchedOperations;
  synchronized (mNonBatchedOperationsLock) {
    if (!mNonBatchedOperations.isEmpty()) {
      nonBatchedOperations =
        mNonBatchedOperations.toArray(new UIOperation[mNonBatchedOperations.size()]);
      mNonBatchedOperations.clear();
    } else {
      nonBatchedOperations = null;
    }
  }

  if (mViewHierarchyUpdateDebugListener != null) {
    mViewHierarchyUpdateDebugListener.onViewHierarchyUpdateEnqueued();
  }

  synchronized (mDispatchRunnablesLock) {
    mDispatchUIRunnables.add(
        new Runnable() {
           @Override
           public void run() {
             SystraceMessage.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "DispatchUI")
                 .arg("BatchId", batchId)
                 .flush();
             try {
               // All nonBatchedOperations should be executed before regular operations as
               // regular operations may depend on them
               if (nonBatchedOperations != null) {
                 for (UIOperation op : nonBatchedOperations) {
                   op.execute();
                 }
               }

               if (operations != null) {
                 for (int i = 0; i < operations.size(); i++) {
                   operations.get(i).execute();
                 }
               }

               // Clear layout animation, as animation only apply to current UI operations batch.
               mNativeViewHierarchyManager.clearLayoutAnimation();

               if (mViewHierarchyUpdateDebugListener != null) {
                 mViewHierarchyUpdateDebugListener.onViewHierarchyUpdateFinished();
               }
             } catch (Exception e) {
               mIsInIllegalUIState = true;
               throw e;
             } finally {
               Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
             }
           }
         });
  }

  // In the case where the frame callback isn't enqueued, the UI isn't being displayed or is being
  // destroyed. In this case it's no longer important to align to frames, but it is imporant to make
  // sure any late-arriving UI commands are executed.
  if (!mIsDispatchUIFrameCallbackEnqueued) {
    UiThreadUtil.runOnUiThread(
        new GuardedRunnable(mReactApplicationContext) {
          @Override
          public void runGuarded() {
            flushPendingBatches();
          }
        });
  }
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:76,代码来源:UIViewOperationQueue.java


注:本文中的com.facebook.react.bridge.UiThreadUtil.runOnUiThread方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。