├── .gitignore
├── AndroidCommonLib
├── AndroidManifest.xml
├── build.gradle
├── res
│ └── values
│ │ └── strings.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── frankdu
│ └── common
│ ├── AndroidAppModule.java
│ ├── BaseActivity.java
│ ├── BaseFragment.java
│ ├── DaggerApplication.java
│ ├── ForActivity.java
│ ├── ForApplication.java
│ └── Injector.java
├── LICENSE
├── MyCoolApp
├── AndroidManifest.xml
├── build.gradle
├── res
│ ├── drawable-hdpi
│ │ └── ic_launcher.png
│ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ ├── drawable-xhdpi
│ │ └── ic_launcher.png
│ ├── layout
│ │ ├── fragment_intro.xml
│ │ ├── fragment_picture.xml
│ │ └── main_feed.xml
│ └── values
│ │ └── strings.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── frankdu
│ └── cool
│ ├── activity
│ ├── ActivityScopeModule.java
│ ├── BaseCoolActivity.java
│ ├── MainCoolActivity.java
│ └── SplashActivity.java
│ ├── annotations
│ ├── FacebookApiKey.java
│ └── FacebookApiSecret.java
│ ├── app
│ ├── MyCoolAppScopeModule.java
│ └── MyCoolApplication.java
│ └── fragment
│ ├── IntroFragment.java
│ └── PictureFragment.java
├── README.md
├── android_common.gradle
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # Android files #
2 | ###################
3 | bin/
4 | gen/
5 | local.properties
6 |
7 | # gradle files #
8 | ###################
9 | .gradle
10 | build
11 |
12 | # IntelliJ #
13 | #######################
14 | .idea
15 | *.iml
16 | *.iws
17 | *.ipr
18 | classes
19 | gen-external-apklibs
20 |
21 | # Eclipse #
22 | #######################
23 | .classpath
24 | .project
25 | .settings
26 |
27 | # binary files #
28 | ###################
29 | *.pyc
30 |
31 | # OS X files #
32 | ###################
33 | .DS_Store
34 | .DS_Store?
35 | ._*
36 | .Spotlight-V100
37 | .Trashes
38 |
39 | # Maven files #
40 | #######################
41 | target/
42 |
43 | # Robolectric #
44 | #######################
45 | tmp
46 |
47 |
48 | # Proguard folder by Eclipse
49 | #######################
50 | proguard/
51 |
52 | # Crashlytics #
53 | #######################
54 | com_crashlytics_export_strings.xml
--------------------------------------------------------------------------------
/AndroidCommonLib/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/AndroidCommonLib/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'android-library'
2 | apply from: "${rootDir}/android_common.gradle"
3 |
4 |
5 | dependencies {
6 | provided 'com.squareup.dagger:dagger-compiler:1.2.1'
7 |
8 | compile fileTree(dir: 'libs', include: '*.jar')
9 |
10 | compile 'com.android.support:support-v4:19.1.+'
11 |
12 | // Notice the @aar suffix
13 | compile 'com.google.android.gms:play-services:3.2.25@aar'
14 |
15 | // Notice the @aar suffix
16 | compile('com.actionbarsherlock:actionbarsherlock:4.4.0@aar')
17 |
18 | compile 'com.squareup.dagger:dagger:1.2.1'
19 |
20 | compile 'com.squareup:otto:1.3.4'
21 | }
22 |
23 | android {
24 | sourceSets {
25 | main {
26 | manifest.srcFile 'AndroidManifest.xml'
27 | res.srcDirs = ['res']
28 | assets.srcDirs = ['assets']
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/AndroidCommonLib/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/AndroidCommonLib/src/main/java/com/frankdu/common/AndroidAppModule.java:
--------------------------------------------------------------------------------
1 | package com.frankdu.common;
2 |
3 | import android.content.Context;
4 | import android.location.LocationManager;
5 |
6 | import com.squareup.otto.Bus;
7 |
8 | import javax.inject.Singleton;
9 |
10 | import dagger.Module;
11 | import dagger.Provides;
12 |
13 | @Module(
14 | complete = false,
15 | library = true,
16 | injects = {
17 | }
18 | )
19 | public class AndroidAppModule {
20 |
21 | /* package */ static Context sApplicationContext = null;
22 |
23 | /**
24 | * Allow the application context to be injected but require that it be annotated with
25 | * {@link com.frankdu.common.ForApplication @Annotation} to explicitly differentiate it from an activity context.
26 | */
27 | @Provides
28 | @Singleton
29 | @ForApplication
30 | Context provideApplicationContext() {
31 | return sApplicationContext;
32 | }
33 |
34 | @Provides @Singleton
35 | LocationManager provideLocationManager() {
36 | return (LocationManager) sApplicationContext.getSystemService(Context.LOCATION_SERVICE);
37 | }
38 |
39 | @Provides @Singleton
40 | Bus provideBus() {
41 | return new Bus();
42 | }
43 | }
--------------------------------------------------------------------------------
/AndroidCommonLib/src/main/java/com/frankdu/common/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.frankdu.common;
2 |
3 | import android.os.Bundle;
4 |
5 | import com.actionbarsherlock.app.SherlockFragmentActivity;
6 |
7 | import dagger.ObjectGraph;
8 |
9 | public abstract class BaseActivity
10 | extends SherlockFragmentActivity
11 | implements Injector {
12 |
13 | private ObjectGraph mActivityGraph;
14 |
15 | @Override
16 | protected void onStart() {
17 | super.onStart();
18 | }
19 |
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 |
24 | // Create the activity graph by .plus-ing our modules onto the application graph.
25 | DaggerApplication application = (DaggerApplication) getApplication();
26 | mActivityGraph = application.getObjectGraph().plus(geActivitytModules());
27 |
28 | // Inject ourselves so subclasses will have dependencies fulfilled when this method returns.
29 | mActivityGraph.inject(this);
30 | }
31 |
32 | @Override
33 | protected void onDestroy() {
34 | // Eagerly clear the reference to the activity graph to allow it to be garbage collected as
35 | // soon as possible.
36 | mActivityGraph = null;
37 |
38 | super.onDestroy();
39 | }
40 |
41 | protected T getView(int id) {
42 | return (T) findViewById(id);
43 | }
44 |
45 | /**
46 | * Inject the supplied {@code object} using the activity-specific graph.
47 | * */
48 | @Override
49 | public void inject(Object object) {
50 | mActivityGraph.inject(object);
51 | }
52 |
53 | public ObjectGraph getObjectGraph() {
54 | return mActivityGraph;
55 | }
56 |
57 | protected abstract Object[] geActivitytModules();
58 | }
--------------------------------------------------------------------------------
/AndroidCommonLib/src/main/java/com/frankdu/common/BaseFragment.java:
--------------------------------------------------------------------------------
1 | package com.frankdu.common;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.Fragment;
5 |
6 | /**
7 | * Base fragment which performs injection using the activity-scoped object graph
8 | */
9 | public abstract class BaseFragment extends Fragment {
10 | @Override
11 | public void onCreate(Bundle savedInstanceState) {
12 | super.onCreate(savedInstanceState);
13 |
14 | // Assume that it lives within a BaseActivity host
15 | ((BaseActivity)getActivity()).inject(this);
16 | }
17 |
18 | protected T getView(int id) {
19 | return (T) getView().findViewById(id);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/AndroidCommonLib/src/main/java/com/frankdu/common/DaggerApplication.java:
--------------------------------------------------------------------------------
1 | package com.frankdu.common;
2 |
3 | import android.app.Application;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | import dagger.ObjectGraph;
9 |
10 | /**
11 | * Base class of a dagger enabled application
12 | */
13 | public abstract class DaggerApplication extends Application implements Injector {
14 |
15 | private ObjectGraph mObjectGraph;
16 |
17 | @Override
18 | public void onCreate() {
19 | super.onCreate();
20 |
21 | AndroidAppModule sharedAppModule = new AndroidAppModule();
22 |
23 | // bootstrap. So that it allows no-arg constructor in AndroidAppModule
24 | sharedAppModule.sApplicationContext = this.getApplicationContext();
25 |
26 | List