mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-22 04:28:00 +01:00
implement the sharing functionality
This commit is contained in:
parent
95ab204fc0
commit
c5224c12e5
2 changed files with 19 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
||||||
package gallery.simplemobiletools.com.activities;
|
package gallery.simplemobiletools.com.activities;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -24,6 +25,8 @@ public class ViewPagerActivity extends AppCompatActivity {
|
||||||
private int pos;
|
private int pos;
|
||||||
private boolean isFullScreen;
|
private boolean isFullScreen;
|
||||||
private ActionBar actionbar;
|
private ActionBar actionbar;
|
||||||
|
private List<String> photos;
|
||||||
|
private MyViewPager pager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -35,9 +38,10 @@ public class ViewPagerActivity extends AppCompatActivity {
|
||||||
isFullScreen = true;
|
isFullScreen = true;
|
||||||
hideSystemUI();
|
hideSystemUI();
|
||||||
|
|
||||||
final MyViewPager pager = (MyViewPager) findViewById(R.id.view_pager);
|
|
||||||
final MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager());
|
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.setAdapter(adapter);
|
||||||
pager.setCurrentItem(pos);
|
pager.setCurrentItem(pos);
|
||||||
|
|
||||||
|
@ -61,12 +65,24 @@ public class ViewPagerActivity extends AppCompatActivity {
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.menu_share:
|
case R.id.menu_share:
|
||||||
|
shareImage();
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return super.onOptionsItemSelected(item);
|
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<String> getPhotos() {
|
private List<String> getPhotos() {
|
||||||
final List<String> photos = new ArrayList<>();
|
final List<String> photos = new ArrayList<>();
|
||||||
final String path = getIntent().getStringExtra(Constants.PHOTO);
|
final String path = getIntent().getStringExtra(Constants.PHOTO);
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">Simple Gallery</string>
|
<string name="app_name">Simple Gallery</string>
|
||||||
|
<string name="share_via">Share via</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue