Back to project page beers-todrink.
The source code is released under:
MIT License
If you think the Android project beers-todrink listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package br.com.androidzin.brunomateus.beerstodrink; //w w w. j av a 2 s .co m import android.database.Cursor; import android.graphics.drawable.AnimationDrawable; import android.support.v4.app.FragmentActivity; import android.support.v4.app.LoaderManager; import android.support.v4.content.CursorLoader; import android.support.v4.content.Loader; import android.os.Bundle; import android.view.View; import android.widget.ImageView; import android.widget.TextView; import org.androidannotations.annotations.AfterViews; import org.androidannotations.annotations.EActivity; import org.androidannotations.annotations.UiThread; import org.androidannotations.annotations.ViewById; import br.com.androidzin.brunomateus.beerstodrink.provider.BeerContract; @EActivity(R.layout.activity_beer_drinking) public class BeerDrinkingActivity extends FragmentActivity implements LoaderManager.LoaderCallbacks<Cursor>{ private static final int URL_LOADER = 3; @ViewById(R.id.drinking_animation) ImageView drinkingAnimation; @ViewById(R.id.drinking_message) TextView drinkingMessage; @ViewById(R.id.beer_name) TextView beerName; private String beer; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); beer = getIntent().getStringExtra(BeerListActivity.BEER_NAME); getSupportLoaderManager().initLoader(URL_LOADER, null, this); } @AfterViews public void setBeerName(){ beerName.setText(beer); } @AfterViews public void startAnimation(){ AnimationDrawable animation = (AnimationDrawable) drinkingAnimation.getBackground(); animation.setOneShot(true); animation.start(); int duration = animation.getDuration(0); showStatus(); } @UiThread(delay=2000) public void showStatus(){ drinkingMessage.setVisibility(View.VISIBLE); } @Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { CursorLoader loader = null; if(id == URL_LOADER){ loader = new CursorLoader(this, BeerContract.BeerColumns.CONTENT_URI, null, BeerContract.NOT_DRANK_BEERS, null, null); } return loader; } @Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { int remaingBeers = data.getCount(); drinkingMessage.setText(getResources().getQuantityString( R.plurals.one_more_congratulations, remaingBeers, remaingBeers)); } @Override public void onLoaderReset(Loader<Cursor> loader) { } }