??xml version="1.0" encoding="utf-8" standalone="yes"?>午夜精品区一区二区三,国内自拍视频一区二区三区,亚洲一区二区三区免费在线观看 http://www.aygfsteel.com/ZouYonghui/zh-cnSun, 22 Jun 2025 16:40:46 GMTSun, 22 Jun 2025 16:40:46 GMT60搭徏React环境Q运行React目http://www.aygfsteel.com/ZouYonghui/archive/2020/04/16/435361.htmlTerry ZouTerry ZouThu, 16 Apr 2020 07:25:00 GMThttp://www.aygfsteel.com/ZouYonghui/archive/2020/04/16/435361.htmlhttp://www.aygfsteel.com/ZouYonghui/comments/435361.htmlhttp://www.aygfsteel.com/ZouYonghui/archive/2020/04/16/435361.html#Feedback0http://www.aygfsteel.com/ZouYonghui/comments/commentRss/435361.htmlhttp://www.aygfsteel.com/ZouYonghui/services/trackbacks/435361.html2.安装cnpm用cnpm替代npm
    地址Qhttp://npm.taobao.org/
安装cnpm:
npm install -g cnpm --registry=https://registry.npm.taobao.org

3、用yarn替代npm
yarn的安装:
W一U方法:参考官Ҏ(gu)档https://yarn.bootcss.com/
W二U方法:cnpm install -g yarn  或?npm install -g yarn
4、搭建React开发环境的W一U方法(?现在推荐Q:
https://reactjs.org/docs/create-a-new-react-app.html
1、必要安装nodejs     注意Q安装nodejsE_版本      教程中的nodejs版本:v8.11.2            教程中的npm版本:v5.6.0
2.安装脚手架工?nbsp;  Q单文glg目生成工具Q?nbsp;  只需要安装一?/div>
npm install -g create-react-app   /  cnpm install -g create-react-app
3.创徏目   Q可能创建多ơ)
扑ֈ目要创建的目录Q?/div>
                create-react-app reactdemo
4.cd  到项目里?span style="white-space:pre">
        cd  reactdemo
                npm start             yarn startq行目
                npm run build         yarn build 生成目
5、搭建React的开发环境的W二U方法(?未来推荐Q:
        https://reactjs.org/docs/create-a-new-react-app.html
        1、必要安装nodejs     注意Q安装nodejsE_版本      教程中的nodejs版本:v8.11.2            教程中的npm版本:v5.6.0
        2.安装脚手架工具ƈ创徏目
            扑ֈ目要创建的目录执行Q?/div>
npx create-react-app reactdemo
4.cd  到项目里?span style="white-space: pre;">
        cd  reactdemo
                npm start  q行目Q调试)
                npm run build 生成目Q发布)
npx介绍Q?/div>
npm v5.2.0引入的一条命令(npxQ,引入q个命o的目的是Z提升开发者用包内提供的命o行工L体验?/div>
详情Q?/div>
        npx create-react-app reactdemoq条命o会时安?create-react-app 包,命o完成后create-react-app 会删掉,不会出现?global 中。下ơ再执行Q还是会重新临时安装?/div>
npx 会帮你执行依赖包里的二进制文件?/div>
        再比?npx http-server 可以一句话帮你开启一个静态服务器


Terry Zou 2020-04-16 15:25 发表评论
]]>Spring @PostConstruct 、@Autowired和Construct 序http://www.aygfsteel.com/ZouYonghui/archive/2020/04/09/435331.htmlTerry ZouTerry ZouThu, 09 Apr 2020 07:29:00 GMThttp://www.aygfsteel.com/ZouYonghui/archive/2020/04/09/435331.htmlhttp://www.aygfsteel.com/ZouYonghui/comments/435331.htmlhttp://www.aygfsteel.com/ZouYonghui/archive/2020/04/09/435331.html#Feedback0http://www.aygfsteel.com/ZouYonghui/comments/commentRss/435331.htmlhttp://www.aygfsteel.com/ZouYonghui/services/trackbacks/435331.html@PostConstruct
PostConstruct注释用于在完成依赖项注入以执行Q何初始化之后需要执行的Ҏ(gu)。必dcL入用之前调用此Ҏ(gu)?
所有支持依赖注入的c都必须支持此注释。即使类没有h注入M资源Q也必须调用使用PostConstruct注释的方法?
只有一个方法可以用此Ҏ(gu)q行Ҏ(gu)?
应用PostConstruct注释的方法必L以下所有条Ӟ除了拦截器之外,Ҏ(gu)l不能有M参数Q在q种情况下它采用Interceptor规范定义的InvocationContext对象?
在拦截器cM定义的方法必d有以下签名之一Q?
void <METHOD>QInvocationContextQObject <METHOD>QInvocationContextQ抛出异常注意:
PostConstruct拦截器方法不能抛出应用程序异常,但可以声明它抛出查异常,包括java.lang.ExceptionQ?
如果相同的拦截器Ҏ(gu)除了生命周期事g之外插入业务或超时方法?
如果PostConstruct拦截器方法返回一个|容器忽略它?
在非拦截器类上定义的Ҏ(gu)必须h以下{֐Q?span class="token keyword" style="box-sizing: border-box; list-style: inherit; color: #cc99cd;">void <METHOD>Q)应用PostConstruct的方法可以是publicQ?span class="token keyword" style="box-sizing: border-box; list-style: inherit; color: #cc99cd;">protectedQ?span class="token keyword" style="box-sizing: border-box; list-style: inherit; color: #cc99cd;">package private?span class="token keyword" style="box-sizing: border-box; list-style: inherit; color: #cc99cd;">private?
除应用程序客L外,该方法绝不能是静态的?
该方法可能是最l的。如果该Ҏ(gu)抛出一个未l检查的异常Q那么该cȝ不能投入使用Q除非EJB可以处理异常甚至从它们恢复的EJB

然后׃思考问题,q个注释是修饰初始化之后需要执行的Ҏ(gu)Q那么它和@Autowired、构造函数的执行序是什么呢Q(当然注释中已l说明了PostConstruct注释用于在完成依赖项注入之后Q?br />
@Service
public class BeanA {

    @Autowired
    private BeanB beanB;

    public BeanA() {
        System.out.println("q是Bean A 的构造方?);
    }
    @PostConstruct
    private void init() {
        System.out.println("q是BeanA?nbsp;init Ҏ(gu)");
        beanB.testB();
    }
}
@Service
public class BeanB {

    @PostConstruct
    private void init() {
        System.out.println("q是BeanB 的init Ҏ(gu)");
    }
    public BeanB() {
        System.out.println("q是Bean B?nbsp;构造方?);
    }
    void testB() {
        System.out.println("q是Bean B ?nbsp;testB Ҏ(gu)");
    }
}

启动后输?
q是Bean A 的构造方?
q是Bean B?构造方?
q是BeanB 的init Ҏ(gu)
q是BeanA?init Ҏ(gu)
q是Bean B ?testB Ҏ(gu)

所以得到结论: 构造方?> @Autowired > @PostConstruct


Terry Zou 2020-04-09 15:29 发表评论
]]>
Spring中的ApplicationListener的用详解案例(观察者模?http://www.aygfsteel.com/ZouYonghui/archive/2020/04/09/435329.htmlTerry ZouTerry ZouThu, 09 Apr 2020 06:47:00 GMThttp://www.aygfsteel.com/ZouYonghui/archive/2020/04/09/435329.htmlhttp://www.aygfsteel.com/ZouYonghui/comments/435329.htmlhttp://www.aygfsteel.com/ZouYonghui/archive/2020/04/09/435329.html#Feedback0http://www.aygfsteel.com/ZouYonghui/comments/commentRss/435329.htmlhttp://www.aygfsteel.com/ZouYonghui/services/trackbacks/435329.html1、ApplicationContext
Spring的核心,Context我们通常解释Z下文环境。ApplicationContext则是应用的容器?Spring把BeanQobjectQ放在容器中Q需要用通过getҎ(gu)取出来。在ApplicationContext接口的众多实现类中,?个是我们l常用到的(见表1-1Q,q且使用q?个实现类也基本能满我们Java EE应用开发中的绝大部分需求?/div>
?-1 ApplicationContext接口的常用实现类介绍
ClassPathXmlApplicationContext
从类路径ClassPath中寻找指定的XML配置文gQ找到ƈ装蝲完成ApplicationContext的实例化工作。例如: //装蝲单个配置文g实例化ApplicationContext容器
ApplicationContext cxt = new ClassPathXmlApplicationContext("applicationContext.xml");
//装蝲多个配置文g实例化ApplicationContext容器
String[] configs = {"bean1.xml","bean2.xml","bean3.xml"};
ApplicationContext cxt = new ClassPathXmlApplicationContext(configs);
FileSystemXmlApplicationContext
从指定的文gpȝ路径中寻找指定的XML配置文gQ找到ƈ装蝲完成ApplicationContext的实例化工作。例如://装蝲单个配置文g实例化ApplicationContext容器
ApplicationContext cxt = new FileSystemXMLApplicationContext("beans.xml");
//装蝲多个配置文g实例化ApplicationContext容器
String[] configs = {"c:/beans1.xml","c:/beans2.xml"};
ApplicationContext cxt = new FileSystemXmlApplicationContext(configs);
XmlWebApplicationContext
从Web应用中寻找指定的XML配置文gQ找到ƈ装蝲完成ApplicationContext的实例化工作。这是ؓWeb工程量n定制的,使用WebApplicationContextUtilscȝgetRequiredWebApplicationContextҎ(gu)可在JSP与Servlet中取得IoC容器的引?/div>
2、ApplicationEvent
是个抽象c,里面只有一个构造函数和一个长整型的timestamp。其源码如下

public abstract class ApplicationEvent extends EventObject {
 
    /** use serialVersionUID from Spring 1.2 for interoperability */
    private static final long serialVersionUID = 7099057708183571937L;
 
    /** System time when the event happened */
    private final long timestamp;
 
    /**
     * Create a new ApplicationEvent.
     * 
@param source the object on which the event initially occurred (never {@code null})
     
*/
    public ApplicationEvent(Object source) {
        super(source);
        this.timestamp = System.currentTimeMillis();
    }
 
    /**
     * Return the system time in milliseconds when the event happened.
     
*/
    public final long getTimestamp() {
        return this.timestamp;
    }
}

3、ApplicationListener

是一个接口,里面只有一个onApplicationEventҎ(gu)。如果在上下文中部v一个实CApplicationListener接口的bean,那么每当在一个ApplicationEvent发布?ApplicationContextӞ调用ApplicationContext.publishEvent()Ҏ(gu)Q这个bean得到通知。类gOberver设计模式?/span>
其源码如下:

public interface ApplicationListener<E extends ApplicationEvent> extends EventListener {
    /**
     * Handle an application event.
     * 
@param event the event to respond to
     
*/
    void onApplicationEvent(E event);
 
}
下面举个例子
自定义事件NotifyEvent:
import org.springframework.context.ApplicationEvent;

public class NotifyEvent  extends ApplicationEvent  {
    private String email;
    private String content;
    public NotifyEvent(Object source){
        super(source);
    }

    public NotifyEvent(Object source,String email,String content){
        super(source);
        this.email = email;
        this.content = content;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }
}

定义监听器NotifyListener:
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;

@Configuration
public class NotifyListener implements ApplicationListener<NotifyEvent>{
    @Override
    public void onApplicationEvent(NotifyEvent event) {
        System.out.println("邮g地址Q? + event.getEmail());
        System.out.println("邮g内容Q? + event.getContent());
    }
}

单元试cListenerTestQ?/span>
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.context.WebApplicationContext;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = ServerLauncher.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class ListenerTest {
    @Autowired
    private WebApplicationContext webApplicationContext;

    @Test
    public void testListener(){
        NotifyEvent event = new NotifyEvent("object","abc@qq.com","This is the content");
        webApplicationContext.publishEvent(event);
    }
}


Terry Zou 2020-04-09 14:47 发表评论
]]>@SpringBootApplication的?/title><link>http://www.aygfsteel.com/ZouYonghui/archive/2020/04/09/435328.html</link><dc:creator>Terry Zou</dc:creator><author>Terry Zou</author><pubDate>Thu, 09 Apr 2020 01:10:00 GMT</pubDate><guid>http://www.aygfsteel.com/ZouYonghui/archive/2020/04/09/435328.html</guid><wfw:comment>http://www.aygfsteel.com/ZouYonghui/comments/435328.html</wfw:comment><comments>http://www.aygfsteel.com/ZouYonghui/archive/2020/04/09/435328.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/ZouYonghui/comments/commentRss/435328.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/ZouYonghui/services/trackbacks/435328.html</trackback:ping><description><![CDATA[<p style="margin-top: 10px; margin-bottom: 10px; font-family: "black Verdana", Arial, Helvetica, sans-serif; background-color: #ffffff;">之前用户使用的是3个注解注解他们的maincR分别是@Configuration,@EnableAutoConfiguration,@ComponentScan。由于这些注解一般都是一起用,spring boot提供了一个统一的注解@SpringBootApplication?/p> <p style="margin-top: 10px; margin-bottom: 10px; font-family: "black Verdana", Arial, Helvetica, sans-serif; background-color: #ffffff;">@SpringBootApplication = (默认属?@Configuration + @EnableAutoConfiguration + @ComponentScan?br /></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->@SpringBootApplication <br /><span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">class</span> ApplicationMain { <br />    <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">static</span> <span style="color: #0000FF; ">void</span> main(String[] args) { <br />        SpringApplication.run(Application.<span style="color: #0000FF; ">class</span>, args); <br />    } <br />}</div><p style="margin-top: 10px; margin-bottom: 10px; font-family: "black Verdana", Arial, Helvetica, sans-serif; background-color: #ffffff;">分开解释@Configuration,@EnableAutoConfiguration,@ComponentScan?br />1、@ConfigurationQ提到@Configurationp提到他的搭档@Bean。用这两个注解可以创Z个简单的spring配置c,可以用来替代相应的xml配置文g?br /></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><beans> <br />    <bean id = "car" <span style="color: #0000FF; ">class</span>="com.test.Car"> <br />        <property name="wheel" ref = "wheel"></property> <br />    </bean> <br />    <bean id = "wheel" <span style="color: #0000FF; ">class</span>="com.test.Wheel"></bean> <br /></beans> </div><p style="margin-top: 10px; margin-bottom: 10px; font-family: "black Verdana", Arial, Helvetica, sans-serif; background-color: #ffffff;"> 相当于:<br /></p><div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all;"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->@Configuration <br /><span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">class</span> Conf { <br />    @Bean <br />    <span style="color: #0000FF; ">public</span> Car car() { <br />        Car car = <span style="color: #0000FF; ">new</span> Car(); <br />        car.setWheel(wheel()); <br />        <span style="color: #0000FF; ">return</span> car; <br />    } <br />    @Bean  <br />    <span style="color: #0000FF; ">public</span> Wheel wheel() { <br />        <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">new</span> Wheel(); <br />    } <br />}</div><p style="margin-top: 10px; margin-bottom: 10px; font-family: "black Verdana", Arial, Helvetica, sans-serif; background-color: #ffffff;">@Configuration的注解类标识q个cd以用Spring IoC容器作ؓbean定义的来源。@Bean注解告诉SpringQ一个带有@Bean的注解方法将q回一个对象,该对象应该被注册为在Spring应用E序上下文中的bean?br /></p><p style="margin-top: 10px; margin-bottom: 10px; font-family: "black Verdana", Arial, Helvetica, sans-serif; background-color: #ffffff;">2、@EnableAutoConfigurationQ能够自动配|spring的上下文Q试囄和配置你想要的beanc,通常会自动根据你的类路径和你的bean定义自动配置?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: "black Verdana", Arial, Helvetica, sans-serif; background-color: #ffffff;">3、@ComponentScanQ会自动扫描指定包下的全部标有@Component的类Qƈ注册成beanQ当然包括@Component下的子注解@Service,@Repository,@Controller?/p><div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all;"><p><br /> </p> </div><img src ="http://www.aygfsteel.com/ZouYonghui/aggbug/435328.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/ZouYonghui/" target="_blank">Terry Zou</a> 2020-04-09 09:10 <a href="http://www.aygfsteel.com/ZouYonghui/archive/2020/04/09/435328.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>服务器连?/title><link>http://www.aygfsteel.com/ZouYonghui/archive/2015/07/13/426208.html</link><dc:creator>Terry Zou</dc:creator><author>Terry Zou</author><pubDate>Mon, 13 Jul 2015 14:10:00 GMT</pubDate><guid>http://www.aygfsteel.com/ZouYonghui/archive/2015/07/13/426208.html</guid><wfw:comment>http://www.aygfsteel.com/ZouYonghui/comments/426208.html</wfw:comment><comments>http://www.aygfsteel.com/ZouYonghui/archive/2015/07/13/426208.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/ZouYonghui/comments/commentRss/426208.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/ZouYonghui/services/trackbacks/426208.html</trackback:ping><description><![CDATA[<div><span style="font-size: 12px;">package com.zhihe.xqsh.utils;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">import java.io.File;</span></div><div><span style="font-size: 12px;">import java.io.FileOutputStream;</span></div><div><span style="font-size: 12px;">import java.io.IOException;</span></div><div><span style="font-size: 12px;">import java.io.InputStream;</span></div><div><span style="font-size: 12px;">import java.io.UnsupportedEncodingException;</span></div><div><span style="font-size: 12px;">import java.util.Date;</span></div><div><span style="font-size: 12px;">import java.util.List;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">import org.apache.http.HttpEntity;</span></div><div><span style="font-size: 12px;">import org.apache.http.HttpResponse;</span></div><div><span style="font-size: 12px;">import org.apache.http.HttpStatus;</span></div><div><span style="font-size: 12px;">import org.apache.http.HttpVersion;</span></div><div><span style="font-size: 12px;">import org.apache.http.NameValuePair;</span></div><div><span style="font-size: 12px;">import org.apache.http.client.ClientProtocolException;</span></div><div><span style="font-size: 12px;">import org.apache.http.client.HttpClient;</span></div><div><span style="font-size: 12px;">import org.apache.http.client.entity.UrlEncodedFormEntity;</span></div><div><span style="font-size: 12px;">import org.apache.http.client.methods.HttpGet;</span></div><div><span style="font-size: 12px;">import org.apache.http.client.methods.HttpPost;</span></div><div><span style="font-size: 12px;">import org.apache.http.conn.ClientConnectionManager;</span></div><div><span style="font-size: 12px;">import org.apache.http.conn.params.ConnManagerParams;</span></div><div><span style="font-size: 12px;">import org.apache.http.conn.params.ConnRouteParams;</span></div><div><span style="font-size: 12px;">import org.apache.http.conn.scheme.PlainSocketFactory;</span></div><div><span style="font-size: 12px;">import org.apache.http.conn.scheme.Scheme;</span></div><div><span style="font-size: 12px;">import org.apache.http.conn.scheme.SchemeRegistry;</span></div><div><span style="font-size: 12px;">import org.apache.http.conn.ssl.SSLSocketFactory;</span></div><div><span style="font-size: 12px;">import org.apache.http.impl.client.DefaultHttpClient;</span></div><div><span style="font-size: 12px;">import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;</span></div><div><span style="font-size: 12px;">import org.apache.http.impl.cookie.BasicClientCookie;</span></div><div><span style="font-size: 12px;">import org.apache.http.params.BasicHttpParams;</span></div><div><span style="font-size: 12px;">import org.apache.http.params.HttpConnectionParams;</span></div><div><span style="font-size: 12px;">import org.apache.http.params.HttpParams;</span></div><div><span style="font-size: 12px;">import org.apache.http.params.HttpProtocolParams;</span></div><div><span style="font-size: 12px;">import org.apache.http.util.EntityUtils;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">import com.zhihe.xqsh.network.ServerErrorException;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">import android.accounts.NetworkErrorException;</span></div><div><span style="font-size: 12px;">import android.annotation.SuppressLint;</span></div><div><span style="font-size: 12px;">import android.util.Log;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">public class CustomerHttpClient {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>private static final String TAG = CustomerHttpClient.class.getSimpleName();</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>private static DefaultHttpClient customerHttpClient;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>private CustomerHttpClient() {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>}</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>public static synchronized HttpClient getHttpClient() {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>if (null == customerHttpClient) {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>HttpParams params = new BasicHttpParams();</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>// 讄K?K�基本参数</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>HttpProtocolParams.setContentCharset(params, "UTF-8");</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>HttpProtocolParams.setUseExpectContinue(params, true);</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>HttpProtocolParams.setUserAgent(params, "Mozilla/5.0(Linux;U;Android 2.2.1;en-us;Nexus One Build.FRG83) "</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>+ "AppleWebKit/553.1(KHTML,like Gecko) Version/4.0 Mobile Safari/533.1");</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>// 时讄</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>/* 从连接池中取q接的超时时K?*/</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>ConnManagerParams.setTimeout(params, 2000);</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>ConnManagerParams.setMaxTotalConnections(params, 800);</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>/* q接时 */</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>HttpConnectionParams.setConnectionTimeout(params, 5000);</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>/* h时 */</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>HttpConnectionParams.setSoTimeout(params, 10000);</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>// 讄我们的HttpClient支持HTTP和HTTPS两种模式</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>SchemeRegistry schReg = new SchemeRegistry();</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>// 使用U程安全的连接管理来创徏HttpClient</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schReg);</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>// K?K�q接敎ͼConnManagerParams.setMaxTotalConnections(params, 50);</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>customerHttpClient = new DefaultHttpClient(conMgr, params);</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>}</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>return customerHttpClient;</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>}</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>/**</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * 以get方式提交数据</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * </span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @param url 提交地址</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @param params 参数</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @return 响应l果</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @throws ServerErrorException hp|</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @throws NetworkErrorException q接p|</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> */</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>public static String get(String url, String params) throws ServerErrorException, NetworkErrorException {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>int tryTimes = 0;</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>NullPointerException ex;</span></div><div><span style="white-space: pre; font-size: 12px;"> </span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>do {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>try {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>return tryGet(url, params);</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>} catch (NullPointerException e) {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>ex = e;</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>tryTimes++;</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>}</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>} while (tryTimes < 3);</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>throw ex;</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>}</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>/**</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * 以get方式提交数据</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * </span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @param url 提交地址</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @param params 参数</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @return 响应l果</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @throws ServerErrorException hp|</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @throws NetworkErrorException q接p|</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> */</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>public static String tryGet(String url, String params) throws ServerErrorException, NetworkErrorException {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>try {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>HttpGet request = new HttpGet(url + params);</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>/*if (LotteryApplication.isCmwap()) {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>org.apache.http.HttpHost proxy = new org.apache.http.HttpHost("10.0.0.172", 80, "http");</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>HttpParams httpParams = new BasicHttpParams();</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>ConnRouteParams.setDefaultProxy(httpParams, proxy);</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>request.setParams(httpParams);</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>}*/</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>HttpClient client = getHttpClient();</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>HttpResponse response = client.execute(request);</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>throw new ServerErrorException("K�K�K�K�æK�K�KԺ�K�K�");</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>}</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>HttpEntity resEntity = response.getEntity();</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>String result = (resEntity == null) ? null : EntityUtils.toString(resEntity, "UTF-8");</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>return result;</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>} catch (UnsupportedEncodingException e) {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>logw(e.getMessage());</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>return null;</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>} catch (ClientProtocolException e) {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>logw(e.getMessage());</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>return null;</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>} catch (IOException e) {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>throw new NetworkErrorException("K�KԌKU�K�K�K�K�K�K�K�", e);</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>}</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>}</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>private static void logw(String string) {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>if (string != null) {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>Log.w(TAG, string);</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>}</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>}</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>/**</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * 以post方式提交数据</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * </span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @param url 提交地址</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @param params 参数</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @return 响应l果</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @throws ServerErrorException hp|</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @throws NetworkErrorException q接p|</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> */</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>public static String post(String url, List<NameValuePair> params) throws ServerErrorException, NetworkErrorException {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>return post(url, params, null);</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>}</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>/**</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * 以post方式提交数据</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * </span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @param url 提交地址</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @param params 参数</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @param soTimeout 响应时旉Q单位毫K?</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @return 响应l果</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @throws ServerErrorException hp|</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @throws NetworkErrorException q接p|</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> */</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>public static String post(String url, List<NameValuePair> params, int soTimeout) throws ServerErrorException,</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>NetworkErrorException {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>HttpParams httpParams;</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>if (soTimeout <= 0) {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>httpParams = null;</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>} else {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>httpParams = new BasicHttpParams();</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>HttpConnectionParams.setSoTimeout(httpParams, soTimeout);</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>}</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>return post(url, params, httpParams);</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>}</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>/**</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * 以post方式提交数据</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * </span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @param url 提交地址</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @param params 参数</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @param httpParams http参数</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @return 响应l果</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @throws ServerErrorException hp|</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @throws NetworkErrorException q接p|</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> */</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>public static String post(String url, List<NameValuePair> params, HttpParams httpParams) throws ServerErrorException,</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>NetworkErrorException {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>int tryTimes = 0;</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>NullPointerException ex;</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>do {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>try {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>return tryPost(url, params, httpParams);</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>} catch (NullPointerException e) {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>ex = e;</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>tryTimes++;</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>}</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>} while (tryTimes < 3);</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>throw ex;</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>}</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>/**</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * 以post方式提交数据</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * </span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @param url 提交地址</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @param params 参数</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @param httpParams http参数</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @return 响应l果</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @throws ServerErrorException hp|</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @throws NetworkErrorException q接p|</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> */</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>public static String tryPost(String url, List<NameValuePair> params, HttpParams httpParams) throws ServerErrorException,</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>NetworkErrorException {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>try {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>HttpPost request = new HttpPost(url);</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>if (params != null && params.size() > 0) {<span style="white-space:pre"> </span></span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>request.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>}</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">//<span style="white-space:pre"> </span>if (LotteryApplication.isCmwap()) {</span></div><div><span style="font-size: 12px;">//<span style="white-space:pre"> </span>org.apache.http.HttpHost proxy = new org.apache.http.HttpHost("10.0.0.172", 80, "http");</span></div><div><span style="font-size: 12px;">//<span style="white-space:pre"> </span>if (httpParams == null)</span></div><div><span style="font-size: 12px;">//<span style="white-space:pre"> </span>httpParams = new BasicHttpParams();</span></div><div><span style="font-size: 12px;">//<span style="white-space:pre"> </span>ConnRouteParams.setDefaultProxy(httpParams, proxy);</span></div><div><span style="font-size: 12px;">//<span style="white-space:pre"> </span>}</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>if (httpParams != null)</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>request.setParams(httpParams);</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>//Log.v("CS", params.toString());</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>HttpClient client = getHttpClient();</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>HttpResponse response = client.execute(request);</span></div><div><span style="white-space: pre; font-size: 12px;"> </span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>//Log.v("CS", params.toString());</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>//Log.v("CS", response.getStatusLine().getStatusCode() + "");</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>request.abort(); </span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>throw new ServerErrorException("K�K�K�K�æK�K�KԺ�K�K�");</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>}</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>if (response.getStatusLine ().getStatusCode () != 200) {  </span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>request.abort();  //KӞK�K�,K�K�K�K�KԿ�ʼK�һK�K�K�</span></div><div><span style="font-size: 12px;">                return null;  </span></div><div><span style="font-size: 12px;">            } </span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>HttpEntity resEntity = response.getEntity();</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>String result = (resEntity == null) ? null : EntityUtils.toString(resEntity, "UTF-8");</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>//Log.v("CS", params.toString() + "||||" + result);</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>return result;</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>} catch (UnsupportedEncodingException e) {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>logw(e.getMessage());</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>return null;</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>} catch (ClientProtocolException e) {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>logw(e.getMessage());</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>return null;</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>} catch (IOException e) {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>throw new NetworkErrorException(e.getMessage(), e);</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>//throw new NetworkErrorException("q接不成功,h查网l设K?, e);</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>}</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>}</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>@SuppressLint("SdCardPath")</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>public static String download(String url) throws ServerErrorException, NetworkErrorException {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>try {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>//Log.i("http-download", url);</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>HttpPost request = new HttpPost(url);</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>HttpClient client = getHttpClient();</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>HttpResponse response = client.execute(request);</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>throw new ServerErrorException("K�K�K�K�æK�K�KԺ�K�K�");</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>}</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>HttpEntity entity = response.getEntity();</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>InputStream is = entity.getContent();</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>if (is == null)</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>throw new ServerErrorException("stream is null ");</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>String fileExt = url.substring(url.lastIndexOf(".") + 1, url.length()).toLowerCase();</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>String fileName = url.substring(url.lastIndexOf("/") + 1, url.lastIndexOf("."));</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>File tempFile = new File("/sdcard/" + fileName + "." + fileExt);</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>if (!tempFile.exists())</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>tempFile.createNewFile();</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>FileOutputStream fileOutputStream = new FileOutputStream(tempFile);</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>byte[] buf = new byte[1024];</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>int ch;</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>while ((ch = is.read(buf)) != -1) {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>fileOutputStream.write(buf, 0, ch);</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>}</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>fileOutputStream.flush();</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>fileOutputStream.close();</span></div><div><span style="white-space: pre; font-size: 12px;"> </span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>return tempFile.getAbsolutePath();</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>} catch (UnsupportedEncodingException e) {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>logw(e.getMessage());</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>return null;</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>} catch (ClientProtocolException e) {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>logw(e.getMessage());</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>return null;</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>} catch (IOException e) {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>throw new NetworkErrorException(e.getMessage(), e);</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>}</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>}</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>/**</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * 清空cookie</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> */</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>public static void clearCookie() {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>if (customerHttpClient != null)</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>customerHttpClient.getCookieStore().clear();</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>}</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>/**</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * 清除指定cookie</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * </span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> * @param name cookie名称</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span> */</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>public static void clearCookie(String name) {</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>if (customerHttpClient == null)</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>return;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>BasicClientCookie expiredCookie = new BasicClientCookie(name, "null");</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>expiredCookie.setExpiryDate(new Date(System.currentTimeMillis() - 1000));</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>customerHttpClient.getCookieStore().addCookie(expiredCookie);</span></div><div><span style="font-size: 12px;"><span style="white-space:pre"> </span>}</span></div><div><span style="font-size: 12px;">}</span></div><div style="font-family: Tahoma; font-size: 11px;"></div><img src ="http://www.aygfsteel.com/ZouYonghui/aggbug/426208.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/ZouYonghui/" target="_blank">Terry Zou</a> 2015-07-13 22:10 <a href="http://www.aygfsteel.com/ZouYonghui/archive/2015/07/13/426208.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ffghttp://www.aygfsteel.com/ZouYonghui/archive/2015/07/13/426185.htmlTerry ZouTerry ZouMon, 13 Jul 2015 03:04:00 GMThttp://www.aygfsteel.com/ZouYonghui/archive/2015/07/13/426185.htmlhttp://www.aygfsteel.com/ZouYonghui/comments/426185.htmlhttp://www.aygfsteel.com/ZouYonghui/archive/2015/07/13/426185.html#Feedback0http://www.aygfsteel.com/ZouYonghui/comments/commentRss/426185.htmlhttp://www.aygfsteel.com/ZouYonghui/services/trackbacks/426185.html

Terry Zou 2015-07-13 11:04 发表评论
]]>
abehttp://www.aygfsteel.com/ZouYonghui/archive/2015/07/09/426109.htmlTerry ZouTerry ZouWed, 08 Jul 2015 16:04:00 GMThttp://www.aygfsteel.com/ZouYonghui/archive/2015/07/09/426109.htmlhttp://www.aygfsteel.com/ZouYonghui/comments/426109.htmlhttp://www.aygfsteel.com/ZouYonghui/archive/2015/07/09/426109.html#Feedback0http://www.aygfsteel.com/ZouYonghui/comments/commentRss/426109.htmlhttp://www.aygfsteel.com/ZouYonghui/services/trackbacks/426109.html
private Drawable img_time_filter,img_time_filter_selected ;
//qo器TextView中显C的囄
img_time_filter = getResources().getDrawable(R.drawable.time_filter);
//调用setCompoundDrawablesӞ必须调用Drawable.setBounds()Ҏ(gu),否则囄不显C?/div>
img_time_filter.setBounds(0, 0, img_time_filter.getMinimumWidth(), img_time_filter.getMinimumHeight());
img_time_filter_selected = getResources().getDrawable(R.drawable.time_filter_selected);
img_time_filter_selected.setBounds(0, 0, img_time_filter_selected.getMinimumWidth(), img_time_filter_selected.getMinimumHeight());
tv_filterTime.setCompoundDrawables(img_time_filter_selected, null, null, null);
tv_filterTime.setTextColor(getResources().getColor(R.color.white));
rl_filterTime.setBackgroundColor(getResources().getColor(R.color.red));

tv_filterTime.setCompoundDrawables(img_time_filter, null, null, null);
rl_filterTime.setBackgroundColor(getResources().getColor(R.color.white)); 
lv_filterTime.setVisibility(View.INVISIBLE);


Terry Zou 2015-07-09 00:04 发表评论
]]>
Android之Activity的四U启动模?/title><link>http://www.aygfsteel.com/ZouYonghui/archive/2015/06/24/425872.html</link><dc:creator>Terry Zou</dc:creator><author>Terry Zou</author><pubDate>Wed, 24 Jun 2015 10:10:00 GMT</pubDate><guid>http://www.aygfsteel.com/ZouYonghui/archive/2015/06/24/425872.html</guid><wfw:comment>http://www.aygfsteel.com/ZouYonghui/comments/425872.html</wfw:comment><comments>http://www.aygfsteel.com/ZouYonghui/archive/2015/06/24/425872.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/ZouYonghui/comments/commentRss/425872.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/ZouYonghui/services/trackbacks/425872.html</trackback:ping><description><![CDATA[<p style="text-align: left; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 10px auto 10px 30px; font: 13px/19px Verdana, Geneva, Arial, Helvetica, sans-serif; white-space: normal; letter-spacing: normal; color: rgb(75,75,75); word-spacing: 0px; -webkit-text-stroke-width: 0px" class="p0"><span style="line-height: 1.5">转蝲Q?a >http://www.cnblogs.com/allenzheng/archive/2013/04/28/3050065.html</a><br />当应用运行v来后׃开启一条线E,U程中会q行一个Q务栈Q当<span style="line-height: 1.5; font-family: 'Times New Roman'">Activity</span><span style="line-height: 1.5; font-family: 宋体">实例创徏后就会放入Q务栈中?/span><span style="line-height: 1.5; font-family: 'Times New Roman'">Activity启动</span><span style="line-height: 1.5; font-family: 宋体">模式的设|在</span></span><span style="line-height: 1.5">AndroidManifest.</span><span style="line-height: 1.5">xml</span><span style="line-height: 1.5">文g中,通过配置</span><span style="line-height: 1.5">Activity<span style="line-height: 1.5; font-family: 宋体">的属?/span></span><span style="line-height: 1.5">android:launchMode</span><span style="line-height: 1.5">=</span><span style="line-height: 1.5">""</span><span style="line-height: 1.5">讄</span><span style="line-height: 1.5">?/span></p> <p style="text-align: left; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 10px auto 10px 30px; font: 13px/19px Verdana, Geneva, Arial, Helvetica, sans-serif; white-space: normal; letter-spacing: normal; color: rgb(75,75,75); word-spacing: 0px; -webkit-text-stroke-width: 0px" class="p0"><span style="line-height: 1.5"> </span></p> <p style="text-align: left; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 10px auto 10px 30px; font: 13px/19px Verdana, Geneva, Arial, Helvetica, sans-serif; white-space: normal; letter-spacing: normal; color: rgb(75,75,75); word-spacing: 0px; -webkit-text-stroke-width: 0px" class="p0"><strong><span style="line-height: 1.5">1. </span><span style="line-height: 1.5">Standared<span style="line-height: 1.5; font-family: 宋体">模式Q默认)</span></span></strong></p> <p style="text-align: left; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 10px auto 10px 30px; font: 13px/19px Verdana, Geneva, Arial, Helvetica, sans-serif; white-space: normal; letter-spacing: normal; color: rgb(75,75,75); word-spacing: 0px; -webkit-text-stroke-width: 0px" class="p0"><span style="line-height: 1.5">我们qx直接创徏?span style="line-height: 1.5; font-family: 'Times New Roman'">Activity</span><span style="line-height: 1.5; font-family: 宋体">都是q种模式?/span><span style="line-height: 1.5; font-family: 'Times New Roman'">Activity</span><span style="line-height: 1.5; font-family: 宋体">Q这U模式的</span><span style="line-height: 1.5; font-family: 'Times New Roman'">Activity</span><span style="line-height: 1.5; font-family: 宋体">的特Ҏ(gu)Q只要你创徏?/span><span style="line-height: 1.5; font-family: 'Times New Roman'">Activity</span><span style="line-height: 1.5; font-family: 宋体">实例Q一旦激z该</span><span style="line-height: 1.5; font-family: 'Times New Roman'">Activity</span><span style="line-height: 1.5; font-family: 宋体">Q则会向d栈中加入新创建的实例Q退?/span><span style="line-height: 1.5; font-family: 'Times New Roman'">Activity</span><span style="line-height: 1.5; font-family: 宋体">则会在Q务栈中销毁该实例?/span></span></p> <p style="text-align: left; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 10px auto; font: 13px/19px Verdana, Geneva, Arial, Helvetica, sans-serif; white-space: normal; letter-spacing: normal; color: rgb(75,75,75); word-spacing: 0px; -webkit-text-stroke-width: 0px" class="p0"> </p> <p style="text-align: left; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 10px auto 10px 30px; font: 13px/19px Verdana, Geneva, Arial, Helvetica, sans-serif; white-space: normal; letter-spacing: normal; color: rgb(75,75,75); word-spacing: 0px; -webkit-text-stroke-width: 0px" class="p0"><strong><span style="line-height: 1.5">2. </span><span style="line-height: 1.5">SingleTop<span style="line-height: 1.5; font-family: 宋体">模式</span></span></strong></p> <p style="text-align: left; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 10px auto 10px 30px; font: 13px/19px Verdana, Geneva, Arial, Helvetica, sans-serif; white-space: normal; letter-spacing: normal; color: rgb(75,75,75); word-spacing: 0px; -webkit-text-stroke-width: 0px" class="p0"><span style="line-height: 1.5">q种模式会考虑当前要激zȝ<span style="line-height: 1.5; font-family: 'Times New Roman'">Activity</span><span style="line-height: 1.5; font-family: 宋体">实例在Q务栈中是否正处于栈顶Q如果处于栈则无需重新创徏新的实例Q会重用已存在的实例Q否则会在Q务栈中创建新的实例?/span></span></p> <p style="text-align: left; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 10px auto 10px 30px; font: 13px/19px Verdana, Geneva, Arial, Helvetica, sans-serif; white-space: normal; letter-spacing: normal; color: rgb(75,75,75); word-spacing: 0px; -webkit-text-stroke-width: 0px" class="p0"><span style="line-height: 1.5"> </span></p> <p style="text-align: left; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 10px auto 10px 30px; font: 13px/19px Verdana, Geneva, Arial, Helvetica, sans-serif; white-space: normal; letter-spacing: normal; color: rgb(75,75,75); word-spacing: 0px; -webkit-text-stroke-width: 0px" class="p0"><strong><span style="line-height: 1.5">3. </span><span style="line-height: 1.5">SingleTask<span style="line-height: 1.5; font-family: 宋体">模式</span></span></strong></p> <p style="text-align: left; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 10px auto 10px 30px; font: 13px/19px Verdana, Geneva, Arial, Helvetica, sans-serif; white-space: normal; letter-spacing: normal; color: rgb(75,75,75); word-spacing: 0px; -webkit-text-stroke-width: 0px" class="p0"><span style="line-height: 1.5">如果d栈中存在该模式的<span style="line-height: 1.5; font-family: 'Times New Roman'">Activity</span><span style="line-height: 1.5; font-family: 宋体">实例Q则把栈中该实例以上?/span><span style="line-height: 1.5; font-family: 'Times New Roman'">Activity</span><span style="line-height: 1.5; font-family: 宋体">实例全部U除Q调用该实例?/span><span style="line-height: 1.5; font-family: 'Times New Roman'">newInstance()</span><span style="line-height: 1.5; font-family: 宋体">Ҏ(gu)重用?/span><span style="line-height: 1.5; font-family: 'Times New Roman'">Activity</span><span style="line-height: 1.5; font-family: 宋体">Q该实例处於栈位|,否则重新创Z个新?/span><span style="line-height: 1.5; font-family: 'Times New Roman'">Activity</span><span style="line-height: 1.5; font-family: 宋体">实例?/span></span></p> <p style="text-align: left; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 10px auto; font: 13px/19px Verdana, Geneva, Arial, Helvetica, sans-serif; white-space: normal; letter-spacing: normal; color: rgb(75,75,75); word-spacing: 0px; -webkit-text-stroke-width: 0px" class="p0"> </p> <p style="text-align: left; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 10px auto 10px 30px; font: 13px/19px Verdana, Geneva, Arial, Helvetica, sans-serif; white-space: normal; letter-spacing: normal; color: rgb(75,75,75); word-spacing: 0px; -webkit-text-stroke-width: 0px" class="p0"><strong><span style="line-height: 1.5">4. </span><span style="line-height: 1.5">SingleInstance<span style="line-height: 1.5; font-family: 宋体">模式</span></span></strong></p> <p style="text-align: left; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 10px auto 10px 30px; font: 13px/19px Verdana, Geneva, Arial, Helvetica, sans-serif; white-space: normal; letter-spacing: normal; color: rgb(75,75,75); word-spacing: 0px; -webkit-text-stroke-width: 0px" class="p0"><span style="line-height: 1.5">当该模式<span style="line-height: 1.5; font-family: 'Times New Roman'">Activity</span><span style="line-height: 1.5; font-family: 宋体">实例在Q务栈中创建后Q只要该实例q在d栈中Q即只要Ȁzȝ是该cd?/span><span style="line-height: 1.5; font-family: 'Times New Roman'">Activity</span><span style="line-height: 1.5; font-family: 宋体">Q都会通过调用实例?/span><span style="line-height: 1.5; font-family: 'Times New Roman'">newInstance()</span><span style="line-height: 1.5; font-family: 宋体">Ҏ(gu)重用?/span><span style="line-height: 1.5; font-family: 'Times New Roman'">Activity</span><span style="line-height: 1.5; font-family: 宋体">Q此时用的都是同一?/span><span style="line-height: 1.5; font-family: 'Times New Roman'">Activity实例</span><span style="line-height: 1.5; font-family: 宋体">Q它都会处于d栈的栈顶。此模式一般用于加载较慢的Q比较耗性能且不需要每ơ都重新创徏?/span><span style="line-height: 1.5; font-family: 'Times New Roman'">Activity</span><span style="line-height: 1.5; font-family: 宋体">?/span></span></p><img src ="http://www.aygfsteel.com/ZouYonghui/aggbug/425872.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/ZouYonghui/" target="_blank">Terry Zou</a> 2015-06-24 18:10 <a href="http://www.aygfsteel.com/ZouYonghui/archive/2015/06/24/425872.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>android中跨q程通讯?U方?/title><link>http://www.aygfsteel.com/ZouYonghui/archive/2015/06/24/425871.html</link><dc:creator>Terry Zou</dc:creator><author>Terry Zou</author><pubDate>Wed, 24 Jun 2015 09:28:00 GMT</pubDate><guid>http://www.aygfsteel.com/ZouYonghui/archive/2015/06/24/425871.html</guid><wfw:comment>http://www.aygfsteel.com/ZouYonghui/comments/425871.html</wfw:comment><comments>http://www.aygfsteel.com/ZouYonghui/archive/2015/06/24/425871.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/ZouYonghui/comments/commentRss/425871.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/ZouYonghui/services/trackbacks/425871.html</trackback:ping><description><![CDATA[     摘要: android中跨q程通讯?U方? 转自Qhttp://www.cnblogs.com/sevenyuan/archive/2013/03/22/2975122.html׃androidpȝ中应用程序之间不能共享内存。因此,在不同应用程序之间交互数据(跨进E通讯Q就E微ȝ一些。在android SDK中提供了4U用于跨q程通讯的方式。这4U方式正好对应于androidpȝ?U应?..  <a href='http://www.aygfsteel.com/ZouYonghui/archive/2015/06/24/425871.html'>阅读全文</a><img src ="http://www.aygfsteel.com/ZouYonghui/aggbug/425871.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/ZouYonghui/" target="_blank">Terry Zou</a> 2015-06-24 17:28 <a href="http://www.aygfsteel.com/ZouYonghui/archive/2015/06/24/425871.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Android 一个应用中只有一个进E么Q还是可以有多个http://www.aygfsteel.com/ZouYonghui/archive/2015/06/24/425869.htmlTerry ZouTerry ZouWed, 24 Jun 2015 09:12:00 GMThttp://www.aygfsteel.com/ZouYonghui/archive/2015/06/24/425869.htmlhttp://www.aygfsteel.com/ZouYonghui/comments/425869.htmlhttp://www.aygfsteel.com/ZouYonghui/archive/2015/06/24/425869.html#Feedback0http://www.aygfsteel.com/ZouYonghui/comments/commentRss/425869.htmlhttp://www.aygfsteel.com/ZouYonghui/services/trackbacks/425869.htmlAndroid 手机上的应用一般情况下都在一个进E中q行?/p>

但是Q也可以指定Activity或者Service在Remote q程中执行。多数情况下Q只有在用户认ؓ应用退出后q需要l后台长期运行的应用Q才需要这样做。此Ӟ该应用有两个q程?/p>

q有一Uhack的方式,在apk中通过调用命o行来启动另外的进E。此U方式用户不可见Q也不安全。不提倡?/p>

Terry Zou 2015-06-24 17:12 发表评论
]]>
վ֩ģ壺 | | | | | Ͽ| | ԫ| | Ҧ| | ֳ| ʮ| | | ʡ| | | | ٳ| | | ͬ| | | ¹| ī| | ʡ| | | | Ͷ| ٤ʦ| | ¡| Դ| | | | ֶ|