• 大小: 2.06M
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2020-12-24
  • 标签:

资源简介

**
 * 这个是进入相册显示所有图片的界面
 * 
 * @author king
 * @QQ:595163260
 * @version 2014年10月18日  下午11:47:15
 */
public class AlbumActivity extends Activity {
//显示手机里的所有图片的列表控件
private GridView gridView;
//当手机里没有图片时,提示用户没有图片的控件
private TextView tv;
//gridView的adapter
private AlbumGridViewAdapter gridImageAdapter;
//完成按钮
private Button okButton;
// 返回按钮
private Button back;
// 取消按钮
private Button cancel;
private Intent intent;
// 预览按钮
private Button preview;
private Context mContext;
private ArrayList<ImageItem> dataList;
private AlbumHelper helper;
public static List<ImageBucket> 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<ImageItem>();
for(int i = 0; i<contentList.size(); i ){
dataList.addAll( contentList.get(i).imageList );
}

back = (Button) findViewById(Res.getWidgetID("back"));
cancel = (Button) findViewById(Res.getWidgetID("cancel"));
cancel.setOnClickListener(new CancelListener());
back.setOnClickListener(new BackListener());
preview = (Button) findViewById(Res.getWidgetID("preview"));
preview.setOnClickListener(new PreviewListener());
intent = getIntent();
Bundle bundle = intent.getExtras();
gridView = (GridView) findViewById(Res.getWidgetID("myGrid"));
gridImageAdapter = new AlbumGridViewAdapter(this,dataList,
Bimp.tempSelectBitmap);
gridView.setAdapter(gridImageAdapter);
tv = (TextView) findViewById(Res.getWidgetID("myText"));
gridView.setEmptyView(tv);
okButton = (Button) findViewById(Res.getWidgetID("ok_button"));
okButton.setText(Res.getString("finish") "(" Bimp.tempSelectBitmap.size()
"/" PublicWay.num ")");
}

private void initListener() {

gridImageAdapter
.setOnItemClickListener(new AlbumGridViewAdapter.OnItemClickListener() {

@Override
public void onItemClick(final ToggleButton toggleButton,
int position, boolean isChecked,Button chooseBt) {
if (Bimp.tempSelectBitmap.size() >= 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;

}
@Override
protected void onRestart() {
isShowOkBt();
super.onRestart();
}

资源截图

代码片段和文件信息

/** Automatically generated file. DO NOT MODIFY */
package com.king.photo;

public final class BuildConfig {
    public final static boolean DEBUG = true;
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        475  2014-12-03 17:10  Photo\.classpath

     文件        841  2014-12-03 17:10  Photo\.project

     文件         57  2014-12-03 17:10  Photo\.settings\org.eclipse.core.resources.prefs

     文件        177  2014-12-03 17:10  Photo\.settings\org.eclipse.jdt.core.prefs

     文件       2151  2014-12-03 17:10  Photo\AndroidManifest.xml

     文件       2151  2014-12-03 17:10  Photo\bin\AndroidManifest.xml

     文件        982  2014-12-03 17:10  Photo\bin\classes\com\king\photo\activity\AlbumActivity$1.class

     文件       2728  2014-12-03 17:10  Photo\bin\classes\com\king\photo\activity\AlbumActivity$2.class

     文件       1483  2014-12-03 17:10  Photo\bin\classes\com\king\photo\activity\AlbumActivity$AlbumSendListener.class

     文件       1266  2014-12-03 17:10  Photo\bin\classes\com\king\photo\activity\AlbumActivity$BackListener.class

     文件       1506  2014-12-03 17:10  Photo\bin\classes\com\king\photo\activity\AlbumActivity$CancelListener.class

     文件       1579  2014-12-03 17:10  Photo\bin\classes\com\king\photo\activity\AlbumActivity$PreviewListener.class

     文件       7970  2014-12-03 17:10  Photo\bin\classes\com\king\photo\activity\AlbumActivity.class

     文件       1093  2014-12-03 17:10  Photo\bin\classes\com\king\photo\activity\GalleryActivity$1.class

     文件       1284  2014-12-03 17:10  Photo\bin\classes\com\king\photo\activity\GalleryActivity$BackListener.class

     文件       2911  2014-12-03 17:10  Photo\bin\classes\com\king\photo\activity\GalleryActivity$DelListener.class

     文件       1440  2014-12-03 17:10  Photo\bin\classes\com\king\photo\activity\GalleryActivity$GallerySendListener.class

     文件       2285  2014-12-03 17:10  Photo\bin\classes\com\king\photo\activity\GalleryActivity$MyPageAdapter.class

     文件       7624  2014-12-03 17:10  Photo\bin\classes\com\king\photo\activity\GalleryActivity.class

     文件       1432  2014-12-03 17:10  Photo\bin\classes\com\king\photo\activity\ImageFile$CancelListener.class

     文件       2653  2014-12-03 17:10  Photo\bin\classes\com\king\photo\activity\ImageFile.class

     文件       1090  2014-12-03 17:10  Photo\bin\classes\com\king\photo\activity\MainActivity$1.class

     文件       1119  2014-12-03 17:10  Photo\bin\classes\com\king\photo\activity\MainActivity$2.class

     文件       1430  2014-12-03 17:10  Photo\bin\classes\com\king\photo\activity\MainActivity$3.class

     文件       1090  2014-12-03 17:10  Photo\bin\classes\com\king\photo\activity\MainActivity$4.class

     文件       2562  2014-12-03 17:10  Photo\bin\classes\com\king\photo\activity\MainActivity$5.class

     文件       1184  2014-12-03 17:10  Photo\bin\classes\com\king\photo\activity\MainActivity$GridAdapter$1.class

     文件       1273  2014-12-03 17:10  Photo\bin\classes\com\king\photo\activity\MainActivity$GridAdapter$2.class

     文件        703  2014-12-03 17:10  Photo\bin\classes\com\king\photo\activity\MainActivity$GridAdapter$ViewHolder.class

     文件       3821  2014-12-03 17:10  Photo\bin\classes\com\king\photo\activity\MainActivity$GridAdapter.class

............此处省略295个文件信息

评论

共有 条评论