public void begin() { while (running) { synchronized (tasks) { int count = tasks.size(); while (count < 10) { count++; Runnable task = taskMaster.buildNextTask(); if (task == null) break; tasks.add(task); } } try { Thread.sleep(1); }catch(Exception exception){} } }
public static void main(String[] args) throws Exception { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { try { JTextField textField = new JTextField(15); textField.setText("ม12345"); float noSpaceMin = textField.getUI().getRootView(textField) .getMinimumSpan(0); textField.getDocument().insertString(3, " ", null); if (noSpaceMin > textField.getUI().getRootView(textField) .getMinimumSpan(0)) { throw new RuntimeException( "Minimum span is calculated for wrapped text"); } } catch (BadLocationException e) { throw new RuntimeException(e); } } }); System.out.println("ok"); }
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); } } }); }
@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"); }
@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" + "}"); }
@Override public <T extends Runnable & Parcelable> void methodWithParcelableParam(T parcelable) throws RemoteException { Parcel data = Parcel.obtain(); Parcel reply = Parcel.obtain(); try { data.writeInterfaceToken(MethodTypeargParcelable$$AidlServerImpl.DESCRIPTOR); data.writeParcelable(parcelable, 0); delegate.transact(MethodTypeargParcelable$$AidlServerImpl.TRANSACT_methodWithParcelableParam, data, reply, 0); reply.readException(); } finally { data.recycle(); reply.recycle(); } }
public int test() { System.out.println("before"); run(new Runnable() { @Override public void run() { System.out.println("Runnable"); } }); test2("1"); if(Math.random() > 0) { System.out.println("0"); return 0; } else { System.out.println("1"); return 1; } }
public static void resetSystemUiVisibility(){ Handler handler = new Handler(); Runnable runnable = new Runnable(){ public void run() { if(currentMode == null) return; if(currentMode.equals("lowProfile")) { _setLowProfile(); } else if(currentMode.equals("immersive")) { _setImmersive(); } else if(currentMode.equals("statusBarColor")) { _setStatusBarColor(-1); } } }; handler.postDelayed(runnable, DELAY_TIME); }
@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); } }
private void scrollListViewToTaggedView(String tag) { final ListView listview = (ListView) findViewById(R.id.event_listview); final Integer index = idToViewIndexMap.get(tag); if (index != null) { View rowView = listview.getChildAt(index.intValue()); int h1 = listview.getHeight(); int h2 = 0; if (rowView != null) { h2 = rowView.getHeight(); } final int h = h1/2 - h2/2; runOnUiThread(new Runnable() { public void run() { listview.smoothScrollToPositionFromTop(index.intValue(), 0, 300); listview.setSelection(index.intValue()); } }); } }
@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); } }
public void foo() { Runnable r = new Runnable() { @Override public void run() { Comparable<Integer> c = new Comparable<Integer>() { @Override public int compareTo(Integer o) { return 0; } }; } }; class FooLocal { Runnable r = new Runnable() { @Override public void run() { } }; } }
static public void retrievePurchases() { GameActivity.getInstance().runOnUiThread ( new Runnable() { public void run() { try { singleton.mHelper.queryInventoryAsync(singleton.mGotInventoryListener); } catch(IllegalStateException ex){ singleton.mHelper.flagEndAsync(); } } } ); }
static public void initInterstitial(final String id, final String testDevice) { activity.runOnUiThread(new Runnable() { public void run() { if (activity == null) { return; } if(testDevice.length() > 0) { adTestMode = true; testDeviceID = testDevice; } else adTestMode = false; interstitial = new InterstitialAd(activity); interstitial.setAdUnitId(id); loadInterstitial(); } }); }
@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); } }
public Runnable next() { synchronized (tasks) { if (tasks.isEmpty()) return null; return tasks.removeFirst(); } }
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 method(final int i) { executor.execute(new Runnable() { @Override() public void run() { decorated.method(i); } }); }
@Override public void mother() { executor.execute(new Runnable() { @Override() public void run() { decorated.mother(); } }); }
@Override public void child() { executor.execute(new Runnable() { @Override() public void run() { decorated.child(); } }); }
@Override public void method(final int i, final Long l) { executor.execute(new Runnable() { @Override() public void run() { decorated.method(i, l); } }); }
@Override public void method() { executor.execute(new Runnable() { @Override() public void run() { decorated.method(); } }); }
@Override public void method() { executor.execute(new Runnable() { @Override() public void run() { final VoidMethodModule.VoidMethod decorated = weakReference.get(); if (decorated != null) { decorated.method(); } } }); }
@Override public void method() { executor.execute(new Runnable() { @Override() public void run() { if (decorated != null) { decorated.method(); } } }); }
@Override public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("comboBoxChanged")) { } Object o = e.getSource(); if (o instanceof Runnable) { ((Runnable) o).run(); } }
@ReactMethod public void start(final int delay) { 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); }
/** * @return An interface that completely ignores exceptions. Consider using this method withLogging() as well. */ default Runnable thatThrowsNothing() { return () -> { try { runWithThrowable(); } catch(Throwable ignored) {} }; }
/** * @throws E if an exception E has been thrown, it is rethrown by this method * @return An interface that is only returned if no exception has been thrown. */ default Runnable thatUnsafelyThrowsUnchecked() throws E { return () -> { try { runWithThrowable(); } catch(final Throwable throwable) { SuppressedException.throwUnsafelyAsUnchecked(throwable); } }; }
public static void main(String[] args) { Runnable runnable = new Runnable() { @Override public void run() { Set<String> test = new LinkedHashSet<String>(); if (test.contains("AA")) { if (test.contains("AS")) { System.out.println("AAAA!"); } } } }; runnable.run(); }
public void test() { run(new Runnable() { @Override public void run() { System.out.println("AAAA"); } }); }
private static void addShutdownHook() { Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { try { Logger.getLogger(Main.class.getName()).info("Server is shutting down"); ServerStaticComponents.server.stop(); } catch (Exception ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } } })); }