Android实现图片帮助跳转以及选择重拍Sqlite本地保存

publicclassChoosePhotosActivity extends BaseActivity {

GridViewgridView;

ImageBucketAdapteradapter;// 自定义的适配器

private ArrayList<String>list;

privateArrayList<Map<String, String>> list1;

private Map<String,String> map;

private Map<String,String> map1;

publicstaticfinal String EXTRA_IMAGE_LIST= "agelist";

publicstatic Bitmap bimap;

privateintc_img[] = { R.drawable.im1, R.drawable.im2, R.drawable.im3,

R.drawable.im4, R.drawable.im5, R.drawable.im6, R.drawable.im7,

R.drawable.im8, R.drawable.im9, R.drawable.im10, R.drawable.im11,

R.drawable.im12, R.drawable.im13 };

private HashMap<String,Integer> map2;

private HashMap<String,String> map3;

private sql_execute sql_execute;

private List<Execute> list_execute;

private ArrayList<String>list_Position;

private String file;

private TextView mTVUpdatePhoto;

private TextView mTvActionBarCenter;

private TextView mIvActionBarRight;

private ImageView mIvActionBarLeft;

private HelpMsgModel hmm;

private String serverType;

private String userCarNum;

private String userCarType;

private String insurer;

private String userPhone;

private String taskId;

private String address;

private String userName;

private String Other;

private ProgressDialog loadingDialog = null;

private String service_text;

privateintserviceId=0;

privatestaticfinalintTAKE_PICTURE = 0;

privatestaticfinalintCHOOSE_PICTURE= 1;

privatestaticintPosition=0;

@Override

protectedvoid onCreate(BundlesavedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.act_image_bucket);

initData();

initDb();

contentData();

clectPhoto();

initView();

map = list1.get(serviceId);

map1 =newHashMap<String,String>();

map2 =newHashMap<String,Integer>();

map3 =newHashMap<String,String>();

for(inti=0;i<map.size();i++){

String aa = getTextTitle(map.get(i+""));

map1.put(i+"",aa);

map2.put(i+"",c_img[Integer.valueOf(map.get(i+""))-1]);

}

loadingDialog = newProgressDialog(ChoosePhotosActivity.this);

loadingDialog.setMessage("正在加载...");

loadingDialog.show();

new MyThread2().start();

}

privatevoid initData() {

hmm = (HelpMsgModel) getIntent().getExtras().get("HMM");

serverType =hmm.getServerType();

userCarNum =hmm.getUserCarNum();

userCarType =hmm.getUserCarType();

insurer =hmm.getInsurer();

userPhone =hmm.getUserPhone();

taskId  =hmm.getTaskId();

address =hmm.getAddress();

userName =hmm.getUserName();

Other =hmm.getOther();

service_text =hmm.getServerType();

}

privatevoid initDb() {

sql_execute =newsql_execute(getApplicationContext());

}

public  String getTextTitle(String str){

int ii =Integer.valueOf(str);

returnlist.get(ii-1);

}

/**

* 初始化view视图

*/

privatevoid initView() {

mTvActionBarCenter=(TextView)this.findViewById(R.id.mTvActionBarCenter);

mTvActionBarCenter.setText("拍摄现场照片");

mIvActionBarRight=(TextView)this.findViewById(R.id.mIvActionBarRight);

mIvActionBarRight.setText("完成");

mIvActionBarRight.setOnClickListener(listener);

mIvActionBarLeft =(ImageView)this.findViewById(R.id.mIvActionBarLeft);

mIvActionBarLeft.setOnClickListener(listener);

gridView = (GridView)findViewById(R.id.gridview);

gridView.setSelector(new ColorDrawable(Color.TRANSPARENT));

}

OnClickListenerlistener=newView.OnClickListener() {

@Override

publicvoid onClick(View v) {

switch (v.getId()) {

case R.id.mIvActionBarRight:

loadingDialog = newProgressDialog(ChoosePhotosActivity.this);

loadingDialog.setMessage("正在加载...");

loadingDialog.show();

new MyThread1().start();

break;

case R.id.mIvActionBarLeft:

AppManager.getAppManager().finishActivity();

break;

default:

break;

}

}

};

privatevoid culcateHasPosition(){

list_Position =newArrayList<String>();

//说明默认的图片的所有的Position已经填满了

if(list_execute.size()>=map1.size()){

for(inti=0;i<list_execute.size();i++){

list_Position.add(i+"");

}

}

for(inti=0;i<list_execute.size();i++){

if(list_execute.get(0).getPhotoPosition()==i+""){

}

}

}

private Handler handler =new MyHandler();

class MyHandler extends Handler{

@Override

publicvoid handleMessage(Messagemsg) {

switch (msg.what) {

case 1:

adapter =newImageBucketAdapter(ChoosePhotosActivity.this, map1, map2,map3,list_execute,handler);

//将处理过的图片显示在界面上,并保存到本地

gridView.setAdapter(adapter);

gridView.setOnItemClickListener(new OnItemClickListener() {

@Override

publicvoidonItemClick(AdapterView<?> parent, View view,

int position, long id) {

//按了+号

if(position==(gridView.getCount()-1)){

//前面的已经输完了

if(list_execute.size()>=position){

Position = (int)position;

// 调用系统的拍照功能

Intentintent2 = newIntent(MediaStore.ACTION_IMAGE_CAPTURE);

FiletempFile = newFile(Environment.getExternalStorageDirectory()

+"/CyyDriver/", getPhotoFileName());

// 指定调用相机拍照后照片的储存路径

intent2.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(tempFile));

startActivityForResult(intent2,2);

}else{

Toast.makeText(getApplicationContext(),"请将上面的图片先拍完", 0).show();

}

}else{

boolean flag =false;

for(int i=0;i<list_execute.size();i++){

if(list_execute.get(i).getPhotoPosition().equals(position+"")){

flag=true;

}}

//如果有此值

if(!flag){

Position = position;

Intentintent1 =newIntent(getApplicationContext(), ActivityCenterHelp.class);

intent1.putExtra("Position",Position);

intent1.putExtra("serviceId",serviceId);

startActivityForResult(intent1,TAKE_PICTURE);

}else{

Position = position;

Intentintent3 =newIntent(getApplicationContext(), ActivityPhotoGraphy.class);

intent3.putExtra("PATH", list_execute.get(Position).getPhotoPath());

intent3.putExtra("POSITION",Position);

startActivityForResult(intent3,TAKE_PICTURE);

}

}

}

});

adapter.notifyDataSetChanged();

if(loadingDialog.isShowing()){

loadingDialog.cancel();

}

break;

case 2:

Position = (int) msg.obj;

Intentintent1 =newIntent(getApplicationContext(), ActivityCenterHelp.class);

intent1.putExtra("Position",Position);

intent1.putExtra("serviceId",serviceId);

startActivityForResult(intent1,TAKE_PICTURE);

break;

case 3:

Position = (int) msg.obj;

// 调用系统的拍照功能

Intentintent2 = newIntent(MediaStore.ACTION_IMAGE_CAPTURE);

FiletempFile = newFile(Environment.getExternalStorageDirectory()

+"/CyyDriver/", getPhotoFileName());

// 指定调用相机拍照后照片的储存路径

intent2.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(tempFile));

startActivityForResult(intent2,2);

break;

case 4:

Toast.makeText(getApplicationContext(),"请将上面的图片先拍完", 0).show();

break;

case 5:

Position = (int) msg.obj;

Intentintent3 =newIntent(getApplicationContext(), ActivityPhotoGraphy.class);

intent3.putExtra("PATH", list_execute.get(Position).getPhotoPath());

intent3.putExtra("POSITION",Position);

startActivityForResult(intent3,TAKE_PICTURE);

break;

case 11:

if(loadingDialog.isShowing()){

loadingDialog.cancel();

}

Toast.makeText(ChoosePhotosActivity.this, "请完成指定需要拍摄的图片", 1).show();

break;

case 12:

if(loadingDialog.isShowing()){

loadingDialog.cancel();

}

AppManager.getAppManager().finishActivity();

break;

default:

break;

}

super.handleMessage(msg);

}

}

//点击完成时对于数据的处理

privateclass MyThread2 extends Thread {

@Override

publicvoid run() {

list_execute = sql_execute.query(taskId, "0");

handler.sendEmptyMessage(1);

super.run();

}

}

//点击完成时对于数据的处理

privateclass MyThread1 extends Thread {

@Override

publicvoid run() {

int a = sql_execute.querycount(taskId, "0");

if(a<map1.size()){

handler.sendEmptyMessage(11);

}else{

sql_execute exe =newsql_execute(getApplicationContext());

TaskMap tp =new TaskMap();

tp.setIsCamera("1");

tp.setStatus("0");

tp.setTaskId(taskId);

exe.insert(tp);

handler.sendEmptyMessage(12);

}

super.run();

}

}

//拍照时处理的后台逻辑

privateclass MyThread extends Thread{

privateintrequestCode;

privateintresultCode;

private Intent data;

public MyThread(int requestCode, int resultCode, Intentdata){

this.requestCode =requestCode;

this.resultCode =resultCode;

this.data =data;

}

@Override

publicvoid run() {

if (resultCode == RESULT_OK) {

Stringpath;

switch (requestCode) {

case 2:

Datedate = newDate(System.currentTimeMillis());

SimpleDateFormatformatter = newSimpleDateFormat("yyyy-MM-dd HH:mm:ss");

String dateString = formatter.format(date);

Executeexe =newExecute();

exe.setPhotoPath(Environment.getExternalStorageDirectory()+"/CyyDriver/"+file);

exe.setTaskId(taskId);

exe.setPhotoPosition(Position+"");

//holder.name.setText((position+1)+"、"+map1.get(position+""));

exe.setPhotoBucketName((Position+1)+"、"+map1.get(Position+""));

exe.setPhotoObjectKey("");

exe.setPhotoSignatual(0);

exe.setPhotoTime(dateString);

exe.setIsUpload(0);

sql_execute.insert(exe);

list_execute =   sql_execute.query(taskId, "0");

map3 = newHashMap<String,String>();

map3.put("POSITION",Position+"");

map3.put("FILE", file);

PhotoModelpm =newPhotoModel();

pm.setPhotoPath(file);

pm.setPosition(Position+"");

handler.sendEmptyMessage(1);

break;

default:

break;

}

}elseif(resultCode ==4){

//将保存在本地的图片取出并缩小后显示在界面上

String tempFile1 = data.getStringExtra("FILE");

Datedate = newDate(System.currentTimeMillis());

SimpleDateFormatformatter = newSimpleDateFormat("yyyy-MM-dd HH:mm:ss");

String dateString = formatter.format(date);

Executeexe =newExecute();

exe.setPhotoPath(Environment.getExternalStorageDirectory()+"/CyyDriver/"+tempFile1);

exe.setTaskId(taskId);

exe.setPhotoPosition((Position)+"");

exe.setPhotoBucketName((Position+1)+"、"+map1.get(Position+""));

exe.setPhotoObjectKey("");

exe.setPhotoSignatual(0);

exe.setPhotoTime(dateString);

exe.setIsUpload(0);

sql_execute.insert(exe);

list_execute =   sql_execute.query(taskId, "0");

map3 = newHashMap<String,String>();

map3.put("POSITION",Position+"");

map3.put("FILE", tempFile1);

PhotoModelpm =newPhotoModel();

pm.setPhotoPath(tempFile1);

pm.setPosition(Position+"");

handler.sendEmptyMessage(1);

}

}

}

@Override

protectedvoid onActivityResult(int requestCode, int resultCode, Intentdata) {

super.onActivityResult(requestCode,resultCode, data);

loadingDialog = new ProgressDialog(ChoosePhotosActivity.this);

loadingDialog.setMessage("正在加载...");

loadingDialog.show();

new MyThread(requestCode, resultCode,data).start();

}

FiletempFile= newFile(Environment.getExternalStorageDirectory()

+"/CyyDriver/", getPhotoFileName());

// 使用系统当前日期加以调整作为照片的名称

private StringgetPhotoFileName() {

Datedate = newDate(System.currentTimeMillis());

SimpleDateFormatdateFormat = newSimpleDateFormat(

"‘IMG‘_yyyyMMdd_HHmmss");

file=dateFormat.format(date) + ".jpg";

return dateFormat.format(date)+ ".jpg";

}

@Override

protectedvoid onResume() {

if(loadingDialog.isShowing()){

loadingDialog.cancel();

}

super.onResume();

}

}

图片适配器:

publicclassImageBucketAdapter extends BaseAdapter {

final String TAG =getClass().getSimpleName();

//最上面显示的文字

Map<String,String> map1;

//中间显示的图片

Map<String,Integer> map2;

//用来刷新拍照的照片

Map<String,String> map3;

Activityact;

List<Execute>list;

BitmapCachecache;

private File tempFile;

private Integer itemsPosition;

privateintsize =0;

private Handler handler;

public ImageBucketAdapter(Activityact,Map<String, String> map1,Map<String, Integer>map2,Map<String, String> map3,List<Execute> list,Handler handler) {

this.act = act;

cache = new BitmapCache();

this.map1 =map1;

this.map2 =map2;

this.map3 =map3;

this.list =list;

this.handler =handler;

}

@Override

publicint getCount() {

if(list.size()>=map1.size()){

size=list.size()+1;

}else{

size =map1.size()+1;

}

returnsize;

}

@Override

public Object getItem(int position) {

return position;

}

@Override

publiclong getItemId(int position) {

return position;

}

class Holder {

private ImageView iv;

private TextView name;

private TextView mTVTimePhotoNow,mTVNoteFouse,mTVPhotoNow;

}

@Override

public View getView(finalint position, View view,ViewGroup arg2) {

// TODO Auto-generated method stub

Holderholder;

if (view == null) {

holder= newHolder();

view= View.inflate(act, R.layout.testitem_image_bucket, null);

holder.iv = (ImageView)view.findViewById(R.id.image);

holder.name = (TextView)view.findViewById(R.id.name);

holder.mTVTimePhotoNow=(TextView)view.findViewById(R.id.mTVTimePhotoNow);

holder.mTVNoteFouse=(TextView)view.findViewById(R.id.mTVNoteFouse);

holder.mTVPhotoNow=(TextView)view.findViewById(R.id.mTVPhotoNow);

view.setTag(holder);

}else{

holder= (Holder) view.getTag();

}

if(position<map1.size()){

holder.name.setText((position+1)+"、"+map1.get(position+""));

holder.iv.setImageResource(map2.get(position+""));

holder.mTVPhotoNow.setVisibility(View.VISIBLE);

holder.mTVNoteFouse.setVisibility(View.GONE);

holder.mTVTimePhotoNow.setVisibility(View.GONE);

}else{

holder.name.setText("");

holder.mTVPhotoNow.setVisibility(View.GONE);

holder.mTVNoteFouse.setVisibility(View.VISIBLE);

holder.mTVTimePhotoNow.setVisibility(View.VISIBLE);

}

BitmapDrawablebitmapDrawable = (BitmapDrawable) holder.iv.getDrawable();

//如果图片还未回收,先强制回收该图片

if(bitmapDrawable.getBitmap().isRecycled())

{

bitmapDrawable.getBitmap().recycle();

}

for(int i=0;i<list.size();i++){

if(list.get(i).getPhotoPosition().equals(position+"")){

tempFile =   new File(list.get(i).getPhotoPath());

if(tempFile.exists()){

Bitmapbitmap = BitmapFactory.decodeFile(tempFile.getPath());

BitmapnewBitmap = ImageTools.zoomBitmap(bitmap, 156,128);

//由于Bitmap内存占用较大,这里需要回收内存,否则会报out of memory异常

bitmap.recycle();

holder.iv.setImageBitmap(newBitmap);

holder.mTVPhotoNow.setVisibility(View.GONE);

holder.mTVNoteFouse.setVisibility(View.VISIBLE);

holder.mTVTimePhotoNow.setVisibility(View.VISIBLE);

holder.mTVTimePhotoNow.setText(list.get(position).getPhotoTime());

}

}

}

//当position显示到最后一个时显示一个+号

if(position==(size-1)){

holder.iv.setImageResource(R.drawable.addpic_nor);

holder.mTVPhotoNow.setVisibility(View.GONE);

holder.mTVNoteFouse.setVisibility(View.GONE);

holder.mTVTimePhotoNow.setVisibility(View.GONE);

//holder.iv.setClickable(true);

}

}

对于图片的Db操作略,

时间: 2024-11-03 10:00:05

Android实现图片帮助跳转以及选择重拍Sqlite本地保存的相关文章

Android 跳转系统选择本地视频的功能

今天在项目开发的过程中产品要求添加选择本地视频的功能,于是就翻阅和查找各种资料,进行功能的开发,但是在开发过程中发现,各种不同的品牌的手机跳转至系统选择本地视频的功能结果不太一样,所以我就对一些主流的品牌进行了测试,现做如下总结: 1.选择本地视频的功能 Button click event: Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Video.Media.EXTERNAL_CONTEN

高仿优酷Android客户端图片左右滑动(自动切换)

本例是用ViewPager去做的实现,支持自动滑动和手动滑动,不仅优酷网,实际上有很多商城和门户网站都有类似的实现: 具体思路: 1. 工程中需要添加android-support-v4.jar,才能使用ViewPager控件. 2. 图片的自动切换: 可使用Timer或者ScheduledExecutorService,这个有多重方式可以实现. 同时要切换底部的dots(园点) 3.Handler+Message机制更新UI,这个相信大家都很熟练,不再描述 4. 实现的一些细节:注意本例中的优

Android BitmapFactory图片压缩处理(大位图二次采样压缩处理)

Android实际开发中,在加载大量图片的时候,比如ViewPager.GridView.ListView中,加载了大量的比较大图片就容易出现OOM(内存溢出)的异常,这是因为一个应用的最大内存使用只有16M,超过了这个值,就会出现OOM.所以我们实际开发中,要想避免OOM出现就要对相应的图片进行压缩处理. 本文即使用了BitmapFactory和BitmapFactory.Option这两个类,对图片进行相应的尺寸压缩处理.经测试,成功解决了未压缩图片之前出现的OOM异常. 实现效果图: 本D

Android 相册图片选取+自定义裁剪方式(非系统裁剪)

不多说,直接上代码(裁剪的代码摘自网络.)(项目可运行) 主要是系统自身的剪切方式在有些机型上会程序崩溃的问题. 1 package com.jichun.activity; 2 3 import java.io.FileNotFoundException; 4 5 import com.jichun.view.CropCanvas; 6 7 import android.app.Activity; 8 import android.content.ContentResolver; 9 impo

Android开发之Intent跳转到系统应用中的拨号界面、联系人界面、短信界面

现在开发中的功能需要直接跳转到拨号.联系人.短信界面等等,查找了很多资料,自己整理了一下.1.跳转到拨号界面,代码如下: 1)直接拨打 Intent intentPhone = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber)); startActivity(intentPhone); 2)跳转到拨号界面 Intent intent = newIntent(Intent.ACTION_DIAL,Uri.pars

Android浏览图片,点击放大至全屏效果

最近做一个项目类似于QQ空间,做到照片浏览的功能,对于QQ空间中点击图片放大至全屏,感觉效果很赞,于是也做了个类似的效果.如下. 我不知道QQ那个是怎么做的,我的思路如下: 首先,从图片缩略界面跳转到图片详情页面,应该是从一个Activity跳转到另外一个Activity,应该图片详情页面也有很多操作,用View或者Dialog不是很好.所以现在难点就是,如何使得前一个界面的ImageView在另外一个界面做缩放切割动画. 一般缩略界面的ImageView的是如上图所示的正方形的,并且是CENT

4解决图片乱跳的问题,preferenceactivity.

设置界面 listview中图片异步加载时,图片乱跳错位的现象原因:这是由于在代码中复用了convertview,同时也复用了convertview中的bitmap,解决:①不用convertview缓存,但程序的效率打折扣②可以用convertview缓存,在xml中不配置ImageView,在代码中手动添加③自定义一个ImageView,同时具有异步加载的功能 <?xml version="1.0" encoding="UTF-8"?> <Li

Android中图片的三级缓存策略

一.简介 现在的Android应用程序中,不可避免的都会使用到图片,如果每次加载图片的时候都要从网络重新拉取,这样不但很耗费用户的流量,而且图片加载的也会很慢,用户体验很不好.所以一个应用的图片缓存策略是很重要的.通常情况下,Android应用程序中图片的缓存策略采用"内存-本地-网络"三级缓存策略,首先应用程序访问网络拉取图片,分别将加载的图片保存在本地SD卡中和内存中,当程序再一次需要加载图片的时候,先判断内存中是否有缓存,有则直接从内存中拉取,否则查看本地SD卡中是否有缓存,SD

Android ImageCache图片缓存,使用简单,支持预取,支持多种缓存算法,支持不同网络类型,扩展性强

本文主要介绍一个支持图片自动预取.支持多种缓存算法的图片缓存的使用及功能.图片较大需要SD卡保存情况推荐使用ImageSDCardCache. 与Android LruCache相比主要特性:(1).  使用简单   (2). 轻松获取及预取新图片  (3).  可选择多种缓存算法(FIFO.LIFO.LRU.MRU.LFU.MFU等13种)或自定义缓存算法   (4).  省流量性能佳(有且仅有一个线程获取图片)   (5).  支持不同类型网络处理  (6).  可根据系统配置初始化缓存