diff --git a/README.md b/README.md index 989a576..d3a3692 100755 --- a/README.md +++ b/README.md @@ -75,8 +75,8 @@ Download ```groovy dependencies { - compile 'com.github.matthiasrobbers:shortbread:1.0.1' - annotationProcessor 'com.github.matthiasrobbers:shortbread-compiler:1.0.1' + compile 'com.github.matthiasrobbers:shortbread:1.0.2' + annotationProcessor 'com.github.matthiasrobbers:shortbread-compiler:1.0.2' } ``` diff --git a/build.gradle b/build.gradle index 48a188c..e10b233 100755 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.0' + classpath 'com.android.tools.build:gradle:2.3.3' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3' } @@ -12,6 +12,9 @@ buildscript { allprojects { repositories { jcenter() + maven { + url "https://maven.google.com" + } } } @@ -20,15 +23,15 @@ task clean(type: Delete) { } ext { - compileSdkVersion = 25 - buildToolsVersion = '25.0.2' + compileSdkVersion = 26 + buildToolsVersion = '26.0.1' minSdkVersion = 9 - targetSdkVersion = 25 + targetSdkVersion = 26 sourceCompatibilityVersion = '1.7' targetCompatibilityVersion = '1.7' - supportLibraryVersion = '25.1.1' + supportLibraryVersion = '26.0.2' githubUrl = 'https://github.com/matthiasrobbers/shortbread' gitUrl = 'https://github.com/matthiasrobbers/shortbread.git' - libraryVersion = '1.0.1' + libraryVersion = '1.0.2' } diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index f76fc49..ef37e0c 100755 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -25,6 +25,6 @@ + android:parentActivityName=".MainActivity"/> \ No newline at end of file diff --git a/sample/src/main/java/com/example/shortbread/books/BooksActivity.java b/sample/src/main/java/com/example/shortbread/books/BooksActivity.java index f3168c7..4833547 100755 --- a/sample/src/main/java/com/example/shortbread/books/BooksActivity.java +++ b/sample/src/main/java/com/example/shortbread/books/BooksActivity.java @@ -2,7 +2,7 @@ import android.app.Activity; import android.os.Bundle; -import android.widget.Toast; +import android.widget.TextView; import com.example.shortbread.R; @@ -20,6 +20,6 @@ protected void onCreate(Bundle savedInstanceState) { @Shortcut(id = "favorite_books", icon = R.drawable.ic_shortcut_favorite, shortLabel = "Favorite books", rank = 2, disabledMessage = "You have no favorite books") public void showFavoriteBooks() { - Toast.makeText(this, "Favorite books", Toast.LENGTH_SHORT).show(); + ((TextView) findViewById(R.id.text)).setText("Favorite books"); } } diff --git a/sample/src/main/java/com/example/shortbread/movies/MoviesActivity.java b/sample/src/main/java/com/example/shortbread/movies/MoviesActivity.java index c171efe..7bbf086 100755 --- a/sample/src/main/java/com/example/shortbread/movies/MoviesActivity.java +++ b/sample/src/main/java/com/example/shortbread/movies/MoviesActivity.java @@ -2,7 +2,7 @@ import android.app.Activity; import android.os.Bundle; -import android.widget.Toast; +import android.widget.TextView; import com.example.shortbread.MainActivity; import com.example.shortbread.R; @@ -20,8 +20,8 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_movies); } - @Shortcut(id = "add_movie", icon = R.drawable.ic_shortcut_add, shortLabel = "Add movie", rank = 4, disabledMessageRes = R.string.label_books) + @Shortcut(id = "add_movie", icon = R.drawable.ic_shortcut_add, shortLabel = "Add movie", rank = 4) public void addMovie() { - Toast.makeText(this, "Add movie", Toast.LENGTH_SHORT).show(); + ((TextView) findViewById(R.id.text)).setText("Add movie"); } } diff --git a/sample/src/main/res/layout/activity_books.xml b/sample/src/main/res/layout/activity_books.xml index 5390e22..7259800 100755 --- a/sample/src/main/res/layout/activity_books.xml +++ b/sample/src/main/res/layout/activity_books.xml @@ -12,5 +12,6 @@ android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="Books"/> + android:text="Books" + android:textSize="48sp"/> diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml index 4682c75..27a2355 100755 --- a/sample/src/main/res/layout/activity_main.xml +++ b/sample/src/main/res/layout/activity_main.xml @@ -12,5 +12,6 @@ android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="Hello World!"/> + android:text="Start" + android:textSize="48sp"/> diff --git a/sample/src/main/res/layout/activity_movies.xml b/sample/src/main/res/layout/activity_movies.xml index efdc05d..3236eb0 100755 --- a/sample/src/main/res/layout/activity_movies.xml +++ b/sample/src/main/res/layout/activity_movies.xml @@ -12,5 +12,6 @@ android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="Movies"/> + android:text="Movies" + android:textSize="48sp"/> diff --git a/shortbread/src/main/java/shortbread/Shortbread.java b/shortbread/src/main/java/shortbread/Shortbread.java index d699789..9fcbe29 100755 --- a/shortbread/src/main/java/shortbread/Shortbread.java +++ b/shortbread/src/main/java/shortbread/Shortbread.java @@ -104,9 +104,19 @@ private static void setShortcuts(@NonNull Context context) { private static void setActivityLifecycleCallbacks(@NonNull Context applicationContext) { ((Application) applicationContext).registerActivityLifecycleCallbacks(new SimpleActivityLifecycleCallbacks() { + private Class createdActivityClass; + @Override - public void onActivityCreated(final Activity activity, final Bundle savedInstanceState) { - callMethodShortcut(activity); + public void onActivityCreated(Activity activity, Bundle savedInstanceState) { + createdActivityClass = activity.getClass(); + } + + @Override + public void onActivityStarted(Activity activity) { + if (activity.getClass() == createdActivityClass) { + callMethodShortcut(activity); + createdActivityClass = null; + } } }); diff --git a/shortbread/src/test/java/shortbread/ShortbreadTest.java b/shortbread/src/test/java/shortbread/ShortbreadTest.java index 599a096..2ad7386 100755 --- a/shortbread/src/test/java/shortbread/ShortbreadTest.java +++ b/shortbread/src/test/java/shortbread/ShortbreadTest.java @@ -129,7 +129,15 @@ public void activityLifecycleListenerCallsMethodShortcut() { Application.ActivityLifecycleCallbacks.class); verify(application).registerActivityLifecycleCallbacks(captor.capture()); Application.ActivityLifecycleCallbacks activityLifecycleCallbacks = captor.getValue(); + activityLifecycleCallbacks.onActivityCreated(activity, null); + assertNull(ShortbreadGenerated.activityThatWasPassedToCallMethodShortcut); + + activityLifecycleCallbacks.onActivityStarted(activity); assertEquals(activity, ShortbreadGenerated.activityThatWasPassedToCallMethodShortcut); + + ShortbreadGenerated.activityThatWasPassedToCallMethodShortcut = null; + activityLifecycleCallbacks.onActivityStarted(activity); + assertNull(ShortbreadGenerated.activityThatWasPassedToCallMethodShortcut); } }