public
class
AndroidGraphics2DTutorial
extends
ListActivity {
private
static
final
String SAMPLE_CATEGORY
=
"com.pstreets.graphics2d.SAMPLE_CODE"
;
@Override
public
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setListAdapter(
new
SimpleAdapter(
this
, getData(),
android.R.layout.simple_list_item_1,
new
String[] {
"title"
},
new
int
[] { android.R.id.text1 }));
getListView().setTextFilterEnabled(
true
);
}
protected
List getData() {
List<Map> myData =
new
ArrayList<Map>();
Intent mainIntent =
new
Intent(Intent.ACTION_MAIN,
null
);
mainIntent.addCategory(SAMPLE_CATEGORY);
PackageManager pm = getPackageManager();
List<ResolveInfo> list = pm.queryIntentActivities(mainIntent,
0
);
if
(
null
== list)
return
myData;
String[] prefixPath;
prefixPath =
null
;
int
len = list.size();
Map<String, Boolean> entries =
new
HashMap<String, Boolean>();
for
(
int
i =
0
; i < len; i++) {
ResolveInfo info = list.get(i);
CharSequence labelSeq = info.loadLabel(pm);
String label = labelSeq !=
null
? labelSeq.toString()
: info.activityInfo.name;
String[] labelPath = label.split(
"/"
);
String nextLabel = prefixPath ==
null
? labelPath[
0
]
: labelPath[prefixPath.length];
if
((prefixPath !=
null
? prefixPath.length :
0
)
== labelPath.length -
1
) {
addItem(myData,
nextLabel,
activityIntent(
info.activityInfo.applicationInfo.packageName,
info.activityInfo.name));
}
else
{
if
(entries.get(nextLabel) ==
null
) {
addItem(myData, nextLabel, browseIntent(nextLabel));
entries.put(nextLabel,
true
);
}
}
}
Collections.sort(myData, sDisplayNameComparator);
return
myData;
}
private
final
static
Comparator<Map> sDisplayNameComparator
=
new
Comparator<Map>() {
private
final
Collator collator = Collator.getInstance();
public
int
compare(Map map1, Map map2) {
return
collator.compare(map1.get(
"title"
), map2.get(
"title"
));
}
};
protected
Intent activityIntent(String pkg, String componentName) {
Intent result =
new
Intent();
result.setClassName(pkg, componentName);
return
result;
}
protected
Intent browseIntent(String path) {
Intent result =
new
Intent();
result.setClass(
this
, AndroidGraphics2DTutorial.
class
);
return
result;
}
protected
void
addItem(List<Map> data, String name, Intent intent) {
Map<String, Object> temp =
new
HashMap<String, Object>();
temp.put(
"title"
, name);
temp.put(
"intent"
, intent);
data.add(temp);
}
@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);
}
}
相关推荐
3. **数据绑定(Data Binding)**: ExtJS支持数据模型和视图之间的双向绑定,使得数据的更新能实时反映到界面上。 **二、ExtJS核心API详解** 1. **Ext.Element**: 表示DOM元素,提供了丰富的DOM操作方法,如样式...
- **Data Binding**: 组件与Store之间的双向数据绑定,当Store中的数据发生变化时,关联的组件会自动更新。 ### 4. MVC架构 ExtJS 2.0 引入了MVC(Model-View-Controller)模式,帮助组织代码,提高可维护性和可...
然后,深入学习数据绑定(Data Binding)机制,这是ExtJS实现数据驱动UI的关键。此外,事件处理(Events)和Ajax通信(Ajax requests)也是重要部分,它们使用户与应用之间的交互变得可能。 在阅读教程和API文档时...
17. **绑定图表至数据源(Binding the Chart to a Data Source)**: - **定义**:实现图表与外部数据源之间的自动同步。 - **应用场景**:动态数据展示或实时监控系统。 - **优势**:减少手动更新的工作量,提高...
它可能会涵盖EXT JS的基本组件如表格(Grid)、面板(Panel)、窗口(Window)、表单(Form)等,以及布局(Layouts)、数据绑定(Data Binding)和事件处理(Events Handling)等内容。EXT JS的组件模型强大,允许...
7. **线程栈大小和线程绑定(Thread Stack Size and Thread Binding)**:这两者影响线程的创建和执行,可以优化性能和资源使用。 8. **监控、调试和性能分析工具(Monitoring, Debugging and Performance Analysis ...