1.网络连接通信
HttpClient 类通信(见《第一行代码》 郭霖2014.8月第一版P385)
Android Asynchronous Http Client (见 http://loopj.com/android-async-http/ )
更多见 https://github.com/itheima1/Android
2.网页浏览 webView
https://github.com/getlantern/FinestWebView-Android
3.日志工具(一个静态类)
public class LogUtil{ public static final int VERBOSE =1; public static final int DEBUG =2; public static final int INFO=3; public static final int WARN=4; public static final int ERROR=5; public static final int NOTHING=6; public static final int LEVEL=VERBOSE; public static void v(String tag,String msg){ if(VERBOSE>=LEVEL){ Log.v(tag,msg); } } public static void d(String tag,String msg){ if(DEBUG>=LEVEL) { Log.d(tag,msg); } } public static void i(String tag,String msg){ if(INFO>=LEVEL){ Log.i(tag,msg); } } public static void w(String tag,String msg){ if(WARN>=LEVEL){ Log.w(tag,msg); } } public static void e(String tag,String msg){ if(ERROR>=LEVEL){ Log.e(tag, msg); } } }
4.Active切换
public class SecondActivity extends Activity{ public static void actionStart(Context context,String data1,String datta2){ Intent intent = new Intent(context,SecondActivity.class); intent.putExtra("param1",data); intent.putExtra("param2",data2); context.startActivity(intent); } }
5.Intent 传递对象(例如Person对象)
一.Person 要继承 Serializable(即;public class Person implements Serializable{.....})
二.传递有intent.putExtra("person",person)
三.获取对象 Person person = (Person) getInstant().getSerializableExtra("person");
6.全局获取Context(and 全局变量存储)
7.左侧滑出菜单栏(使用布局:android.support.v4.widget.DrawerLayout)
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <!-- The main content view --> <FrameLayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent" /> <!-- The navigation drawer --> <ListView android:id="@+id/left_drawer" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="start" <!--此处是关键语句--> android:choiceMode="singleChoice" android:divider="@android:color/transparent" android:dividerHeight="0dp" android:background="#111"/> </android.support.v4.widget.DrawerLayout>
禁止滑动调出侧边栏:
参考资料:http://blog.csdn.net/very_caiing/article/details/41854569
https://developer.android.com/training/implementing-navigation/nav-drawer.html
8.Android开发需要新建的文件夹
Helpers:存放一些帮助类文件
Models:存放模型
Services:存放网络通信,或一些调用手机硬件接口的方法类
Adapters: ListView 的adapter
Controls:存放自定义控件
Fragments:存放定义的Fragents
9.知晓当前实在哪一个活动
在onCreate()方法中添加语句:
Log.d("BaseActivity",getClass().getSimpleName());
10.Android 图表控件
https://github.com/PhilJay/MPAndroidChart
https://github.com/PhilJay/MPAndroidChart/wiki
11.Android 开发必看
http://www.jdzhao.com/
http://a.codekk.com/
https://github.com/hehonghui/android-tech-frontier
http://www.simplecoder.cn/
http://www.open-open.com/lib/view/open1461395311690.html //完整项目mvp
http://blog.csdn.net/typename/article/details/39030091 //webview
http://www.devtf.cn/
12.Android网络HttpClient(像html中 ajax 调用服务)
和Ajax的功能相同(确保服务ajax可以正常使用)
1.“http://192.168.17.44:81/amtioth5.Wcf/AjaxGetData/DataService.asmx”是地址
2.hello是方法名
3.obj.put("name", "your name"); 传参数。
4.相关下载:链接:http://pan.baidu.com/s/1eSsftya 密码:pf52
try { HttpClient httpclient = new DefaultHttpClient(); String uri = "http://192.168.17.44:81/amtioth5.Wcf/AjaxGetData/DataService.asmx/hello"; //类似这样的地址也可以:http://192.168.17.44:81/amtioth5.Wcf/Service2.svc/DoWork2 HttpPost httppost = new HttpPost(uri); //添加http头信息 httppost.addHeader("Content-Type", "application/json"); httppost.addHeader("User-Agent", "imgfornote"); //http post的json数据格式: {"name": "your name","parentId": "id_of_parent"} JSONObject obj = new JSONObject(); obj.put("name", "your name"); httppost.setEntity(new StringEntity(obj.toString())); HttpResponse response; response = httpclient.execute(httppost); int code = response.getStatusLine().getStatusCode(); if (code == 200) { String rev = EntityUtils.toString(response.getEntity()); } } catch (ClientProtocolException e) { } catch (IOException e) { } catch (JSONException e) { }
13.线程
一、新建一个类继承子Thread
class MyThread extends Thread{ @Override public void run(){ //TODO } }
//启动线程
new MyThread().start();
二、实现Runnable 接口
class MyThread implements Runnable{ @Override public void run(){ //TODO } } //启动线程 MyThread myThread = new MyThread(); new Thread(myThread).start();
//UI interactive
private Handler handler = new Handler(){ public void handlerMessage(Message msg){ switch(msg.what){ // case .... handle UI default: break; } } }
三、使用AsyncTask /*recommend*/
class DownLoadTask extends AsyncTask<Void, Integer, Boolean>{ @Override protected void onPreExecute(){} @Override protected Boolean doInBackground(void... params){return true;} @Override protected void onProgressUpdate(Integer... value){} @Override protected void onPostExecute(Boolean result){} } // 执行 new DownLoadTask().execute();
14.底部tab
http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0731/3247.html
https://www.aswifter.com/2015/07/02/Material-Design-Example-5/
https://github.com/lwngreat/MaterialDesignExample
https://www.aswifter.com/2015/08/09/implements-bottom-tab-with-tablayout/
http://www.jianshu.com/p/c3f6d316ec5b
https://www.aswifter.com/android/ /*importent*/
15.Android Studio 使用 proguard
配置文件 proguard-rules.pro (Eclipse中的文件名为proguard.cfg)
#指定代码的压缩级别 -optimizationpasses 5 #是否使用大小写混合 -dontusemixedcaseclassnames #优化/不优化输入的类文件 -dontoptimize #是否混淆第三方jar包 -dontskipnonpubliclibraryclasses #混淆时是否做预校验 -dontpreverify #混淆时是否记录日志 -verbose #混淆时所采用的算法 -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* #保护注解 -keepattributes *Annotation* #保持JNI用到的native方法不被混淆 -keepclasseswithmembers class * { native <methods>; } #保持自定义控件的构造函数不被混淆,因为自定义控件很可能直接写在布局文件中 -keepclasseswithmembers class * { public <init>(android.content.Context, android.util.AttributeSet); } #保持自定义控件的构造函数不被混淆 -keepclasseswithmembers class * { public <init>(android.content.Context, android.util.AttributeSet, int); } #保持布局中onClick属性指定的方法不被混淆 -keepclassmembers class * extends android.app.Activity { public void *(android.view.View); } #保持枚举enum类不被混淆 -keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); } #保持序列化的Parcelable不被混淆 -keep class * implements android.os.Parcelable { public static final android.os.Parcelable$Creator *; } #指定哪些第三方jar包需要混淆 #-libraryjars libs/bcprov-jdk16-1.46.jar #保持哪些系统组件类不被混淆 -keep public class * extends android.app.Fragment -keep public class * extends android.app.Activity -keep public class * extends android.app.Application -keep public class * extends android.app.Service -keep public class * extends android.content.BroadcastReceiver -keep public class * extends android.content.ContentProvider -keep public class * extends android.app.backup.BackupAgentHelper -keep public class * extends android.preference.Preference -keep public class * extends android.support.v4.** -keep public class com.android.vending.licensing.ILicensingService #保持哪些第三方jar包不被混淆 -keep class com.baidu.** {*;} -keep class vi.com.** {*;} -dontwarn com.baidu.** -dontwarn org.xmlpull.v1.XmlPullParser -dontwarn org.xmlpull.v1.XmlSerializer
将配置添加的app项目中
17:40:18 Gradle build finished with 1 error(s) and 23 warning(s) in 2s 946ms
17:40:18 Generate Signed APK: Errors while building APK. You can find the errors in the 'Messages' view.
/*************-------------------*******************/
Warning:library class android.content.res.ColorStateList depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.graphics.drawable.AnimationDrawable depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.graphics.drawable.BitmapDrawable depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.graphics.drawable.ClipDrawable depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.graphics.drawable.ColorDrawable depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.graphics.drawable.Drawable depends on program class org.xmlpull.v1.XmlPullParser
Warning:library class android.graphics.drawable.GradientDrawable depends on program class org.xmlpull.v1.XmlPullParser
解决方法:在proguard-rules.pro 添加如下内容
-dontwarn org.xmlpull.v1.XmlPullParser
-dontwarn org.xmlpull.v1.XmlSerializer
16.App检测更新
http://blog.csdn.net/wwj_748/article/details/8195565
图书: