summaryrefslogtreecommitdiff
path: root/client/Piztor/src/com/macaroon/piztor/AlertMaker.java
blob: 63382bbf69639a44be2e0c3d41409e33c462ae77 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package com.macaroon.piztor;

import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.TimePickerDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.map.LocationData;
import com.baidu.mapapi.map.MKMapTouchListener;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.OverlayItem;
import com.baidu.mapapi.map.PopupOverlay;
import com.baidu.platform.comapi.basestruct.GeoPoint;

public class AlertMaker {

	private Calendar calendar;
	private Context context;
	private GeoPoint markerPoint;
	private MapMaker mapMaker;

	public AlertMaker(Context cc, MapMaker mm) {
		context =cc;
		mapMaker = mm;
	}
		
	public static void closeBoard(Context cc) {
		InputMethodManager imm = (InputMethodManager) cc
				.getSystemService(Context.INPUT_METHOD_SERVICE);
		  if (imm.isActive())
			  imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT,
		 InputMethodManager.HIDE_NOT_ALWAYS);
		 }

	public void showSettingsAlert() {
		
		closeBoard(context);
		AlertDialog.Builder gpsDialog = new AlertDialog.Builder(context);
		gpsDialog.setTitle("GPS settings");
		gpsDialog.setMessage("GPS is not enabled. Please turn it on.");
		gpsDialog.setPositiveButton("Settings",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
						context.startActivity(intent);
					}
				});
		gpsDialog.setNegativeButton("Go without GPS",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						dialog.cancel();
					}
				});
		gpsDialog.show();
	}

	public void showMarkerAlert(GeoPoint point) {
		
		closeBoard(context);
		if (point == null) return;
		markerPoint = point;
		calendar = Calendar.getInstance();
		TimePickerDialog markerDialog = new TimePickerDialog(context
				, new TimePickerDialog.OnTimeSetListener() {
					
					@Override
					public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
						////// at least 2 minutes
						if ((hourOfDay >= calendar.get(Calendar.HOUR_OF_DAY) && minute >= calendar.get(Calendar.MINUTE))
								|| hourOfDay > calendar.get(Calendar.HOUR_OF_DAY))
							mapMaker.DrawMarker(markerPoint);
						else {
							Toast toast = Toast.makeText(context,
									"Too early!Give me more time!", Toast.LENGTH_LONG);
							toast.show();
							closeBoard(context);
							showMarkerAlert(markerPoint);
						}
					}
				}
				, calendar.get(Calendar.HOUR_OF_DAY)
				, calendar.get(Calendar.MINUTE), false);
		markerDialog.show();
	}
	
	public void showQuitAlert() {
		
		AlertDialog.Builder quitDialog = new AlertDialog.Builder(context);
		closeBoard(context);
		quitDialog.setTitle("Quit");
		quitDialog.setMessage("Do you want to logout and quit?");
		quitDialog.setPositiveButton("Quit",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						AppMgr.exit();
					}
				});
		quitDialog.setNegativeButton("Cancel",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						dialog.cancel();
					}
				});
		quitDialog.show();
	}
	
}