<span id="Label3"></p><p><p>/*</p></p><p><p>* Copyright (C) the Android Open Source Project</p></p><p><p>*</p></p><p><p>* Licensed under the Apache License, Version 2.0 (the "License");</p></p><p><p>* You are not a use this file except in compliance with the License.</p></p><p><p>* Obtain a copy of the License at</p></p><p><p>*</p></p><p><p>* http://www.apache.org/licenses/LICENSE-2.0</p></p><p><p>*</p></p><p><p>* Unless required by applicable or agreed to writing, software</p></p><p><p>* Distributed under the License is distributed on a "as is" BASIS,</p></p><p><p>* Without warranties or CONDITIONS of any KIND, either express or Implied.</p></p><p><p>* See the License for the specific language governing permissions and</p></p><p><p>* Limitations under the License.</p></p><p><p>*/</p></p><p><p><br></p></p><p><p>Package org.cocos2d;</p></p><p><p><br></p></p><p><p>Import java.text.Collator;</p></p><p><p>Import java.util.ArrayList;</p></p><p><p>Import java.util.Collections;</p></p><p><p>Import java.util.Comparator;</p></p><p><p>Import java.util.HashMap;</p></p><p><p>Import java.util.List;</p></p><p><p>Import java.util.Map;</p></p><p><p><br></p></p><p><p>Import android.app.ListActivity;</p></p><p><p>Import android.content.Intent;</p></p><p><p>Import android.content.pm.PackageManager;</p></p><p><p>Import android.content.pm.ResolveInfo;</p></p><p><p>Import android.os.Bundle;</p></p><p><p>Import android.view.View;</p></p><p><p>Import android.widget.ListView;</p></p><p><p>Import android.widget.SimpleAdapter;</p></p><p><p><br></p></p><p><p>public class Cocos2d extends Listactivity {//this class uses the Listactivity</p></p><p><p><br></p></p><p><p>@Override</p></p><p><p>public void OnCreate (Bundle Savedinstancestate) {</p></p><p><p>Super.oncreate (savedinstancestate); Inherit Listactivity's oncreate method//the Following is the setting of the adapter in the list</p></p><p><p>Setlistadapter (new Simpleadapter (this,//), which uses its own context</p></p><p><p>(list<map<string,?>>) GetData ("org.cocos2d.tests"),//getdata is a method, getData (String) looks down at the declaration of a method</p></p><p><p>Android. r.layout.simple_list_item_1, New string[]{"title"},</p></p><p><p>New Int[]{android. r.id.text1}));</p></p><p><p>Getlistview (). settextfilterenabled (true);//enable Filter window</p></p><p><p>}</p></p><p><p><br></p></p><p><p>Protected list<?> getData (String prefix) {/= The above method</p></p><p><p>list<map<string,?>> myData = new arraylist<map<string,?>> ();//a list,map for placing a Map String</p></p><p><p><br></p></p><p><p><br></p></p><p><p>Intent mainintent = new Intent (intent.action_main, null);//intent to specify jump to system desktop</p></p><p><p>Mainintent.addcategory (intent.category_test);//for Test Use</p></p><p><p><br></p></p><p><p>Packagemanager pm = Getpackagemanager ();//packet controller, used to get the current process</p></p><p><p>list<resolveinfo> list = pm.queryintentactivities (mainintent, 0);//through Intent to find related activity, more accurate</p></p><p><p>if (null = = list)//failed to find the test intent</p></p><p><p>return mydata;//is Over.</p></p><p><p><br></p></p><p><p>/* below is an unused method used to split the string, using/</p></p><p><p>string[] prefixpath;</p></p><p><p>If (prefix.equals ("")) {</p></p><p><p>Prefixpath = null;</p></p><p><p>} else {</p></p><p><p>Prefixpath = Prefix.split ("/");</p></p><p><p>}*/</p></p><p><p>int len = list.size ();//get list length</p></p><p><p><br></p></p><p><p>map<string, boolean> entries = new hashmap<string, boolean> ();//a map that is not used, with a hash type of map</p></p><p><p><br></p></p><p><p><br></p></p><p><p>for (int i = 0; i < len; i++) {</p></p><p><p>ResolveInfo info = list.get (i);//used to loop the list you just Got.</p></p><p><p>String activityname = info.activityinfo.name;//gets The name of the activity</p></p><p><p>If (prefix.length () = = 0 | | Activityname.startswith (prefix)) {//if The activity you are looking for has a package name length of 0 or the name we're looking for is the one that starts with This.</p></p><p><p>string[] Labelpath = Activityname.split ("\ \"); /use the name of the Package. separate</p></p><p><p>String Nextlabel = Labelpath[labelpath.length-1];//gets The last one. the name of the following, the class name</p></p><p><p>AddItem (myData, nextlabel, activityintent (///now add him to the collection of myData, this method will appear in the back, is to separate the various information by map</p></p><p><p>info.activityInfo.applicationInfo.packageName,</p></p><p><p>info.activityInfo.name));</p></p><p><p>}</p></p><p><p>}</p></p><p><p>Collections.sort (myData, Sdisplaynamecomparator);//collections is a useful collection in which a sort is used for sorting, Sdisplaynamecomparator in Parameters is a comparison method</p></p><p><p>Return myData;</p></p><p><p>}</p></p><p><p>The following definition, at first glance, is a method, which is actually a field that defines a reference to a comparison method</p></p><p><p>Private final static comparator<map<string,?>> Sdisplaynamecomparator = new comparator<map<string,? >> () {//to The implementation of that reference</p></p><p><p>Private final Collator Collator = collator.getinstance ();//xinjiang a collection</p></p><p><p><br></p></p><p><p>public int Compare (map<string,?> map1, map<string,?> map2) {//two comparison rules</p></p><p><p>return collator.compare (map1.get ("title"), map2.get ("title"), or//is the way to compare their characters, that is, a letter from left to right, more than ASCLL code</p></p><p><p>}</p></p><p><p>};</p></p><p><p><br></p></p><p><p>Protected Intent activityintent (string pkg, string Componentname) {</p></p><p><p>Intent result = new Intent ();</p></p><p><p>Result.setclassname (pkg, Componentname);//set which package is intended from which class</p></p><p><p>Return result;</p></p><p><p>}</p></p><p><p><br></p></p><p><p>Protected Intent browserintent (String Path) {</p></p><p><p>Intent result = new Intent ();</p></p><p><p>Result.setclass (this, Cocos2d.class);//set from which class to where</p></p><p><p>Result.putextra ("org.cocos2d.tests.Path", Path);//add an extra variable</p></p><p><p>Return result;</p></p><p><p>}</p></p><p><p><br></p></p><p><p>protected void AddItem (list<map<string,?>> data, String name, Intent Intent) {</p></p><p><p>map<string, object> temp = new hashmap<string, object> ();</p></p><p><p>Temp.put ("title", name);</p></p><p><p>Temp.put ("intent", intent);</p></p><p><p>Data.add (temp);//add a project to data</p></p><p><p>}</p></p><p><p><br></p></p><p><p>@Override</p></p><p><p>protected void Onlistitemclick (ListView l, View v, int position, long Id) {</p></p><p><p>map<string,?> map = (map<string,?>) l.getitematposition (position);//get A click on which package</p></p><p><p>Intent Intent = (Intent) Map.get ("Intent");//find that class full name</p></p><p><p>StartActivity (intent);//open that class</p></p><p><p>}</p></p><p><p>}</p></p><p><p><br></p></p><p><p>Cocos2d-android-1 Source Detailed: 1.cocos2d</p></p></span>
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