"Android Development" for fun, a joke app making process record

Source: Internet
Author: User

Origin

The reason you want to make a joke app is because you've seen a post on the know. What data does Android have to be able to practiced hand, a few data open platforms are recommended.

In these platforms there is no public joke interface, then thought this can be brought to practiced hand ah, is quite interesting, is expected to accumulate a bit of users.

It happens (it's a coincidence) that in GitHub there's a framework for MVP design pattern beam, author Jude95 has a joke warehouse ———— Joy (beans). It's just a joke!

Even more coincidentally, the interface I'm using is also the interface I'm looking at. I thought it would be better to change it, to do an upgrade version. You can also learn how others write apps in this way.

It was later found to be a very correct decision.

Prototype

Because it is based on the improvement of others. So I had a prototype before I wrote it. Of course, this prototype is not very good, which gives me the space to change. After getting the author's changes, I went further into the app that was written using the MVP framework. Before changes are made:

Raw=true "title=" >

First of all. Bean Force only can view the satin and view pictures, I think the main copy of the text and view large images as well as download pictures. None of this is.

The author only uses this repository to illustrate the MVP model. So just do the main function. The author also said. A joke doesn't even have an ID. It's impossible to praise or comment on anything.

Well, I'll make a copy of the text I feel and the picture related to do it.

Study

MVP model I studied very little before this project. Just heard, but this project completely gave me a refreshing feeling. MVP is too practical for Android!

About MVP I would like to write a detailed post to study. Just to show that the MVP makes the Android project hierarchical and the code structure simple. High reusability. The author's beam.

This project uses a very good open source control. It is also the project author's own control Easyrecyclerview, and this control is brief encounter for me. Linear layout Imitation Easyrecyclerview has implemented a pull-down refresh, loading a lot of other, error hints, and so on, the project can be encountered in the development of the pits are done. I've only been able to do these functions one after the other! Why not use this control early.

The rest is not a big surprise. However, the overall sense of the project code is very small, very concise. Let's say I finished the same feature app. May require 3 times times the code to achieve.

Improved view large image

First realize the function of click to view large image.

Photoview This control is also a long time ago in the GitHub encountered, when using it unexpectedly so easy! Simply declare a photoview in the XML. The main zoom, zoom out, gesture recognition all have! Too convenient. It may also be a tool for viewing large images by the official client of the Bupt forum.

When the Java file loads the picture, it is exactly the same as ImageView.

Another area to expand is to click on the picture to return (= = usually there?). )。 This needs to be based on Photoview official instructions, using Attacher to manage click events, after I test, it seems that the direct statement ImageView click is not effective.

Image download

This app uses glide to load web images. And glide does not directly download the method of storage, just have their own expansion, delayed some kung fu.

Share a picture to download and notify the library's code directly.

     Public void SaveImage(String imageUrl) {string[] names =Newstring[0];if(ImageUrl! =NULL) {names = Imageurl.split ("/"); } String imageName = Names[names.length-1]; Glide. With (GetView ()). Load (IMAGEURL). Asbitmap (). Tobytes (Bi Tmap. Compressformat.jpeg, -). into (Newsimpletarget<byte[]> () {@Override                     Public void Onresourceready(Final byte[] resource, glideanimation<?Super byte[]> glideanimation) {NewAsynctask<void, Void, void> () {@Override                            protectedVoidDoinbackground(Void ... params) {if(Imagestorage.checkifimageexists (ImageName)) {Snackbar.make (GetView (). Fab,"Picture already exists", Snackbar. Length_long). Setaction ("Action",NULL). Show ();return NULL;                                } String Path = Environment.getexternalstoragedirectory (). toString (); JUtils.Log ("Path", path); Bitmap Bitmap = Bitmapfactory.decodebytearray (Resource,0, resource.length); JUtils.Log ("ImageName", imageName);                                Imagestorage.savetosdcard (GetView (), Bitmap, imageName); Snackbar.make (GetView (). Fab,"picture has been downloaded", Snackbar.length_long). Setaction ("Action",NULL). Show ();return NULL;                    }}.execute ();    }                }); }

Among the Imagestorage.java:

     Public  class imagestorage {         Public StaticStringSavetosdcard(context context, Bitmap Bitmap, String filename) {String stored =NULL;            File sdcard = Environment.getexternalstoragedirectory (); File folder =NewFile (Sdcard.getabsolutefile (),"Findjoy");//the dot makes this directory hidden to            // the            //userFolder.mkdir (); File File =NewFile (Folder.getabsolutefile (), filename +". jpg");if(File.exists ())returnStoredTry{FileOutputStream out =NewFileOutputStream (file); Bitmap.compress (Bitmap.CompressFormat.JPEG, -, out);                Out.flush ();                Out.close (); stored ="Success"; JUtils.Log ("Stored", stored); }Catch(Exception e)            {E.printstacktrace (); }///Next insert the file into the system Gallery            Try{MediaStore.Images.Media.insertImage (Context.getcontentresolver (), File.getabsolute Path (), filename,NULL); }Catch(FileNotFoundException e)            {E.printstacktrace (); }///Last notification of the gallery updateContext.sendbroadcast (NewIntent (Intent.action_media_scanner_scan_file, Uri.parse ("file://"+ file. GetAbsolutePath ()));returnStored } Public StaticFileGetImage(String imagename) {File Mediaimage =NULL;Try{String root = Environment.getexternalstoragedirectory (). toString (); File MyDir =NewFile (root);if(!mydir.exists ())return NULL; Mediaimage =NewFile (Mydir.getpath () +"/findjoy/"+ imagename); }Catch(Exception e) {//TODO auto-generated catch blockE.printstacktrace (); }returnMediaimage; } Public Static Boolean checkifimageexists(String imagename) {Bitmap b =NULL; File File = Imagestorage.getimage ("/"+ ImageName +""+". jpg"); String path = File.getabsolutepath ();if(Path! =NULL) b = bitmapfactory.decodefile (path);if(b = =NULL|| B.equals ("")) {return false; }return true; }    }

Why did I try for a long time but always found that the library has no pictures? Always thought it was their own picture is not stored down, and later with the library's view folder way to discover the Findjoy folder.

It is necessary to notify the library update, otherwise the picture will not be displayed in the gallery. Please see the code above for details.

Copy a Satin

This is not a hassle in itself, and the point of failure is how to add Onitemclilklistner to the list in this MVP framework.

I'm not very familiar with it. This place made a lot of mistakes, why didn't I think of Easyrecyclerview's official statement?

The workaround is to add the Itemview in the Textviewholder:

Itemview.setonclicklistener (View-NewMaterialdialog.builder (GetContext ()). Title (R.string.select). Content (R.string.copy) . Positivetext (R.string.agree). Negativetext (R.string.disagree). Onpositive ((Dialog, which), {//Gets a handle to the Clipboard service.Clipboardmanager Clipboard = (Clipboardmanager) getcontext (). Getsystemservice (Context.clipboard_service);//Creates a new text clip to put on the clipboardClipdata clip = Clipdata.newplaintext ("Joy", Data.gettext ());//Set the Clipboard ' s primary clip.Clipboard.setprimaryclip (clip); Snackbar.make (Itemview,"The satin has been copied to the Pasteboard", Snackbar.length_short). Show (); }). Show ());

The official library also has the ability to set the Easyrecyclerview monitoring method, the effect is the same.

Friends League statistics

Friends of the league statistics may be my own to outsource a required item, because you want to know the use of the app ah.

This time the discovery of Friends League statistics is more useful than ever. The jar package is also placed in the Jcenter () warehouse, which is very convenient.

Here's how to enjoy the benefits of this MVP library. The statistical method is called in the Onresume () and OnPause () methods of all the actvity that are required in the Friend League statistics by invoking the same piece of code for the entire activity lifecycle.

Implementation is through a top management class myactivitylifecycledelegate inherit Activitylifecycledelegate, in the inside set up the method of Friend League statistics.

     Public  class myactivitylifecycledelegate extends activitylifecycledelegate {         Public myactivitylifecycledelegate(Activity Act) {Super(act); }@Override        protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); JUtils.Log ("OnCreate"+ getactivity (). GetClass (). GetName ()); }@Override        protected void OnPause() {Super. OnPause (); JUtils.Log ("OnPause");        Mobclickagent.onpause (Getactivity ()); }@Override        protected void Onresume() {Super. Onresume (); JUtils.Log ("Onresume");        Mobclickagent.onresume (Getactivity ()); }    }

Then in the app's application

Beam.setActivityLifeCycleDelegateProvider(MyActivityLifeCycleDelegate::new);

The above line of code is simplified by the IDE itself. Good high-end ah, incredibly a little unclear is how it happened. )

Oh, by the manifest, don't forget to declare the Appkey in the League of Friends.

Well. The statistics are integrated well.

Proactively update yourself

It is also the service of Friends Union. I also thought that only a few minutes of things to be done, but because of their own problems, delayed a period of time, incredibly still want to throw this pot to friends of the league.

Well, I was wrong.

This is not the same as the statistics is the need to manually download the package into the project, including a. so file.

Because this sentence is stated in the app's Gradle:

    compile fileTree(include: [‘*.jar‘dir‘libs‘)

I thought everything was going to be all right. In fact, I opened the Friends of the Union debug mode only to see that it is my. So is not loaded in.

Well. JNI should be so declared. I forgot:

    sourceSets {        main {            jniLibs.srcDirs = [‘libs‘]        }    }

So the. So file can be loaded in.

But the Friend Alliance own initiative updates only need to write a code in the mainactivity:

    UmengUpdateAgent.update(this);

Very cool right?

Self-initiated updates are based on app Versioncode. Note the changes when updating.

App

I changed the color when I finished these functions. Finally the effect is general, part of the function is not.

Raw=true "title=" >

Application Market

Well, these are all implemented after the online app store, mainly with these several:

    • Xiaomi App Store: http://app.mi.com/detail/286105
    • App Bao: http://android.myapp.com/myapp/detail.htm?

      Apkname=com.fuxuemingzhu.findjoy

    • Pea pod: Http://www.wandoujia.com/apps/com.fuxuemingzhu.findjoy
    • Fir.im:http://fir.im/axy4

Ability to scan code to download:

App Treasure Download:

Raw=true "title=" >

Pea pod Download:

fir.im Download:

Try not to use FIR. Since FIR does not have an intuitive download count, uh. Try it through the regular app store.

We have to hold a game to download it.

Conclusion

Although it is a very easy app, it includes a lot of mind in it. And when trying something new, you can learn a lot. This is worth affirming. After all, I now have the urge to crush the previous app and write it again. After all, I can't resist the double temptation of MVP + Material design!

Android Development has a very long way to go.

This project has been completely open source, code in: Https://github.com/fuxuemingzhu/FindJoy, welcome star and Fork.

"Android Development" for fun, a joke app making process record

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.