GetSDimplementation code for card and memory space information
Get sdcard Memory Information
* @param view
*/
public void Sdcardinfo (view view) {
File storagedirectory = Environment.getexternalstoragedirectory ();
* returns the total size of the file under this path, in bytes. Returns 0 if the path does not exist
Long totalspace = Storagedirectory.gettotalspace ();
Long usablespace = Storagedirectory.getusablespace ();
* Format the returned size as Byte, KB, MB, and so on.
*/
String totalspacestring = Formatter.formatfilesize (this, totalspace);
String usablespacestring = Formatter.formatfilesize (this, usablespace);
StatFs fs = new StatFs (Storagedirectory.getabsolutepath ());
Long Blockcount = Fs.getblockcount ();
int blockSize = Fs.getblocksize ();
int availableblocks = Fs.getavailableblocks ();
Long totalsizefs = blockcount*blocksize;
Long avaisizefs = blocksize*availableblocks;
String totalsizefsstring = Formatter.formatfilesize (this, totalsizefs);
String avaisizefsstring = Formatter.formatfilesize (this, avaisizefs);
Et_totalsize.settext (totalsizefsstring);
Et_avaisize.settext (avaisizefsstring);
The first method is provided by the JDK API , and the second method is provided by the Android API.
In our Android Development, we recommend using the second method. Because the second way , Google Engineers specifically designed for Android systems. Relatively more applicable,
Get information on your phone's internal storage
* @param view
*/
public void Memeoryinfo (view view) {
File Filesdir = Getfilesdir ();
Long totalspace = Filesdir.gettotalspace ();
Long usablespace = Filesdir.getusablespace ();
String totalspacestr = Formatter.formatfilesize (this, totalspace);
String usablespacestr = Formatter.formatfilesize (this, usablespace);
Et_totalsize.settext (TOTALSPACESTR);
Et_avaisize.settext (USABLESPACESTR);
}
=====================================================================
common in the work
Ø Read and write files
Some of the APIsused to manipulate files are available at work:
Environment.getexternalstoragedirectory () Gets the current sdcard
Environment.getexternalstoragestate () method gets The current state of the sdcard
Context.openfileoutput (String name, int mode) can get a file output stream
Context.openfileinput (String name) can get a file input stream
Context.getfilesdir (). GetAbsolutePath (); get the app path
Getcachedir (). GetAbsolutePath (); Get Cache directory
==
Ø about file operation, in the application generally will have a clear cache this function
This function is implemented by the file operation:
Display the cache size, recursively loop through the cache folder for all file sizes, and then sum.
Clear the cache, to recursively delete files.
After you find the project, many projects have this function, the interview may be asked how to achieve.
Recursive Delete code: This method is to be done in a sub-thread
=================================
Files are stored in the database
Step: Create your own Help class to inherit the Sqliteopenhelper constructor to specify the name of the database such as rewrite OnCreate (); In Mainactivity (); New Mydatabaseopenhelper (this);
Helper.getwritabledatabase ();
In the Help class onCreate is called when the database is first created, only once Db.execsql (...) is executed. Create a table structure for the database Onupgarade when the database needs to be updated, can only be upgraded, not degraded DOS database additions and deletions to the introduction of LISTVIEWMVC Mode database update upgrade--------------------steps to use the ListViewDeclaring in the XML file layout
Locate the LV control in Java to set adapter GetCount () GetView () 1.1. List view(ListView)batch loading, paging loading1.1. Common adaptersAdapter
the adapters used in the ListView are: baseadapter,arrayadapter,simpleadapter .
Ølistview Optimization
L Reuse convertview reduce time to load XML
L Use viewholder to reduce Findviewbyid time
L should not refresh the entire ListView if only one Item is involved in the change of one of the controls (Notifydatasetchanged ( ))
 &NB sp; Instead, use settag (Position) tag, then use Locate the corresponding control to make the change
(when you need to use notifydatasetchanged, When an entry is added or deleted , This time it must be refreshed )
Ø Partial Paging loading
Ø Adapter baseadapter
Common dialog Box Reminders dialog box Multi-Select dialog box Progress dialog status bar notification
Ø a dialog box pops up , What life cycle method does Activity perform?
======================================================================
Transaction Management 5.4 126 pages
Case: Bank transfer,
How to use:
L BeginTransaction (): Open a transaction
L settransactionsuccessful (): SET Transaction Success Token
L endtransaction (): End transaction, including commit and rollback, need to be executed in finally , otherwise the transaction will not end automatically until time-out, reducing the database concurrency efficiency
Execution process:
When you use begintransaction to open a transaction, the program executes to the endtransaction method to check whether the flag of the transaction is successful, and if the program executes to Endtransaction before the settransactionsuccessful method is called to set the transaction flag as successful, the transaction is committed; The Settransactionsuccessful method rolls back the transaction.
The improvement of the efficiency of the transaction
When you bulk modify the data, because the transaction is the SQL operation to be executed at the time of the transaction commit , the database connection execution is opened once,
its execution speed is more than the execution SQL statements are many times faster.
So when we develop the bulk operations of the database then the use of transactions is an important principle to improve efficiency.
===================================================
several common controls in Android
ProgressBar , Spinner , Autocompletetextview , Multiautocompletetextview basic usage of a total of four controls
======================================
styles and Themes in Android
Android for internationalization
======================================================
animations in Android
Frame animation Frameanimation
Gradient animation tweenanimation
View Animation (Tween Animation): Motion tween, gives two keyframes, with some algorithms to ramp a given attribute value between two keyframes in a given time.
Gradients include: panning, zooming, rotating, and changing transparency. The definition of an animation effect can be done using XML or Java code. There are 4 types of tweened animations:
Alpha Gradient Animation scale scaling animation Translate displacement animation Rotate rotation
The collection of Animationset animations
Third day of Android