自定义style,设置全屏属性
<resources>
<style name="AppTheme" parent="android:Theme.Black"/>
<style name="processDialog" >
<item name="android:windowIsFloating">true</item><!--是否浮现在activity之上-->
<item name="android:windowFullscreen">true</item>
<item name="android:windowIsTranslucent">false</item><!--半透明-->
<item name="android:windowNoTitle">true</item><!--无标题-->
<item name="android:windowBackground">@android:color/transparent</item><!--背景透明-->
<item name="android:backgroundDimEnabled">true</item><!--模糊-->
<item name="android:backgroundDimAmount">0.5</item>
<item name="android:alpha">0.3</item>
</style>
</resources>
代码中加载这个view并把view set到dialog上,这样全屏的dialog就完成了
mView = LayoutInflater.from(this).inflate(R.layout.process_dialog, null);
processDialog = new Dialog(context, R.style.processDialog);
processDialog.setCancelable(false);
processDialog.setContentView(mView);
mAutoCloseDialog = new AutoCloseDialog(processDialog);
mAutoCloseDialog.show(Prefs.DIALOG_DISPLAY_TIME);
接下来用一个封装好的类,做一个延时关闭的效果
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import android.app.Dialog;
public class AutoCloseDialog{
private Dialog dialog;
private ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
public AutoCloseDialog(Dialog dialog){
this.dialog = dialog;
}
public void show(long duration){
Runnable runner = new Runnable() {
public void run() {
dialog.dismiss();
}
};
executor.schedule(runner, duration, TimeUnit.MILLISECONDS);
dialog.show();
}
}
其他用法示例:
Here is a class with a method that sets up a ScheduledExecutorService to beep every ten seconds for an hour:
import static java.util.concurrent.TimeUnit.*;
class BeeperControl {
private final ScheduledExecutorService scheduler =
Executors.newScheduledThreadPool(1);
public void beepForAnHour() {
final Runnable beeper = new Runnable() {
public void run() { System.out.println("beep"); }
};
final ScheduledFuture<?> beeperHandle =
scheduler.scheduleAtFixedRate(beeper, 10, 10, SECONDS);
scheduler.schedule(new Runnable() {
public void run() { beeperHandle.cancel(true); }
}, 60 * 60, SECONDS);
}
}
ScheduledExecutorService执行周期性或定时任务
分享到:
相关推荐
主要介绍了ScheduledExecutorService任务定时代码示例,具有一定借鉴价值,需要的朋友可以参考下
定时器小例子,这是一个经较好定时器应用
这是一个jar,很秀。自定义的一个Java定时器工具类。主要是结合Spring Boot一起使用,并在Spring Boot启动的时候一起启动运行。
ScheduledExecutorService 计时器任务处理,用于超时处理。
您可以在工作线程上运行任务(Runnable或Callable),以指定执行计划(如ScheduledExecutorService),并指定执行时间。 介面 ScheduledFuture<?> schedule( Runnable command, int executeTime, long delay,...
下面小编就为大家带来一篇基于ScheduledExecutorService的两种方法(详解)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
延时消息是指消息被发送以后,并不想让消费者立即拿到消息,而是等待指定时间后,消费者才拿到这个消息进行消费。 使用延时消息的典型场景,例如: 在电商系统中,用户下完订单30分钟内没支付,则订单可能会被取消...
Springmvc java注解设置定时任务实例,利用 ScheduledExecutorService 接口实现
springMVC配置、注解、列子
Java通用任务执行程序,基于java.util.concurrent.ScheduledExecutorService。 Java通用的任务执行器,基于java.util.concurrent.ScheduledExecutorService工具类实现。 Maven: <groupId>...
ScheduledExecutorService 的测试实用程序实现 允许测试如下代码: class Foo { private int count = 0; public Foo(ScheduledExecutorService service, Bar bar) { service.scheduleAtFixedRate(new Runnable...
线程池执行者 ThreadPoolExecutor,定时执行者服务 ScheduledExecutorService, 使用 ForkJoinPool 进行分叉和合并,锁 Lock,读写锁 ReadWriteLock 原子性长整型 AtomicLong,原子性引用型 AtomicReference 修改数据:...
2)一个具有线程池的工作队列 3 3)使用线程池的风险: 4 4)有效使用线程池的原则 5 二.入门 6 1)定时器 Timer—sleep()的替代类 6 2)后台线程 daemon 6 3)线程join()方法 8 4)几种多线程代码写法 10 5)一个超时自动...
正宗的地方 Android应用程序。 该应用程序旨在标记罕见的美丽步行场所,您可以在其中为标记的地方添加照片和评论。 由Google Maps API使用,以查看和添加新地点。... 对于多线程,使用ScheduledExecutorService。
在Java 5.0之前启动一个任务...这三个接口是Executor, ExecutorService、ScheduledExecutorService,让我们先用一个图来显示它们的关系:图的左侧是接口,图的右侧是这些接口的具体类。注意Executor是没有直接具体实现
|--TabHost一个界面显示多Activity |--TextView单行跑马灯效果 |--TextView虚拟获得焦点 |--uploadServlet |--uri之表示资源resource |--ViewPage的使用 |--view中的tag用法之存储对象 |--view常用属性 |--xml常用...
1、使用线程的经验:设置名称、响应中断、使用ThreadLocal 2、Executor :ExecutorService和Future ☆ ☆ ☆ 3、阻塞队列 : put和take、offer和poll、drainTo 4、线程间的协调手段:lock、condition、wait、notify、...
内容列表 1、使用线程的经验:设置名称、...8、定时器: ScheduledExecutorService、大规模定时器TimerWheel 9、并发三大定律:Amdahl、Gustafson、Sun-Ni 10、神人和图书 11、业界发展情况: GPGPU、OpenCL 12、复习题
1、使用线程的经验:设置名称、响应中断、使用ThreadLocal 2、Executor :ExecutorService和Future ☆☆☆ 3、阻塞队列: put和take、offer和poll、drainTo 4、线程间的协调手段:lock、condition、wait、notify、...