diff --git a/app/src/main/java/gallery/simplemobiletools/com/activities/ViewPagerActivity.java b/app/src/main/java/gallery/simplemobiletools/com/activities/ViewPagerActivity.java index a6cc699c2..7a7bbdaed 100644 --- a/app/src/main/java/gallery/simplemobiletools/com/activities/ViewPagerActivity.java +++ b/app/src/main/java/gallery/simplemobiletools/com/activities/ViewPagerActivity.java @@ -1,5 +1,6 @@ package gallery.simplemobiletools.com.activities; +import android.content.Intent; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; @@ -24,6 +25,8 @@ public class ViewPagerActivity extends AppCompatActivity { private int pos; private boolean isFullScreen; private ActionBar actionbar; + private List photos; + private MyViewPager pager; @Override protected void onCreate(Bundle savedInstanceState) { @@ -35,9 +38,10 @@ public class ViewPagerActivity extends AppCompatActivity { isFullScreen = true; hideSystemUI(); - final MyViewPager pager = (MyViewPager) findViewById(R.id.view_pager); final MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager()); - adapter.setPaths(getPhotos()); + pager = (MyViewPager) findViewById(R.id.view_pager); + photos = getPhotos(); + adapter.setPaths(photos); pager.setAdapter(adapter); pager.setCurrentItem(pos); @@ -61,12 +65,24 @@ public class ViewPagerActivity extends AppCompatActivity { public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_share: + shareImage(); return true; default: return super.onOptionsItemSelected(item); } } + private void shareImage() { + final String shareTitle = getResources().getString(R.string.share_via); + final Intent sendIntent = new Intent(); + final File file = new File(photos.get(pager.getCurrentItem())); + final Uri uri = Uri.fromFile(file); + sendIntent.setAction(Intent.ACTION_SEND); + sendIntent.putExtra(Intent.EXTRA_STREAM, uri); + sendIntent.setType("image/*"); + startActivity(Intent.createChooser(sendIntent, shareTitle)); + } + private List getPhotos() { final List photos = new ArrayList<>(); final String path = getIntent().getStringExtra(Constants.PHOTO); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c19877aea..834e2a1e4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,4 @@ Simple Gallery + Share via