Advertisement
Guest User

Untitled

a guest
Oct 7th, 2015
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. public class FullScreenActivity extends Activity {
  2.  
  3. PhotoViewAttacher mAttacher;
  4. ShareActionProvider mShareActionProvider;
  5. private static final String TAG_ARQUIVO = "arquivo";
  6. String path;
  7. File file;
  8. Intent shareIntent;
  9. ImageView fullImg;
  10.  
  11. @Override
  12. protected void onCreate(Bundle savedInstanceState) {
  13. super.onCreate(savedInstanceState);
  14. setContentView(R.layout.activity_full_screen);
  15.  
  16. getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
  17. WindowManager.LayoutParams.FLAG_FULLSCREEN);
  18.  
  19. fullImg = (ImageView) findViewById(R.id.fullImage);
  20.  
  21. Intent i = getIntent();
  22. path = i.getStringExtra(TAG_ARQUIVO);
  23.  
  24. Picasso.with(FullScreenActivity.this).load(path).into(fullImg);
  25.  
  26. mAttacher = new PhotoViewAttacher(fullImg);
  27.  
  28. Uri bmpUri = getLocalBitmapUri(fullImg);
  29.  
  30. shareIntent = new Intent();
  31. shareIntent.setAction(Intent.ACTION_SEND);
  32. shareIntent.setType("image/*");
  33. shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
  34.  
  35. }
  36.  
  37. @Override
  38. public boolean onCreateOptionsMenu(Menu menu) {
  39. getMenuInflater().inflate(R.menu.full_screen, menu);
  40.  
  41. MenuItem item = menu.findItem(R.id.menu_item_share);
  42. mShareActionProvider = (ShareActionProvider) item.getActionProvider();
  43. if (mShareActionProvider != null) {
  44. mShareActionProvider.setShareIntent(shareIntent);
  45. }
  46. return true;
  47. }
  48.  
  49. // Returns the URI path to the Bitmap displayed in specified ImageView
  50. public Uri getLocalBitmapUri(ImageView imageView) {
  51. // Extract Bitmap from ImageView drawable
  52. Drawable drawable = imageView.getDrawable();
  53. Bitmap bmp = null;
  54. if (drawable instanceof BitmapDrawable){
  55. bmp = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
  56. } else {
  57. return null;
  58. }
  59. // Store image to default external storage directory
  60. Uri bmpUri = null;
  61. try {
  62. File file = new File(Environment.getExternalStoragePublicDirectory(
  63. Environment.DIRECTORY_DOWNLOADS), "share_image_" + System.currentTimeMillis() + ".png");
  64. file.getParentFile().mkdirs();
  65. FileOutputStream out = new FileOutputStream(file);
  66. bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
  67. out.close();
  68. bmpUri = Uri.fromFile(file);
  69. } catch (IOException e) {
  70. e.printStackTrace();
  71. }
  72. return bmpUri;
  73. }
  74.  
  75. @Override
  76. public boolean onOptionsItemSelected(MenuItem item) {
  77. int id = item.getItemId();
  78. if (id == R.id.action_settings) {
  79. return true;
  80. }
  81. return super.onOptionsItemSelected(item);
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement