本文整理汇总了Java中android.os.Handler.sendMessageDelayed方法的典型用法代码示例。如果您正苦于以下问题:Java Handler.sendMessageDelayed方法的具体用法?Java Handler.sendMessageDelayed怎么用?Java Handler.sendMessageDelayed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.os.Handler
的用法示例。
在下文中一共展示了Handler.sendMessageDelayed方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import android.os.Handler; //导入方法依赖的package包/类
private void init() {
handler = new Handler(getLooper()) {
@Override
public void handleMessage(Message msg) {
switch (msg.what){
case CHECK_HITALK_CONVERSATION:
MonitorEvent monitorEvent = (MonitorEvent) msg.obj;
Message newMsg = new Message();
newMsg.copyFrom(msg);
if (!monitorEvent.check()) {
IMMEDIATE_TIMES ++;
monitorEvent.run();
handler.sendMessageDelayed(newMsg,
LOOP_IMMEDIATE + (IMMEDIATE_TIMES / 3) * LOOP_INCREAMENT);
} else {
IMMEDIATE_TIMES = 0;
handler.sendMessageDelayed(newMsg,
LOOP_TIME);
}
break;
}
}
};
}
示例2: onCreate
import android.os.Handler; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Handler handler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
if(msg.what == DELAYED_MESSAGE) {
UpdateScreenBrightness.this.finish();
}
return false;
}
});
Intent brightnessIntent = this.getIntent();
float brightness = brightnessIntent.getFloatExtra("brightness value", 0);
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = brightness;
getWindow().setAttributes(lp);
Message message = handler.obtainMessage(DELAYED_MESSAGE);
//this next line is very important, you need to finish your activity with slight delay
handler.sendMessageDelayed(message,1);
}
示例3: removeNotificationsForSMS
import android.os.Handler; //导入方法依赖的package包/类
public void removeNotificationsForSMS(String smsPackage, String from, String address, String displayAddress, String body, long timestamp) {
if (!this.keepNotificationsInDrawer) {
final String str = smsPackage;
final String str2 = from;
final String str3 = address;
final String str4 = displayAddress;
final String str5 = body;
final long j = timestamp;
Handler handler = new Handler() {
public void handleMessage(Message msg) {
Intent i = new Intent(NotificationService.INTENT_ACTION_CMDS);
i.putExtra("command", NotificationService.CMD_REMOVE_SMS);
i.putExtra(NotificationService.KEY_SMS_PACKAGE, str);
i.putExtra(NotificationService.KEY_SMS_FROM, str2);
i.putExtra(NotificationService.KEY_SMS_ADDRESS, str3);
i.putExtra(NotificationService.KEY_SMS_DISPLAY_ADDRESS, str4);
i.putExtra(NotificationService.KEY_SMS_BODY, str5);
i.putExtra(NotificationService.KEY_SMS_TIMESTAMP, j);
NotificationManager.this.context.sendBroadcast(i);
}
};
handler.sendMessageDelayed(handler.obtainMessage(), 3000);
}
}
示例4: removeNotification
import android.os.Handler; //导入方法依赖的package包/类
void removeNotification(Notification notification) {
final String packageName = notification.getPackageName();
final String tag = notification.getTag();
final int id = notification.getId();
final String key = notification.getKey();
long delay = REMOVE_NOTIFICATION_DELAY;
if (VERSION.SDK_INT >= 21 && notification.getPriority() >= 1) {
delay = SHORT_REMOVE_NOTIFICATION_DELAY;
}
Handler handler = new Handler() {
public void handleMessage(Message msg) {
Intent i = new Intent(NotificationService.INTENT_ACTION_CMDS);
i.putExtra("command", NotificationService.CMD_REMOVE);
i.putExtra(NotificationService.KEY_NOTIFICATION_PACKAGE, packageName);
i.putExtra(NotificationService.KEY_NOTIFICATION_TAG, tag);
i.putExtra(NotificationService.KEY_NOTIFICATION_ID, id);
i.putExtra(NotificationService.KEY_NOTIFICATION_KEY, key);
NotificationManager.this.context.sendBroadcast(i);
}
};
handler.sendMessageDelayed(handler.obtainMessage(), delay);
}
示例5: flushStackLocalLeaks
import android.os.Handler; //导入方法依赖的package包/类
/**
* Prior to Android 5, HandlerThread always keeps a stack local reference to the last message
* that was sent to it. This method makes sure that stack local reference never stays there
* for too long by sending new messages to it every second.
*/
static void flushStackLocalLeaks(Looper looper) {
Handler handler = new Handler(looper) {
@Override public void handleMessage(Message msg) {
sendMessageDelayed(obtainMessage(), THREAD_LEAK_CLEANING_MS);
}
};
handler.sendMessageDelayed(handler.obtainMessage(), THREAD_LEAK_CLEANING_MS);
}
示例6: TipViewController
import android.os.Handler; //导入方法依赖的package包/类
private TipViewController(Context application) {
mContext = application;
mWindowManager = (WindowManager) application.getSystemService(Context.WINDOW_SERVICE);
mainHandler=new Handler(Looper.getMainLooper()){
@Override
public void handleMessage(Message msg) {
switch (msg.what){
case MOVETOEDGE:
int desX= (int) msg.obj;
if (desX==0){
layoutParams.x= (int) (layoutParams.x - density*10);
if (layoutParams.x<0){
layoutParams.x=0;
}
}else {
layoutParams.x= (int) (layoutParams.x + density*10);
if (layoutParams.x>desX){
layoutParams.x=desX;
}
}
updateViewPosition(layoutParams.x,layoutParams.y);
if (layoutParams.x!=desX) {
mainHandler.sendMessageDelayed(mainHandler.obtainMessage(MOVETOEDGE, desX),10);
}else {
isMovingToEdge = false;
}
break;
}
}
};
}
示例7: notifyRootCompleted
import android.os.Handler; //导入方法依赖的package包/类
public void notifyRootCompleted(List<String> output) {
if (handlerReference != null) {
Handler handler = handlerReference.get();
if (handler != null) {
Message message = handler.obtainMessage(BreventActivity.MESSAGE_ROOT_COMPLETED,
output);
handler.sendMessageDelayed(message, 0x400);
}
handlerReference = null;
}
}
示例8: flushStackLocalLeaks
import android.os.Handler; //导入方法依赖的package包/类
static void flushStackLocalLeaks(Looper looper) {
Handler handler = new Handler(looper) {
@Override public void handleMessage(Message msg) {
sendMessageDelayed(obtainMessage(), THREAD_LEAK_CLEANING_MS);
}
};
handler.sendMessageDelayed(handler.obtainMessage(), THREAD_LEAK_CLEANING_MS);
}
示例9: onTouch
import android.os.Handler; //导入方法依赖的package包/类
/**
* Called when a touch event is dispatched to a view. This allows listeners to
* get a chance to respond before the target view.
*
* @param v The view the touch event has been dispatched to.
* @param event The MotionEvent object containing full information about
* the event.
* @return True if the listener has consumed the event, false otherwise.
*/
@Override
public boolean onTouch(final View v, MotionEvent event) {
if (MotionEvent.ACTION_DOWN == event.getAction()) {
count++;
if (count == 1) {
Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what){
case HANDLER_ON_CLICK:{
if(count == 1){
count = 0;
onClick(v);
}
}break;
}
}
};
Message m = Message.obtain(handler);
m.what = HANDLER_ON_CLICK;
handler.sendMessageDelayed(m, 200);
/**事件没有被消费完*/
return false;
} else if (count == 2) {
count = 0;
onDoubleClick(v);
/**事件不再往下面传递*/
return true;
}
}
return false;
}
示例10: ArcTipViewController
import android.os.Handler; //导入方法依赖的package包/类
private ArcTipViewController(Context application) {
mContext = application;
mWindowManager = (WindowManager) application.getSystemService(Context.WINDOW_SERVICE);
MAX_LENGTH = DEFAULT_MAX_LENGTH *SPHelper.getFloat(ConstantUtil.FLOATVIEW_SIZE,100)/ 100f;
MIN_LENGTH = DEFAULT_MIN_LENGTH *SPHelper.getFloat(ConstantUtil.FLOATVIEW_SIZE,100)/ 100f;
int resourceId = application.getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
mStatusBarHeight = application.getResources().getDimensionPixelSize(resourceId);
}
mainHandler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message msg) {
synchronized (ArcTipViewController.this) {
switch (msg.what) {
case MOVETOEDGE:
int desX = (int) msg.obj;
if (desX == 0) {
layoutParams.x = (int) (layoutParams.x - density * 10);
if (layoutParams.x < 0) {
layoutParams.x = 0;
}
} else {
layoutParams.x = (int) (layoutParams.x + density * 10);
if (layoutParams.x > desX) {
layoutParams.x = desX;
}
}
updateViewPosition(layoutParams.x, layoutParams.y);
if (layoutParams.x != desX) {
mainHandler.sendMessageDelayed(mainHandler.obtainMessage(MOVETOEDGE, desX), 10);
} else {
isMovingToEdge = false;
if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) {
SPHelper.save(ConstantUtil.FLOAT_VIEW_PORT_X, layoutParams.x);
SPHelper.save(ConstantUtil.FLOAT_VIEW_PORT_Y, layoutParams.y);
} else {
SPHelper.save(ConstantUtil.FLOAT_VIEW_LAND_X, layoutParams.x);
SPHelper.save(ConstantUtil.FLOAT_VIEW_LAND_Y, layoutParams.y);
}
}
break;
case HIDETOEDGE:
if (layoutParams.x <= mScaledTouchSlop && ((layoutParams.gravity & (Gravity.TOP | Gravity.LEFT)) == (Gravity.TOP | Gravity.LEFT))) {
floatImageView.setImageDrawable(mContext.getResources().getDrawable(R.mipmap.floatview_hide_left));
} else {
floatImageView.setImageDrawable(mContext.getResources().getDrawable(R.mipmap.floatview_hide_right));
}
iconFloatView.setOnTouchListener(ArcTipViewController.this);
acrFloatView.setOnTouchListener(ArcTipViewController.this);
floatImageView.setContentDescription(mContext.getString(R.string.float_view_hide));
LinearLayout.LayoutParams layoutParams_ = (LinearLayout.LayoutParams) floatImageView.getLayoutParams();
layoutParams_.width = (int) ((int) ViewUtil.dp2px(DEFAULT_MIN_WIDTH_HIDE)*SPHelper.getFloat(ConstantUtil.FLOATVIEW_SIZE,100)/ 100f);
layoutParams_.height = (int) ViewUtil.dp2px(MIN_LENGTH);
layoutParams_.gravity = Gravity.NO_GRAVITY;
floatImageView.setLayoutParams(layoutParams_);
floatImageView.setPadding(0,0,0,0);
//TODO 不贴边的问题
// layoutParams.width = (int) ViewUtil.dp2px(DEFAULT_MIN_WIDTH_HIDE);
reuseSavedWindowMangerPosition((int) (ViewUtil.dp2px(DEFAULT_MIN_WIDTH_HIDE)*SPHelper.getFloat(ConstantUtil.FLOATVIEW_SIZE,100)/ 100f), ViewUtil.dp2px(MIN_LENGTH));
updateViewPosition(layoutParams.x, layoutParams.y);
break;
}
}
}
};
mActionListener = new ArrayList<>();
mScaledTouchSlop = (int) (ViewUtil.dp2px(DEFAULT_MIN_WIDTH_HIDE)*SPHelper.getFloat(ConstantUtil.FLOATVIEW_SIZE,100)/ 100f);
initView();
applySizeChange();
isRemoved = true;
}
示例11: onCreate
import android.os.Handler; //导入方法依赖的package包/类
@Override
public void onCreate() {
if (DBG) Log.d(TAG, "onCreate");
// importer logic
mImporter = new VideoStoreImportImpl(this);
// setup background worker thread
mHandlerThread = new HandlerThread("ImportWorker", Process.THREAD_PRIORITY_BACKGROUND);
mHandlerThread.start();
Looper looper = mHandlerThread.getLooper();
// associate a handler with the new thread
mHandler = new Handler(looper, this);
// associate content observer that reports in background thread
mContentObserver = new ContentChangeObserver(mHandler);
// handles changes to mounted / unmounted volumes, needs to exist before foreground state
// handler because it's used in there
mVolumeState = new VolumeState(this);
mVolumeStateObserver = new VolumeState.Observer() {
@Override
public void onMountStateChanged(Volume... volumes) {
for (Volume volume : volumes) {
if (DBG) Log.d(TAG, "Change:" + volume.getMountPoint() + " to " + volume.getMountState());
if (!volume.getMountState()) {
mHandler
.obtainMessage(MESSAGE_HIDE_VOLUME, DONT_KILL_SELF, volume.getStorageId())
.sendToTarget();
}
}
}
};
mVolumeState.addObserver(mVolumeStateObserver);
// fetch initial state
mVolumeState.updateState();
if (AppState.isForeGround()) {
// we are most likely started in foreground but won't get a notification
// on the listener so register receiver manually.
mVolumeState.registerReceiver();
}
mForeGroundListener = new AppState.OnForeGroundListener() {
@Override
public void onForeGroundState(Context applicationContext, boolean foreground) {
if (DBG) Log.d(TAG, "onForeGroundState:" + foreground);
// when switching to foreground state and db
// has potentially changed: trigger db import
if (foreground) {
mVolumeState.registerReceiver();
mVolumeState.updateState();
if (ImportState.VIDEO.isDirty()) {
if (DBG) Log.d(TAG, "onForeGround && ImportState.isDirty");
mHandler
.obtainMessage(MESSAGE_IMPORT_FULL, DONT_KILL_SELF, 0)
.sendToTarget();
}
} else {
mVolumeState.unregisterReceiver();
}
}
};
AppState.addOnForeGroundListener(mForeGroundListener);
// register contentobserver for files and videos, on change we import them
getContentResolver().registerContentObserver(MediaStore.Files.getContentUri("external"),
true, mContentObserver);
getContentResolver().registerContentObserver(MediaStore.Video.Media.getContentUri("external"),
true, mContentObserver);
// do a full import here to make sure that we have initial data
Message m = mHandler.obtainMessage(MESSAGE_IMPORT_FULL, DONT_KILL_SELF, 0);
// assume this is the initial import although there could be data in the db already.
ImportState.VIDEO.setState(State.INITIAL_IMPORT);
// we also may need to init scraper default content
mNeedToInitScraper = true;
mHandler.sendMessageDelayed(m, 1000);
}