Skip to content

Commit 5f86bac

Browse files
committed
Updating activities, Adding Strings, Ln and SafeAsyncTask as well as updating InjectExtra to normal getExtra call. Also cleaned up various imports and added new SherlockAccountAuthenticatorActivity from rtyley source of roboguice-sherlock.
1 parent 253a01e commit 5f86bac

25 files changed

+949
-95
lines changed

app/pom.xml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,6 @@
3131
<artifactId>gson</artifactId>
3232
<version>2.2.2</version>
3333
</dependency>
34-
<dependency>
35-
<groupId>com.github.rtyley</groupId>
36-
<artifactId>roboguice-sherlock</artifactId>
37-
<version>1.5</version>
38-
</dependency>
39-
<dependency>
40-
<groupId>org.roboguice</groupId>
41-
<artifactId>roboguice</artifactId>
42-
<version>2.0</version>
43-
</dependency>
4434
<dependency>
4535
<groupId>com.squareup</groupId>
4636
<artifactId>dagger</artifactId>
@@ -52,6 +42,11 @@
5242
<version>${dagger.version}</version>
5343
<optional>true</optional>
5444
</dependency>
45+
<dependency>
46+
<groupId>com.jakewharton</groupId>
47+
<artifactId>butterknife</artifactId>
48+
<version>1.2.0</version>
49+
</dependency>
5550
<dependency>
5651
<groupId>com.actionbarsherlock</groupId>
5752
<artifactId>library</artifactId>

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

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
import android.content.Context;
1010

1111
import com.github.kevinsawicki.http.HttpRequest;
12-
import com.google.inject.Injector;
13-
import com.google.inject.Stage;
14-
15-
import roboguice.RoboGuice;
1612

1713
/**
1814
* Android Bootstrap application
@@ -38,12 +34,7 @@ public BootstrapApplication(final Context context) {
3834
attachBaseContext(context);
3935
}
4036

41-
@Override
42-
public void onCreate() {
43-
super.onCreate();
4437

45-
setApplicationInjector(this);
46-
}
4738

4839
/**
4940
* Create main application
@@ -55,14 +46,5 @@ public BootstrapApplication(final Instrumentation instrumentation) {
5546
attachBaseContext(instrumentation.getTargetContext());
5647
}
5748

58-
/**
59-
* Sets the application injector. Using the {@link RoboGuice#newDefaultRoboModule} as well as a
60-
* custom binding module {@link BootstrapModule} to set up your application module
61-
* @param application
62-
* @return
63-
*/
64-
public static Injector setApplicationInjector(Application application) {
65-
return RoboGuice.setBaseApplicationInjector(application, Stage.DEVELOPMENT, RoboGuice.newDefaultRoboModule
66-
(application), new BootstrapModule());
67-
}
49+
6850
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import com.donnfelker.android.bootstrap.authenticator.ApiKeyProvider;
77
import com.donnfelker.android.bootstrap.core.BootstrapService;
88
import com.donnfelker.android.bootstrap.core.UserAgentProvider;
9-
import com.google.inject.Inject;
9+
import javax.inject.Inject;
1010

1111
import java.io.IOException;
1212

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import android.os.Bundle;
1212

1313
import com.donnfelker.android.bootstrap.core.Constants;
14-
import com.google.inject.Inject;
14+
import javax.inject.Inject;
1515

1616
import java.io.IOException;
1717

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

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,32 +40,30 @@
4040

4141
import com.donnfelker.android.bootstrap.core.Constants;
4242
import com.donnfelker.android.bootstrap.core.User;
43+
import com.donnfelker.android.bootstrap.util.Ln;
44+
import com.donnfelker.android.bootstrap.util.SafeAsyncTask;
45+
import com.donnfelker.android.bootstrap.util.Strings;
4346
import com.github.kevinsawicki.http.HttpRequest;
4447
import com.github.kevinsawicki.wishlist.Toaster;
4548
import com.donnfelker.android.bootstrap.R.id;
4649
import com.donnfelker.android.bootstrap.R.layout;
4750
import com.donnfelker.android.bootstrap.R.string;
4851
import com.donnfelker.android.bootstrap.ui.TextWatcherAdapter;
49-
import com.github.rtyley.android.sherlock.roboguice.activity.RoboSherlockAccountAuthenticatorActivity;
5052
import com.google.gson.Gson;
5153

5254
import java.net.URLEncoder;
5355
import java.util.ArrayList;
5456
import java.util.List;
5557

56-
import roboguice.inject.InjectView;
57-
import roboguice.util.Ln;
58-
import roboguice.util.RoboAsyncTask;
59-
import roboguice.util.Strings;
58+
import butterknife.InjectView;
6059

6160
import static com.donnfelker.android.bootstrap.core.Constants.Http.USERNAME;
6261
import static com.donnfelker.android.bootstrap.core.Constants.Http.PASSWORD;
6362

6463
/**
6564
* Activity to authenticate the user against an API (example API on Parse.com)
6665
*/
67-
public class BootstrapAuthenticatorActivity extends
68-
RoboSherlockAccountAuthenticatorActivity {
66+
public class BootstrapAuthenticatorActivity extends SherlockAccountAuthenticatorActivity {
6967

7068
/**
7169
* PARAM_CONFIRMCREDENTIALS
@@ -90,18 +88,13 @@ public class BootstrapAuthenticatorActivity extends
9088

9189
private AccountManager accountManager;
9290

93-
@InjectView(id.et_email)
94-
private AutoCompleteTextView emailText;
95-
96-
@InjectView(id.et_password)
97-
private EditText passwordText;
98-
99-
@InjectView(id.b_signin)
100-
private Button signinButton;
91+
@InjectView(id.et_email) private AutoCompleteTextView emailText;
92+
@InjectView(id.et_password) private EditText passwordText;
93+
@InjectView(id.b_signin) private Button signinButton;
10194

10295
private TextWatcher watcher = validationTextWatcher();
10396

104-
private RoboAsyncTask<Boolean> authenticationTask;
97+
private SafeAsyncTask<Boolean> authenticationTask;
10598
private String authToken;
10699
private String authTokenType;
107100

@@ -241,7 +234,7 @@ public void handleLogin(View view) {
241234
password = passwordText.getText().toString();
242235
showProgress();
243236

244-
authenticationTask = new RoboAsyncTask<Boolean>(this) {
237+
authenticationTask = new SafeAsyncTask<Boolean>() {
245238
public Boolean call() throws Exception {
246239

247240
final String query = String.format("%s=%s&%s=%s", PARAM_USERNAME, email, PARAM_PASSWORD, password);

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
import android.util.Log;
88

99
import com.donnfelker.android.bootstrap.core.Constants;
10-
import com.google.inject.Inject;
10+
import com.donnfelker.android.bootstrap.util.SafeAsyncTask;
11+
12+
import javax.inject.Inject;
1113

1214
import java.util.concurrent.Callable;
1315
import java.util.concurrent.Executor;
1416

15-
import roboguice.inject.ContextSingleton;
16-
import roboguice.util.RoboAsyncTask;
1717

18-
@ContextSingleton
18+
// TODO-dagger: Mark this a s singleton of some sort, maybe.
19+
// @ContextSingleton
1920
public class LogoutService {
2021

2122
@Inject protected Context context;
@@ -28,12 +29,13 @@ public void logout(final Runnable onSuccess) {
2829
new LogoutTask(context, onSuccess).execute();
2930
}
3031

31-
private static class LogoutTask extends RoboAsyncTask<Boolean> {
32+
private static class LogoutTask extends SafeAsyncTask<Boolean> {
3233

34+
private final Context context;
3335
private Runnable onSuccess;
3436

3537
protected LogoutTask(Context context, Runnable onSuccess) {
36-
super(context);
38+
this.context = context;
3739
this.onSuccess = onSuccess;
3840
}
3941

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package com.donnfelker.android.bootstrap.authenticator;
2+
3+
/*
4+
* Copyright (C) 2009 The Android Open Source Project
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import android.accounts.AccountAuthenticatorResponse;
20+
import android.accounts.AccountManager;
21+
import android.app.Activity;
22+
import android.content.Intent;
23+
import android.os.Bundle;
24+
import com.actionbarsherlock.app.SherlockActivity;
25+
26+
/**
27+
* Base class for implementing an Activity that is used to help implement an
28+
* AbstractAccountAuthenticator. If the AbstractAccountAuthenticator needs to use an activity
29+
* to handle the request then it can have the activity extend SherlockAccountAuthenticatorActivity.
30+
* The AbstractAccountAuthenticator passes in the response to the intent using the following:
31+
* <pre>
32+
* intent.putExtra({@link android.accounts.AccountManager#KEY_ACCOUNT_AUTHENTICATOR_RESPONSE}, response);
33+
* </pre>
34+
* The activity then sets the result that is to be handed to the response via
35+
* {@link #setAccountAuthenticatorResult(android.os.Bundle)}.
36+
* This result will be sent as the result of the request when the activity finishes. If this
37+
* is never set or if it is set to null then error {@link android.accounts.AccountManager#ERROR_CODE_CANCELED}
38+
* will be called on the response.
39+
*/
40+
public class SherlockAccountAuthenticatorActivity extends SherlockActivity {
41+
private AccountAuthenticatorResponse mAccountAuthenticatorResponse = null;
42+
private Bundle mResultBundle = null;
43+
44+
/**
45+
* Set the result that is to be sent as the result of the request that caused this
46+
* Activity to be launched. If result is null or this method is never called then
47+
* the request will be canceled.
48+
* @param result this is returned as the result of the AbstractAccountAuthenticator request
49+
*/
50+
public final void setAccountAuthenticatorResult(Bundle result) {
51+
mResultBundle = result;
52+
}
53+
54+
/**
55+
* Retreives the AccountAuthenticatorResponse from either the intent of the icicle, if the
56+
* icicle is non-zero.
57+
* @param icicle the save instance data of this Activity, may be null
58+
*/
59+
protected void onCreate(Bundle icicle) {
60+
super.onCreate(icicle);
61+
62+
mAccountAuthenticatorResponse =
63+
getIntent().getParcelableExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE);
64+
65+
if (mAccountAuthenticatorResponse != null) {
66+
mAccountAuthenticatorResponse.onRequestContinued();
67+
}
68+
}
69+
70+
/**
71+
* Sends the result or a Constants.ERROR_CODE_CANCELED error if a result isn't present.
72+
*/
73+
public void finish() {
74+
if (mAccountAuthenticatorResponse != null) {
75+
// send the result bundle back if set, otherwise send an error.
76+
if (mResultBundle != null) {
77+
mAccountAuthenticatorResponse.onResult(mResultBundle);
78+
} else {
79+
mAccountAuthenticatorResponse.onError(AccountManager.ERROR_CODE_CANCELED,
80+
"canceled");
81+
}
82+
mAccountAuthenticatorResponse = null;
83+
}
84+
super.finish();
85+
}
86+
}

app/src/main/java/com/donnfelker/android/bootstrap/core/AvatarLoader.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414

1515
import com.actionbarsherlock.app.ActionBar;
1616
import com.donnfelker.android.bootstrap.R;
17+
import com.donnfelker.android.bootstrap.util.SafeAsyncTask;
1718
import com.github.kevinsawicki.http.HttpRequest;
18-
import com.google.inject.Inject;
19+
import javax.inject.Inject;
1920

2021
import java.io.File;
2122
import java.io.FileOutputStream;
@@ -26,7 +27,6 @@
2627
import java.util.concurrent.Executors;
2728
import java.util.concurrent.atomic.AtomicReference;
2829

29-
import roboguice.util.RoboAsyncTask;
3030

3131
/**
3232
* Avatar utilities
@@ -40,13 +40,13 @@ public class AvatarLoader {
4040
private static final int CACHE_SIZE = 75;
4141

4242
private static abstract class FetchAvatarTask extends
43-
RoboAsyncTask<BitmapDrawable> {
43+
SafeAsyncTask<BitmapDrawable> {
4444

4545
private static final Executor EXECUTOR = Executors
4646
.newFixedThreadPool(1);
4747

4848
private FetchAvatarTask(Context context) {
49-
super(context, EXECUTOR);
49+
super(EXECUTOR);
5050
}
5151

5252
@Override

app/src/main/java/com/donnfelker/android/bootstrap/core/TimerService.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.app.Notification;
44
import android.app.NotificationManager;
55
import android.app.PendingIntent;
6+
import android.app.Service;
67
import android.content.Intent;
78
import android.os.Handler;
89
import android.os.IBinder;
@@ -12,17 +13,16 @@
1213

1314
import com.donnfelker.android.bootstrap.R;
1415
import com.donnfelker.android.bootstrap.ui.BootstrapTimerActivity;
15-
import com.google.inject.Inject;
16+
import javax.inject.Inject;
17+
18+
import com.donnfelker.android.bootstrap.util.Ln;
1619
import com.squareup.otto.Bus;
1720
import com.squareup.otto.Produce;
1821
import com.squareup.otto.Subscribe;
1922

20-
import roboguice.service.RoboService;
21-
import roboguice.util.Ln;
22-
2323
import static com.donnfelker.android.bootstrap.core.Constants.Notification.TIMER_NOTIFICATION_ID;
2424

25-
public class TimerService extends RoboService {
25+
public class TimerService extends Service {
2626

2727
@Inject protected Bus BUS;
2828
@Inject private NotificationManager notificationManager;

app/src/main/java/com/donnfelker/android/bootstrap/core/UserAgentProvider.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@
66
import android.os.Build;
77
import android.telephony.TelephonyManager;
88

9-
import com.google.inject.Inject;
10-
import com.google.inject.Provider;
9+
import com.donnfelker.android.bootstrap.util.Ln;
10+
import com.donnfelker.android.bootstrap.util.Strings;
11+
12+
import javax.inject.Inject;
13+
import javax.inject.Provider;
14+
1115

1216
import java.lang.reflect.Method;
1317
import java.util.ArrayList;
1418
import java.util.Locale;
1519

16-
import roboguice.util.Ln;
17-
import roboguice.util.Strings;
1820

1921
public class UserAgentProvider implements Provider<String> {
2022
@Inject protected Application app;

app/src/main/java/com/donnfelker/android/bootstrap/ui/BootstrapActivity.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,23 @@
44
import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP;
55
import android.content.Intent;
66

7+
import com.actionbarsherlock.app.SherlockActivity;
78
import com.actionbarsherlock.view.MenuItem;
8-
import com.github.rtyley.android.sherlock.roboguice.activity.RoboSherlockActivity;
9+
10+
import butterknife.Views;
911

1012
/**
1113
* Base activity for a Bootstrap activity which does not use fragments.
1214
*/
13-
public abstract class BootstrapActivity extends RoboSherlockActivity {
15+
public abstract class BootstrapActivity extends SherlockActivity {
16+
17+
@Override
18+
public void setContentView(int layoutResId) {
19+
super.setContentView(layoutResId);
20+
21+
// Used to inject views with the Butterknife library
22+
Views.inject(this);
23+
}
1424

1525
@Override
1626
public boolean onOptionsItemSelected(MenuItem item) {

0 commit comments

Comments
 (0)