Java tutorial
/** * Copyright (C) 2012 Picon software * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ package fr.eoidb.activity; import android.content.ContentUris; import android.content.Intent; import android.database.Cursor; import android.os.Bundle; import android.support.v4.content.Loader; import android.util.TypedValue; import android.view.View; import android.view.View.OnClickListener; import android.widget.LinearLayout.LayoutParams; import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuItem; import fr.eoidb.R; import fr.eoidb.util.DbUtil; /** * @author picon.software * */ public class ItemInfoActivity extends LoaderActivity<Cursor> { private MenuItem favoriteMenuItem; private int itemId, categorieId, metaGroupId, groupId; private boolean favorite, isItemIconExpended = false; private double volume; private String itemName; /** Called when the activity is first created. */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.item_info); setActionBarInderterminate(true); itemId = (int) ContentUris.parseId(getIntent().getData()); initOrRestart(); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(false); if (findViewById(R.id.ITEM_ICON_LAYOUT) != null) { findViewById(R.id.ITEM_ICON_LAYOUT).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (isItemIconExpended) { LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 150, getResources().getDisplayMetrics())); v.setLayoutParams(layoutParams); isItemIconExpended = false; } else { LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 250, getResources().getDisplayMetrics())); v.setLayoutParams(layoutParams); isItemIconExpended = true; } } }); } } @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getSupportMenuInflater(); inflater.inflate(R.menu.iteminfomenu, menu); favoriteMenuItem = menu.findItem(R.id.FAVORITE_OPTION); return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { Intent intent; switch (item.getItemId()) { case android.R.id.home: // app icon in action bar clicked; go home intent = new Intent(this, MarketGroupListActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); return true; default: break; } return super.onOptionsItemSelected(item); } @Override protected void onResume() { super.onResume(); setActionBarInderterminate(false); } @Override public Loader<Cursor> getCursorLoader(int id, Bundle args) { return null; } @Override public void onLoadFinished(Cursor cursor) { if (DbUtil.hasAtLeastOneRow(cursor)) { setActionBarInderterminate(false); } } @Override public void onLoaderReset(Loader<Cursor> loader) { } }