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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
package com.mapswithme.yopme;
import com.mapswithme.maps.api.MWMPoint;
import com.mapswithme.maps.api.MWMResponse;
import com.mapswithme.maps.api.MapsWithMeApi;
import com.mapswithme.maps.api.MwmRequest;
import com.mapswithme.yopme.BackscreenActivity.Mode;
import com.mapswithme.yopme.map.MapDataProvider;
import android.os.Bundle;
import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.PendingIntent;
import android.content.Intent;
import android.text.SpannableString;
import android.text.util.Linkify;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.PopupMenu;
import android.widget.Toast;
import android.widget.PopupMenu.OnMenuItemClickListener;
import android.widget.TextView;
public class YopmeFrontActivity extends Activity
implements OnClickListener
{
private TextView mSelectedLocation;
private View mMenu;
private Mode mMode;
private MWMPoint mPoint;
private final static String KEY_MODE = "key.mode";
private final static String KEY_POINT = "key.point";
@Override
protected void onSaveInstanceState(Bundle outState)
{
super.onSaveInstanceState(outState);
outState.putSerializable(KEY_MODE, mMode);
outState.putSerializable(KEY_POINT, mPoint);
}
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_yopme_main);
final ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(R.layout.action_bar_view);
setUpView();
//restore
if (savedInstanceState != null)
{
mMode = (Mode) savedInstanceState.getSerializable(KEY_MODE);
mPoint = (MWMPoint) savedInstanceState.getSerializable(KEY_POINT);
if (Mode.LOCATION == mMode)
setLocationView();
else if (Mode.POI == mMode)
mSelectedLocation.setText(mPoint.getName());
}
setUpListeners();
if (isIntroNeeded())
showIntro();
}
@Override
protected void onNewIntent(Intent intent)
{
super.onNewIntent(intent);
if (intent.hasExtra(EXTRA_PICK) && intent.getBooleanExtra(EXTRA_PICK, false))
{
final MWMResponse response = MWMResponse.extractFromIntent(this, intent);
if (response.hasPoint())
{
mPoint = response.getPoint();
mSelectedLocation.setText(mPoint.getName());
BackscreenActivity.startInMode(this, Mode.POI, mPoint, response.getZoomLevel());
Toast.makeText(this, R.string.toast_poi, Toast.LENGTH_LONG).show();
}
}
}
private void setUpView()
{
mSelectedLocation = (TextView) findViewById(R.id.selectedLocation);
mMenu = findViewById(R.id.menu);
}
private void setUpListeners()
{
findViewById(R.id.poi).setOnClickListener(this);
findViewById(R.id.me).setOnClickListener(this);
mMenu.setOnClickListener(this);
}
@Override
public void onClick(View v)
{
if (R.id.me == v.getId())
{
BackscreenActivity.startInMode(getApplicationContext(), Mode.LOCATION, null, MapDataProvider.COMFORT_ZOOM);
Toast.makeText(this, R.string.toast_your_location, Toast.LENGTH_LONG).show();
setLocationView();
}
else if (R.id.poi == v.getId())
{
final MwmRequest request = new MwmRequest()
.setCustomButtonName(getString(R.string.pick_point_button_name))
.setPendingIntent(getPickPointPendingIntent())
.setTitle(getString(R.string.app_name))
.setPickPointMode(true);
MapsWithMeApi.sendRequest(this, request);
}
else if (R.id.menu == v.getId())
{
final PopupMenu popupMenu = new PopupMenu(this, mMenu);
popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener()
{
@Override
public boolean onMenuItemClick(MenuItem item)
{
final int itemId = item.getItemId();
if (itemId == R.id.menu_help)
{
startActivity(new Intent(getApplicationContext(), ReferenceActivity.class));
return true;
}
else if (itemId == R.id.menu_settings)
{
startActivity(new Intent(getApplicationContext(), YopmePreference.class));
return true;
}
else if (itemId == R.id.menu_about)
{
final SpannableString linkifiedAbout = new SpannableString(getString(R.string.about));
Linkify.addLinks(linkifiedAbout, Linkify.ALL);
new AlertDialog.Builder(YopmeFrontActivity.this)
.setTitle(R.string.about_title)
.setMessage(linkifiedAbout)
.create()
.show();
return true;
}
return false;
}
});
popupMenu.inflate(R.menu.yopme_main);
popupMenu.show();
}
}
private final static String EXTRA_PICK = ".pick_point";
private PendingIntent getPickPointPendingIntent()
{
final Intent i = new Intent(this, YopmeFrontActivity.class);
i.putExtra(EXTRA_PICK, true);
return PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
}
private void setLocationView()
{
mSelectedLocation.setText(getString(R.string.poi_label));
}
private void showIntro()
{
final View intro = View.inflate(this, R.layout.help, null);
intro.setBackgroundColor(0x80000000);
((ViewGroup)getWindow().getDecorView()).addView(intro);
intro.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
intro.setVisibility(View.GONE);
markIntroShown();
}
});
}
private final static String PREFS = "prefs.xml";
private final static String KEY_INTRO = "intro";
private boolean isIntroNeeded()
{
return getSharedPreferences(PREFS, 0).getBoolean(KEY_INTRO, true);
}
private void markIntroShown()
{
getSharedPreferences(PREFS, 0).edit().putBoolean(KEY_INTRO, false).apply();
}
}
|