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
  • Loading branch information
aristides committed Jun 18, 2013
1 parent a4c6ec2 commit de5f164
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 42 deletions.
4 changes: 2 additions & 2 deletions app/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
android:debuggable="true">

<activity
android:name=".ui.CarouselActivity"
android:name=".ui.CarouselActivity_"
android:configChanges="orientation|keyboardHidden|screenSize" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
injects = {
BootstrapApplication.class,
BootstrapAuthenticatorActivity.class,
CarouselActivity.class,
CarouselActivity_.class,
BootstrapTimerActivity.class,
CheckInsListFragment.class,
NewsActivity_.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
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 static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP;

/**
* Base activity for a Bootstrap activity which does not use fragments.
*/
@EActivity
public abstract class BootstrapActivity extends SherlockActivity {

@Override
Expand All @@ -21,17 +24,15 @@ protected void onCreate(Bundle savedInstanceState) {
BootstrapApplication.getInstance().inject(this);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home: // This is the home button in the top left corner of the screen.
// Dont call finish! Because activity could have been started by an outside activity and the home button would not operated as expected!
Intent homeIntent = new Intent(this, CarouselActivity.class);
homeIntent.addFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP);
startActivity(homeIntent);
return true;
default:
return super.onOptionsItemSelected(item);
}
/**
* This is the home button in the top left corner of the screen.
* Dont call finish! Because activity could have been started by an outside activity and the home button would not operated as expected!
* */
@OptionsItem
boolean homeSelected() {
Intent homeIntent = new Intent(this, CarouselActivity_.class);
homeIntent.addFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP);
startActivity(homeIntent);
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class BootstrapPagerAdapter extends FragmentPagerAdapter {
private final Resources resources;

/**
* Create pager adapter
* Create vp_pages adapter
*
* @param resources
* @param fragmentManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
import com.donnfelker.android.bootstrap.core.TimerService;
import com.donnfelker.android.bootstrap.core.TimerTickEvent;
import javax.inject.Inject;

import com.googlecode.androidannotations.annotations.EActivity;
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 {

@Inject Bus BUS;
Expand All @@ -37,8 +40,6 @@ public class BootstrapTimerActivity extends BootstrapFragmentActivity implements
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.bootstrap_timer);

setTitle(R.string.timer);

start.setOnClickListener(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,50 @@

package com.donnfelker.android.bootstrap.ui;

import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;

import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.Window;
import com.donnfelker.android.bootstrap.BootstrapApplication;
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 com.viewpagerindicator.TitlePageIndicator;

import butterknife.InjectView;
import butterknife.Views;

/**
* Activity to view the carousel and view pager indicator with fragments.
* Activity to view the carousel and view vp_pages tpi_header with fragments.
*/
@EActivity(R.layout.carousel_view)
public class CarouselActivity extends BootstrapFragmentActivity {

@InjectView(id.tpi_header) TitlePageIndicator indicator;
@InjectView(id.vp_pages) ViewPager pager;
@ViewById TitlePageIndicator tpi_header;
@ViewById ViewPager vp_pages;

@Override
protected void onCreate(Bundle savedInstanceState) {

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

super.onCreate(savedInstanceState);
setContentView(R.layout.carousel_view);
}

pager.setAdapter(new BootstrapPagerAdapter(getResources(), getSupportFragmentManager()));
@AfterViews
protected void configureAdapter(){
vp_pages.setAdapter(new BootstrapPagerAdapter(getResources(), getSupportFragmentManager()));

indicator.setViewPager(pager);
pager.setCurrentItem(1);
tpi_header.setViewPager(vp_pages);
vp_pages.setCurrentItem(1);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case id.timer:
final Intent i = new Intent(this, BootstrapTimerActivity.class);
startActivity(i);
return true;
default:
return super.onOptionsItemSelected(item);
}
@OptionsItem
boolean timerSelected() {
final Intent i = new Intent(this, BootstrapTimerActivity.class);
startActivity(i);
return true;
}
}

0 comments on commit de5f164

Please sign in to comment.