TRACKING APP: Thank you screen

This commit is contained in:
Lukas Zielinski committed 2014-11-26 15:27:33 +01:00
1 parent d7ffd34dfb
commit f9c0e3b649
5 files changed
+143 -67

No files matched your search

@@ -123,6 +123,30 @@
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@color/sap_yellow" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/thank_you_layout"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/start_tracking_box"
android:layout_below="@id/image"
android:baselineAligned="false"
android:measureWithLargestChild="false"
android:orientation="horizontal"
android:visibility="invisible"
android:padding="10dp" >
<TextView
android:id="@+id/thank_you_note"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:padding="0dp"
android:text="@string/thank_you_you_successfully_participated"
android:textColor="@color/white"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
@@ -287,6 +311,7 @@
android:layout_alignParentLeft="true" >
<TextView
android:id="@+id/bottom_announcement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
@@ -67,5 +67,7 @@
<string name="no_qr_code">Sie haben keinen QR-Code?</string>
<string name="scan_qr">QR-Code scannen</string>
<string name="your_regattas">Ihre Regattas:</string>
<string name="close">Schließen</string>
<string name="thank_you_you_successfully_participated">Vielen Dank, Sie haben erfolgreich an der Regatta teilgenommen.\n\nIhr SAP Sailing Team</string>
</resources>
@@ -59,5 +59,7 @@
<string name="day">Day</string>
<string name="please_listen_to_announcements">Please listen to the announcements</string>
<string name="your_regattas">Your Regattas:</string>
<string name="close">Close</string>
<string name="thank_you_you_successfully_participated">Thank you, you have successfully taken part in the regatta.\n\nYour SAP Sailing Team</string>
</resources>
@@ -338,7 +338,7 @@ public class RegattaActivity extends BaseActivity {
/**
* Check out from regatta;
*/
private void checkout()
public void checkout()
{
final String checkoutURLStr = prefs.getServerURL()
+ prefs.getServerCheckoutPath().replace("{leaderboard-name}",
@@ -20,6 +20,7 @@ import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.sap.sailing.android.shared.logging.ExLog;
@@ -30,12 +31,14 @@ import com.sap.sailing.android.tracking.app.ui.activities.TrackingActivity;
public class RegattaFragment extends BaseFragment implements OnClickListener {
private final String TAG = RegattaFragment.class.toString();
private final int CAMERA_REQUEST_CODE = 3118;
private final int SELECT_PHOTO_REQUEST_CODE = 1693;
private boolean showingThankYouNote;
private TimerRunnable timer;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
@@ -63,24 +66,76 @@ public class RegattaFragment extends BaseFragment implements OnClickListener {
return view;
}
private void switchToThankYouScreen() {
showingThankYouNote = true;
RelativeLayout startsInLayout = (RelativeLayout) getActivity()
.findViewById(R.id.start_date_layout);
startsInLayout.setVisibility(View.INVISIBLE);
Button startTrackingButton = (Button) getActivity().findViewById(
R.id.start_tracking);
startTrackingButton.setBackgroundColor(getActivity().getResources()
.getColor(R.color.sap_yellow));
startTrackingButton.setText(getActivity().getString(R.string.close));
TextView bottomAnnouncement = (TextView) getActivity().findViewById(R.id.bottom_announcement);
bottomAnnouncement.setVisibility(View.INVISIBLE);
RelativeLayout thankYouLayout = (RelativeLayout)getActivity().findViewById(R.id.thank_you_layout);
thankYouLayout.setVisibility(View.VISIBLE);
}
@Override
public void onResume() {
super.onResume();
timer = new TimerRunnable();
timer.start();
// TODO delete test
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
switchToThankYouScreen();
}
});
}
}).start();
}
@Override
public void onPause() {
super.onPause();
timer.stop();
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.start_tracking:
showTrackingActivity();
if (showingThankYouNote)
{
RegattaActivity regattaActivity = (RegattaActivity)getActivity();
regattaActivity.checkout();
}
else
{
showTrackingActivity();
}
break;
case R.id.add_photo_button:
showChooseExistingPictureOrTakeNewPhotoAlert();
@@ -112,7 +167,8 @@ public class RegattaFragment extends BaseFragment implements OnClickListener {
private void showChooseExistingPictureOrTakeNewPhotoAlert() {
AlertDialog dialog = new AlertDialog.Builder(getActivity())
.setTitle(R.string.add_photo_select)
.setMessage(R.string.do_you_want_to_choose_existing_img_or_take_a_new_one)
.setMessage(
R.string.do_you_want_to_choose_existing_img_or_take_a_new_one)
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(R.string.existing_image,
new DialogInterface.OnClickListener() {
@@ -128,17 +184,15 @@ public class RegattaFragment extends BaseFragment implements OnClickListener {
int which) {
showTakePhotoActivity();
}
})
.create();
}).create();
dialog.show();
}
private void pickExistingImage()
{
private void pickExistingImage() {
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, SELECT_PHOTO_REQUEST_CODE);
startActivityForResult(photoPickerIntent, SELECT_PHOTO_REQUEST_CODE);
}
private void showTakePhotoActivity() {
@@ -148,23 +202,23 @@ public class RegattaFragment extends BaseFragment implements OnClickListener {
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK)
{
if (resultCode == Activity.RESULT_OK) {
RegattaActivity activity = (RegattaActivity) getActivity();
if (requestCode == CAMERA_REQUEST_CODE) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
activity.updatePictureChosenByUser(photo);
}
else if (requestCode == SELECT_PHOTO_REQUEST_CODE) {
} else if (requestCode == SELECT_PHOTO_REQUEST_CODE) {
Uri selectedImage = data.getData();
InputStream imageStream;
InputStream imageStream;
try {
imageStream = getActivity().getContentResolver().openInputStream(selectedImage);
imageStream = getActivity().getContentResolver()
.openInputStream(selectedImage);
Bitmap photo = BitmapFactory.decodeStream(imageStream);
activity.updatePictureChosenByUser(photo);
} catch (FileNotFoundException e) {
ExLog.e(getActivity(), TAG, "File not found exception after picking image from gallery");
ExLog.e(getActivity(), TAG,
"File not found exception after picking image from gallery");
return;
}
}
@@ -178,74 +232,67 @@ public class RegattaFragment extends BaseFragment implements OnClickListener {
Intent intent = new Intent(getActivity(), TrackingActivity.class);
getActivity().startActivity(intent);
}
private void timerFired()
{
RegattaActivity regattaActivity = (RegattaActivity)getActivity();
private void timerFired() {
RegattaActivity regattaActivity = (RegattaActivity) getActivity();
updateCountdownTimer(regattaActivity.getEventStartMillis());
}
private void updateCountdownTimer(long startTime)
{
private void updateCountdownTimer(long startTime) {
long diff = startTime - System.currentTimeMillis();
if (diff < 0) // event is in the past
{
setCountdownTime(0, 0, 0);
}
else
{
int days = (int)TimeUnit.MILLISECONDS.toDays(diff);
int hours = (int)TimeUnit.MILLISECONDS.toHours(diff) - (days * 24);
int minutes = (int)TimeUnit.MILLISECONDS.toMinutes(diff) - (hours * 60) - (days * 24 * 60);
setCountdownTime(days, hours, minutes);
} else {
int days = (int) TimeUnit.MILLISECONDS.toDays(diff);
int hours = (int) TimeUnit.MILLISECONDS.toHours(diff) - (days * 24);
int minutes = (int) TimeUnit.MILLISECONDS.toMinutes(diff)
- (hours * 60) - (days * 24 * 60);
setCountdownTime(days, hours, minutes);
}
}
private void setCountdownTime(int days, int hours, int minutes)
{
TextView daysTextView = (TextView)getActivity().findViewById(R.id.starts_in_days);
TextView hoursTextView = (TextView)getActivity().findViewById(R.id.starts_in_hours);
TextView minutesTextView = (TextView)getActivity().findViewById(R.id.starts_in_minutes);
TextView daysTextViewLabel = (TextView)getActivity().findViewById(R.id.starts_in_days_label);
TextView hoursTextViewLabel = (TextView)getActivity().findViewById(R.id.starts_in_hours_label);
TextView minutesTextViewLabel = (TextView)getActivity().findViewById(R.id.starts_in_minutes_label);
private void setCountdownTime(int days, int hours, int minutes) {
TextView daysTextView = (TextView) getActivity().findViewById(
R.id.starts_in_days);
TextView hoursTextView = (TextView) getActivity().findViewById(
R.id.starts_in_hours);
TextView minutesTextView = (TextView) getActivity().findViewById(
R.id.starts_in_minutes);
TextView daysTextViewLabel = (TextView) getActivity().findViewById(
R.id.starts_in_days_label);
TextView hoursTextViewLabel = (TextView) getActivity().findViewById(
R.id.starts_in_hours_label);
TextView minutesTextViewLabel = (TextView) getActivity().findViewById(
R.id.starts_in_minutes_label);
daysTextView.setText(String.format("%02d", days));
hoursTextView.setText(String.format("%02d", hours));
minutesTextView.setText(String.format("%02d", minutes));
if (days == 1)
{
if (days == 1) {
daysTextViewLabel.setText(R.string.day);
}
else
{
} else {
daysTextViewLabel.setText(R.string.days);
}
if (hours == 1)
{
if (hours == 1) {
hoursTextViewLabel.setText(R.string.hour);
}
else
{
} else {
hoursTextViewLabel.setText(R.string.hours);
}
if (minutes == 1)
{
if (minutes == 1) {
minutesTextViewLabel.setText(R.string.minute);
}
else
{
} else {
minutesTextViewLabel.setText(R.string.minutes);
}
}
private class TimerRunnable implements Runnable {
public Thread t;
public volatile boolean running = true;