View photos in gallery when Long Pressed (#1052)

* Open Native Image Viewer on long pressing a photo inside LoyaltyCardViewActivity

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

Signed-off-by: Manan Jhaveri <incrediblemanan@gmail.com>
This commit is contained in:
Manan Jhaveri
2022-10-01 17:41:15 +05:30
committed by GitHub
parent 523aaef650
commit aa481ea094
4 changed files with 54 additions and 3 deletions

View File

@@ -1,5 +1,6 @@
package protect.card_locker;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.ColorStateList;
@@ -43,6 +44,7 @@ import androidx.appcompat.widget.Toolbar;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.Guideline;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.content.FileProvider;
import androidx.core.graphics.BlendModeColorFilterCompat;
import androidx.core.graphics.BlendModeCompat;
import androidx.core.graphics.ColorUtils;
@@ -53,6 +55,7 @@ import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.bottomappbar.BottomAppBar;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.text.DateFormat;
@@ -150,8 +153,45 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements
@Override
public void onLongPress(MotionEvent e) {
// Also switch on long-press for accessibility
setMainImage(true, true);
openCurrentMainImageInGallery();
}
private void openCurrentMainImageInGallery() {
ImageType wantedImageType = imageTypes.get(mainImageIndex);
File file = null;
switch (wantedImageType) {
case IMAGE_FRONT:
file = Utils.retrieveCardImageAsFile(this, loyaltyCardId, ImageLocationType.front);
break;
case IMAGE_BACK:
file = Utils.retrieveCardImageAsFile(this, loyaltyCardId, ImageLocationType.back);
break;
case BARCODE:
Toast.makeText(this, R.string.barcodeLongPressMessage, Toast.LENGTH_SHORT).show();
return;
default:
// Empty default case for now to keep the spotBugsRelease job happy
}
// Do nothing if there is no file
if (file == null) {
Toast.makeText(this, R.string.failedToRetrieveImageFile, Toast.LENGTH_SHORT).show();
return;
}
try {
Intent intent = new Intent(Intent.ACTION_VIEW)
.setDataAndType(FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID, file), "image/*")
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
}
catch (ActivityNotFoundException e) {
// Display a toast message if an image viewer is not installed on device
Toast.makeText(this, R.string.failedLaunchingPhotoPicker, Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
@Override