下面列出了java.lang.AssertionError#java.lang.Runnable 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@ReactMethod
public void setColor(final String color) {
final Activity activity = getCurrentActivity();
if (activity == null) {
return;
}
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
View view = activity.getWindow().getDecorView();
int parsedColor = Color.parseColor(color);
view.getRootView().setBackgroundColor(parsedColor);
}
});
}
private void manualTurnScreenOff() {
Log.d(TAG, "manualTurnScreenOff()");
UiThreadUtil.runOnUiThread(new Runnable() {
public void run() {
Activity mCurrentActivity = getCurrentActivity();
if (mCurrentActivity == null) {
Log.d(TAG, "ReactContext doesn't hava any Activity attached.");
return;
}
Window window = mCurrentActivity.getWindow();
WindowManager.LayoutParams params = window.getAttributes();
lastLayoutParams = params; // --- store last param
params.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_OFF; // --- Dim as dark as possible. see BRIGHTNESS_OVERRIDE_OFF
window.setAttributes(params);
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
});
}
private void manualTurnScreenOn() {
Log.d(TAG, "manualTurnScreenOn()");
UiThreadUtil.runOnUiThread(new Runnable() {
public void run() {
Activity mCurrentActivity = getCurrentActivity();
if (mCurrentActivity == null) {
Log.d(TAG, "ReactContext doesn't hava any Activity attached.");
return;
}
Window window = mCurrentActivity.getWindow();
if (lastLayoutParams != null) {
window.setAttributes(lastLayoutParams);
} else {
WindowManager.LayoutParams params = window.getAttributes();
params.screenBrightness = -1; // --- Dim to preferable one
window.setAttributes(params);
}
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
});
}
@ReactMethod
public void setKeepScreenOn(final boolean enable) {
Log.d(TAG, "setKeepScreenOn() " + enable);
UiThreadUtil.runOnUiThread(new Runnable() {
public void run() {
Activity mCurrentActivity = getCurrentActivity();
if (mCurrentActivity == null) {
Log.d(TAG, "ReactContext doesn't hava any Activity attached.");
return;
}
Window window = mCurrentActivity.getWindow();
if (enable) {
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
} else {
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
}
});
}
@Override
public void handlePreBind(final EpoxyViewHolder holder, final ModelViewWithParis object,
final int position) {
validateStateHasNotChangedSinceAdded("The model was changed between being added to the controller and being bound.", position);
if (!Objects.equals(style, object.getTag(R.id.epoxy_saved_view_style))) {
AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() {
public void run() {
try {
StyleApplierUtils.Companion.assertSameAttributes(new ModelViewWithParisStyleApplier(object), style, DEFAULT_PARIS_STYLE);
}
catch(AssertionError e) {
throw new IllegalStateException("ModelViewWithParisModel_ model at position " + position + " has an invalid style:\n\n" + e.getMessage());
}
}
} );
}
}
@Override
public void handlePreBind(final EpoxyViewHolder holder, final StyleableModelView object,
final int position) {
validateStateHasNotChangedSinceAdded("The model was changed between being added to the controller and being bound.", position);
if (!Objects.equals(style, object.getTag(R.id.epoxy_saved_view_style))) {
AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() {
public void run() {
try {
StyleApplierUtils.Companion.assertSameAttributes(new StyleableModelViewStyleApplier(object), style, DEFAULT_PARIS_STYLE);
}
catch(AssertionError e) {
throw new IllegalStateException("StyleableModelViewModel_ model at position " + position + " has an invalid style:\n\n" + e.getMessage());
}
}
} );
}
}
/**
* Tests that if a Future that is being processed in flush() failed with an exception and then a
* second Future is processed successfully in a subsequent flush, then the subsequent flush
* succeeds.
*/
@Test
public void testFlushExceptionThenNoExceptionCase() throws Exception {
task.start(props);
Map<TopicPartition, OffsetAndMetadata> partitionOffsets = new HashMap<>();
partitionOffsets.put(new TopicPartition(KAFKA_TOPIC, 0), null);
List<SinkRecord> records = getSampleRecords();
ApiFuture<String> badFuture = getFailedPublishFuture();
ApiFuture<String> goodFuture = getSuccessfulPublishFuture();
when(publisher.publish(any(PubsubMessage.class))).thenReturn(badFuture).thenReturn(badFuture).thenReturn(goodFuture);
task.put(records);
try {
task.flush(partitionOffsets);
} catch (RuntimeException e) {
}
records = getSampleRecords();
task.put(records);
task.flush(partitionOffsets);
verify(publisher, times(4)).publish(any(PubsubMessage.class));
verify(badFuture, times(2)).addListener(any(Runnable.class), any(Executor.class));
verify(goodFuture, times(2)).addListener(any(Runnable.class), any(Executor.class));
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection.
switch (item.getItemId()) {
case R.id.stop:
// Stop the service at the end of the message queue for proper options menu
// animation. This is only needed when starting a new Activity or stopping a Service
// that published a LiveCard.
mHandler.post(new Runnable() {
@Override
public void run() {
stopService(new Intent(MenuActivity.this, MapService.class));
setResult(RESULT_OK);
finish();
}
});
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection.
switch (item.getItemId()) {
case R.id.stop:
// Stop the service at the end of the message queue for proper options menu
// animation. This is only needed when starting a new Activity or stopping a Service
// that published a LiveCard.
mHandler.post(new Runnable() {
@Override
public void run() {
stopService(new Intent(MenuActivity.this, OpenGlService.class));
}
});
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.read_aloud:
mCompassService.readHeadingAloud();
return true;
case R.id.stop:
// Stop the service at the end of the message queue for proper options menu
// animation. This is only needed when starting an Activity or stopping a Service
// that published a LiveCard.
mHandler.post(new Runnable() {
@Override
public void run() {
stopService(new Intent(CompassMenuActivity.this, CompassService.class));
}
});
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection.
switch (item.getItemId()) {
case R.id.stop:
// Stop the service at the end of the message queue for proper options menu
// animation. This is only needed when starting a new Activity or stopping a Service
// that published a LiveCard.
mHandler.post(new Runnable() {
@Override
public void run() {
stopService(new Intent(MenuActivity.this, OpenGlService.class));
}
});
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection.
switch (item.getItemId()) {
case R.id.stop:
// Stop the service at the end of the message queue for proper options menu
// animation. This is only needed when starting a new Activity or stopping a Service
// that published a LiveCard.
post(new Runnable() {
@Override
public void run() {
stopService(new Intent(MenuActivity.this, StopwatchService.class));
}
});
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Test public void varargs() throws Exception {
TypeSpec taqueria = TypeSpec.classBuilder("Taqueria")
.addMethod(MethodSpec.methodBuilder("prepare")
.addParameter(int.class, "workers")
.addParameter(Runnable[].class, "jobs")
.varargs()
.build())
.build();
assertThat(toString(taqueria)).isEqualTo(""
+ "package com.squareup.tacos;\n"
+ "\n"
+ "import java.lang.Runnable;\n"
+ "\n"
+ "class Taqueria {\n"
+ " void prepare(int workers, Runnable... jobs) {\n"
+ " }\n"
+ "}\n");
}
private void initRunnable(Runnable wrappedRunnable, SofaTraceContext traceContext) {
this.wrappedRunnable = wrappedRunnable;
this.traceContext = traceContext;
if (!traceContext.isEmpty()) {
this.currentSpan = traceContext.getCurrentSpan();
} else {
this.currentSpan = null;
}
}
private InCallProximityManager(Context context, final FlutterIncallManagerPlugin inCallManager) {
Log.d(TAG, "InCallProximityManager");
checkProximitySupport(context);
if (proximitySupported) {
proximitySensor = AppRTCProximitySensor.create(context,
new Runnable() {
@Override
public void run() {
Log.d(TAG,"InCallProximityManager:AppRTCProximitySensor:run()");
inCallManager.onProximitySensorChangedState(proximitySensor.sensorReportsNearState());
}
}
);
}
}
/**
* This executes all of the Runnable's stored within API.login_tasks
*
* NOT TO BE REFERENCED BY MODS
*/
static void executeAll_Login() {
if (API.login_tasks.entrySet().size() >= 1) {
API.println("Executing LoginPage Tasks..");
for (Map.Entry<String, Runnable> entry : API.login_tasks.entrySet()) {
API.println(String.format("Executing %s..", entry.getKey()));
entry.getValue().run();
}
}
}
/**
* This executes all of the Runnable's stored within API.desktop_tasks
*
* NOT TO BE REFERENCED BY MODS
*/
static void executeAll_Desktop() {
if (API.desktop_tasks.entrySet().size() >= 1) {
API.println("Executing Desktop Tasks..");
for (Map.Entry<String, Runnable> entry : API.desktop_tasks.entrySet()) {
API.println(String.format("Executing %s..", entry.getKey()));
entry.getValue().run();
}
}
}
/**
* This executes all of the Runnable's stored within API.desktop_tasks2
*
* NOT TO BE REFERENCED BY MODS
*/
static void executeAll_Desktop2() {
if (API.desktop_tasks2.entrySet().size() >= 1) {
API.println("Executing Secondary Desktop Tasks..");
for (Map.Entry<String, Runnable> entry : API.desktop_tasks2.entrySet()) {
API.println(String.format("Executing %s..", entry.getKey()));
entry.getValue().run();
}
}
}
/**
* This executes all of the Runnable's stored within API.shutdown_tasks
*
* NOT TO BE REFERENCED BY MODS
*/
static void executeShutdownTasks() {
if (API.shutdown_tasks.entrySet().size() >= 1) {
API.println("Executing Shutdown Tasks..");
for (Map.Entry<String, Runnable> entry : API.shutdown_tasks.entrySet()) {
API.println(String.format("Executing %s..", entry.getKey()));
entry.getValue().run();
}
}
}
private InCallProximityManager(Context context, final InCallManagerModule inCallManager) {
Log.d(TAG, "InCallProximityManager");
checkProximitySupport(context);
if (proximitySupported) {
proximitySensor = AppRTCProximitySensor.create(context,
new Runnable() {
@Override
public void run() {
inCallManager.onProximitySensorChangedState(proximitySensor.sensorReportsNearState());
}
}
);
}
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("comboBoxChanged")) {
}
Object o = e.getSource();
if (o instanceof Runnable) {
((Runnable) o).run();
}
}
/**
* Tests that a call to flush() processes the Futures that were generated by calls to put.
*/
@Test
public void testFlushWithNoPublishInPut() throws Exception {
task.start(props);
Map<TopicPartition, OffsetAndMetadata> partitionOffsets = new HashMap<>();
partitionOffsets.put(new TopicPartition(KAFKA_TOPIC, 0), null);
List<SinkRecord> records = getSampleRecords();
ApiFuture<String> goodFuture = getSuccessfulPublishFuture();
when(publisher.publish(any(PubsubMessage.class))).thenReturn(goodFuture);
task.put(records);
task.flush(partitionOffsets);
verify(publisher, times(2)).publish(any(PubsubMessage.class));
verify(goodFuture, times(2)).addListener(any(Runnable.class), any(Executor.class));
}
/**
* Tests that if a Future that is being processed in flush() failed with an exception, that an
* exception is thrown.
*/
@Test(expected = RuntimeException.class)
public void testFlushExceptionCase() throws Exception {
task.start(props);
Map<TopicPartition, OffsetAndMetadata> partitionOffsets = new HashMap<>();
partitionOffsets.put(new TopicPartition(KAFKA_TOPIC, 0), null);
List<SinkRecord> records = getSampleRecords();
ApiFuture<String> badFuture = getFailedPublishFuture();
when(publisher.publish(any(PubsubMessage.class))).thenReturn(badFuture);
task.put(records);
task.flush(partitionOffsets);
verify(publisher, times(1)).publish(any(PubsubMessage.class));
verify(badFuture, times(1)).addListener(any(Runnable.class), any(Executor.class));
}
@ReactMethod
public void start(final int delay) {
if (!wakeLock.isHeld()) wakeLock.acquire();
handler = new Handler();
runnable = new Runnable() {
@Override
public void run() {
sendEvent(reactContext, "backgroundTimer");
}
};
handler.post(runnable);
}
@ReactMethod
public void setTimeout(final int id, final int timeout) {
Handler handler = new Handler();
handler.postDelayed(new Runnable(){
@Override
public void run(){
if (getReactApplicationContext().hasActiveCatalystInstance()) {
getReactApplicationContext()
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("backgroundTimer.timeout", id);
}
}
}, timeout);
}
public void onVideoFragmentResume() {
if (isResumePlay() && mYouTubePlayer != null) {
// For some reason calling mYouTubePlayer.play() right away is ineffective
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
mYouTubePlayer.play();
}
}, 1);
}
}
public static void dispatchPendingRunnables() {
for (int i = RUNNABLES_PER_FRAME; i > 0; i--) {
Runnable job = jobs.poll();
if (job == null) {
return;
}
job.run();
}
}
public static void dispatchPendingRunnables() {
for (int i = RUNNABLES_PER_FRAME; i > 0; i--) {
Runnable job = jobs.poll();
if (job == null) {
return;
}
job.run();
}
}
public static void dispatchPendingRunnables() {
for (int i = RUNNABLES_PER_FRAME; i > 0; i--) {
Runnable job = jobs.poll();
if (job == null) {
return;
}
job.run();
}
}
private void publishRoutesInMainThread() {
Handler mainHandler = new Handler(this.getContext().getMainLooper());
mainHandler.post(new Runnable() {
@Override
public void run() {
publishRoutes();
}
});
}