0){intent.putExtra("position","1");intent.setClass(AlbumActivity.this,GalleryActivity.class);startActivity(intent);}}}//完成按钮的监听privateclassAlbumSendListenerimplementsOnClickListener{publicvoidonClick(Viewv){overridePendingTransition(R.anim.activity_translate_in,R.anim.activity_translate_out);intent.setClass(mContext,MainActivity.class);startActivity(intent);finish();}}//返回按钮监听privateclassBackListenerimplementsOnClickListener{publicvoidonClick(Viewv){intent.setClass(AlbumActivity.this,ImageFile.class);startActivity(intent);}}//取消按钮的监听privateclassCancelListenerimplementsOnClickListener{publicvoidonClick(Viewv){Bimp.tempSelectBitmap.clear();intent.setClass(mContext,MainActivity.class);startActivity(intent);}}//初始化,给一些对象赋值privatevoidinit(){helper=AlbumHelper.getHelper();helper.init(getApplicationContext());contentList=helper.getImagesBucketList(false);dataList=newArrayList();for(inti=0;i=PublicWay.num){toggleButton.setChecked(false);chooseBt.setVisibility(View.GONE);if(!removeOneData(dataList.get(position))){Toast.makeText(AlbumActivity.this,Res.getString("only_choose_num"),200).show();}return;}if(isChecked){chooseBt.setVisibility(View.VISIBLE);Bimp.tempSelectBitmap.add(dataList.get(position));okButton.setText(Res.getString("finish")"("Bimp.tempSelectBitmap.size()"/"PublicWay.num")");}else{Bimp.tempSelectBitmap.remove(dataList.get(position));chooseBt.setVisibility(View.GONE);okButton.setText(Res.getString("finish")"("Bimp.tempSelectBitmap.size()"/"PublicWay.num")");}isShowOkBt();}});okButton.setOnClickListener(newAlbumSendListener());}privatebooleanremoveOneData(ImageItemimageItem){if(Bimp.tempSelectBitmap.contains(imageItem)){Bimp.tempSelectBitmap.remove(imageItem);okButton.setText(Res.getString("finish")"("Bimp.tempSelectBitmap.size()"/"PublicWay.num")");returntrue;}returnfalse;}publicvoidisShowOkBt(){if(Bimp.tempSelectBitmap.size()>0){okButton.setText(Res.getString("finish")"("Bimp.tempSelectBitmap.size()"/"PublicWay.num")");preview.setPressed(true);okButton.setPressed(true);preview.setClickable(true);okButton.setClickable(true);okButton.setTextColor(Color.WHITE);preview.setTextColor(Color.WHITE);}else{okButton.setText(Res.getString("finish")"("Bimp.tempSelectBitmap.size()"/"PublicWay.num")");preview.setPressed(false);preview.setClickable(false);okButton.setPressed(false);okButton.setClickable(false);okButton.setTextColor(Color.parseColor("#E1E0DE"));preview.setTextColor(Color.parseColor("#E1E0DE"));}}publicbooleanonKeyDown(intkeyCode,KeyEventevent){if(keyCode==KeyEvent.KEYCODE_BACK){intent.setClass(AlbumActivity.this,ImageFile.class);startActivity(intent);}returnfalse;}@OverrideprotectedvoidonRestart(){isShowOkBt();super.onRestart();}-IMDN开发者社群-imdn.cn">
0){intent.putExtra("position","1");intent.setClass(AlbumActivity.this,GalleryActivity.class);startActivity(intent);}}}//完成按钮的监听privateclassAlbumSendListenerimplementsOnClickListener{publicvoidonClick(Viewv){overridePendingTransition(R.anim.activity_translate_in,R.anim.activity_translate_out);intent.setClass(mContext,MainActivity.class);startActivity(intent);finish();}}//返回按钮监听privateclassBackListenerimplementsOnClickListener{publicvoidonClick(Viewv){intent.setClass(AlbumActivity.this,ImageFile.class);startActivity(intent);}}//取消按钮的监听privateclassCancelListenerimplementsOnClickListener{publicvoidonClick(Viewv){Bimp.tempSelectBitmap.clear();intent.setClass(mContext,MainActivity.class);startActivity(intent);}}//初始化,给一些对象赋值privatevoidinit(){helper=AlbumHelper.getHelper();helper.init(getApplicationContext());contentList=helper.getImagesBucketList(false);dataList=newArrayList();for(inti=0;i=PublicWay.num){toggleButton.setChecked(false);chooseBt.setVisibility(View.GONE);if(!removeOneData(dataList.get(position))){Toast.makeText(AlbumActivity.this,Res.getString("only_choose_num"),200).show();}return;}if(isChecked){chooseBt.setVisibility(View.VISIBLE);Bimp.tempSelectBitmap.add(dataList.get(position));okButton.setText(Res.getString("finish")"("Bimp.tempSelectBitmap.size()"/"PublicWay.num")");}else{Bimp.tempSelectBitmap.remove(dataList.get(position));chooseBt.setVisibility(View.GONE);okButton.setText(Res.getString("finish")"("Bimp.tempSelectBitmap.size()"/"PublicWay.num")");}isShowOkBt();}});okButton.setOnClickListener(newAlbumSendListener());}privatebooleanremoveOneData(ImageItemimageItem){if(Bimp.tempSelectBitmap.contains(imageItem)){Bimp.tempSelectBitmap.remove(imageItem);okButton.setText(Res.getString("finish")"("Bimp.tempSelectBitmap.size()"/"PublicWay.num")");returntrue;}returnfalse;}publicvoidisShowOkBt(){if(Bimp.tempSelectBitmap.size()>0){okButton.setText(Res.getString("finish")"("Bimp.tempSelectBitmap.size()"/"PublicWay.num")");preview.setPressed(true);okButton.setPressed(true);preview.setClickable(true);okButton.setClickable(true);okButton.setTextColor(Color.WHITE);preview.setTextColor(Color.WHITE);}else{okButton.setText(Res.getString("finish")"("Bimp.tempSelectBitmap.size()"/"PublicWay.num")");preview.setPressed(false);preview.setClickable(false);okButton.setPressed(false);okButton.setClickable(false);okButton.setTextColor(Color.parseColor("#E1E0DE"));preview.setTextColor(Color.parseColor("#E1E0DE"));}}publicbooleanonKeyDown(intkeyCode,KeyEventevent){if(keyCode==KeyEvent.KEYCODE_BACK){intent.setClass(AlbumActivity.this,ImageFile.class);startActivity(intent);}returnfalse;}@OverrideprotectedvoidonRestart(){isShowOkBt();super.onRestart();} - IMDN开发者社群-imdn.cn">
首页 »
Java »
获取系统图库的图片,调用系统相机,并生成预览,
** * 这个是进入相册显示所有图片的界面 * * @author king * @QQ:595163260 * @version 2014年10月18日 下午11:47:15 */public class AlbumActivity extends Activity {//显示手机里的所有图片的列表控件private GridView gridView;//当手机里没有图片时,提示用户没有图片的控件private TextView tv;//gridView的adapterprivate AlbumGridViewAdapter gridImageAdapter;//完成按钮private Button okButton;// 返回按钮private Button back;// 取消按钮private Button cancel;private Intent intent;// 预览按钮private Button preview;private Context mContext;private ArrayList dataList;private AlbumHelper helper;public static List contentList;public static Bitmap bitmap;protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(Res.getLayoutID("plugin_camera_album"));PublicWay.activityList.add(this);mContext = this;//注册一个广播,这个广播主要是用于在GalleryActivity进行预览时,防止当所有图片都删除完后,再回到该页面时被取消选中的图片仍处于选中状态IntentFilter filter = new IntentFilter("data.broadcast.action"); registerReceiver(broadcastReceiver, filter); bitmap = BitmapFactory.decodeResource(getResources(),Res.getDrawableID("plugin_camera_no_pictures")); init();initListener();//这个函数主要用来控制预览和完成按钮的状态isShowOkBt();}BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { //mContext.unregisterReceiver(this); // TODO Auto-generated method stub gridImageAdapter.notifyDataSetChanged(); } }; // 预览按钮的监听private class PreviewListener implements OnClickListener {public void onClick(View v) {if (Bimp.tempSelectBitmap.size() > 0) {intent.putExtra("position", "1");intent.setClass(AlbumActivity.this, GalleryActivity.class);startActivity(intent);}}}// 完成按钮的监听private class AlbumSendListener implements OnClickListener {public void onClick(View v) {overridePendingTransition(R.anim.activity_translate_in, R.anim.activity_translate_out);intent.setClass(mContext, MainActivity.class);startActivity(intent);finish();}}// 返回按钮监听private class BackListener implements OnClickListener {public void onClick(View v) {intent.setClass(AlbumActivity.this, ImageFile.class);startActivity(intent);}}// 取消按钮的监听private class CancelListener implements OnClickListener {public void onClick(View v) {Bimp.tempSelectBitmap.clear();intent.setClass(mContext, MainActivity.class);startActivity(intent);}}// 初始化,给一些对象赋值private void init() {helper = AlbumHelper.getHelper();helper.init(getApplicationContext());contentList = helper.getImagesBucketList(false);dataList = new ArrayList();for(int i = 0; i= PublicWay.num) {toggleButton.setChecked(false);chooseBt.setVisibility(View.GONE);if (!removeOneData(dataList.get(position))) {Toast.makeText(AlbumActivity.this, Res.getString("only_choose_num"),200).show();}return;}if (isChecked) {chooseBt.setVisibility(View.VISIBLE);Bimp.tempSelectBitmap.add(dataList.get(position));okButton.setText(Res.getString("finish") "(" Bimp.tempSelectBitmap.size() "/" PublicWay.num ")");} else {Bimp.tempSelectBitmap.remove(dataList.get(position));chooseBt.setVisibility(View.GONE);okButton.setText(Res.getString("finish") "(" Bimp.tempSelectBitmap.size() "/" PublicWay.num ")");}isShowOkBt();}});okButton.setOnClickListener(new AlbumSendListener());}private boolean removeOneData(ImageItem imageItem) {if (Bimp.tempSelectBitmap.contains(imageItem)) {Bimp.tempSelectBitmap.remove(imageItem);okButton.setText(Res.getString("finish") "(" Bimp.tempSelectBitmap.size() "/" PublicWay.num ")");return true;}return false;}public void isShowOkBt() {if (Bimp.tempSelectBitmap.size() > 0) {okButton.setText(Res.getString("finish") "(" Bimp.tempSelectBitmap.size() "/" PublicWay.num ")");preview.setPressed(true);okButton.setPressed(true);preview.setClickable(true);okButton.setClickable(true);okButton.setTextColor(Color.WHITE);preview.setTextColor(Color.WHITE);} else {okButton.setText(Res.getString("finish") "(" Bimp.tempSelectBitmap.size() "/" PublicWay.num ")");preview.setPressed(false);preview.setClickable(false);okButton.setPressed(false);okButton.setClickable(false);okButton.setTextColor(Color.parseColor("#E1E0DE"));preview.setTextColor(Color.parseColor("#E1E0DE"));}}public boolean onKeyDown(int keyCode, KeyEvent event) {if (keyCode == KeyEvent.KEYCODE_BACK) {intent.setClass(AlbumActivity.this, ImageFile.class);startActivity(intent);}return false;}@Overrideprotected void onRestart() {isShowOkBt();super.onRestart();}
下载说明:请别用迅雷下载,失败请重下,重下不扣分!