Dialog display app information for Android installation of mobile phone

Source: Internet
Author: User

Recently do feature development need to display the current mobile phone installed app information. Here I use dialog to show. as follows:


As shown above, this dialog shows the app currently installed on the phone, and when clicked on a menu item it displays a locked pattern (e.g., video/camera/contact). This is a design interface that can be locked to the app.

First look at the creation of dialog:

private void Init_create_dialog () {if (null = = Show_app_dialog) {show_app_dialog = New dialog (Getactivity ()) {protected void OnStop () {super.onstop (); Fingerprint_utils.fingerprint_save_lockapp (Getactivity ());}; Show_app_dialog.setcontentview (R.layout.finger_gride_app_choose); Show_app_dialog.settitle (R.string.finger_ Print_set_unlock_app_title); GridView Gvapp = ((GridView) Show_app_dialog.findviewbyid (R.id.gv_app)); final List<fingerprintapplicationinfo > list = Fingerprint_utils.get_lockapplicationinfolist (); Gvapp.setadapter (new Appchooseadapter (list)); Gvapp.setonitemclicklistener (New Adapterview.onitemclicklistener () {public void Onitemclick (adapterview<?> Parent, view view, int position, long id) {Fingerprintapplicationinfo fingerappinfo = (fingerprintapplicationinfo) Parent.getitematposition (position); ResolveInfo appinfo = fingerappinfo.launcher_activity;//charsequence name = Appinfo.loadlabel (Package_manager); Appchooseadapter.viewholder hold = (appchooseadapter.viewholder) view.geTtag (); if (fingerappinfo.locked) {hold.app_icon.setImageResource (0); fingerappinfo.locked = false; Fingerprint_utils.fingerprint_dele_lockapp (appinfo.activityInfo.packageName);//activityinfo.packagename}else{ Hold.app_icon.setImageResource (R.drawable.lock_app_icon); Fingerappinfo.locked = true; Fingerprint_utils.fingerprint_addnew_lockapp (appinfo.activityInfo.packageName);} Selected_str = appinfo.packagename;//if (DEBUG) log.d (TAG, "fingerprintsettingmain:name=" +name+ "; Appinfo.packagename= "+appinfo.packagename);//show_app_dialog.dismiss ();}); * Show_app_dialog.setondismisslistener (new Dialoginterface.ondismisslistener () {public void OnD                Ismiss (Final Dialoginterface Dialog) {Fingerprint_utils.fingerprint_save_lockapp (getactivity ()); }}); */show_app_dialog.getwindow (). Setcloseontouchoutside (True); Show_app_dialog.setcanceledontouchoutside (True) ;}}

And look at its layout file: Finger_gride_app_choose.xml

<?xml version= "1.0" encoding= "Utf-8"? ><gridview xmlns:android= "http://schemas.android.com/apk/res/ Android "android:id=" @+id/gv_app "android:layout_width=" match_parent "android:layout_height=" Match_parent    " android:numcolumns= "3"     android:padding= "10DP"    android:verticalspacing= "10DP"    android: horizontalspacing= "10DP"    android:gravity= "center"    />
is actually a GridView, so the focus of the whole interface is actually the adapter design of the GridView. So look at this adapter:appchooseadapter.

 Class Appchooseadapter extends baseadapter{private list<fingerprintapplicationinfo> Applicationinfos; Private Packagemanager pm;class Viewholder {TextView app_name; ImageView App_icon;    ImageView Locked_icon;}    Public Appchooseadapter (list<fingerprintapplicationinfo> list) {Applicationinfos = list;    } public int GetCount () {return applicationinfos.size ();    } public Object GetItem (int position) {return applicationinfos.get (position);    } public long Getitemid (int position) {return position;        Public View GetView (int position, view view, ViewGroup parent) {//packagemanager pm = Package_manager;        Final Viewholder hold; if (view = null) {if (DEBUG) log.d (TAG, "appchooseadapter: (view = = null) position=" +position); Context context = Parent.getcontext (); view = Layoutinflater.from (context). Inflate (r.layout.item_app_gride, NULL); hold = new Viewholder (); Hold.app_icon = (ImageView) View.findviewbyid (R.ID.IV_icon);//hold.locked_icon = (ImageView) View.findviewbyid (r.id.lock_statu_img); hold.app_name = (TextView) View.findviewbyid (R.id.tv_name); View.settag (hold);} Else{if (DEBUG) log.d (TAG, "Appchooseadapter: (view! = null) position=" +position); hold = (Viewholder) View.gettag ();} Final int curr_position = Position;view.post (new Runnable () {public void run () {//viewholder hold = (viewholder) View.gett AG (); Packagemanager pm = package_manager;if (hold! = null) {Fingerprintapplicationinfo Ainfo = (fingerprintapplicationinfo) Applicationinfos.get (curr_position); String package_name = ainfo.launcher_activity.activityinfo.packagename;//ainfo.app.packagename;if (aInfo.locked) { Hold.app_icon.setImageResource (R.drawable.lock_app_icon); }else{hold.app_icon.setimageresource (0);} Hold.app_name.setText (AInfo.launcher_activity.loadLabel (PM)); Hold.app_icon.setBackgroundDrawable ( AInfo.launcher_activity.loadIcon (PM));        Image.setimagedrawable (AInfo.app.loadIcon (PM));}});    return view; }}
All the basic code has been posted above. Here's a description:

(1) Every time this dialog will be a little bit delayed, how to solve this problem. I have two ways to solve it:

First, load the app information for the phone installation, I'll load it before displaying this dialog, and then just need to pass fingerprint_utils.get_lockapplicationinfolist () You can get it. The Load app information is done using Asynctask. The use of Asynctask is simple, here I only give the code to load the app's information:

    private static Arraylist<fingerprintapplicationinfo> Getinstalledlaunchableapps ( Fingerprintsettingmain.applabelcomparator mcomparator) {        final Intent Mainintent = new Intent (intent.action_main, null);        mainintent.addcategory ( Intent.category_launcher);                Packagemanager pm = Mcomparator.getpackagemanager ();        List List = Pm.queryintentactivities (mainintent, 0);//Query get all installed app                 arraylist<fingerprintapplicationinfo> array = new arraylist< Fingerprintapplicationinfo> ();        arraylist<fingerprintapplicationinfo > array1 = new arraylist<fingerprintapplicationinfo> ();                 int Size = List.size ();        string[] App_dele = all_app_dele_packagename;        string[] Lock_app_dele = lock_app_dele_packagename;        // LOG.D (TAG, "getinstalledlaunchableapps:size=" +size);        boolean has = false;         string locked_packagename = app_locked_packagename!=null?app_locked_ Packagename.tostring ():null;        resolveinfo curr;         for (int i=0; i<size; i++) {            have = false;            curr = (ResolveInfo) list.get (i);             if (null = = Curr) {                 continue;            }            String str = curr.activityinfo.packagename;            if (!wei_xing_install && 0 = = Weixing_package.compareto (str)) {// Detect if installation                 wei_xing_install = true;             }             Iterator Iterator = Array.iterator ();            if (null! = App_ DELE) {                for (int j = 0; j < App_dele.length; J + +) {//Some apps don't need to be shown here, filter out some app                     if (App_dele[j].compareto (str) = = 0) {                         has = true;   &NBSP;&NBSP;&NBsp              }                }            }             if (has) continue;                 fingerprintapplicationinfo app = new Fingerprintapplicationinfo ();                app.launcher_activity = curr;                 if (locked_packagename! = null && locked_packagename.indexof (str) >-1 ) {                    app.locked = true;& nbsp;               }                                 Array.add (APP);                 if (null! = Lock_app_dele) {                     for (int n = 0; n < lock_app_dele.length; n++) {       &N bsp;                if (Lock_app_dele[n].compareto (str) = = 0) {                            has = true;                         }                     }                }                 if (HAS) Continue; &nbsP              array1.add (APP);        }                collections.sort ( Array, mcomparator);        collections.sort (array1, mcomparator);         if (array1 = null) {            unlock_pacakegename_ App_dele = array1;        }        return array;    }
Even if the app information is loaded before the dialog is displayed, there is a long delay when the dialog is displayed because it takes time to load each app's icon and Text_name. So, As in the above code appchooseadapter GetView I used the View.post (new Runnable ()) method to load the displayed information.

(2) How to achieve a click on an app menu option to display a lock on the image above. Look closely at the above source code can be found, here I used ImageView image and background to do. First ImageView background image is used to show the app icon, And ImageView's image shows the picture that is a lock. If locked, this imageview sets the image:

Hold.app_icon.setImageResource (R.drawable.lock_app_icon);

Otherwise:

Hold.app_icon.setImageResource (0);




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Dialog display app information for Android installation of mobile phone

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.