您好,欢迎光临本网站![请登录][注册会员]  
文件名称: 具有拖曳功能的Gallery
  所属分类: Android
  开发工具:
  文件大小: 727kb
  下载次数: 0
  上传时间: 2011-11-10
  提 供 者: tdk****
 详细说明: package seker.mygallery; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import seker.mygallery.R; import seker.mygallery.view.GalleryAdapter; import seker.mygallery.view.MyAdapterView; import seker.mygallery.view.MyGallery; import android.app.Activity; import android.content.ComponentName; import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.os.Bundle; import android.os.Ha ndler; import android.os.Message; import android.util.Log; import android.view.View; import android.widget.SimpleAdapter; public class MainActivity extends Activity implements Runnable { public static final String NAME = "name"; public static final String NUMBER = "number"; public static final String IMAGE = "image"; SimpleAdapter m_simpleadapter; GalleryAdapter m_galleryadapter; private List> m_list; private static final int FINISH_GET_APPS = 1024; List m_infos; PackageManager m_packageMgr; MyGallery g1, g2; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); m_packageMgr = getPackageManager(); initMyGallery1(); Thread thread = new Thread(this); thread.start(); } private Handler handler = new Handler(){ public void handleMessage(Message msg){ switch (msg.what) { case FINISH_GET_APPS: initMyGallery2(); break; } } }; @Override public void run() { Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); m_infos = m_packageMgr.queryIntentActivities(mainIntent, 0); Collections.sort(m_infos, new ResolveInfo.DisplayNameComparator(m_packageMgr)); Message message = new Message(); message.what = FINISH_GET_APPS; handler.sendMessage(message); } private void initMyGallery1() { initData(); m_simpleadapter = new SimpleAdapter(this, m_list, R.layout.gallerychild_box , new String[] {NAME, NUMBER, IMAGE} , new int[] {R.id.name, R.id.box_num, R.id.AppBtnImageView}); g1 = (MyGallery) findViewById(R.id.myGallery1); g1.setAdapter(m_simpleadapter); g1.setSelection(0); g1.setOnItemClickListener(itemclick_listener1); } private void initMyGallery2() { m_galleryadapter = new GalleryAdapter(this, m_infos, m_packageMgr); g2 = (MyGallery) findViewById(R.id.myGallery2); g2.setAdapter(m_galleryadapter); g2.setSelection(0); g2.setOnItemClickListener(itemclick_listener2); } MyGallery.OnItemClickListener itemclick_listener1 = new MyGallery.OnItemClickListener() { private int testIndex = 0; @Override public void onItemClick(MyAdapterView parent, View view, int position, long id) { if (0 == position) { Map map = new HashMap(); map.put(NAME, "add" + testIndex); map.put(NUMBER, testIndex ++); map.put(IMAGE, R.drawable.img00); m_list.add(1, map); m_simpleadapter.notifyDataSetChanged(); } } }; MyGallery.OnItemClickListener itemclick_listener2 = new MyGallery.OnItemClickListener() { @Override public void onItemClick(MyAdapterView parent, View view, int position, long id) { ResolveInfo info = m_infos.get(position); String packageName = info.activityInfo.applicationInfo.packageName; String className = info.activityInfo.name; Log.d("StartActivity", "packageName = " + packageName + "\tclassName = " + className); Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setComponent(new ComponentName(packageName, className)); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); startActivity(intent); } }; private void initData() { m_list = new ArrayList>(); Map map = new HashMap(); map.put(NAME, "img1"); map.put(NUMBER, 1); map.put(IMAGE, R.drawable.img01); m_list.add(map); map = new HashMap(); map.put(NAME, "img2"); map.put(NUMBER, 2); map.put(IMAGE, R.drawable.img02); m_list.add(map); map = new HashMap(); map.put(NAME, "img3"); map.put(NUMBER, 3); map.put(IMAGE, R.drawable.img03); m_list.add(map); map = new HashMap(); map.put(NAME, "img4"); map.put(NUMBER, 4); map.put(IMAGE, R.drawable.img04); m_list.add(map); map = new HashMap(); map.put(NAME, "img5"); map.put(NUMBER, 5); map.put(IMAGE, R.drawable.img05); m_list.add(map); map = new HashMap(); map.put(NAME, "img6"); map.put(NUMBER, 6); map.put(IMAGE, R.drawable.img06); m_list.add(map); map = new HashMap(); map.put(NAME, "img7"); map.put(NUMBER, 7); map.put(IMAGE, R.drawable.img07); m_list.add(map); map = new HashMap(); map.put(NAME, "img8"); map.put(NUMBER, 8); map.put(IMAGE, R.drawable.img08); m_list.add(map); } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: android gallery
 输入关键字,在本站1000多万海量源码库中尽情搜索: