From fe7ac319e2996128be2e12fbb5f00a1d6640f58f Mon Sep 17 00:00:00 2001 From: Ashish Goel Date: Thu, 23 Nov 2017 19:48:10 +0530 Subject: [PATCH 1/3] made project compatible with android studio 3, updated dependencies and modified UI --- app/build.gradle | 17 ++++- app/src/main/AndroidManifest.xml | 7 +- .../sampleffmpeg/ApplicationComponent.java | 17 +++++ .../sampleffmpeg/BaseActivity.java | 58 +++++++++++++++++ .../sampleffmpeg/BaseApplication.java | 34 ++++++++++ .../sampleffmpeg/DaggerDependencyModule.java | 9 ++- .../hiteshsondhi88/sampleffmpeg/Home.java | 27 ++++---- app/src/main/res/layout/activity_home.xml | 64 +++++++++++-------- app/src/main/res/layout/toolbar_layout.xml | 17 +++++ app/src/main/res/values/colors.xml | 6 ++ app/src/main/res/values/styles.xml | 13 ++-- build.gradle | 18 ++++-- gradle/wrapper/gradle-wrapper.properties | 4 +- 13 files changed, 228 insertions(+), 63 deletions(-) create mode 100644 app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/ApplicationComponent.java create mode 100644 app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/BaseActivity.java create mode 100644 app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/BaseApplication.java create mode 100644 app/src/main/res/layout/toolbar_layout.xml create mode 100644 app/src/main/res/values/colors.xml 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/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7a7ba8d..d25df5b 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:label="@string/app_name"> diff --git a/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/ApplicationComponent.java b/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/ApplicationComponent.java new file mode 100644 index 0000000..aa3be2f --- /dev/null +++ b/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/ApplicationComponent.java @@ -0,0 +1,17 @@ +package com.github.hiteshsondhi88.sampleffmpeg; + +/** + * Created by navjotsinghbedi on 3/28/16. + */ + + +import javax.inject.Singleton; + +import dagger.Component; + +@Singleton +@Component(modules = {DaggerDependencyModule.class}) +public interface ApplicationComponent { + + void inject(Home home); +} diff --git a/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/BaseActivity.java b/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/BaseActivity.java new file mode 100644 index 0000000..477bb6a --- /dev/null +++ b/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/BaseActivity.java @@ -0,0 +1,58 @@ +package com.github.hiteshsondhi88.sampleffmpeg; + +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 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; + } + + protected abstract void reloadData(); +} diff --git a/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/BaseApplication.java b/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/BaseApplication.java new file mode 100644 index 0000000..e57f23d --- /dev/null +++ b/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/BaseApplication.java @@ -0,0 +1,34 @@ +package com.github.hiteshsondhi88.sampleffmpeg; + +import android.app.Application; +import android.content.Context; + +/** + * 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/DaggerDependencyModule.java b/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/DaggerDependencyModule.java index 1807ede..425c94c 100644 --- a/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/DaggerDependencyModule.java +++ b/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/DaggerDependencyModule.java @@ -6,11 +6,10 @@ import dagger.Module; import dagger.Provides; + import com.github.hiteshsondhi88.libffmpeg.FFmpeg; -@Module( - injects = Home.class -) +@Module @SuppressWarnings("unused") public class DaggerDependencyModule { @@ -20,9 +19,9 @@ public class DaggerDependencyModule { 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/Home.java index 4568f6f..f79d0ff 100644 --- a/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/Home.java +++ b/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/Home.java @@ -5,7 +5,6 @@ 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; @@ -16,9 +15,8 @@ import javax.inject.Inject; +import butterknife.BindView; import butterknife.ButterKnife; -import butterknife.InjectView; -import dagger.ObjectGraph; import com.github.hiteshsondhi88.libffmpeg.ExecuteBinaryResponseHandler; import com.github.hiteshsondhi88.libffmpeg.FFmpeg; @@ -33,13 +31,13 @@ public class Home extends Activity implements View.OnClickListener { @Inject 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,8 +46,9 @@ 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); loadFFMpegBinary(); initUI(); @@ -80,19 +79,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 +105,7 @@ public void onStart() { @Override public void onFinish() { - Log.d(TAG, "Finished command : ffmpeg "+command); + Log.d(TAG, "Finished command : ffmpeg " + command); progressDialog.dismiss(); } }); diff --git a/app/src/main/res/layout/activity_home.xml b/app/src/main/res/layout/activity_home.xml index 7495e25..261e32e 100644 --- a/app/src/main/res/layout/activity_home.xml +++ b/app/src/main/res/layout/activity_home.xml @@ -2,36 +2,48 @@ 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=".Home"> - - -