Java Code Examples for android.os.Handler.post()

The following are Jave code examples for showing how to use post() of the android.os.Handler class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: https-github.com-hyb1996-NoRootScriptDroid   File: Shell.java   View Source Code Vote up 7 votes
@Override
protected void init(final String initialCommand) {
    Handler uiHandler = new Handler(mContext.getMainLooper());
    uiHandler.post(new Runnable() {
        @Override
        public void run() {
            TermSettings settings = new TermSettings(mContext.getResources(), PreferenceManager.getDefaultSharedPreferences(mContext));
            try {
                mTermSession = new MyShellTermSession(settings, initialCommand);
                mTermSession.initializeEmulator(1024, 40);
            } catch (IOException e) {
                mInitException = new UncheckedIOException(e);
            }
        }
    });
}
 
Example 2
Project: home-assistant-android   File: HassEntities.java   View Source Code Vote up 6 votes
private WebSocket.StringCallback getStringCallback() {
    return new WebSocket.StringCallback(){
        public void onStringAvailable(String s){
            try {
                final JSONObject row = new JSONObject(s);
                Runnable dispatchState = new Runnable() {
                    @Override
                    public void run() {
                        processData(row);
                    }
                };
                Handler mainHandler = new Handler(context.getMainLooper());
                mainHandler.post(dispatchState);
            } catch (JSONException e) {}
        }
    };
}
 
Example 3
Project: GeekZone   File: ExecutorDelivery.java   View Source Code Vote up 5 votes
/**
 * Creates a new response delivery interface.
 * @param handler {@link Handler} to post responses on
 */
public ExecutorDelivery(final Handler handler) {
    // Make an Executor that just wraps the handler.
    mResponsePoster = new Executor() {
        @Override
        public void execute(Runnable command) {
            handler.post(command);
        }
    };
}
 
Example 4
Project: EvilsLive   File: CameraOld.java   View Source Code Vote up 5 votes
private void runMainHanlder(final Camera.Size previewSize) {
    Handler mainHanlder = new Handler(Looper.getMainLooper());
    mainHanlder.post(new Runnable() {
        @Override
        public void run() {
            adjustViewSize(previewSize);
        }
    });
}
 
Example 5
Project: letv   File: LoadAndDisplayImageTask.java   View Source Code Vote up 5 votes
static void runTask(Runnable r, boolean sync, Handler handler, ImageLoaderEngine engine) {
    if (sync) {
        r.run();
    } else if (handler == null) {
        engine.fireCallback(r);
    } else {
        handler.post(r);
    }
}
 
Example 6
Project: boxing   File: BoxingExecutor.java   View Source Code Vote up 5 votes
public void runUI(@NonNull Runnable runnable) {
    if (Looper.myLooper() == Looper.getMainLooper()) {
        runnable.run();
        return;
    }
    Handler handler = ensureUiHandlerNotNull();
    try {
        handler.post(runnable);
    } catch (Exception e) {
        BoxingLog.d("update UI task fail. " + e.getMessage());
    }
}
 
Example 7
Project: AOSP-Kayboard-7.1.2   File: DictionaryDownloadProgressBar.java   View Source Code Vote up 5 votes
public void setProgressFromAnotherThread(final int progress) {
    if (mProgress != progress) {
        mProgress = progress;
        // For some unknown reason, setProgress just does not work from a separate
        // thread, although the code in ProgressBar looks like it should. Thus, we
        // resort to a runnable posted to the handler of the view.
        final Handler handler = getHandler();
        // It's possible to come here before this view has been laid out. If so,
        // just ignore the call - it will be updated again later.
        if (null == handler) return;
        handler.post(this);
    }
}
 
Example 8
Project: boohee_v5.6   File: DownloadStatusDeliveryImpl.java   View Source Code Vote up 5 votes
public DownloadStatusDeliveryImpl(final Handler handler) {
    this.mDownloadStatusPoster = new Executor() {
        public void execute(Runnable command) {
            handler.post(command);
        }
    };
}
 
Example 9
Project: buildAPKsSamples   File: InputManagerV9.java   View Source Code Vote up 5 votes
private void notifyListeners(int why, int deviceId) {
    // the state of some device has changed
    if (!mListeners.isEmpty()) {
        // yes... this will cause an object to get created... hopefully
        // it won't happen very often
        for (InputDeviceListener listener : mListeners.keySet()) {
            Handler handler = mListeners.get(listener);
            DeviceEvent odc = DeviceEvent.getDeviceEvent(why, deviceId, listener);
            handler.post(odc);
        }
    }
}
 
Example 10
Project: OpenVideoCall-Android   File: BaseActivity.java   View Source Code Vote up 5 votes
public void openIME(final EditText v) {
    final boolean focus = v.requestFocus();
    if (v.hasFocus()) {
        final Handler handler = new Handler(Looper.getMainLooper());
        handler.post(new Runnable() {
            @Override
            public void run() {
                InputMethodManager mgr = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
                boolean result = mgr.showSoftInput(v, InputMethodManager.SHOW_FORCED);
                log.debug("openIME " + focus + " " + result);
            }
        });
    }
}
 
Example 11
Project: react-native-apptentive-module   File: RNApptentiveModule.java   View Source Code Vote up 5 votes
@ReactMethod
public void addPersonDataBool(final Boolean bool, final String key, final Promise promise)
{
	if (!_initialised)
	{
		promise.reject(APPTENTIVE, "Apptentive is not initialised");
		return;
	}
	if (bool == null)
	{
		promise.reject(APPTENTIVE, "Your bool is empty");
		return;
	}
	if (key == null || key.isEmpty())
	{
		promise.reject(APPTENTIVE, "Your key is empty");
		return;
	}

	Handler handler = new Handler(_application.getMainLooper());
	Runnable runnable = new Runnable()
	{
		@Override
		public void run()
		{
			Apptentive.addCustomPersonData(key, bool);
			promise.resolve(true);
		}
	};
	handler.post(runnable);
}
 
Example 12
Project: PlusGram   File: ExecutorDelivery.java   View Source Code Vote up 5 votes
/**
 * Creates a new response delivery interface.
 * @param handler {@link Handler} to post responses on
 */
public ExecutorDelivery(final Handler handler) {
    // Make an Executor that just wraps the handler.
    mResponsePoster = new Executor() {
        @Override
        public void execute(Runnable command) {
            handler.post(command);
        }
    };
}
 
Example 13
Project: MyMap   File: PiclocationActivity.java   View Source Code Vote up 5 votes
/**
 * marker点击时跳动一下
 */
public void jumpPoint(final Marker marker) {
    final Handler handler = new Handler();
    final long start = SystemClock.uptimeMillis();
    //获取地图投影坐标转换器
    Projection proj = amap.getProjection();
    final LatLng markerLatlng = marker.getPosition();
    Point markerPoint = proj.toScreenLocation(markerLatlng);
    markerPoint.offset(0, -50);
    final LatLng startLatLng = proj.fromScreenLocation(markerPoint);
    final long duration = 500;

    final Interpolator interpolator = new BounceInterpolator();
    handler.post(new Runnable() {
        @Override
        public void run() {
            long elapsed = SystemClock.uptimeMillis() - start;
            float t = interpolator.getInterpolation((float) elapsed
                    / duration);
            double lng = t * markerLatlng.longitude + (1 - t)
                    * startLatLng.longitude;
            double lat = t * markerLatlng.latitude + (1 - t)
                    * startLatLng.latitude;
            marker.setPosition(new LatLng(lat, lng));
            if (t < 1.0) {
                handler.postDelayed(this, 16);
            }
        }
    });
}
 
Example 14
Project: AndroidSnooper   File: AndroidSnooper.java   View Source Code Vote up 5 votes
public void record(final HttpCall httpCall) throws IOException {
  Handler handler = new Handler(context.getMainLooper());
  handler.post(new Runnable() {
    @Override
    public void run() {
      AndroidSnooper.this.snooperRepo.save(HttpCallRecord.from(httpCall));
    }
  });
}
 
Example 15
Project: ImageLoaderSupportGif   File: LoadAndDisplayImageTask.java   View Source Code Vote up 5 votes
static void runTask(Runnable r, boolean sync, Handler handler, ImageLoaderEngine engine) {
    if (sync) {
        r.run();
    } else if (handler == null) {
        engine.fireCallback(r);
    } else {
        handler.post(r);
    }
}
 
Example 16
Project: react-native-apptentive-module   File: RNApptentiveModule.java   View Source Code Vote up 5 votes
@ReactMethod
public void addDeviceDataNumber(final Number number, final String key, final Promise promise)
{
	if (!_initialised)
	{
		promise.reject(APPTENTIVE, "Apptentive is not initialised");
		return;
	}
	if (number == null)
	{
		promise.reject(APPTENTIVE, "Your number is empty");
		return;
	}
	if (key == null || key.isEmpty())
	{
		promise.reject(APPTENTIVE, "Your key is empty");
		return;
	}

	Handler handler = new Handler(_application.getMainLooper());
	Runnable runnable = new Runnable()
	{
		@Override
		public void run()
		{
			Apptentive.addCustomDeviceData(key, number);
			promise.resolve(true);
		}
	};
	handler.post(runnable);
}
 
Example 17
Project: mapbook-android   File: DownloadPresenter.java   View Source Code Vote up 5 votes
/**
 * Update mobile map package with latest version
 */
@Override public void update() {
  //Check for valid credentials

  final String credentialString;
  try {
    credentialString = mCredentialCryptographer.decrypt();
    if (credentialString != null && credentialString.length() > 0 ){
      Log.i(TAG,"Downloading with cached credentials");

      // Rehydrate the credential cache from the decrypted file
      AuthenticationManager.CredentialCache.restoreFromJson(credentialString);

      //Kick off a thread to handle mobile map package download
      final Handler handler = new Handler() ;
      handler.post(new Runnable() {
        @Override public void run() {
          // Download map book
          downloadMapbook();
        }
      });
    }else{
      // If credentials are null, we'll prompt user for credentials
      Log.i(TAG,"Credential cache cannot be reconstituted from null credentials, so asking using to provide credentials...");
      signIn();
    }
  } catch (Exception e) {
    Log.e(TAG, e.getClass().getSimpleName() + " " + e.getMessage());
    if (e.getCause() != null){
      Log.e(TAG, e.getCause().getMessage());
    }
  }


}
 
Example 18
Project: Amazing   File: SendFlowersActivity.java   View Source Code Vote up 5 votes
private void startA() {
    flowerGiftView.startAnim(5);
    Handler handler = new Handler(getMainLooper());
    handler.post(new Runnable() {
        @Override
        public void run() {

        }
    });
}
 
Example 19
Project: react-native-apptentive-module   File: RNApptentiveModule.java   View Source Code Vote up 5 votes
@ReactMethod
public void presentMessageCenterWithCustomData(ReadableMap customData, final Promise promise)
{
	if (customData == null)
	{
		this.presentMessageCenter(promise);
		return;
	}
	if (!_initialised)
	{
		promise.reject(APPTENTIVE, "Apptentive is not initialised");
		return;
	}
	if (!Apptentive.canShowMessageCenter())
	{
		promise.reject(APPTENTIVE, "Apptentive message center can't be shown");
		return;
	}
	if (!(customData instanceof ReadableNativeMap))
	{
		promise.reject(APPTENTIVE, "Apptentive can't handle this customData");
		return;
	}

	ReadableNativeMap nativeMap = (ReadableNativeMap) customData;
	final HashMap<String, Object> hashMap = nativeMap.toHashMap();

	Handler handler = new Handler(_application.getMainLooper());
	Runnable runnable = new Runnable()
	{
		@Override
		public void run()
		{
			boolean shown = Apptentive.showMessageCenter(getReactApplicationContext(), hashMap);
			promise.resolve(shown);
		}
	};
	handler.post(runnable);
}
 
Example 20
Project: appinventor-extensions   File: NxtColorSensor.java   View Source Code Vote up 4 votes
/**
 * Creates a new NxtColorSensor component.
 */
public NxtColorSensor(ComponentContainer container) {
  super(container, "NxtColorSensor");
  handler = new Handler();
  previousState = State.UNKNOWN;
  previousColor = Component.COLOR_NONE;
  sensorReader = new Runnable() {
    public void run() {
      if (bluetooth != null && bluetooth.IsConnected()) {
        if (detectColor) {
          // Detecting color
          SensorValue<Integer> sensorValue = getColorValue("");
          if (sensorValue.valid) {
            int currentColor = sensorValue.value;

            if (currentColor != previousColor) {
              ColorChanged(currentColor);
            }

            previousColor = currentColor;
          }

        } else {
          // Detecting light
          SensorValue<Integer> sensorValue = getLightValue("");
          if (sensorValue.valid) {
            State currentState;
            if (sensorValue.value < bottomOfRange) {
              currentState = State.BELOW_RANGE;
            } else if (sensorValue.value > topOfRange) {
              currentState = State.ABOVE_RANGE;
            } else {
              currentState = State.WITHIN_RANGE;
            }

            if (currentState != previousState) {
              if (currentState == State.BELOW_RANGE && belowRangeEventEnabled) {
                BelowRange();
              }
              if (currentState == State.WITHIN_RANGE && withinRangeEventEnabled) {
                WithinRange();
              }
              if (currentState == State.ABOVE_RANGE && aboveRangeEventEnabled) {
                AboveRange();
              }
            }

            previousState = currentState;
          }
        }
      }
      if (isHandlerNeeded()) {
        handler.post(sensorReader);
      }
    }
  };

  SensorPort(DEFAULT_SENSOR_PORT);

  // Detecting color
  DetectColor(true);
  ColorChangedEventEnabled(false);

  // Detecting light
  BottomOfRange(DEFAULT_BOTTOM_OF_RANGE);
  TopOfRange(DEFAULT_TOP_OF_RANGE);
  BelowRangeEventEnabled(false);
  WithinRangeEventEnabled(false);
  AboveRangeEventEnabled(false);
  GenerateColor(Component.COLOR_NONE);
}