私はアプリケーションを開発する必要があります。そこでは、ユーザーがいつshare image
からできる必要があります。ImageView in ViewPager
press on Share Button
私の問題:
私
press on Share Button
がImageView
キャッシュするときImage
、現在ではなく次の。パブリッククラスMainActivityはActivity{を拡張します プライベートViewPagerページャー; プライベートImageViewImgv;
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); pager = (ViewPager) findViewById(R.id.pager); final Integer[] imageUrls={ R.drawable.img1 , R.drawable.img2 , R.drawable.img3 , R.drawable.img4 }; pager.setAdapter(new MyAdapter(imageUrls)); Button share = (Button) findViewById(R.id.share); share.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub Imgv.setDrawingCacheEnabled(true); Bitmap icon = Imgv.getDrawingCache(); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); icon.compress(Bitmap.CompressFormat.JPEG, 100, bytes); File file = new File(Environment.getExternalStorageDirectory() + File.separator + "temporary_file.jpg"); try { file.createNewFile(); FileOutputStream fo = new FileOutputStream(file); fo.write(bytes.toByteArray()); } catch (IOException e) { e.printStackTrace(); } Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); shareIntent.setType("image/jpeg"); Uri uri = Uri.parse("file:///sdcard/temporary_file.jpg"); shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); shareIntent.putExtra(Intent.EXTRA_STREAM,uri); startActivity(shareIntent); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } private class MyAdapter extends PagerAdapter { private LayoutInflater inflater; private Integer[] fimg; public MyAdapter(Integer[] fimg ) { this.fimg=fimg; inflater = getLayoutInflater(); } @Override public Object instantiateItem(View collection, int position ) { final View imageLayout = inflater.inflate(R.layout.imgview, null); Imgv = (ImageView)imageLayout.findViewById(R.id.full_image_view); Imgv.setBackgroundResource(fimg[position]); ((ViewPager) collection).addView(imageLayout ,0); return imageLayout; } @Override public int getItemPosition(Object object) { // TODO Auto-generated method stub return super.getItemPosition(object); } @Override public int getCount() { return fimg.length; } @Override public void destroyItem(View container, int position, Object object) { ((ViewPager) container).removeView((View) object); } @Override public boolean isViewFromObject(View view, Object object) { // TODO Auto-generated method stub return view==((View)object); } @Override public void restoreState(Parcelable arg0, ClassLoader loader) {} @Override public Parcelable saveState() { return null; } @Override public void startUpdate(View container) { } @Override public void finishUpdate(View container) { }
}
}