From d6a8683941694a13f0b6d9eb536382e85030f1cf Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 14 Jun 2016 11:24:57 +0200 Subject: [PATCH] allow opening other photos with the Gallery --- app/src/main/AndroidManifest.xml | 14 +++ .../com/simplemobiletools/gallery/Utils.java | 24 +++++ .../gallery/activities/PhotoActivity.java | 90 +++++++++++++++++++ .../gallery/activities/ViewPagerActivity.java | 17 +--- app/src/main/res/layout/photo_layout.xml | 7 ++ app/src/main/res/menu/photo_video_menu.xml | 9 ++ 6 files changed, 146 insertions(+), 15 deletions(-) create mode 100644 app/src/main/java/com/simplemobiletools/gallery/activities/PhotoActivity.java create mode 100644 app/src/main/res/layout/photo_layout.xml create mode 100644 app/src/main/res/menu/photo_video_menu.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 832968e31..8510884d0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -36,5 +36,19 @@ android:name=".activities.LicenseActivity" android:label="@string/third_party_licences" android:screenOrientation="portrait"/> + + + + + + + + + + + + diff --git a/app/src/main/java/com/simplemobiletools/gallery/Utils.java b/app/src/main/java/com/simplemobiletools/gallery/Utils.java index f76a6e8a4..ddf73bb3e 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/Utils.java +++ b/app/src/main/java/com/simplemobiletools/gallery/Utils.java @@ -5,6 +5,9 @@ import android.content.Context; import android.content.pm.PackageManager; import android.content.res.Resources; import android.support.v4.content.ContextCompat; +import android.support.v7.app.ActionBar; +import android.view.View; +import android.view.Window; import android.widget.Toast; public class Utils { @@ -28,4 +31,25 @@ public class Utils { public static boolean hasStoragePermission(Context cxt) { return ContextCompat.checkSelfPermission(cxt, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED; } + + public static void showSystemUI(ActionBar actionbar, Window window) { + if (actionbar != null) + actionbar.show(); + + window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | + View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | + View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); + } + + public static void hideSystemUI(ActionBar actionbar, Window window) { + if (actionbar != null) + actionbar.hide(); + + window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | + View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | + View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | + View.SYSTEM_UI_FLAG_LOW_PROFILE | + View.SYSTEM_UI_FLAG_FULLSCREEN | + View.SYSTEM_UI_FLAG_IMMERSIVE); + } } diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/PhotoActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/PhotoActivity.java new file mode 100644 index 000000000..3f5d3a849 --- /dev/null +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/PhotoActivity.java @@ -0,0 +1,90 @@ +package com.simplemobiletools.gallery.activities; + +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; +import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; +import android.view.Menu; +import android.view.MenuItem; + +import com.simplemobiletools.gallery.Constants; +import com.simplemobiletools.gallery.R; +import com.simplemobiletools.gallery.Utils; +import com.simplemobiletools.gallery.fragments.PhotoFragment; +import com.simplemobiletools.gallery.fragments.ViewPagerFragment; +import com.simplemobiletools.gallery.models.Medium; + +public class PhotoActivity extends AppCompatActivity implements ViewPagerFragment.FragmentClickListener { + private ActionBar actionbar; + private boolean isFullScreen; + private Uri uri; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.photo_layout); + + uri = getIntent().getData(); + if (uri == null) + return; + + actionbar = getSupportActionBar(); + isFullScreen = true; + hideSystemUI(); + + final Bundle bundle = new Bundle(); + final Medium medium = new Medium(uri.toString(), false); + bundle.putSerializable(Constants.MEDIUM, medium); + final ViewPagerFragment fragment = new PhotoFragment(); + fragment.setListener(this); + fragment.setArguments(bundle); + getSupportFragmentManager().beginTransaction().replace(R.id.photo_holder, fragment).commit(); + hideSystemUI(); + setTitle(Utils.getFilename(uri.toString())); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.photo_video_menu, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.menu_share: + shareMedium(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + private void shareMedium() { + final String shareTitle = getResources().getString(R.string.share_via); + final Intent sendIntent = new Intent(); + sendIntent.setAction(Intent.ACTION_SEND); + sendIntent.putExtra(Intent.EXTRA_STREAM, uri); + sendIntent.setType("image/*"); + startActivity(Intent.createChooser(sendIntent, shareTitle)); + } + + @Override + public void fragmentClicked() { + isFullScreen = !isFullScreen; + if (isFullScreen) { + hideSystemUI(); + } else { + showSystemUI(); + } + } + + private void hideSystemUI() { + Utils.hideSystemUI(actionbar, getWindow()); + } + + private void showSystemUI() { + Utils.showSystemUI(actionbar, getWindow()); + } +} diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java index 8562b21af..41bdfc6b3 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java @@ -315,24 +315,11 @@ public class ViewPagerActivity extends AppCompatActivity } private void hideSystemUI() { - if (actionbar != null) - actionbar.hide(); - - getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | - View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | - View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | - View.SYSTEM_UI_FLAG_LOW_PROFILE | - View.SYSTEM_UI_FLAG_FULLSCREEN | - View.SYSTEM_UI_FLAG_IMMERSIVE); + Utils.hideSystemUI(actionbar, getWindow()); } private void showSystemUI() { - if (actionbar != null) - actionbar.show(); - - getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | - View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | - View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); + Utils.showSystemUI(actionbar, getWindow()); } private void updateActionbarTitle() { diff --git a/app/src/main/res/layout/photo_layout.xml b/app/src/main/res/layout/photo_layout.xml new file mode 100644 index 000000000..8ca99fd91 --- /dev/null +++ b/app/src/main/res/layout/photo_layout.xml @@ -0,0 +1,7 @@ + + diff --git a/app/src/main/res/menu/photo_video_menu.xml b/app/src/main/res/menu/photo_video_menu.xml new file mode 100644 index 000000000..65e9d5e91 --- /dev/null +++ b/app/src/main/res/menu/photo_video_menu.xml @@ -0,0 +1,9 @@ + + + +