android studio : rename package name

1. 重命名 包名

  1. In your Project pane, click on the little gear icon ( Gears icon )
  2. Uncheck / De-select the Compact Empty Middle Packages option

Compact Empty Middle Packages

  1. Your package directory will now be broken up in individual directories
  2. Individually select each directory you want to rename, and:
    • Right-click it
    • Select Refactor
    • Click on Rename
    • In the Pop-up dialog, click on Rename Package instead of Rename Directory
    • Enter the new name and hit Refactor
    • Allow a minute to let Android Studio update all changes
    • Note: When renaming com in Android Studio, it might give a warning. In such case, selectRename All

enter image description here

  1. Now open your Gradle Build File (build.gradle – Usually app or mobile). Update the applicationId to your new Package Name and Sync Gradle, if it hasn’t already been updated automatically:

Refactor Directories

  1. Done! Anyways, Android Studio needs to make this process a little simpler.

 

Selection_034

 

参考:http://stackoverflow.com/questions/16804093/android-studio-rename-package

android studio : 快捷键

1. android studio 的快捷键用的很不习惯,还是习惯eclipse
2. android studio 里有个选项可以选择eclipse的快捷键风格
3. 减少学习成本,快速上手

keymap

 

4. 自动提示doc
20140614163235750

 

5.  自动提示,忽略大小写

20140614162709687

 

参考:http://stormzhang.com/devtools/2014/12/09/android-studio-tutorial3/

http://blog.csdn.net/eclipsexys/article/details/30748339

android studio : 将project 作为library 引用

主要看官方文档

方法一.

Selection_032

 

方法二:

Selection_033

module : app [主程序]
module : mylibrary   【作为library】

修改:module : mylibrary
a) apply plugin: ‘com.android.application’ ——>apply plugin: ‘com.android.library’
b) //applicationId “com.example.chenwei.tmylibrary” 屏蔽自动生产的applicationId

修改:module : app
a)
dependencies {
compile project(“:mylibrary”)
}
最后,sync后就ok了

参考:
https://developer.android.com/sdk/installing/create-project.html

python logging 使用

1. 
TODO

import logging
import datetime
LOGDIR = os.path.join(DIRNAME,'log')
LOGFILE = datetime.datetime.now().strftime('%Y-%m-%d')+'.log'
logging.basicConfig(level=logging.DEBUG,
                    format='',
                    datefmt='%a, %d %b %Y %H:%M:%S',
                    filename = os.path.join(LOGDIR,LOGFILE),
                    filemode='a'
                    )

fileLog = logging.FileHandler(os.path.join(LOGDIR,LOGFILE),'w')
formatter = logging.Formatter('%(asctime)s %(name)s:%(levelname)s %(message)s')
fileLog.setFormatter(formatter)

logging.getLogger('demo').addHandler(fileLog)
logging.getLogger('demo').setLevel(logging.DEBUG)
logging.getLogger('demo').info(u'项目已启动:')

参考: http://www.cnblogs.com/BeginMan/p/3328671.html 【主要】
http://www.cnblogs.com/BeginMan/p/3335110.html 【主要】
http://blog.csdn.net/jgood/article/details/4340740

android MD5加密字符串

1.

public static String md5(String string) {
    byte[] hash;
    try {
        hash = MessageDigest.getInstance("MD5").digest(string.getBytes("UTF-8"));
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException("Huh, MD5 should be supported?", e);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException("Huh, UTF-8 should be supported?", e);
    }

    StringBuilder hex = new StringBuilder(hash.length * 2);
    for (byte b : hash) {
        if ((b & 0xFF) < 0x10) hex.append("0");
        hex.append(Integer.toHexString(b & 0xFF));
    }
    return hex.toString();
}

参考: http://www.cnblogs.com/bobli/archive/2012/03/26/2418694.html

google domains 被墙

1. 突然发现博客被墙了, ip ping的通,域名ping 不同,
查了下google domains name server

ns-cloud-e1.googledomains.com
ns-cloud-e2.googledomains.com
全部被墙

2. 查了写资料,使用dnspod 来解析域名,先保证能上网,以后有更好的选择再换

f1g1ns1.dnspod.net
f1g1ns2.dnspod.net

3. TODO 阿里dns云解析
http://www.net.cn/core/domain/tclist

4. dnspod 国际版
注: 当ip在国内的时候,可以打开网站;
当ip在国外的时候,打不开网站;

Selection_035

 

5.CloudFlare 【正在使用】,
解析速度快了很多

5.1  cloudflare subdomains

参考:

 

6. cloudxns [TODO]

参考: https://support.dnspod.cn/Kb/showarticle/tsid/177/#ChangeDomainNS
http://www.freehao123.com/ten-dns/
http://www.freehao123.com/linode-he-net/
http://www.tuicool.com/articles/QvIFJv

android与tornado交互(四): getinputstream

1. 服务端不打log/print

服务端

class RegisterHandler(tornado.web.RequestHandler):
    def get(self):
        print 'RegisterHandler  get()'

    def post(self,message):
        print 'RegisterHandler  post()'

客服端

private void testGet(){
        URL url = null;
        HttpURLConnection con = null;
        OutputStream out;
        try {
            url = new URL("http://192.168.1.104:8888/register");
            con = (HttpURLConnection) url.openConnection();
            con.setRequestMethod("POST");
            con.setConnectTimeout(10000);
            con.getInputStream();   //这句很关键
        } catch (IOException e) {
            Log.e(TAG, e.toString());
            e.printStackTrace();
        } finally {
            if (con != null) con.disconnect();
        }
    }

注: con.getInputStream(); 这句很重要,如果没写,服务器没反应,服务器log打不出来

2. bug: log

客服端

private void testRegister(){
        String Server_url="http://192.168.1.104:8888/register";
        URL url = null;
        HttpURLConnection con = null;
        OutputStream output = null;
        InputStream in = null;

        try {
            url = new URL(Server_url);
            Log.i(TAG,"url="+url.toString());
            con = (HttpURLConnection) url.openConnection();
            con.setRequestMethod("POST");
            con.setConnectTimeout(10000);

            con.getInputStream();     //注意这行
            output = con.getOutputStream();//注意这行

            output.write("hello world".toString().getBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }  finally {
           ........
        }
    }

结论: 注意 con.getInputStream(); 与 con.getOutputStream(); 的位置
    con.getInputStream(); 在 con.getOutputStream() 的前面,才引发这个bug

3. bug log [ java.io.IOException: stream closed]

private void testRegister(){
        String Server_url="http://192.168.1.104:8888/register";
        URL url = null;
        HttpURLConnection con = null;
        OutputStream output = null;
        InputStream in = null;

        try {
            url = new URL(Server_url);
            Log.i(TAG,"url="+url.toString());
            con = (HttpURLConnection) url.openConnection();
            con.setRequestMethod("POST");
            con.setConnectTimeout(10000);

            output = con.getOutputStream();
            con.getInputStream();     //注意这行

            output.write("hello world".toString().getBytes());//注意这行
        } catch (IOException e) {
            e.printStackTrace();
        }  finally {
           ........
        }
    }

结论: 注意 con.getInputStream(); 与 output.write() 的位置
    con.getInputStream(); 在 output.write() 的前面,才引发这个bug

4. 正确的写法

private void testRegister(){
        String Server_url="http://192.168.1.104:8888/register";
        URL url = null;
        HttpURLConnection con = null;
        OutputStream output = null;
        InputStream in = null;

        try {
            url = new URL(Server_url);
            Log.i(TAG,"url="+url.toString());
            con = (HttpURLConnection) url.openConnection();
            con.setRequestMethod("POST");
            con.setConnectTimeout(10000);

            output = con.getOutputStream();//注意这行
            output.write("hello world".toString().getBytes());//注意这行
       con.getInputStream();     //注意这行
        } catch (IOException e) {
            e.printStackTrace();
        }  finally {
           ........
        }
    }

注意: con.getOutputStream(), output.write(), con.getInputStream(); 这三行的位置