Skip to content
This repository was archived by the owner on May 19, 2023. It is now read-only.

add chooser intent - to show both media and camera when clicking on b… #26

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions app/src/main/java/com/jasonette/seed/Action/JasonMediaAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.os.Parcelable;
import android.provider.MediaStore;
import android.util.Base64;
import android.util.Log;
Expand All @@ -23,6 +25,7 @@
import com.commonsware.cwac.cam2.VideoRecorderActivity;
import com.commonsware.cwac.cam2.ZoomStyle;
import com.jasonette.seed.Helper.JasonHelper;
import com.jasonette.seed.Launcher.Launcher;

import org.json.JSONObject;

Expand Down Expand Up @@ -94,6 +97,80 @@ public void finishplay(Intent intent, final JSONObject options) {
*
**********************************/

private File createImageFile() throws IOException {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "1mind_" + timeStamp + ".jpg";
File photo = new File(Environment.getExternalStorageDirectory(), imageFileName);
return photo;
}

private File mTempImage;

public Intent makePhotoIntent(String title, Context context){

//Build galleryIntent
Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
galleryIntent.setType("image/*");

//Create chooser
Intent chooser = Intent.createChooser(galleryIntent,title);

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
mTempImage = null;
try {
mTempImage = createImageFile();
} catch (IOException e) {
e.printStackTrace();
}

if (mTempImage != null){
cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(mTempImage));
Intent[] extraIntents = {cameraIntent};
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
}

return chooser;
}


public void pickerAndCamera(final JSONObject action, JSONObject data, final JSONObject event, final Context context) {

// Image picker intent
try {
String type = "image";
if(action.has("options")){
if(action.getJSONObject("options").has("type")){
type = action.getJSONObject("options").getString("type");
}
}

Intent intent;
if(type.equalsIgnoreCase("video")){
// video
intent = new Intent(Intent.ACTION_PICK, MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
} else {
// image
intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
}

intent = makePhotoIntent("pickerAndCamera", context);

// dispatchIntent method
// 1. triggers an external Intent
// 2. attaches a callback with all the payload so that we can pick it up where we left off when the intent returns

// the callback needs to specify the class name and the method name we wish to trigger after the intent returns
JSONObject callback = new JSONObject();
callback.put("class", "JasonMediaAction");
callback.put("method", "process");

JasonHelper.dispatchIntent(action, data, event, context, intent, callback);
} catch (SecurityException e){
JasonHelper.permission_exception("$media.picker", context);
} catch (Exception e) {
Log.d("Warning", e.getStackTrace()[0].getMethodName() + " : " + e.toString());
}
}

public void picker(final JSONObject action, JSONObject data, final JSONObject event, final Context context) {

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
classpath 'com.android.tools.build:gradle:7.0.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip