List of usage examples for android.os Handler Handler
@UnsupportedAppUsage public Handler(boolean async)
From source file:com.lovejoy777sarootool.rootool.fragments.BrowserFragment.java
@Override public void onAttach(final Activity activity) { super.onAttach(activity); mObserverCache = FileObserverCache.getInstance(); mActionController = new ActionModeController(activity); if (sHandler == null) { sHandler = new Handler(activity.getMainLooper()); }//ww w . ja va 2 s.c o m try { mUpdatePathListener = (onUpdatePathListener) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement mUpdatePathListener"); } }
From source file:org.projectbuendia.client.diagnostics.PackageServerHealthCheck.java
@Override protected void startImpl() { synchronized (mLock) { if (mHandlerThread == null) { mHandlerThread = new HandlerThread("Buendia Package Server Health Check"); mHandlerThread.start();// w w w.j a v a 2s. c om mHandler = new Handler(mHandlerThread.getLooper()); mHandler.post(mHealthCheckRunnable); } } }
From source file:cn.edu.gdmec.t00385.lightsensor.LightSensorListener.java
/** * Executes the request and returns PluginResult. * * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackS=Context The callback id used when calling back into JavaScript. * @return True if the action was valid. * @throws JSONException /*from ww w . j a v a 2 s .co m*/ */ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if (action.equals("start")) { this.start(); } else if (action.equals("stop")) { this.stop(); } else if (action.equals("getStatus")) { int i = this.getStatus(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, i)); } else if (action.equals("getLumen")) { // If not running, then this is an async call, so don't worry about waiting if (this.status != LightSensorListener.RUNNING) { int r = this.start(); if (r == LightSensorListener.ERROR_FAILED_TO_START) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, LightSensorListener.ERROR_FAILED_TO_START)); return true; } // Set a timeout callback on the main thread. Handler handler = new Handler(Looper.getMainLooper()); handler.postDelayed(new Runnable() { public void run() { LightSensorListener.this.timeout(); } }, 2000); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, getCompassHeading())); } else if (action.equals("setTimeout")) { this.setTimeout(args.getLong(0)); } else if (action.equals("getTimeout")) { long l = this.getTimeout(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, l)); } else { // Unsupported action return false; } return true; }
From source file:com.nuvolect.securesuite.data.SqlSyncTest.java
/** * Test the network performance between this device and a companion device. * CONCEPT://from w w w . j a va 2s. com * A package is constructed of minimal size and sent to the companion device. * The companion tests the package for integrity and if successful, creates a larger package and sends it back. * The process is continued until communications fail. * * TODO complete ping pong test. Show running data rate, success and failure. * * @param ctx * @return */ public JSONObject ping_test(final Context ctx) { managePayloadSize(); /** * Build the payload and generate MD5 */ Map<String, String> params = makeParameters(); params.put(CConst.CMD, SyncRest.CMD.ping_test.toString()); params.put(CConst.COUNTER, String.valueOf(++ping_counter)); String url = WebUtil.getCompanionServerUrl(CConst.SYNC); startTime = System.currentTimeMillis(); Comm.sendPost(ctx, url, params, new Comm.CommPostCallbacks() { @Override public void success(String response) { LogUtil.log(LogUtil.LogType.SQL_SYNC_TEST, SyncRest.CMD.ping_test + " response: " + response); if (WebUtil.responseMatch(response, CConst.RESPONSE_CODE_SUCCESS_100)) { if (m_pingPongCallbacks != null) { Handler handler = new Handler(Looper.getMainLooper()); Runnable r = new Runnable() { @Override public void run() { m_pingPongCallbacks.progressUpdate(m_pingPongCallbacksAct, ping_counter, pong_counter, payloadSize); if (!m_continueTest) m_pingPongCallbacks.cancelDialog(m_pingPongCallbacksAct); } }; handler.post(r); } /** * To alternate volleys, pong is kicked off by the response sender * versus the machine receiving the response * * if( m_continueTest) WorkerCommand.quePongTest(ctx); */ } } @Override public void fail(String error) { LogUtil.log(LogUtil.LogType.SQL_SYNC_TEST, SyncRest.CMD.ping_test + " error: " + error); } }); if (m_continueTest) return WebUtil.response(CConst.RESPONSE_CODE_SUCCESS_100); else return WebUtil.response(CConst.RESPONSE_CODE_USER_CANCEL_102); }
From source file:com.wbtech.ums.UmsAgent.java
private UmsAgent() { HandlerThread localHandlerThread = new HandlerThread("UmsAgent"); localHandlerThread.start();//from w ww . j a v a 2s . com this.handler = new Handler(localHandlerThread.getLooper()); }
From source file:com.googlecode.android_scripting.facade.AndroidFacade.java
public AndroidFacade(FacadeManager manager) { super(manager); mService = manager.getService();// ww w.j a va2s . co m mIntent = manager.getIntent(); BaseApplication application = ((BaseApplication) mService.getApplication()); mTaskQueue = application.getTaskExecutor(); mHandler = new Handler(mService.getMainLooper()); mVibrator = (Vibrator) mService.getSystemService(Context.VIBRATOR_SERVICE); mNotificationManager = (NotificationManager) mService.getSystemService(Context.NOTIFICATION_SERVICE); mResources = manager.getAndroidFacadeResources(); }
From source file:com.cyanogenmod.effem.FmRadio.java
/** * Required method from parent class/*from w ww . j ava 2 s . co m*/ * * @param icicle - The previous instance of this app */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); context = getApplicationContext(); setContentView(R.layout.main); // restore preferences SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); mSelectedBand = settings.getInt("selectedBand", 1); mCurrentFrequency = settings.getInt("currentFrequency", 0); if (context.getResources().getBoolean(R.bool.speaker_supported)) { mSelectedOutput = settings.getInt("selectedOutput", 0) > 0 ? 1 : 0; } // misc setup setVolumeControlStream(AudioManager.STREAM_MUSIC); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // worker thread for async execution of FM stuff mWorker = new HandlerThread("EffemWorker"); mWorker.start(); mWorkerHandler = new Handler(mWorker.getLooper()); // ui preparations setupButtons(); }
From source file:com.google.android.apps.muzei.featuredart.FeaturedArtSource.java
@Override protected void onCustomCommand(int id) { super.onCustomCommand(id); if (COMMAND_ID_SHARE == id) { Artwork currentArtwork = getCurrentArtwork(); if (currentArtwork == null) { LOGW(TAG, "No current artwork, can't share."); new Handler(Looper.getMainLooper()).post(new Runnable() { @Override//w ww . jav a 2 s .c o m public void run() { Toast.makeText(FeaturedArtSource.this, R.string.featuredart_source_error_no_artwork_to_share, Toast.LENGTH_SHORT).show(); } }); return; } String detailUrl = ("initial".equals(currentArtwork.getToken())) ? "http://www.wikipaintings.org/en/vincent-van-gogh/the-starry-night-1889" : currentArtwork.getViewIntent().getDataString(); String artist = currentArtwork.getByline().replaceFirst("\\.\\s*($|\\n).*", "").trim(); Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("text/plain"); shareIntent.putExtra(Intent.EXTRA_TEXT, "My Android wallpaper today is '" + currentArtwork.getTitle().trim() + "' by " + artist + ". #MuzeiFeaturedArt\n\n" + detailUrl); shareIntent = Intent.createChooser(shareIntent, "Share artwork"); shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(shareIntent); } else if (COMMAND_ID_DEBUG_INFO == id) { long nextUpdateTimeMillis = getSharedPreferences().getLong("scheduled_update_time_millis", 0); final String nextUpdateTime; if (nextUpdateTimeMillis > 0) { Date d = new Date(nextUpdateTimeMillis); nextUpdateTime = SimpleDateFormat.getDateTimeInstance().format(d); } else { nextUpdateTime = "None"; } new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { Toast.makeText(FeaturedArtSource.this, "Next update time: " + nextUpdateTime, Toast.LENGTH_LONG) .show(); } }); } }
From source file:com.connectsdk.discovery.provider.CastDiscoveryProvider.java
private void sendSearch() { List<String> killKeys = new ArrayList<String>(); long killPoint = new Date().getTime() - SSDP_TIMEOUT; for (String key : foundServices.keySet()) { ServiceDescription service = foundServices.get(key); if (service == null || service.getLastDetection() < killPoint) { killKeys.add(key);/*from ww w.j ava 2s . c om*/ } } for (String key : killKeys) { final ServiceDescription service = foundServices.get(key); if (service != null) { Util.runOnUI(new Runnable() { @Override public void run() { for (DiscoveryProviderListener listener : serviceListeners) { listener.onServiceRemoved(CastDiscoveryProvider.this, service); } } }); } if (foundServices.containsKey(key)) foundServices.remove(key); } new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback, MediaRouter.CALLBACK_FLAG_PERFORM_ACTIVE_SCAN); } }); }