java.lang.Runnable Java Examples

The following examples show how to use java.lang.Runnable. 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: BackgroundColorModule.java    From react-native-background-color with The Unlicense 6 votes vote down vote up
@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);
    }
  });
}
 
Example #2
Source File: TypeSpecTest.java    From javapoet with Apache License 2.0 6 votes vote down vote up
@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");
}
 
Example #3
Source File: MenuActivity.java    From PTVGlass with MIT License 6 votes vote down vote up
@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);
    }
}
 
Example #4
Source File: MenuActivity.java    From PTVGlass with MIT License 6 votes vote down vote up
@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);
    }
}
 
Example #5
Source File: CompassMenuActivity.java    From PTVGlass with MIT License 6 votes vote down vote up
@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);
    }
}
 
Example #6
Source File: MenuActivity.java    From gdk-apidemo-sample with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #7
Source File: MenuActivity.java    From arcgis-runtime-demos-android with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #8
Source File: StyleableModelViewModel_.java    From epoxy with Apache License 2.0 6 votes vote down vote up
@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());
        }
      }
    } );
  }
}
 
Example #9
Source File: ModelViewWithParisModel_.java    From epoxy with Apache License 2.0 6 votes vote down vote up
@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());
        }
      }
    } );
  }
}
 
Example #10
Source File: InCallManagerModule.java    From react-native-incall-manager with ISC License 6 votes vote down vote up
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);
        }
    });
}
 
Example #11
Source File: InCallManagerModule.java    From react-native-incall-manager with ISC License 6 votes vote down vote up
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);
        }
    });
}
 
Example #12
Source File: CloudPubSubSinkTaskTest.java    From pubsub with Apache License 2.0 6 votes vote down vote up
/**
 * 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));
}
 
Example #13
Source File: InCallManagerModule.java    From react-native-incall-manager with ISC License 6 votes vote down vote up
@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);
            }
        }
    });
}
 
Example #14
Source File: SofaTracerRunnable.java    From sofa-tracer with Apache License 2.0 5 votes vote down vote up
private void initRunnable(Runnable wrappedRunnable, SofaTraceContext traceContext) {
    this.wrappedRunnable = wrappedRunnable;
    this.traceContext = traceContext;
    if (!traceContext.isEmpty()) {
        this.currentSpan = traceContext.getCurrentSpan();
    } else {
        this.currentSpan = null;
    }
}
 
Example #15
Source File: API.java    From exit_code_java with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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();
        }
    }
}
 
Example #16
Source File: InCallProximityManager.java    From flutter-incall-manager with ISC License 5 votes vote down vote up
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());               
                }
            }
        );
    }
}
 
Example #17
Source File: CloudPubSubSinkTaskTest.java    From pubsub with Apache License 2.0 5 votes vote down vote up
/**
 * 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));
}
 
Example #18
Source File: API.java    From exit_code_java with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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();
        }
    }
}
 
Example #19
Source File: InCallProximityManager.java    From react-native-incall-manager with ISC License 5 votes vote down vote up
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());               
                }
            }
        );
    }
}
 
Example #20
Source File: API.java    From exit_code_java with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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();
        }
    }
}
 
Example #21
Source File: TransitionsPanel.java    From iBioSim with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
	if (e.getActionCommand().equals("comboBoxChanged")) {

	}
	Object o = e.getSource();
	if (o instanceof Runnable) {
		((Runnable) o).run();
	}
}
 
Example #22
Source File: CloudPubSubSinkTaskTest.java    From pubsub with Apache License 2.0 5 votes vote down vote up
/**
 * 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));
}
 
Example #23
Source File: BackgroundTimerModule.java    From react-native-background-timer with MIT License 5 votes vote down vote up
@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);
}
 
Example #24
Source File: BackgroundTimerModule.java    From react-native-background-timer with MIT License 5 votes vote down vote up
@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);
}
 
Example #25
Source File: YouTubePlayerController.java    From react-native-youtube with MIT License 5 votes vote down vote up
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);
    }
}
 
Example #26
Source File: Cocos2dxHelper.java    From Example-of-Cocos2DX with MIT License 5 votes vote down vote up
public static void dispatchPendingRunnables() {
	for (int i = RUNNABLES_PER_FRAME; i > 0; i--) {
		Runnable job = jobs.poll();
		if (job == null) {
			return;
		}
		job.run();
	}
}
 
Example #27
Source File: Cocos2dxHelper.java    From Example-of-Cocos2DX with MIT License 5 votes vote down vote up
public static void dispatchPendingRunnables() {
	for (int i = RUNNABLES_PER_FRAME; i > 0; i--) {
		Runnable job = jobs.poll();
		if (job == null) {
			return;
		}
		job.run();
	}
}
 
Example #28
Source File: Cocos2dxHelper.java    From Earlybird with Apache License 2.0 5 votes vote down vote up
public static void dispatchPendingRunnables() {
	for (int i = RUNNABLES_PER_FRAME; i > 0; i--) {
		Runnable job = jobs.poll();
		if (job == null) {
			return;
		}
		job.run();
	}
}
 
Example #29
Source File: CastMediaRouteProvider.java    From android_packages_apps_GmsCore with Apache License 2.0 5 votes vote down vote up
private void publishRoutesInMainThread() {
    Handler mainHandler = new Handler(this.getContext().getMainLooper());
    mainHandler.post(new Runnable() {
        @Override
        public void run() {
            publishRoutes();
        }
    });
}
 
Example #30
Source File: TypeSpecTest.java    From javapoet with Apache License 2.0 5 votes vote down vote up
@Test public void anonymousClassToString() throws Exception {
  TypeSpec type = TypeSpec.anonymousClassBuilder("")
      .addSuperinterface(Runnable.class)
      .addMethod(MethodSpec.methodBuilder("run")
          .addAnnotation(Override.class)
          .addModifiers(Modifier.PUBLIC)
          .build())
      .build();
  assertThat(type.toString()).isEqualTo(""
      + "new java.lang.Runnable() {\n"
      + "  @java.lang.Override\n"
      + "  public void run() {\n"
      + "  }\n"
      + "}");
}