Back to project page Joetz-Android-V2.
The source code is released under:
GNU General Public License
If you think the Android project Joetz-Android-V2 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.example.jens.myapplication.camps; //from w w w .j a v a2 s .c om import android.app.ActionBar; import android.app.FragmentTransaction; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.support.v4.app.NavUtils; import android.support.v4.view.ViewPager; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import com.example.jens.myapplication.R; import com.example.jens.myapplication.apimanager.SimpleRequestTask; import com.example.jens.myapplication.apimanager.manager.LoginManager; import com.example.jens.myapplication.booking.BookingActivity; import com.example.jens.myapplication.domain.Camp; import com.example.jens.myapplication.domain.User; import com.example.jens.myapplication.sam.JoetzApplication; import java.util.List; public class CampDetailActivity extends FragmentActivity implements ActionBar.TabListener, InfoFragment.OnFragmentInteractionListener { //USED FOR TABS private ViewPager viewPager; private TabsPagerAdapter mAdapter; private android.app.ActionBar actionBar; // Tab title icons private int[] tabDrawable = {R.drawable.ic_action_ic_info_48px, R.drawable.ic_action_ic_photo_camera_48px}; private Camp mCamp; private MenuItem mMenuItemBookmark; private boolean currentBookmark = false; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_camp_detail); mCamp = JoetzApplication.getContext().getCampManager().findCampById( getIntent().getExtras().getLong(InfoFragment.ARG_CAMP_ID)); // TODO CHECK TEES /* if (savedInstanceState != null) { // Create the detail fragment and add it to the activity // using a fragment transaction. Bundle arguments = new Bundle(); arguments.putString(FragmentCampDetail.ARG_CAMP_ID, getIntent().getStringExtra(FragmentCampDetail.ARG_CAMP_ID)); FragmentCampDetail fragment = new FragmentCampDetail(); fragment.setArguments(arguments); getFragmentManager().beginTransaction() .add(R.id.camp_detail_container, fragment) .commit(); }*/ // USED FOR TABS viewPager = (ViewPager) findViewById(R.id.pager); actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); mAdapter = new TabsPagerAdapter(getSupportFragmentManager()); viewPager.setAdapter(mAdapter); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Adding Tabs /* for (String tab_name : tabs) { actionBar.addTab(actionBar.newTab().setText(tab_name) .setTabListener(this)); }*/ for (int tab_drawable : tabDrawable) { actionBar.addTab(actionBar.newTab().setIcon(tab_drawable) .setTabListener(this)); } viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageSelected(int position) { // on changing the page // make respected tab selected actionBar.setSelectedNavigationItem(position); } @Override public void onPageScrolled(int arg0, float arg1, int arg2) { } @Override public void onPageScrollStateChanged(int arg0) { } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { //super.onCreateOptionsMenu(menu); getMenuInflater().inflate(R.menu.camp_detail, menu); mMenuItemBookmark = menu.findItem(R.id.action_bookmark); if(JoetzApplication.getContext().getLoginManager().isLoggedIn()){ User u = JoetzApplication.getContext().getLoginManager().getUser(); currentBookmark = false; if(u != null){ if(u.hasBookmarkedCamp(mCamp.getId())){ currentBookmark = true; } } invalidateBookmarkedIcon(); } else{ mMenuItemBookmark.setVisible(false); } return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == android.R.id.home) { // This ID represents the Home or Up button. In the case of this NavUtils.navigateUpFromSameTask(this); return true; } if (id == R.id.action_bookmark) { bookmarkCamp(); return true; } return super.onOptionsItemSelected(item); } private void invalidateBookmarkedIcon(){ if (JoetzApplication.getContext().getLoginManager().getUser().hasBookmarkedCamp(mCamp.getId())) { mMenuItemBookmark.setIcon(R.drawable.ic_toggle_star); } else { mMenuItemBookmark.setIcon(R.drawable.ic_toggle_star_outline); } } @Override protected void onResume() { super.onResume(); if(mMenuItemBookmark != null){ mMenuItemBookmark.setVisible( JoetzApplication.getContext().getLoginManager().isLoggedIn()); } } private void bookmarkCamp() { //currentBookmark = !currentBookmark; JoetzApplication.getContext().getLoginManager().getUser().toggleBookmarkedCamp(mCamp.getId()); invalidateBookmarkedIcon(); } private void checkSendRequestBookmark(){ LoginManager manager = JoetzApplication.getContext().getLoginManager(); if(!manager.isLoggedIn()){ return; } if(manager.getUser().hasBookmarkedCamp(mCamp.getId()) == currentBookmark){ return; } JoetzApplication.getContext().getCampManager().toggleBookmark(mCamp.getId(), null); } @Override protected void onPause() { super.onPause(); checkSendRequestBookmark(); } @Override public void toBooking(long campId) { //long campId = JoetzApplication.getContext().getCampManager().getCamps().get(0).getId(); Intent i = new Intent(this, BookingActivity.class); i.putExtra(BookingActivity.ARG_CAMPID, campId); startActivity(i); } @Override public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) { viewPager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) { } @Override public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) { } }