基本信息
源码名称:拍照/选择图片,并显示,防QQ空间动态发布图片
源码大小:3.55M
文件格式:.zip
开发语言:Java
更新时间:2015-05-06
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
拍照/从相册中选中图片,并显示缩略图。

public class PublishedActivity extends Activity
{

private GridView noScrollgridview;
private GridAdapter adapter;
private TextView activity_selectimg_send;

protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_selectimg);
Init();
}

public void Init()
{
noScrollgridview = (GridView) findViewById(R.id.noScrollgridview);
noScrollgridview.setSelector(new ColorDrawable(Color.TRANSPARENT));
adapter = new GridAdapter(this);
adapter.update1();
noScrollgridview.setAdapter(adapter);
noScrollgridview.setOnItemClickListener(new OnItemClickListener()
{

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3)
{
if (arg2 == Bimp.bmp.size())
{
new PopupWindows(PublishedActivity.this, noScrollgridview);
} else
{
Intent intent = new Intent(PublishedActivity.this,
PhotoActivity.class);
intent.putExtra("ID", arg2);
startActivity(intent);
}
}
});

}

@SuppressLint("HandlerLeak")
public class GridAdapter extends BaseAdapter
{
private LayoutInflater inflater; // 视图容器
private int selectedPosition = -1;// 选中的位置
private boolean shape;

public boolean isShape()
{
return shape;
}

public void setShape(boolean shape)
{
this.shape = shape;
}

public GridAdapter(Context context)
{
inflater = LayoutInflater.from(context);
}

public void update1()
{
loading1();
}

public int getCount()
{
return (Bimp.bmp.size() 1);
}

public Object getItem(int arg0)
{

return null;
}

public long getItemId(int arg0)
{

return 0;
}

public void setSelectedPosition(int position)
{
selectedPosition = position;
}

public int getSelectedPosition()
{
return selectedPosition;
}

/**
* ListView Item设置
*/
public View getView(int position, View convertView, ViewGroup parent)
{
//final int coord = position;
ViewHolder holder = null;

System.out.println("测试下表=" position);
if (convertView == null)
{

convertView = inflater.inflate(R.layout.item_published_grida,
parent, false);
holder = new ViewHolder();
holder.image = (ImageView) convertView
.findViewById(R.id.item_grida_image);
convertView.setTag(holder);
} else
{
holder = (ViewHolder) convertView.getTag();
}

holder.image.setVisibility(View.VISIBLE);

if (position == Bimp.bmp.size())
{
holder.image.setImageBitmap(BitmapFactory.decodeResource(
getResources(), R.drawable.icon_addpic_unfocused));

} else
{
holder.image.setImageBitmap(Bimp.bmp.get(position));
}

if (position == 9)
{
holder.image.setVisibility(View.GONE);
}

return convertView;
}

public class ViewHolder
{
public ImageView image;
}

Handler handler = new Handler()
{
public void handleMessage(Message msg)
{
switch (msg.what)
{
case 1:
adapter.notifyDataSetChanged();
break;
}
super.handleMessage(msg);
}
};

public void loading1()
{
new Thread(new Runnable()
{
public void run()
{
while (true)
{
if (Bimp.max == Bimp.drr.size())
{
Message message = new Message();
message.what = 1;
handler.sendMessage(message);
break;
} else
{
try
{
String path = Bimp.drr.get(Bimp.max);
System.out.println(path);
Bitmap bm = Bimp.revitionImageSize(path);
Bimp.bmp.add(bm);
String newStr = path.substring(
path.lastIndexOf("/") 1,
path.lastIndexOf("."));
FileUtils.saveBitmap(bm, "" newStr);
Bimp.max = 1;
Message message = new Message();
message.what = 1;
handler.sendMessage(message);
} catch (IOException e)
{

e.printStackTrace();
}
}
}
}
}).start();
}
}

public String getString(String s)
{
String path = null;
if (s == null)
return "";
for (int i = s.length() - 1; i > 0; i )
{
s.charAt(i);
}
return path;
}

protected void onRestart()
{
adapter.update1();
super.onRestart();
}

public class PopupWindows extends PopupWindow
{

public PopupWindows(Context mContext, View parent)
{

super(mContext);

View view = View
.inflate(mContext, R.layout.item_popupwindows, null);
view.startAnimation(AnimationUtils.loadAnimation(mContext,
R.anim.fade_ins));
LinearLayout ll_popup = (LinearLayout) view
.findViewById(R.id.ll_popup);
ll_popup.startAnimation(AnimationUtils.loadAnimation(mContext,
R.anim.push_bottom_in_2));

setWidth(LayoutParams.FILL_PARENT);
setHeight(LayoutParams.FILL_PARENT);
setBackgroundDrawable(new BitmapDrawable());
setFocusable(true);
setOutsideTouchable(true);
setContentView(view);
showAtLocation(parent, Gravity.BOTTOM, 0, 0);
update();

Button bt1 = (Button) view
.findViewById(R.id.item_popupwindows_camera);
Button bt2 = (Button) view
.findViewById(R.id.item_popupwindows_Photo);
Button bt3 = (Button) view
.findViewById(R.id.item_popupwindows_cancel);
bt1.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
photo();
dismiss();
}
});
bt2.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent(PublishedActivity.this,
TestPicActivity.class);
startActivity(intent);
// xitongxiangce
dismiss();
}
});
bt3.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
dismiss();
}
});

}
}

private static final int TAKE_PICTURE = 0x000000;
private String path = "";

public void onConfigurationChanged(Configuration config) 

   super.onConfigurationChanged(config); 


public void photo()
{
String status=Environment.getExternalStorageState(); 
if(status.equals(Environment.MEDIA_MOUNTED)) 
{
File dir=new File(Environment.getExternalStorageDirectory() "/myimage/"); 
if(!dir.exists())dir.mkdirs(); 

Intent openCameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(dir, String.valueOf(System.currentTimeMillis())
".jpg");
path = file.getPath();
Uri imageUri = Uri.fromFile(file);
openCameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
openCameraIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
startActivityForResult(openCameraIntent, TAKE_PICTURE);
}
else{ 
Toast.makeText(PublishedActivity.this, "没有储存卡",Toast.LENGTH_LONG).show(); 

}

protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);  
switch (requestCode)
{
case TAKE_PICTURE:
if (Bimp.drr.size() < 9 && resultCode == -1)
{
Bimp.drr.add(path);
}
break;
}
}

}