最近2018中文字幕在日韩欧美国产成人片_国产日韩精品一区二区在线_在线观看成年美女黄网色视频_国产精品一区三区五区_国产精彩刺激乱对白_看黄色黄大色黄片免费_人人超碰自拍cao_国产高清av在线_亚洲精品电影av_日韩美女尤物视频网站

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Cocos2D-Android-1之源碼詳解:1.Cocos2D

/*

創(chuàng)新互聯(lián)公司長期為上千客戶提供的網(wǎng)站建設服務,團隊從業(yè)經(jīng)驗10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務;打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為龍川企業(yè)提供專業(yè)的做網(wǎng)站、網(wǎng)站建設,龍川網(wǎng)站改版等技術(shù)服務。擁有十載豐富建站經(jīng)驗和眾多成功案例,為您定制開發(fā)。

 * Copyright (C) 2007 The Android Open Source Project

 *

 * Licensed under the Apache License, Version 2.0 (the "License");

 * you may not use this file except in compliance with the License.

 * You may obtain a copy of the License at

 *

 *      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 java.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 extends ListActivity {//這個類用了ListActivity 

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState); //繼承 ListActivity 的 onCreate方法     //以下是設置list里的適配器

        setListAdapter(new SimpleAdapter(this,//新的簡單適配器,運用了自己的上下文

                (List>)getData("org.cocos2d.tests"),//getData是個方法,getData(String)往下看有方法的聲明

                android.R.layout.simple_list_item_1, new String[]{"title"},

                new int[]{android.R.id.text1}));

        getListView().setTextFilterEnabled(true);//啟用過濾窗口

    }

    protected List getData(String prefix) {//即上述方法

        List> myData = new ArrayList>();//一個用來盛放map的list,map立盛放String

        Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);//意圖指定跳到系統(tǒng)桌面

        mainIntent.addCategory(Intent.CATEGORY_TEST);//供測試使用

        PackageManager pm = getPackageManager();//包控制器,用來獲得現(xiàn)在有的進程

        List list = pm.queryIntentActivities(mainIntent, 0);//通過Intent查找相關(guān)的Activity,更準確

        if (null == list)//沒找到那個測試意圖

            return myData;//就結(jié)束

        /* 以下是個沒有被使用的方法用來分割字符串,用/

        String[] prefixPath;

        if (prefix.equals("")) {

            prefixPath = null;

        } else {

            prefixPath = prefix.split("/");

        }*/

        int len = list.size();//得到list的長度

        // Map entries = new HashMap();//一個沒有被使用的map,用了哈希類型的map

        for (int i = 0; i < len; i++) {

            ResolveInfo info = list.get(i);//用來循環(huán)剛才得到的那個list

            String activityName = info.activityInfo.name;//得到activity的名字

            if (prefix.length() == 0 || activityName.startsWith(prefix)) {//如果要查找的那個activity的包名長度為0或者與我們要找的那個名字是以這個開頭的

                String[] labelPath = activityName.split("\\.");//把包名用.分開

                String nextLabel = labelPath[labelPath.length - 1];//得到最后一個.后面的名字,即類名

                addItem(myData, nextLabel, activityIntent(//現(xiàn)在把他添加到mydata的集合,這個方法在后面會出現(xiàn),就是分別把各種信息用map區(qū)分了

                        info.activityInfo.applicationInfo.packageName,

                        info.activityInfo.name));

            }

        }

        Collections.sort(myData, sDisplayNameComparator);//Collections是個很有用的集合,其中有個sort是用來排序的,參數(shù)中sDisplayNameComparator是個比較方法

        return myData;

    }

//下面這個定義,乍一看是方法,其實是個字段,定義一個比較方法的引用

    private final static Comparator> sDisplayNameComparator = new Comparator>() {//對那個引用的實現(xiàn)

        private final Collator collator = Collator.getInstance();//新疆一個集合

        public int compare(Map map1, Map map2) {//兩個的比較規(guī)則

            return collator.compare(map1.get("title"), map2.get("title"));//就是比較他們字符的那種方法,就是從左到右一個一個字母,比ascll碼

        }

    };

    protected Intent activityIntent(String pkg, String componentName) {

        Intent result = new Intent();

        result.setClassName(pkg, componentName);//設置意圖從哪個包到哪個類

        return result;

    }

    protected Intent browserIntent(String path) {

        Intent result = new Intent();

        result.setClass(this, Cocos2D.class);//設置從哪個class到哪

        result.putExtra("org.cocos2d.tests.Path", path);//加一個額外的變量

        return result;

    }

    protected void addItem(List> data, String name, Intent intent) {

        Map temp = new HashMap();

        temp.put("title", name);

        temp.put("intent", intent);

        data.add(temp);//對data添加項目

    }

    @Override

    protected void onListItemClick(ListView l, View v, int position, long id) {

        Map map = (Map) l.getItemAtPosition(position);//得到點擊了哪個包

        Intent intent = (Intent) map.get("intent");//找到那個類全名

        startActivity(intent);//打開那個類

    }

}


新聞標題:Cocos2D-Android-1之源碼詳解:1.Cocos2D
路徑分享:http://fisionsoft.com.cn/article/jjscco.html