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;
/*www.java2s.com*/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.
*
*/publicclass BookingExtraFragment extends MyFragment implements MySaveableFragment {
publicstaticfinal String ARG_CAMP_ID = "campidarg";
publicstaticfinal String ARG_PARTICIPANTS = "participantsarg";
publicstaticfinal 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
*/publicstatic BookingExtraFragment newInstance(Bundle bundle) {
BookingExtraFragment fragment = new BookingExtraFragment();
if(bundle == null){
thrownew IllegalArgumentException("Extra fragment requires a bundle " +
"containing campId and amount of participants");
}
fragment.setArguments(bundle);
return fragment;
}
public BookingExtraFragment() {
// Required empty public constructor
}
@Override
publicvoid 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
publicvoid onClick(View v) {
mListener.doBooking();
}
});
mBtnBack = (Button) rootView.findViewById(R.id.btnBack);
mBtnBack.setOnClickListener(new View.OnClickListener() {
@Override
publicvoid 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
publicvoid onAttach(Activity activity) {
super.onAttach(activity);
try {
mListener = (OnFragmentInteractionListener) activity;
} catch (ClassCastException e) {
thrownew ClassCastException(activity.toString()
+ " must implement OnFragmentInteractionListener");
}
}
@Override
publicvoid onDetach() {
super.onDetach();
passBundleToParent();
mListener = null;
}
@Override
publicvoid passBundleToParent() {
}
publicinterface OnFragmentInteractionListener {
/**
* Go to the next fragment
*/publicvoid toParticipantsFragment();
publicvoid passExtraBundle(Bundle bundle);
/**
* Perform the booking request
*/publicvoid doBooking();
}
}