Drop-down Refresh
Encapsulation of the network engine
- The network request is encapsulated into the cloudengine.class and exposed in the form of a method;
- Processing of all network request results. Callback back by means of interface method;
Interface callbacks
- Handler mechanism +thread
- How to understand the interface callback--the interface callback is a notification mechanism
- Effect: 1. Simple notification 2. Notification + value
- Steps:
- 1. Define interfaces, and interface methods
- 2. Defining Interface Objects
- 3. In a certain place. Interface Object Call interface method
- 4. Exposing interface Objects (construction method, setter method)
Asynctask Basic Use
onPredoInbackGrouponpost
Asynctask Source Code Analysis
private static final int CORE_POOL_SIZE = 5; //核心线程数private static final int MAXIMUM_POOL_SIZE = 128; //最大线程数private static final int KEEP_ALIVE = 1;
Asynctask defects
- 1. At the same time there are only 5 threads to access the network--this is the point
- 2. The number of threads is more than 128, will throw an exception--this situation is actually OK;
Asynctask Version Differences
- COREPOOLsize maximum_poolsize KEEPalive on different versions. The value is not the same;
- 1.5 was executed serially. One task at a time
- Previous versions of 1.6-2.3. is executed in parallel. Perform 5 tasks at a time
Serial and parallel are provided after 3.0, and the default is serial
executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, null);//串行executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null);//并行
Asynctask Simple Package
Actual development we will inherit asynctask.
Asynctask functional encapsulation, Asynctask function invocation interface Callback instance
//1. public static interface OnCheckedChangeListener { void onCheckedChanged(CompoundButton buttonView, boolean isChecked); } //2. private OnCheckedChangeListener mOnCheckedChangeListener; //3. mOnCheckedChangeListener.onCheckedChanged(this, mChecked); //4. public void setOnCheckedChangeListener(OnCheckedChangeListener listener) { mOnCheckedChangeListener = listener; }
Global exception Handling
Method defines the place. Uniform throw base class
/** * 这个是一个会抛出异常b的方法 * @throws HMException * @throws HMException */public static void methodB() throws HMException { //如果在某一个时刻.出现了异常啊. //出现状态的是子类.抛出的是父类. throw new HMBException();//主动抛异常}
Where the method is used, the try catch base class
try { Api.methodB(); } catch (HMException e) { handleException(e);}
Hint Information materialized
/** * 不同异常子类用不同的code表示 * @param e * @return */public static int exception2code(HMException e) {int errCode = 0;if (e instanceof HMAException) { errCode = 1;} else if (e instanceof HMBException) { errCode = 2;} else if (e instanceof HMCException) { errCode = 3;} else if (e instanceof HMDException) { errCode = 4;}return errCode;}/** * 根据不同的异常信息.显示不同的效果 * @param e */public void handleException(HMException e) { int exception2code = ExceptionHandler.exception2code(e); String code2String = ExceptionHandler.code2String(exception2code); Toast.makeText(getApplicationContext(), code2String, 0).show();}
Actionbarsherlock
Actionbar version Compatibility Library. We can use the Actionbar under 2.1.
actionBar = getSupportActionBar();//得到actionbar, actionBar.setDisplayHomeAsUpEnabled(true);//是否显示返回箭头,默认情况是false, //如果setDisplayShowHomeEnabled setDisplayShowTitleEnabled 都是false,那么退回图标设置为true/false都不见 actionBar.setDisplayShowHomeEnabled(false);//是否显示logo,默认是true actionBar.setDisplayShowTitleEnabled(true);//是否显示title,默认是true // actionBar.setTitle("56期");//修改title // actionBar.setIcon(R.drawable.icon_download);//修改logo
The difference between several actionbar
- Actionbarsherlock->actionbar--> support-->2.1 The following systems also have to be used, Actionbarsherlock provides a lot of styles;
- The system above v7-->actionbar-->2.1 can support
- Android sdk->actionbar-->3.0 above phone support
V4 V7 V13
- V4: Compatible with API Level4 (Android 1.6)
- V7: Compatible with API Level7 (Android 2.1)
- V13: Compatible with API Level3 (Android 3.2)
QR code, historic stuff.
Using the zxing package, QRCode
The simplification of two-dimensional code
It was a long time ago. The simplification of the zxing package is a comparison of fire.
Two-dimensional code and screen switching
The picture is cut sideways
Two-dimensional code animation
Imitation Scan effect
Using zxing to scan two-dimensional code to understand two-dimensional code
- The range of the QR code
- Two-dimensional code fault tolerance level
- Two-dimensional Code embedded logo
Use the Find button first and then call
1. Start the scanning interface Intent Intent = new Intent (mainactivity.this, Captureactivity.class); Startactivityforresult (Intent, scannin_grequest_code);//2. Processing Scan Results/** * * @param result * @param barcode */public void Han Dledecode (result result, Bitmap barcode) {inactivitytimer.onactivity (); Playbeepsoundandvibrate (); Scan result String resultstring = Result.gettext (); if (Resultstring.equals (")") {Toast.maketext (Captureactivity.this, "Scan failed!", Toast.length_short). Show (); } else {//2. Pass the scan result Intent resultintent = new Intent (); Bundle bundle = new bundle (); Bundle.putstring ("result", resultstring); Bundle.putparcelable ("Bitmap", barcode); Resultintent.putextras (bundle); This.setresult (RESULT_OK, resultintent); } CaptureActivity.this.finish ();} 3. Results of receiving callbacks @overrideprotected void Onactivityresult (int requestcode, int resultcode, Intent data) {Super.onactivityre Sult (Requestcode, ResultCode, data); Switch (requestcode) {case Scannin_grequest_code:if (ResultCode = = RESULT_OK) {Bundle bundle = d Ata.getextras (); Displays the contents of the scan Tv_result.settext (bundle.getstring ("result")); Show Iv_qrcode.setimagebitmap ((Bitmap) Data.getparcelableextra ("Bitmap")); } break; }}
Friends Leaguemulti-channel packaging can be UF tools, ant, Gradle
2. Drop-down refresh, two-dimensional code