Skip to content

Commit 8c2b5cd

Browse files
committed
Merge branch 'code-style' into code-style-merge
Trying to get code to be conform with Android's Guidelines.
2 parents ec0e171 + 5eb2885 commit 8c2b5cd

38 files changed

+639
-558
lines changed

app/src/main/java/com/donnfelker/android/bootstrap/BootstrapApplication.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616
*/
1717
public class BootstrapApplication extends Application {
1818

19-
private static BootstrapApplication instance;
19+
private static BootstrapApplication sInstance;
2020

2121
/**
2222
* Create main application
2323
*/
2424
public BootstrapApplication() {
25-
2625
// Disable http.keepAlive on Froyo and below
27-
if (SDK_INT <= FROYO)
26+
if (SDK_INT <= FROYO) {
2827
HttpRequest.keepAlive(false);
28+
}
2929
}
3030

3131
/**
@@ -36,14 +36,13 @@ public BootstrapApplication() {
3636
public BootstrapApplication(final Context context) {
3737
this();
3838
attachBaseContext(context);
39-
4039
}
4140

4241
@Override
4342
public void onCreate() {
4443
super.onCreate();
4544

46-
instance = this;
45+
sInstance = this;
4746

4847
// Perform injection
4948
Injector.init(getRootModule(), this);
@@ -66,6 +65,6 @@ public BootstrapApplication(final Instrumentation instrumentation) {
6665
}
6766

6867
public static BootstrapApplication getInstance() {
69-
return instance;
68+
return sInstance;
7069
}
7170
}

app/src/main/java/com/donnfelker/android/bootstrap/BootstrapServiceProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
*/
1818
public class BootstrapServiceProvider {
1919

20-
@Inject ApiKeyProvider keyProvider;
21-
@Inject UserAgentProvider userAgentProvider;
20+
@Inject ApiKeyProvider mKeyProvider;
21+
@Inject UserAgentProvider mUserAgentProvider;
2222

2323
/**
2424
* Get service for configured key provider
@@ -30,6 +30,6 @@ public class BootstrapServiceProvider {
3030
* @throws AccountsException
3131
*/
3232
public BootstrapService getService(Activity activity) throws IOException, AccountsException {
33-
return new BootstrapService(keyProvider.getAuthKey(activity), userAgentProvider);
33+
return new BootstrapService(mKeyProvider.getAuthKey(activity), mUserAgentProvider);
3434
}
3535
}

app/src/main/java/com/donnfelker/android/bootstrap/Injector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import dagger.ObjectGraph;
44

55
public final class Injector {
6-
public static ObjectGraph objectGraph = null;
76

7+
public static ObjectGraph objectGraph = null; //TODO why is this public?
88

99
public static void init(final Object rootModule) {
1010

app/src/main/java/com/donnfelker/android/bootstrap/authenticator/AccountAuthenticatorService.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,24 @@
88
import static android.accounts.AccountManager.ACTION_AUTHENTICATOR_INTENT;
99

1010
/**
11-
* Authenticator service that returns a subclass of AbstractAccountAuthenticator in onBind()
11+
* Authenticator service that returns a subclass of AbstractAccountAuthenticator in onBind().
1212
*/
1313
public class AccountAuthenticatorService extends Service {
1414

15-
private static BootstrapAccountAuthenticator AUTHENTICATOR = null;
15+
private static BootstrapAccountAuthenticator sAuthenticator = null;
1616

1717
@Override
18-
public IBinder onBind(Intent intent) {
19-
return ACTION_AUTHENTICATOR_INTENT.equals(intent.getAction()) ? getAuthenticator().getIBinder() : null;
18+
public IBinder onBind(final Intent intent) {
19+
if (intent != null && ACTION_AUTHENTICATOR_INTENT.equals(intent.getAction())) {
20+
return getAuthenticator().getIBinder();
21+
}
22+
return null;
2023
}
2124

2225
private BootstrapAccountAuthenticator getAuthenticator() {
23-
if (AUTHENTICATOR == null)
24-
AUTHENTICATOR = new BootstrapAccountAuthenticator(this);
25-
return AUTHENTICATOR;
26+
if (sAuthenticator == null) {
27+
sAuthenticator = new BootstrapAccountAuthenticator(this);
28+
}
29+
return sAuthenticator;
2630
}
2731
}

app/src/main/java/com/donnfelker/android/bootstrap/authenticator/ApiKeyProvider.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,33 @@
88
import android.app.Activity;
99
import android.os.Bundle;
1010

11-
import com.donnfelker.android.bootstrap.core.Constants;
12-
1311
import java.io.IOException;
1412

1513
import javax.inject.Inject;
1614

1715
import static android.accounts.AccountManager.KEY_AUTHTOKEN;
16+
import static com.donnfelker.android.bootstrap.core.Constants.Auth.AUTHTOKEN_TYPE;
17+
import static com.donnfelker.android.bootstrap.core.Constants.Auth.BOOTSTRAP_ACCOUNT_TYPE;
1818

1919
/**
2020
* Bridge class that obtains a API key for the currently configured account
2121
*/
2222
public class ApiKeyProvider {
2323

24-
@Inject AccountManager accountManager;
24+
@Inject protected AccountManager mAccountManager;
2525

2626
/**
27-
* This call blocks, so shouldn't be called on the UI thread
27+
* This call blocks, so shouldn't be called on the UI thread.
2828
*
29-
* @return API key to be used for authorization with a {@link com.donnfelker.android.bootstrap.core.BootstrapService} instance
29+
* @return API key to be used for authorization with a
30+
* {@link com.donnfelker.android.bootstrap.core.BootstrapService} instance
3031
* @throws AccountsException
3132
* @throws IOException
3233
*/
33-
public String getAuthKey(Activity activity) throws AccountsException, IOException {
34-
AccountManagerFuture<Bundle> accountManagerFuture = accountManager.getAuthTokenByFeatures(Constants.Auth.BOOTSTRAP_ACCOUNT_TYPE,
35-
Constants.Auth.AUTHTOKEN_TYPE, new String[0], activity, null, null, null, null);
34+
public String getAuthKey(final Activity activity) throws AccountsException, IOException {
35+
final AccountManagerFuture<Bundle> accountManagerFuture
36+
= mAccountManager.getAuthTokenByFeatures(BOOTSTRAP_ACCOUNT_TYPE,
37+
AUTHTOKEN_TYPE, new String[0], activity, null, null, null, null);
3638

3739
return accountManagerFuture.getResult().getString(KEY_AUTHTOKEN);
3840
}

app/src/main/java/com/donnfelker/android/bootstrap/authenticator/BootstrapAccountAuthenticator.java

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,43 +25,49 @@ class BootstrapAccountAuthenticator extends AbstractAccountAuthenticator {
2525

2626
private static final String DESCRIPTION_CLIENT = "Bootstrap for Android";
2727

28-
private final Context context;
28+
private final Context mContext;
2929

30-
public BootstrapAccountAuthenticator(Context context) {
30+
public BootstrapAccountAuthenticator(final Context context) {
3131
super(context);
3232

33-
this.context = context;
33+
mContext = context;
3434
}
3535

3636
/*
37-
* The user has requested to add a new account to the system. We return an intent that will launch our login screen
38-
* if the user has not logged in yet, otherwise our activity will just pass the user's credentials on to the account
39-
* manager.
37+
* The user has requested to add a new account to the system. We return an intent that will
38+
* launch our login screen if the user has not logged in yet, otherwise our activity will
39+
* just pass the user's credentials on to the account manager.
4040
*/
4141
@Override
42-
public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType,
43-
String[] requiredFeatures, Bundle options) throws NetworkErrorException {
44-
final Intent intent = new Intent(context, BootstrapAuthenticatorActivity.class);
42+
public Bundle addAccount(final AccountAuthenticatorResponse response, final String accountType,
43+
final String authTokenType, final String[] requiredFeatures,
44+
final Bundle options) throws NetworkErrorException {
45+
final Intent intent = new Intent(mContext, BootstrapAuthenticatorActivity.class);
4546
intent.putExtra(PARAM_AUTHTOKEN_TYPE, authTokenType);
4647
intent.putExtra(KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
48+
4749
final Bundle bundle = new Bundle();
4850
bundle.putParcelable(KEY_INTENT, intent);
51+
4952
return bundle;
5053
}
5154

5255
@Override
53-
public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account account, Bundle options) {
56+
public Bundle confirmCredentials(final AccountAuthenticatorResponse response,
57+
final Account account, final Bundle options) {
5458
return null;
5559
}
5660

5761
@Override
58-
public Bundle editProperties(AccountAuthenticatorResponse response, String accountType) {
62+
public Bundle editProperties(final AccountAuthenticatorResponse response,
63+
final String accountType) {
5964
return null;
6065
}
6166

6267
/**
6368
* This method gets called when the
64-
* {@link com.donnfelker.android.bootstrap.authenticator.ApiKeyProvider#getAuthKey()} methods gets invoked.
69+
* {@link com.donnfelker.android.bootstrap.authenticator.ApiKeyProvider#getAuthKey()}
70+
* methods gets invoked.
6571
* This happens on a different process, so debugging it can be a beast.
6672
*
6773
* @param response
@@ -72,35 +78,39 @@ public Bundle editProperties(AccountAuthenticatorResponse response, String accou
7278
* @throws NetworkErrorException
7379
*/
7480
@Override
75-
public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType,
76-
Bundle options) throws NetworkErrorException {
81+
public Bundle getAuthToken(final AccountAuthenticatorResponse response,
82+
final Account account, final String authTokenType,
83+
final Bundle options) throws NetworkErrorException {
7784

7885
Ln.d("Attempting to get authToken");
7986

80-
String authToken = AccountManager.get(context).peekAuthToken(account, authTokenType);
81-
Bundle bundle = new Bundle();
87+
final String authToken = AccountManager.get(mContext).peekAuthToken(account, authTokenType);
88+
89+
final Bundle bundle = new Bundle();
8290
bundle.putString(KEY_ACCOUNT_NAME, account.name);
8391
bundle.putString(KEY_ACCOUNT_TYPE, Constants.Auth.BOOTSTRAP_ACCOUNT_TYPE);
8492
bundle.putString(KEY_AUTHTOKEN, authToken);
93+
8594
return bundle;
8695
}
8796

8897
@Override
89-
public String getAuthTokenLabel(String authTokenType) {
98+
public String getAuthTokenLabel(final String authTokenType) {
9099
return authTokenType.equals(Constants.Auth.AUTHTOKEN_TYPE) ? authTokenType : null;
91100
}
92101

93102
@Override
94-
public Bundle hasFeatures(AccountAuthenticatorResponse response, Account account, String[] features)
95-
throws NetworkErrorException {
103+
public Bundle hasFeatures(final AccountAuthenticatorResponse response, final Account account,
104+
final String[] features) throws NetworkErrorException {
96105
final Bundle result = new Bundle();
97106
result.putBoolean(KEY_BOOLEAN_RESULT, false);
98107
return result;
99108
}
100109

101110
@Override
102-
public Bundle updateCredentials(AccountAuthenticatorResponse response, Account account, String authTokenType,
103-
Bundle options) {
111+
public Bundle updateCredentials(final AccountAuthenticatorResponse response,
112+
final Account account, final String authTokenType,
113+
final Bundle options) {
104114
return null;
105115
}
106116
}

0 commit comments

Comments
 (0)