Back to project page WineDB.
The source code is released under:
MIT License
If you think the Android project WineDB 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 com.selesse.android.winedb.activity; // w ww .j a v a 2s.c o m import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; import android.support.v4.view.ViewPager; import android.support.v7.app.ActionBarActivity; import android.util.Log; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import com.selesse.android.winedb.R; import com.selesse.android.winedb.database.Wine; import com.selesse.android.winedb.database.WineDatabaseHandler; import com.selesse.android.winedb.model.RequestCode; public class SingleWineViewActivity extends ActionBarActivity { private static final String TAG = SingleWineViewActivity.class.getSimpleName(); private ViewPager viewPager; private Wine wine; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.single_wine); int position = 0; Bundle args = getIntent().getExtras(); if (args != null) { position = args.getInt("position", 0); } WineCollectionPagerAdapter wineCollectionPagerAdapter = new WineCollectionPagerAdapter(getSupportFragmentManager(), this); viewPager = (ViewPager) findViewById(R.id.wine_pager); viewPager.setAdapter(wineCollectionPagerAdapter); viewPager.setCurrentItem(position); // remove the icon from the ActionBar getSupportActionBar().setIcon(new ColorDrawable(android.R.color.transparent)); } @Override protected void onResume() { super.onResume(); getSupportActionBar().setIcon(new ColorDrawable(android.R.color.transparent)); } @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.single_wine, menu); return true; } @Override protected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); long savedId = savedInstanceState.getLong("id"); if (savedId != 0) { wine = WineDatabaseHandler.getInstance(this).getWine(savedId); Log.i(TAG, "Restoring " + wine.getName()); } } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); if (wine != null && wine.getId() > 0) { Log.i(TAG, "Saving " + wine.getName()); outState.putLong("id", wine.getId()); } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (data != null) { viewPager.getAdapter().notifyDataSetChanged(); } } @Override public boolean onOptionsItemSelected(MenuItem item) { wine = WineDatabaseHandler.getInstance(this).getWineNumber(viewPager.getCurrentItem()); Log.i(TAG, "Selected options for " + wine.getName()); switch (item.getItemId()) { case R.id.edit_wine_button: Intent intent = new Intent(this, CreateOrEditWineActivity.class); intent.putExtra("id", wine.getId()); startActivityForResult(intent, RequestCode.EDIT_WINE.ordinal()); return true; case R.id.delete_wine_button: confirmDeleteDialog(); return true; default: return super.onOptionsItemSelected(item); } } private void confirmDeleteDialog() { new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert) .setTitle(R.string.confirm_delete).setMessage(R.string.confirm_delete_message) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { WineDatabaseHandler.getInstance(getApplicationContext()).removeWine(wine); viewPager.getAdapter().notifyDataSetChanged(); if (viewPager.getAdapter().getCount() == 0) { finish(); } } }).setNegativeButton(R.string.no, null).show(); } }