Skip to content

Commit

Permalink
Feature/native-android-camera-component (#210)
Browse files Browse the repository at this point in the history
* upgraded to RN 0.43.4 with broken dependencies

* Fixed style issues cause by native-base in some components (will be fully fixed in future commit)

* deleted ‘home’ page (was not used anywhere)

* Removed some native-base redundant form components

* handled some parts of sign-in and splash screen to be “native-base less”

* Made BadNavigationScreen into a Functional Component

* Fixed native-base issues in activation page

* fixed native-base issues in signup page

* Replaced all the native-base view and text with react-native view and text

* Animations look AWESOME

* Refactored most of the flow of uploadLook

* tiny refactor for brands autocomplete

* Fixed native-base style issues in uploadLook (all stages)

* fixed native-base issues with profilescreen & settings screen

* Fixed broken react-native-video

* fixed disappearing list views

* Updated package son for RN0.43

* Removed duplicate permissions from AndroidManifest

* fixed ‘next’ button style in uploadLookScreen

* Added missing binding in addItemScreen constructor

* fixed clear button

* Fixed gif issue (facebook/react-native#13345)

* Aligned Gllu.Button text

* aligned report and back button in profile screen

* fixed LikeView alignment

* Fixed incorrect styling of LikeView

* fix look screen keys bug

* Removed weird gap in bottom of comments view

* ios changes for rn0.40

* fixed empty view style issues in Notifications/Followers & Following screens

* App loads react modules correctly. (Still have to deal with Flurry bug)

* Fixed iOS flurry bug (resolved react-native-config version straight form sources instead of fork)

* fixed missing config files in build.gradle

* Feature/native android camera component (#208)

* - Integrate camera native component

*  -Change default record circle button.
- Force default front camera.
- Crop image after stillshot.
- Set crop aspect ratio to 9:16

* - Change cropper action bar background.
- Remove unnecessary buttons.
- Add flip horizontal button.
- Remove image preview screen.
- Fix taking photos on some devices.

* - Fix video stretching.
- Video preview now showed full screen

* Remove from gitignore

* - Remove rotate button.
- Fix landscape camera crash (disable landscape)

* - Add trimer library

* Trim Video settings

* Integrate video trimming in entire flow
  • Loading branch information
shirbr510 authored May 14, 2017
1 parent 7178b7a commit 8538b0b
Show file tree
Hide file tree
Showing 41 changed files with 2,785 additions and 14 deletions.
8 changes: 8 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false

android {

dexOptions {
jumboMode = true
}

compileSdkVersion 25
buildToolsVersion '25.0.2'
defaultConfig {
Expand Down Expand Up @@ -127,6 +132,7 @@ android {
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
debuggable false
shrinkResources true
applicationIdSuffix 'release'
}
staging {
Expand Down Expand Up @@ -156,7 +162,9 @@ android {
}

dependencies {

compile project(':libs:cropper')
compile project(':libs:video-trimmer')
compile project(':react-native-image-crop-picker')
compile 'com.facebook.fresco:animated-base-support:0.14.1'
compile 'com.facebook.fresco:animated-gif:0.14.1'
Expand Down
4 changes: 4 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
<activity
android:name="com.theartofdev.edmodo.cropper2.CropImageActivity"
android:screenOrientation="portrait"
android:theme="@style/AppTheme2" />
<activity
android:name="com.gllu.Activities.TrimmerActivity"
android:screenOrientation="portrait" android:theme="@style/AppTheme2"/> <!-- optional (needed if default theme has no action bar) -->
android:theme="@style/AppTheme2" /> <!-- optional (needed if default theme has no action bar) -->


Expand Down
117 changes: 117 additions & 0 deletions android/app/src/main/java/com/gllu/Activities/TrimmerActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package com.gllu.Activities;

import android.app.ProgressDialog;
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 android.widget.Toast;

import com.gllu.R;

import life.knowledge4.videotrimmer.K4LVideoTrimmer;
import life.knowledge4.videotrimmer.interfaces.OnK4LVideoListener;
import life.knowledge4.videotrimmer.interfaces.OnTrimVideoListener;

public class TrimmerActivity extends AppCompatActivity implements OnTrimVideoListener, OnK4LVideoListener {

public final static String EXTRA_VIDEO_PATH = "EXTRA_VIDEO_PATH";

private K4LVideoTrimmer mVideoTrimmer;
private ProgressDialog mProgressDialog;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_trimmer);

Intent extraIntent = getIntent();
String path = "";

if (extraIntent != null) {
path = extraIntent.getStringExtra(this.EXTRA_VIDEO_PATH);
}

//setting progressbar
mProgressDialog = new ProgressDialog(this);
mProgressDialog.setCancelable(false);
mProgressDialog.setMessage("Trimming your video...");

mVideoTrimmer = ((K4LVideoTrimmer) findViewById(R.id.timeLine));
if (mVideoTrimmer != null) {
mVideoTrimmer.setMaxDuration(20);
mVideoTrimmer.setOnTrimVideoListener(this);
mVideoTrimmer.setOnK4LVideoListener(this);
mVideoTrimmer.setDestinationPath("/storage/emulated/0/DCIM/CameraCustom/");
mVideoTrimmer.setVideoURI(Uri.parse(path));
mVideoTrimmer.setVideoInformationVisibility(false);
}

ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setTitle("Trim Video");
actionBar.setDisplayHomeAsUpEnabled(true);
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.trim_video_menu, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.trim_video){
mVideoTrimmer.onSaveClicked();
}
if (item.getItemId() == android.R.id.home) {
setResult(RESULT_CANCELED);
finish();
return true;
}

return true;
}

@Override
public void onTrimStarted() {
mProgressDialog.show();
}

@Override
public void getResult(final Uri uri) {
mProgressDialog.cancel();
Intent intent = new Intent();
intent.putExtra(EXTRA_VIDEO_PATH, uri);
setResult(RESULT_OK, intent);
finish();
}

@Override
public void cancelAction() {
mProgressDialog.cancel();
mVideoTrimmer.destroy();
finish();
}

@Override
public void onError(final String message) {
mProgressDialog.cancel();

runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(TrimmerActivity.this, message, Toast.LENGTH_SHORT).show();
}
});
}

@Override
public void onVideoPrepared() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public void onCreate(Bundle savedInstanceState) {
new MaterialCamera(this)
.defaultToFrontFacing(true)
.videoPreferredAspect(16f/9f)
.autoSubmit(true)
.allowRetry(false)
.qualityProfile(MaterialCamera.QUALITY_480P)
.start(CAMERA_RQ);
Log.d(msg, "The onCreate() event");
Expand Down
2 changes: 2 additions & 0 deletions android/app/src/main/java/com/gllu/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.facebook.CallbackManager;

import com.facebook.react.ReactActivity;
import com.github.xinthink.rnmk.ReactMaterialKitPackage;
import ca.jaysoo.extradimensions.ExtraDimensionsPackage;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
Expand All @@ -30,6 +31,7 @@ protected List<ReactPackage> getPackages() {
mCallbackManager = new CallbackManager.Factory().create();
ReactPackage packages[] = new ReactPackage[]{
new MainReactPackage(),
new ReactMaterialKitPackage(),
new ExtraDimensionsPackage(),
new FBSDKPackage(mCallbackManager),
};
Expand Down
4 changes: 2 additions & 2 deletions android/app/src/main/java/com/gllu/MainApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import android.app.Application;

import com.facebook.react.ReactApplication;
import com.github.xinthink.rnmk.ReactMaterialKitPackage;
import com.gllu.customPackages.CameraReactPackage;
import com.reactnative.ivpusic.imagepicker.PickerPackage;
import com.idehub.GoogleAnalyticsBridge.GoogleAnalyticsBridgePackage;
import com.xxsnakerxx.flurryanalytics.FlurryAnalyticsPackage;
import com.RNFetchBlob.RNFetchBlobPackage;
Expand Down Expand Up @@ -69,7 +69,7 @@ protected List<ReactPackage> getPackages() {
new LinearGradientPackage(),
new ReactVideoPackage(),
new ExtraDimensionsPackage(),
new PickerPackage(),
new ReactMaterialKitPackage(),
new VectorIconsPackage(),
new CodePush(null, getApplicationContext(), BuildConfig.DEBUG),
new FBSDKPackage(mCallbackManager)
Expand Down
49 changes: 37 additions & 12 deletions android/app/src/main/java/com/gllu/modules/CameraUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.gllu.Activities.TrimmerActivity;
import com.gllu.Activities.cameraRecorderActivity;
import com.gllu.utils.FileUtils;
import com.theartofdev.edmodo.cropper2.CropImage;
Expand All @@ -32,8 +33,10 @@ public class CameraUtils extends ReactContextBaseJavaModule {
private Promise mPromise;
public static final int RECORD_VIDEO = 1;
private static final int PICK_GALLERY = 2;
private static final int TRIM_VIDEO = 3;
private String mFileType = "";
private boolean mImageTaken = false;
private boolean mVideoTaken = false;
private Uri mOriginalFile;

private final ActivityEventListener mActivityEventListener = new BaseActivityEventListener() {
Expand All @@ -45,20 +48,20 @@ public void onActivityResult(Activity activity, int requestCode, int resultCode,
case RECORD_VIDEO:
if (resultCode == RESULT_OK) {
String mFilePath = intent.getStringExtra(cameraRecorderActivity.VIDEO_PATH);
mOriginalFile = Uri.parse(mFilePath);

if(MimeTypeMap.getFileExtensionFromUrl(mFilePath) == "mp4"){
mPromise.resolve(mFilePath);
}
else{
if(MimeTypeMap.getFileExtensionFromUrl(mFilePath).equals("mp4")){
Intent timmerIntent = new Intent(getCurrentActivity(), TrimmerActivity.class);
timmerIntent.putExtra(TrimmerActivity.EXTRA_VIDEO_PATH, mFilePath);
getCurrentActivity().startActivityForResult(timmerIntent, TRIM_VIDEO);
} else {
mImageTaken = true;
mOriginalFile = Uri.parse(mFilePath);
CropImage.activity(Uri.parse(mFilePath))
.setAspectRatio(9,16)
.setAspectRatio(9, 16)
.setFlipHorizontally(true)
.start(getCurrentActivity());
}
}
else if (resultCode == 1001) {
} else if (resultCode == 1001) {

mFileType = intent.getStringExtra("file_type");
openGallery(mFileType);
Expand All @@ -72,30 +75,52 @@ else if (resultCode == 1001) {
if (mFileType.equals("image")) {
// start cropping activity for pre-acquired image saved on the device
CropImage.activity(uri)
.setAspectRatio(9,16)
.setAspectRatio(9, 16)
.setGuidelines(CropImageView.Guidelines.ON)
.start(getCurrentActivity());
} else {

Intent timmerIntent = new Intent(getCurrentActivity(), TrimmerActivity.class);
timmerIntent.putExtra(TrimmerActivity.EXTRA_VIDEO_PATH, uri.toString());
getCurrentActivity().startActivityForResult(timmerIntent, TRIM_VIDEO);


String realPath = FileUtils.getPath(getReactApplicationContext(), uri);
mPromise.resolve("file://" + realPath);
}
}
break;

case TRIM_VIDEO:

/*
File mVideoToDelete = new File(mOriginalFile.getPath());
if (mVideoToDelete.exists()) {
mVideoToDelete.delete();
}
*/
if (resultCode == RESULT_OK) {
mPromise.resolve("file://" + intent.getParcelableExtra(TrimmerActivity.EXTRA_VIDEO_PATH).toString());
} else {
Intent intent2 = new Intent(getCurrentActivity(), cameraRecorderActivity.class);
getCurrentActivity().startActivityForResult(intent2, RECORD_VIDEO);
}
break;

case CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE:
CropImage.ActivityResult result = CropImage.getActivityResult(intent);

File mfileToDelete = new File(mOriginalFile.getPath());
if (mfileToDelete.exists()){
if (mfileToDelete.exists()) {
mfileToDelete.delete();
}
if (resultCode == RESULT_OK) {
Uri resultUri = result.getUri();
String realPath = FileUtils.getPath(getReactApplicationContext(), resultUri);
Log.d("martinResult", realPath);
mPromise.resolve("file://" + realPath);
}
else if (mImageTaken){
} else if (mImageTaken) {
Intent intent2 = new Intent(getCurrentActivity(), cameraRecorderActivity.class);
getCurrentActivity().startActivityForResult(intent2, RECORD_VIDEO);
}
Expand Down
5 changes: 5 additions & 0 deletions android/app/src/main/res/layout/activity_trimmer.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<life.knowledge4.videotrimmer.K4LVideoTrimmer xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/timeLine"
android:layout_width="match_parent"
android:layout_height="match_parent" />

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package life.knowledge4.videotrimmer;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.MediumTest;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;


import static org.junit.Assert.*;

/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@MediumTest
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentationTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("life.knowledge4.videotrimmer", appContext.getPackageName());
}
}
11 changes: 11 additions & 0 deletions android/libs/video-trimmer/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="life.knowledge4.videotrimmer">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:allowBackup="true">

</application>

</manifest>
Loading

0 comments on commit 8538b0b

Please sign in to comment.