handler

JS监听div的resize事件

旧巷老猫 提交于 2019-12-22 15:08:13
原文地址: http://zhangyiheng.com/blog/articles/div_resize.html 需求 开发过程中经常遇到的一个问题就是如何监听一个div的size变化。 比如我用canvas绘制了一个chart,当canvas的size发生变化的时候,需要重新绘制里面的内容,这个时候就需要监听resize事件做处理。 window上虽然可以添加resize事件监听,但这并不能满足我们的需求,因为很多时候,div的size发生了变化,但是window的size并没有改变。 不过我们可以间接利用window的resize事件监听来实现对于某个div的resize事件监听,请看下面具体实现。 对于div的resize事件的监听,实现方式有很多,比如周期性检查,通过scroll事件等等,本文主要介绍通过 object 元素来实现监听。 具体实现 /** * Created by taozh on 2017/5/6. * taozh1982@gmail.com */ var EleResize = { _handleResize: function (e) { var ele = e.target || e.srcElement; var trigger = ele.__resizeTrigger__; if (trigger) { var handlers =

SpringMVC工作原理

元气小坏坏 提交于 2019-12-22 12:30:28
SpringMVC的工作原理图: SpringMVC流程 1、 用户发送请求至前端控制器DispatcherServlet。 2、 DispatcherServlet收到请求调用HandlerMapping处理器映射器。 3、 处理器映射器找到具体的处理器(可以根据xml配置、注解进行查找),生成处理器对象及处理器拦截器(如果有则生成)一并返回给DispatcherServlet。 4、 DispatcherServlet调用HandlerAdapter处理器适配器。 5、 HandlerAdapter经过适配调用具体的处理器(Controller,也叫后端控制器)。 6、 Controller执行完成返回ModelAndView。 7、 HandlerAdapter将controller执行结果ModelAndView返回给DispatcherServlet。 8、 DispatcherServlet将ModelAndView传给ViewReslover视图解析器。 9、 ViewReslover解析后返回具体View。 10、DispatcherServlet根据View进行渲染视图(即将模型数据填充至视图中)。 11、 DispatcherServlet响应用户。 组件说明: 以下组件通常使用框架提供实现: DispatcherServlet:作为前端控制器

ProgressDialog while load Activity

对着背影说爱祢 提交于 2019-12-22 11:28:02
问题 I found this code in SO to show ProgressDialog while load Activity : progDailog = ProgressDialog.show(MyActivity.this, "Process", "please wait....", true, true); new Thread(new Runnable() { public void run() { // code for load activity }).start(); Handler progressHandler = new Handler() { public void handleMessage(Message msg1) { progDailog.dismiss(); } }; But I always get this exception: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() I

Handler/Runnable delays producing events that are out of sync sometimes

ぃ、小莉子 提交于 2019-12-22 10:27:22
问题 When trying to learn how to create a delay I researched and found the dominant answer to be to use Handler/Runnable/postDelayed. Handler handler=new Handler(); final Runnable r = new Runnable() { public void run() { delayedMethod(); } }; handler.postDelayed(r, 1000); That worked ok for a while, but I've added a few more things going on and now they are sometimes happening in the wrong order. This set of events: paintScreen1() ... delayedPaintScreen2() ... paintScreen3() is screwing up

.NET HTTP Handler — How to Send Custom Response?

安稳与你 提交于 2019-12-22 09:47:46
问题 I have converted my custom (socket-based) server over to an HTTP Handler in IIS (.NET 4.0). I have converted my client to send an HTTP GET in the proper format. I do not want to change my client's response-handling code to parse out the HTML code. That is a pain in the rear that is also unnecessary. I do not need this server to work with a browser or be compatible with anything except my client. So, I basically need the HTTP Handler (server) to send the response that the client expects --

设计模式之责任链模式

孤者浪人 提交于 2019-12-22 08:22:21
定义:责任链模式是一种对象的行为模式。在责任链模式里,很多对象由每一个对象对其下家的引用而连接起来形成一条链。请求在这个链上传递,直到链上的某一个对象决定处理此请求。发出这个请求的客户端并不知道链上的哪一个对象最终处理这个请求,这使得系统可以在不影响客户端的情况下动态地重新组织和分配责任。 责任链可能是一条’直线‘、一个‘环链’或者一个‘树’结构的一部分。 责任链模式涉及到的角色如下所示:   ●   抽象处理者(Handler)角色: 定义出一个处理请求的接口。如果需要,接口可以定义 出一个方法以设定和返回对下家的引用。这个角色通常由一个Java抽象类或者Java接口实现。上图中Handler类的聚合关系给出了具体子类对下家的引用,抽象方法handleRequest()规范了子类处理请求的操作。   ●   具体处理者(ConcreteHandler)角色: 具体处理者接到请求后,可以选择将请求处理掉,或者将请求传给下家。由于具体处理者持有对下家的引用,因此,如果需要,具体处理者可以访问下家。 结构: 代码举例: 抽象处理者角色 public abstract class Handler { /** * 持有后继的责任对象 */ protected Handler successor; /** * 示意处理请求的方法,虽然这个示意方法是没有传入参数的 * 但实际是可以传入参数的

ProxyHandler处理器(代理设置)

余生长醉 提交于 2019-12-22 08:21:09
很多网站会检测某一段时间某个IP的访问次数(通过流量统计,系统日志等),如果访问的次数多得不像正常人,它会禁止这个IP的访问。 所以我们可以设置一些代理服务器,每个一段时间换一个代理,就算IP被禁止,依然可以换个IP继续爬取。 1.代理的原理:在请求目的网站之前,先请求代理服务器,然后让代理服务器去请求目的网站,代理服务器拿到目的网站的数据后,再转发给我们的代码。 2.http://httpbin.org:这个网站可以方便的查看HTTP请求的一些参数。 3.urllib中通过ProxyHandler来设置使用代理服务器,下面代码说明如何使用自定义opener来使用代理:   * 使用`urllib.request.ProxyHandler`,传入一个代理,这个代理是一个字典,字典的key依赖于代理服务器能够接收的类型,一般是`http`或者`https`,值是`ip:port`。   * 使用上一步创建的`handler`,以及`request.bulid_opener`创建一个`opener`对象。   * 使用上一步创建的`opener`,调用`open`函数,发起请求。 from urllib import request # 这个是没有使用代理的 # resp = request.urlopen("http://httpbin.org/get") # print(resp

Session_set_save_handler not setting

时光毁灭记忆、已成空白 提交于 2019-12-22 07:54:11
问题 I'm having issues with setting session_set_save_handler. I configured my php.ini to session.handler = user This simple test is failing: //Define custom session handler if(session_set_save_handler("sess_open", "sess_close", "sess_read", "sess_write", "sess_destroy", "sess_gc")){ die('set fine'); }else{ die('Couldn\'t set session handler'); Here is my session class. //Constructor function __construct(){ //Define custom session handler if(session_set_save_handler("sess_open", "sess_close", "sess

How to pass a Bluetooth Socket to another Activity using Application interface

被刻印的时光 ゝ 提交于 2019-12-22 06:00:16
问题 so from what i gather, Socket connections are neither serializable or parcelable, but i need to pass a bluetooth connection to another Activity. i do not want to write a Service as a middle man, so please don't post this as a solution. i've heard that there is a way to pass these types of Objects using a custom Application interface, but i cannot, for the life of me, find a working example of this. i've seen plenty of documentation that says something to the effect of "this is possible" but

Why is posting & cancelled a runnable on a View and Handler result in different bahviour?

有些话、适合烂在心里 提交于 2019-12-22 05:25:34
问题 I've been playing about with Runnable s and have discovered that if you postDelayed a Runnable on a View then removing the callback won't work, however if you do the same but post the Runnable on a Handler then removing the callback does work. Why does this work ( Runnable run() code never gets executed): Runnable runnable = new Runnable() { @Override public void run() { // execute some code } }; Handler handler = new Handler(); handler.postDelayed(runnable, 10000); handler.removeCallbacks