Cocos2D-Android-1 source code explanation: 1. Cocos2D

Source: Internet
Author: User
Tags collator

Cocos2D-Android-1 source code explanation: 1. Cocos2D

/** Copyright (C) 2007 The Android Open Source Project ** Licensed under the Apache License, Version 2.0 (the "License "); * you may not use this file before t in compliance with the License. * You may obtain a copy of the License ** http://www.apache.org/licenses/LICENSE-2.0 ** Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "as is" BASIS, * without warranties or conditions of any kind, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org. cocos2d; import java. text. collator; import java. util. arrayList; import j Ava. util. collections; import java. util. comparator; import java. util. hashMap; import java. util. list; import java. util. map; import android. app. listActivity; import android. content. intent; import android. content. pm. packageManager; import android. content. pm. resolveInfo; import android. OS. bundle; import android. view. view; import android. widget. listView; import android. widget. simpleAdapter; public class Cocos2D exte Nds ListActivity {// This class uses ListActivity @ Override public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); // inherit the onCreate method of ListActivity // The following is the setListAdapter (new SimpleAdapter (this, // new simple adapter, use your own context (List <Map <String,?>) GetData ("org. cocos2d. tests "), // getData is a method, and getData (String) looks down at the method declaration android. r. layout. simple_list_item_1, new String [] {"title"}, new int [] {android. r. id. text1}); getListView (). setTextFilterEnabled (true); // enable the filter window} protected List <?> GetData (String prefix) {// List <Map <String,?> MyData = new ArrayList <Map <String,?> (); // A list used to hold the map. map stands for String Intent mainIntent = new Intent (Intent. ACTION_MAIN, null); // specifies the intent to jump to the system desktop mainIntent. addCategory (Intent. CATEGORY_TEST); // PackageManager pm = getPackageManager (); // The package controller is used to obtain the List of existing processes <ResolveInfo> list = pm. queryIntentActivities (mainIntent, 0); // search for related activities through Intent, more accurate if (null = list) // The test Intent returned myData is not found; // end./* the following is an unused method used to split a String. Use/String [] prefixPath; If (prefix. equals ("") {prefixPath = null;} else {prefixPath = prefix. split ("/");} */int len = list. size (); // obtain the list length // Map <String, Boolean> entries = new HashMap <String, Boolean> (); // an unused map, map for (int I = 0; I <len; I ++) {ResolveInfo info = list. get (I); // used to loop the list String activityName = info. activityInfo. name; // obtain the activity name if (prefix. length () = 0 | activityName. st ArtsWith (prefix) {// if the package name of the activity to be searched is 0 or the String [] labelPath = activityName that we are looking for starts with this. split ("\\. "); // use the package name. separate String nextLabel = labelPath [labelPath. length-1]; // get the last one. the following name is the class name addItem (myData, nextLabel, activityIntent (// Add it to the set of mydata now, this method will appear later, the information is distinguished by info by map. activityInfo. applicationInfo. packageName, info. activityInfo. name) ;}} Collections. sort (myData, sDisplayNameCompar Ator); // Collections is a very useful set, where a sort is used for sorting. In the parameter, sDisplayNameComparator is a comparison method return myData;} // the following definition, at first glance, the method is actually a field, defining a comparison method to reference private final static Comparator <Map <String,?> SDisplayNameComparator = new Comparator <Map <String,?> () {// Implement private final Collator collator = Collator. getInstance () for that reference; // public int compare (Map <String,?> Map1, Map <String,?> Map2) {// two comparison rules return collator. compare (map1.get ("title"), map2.get ("title"); // It is the method for comparing their characters, that is, one letter from left to right, than ascll code }}; protected Intent activityIntent (String pkg, String componentName) {Intent result = new Intent (); result. setClassName (pkg, componentName); // you can specify the packet from which the Intent is returned to the returned result class.} protected Intent browserIntent (String path) {Intent result = new Intent (); result. setClass (this, Cocos2D. CIA Ss); // set the class to which result. putExtra ("org. cocos2d. tests. path ", path); // Add an additional variable return result;} protected void addItem (List <Map <String,?> Data, String name, Intent intent) {Map <String, Object> temp = new HashMap <String, Object> (); temp. put ("title", name); temp. put ("intent", intent); data. add (temp); // add a project to data} @ Override protected void onListItemClick (ListView l, View v, int position, long id) {Map <String,?> Map = (Map <String,?>) L. getItemAtPosition (position); // obtain the packet Intent intent = (Intent) map you clicked. get ("intent"); // locate the class full name startActivity (intent );}}

 

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.