Skip to content

Commit

Permalink
Merge pull request #18 from MatthiasRobbers/mr/fix_method_shortcuts_c…
Browse files Browse the repository at this point in the history
…alled_before_on_create

Fix #13 Method annotations don't work
  • Loading branch information
MatthiasRobbers authored Sep 24, 2017
2 parents bb9a8cf + dffcdf1 commit a3f99c9
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 19 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
```

Expand Down
15 changes: 9 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand All @@ -12,6 +12,9 @@ buildscript {
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}

Expand All @@ -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'
}
2 changes: 1 addition & 1 deletion sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@

<activity
android:name="com.example.shortbread.books.BooksActivity"
android:parentActivityName=".movies.MoviesActivity"/>
android:parentActivityName=".MainActivity"/>
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
}
}
3 changes: 2 additions & 1 deletion sample/src/main/res/layout/activity_books.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
</RelativeLayout>
3 changes: 2 additions & 1 deletion sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
</RelativeLayout>
3 changes: 2 additions & 1 deletion sample/src/main/res/layout/activity_movies.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
</RelativeLayout>
14 changes: 12 additions & 2 deletions shortbread/src/main/java/shortbread/Shortbread.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<? extends Activity> 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;
}
}
});

Expand Down
8 changes: 8 additions & 0 deletions shortbread/src/test/java/shortbread/ShortbreadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit a3f99c9

Please sign in to comment.