Introduce close button

This commit is contained in:
Victor Shcherb 2012-04-27 20:57:41 +02:00
parent 399c5f0a7d
commit d0bb21a03d
2 changed files with 123 additions and 90 deletions

View file

@ -1,84 +1,84 @@
:- op('==', xfy, 500).
version(101).
language(zh).
% before each announcement (beep)
preamble - [].
%% TURNS
turn('left', ['左轉 ']).
turn('left_sh', ['向左急轉 ']).
turn('left_sl', ['稍向左轉 ']).
turn('right', ['右轉 ']).
turn('right_sh', ['向右急轉 ']).
turn('right_sl', ['稍向右轉 ']).
prepare_turn(Turn, Dist) == ['請準備 ', D, ' 後 ', M] :- distance(Dist) == D, turn(Turn, M).
turn(Turn, Dist) == [D, ' 後 ',M] :- distance(Dist) == D, turn(Turn, M).
turn(Turn) == M :- turn(Turn, M).
prepare_make_ut(Dist) == ['請準備', D, ' 後迴轉 '] :- distance(Dist) == D.
make_ut(Dist) == [D, ' 後請迴轉'] :- distance(Dist) == D.
make_ut == ['請迴轉 '].
make_ut_wp == ['可能的話, 請迴轉 '].
prepare_roundabout(Dist) == ['請準備', D,' 後進入圓環 '] :- distance(Dist) == D.
roundabout(Dist, _Angle, Exit) == [D, ' 後進入圓環, 然後在 ', E, ' 出口離開'] :- distance(Dist) == D, nth(Exit, E).
roundabout(_Angle, Exit) == ['在 ', E, ' 出口離開'] :- nth(Exit, E).
go_ahead == ['直直往前開 '].
go_ahead(Dist) == ['沿著馬路往前 ', D]:- distance(Dist) == D.
and_arrive_destination == ['然後可達終點 '].
then == ['然後 '].
reached_destination == ['抵達終點 '].
bear_right == ['靠右 '].
bear_left == ['靠左 '].
route_new_calc(Dist) == ['路程有 ', D, ' 遠'] :- distance(Dist) == D.
route_recalc(Dist) == ['重新計算路程, 距離有 ', D] :- distance(Dist) == D.
location_lost == ['接收不到 g p s 信號 '].
%%
nth(1, '第一個 ').
nth(2, '第二個 ').
nth(3, '第三個 ').
nth(4, '第四個 ').
nth(5, '第五個 ').
nth(6, '第六個 ').
nth(7, '第七個 ').
nth(8, '第八個 ').
nth(9, '第九個 ').
nth(10, '第十個 ').
nth(11, '第十一個 ').
nth(12, '第十二個 ').
nth(13, '第十三個 ').
nth(14, '第十四個 ').
nth(15, '第十五個 ').
nth(16, '第十六個 ').
nth(17, '第十七個 ').
%%% distance measure
distance(Dist) == [ X, ' 公尺'] :- Dist < 100, D is round(Dist/10)*10, num_atom(D, X).
distance(Dist) == [ X, ' 公尺'] :- Dist < 1000, D is round(2*Dist/100)*50, num_atom(D, X).
distance(Dist) == ['約 1 公里 '] :- Dist < 1500.
distance(Dist) == ['約 ', X, ' 公里 '] :- Dist < 10000, D is round(Dist/1000), num_atom(D, X).
distance(Dist) == [ X, ' 公里 '] :- D is round(Dist/1000), num_atom(D, X).
%% resolve command main method
%% if you are familar with Prolog you can input specific to the whole mechanism,
%% by adding exception cases.
flatten(X, Y) :- flatten(X, [], Y), !.
flatten([], Acc, Acc).
flatten([X|Y], Acc, Res):- flatten(Y, Acc, R), flatten(X, R, Res).
flatten(X, Acc, [X|Acc]).
resolve(X, Y) :- resolve_impl(X,Z), flatten(Z, Y).
resolve_impl([],[]).
:- op('==', xfy, 500).
version(101).
language(zh).
% before each announcement (beep)
preamble - [].
%% TURNS
turn('left', ['左轉 ']).
turn('left_sh', ['向左急轉 ']).
turn('left_sl', ['稍向左轉 ']).
turn('right', ['右轉 ']).
turn('right_sh', ['向右急轉 ']).
turn('right_sl', ['稍向右轉 ']).
prepare_turn(Turn, Dist) == ['請準備 ', D, ' 後 ', M] :- distance(Dist) == D, turn(Turn, M).
turn(Turn, Dist) == [D, ' 後 ',M] :- distance(Dist) == D, turn(Turn, M).
turn(Turn) == M :- turn(Turn, M).
prepare_make_ut(Dist) == ['請準備', D, ' 後迴轉 '] :- distance(Dist) == D.
make_ut(Dist) == [D, ' 後請迴轉'] :- distance(Dist) == D.
make_ut == ['請迴轉 '].
make_ut_wp == ['可能的話, 請迴轉 '].
prepare_roundabout(Dist) == ['請準備', D,' 後進入圓環 '] :- distance(Dist) == D.
roundabout(Dist, _Angle, Exit) == [D, ' 後進入圓環, 然後在 ', E, ' 出口離開'] :- distance(Dist) == D, nth(Exit, E).
roundabout(_Angle, Exit) == ['在 ', E, ' 出口離開'] :- nth(Exit, E).
go_ahead == ['直直往前開 '].
go_ahead(Dist) == ['沿著馬路往前 ', D]:- distance(Dist) == D.
and_arrive_destination == ['然後可達終點 '].
then == ['然後 '].
reached_destination == ['抵達終點 '].
bear_right == ['靠右 '].
bear_left == ['靠左 '].
route_new_calc(Dist) == ['路程有 ', D, ' 遠'] :- distance(Dist) == D.
route_recalc(Dist) == ['重新計算路程, 距離有 ', D] :- distance(Dist) == D.
location_lost == ['接收不到 g p s 信號 '].
%%
nth(1, '第一個 ').
nth(2, '第二個 ').
nth(3, '第三個 ').
nth(4, '第四個 ').
nth(5, '第五個 ').
nth(6, '第六個 ').
nth(7, '第七個 ').
nth(8, '第八個 ').
nth(9, '第九個 ').
nth(10, '第十個 ').
nth(11, '第十一個 ').
nth(12, '第十二個 ').
nth(13, '第十三個 ').
nth(14, '第十四個 ').
nth(15, '第十五個 ').
nth(16, '第十六個 ').
nth(17, '第十七個 ').
%%% distance measure
distance(Dist) == [ X, ' 公尺'] :- Dist < 100, D is round(Dist/10)*10, num_atom(D, X).
distance(Dist) == [ X, ' 公尺'] :- Dist < 1000, D is round(2*Dist/100)*50, num_atom(D, X).
distance(Dist) == ['約 1 公里 '] :- Dist < 1500.
distance(Dist) == ['約 ', X, ' 公里 '] :- Dist < 10000, D is round(Dist/1000), num_atom(D, X).
distance(Dist) == [ X, ' 公里 '] :- D is round(Dist/1000), num_atom(D, X).
%% resolve command main method
%% if you are familar with Prolog you can input specific to the whole mechanism,
%% by adding exception cases.
flatten(X, Y) :- flatten(X, [], Y), !.
flatten([], Acc, Acc).
flatten([X|Y], Acc, Res):- flatten(Y, Acc, R), flatten(X, R, Res).
flatten(X, Acc, [X|Acc]).
resolve(X, Y) :- resolve_impl(X,Z), flatten(Z, Y).
resolve_impl([],[]).
resolve_impl([X|Rest], List) :- resolve_impl(Rest, Tail), ((X == L) -> append(L, Tail, List); List = Tail).

View file

@ -22,6 +22,7 @@ import android.view.Gravity;
import android.view.MotionEvent;
import android.view.WindowManager;
import android.widget.FrameLayout.LayoutParams;
import android.widget.ImageView;
import android.widget.TextView;
public class ContextMenuLayer extends OsmandMapLayer {
@ -47,10 +48,12 @@ public class ContextMenuLayer extends OsmandMapLayer {
private List<Object> selectedObjects = new ArrayList<Object>();
private TextView textView;
private ImageView closeButton;
private DisplayMetrics dm;
private OsmandMapTileView view;
private int BASE_TEXT_SIZE = 170;
private int SHADOW_OF_LEG = 5;
private int CLOSE_BTN = 3;
private final MapActivity activity;
private Drawable boxLeg;
@ -78,6 +81,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
}
BASE_TEXT_SIZE = (int) (BASE_TEXT_SIZE * scaleCoefficient);
SHADOW_OF_LEG = (int) (SHADOW_OF_LEG * scaleCoefficient);
CLOSE_BTN = (int) (CLOSE_BTN * scaleCoefficient);
boxLeg = view.getResources().getDrawable(R.drawable.box_leg);
boxLeg.setBounds(0, 0, boxLeg.getMinimumWidth(), boxLeg.getMinimumHeight());
@ -96,6 +100,12 @@ public class ContextMenuLayer extends OsmandMapLayer {
textView.setBackgroundDrawable(view.getResources().getDrawable(R.drawable.box_free));
textPadding = new Rect();
textView.getBackground().getPadding(textPadding);
closeButton = new ImageView(view.getContext());
lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
closeButton.setLayoutParams(lp);
closeButton.setImageDrawable(view.getResources().getDrawable(R.drawable.headliner_close));
closeButton.setClickable(true);
}
@Override
@ -115,6 +125,8 @@ public class ContextMenuLayer extends OsmandMapLayer {
int c = textView.getLineCount();
textView.draw(canvas);
canvas.translate(textView.getWidth() - closeButton.getWidth() - CLOSE_BTN, CLOSE_BTN);
closeButton.draw(canvas);
if (c == 0) {
// special case relayout after on draw method
layoutText();
@ -133,6 +145,9 @@ public class ContextMenuLayer extends OsmandMapLayer {
int h = (int) ((textView.getPaint().getTextSize() + 4) * textView.getLineCount());
textView.layout(0, -padding.bottom, w, h + padding.top);
int minw = closeButton.getDrawable().getMinimumWidth();
int minh = closeButton.getDrawable().getMinimumHeight();
closeButton.layout(0, 0, minw, minh);
}
public void setLocation(LatLon loc, String description){
@ -170,7 +185,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
return true;
}
if(pressedInTextView(point.x, point.y)){
if(pressedInTextView(point.x, point.y) > 0){
setLocation(null, ""); //$NON-NLS-1$
view.refreshMap();
return true;
@ -207,18 +222,23 @@ public class ContextMenuLayer extends OsmandMapLayer {
return true;
}
public boolean pressedInTextView(float px, float py) {
public int pressedInTextView(float px, float py) {
if (latLon != null) {
Rect bs = textView.getBackground().getBounds();
Rect closes = closeButton.getDrawable().getBounds();
int x = (int) (px - view.getRotatedMapXForPoint(latLon.getLatitude(), latLon.getLongitude()));
int y = (int) (py - view.getRotatedMapYForPoint(latLon.getLatitude(), latLon.getLongitude()));
x += bs.width() / 2;
y += bs.height() + boxLeg.getMinimumHeight() - SHADOW_OF_LEG;
if (bs.contains(x, y)) {
return true;
int dclosex = x - bs.width() + CLOSE_BTN + closes.width();
int dclosey = y + CLOSE_BTN;
if(closes.intersects(dclosex - CLOSE_BTN, dclosey - CLOSE_BTN, dclosex + CLOSE_BTN, dclosey + CLOSE_BTN)) {
return 2;
} else if (bs.contains(x, y)) {
return 1;
}
}
return false;
return 0;
}
public String getSelectedObjectName(){
@ -250,7 +270,12 @@ public class ContextMenuLayer extends OsmandMapLayer {
@Override
public boolean onSingleTap(PointF point) {
boolean nativeMode = view.getSettings().SCROLL_MAP_BY_GESTURES.get();
if ((!nativeMode) || pressedInTextView(point.x, point.y)) {
int val = pressedInTextView(point.x, point.y);
if (val == 2) {
setLocation(null, ""); //$NON-NLS-1$
view.refreshMap();
return true;
} else if (val == 1 || !nativeMode) {
if (!selectedObjects.isEmpty()) {
showContextMenuForSelectedObjects();
} else if (nativeMode) {
@ -292,9 +317,13 @@ public class ContextMenuLayer extends OsmandMapLayer {
public boolean onTouchEvent(MotionEvent event) {
if (latLon != null) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if(pressedInTextView(event.getX(), event.getY())){
int vl = pressedInTextView(event.getX(), event.getY());
if(vl == 1){
textView.setPressed(true);
view.refreshMap();
} else if(vl == 2){
closeButton.setPressed(true);
view.refreshMap();
}
}
}
@ -303,6 +332,10 @@ public class ContextMenuLayer extends OsmandMapLayer {
textView.setPressed(false);
view.refreshMap();
}
if(closeButton.isPressed()) {
closeButton.setPressed(false);
view.refreshMap();
}
}
return false;
}