Android Open Source - Joetz-Android-V2 Booking Extra Fragment






From Project

Back to project page Joetz-Android-V2.

License

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.

Java Source Code

package com.example.jens.myapplication.booking;
/* ww  w  .  ja va 2s. co m*/
import android.app.Activity;
import android.os.Bundle;
import android.os.Parcelable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.example.jens.myapplication.R;
import com.example.jens.myapplication.domain.Camp;
import com.example.jens.myapplication.domain.Person;
import com.example.jens.myapplication.sam.JoetzApplication;
import com.example.jens.myapplication.sam.MyFragment;
import com.example.jens.myapplication.sam.MySaveableFragment;

import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * A simple {@link android.app.Fragment} subclass.
 * Activities that contain this fragment must implement the
 * {@link BookingExtraFragment.OnFragmentInteractionListener} interface
 * to handle interaction events.
 * Use the {@link BookingExtraFragment#newInstance} factory method to
 * create an instance of this fragment.
 *
 */
public class BookingExtraFragment extends MyFragment implements MySaveableFragment {
    public static final String ARG_CAMP_ID = "campidarg";
    public static final String ARG_PARTICIPANTS = "participantsarg";
    public static final String ARG_CAMP_PRICE = "camppricearg";

    private OnFragmentInteractionListener mListener;

    private BigDecimal mCampPrice;
//    private int mCountParticipants;
    private Person[] mParticipants;

    private TextView mTxtParticipants;
    private TextView mTxtPrice;

    private Button mBtnBook;
    private Button mBtnBack;

    /**
     * Bundle is required to create this fragment
     * @param bundle The bundle containing information about the booking
     * @return
     */
    public static BookingExtraFragment newInstance(Bundle bundle) {
        BookingExtraFragment fragment = new BookingExtraFragment();
        if(bundle == null){
            throw new IllegalArgumentException("Extra fragment requires a bundle " +
                    "containing campId and amount of participants");
        }
        fragment.setArguments(bundle);
        return fragment;
    }
    public BookingExtraFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

//        mCountParticipants = getArguments().getInt(ARG_COUNT_PARTICIPANTS);
        Parcelable[] parcPersons = getArguments().getParcelableArray(ARG_PARTICIPANTS);
        mParticipants = Arrays.copyOf(parcPersons, parcPersons.length, Person[].class);

        mCampPrice = (BigDecimal) getArguments().getSerializable(ARG_CAMP_PRICE);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View rootView = inflater.inflate(R.layout.fragment_booking_extra, container, false);

        mTxtParticipants = (TextView) rootView.findViewById(R.id.txtParticipants);
        StringBuilder partsSb = new StringBuilder();
        for(int i=0; i<mParticipants.length; i++){
            partsSb.append(mParticipants[i].getFirstName() + " "
                    + mParticipants[i].getLastName());
            if(i < mParticipants.length - 1){
                partsSb.append(System.getProperty("line.separator"));
            }
        }
        mTxtParticipants.setText(partsSb.toString());

        mTxtPrice = (TextView) rootView.findViewById(R.id.txtPrice);

        // example: "Price: 123,45 \u20ac (euro sign)
        mTxtPrice.setText((getString(R.string.price) + ": ")
                + NumberFormat.getCurrencyInstance().format(getFullPrice()));

        mBtnBook = (Button) rootView.findViewById(R.id.btnBook);
        mBtnBook.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mListener.doBooking();
            }
        });

        mBtnBack = (Button) rootView.findViewById(R.id.btnBack);
        mBtnBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mListener.toParticipantsFragment();
            }
        });

        return rootView;
    }

    /**
     * get the full price of the camp
     * @return the full price of the camp
     */
    private BigDecimal getFullPrice(){
        return mCampPrice;
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        try {
            mListener = (OnFragmentInteractionListener) activity;
        } catch (ClassCastException e) {
            throw new ClassCastException(activity.toString()
                    + " must implement OnFragmentInteractionListener");
        }
    }

    @Override
    public void onDetach() {
        super.onDetach();
        passBundleToParent();
        mListener = null;
    }

    @Override
    public void passBundleToParent() {

    }

    public interface OnFragmentInteractionListener {
        /**
         * Go to the next fragment
         */
        public void toParticipantsFragment();
        public void passExtraBundle(Bundle bundle);

        /**
         * Perform the booking request
         */
        public void doBooking();
    }

}




Java Source Code List

com.example.jens.myapplication.ApplicationTest.java
com.example.jens.myapplication.account.FragmentAccount.java
com.example.jens.myapplication.account.LoginDialogActivity.java
com.example.jens.myapplication.account.LoginFragment.java
com.example.jens.myapplication.account.PersonsFragment.java
com.example.jens.myapplication.account.ProfileFragment.java
com.example.jens.myapplication.account.RegisterDialogActivity.java
com.example.jens.myapplication.account.RegisterFragment.java
com.example.jens.myapplication.account.TabsPagerAdapter.java
com.example.jens.myapplication.activities.ActivityDetailActivity.java
com.example.jens.myapplication.activities.ActivityDetailFragment.java
com.example.jens.myapplication.activities.FragmentListActivities.java
com.example.jens.myapplication.activities.JoetzActivitiesAdapter.java
com.example.jens.myapplication.activities.JoetzActivity.java
com.example.jens.myapplication.activities.StartActivity.java
com.example.jens.myapplication.apimanager.ApiConnection.java
com.example.jens.myapplication.apimanager.CancellableTask.java
com.example.jens.myapplication.apimanager.JSONParsingTask.java
com.example.jens.myapplication.apimanager.PostRequestTask.java
com.example.jens.myapplication.apimanager.RequestParams.java
com.example.jens.myapplication.apimanager.SimpleRequestTask.java
com.example.jens.myapplication.apimanager.filter.PersonFilter.java
com.example.jens.myapplication.apimanager.manager.ActivityManager.java
com.example.jens.myapplication.apimanager.manager.AuthToken.java
com.example.jens.myapplication.apimanager.manager.BookingManager.java
com.example.jens.myapplication.apimanager.manager.CampManager.java
com.example.jens.myapplication.apimanager.manager.ImageManager.java
com.example.jens.myapplication.apimanager.manager.LoginManager.java
com.example.jens.myapplication.apimanager.manager.ProfileManager.java
com.example.jens.myapplication.apimanager.manager.RegisterManager.java
com.example.jens.myapplication.booking.AddPersonActivity.java
com.example.jens.myapplication.booking.BookingActivity.java
com.example.jens.myapplication.booking.BookingBondFragment.java
com.example.jens.myapplication.booking.BookingContactFragment.java
com.example.jens.myapplication.booking.BookingExtraFragment.java
com.example.jens.myapplication.booking.BookingParticipantsFragment.java
com.example.jens.myapplication.bookingHistory.BookingHistoryDetailActivity.java
com.example.jens.myapplication.bookingHistory.BookingHistoryDetailFragment.java
com.example.jens.myapplication.bookingHistory.BookingHistoryOverviewFragment.java
com.example.jens.myapplication.bookingHistory.BookingsAdapter.java
com.example.jens.myapplication.calendar.FragmentCalendar.java
com.example.jens.myapplication.calendar.KalenderAdapter.java
com.example.jens.myapplication.calendar.KalenderItem.java
com.example.jens.myapplication.camps.CampAdapter.java
com.example.jens.myapplication.camps.CampDetailActivity.java
com.example.jens.myapplication.camps.CampFilterActivity.java
com.example.jens.myapplication.camps.FilterFragment.java
com.example.jens.myapplication.camps.FragmentListCamps.java
com.example.jens.myapplication.camps.ImageActivity.java
com.example.jens.myapplication.camps.ImagePagerFragment.java
com.example.jens.myapplication.camps.InfoFragment.java
com.example.jens.myapplication.camps.PhotoFragment.java
com.example.jens.myapplication.camps.RecyclerItemClickListener.java
com.example.jens.myapplication.camps.SquareImageView.java
com.example.jens.myapplication.camps.TabsPagerAdapter.java
com.example.jens.myapplication.domain.BookingStatus.java
com.example.jens.myapplication.domain.Booking.java
com.example.jens.myapplication.domain.Camp.java
com.example.jens.myapplication.domain.PeriodCategory.java
com.example.jens.myapplication.domain.Person.java
com.example.jens.myapplication.domain.UserRole.java
com.example.jens.myapplication.domain.User.java
com.example.jens.myapplication.domain.binding.PersonValidatorBinding.java
com.example.jens.myapplication.domain.binding.UserValidatorBinding.java
com.example.jens.myapplication.domain.binding.ValidatorBinding.java
com.example.jens.myapplication.domain.converter.ErrorConverter.java
com.example.jens.myapplication.domain.converter.MyStringParser.java
com.example.jens.myapplication.domain.converter.UnixDateTimeConverter.java
com.example.jens.myapplication.domain.validator.PersonValidator.java
com.example.jens.myapplication.domain.validator.UserValidator.java
com.example.jens.myapplication.domain.validator.Validator.java
com.example.jens.myapplication.home.AanbevolenAdapter.java
com.example.jens.myapplication.home.HomeFragment.java
com.example.jens.myapplication.home.ImageSlideAdapter.java
com.example.jens.myapplication.home.Reclame.java
com.example.jens.myapplication.lib.RangeSeekBar.java
com.example.jens.myapplication.main.MainActivity.java
com.example.jens.myapplication.main.NavDrawerAdapter.java
com.example.jens.myapplication.main.NavDrawerItem.java
com.example.jens.myapplication.main.NavMenuItem.java
com.example.jens.myapplication.main.NavMenuSection.java
com.example.jens.myapplication.sam.JoetzApplication.java
com.example.jens.myapplication.sam.MyFragment.java
com.example.jens.myapplication.sam.MySaveableFragment.java
com.example.jens.myapplication.util.AESEncryption.java
com.example.jens.myapplication.util.ActivityUtils.java
com.example.jens.myapplication.util.BindingUtils.java
com.example.jens.myapplication.util.DateTimeStringConverter.java
com.example.jens.myapplication.util.JsonUtils.java
com.example.jens.myapplication.util.MyMonths.java
com.example.jens.myapplication.util.StringUtils.java
com.example.jens.myapplication.view.MyLinearLayout.java