-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mithilesh
committed
Jul 4, 2016
1 parent
ef38d2d
commit d4a150e
Showing
44 changed files
with
791 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 23 | ||
buildToolsVersion "23.0.2" | ||
|
||
defaultConfig { | ||
applicationId "com.mithi.videocutter" | ||
minSdkVersion 16 | ||
targetSdkVersion 23 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(include: ['*.jar'], dir: 'libs') | ||
testCompile 'junit:junit:4.12' | ||
compile 'com.android.support:appcompat-v7:23.2.1' | ||
compile project(':FFmpegAndroid') | ||
compile 'com.android.support:recyclerview-v7:23.2.1' | ||
compile 'com.github.bumptech.glide:glide:3.7.0' | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in C:\Development\Android\sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.mithi.videocutter"> | ||
|
||
<uses-feature | ||
android:name="android.hardware.camera" | ||
android:required="true" /> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||
|
||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name="com.mithi.videocutter.MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.mithi.videocutter; | ||
|
||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
|
||
import com.github.hiteshsondhi88.libffmpeg.FFmpeg; | ||
import com.github.hiteshsondhi88.libffmpeg.LoadBinaryResponseHandler; | ||
import com.github.hiteshsondhi88.libffmpeg.exceptions.FFmpegNotSupportedException; | ||
|
||
import com.mithi.videocutter.fragment.RecTrimFragment; | ||
import com.mithi.videocutter.util.FragmentUtils; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
loadFFMpegBinary(); | ||
if (savedInstanceState == null) { | ||
FragmentUtils.setFragment(getSupportFragmentManager(), RecTrimFragment.class); | ||
} | ||
} | ||
|
||
|
||
private void loadFFMpegBinary() { | ||
try { | ||
FFmpeg.getInstance(this).loadBinary(new LoadBinaryResponseHandler() { | ||
@Override | ||
public void onFailure() { | ||
// showUnsupportedExceptionDialog(); | ||
} | ||
}); | ||
} catch (FFmpegNotSupportedException e) { | ||
// showUnsupportedExceptionDialog(); | ||
} | ||
} | ||
|
||
|
||
} |
55 changes: 55 additions & 0 deletions
55
app/src/main/java/com/mithi/videocutter/adapter/VideoPreviewAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.mithi.videocutter.adapter; | ||
|
||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
import com.bumptech.glide.Glide; | ||
|
||
import com.mithi.videocutter.R; | ||
import com.mithi.videocutter.model.VideoPreview; | ||
|
||
import java.util.List; | ||
|
||
public class VideoPreviewAdapter extends RecyclerView.Adapter<VideoPreviewAdapter.ViewHolder> { | ||
private List<VideoPreview> mContent; | ||
|
||
public VideoPreviewAdapter(List<VideoPreview> content) { | ||
mContent = content; | ||
} | ||
|
||
@Override | ||
public VideoPreviewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_video_preview_item, parent, false); | ||
return new ViewHolder(view); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(VideoPreviewAdapter.ViewHolder holder, int position) { | ||
VideoPreview videoPreview = getItem(position); | ||
holder.title.setText(videoPreview.getVideoFile().getName()); | ||
Glide.with(holder.itemView.getContext()).load(videoPreview.getVideoFile()).centerCrop().into(holder.preview); | ||
} | ||
|
||
private VideoPreview getItem(int position) { | ||
return mContent.get(position); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return mContent.size(); | ||
} | ||
|
||
static class ViewHolder extends RecyclerView.ViewHolder { | ||
TextView title; | ||
ImageView preview; | ||
public ViewHolder(View itemView) { | ||
super(itemView); | ||
title = (TextView)itemView.findViewById(R.id.title); | ||
preview = (ImageView)itemView.findViewById(R.id.preview); | ||
} | ||
} | ||
} |
122 changes: 122 additions & 0 deletions
122
app/src/main/java/com/mithi/videocutter/fragment/RecTrimFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package com.mithi.videocutter.fragment; | ||
|
||
import android.app.Activity; | ||
import android.app.ProgressDialog; | ||
import android.content.Intent; | ||
import android.net.Uri; | ||
import android.os.Bundle; | ||
import android.provider.MediaStore; | ||
import android.support.annotation.Nullable; | ||
import android.support.v4.app.Fragment; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import com.github.hiteshsondhi88.libffmpeg.ExecuteBinaryResponseHandler; | ||
|
||
import com.mithi.videocutter.R; | ||
import com.mithi.videocutter.util.AppUtils; | ||
import com.mithi.videocutter.util.DialogUtils; | ||
import com.mithi.videocutter.util.FFmpegUtils; | ||
import com.mithi.videocutter.util.FragmentUtils; | ||
|
||
public class RecTrimFragment extends Fragment { | ||
private static final int REQUEST_VIDEO_CAPTURE = 1; | ||
private static final String TAG = "VideoCutterLastVideo"; | ||
private static final int VIDEO_DURATION = 60; | ||
|
||
private Uri mPath; | ||
private ProgressDialog mProgressDialog; | ||
private boolean isTriming; | ||
|
||
@Override | ||
public void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setRetainInstance(true); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | ||
return inflater.inflate(R.layout.fragment_rec_trim, container, false); | ||
} | ||
|
||
@Override | ||
public void onActivityCreated(@Nullable Bundle savedInstanceState) { | ||
super.onActivityCreated(savedInstanceState); | ||
mProgressDialog = new ProgressDialog(getContext()); | ||
mProgressDialog.setCancelable(false); | ||
if (isTriming) { | ||
mProgressDialog.setMessage("Processing..."); | ||
mProgressDialog.show(); | ||
} | ||
View view = getView(); | ||
|
||
view.findViewById(R.id.cut_video).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
trimVideo(mPath); | ||
} | ||
}); | ||
|
||
view.findViewById(R.id.rec_video).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
dispatchTakeVideoIntent(); | ||
} | ||
}); | ||
|
||
view.findViewById(R.id.log_last_video).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
AppUtils.logLastVideo(); | ||
} | ||
}); | ||
} | ||
|
||
private void dispatchTakeVideoIntent() { | ||
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); | ||
if (takeVideoIntent.resolveActivity(getActivity().getPackageManager()) != null) { | ||
startActivityForResult(takeVideoIntent, REQUEST_VIDEO_CAPTURE); | ||
} | ||
} | ||
|
||
private void trimVideo(Uri path) { | ||
if (path == null) { | ||
DialogUtils.showAlert(getContext(), R.string.error, R.string.video_is_not_recorded); | ||
return; | ||
} | ||
mProgressDialog.setMessage("Processing..."); | ||
mProgressDialog.show(); | ||
isTriming = true; | ||
FFmpegUtils.trimVideo(getContext(), path, VIDEO_DURATION, new ExecuteBinaryResponseHandler() { | ||
@Override | ||
public void onFailure(String s) { | ||
mProgressDialog.dismiss(); | ||
DialogUtils.showAlert(getContext(), R.string.error, R.string.trim_error); | ||
} | ||
|
||
@Override | ||
public void onSuccess(String s) { | ||
mProgressDialog.dismiss(); | ||
DialogUtils.showAlert(getContext(), R.string.app_name, R.string.trim_success); | ||
FragmentUtils.addFragment(getFragmentManager(), VideoListFragment.class); | ||
} | ||
|
||
@Override | ||
public void onFinish() { | ||
isTriming = false; | ||
mProgressDialog.dismiss(); | ||
AppUtils.logLastVideo(); | ||
} | ||
}); | ||
} | ||
|
||
|
||
@Override | ||
public void onActivityResult(int requestCode, int resultCode, Intent data) { | ||
if (requestCode == REQUEST_VIDEO_CAPTURE && resultCode == Activity.RESULT_OK) { | ||
mPath = data.getData(); | ||
} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
app/src/main/java/com/mithi/videocutter/fragment/VideoListFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.mithi.videocutter.fragment; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v4.app.Fragment; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
|
||
import com.mithi.videocutter.R; | ||
import com.mithi.videocutter.adapter.VideoPreviewAdapter; | ||
import com.mithi.videocutter.model.VideoPreview; | ||
import com.mithi.videocutter.util.AppUtils; | ||
import com.mithi.videocutter.util.FFmpegUtils; | ||
|
||
import java.io.File; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class VideoListFragment extends Fragment { | ||
|
||
@Override | ||
public void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setRetainInstance(true); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | ||
return inflater.inflate(R.layout.fragment_video_list, container, false); | ||
} | ||
|
||
@Override | ||
public void onActivityCreated(@Nullable Bundle savedInstanceState) { | ||
super.onActivityCreated(savedInstanceState); | ||
RecyclerView recyclerView = (RecyclerView)getView().findViewById(R.id.recycler_view); | ||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); | ||
recyclerView.setAdapter(new VideoPreviewAdapter(getVideoPreviews())); | ||
getView().findViewById(R.id.log_last_video).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
AppUtils.logLastVideo(); | ||
} | ||
}); | ||
} | ||
|
||
private List<VideoPreview> getVideoPreviews() { | ||
List<VideoPreview> list = new ArrayList<>(); | ||
|
||
File cutterOutputDir = new File(FFmpegUtils.getVideoCutterOutputDir()); | ||
|
||
for (File file: cutterOutputDir.listFiles()) { | ||
VideoPreview videoPreview = new VideoPreview(file); | ||
list.add(videoPreview); | ||
} | ||
|
||
return list; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
app/src/main/java/com/mithi/videocutter/model/VideoPreview.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.mithi.videocutter.model; | ||
|
||
|
||
import java.io.File; | ||
|
||
public class VideoPreview { | ||
private File mVideoFile; | ||
|
||
public VideoPreview(File file) { | ||
mVideoFile = file; | ||
} | ||
|
||
public File getVideoFile() { | ||
return mVideoFile; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
app/src/main/java/com/mithi/videocutter/util/AppUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.mithi.videocutter.util; | ||
|
||
import android.util.Log; | ||
|
||
import java.io.File; | ||
|
||
public class AppUtils { | ||
private static final String TAG = "VideoCutterLastVideo"; | ||
public static void logLastVideo() { | ||
File dir = new File(FFmpegUtils.getVideoCutterOutputDir()); | ||
if (dir.exists()) { | ||
File[] list = dir.listFiles(); | ||
if (list != null && list.length > 0) { | ||
Log.d(TAG, "" + list[list.length - 1].getName()); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.