当屏幕交互闲置10秒时,android弹出图像窗口
我有一个问题,试图实现一个弹出图像时,屏幕的android手机是闲置或闲置了10秒。目前我正在使用计时器,但需要实现一个空闲侦听器,但我不知道如何实现。 有人能帮我吗 弹出图像由以下代码中的计时器完成当屏幕交互闲置10秒时,android弹出图像窗口,android,image,popup,timertask,Android,Image,Popup,Timertask,我有一个问题,试图实现一个弹出图像时,屏幕的android手机是闲置或闲置了10秒。目前我正在使用计时器,但需要实现一个空闲侦听器,但我不知道如何实现。 有人能帮我吗 弹出图像由以下代码中的计时器完成 public class CustomPopupWindowExample extends Activity { private Animation animShow, animHide; com.example.custompopupwindowexample.Transpare
public class CustomPopupWindowExample extends Activity {
private Animation animShow, animHide;
com.example.custompopupwindowexample.TransparentPanel popup;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.popup);
popup = (com.example.custompopupwindowexample.TransparentPanel) findViewById(R.id.popup_window);
//Declare the timer
Timer t = new Timer();
//Set the schedule function and rate
t.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
//Called each time when 1000 milliseconds (1 second) (the period parameter)
//We must use this function in order to change the text view text
runOnUiThread(new Runnable() {
@Override
public void run() {
popup.setVisibility(View.GONE);
initPopup();
}
});
}
},
//Set how long before to start calling the TimerTask (in milliseconds)
10000,
//Set the amount of time between each execution (in milliseconds)
50000);
}
private void initPopup() {
final com.example.custompopupwindowexample.TransparentPanel popup = (com.example.custompopupwindowexample.TransparentPanel) findViewById(R.id.popup_window);
animShow = AnimationUtils.loadAnimation(this, R.anim.popup_show);
animHide = AnimationUtils.loadAnimation(this, R.anim.popup_hide);
final Button hideButton = (Button) findViewById(R.id.hide_popup_button);
final ImageView locationDescription = (ImageView) findViewById(R.id.location_description);
locationDescription.setBackgroundResource(R.drawable.nike_logo);
popup.setVisibility(View.VISIBLE);
popup.startAnimation(animShow);
hideButton.setEnabled(true);
hideButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
popup.startAnimation( animHide );
hideButton.setEnabled(false);
popup.setVisibility(View.GONE);
}});
}
}
您应该使用touchlistener,以便onTouchEvent可以检查用户是否触摸了它。定义一个变量来保存空闲时间值,如果他/她触摸,则将该变量设置为0,否则将其递增,当它达到10秒(或您想要的任何值)时,显示该弹出窗口