<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 93,  comments - 2,  trackbacks - 0
      2020年4月16日
    1.必須安裝nodejs
    2.安裝cnpm用cnpm替代npm
        地址:http://npm.taobao.org/
    安裝cnpm:
    npm install -g cnpm --registry=https://registry.npm.taobao.org

    3、用yarn替代npm
    yarn的安裝:
    第一種方法:參考官方文檔https://yarn.bootcss.com/
    第二種方法:cnpm install -g yarn  或者 npm install -g yarn
    4、搭建React開發(fā)環(huán)境的第一種方法(老-現(xiàn)在推薦):
    https://reactjs.org/docs/create-a-new-react-app.html
    1、必須要安裝nodejs     注意:安裝nodejs穩(wěn)定版本      教程中的nodejs版本:v8.11.2            教程中的npm版本:v5.6.0
    2.安裝腳手架工具   (單文件組件項(xiàng)目生成工具)   只需要安裝一次
    npm install -g create-react-app   /  cnpm install -g create-react-app
    3.創(chuàng)建項(xiàng)目   (可能創(chuàng)建多次)
    找到項(xiàng)目要?jiǎng)?chuàng)建的目錄:
                    create-react-app reactdemo
    4.cd  到項(xiàng)目里面
            cd  reactdemo
                    npm start             yarn start運(yùn)行項(xiàng)目
                    npm run build         yarn build 生成項(xiàng)目
    5、搭建React的開發(fā)環(huán)境的第二種方法(新-未來推薦):
            https://reactjs.org/docs/create-a-new-react-app.html
            1、必須要安裝nodejs     注意:安裝nodejs穩(wěn)定版本      教程中的nodejs版本:v8.11.2            教程中的npm版本:v5.6.0
            2.安裝腳手架工具并創(chuàng)建項(xiàng)目
                找到項(xiàng)目要?jiǎng)?chuàng)建的目錄執(zhí)行:
    npx create-react-app reactdemo
    4.cd  到項(xiàng)目里面
            cd  reactdemo
                    npm start  運(yùn)行項(xiàng)目(調(diào)試)
                    npm run build 生成項(xiàng)目(發(fā)布)
    npx介紹:
    npm v5.2.0引入的一條命令(npx),引入這個(gè)命令的目的是為了提升開發(fā)者使用包內(nèi)提供的命令行工具的體驗(yàn)。
    詳情:
            npx create-react-app reactdemo這條命令會(huì)臨時(shí)安裝 create-react-app 包,命令完成后create-react-app 會(huì)刪掉,不會(huì)出現(xiàn)在 global 中。下次再執(zhí)行,還是會(huì)重新臨時(shí)安裝。
    npx 會(huì)幫你執(zhí)行依賴包里的二進(jìn)制文件。
            再比如 npx http-server 可以一句話幫你開啟一個(gè)靜態(tài)服務(wù)器
    posted @ 2020-04-16 15:25 Terry Zou 閱讀(308) | 評(píng)論 (0)編輯 收藏
      2020年4月9日
    @PostConstruct
    PostConstruct注釋用于在完成依賴項(xiàng)注入以執(zhí)行任何初始化之后需要執(zhí)行的方法。必須在類投入使用之前調(diào)用此方法。
    所有支持依賴注入的類都必須支持此注釋。即使類沒有請(qǐng)求注入任何資源,也必須調(diào)用使用PostConstruct注釋的方法。
    只有一個(gè)方法可以使用此批注進(jìn)行批注。
    應(yīng)用PostConstruct注釋的方法必須滿足以下所有條件:除了攔截器之外,方法絕不能有任何參數(shù),在這種情況下它采用Interceptor規(guī)范定義的InvocationContext對(duì)象。
    在攔截器類上定義的方法必須具有以下簽名之一:
    void <METHOD>(InvocationContext)Object <METHOD>(InvocationContext)拋出異常注意:
    PostConstruct攔截器方法不能拋出應(yīng)用程序異常,但可以聲明它拋出檢查異常,包括java.lang.Exception,
    如果相同的攔截器方法除了生命周期事件之外插入業(yè)務(wù)或超時(shí)方法。
    如果PostConstruct攔截器方法返回一個(gè)值,容器將忽略它。
    在非攔截器類上定義的方法必須具有以下簽名:void <METHOD>()應(yīng)用PostConstruct的方法可以是publicprotectedpackage privateprivate。
    除應(yīng)用程序客戶端外,該方法絕不能是靜態(tài)的。
    該方法可能是最終的。如果該方法拋出一個(gè)未經(jīng)檢查的異常,那么該類絕不能投入使用,除非EJB可以處理異常甚至從它們恢復(fù)的EJB

    然后就會(huì)思考問題,這個(gè)注釋是修飾初始化之后需要執(zhí)行的方法,那么它和@Autowired、構(gòu)造函數(shù)的執(zhí)行順序是什么呢?(當(dāng)然注釋中已經(jīng)說明了PostConstruct注釋用于在完成依賴項(xiàng)注入之后)
    @Service
    public class BeanA {

        @Autowired
        private BeanB beanB;

        public BeanA() {
            System.out.println("這是Bean A 的構(gòu)造方法");
        }
        @PostConstruct
        private void init() {
            System.out.println("這是BeanA的 init 方法");
            beanB.testB();
        }
    }
    @Service
    public class BeanB {

        @PostConstruct
        private void init() {
            System.out.println("這是BeanB 的init 方法");
        }
        public BeanB() {
            System.out.println("這是Bean B的 構(gòu)造方法");
        }
        void testB() {
            System.out.println("這是Bean B 的 testB 方法");
        }
    }

    啟動(dòng)后輸出:
    這是Bean A 的構(gòu)造方法 
    這是Bean B的 構(gòu)造方法
    這是BeanB 的init 方法
    這是BeanA的 init 方法
    這是Bean B 的 testB 方法

    所以得到結(jié)論: 構(gòu)造方法 > @Autowired > @PostConstruct
    posted @ 2020-04-09 15:29 Terry Zou 閱讀(309) | 評(píng)論 (0)編輯 收藏
    1、ApplicationContext
    Spring的核心,Context我們通常解釋為上下文環(huán)境。ApplicationContext則是應(yīng)用的容器。 Spring把Bean(object)放在容器中,需要用就通過get方法取出來。在ApplicationContext接口的眾多實(shí)現(xiàn)類中,有3個(gè)是我們經(jīng)常用到的(見表1-1),并且使用這3個(gè)實(shí)現(xiàn)類也基本能滿足我們Java EE應(yīng)用開發(fā)中的絕大部分需求。
    表1-1 ApplicationContext接口的常用實(shí)現(xiàn)類介紹
    ClassPathXmlApplicationContext
    從類路徑ClassPath中尋找指定的XML配置文件,找到并裝載完成ApplicationContext的實(shí)例化工作。例如: //裝載單個(gè)配置文件實(shí)例化ApplicationContext容器
    ApplicationContext cxt = new ClassPathXmlApplicationContext("applicationContext.xml");
    //裝載多個(gè)配置文件實(shí)例化ApplicationContext容器
    String[] configs = {"bean1.xml","bean2.xml","bean3.xml"};
    ApplicationContext cxt = new ClassPathXmlApplicationContext(configs);
    FileSystemXmlApplicationContext
    從指定的文件系統(tǒng)路徑中尋找指定的XML配置文件,找到并裝載完成ApplicationContext的實(shí)例化工作。例如://裝載單個(gè)配置文件實(shí)例化ApplicationContext容器
    ApplicationContext cxt = new FileSystemXMLApplicationContext("beans.xml");
    //裝載多個(gè)配置文件實(shí)例化ApplicationContext容器
    String[] configs = {"c:/beans1.xml","c:/beans2.xml"};
    ApplicationContext cxt = new FileSystemXmlApplicationContext(configs);
    XmlWebApplicationContext
    從Web應(yīng)用中尋找指定的XML配置文件,找到并裝載完成ApplicationContext的實(shí)例化工作。這是為Web工程量身定制的,使用WebApplicationContextUtils類的getRequiredWebApplicationContext方法可在JSP與Servlet中取得IoC容器的引用
    2、ApplicationEvent
    是個(gè)抽象類,里面只有一個(gè)構(gòu)造函數(shù)和一個(gè)長整型的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

    是一個(gè)接口,里面只有一個(gè)onApplicationEvent方法。如果在上下文中部署一個(gè)實(shí)現(xiàn)了ApplicationListener接口的bean,那么每當(dāng)在一個(gè)ApplicationEvent發(fā)布到 ApplicationContext時(shí),調(diào)用ApplicationContext.publishEvent()方法,這個(gè)bean得到通知。類似于Oberver設(shè)計(jì)模式。
    其源碼如下:

    public interface ApplicationListener<E extends ApplicationEvent> extends EventListener {
        /**
         * Handle an application event.
         * 
    @param event the event to respond to
         
    */
        void onApplicationEvent(E event);
     
    }
    下面舉個(gè)例子
    自定義事件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;
        }
    }

    定義監(jiān)聽器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("郵件地址:" + event.getEmail());
            System.out.println("郵件內(nèi)容:" + event.getContent());
        }
    }

    單元測(cè)試類ListenerTest:
    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);
        }
    }
    posted @ 2020-04-09 14:47 Terry Zou 閱讀(1282) | 評(píng)論 (0)編輯 收藏

    之前用戶使用的是3個(gè)注解注解他們的main類。分別是@Configuration,@EnableAutoConfiguration,@ComponentScan。由于這些注解一般都是一起使用,spring boot提供了一個(gè)統(tǒng)一的注解@SpringBootApplication。

    @SpringBootApplication = (默認(rèn)屬性)@Configuration + @EnableAutoConfiguration + @ComponentScan。

    @SpringBootApplication 
    public class ApplicationMain { 
        public static void main(String[] args) { 
            SpringApplication.run(Application.class, args); 
        } 
    }

    分開解釋@Configuration,@EnableAutoConfiguration,@ComponentScan。
    1、@Configuration:提到@Configuration就要提到他的搭檔@Bean。使用這兩個(gè)注解就可以創(chuàng)建一個(gè)簡(jiǎn)單的spring配置類,可以用來替代相應(yīng)的xml配置文件。

    <beans> 
        <bean id = "car" class="com.test.Car"> 
            <property name="wheel" ref = "wheel"></property> 
        </bean> 
        <bean id = "wheel" class="com.test.Wheel"></bean> 
    </beans> 

     相當(dāng)于:

    @Configuration 
    public class Conf { 
        @Bean 
        public Car car() { 
            Car car = new Car(); 
            car.setWheel(wheel()); 
            return car; 
        } 
        @Bean  
        public Wheel wheel() { 
            return new Wheel(); 
        } 
    }

    @Configuration的注解類標(biāo)識(shí)這個(gè)類可以使用Spring IoC容器作為bean定義的來源。@Bean注解告訴Spring,一個(gè)帶有@Bean的注解方法將返回一個(gè)對(duì)象,該對(duì)象應(yīng)該被注冊(cè)為在Spring應(yīng)用程序上下文中的bean。

    2、@EnableAutoConfiguration:能夠自動(dòng)配置spring的上下文,試圖猜測(cè)和配置你想要的bean類,通常會(huì)自動(dòng)根據(jù)你的類路徑和你的bean定義自動(dòng)配置。

    3、@ComponentScan:會(huì)自動(dòng)掃描指定包下的全部標(biāo)有@Component的類,并注冊(cè)成bean,當(dāng)然包括@Component下的子注解@Service,@Repository,@Controller。


    posted @ 2020-04-09 09:10 Terry Zou 閱讀(131) | 評(píng)論 (0)編輯 收藏
      2015年7月13日
    package com.zhihe.xqsh.utils;

    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.UnsupportedEncodingException;
    import java.util.Date;
    import java.util.List;

    import org.apache.http.HttpEntity;
    import org.apache.http.HttpResponse;
    import org.apache.http.HttpStatus;
    import org.apache.http.HttpVersion;
    import org.apache.http.NameValuePair;
    import org.apache.http.client.ClientProtocolException;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.entity.UrlEncodedFormEntity;
    import org.apache.http.client.methods.HttpGet;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.conn.ClientConnectionManager;
    import org.apache.http.conn.params.ConnManagerParams;
    import org.apache.http.conn.params.ConnRouteParams;
    import org.apache.http.conn.scheme.PlainSocketFactory;
    import org.apache.http.conn.scheme.Scheme;
    import org.apache.http.conn.scheme.SchemeRegistry;
    import org.apache.http.conn.ssl.SSLSocketFactory;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
    import org.apache.http.impl.cookie.BasicClientCookie;
    import org.apache.http.params.BasicHttpParams;
    import org.apache.http.params.HttpConnectionParams;
    import org.apache.http.params.HttpParams;
    import org.apache.http.params.HttpProtocolParams;
    import org.apache.http.util.EntityUtils;

    import com.zhihe.xqsh.network.ServerErrorException;

    import android.accounts.NetworkErrorException;
    import android.annotation.SuppressLint;
    import android.util.Log;


    public class CustomerHttpClient {
    private static final String TAG = CustomerHttpClient.class.getSimpleName();

    private static DefaultHttpClient customerHttpClient;

    private CustomerHttpClient() {
    }

    public static synchronized HttpClient getHttpClient() {
    if (null == customerHttpClient) {
    HttpParams params = new BasicHttpParams();
    // 設(shè)置????基本參數(shù)
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, "UTF-8");
    HttpProtocolParams.setUseExpectContinue(params, true);
    HttpProtocolParams.setUserAgent(params, "Mozilla/5.0(Linux;U;Android 2.2.1;en-us;Nexus One Build.FRG83) "
    + "AppleWebKit/553.1(KHTML,like Gecko) Version/4.0 Mobile Safari/533.1");
    // 超時(shí)設(shè)置
    /* 從連接池中取連接的超時(shí)時(shí)??*/
    ConnManagerParams.setTimeout(params, 2000);
    ConnManagerParams.setMaxTotalConnections(params, 800);
    /* 連接超時(shí) */
    HttpConnectionParams.setConnectionTimeout(params, 5000);
    /* 請(qǐng)求超時(shí) */
    HttpConnectionParams.setSoTimeout(params, 10000);

    // 設(shè)置我們的HttpClient支持HTTP和HTTPS兩種模式
    SchemeRegistry schReg = new SchemeRegistry();
    schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

    // 使用線程安全的連接管理來創(chuàng)建HttpClient
    ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schReg);
    // ????連接數(shù):ConnManagerParams.setMaxTotalConnections(params, 50);
    customerHttpClient = new DefaultHttpClient(conMgr, params);
    }
    return customerHttpClient;
    }

    /**
    * 以get方式提交數(shù)據(jù)
    * @param url 提交地址
    * @param params 參數(shù)
    * @return 響應(yīng)結(jié)果
    * @throws ServerErrorException 請(qǐng)求失敗
    * @throws NetworkErrorException 連接失敗
    */
    public static String get(String url, String params) throws ServerErrorException, NetworkErrorException {
    int tryTimes = 0;
    NullPointerException ex;
    do {
    try {
    return tryGet(url, params);
    } catch (NullPointerException e) {
    ex = e;
    tryTimes++;
    }
    } while (tryTimes < 3);
    throw ex;
    }

    /**
    * 以get方式提交數(shù)據(jù)
    * @param url 提交地址
    * @param params 參數(shù)
    * @return 響應(yīng)結(jié)果
    * @throws ServerErrorException 請(qǐng)求失敗
    * @throws NetworkErrorException 連接失敗
    */
    public static String tryGet(String url, String params) throws ServerErrorException, NetworkErrorException {
    try {
    HttpGet request = new HttpGet(url + params);

    /*if (LotteryApplication.isCmwap()) {
    org.apache.http.HttpHost proxy = new org.apache.http.HttpHost("10.0.0.172", 80, "http");
    HttpParams httpParams = new BasicHttpParams();
    ConnRouteParams.setDefaultProxy(httpParams, proxy);
    request.setParams(httpParams);
    }*/

    HttpClient client = getHttpClient();
    HttpResponse response = client.execute(request);
    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
    throw new ServerErrorException("????????æ???????????");
    }
    HttpEntity resEntity = response.getEntity();
    String result = (resEntity == null) ? null : EntityUtils.toString(resEntity, "UTF-8");
    return result;
    } catch (UnsupportedEncodingException e) {
    logw(e.getMessage());
    return null;
    } catch (ClientProtocolException e) {
    logw(e.getMessage());
    return null;
    } catch (IOException e) {
    throw new NetworkErrorException("??????????????????????", e);
    }
    }

    private static void logw(String string) {
    if (string != null) {
    Log.w(TAG, string);
    }
    }

    /**
    * 以post方式提交數(shù)據(jù)
    * @param url 提交地址
    * @param params 參數(shù)
    * @return 響應(yīng)結(jié)果
    * @throws ServerErrorException 請(qǐng)求失敗
    * @throws NetworkErrorException 連接失敗
    */
    public static String post(String url, List<NameValuePair> params) throws ServerErrorException, NetworkErrorException {
    return post(url, params, null);
    }

    /**
    * 以post方式提交數(shù)據(jù)
    * @param url 提交地址
    * @param params 參數(shù)
    * @param soTimeout 響應(yīng)超時(shí)時(shí)間,單位毫??
    * @return 響應(yīng)結(jié)果
    * @throws ServerErrorException 請(qǐng)求失敗
    * @throws NetworkErrorException 連接失敗
    */
    public static String post(String url, List<NameValuePair> params, int soTimeout) throws ServerErrorException,
    NetworkErrorException {
    HttpParams httpParams;
    if (soTimeout <= 0) {
    httpParams = null;
    } else {
    httpParams = new BasicHttpParams();
    HttpConnectionParams.setSoTimeout(httpParams, soTimeout);
    }
    return post(url, params, httpParams);
    }

    /**
    * 以post方式提交數(shù)據(jù)
    * @param url 提交地址
    * @param params 參數(shù)
    * @param httpParams http參數(shù)
    * @return 響應(yīng)結(jié)果
    * @throws ServerErrorException 請(qǐng)求失敗
    * @throws NetworkErrorException 連接失敗
    */
    public static String post(String url, List<NameValuePair> params, HttpParams httpParams) throws ServerErrorException,
    NetworkErrorException {
    int tryTimes = 0;
    NullPointerException ex;
    do {
    try {
    return tryPost(url, params, httpParams);
    } catch (NullPointerException e) {
    ex = e;
    tryTimes++;
    }
    } while (tryTimes < 3);
    throw ex;
    }

    /**
    * 以post方式提交數(shù)據(jù)
    * @param url 提交地址
    * @param params 參數(shù)
    * @param httpParams http參數(shù)
    * @return 響應(yīng)結(jié)果
    * @throws ServerErrorException 請(qǐng)求失敗
    * @throws NetworkErrorException 連接失敗
    */
    public static String tryPost(String url, List<NameValuePair> params, HttpParams httpParams) throws ServerErrorException,
    NetworkErrorException {
    try {
    HttpPost request = new HttpPost(url);
    if (params != null && params.size() > 0) {
    request.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
    }

    // if (LotteryApplication.isCmwap()) {
    // org.apache.http.HttpHost proxy = new org.apache.http.HttpHost("10.0.0.172", 80, "http");
    // if (httpParams == null)
    // httpParams = new BasicHttpParams();
    // ConnRouteParams.setDefaultProxy(httpParams, proxy);
    // }

    if (httpParams != null)
    request.setParams(httpParams);
    //Log.v("CS", params.toString());
    HttpClient client = getHttpClient();
    HttpResponse response = client.execute(request);
    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
    //Log.v("CS", params.toString());
    //Log.v("CS", response.getStatusLine().getStatusCode() + "");
    request.abort(); 
    throw new ServerErrorException("????????æ???????????");
    }
    if (response.getStatusLine ().getStatusCode () != 200) {  
    request.abort();  //?ж?????,?????????????????????
                    return null;  
                } 
    HttpEntity resEntity = response.getEntity();
    String result = (resEntity == null) ? null : EntityUtils.toString(resEntity, "UTF-8");
    //Log.v("CS", params.toString() + "||||" + result);
    return result;
    } catch (UnsupportedEncodingException e) {
    logw(e.getMessage());
    return null;
    } catch (ClientProtocolException e) {
    logw(e.getMessage());
    return null;
    } catch (IOException e) {
    throw new NetworkErrorException(e.getMessage(), e);
    //throw new NetworkErrorException("連接不成功,請(qǐng)檢查網(wǎng)絡(luò)設(shè)??, e);
    }
    }

    @SuppressLint("SdCardPath")
    public static String download(String url) throws ServerErrorException, NetworkErrorException {
    try {
    //Log.i("http-download", url);
    HttpPost request = new HttpPost(url);
    HttpClient client = getHttpClient();
    HttpResponse response = client.execute(request);
    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
    throw new ServerErrorException("????????æ???????????");
    }

    HttpEntity entity = response.getEntity();
    InputStream is = entity.getContent();
    if (is == null)
    throw new ServerErrorException("stream is null ");

    String fileExt = url.substring(url.lastIndexOf(".") + 1, url.length()).toLowerCase();
    String fileName = url.substring(url.lastIndexOf("/") + 1, url.lastIndexOf("."));

    File tempFile = new File("/sdcard/" + fileName + "." + fileExt);
    if (!tempFile.exists())
    tempFile.createNewFile();
    FileOutputStream fileOutputStream = new FileOutputStream(tempFile);

    byte[] buf = new byte[1024];
    int ch;
    while ((ch = is.read(buf)) != -1) {
    fileOutputStream.write(buf, 0, ch);
    }

    fileOutputStream.flush();
    fileOutputStream.close();
    return tempFile.getAbsolutePath();
    } catch (UnsupportedEncodingException e) {
    logw(e.getMessage());
    return null;
    } catch (ClientProtocolException e) {
    logw(e.getMessage());
    return null;
    } catch (IOException e) {
    throw new NetworkErrorException(e.getMessage(), e);
    }
    }

    /**
    * 清空cookie
    */
    public static void clearCookie() {
    if (customerHttpClient != null)
    customerHttpClient.getCookieStore().clear();
    }

    /**
    * 清除指定cookie
    * @param name cookie名稱
    */
    public static void clearCookie(String name) {
    if (customerHttpClient == null)
    return;

    BasicClientCookie expiredCookie = new BasicClientCookie(name, "null");
    expiredCookie.setExpiryDate(new Date(System.currentTimeMillis() - 1000));
    customerHttpClient.getCookieStore().addCookie(expiredCookie);
    }
    }
    posted @ 2015-07-13 22:10 Terry Zou 閱讀(282) | 評(píng)論 (0)編輯 收藏
    ffg
    http://yunpan.cn/ccdbTgQaYa4U7
    posted @ 2015-07-13 11:04 Terry Zou 閱讀(141) | 評(píng)論 (0)編輯 收藏
      2015年7月9日
    abe
    private Drawable img_time_filter,img_time_filter_selected ;
    //過濾器TextView中顯示的圖片
    img_time_filter = getResources().getDrawable(R.drawable.time_filter);
    //調(diào)用setCompoundDrawables時(shí),必須調(diào)用Drawable.setBounds()方法,否則圖片不顯示
    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);
    posted @ 2015-07-09 00:04 Terry Zou 閱讀(211) | 評(píng)論 (0)編輯 收藏
      2015年7月8日
    abd
    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white"
        android:orientation="vertical" >
        <com.baidu.mapapi.map.MapView
            android:id="@+id/bmapView_routePlanActivity"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clickable="true" />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:background="@drawable/common_title_back"
            android:gravity="center"
            android:padding="5dp" >
            <Button
                android:id="@+id/button_transit_routePlan"
                android:layout_width="0dp"
                android:drawableLeft="@drawable/ic_bus"
                android:padding="5dp"
                android:background="@drawable/selector_white_gray"
                android:layout_height="50dp"
                android:layout_weight="1.0"
                android:onClick="SearchButtonProcess"
                android:text="公交" />
            <Button
                android:id="@+id/button_drive_routePlan"
                android:layout_width="0dp"
                 android:drawableLeft="@drawable/ic_drive"
                android:layout_height="50dp"
                android:layout_weight="1.0"
                android:padding="5dp"
                android:background="@drawable/selector_white_gray"
                android:onClick="SearchButtonProcess"
                android:text="駕車" />
            <Button
                android:id="@+id/button_walk_routePlan"
                android:layout_width="0dp"
                android:layout_height="50dp"
                 android:drawableLeft="@drawable/ic_walk"
                android:layout_weight="1.0"
                android:padding="5dp"
                android:background="@drawable/selector_white_gray"
                android:onClick="SearchButtonProcess"
                android:text="步行" />
        </LinearLayout>
        <LinearLayout
            android:id="@+id/linearLayout_node_routePlan"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="10dip"
            android:visibility="gone"
            android:gravity="bottom|center_horizontal" >
            <Button
                android:id="@+id/button_pre_routePlan"
                android:layout_width="60dp"
                android:layout_height="30dp"
                android:layout_marginRight="2dip"
                android:background="@drawable/pre_"
                android:onClick="nodeClick" />
            <Button
                android:id="@+id/button_next_routePlan"
                android:layout_width="60dp"
                android:layout_height="30dp"
                android:layout_marginLeft="2dip"
                android:background="@drawable/next_"
                android:onClick="nodeClick" />
        </LinearLayout>
    </FrameLayout>
    posted @ 2015-07-08 23:57 Terry Zou| 編輯 收藏
    abc
    <LinearLayout
               android:id="@+id/estate_linear"
               android:layout_width="fill_parent"
               android:layout_height="35dp"
               android:layout_weight="1"
               android:background="@drawable/border_rounded_gray_white"
               android:layout_gravity="center_vertical"
               android:gravity="center_vertical"
               android:layout_margin="5dp"
               android:orientation="horizontal" >
    <ImageButton
               android:id="@+id/object_btn_search"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_marginLeft="8dp"
               android:layout_gravity="center_vertical|right"
               android:background="@drawable/btn_search"
               android:contentDescription="@null"
               android:scaleType="fitXY" />
    <RelativeLayout
                android:layout_width="1dp"
                android:layout_height="33dp"
                android:layout_marginLeft="8dp"
                android:background="@color/color_line" />
                <EditText
                     android:id="@+id/object_et_content"
                     style="@style/StringSearchText"
                     android:layout_gravity="left|center_vertical"
                     android:layout_marginLeft="2dp"
                     android:layout_marginRight="8dp"
                     android:layout_weight="1"
                     android:background="@null"
                     android:hint="@string/tip_search_hint"
                     android:imeOptions="actionSend"
                     android:singleLine="true"
                     android:textCursorDrawable="@null"
                     android:textColorHint="#626463" />
                <ImageButton
                     android:id="@+id/object_btn_del"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:layout_gravity="right|center_vertical"
                     android:layout_marginRight="10dp"
                     android:background="@drawable/ic_clear" />
             </LinearLayout>


    border_rounded_gray_white.xml
    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
        <!-- 連框顏色值 -->
        <item>
            <shape>
                <solid android:color="@color/bg_gray" />
                <corners
                    android:bottomLeftRadius="3dp"
                    android:bottomRightRadius="3dp"
                    android:topLeftRadius="3dp"
                    android:topRightRadius="3dp" />
            </shape>
        </item>
        <!-- 主體背景顏色值 -->
        <item
            android:bottom="1dp"
            android:left="1dp"
            android:right="1dp"
            android:top="1dp">
            <shape>
                <solid android:color="@color/white" />
                <corners
                    android:bottomLeftRadius="3dp"
                    android:bottomRightRadius="3dp"
                    android:topLeftRadius="3dp"
                    android:topRightRadius="3dp" />
            </shape>
        </item>
    </layer-list>

    <style name="StringSearchText">
            <item name="android:textSize">14dp</item>
            <item name="android:layout_width">wrap_content</item>
            <item name="android:layout_height">wrap_content</item>
            <item name="android:textColor">@android:color/black</item>
        </style>

    btn_search.xml
    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <!-- 沒有焦點(diǎn)時(shí)的背景圖片 -->
        <item android:drawable="@drawable/ic_search_normal" android:state_window_focused="false"/>
        <!-- 非觸摸模式下獲得焦點(diǎn)并單擊時(shí)的背景圖片 -->
        <item android:drawable="@drawable/ic_search_pressed" android:state_focused="true" android:state_pressed="true"/>
        <!-- 觸摸模式下單擊時(shí)的背景圖片 -->
        <item android:drawable="@drawable/ic_search_pressed" android:state_focused="false" android:state_pressed="true"/>
        <!-- 選中時(shí)的圖片背景 -->
        <item android:drawable="@drawable/ic_search_pressed" android:state_selected="true"/>
        <!-- 獲得焦點(diǎn)時(shí)的圖片背景 -->
        <item android:drawable="@drawable/ic_search_pressed" android:state_focused="true"/>
        <!-- 默認(rèn)圖片背景 -->
        <item android:drawable="@drawable/ic_search_normal"/>
    </selector>

    <color name="color_line">#bebebe</color>



    private TextWatcher textWatcher = new TextWatcher() {
    @Override
    public void beforeTextChanged(CharSequence s, int start, int count,
    int after) {
    }
    @Override
    public void onTextChanged(CharSequence s, int start, int before,
    int count) {
    }
    @Override
    public void afterTextChanged(Editable s) {
    mKeywords = tv_keyword.getText().toString();
    AgUtils.log(TAG+"mKeywords:"+mKeywords, 4);
    if (TextUtils.isEmpty(mKeywords)) {
    object_btn_del.setVisibility(View.GONE);
    } else {
    object_btn_del.setVisibility(View.VISIBLE);
    searchIndexListInfo();
    }
    }
    };

    tv_keyword.addTextChangedListener(textWatcher);
    posted @ 2015-07-08 23:55 Terry Zou| 編輯 收藏
      2015年6月24日

    轉(zhuǎn)載:http://www.cnblogs.com/allenzheng/archive/2013/04/28/3050065.html
    當(dāng)應(yīng)用運(yùn)行起來后就會(huì)開啟一條線程,線程中會(huì)運(yùn)行一個(gè)任務(wù)棧,當(dāng)Activity實(shí)例創(chuàng)建后就會(huì)放入任務(wù)棧中。Activity啟動(dòng)模式的設(shè)置在
    AndroidManifest.xml文件中,通過配置Activity的屬性android:launchMode=""設(shè)置

     

    1. Standared模式(默認(rèn))

    我們平時(shí)直接創(chuàng)建的Activity都是這種模式的Activity,這種模式的Activity的特點(diǎn)是:只要你創(chuàng)建了Activity實(shí)例,一旦激活該Activity,則會(huì)向任務(wù)棧中加入新創(chuàng)建的實(shí)例,退出Activity則會(huì)在任務(wù)棧中銷毀該實(shí)例。

     

    2. SingleTop模式

    這種模式會(huì)考慮當(dāng)前要激活的Activity實(shí)例在任務(wù)棧中是否正處于棧頂,如果處于棧頂則無需重新創(chuàng)建新的實(shí)例,會(huì)重用已存在的實(shí)例,否則會(huì)在任務(wù)棧中創(chuàng)建新的實(shí)例。

     

    3. SingleTask模式

    如果任務(wù)棧中存在該模式的Activity實(shí)例,則把棧中該實(shí)例以上的Activity實(shí)例全部移除,調(diào)用該實(shí)例的newInstance()方法重用該Activity,使該實(shí)例處於棧頂位置,否則就重新創(chuàng)建一個(gè)新的Activity實(shí)例。

     

    4. SingleInstance模式

    當(dāng)該模式Activity實(shí)例在任務(wù)棧中創(chuàng)建后,只要該實(shí)例還在任務(wù)棧中,即只要激活的是該類型的Activity,都會(huì)通過調(diào)用實(shí)例的newInstance()方法重用該Activity,此時(shí)使用的都是同一個(gè)Activity實(shí)例,它都會(huì)處于任務(wù)棧的棧頂。此模式一般用于加載較慢的,比較耗性能且不需要每次都重新創(chuàng)建的Activity

    posted @ 2015-06-24 18:10 Terry Zou 閱讀(472) | 評(píng)論 (0)編輯 收藏
    僅列出標(biāo)題  下一頁
    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    常用鏈接

    留言簿(2)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    相冊(cè)

    收藏夾

    Java

    搜索

    •  

    最新隨筆

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 777亚洲精品乱码久久久久久 | 亚洲一区二区三区首页| 亚洲最大成人网色| 亚洲乱码在线视频| 亚洲伊人久久大香线蕉综合图片| 亚洲情XO亚洲色XO无码| 亚洲午夜未满十八勿入| 久久亚洲精品无码观看不卡| 亚洲国产成人片在线观看| 亚洲综合日韩久久成人AV| 亚洲视频在线视频| 国产亚洲精aa在线看| 伊人久久国产免费观看视频| 免费国产成人午夜在线观看| 国产三级在线免费| 免费无码肉片在线观看| 亚洲av无码不卡私人影院| 亚洲AV综合色区无码另类小说| 亚洲欧洲精品无码AV| 亚洲福利电影一区二区?| 亚洲美女精品视频| 亚洲av成人一区二区三区在线播放| 一级片在线免费看| 亚洲一区免费在线观看| 中文字幕在线免费观看| 野花香在线视频免费观看大全 | 午夜神器成在线人成在线人免费 | 亚洲自偷自偷在线制服| 亚洲精品国产福利片| 看成年女人免费午夜视频| 污污免费在线观看| 日韩毛片在线免费观看| 日韩内射激情视频在线播放免费| 99re这里有免费视频精品| 国产精品美女自在线观看免费| 免费在线观看污网站| 超清首页国产亚洲丝袜| 亚洲w码欧洲s码免费| 91视频免费观看| 2021精品国产品免费观看 | 巨波霸乳在线永久免费视频|