AFinal-Introduction to the open-source android Application Framework

Source: Internet
Author: User

AFinal-Introduction to the open-source android Application Framework
Body 1. Official Website

Open source China Community AFinal Project

2. Introduction Afinal is an android sqlite OrmAnd IocFramework. It also encapsulates the http framework in android to make it easier to use. Using finalBitmap, you do not need to consider bitmap in android
The oom problem during loading and the mismatch of the image loading position during fast sliding. Afinal aims to be concise and fast. The conventions are greater than the configurations. Try to complete everything with one line of code. What is orm?

Object relationship Mapping (ORM, O/RM, or O/R mapping) is a program technology, it is used to convert data of different types of systems in object-oriented programming languages. In effect, it is actually a "Virtual Object Database" that can be used in programming languages ".
For details, see here

What is ioc?

Inversion of Control (IoC) is an important Object-Oriented Programming Law to reduce the coupling of computer programs. It is also the core of a lightweight Spring framework. There are two types of control inversion: Dependency Injection (DI) and Dependency Lookup ). Dependency injection is widely used.
For details, see here

3. Currently, four FinalDB modules of Afinal are: The orm framework in android. You can add, delete, modify, and query a line of code. Supports one-to-multiple and multiple-to-one queries. FinalActivity module: ioc framework in android. UI binding and event binding can be performed in full annotation mode. No need for findViewById and setClickListener. FinalHttp module: Uses httpclient to encapsulate http data requests and supports ajax loading. FinalBitmap module: when using FinalBitmap and imageview to load bitmap, you do not need to consider the oom and android container image dislocation during the bitmap loading process. FinalBitmap can be used to configure the number of threads loaded, cache size, cache path, and display animation. The memory management of FinalBitmap uses the lru algorithm and does not use weak references. (In the future, google does not recommend weak references. In the future, android2.3 forcibly recycles soft references and weak references. For details, see the official android documentation ), better management of bitmap memory. FinalBitmap can be used to customize the download tool to expand other protocols to display network images, such as ftp. At the same time, you can customize the bitmap display and play the animation when the imageview displays the image (the default is gradient animation display ). What Is ajax?

AJAX is "Asynchronous Javascript And XML" (Asynchronous JavaScript And XML), which is a Web page development technology used to create interactive web applications. By performing a small amount of data exchange with the server in the background, AJAX can implement asynchronous updates on webpages. This means that you can update a part of a webpage without reloading the entire webpage.
For details, see here

What is the LRU algorithm?

LRU is the Least Recently Used algorithm for Least Recently Used. Memory Management is a page replacement algorithm. For data blocks (memory blocks) that are not used in the memory, they are called LRU, the operating system moves data out of the memory based on which data belongs to the LRU to free up space for loading additional data.
For details, see here

4. Use FinalDB

For more information about finalDb, click here

FinalDb db = FinalDb. create (this); User user = new User (); // note that the User object must have the id attribute or the attribute user with the @ ID annotation. setEmail ("mail@tsz.net"); user. setName ("michael yang"); db. save (user );
5. FinalActivity can be bound to the UI and events through full annotation without the need for findViewById and setClickListener.
Public class AfinalDemoActivity extends FinalActivity {// you do not need to call @ ViewInject (id = R. id. button, click = "btnClick") Button; @ ViewInject (id = R. id. textView) TextView textView; public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. main);} public void btnClick (View v) {textView. setText ("text set form button ");}}
What is java annotation? Annotation is also called metadata. A code-level description. It is a feature introduced by JDK and later versions. It is at the same level as classes, interfaces, and enumeration. It can be declared before packages, classes, fields, methods, local variables, and method parameters to describe and annotate these elements. Category:
① Compile the document: generate the document [generate the document doc] using the metadata identified in the code]
② Code analysis: analyze the code using the metadata identified in the Code [Use reflection]
③ Compile check: Enable the compiler to perform basic compilation check through the metadata identified in the Code [Override]

For details, see here

6. Use FinalHttp as a normal get Method
FinalHttp fh = new FinalHttp (); fh. get ("http://www.yangfuhai.com", new AjaxCallBack () {@ Override public void onLoading (long count, long current) {// textView is automatically called back every second. setText (current + "/" + count) ;}@ Override public void onSuccess (String t) {textView. setText (t = null? "Null": t) ;}@ Override public void onStart () {// callback when starting an http request} @ Override public void onFailure (Throwable t, String strMsg) {// callback when loading fails }});
Use FinalHttp to upload files or submit data to the server (post method)
How to receive files uploaded to the server?
AjaxParams params = new AjaxParams (); params. put ("username", "michael yang"); params. put ("password", "123456"); params. put ("email", "test@tsz.net"); params. put ("profile_picture", new File ("/mnt/sdcard/pic.jpg"); // upload the File params. put ("profile_picture2", inputStream); // upload data stream params. put ("profile_picture3", new ByteArrayInputStream (bytes); // submit the byte stream FinalHttp fh = new FinalHttp (); fh. post ("http: // www. Yangfuhai.com ", params, new AjaxCallBack () {@ Overridepublic void onLoading (long count, long current) {textView. setText (current + "/" + count) ;}@ Overridepublic void onSuccess (String t) {textView. setText (t = null? "Null": t );}});
Use FinalHttp to download files:
Supports resumable upload to stop or start a download task at any time.
FinalHttp fh = new FinalHttp (); // call the download method to download HttpHandler handler = fh. download ("http://www.xxx.com/download #/xxx.apk", // here is the download path true, // true: resumable upload false: continuous download (new download) "/mnt/sdcard/testapk.apk", // This is the local path to save to new AjaxCallBack () {@ Override public void onLoading (long count, long current) {textView. setText ("download progress:" + current + "/" + count) ;}@ Override public void onSuccess (File t) {textView. setText (t = null? "Null": t. getAbsoluteFile (). toString () ;}}); // call the stop () method to stop downloading handler. stop ();
7. Use FinalBitmap to load the network image with a line of code fb. display (imageView, url). For more display reloads, see the help documentation.
Private GridView; private FinalBitmap fb; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. images); gridView = (GridView) findViewById (R. id. gridView); gridView. setAdapter (mAdapter); fb = FinalBitmap. create (this); // initialize the FinalBitmap module fb. configLoadingImage (R. drawable. downloading); // you can configure more than 10 items here, or you do not need to configure them. After the configuration, you must call the init () function to make the configuration take effect. // fb. configBitmapLoadThreadSize (int size) // fb. configBitmapMaxHeight (bitmapHeight )} /// // adapter getView /////////// /// // public View getView (int position, view convertView, ViewGroup parent) {ImageView iv; if (convertView = null) {convertView = View. inflate (BitmapCacheActivity. this, R. layout. image_item, null); iv = (ImageView) convertView. findViewById (R. id. imageView); iv. setScaleType (ScaleType. CENTER_CROP); convertView. setTag (iv);} else {iv = (ImageView) convertView. getTag () ;}// bitmap loads this line of code, and display has other overloading. For more information, see source code fb. display (iv, Images. imageUrls [position]);
8. To be continued

For more information about the AFinal-open-source android Application Framework DB module, see ~~~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.