package denesoft.demo.host;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.TextView;
public class DemoHost extends Activity {
public static final String PLUGIN_ACTION_STRING = "denesoft.demo.plugin.client";
private GridView m_gridView;
private ArrayList<PluginBean> m_plugins;
private class PluginBean {
public PluginBean(String ver, String name) {
m_version = ver;
m_name = name;
}
public String m_version;
public String m_name;
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initControls();
}
protected void initControls() {
m_gridView = (GridView) findViewById(R.id.gv_plugins);
loadPlugIns();
// 开始加载外部插件。
m_gridView.setAdapter(new MyAdapter(this));
}
public void loadPlugIns() {
Intent intent = new Intent(PLUGIN_ACTION_STRING, null);
PackageManager pm = this.getPackageManager();
final List<ResolveInfo> plugIns = pm.queryIntentActivities(intent, 0);
String packageName = null;
String version = null;
String name = null;
if (plugIns != null && plugIns.size() > 0) {
m_plugins = new ArrayList<DemoHost.PluginBean>(plugIns.size());
}
for (int i = 0; i < plugIns.size(); i++) {
ResolveInfo rInfo = plugIns.get(i);
ActivityInfo aInfo = rInfo.activityInfo;
packageName = aInfo.packageName;
// 得到插件信息
try {
Resources res = pm.getResourcesForApplication(packageName);
// TypedValue outValue;
int id = res.getIdentifier("version", "string", packageName);
version = res.getString(id);
id = res.getIdentifier("name", "string", packageName);
name = res.getString(id);
} catch (NameNotFoundException e1) {
e1.printStackTrace();
} catch (Resources.NotFoundException e) {
Log.i("xx", e.toString());
}
m_plugins.add(new PluginBean(version, name));
}
// DexClassLoader cl = new DexClassLoader(dexPath, dexOutputDir,
// libPath,
// this.getClass().getClassLoader());
}
class MyAdapter extends BaseAdapter {
private LayoutInflater m_Inflater;
public MyAdapter(Context context) {
m_Inflater = LayoutInflater.from(context);
}
public int getCount() {
if (m_plugins != null) {
return m_plugins.size();
}
return 0;
}
public Object getItem(int pos) {
return pos;
}
public long getItemId(int pos) {
return pos;
}
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = m_Inflater.inflate(R.layout.griditem, null);
} else {
; //nothing to do;
}
convertView.setTag(m_plugins.get(position));
((TextView) convertView).setText(m_plugins.get(position).m_name);
convertView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//Toast.makeText(DemoHost.this, "click me", 1000).show();
Intent intent = new Intent(PLUGIN_ACTION_STRING);
startActivity(intent);
}
});
return convertView;
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
DemoPlugin.zip (24个子文件)
DemoPlugin
res
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
ic_launcher.png 4KB
values
strings.xml 261B
drawable-mdpi
ic_launcher.png 3KB
layout
main.xml 398B
assets
proguard.cfg 1KB
src
denesoft
demo
plugin
DemoPlugin.java 342B
.project 846B
.classpath 438B
project.properties 361B
AndroidManifest.xml 971B
DemoHost
res
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
ic_launcher.png 4KB
values
strings.xml 172B
drawable-mdpi
ic_launcher.png 3KB
layout
griditem.xml 1KB
main.xml 399B
assets
proguard.cfg 1KB
src
denesoft
demo
host
DemoHost.java 4KB
comm
IDsoftComm.java 99B
.project 844B
.classpath 364B
project.properties 361B
AndroidManifest.xml 730B
共 24 条
- 1
szbhzc
- 粉丝: 0
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页