diff --git a/app/build.gradle b/app/build.gradle index f6d48ab..a371d69 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -31,10 +31,21 @@ android { } dependencies { - compile 'com.squareup.dagger:dagger-compiler:1.2.2' - compile 'com.squareup.dagger:dagger:1.2.2' - compile 'com.jakewharton:butterknife:5.1.2' + // dagger 2 for dependency injection + annotationProcessor "com.google.dagger:dagger-compiler:$rootProject.ext.daggerVersion" + compile "com.google.dagger:dagger:$rootProject.ext.daggerVersion" + provided 'javax.annotation:jsr250-api:1.0' + + // butterknife for view binding + compile "com.jakewharton:butterknife:$rootProject.ext.butterknifeVersion" + annotationProcessor "com.jakewharton:butterknife-compiler:$rootProject.ext.butterknifeVersion" + compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile 'com.squareup.assertj:assertj-android:1.0.0' compile project(':FFmpegAndroid') + + // app compat and design support library + compile "com.android.support:appcompat-v7:$rootProject.ext.supportLibraryVersion" + compile "com.android.support:support-v13:$rootProject.ext.supportLibraryVersion" + compile "com.android.support:design:$rootProject.ext.supportLibraryVersion" } diff --git a/app/src/androidTest/java/com/github/hiteshsondhi88/sampleffmpeg/FFmpegInstrumentationTest.java b/app/src/androidTest/java/com/github/hiteshsondhi88/sampleffmpeg/FFmpegInstrumentationTest.java index 7b9f160..a462158 100644 --- a/app/src/androidTest/java/com/github/hiteshsondhi88/sampleffmpeg/FFmpegInstrumentationTest.java +++ b/app/src/androidTest/java/com/github/hiteshsondhi88/sampleffmpeg/FFmpegInstrumentationTest.java @@ -12,10 +12,11 @@ import com.github.hiteshsondhi88.libffmpeg.FFmpegExecuteResponseHandler; import com.github.hiteshsondhi88.libffmpeg.FFmpegLoadBinaryResponseHandler; import com.github.hiteshsondhi88.libffmpeg.exceptions.FFmpegCommandAlreadyRunningException; +import com.github.hiteshsondhi88.sampleffmpeg.screens.home.HomeActivity; import static org.assertj.core.api.Assertions.assertThat; -public class FFmpegInstrumentationTest extends ActivityInstrumentationTestCase2 { +public class FFmpegInstrumentationTest extends ActivityInstrumentationTestCase2 { private static final String TAG = FFmpegInstrumentationTest.class.getSimpleName(); @@ -23,7 +24,7 @@ public class FFmpegInstrumentationTest extends ActivityInstrumentationTestCase2< FFmpeg ffmpeg; public FFmpegInstrumentationTest() { - super(Home.class); + super(HomeActivity.class); } @Override @@ -123,21 +124,22 @@ public void testFFmpegAVItoMP4Usingx264() { public void testLibass() { File outass = new File(getFFmpegFilesDir(), "output.ass"); - checkFFmpegCommon("-y -i "+getSrtSampleFile()+" "+outass.getAbsolutePath(), outass); + checkFFmpegCommon("-y -i " + getSrtSampleFile() + " " + outass.getAbsolutePath(), outass); } private void checkFFmpegConvertUsingx264(File inputFile, File outputFile) { - checkFFmpegCommon("-y -i "+inputFile.getAbsolutePath()+" -c:v libx264 -preset ultrafast "+outputFile.getAbsolutePath(), outputFile); + checkFFmpegCommon("-y -i " + inputFile.getAbsolutePath() + " -c:v libx264 -preset ultrafast " + outputFile.getAbsolutePath(), outputFile); } private void checkFFmpegConvertCommon(File inputFile, File outputFile) { - checkFFmpegCommon("-y -i "+inputFile.getAbsolutePath()+" "+outputFile.getAbsolutePath(), outputFile); + checkFFmpegCommon("-y -i " + inputFile.getAbsolutePath() + " " + outputFile.getAbsolutePath(), outputFile); } private void checkFFmpegCommon(final String cmd, final File outputFile) { - Log.d(TAG, "start : "+outputFile.getAbsolutePath()); + Log.d(TAG, "start : " + outputFile.getAbsolutePath()); try { - ffmpeg.execute(cmd, new FFmpegExecuteResponseHandler() { + String[] cmdArray = {cmd}; + ffmpeg.execute(cmdArray, new FFmpegExecuteResponseHandler() { @Override public void onStart() { @@ -146,7 +148,7 @@ public void onStart() { @Override public void onProgress(String message) { - Log.d(TAG, "progress : "+message); + Log.d(TAG, "progress : " + message); } @Override @@ -161,7 +163,7 @@ public void onSuccess(String message) { @Override public void onFinish() { - Log.d(TAG, "done : "+outputFile.getAbsolutePath()); + Log.d(TAG, "done : " + outputFile.getAbsolutePath()); synchronized (FFmpegInstrumentationTest.this) { FFmpegInstrumentationTest.this.notify(); } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7a7ba8d..32012e9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,17 +1,18 @@ + package="com.github.hiteshsondhi88.sampleffmpeg"> + android:theme="@style/AppTheme"> + android:name=".screens.home.HomeActivity" + android:label="@string/app_name"> diff --git a/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/core/BaseActivity.java b/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/core/BaseActivity.java new file mode 100644 index 0000000..86a3bae --- /dev/null +++ b/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/core/BaseActivity.java @@ -0,0 +1,58 @@ +package com.github.hiteshsondhi88.sampleffmpeg.core; + +import android.content.Context; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.view.MenuItem; +import android.view.View; + +import com.github.hiteshsondhi88.sampleffmpeg.R; + +import javax.inject.Inject; + +import butterknife.BindView; + +/** + * Created by sd2_rails on 4/18/17. + */ + +public abstract class BaseActivity extends AppCompatActivity { + + @Nullable + @BindView(R.id.toolbar) + public Toolbar toolbar; + + public void setToolbar(String title) { + setToolbar(title, true); + } + + public void setToolbar(String title, boolean showBackButton) { + if (toolbar != null) { + setSupportActionBar(toolbar); + if (getSupportActionBar() != null) { + getSupportActionBar().setDisplayHomeAsUpEnabled(showBackButton); + getSupportActionBar().setDisplayShowHomeEnabled(showBackButton); + getSupportActionBar().setTitle(title); + } + } + } + + public void setToolbarText(String title) { + if (getSupportActionBar() != null) { + getSupportActionBar().setTitle(title); + } + } + + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == android.R.id.home) { + onBackPressed(); + } + return super.onOptionsItemSelected(item); + } + + public Context getContext() { + return this; + } +} diff --git a/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/core/BaseApplication.java b/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/core/BaseApplication.java new file mode 100644 index 0000000..42d7d5f --- /dev/null +++ b/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/core/BaseApplication.java @@ -0,0 +1,37 @@ +package com.github.hiteshsondhi88.sampleffmpeg.core; + +import android.app.Application; + +import com.github.hiteshsondhi88.sampleffmpeg.di.component.ApplicationComponent; +import com.github.hiteshsondhi88.sampleffmpeg.di.component.DaggerApplicationComponent; +import com.github.hiteshsondhi88.sampleffmpeg.di.module.DaggerDependencyModule; + +/** + * Created by bedi on 01/03/17. + */ + +public class BaseApplication extends Application { + + private static BaseApplication sInstance; + + private ApplicationComponent applicationComponent; + + public static BaseApplication getInstance() { + return sInstance; + } + + @Override + public void onCreate() { + super.onCreate(); + sInstance = this; + } + + public ApplicationComponent getApplicationComponent() { + if (applicationComponent == null) { + applicationComponent = DaggerApplicationComponent.builder() + .daggerDependencyModule(new DaggerDependencyModule(this)) + .build(); + } + return applicationComponent; + } +} diff --git a/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/di/component/ApplicationComponent.java b/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/di/component/ApplicationComponent.java new file mode 100644 index 0000000..a63c313 --- /dev/null +++ b/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/di/component/ApplicationComponent.java @@ -0,0 +1,20 @@ +package com.github.hiteshsondhi88.sampleffmpeg.di.component; + +/** + * Created by navjotsinghbedi on 3/28/16. + */ + + +import com.github.hiteshsondhi88.sampleffmpeg.di.module.DaggerDependencyModule; +import com.github.hiteshsondhi88.sampleffmpeg.screens.home.HomeActivity; + +import javax.inject.Singleton; + +import dagger.Component; + +@Singleton +@Component(modules = {DaggerDependencyModule.class}) +public interface ApplicationComponent { + + void inject(HomeActivity homeActivity); +} diff --git a/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/DaggerDependencyModule.java b/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/di/module/DaggerDependencyModule.java similarity index 72% rename from app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/DaggerDependencyModule.java rename to app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/di/module/DaggerDependencyModule.java index 1807ede..cbe200b 100644 --- a/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/DaggerDependencyModule.java +++ b/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/di/module/DaggerDependencyModule.java @@ -1,4 +1,4 @@ -package com.github.hiteshsondhi88.sampleffmpeg; +package com.github.hiteshsondhi88.sampleffmpeg.di.module; import android.content.Context; @@ -6,23 +6,22 @@ import dagger.Module; import dagger.Provides; + import com.github.hiteshsondhi88.libffmpeg.FFmpeg; -@Module( - injects = Home.class -) +@Module @SuppressWarnings("unused") public class DaggerDependencyModule { private final Context context; - DaggerDependencyModule(Context context) { + public DaggerDependencyModule(Context context) { this.context = context; } - @Provides @Singleton + @Provides + @Singleton FFmpeg provideFFmpeg() { return FFmpeg.getInstance(context.getApplicationContext()); } - } diff --git a/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/Home.java b/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/screens/home/HomeActivity.java similarity index 69% rename from app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/Home.java rename to app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/screens/home/HomeActivity.java index 4568f6f..66cb9eb 100644 --- a/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/Home.java +++ b/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/screens/home/HomeActivity.java @@ -1,13 +1,10 @@ -package com.github.hiteshsondhi88.sampleffmpeg; +package com.github.hiteshsondhi88.sampleffmpeg.screens.home; -import android.app.Activity; import android.app.AlertDialog; import android.app.ProgressDialog; import android.content.DialogInterface; import android.os.Bundle; -import android.text.TextUtils; import android.util.Log; -import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.LinearLayout; @@ -16,30 +13,33 @@ import javax.inject.Inject; +import butterknife.BindView; import butterknife.ButterKnife; -import butterknife.InjectView; -import dagger.ObjectGraph; +import butterknife.OnClick; import com.github.hiteshsondhi88.libffmpeg.ExecuteBinaryResponseHandler; import com.github.hiteshsondhi88.libffmpeg.FFmpeg; import com.github.hiteshsondhi88.libffmpeg.LoadBinaryResponseHandler; import com.github.hiteshsondhi88.libffmpeg.exceptions.FFmpegCommandAlreadyRunningException; import com.github.hiteshsondhi88.libffmpeg.exceptions.FFmpegNotSupportedException; +import com.github.hiteshsondhi88.sampleffmpeg.R; +import com.github.hiteshsondhi88.sampleffmpeg.core.BaseActivity; +import com.github.hiteshsondhi88.sampleffmpeg.core.BaseApplication; -public class Home extends Activity implements View.OnClickListener { +public class HomeActivity extends BaseActivity { - private static final String TAG = Home.class.getSimpleName(); + private static final String TAG = HomeActivity.class.getSimpleName(); @Inject - FFmpeg ffmpeg; + public FFmpeg ffmpeg; - @InjectView(R.id.command) + @BindView(R.id.command) EditText commandEditText; - @InjectView(R.id.command_output) + @BindView(R.id.command_output) LinearLayout outputLayout; - @InjectView(R.id.run_command) + @BindView(R.id.run_command) Button runButton; private ProgressDialog progressDialog; @@ -48,16 +48,17 @@ public class Home extends Activity implements View.OnClickListener { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home); - ButterKnife.inject(this); - ObjectGraph.create(new DaggerDependencyModule(this)).inject(this); + ButterKnife.bind(this); + + BaseApplication.getInstance().getApplicationComponent().inject(this); + + setToolbar(getResources().getString(R.string.app_name), false); loadFFMpegBinary(); initUI(); } private void initUI() { - runButton.setOnClickListener(this); - progressDialog = new ProgressDialog(this); progressDialog.setTitle(null); } @@ -80,19 +81,19 @@ private void execFFmpegBinary(final String[] command) { ffmpeg.execute(command, new ExecuteBinaryResponseHandler() { @Override public void onFailure(String s) { - addTextViewToLayout("FAILED with output : "+s); + addTextViewToLayout("FAILED with output : " + s); } @Override public void onSuccess(String s) { - addTextViewToLayout("SUCCESS with output : "+s); + addTextViewToLayout("SUCCESS with output : " + s); } @Override public void onProgress(String s) { - Log.d(TAG, "Started command : ffmpeg "+command); - addTextViewToLayout("progress : "+s); - progressDialog.setMessage("Processing\n"+s); + Log.d(TAG, "Started command : ffmpeg " + command); + addTextViewToLayout("progress : " + s); + progressDialog.setMessage("Processing\n" + s); } @Override @@ -106,7 +107,7 @@ public void onStart() { @Override public void onFinish() { - Log.d(TAG, "Finished command : ffmpeg "+command); + Log.d(TAG, "Finished command : ffmpeg " + command); progressDialog.dismiss(); } }); @@ -116,13 +117,13 @@ public void onFinish() { } private void addTextViewToLayout(String text) { - TextView textView = new TextView(Home.this); + TextView textView = new TextView(HomeActivity.this); textView.setText(text); outputLayout.addView(textView); } private void showUnsupportedExceptionDialog() { - new AlertDialog.Builder(Home.this) + new AlertDialog.Builder(HomeActivity.this) .setIcon(android.R.drawable.ic_dialog_alert) .setTitle(getString(R.string.device_not_supported)) .setMessage(getString(R.string.device_not_supported_message)) @@ -130,7 +131,7 @@ private void showUnsupportedExceptionDialog() { .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - Home.this.finish(); + HomeActivity.this.finish(); } }) .create() @@ -138,18 +139,14 @@ public void onClick(DialogInterface dialog, int which) { } - @Override - public void onClick(View v) { - switch (v.getId()) { - case R.id.run_command: - String cmd = commandEditText.getText().toString(); - String[] command = cmd.split(" "); - if (command.length != 0) { - execFFmpegBinary(command); - } else { - Toast.makeText(Home.this, getString(R.string.empty_command_toast), Toast.LENGTH_LONG).show(); - } - break; + @OnClick(R.id.run_command) + void runCommand() { + String cmd = commandEditText.getText().toString(); + String[] command = cmd.split(" "); + if (command.length != 0) { + execFFmpegBinary(command); + } else { + Toast.makeText(HomeActivity.this, getString(R.string.empty_command_toast), Toast.LENGTH_LONG).show(); } } } diff --git a/app/src/main/res/layout/activity_home.xml b/app/src/main/res/layout/activity_home.xml index 7495e25..64591d8 100644 --- a/app/src/main/res/layout/activity_home.xml +++ b/app/src/main/res/layout/activity_home.xml @@ -2,36 +2,43 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - android:paddingLeft="@dimen/activity_horizontal_margin" - android:paddingRight="@dimen/activity_horizontal_margin" - android:paddingTop="@dimen/activity_vertical_margin" - android:paddingBottom="@dimen/activity_vertical_margin" - tools:context=".Home" - android:orientation="vertical"> + android:orientation="vertical" + tools:context=".screens.home.HomeActivity"> - - -