Skip to content

Commit

Permalink
Upgrading from butterknife to AndroidAnnotations, making the code eve…
Browse files Browse the repository at this point in the history
…n cleaner. This even fixes the Functional Tests
  • Loading branch information
aristides committed Jun 19, 2013
1 parent de5f164 commit f8d7538
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 102 deletions.
4 changes: 2 additions & 2 deletions app/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</intent-filter>
</activity>

<activity android:name=".ui.BootstrapTimerActivity"
<activity android:name=".ui.BootstrapTimerActivity_"
android:configChanges="orientation|keyboardHidden|screenSize" android:label="@string/app_name"
android:launchMode="singleTop"/>

Expand All @@ -53,7 +53,7 @@
</service>

<activity
android:name=".authenticator.BootstrapAuthenticatorActivity"
android:name=".authenticator.BootstrapAuthenticatorActivity_"
android:excludeFromRecents="true" >

<!--
Expand Down
11 changes: 3 additions & 8 deletions app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<dagger.version>1.0.0</dagger.version>
<otto.version>1.3.3</otto.version>
<gson.version>2.2.3</gson.version>
<androidannotations.version>2.7.1</androidannotations.version>
<androidannotations.version>3.0-SNAPSHOT</androidannotations.version>
</properties>

<dependencies>
Expand All @@ -37,13 +37,13 @@
</dependency>
<!-- Order here is important: Androidannotations before the Dagger -->
<dependency>
<groupId>com.googlecode.androidannotations</groupId>
<groupId>org.androidannotations</groupId>
<artifactId>androidannotations</artifactId>
<version>${androidannotations.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.googlecode.androidannotations</groupId>
<groupId>org.androidannotations</groupId>
<artifactId>androidannotations-api</artifactId>
<version>${androidannotations.version}</version>
</dependency>
Expand All @@ -58,11 +58,6 @@
<version>${dagger.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.jakewharton</groupId>
<artifactId>butterknife</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>com.actionbarsherlock</groupId>
<artifactId>actionbarsherlock</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import android.accounts.AccountManager;
import android.content.Context;
import com.donnfelker.android.bootstrap.authenticator.BootstrapAuthenticatorActivity;
import com.donnfelker.android.bootstrap.authenticator.BootstrapAuthenticatorActivity_;
import com.donnfelker.android.bootstrap.authenticator.LogoutService;
import com.donnfelker.android.bootstrap.core.TimerService;
import com.donnfelker.android.bootstrap.ui.*;
Expand All @@ -22,9 +22,9 @@

injects = {
BootstrapApplication.class,
BootstrapAuthenticatorActivity.class,
BootstrapAuthenticatorActivity_.class,
CarouselActivity_.class,
BootstrapTimerActivity.class,
BootstrapTimerActivity_.class,
CheckInsListFragment.class,
NewsActivity_.class,
NewsListFragment.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import android.text.Html;
import android.text.TextWatcher;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
Expand All @@ -45,25 +44,22 @@
import com.donnfelker.android.bootstrap.util.Strings;
import com.github.kevinsawicki.http.HttpRequest;
import com.github.kevinsawicki.wishlist.Toaster;
import com.donnfelker.android.bootstrap.R.id;
import com.donnfelker.android.bootstrap.R.layout;
import com.donnfelker.android.bootstrap.R.string;
import com.donnfelker.android.bootstrap.ui.TextWatcherAdapter;
import com.google.gson.Gson;

import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

import butterknife.InjectView;
import butterknife.Views;

import static com.donnfelker.android.bootstrap.core.Constants.Http.USERNAME;
import static com.donnfelker.android.bootstrap.core.Constants.Http.PASSWORD;
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

/**
* Activity to authenticate the user against an API (example API on Parse.com)
*/
@EActivity(layout.login_activity)
public class BootstrapAuthenticatorActivity extends SherlockAccountAuthenticatorActivity {

/**
Expand All @@ -89,9 +85,10 @@ public class BootstrapAuthenticatorActivity extends SherlockAccountAuthenticator

private AccountManager accountManager;

@InjectView(id.et_email) AutoCompleteTextView emailText;
@InjectView(id.et_password) EditText passwordText;
@InjectView(id.b_signin) Button signinButton;
@ViewById AutoCompleteTextView et_email;
@ViewById EditText et_password;
@ViewById Button b_signin;
@ViewById TextView tv_signup;

private TextWatcher watcher = validationTextWatcher();

Expand Down Expand Up @@ -133,44 +130,42 @@ public void onCreate(Bundle bundle) {
requestNewAccount = email == null;
confirmCredentials = intent.getBooleanExtra(PARAM_CONFIRMCREDENTIALS,
false);
}

setContentView(layout.login_activity);

Views.inject(this);

emailText.setAdapter(new ArrayAdapter<String>(this,
@AfterViews
protected void configureAdapter(){
et_email.setAdapter(new ArrayAdapter<String>(this,
simple_dropdown_item_1line, userEmailAccounts()));

passwordText.setOnKeyListener(new OnKeyListener() {
et_password.setOnKeyListener(new OnKeyListener() {

public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event != null && ACTION_DOWN == event.getAction()
&& keyCode == KEYCODE_ENTER && signinButton.isEnabled()) {
handleLogin(signinButton);
&& keyCode == KEYCODE_ENTER && b_signin.isEnabled()) {
handleLogin(b_signin);
return true;
}
return false;
}
});

passwordText.setOnEditorActionListener(new OnEditorActionListener() {
et_password.setOnEditorActionListener(new OnEditorActionListener() {

public boolean onEditorAction(TextView v, int actionId,
KeyEvent event) {
if (actionId == IME_ACTION_DONE && signinButton.isEnabled()) {
handleLogin(signinButton);
KeyEvent event) {
if (actionId == IME_ACTION_DONE && b_signin.isEnabled()) {
handleLogin(b_signin);
return true;
}
return false;
}
});

emailText.addTextChangedListener(watcher);
passwordText.addTextChangedListener(watcher);

TextView signupText = (TextView) findViewById(id.tv_signup);
signupText.setMovementMethod(LinkMovementMethod.getInstance());
signupText.setText(Html.fromHtml(getString(string.signup_link)));
et_email.addTextChangedListener(watcher);
et_password.addTextChangedListener(watcher);
tv_signup.setMovementMethod(LinkMovementMethod.getInstance());
tv_signup.setText(Html.fromHtml(getString(string.signup_link)));
}

private List<String> userEmailAccounts() {
Expand All @@ -197,8 +192,8 @@ protected void onResume() {
}

private void updateUIWithValidation() {
boolean populated = populated(emailText) && populated(passwordText);
signinButton.setEnabled(populated);
boolean populated = populated(et_email) && populated(et_password);
b_signin.setEnabled(populated);
}

private boolean populated(EditText editText) {
Expand Down Expand Up @@ -233,8 +228,8 @@ public void handleLogin(View view) {
return;

if (requestNewAccount)
email = emailText.getText().toString();
password = passwordText.getText().toString();
email = et_email.getText().toString();
password = et_password.getText().toString();
showProgress();

authenticationTask = new SafeAsyncTask<Boolean>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.MenuItem;
import com.donnfelker.android.bootstrap.BootstrapApplication;
import com.googlecode.androidannotations.annotations.EActivity;
import com.googlecode.androidannotations.annotations.OptionsItem;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.OptionsItem;

import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,28 @@
import com.donnfelker.android.bootstrap.core.TimerTickEvent;
import javax.inject.Inject;

import com.googlecode.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;
import com.squareup.otto.Bus;
import com.squareup.otto.Subscribe;

import butterknife.InjectView;
import butterknife.Views;

@EActivity(R.layout.bootstrap_timer)
public class BootstrapTimerActivity extends BootstrapFragmentActivity implements View.OnClickListener {
public class BootstrapTimerActivity extends BootstrapFragmentActivity {

@Inject Bus BUS;

@InjectView(R.id.chronometer) protected TextView chronometer;
@InjectView(R.id.start) protected Button start;
@InjectView(R.id.stop) protected Button stop;
@InjectView(R.id.pause) protected Button pause;
@InjectView(R.id.resume) protected Button resume;
@ViewById protected TextView chronometer;
@ViewById protected Button start;
@ViewById protected Button stop;
@ViewById protected Button pause;
@ViewById protected Button resume;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setTitle(R.string.timer);

start.setOnClickListener(this);
stop.setOnClickListener(this);
pause.setOnClickListener(this);
resume.setOnClickListener(this);

}

@Override
Expand All @@ -63,28 +56,12 @@ protected void onPause() {
BUS.unregister(this);
}

@Override
public void onClick(View v) {
switch(v.getId()) {
case R.id.start:
startTimer();
break;
case R.id.stop:
produceStopEvent();
break;
case R.id.pause:
producePauseEvent();
break;
case R.id.resume:
produceResumeEvent();
break;
}
}

/**
* Starts the timer service
*/
private void startTimer() {
@Click
void startClicked(){
if(isTimerServiceRunning() == false) {
final Intent i = new Intent(this, TimerService.class);
startService(i);
Expand All @@ -98,24 +75,31 @@ private void startTimer() {
/**
* Posts a {@link StopTimerEvent} message to the {@link Bus}
*/
private void produceStopEvent() {
@Click
void stopClicked(){
BUS.post(new StopTimerEvent());
}

/**
* Posts a {@link PauseTimerEvent} message to the {@link Bus}
*/
private void producePauseEvent() {
@Click
void pauseClicked(){
BUS.post(new PauseTimerEvent());
}

/**
* Posts a {@link ResumeTimerEvent} message to the {@link Bus}
*/
private void produceResumeEvent() {
@Click
void resumeClicked(){
BUS.post(new ResumeTimerEvent());
}

private void produceResumeEvent() {

}

@Subscribe
public void onTimerPausedEvent(TimerPausedEvent event) {
if(event.isTimerIsPaused()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import com.donnfelker.android.bootstrap.R;
import com.donnfelker.android.bootstrap.R.id;

import com.googlecode.androidannotations.annotations.AfterViews;
import com.googlecode.androidannotations.annotations.EActivity;
import com.googlecode.androidannotations.annotations.OptionsItem;
import com.googlecode.androidannotations.annotations.ViewById;
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.OptionsItem;
import org.androidannotations.annotations.ViewById;
import com.viewpagerindicator.TitlePageIndicator;

/**
Expand Down Expand Up @@ -44,7 +44,7 @@ protected void configureAdapter(){

@OptionsItem
boolean timerSelected() {
final Intent i = new Intent(this, BootstrapTimerActivity.class);
final Intent i = new Intent(this, BootstrapTimerActivity_.class);
startActivity(i);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import com.donnfelker.android.bootstrap.R;
import com.donnfelker.android.bootstrap.core.News;

import com.googlecode.androidannotations.annotations.AfterViews;
import com.googlecode.androidannotations.annotations.EActivity;
import com.googlecode.androidannotations.annotations.ViewById;
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

@EActivity(R.layout.news)
public class NewsActivity extends BootstrapActivity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import com.donnfelker.android.bootstrap.core.User;
import javax.inject.Inject;

import com.googlecode.androidannotations.annotations.AfterViews;
import com.googlecode.androidannotations.annotations.EActivity;
import com.googlecode.androidannotations.annotations.ViewById;
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

@EActivity(R.layout.user_view)
public class UserActivity extends BootstrapActivity {
Expand Down
Loading

0 comments on commit f8d7538

Please sign in to comment.