File tree Expand file tree Collapse file tree 2 files changed +80
-7
lines changed
app/src/main/java/com/donnfelker/android/bootstrap Expand file tree Collapse file tree 2 files changed +80
-7
lines changed Original file line number Diff line number Diff line change
1
+ package com .donnfelker .android .bootstrap ;
2
+
3
+ import android .content .Context ;
4
+ import android .content .SharedPreferences ;
5
+ import android .content .pm .PackageInfo ;
6
+ import android .content .pm .PackageManager ;
7
+ import android .preference .PreferenceManager ;
8
+ import android .telephony .TelephonyManager ;
9
+ import android .view .inputmethod .InputMethodManager ;
10
+
11
+ import dagger .Module ;
12
+ import dagger .Provides ;
13
+
14
+ @ Module (
15
+ complete = false
16
+ )
17
+ public class AndroidModule {
18
+
19
+ @ Provides
20
+ SharedPreferences provideDefaultSharedPreferences (final Context context )
21
+ {
22
+ return PreferenceManager .getDefaultSharedPreferences (context );
23
+ }
24
+
25
+ @ Provides
26
+ PackageInfo providePackageInfo (Context context )
27
+ {
28
+ try
29
+ {
30
+ return context .getPackageManager ().getPackageInfo (context .getPackageName (), 0 );
31
+ }
32
+ catch (PackageManager .NameNotFoundException e )
33
+ {
34
+ throw new RuntimeException (e );
35
+ }
36
+ }
37
+
38
+ @ Provides
39
+ TelephonyManager provideTelephonyManager (Context context )
40
+ {
41
+ return getSystemService (context , Context .TELEPHONY_SERVICE );
42
+ }
43
+
44
+ @ SuppressWarnings ("unchecked" )
45
+ public <T > T getSystemService (Context context , String serviceConstant )
46
+ {
47
+ return (T ) context .getSystemService (serviceConstant );
48
+ }
49
+
50
+ @ Provides
51
+ InputMethodManager provideInputMethodManager (final Context context )
52
+ {
53
+ return (InputMethodManager ) context .getSystemService (Context .INPUT_METHOD_SERVICE );
54
+ }
55
+
56
+
57
+ }
Original file line number Diff line number Diff line change 4
4
import com .google .inject .Singleton ;
5
5
import com .squareup .otto .Bus ;
6
6
7
+ import javax .inject .Singleton ;
8
+
9
+ import dagger .Module ;
10
+ import dagger .Provides ;
11
+
7
12
/**
8
- * Module for setting up custom bindings in RoboGuice .
13
+ * Dagger module for setting up provides statements .
9
14
*/
10
- public class BootstrapModule extends AbstractModule {
15
+ @ Module
16
+ (
17
+ complete = false ,
18
+
19
+ entryPoints = {
20
+ BootstrapApplication .class
21
+ },
22
+
23
+ includes = {
24
+ AndroidModule .class
25
+ }
26
+ )
27
+ public class BootstrapModule {
11
28
12
- @ Override
13
- protected void configure () {
29
+ @ Singleton
30
+ @ Provides
31
+ Bus provideOttoBus () {
14
32
15
- // We want Otto to be bound as a singleton as one instance only needs
16
- // to be present in this app
17
- bind (Bus .class ).in (Singleton .class );
33
+ return new Bus ();
18
34
19
35
}
20
36
You can’t perform that action at this time.
0 commit comments