Merge branch 'mapref'

This commit is contained in:
Victor Shcherb 2015-03-15 22:26:24 +01:00
commit 0df70fce6c
129 changed files with 6274 additions and 4204 deletions

View file

@ -13,3 +13,4 @@ split.density=false
target=android-21
dex.force.jumbo=true
android.library.reference.1=../appcompat
android.library.reference.2=../eclipse-compile/fab

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"><shape android:shape="oval">
<solid android:color="@color/map_widget_light_pressed" />
<stroke android:color="@color/map_widget_stroke" android:width="@dimen/map_button_stroke"/>
</shape></item>
<item><shape android:shape="oval">
<solid android:color="@color/map_widget_light" />
<stroke android:color="@color/map_widget_stroke" android:width="@dimen/map_button_stroke"/>
</shape></item>
</selector>

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"><shape android:shape="oval">
<solid android:color="@color/map_widget_blue_pressed" />
<stroke android:color="@color/map_widget_stroke" android:width="@dimen/map_button_stroke"/>
</shape></item>
<item><shape android:shape="oval">
<solid android:color="@color/map_widget_blue" />
<stroke android:color="@color/map_widget_stroke" android:width="@dimen/map_button_stroke"/>
</shape></item>
</selector>

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"><shape android:shape="oval">
<solid android:color="@color/map_widget_light_pressed" />
<stroke android:color="@color/map_widget_stroke" android:width="@dimen/map_button_stroke"/>
</shape></item>
<item><shape android:shape="oval">
<solid android:color="@color/map_widget_light_trans" />
<stroke android:color="@color/map_widget_stroke" android:width="@dimen/map_button_stroke"/>
</shape></item>
</selector>

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"><inset android:insetBottom="@dimen/map_button_inset" android:insetLeft="@dimen/map_button_inset" android:insetRight="@dimen/map_button_inset" android:insetTop="@dimen/map_button_inset">
<shape android:shape="oval">
<solid android:color="@color/map_widget_light_pressed" />
</shape>
</inset></item>
</selector>

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"><shape android:shape="rectangle">
<solid android:color="@color/map_widget_light_pressed" />
<stroke android:width="@dimen/map_button_stroke" android:color="@color/map_widget_stroke" />
</shape></item>
<item><shape android:shape="rectangle">
<solid android:color="@color/map_widget_light" />
<stroke android:width="@dimen/map_button_stroke" android:color="@color/map_widget_stroke" />
</shape></item>
</selector>

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"><shape android:shape="rectangle">
<solid android:color="@color/map_widget_dark_pressed" />
<stroke android:width="@dimen/map_button_stroke" android:color="@color/map_widget_stroke" />
</shape></item>
<item><shape android:shape="rectangle">
<solid android:color="@color/map_widget_dark" />
<stroke android:width="@dimen/map_button_stroke" android:color="@color/map_widget_stroke" />
</shape></item>
</selector>

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"><shape android:shape="rectangle">
<solid android:color="@color/map_widget_light_pressed" />
<stroke android:width="@dimen/map_button_stroke" android:color="@color/map_widget_stroke" />
</shape></item>
<item><shape android:shape="rectangle">
<solid android:color="@color/map_widget_light_trans" />
<stroke android:width="@dimen/map_button_stroke" android:color="@color/map_widget_stroke" />
</shape></item>
</selector>

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"><inset android:insetBottom="@dimen/map_button_inset" android:insetLeft="@dimen/map_button_inset" android:insetRight="@dimen/map_button_inset" android:insetTop="@dimen/map_button_inset">
<shape android:shape="oval">
<solid android:color="@color/map_widget_light_pressed" />
<stroke android:width="@dimen/map_button_stroke" android:color="@color/map_widget_stroke" />
</shape>
</inset></item>
<item><inset android:insetBottom="@dimen/map_button_inset" android:insetLeft="@dimen/map_button_inset" android:insetRight="@dimen/map_button_inset" android:insetTop="@dimen/map_button_inset">
<shape android:shape="oval">
<solid android:color="@color/map_widget_light" />
<stroke android:width="@dimen/map_button_stroke" android:color="@color/map_widget_stroke" />
</shape>
</inset></item>
</selector>

View file

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"><inset android:insetBottom="@dimen/map_button_inset" android:insetLeft="@dimen/map_button_inset" android:insetRight="@dimen/map_button_inset" android:insetTop="@dimen/map_button_inset">
<shape android:shape="oval">
<solid android:color="@color/map_widget_dark_pressed" />
<stroke android:color="@color/map_widget_stroke" android:width="@dimen/map_button_stroke"/>
</shape>
</inset></item>
<item><inset android:insetBottom="@dimen/map_button_inset" android:insetLeft="@dimen/map_button_inset" android:insetRight="@dimen/map_button_inset" android:insetTop="@dimen/map_button_inset">
<shape android:shape="oval">
<solid android:color="@color/map_widget_dark" />
<stroke android:color="@color/map_widget_stroke" android:width="@dimen/map_button_stroke"/>
</shape>
</inset></item>
</selector>

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"><inset android:insetBottom="@dimen/map_button_inset" android:insetLeft="@dimen/map_button_inset" android:insetRight="@dimen/map_button_inset" android:insetTop="@dimen/map_button_inset">
<shape android:shape="oval">
<solid android:color="@color/map_widget_light_pressed" />
<stroke android:width="@dimen/map_button_stroke" android:color="@color/map_widget_stroke" />
</shape>
</inset></item>
<item><inset android:insetBottom="@dimen/map_button_inset" android:insetLeft="@dimen/map_button_inset" android:insetRight="@dimen/map_button_inset" android:insetTop="@dimen/map_button_inset">
<shape android:shape="oval">
<solid android:color="@color/map_widget_light_trans" />
<stroke android:width="@dimen/map_button_stroke" android:color="@color/map_widget_stroke" />
</shape>
</inset></item>
</selector>

View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"><shape android:shape="rectangle">
<solid android:color="@color/map_widget_light_pressed" />
<corners android:radius="@dimen/map_button_rect_rad" />
<stroke android:color="@color/map_widget_stroke" android:width="@dimen/map_button_stroke"/>
</shape></item>
<item><shape android:shape="rectangle">
<solid android:color="@color/map_widget_light" />
<corners android:topLeftRadius="@dimen/map_button_rect_rad" android:bottomLeftRadius="@dimen/map_button_rect_rad" />
<stroke android:color="@color/map_widget_stroke" android:width="@dimen/map_button_stroke"/>
</shape></item>
</selector>

View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"><shape android:shape="rectangle">
<solid android:color="@color/map_widget_dark_pressed" />
<corners android:radius="@dimen/map_button_rect_rad" />
<stroke android:color="@color/map_widget_stroke" android:width="@dimen/map_button_stroke"/>
</shape></item>
<item><shape android:shape="rectangle">
<solid android:color="@color/map_widget_dark" />
<corners android:topLeftRadius="@dimen/map_button_rect_rad" android:bottomLeftRadius="@dimen/map_button_rect_rad" />
<stroke android:color="@color/map_widget_stroke" android:width="@dimen/map_button_stroke"/>
</shape></item>
</selector>

View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"><shape android:shape="rectangle">
<solid android:color="@color/map_widget_light_pressed" />
<corners android:radius="@dimen/map_button_rect_rad" />
<stroke android:color="@color/map_widget_stroke" android:width="@dimen/map_button_stroke"/>
</shape></item>
<item><shape android:shape="rectangle">
<solid android:color="@color/map_widget_light_trans" />
<corners android:topLeftRadius="@dimen/map_button_rect_rad" android:bottomLeftRadius="@dimen/map_button_rect_rad" />
<stroke android:color="@color/map_widget_stroke" android:width="@dimen/map_button_stroke"/>
</shape></item>
</selector>

View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"><shape android:shape="rectangle">
<solid android:color="@color/map_widget_light_pressed" />
<corners android:radius="@dimen/map_button_rect_rad" />
<stroke android:color="@color/map_widget_stroke" android:width="@dimen/map_button_stroke"/>
</shape></item>
<item><shape android:shape="rectangle">
<solid android:color="@color/map_widget_light" />
<corners
android:topRightRadius="@dimen/map_button_rect_rad"
android:bottomRightRadius="@dimen/map_button_rect_rad"
/>
<stroke android:color="@color/map_widget_stroke" android:width="@dimen/map_button_stroke"/>
</shape></item>
</selector>

View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"><shape android:shape="rectangle">
<solid android:color="@color/map_widget_dark_pressed" />
<corners android:radius="@dimen/map_button_rect_rad" />
<stroke android:color="@color/map_widget_stroke" android:width="@dimen/map_button_stroke"/>
</shape></item>
<item><shape android:shape="rectangle">
<solid android:color="@color/map_widget_dark" />
<corners
android:topRightRadius="@dimen/map_button_rect_rad"
android:bottomRightRadius="@dimen/map_button_rect_rad"
/>
<stroke android:color="@color/map_widget_stroke" android:width="@dimen/map_button_stroke"/>
</shape></item>
</selector>

View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"><shape android:shape="rectangle">
<solid android:color="@color/map_widget_light_pressed" />
<corners android:radius="@dimen/map_button_rect_rad" />
<stroke android:color="@color/map_widget_stroke" android:width="@dimen/map_button_stroke"/>
</shape></item>
<item><shape android:shape="rectangle">
<solid android:color="@color/map_widget_light_trans" />
<corners
android:topRightRadius="@dimen/map_button_rect_rad"
android:bottomRightRadius="@dimen/map_button_rect_rad"
/>
<stroke android:color="@color/map_widget_stroke" android:width="@dimen/map_button_stroke"/>
</shape></item>
</selector>

View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"><shape android:shape="rectangle">
<solid android:color="@color/map_widget_light_pressed" />
<corners android:radius="@dimen/map_button_rect_rad" />
<stroke android:width="@dimen/map_button_stroke" android:color="@color/map_widget_stroke" />
</shape></item>
<item><shape android:shape="rectangle">
<solid android:color="@color/map_widget_light" />
<corners android:radius="@dimen/map_button_rect_rad" />
<stroke android:width="@dimen/map_button_stroke" android:color="@color/map_widget_stroke" />
</shape></item>
</selector>

View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"><shape android:shape="rectangle">
<solid android:color="@color/map_widget_dark_pressed" />
<corners android:radius="@dimen/map_button_rect_rad" />
<stroke android:width="@dimen/map_button_stroke" android:color="@color/map_widget_stroke" />
</shape></item>
<item><shape android:shape="rectangle">
<solid android:color="@color/map_widget_dark" />
<corners android:radius="@dimen/map_button_rect_rad" />
<stroke android:width="@dimen/map_button_stroke" android:color="@color/map_widget_stroke" />
</shape></item>
</selector>

View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"><shape android:shape="rectangle">
<solid android:color="@color/map_widget_light_pressed" />
<corners android:radius="@dimen/map_button_rect_rad" />
<stroke android:width="@dimen/map_button_stroke" android:color="@color/map_widget_stroke" />
</shape></item>
<item><shape android:shape="rectangle">
<solid android:color="@color/map_widget_light_trans" />
<corners android:radius="@dimen/map_button_rect_rad" />
<stroke android:width="@dimen/map_button_stroke" android:color="@color/map_widget_stroke" />
</shape></item>
</selector>

View file

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"><shape android:shape="oval">
<solid android:color="#eeaaaaaa" />
</shape></item>
<item><shape android:shape="oval">
<solid android:color="#eeffffff" />
</shape></item>
</selector>

View file

@ -48,7 +48,7 @@
<include
android:id="@+id/map_part_dashboard"
android:layout_width="match_parent"
android:layout_height="@dimen/dashboard_map_top_padding"
android:layout_height="match_parent"
layout="@layout/map_view_on_dashboard" />
</LinearLayout>

View file

@ -1,64 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/ParentLayout"
android:clipChildren="false"
android:keepScreenOn="true"
android:orientation="vertical">
<FrameLayout
android:id="@+id/MapViewWithLayers"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:keepScreenOn="true"
android:orientation="vertical" >
<ViewStub
android:id="@+id/atlasMapRendererViewStub"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inflatedId="@+id/atlasMapRendererView"
android:layout="@layout/atlas_map_renderer_view"/>
<ViewStub
android:id="@+id/atlasMapRendererViewStub"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inflatedId="@+id/atlasMapRendererView"
android:layout="@layout/atlas_map_renderer_view" />
<net.osmand.plus.views.OsmAndMapSurfaceView
android:id="@+id/MapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:contentDescription="@string/shared_string_map"
android:visibility="gone"/>
<net.osmand.plus.views.OsmAndMapSurfaceView
android:id="@+id/MapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:contentDescription="@string/shared_string_map"
android:visibility="gone" />
<net.osmand.plus.views.OsmAndMapLayersView
android:id="@+id/MapLayersView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:contentDescription="@string/shared_string_map"
android:visibility="gone"/>
<net.osmand.plus.views.OsmAndMapLayersView
android:id="@+id/MapLayersView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:contentDescription="@string/shared_string_map"
android:visibility="gone" />
<FrameLayout android:id="@+id/MapInfoControls"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
<LinearLayout
android:id="@+id/dialog_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal"/>
<FrameLayout
android:id="@+id/MapHudButtonsOverlay"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<include layout="@layout/map_hud_top" />
<include layout="@layout/map_hud_bottom" />
</FrameLayout>
<include
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@layout/dashboard_over_map" />
<FrameLayout android:id="@+id/MapButtons"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
<ListView
android:id="@+id/left_drawer"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="?attr/expandable_list_background"
android:choiceMode="singleChoice"
android:divider="@drawable/divider"
android:dividerHeight="1dp"/>
<ListView
android:id="@+id/left_drawer"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="?attr/expandable_list_background"
android:choiceMode="singleChoice"
android:divider="@drawable/divider"
android:dividerHeight="1dp" />
</android.support.v4.widget.DrawerLayout>

View file

@ -0,0 +1,253 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="vertical" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<FrameLayout
android:id="@+id/map_alarm_warning"
android:layout_gravity="bottom|left"
android:layout_marginBottom="@dimen/map_alarm_bottom_margin"
android:layout_marginLeft="@dimen/map_button_shadow_margin"
android:layout_width="@dimen/map_alarm_size"
android:layout_height="@dimen/map_alarm_size">
<ImageView
android:id="@+id/map_alarm_warning_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/warnings_limit" />
<TextView
android:id="@+id/map_alarm_warning_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textStyle="bold"
android:textColor="@color/color_black"
android:textSize="@dimen/map_alarm_text_size"
android:text="60"/>
</FrameLayout>
<FrameLayout
android:id="@+id/map_app_mode_shadow"
android:layout_width="@dimen/map_button_shadow_width"
android:layout_height="@dimen/map_button_shadow_height"
android:layout_gravity="bottom|left"
android:layout_marginBottom="@dimen/map_button_shadow_margin"
android:layout_marginLeft="@dimen/map_button_shadow_margin"
android:background="@drawable/btn_round_trans" >
<ImageView
android:id="@+id/map_app_mode_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:layout_marginTop="3dp"
android:src="@drawable/ic_action_remove_light" />
<TextView
android:id="@+id/map_app_mode_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:layout_marginTop="3dp"
android:textSize="@dimen/map_button_text_size" />
</FrameLayout>
<LinearLayout
android:id="@+id/map_transparency_layout"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="bottom|center"
android:layout_marginBottom="@dimen/map_button_size"
android:orientation="horizontal" >
<SeekBar
android:id="@+id/map_transparency_seekbar"
android:layout_height="wrap_content"
android:layout_width="@dimen/map_trans_seek_size"
android:layout_gravity="center"
/>
<ImageButton
android:id="@+id/map_transparency_hide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/btn_circle_transparent"
android:src="@drawable/headliner_close" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|left"
android:layout_marginBottom="@dimen/map_button_margin"
android:layout_marginLeft="@dimen/map_button_margin" >
<ImageButton
android:id="@+id/map_menu_button"
android:layout_width="@dimen/map_button_size"
android:layout_height="@dimen/map_button_size"
android:background="@drawable/btn_round"
android:src="@drawable/ic_action_remove_light" />
<ImageButton
android:id="@+id/map_route_info_button"
android:layout_width="@dimen/map_button_size"
android:layout_height="@dimen/map_button_size"
android:layout_marginLeft="@dimen/map_button_spacing"
android:background="@drawable/btn_round"
android:src="@drawable/ic_action_remove_light" />
<FrameLayout
android:id="@+id/map_ruler_layout"
android:layout_width="@dimen/map_ruler_width"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginLeft="@dimen/map_button_margin">
<TextView
android:id="@+id/map_ruler_text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="@dimen/map_ruler_bottom_margin"
android:text="100 m"
android:gravity="center_horizontal"
android:layout_gravity="bottom"
android:textSize="@dimen/map_widget_text_size_small"
/>
<ImageView
android:id="@+id/map_ruler_image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@drawable/ruler"
/>
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_marginBottom="@dimen/map_button_margin"
android:layout_marginRight="@dimen/map_button_margin" >
<ImageButton
android:id="@+id/map_my_location_button"
android:layout_width="@dimen/map_button_size"
android:layout_height="@dimen/map_button_size"
android:layout_gravity="bottom"
android:background="@drawable/btn_circle"
android:src="@drawable/ic_action_remove_light" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginLeft="@dimen/map_button_spacing"
android:orientation="vertical" >
<ImageButton
android:id="@+id/map_zoom_in_button"
android:layout_width="@dimen/map_button_size"
android:layout_height="@dimen/map_button_size"
android:background="@drawable/btn_circle"
android:src="@drawable/ic_action_remove_light" />
<ImageButton
android:id="@+id/map_zoom_out_button"
android:layout_width="@dimen/map_button_size"
android:layout_height="@dimen/map_button_size"
android:layout_marginTop="@dimen/map_button_spacing"
android:background="@drawable/btn_circle"
android:src="@drawable/ic_action_remove_light" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/map_route_preparation_layout"
android:layout_width="match_parent"
android:layout_height="@dimen/map_route_buttons_height"
android:layout_gravity="bottom" >
<ImageButton
android:id="@+id/map_cancel_route_button"
android:layout_width="@dimen/map_route_buttons_width"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:background="@drawable/btn_flat"
android:src="@drawable/ic_action_remove_light" />
<ImageButton
android:id="@+id/map_waypoints_route_button"
android:layout_width="@dimen/map_route_buttons_width"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:background="@drawable/btn_flat"
android:src="@drawable/ic_action_remove_light" />
<ImageButton
android:id="@+id/map_options_route_button"
android:layout_width="@dimen/map_route_buttons_width"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:background="@drawable/btn_flat"
android:src="@drawable/ic_action_remove_light" />
<TextView
android:id="@+id/map_go_route_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:background="@drawable/btn_flat"
android:drawableLeft="@drawable/ic_action_remove_light"
android:drawablePadding="4dp"
android:gravity="center_vertical"
android:paddingLeft="12dp"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="@+id/map_context_menu_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@drawable/btn_flat"
android:visibility="gone" >
<TextView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:ellipsize="end"
android:gravity="center" >
</TextView>
<ImageButton
android:layout_width="@dimen/map_address_height"
android:layout_height="@dimen/map_address_height"
android:layout_gravity="center_vertical"
android:background="@drawable/btn_circle_transparent"
android:src="@drawable/ic_action_remove_light" />
<ImageButton
android:layout_width="@dimen/map_address_height"
android:layout_height="@dimen/map_address_height"
android:layout_gravity="center_vertical"
android:background="@drawable/btn_circle_transparent"
android:src="@drawable/ic_action_remove_light" />
</LinearLayout>
</FrameLayout>
</LinearLayout>

View file

@ -0,0 +1,239 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<!-- TOP ROW -->
<FrameLayout
android:id="@+id/map_top_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/btn_flat"
android:minHeight="@dimen/map_address_height" >
<!-- android:layout_weight="1" to show properly next turn -->
<TextView
android:id="@+id/map_address_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
android:shadowColor="@color/color_myloc_distance"
android:shadowRadius="10"
android:text="Long Street Name"
android:textColor="@color/color_black"
android:textSize="@dimen/map_widget_text_size"
android:textStyle="bold" >
</TextView>
<LinearLayout
android:id="@+id/waypoint_info_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="@+id/waypoint_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="@dimen/map_button_margin"
android:layout_marginRight="@dimen/map_button_margin"
android:src="@drawable/ic_action_remove_light" />
<TextView
android:id="@+id/waypoint_dist"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="4dp"
android:maxLines="2"
android:textColor="@color/wpt_distance_color"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="@+id/waypoint_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="4dp"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="2"
android:textSize="18sp" />
<ImageButton
android:id="@+id/waypoint_more"
android:layout_width="@dimen/map_address_height"
android:layout_height="@dimen/map_address_height"
android:background="@drawable/btn_circle_transparent"
android:src="@drawable/ic_overflow_menu_white" />
<ImageButton
android:id="@+id/waypoint_close"
android:layout_width="@dimen/map_address_height"
android:layout_height="@dimen/map_address_height"
android:background="@drawable/btn_circle_transparent"
android:src="@drawable/ic_action_remove_light" />
</LinearLayout>
</FrameLayout>
<!-- Widgets -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- LEFT widgets colon -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="top|left"
android:layout_weight="0.4"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/map_left_widgets_panel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|left"
android:orientation="vertical" >
<include layout="@layout/map_hud_widget" />
<include layout="@layout/map_hud_widget" />
<include layout="@layout/map_hud_widget" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|left"
android:layout_marginLeft="@dimen/map_button_margin"
android:layout_marginTop="@dimen/map_button_margin"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/map_layers_button"
android:layout_width="@dimen/map_button_size"
android:layout_height="@dimen/map_button_size"
android:background="@drawable/btn_inset_circle"
android:src="@drawable/ic_action_remove_light" />
<ImageButton
android:id="@+id/map_compass_button"
android:layout_width="@dimen/map_button_size"
android:layout_height="@dimen/map_button_size"
android:background="@drawable/btn_inset_circle"
android:src="@drawable/ic_action_remove_light" />
</LinearLayout>
</LinearLayout>
<!-- empty block to not let widgets grow more than 40% -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0.6" >
</LinearLayout>
</LinearLayout>
<!-- CENTER -->
<LinearLayout
android:id="@+id/map_center_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:layout_marginTop="@dimen/map_button_margin"
android:background="@drawable/btn_round"
android:orientation="vertical" >
<ImageView
android:id="@+id/map_lanes"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/map_lanes_dist_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:maxLines="1"
android:text="1048 km"
android:textColor="@color/color_black"
android:textSize="@dimen/map_widget_text_size_small" />
<ProgressBar
android:id="@+id/map_horizontal_progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="@dimen/map_routing_progress_width"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/map_button_margin"
android:layout_marginRight="@dimen/map_button_margin"
android:max="100"
android:progress="60"
android:visibility="gone" />
</LinearLayout>
<!-- RIGHT widgets colon -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1" >
<!-- empty block to not let widgets grow more than 40% -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0.6" >
</LinearLayout>
<FrameLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="top|right"
android:layout_weight="0.4" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|right"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/map_right_widgets_panel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|right"
android:orientation="vertical" >
<include layout="@layout/map_hud_widget" />
<include layout="@layout/map_hud_widget" />
</LinearLayout>
<ImageButton
android:id="@+id/map_collapse_button"
android:layout_width="@dimen/map_button_size"
android:layout_height="@dimen/map_button_size"
android:layout_gravity="top|center_horizontal"
android:background="@drawable/btn_inset_circle"
android:src="@drawable/ic_action_remove_light" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</FrameLayout>
</LinearLayout>

View file

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="@+id/widget_bg"
android:minWidth="100dp"
android:layout_height="wrap_content"
android:background="@drawable/btn_left_round"
android:orientation="vertical">
<ImageView
android:id="@+id/widget_top_icon"
android:layout_width="@dimen/map_widget_image"
android:layout_height="@dimen/map_widget_image"
android:layout_gravity="center"
android:src="@drawable/ic_action_close_light"
android:visibility="gone" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="@dimen/map_widget_height"
android:orientation="horizontal" >
<ImageView
android:layout_width="@dimen/map_widget_icon"
android:layout_height="@dimen/map_widget_icon"
android:id="@+id/widget_icon"
android:gravity="center"
android:layout_gravity="left|center_vertical"
android:src="@drawable/ic_action_remove_light"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/widget_text"
android:layout_gravity="bottom"
android:layout_marginBottom="@dimen/map_widget_text_bottom_margin"
android:layout_weight="1"
android:minWidth="10dp"
android:maxLines="1"
android:shadowColor="@color/color_myloc_distance"
android:textColor="@color/color_black"
android:shadowRadius="10"
android:textSize="@dimen/map_widget_text_size"
android:text="1048" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/widget_text_small"
android:layout_marginLeft="4dp"
android:layout_gravity="bottom"
android:layout_marginBottom="@dimen/map_widget_text_bottom_margin"
android:layout_marginRight="4dp"
android:maxLines="1"
android:shadowColor="@color/color_myloc_distance"
android:textColor="@color/color_black"
android:shadowRadius="10"
android:textSize="@dimen/map_widget_text_size_small"
android:text="km" />
</LinearLayout>
</LinearLayout>

View file

@ -4,20 +4,21 @@
android:layout_height="fill_parent" >
<ImageButton
android:id="@+id/map_layers_button"
android:id="@+id/map_menu_button"
android:layout_width="@dimen/map_button_size"
android:layout_height="@dimen/map_button_size"
android:layout_gravity="top|left"
android:layout_marginLeft="@dimen/map_button_margin"
android:layout_marginTop="@dimen/map_button_margin"
android:background="@drawable/roundedbutton"
android:src="@drawable/ic_action_layers_light" />
android:background="@drawable/btn_inset_circle"
android:src="@drawable/ic_action_remove_light" />
<Button
android:id="@+id/map_download_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone"
android:text="@string/shared_string_download" />
</FrameLayout>

View file

@ -16,6 +16,15 @@
<color name="list_item_light_pressed">#8cd0d0d0</color>
<color name="list_item_background_dark">#333b40</color>
<color name="list_item_background_dark_pressed">#be39464d</color>
<color name="map_widget_stroke">#333333</color>
<color name="map_widget_light">#eeffffff</color>
<color name="map_widget_dark">#aa3f3f3f</color>
<color name="map_widget_dark_pressed">#ddcccccc</color>
<color name="map_widget_light_trans">#88bbbbbb</color>
<color name="map_widget_light_pressed">#ddcccccc</color>
<color name="map_widget_blue">#30A0FF</color>
<color name="map_widget_blue_pressed">#dd30D0FF</color>
<color name="actionbar_dark_color">#39464d</color>

View file

@ -47,10 +47,36 @@
<dimen name="dashboard_map_bottom_padding">90dp</dimen>
<dimen name="dashboard_parking_left_margin">16dp</dimen>
<dimen name="dashboard_parking_icon_size">48dp</dimen>
<dimen name="map_button_size">40dp</dimen>
<dimen name="map_button_margin">8dp</dimen>
<dimen name="osmo_header_height">56dp</dimen>
<!-- map buttons -->
<dimen name="map_trans_seek_size">80dp</dimen>
<dimen name="map_widget_text_size">23sp</dimen>
<dimen name="map_widget_text_size_small">15sp</dimen>
<dimen name="map_widget_text_bottom_margin">0sp</dimen>
<dimen name="map_button_text_size">18sp</dimen>
<dimen name="map_route_buttons_width">60dp</dimen>
<dimen name="map_route_buttons_height">54dp</dimen>
<dimen name="map_address_height">40dp</dimen>
<dimen name="map_button_size">48dp</dimen>
<dimen name="map_ruler_width">120dp</dimen>
<dimen name="map_ruler_bottom_margin">7dp</dimen>
<dimen name="map_button_shadow_width">52dp</dimen>
<dimen name="map_alarm_size">78dp</dimen>
<dimen name="map_alarm_text_size">25sp</dimen>
<dimen name="map_alarm_bottom_margin">87dp</dimen>
<dimen name="map_button_shadow_height">85dp</dimen>
<dimen name="map_widget_icon">24dp</dimen>
<dimen name="map_widget_height">32dp</dimen>
<dimen name="map_widget_image">80dp</dimen>
<dimen name="map_button_spacing">15dp</dimen>
<dimen name="map_button_margin">4dp</dimen>
<dimen name="map_routing_progress_width">100dp</dimen>
<dimen name="map_button_shadow_margin">2dp</dimen>
<dimen name="map_button_inset">4dp</dimen>
<dimen name="map_button_rect_rad">3dp</dimen>
<dimen name="map_button_stroke">1px</dimen>
<!-- TextSizes -->
<dimen name="list_header_text_size">14sp</dimen>

View file

@ -9,6 +9,9 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="delay_to_start_navigation_descr">Automatically start navigation after specified interval</string>
<string name="delay_to_start_navigation">Skip route planning</string>
<string name="shared_string_go">Go</string>
<string name="osmand_parking_outdated">Outdated</string>
<string name="action_create">Action create</string>
<string name="action_modify">Action modify</string>
@ -32,6 +35,7 @@
<string name="shared_string_cancel">Cancel</string>
<string name="shared_string_dismiss">Dismiss</string>
<string name="shared_string_yes">Yes</string>
<string name="shared_string_not_use">Not use</string>
<string name="shared_string_no">No</string>
<string name="shared_string_on">On</string>
<string name="shared_string_off">Off</string>

View file

@ -32,5 +32,10 @@
android:key="wake_on_voice_int"
android:title="@string/wake_on_voice"
android:summary="@string/wake_on_voice_descr" />
<ListPreference
android:key="delay_to_start_navigation"
android:title="@string/delay_to_start_navigation"
android:summary="@string/delay_to_start_navigation_descr" />
</PreferenceCategory>
</PreferenceScreen>

View file

@ -48,6 +48,7 @@ public class QuickAction extends CustomPopupWindow {
private boolean animateTrack;
private ViewGroup mTrack;
private ArrayList<ActionItem> actionList;
private boolean onTop;
/**
* Constructor
@ -85,6 +86,11 @@ public class QuickAction extends CustomPopupWindow {
animStyle = ANIM_AUTO;
animateTrack = true;
}
public void setOnAnchorOnTop(boolean top) {
this.onTop = top;
}
/**
* Animate track
@ -150,7 +156,7 @@ public class QuickAction extends CustomPopupWindow {
boolean onTop = true;
// display on bottom
if (rootHeight > anchor.getTop()) {
if (rootHeight > anchor.getTop() && !this.onTop) {
yPos = anchorRect.bottom;
onTop = false;
}

View file

@ -231,17 +231,18 @@ public class AppInitializer implements IProgress {
}
private void indexRegionsBoundaries(boolean overwrite) {
private void indexRegionsBoundaries(List<String> warnings) {
try {
File file = app.getAppPath("regions.ocbf");
if (file != null) {
if (!file.exists() || overwrite) {
if (!file.exists()) {
Algorithms.streamCopy(OsmandRegions.class.getResourceAsStream("regions.ocbf"),
new FileOutputStream(file));
}
app.regions.prepareFile(file.getAbsolutePath());
}
app.regions.prepareFile(file.getAbsolutePath());
} catch (IOException e) {
} catch (Exception e) {
warnings.add(e.getMessage());
LOG.error(e.getMessage(), e);
}
}
@ -392,7 +393,7 @@ public class AppInitializer implements IProgress {
app.poiFilters.reloadAllPoiFilters();
notifyEvent(InitEvents.POI_TYPES_INITIALIZED);
indexRegionsBoundaries(false);
indexRegionsBoundaries(warnings);
notifyEvent(InitEvents.INDEX_REGION_BOUNDARIES);
app.selectedGpxHelper.loadGPXTracks(this);
notifyEvent(InitEvents.LOAD_GPX_TRACKS);

View file

@ -52,6 +52,7 @@ public class ApplicationMode {
static {
ApplicationMode[] exceptPedestrianAndDefault = new ApplicationMode[] { CAR, BICYCLE, BOAT, AIRCRAFT };
ApplicationMode[] exceptAirBoat = new ApplicationMode[] { DEFAULT, CAR, BICYCLE, PEDESTRIAN };
ApplicationMode[] exceptAirBoatDefault = new ApplicationMode[] { CAR, BICYCLE, PEDESTRIAN };
ApplicationMode[] pedestrian = new ApplicationMode[] { PEDESTRIAN };
ApplicationMode[] pedestrianBicycle = new ApplicationMode[] { PEDESTRIAN, BICYCLE };
@ -75,7 +76,7 @@ public class ApplicationMode {
// top
regWidget("compass", all);
regWidget("config", none);
regWidget("street_name", exceptAirBoat);
regWidget("street_name", exceptAirBoatDefault);
regWidget("back_to_location", all);
regWidget("monitoring_services", none);
regWidget("bgService", none);

View file

@ -151,7 +151,6 @@ public class OsmAndAppCustomization {
return osmandSettings.getExternalStorageDirectory();
}
public boolean showNavigationControls() { return true;}
public boolean onlyTourDownload() {
return false;

View file

@ -43,12 +43,15 @@ public class OsmAndFormatter {
int generator = 1;
byte pointer = 1;
double point = mainUnitInMeter;
double roundDist = 1;
while (distInMeters * point > generator) {
roundDist = (generator / point);
if (pointer++ % 3 == 2) {
generator = generator * 5 / 2;
} else {
generator *= 2;
}
if (point == mainUnitInMeter && metersInSecondUnit * mainUnitInMeter * 0.9f <= generator) {
point = 1 / metersInSecondUnit;
generator = 1;
@ -56,7 +59,7 @@ public class OsmAndFormatter {
}
}
return (generator / point);
return roundDist;
}
public static String getFormattedRoundDistanceKm(float meters, int digits, OsmandApplication ctx) {

View file

@ -66,16 +66,12 @@ import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewStub;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
@ -109,7 +105,6 @@ public class MapActivity extends AccessibleActivity {
private List<DialogProvider> dialogProviders = new ArrayList<DialogProvider>(2);
private StateChangedListener<ApplicationMode> applicationModeListener;
private FrameLayout lockView;
private GpxImportHelper gpxImportHelper;
private WakeLockHelper wakeLockHelper;
private boolean intentLocation = false;
@ -139,57 +134,15 @@ public class MapActivity extends AccessibleActivity {
// Full screen is not used here
// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
mapView = new OsmandMapTileView();
mapView.init(this);
mapView = new OsmandMapTileView(this);
mapActions = new MapActivityActions(this);
mapLayers = new MapActivityLayers(this);
if (mapViewTrackingUtilities == null) {
mapViewTrackingUtilities = new MapViewTrackingUtilities(app);
}
dashboardOnMap.createDashboardView();
if (app.isApplicationInitializing() || DashboardOnMap.staticVisible) {
dashboardOnMap.setDashboardVisibility(true);
}
if (app.isApplicationInitializing()) {
findViewById(R.id.init_progress).setVisibility(View.VISIBLE);
initListener = new AppInitializeListener() {
boolean openGlSetup = false;
@Override
public void onProgress(AppInitializer init, InitEvents event) {
String tn = init.getCurrentInitTaskName();
if (tn != null) {
((TextView) findViewById(R.id.ProgressMessage)).setText(tn);
}
if(event == InitEvents.NATIVE_INITIALIZED) {
setupOpenGLView();
openGlSetup = true;
}
if(event == InitEvents.MAPS_INITIALIZED) {
mapView.refreshMap(true);
}
}
@Override
public void onFinish(AppInitializer init) {
if(!openGlSetup) {
setupOpenGLView();
}
mapView.refreshMap(true);
findViewById(R.id.init_progress).setVisibility(View.GONE);
findViewById(R.id.ParentLayout).invalidate();
}
};
getMyApplication().checkApplicationIsBeingInitialized(this, initListener);
} else {
setupOpenGLView();
}
checkAppInitialization();
parseLaunchIntentLocation();
OsmAndMapSurfaceView surf = (OsmAndMapSurfaceView) findViewById(R.id.MapView);
surf.setVisibility(View.VISIBLE);
surf.setMapView(mapView);
mapView.setTrackBallDelegate(new OsmandMapTileView.OnTrackBallListener() {
@Override
public boolean onTrackBallEvent(MotionEvent e) {
@ -231,21 +184,56 @@ public class MapActivity extends AccessibleActivity {
}
addDialogProvider(mapActions);
OsmandPlugin.onMapActivityCreate(this);
if (lockView != null) {
((FrameLayout) mapView.getParent()).addView(lockView);
}
gpxImportHelper = new GpxImportHelper(this, getMyApplication(), getMapView());
mapActions.prepareStartOptionsMenu();
wakeLockHelper = new WakeLockHelper(getMyApplication());
if(System.currentTimeMillis() - tm > 50) {
System.err.println("OnCreate for MapActivity took " + (System.currentTimeMillis() - tm) + " ms");
}
mapView.refreshMap(true);
}
private void checkAppInitialization() {
if (app.isApplicationInitializing() || DashboardOnMap.staticVisible) {
dashboardOnMap.setDashboardVisibility(true);
}
if (app.isApplicationInitializing()) {
findViewById(R.id.init_progress).setVisibility(View.VISIBLE);
initListener = new AppInitializeListener() {
boolean openGlSetup = false;
@Override
public void onProgress(AppInitializer init, InitEvents event) {
String tn = init.getCurrentInitTaskName();
if (tn != null) {
((TextView) findViewById(R.id.ProgressMessage)).setText(tn);
}
if(event == InitEvents.NATIVE_INITIALIZED) {
setupOpenGLView(false);
openGlSetup = true;
}
if(event == InitEvents.MAPS_INITIALIZED) {
mapView.refreshMap(true);
}
}
@Override
public void onFinish(AppInitializer init) {
if(!openGlSetup) {
setupOpenGLView(false);
}
mapView.refreshMap(true);
findViewById(R.id.init_progress).setVisibility(View.GONE);
findViewById(R.id.drawer_layout).invalidate();
}
};
getMyApplication().checkApplicationIsBeingInitialized(this, initListener);
} else {
setupOpenGLView(true);
}
}
private void setupOpenGLView() {
private void setupOpenGLView(boolean init) {
if (settings.USE_OPENGL_RENDER.get() && NativeCoreContext.isInit()) {
ViewStub stub = (ViewStub) findViewById(R.id.atlasMapRendererViewStub);
atlasMapRendererView = (AtlasMapRendererView) stub.inflate();
@ -259,33 +247,22 @@ public class MapActivity extends AccessibleActivity {
mapView.setMapRender(atlasMapRendererView);
OsmAndMapSurfaceView surf = (OsmAndMapSurfaceView) findViewById(R.id.MapView);
surf.setVisibility(View.GONE);
} else {
OsmAndMapSurfaceView surf = (OsmAndMapSurfaceView) findViewById(R.id.MapView);
surf.setVisibility(View.VISIBLE);
surf.setMapView(mapView);
}
}
public void addLockView(FrameLayout lockView) {
this.lockView = lockView;
}
private void createProgressBarForRouting() {
FrameLayout parent = (FrameLayout) mapView.getParent();
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL | Gravity.TOP);
DisplayMetrics dm = getResources().getDisplayMetrics();
params.topMargin = (int) (60 * dm.density);
final ProgressBar pb = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);
pb.setIndeterminate(false);
pb.setMax(100);
pb.setLayoutParams(params);
pb.setVisibility(View.GONE);
parent.addView(pb);
final ProgressBar pb = (ProgressBar) findViewById(R.id.map_horizontal_progress);
app.getRoutingHelper().setProgressBar(new RouteCalculationProgressCallback() {
@Override
public void updateProgress(int progress) {
pb.setVisibility(View.VISIBLE);
pb.setProgress(progress);
pb.requestLayout();
}
@Override

View file

@ -107,8 +107,8 @@ public class MapActivityActions implements DialogProvider {
settings = mapActivity.getMyApplication().getSettings();
routingHelper = mapActivity.getMyApplication().getRoutingHelper();
waypointDialogHelper = new WaypointDialogHelper(mapActivity);
waypointDialogHelper.init();
}
protected void addFavouritePoint(final double latitude, final double longitude){
String name = mapActivity.getMapLayers().getContextMenuLayer().getSelectedObjectName();
@ -953,6 +953,14 @@ public class MapActivityActions implements DialogProvider {
mDrawerList.setOnItemClickListener(waypointDialogHelper.getDrawerItemClickListener(mapActivity, running,
listAdapter, null));
}
public void showWaypointsDialog(boolean flat) {
if(flat) {
waypointDialogHelper.showWaypointsDialogFlat(mapActivity, false);
} else {
waypointDialogHelper.showWaypointsDialog(mapActivity, false);
}
}
public void disableDrawer(){
if(mDrawerLayout == null) {

View file

@ -5,9 +5,14 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.osmand.plus.*;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.DeviceAdminRecv;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.AutoZoomMap;
import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.routing.RouteProvider.RouteService;
import net.osmand.router.GeneralRouter;
import net.osmand.router.GeneralRouter.RoutingParameter;
@ -184,13 +189,22 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
if (!mode.isDerivedRoutingFrom(ApplicationMode.CAR)) {
category.removePreference(speedLimitExceed);
}
Integer[] delayIntervals = new Integer[] { -1, 3, 5, 7, 10, 15, 20 };
String[] delayIntervalNames = new String[delayIntervals.length];
for (int i = 0; i < delayIntervals.length; i++) {
if (i == 0) {
delayIntervalNames[i] = getString(R.string.shared_string_not_use);
} else {
delayIntervalNames[i] = delayIntervals[i] + " " + getString(R.string.int_seconds);
}
}
registerListPreference(settings.DELAY_TO_START_NAVIGATION, screen, delayIntervalNames, delayIntervals);
profileDialog();
}
private void prepareRoutingPrefs(PreferenceScreen screen) {
PreferenceCategory cat = (PreferenceCategory) screen.findPreference("routing_preferences");

View file

@ -104,10 +104,10 @@ public class StartGPSStatus extends OsmAndAction {
}
OsmandMapTileView view = mapActivity.getMapView();
AlertDialog.Builder builder = new AccessibleAlertBuilder(mapActivity);
LinearLayout ll = new LinearLayout(view.getContext());
final ListView lv = new ListView(view.getContext());
LinearLayout ll = new LinearLayout(activity);
final ListView lv = new ListView(activity);
lv.setPadding(7, 3, 7, 0);
final CheckBox cb = new CheckBox(view.getContext());
final CheckBox cb = new CheckBox(activity);
cb.setText(R.string.shared_string_remember_my_choice);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
lp.setMargins(7, 10, 7, 0);

View file

@ -31,14 +31,13 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.myplaces.FavoritesActivity;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.activities.TabActivity.TabItem;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.myplaces.FavoritesActivity;
import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.mapwidgets.StackWidgetView;
import net.osmand.plus.views.mapwidgets.TextInfoWidget;
import net.osmand.util.Algorithms;
import net.osmand.util.GeoPointParserUtil.GeoParsedPoint;
@ -518,10 +517,10 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
private void registerWidget(MapActivity activity) {
MapInfoLayer mapInfoLayer = activity.getMapLayers().getMapInfoLayer();
if (mapInfoLayer != null) {
recordControl = new TextInfoWidget(activity, 0, mapInfoLayer.getPaintText(), mapInfoLayer.getPaintSubText());
recordControl = new TextInfoWidget(activity);
recordControl.setImageDrawable(activity.getResources().getDrawable(R.drawable.monitoring_rec_inactive));
setRecordListener(recordControl, activity);
mapInfoLayer.getMapInfoControls().registerSideWidget(recordControl, R.drawable.widget_icon_av_inactive, R.drawable.widget_icon_av_inactive,
mapInfoLayer.registerSideWidget(recordControl, R.drawable.widget_icon_av_inactive, R.drawable.widget_icon_av_inactive,
R.string.map_widget_av_notes, "audionotes", false, 22);
mapInfoLayer.recreateControls();
}
@ -948,10 +947,10 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
recordControl.setText(app.getString(R.string.shared_string_control_stop), "");
recordControl.setImageDrawable(activity.getResources().getDrawable(R.drawable.widget_icon_av_active));
final MapInfoLayer mil = mapActivity.getMapLayers().getMapInfoLayer();
final StackWidgetView par = mil.getRightStack();
final boolean contains = par.getAllViews().contains(recordControl);
final boolean contains = recordControl.isVisible();
if (!contains) {
par.addStackView(recordControl);
recordControl.setExplicitlyVisible(true);
mil.recreateControls();
mapActivity.getMapView().refreshMap(true);
}
AccessibleToast.makeText(mapActivity, R.string.recording_is_recorded, Toast.LENGTH_LONG).show();
@ -959,7 +958,8 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
@Override
public void onClick(View v) {
if (!contains) {
par.removeView(recordControl);
recordControl.setExplicitlyVisible(false);
mil.recreateControls();
}
stopRecording(mapActivity);
SHOW_RECORDINGS.set(true);

View file

@ -18,6 +18,7 @@ import android.view.animation.Animation.AnimationListener;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ScrollView;
import com.software.shell.fab.ActionButton;
@ -56,7 +57,7 @@ public class DashboardOnMap {
private static final int CONFIGURE_SCREEN_ID = 3;
private static final int SETTINGS_ID = 4;
private MapActivity mapActivity;
ActionButton actionButton;
private ActionButton actionButton;
private FrameLayout dashboardView;
private boolean visible = false;
@ -69,6 +70,7 @@ public class DashboardOnMap {
private float mapRotation;
private boolean inLocationUpdate = false;
private boolean saveBackAction;
private ImageView switchButton;
public DashboardOnMap(MapActivity ma) {
@ -78,9 +80,11 @@ public class DashboardOnMap {
public void createDashboardView() {
landscape = !ScreenOrientationHelper.isOrientationPortrait(mapActivity);
dashboardView = (FrameLayout) mapActivity.getLayoutInflater().inflate(R.layout.dashboard_over_map, null, false);
dashboardView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
// dashboardView = (FrameLayout) mapActivity.getLayoutInflater().inflate(R.layout.dashboard_over_map, null, false);
// dashboardView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
// ViewGroup.LayoutParams.MATCH_PARENT));
// ((FrameLayout) mapActivity.findViewById(R.id.MapHudButtonsOverlay)).addView(dashboardView);
dashboardView = (FrameLayout) mapActivity.findViewById(R.id.dashboard);
View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -89,19 +93,19 @@ public class DashboardOnMap {
};
dashboardView.findViewById(R.id.animateContent).setOnClickListener(listener);
dashboardView.setOnClickListener(listener);
((FrameLayout) mapActivity.findViewById(R.id.ParentLayout)).addView(dashboardView);
dashboardView.findViewById(R.id.map_layers_button).setOnClickListener(new View.OnClickListener() {
switchButton = (ImageView) dashboardView.findViewById(R.id.map_menu_button);
switchButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setDashboardVisibility(false);
mapActivity.getMapActions().prepareConfigureMap();
mapActivity.getMyApplication().getSettings().USE_DASHBOARD_INSTEAD_OF_DRAWER.set(false);
mapActivity.getMapActions().toggleDrawer();
}
});
actionButton = new ActionButton(mapActivity);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
int marginRight = convertPixelsToDp(16, mapActivity);
@ -177,20 +181,19 @@ public class DashboardOnMap {
actionButton.show();
//fabButton.showFloatingActionButton();
open(dashboardView.findViewById(R.id.animateContent));
switchButton.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getIcon(R.drawable.ic_navigation_drawer,
R.color.icon_color_light));
mapActivity.getMapActions().disableDrawer();
mapActivity.findViewById(R.id.MapInfoControls).setVisibility(View.GONE);
mapActivity.findViewById(R.id.MapButtons).setVisibility(View.GONE);
mapActivity.findViewById(R.id.MapHudButtonsOverlay).setVisibility(View.INVISIBLE);
updateLocation(true, true, false);
} else {
mapActivity.getMapActions().enableDrawer();
mapActivity.getMapViewTrackingUtilities().setDashboard(null);
hide(dashboardView.findViewById(R.id.animateContent));
mapActivity.findViewById(R.id.MapInfoControls).setVisibility(View.VISIBLE);
mapActivity.findViewById(R.id.MapButtons).setVisibility(View.VISIBLE);
mapActivity.findViewById(R.id.MapHudButtonsOverlay).setVisibility(View.VISIBLE);
actionButton.hide();
//fabButton.hideFloatingActionButton();
for (WeakReference<DashBaseFragment> df : fragList) {
if (df.get() != null) {
df.get().onCloseDash();
@ -297,6 +300,7 @@ public class DashboardOnMap {
if(!routingHelper.isFollowingMode() && !routingHelper.isRoutePlanningMode()) {
mapActivity.getMapActions().enterRoutePlanningMode(null, null, false);
} else {
mapActivity.getRoutingHelper().setRoutePlanningMode(true);
mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode();
mapActivity.refreshMap();
}
@ -305,7 +309,7 @@ public class DashboardOnMap {
// To animate view slide out from right to left
private void open(View view){
TranslateAnimation animate = new TranslateAnimation(-mapActivity.findViewById(R.id.ParentLayout).getWidth(),0,0,0);
TranslateAnimation animate = new TranslateAnimation(-mapActivity.findViewById(R.id.MapHudButtonsOverlay).getWidth(),0,0,0);
animate.setDuration(500);
animate.setFillAfter(true);
view.startAnimation(animate);
@ -313,7 +317,7 @@ public class DashboardOnMap {
}
private void hide(View view) {
TranslateAnimation animate = new TranslateAnimation(0, -mapActivity.findViewById(R.id.ParentLayout).getWidth(), 0, 0);
TranslateAnimation animate = new TranslateAnimation(0, -mapActivity.findViewById(R.id.MapHudButtonsOverlay).getWidth(), 0, 0);
animate.setDuration(500);
animate.setFillAfter(true);
animate.setAnimationListener(new AnimationListener() {

View file

@ -10,6 +10,7 @@ import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
@ -45,7 +46,7 @@ public class DashSimulateFragment extends DashBaseFragment {
View item = inflater.inflate(R.layout.dash_simulate_item, null, false);
tracks.addView(item);
final OsmAndLocationProvider loc = getMyApplication().getLocationProvider();
((ImageButton) item.findViewById(R.id.stop)).setOnClickListener(new View.OnClickListener() {
OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -54,7 +55,9 @@ public class DashSimulateFragment extends DashBaseFragment {
dashboard.setDashboardVisibility(false);
}
}
});
};
item.setOnClickListener(listener);
((ImageButton) item.findViewById(R.id.stop)).setOnClickListener(listener);
((TextView) item.findViewById(R.id.name)).setText(R.string.animate_route);
item.findViewById(R.id.divider).setVisibility(View.VISIBLE);

View file

@ -53,7 +53,7 @@ public class OsmandDevelopmentPlugin extends OsmandPlugin {
MapInfoLayer mapInfoLayer = activity.getMapLayers().getMapInfoLayer();
final OsmandMapTileView mv = activity.getMapView();
if (mapInfoLayer != null) {
fps = new TextInfoWidget(activity, 0, mapInfoLayer.getPaintText(), mapInfoLayer.getPaintSubText()) {
fps = new TextInfoWidget(activity) {
@Override
public boolean updateInfo(DrawSettings drawSettings) {
if(!mv.isMeasureFPS()) {
@ -65,7 +65,7 @@ public class OsmandDevelopmentPlugin extends OsmandPlugin {
return true;
}
};
mapInfoLayer.getMapInfoControls().registerSideWidget(fps, R.drawable.widget_no_icon, R.drawable.widget_no_icon,
mapInfoLayer.registerSideWidget(fps, R.drawable.widget_no_icon, R.drawable.widget_no_icon,
R.string.map_widget_fps_info, "fps", false, 30);
mapInfoLayer.recreateControls();
}

View file

@ -31,7 +31,6 @@ import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.views.ContextMenuLayer;
import net.osmand.plus.views.MapInfoLayer;
@ -56,7 +55,6 @@ import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.PointF;
import android.os.AsyncTask;
import android.preference.PreferenceScreen;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
@ -118,8 +116,8 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
private void registerWidget(MapActivity activity) {
MapInfoLayer mapInfoLayer = activity.getMapLayers().getMapInfoLayer();
if (mapInfoLayer != null ) {
distanceControl = createDistanceControl(activity, mapInfoLayer.getPaintText(), mapInfoLayer.getPaintSubText());
mapInfoLayer.getMapInfoControls().registerSideWidget(distanceControl,
distanceControl = createDistanceControl(activity);
mapInfoLayer.registerSideWidget(distanceControl,
R.drawable.widget_distance, R.drawable.widget_distance, R.string.map_widget_distancemeasurement, "distance.measurement", false, 21);
mapInfoLayer.recreateControls();
updateText();
@ -371,8 +369,8 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
}
private TextInfoWidget createDistanceControl(final MapActivity activity, Paint paintText, Paint paintSubText) {
final TextInfoWidget distanceControl = new TextInfoWidget(activity, 0, paintText, paintSubText);
private TextInfoWidget createDistanceControl(final MapActivity activity) {
final TextInfoWidget distanceControl = new TextInfoWidget(activity);
distanceControl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

View file

@ -3,12 +3,10 @@ package net.osmand.plus.helpers;
import java.util.ArrayList;
import java.util.List;
import net.osmand.Location;
import net.osmand.data.LatLon;
import net.osmand.data.LocationPoint;
import net.osmand.data.PointDescription;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.IntermediatePointsDialog;
@ -16,23 +14,18 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper;
import net.osmand.plus.poi.PoiLegacyFilter;
import net.osmand.plus.views.AnimateDraggingMapThread;
import net.osmand.plus.views.MapControlsLayer;
import net.osmand.util.MapUtils;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnDismissListener;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
@ -41,16 +34,14 @@ import android.widget.CompoundButton;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
/**
*/
public class WaypointDialogHelper implements OsmAndLocationListener {
public class WaypointDialogHelper {
private MapActivity mapActivity;
private OsmandApplication app;
private LinearLayout mainLayout;
private WaypointHelper waypointHelper;
@ -62,79 +53,14 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
}
}
public final static boolean OVERLAP_LAYOUT = true; // only true is supported
private View closePointDialog;
private List<LocationPointWrapper> many = new ArrayList<WaypointHelper.LocationPointWrapper>();
public WaypointDialogHelper(MapActivity mapActivity) {
this.app = mapActivity.getMyApplication();
waypointHelper = this.app.getWaypointHelper();
this.mapActivity = mapActivity;
this.mainLayout = (LinearLayout) mapActivity.findViewById(R.id.dialog_layout);
}
public void init() {
app.getLocationProvider().addLocationListener(this);
}
@Override
public void updateLocation(Location location) {
if (mapActivity != null) {
updateDialog();
}
}
public void removeListener() {
app.getLocationProvider().removeLocationListener(this);
mapActivity = null;
}
@SuppressWarnings("deprecation")
public void updateDialog() {
final LocationPointWrapper point = waypointHelper.getMostImportantLocationPoint(many);
if (point == null) {
removeDialog();
} else {
boolean created = false;
View dlg = closePointDialog;
if (dlg == null) {
created = true;
final LayoutInflater vi = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
dlg = vi.inflate(R.layout.waypoint_reached, null);
}
updatePointInfoView(app, mapActivity, dlg, point, null);
View all = dlg.findViewById(R.id.all_points);
all.setVisibility(/*many.size() <= 1 ? View.GONE : */View.VISIBLE);
View btnN = dlg.findViewById(R.id.info_close);
btnN.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
waypointHelper.removeVisibleLocationPoint(point);
updateDialog();
}
});
if (created) {
dlg.setBackgroundDrawable(mapActivity.getResources().getDrawable(R.drawable.view_black_selection));
((TextView) dlg.findViewById(R.id.waypoint_text)).setTextColor(Color.WHITE);
all.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showWaypointsDialog(mapActivity, false);
}
});
closePointDialog = dlg;
mainLayout.addView(closePointDialog, getDialogLayoutParams());
waitBeforeLayoutIsResized(dlg);
}
}
}
private static void updatePointInfoView(final OsmandApplication app, final Activity ctx,
public static void updatePointInfoView(final OsmandApplication app, final MapActivity activity,
View localView, final LocationPointWrapper ps, final DialogFragment dialog) {
WaypointHelper wh = app.getWaypointHelper();
final LocationPoint point = ps.getPoint();
@ -142,15 +68,15 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
localView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showOnMap(app, ctx, point, dialog);
showOnMap(app, activity, point, dialog);
}
});
TextView textDist = (TextView) localView.findViewById(R.id.waypoint_dist);
((ImageView) localView.findViewById(R.id.waypoint_icon)).setImageDrawable(ps.getDrawable(ctx, app));
((ImageView) localView.findViewById(R.id.waypoint_icon)).setImageDrawable(ps.getDrawable(activity, app));
int dist = -1;
if (!wh.isRouteCalculated()) {
if (ctx instanceof MapActivity) {
dist = (int) MapUtils.getDistance(((MapActivity) ctx).getMapView().getLatitude(), ((MapActivity) ctx)
if (activity instanceof MapActivity) {
dist = (int) MapUtils.getDistance(((MapActivity) activity).getMapView().getLatitude(), ((MapActivity) activity)
.getMapView().getLongitude(), point.getLatitude(), point.getLongitude());
}
} else {
@ -171,54 +97,12 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
// 0);
}
public void removeDialog() {
if (closePointDialog != null) {
mainLayout.removeView(closePointDialog);
closePointDialog = null;
shiftButtons(0);
}
}
private FrameLayout.LayoutParams getDialogLayoutParams() {
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
return params;
}
private void shiftButtons(int height) {
MapControlsLayer mapControls = mapActivity.getMapLayers().getMapControlsLayer();
if (mapControls != null) {
mapControls.shiftLayout(height);
}
}
private void waitBeforeLayoutIsResized(View reachedView) {
//this async task is needed because layout height is not set
// right after you add it so we need to w8 some time
new AsyncTask<View, Void, Void>() {
int height;
@Override
protected Void doInBackground(View... params) {
for (int i = 0; i < 10; i++) {
SystemClock.sleep(50);
height = params[0].getHeight();
if (params[0].getHeight() > 0) {
break;
}
}
return null;
}
protected void onPostExecute(Void result) {
if (height > 0 && OVERLAP_LAYOUT) {
shiftButtons(height);
}
}
}.execute(reachedView);
}
public void showWaypointsDialogFlat(FragmentActivity fragmentActivity, boolean edit) {
Bundle args = new Bundle();
args.putBoolean(WaypointDialogFragment.FLAT_ARG, true);
@ -237,7 +121,7 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
}
public ArrayAdapter<Object> getWaypointsDrawerAdapter(final FragmentActivity ctx, final int[] running, final boolean flat) {
public ArrayAdapter<Object> getWaypointsDrawerAdapter(final MapActivity ctx, final int[] running, final boolean flat) {
final List<Object> points;
if(flat) {
points = new ArrayList<Object>(waypointHelper.getAllPoints());
@ -277,7 +161,7 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
}
public ArrayAdapter<Object> getWaypointsAdapter(final boolean edit, final List<LocationPointWrapper> deletedPoints,
final FragmentActivity ctx, final int[] running,
final MapActivity ctx, final int[] running,
final AlertDialog[] srcDialog, final DialogFragment dialogFragment) {
final List<Object> points = getPoints();
return new ArrayAdapter<Object>(ctx,
@ -734,7 +618,7 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
if (v == null || v.findViewById(R.id.waypoint_icon) == null) {
v = ctx.getLayoutInflater().inflate(R.layout.waypoint_reached, null);
}
updatePointInfoView(app, ctx, v, getItem(position), WaypointDialogFragment.this);
updatePointInfoView(app, (MapActivity) ctx, v, getItem(position), WaypointDialogFragment.this);
View remove = v.findViewById(R.id.info_close);
if (!edit) {
remove.setVisibility(View.GONE);
@ -790,7 +674,7 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
final ListView listView = new ListView(ctx);
final int[] running = new int[]{-1};
final AlertDialog[] srcDialog = new AlertDialog[1];
final ArrayAdapter<Object> listAdapter = getWaypointsAdapter(edit, deletedPoints, ctx,
final ArrayAdapter<Object> listAdapter = getWaypointsAdapter(edit, deletedPoints, (MapActivity) ctx,
running, srcDialog, WaypointDialogFragment.this);
listView.setAdapter(listAdapter);

View file

@ -18,12 +18,8 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.MonitoringInfoControl;
import net.osmand.plus.views.MonitoringInfoControl.MonitoringInfoControlServices;
import net.osmand.plus.views.MonitoringInfoControl.ValueHolder;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.mapwidgets.BaseMapWidget;
import net.osmand.plus.views.mapwidgets.TextInfoWidget;
import android.app.Activity;
import android.app.AlertDialog;
@ -31,8 +27,6 @@ import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.util.DisplayMetrics;
import android.view.View;
@ -47,11 +41,11 @@ import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
public class OsmandMonitoringPlugin extends OsmandPlugin implements MonitoringInfoControlServices {
public class OsmandMonitoringPlugin extends OsmandPlugin {
private static final String ID = "osmand.monitoring";
private OsmandSettings settings;
private OsmandApplication app;
private BaseMapWidget monitoringControl;
private TextInfoWidget monitoringControl;
private LiveMonitoringHelper liveMonitoringHelper;
private boolean ADD_BG_TO_ACTION = true;
private boolean isSaving;
@ -103,9 +97,9 @@ public class OsmandMonitoringPlugin extends OsmandPlugin implements MonitoringIn
@Override
public void registerLayers(MapActivity activity) {
MapInfoLayer layer = activity.getMapLayers().getMapInfoLayer();
monitoringControl = createMonitoringControl(activity, layer.getPaintText(), layer.getPaintSubText());
monitoringControl = createMonitoringControl(activity);
layer.getMapInfoControls().registerSideWidget(monitoringControl,
layer.registerSideWidget(monitoringControl,
R.drawable.monitoring_rec_big, R.drawable.monitoring_rec_big, R.string.map_widget_monitoring, "monitoring", false, 18);
layer.recreateControls();
}
@ -115,10 +109,6 @@ public class OsmandMonitoringPlugin extends OsmandPlugin implements MonitoringIn
if(monitoringControl == null) {
registerLayers(activity);
}
MonitoringInfoControl lock = activity.getMapLayers().getMapInfoLayer().getMonitoringInfoControl();
if(lock != null && !lock.getMonitorActions().contains(this)) {
lock.addMonitorActions(this);
}
}
@Override
@ -151,11 +141,11 @@ public class OsmandMonitoringPlugin extends OsmandPlugin implements MonitoringIn
/**
* creates (if it wasn't created previously) the control to be added on a MapInfoLayer that shows a monitoring state (recorded/stopped)
*/
private BaseMapWidget createMonitoringControl(final MapActivity map, Paint paintText, Paint paintSubText) {
private TextInfoWidget createMonitoringControl(final MapActivity map) {
final Drawable monitoringBig = map.getResources().getDrawable(R.drawable.monitoring_rec_big);
final Drawable monitoringSmall = map.getResources().getDrawable(R.drawable.monitoring_rec_small);
final Drawable monitoringInactive = map.getResources().getDrawable(R.drawable.monitoring_rec_inactive);
monitoringControl = new TextInfoWidget(map, 0, paintText, paintSubText) {
monitoringControl = new TextInfoWidget(map) {
long lastUpdateTime;
@Override
public boolean updateInfo(DrawSettings drawSettings) {
@ -164,7 +154,6 @@ public class OsmandMonitoringPlugin extends OsmandPlugin implements MonitoringIn
setImageDrawable(monitoringBig);
return true;
}
boolean visible = true;
String txt = map.getString(R.string.monitoring_control_start);
String subtxt = null;
Drawable d = monitoringInactive;
@ -202,8 +191,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin implements MonitoringIn
lastUpdateTime = last;
//blink implementation with 2 indicator states (global logging + profile/navigation logging)
setImageDrawable(monitoringInactive);
invalidate();
postDelayed(new Runnable() {
map.getMyApplication().runInUIThread(new Runnable() {
@Override
public void run() {
if (globalRecord) {
@ -211,11 +199,9 @@ public class OsmandMonitoringPlugin extends OsmandPlugin implements MonitoringIn
} else {
setImageDrawable(monitoringSmall);
}
invalidate();
}
}, 500);
}
updateVisibility(visible);
return true;
}
};
@ -458,38 +444,4 @@ public class OsmandMonitoringPlugin extends OsmandPlugin implements MonitoringIn
return ll;
}
@Override
public void addMonitorActions(final ContextMenuAdapter qa, final MonitoringInfoControl li, final OsmandMapTileView view) {
if (ADD_BG_TO_ACTION) {
final Intent serviceIntent = new Intent(view.getContext(), NavigationService.class);
final boolean bgoff = view.getApplication().getNavigationService() == null;
int msgId = !bgoff ? R.string.bg_service_sleep_mode_on : R.string.bg_service_sleep_mode_off;
int draw = !bgoff ? R.drawable.monitoring_rec_big : R.drawable.monitoring_rec_inactive;
qa.item(msgId).icon(draw).listen(new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
if (view.getApplication().getNavigationService() == null) {
final ValueHolder<Integer> vs = new ValueHolder<Integer>();
final ValueHolder<Boolean> choice = new ValueHolder<Boolean>();
vs.value = view.getSettings().SERVICE_OFF_INTERVAL.get();
showIntervalChooseDialog(view.getContext(), app.getString(R.string.gps_wakeup_interval),
app.getString(R.string.background_router_service),
SettingsMonitoringActivity.BG_SECONDS, SettingsMonitoringActivity.BG_MINUTES, choice, vs,
new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
view.getSettings().SERVICE_OFF_INTERVAL.set(vs.value);
view.getContext().startService(serviceIntent);
}
});
} else {
view.getContext().stopService(serviceIntent);
}
return true;
}
}).position(0).reg();
}
}
}

View file

@ -0,0 +1,6 @@
package net.osmand.plus.monitoring;
public class ValueHolder<T> {
public T value;
}

View file

@ -95,7 +95,7 @@ public class DashOsmEditsFragment extends DashBaseFragment implements OsmEditsUp
send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OpenstreetmapRemoteUtil remotepoi = new OpenstreetmapRemoteUtil(getActivity(), getActivity().getWindow().getDecorView());
OpenstreetmapRemoteUtil remotepoi = new OpenstreetmapRemoteUtil(getActivity());
OsmPoint[] toUpload = new OsmPoint[]{point};
OsmBugsRemoteUtil remotebug = new OsmBugsRemoteUtil(getMyApplication());
ProgressDialog dialog = ProgressImplementation.createProgressDialog(

View file

@ -30,6 +30,7 @@ import net.osmand.util.OpeningHoursParser;
import net.osmand.util.OpeningHoursParser.BasicOpeningHourRule;
import net.osmand.util.OpeningHoursParser.OpeningHours;
import net.osmand.util.OpeningHoursParser.OpeningHoursRule;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
@ -61,7 +62,7 @@ import android.widget.Toast;
public class EditingPOIActivity implements DialogProvider {
private final MapActivity ctx;
private final Activity activity;
private final OpenstreetmapUtil openstreetmapUtil;
private final OpenstreetmapUtil openstreetmapUtilToLoad;
private AutoCompleteTextView typeText;
@ -97,20 +98,20 @@ public class EditingPOIActivity implements DialogProvider {
public EditingPOIActivity(MapActivity uiContext){
this.ctx = uiContext;
this.activity = uiContext;
poiTypes = uiContext.getMyApplication().getPoiTypes();
allTranslatedSubTypes = poiTypes.getAllTranslatedNames(false);
settings = ((OsmandApplication) uiContext.getApplication()).getSettings();
if (settings.OFFLINE_EDITION.get() || !settings.isInternetConnectionAvailable(true)) {
this.openstreetmapUtil = new OpenstreetmapLocalUtil(ctx);
this.openstreetmapUtil = new OpenstreetmapLocalUtil(activity);
if (settings.isInternetConnectionAvailable(true)) {
this.openstreetmapUtilToLoad = new OpenstreetmapRemoteUtil(ctx, ctx.getMapView().getView());
this.openstreetmapUtilToLoad = new OpenstreetmapRemoteUtil(activity);
} else {
this.openstreetmapUtilToLoad = openstreetmapUtil;
}
} else {
this.openstreetmapUtil = new OpenstreetmapRemoteUtil(ctx, ctx.getMapView().getView());
this.openstreetmapUtil = new OpenstreetmapRemoteUtil(activity);
this.openstreetmapUtilToLoad= openstreetmapUtil;
}
}
@ -127,7 +128,7 @@ public class EditingPOIActivity implements DialogProvider {
if(n != null){
showPOIDialog(DIALOG_EDIT_POI, n, editA.getType(), editA.getSubType());
} else {
AccessibleToast.makeText(ctx, ctx.getString(R.string.poi_error_poi_not_found), Toast.LENGTH_SHORT).show();
AccessibleToast.makeText(activity, activity.getString(R.string.poi_error_poi_not_found), Toast.LENGTH_SHORT).show();
}
};
@ -144,7 +145,7 @@ public class EditingPOIActivity implements DialogProvider {
Amenity a = EntityParser.parseAmenity(n, type, subType, null, MapRenderingTypes.getDefault());
dialogBundle.putSerializable(KEY_AMENITY, a);
dialogBundle.putSerializable(KEY_AMENITY_NODE, n);
ctx.showDialog(dialogID);
activity.showDialog(dialogID);
}
public void showDeleteDialog(final Amenity a){
@ -155,32 +156,32 @@ public class EditingPOIActivity implements DialogProvider {
protected void onPostExecute(Node n) {
if(n == null){
AccessibleToast.makeText(ctx, ctx.getResources().getString(R.string.poi_error_poi_not_found), Toast.LENGTH_LONG).show();
AccessibleToast.makeText(activity, activity.getResources().getString(R.string.poi_error_poi_not_found), Toast.LENGTH_LONG).show();
return;
}
dialogBundle.putSerializable(KEY_AMENITY, a);
dialogBundle.putSerializable(KEY_AMENITY_NODE, n);
ctx.showDialog(DIALOG_DELETE_POI); //TODO from android 2.0 use showDialog(id,bundle)
activity.showDialog(DIALOG_DELETE_POI); //TODO from android 2.0 use showDialog(id,bundle)
};
}.execute(new Void[0]);
}
private void prepareDeleteDialog(Dialog dlg, Bundle args) {
Amenity a = (Amenity) args.getSerializable(KEY_AMENITY);
dlg.setTitle(MessageFormat.format(this.ctx.getMapView().getResources().getString(R.string.poi_remove_confirm_template),
dlg.setTitle(MessageFormat.format(this.activity.getResources().getString(R.string.poi_remove_confirm_template),
OsmAndFormatter.getPoiStringWithoutType(a, settings.usingEnglishNames())));
}
private Dialog createDeleteDialog(final Bundle args) {
Builder builder = new AlertDialog.Builder(ctx);
Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(R.string.poi_remove_title);
LinearLayout ll = new LinearLayout(ctx);
LinearLayout ll = new LinearLayout(activity);
ll.setPadding(4, 2, 4, 0);
ll.setOrientation(LinearLayout.VERTICAL);
final EditText comment = new EditText(ctx);
final EditText comment = new EditText(activity);
comment.setText(R.string.poi_remove_title);
ll.addView(comment);
final CheckBox closeChangeset = new CheckBox(ctx);
final CheckBox closeChangeset = new CheckBox(activity);
closeChangeset.setText(R.string.close_changeset);
ll.addView(closeChangeset);
builder.setView(ll);
@ -193,9 +194,9 @@ public class EditingPOIActivity implements DialogProvider {
commitNode(OsmPoint.Action.DELETE, n, openstreetmapUtil.getEntityInfo(), c, closeChangeset.isSelected(), new Runnable(){
@Override
public void run() {
AccessibleToast.makeText(ctx, ctx.getResources().getString(R.string.poi_remove_success), Toast.LENGTH_LONG).show();
if(ctx.getMapView() != null){
ctx.getMapView().refreshMap(true);
AccessibleToast.makeText(activity, activity.getResources().getString(R.string.poi_remove_success), Toast.LENGTH_LONG).show();
if(activity instanceof MapActivity){
((MapActivity) activity).getMapView().refreshMap(true);
}
}
});
@ -227,15 +228,15 @@ public class EditingPOIActivity implements DialogProvider {
}
private void addTagValueRow(final Node n, final TableLayout layout, String tg, String vl) {
final TableRow newTagRow = new TableRow(ctx);
final TableRow newTagRow = new TableRow(activity);
TableRow.LayoutParams tlp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
tlp.leftMargin = 5;
tlp.gravity = Gravity.CENTER;
newTagRow.setLayoutParams(tlp);
final AutoCompleteTextView tag = new AutoCompleteTextView(ctx);
final AutoCompleteTextView value = new AutoCompleteTextView(ctx);
final Button delete = new Button(ctx);
final AutoCompleteTextView tag = new AutoCompleteTextView(activity);
final AutoCompleteTextView value = new AutoCompleteTextView(activity);
final Button delete = new Button(activity);
tag.setLayoutParams(tlp);
if(tg != null) {
@ -251,13 +252,13 @@ public class EditingPOIActivity implements DialogProvider {
tagKeys.add(t.getValue());
}
}
ArrayAdapter<Object> adapter = new ArrayAdapter<Object>(ctx, R.layout.list_textview, tagKeys.toArray());
ArrayAdapter<Object> adapter = new ArrayAdapter<Object>(activity, R.layout.list_textview, tagKeys.toArray());
tag.setAdapter(adapter);
tag.setThreshold(1);
tag.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Builder builder = new AlertDialog.Builder(ctx);
Builder builder = new AlertDialog.Builder(activity);
final String[] tags = tagKeys.toArray(new String[tagKeys.size()]);
builder.setItems(tags, new Dialog.OnClickListener() {
@Override
@ -286,7 +287,7 @@ public class EditingPOIActivity implements DialogProvider {
// subCategories.add(s);
// }
// } ;
ArrayAdapter<Object> valueAdapter = new ArrayAdapter<Object>(ctx, R.layout.list_textview, subCategories.toArray());
ArrayAdapter<Object> valueAdapter = new ArrayAdapter<Object>(activity, R.layout.list_textview, subCategories.toArray());
value.setThreshold(1);
value.setAdapter(valueAdapter);
value.addTextChangedListener(new TextWatcher() {
@ -327,7 +328,7 @@ public class EditingPOIActivity implements DialogProvider {
}
private Dialog createPOIDialog(final int dialogID, Bundle args) {
final Dialog dlg = new Dialog(ctx);
final Dialog dlg = new Dialog(activity);
dlg.setContentView(R.layout.editing_poi);
dlg.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);;
@ -351,7 +352,7 @@ public class EditingPOIActivity implements DialogProvider {
@Override
public void onClick(View v) {
ctx.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://wiki.openstreetmap.org/wiki/Map_Features")));
activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://wiki.openstreetmap.org/wiki/Map_Features")));
}
});
linkToOsmDoc.setMovementMethod(LinkMovementMethod.getInstance());
@ -381,7 +382,7 @@ public class EditingPOIActivity implements DialogProvider {
openHoursButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
ctx.showDialog(DIALOG_OPENING_HOURS);
activity.showDialog(DIALOG_OPENING_HOURS);
}
});
typeText.addTextChangedListener(new TextWatcher(){
@ -411,7 +412,7 @@ public class EditingPOIActivity implements DialogProvider {
typeButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
ctx.showDialog(DIALOG_POI_TYPES);
activity.showDialog(DIALOG_POI_TYPES);
}
});
@ -454,7 +455,7 @@ public class EditingPOIActivity implements DialogProvider {
@Override
public void onClick(View v) {
//we must do remove, because there are two dialogs EDIT,CREATE using same variables!!
ctx.removeDialog(dialogID);
activity.removeDialog(dialogID);
}
});
((Button)dlg.findViewById(R.id.Commit)).setOnClickListener(new View.OnClickListener(){
@ -511,12 +512,12 @@ public class EditingPOIActivity implements DialogProvider {
new Runnable() {
@Override
public void run() {
AccessibleToast.makeText(ctx, MessageFormat.format(ctx.getResources().getString(R.string.poi_action_succeded_template), msg),
AccessibleToast.makeText(activity, MessageFormat.format(activity.getResources().getString(R.string.poi_action_succeded_template), msg),
Toast.LENGTH_LONG).show();
if (ctx.getMapView() != null) {
ctx.getMapView().refreshMap(true);
if (activity instanceof MapActivity) {
((MapActivity) activity).getMapView().refreshMap(true);
}
ctx.removeDialog(dialogID);
activity.removeDialog(dialogID);
}
});
}
@ -525,13 +526,13 @@ public class EditingPOIActivity implements DialogProvider {
private void showSubCategory(Amenity a) {
if(typeText.getText().length() == 0 && a.getType() != null){
ctx.showDialog(DIALOG_SUB_CATEGORIES);
activity.showDialog(DIALOG_SUB_CATEGORIES);
}
}
private void updateSubTypesAdapter(PoiCategory poiCategory) {
final Map<String, PoiType> subCategories = getSubCategoriesMap(poiCategory);
final ArrayAdapter<Object> adapter = new ArrayAdapter<Object>(ctx, R.layout.list_textview, subCategories.keySet().toArray());
final ArrayAdapter<Object> adapter = new ArrayAdapter<Object>(activity, R.layout.list_textview, subCategories.keySet().toArray());
typeText.setAdapter(adapter);
typeText.setOnItemSelectedListener(new OnItemSelectedListener() {
@ -557,6 +558,9 @@ public class EditingPOIActivity implements DialogProvider {
subCategories.put(s.getKey(), s.getValue());
}
}
ArrayAdapter<Object> adapter = new ArrayAdapter<Object>(activity, R.layout.list_textview,
subCategories.keySet().toArray());
typeText.setAdapter(adapter);
return subCategories;
}
@ -570,7 +574,7 @@ public class EditingPOIActivity implements DialogProvider {
private Dialog createOpenHoursDlg(){
OpeningHours time = OpeningHoursParser.parseOpenedHours(openingHours.getText().toString());
if(time == null){
AccessibleToast.makeText(ctx, ctx.getString(R.string.opening_hours_not_supported), Toast.LENGTH_LONG).show();
AccessibleToast.makeText(activity, activity.getString(R.string.opening_hours_not_supported), Toast.LENGTH_LONG).show();
return null;
}
@ -587,21 +591,21 @@ public class EditingPOIActivity implements DialogProvider {
}
}
Builder builder = new AlertDialog.Builder(ctx);
final OpeningHoursView v = new OpeningHoursView(ctx);
Builder builder = new AlertDialog.Builder(activity);
final OpeningHoursView v = new OpeningHoursView(activity);
builder.setView(v.createOpeningHoursEditView(simple));
builder.setPositiveButton(ctx.getString(R.string.shared_string_apply), new DialogInterface.OnClickListener(){
builder.setPositiveButton(activity.getString(R.string.shared_string_apply), new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
OpeningHours oh = new OpeningHours((ArrayList<OpeningHoursRule>) v.getTime());
openingHours.setText(oh.toString());
ctx.removeDialog(DIALOG_OPENING_HOURS);
activity.removeDialog(DIALOG_OPENING_HOURS);
}
});
builder.setNegativeButton(ctx.getString(R.string.shared_string_cancel), new DialogInterface.OnClickListener() {
builder.setNegativeButton(activity.getString(R.string.shared_string_cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ctx.removeDialog(DIALOG_OPENING_HOURS);
activity.removeDialog(DIALOG_OPENING_HOURS);
}
});
return builder.create();
@ -612,14 +616,14 @@ public class EditingPOIActivity implements DialogProvider {
final boolean closeChangeSet,
final Runnable successAction) {
if (info == null && OsmPoint.Action.CREATE != action) {
AccessibleToast.makeText(ctx, ctx.getResources().getString(R.string.poi_error_info_not_loaded), Toast.LENGTH_LONG).show();
AccessibleToast.makeText(activity, activity.getResources().getString(R.string.poi_error_info_not_loaded), Toast.LENGTH_LONG).show();
return;
}
new AsyncTask<Void, Void, Node>() {
ProgressDialog progress;
@Override
protected void onPreExecute() {
progress = ProgressDialog.show(ctx, ctx.getString(R.string.uploading), ctx.getString(R.string.uploading_data));
progress = ProgressDialog.show(activity, activity.getString(R.string.uploading), activity.getString(R.string.uploading_data));
super.onPreExecute();
}
@Override
@ -648,7 +652,7 @@ public class EditingPOIActivity implements DialogProvider {
case DIALOG_DELETE_POI:
return createDeleteDialog(args);
case DIALOG_SUB_CATEGORIES: {
Builder builder = new AlertDialog.Builder(ctx);
Builder builder = new AlertDialog.Builder(activity);
final Amenity a = (Amenity) args.getSerializable(KEY_AMENITY);
final Map<String, PoiType> allTranslatedNames = poiTypes.getAllTranslatedNames(a.getType(), true);
final String[] subCats = allTranslatedNames.keySet().toArray(new String[0]);
@ -657,21 +661,21 @@ public class EditingPOIActivity implements DialogProvider {
public void onClick(DialogInterface dialog, int which) {
PoiType poiType = allTranslatedNames.get(subCats[which]);
typeText.setText(poiType.getKeyName());
a.setSubType(poiType.getKeyName());
ctx.removeDialog(DIALOG_SUB_CATEGORIES);
a.setSubType(subCats[which]);
activity.removeDialog(DIALOG_SUB_CATEGORIES);
}
});
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
ctx.removeDialog(DIALOG_SUB_CATEGORIES);
activity.removeDialog(DIALOG_SUB_CATEGORIES);
}
});
return builder.create();
}
case DIALOG_POI_TYPES: {
final Amenity a = (Amenity) args.getSerializable(KEY_AMENITY);
Builder builder = new AlertDialog.Builder(ctx);
Builder builder = new AlertDialog.Builder(activity);
final List<PoiCategory> categories = poiTypes.getCategories();
String[] vals = new String[categories.size()];
for (int i = 0; i < vals.length; i++) {
@ -686,13 +690,13 @@ public class EditingPOIActivity implements DialogProvider {
a.setSubType(""); //$NON-NLS-1$
updateType(a);
}
ctx.removeDialog(DIALOG_POI_TYPES);
activity.removeDialog(DIALOG_POI_TYPES);
}
});
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
ctx.removeDialog(DIALOG_POI_TYPES);
activity.removeDialog(DIALOG_POI_TYPES);
}
});
return builder.create();

View file

@ -81,7 +81,7 @@ public class LocalOpenstreetmapActivity extends OsmandListActivity {
dbpoi = new OpenstreetmapsDbHelper(this);
dbbug = new OsmBugsDbHelper(this);
remotepoi = new OpenstreetmapRemoteUtil(this, this.getWindow().getDecorView());
remotepoi = new OpenstreetmapRemoteUtil(this);
remotebug = new OsmBugsRemoteUtil(getMyApplication());
}

View file

@ -46,11 +46,10 @@ import android.widget.Toast;
public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
private static final long NO_CHANGESET_ID = -1;
private final OsmandApplication ctx;
private final View view;
private EntityInfo entityInfo;
// reuse changeset
private long changeSetId = NO_CHANGESET_ID;
private long changeSetTimeStamp = NO_CHANGESET_ID;
@ -59,9 +58,8 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
private OsmandSettings settings;
public OpenstreetmapRemoteUtil(Context uiContext, View view){
public OpenstreetmapRemoteUtil(Context uiContext) {
this.ctx = ((OsmandApplication) uiContext.getApplicationContext());
this.view = view;
settings = ctx.getSettings();
}
@ -69,42 +67,41 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
public EntityInfo getEntityInfo() {
return entityInfo;
}
private static String getSiteApi()
{
private static String getSiteApi() {
final int deviceApiVersion = android.os.Build.VERSION.SDK_INT;
String RETURN_API;
if (deviceApiVersion >= android.os.Build.VERSION_CODES.GINGERBREAD) {
RETURN_API = "https://api.openstreetmap.org/";
}
else {
} else {
RETURN_API = "http://api.openstreetmap.org/";
}
// RETURN_API = "http://api06.dev.openstreetmap.org/";
// RETURN_API = "http://api06.dev.openstreetmap.org/";
return RETURN_API;
}
private final static String URL_TO_UPLOAD_GPX = getSiteApi() + "api/0.6/gpx/create";
public String uploadGPXFile(String tagstring, String description, String visibility, File f) {
String url = URL_TO_UPLOAD_GPX;
String url = URL_TO_UPLOAD_GPX;
Map<String, String> additionalData = new LinkedHashMap<String, String>();
additionalData.put("description", description);
additionalData.put("tags", tagstring);
additionalData.put("visibility", visibility);
return NetworkUtils.uploadFile(url, f, settings.USER_NAME.get()+":"+
settings.USER_PASSWORD.get(), "file", true, additionalData);
return NetworkUtils.uploadFile(url, f, settings.USER_NAME.get() + ":" + settings.USER_PASSWORD.get(), "file",
true, additionalData);
}
private String sendRequest(String url, String requestMethod, String requestBody, String userOperation, boolean doAuthenticate) {
private String sendRequest(String url, String requestMethod, String requestBody, String userOperation,
boolean doAuthenticate) {
log.info("Sending request " + url); //$NON-NLS-1$
try {
HttpURLConnection connection = NetworkUtils.getHttpURLConnection(url);
connection.setConnectTimeout(15000);
connection.setRequestMethod(requestMethod);
connection.setRequestProperty("User-Agent", Version.getFullVersion(ctx)); //$NON-NLS-1$
@ -127,7 +124,8 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
}
connection.connect();
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
String msg = userOperation + " " + ctx.getString(R.string.failed_op) + " : " + connection.getResponseMessage(); //$NON-NLS-1$//$NON-NLS-2$
String msg = userOperation
+ " " + ctx.getString(R.string.failed_op) + " : " + connection.getResponseMessage(); //$NON-NLS-1$//$NON-NLS-2$
log.error(msg);
showWarning(msg);
} else {
@ -140,7 +138,7 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
String s;
boolean f = true;
while ((s = in.readLine()) != null) {
if(!f){
if (!f) {
responseBody.append("\n"); //$NON-NLS-1$
} else {
f = false;
@ -153,20 +151,21 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
} catch (NullPointerException e) {
// that's tricky case why NPE is thrown to fix that problem httpClient could be used
String msg = ctx.getString(R.string.auth_failed);
log.error(msg , e);
log.error(msg, e);
showWarning(msg);
} catch (MalformedURLException e) {
log.error(userOperation + " " + ctx.getString(R.string.failed_op) , e); //$NON-NLS-1$
showWarning(MessageFormat.format(ctx.getResources().getString(R.string.shared_string_action_template) + ": " + ctx.getResources().getString(R.string.shared_string_unexpected_error), userOperation));
log.error(userOperation + " " + ctx.getString(R.string.failed_op), e); //$NON-NLS-1$
showWarning(MessageFormat.format(ctx.getResources().getString(R.string.shared_string_action_template)
+ ": " + ctx.getResources().getString(R.string.shared_string_unexpected_error), userOperation));
} catch (IOException e) {
log.error(userOperation + " " + ctx.getString(R.string.failed_op) , e); //$NON-NLS-1$
showWarning(MessageFormat.format(ctx.getResources().getString(R.string.shared_string_action_template) + ": " + ctx.getResources().getString(R.string.shared_string_io_error), userOperation));
log.error(userOperation + " " + ctx.getString(R.string.failed_op), e); //$NON-NLS-1$
showWarning(MessageFormat.format(ctx.getResources().getString(R.string.shared_string_action_template)
+ ": " + ctx.getResources().getString(R.string.shared_string_io_error), userOperation));
}
return null;
}
public long openChangeSet(String comment) {
long id = -1;
StringWriter writer = new StringWriter(256);
@ -193,19 +192,21 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
} catch (IOException e) {
log.error("Unhandled exception", e); //$NON-NLS-1$
}
String response = sendRequest(getSiteApi() + "api/0.6/changeset/create/", "PUT", writer.getBuffer().toString(), ctx.getString(R.string.opening_changeset), true); //$NON-NLS-1$ //$NON-NLS-2$
String response = sendRequest(
getSiteApi() + "api/0.6/changeset/create/", "PUT", writer.getBuffer().toString(), ctx.getString(R.string.opening_changeset), true); //$NON-NLS-1$ //$NON-NLS-2$
if (response != null && response.length() > 0) {
id = Long.parseLong(response);
}
return id;
}
private void writeNode(Node n, EntityInfo i, XmlSerializer ser, long changeSetId, String user) throws IllegalArgumentException, IllegalStateException, IOException{
private void writeNode(Node n, EntityInfo i, XmlSerializer ser, long changeSetId, String user)
throws IllegalArgumentException, IllegalStateException, IOException {
ser.startTag(null, "node"); //$NON-NLS-1$
ser.attribute(null, "id", n.getId()+""); //$NON-NLS-1$ //$NON-NLS-2$
ser.attribute(null, "lat", n.getLatitude()+""); //$NON-NLS-1$ //$NON-NLS-2$
ser.attribute(null, "lon", n.getLongitude()+""); //$NON-NLS-1$ //$NON-NLS-2$
ser.attribute(null, "id", n.getId() + ""); //$NON-NLS-1$ //$NON-NLS-2$
ser.attribute(null, "lat", n.getLatitude() + ""); //$NON-NLS-1$ //$NON-NLS-2$
ser.attribute(null, "lon", n.getLongitude() + ""); //$NON-NLS-1$ //$NON-NLS-2$
if (i != null) {
// ser.attribute(null, "timestamp", i.getETimestamp());
// ser.attribute(null, "uid", i.getUid());
@ -213,11 +214,12 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
ser.attribute(null, "visible", i.getVisible()); //$NON-NLS-1$
ser.attribute(null, "version", i.getVersion()); //$NON-NLS-1$
}
ser.attribute(null, "changeset", changeSetId+""); //$NON-NLS-1$ //$NON-NLS-2$
for(String k : n.getTagKeySet()){
ser.attribute(null, "changeset", changeSetId + ""); //$NON-NLS-1$ //$NON-NLS-2$
for (String k : n.getTagKeySet()) {
String val = n.getTag(k);
if (val.length() == 0) continue;
if (val.length() == 0)
continue;
ser.startTag(null, "tag"); //$NON-NLS-1$
ser.attribute(null, "k", k); //$NON-NLS-1$
ser.attribute(null, "v", val); //$NON-NLS-1$
@ -228,7 +230,7 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
private boolean isNewChangesetRequired() {
// first commit
if (changeSetId == NO_CHANGESET_ID){
if (changeSetId == NO_CHANGESET_ID) {
return true;
}
@ -242,12 +244,13 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
}
@Override
public Node commitNodeImpl(OsmPoint.Action action, final Node n, EntityInfo info, String comment, boolean closeChangeSet){
if (isNewChangesetRequired()){
public Node commitNodeImpl(OsmPoint.Action action, final Node n, EntityInfo info, String comment,
boolean closeChangeSet) {
if (isNewChangesetRequired()) {
changeSetId = openChangeSet(comment);
changeSetTimeStamp = System.currentTimeMillis();
}
if(changeSetId < 0){
if (changeSetId < 0) {
return null;
}
@ -259,7 +262,7 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
ser.setOutput(writer);
ser.startDocument("UTF-8", true); //$NON-NLS-1$
ser.startTag(null, "osmChange"); //$NON-NLS-1$
ser.attribute(null, "version", "0.6"); //$NON-NLS-1$ //$NON-NLS-2$
ser.attribute(null, "version", "0.6"); //$NON-NLS-1$ //$NON-NLS-2$
ser.attribute(null, "generator", Version.getAppName(ctx)); //$NON-NLS-1$
ser.startTag(null, OsmPoint.stringAction.get(action));
ser.attribute(null, "version", "0.6"); //$NON-NLS-1$ //$NON-NLS-2$
@ -271,9 +274,9 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
} catch (IOException e) {
log.error("Unhandled exception", e); //$NON-NLS-1$
}
String res = sendRequest(getSiteApi() + "api/0.6/changeset/"+changeSetId + "/upload", "POST", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String res = sendRequest(getSiteApi() + "api/0.6/changeset/" + changeSetId + "/upload", "POST", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
writer.getBuffer().toString(), ctx.getString(R.string.commiting_node), true);
log.debug(res+""); //$NON-NLS-1$
log.debug(res + ""); //$NON-NLS-1$
if (res != null) {
if (OsmPoint.Action.CREATE == action) {
long newId = n.getId();
@ -292,88 +295,94 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil {
}
return null;
} finally {
if(closeChangeSet) {
if (closeChangeSet) {
closeChangeSet();
}
}
}
@Override
public void closeChangeSet() {
if (changeSetId != NO_CHANGESET_ID) {
String response = sendRequest(getSiteApi() + "api/0.6/changeset/"+changeSetId+"/close", "PUT", "", ctx.getString(R.string.closing_changeset), true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
String response = sendRequest(
getSiteApi() + "api/0.6/changeset/" + changeSetId + "/close", "PUT", "", ctx.getString(R.string.closing_changeset), true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
log.info("Response : " + response); //$NON-NLS-1$
changeSetId = NO_CHANGESET_ID;
}
}
public EntityInfo loadNode(Node n) {
long nodeId = n.getId(); // >> 1;
try {
String res = sendRequest(getSiteApi() + "api/0.6/node/"+nodeId, "GET", null, ctx.getString(R.string.loading_poi_obj) + nodeId, false); //$NON-NLS-1$ //$NON-NLS-2$
if(res != null){
String res = sendRequest(
getSiteApi() + "api/0.6/node/" + nodeId, "GET", null, ctx.getString(R.string.loading_poi_obj) + nodeId, false); //$NON-NLS-1$ //$NON-NLS-2$
if (res != null) {
OsmBaseStorage st = new OsmBaseStorage();
st.parseOSM(new ByteArrayInputStream(res.getBytes("UTF-8")), null, null, true); //$NON-NLS-1$
EntityId id = new Entity.EntityId(EntityType.NODE, nodeId);
Node entity = (Node) st.getRegisteredEntities().get(id);
// merge non existing tags
for(String rtag : entity.getTagKeySet()) {
if(!n.getTagKeySet().contains(rtag)) {
for (String rtag : entity.getTagKeySet()) {
if (!n.getTagKeySet().contains(rtag)) {
n.putTag(rtag, entity.getTag(rtag));
}
}
entityInfo = st.getRegisteredEntityInfo().get(id);
return entityInfo;
}
} catch (IOException e) {
log.error("Loading node failed " + nodeId, e); //$NON-NLS-1$
AccessibleToast.makeText(ctx, ctx.getResources().getString(R.string.shared_string_io_error), Toast.LENGTH_LONG).show();
AccessibleToast.makeText(ctx, ctx.getResources().getString(R.string.shared_string_io_error),
Toast.LENGTH_LONG).show();
} catch (SAXException e) {
log.error("Loading node failed " + nodeId, e); //$NON-NLS-1$
AccessibleToast.makeText(ctx, ctx.getResources().getString(R.string.shared_string_io_error), Toast.LENGTH_LONG).show();
AccessibleToast.makeText(ctx, ctx.getResources().getString(R.string.shared_string_io_error),
Toast.LENGTH_LONG).show();
}
return null;
}
@Override
public Node loadNode(Amenity n) {
if(n.getId() % 2 == 1){
if (n.getId() % 2 == 1) {
// that's way id
return null;
}
long nodeId = n.getId() >> 1;
try {
String res = sendRequest(getSiteApi() + "api/0.6/node/"+nodeId, "GET", null, ctx.getString(R.string.loading_poi_obj) + nodeId, false); //$NON-NLS-1$ //$NON-NLS-2$
if(res != null){
String res = sendRequest(
getSiteApi() + "api/0.6/node/" + nodeId, "GET", null, ctx.getString(R.string.loading_poi_obj) + nodeId, false); //$NON-NLS-1$ //$NON-NLS-2$
if (res != null) {
OsmBaseStorage st = new OsmBaseStorage();
st.parseOSM(new ByteArrayInputStream(res.getBytes("UTF-8")), null, null, true); //$NON-NLS-1$
EntityId id = new Entity.EntityId(EntityType.NODE, nodeId);
Node entity = (Node) st.getRegisteredEntities().get(id);
entityInfo = st.getRegisteredEntityInfo().get(id);
// check whether this is node (because id of node could be the same as relation)
if(entity != null && MapUtils.getDistance(entity.getLatLon(), n.getLocation()) < 50){
// check whether this is node (because id of node could be the same as relation)
if (entity != null && MapUtils.getDistance(entity.getLatLon(), n.getLocation()) < 50) {
return entity;
}
return null;
}
} catch (Exception e) {
log.error("Loading node failed " + nodeId, e); //$NON-NLS-1$
ctx.runInUIThread(new Runnable() {
@Override
public void run() {
AccessibleToast.makeText(ctx, ctx.getResources().getString(R.string.shared_string_io_error), Toast.LENGTH_LONG).show();
AccessibleToast.makeText(ctx, ctx.getResources().getString(R.string.shared_string_io_error),
Toast.LENGTH_LONG).show();
}
});
}
return null;
}
private void showWarning(final String msg){
view.post(new Runnable(){
private void showWarning(final String msg) {
ctx.runInUIThread(new Runnable() {
@Override
public void run() {
AccessibleToast.makeText(ctx, msg, Toast.LENGTH_LONG).show();

View file

@ -72,7 +72,7 @@ public class OsmEditsFragment extends ListFragment implements OsmEditsUploadList
dbpoi = new OpenstreetmapsDbHelper(getActivity());
dbbug = new OsmBugsDbHelper(getActivity());
remotepoi = new OpenstreetmapRemoteUtil(getActivity(), getActivity().getWindow().getDecorView());
remotepoi = new OpenstreetmapRemoteUtil(getActivity());
remotebug = new OsmBugsRemoteUtil(getMyApplication());
return view;

View file

@ -34,7 +34,7 @@ public class UploadGPXFilesTask extends AsyncTask<GpxInfo, String, String> {
if (!isCancelled() && info.file != null) {
String warning = null;
File file = info.file;
warning = new OpenstreetmapRemoteUtil(la, null).uploadGPXFile(tagstring, description, visibility,
warning = new OpenstreetmapRemoteUtil(la).uploadGPXFile(tagstring, description, visibility,
file);
total++;
if (warning == null) {

View file

@ -28,11 +28,7 @@ import net.osmand.plus.download.DownloadFileHelper;
import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoDevice;
import net.osmand.plus.osmo.OsMoService.SessionInfo;
import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.MonitoringInfoControl;
import net.osmand.plus.views.MonitoringInfoControl.MonitoringInfoControlServices;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.mapwidgets.BaseMapWidget;
import net.osmand.plus.views.mapwidgets.TextInfoWidget;
import net.osmand.util.Algorithms;
@ -42,20 +38,19 @@ import org.json.JSONObject;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.view.View;
import android.widget.ArrayAdapter;
public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlServices, OsMoReactor {
public class OsMoPlugin extends OsmandPlugin implements OsMoReactor {
private OsmandApplication app;
public static final String ID = "osmand.osmo";
private OsMoService service;
private OsMoTracker tracker;
private OsMoGroups groups;
private BaseMapWidget osmoControl;
private TextInfoWidget osmoControl;
private OsMoPositionLayer olayer;
protected MapActivity mapActivity;
protected OsMoGroupsActivity groupsActivity;
@ -125,17 +120,6 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
return R.drawable.ic_osmo_dark;
}
@Override
public void updateLayers(OsmandMapTileView mapView, MapActivity activity) {
// registerLayers(activity);
super.updateLayers(mapView, activity);
MonitoringInfoControl lock = activity.getMapLayers().getMapInfoLayer().getMonitoringInfoControl();
if (lock != null && !lock.getMonitorActions().contains(this)) {
lock.addMonitorActions(this);
}
}
@Override
public void registerMapContextMenuActions(final MapActivity mapActivity, final double latitude, final double longitude,
@ -189,8 +173,8 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
public void registerLayers(MapActivity activity) {
super.registerLayers(activity);
MapInfoLayer layer = activity.getMapLayers().getMapInfoLayer();
osmoControl = createOsMoControl(activity, layer.getPaintText(), layer.getPaintSubText());
layer.getMapInfoControls().registerSideWidget(osmoControl,
osmoControl = createOsMoControl(activity);
layer.registerSideWidget(osmoControl,
R.drawable.mon_osmo_signal_inactive, R.drawable.mon_osmo_signal_inactive, R.string.osmo_control, "osmo_control", false, 18);
layer.recreateControls();
@ -218,7 +202,7 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
/**
* creates (if it wasn't created previously) the control to be added on a MapInfoLayer that shows a monitoring state (recorded/stopped)
*/
private BaseMapWidget createOsMoControl(final MapActivity map, Paint paintText, Paint paintSubText) {
private TextInfoWidget createOsMoControl(final MapActivity map) {
final Drawable srcSmall = map.getResources().getDrawable(R.drawable.mon_osmo_conn_small);
final Drawable srcSignalSmall = map.getResources().getDrawable(R.drawable.mon_osmo_conn_signal_small);
@ -226,12 +210,11 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
final Drawable srcSignalBig = map.getResources().getDrawable(R.drawable.mon_osmo_conn_signal_big);
// final Drawable srcinactive = map.getResources().getDrawable(R.drawable.mon_osmo_inactive);
final Drawable srcSignalinactive = map.getResources().getDrawable(R.drawable.mon_osmo_signal_inactive);
final TextInfoWidget osmoControl = new TextInfoWidget(map, 0, paintText, paintSubText) {
final TextInfoWidget osmoControl = new TextInfoWidget(map) {
long lastUpdateTime;
private Drawable blinkImg;
@Override
public boolean updateInfo(DrawSettings drawSettings) {
boolean visible = true;
String txt = "OsMo";
String subtxt = "";
SessionInfo si = getService().getCurrentSessionInfo();
@ -274,21 +257,17 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
blink(big, small);
}
updateVisibility(visible);
return true;
}
private void blink(Drawable bigger, final Drawable smaller ) {
blinkImg = smaller;
setImageDrawable(bigger);
invalidate();
postDelayed(new Runnable() {
map.getMyApplication().runInUIThread(new Runnable() {
@Override
public void run() {
blinkImg = null;
setImageDrawable(smaller);
requestLayout();
invalidate();
}
}, 500);
}
@ -305,21 +284,6 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
return osmoControl;
}
@Override
public void addMonitorActions(ContextMenuAdapter qa, MonitoringInfoControl li, final OsmandMapTileView view) {
qa.item("Test (send)").icons(R.drawable.ic_action_grefresh_dark, R.drawable.ic_action_grefresh_light)
.listen(new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
final double lat = view.getLatitude();
final double lon = view.getLongitude();
tracker.sendCoordinate(lat, lon);
return true;
}
}).reg();
}
@Override
public Class<? extends Activity> getSettingsActivity() {
return SettingsOsMoActivity.class;

View file

@ -18,7 +18,6 @@ import net.osmand.plus.views.AnimateDraggingMapThread;
import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.mapwidgets.BaseMapWidget;
import net.osmand.plus.views.mapwidgets.TextInfoWidget;
import android.app.Activity;
import android.app.AlertDialog;
@ -26,7 +25,6 @@ import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Paint;
import android.text.format.DateFormat;
import android.text.format.Time;
import android.view.View;
@ -56,7 +54,7 @@ public class ParkingPositionPlugin extends OsmandPlugin {
private OsmandApplication app;
private ParkingPositionLayer parkingLayer;
private BaseMapWidget parkingPlaceControl;
private TextInfoWidget parkingPlaceControl;
private final CommonPreference<Float> parkingLat;
private final CommonPreference<Float> parkingLon;
private CommonPreference<Boolean> parkingType;
@ -191,8 +189,8 @@ public class ParkingPositionPlugin extends OsmandPlugin {
private void registerWidget(MapActivity activity) {
MapInfoLayer mapInfoLayer = activity.getMapLayers().getMapInfoLayer();
if (mapInfoLayer != null) {
parkingPlaceControl = createParkingPlaceInfoControl(activity, mapInfoLayer.getPaintText(), mapInfoLayer.getPaintSubText());
mapInfoLayer.getMapInfoControls().registerSideWidget(parkingPlaceControl,
parkingPlaceControl = createParkingPlaceInfoControl(activity);
mapInfoLayer.registerSideWidget(parkingPlaceControl,
R.drawable.widget_parking, R.drawable.widget_parking, R.string.map_widget_parking, "parking", false, 8);
mapInfoLayer.recreateControls();
}
@ -443,8 +441,8 @@ public class ParkingPositionPlugin extends OsmandPlugin {
* the current position on the map
* and the location of the parked car
*/
private TextInfoWidget createParkingPlaceInfoControl(final MapActivity map, Paint paintText, Paint paintSubText) {
TextInfoWidget parkingPlaceControl = new TextInfoWidget(map, 0, paintText, paintSubText) {
private TextInfoWidget createParkingPlaceInfoControl(final MapActivity map) {
TextInfoWidget parkingPlaceControl = new TextInfoWidget(map) {
private float[] calculations = new float[1];
private int cachedMeters = 0;

View file

@ -467,6 +467,7 @@ public class ResourceManager {
unpackBundledAssets(assetManager, applicationDataDir, progress, isFirstInstall);
context.getSettings().PREVIOUS_INSTALLED_VERSION.set(Version.getFullVersion(context));
context.getPoiFilters().updateFilters(false);
copyRegionsBoundaries();
} catch (SQLiteException e) {
log.error(e.getMessage(), e);
} catch (IOException e) {
@ -478,6 +479,18 @@ public class ResourceManager {
}
return Collections.emptyList();
}
private void copyRegionsBoundaries() {
try {
File file = context.getAppPath("regions.ocbf");
if (file != null) {
Algorithms.streamCopy(OsmandRegions.class.getResourceAsStream("regions.ocbf"), new FileOutputStream(
file));
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
private final static String ASSET_INSTALL_MODE__alwaysCopyOnFirstInstall = "alwaysCopyOnFirstInstall";
private final static String ASSET_COPY_MODE__overwriteOnlyIfExists = "overwriteOnlyIfExists";

View file

@ -199,8 +199,8 @@ public class RoutePointsPlugin extends OsmandPlugin {
private void registerWidget(MapActivity activity) {
MapInfoLayer mapInfoLayer = activity.getMapLayers().getMapInfoLayer();
if (mapInfoLayer != null) {
routeStepsControl = createRouteStepsInfoControl(activity, mapInfoLayer.getPaintText(), mapInfoLayer.getPaintSubText());
mapInfoLayer.getMapInfoControls().registerSideWidget(routeStepsControl,
routeStepsControl = createRouteStepsInfoControl(activity);
mapInfoLayer.registerSideWidget(routeStepsControl,
R.drawable.widget_signpost, R.drawable.widget_signpost, R.string.map_widget_route_points, "route_steps", false, 8);
mapInfoLayer.recreateControls();
}
@ -245,8 +245,8 @@ public class RoutePointsPlugin extends OsmandPlugin {
}
}
private TextInfoWidget createRouteStepsInfoControl(final MapActivity map, Paint paintText, Paint paintSubText) {
TextInfoWidget routeStepsControl = new TextInfoWidget(map, 0, paintText, paintSubText) {
private TextInfoWidget createRouteStepsInfoControl(final MapActivity map) {
TextInfoWidget routeStepsControl = new TextInfoWidget(map) {
@Override()
public boolean updateInfo(OsmandMapLayer.DrawSettings drawSettings) {

View file

@ -20,9 +20,9 @@ import net.osmand.plus.TargetPointsHelper.TargetPoint;
import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo;
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
import net.osmand.plus.routing.RouteProvider.RouteService;
import net.osmand.plus.voice.CommandPlayer;
import net.osmand.router.RouteCalculationProgress;
import net.osmand.router.RouteSegmentResult;
import net.osmand.router.TurnType;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
@ -660,7 +660,7 @@ public class RoutingHelper {
return false;
}
public synchronized String getCurrentName(){
public synchronized String getCurrentName(TurnType[] next){
NextDirectionInfo n = getNextRouteDirectionInfo(new NextDirectionInfo(), false);
Location l = lastFixedLocation;
float speed = 0;
@ -672,14 +672,17 @@ public class RoutingHelper {
String nm = n.directionInfo.getStreetName();
String rf = n.directionInfo.getRef();
String dn = n.directionInfo.getDestinationName();
return "\u2566 " + formatStreetName(nm, rf, dn);
if(next != null) {
next[0] = n.directionInfo.getTurnType();
}
return formatStreetName(nm, rf, dn);
}
RouteSegmentResult rs = getCurrentSegmentResult();
if(rs != null) {
String nm = rs.getObject().getName();
String rf = rs.getObject().getRef();
String dn = rs.getObject().getDestinationName();
return "\u21E7 " + formatStreetName(nm, rf, dn);
return formatStreetName(nm, rf, dn);
}
return null;
}
@ -822,7 +825,7 @@ public class RoutingHelper {
params.type = settings.ROUTER_SERVICE.getModeValue(mode);
params.mode = mode;
params.ctx = app;
if (previousRoute == null && params.type == RouteService.OSMAND) {
if (params.type == RouteService.OSMAND) {
params.calculationProgress = new RouteCalculationProgress();
updateProgress(params.calculationProgress);
}

View file

@ -739,9 +739,5 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
a.startActivityForResult(newIntent, 0);
}
@Override
public boolean showNavigationControls() {
return false;
}
}

View file

@ -32,7 +32,6 @@ public class SherpafyStageItineraryFragment extends SherpafyStageInfoFragment im
protected void updateView(WebView description, ImageView icon, TextView additional, TextView text, TextView header) {
app.getResourceManager().getMapTileDownloader().addDownloaderCallback(this);
osmandMapTileView.getView().setVisibility(View.VISIBLE);
osmandMapTileView.removeAllLayers();
MapVectorLayer mapVectorLayer = new MapVectorLayer(null, true);
MapTextLayer mapTextLayer = new MapTextLayer();

View file

@ -1,78 +1,90 @@
package net.osmand.plus.views;
import gnu.trove.list.array.TIntArrayList;
import java.util.ArrayList;
import java.util.List;
import android.content.pm.ActivityInfo;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Surface;
import net.osmand.PlatformUtil;
import net.londatiga.android.ActionItem;
import net.londatiga.android.QuickAction;
import net.osmand.core.android.MapRendererContext;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.ScreenOrientationHelper;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.helpers.WaypointDialogHelper;
import net.osmand.plus.views.controls.MapRoutePlanControl;
import net.osmand.plus.views.controls.MapRoutePreferencesControl;
import net.osmand.plus.views.controls.MapCancelControl;
import net.osmand.plus.views.controls.MapControls;
import net.osmand.plus.views.controls.MapRouteInfoControl;
import net.osmand.plus.views.controls.MapMenuControls;
import net.osmand.plus.views.controls.MapNavigateControl;
import net.osmand.plus.views.controls.MapZoomControls;
import net.osmand.plus.views.controls.RulerControl;
import net.osmand.plus.views.controls.SmallMapMenuControls;
import net.osmand.plus.views.controls.MapRoutePreferencesControl;
import net.osmand.plus.views.corenative.NativeCoreContext;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.PointF;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView;
public class MapControlsLayer extends OsmandMapLayer {
private static final int TIMEOUT_TO_SHOW_BUTTONS = 5000;
public MapHudButton createHudButton(View iv, int resId) {
MapHudButton mc = new MapHudButton();
mc.iv = iv;
mc.resId = resId;
return mc;
}
private List<MapHudButton> controls = new ArrayList<MapControlsLayer.MapHudButton>();
private final MapActivity mapActivity;
private int shadowColor = -1;
private MapZoomControls zoomControls;
private MapZoomControls zoomSideControls;
private MapMenuControls mapMenuControls;
private RulerControl rulerControl;
private SmallMapMenuControls mapSmallMenuControls;
private MapCancelControl mapCancelNavigationControl;
private MapRouteInfoControl mapInfoNavigationControl;
private MapNavigateControl mapNavigationControl;
private MapRoutePlanControl mapRoutePlanControl;
private MapRoutePreferencesControl mapAppModeControl;
private List<MapControls> allControls = new ArrayList<MapControls>();
private float scaleCoefficient;
// private RulerControl rulerControl;
// private List<MapControls> allControls = new ArrayList<MapControls>();
private SeekBar transparencyBar;
private LinearLayout transparencyBarLayout;
private static CommonPreference<Integer> settingsToTransparency;
private OsmandSettings settings;
private MapRoutePreferencesControl optionsRouteControlDialog;
private MapRouteInfoControl mapRouteInfoControlDialog;
private View routePreparationLayout;
private MapHudButton backToLocationControl;
private MapHudButton menuControl;
private MapHudButton optionsRouteControl;
private MapHudButton routeGoControl;
private MapHudButton compassHud;
private float cachedRotate = 0;
private static long startCounter;
private Runnable delayStart;
private Handler showUIHandler;
private ImageView appModeIcon;
private TextView zoomText;
private OsmandMapTileView mapView;
private OsmandApplication app;
private View mapAppModeShadow;
public MapControlsLayer(MapActivity activity){
public MapControlsLayer(MapActivity activity) {
this.mapActivity = activity;
app = activity.getMyApplication();
settings = activity.getMyApplication().getSettings();
mapView = mapActivity.getMapView();
}
@Override
public boolean drawInScreenPixels() {
return true;
@ -80,204 +92,467 @@ public class MapControlsLayer extends OsmandMapLayer {
@Override
public void initLayer(final OsmandMapTileView view) {
scaleCoefficient = view.getScaleCoefficient();
FrameLayout parent = getParent();
Handler showUIHandler = new Handler();
int rightGravity = Gravity.RIGHT | Gravity.BOTTOM;
int leftGravity = Gravity.LEFT | Gravity.BOTTOM;
int rightCenterGravity = Gravity.RIGHT | Gravity.CENTER;
int leftCenterGravity = Gravity.LEFT | Gravity.CENTER;
// default buttons
zoomControls = init(new MapZoomControls(mapActivity, showUIHandler, scaleCoefficient), parent,
rightGravity);
if (ScreenOrientationHelper.getScreenOrientation(mapActivity) == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT){
zoomSideControls = init(new MapZoomControls(mapActivity, showUIHandler, scaleCoefficient), parent,
rightCenterGravity);
} else {
zoomSideControls = init(new MapZoomControls(mapActivity, showUIHandler, scaleCoefficient), parent,
leftCenterGravity);
}
mapMenuControls = init(new MapMenuControls(mapActivity, showUIHandler, scaleCoefficient), parent,
leftGravity);
mapRoutePlanControl = init(new MapRoutePlanControl(mapActivity, showUIHandler, scaleCoefficient), parent,
leftGravity);
// calculate route buttons
mapSmallMenuControls = init(new SmallMapMenuControls(mapActivity, showUIHandler, scaleCoefficient), parent,
leftGravity);
mapCancelNavigationControl = init(new MapCancelControl(mapActivity, showUIHandler, scaleCoefficient), parent,
leftGravity);
mapInfoNavigationControl = init(new MapRouteInfoControl(mapActivity.getMapLayers().getContextMenuLayer(),
mapActivity, showUIHandler, scaleCoefficient), parent,
leftGravity);
mapNavigationControl = init(new MapNavigateControl(mapInfoNavigationControl, mapActivity, showUIHandler, scaleCoefficient), parent,
rightGravity);
mapAppModeControl = init(new MapRoutePreferencesControl(mapActivity, showUIHandler, scaleCoefficient), parent,
rightGravity);
rulerControl = init(new RulerControl(zoomControls, mapActivity, showUIHandler, scaleCoefficient), parent,
rightGravity);
mapRoutePlanControl.setMargin(mapMenuControls.getWidth());
mapCancelNavigationControl.setMargin(mapSmallMenuControls.getWidth());
mapInfoNavigationControl.setMargin(mapSmallMenuControls.getWidth() + mapCancelNavigationControl.getWidth());
mapAppModeControl.setMargin(mapNavigationControl.getWidth());
showUIHandler = new Handler();
initTopControls();
initTransparencyBar();
initZooms();
initControls();
initRouteControls();
updateControls(view.getCurrentRotatedTileBox(), null);
}
initTransparencyBar(view, parent);
private class CompassDrawable extends Drawable {
private Drawable original;
public CompassDrawable(Drawable original) {
this.original = original;
}
@Override
public void draw(Canvas canvas) {
canvas.save();
canvas.rotate(cachedRotate, getIntrinsicWidth() / 2, getIntrinsicHeight() / 2);
original.draw(canvas);
canvas.restore();
}
@Override
public int getMinimumHeight() {
return original.getMinimumHeight();
}
@Override
public int getMinimumWidth() {
return original.getMinimumWidth();
}
@Override
public int getIntrinsicHeight() {
return original.getIntrinsicHeight();
}
@Override
public int getIntrinsicWidth() {
return original.getIntrinsicWidth();
}
@Override
public void setChangingConfigurations(int configs) {
super.setChangingConfigurations(configs);
original.setChangingConfigurations(configs);
}
@Override
public void setBounds(int left, int top, int right, int bottom) {
super.setBounds(left, top, right, bottom);
original.setBounds(left, top, right, bottom);
}
@Override
public void setAlpha(int alpha) {
original.setAlpha(alpha);
}
@Override
public void setColorFilter(ColorFilter cf) {
original.setColorFilter(cf);
}
@Override
public int getOpacity() {
return original.getOpacity();
}
}
private void initTopControls() {
View configureMap = mapActivity.findViewById(R.id.map_layers_button);
controls.add(createHudButton((ImageView) configureMap, R.drawable.ic_action_layers_dark).setBg(
R.drawable.btn_inset_circle, R.drawable.btn_inset_circle_night));
configureMap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
notifyClicked();
mapActivity.getMapActions().prepareConfigureMap();
mapActivity.getMapActions().toggleDrawer();
}
});
View compass = mapActivity.findViewById(R.id.map_compass_button);
compassHud = createHudButton((ImageView) compass, R.drawable.map_compass).setIconColorId(0).setBg(
R.drawable.btn_inset_circle, R.drawable.btn_inset_circle_night);
compassHud.compass = true;
controls.add(compassHud);
compass.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
notifyClicked();
mapActivity.getMapViewTrackingUtilities().switchRotateMapMode();
}
});
}
private void initRouteControls() {
routePreparationLayout = mapActivity.findViewById(R.id.map_route_preparation_layout);
View cancelRouteButton = mapActivity.findViewById(R.id.map_cancel_route_button);
controls.add(createHudButton((ImageView) cancelRouteButton, R.drawable.ic_action_remove_dark).setBg(
R.drawable.btn_flat, R.drawable.btn_flat_night));
cancelRouteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
notifyClicked();
if (mapActivity.getRoutingHelper().isFollowingMode()) {
mapActivity.getMapActions().stopNavigationActionConfirm(mapActivity.getMapView());
} else {
mapActivity.getMapActions().stopNavigationWithoutConfirm();
}
}
});
mapRouteInfoControlDialog = new MapRouteInfoControl(mapActivity.getMapLayers().getContextMenuLayer(),
mapActivity);
View waypointsButton = mapActivity.findViewById(R.id.map_waypoints_route_button);
controls.add(createHudButton((ImageView) waypointsButton, R.drawable.ic_action_flage_dark).setBg(
R.drawable.btn_flat, R.drawable.btn_flat_night));
waypointsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
notifyClicked();
mapRouteInfoControlDialog.showHideDialog();
}
});
View optionsRouteButton = mapActivity.findViewById(R.id.map_options_route_button);
optionsRouteControl = createHudButton((ImageView) optionsRouteButton,
settings.getApplicationMode().getSmallIcon(true)).setBg(R.drawable.btn_flat, R.drawable.btn_flat_night);
optionsRouteControlDialog = new MapRoutePreferencesControl(mapActivity);
controls.add(optionsRouteControl);
optionsRouteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
notifyClicked();
optionsRouteControlDialog.showAndHideDialog();
}
});
TextView routeGoButton = (TextView) mapActivity.findViewById(R.id.map_go_route_button);
routeGoControl = createHudButton(routeGoButton, R.drawable.ic_destination_arrow_white).setBg(
R.drawable.btn_flat, R.drawable.btn_flat_night);
controls.add(routeGoControl);
routeGoButton.setText(mapActivity.getString(R.string.shared_string_go).toUpperCase());
routeGoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
notifyClicked();
RoutingHelper routingHelper = mapActivity.getMyApplication().getRoutingHelper();
if (!routingHelper.isFollowingMode() && !routingHelper.isRoutePlanningMode()) {
mapActivity.getMapActions().enterRoutePlanningMode(null, null, false);
} else {
startNavigation();
}
}
});
}
public void showDialog() {
mapRouteInfoControlDialog.setShowDialog();
}
private void initControls() {
View backToLocation = mapActivity.findViewById(R.id.map_my_location_button);
backToLocationControl = createHudButton((ImageView) backToLocation, R.drawable.ic_action_get_my_location)
.setBg(R.drawable.btn_circle_blue);
controls.add(backToLocationControl);
backToLocation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mapActivity.getMapViewTrackingUtilities().backToLocationImpl();
}
});
View backToMenuButton = mapActivity.findViewById(R.id.map_menu_button);
menuControl = createHudButton((ImageView) backToMenuButton, R.drawable.ic_navigation_drawer).setBg(
R.drawable.btn_round, R.drawable.btn_round_night);
controls.add(menuControl);
backToMenuButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// double lat = activity.getMapView().getLatitude();
// double lon = activity.getMapView().getLongitude();
// MainMenuActivity.backToMainMenuDialog(activity, new LatLon(lat, lon));
notifyClicked();
if (mapActivity.getMyApplication().getSettings().USE_DASHBOARD_INSTEAD_OF_DRAWER.get()) {
mapActivity.getDashboard().setDashboardVisibility(true);
} else {
mapActivity.getMapActions().onDrawerBack();
mapActivity.getMapActions().toggleDrawer();
}
}
});
mapAppModeShadow = mapActivity.findViewById(R.id.map_app_mode_shadow);
mapAppModeShadow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onApplicationModePress(v);
}
});
appModeIcon = (ImageView) mapActivity.findViewById(R.id.map_app_mode_icon);
zoomText = (TextView) mapActivity.findViewById(R.id.map_app_mode_text);
View routePlanButton = mapActivity.findViewById(R.id.map_route_info_button);
controls.add(createHudButton((ImageView) routePlanButton, R.drawable.ic_action_gdirections_dark).setBg(
R.drawable.btn_round, R.drawable.btn_round_night));
routePlanButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
notifyClicked();
RoutingHelper routingHelper = mapActivity.getRoutingHelper();
if (!routingHelper.isFollowingMode() && !routingHelper.isRoutePlanningMode()) {
mapActivity.getMapActions().enterRoutePlanningMode(null, null, false);
} else {
mapActivity.getRoutingHelper().setRoutePlanningMode(true);
mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode();
mapActivity.refreshMap();
}
}
});
}
private void initZooms() {
final OsmandMapTileView view = mapActivity.getMapView();
View zoomInButton = mapActivity.findViewById(R.id.map_zoom_in_button);
controls.add(createHudButton((ImageView) zoomInButton, R.drawable.ic_action_zoom_in).setRoundTransparent());
zoomInButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
notifyClicked();
if (view.isZooming()) {
mapActivity.changeZoom(2, System.currentTimeMillis());
} else {
mapActivity.changeZoom(1, System.currentTimeMillis());
}
}
});
final View.OnLongClickListener listener = MapControlsLayer.getOnClickMagnifierListener(view);
zoomInButton.setOnLongClickListener(listener);
View zoomOutButton = mapActivity.findViewById(R.id.map_zoom_out_button);
controls.add(createHudButton((ImageView) zoomOutButton, R.drawable.ic_action_zoom_out).setRoundTransparent());
zoomOutButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
notifyClicked();
mapActivity.changeZoom(-1, System.currentTimeMillis());
}
});
zoomOutButton.setOnLongClickListener(listener);
}
public void startNavigation() {
if (mapNavigationControl == null) {
stopCounter();
OsmandApplication app = mapActivity.getMyApplication();
RoutingHelper routingHelper = app.getRoutingHelper();
if (routingHelper.isFollowingMode()) {
routingHelper.setRoutePlanningMode(false);
mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode();
} else {
if (!app.getTargetPointsHelper().checkPointToNavigateShort()) {
mapRouteInfoControlDialog.showDialog();
} else {
mapActivity.getMapViewTrackingUtilities().backToLocationImpl();
app.getSettings().FOLLOW_THE_ROUTE.set(true);
routingHelper.setFollowingMode(true);
routingHelper.setRoutePlanningMode(false);
mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode();
routingHelper.setCurrentLocation(app.getLocationProvider().getLastKnownLocation(), false);
app.getRoutingHelper().notifyIfRouteIsCalculated();
}
}
}
private void stopCounter() {
startCounter = 0;
}
public void startCounter() {
OsmandSettings settings = mapActivity.getMyApplication().getSettings();
int del = settings.DELAY_TO_START_NAVIGATION.get();
if (del <= 0) {
return;
}
mapNavigationControl.startNavigation();
}
private <T extends MapControls> T init(final T c, FrameLayout parent, int gravity) {
c.setGravity(gravity);
c.init(parent);
allControls.add(c);
c.setNotifyClick(new Runnable() {
@Override
public void run() {
notifyClicked(c);
}
});
return c;
}
protected void notifyClicked(MapControls m) {
if(mapNavigationControl != null) {
mapNavigationControl.stopCounter();
if (startCounter <= 0) {
startCounter = System.currentTimeMillis() + del * 1000;
delayStart = new Runnable() {
@Override
public void run() {
if (startCounter > 0) {
if (System.currentTimeMillis() > startCounter) {
startCounter = 0;
startNavigation();
} else {
mapActivity.refreshMap();
showUIHandler.postDelayed(delayStart, 1000);
}
}
}
};
delayStart.run();
}
}
protected void notifyClicked() {
stopCounter();
}
@Override
public void destroyLayer() {
controls.clear();
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) {
updateControls(tileBox, nightMode);
}
private void updateControls(RotatedTileBox tileBox, DrawSettings nightMode) {
boolean isNight = nightMode != null && nightMode.isNightMode();
int shadw = isNight ? Color.TRANSPARENT : Color.WHITE;
int textColor = isNight ? mapActivity.getResources().getColor(R.color.widgettext_night) : Color.BLACK ;
if(shadowColor != shadw) {
int textColor = isNight ? mapActivity.getResources().getColor(R.color.widgettext_night) : Color.BLACK;
if (shadowColor != shadw) {
shadowColor = shadw;
updatextColor(textColor, shadw, rulerControl, zoomControls, mapMenuControls);
// TODO
// updatextColor(textColor, shadw, rulerControl, zoomControls, mapMenuControls);
}
// default buttons
boolean routePlanningMode = false;
RoutingHelper rh = mapActivity.getRoutingHelper();
if(rh.isRoutePlanningMode() ) {
if (rh.isRoutePlanningMode()) {
routePlanningMode = true;
} else if((rh.isRouteCalculated() || rh.isRouteBeingCalculated()) &&
!rh.isFollowingMode()){
} else if ((rh.isRouteCalculated() || rh.isRouteBeingCalculated()) && !rh.isFollowingMode()) {
routePlanningMode = true;
}
boolean routeFollowingMode = !routePlanningMode && rh.isFollowingMode();
boolean showDefaultButtons = !routePlanningMode && (!routeFollowingMode || settings.SHOW_ZOOM_BUTTONS_NAVIGATION.get());
if(routePlanningMode) {
forceHideView(zoomControls);
forceHideView(mapMenuControls);
forceHideView(mapRoutePlanControl);
}
checkVisibilityAndDraw(showDefaultButtons, zoomControls, canvas, tileBox, nightMode);
checkVisibilityAndDraw(showDefaultButtons, mapMenuControls, canvas, tileBox, nightMode);
// show only on touch
checkVisibilityAndDraw(false, mapRoutePlanControl, canvas, tileBox, nightMode);
// route calculation buttons
boolean showRouteCalculationControls = routePlanningMode;
boolean showNavigationControls = mapActivity.getMyApplication().getAppCustomization().showNavigationControls();
checkVisibilityAndDraw(showRouteCalculationControls, mapSmallMenuControls, canvas, tileBox, nightMode);
checkVisibilityAndDraw(showNavigationControls && showRouteCalculationControls, mapCancelNavigationControl, canvas, tileBox, nightMode);
checkVisibilityAndDraw(showNavigationControls && showRouteCalculationControls, mapInfoNavigationControl, canvas, tileBox, nightMode);
checkVisibilityAndDraw(showNavigationControls && showRouteCalculationControls, mapAppModeControl, canvas, tileBox, nightMode);
checkVisibilityAndDraw(showRouteCalculationControls, mapNavigationControl, canvas, tileBox, nightMode);
checkVisibilityAndDraw(showRouteCalculationControls, zoomSideControls, canvas, tileBox, nightMode);
// the last one to check other controls visibility
int vmargin = mapNavigationControl.isVisible() || zoomControls.isVisible() ?
(zoomControls.getHeight() + zoomControls.getTotalVerticalMargin()) : 0;
rulerControl.setVerticalMargin(vmargin);
checkVisibilityAndDraw(true, rulerControl, canvas, tileBox, nightMode);
}
private void updatextColor(int textColor, int shadowColor, MapControls... mc) {
for(MapControls m : mc) {
m.updateTextColor(textColor, shadowColor);
}
}
private void checkVisibilityAndDraw(boolean visibility, MapControls controls, Canvas canvas,
RotatedTileBox tileBox, DrawSettings nightMode) {
if(visibility != controls.isVisible() ){
if(visibility) {
controls.show(getParent());
boolean showDefaultButtons = !routePlanningMode
&& (!routeFollowingMode || settings.SHOW_ZOOM_BUTTONS_NAVIGATION.get());
// /////////////////////////////////////////////
// new update
updateMyLocation();
menuControl.setIconResId(settings.USE_DASHBOARD_INSTEAD_OF_DRAWER.get() ? R.drawable.ic_dashboard_dark
: R.drawable.ic_navigation_drawer);
if(routeFollowingMode || routePlanningMode) {
mapAppModeShadow.setVisibility(View.GONE);
} else {
mapAppModeShadow.setVisibility(View.VISIBLE);
if (!mapView.isZooming() || !OsmandPlugin.isDevelopment()) {
zoomText.setVisibility(View.GONE);
appModeIcon.setVisibility(View.VISIBLE);
appModeIcon.setImageResource(settings.getApplicationMode().getSmallIcon(isNight));
} else {
controls.hide(getParent());
zoomText.setVisibility(View.VISIBLE);
appModeIcon.setVisibility(View.GONE);
zoomText.setText(getZoomLevel(tileBox));
}
}
if(controls.isVisible()) {
controls.onDraw(canvas, tileBox, nightMode);
}
optionsRouteControl.setIconResId(settings.getApplicationMode().getSmallIcon(true));
int vis = showRouteCalculationControls ? View.VISIBLE : View.GONE;
if (showRouteCalculationControls) {
((TextView) routeGoControl.iv).setTextColor(textColor);
final String text;
if (startCounter > 0) {
int get = (int) ((startCounter - System.currentTimeMillis()) / 1000l);
text = mapActivity.getString(R.string.shared_string_go) + " (" + get + ")";
} else {
text = mapActivity.getString(R.string.shared_string_go);
}
((TextView) routeGoControl.iv).setText(text);
}
if (routePreparationLayout.getVisibility() != vis) {
routePreparationLayout.setVisibility(vis);
mapRouteInfoControlDialog.setVisible(showRouteCalculationControls);
if (showRouteCalculationControls) {
if (!mapActivity.getRoutingHelper().isFollowingMode()
&& !mapActivity.getRoutingHelper().isPauseNavigation()) {
startCounter();
}
} else {
stopCounter();
}
}
float mapRotate = mapActivity.getMapView().getRotate();
if (mapRotate != cachedRotate) {
cachedRotate = mapRotate;
// Aply animation to image view
compassHud.iv.invalidate();
}
if (settings.ROTATE_MAP.get() == OsmandSettings.ROTATE_MAP_NONE) {
compassHud.setIconResId(isNight ? R.drawable.map_compass_niu_white : R.drawable.map_compass_niu);
} else if (settings.ROTATE_MAP.get() == OsmandSettings.ROTATE_MAP_BEARING) {
compassHud.setIconResId(isNight ? R.drawable.map_compass_bearing_white : R.drawable.map_compass_bearing);
} else {
compassHud.setIconResId(isNight ? R.drawable.map_compass_white : R.drawable.map_compass);
}
for (MapHudButton mc : controls) {
mc.update(mapActivity.getMyApplication(), nightMode == null ? false : nightMode.isNightMode());
}
}
private FrameLayout getParent() {
return (FrameLayout) mapActivity.findViewById(R.id.MapButtons);
}
private void forceHideView(MapControls controls) {
if (controls.isVisible()) {
controls.forceHide(getParent());
private void updateMyLocation() {
// final Drawable backToLoc = map.getResources().getDrawable(R.drawable.back_to_loc);
// final Drawable backToLocWhite = map.getResources().getDrawable(R.drawable.back_to_loc_white);
// final Drawable backToLocDisabled = map.getResources().getDrawable(R.drawable.la_backtoloc_disabled);
// final Drawable backToLocDisabledWhite = map.getResources().getDrawable(R.drawable.la_backtoloc_disabled_white);
// final Drawable backToLocTracked = map.getResources().getDrawable(R.drawable.back_to_loc_tracked);
// final Drawable backToLocTrackedWhite = map.getResources().getDrawable(R.drawable.back_to_loc_tracked_white);
boolean enabled = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation() != null;
boolean tracked = mapActivity.getMapViewTrackingUtilities().isMapLinkedToLocation();
if (!enabled) {
backToLocationControl.setIconColorId(R.color.icon_color_light);
} else if (tracked) {
backToLocationControl.setIconColorId(R.color.color_distance);
} else {
backToLocationControl.setIconColorId(R.color.color_white);
}
}
@Override
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
for(MapControls m : allControls) {
if(m.isVisible() && m.onSingleTap(point, tileBox)){
return true;
}
if (mapRouteInfoControlDialog.onSingleTap(point, tileBox)) {
return true;
}
stopCounter();
return false;
}
@Override
public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) {
if(!mapActivity.getRoutingHelper().isRoutePlanningMode() && mapActivity.getRoutingHelper().isFollowingMode()) {
if(!settings.SHOW_ZOOM_BUTTONS_NAVIGATION.get()) {
zoomControls.showWithDelay(getParent(), TIMEOUT_TO_SHOW_BUTTONS);
mapMenuControls.showWithDelay(getParent(), TIMEOUT_TO_SHOW_BUTTONS);
}
mapRoutePlanControl.showWithDelay(getParent(), TIMEOUT_TO_SHOW_BUTTONS);
}
for(MapControls m : allControls) {
if(m.isVisible() && m.onTouchEvent(event, tileBox)){
return true;
}
}
stopCounter();
return false;
}
///////////////// Transparency bar /////////////////////////
private void initTransparencyBar(final OsmandMapTileView view, FrameLayout parent) {
int minimumHeight = view.getResources().getDrawable(R.drawable.map_zoom_in).getMinimumHeight();
android.widget.FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
Gravity.BOTTOM | Gravity.CENTER);
params.setMargins(0, 0, 0, minimumHeight + 3);
transparencyBarLayout = new LinearLayout(view.getContext());
transparencyBarLayout.setVisibility(settingsToTransparency != null ? View.VISIBLE : View.GONE);
parent.addView(transparencyBarLayout, params);
transparencyBar = new SeekBar(view.getContext());
// /////////////// Transparency bar /////////////////////////
private void initTransparencyBar() {
transparencyBarLayout = (LinearLayout) mapActivity.findViewById(R.id.map_transparency_layout);
transparencyBar = (SeekBar) mapActivity.findViewById(R.id.map_transparency_seekbar);
transparencyBar.setMax(255);
if(settingsToTransparency != null) {
if (settingsToTransparency != null) {
transparencyBar.setProgress(settingsToTransparency.get());
transparencyBarLayout.setVisibility(View.VISIBLE);
} else {
transparencyBarLayout.setVisibility(View.GONE);
}
transparencyBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@ -297,12 +572,7 @@ public class MapControlsLayer extends OsmandMapLayer {
}
}
});
android.widget.LinearLayout.LayoutParams prms = new LinearLayout.LayoutParams((int) (scaleCoefficient * 100),
LayoutParams.WRAP_CONTENT);
transparencyBarLayout.addView(transparencyBar, prms);
ImageButton imageButton = new ImageButton(view.getContext());
prms = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
prms.setMargins((int) (2 * scaleCoefficient), (int) (2 * scaleCoefficient), 0, 0);
ImageButton imageButton = (ImageButton) mapActivity.findViewById(R.id.map_transparency_hide);
imageButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
@ -310,41 +580,189 @@ public class MapControlsLayer extends OsmandMapLayer {
hideTransparencyBar(settingsToTransparency);
}
});
imageButton.setContentDescription(view.getContext().getString(R.string.shared_string_close));
imageButton.setBackgroundResource(R.drawable.headliner_close);
transparencyBarLayout.addView(imageButton, prms);
}
public void showTransparencyBar(CommonPreference<Integer> transparenPreference) {
MapControlsLayer.settingsToTransparency = transparenPreference;
transparencyBarLayout.setVisibility(View.VISIBLE);
transparencyBar.setProgress(transparenPreference.get());
}
public void hideTransparencyBar(CommonPreference<Integer> transparentPreference) {
if(settingsToTransparency == transparentPreference) {
if (settingsToTransparency == transparentPreference) {
transparencyBarLayout.setVisibility(View.GONE);
settingsToTransparency = null;
}
}
public void shiftLayout(int height) {
FrameLayout parent = getParent();
parent.requestLayout();
for(MapControls mc : allControls) {
if(mc.isBottom()){
mc.setExtraVerticalMargin(height);
if( mc.isVisible()) {
mc.forceHide(parent);
mc.show(parent);
private class MapHudButton {
View iv;
int bgDark;
int bgLight;
int resId;
int resLight = R.color.icon_color_light;
int resDark = 0;
boolean nightMode = false;
boolean f = true;
boolean compass;
public MapHudButton setRoundTransparent() {
setBg(R.drawable.btn_circle_trans);
return this;
}
public MapHudButton setBg(int dayBg, int nightBg) {
bgDark = nightBg;
bgLight = dayBg;
f = true;
return this;
}
public MapHudButton setBg(int bg) {
bgDark = bg;
bgLight = bg;
f = true;
return this;
}
public boolean setIconResId(int resId) {
if (this.resId == resId) {
return false;
}
this.resId = resId;
f = true;
return true;
}
public MapHudButton setIconColorId(int clr) {
if (resLight == clr && resDark == clr) {
return this;
}
resLight = clr;
resDark = clr;
f = true;
return this;
}
public void update(OsmandApplication ctx, boolean night) {
if (nightMode == night && !f) {
return;
}
f = false;
nightMode = night;
if (bgDark != 0 && bgLight != 0) {
iv.setBackgroundDrawable(ctx.getResources().getDrawable(night ? bgDark : bgLight));
}
if (iv instanceof ImageView) {
if (compass) {
((ImageView) iv).setImageDrawable(new CompassDrawable(ctx.getIconsCache().getIcon(resId,
nightMode ? resDark : resLight)));
} else {
((ImageView) iv).setImageDrawable(ctx.getIconsCache()
.getIcon(resId, nightMode ? resDark : resLight));
}
} else if (iv instanceof TextView) {
((TextView) iv).setCompoundDrawablesWithIntrinsicBounds(
ctx.getIconsCache().getIcon(resId, nightMode ? resDark : resLight), null, null, null);
}
}
}
public void showDialog(){
mapInfoNavigationControl.setShowDialog();
private void onApplicationModePress(View v) {
final QuickAction mQuickAction = new QuickAction(v);
mQuickAction.setOnAnchorOnTop(true);
List<ApplicationMode> vls = ApplicationMode.values(mapActivity.getMyApplication().getSettings());
final ApplicationMode[] modes = vls.toArray(new ApplicationMode[vls.size()]);
int[] icons = new int[vls.size()];
int[] values = new int[vls.size()];
for (int k = 0; k < modes.length; k++) {
icons[k] = modes[k].getSmallIcon(false);
values[k] = modes[k].getStringResource();
}
for (int i = 0; i < modes.length; i++) {
final ActionItem action = new ActionItem();
action.setTitle(mapActivity.getResources().getString(values[i]));
action.setIcon(mapActivity.getResources().getDrawable(icons[i]));
final int j = i;
action.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mapActivity.getMyApplication().getSettings().APPLICATION_MODE.set(modes[j]);
mQuickAction.dismiss();
}
});
mQuickAction.addActionItem(action);
}
mQuickAction.setAnimStyle(QuickAction.ANIM_AUTO);
mQuickAction.show();
}
private String getZoomLevel(RotatedTileBox tb) {
String zoomText = tb.getZoom() + "";
double frac = tb.getMapDensity();
if (frac != 0) {
int ifrac = (int) (frac * 10);
zoomText += " ";
zoomText += Math.abs(ifrac) / 10;
if (ifrac % 10 != 0) {
zoomText += "." + Math.abs(ifrac) % 10;
}
}
return zoomText;
}
public static View.OnLongClickListener getOnClickMagnifierListener(final OsmandMapTileView view) {
final View.OnLongClickListener listener = new View.OnLongClickListener() {
@Override
public boolean onLongClick(View notUseCouldBeNull) {
final OsmandSettings.OsmandPreference<Float> mapDensity = view.getSettings().MAP_DENSITY;
final AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext());
int p = (int) (mapDensity.get() * 100);
final TIntArrayList tlist = new TIntArrayList(new int[] { 33, 50, 75, 100, 150, 200, 300, 400 });
final List<String> values = new ArrayList<String>();
int i = -1;
for (int k = 0; k <= tlist.size(); k++) {
final boolean end = k == tlist.size();
if (i == -1) {
if ((end || p < tlist.get(k))) {
values.add(p + "%");
i = k;
} else if (p == tlist.get(k)) {
i = k;
}
}
if (k < tlist.size()) {
values.add(tlist.get(k) + "%");
}
}
if (values.size() != tlist.size()) {
tlist.insert(i, p);
}
bld.setTitle(R.string.map_magnifier);
bld.setSingleChoiceItems(values.toArray(new String[values.size()]), i,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int p = tlist.get(which);
mapDensity.set(p / 100.0f);
view.setComplexZoom(view.getZoom(), view.getSettingsMapDensity());
MapRendererContext mapContext = NativeCoreContext.getMapRendererContext();
if (mapContext != null) {
mapContext.updateMapSettings();
}
dialog.dismiss();
}
});
bld.show();
return true;
}
};
return listener;
}
}

View file

@ -2,7 +2,6 @@ package net.osmand.plus.views;
import java.lang.reflect.Field;
import java.util.Set;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ApplicationMode;
@ -13,285 +12,296 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dialogs.ConfigureMapMenu;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.mapwidgets.AppearanceWidgetsFactory;
import net.osmand.plus.views.mapwidgets.BaseMapWidget;
import net.osmand.plus.views.mapwidgets.ImageViewWidget;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopTextView;
import net.osmand.plus.views.mapwidgets.MapWidgetRegistry;
import net.osmand.plus.views.mapwidgets.MapWidgetRegistry.MapWidgetRegInfo;
import net.osmand.plus.views.mapwidgets.NextTurnInfoWidget;
import net.osmand.plus.views.mapwidgets.RouteInfoWidgetsFactory;
import net.osmand.plus.views.mapwidgets.StackWidgetView;
import net.osmand.plus.views.mapwidgets.RouteInfoWidgetsFactory.AlarmWidget;
import net.osmand.plus.views.mapwidgets.RouteInfoWidgetsFactory.LanesControl;
import net.osmand.plus.views.mapwidgets.RouteInfoWidgetsFactory.RulerWidget;
import net.osmand.plus.views.mapwidgets.TextInfoWidget;
import net.osmand.plus.views.mapwidgets.UpdateableWidget;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.view.Gravity;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ImageButton;
import android.widget.LinearLayout;
public class MapInfoLayer extends OsmandMapLayer {
public static float scaleCoefficient = 1;
private final MapActivity map;
private final RouteLayer routeLayer;
private OsmandMapTileView view;
private Paint paintText;
private Paint paintSubText;
private Paint paintSmallText;
private Paint paintSmallSubText;
private Paint paintImg;
// layout pseudo-constants
private int STATUS_BAR_MARGIN_X = -4;
private TopTextView topText;
private View progressBar;
// groups
private StackWidgetView rightStack;
private StackWidgetView leftStack;
private LinearLayout statusBar;
private BaseMapWidget lanesControl;
private BaseMapWidget alarmControl;
private LinearLayout rightStack;
private LinearLayout leftStack;
private ImageButton expand;
private static boolean expanded = false;
private LanesControl lanesControl;
private AlarmWidget alarmControl;
private RulerWidget rulerControl;
private MapWidgetRegistry mapInfoControls;
private MonitoringInfoControl monitoringServices;
private OsmandSettings settings;
private DrawSettings drawSettings;
private TopTextView streetNameView;
public MapInfoLayer(MapActivity map, RouteLayer layer){
this.map = map;
settings = map.getMyApplication().getSettings();
this.routeLayer = layer;
}
public Paint getPaintSmallSubText() {
return paintSmallSubText;
}
public Paint getPaintText() {
return paintText;
}
public Paint getPaintSmallText() {
return paintSmallText;
}
public Paint getPaintSubText() {
return paintSubText;
}
public MonitoringInfoControl getMonitoringInfoControl() {
return monitoringServices;
}
public MapWidgetRegistry getMapInfoControls() {
return mapInfoControls;
}
public MapActivity getMapActivity() {
return map;
}
@Override
public void initLayer(final OsmandMapTileView view) {
this.view = view;
scaleCoefficient = view.getScaleCoefficient();
paintText = new Paint();
paintText.setStyle(Style.FILL_AND_STROKE);
paintText.setColor(Color.BLACK);
paintText.setTextSize(23 * scaleCoefficient);
paintText.setAntiAlias(true);
paintText.setStrokeWidth(4);
paintSubText = new Paint();
paintSubText.setStyle(Style.FILL_AND_STROKE);
paintSubText.setColor(Color.BLACK);
paintSubText.setTextSize(15 * scaleCoefficient);
paintSubText.setAntiAlias(true);
paintSmallText = new Paint();
paintSmallText.setStyle(Style.FILL_AND_STROKE);
paintSmallText.setColor(Color.BLACK);
paintSmallText.setTextSize(19 * scaleCoefficient);
paintSmallText.setAntiAlias(true);
paintSmallText.setStrokeWidth(4);
paintSmallSubText = new Paint();
paintSmallSubText.setStyle(Style.FILL_AND_STROKE);
paintSmallSubText.setColor(Color.BLACK);
paintSmallSubText.setTextSize(13 * scaleCoefficient);
paintSmallSubText.setAntiAlias(true);
paintImg = new Paint();
paintImg.setDither(true);
paintImg.setFilterBitmap(true);
paintImg.setAntiAlias(true);
mapInfoControls = new MapWidgetRegistry(map.getMyApplication().getSettings());
monitoringServices = new MonitoringInfoControl();
registerAllControls();
createControls();
}
public void registerAllControls(){
statusBar = new LinearLayout(view.getContext());
statusBar.setOrientation(LinearLayout.HORIZONTAL);
RouteInfoWidgetsFactory ric = new RouteInfoWidgetsFactory(scaleCoefficient);
MapInfoWidgetsFactory mic = new MapInfoWidgetsFactory(scaleCoefficient);
OsmandApplication app = view.getApplication();
lanesControl = ric.createLanesControl(map, view);
lanesControl.setBackgroundDrawable(view.getResources().getDrawable(R.drawable.box_free));
alarmControl = ric.createAlarmInfoControl(app, map);
// register right stack
RoutingHelper routingHelper = app.getRoutingHelper();
NextTurnInfoWidget bigInfoControl = ric.createNextInfoControl(routingHelper, app, view.getSettings(), paintText,
paintSubText, false);
mapInfoControls.registerSideWidget(bigInfoControl, R.drawable.widget_next_turn, R.drawable.widget_next_turn, R.string.map_widget_next_turn,"next_turn", true, 5);
NextTurnInfoWidget smallInfoControl = ric.createNextInfoControl(routingHelper, app, view.getSettings(),
paintSmallText, paintSmallSubText, true);
mapInfoControls.registerSideWidget(smallInfoControl, R.drawable.widget_next_turn, R.drawable.widget_next_turn, R.string.map_widget_next_turn_small, "next_turn_small", true,
10);
NextTurnInfoWidget nextNextInfoControl = ric.createNextNextInfoControl(routingHelper, app, view.getSettings(),
paintSmallText, paintSmallSubText, true);
mapInfoControls.registerSideWidget(nextNextInfoControl, R.drawable.widget_next_turn, R.drawable.widget_next_turn, R.string.map_widget_next_next_turn, "next_next_turn",true, 15);
//MiniMapControl miniMap = ric.createMiniMapControl(routingHelper, view);
//mapInfoControls.registerSideWidget(miniMap, R.drawable.widget_next_turn, R.string.map_widget_mini_route, "mini_route", true, none, none, 20);
// right stack
TextInfoWidget intermediateDist = ric.createIntermediateDistanceControl(map, paintText, paintSubText);
mapInfoControls.registerSideWidget(intermediateDist, R.drawable.widget_intermediate, R.drawable.widget_intermediate, R.string.map_widget_intermediate_distance, "intermediate_distance", false, 3);
TextInfoWidget dist = ric.createDistanceControl(map, paintText, paintSubText);
mapInfoControls.registerSideWidget(dist, R.drawable.widget_target, R.drawable.widget_target, R.string.map_widget_distance, "distance", false, 5);
TextInfoWidget time = ric.createTimeControl(map, paintText, paintSubText);
mapInfoControls.registerSideWidget(time, R.drawable.widget_time, R.drawable.widget_time, R.string.map_widget_time, "time", false, 10);
TextInfoWidget speed = ric.createSpeedControl(map, paintText, paintSubText);
mapInfoControls.registerSideWidget(speed, R.drawable.widget_speed, R.drawable.widget_speed, R.string.map_widget_speed, "speed", false, 15);
TextInfoWidget gpsInfo = mic.createGPSInfoControl(map, paintText, paintSubText);
mapInfoControls.registerSideWidget(gpsInfo, R.drawable.widget_gps_info, R.drawable.widget_gps_info, R.string.map_widget_gps_info, "gps_info", false, 17);
TextInfoWidget maxspeed = ric.createMaxSpeedControl(map, paintText, paintSubText);
mapInfoControls.registerSideWidget(maxspeed, R.drawable.widget_max_speed, R.drawable.widget_max_speed, R.string.map_widget_max_speed, "max_speed", false, 18);
TextInfoWidget alt = mic.createAltitudeControl(map, paintText, paintSubText);
mapInfoControls.registerSideWidget(alt, R.drawable.widget_altitude, R.drawable.widget_altitude, R.string.map_widget_altitude, "altitude", false, 20);
TextInfoWidget plainTime = ric.createPlainTimeControl(map, paintText, paintSubText);
mapInfoControls.registerSideWidget(plainTime, R.drawable.widget_time_to_distance, R.drawable.widget_time_to_distance, R.string.map_widget_plain_time, "plain_time", false, 25);
// Top widgets
ImageViewWidget compassView = mic.createCompassView(map);
mapInfoControls.registerTopWidget(compassView, R.drawable.widget_compass_dark, R.drawable.widget_compass_light, R.string.map_widget_compass, "compass", MapWidgetRegistry.LEFT_CONTROL, 5);
mapInfoControls.registerTopWidget(mic.createLockInfo(map), R.drawable.widget_lock_screen_dark, R.drawable.widget_lock_screen_light, R.string.bg_service_screen_lock, "bgService",
MapWidgetRegistry.LEFT_CONTROL, 15);
mapInfoControls.registerTopWidget(createBackToLocation(mic), R.drawable.widget_backtolocation_dark, R.drawable.widget_backtolocation_light, R.string.map_widget_back_to_loc, "back_to_location", MapWidgetRegistry.RIGHT_CONTROL, 5);
topText = mic.createStreetView(app, map, paintText);
mapInfoControls.registerTopWidget(topText, R.drawable.street_name_dark, R.drawable.street_name_light, R.string.map_widget_top_text,
"street_name", MapWidgetRegistry.MAIN_CONTROL, 100);
// Register appearance widgets
AppearanceWidgetsFactory.INSTANCE.registerAppearanceWidgets(map, this, mapInfoControls);
}
public void recreateControls(){
rightStack.clearAllViews();
mapInfoControls.populateStackControl(rightStack, view, false);
leftStack.clearAllViews();
mapInfoControls.populateStackControl(leftStack, view, true);
leftStack.requestLayout();
rightStack.requestLayout();
statusBar.removeAllViews();
mapInfoControls.populateStatusBar(statusBar);
updateColorShadowsOfText(null);
}
public void createControls() {
FrameLayout parent = (FrameLayout) ((FrameLayout) view.getParent()).findViewById(R.id.MapInfoControls);
// 1. Create view groups and controls
statusBar.setBackgroundDrawable(view.getResources().getDrawable(R.drawable.box_top));
// form measurement
ImageView iv = new ImageView(map);
iv.setImageDrawable(map.getResources().getDrawable(R.drawable.la_backtoloc_disabled));
statusBar.addView(iv);
rightStack = new StackWidgetView(view.getContext());
leftStack = new StackWidgetView(view.getContext());
// 2. Preparations
Rect topRectPadding = new Rect();
view.getResources().getDrawable(R.drawable.box_top).getPadding(topRectPadding);
// for measurement
STATUS_BAR_MARGIN_X = (int) (STATUS_BAR_MARGIN_X * scaleCoefficient);
statusBar.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
Rect statusBarPadding = new Rect();
statusBar.getBackground().getPadding(statusBarPadding);
// 3. put into frame parent layout controls
// status bar hides own top part
int topMargin = statusBar.getMeasuredHeight() - statusBarPadding.top - statusBarPadding.bottom ;
// we want that status bar lays over map stack controls
topMargin -= topRectPadding.top;
FrameLayout.LayoutParams flp = new FrameLayout.LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.RIGHT);
flp.rightMargin = STATUS_BAR_MARGIN_X;
flp.topMargin = topMargin;
rightStack.setLayoutParams(flp);
flp = new FrameLayout.LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL | Gravity.TOP);
flp.topMargin = (int) (topMargin + scaleCoefficient * 8);
lanesControl.setLayoutParams(flp);
flp = new FrameLayout.LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.LEFT);
flp.leftMargin = STATUS_BAR_MARGIN_X;
flp.topMargin = topMargin;
leftStack.setLayoutParams(flp);
flp = new FrameLayout.LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.TOP);
flp.leftMargin = STATUS_BAR_MARGIN_X;
flp.rightMargin = STATUS_BAR_MARGIN_X;
flp.topMargin = -topRectPadding.top;
statusBar.setLayoutParams(flp);
flp = new FrameLayout.LayoutParams((int)(78 * scaleCoefficient),
(int)(78 * scaleCoefficient), Gravity.LEFT | Gravity.BOTTOM);
flp.leftMargin = (int) (10*scaleCoefficient);
flp.bottomMargin = (int) (85*scaleCoefficient);
alarmControl.setLayoutParams(flp);
parent.addView(rightStack);
parent.addView(leftStack);
parent.addView(statusBar);
parent.addView(lanesControl);
parent.addView(alarmControl);
alarmControl.setVisibility(View.GONE);
lanesControl.setVisibility(View.GONE);
leftStack = (LinearLayout) map.findViewById(R.id.map_left_widgets_panel);
rightStack = (LinearLayout) map.findViewById(R.id.map_right_widgets_panel);
expand = (ImageButton) map.findViewById(R.id.map_collapse_button);
// update and create controls
registerAllControls();
recreateControls();
}
public void registerSideWidget(TextInfoWidget widget, int drawableDark,int drawableLight,
int messageId, String key, boolean left, int priorityOrder) {
MapWidgetRegInfo reg = mapInfoControls.registerSideWidgetInternal(widget, drawableDark, drawableLight, messageId, key, left, priorityOrder);
updateReg(calculateTextState(), reg);
}
public void registerAllControls(){
RouteInfoWidgetsFactory ric = new RouteInfoWidgetsFactory();
MapInfoWidgetsFactory mic = new MapInfoWidgetsFactory();
OsmandApplication app = view.getApplication();
lanesControl = ric.createLanesControl(map, view);
streetNameView = new MapInfoWidgetsFactory.TopTextView(map.getMyApplication(), map);
updateStreetName(calculateTextState());
alarmControl = ric.createAlarmInfoControl(app, map);
alarmControl.setVisibility(false);
rulerControl = ric.createRulerControl(app, map);
rulerControl.setVisibility(false);
// register left stack
NextTurnInfoWidget bigInfoControl = ric.createNextInfoControl(map, app, false);
registerSideWidget(bigInfoControl, R.drawable.widget_next_turn, R.drawable.widget_next_turn, R.string.map_widget_next_turn,"next_turn", true, 5);
NextTurnInfoWidget smallInfoControl = ric.createNextInfoControl(map, app, true);
registerSideWidget(smallInfoControl, R.drawable.widget_next_turn, R.drawable.widget_next_turn, R.string.map_widget_next_turn_small, "next_turn_small", true,
10);
NextTurnInfoWidget nextNextInfoControl = ric.createNextNextInfoControl(map, app, true);
registerSideWidget(nextNextInfoControl, R.drawable.widget_next_turn, R.drawable.widget_next_turn, R.string.map_widget_next_next_turn, "next_next_turn",true, 15);
// right stack
TextInfoWidget intermediateDist = ric.createIntermediateDistanceControl(map);
registerSideWidget(intermediateDist, R.drawable.widget_intermediate, R.drawable.widget_intermediate, R.string.map_widget_intermediate_distance, "intermediate_distance", false, 3);
TextInfoWidget dist = ric.createDistanceControl(map);
registerSideWidget(dist, R.drawable.widget_target, R.drawable.widget_target, R.string.map_widget_distance, "distance", false, 5);
TextInfoWidget time = ric.createTimeControl(map);
registerSideWidget(time, R.drawable.widget_time, R.drawable.widget_time, R.string.map_widget_time, "time", false, 10);
TextInfoWidget speed = ric.createSpeedControl(map);
registerSideWidget(speed, R.drawable.widget_speed, R.drawable.widget_speed, R.string.map_widget_speed, "speed", false, 15);
TextInfoWidget gpsInfo = mic.createGPSInfoControl(map);
registerSideWidget(gpsInfo, R.drawable.widget_gps_info, R.drawable.widget_gps_info, R.string.map_widget_gps_info, "gps_info", false, 17);
TextInfoWidget maxspeed = ric.createMaxSpeedControl(map);
registerSideWidget(maxspeed, R.drawable.widget_max_speed, R.drawable.widget_max_speed, R.string.map_widget_max_speed, "max_speed", false, 18);
TextInfoWidget alt = mic.createAltitudeControl(map);
registerSideWidget(alt, R.drawable.widget_altitude, R.drawable.widget_altitude, R.string.map_widget_altitude, "altitude", false, 20);
TextInfoWidget plainTime = ric.createPlainTimeControl(map);
registerSideWidget(plainTime, R.drawable.widget_time_to_distance, R.drawable.widget_time_to_distance, R.string.map_widget_plain_time, "plain_time", false, 25);
}
public void recreateControls() {
rightStack.removeAllViews();
mapInfoControls.populateStackControl(rightStack, settings.getApplicationMode(), false, expanded);
leftStack.removeAllViews();
mapInfoControls.populateStackControl(leftStack, settings.getApplicationMode(), true, expanded);
leftStack.requestLayout();
rightStack.requestLayout();
expand.setVisibility(mapInfoControls.hasCollapsibles(settings.getApplicationMode())?
View.VISIBLE : View.GONE);
this.expand.setImageResource(expanded ? R.drawable.av_upload :
R.drawable.av_download);
expand.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
expanded = !expanded;
recreateControls();
}
});
}
private static class TextState {
boolean textBold ;
int textColor ;
int textShadowColor ;
int boxTop;
int rightRes;
int leftRes;
int expand;
int boxFree;
int textShadowRadius;
}
private int themeId = -1;
public void updateColorShadowsOfText() {
boolean transparent = view.getSettings().TRANSPARENT_MAP_THEME.get();
boolean nightMode = drawSettings == null ? false : drawSettings.isNightMode();
boolean following = routeLayer.getHelper().isFollowingMode();
int calcThemeId = (transparent ? 4 : 0) | (nightMode ? 2 : 0) | (following ? 1 : 0);
if (themeId != calcThemeId) {
themeId = calcThemeId;
TextState ts = calculateTextState();
map.findViewById(R.id.map_center_info).setBackgroundResource(ts.boxFree);
for (MapWidgetRegInfo reg : mapInfoControls.getLeft()) {
updateReg(ts, reg);
}
for (MapWidgetRegInfo reg : mapInfoControls.getRight()) {
updateReg(ts, reg);
}
updateStreetName(ts);
lanesControl.updateTextSize(nightMode, ts.textColor, ts.textShadowColor, ts.textBold, ts.textShadowRadius);
rulerControl.updateTextSize(nightMode, ts.textColor, ts.textShadowColor, ts.textShadowRadius);
this.expand.setBackgroundResource(ts.expand);
rightStack.invalidate();
leftStack.invalidate();
}
}
private void updateStreetName(TextState ts) {
streetNameView.setBackgroundResource(ts.boxTop);
streetNameView.updateTextColor(ts.textColor, ts.textShadowColor, ts.textBold, ts.textShadowRadius);
}
private void updateReg(TextState ts, MapWidgetRegInfo reg) {
View v = reg.widget.getView().findViewById(R.id.widget_bg);
if(v != null) {
v.setBackgroundResource(reg.left ? ts.leftRes : ts.rightRes);
reg.widget.updateTextColor(ts.textColor, ts.textShadowColor, ts.textBold, ts.textShadowRadius);
}
}
private TextState calculateTextState() {
boolean transparent = view.getSettings().TRANSPARENT_MAP_THEME.get();
boolean nightMode = drawSettings == null ? false : drawSettings.isNightMode();
boolean following = routeLayer.getHelper().isFollowingMode();
TextState ts = new TextState();
ts.textBold = following;
ts.textColor = nightMode ? view.getResources().getColor(R.color.widgettext_night) : Color.BLACK;
// Night shadowColor always use widgettext_shadow_night, same as widget background color for non-transparent
// night skin (from box_night_free_simple.9.png)
ts.textShadowColor = nightMode ? view.getResources().getColor(R.color.widgettext_shadow_night) : Color.WHITE;
if (!transparent && !nightMode) {
ts.textShadowColor = Color.TRANSPARENT;
}
ts.textShadowRadius = ts.textShadowColor == 0 ? 0 : 8;
if (transparent) {
ts.boxTop = R.drawable.btn_flat_trans;
ts.rightRes = R.drawable.btn_left_round_trans;
ts.leftRes = R.drawable.btn_right_round_trans;
ts.expand = R.drawable.btn_inset_circle_trans;
ts.boxFree = R.drawable.btn_round_trans;
} else if (nightMode) {
ts.boxTop = R.drawable.btn_flat_night;
ts.rightRes = R.drawable.btn_left_round_night;
ts.leftRes = R.drawable.btn_right_round_night;
ts.expand = R.drawable.btn_inset_circle_night;
ts.boxFree = R.drawable.btn_round_night;
} else {
ts.boxTop = R.drawable.btn_flat;
ts.rightRes = R.drawable.btn_left_round;
ts.leftRes = R.drawable.btn_right_round;
ts.expand = R.drawable.btn_inset_circle;
ts.boxFree = R.drawable.btn_round;
}
return ts;
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings drawSettings) {
this.drawSettings = drawSettings;
// update data on draw
updateColorShadowsOfText();
mapInfoControls.updateInfo(settings.getApplicationMode(), drawSettings, expanded);
streetNameView.updateInfo(drawSettings);
alarmControl.updateInfo(drawSettings);
rulerControl.updateInfo(tileBox, drawSettings);
lanesControl.updateInfo(drawSettings);
}
@Override
public void destroyLayer() {
}
@Override
public boolean drawInScreenPixels() {
return true;
}
public View getProgressBar() {
// currently no progress on info layer
return null;
}
public static String getStringPropertyName(Context ctx, String propertyName, String defValue) {
try {
Field f = R.string.class.getField("rendering_attr_" + propertyName + "_name");
if (f != null) {
Integer in = (Integer) f.get(null);
return ctx.getString(in);
}
} catch (Exception e) {
System.err.println(e.getMessage());
}
return defValue;
}
public static String getStringPropertyDescription(Context ctx, String propertyName, String defValue) {
try {
Field f = R.string.class.getField("rendering_attr_" + propertyName + "_description");
if (f != null) {
Integer in = (Integer) f.get(null);
return ctx.getString(in);
}
} catch (Exception e) {
//e.printStackTrace();
System.err.println(e.getMessage());
}
return defValue;
}
public ContextMenuAdapter getViewConfigureMenuAdapter() {
final OsmandSettings settings = view.getSettings();
ContextMenuAdapter cm = new ContextMenuAdapter(view.getContext());
cm.setDefaultLayoutId(R.layout.drawer_list_item);
cm.item(R.string.layer_map_appearance).icons(R.drawable.ic_back_drawer_dark, R.drawable.ic_back_drawer_white)
@ -323,243 +333,10 @@ public class MapInfoLayer extends OsmandMapLayer {
}
}).reg();
final ApplicationMode mode = settings.getApplicationMode();
cm.item(R.string.map_widget_top).setCategory(true).layout(R.layout.drawer_list_sub_header).reg();
addControls(cm, mapInfoControls.getTop(), mode);
cm.item(R.string.map_widget_right).setCategory(true).layout(R.layout.drawer_list_sub_header).reg();
addControls(cm, mapInfoControls.getRight(), mode);
cm.item(R.string.map_widget_left).setCategory(true).layout(R.layout.drawer_list_sub_header).reg();
addControls(cm, mapInfoControls.getLeft(), mode);
cm.item(R.string.map_widget_appearance_rem).setCategory(true).layout(R.layout.drawer_list_sub_header).reg();
addControls(cm, mapInfoControls.getAppearanceWidgets(), mode);
// TODO add profiles
// View confirmDialog = View.inflate(view.getContext(), R.layout.configuration_dialog, null);
// AppModeDialog.prepareAppModeView(map, selected, true,
// (ViewGroup) confirmDialog.findViewById(R.id.TopBar), true,
// new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// if(selected.size() > 0) {
// view.getSettings().APPLICATION_MODE.set(selected.iterator().next());
// listAdapter.notifyDataSetChanged();
// }
// }
// });
mapInfoControls.addControls(this, cm, mode);
return cm;
}
private void addControls(final ContextMenuAdapter adapter, Set<MapWidgetRegInfo> top, final ApplicationMode mode) {
for(final MapWidgetRegInfo r : top){
adapter.item(r.messageId).selected(r.visibleCollapsed(mode) || r.visible(mode) ? 1 : 0)
.icons(r.drawableDark, r.drawableLight).listen(new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> a, int itemId, int pos, boolean isChecked) {
final boolean selecteable = r.selecteable();
boolean check = r.visibleCollapsed(mode) || r.visible(mode);
if (check || selecteable) {
mapInfoControls.changeVisibility(r);
}
recreateControls();
adapter.setItemName(pos, getText(mode, r));
adapter.setSelection(pos, r.visibleCollapsed(mode) || r.visible(mode) ? 1 : 0);
a.notifyDataSetInvalidated();
return false;
}
}).reg();
adapter.setItemName(adapter.length() - 1, getText(mode, r));
}
}
protected String getText(final ApplicationMode mode, final MapWidgetRegInfo r) {
return (r.visibleCollapsed(mode)? " + " : " ") + map.getString(r.messageId);
}
private int themeId = -1;
public void updateColorShadowsOfText(DrawSettings drawSettings) {
boolean transparent = view.getSettings().TRANSPARENT_MAP_THEME.get();
boolean nightMode = drawSettings == null ? false : drawSettings.isNightMode();
boolean following = routeLayer.getHelper().isFollowingMode();
int calcThemeId = (transparent ? 4 : 0) | (nightMode ? 2 : 0) | (following ? 1 : 0);
if (themeId != calcThemeId) {
themeId = calcThemeId;
boolean textBold = following;
int textColor = nightMode ? view.getResources().getColor(R.color.widgettext_night):Color.BLACK;
// Night shadowColor always use widgettext_shadow_night, same as widget background color for non-transparent night skin (from box_night_free_simple.9.png)
int textShadowColor = nightMode? view.getResources().getColor(R.color.widgettext_shadow_night) : Color.WHITE;
if (!transparent && !nightMode) {
textShadowColor = Color.TRANSPARENT;
}
int boxTop;
int boxTopStack;
int boxTopR;
int boxTopL;
int expand;
Drawable boxFree = view.getResources().getDrawable(R.drawable.box_free_simple);
if (transparent) {
boxTop = R.drawable.box_top_t;
boxTopStack = R.drawable.box_top_t_stack;
boxTopR = R.drawable.box_top_rt;
boxTopL = R.drawable.box_top_lt;
expand = R.drawable.box_expand_t;
if (nightMode) {
boxFree = view.getResources().getDrawable(R.drawable.box_night_free_simple);
}
} else if (nightMode) {
boxTop = R.drawable.box_top_n;
boxTopStack = R.drawable.box_top_n_stack;
boxTopR = R.drawable.box_top_rn;
boxTopL = R.drawable.box_top_ln;
expand = R.drawable.box_expand_t;
boxFree = view.getResources().getDrawable(R.drawable.box_night_free_simple);
} else {
boxTop = R.drawable.box_top;
boxTopStack = R.drawable.box_top_stack;
boxTopR = R.drawable.box_top_r;
boxTopL = R.drawable.box_top_l;
expand = R.drawable.box_expand;
}
lanesControl.setBackgroundDrawable(boxFree);
rightStack.setTopDrawable(view.getResources().getDrawable(boxTopR));
rightStack.setStackDrawable(boxTopStack);
leftStack.setTopDrawable(view.getResources().getDrawable(boxTopL));
leftStack.setStackDrawable(boxTopStack);
leftStack.setExpandImageDrawable(view.getResources().getDrawable(expand));
rightStack.setExpandImageDrawable(view.getResources().getDrawable(expand));
statusBar.setBackgroundDrawable(view.getResources().getDrawable(boxTop));
paintText.setColor(textColor);
paintSubText.setColor(textColor);
paintSmallText.setColor(textColor);
paintSmallSubText.setColor(textColor);
topText.setShadowColor(textShadowColor);
leftStack.setShadowColor(textShadowColor);
rightStack.setShadowColor(textShadowColor);
paintText.setFakeBoldText(textBold);
paintSubText.setFakeBoldText(textBold);
paintSmallText.setFakeBoldText(textBold);
paintSmallSubText.setFakeBoldText(textBold);
rightStack.invalidate();
leftStack.invalidate();
statusBar.invalidate();
}
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings drawSettings) {
updateColorShadowsOfText(drawSettings);
// update data on draw
rightStack.updateInfo(drawSettings);
leftStack.updateInfo(drawSettings);
lanesControl.updateInfo(drawSettings);
alarmControl.updateInfo(drawSettings);
for (int i = 0; i < statusBar.getChildCount(); i++) {
View v = statusBar.getChildAt(i);
if (v instanceof UpdateableWidget) {
((UpdateableWidget) v).updateInfo(drawSettings);
}
}
}
public StackWidgetView getRightStack() {
return rightStack;
}
public StackWidgetView getLeftStack() {
return leftStack;
}
@Override
public void destroyLayer() {
}
@Override
public boolean drawInScreenPixels() {
return true;
}
public View getProgressBar() {
return progressBar;
}
private static class UpdateFrameLayout extends FrameLayout implements UpdateableWidget {
private ImageViewWidget widget;
private UpdateFrameLayout(Context c, ImageViewWidget widget) {
super(c);
this.widget = widget;
}
@Override
public boolean updateInfo(DrawSettings drawSettings) {
return widget.updateInfo(drawSettings);
}
}
public static String getStringPropertyName(Context ctx, String propertyName, String defValue) {
try {
Field f = R.string.class.getField("rendering_attr_" + propertyName + "_name");
if (f != null) {
Integer in = (Integer) f.get(null);
return ctx.getString(in);
}
} catch (Exception e) {
System.err.println(e.getMessage());
}
return defValue;
}
public static String getStringPropertyDescription(Context ctx, String propertyName, String defValue) {
try {
Field f = R.string.class.getField("rendering_attr_" + propertyName + "_description");
if (f != null) {
Integer in = (Integer) f.get(null);
return ctx.getString(in);
}
} catch (Exception e) {
//e.printStackTrace();
System.err.println(e.getMessage());
}
return defValue;
}
private UpdateFrameLayout createBackToLocation(MapInfoWidgetsFactory mic){
progressBar = new View(view.getContext());
progressBar.setPadding((int) (5 * scaleCoefficient), 0, (int) (5 * scaleCoefficient), 0);
final ImageViewWidget widget = mic.createBackToLocation(map);
Drawable backToLoc = map.getResources().getDrawable(R.drawable.la_backtoloc_disabled);
UpdateFrameLayout layout = new UpdateFrameLayout(view.getContext(), widget) ;
FrameLayout.LayoutParams fparams;
fparams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
layout.addView(widget, fparams);
fparams = new FrameLayout.LayoutParams((int) (backToLoc.getMinimumWidth() ),
backToLoc.getMinimumHeight());
//this fix needed for android 2.3 because margin doesn't work without gravity
fparams.gravity = Gravity.TOP;
fparams.setMargins((int) (5 * scaleCoefficient), 0, 0, 0);
layout.addView(progressBar, fparams);
layout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
widget.performClick();
}
});
return layout;
}
}

View file

@ -1,101 +0,0 @@
package net.osmand.plus.views;
import java.util.ArrayList;
import java.util.List;
import net.londatiga.android.ActionItem;
import net.londatiga.android.QuickAction;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.mapwidgets.ImageViewWidget;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;
public class MonitoringInfoControl {
private List<MonitoringInfoControlServices> monitoringServices = new ArrayList<MonitoringInfoControl.MonitoringInfoControlServices>();
public interface MonitoringInfoControlServices {
public void addMonitorActions(ContextMenuAdapter ca, MonitoringInfoControl li, OsmandMapTileView view);
}
public void addMonitorActions(MonitoringInfoControlServices la){
monitoringServices.add(la);
}
public List<MonitoringInfoControlServices> getMonitorActions() {
return monitoringServices;
}
public ImageViewWidget createMonitoringWidget(final OsmandMapTileView view, final MapActivity map) {
final Drawable m = view.getResources().getDrawable(R.drawable.map_monitoring);
final Drawable mWhite = view.getResources().getDrawable(R.drawable.map_monitoring_white);
final ImageViewWidget monitoringServices = new ImageViewWidget(view.getContext()) {
private boolean nightMode;
@Override
public boolean updateInfo(DrawSettings drawSettings) {
boolean nightMode = drawSettings == null ? false : drawSettings.isNightMode();
if(nightMode != this.nightMode) {
this.nightMode = nightMode;
setImageDrawable(nightMode ? mWhite : m);
return true;
}
return false;
}
};
monitoringServices.setImageDrawable(m);
monitoringServices.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(MonitoringInfoControl.this.monitoringServices.isEmpty()) {
Toast.makeText(view.getContext(), R.string.enable_plugin_monitoring_services, Toast.LENGTH_LONG).show();
} else {
showBgServiceQAction(monitoringServices, view, map);
}
}
});
return monitoringServices;
}
private void showBgServiceQAction(final ImageView lockView, final OsmandMapTileView view, final MapActivity map) {
final ContextMenuAdapter ca = new ContextMenuAdapter(map);
for(MonitoringInfoControlServices la : monitoringServices){
la.addMonitorActions(ca, this, view);
}
final QuickAction qa = new QuickAction(lockView);
String[] itemNames = ca.getItemNames();
for(int i = 0; i < ca.length(); i++) {
final int ij = i;
ActionItem ai = new ActionItem();
ai.setTitle(itemNames[ij]);
if(ca.getImageId(ij, false) != 0) {
ai.setIcon(view.getResources().getDrawable(ca.getImageId(ij , false)));
}
ai.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ca.getClickAdapter(ij).onContextMenuClick(null, ca.getElementId(ij), ij, false);
qa.dismiss();
}
});
qa.addActionItem(ai);
}
qa.show();
}
public static class ValueHolder<T> {
public T value;
}
}

View file

@ -31,6 +31,7 @@ import net.osmand.util.MapUtils;
import org.apache.commons.logging.Log;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
@ -53,7 +54,6 @@ import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewParent;
import android.view.WindowManager;
import android.widget.Toast;
@ -67,6 +67,9 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
private FPSMeasurement main = new FPSMeasurement();
private FPSMeasurement additional = new FPSMeasurement();
private View view;
private Activity activity;
private OsmandApplication application;
protected OsmandSettings settings = null;
private class FPSMeasurement {
int fpsMeasureCount = 0;
@ -146,13 +149,8 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
Paint paintCenter;
private DisplayMetrics dm;
private MapRendererView mapRenderer;
private OsmandApplication application;
protected OsmandSettings settings = null;
private Bitmap bufferBitmap;
private RotatedTileBox bufferImgLoc;
private Bitmap bufferBitmapTmp;
@ -167,14 +165,17 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
getAnimatedDraggingThread().startZooming(getZoom() - 1, currentViewport.getZoomFloatPart(), true);
}
};
public OsmandMapTileView(Activity activity) {
this.activity = activity;
init(activity);
}
// ///////////////////////////// INITIALIZING UI PART ///////////////////////////////////
public void init(Context ctx) {
application = (OsmandApplication) ctx.getApplicationContext();
settings = application.getSettings();
paintGrayFill = new Paint();
paintGrayFill.setColor(Color.GRAY);
paintGrayFill.setStyle(Style.FILL);
@ -213,8 +214,10 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
WindowManager mgr = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
dm = new DisplayMetrics();
mgr.getDefaultDisplay().getMetrics(dm);
LatLon ll = settings.getLastKnownMapLocation();
currentViewport = new RotatedTileBox.RotatedTileBoxBuilder().
setLocation(0, 0).setZoom(3).setPixelDimensions(100, 100).build();
setLocation(ll.getLatitude(), ll.getLongitude()).setZoom(settings.getLastKnownMapZoom()).
setPixelDimensions(400, 700).build();
currentViewport.setDensity(dm.density);
currentViewport.setMapDensity(getSettingsMapDensity());
}
@ -224,6 +227,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
view.setClickable(true);
view.setLongClickable(true);
view.setFocusable(true);
refreshMap(true);
}
public Boolean onKeyDown(int keyCode, KeyEvent event) {
@ -396,9 +400,6 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
}
public OsmandSettings getSettings() {
if (settings == null) {
settings = getApplication().getSettings();
}
return settings;
}
@ -977,31 +978,12 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
}
}
public Resources getResources() {
return application.getResources();
}
public Context getContext() {
return view.getContext();
}
public ViewParent getParent() {
return view.getParent();
}
public View getView() {
return view;
}
public int getHeight() {
return view.getHeight();
}
public float getWidth() {
return view.getWidth();
return activity;
}
}

View file

@ -1,54 +0,0 @@
package net.osmand.plus.views.controls;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
public class MapCancelControl extends MapControls {
private Button cancelButton;
public MapCancelControl(MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) {
super(mapActivity, showUIHandler, scaleCoefficient);
}
@Override
public void showControls(FrameLayout parent) {
cancelButton = addButton(parent, R.string.cancel_navigation, R.drawable.map_btn_cancel);
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
notifyClicked();
if(mapActivity.getRoutingHelper().isFollowingMode()) {
mapActivity.getMapActions().stopNavigationActionConfirm(mapActivity.getMapView());
} else {
mapActivity.getMapActions().stopNavigationWithoutConfirm();
}
}
});
}
@Override
public void hideControls(FrameLayout layout) {
removeButton(layout, cancelButton);
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) {
}
public int getWidth() {
if (width == 0) {
Drawable buttonDrawable = mapActivity.getResources().getDrawable(R.drawable.map_btn_cancel);
width = buttonDrawable.getMinimumWidth();
}
return width ;
}
}

View file

@ -1,224 +0,0 @@
package net.osmand.plus.views.controls;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.PointF;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageButton;
public abstract class MapControls {
protected MapActivity mapActivity;
protected float scaleCoefficient;
protected Handler showUIHandler;
protected int shadowColor;
private boolean visible;
private long delayTime;
protected int gravity = Gravity.BOTTOM | Gravity.RIGHT;
protected int margin;
protected int vmargin;
protected int width;
protected int height;
protected Runnable notifyClick;
private int extraVerticalMargin;
public MapControls(MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) {
this.mapActivity = mapActivity;
this.showUIHandler = showUIHandler;
this.scaleCoefficient = scaleCoefficient;
}
public void setGravity(int gravity) {
this.gravity = gravity;
}
public void setMargin(int margin) {
this.margin = margin;
}
public void setVerticalMargin(int vmargin) {
this.vmargin = vmargin;
}
protected ImageButton addImageButton(FrameLayout parent, int stringId, int resourceId) {
Context ctx = mapActivity;
ImageButton button = new ImageButton(ctx);
applyAttributes(ctx, parent, button, stringId, resourceId, 0);
return button;
}
public int getTotalVerticalMargin() {
return extraVerticalMargin + vmargin;
}
protected Button addButton(FrameLayout parent, int stringId, int resourceId) {
return addButton(parent, stringId, resourceId, 0);
}
protected Button addButton(FrameLayout parent, int stringId, int resourceId, int extraMargin) {
Context ctx = mapActivity;
Button button = new Button(ctx);
applyAttributes(ctx, parent, button, stringId, resourceId, extraMargin);
return button;
}
public void setNotifyClick(Runnable notifyClick) {
this.notifyClick = notifyClick;
}
protected void notifyClicked() {
if(notifyClick != null) {
notifyClick.run();
}
}
private void applyAttributes(Context ctx, FrameLayout parent, View button, int stringId, int resourceId,
int extraMargin) {
button.setContentDescription(ctx.getString(stringId));
button.setBackgroundResource(resourceId);
Drawable d = ctx.getResources().getDrawable(resourceId);
android.widget.FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(d.getMinimumWidth(), d.getMinimumHeight(),
gravity);
if((gravity & Gravity.LEFT) == Gravity.LEFT) {
params.leftMargin = margin + extraMargin;
} else {
params.rightMargin = margin + extraMargin;
}
if((gravity & Gravity.BOTTOM) == Gravity.BOTTOM) {
params.bottomMargin = vmargin + extraVerticalMargin;
} else {
params.topMargin = vmargin + extraVerticalMargin;
}
button.setLayoutParams(params);
parent.addView(button);
button.setEnabled(true);
mapActivity.accessibleContent.add(button);
}
public int getGravity() {
return gravity;
}
protected void removeButton(final FrameLayout layout, final View b) {
b.setVisibility(View.GONE);
if (layout.getHandler() != null){
layout.getHandler().post(new Runnable() {
@Override
public void run() {
layout.removeView(b);
}
});
}
mapActivity.accessibleContent.remove(b);
}
public void updateTextColor(int textColor, int shadowColor) {
this.shadowColor = shadowColor;
}
public final void init(FrameLayout layout) {
initControls(layout);
}
public final void show(FrameLayout layout) {
visible = true;
showControls(layout);
}
public final void showWithDelay(final FrameLayout layout, final long delay) {
this.delayTime = System.currentTimeMillis() + delay;
if(!visible) {
visible = true;
showControls(layout);
runWithDelay(layout, delay);
mapActivity.getMapView().refreshMap();
}
}
private void runWithDelay(final FrameLayout layout, final long delay) {
showUIHandler.postDelayed(new Runnable() {
@Override
public void run() {
long ctime = System.currentTimeMillis();
if(MapControls.this.delayTime <= ctime) {
if (MapControls.this.delayTime != 0) {
MapControls.this.delayTime = 0;
visible = false;
hideControls(layout);
mapActivity.getMapView().refreshMap();
}
} else {
runWithDelay(layout, MapControls.this.delayTime - ctime);
}
}
}, delay);
}
public final void hide(FrameLayout layout) {
if(this.delayTime == 0) {
visible = false;
hideControls(layout);
}
}
public final void forceHide(FrameLayout layout) {
delayTime = 0;
visible = false;
hideControls(layout);
mapActivity.getMapView().refreshMap();
}
public boolean isVisible() {
return visible;
}
protected boolean isLeft() {
return (Gravity.LEFT & gravity) == Gravity.LEFT;
}
public boolean isBottom() {
return (Gravity.BOTTOM & gravity) == Gravity.BOTTOM;
}
protected void initControls(FrameLayout layout) {
}
protected abstract void hideControls(FrameLayout layout);
protected abstract void showControls(FrameLayout layout);
public abstract void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode);
public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) {
return false;
}
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
return false;
}
public void setExtraVerticalMargin(int extraVerticalMargin) {
this.extraVerticalMargin = extraVerticalMargin;
}
public int getExtraVerticalMargin() {
return this.extraVerticalMargin;
}
}

View file

@ -1,139 +0,0 @@
package net.osmand.plus.views.controls;
import java.util.List;
import net.londatiga.android.ActionItem;
import net.londatiga.android.QuickAction;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.OsmandMapTileView;
import android.graphics.Canvas;
import android.graphics.PointF;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.FrameLayout;
public class MapMenuControls extends MapControls {
private Button backToMenuButton;
private Drawable modeShadow;
private Drawable cacheAppModeIcon = null;
private ApplicationMode cacheApplicationMode = null;
public MapMenuControls(MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) {
super(mapActivity, showUIHandler, scaleCoefficient);
}
private void initBackToMenuButton(final OsmandMapTileView view, FrameLayout parent) {
backToMenuButton = addButton(parent, R.string.backToMenu, R.drawable.map_btn_menu);
modeShadow = view.getResources().getDrawable(R.drawable.zoom_background);
backToMenuButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// double lat = activity.getMapView().getLatitude();
// double lon = activity.getMapView().getLongitude();
// MainMenuActivity.backToMainMenuDialog(activity, new LatLon(lat, lon));
notifyClicked();
if(mapActivity.getMyApplication().getSettings().USE_DASHBOARD_INSTEAD_OF_DRAWER.get()) {
mapActivity.getDashboard().setDashboardVisibility(true);
} else {
mapActivity.getMapActions().onDrawerBack();
mapActivity.getMapActions().toggleDrawer();
}
}
});
}
@Override
public void showControls(FrameLayout layout) {
initBackToMenuButton(mapActivity.getMapView(), layout);
}
@Override
public void hideControls(FrameLayout layout) {
removeButton(layout, backToMenuButton);
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) {
if(mapActivity.findViewById(R.id.MapButtons).getVisibility() == View.GONE) {
return;
}
drawApplicationMode(canvas, nightMode != null && nightMode.isNightMode());
}
private void drawApplicationMode(Canvas canvas, boolean nightMode) {
OsmandMapTileView view = mapActivity.getMapView();
ApplicationMode appMode = view.getSettings().getApplicationMode();
if(appMode != cacheApplicationMode){
modeShadow.setBounds(backToMenuButton.getLeft() + (int) (2 * scaleCoefficient), backToMenuButton.getTop() - (int) (24 * scaleCoefficient),
backToMenuButton.getRight() - (int) (4 * scaleCoefficient), backToMenuButton.getBottom());
cacheAppModeIcon = view.getResources().getDrawable(appMode.getSmallIcon(nightMode));
int l = modeShadow.getBounds().left + (modeShadow.getBounds().width() - cacheAppModeIcon.getMinimumWidth()) / 2;
int t = (int) (modeShadow.getBounds().top + 2 * scaleCoefficient);
cacheAppModeIcon.setBounds(l, t, l + cacheAppModeIcon.getMinimumWidth(), t + cacheAppModeIcon.getMinimumHeight());
}
modeShadow.draw(canvas);
if(cacheAppModeIcon != null){
cacheAppModeIcon.draw(canvas);
}
}
@Override
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
if (modeShadow.getBounds().contains((int) point.x, (int) point.y)) {
onApplicationModePress();
return true;
}
return false;
}
private void onApplicationModePress() {
final QuickAction mQuickAction = new QuickAction(backToMenuButton);
List<ApplicationMode> vls = ApplicationMode.values(mapActivity.getMyApplication().getSettings());
final ApplicationMode[] modes = vls.toArray(new ApplicationMode[vls.size()]);
int[] icons = new int[vls.size()];
int[] values = new int[vls.size()];
for(int k = 0; k < modes.length; k++) {
icons[k] = modes[k].getSmallIcon(false);
values[k] = modes[k].getStringResource();
}
for (int i = 0; i < modes.length; i++) {
final ActionItem action = new ActionItem();
action.setTitle(mapActivity.getResources().getString(values[i]));
action.setIcon(mapActivity.getResources().getDrawable(icons[i]));
final int j = i;
action.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mapActivity.getMyApplication().getSettings().APPLICATION_MODE.set(modes[j]);
mQuickAction.dismiss();
}
});
mQuickAction.addActionItem(action);
}
mQuickAction.setAnimStyle(QuickAction.ANIM_AUTO);
mQuickAction.show();
}
public int getWidth() {
if (width == 0) {
Drawable buttonDrawable = mapActivity.getResources().getDrawable(R.drawable.map_btn_menu);
width = buttonDrawable.getMinimumWidth();
}
return width ;
}
}

View file

@ -1,229 +0,0 @@
package net.osmand.plus.views.controls;
import gnu.trove.list.array.TIntArrayList;
import java.util.ArrayList;
import java.util.List;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.ShadowText;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.text.TextPaint;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
public class MapNavigateControl extends MapControls {
private Button navigateButton;
private MapRouteInfoControl ri;
private Runnable delayStart;
private Drawable navigateShadow;
private Bitmap mapMagnifier;
private TextPaint counterTextPaint;
private Paint bitmapPaint;
private static long startCounter = 0;
public MapNavigateControl(MapRouteInfoControl ri, MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) {
super(mapActivity, showUIHandler, scaleCoefficient);
this.ri = ri;
counterTextPaint = new TextPaint();
counterTextPaint.setTextSize(18 * scaleCoefficient);
counterTextPaint.setAntiAlias(true);
counterTextPaint.setFakeBoldText(true);
}
public void startCounter() {
OsmandSettings settings = mapActivity.getMyApplication().getSettings();
if(settings.DELAY_TO_START_NAVIGATION.get() <= 0) {
return;
}
if (startCounter <= 0) {
startCounter = System.currentTimeMillis() + settings.DELAY_TO_START_NAVIGATION.get() * 1000;
delayStart = new Runnable() {
@Override
public void run() {
if (startCounter > 0) {
if (System.currentTimeMillis() > startCounter) {
startCounter = 0;
startNavigation();
} else {
mapActivity.refreshMap();
showUIHandler.postDelayed(delayStart, 1000);
}
}
}
};
delayStart.run();
}
}
public void startNavigation() {
stopCounter();
OsmandApplication app = mapActivity.getMyApplication();
RoutingHelper routingHelper = app.getRoutingHelper();
if(routingHelper.isFollowingMode()) {
routingHelper.setRoutePlanningMode(false);
mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode();
} else {
if(!app.getTargetPointsHelper().checkPointToNavigateShort()) {
ri.showDialog();
} else {
mapActivity.getMapViewTrackingUtilities().backToLocationImpl();
app.getSettings().FOLLOW_THE_ROUTE.set(true);
routingHelper.setFollowingMode(true);
routingHelper.setRoutePlanningMode(false);
mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode();
routingHelper.setCurrentLocation(app.getLocationProvider().getLastKnownLocation(), false);
app.getRoutingHelper().notifyIfRouteIsCalculated();
}
}
}
@Override
public void showControls(final FrameLayout parent) {
navigateButton = addButton(parent, R.string.get_directions, R.drawable.map_btn_navigate);
navigateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
notifyClicked();
startNavigation();
}
});
if(!mapActivity.getRoutingHelper().isFollowingMode() && !mapActivity.getRoutingHelper().isPauseNavigation()) {
startCounter();
}
}
@Override
protected void initControls(FrameLayout layout) {
super.initControls(layout);
navigateShadow = mapActivity.getResources().getDrawable(R.drawable.zoom_background).mutate();
mapMagnifier = BitmapFactory.decodeResource(mapActivity.getResources(), R.drawable.map_magnifier);
bitmapPaint = new Paint();
}
@Override
public void hideControls(FrameLayout layout) {
removeButton(layout, navigateButton);
stopCounter();
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) {
if(!mapActivity.getRoutingHelper().isFollowingMode()) {
drawCount(canvas, tileBox);
}
}
public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) {
stopCounter();
return false;
}
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
stopCounter();
if (navigateShadow.getBounds().contains((int) point.x, (int) point.y)) {
openDialog();
return true;
}
return false;
}
private void openDialog() {
Builder bld = new AlertDialog.Builder(mapActivity);
final TIntArrayList opt = new TIntArrayList();
List<String> items = new ArrayList<String>();
int[] checkedItem = new int[]{ -1};
Integer selected = mapActivity.getMyApplication().getSettings().DELAY_TO_START_NAVIGATION.get();
addOpt(-1, items, opt, checkedItem, selected);
addOpt(3, items, opt, checkedItem, selected);
addOpt(5, items, opt, checkedItem, selected);
addOpt(7, items, opt, checkedItem, selected);
addOpt(10, items, opt, checkedItem, selected);
addOpt(15, items, opt, checkedItem, selected);
addOpt(20, items, opt, checkedItem, selected);
bld.setTitle(R.string.delay_navigation_start);
bld.setSingleChoiceItems(items.toArray(new String[items.size()]), checkedItem[0], new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
notifyClicked();
dialog.dismiss();
mapActivity.getMyApplication().getSettings().DELAY_TO_START_NAVIGATION.set(opt.get(which));
startCounter();
}
});
bld.show();
}
private void addOpt(int i, List<String> items, TIntArrayList opt, int[] checkedItem, int selected) {
if(i == selected) {
checkedItem[0] = items.size();
}
opt.add(i);
if(i < 0) {
items.add(mapActivity.getString(R.string.auto_follow_route_never));
} else {
items.add(i + " " +mapActivity.getString(R.string.int_seconds));
}
}
private void drawCount(Canvas canvas, RotatedTileBox tb) {
if ((navigateShadow.getBounds().width() == 0 && navigateButton.getWidth() > 0 )||
navigateShadow.getBounds().bottom != navigateButton.getBottom()) {
navigateShadow.setBounds(navigateButton.getLeft() - 2, navigateButton.getTop()
- (int) (18 * scaleCoefficient), navigateButton.getRight(), navigateButton.getBottom());
}
if(navigateShadow.getBounds().width() > 0) {
navigateShadow.draw(canvas);
}
if (startCounter > 0) {
int get = (int) ((startCounter -System.currentTimeMillis()) / 1000l);
final String text = get + "";
float length = counterTextPaint.measureText(text);
ShadowText.draw(text, canvas, navigateButton.getLeft() + (navigateButton.getWidth() - length - 2) / 2,
navigateButton.getTop() + 4 * scaleCoefficient, counterTextPaint, shadowColor);
} else {
int size = (int) (16 * scaleCoefficient);
int top = (int) (navigateButton.getTop() - size - 4 * scaleCoefficient);
int left = (int) (navigateButton.getLeft() + (navigateButton.getWidth() - mapMagnifier.getWidth() - 2 * scaleCoefficient) / 2);
// canvas density /2 ? size * 2
canvas.drawBitmap(mapMagnifier, null, new Rect(left, top, left + size * 2, top + size * 2), bitmapPaint);
}
}
public int getWidth() {
if (width == 0) {
Drawable buttonDrawable = mapActivity.getResources().getDrawable(R.drawable.map_btn_navigate);
width = buttonDrawable.getMinimumWidth();
}
return width ;
}
public void stopCounter() {
startCounter = 0;
}
}

View file

@ -20,7 +20,6 @@ import net.osmand.plus.routing.RouteDirectionInfo;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.routing.RoutingHelper.IRouteInformationListener;
import net.osmand.plus.views.ContextMenuLayer;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.OsmandMapTileView;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
@ -28,10 +27,7 @@ import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.PointF;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
@ -39,17 +35,14 @@ import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
public class MapRouteInfoControl extends MapControls implements IRouteInformationListener {
private Button infoButton;
public class MapRouteInfoControl implements IRouteInformationListener {
public static int directionInfo = -1;
public static boolean controlVisible = false;
private final ContextMenuLayer contextMenu;
private final RoutingHelper routingHelper;
private OsmandMapTileView mapView;
@ -59,17 +52,17 @@ public class MapRouteInfoControl extends MapControls implements IRouteInformatio
private boolean selectFromMapForTarget;
private boolean showDialog = false;
private MapActivity mapActivity;
public MapRouteInfoControl(ContextMenuLayer contextMenu,
MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) {
super(mapActivity, showUIHandler, scaleCoefficient);
MapActivity mapActivity) {
this.contextMenu = contextMenu;
this.mapActivity = mapActivity;
routingHelper = mapActivity.getRoutingHelper();
mapView = mapActivity.getMapView();
routingHelper.addListener(this);
}
@Override
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
if(selectFromMapTouch) {
LatLon latlon = tileBox.getLatLonFromPixel(point.x, point.y);
@ -83,30 +76,31 @@ public class MapRouteInfoControl extends MapControls implements IRouteInformatio
showDialog();
return true;
}
return super.onSingleTap(point, tileBox);
return false;
}
@Override
public void showControls(FrameLayout parent) {
infoButton = addButton(parent, R.string.route_info, R.drawable.map_btn_signpost);
if (showDialog){
if (getTargets().getPointToNavigate() == null){
showDialog();
}
showDialog = false;
}
controlVisible = true;
infoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
notifyClicked();
if(dialog != null) {
hideDialog();
} else {
public void setVisible(boolean visible) {
if(visible) {
if (showDialog){
if (getTargets().getPointToNavigate() == null){
showDialog();
}
showDialog = false;
}
});
controlVisible = true;
} else {
hideDialog();
controlVisible = false;
}
}
public void showHideDialog() {
if(dialog != null) {
hideDialog();
} else {
showDialog();
}
}
private Dialog createDialog() {
@ -137,7 +131,8 @@ public class MapRouteInfoControl extends MapControls implements IRouteInformatio
lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
lp.gravity = Gravity.BOTTOM;
lp.y = (int) (infoButton.getBottom() - infoButton.getTop() + scaleCoefficient * 5 + getExtraVerticalMargin());
// TODO
// lp.y = (int) (infoButton.getBottom() - infoButton.getTop() + scaleCoefficient * 5 + getExtraVerticalMargin());
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setAttributes(lp);
@ -253,26 +248,6 @@ public class MapRouteInfoControl extends MapControls implements IRouteInformatio
return controlVisible;
}
@Override
public void hideControls(FrameLayout layout) {
removeButton(layout, infoButton);
hideDialog();
controlVisible = false;
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) {
}
public int getWidth() {
if (width == 0) {
Drawable buttonDrawable = mapActivity.getResources().getDrawable(R.drawable.map_btn_info);
width = buttonDrawable.getMinimumWidth();
}
return width ;
}
private void attachListeners(final View mainView) {
final OsmandApplication ctx = mapActivity.getMyApplication();
final Button simulateRoute = (Button) mainView.findViewById(R.id.SimulateRoute);
@ -449,11 +424,9 @@ public class MapRouteInfoControl extends MapControls implements IRouteInformatio
public void showDialog() {
dialog = createDialog();
dialog.show();
infoButton.setBackgroundResource(R.drawable.map_btn_signpost_p);
dialog.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dlg) {
infoButton.setBackgroundResource(R.drawable.map_btn_signpost);
dialog = null;
}
});
@ -463,7 +436,6 @@ public class MapRouteInfoControl extends MapControls implements IRouteInformatio
if (dialog != null) {
dialog.hide();
dialog = null;
infoButton.setBackgroundResource(R.drawable.map_btn_signpost);
}
}

View file

@ -1,52 +0,0 @@
package net.osmand.plus.views.controls;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
public class MapRoutePlanControl extends MapControls {
private Button routePlanButton;
public MapRoutePlanControl(MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) {
super(mapActivity, showUIHandler, scaleCoefficient);
}
@Override
public void showControls(FrameLayout parent) {
routePlanButton = addButton(parent, R.string.info_button, R.drawable.map_btn_info);
routePlanButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
notifyClicked();
mapActivity.getRoutingHelper().setRoutePlanningMode(true);
mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode();
mapActivity.refreshMap();
}
});
}
@Override
public void hideControls(FrameLayout layout) {
removeButton(layout, routePlanButton);
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) {
}
public int getWidth() {
if (width == 0) {
Drawable buttonDrawable = mapActivity.getResources().getDrawable(R.drawable.map_btn_info);
width = buttonDrawable.getMinimumWidth();
}
return width ;
}
}

View file

@ -9,14 +9,13 @@ import java.util.Set;
import net.osmand.CallbackWithObject;
import net.osmand.Location;
import net.osmand.data.LatLon;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.TargetPointsHelper.TargetPoint;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SettingsBaseActivity;
@ -25,7 +24,6 @@ import net.osmand.plus.activities.actions.AppModeDialog;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
import net.osmand.plus.routing.RouteProvider.RouteService;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.router.GeneralRouter;
import net.osmand.router.GeneralRouter.RoutingParameter;
import net.osmand.router.GeneralRouter.RoutingParameterType;
@ -35,8 +33,6 @@ import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.graphics.Canvas;
import android.os.Handler;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
@ -47,120 +43,107 @@ import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
public class MapRoutePreferencesControl extends MapControls {
private ImageButton settingsAppModeButton;
public class MapRoutePreferencesControl {
private OsmandSettings settings;
private int cachedId;
private Dialog dialog;
private ArrayAdapter<LocalRoutingParameter> listAdapter;
public MapRoutePreferencesControl(MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) {
super(mapActivity, showUIHandler, scaleCoefficient);
private MapActivity mapActivity;
public MapRoutePreferencesControl(MapActivity mapActivity) {
this.mapActivity = mapActivity;
settings = mapActivity.getMyApplication().getSettings();
}
private static class LocalRoutingParameter {
public RoutingParameter routingParameter;
public String getText(MapActivity mapActivity) {
return SettingsBaseActivity.getRoutingStringPropertyName(mapActivity, routingParameter.getId(), routingParameter.getName());
return SettingsBaseActivity.getRoutingStringPropertyName(mapActivity, routingParameter.getId(),
routingParameter.getName());
}
public boolean isSelected(OsmandSettings settings) {
final CommonPreference<Boolean> property = settings.getCustomRoutingBooleanProperty(routingParameter.getId());
final CommonPreference<Boolean> property = settings.getCustomRoutingBooleanProperty(routingParameter
.getId());
return property.get();
}
public void setSelected(OsmandSettings settings, boolean isChecked) {
final CommonPreference<Boolean> property = settings.getCustomRoutingBooleanProperty(routingParameter.getId());
property.set(isChecked);
final CommonPreference<Boolean> property = settings.getCustomRoutingBooleanProperty(routingParameter
.getId());
property.set(isChecked);
}
}
private static class OtherLocalRoutingParameter extends LocalRoutingParameter {
public String text;
public boolean selected;
public int id;
public OtherLocalRoutingParameter(int id, String text, boolean selected) {
this.text = text;
this.selected = selected;
this.id = id;
}
@Override
public String getText(MapActivity mapActivity) {
return text;
}
@Override
public boolean isSelected(OsmandSettings settings) {
return selected;
}
@Override
public void setSelected(OsmandSettings settings, boolean isChecked) {
selected = isChecked;
}
}
@Override
public void showControls(FrameLayout parent) {
settingsAppModeButton = addImageButton(parent, R.string.route_preferences, R.drawable.map_btn_plain);
cachedId = 0;
settingsAppModeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
notifyClicked();
if(dialog != null) {
dialog.hide();
public void showAndHideDialog() {
if (dialog != null) {
dialog.hide();
dialog = null;
} else {
dialog = showDialog();
dialog.show();
dialog.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dlg) {
dialog = null;
settingsAppModeButton.setBackgroundResource(R.drawable.map_btn_plain);
} else {
dialog = showDialog();
dialog.show();
settingsAppModeButton.setBackgroundResource(R.drawable.map_btn_plain_p);
dialog.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dlg) {
settingsAppModeButton.setBackgroundResource(R.drawable.map_btn_plain);
dialog = null;
}
});
}
}
});
});
}
}
private Dialog showDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity);
View ll = createLayout();
builder.setView(ll);
//builder.setTitle(R.string.route_preferences);
Dialog dialog = builder.create();
dialog.setCanceledOnTouchOutside(true);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
lp.gravity = Gravity.BOTTOM;
lp.y = (int) (settingsAppModeButton.getBottom() - settingsAppModeButton.getTop() + scaleCoefficient * 5);
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setAttributes(lp);
return dialog;
AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity);
View ll = createLayout();
builder.setView(ll);
// builder.setTitle(R.string.route_preferences);
Dialog dialog = builder.create();
dialog.setCanceledOnTouchOutside(true);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
lp.gravity = Gravity.BOTTOM;
// TODO
// lp.y = (int) (settingsAppModeButton.getBottom() - settingsAppModeButton.getTop() + scaleCoefficient * 5);
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setAttributes(lp);
return dialog;
}
private void updateGpxRoutingParameter(OtherLocalRoutingParameter gpxParam) {
GPXRouteParamsBuilder rp = mapActivity.getRoutingHelper().getCurrentGPXRoute();
boolean selected = gpxParam.isSelected(settings);
@ -174,17 +157,18 @@ public class MapRoutePreferencesControl extends MapControls {
Location end = ps.get(ps.size() - 1);
TargetPoint pn = tg.getPointToNavigate();
boolean update = false;
if (pn == null ||
MapUtils.getDistance(pn.point, new LatLon(first.getLatitude(), first.getLongitude())) < 10) {
if (pn == null
|| MapUtils.getDistance(pn.point, new LatLon(first.getLatitude(), first.getLongitude())) < 10) {
tg.navigateToPoint(new LatLon(end.getLatitude(), end.getLongitude()), false, -1);
update = true;
}
if (tg.getPointToStart() == null ||
MapUtils.getDistance(tg.getPointToStart().point, new LatLon(end.getLatitude(), end.getLongitude())) < 10) {
if (tg.getPointToStart() == null
|| MapUtils.getDistance(tg.getPointToStart().point,
new LatLon(end.getLatitude(), end.getLongitude())) < 10) {
tg.setStartPoint(new LatLon(first.getLatitude(), first.getLongitude()), false, null);
update = true;
}
if(update) {
if (update) {
tg.updateRouteAndReferesh(true);
}
}
@ -208,45 +192,47 @@ public class MapRoutePreferencesControl extends MapControls {
if (gpxParam.id == R.string.fast_route_mode) {
settings.FAST_ROUTE_MODE.set(selected);
}
if (gpxParam.id == R.string.speak_favorites){
if (gpxParam.id == R.string.speak_favorites) {
settings.ANNOUNCE_NEARBY_FAVORITES.set(selected);
}
}
private List<LocalRoutingParameter> getRoutingParameters(ApplicationMode am) {
List<LocalRoutingParameter> list = new ArrayList<LocalRoutingParameter>();
GPXRouteParamsBuilder rparams = mapActivity.getRoutingHelper().getCurrentGPXRoute();
boolean osmandRouter = settings.ROUTER_SERVICE.get() == RouteService.OSMAND ;
if(!osmandRouter) {
list.add(new OtherLocalRoutingParameter(R.string.calculate_osmand_route_without_internet,
getString(R.string.calculate_osmand_route_without_internet), settings.GPX_ROUTE_CALC_OSMAND_PARTS.get()));
list.add(new OtherLocalRoutingParameter(R.string.fast_route_mode,
getString(R.string.fast_route_mode), settings.FAST_ROUTE_MODE.get()));
boolean osmandRouter = settings.ROUTER_SERVICE.get() == RouteService.OSMAND;
if (!osmandRouter) {
list.add(new OtherLocalRoutingParameter(R.string.calculate_osmand_route_without_internet,
getString(R.string.calculate_osmand_route_without_internet), settings.GPX_ROUTE_CALC_OSMAND_PARTS
.get()));
list.add(new OtherLocalRoutingParameter(R.string.fast_route_mode, getString(R.string.fast_route_mode),
settings.FAST_ROUTE_MODE.get()));
return list;
}
if(rparams != null) {
if (rparams != null) {
GPXFile fl = rparams.getFile();
if (fl.hasRtePt()) {
list.add(new OtherLocalRoutingParameter(R.string.use_points_as_intermediates,
getString(R.string.use_points_as_intermediates), rparams.isUseIntermediatePointsRTE()));
}
list.add(new OtherLocalRoutingParameter(R.string.gpx_option_reverse_route,
list.add(new OtherLocalRoutingParameter(R.string.gpx_option_reverse_route,
getString(R.string.gpx_option_reverse_route), rparams.isReverse()));
if (!rparams.isUseIntermediatePointsRTE()) {
list.add(new OtherLocalRoutingParameter(R.string.gpx_option_from_start_point,
getString(R.string.gpx_option_from_start_point), rparams.isPassWholeRoute()));
list.add(new OtherLocalRoutingParameter(R.string.gpx_option_from_start_point,
getString(R.string.gpx_option_from_start_point), rparams.isPassWholeRoute()));
list.add(new OtherLocalRoutingParameter(R.string.gpx_option_calculate_first_last_segment,
getString(R.string.gpx_option_calculate_first_last_segment), rparams.isCalculateOsmAndRouteParts()));
getString(R.string.gpx_option_calculate_first_last_segment), rparams
.isCalculateOsmAndRouteParts()));
}
// list.add(new OtherLocalRoutingParameter(R.string.announce_gpx_waypoints,
// getString(R.string.announce_gpx_waypoints), rparams.isAnnounceWaypoints()));
// list.add(new OtherLocalRoutingParameter(R.string.announce_gpx_waypoints,
// getString(R.string.announce_gpx_waypoints), rparams.isAnnounceWaypoints()));
// Temporary disabled
// list.add(new GPXLocalRoutingParameter(R.string.calculate_osmand_route_gpx,
// getString(R.string.calculate_osmand_route_gpx), rparams.isCalculateOsmAndRoute()));
// list.add(new GPXLocalRoutingParameter(R.string.calculate_osmand_route_gpx,
// getString(R.string.calculate_osmand_route_gpx), rparams.isCalculateOsmAndRoute()));
}
GeneralRouter rm = SettingsNavigationActivity.getRouter(mapActivity.getMyApplication().getDefaultRoutingConfig(), am);
if(rm == null || (rparams != null && !rparams.isCalculateOsmAndRoute())) {
GeneralRouter rm = SettingsNavigationActivity.getRouter(mapActivity.getMyApplication()
.getDefaultRoutingConfig(), am);
if (rm == null || (rparams != null && !rparams.isCalculateOsmAndRoute())) {
return list;
}
for (RoutingParameter r : rm.getParameters().values()) {
@ -259,6 +245,7 @@ public class MapRoutePreferencesControl extends MapControls {
return list;
}
private String getString(int id) {
return mapActivity.getString(id);
}
@ -271,12 +258,12 @@ public class MapRoutePreferencesControl extends MapControls {
final ListView lv = (ListView) settingsDlg.findViewById(android.R.id.list);
final Set<ApplicationMode> selected = new HashSet<ApplicationMode>();
selected.add(am);
setupSpinner(settingsDlg);
listAdapter = new ArrayAdapter<LocalRoutingParameter>(ctx,
R.layout.layers_list_activity_item, R.id.title, getRoutingParameters(am)) {
final float scaleCoefficient = mapActivity.getMapView().getScaleCoefficient();
listAdapter = new ArrayAdapter<LocalRoutingParameter>(ctx, R.layout.layers_list_activity_item, R.id.title,
getRoutingParameters(am)) {
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View v = mapActivity.getLayoutInflater().inflate(R.layout.layers_list_activity_item, null);
@ -285,8 +272,8 @@ public class MapRoutePreferencesControl extends MapControls {
final LocalRoutingParameter rp = getItem(position);
tv.setText(rp.getText(mapActivity));
tv.setPadding((int) (5 * scaleCoefficient), 0, 0, 0);
if (rp.routingParameter != null && rp.routingParameter.getId().equals("short_way")){
//if short route settings - it should be inverse of fast_route_mode
if (rp.routingParameter != null && rp.routingParameter.getId().equals("short_way")) {
// if short route settings - it should be inverse of fast_route_mode
ch.setChecked(!settings.FAST_ROUTE_MODE.get());
} else {
ch.setChecked(rp.isSelected(settings));
@ -295,13 +282,13 @@ public class MapRoutePreferencesControl extends MapControls {
ch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//if short way that it should set valut to fast mode opposite of current
if (rp.routingParameter != null && rp.routingParameter.getId().equals("short_way")){
// if short way that it should set valut to fast mode opposite of current
if (rp.routingParameter != null && rp.routingParameter.getId().equals("short_way")) {
settings.FAST_ROUTE_MODE.set(!isChecked);
}
rp.setSelected(settings, isChecked);
if(rp instanceof OtherLocalRoutingParameter) {
if (rp instanceof OtherLocalRoutingParameter) {
updateGpxRoutingParameter((OtherLocalRoutingParameter) rp);
}
mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange();
@ -310,31 +297,29 @@ public class MapRoutePreferencesControl extends MapControls {
return v;
}
};
AppModeDialog.prepareAppModeView(mapActivity, selected, false,
(ViewGroup) settingsDlg.findViewById(R.id.TopBar), true,
new View.OnClickListener() {
@Override
public void onClick(View v) {
if(selected.size() > 0) {
ApplicationMode next = selected.iterator().next();
settings.APPLICATION_MODE.set(next);
mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange();
updateParameters();
}
}
});
AppModeDialog.prepareAppModeView(mapActivity, selected, false,
(ViewGroup) settingsDlg.findViewById(R.id.TopBar), true, new View.OnClickListener() {
@Override
public void onClick(View v) {
if (selected.size() > 0) {
ApplicationMode next = selected.iterator().next();
settings.APPLICATION_MODE.set(next);
mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange();
updateParameters();
}
}
});
lv.setAdapter(listAdapter);
return settingsDlg;
}
private void updateParameters() {
ApplicationMode am = settings.APPLICATION_MODE.get();
listAdapter.setNotifyOnChange(false);
listAdapter.clear();
for(LocalRoutingParameter r : getRoutingParameters(am)) {
for (LocalRoutingParameter r : getRoutingParameters(am)) {
listAdapter.add(r);
}
listAdapter.notifyDataSetChanged();
@ -347,19 +332,19 @@ public class MapRoutePreferencesControl extends MapControls {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if(position == 0) {
if(mapActivity.getRoutingHelper().getCurrentGPXRoute() != null) {
if (position == 0) {
if (mapActivity.getRoutingHelper().getCurrentGPXRoute() != null) {
mapActivity.getRoutingHelper().setGpxParams(null);
settings.FOLLOW_THE_GPX_ROUTE.set(null);
mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange();
}
updateParameters();
} else if(position == 1) {
} else if (position == 1) {
openGPXFileSelection(gpxSpinner);
} else if(position == 2) {
// nothing to change
}
} else if (position == 2) {
// nothing to change
}
}
@Override
@ -370,7 +355,7 @@ public class MapRoutePreferencesControl extends MapControls {
protected void openGPXFileSelection(final Spinner gpxSpinner) {
GpxUiHelper.selectGPXFile(mapActivity, false, false, new CallbackWithObject<GPXUtilities.GPXFile[]>() {
@Override
public boolean processResult(GPXFile[] result) {
mapActivity.getMapActions().setGPXRouteParams(result[0]);
@ -388,34 +373,19 @@ public class MapRoutePreferencesControl extends MapControls {
gpxActions.add(mapActivity.getString(R.string.shared_string_none));
gpxActions.add(mapActivity.getString(R.string.select_gpx));
GPXRouteParamsBuilder rp = mapActivity.getRoutingHelper().getCurrentGPXRoute();
if(rp != null) {
if (rp != null) {
gpxActions.add(new File(rp.getFile().path).getName());
}
ArrayAdapter<String> gpxAdapter = new ArrayAdapter<String>(mapActivity,
android.R.layout.simple_spinner_item,
gpxActions
);
ArrayAdapter<String> gpxAdapter = new ArrayAdapter<String>(mapActivity, android.R.layout.simple_spinner_item,
gpxActions);
gpxAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
gpxSpinner.setAdapter(gpxAdapter);
if(rp != null) {
if (rp != null) {
gpxSpinner.setSelection(2);
} else {
gpxSpinner.setSelection(0);
}
}
@Override
public void hideControls(FrameLayout layout) {
removeButton(layout, settingsAppModeButton);
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) {
int id = settings.getApplicationMode().getSmallIcon(false); // settingsAppModeButton.isPressed() || dialog != null
if(cachedId != id && settingsAppModeButton.getLeft() > 0) {
cachedId = id;
settingsAppModeButton.setImageResource(id);
}
}
}

View file

@ -1,288 +0,0 @@
package net.osmand.plus.views.controls;
import gnu.trove.list.array.TIntArrayList;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import net.osmand.core.android.MapRendererContext;
import net.osmand.core.android.MapRendererView;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.OsmAndConstants;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.BaseMapLayer;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.ShadowText;
import net.osmand.plus.views.corenative.NativeCoreContext;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Message;
import android.text.TextPaint;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
public class MapZoomControls extends MapControls {
private static final int SHOW_ZOOM_LEVEL_MSG_ID = OsmAndConstants.UI_HANDLER_MAP_CONTROLS + 1;
private static final int SHOW_ZOOM_BUTTON_MSG_ID = OsmAndConstants.UI_HANDLER_MAP_CONTROLS + 2;
private static final int SHOW_ZOOM_LEVEL_DELAY = 1000;
private static final int SHOW_ZOOM_LEVEL_BUTTON_DELAY = 1500;
private Button zoomInButton;
private Button zoomOutButton;
private TextPaint zoomTextPaint;
private Drawable zoomShadow;
private Bitmap mapMagnifier;
private Paint bitmapPaint;
private boolean showZoomLevel = false;
private boolean showZoomLevelButton = false;
private OsmandMapTileView view;
public MapZoomControls(MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) {
super(mapActivity, showUIHandler, scaleCoefficient);
view = mapActivity.getMapView();
zoomTextPaint = new TextPaint();
zoomTextPaint.setTextSize(18 * scaleCoefficient);
zoomTextPaint.setAntiAlias(true);
zoomTextPaint.setFakeBoldText(true);
}
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
if (isShowZoomLevel() && zoomShadow.getBounds().contains((int) point.x, (int) point.y)) {
getOnClickMagnifierListener(view).onLongClick(null);
return true;
}
return false;
}
@Override
protected void showControls(FrameLayout parent) {
int minimumWidth = view.getResources().getDrawable(R.drawable.map_zoom_in).getMinimumWidth();
int minimumHeight = view.getResources().getDrawable(R.drawable.map_zoom_in).getMinimumWidth();
vmargin = 0;
zoomInButton = addButton(parent, R.string.zoomIn, R.drawable.map_zoom_in);
if(isBottom()) {
zoomOutButton = addButton(parent, R.string.zoomOut, R.drawable.map_zoom_out, minimumWidth);
} else {
vmargin = minimumHeight - (minimumHeight / 6);
zoomOutButton = addButton(parent, R.string.zoomOut, R.drawable.map_zoom_out);
}
zoomInButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
notifyClicked();
if (view.isZooming()) {
mapActivity.changeZoom(2, System.currentTimeMillis());
} else {
mapActivity.changeZoom(1, System.currentTimeMillis());
}
}
});
final View.OnLongClickListener listener = getOnClickMagnifierListener(view);
zoomInButton.setOnLongClickListener(listener);
zoomOutButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
long time = Calendar.getInstance().getTime().getTime();
notifyClicked();
mapActivity.changeZoom(-1, System.currentTimeMillis());
}
});
zoomOutButton.setOnLongClickListener(listener);
}
@Override
public void initControls(FrameLayout parent) {
if(isBottom()) {
zoomShadow = view.getResources().getDrawable(R.drawable.zoom_background).mutate();
}
mapMagnifier = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_magnifier);
bitmapPaint = new Paint();
}
@Override
public void hideControls(FrameLayout layout) {
removeButton(layout, zoomInButton);
removeButton(layout, zoomOutButton);
}
private void drawZoomLevel(Canvas canvas, RotatedTileBox tb, boolean drawZoomLevel) {
if (zoomShadow.getBounds().width() == 0) {
zoomShadow.setBounds(zoomInButton.getLeft() - 2, zoomInButton.getTop() - (int) (18 * scaleCoefficient),
zoomInButton.getRight(), zoomInButton.getBottom());
}
zoomShadow.draw(canvas);
if (drawZoomLevel) {
String zoomText = tb.getZoom() + "";
double frac = tb.getMapDensity();
if (frac != 0) {
int ifrac = (int) (frac * 10);
zoomText += " ";
zoomText += Math.abs(ifrac) / 10;
if (ifrac % 10 != 0) {
zoomText += "." + Math.abs(ifrac) % 10;
}
}
float length = zoomTextPaint.measureText(zoomText);
ShadowText.draw(zoomText, canvas, zoomInButton.getLeft() + (zoomInButton.getWidth() - length - 2) / 2,
zoomInButton.getTop() + 4 * scaleCoefficient, zoomTextPaint, shadowColor);
} else {
int size = (int) (16 * scaleCoefficient);
int top = (int) (zoomInButton.getTop() - size - 4 * scaleCoefficient);
int left = (int) (zoomInButton.getLeft() + (zoomInButton.getWidth() - mapMagnifier.getWidth() - 2 * scaleCoefficient) / 2);
// canvas density /2 ? size * 2
canvas.drawBitmap(mapMagnifier, null, new Rect(left, top, left + size * 2, top + size * 2), bitmapPaint);
}
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) {
BaseMapLayer mainLayer = view.getMainLayer();
boolean zoomInEnabled = mainLayer != null && tileBox.getZoom() < mainLayer.getMaximumShownMapZoom();
boolean zoomOutEnabled = mainLayer != null && tileBox.getZoom() > mainLayer.getMinimumShownMapZoom();
if (zoomInButton.isEnabled() != zoomInEnabled) {
zoomInButton.setEnabled(zoomInEnabled);
}
if (zoomOutButton.isEnabled() != zoomOutEnabled) {
zoomOutButton.setEnabled(zoomOutEnabled);
}
if (isBottom()) {
if (view.isZooming()) {
showZoomLevel = true;
showZoomLevelButton = false;
showUIHandler.removeMessages(SHOW_ZOOM_LEVEL_MSG_ID);
showUIHandler.removeMessages(SHOW_ZOOM_BUTTON_MSG_ID);
} else {
if (isShowZoomLevel() && view.getSettings().SHOW_RULER.get()) {
hideZoomLevelInTime();
}
}
boolean drawZoomLevel = isShowZoomLevel() || !view.getSettings().SHOW_RULER.get();
if (drawZoomLevel) {
drawZoomLevel(canvas, tileBox, !showZoomLevelButton);
}
}
}
private void sendMessageToShowZoomLevel() {
Message msg = Message.obtain(showUIHandler, new Runnable() {
@Override
public void run() {
showZoomLevelButton = true;
sendMessageToShowZoomButton();
view.refreshMap();
}
});
msg.what = SHOW_ZOOM_LEVEL_MSG_ID;
showUIHandler.sendMessageDelayed(msg, SHOW_ZOOM_LEVEL_DELAY);
}
private void sendMessageToShowZoomButton() {
Message msg = Message.obtain(showUIHandler, new Runnable() {
@Override
public void run() {
showZoomLevelButton = false;
showZoomLevel = false;
view.refreshMap();
}
});
msg.what = SHOW_ZOOM_BUTTON_MSG_ID;
showUIHandler.sendMessageDelayed(msg, SHOW_ZOOM_LEVEL_BUTTON_DELAY);
}
private void hideZoomLevelInTime() {
if (!showUIHandler.hasMessages(SHOW_ZOOM_LEVEL_MSG_ID) && !showUIHandler.hasMessages(SHOW_ZOOM_BUTTON_MSG_ID)) {
sendMessageToShowZoomLevel();
}
}
@Override
public void updateTextColor(int textColor, int shadowColor) {
super.updateTextColor(textColor, shadowColor);
zoomTextPaint.setColor(textColor);
}
public boolean isShowZoomLevel() {
return showZoomLevel;
}
public int getHeight() {
if (height == 0) {
Drawable buttonDrawable = view.getResources().getDrawable(R.drawable.map_zoom_in);
height = buttonDrawable.getMinimumHeight();
}
return height;
}
public static View.OnLongClickListener getOnClickMagnifierListener(final OsmandMapTileView view) {
final View.OnLongClickListener listener = new View.OnLongClickListener() {
@Override
public boolean onLongClick(View notUseCouldBeNull) {
final OsmandSettings.OsmandPreference<Float> mapDensity = view.getSettings().MAP_DENSITY;
final AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext());
int p = (int) (mapDensity.get() * 100);
final TIntArrayList tlist = new TIntArrayList(new int[] {33, 50, 75, 100, 150, 200, 300, 400 });
final List<String> values = new ArrayList<String>();
int i = -1;
for (int k = 0; k <= tlist.size(); k++) {
final boolean end = k == tlist.size();
if (i == -1) {
if ((end || p < tlist.get(k))) {
values.add(p + "%");
i = k;
} else if (p == tlist.get(k)) {
i = k;
}
}
if (k < tlist.size()) {
values.add(tlist.get(k) + "%");
}
}
if (values.size() != tlist.size()) {
tlist.insert(i, p);
}
bld.setTitle(R.string.map_magnifier);
bld.setSingleChoiceItems(values.toArray(new String[values.size()]), i,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int p = tlist.get(which);
mapDensity.set(p / 100.0f);
view.setComplexZoom(view.getZoom(), view.getSettingsMapDensity());
MapRendererContext mapContext = NativeCoreContext.getMapRendererContext();
if(mapContext != null) {
mapContext.updateMapSettings();
}
dialog.dismiss();
}
});
bld.show();
return true;
}
};
return listener;
}
}

View file

@ -1,109 +0,0 @@
package net.osmand.plus.views.controls;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.ShadowText;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.text.TextPaint;
import android.view.View;
import android.widget.FrameLayout;
public class RulerControl extends MapControls {
//ruler and ruler label appeareance:
// Day view: color black, shadowColor white (transpparent skin or not)
// Night view: color widgettext_night, shadowColor always use widgettext_shadow_night, same as widget background color for non-transparent night skin (from box_night_free_simple.9.png)
ShadowText cacheRulerText = null;
double cacheRulerZoom = 0;
double cacheRulerTileX = 0;
double cacheRulerTileY = 0;
float cacheRulerTextLen = 0;
MapZoomControls zoomControls;
Drawable rulerDrawable;
TextPaint rulerTextPaint;
final static double screenRulerPercent = 0.25;
boolean isNightRemembered = false;
public RulerControl(MapZoomControls zoomControls, MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) {
super(mapActivity, showUIHandler, scaleCoefficient);
this.zoomControls = zoomControls;
rulerTextPaint = new TextPaint();
rulerTextPaint.setTextSize(20 * scaleCoefficient);
rulerTextPaint.setAntiAlias(true);
rulerDrawable = mapActivity.getResources().getDrawable(R.drawable.ruler);
}
@Override
protected void hideControls(FrameLayout layout) {
}
@Override
public void updateTextColor(int textColor, int shadowColor) {
super.updateTextColor(textColor, shadowColor);
rulerTextPaint.setColor(textColor);
}
@Override
protected void showControls(FrameLayout layout) {
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings nightMode) {
if( (zoomControls.isVisible() && zoomControls.isShowZoomLevel()) || !mapActivity.getMyApplication().getSettings().SHOW_RULER.get()){
return;
}
if(mapActivity.findViewById(R.id.MapButtons).getVisibility() == View.GONE) {
return;
}
OsmandMapTileView view = mapActivity.getMapView();
boolean isNight = nightMode == null ? false : nightMode.isNightMode();
// update cache
if (view.isZooming()) {
cacheRulerText = null;
} else if (((isNight != isNightRemembered) || (tb.getZoom() != cacheRulerZoom) ||
Math.abs(tb.getCenterTileX() - cacheRulerTileX) + Math.abs(tb.getCenterTileY() - cacheRulerTileY) > 1) &&
tb.getPixWidth() > 0){
cacheRulerZoom = (tb.getZoom());
cacheRulerTileX = tb.getCenterTileX();
cacheRulerTileY = tb.getCenterTileY();
final double dist = tb.getDistance(0, tb.getPixHeight() / 2, tb.getPixWidth(), tb.getPixHeight() / 2);
double pixDensity = tb.getPixWidth() / dist;
double roundedDist = OsmAndFormatter.calculateRoundedDist(dist * screenRulerPercent, view.getApplication());
int cacheRulerDistPix = (int) (pixDensity * roundedDist);
cacheRulerText = ShadowText.create(OsmAndFormatter.getFormattedDistance((float) roundedDist, view.getApplication()));
cacheRulerTextLen = rulerTextPaint.measureText(cacheRulerText.getText());
rulerDrawable = (isNight ? mapActivity.getResources().getDrawable(R.drawable.ruler_night) : mapActivity.getResources().getDrawable(R.drawable.ruler));
Rect bounds = rulerDrawable.getBounds();
bounds.right = (int) (view.getWidth() - 7 * scaleCoefficient);
bounds.left = bounds.right - cacheRulerDistPix;
rulerDrawable.setBounds(bounds);
rulerDrawable.invalidateSelf();
}
if (cacheRulerText != null) {
Rect bounds = rulerDrawable.getBounds();
int bottom = (int) (view.getHeight() - vmargin);
if(bounds.bottom != bottom) {
bounds.bottom = bottom;
bounds.top = bounds.bottom - rulerDrawable.getMinimumHeight();
rulerDrawable.setBounds(bounds);
rulerDrawable.invalidateSelf();
}
rulerDrawable.draw(canvas);
int shadowColor = isNight == true ? mapActivity.getResources().getColor(R.color.widgettext_shadow_night) : Color.WHITE;
cacheRulerText.draw(canvas, bounds.left + (bounds.width() - cacheRulerTextLen) / 2, bounds.bottom - 8 * scaleCoefficient,
rulerTextPaint, shadowColor);
}
isNightRemembered = isNight;
}
}

View file

@ -1,55 +0,0 @@
package net.osmand.plus.views.controls;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
public class SmallMapMenuControls extends MapControls {
private Button backToMenuButton;
public SmallMapMenuControls(MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) {
super(mapActivity, showUIHandler, scaleCoefficient);
}
@Override
public void showControls(FrameLayout parent) {
backToMenuButton = addButton(parent, R.string.backToMenu, R.drawable.map_btn_menu);
mapActivity.accessibleContent.add(backToMenuButton);
backToMenuButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
notifyClicked();
if(mapActivity.getMyApplication().getSettings().USE_DASHBOARD_INSTEAD_OF_DRAWER.get()) {
mapActivity.getDashboard().setDashboardVisibility(true);
} else {
mapActivity.getMapActions().onDrawerBack();
mapActivity.getMapActions().toggleDrawer();
}
}
});
}
@Override
public void hideControls(FrameLayout layout) {
removeButton(layout, backToMenuButton);
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) {
}
public int getWidth() {
if (width == 0) {
Drawable buttonDrawable = mapActivity.getResources().getDrawable(R.drawable.map_btn_menu);
width = buttonDrawable.getMinimumWidth();
}
return width ;
}
}

View file

@ -1,72 +0,0 @@
package net.osmand.plus.views.mapwidgets;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapTileView;
public class AppearanceWidgetsFactory {
public static AppearanceWidgetsFactory INSTANCE = new AppearanceWidgetsFactory();
public static boolean POSITION_ON_THE_MAP = false;
public void registerAppearanceWidgets(final MapActivity map, final MapInfoLayer mapInfoLayer,
final MapWidgetRegistry mapInfoControls) {
final OsmandMapTileView view = map.getMapView();
// final MapWidgetRegistry.MapWidgetRegInfo displayViewDirections = mapInfoControls.registerAppearanceWidget(R.drawable.widget_viewing_direction, R.string.map_widget_view_direction,
// "viewDirection", view.getSettings().SHOW_VIEW_ANGLE);
// displayViewDirections.setStateChangeListener(new Runnable() {
// @Override
// public void run() {
// view.getSettings().SHOW_VIEW_ANGLE.set(!view.getSettings().SHOW_VIEW_ANGLE.get());
// map.getMapViewTrackingUtilities().updateSettings();
// }
// });
final MapWidgetRegistry.MapWidgetRegInfo showRuler = mapInfoControls.registerAppearanceWidget(0, 0, /*R.drawable.widget_ruler, R.drawable.widget_ruler, */R.string.map_widget_show_ruler,
"showRuler", view.getSettings().SHOW_RULER);
showRuler.setStateChangeListener(new Runnable() {
@Override
public void run() {
view.getSettings().SHOW_RULER.set(!view.getSettings().SHOW_RULER.get());
view.refreshMap();
}
});
final MapWidgetRegistry.MapWidgetRegInfo showDestinationArrow = mapInfoControls.registerAppearanceWidget(0, 0, /*R.drawable.widget_show_destination_arrow, R.drawable.widget_show_destination_arrow, */R.string.map_widget_show_destination_arrow,
"show_destination_arrow", view.getSettings().SHOW_DESTINATION_ARROW);
showDestinationArrow.setStateChangeListener(new Runnable() {
@Override
public void run() {
view.getSettings().SHOW_DESTINATION_ARROW.set(!view.getSettings().SHOW_DESTINATION_ARROW.get());
mapInfoLayer.recreateControls();
}
});
final MapWidgetRegistry.MapWidgetRegInfo transparent = mapInfoControls.registerAppearanceWidget(0, 0, /*R.drawable.widget_transparent_skin, R.drawable.widget_transparent_skin, */R.string.map_widget_transparent,
"transparent", view.getSettings().TRANSPARENT_MAP_THEME);
transparent.setStateChangeListener(new Runnable() {
@Override
public void run() {
view.getSettings().TRANSPARENT_MAP_THEME.set(!view.getSettings().TRANSPARENT_MAP_THEME.get());
mapInfoLayer.recreateControls();
}
});
final MapWidgetRegistry.MapWidgetRegInfo centerPosition = mapInfoControls.registerAppearanceWidget(0, 0, /*R.drawable.widget_position_marker, R.drawable.widget_position_marker,*/
R.string.always_center_position_on_map,
"centerPosition", view.getSettings().CENTER_POSITION_ON_MAP);
centerPosition.setStateChangeListener(new Runnable() {
@Override
public void run() {
view.getSettings().CENTER_POSITION_ON_MAP.set(!view.getSettings().CENTER_POSITION_ON_MAP.get());
map.updateApplicationModeSettings();
view.refreshMap(true);
mapInfoLayer.recreateControls();
}
});
}
}

View file

@ -1,107 +0,0 @@
package net.osmand.plus.views.mapwidgets;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.ShadowText;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.view.View;
public abstract class BaseMapWidget extends View implements UpdateableWidget {
int width = 0;
int height = 0;
Rect padding = new Rect();
int shadowColor = Color.WHITE;
private String contentTitle;
public BaseMapWidget(Context ctx) {
super(ctx);
}
@Override
public void setBackgroundDrawable(Drawable d) {
d.getPadding(padding);
super.setBackgroundDrawable(d);
}
@Override
public void setContentDescription(CharSequence text) {
if (contentTitle != null)
super.setContentDescription(contentTitle + " " + text); //$NON-NLS-1$
else super.setContentDescription(text);
}
public void setContentTitle(String text) {
contentTitle = text;
super.setContentDescription(text);
}
public void setWDimensions(int w, int h){
setMeasuredDimension(w + padding.left + padding.right, h + padding.top + padding.bottom);
}
@Override
protected final void onLayout(boolean changed, int left, int top, int right, int bottom) {
onWLayout(right - left - padding.left - padding.right, bottom - top - padding.bottom - padding.top);
}
public int getWHeight(){
return getBottom() - getTop() - padding.top - padding.bottom;
}
public int getWWidth(){
return getRight() - getLeft() - padding.left - padding.right;
}
// To override
protected void onWLayout(int w, int h) {
}
protected void drawShadowText(Canvas cv, String text, float centerX, float centerY, Paint textPaint) {
ShadowText.draw(text, cv, centerX, centerY, textPaint, shadowColor);
}
public void setShadowColor(int shadowColor) {
this.shadowColor = shadowColor;
}
public int getShadowColor() {
return shadowColor;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.translate(padding.left, padding.top);
canvas.clipRect(0, 0, getWWidth(),getWHeight());
}
@Override
public boolean updateInfo(DrawSettings drawSettings) { return false; }
protected boolean updateVisibility(boolean visible) {
if (visible != (getVisibility() == View.VISIBLE)) {
if (visible) {
setVisibility(View.VISIBLE);
} else {
setVisibility(View.GONE);
}
requestLayout();
invalidate();
return true;
}
return false;
}
public OsmandApplication getClientContext(){
return (OsmandApplication) getContext().getApplicationContext();
}
}

View file

@ -1,12 +0,0 @@
package net.osmand.plus.views.mapwidgets;
import android.content.Context;
import android.widget.ImageView;
public abstract class ImageViewWidget extends ImageView implements UpdateableWidget {
public ImageViewWidget(Context context) {
super(context);
}
}

View file

@ -3,6 +3,7 @@ package net.osmand.plus.views.mapwidgets;
import net.osmand.Location;
import net.osmand.access.AccessibleToast;
import net.osmand.binary.RouteDataObject;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.NavigationService;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmAndLocationProvider;
@ -13,27 +14,26 @@ import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.actions.StartGPSStatus;
import net.osmand.plus.helpers.WaypointDialogHelper;
import net.osmand.plus.helpers.WaypointHelper;
import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.monitoring.ValueHolder;
import net.osmand.plus.routing.RouteDirectionInfo;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.MonitoringInfoControl;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.ShadowText;
import net.osmand.plus.views.controls.MapRouteInfoControl;
import net.osmand.plus.views.mapwidgets.NextTurnInfoWidget.TurnDrawable;
import net.osmand.router.TurnType;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.text.TextPaint;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
@ -47,14 +47,8 @@ import android.widget.Toast;
public class MapInfoWidgetsFactory {
private float scaleCoefficient;
public MapInfoWidgetsFactory(float scaleCoefficient){
this.scaleCoefficient = scaleCoefficient;
}
public TextInfoWidget createAltitudeControl(final MapActivity map, Paint paintText, Paint paintSubText) {
final TextInfoWidget altitudeControl = new TextInfoWidget(map, 0, paintText, paintSubText) {
public TextInfoWidget createAltitudeControl(final MapActivity map) {
final TextInfoWidget altitudeControl = new TextInfoWidget(map) {
private int cachedAlt = 0;
@Override
@ -87,10 +81,10 @@ public class MapInfoWidgetsFactory {
return altitudeControl;
}
public TextInfoWidget createGPSInfoControl(final MapActivity map, Paint paintText, Paint paintSubText) {
public TextInfoWidget createGPSInfoControl(final MapActivity map) {
final OsmandApplication app = map.getMyApplication();
final OsmAndLocationProvider loc = app.getLocationProvider();
final TextInfoWidget gpsInfoControl = new TextInfoWidget(map, 3, paintText, paintSubText) {
final TextInfoWidget gpsInfoControl = new TextInfoWidget(map) {
private int u = -1;
private int f = -1;
@ -136,7 +130,7 @@ public class MapInfoWidgetsFactory {
dlg.show();
} else {
final MonitoringInfoControl.ValueHolder<Integer> vs = new MonitoringInfoControl.ValueHolder<Integer>();
final ValueHolder<Integer> vs = new ValueHolder<Integer>();
vs.value = app.getSettings().SERVICE_OFF_INTERVAL.get();
final AlertDialog[] dlgshow = new AlertDialog[1];
Builder dlg = new AlertDialog.Builder(map);
@ -178,46 +172,6 @@ public class MapInfoWidgetsFactory {
public ImageViewWidget createBackToLocation(final MapActivity map){
final Drawable backToLoc = map.getResources().getDrawable(R.drawable.back_to_loc);
final Drawable backToLocWhite = map.getResources().getDrawable(R.drawable.back_to_loc_white);
final Drawable backToLocDisabled = map.getResources().getDrawable(R.drawable.la_backtoloc_disabled);
final Drawable backToLocDisabledWhite = map.getResources().getDrawable(R.drawable.la_backtoloc_disabled_white);
final Drawable backToLocTracked = map.getResources().getDrawable(R.drawable.back_to_loc_tracked);
final Drawable backToLocTrackedWhite = map.getResources().getDrawable(R.drawable.back_to_loc_tracked_white);
ImageViewWidget backToLocation = new ImageViewWidget(map) {
Drawable lastDrawable = null;
@Override
public boolean updateInfo(DrawSettings drawSettings) {
boolean nightMode = drawSettings == null ? false : drawSettings.isNightMode();
boolean enabled = map.getMyApplication().getLocationProvider().getLastKnownLocation() != null;
boolean tracked = map.getMapViewTrackingUtilities().isMapLinkedToLocation();
Drawable d;
if(!enabled) {
d = nightMode ? backToLocDisabledWhite : backToLocDisabled;
} else if(tracked) {
d = nightMode ? backToLocTrackedWhite : backToLocTracked;
} else {
d = nightMode ? backToLocWhite : backToLoc;
}
if(d != lastDrawable) {
lastDrawable = d;
setImageDrawable(d);
}
return true;
}
};
backToLocation.setPadding((int) (5 * scaleCoefficient), 0, (int) (5 * scaleCoefficient), 0);
backToLocation.setImageDrawable(map.getResources().getDrawable(R.drawable.back_to_loc));
backToLocation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
map.getMapViewTrackingUtilities().backToLocationImpl();
}
});
return backToLocation;
}
private static boolean isScreenLocked = false;
private Drawable lockEnabled;
@ -230,21 +184,22 @@ public class MapInfoWidgetsFactory {
final Drawable lockDisabledWhite = view.getResources().getDrawable(R.drawable.lock_disabled_white);
lockDisabled = lockDisabledNormal;
lockEnabled = lockEnabledNormal;
final ImageViewWidget lockView = new ImageViewWidget(view.getContext()) {
private boolean nightMode;
@Override
public boolean updateInfo(DrawSettings drawSettings) {
boolean nightMode = drawSettings == null ? false : drawSettings.isNightMode();
if(nightMode != this.nightMode) {
this.nightMode = nightMode;
lockDisabled = drawSettings.isNightMode() ? lockDisabledWhite : lockDisabledNormal;
lockEnabled = drawSettings.isNightMode() ? lockEnabledWhite : lockEnabledNormal;
setImageDrawable(isScreenLocked ? lockEnabled : lockDisabled);
return true;
}
return false;
}
};
final ImageView lockView = null;
// final ImageViewWidget lockView = new ImageViewWidget(view.getContext()) {
// private boolean nightMode;
// @Override
// public boolean updateInfo(DrawSettings drawSettings) {
// boolean nightMode = drawSettings == null ? false : drawSettings.isNightMode();
// if(nightMode != this.nightMode) {
// this.nightMode = nightMode;
// lockDisabled = drawSettings.isNightMode() ? lockDisabledWhite : lockDisabledNormal;
// lockEnabled = drawSettings.isNightMode() ? lockEnabledWhite : lockEnabledNormal;
// setImageDrawable(isScreenLocked ? lockEnabled : lockDisabled);
// return true;
// }
// return false;
// }
// };
if (isScreenLocked) {
map.getMapViewTrackingUtilities().backToLocationImpl();
@ -279,16 +234,17 @@ public class MapInfoWidgetsFactory {
private void blinkIcon() {
lockView.setBackgroundDrawable(lockDisabled);
view.getView().postDelayed(new Runnable() {
@Override
public void run() {
lockView.setBackgroundDrawable(lockEnabled);
}
}, 300);
// TODO!
// map.postDelayed(new Runnable() {
// @Override
// public void run() {
// lockView.setBackgroundDrawable(lockEnabled);
// }
// }, 300);
}
});
final FrameLayout parent = (FrameLayout) view.getParent();
final FrameLayout parent = null; // TODO
lockView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -306,171 +262,167 @@ public class MapInfoWidgetsFactory {
}
});
if(isScreenLocked){
map.addLockView(transparentLockView);
// TODO
// map.addLockView(transparentLockView);
}
return lockView;
}
public ImageViewWidget createCompassView(final MapActivity map){
final OsmandMapTileView view = map.getMapView();
final OsmandApplication app = map.getMyApplication();
final Drawable compassNiu = map.getResources().getDrawable(R.drawable.map_compass_niu);
final Drawable compassNiuWhite = map.getResources().getDrawable(R.drawable.map_compass_niu_white);
final Drawable compassBearing = map.getResources().getDrawable(R.drawable.map_compass_bearing);
final Drawable compassBearingWhite = map.getResources().getDrawable(R.drawable.map_compass_bearing_white);
final Drawable compass = map.getResources().getDrawable(R.drawable.map_compass);
final Drawable compassWhite = map.getResources().getDrawable(R.drawable.map_compass_white);
final int mw = (int) compass.getMinimumWidth() ;
final int mh = (int) compass.getMinimumHeight() ;
ImageViewWidget compassView = new ImageViewWidget(map) {
private float cachedRotate = 0;
private int cachedRotateMap = 0;
private boolean nm;
@Override
protected void onDraw(Canvas canvas) {
canvas.save();
canvas.rotate(view.getRotate(), mw / 2, mh / 2);
getDrawable().draw(canvas);
canvas.restore();
}
@Override
public boolean updateInfo(DrawSettings drawSettings) {
boolean nightMode = drawSettings != null && drawSettings.isNightMode();
if(nightMode != this.nm) {
this.nm = nightMode;
if (app.getSettings().ROTATE_MAP.get() == OsmandSettings.ROTATE_MAP_NONE) {
setImageDrawable(nightMode ? compassNiuWhite : compassNiu);
} else if (app.getSettings().ROTATE_MAP.get() == OsmandSettings.ROTATE_MAP_BEARING) {
setImageDrawable(nightMode ? compassBearingWhite : compassBearing);
} else {
setImageDrawable(nightMode ? compassWhite : compass);
}
return true;
}
if(view.getRotate() != cachedRotate) {
cachedRotate = view.getRotate();
invalidate();
return true;
}
if(app.getSettings().ROTATE_MAP.get() != cachedRotateMap) {
cachedRotateMap = app.getSettings().ROTATE_MAP.get();
if (app.getSettings().ROTATE_MAP.get() == OsmandSettings.ROTATE_MAP_NONE) {
setImageDrawable(drawSettings.isNightMode() ? compassNiuWhite : compassNiu);
} else if (app.getSettings().ROTATE_MAP.get() == OsmandSettings.ROTATE_MAP_BEARING) {
setImageDrawable(drawSettings.isNightMode() ? compassBearingWhite : compassBearing);
} else {
setImageDrawable(drawSettings.isNightMode() ? compassWhite : compass);
}
return true;
}
return false;
}
};
compassView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
map.getMapViewTrackingUtilities().switchRotateMapMode();
}
});
if (app.getSettings().ROTATE_MAP.get() == OsmandSettings.ROTATE_MAP_NONE) {
compassView.setImageDrawable(compassNiu);
} else if (app.getSettings().ROTATE_MAP.get() == OsmandSettings.ROTATE_MAP_BEARING) {
compassView.setImageDrawable(compassBearing);
} else {
compassView.setImageDrawable(compass);
}
return compassView;
}
public TopTextView createStreetView(OsmandApplication app, MapActivity map, Paint paintText){
return new TopTextView(app, map, paintText);
}
public class TopTextView extends TextView implements UpdateableWidget {
public static class TopTextView {
private final RoutingHelper routingHelper;
private final MapActivity map;
private int shadowColor = Color.WHITE;
private View topBar;
private TextView addressText;
private OsmAndLocationProvider locationProvider;
private Paint paintText;
private WaypointHelper waypointHelper;
private OsmandSettings settings;
private View waypointInfoBar;
private LocationPointWrapper lastPoint;
private TurnDrawable turnDrawable;
public TopTextView(OsmandApplication app, MapActivity map, Paint paintText) {
super(map);
this.paintText = paintText;
public TopTextView(OsmandApplication app, MapActivity map) {
topBar = map.findViewById(R.id.map_top_bar);
addressText = (TextView) map.findViewById(R.id.map_address_text);
waypointInfoBar = map.findViewById(R.id.waypoint_info_bar);
this.routingHelper = app.getRoutingHelper();
locationProvider = app.getLocationProvider();
this.map = map;
getPaint().setTextAlign(Align.CENTER);
setTextColor(Color.BLACK);
settings = app.getSettings();
waypointHelper = app.getWaypointHelper();
updateVisibility(false);
turnDrawable = new NextTurnInfoWidget.TurnDrawable(map);
}
public boolean updateVisibility(boolean visible) {
return updateVisibility(topBar, visible);
}
public boolean updateVisibility(View v, boolean visible) {
if (visible != (v.getVisibility() == View.VISIBLE)) {
if (visible) {
v.setVisibility(View.VISIBLE);
} else {
v.setVisibility(View.GONE);
}
v.invalidate();
return true;
}
return false;
}
public void updateTextColor(int textColor, int textShadowColor, boolean bold, int rad) {
updateTextColor(addressText, textColor, textShadowColor, bold, rad);
updateTextColor((TextView) waypointInfoBar.findViewById(R.id.waypoint_text),
textColor, textShadowColor, bold, rad);
}
private void updateTextColor(TextView tv, int textColor, int textShadowColor, boolean textBold, int rad) {
tv.setTextColor(textColor);
tv.setShadowLayer(rad, 0, 0, textShadowColor);
tv.setTypeface(Typeface.DEFAULT, textBold ? Typeface.BOLD : Typeface.NORMAL);
}
@Override
protected void onDraw(Canvas canvas) {
getPaint().setColor(paintText.getColor());
getPaint().setFakeBoldText(paintText.isFakeBoldText());
ShadowText.draw(getText().toString(), canvas, getWidth() / 2, getHeight() - 4 * scaleCoefficient,
getPaint(), shadowColor);
}
public void setShadowColor(int shadowColor) {
this.shadowColor = shadowColor;
}
@Override
public boolean updateInfo(DrawSettings d) {
String text = null;
TurnType[] type = new TurnType[1];
boolean showNextTurn = false;
if (routingHelper != null && routingHelper.isRouteCalculated()) {
if (routingHelper.isFollowingMode()) {
text = routingHelper.getCurrentName();
text = routingHelper.getCurrentName(type);
} else {
int di = MapRouteInfoControl.getDirectionInfo();
if (di >= 0 && MapRouteInfoControl.isControlVisible() &&
di < routingHelper.getRouteDirections().size()) {
showNextTurn = true;
RouteDirectionInfo next = routingHelper.getRouteDirections().get(di);
text = "\u2566 " + RoutingHelper.formatStreetName(next.getStreetName(), next.getRef(), next.getDestinationName());
type[0] = next.getTurnType();
text = RoutingHelper.formatStreetName(next.getStreetName(), next.getRef(), next.getDestinationName());
// if(next.distance > 0) {
// text += " " + OsmAndFormatter.getFormattedDistance(next.distance, map.getMyApplication());
// }
}
}
} else if(map.getMapViewTrackingUtilities().isMapLinkedToLocation()) {
} else if(settings.getApplicationMode() != ApplicationMode.DEFAULT &&
map.getMapViewTrackingUtilities().isMapLinkedToLocation()) {
RouteDataObject rt = locationProvider.getLastKnownRouteSegment();
if(rt != null) {
text = RoutingHelper.formatStreetName(rt.getName(), rt.getRef(), rt.getDestinationName());
}
}
if(text == null) {
text = "";
}
if (!text.equals(getText().toString())) {
TextPaint pp = new TextPaint(getPaint());
if (!text.equals("")) {
pp.setTextSize(20 * scaleCoefficient);
float ts = pp.measureText(text);
int wth = getWidth();
while (ts > wth && pp.getTextSize() > (16 * scaleCoefficient)) {
pp.setTextSize(pp.getTextSize() - 1);
ts = pp.measureText(text);
}
boolean dots = false;
while (ts > wth) {
dots = true;
ts = pp.measureText(text);
text = text.substring(0, text.length() - 2);
}
if (dots) {
text += "..";
}
setTextSize(TypedValue.COMPLEX_UNIT_PX, pp.getTextSize());
setContentDescription(text);
} else {
setTextSize(TypedValue.COMPLEX_UNIT_PX, 7);
setContentDescription(getResources().getString(R.string.map_widget_top_text));
if(!showNextTurn && updateWaypoint()) {
updateVisibility(true);
updateVisibility(addressText, false);
} else if(text == null) {
updateVisibility(false);
} else {
updateVisibility(true);
updateVisibility(waypointInfoBar, false);
updateVisibility(addressText, true);
boolean update = turnDrawable.setTurnType(type[0]);
int h = addressText.getHeight() / 4 * 3;
if (h != turnDrawable.getBounds().bottom) {
turnDrawable.setBounds(0, 0, h, h);
}
if (update) {
if (type[0] != null) {
addressText.setCompoundDrawables(turnDrawable, null, null, null);
} else {
addressText.setCompoundDrawables(null, null, null, null);
}
}
if (!text.equals(addressText.getText().toString())) {
if (!text.equals("")) {
topBar.setContentDescription(text);
} else {
topBar.setContentDescription(map.getResources().getString(R.string.map_widget_top_text));
}
addressText.setText(text);
return true;
}
setText(text);
invalidate();
return true;
}
return false;
}
public boolean updateWaypoint() {
lastPoint = waypointHelper.getMostImportantLocationPoint(null);
if (lastPoint == null) {
topBar.setOnClickListener(null);
updateVisibility(waypointInfoBar, false);
return false;
} else {
updateVisibility(addressText, false);
boolean updated = updateVisibility(waypointInfoBar, true);
// pass top bar to make it clickable
WaypointDialogHelper.updatePointInfoView(map.getMyApplication(), map, topBar,
lastPoint, null);
if (updated) {
ImageView all = (ImageView) waypointInfoBar.findViewById(R.id.waypoint_more);
View btnN = waypointInfoBar.findViewById(R.id.waypoint_close);
all.setImageDrawable(map.getMyApplication().getIconsCache().
getContentIcon(R.drawable.ic_overflow_menu_light));
all.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
map.getMapActions().showWaypointsDialog(false);
}
});
btnN.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
waypointHelper.removeVisibleLocationPoint(lastPoint);
map.refreshMap();
}
});
}
return true;
}
}
public void setBackgroundResource(int boxTop) {
topBar.setBackgroundResource(boxTop);
}
}
}

View file

@ -1,7 +1,6 @@
package net.osmand.plus.views.mapwidgets;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
@ -9,44 +8,23 @@ import java.util.Set;
import java.util.TreeSet;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.OsmandMapTileView;
import android.view.View;
import android.view.ViewGroup;
import android.content.Context;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
public class MapWidgetRegistry {
public static final int LEFT_CONTROL = -1;
public static final int RIGHT_CONTROL = 1;
public static final int MAIN_CONTROL = 0;
private Set<MapWidgetRegInfo> appearanceWidgets = new LinkedHashSet<MapWidgetRegistry.MapWidgetRegInfo>();
private Set<MapWidgetRegInfo> left = new TreeSet<MapWidgetRegistry.MapWidgetRegInfo>();
private Set<MapWidgetRegInfo> right = new TreeSet<MapWidgetRegistry.MapWidgetRegInfo>();
private Set<MapWidgetRegInfo> top = new TreeSet<MapWidgetRegistry.MapWidgetRegInfo>(new Comparator<MapWidgetRegInfo>() {
@Override
public int compare(MapWidgetRegInfo object1, MapWidgetRegInfo object2) {
if (object1.position != object2.position) {
if(object1.position == LEFT_CONTROL) {
return -1;
} else if(object1.position == RIGHT_CONTROL) {
return 1;
} else {
return object2.position == LEFT_CONTROL ? 1 : -1;
}
}
int cmp = object1.priorityOrder - object2.priorityOrder;
if(object1.position == RIGHT_CONTROL) {
cmp = -cmp;
}
return cmp;
}
});
private Map<ApplicationMode, Set<String>> visibleElementsFromSettings = new LinkedHashMap<ApplicationMode, Set<String>>();
private final OsmandSettings settings;
@ -64,214 +42,157 @@ public class MapWidgetRegistry {
Collections.addAll(set, mpf.split(";"));
}
}
}
public MapWidgetRegInfo registerAppearanceWidget(int drawableDark,int drawableLight, int messageId, String key,
OsmandPreference<?> pref) {
MapWidgetRegInfo ii = new MapWidgetRegInfo();
ii.key = key;
ii.preference = pref;
ii.visibleModes = new LinkedHashSet<ApplicationMode>();
ii.visibleCollapsible = null;
ii.drawableDark = drawableDark;
ii.drawableLight = drawableLight;
ii.messageId = messageId;
this.appearanceWidgets.add(ii);
return ii;
public void populateStackControl(LinearLayout stack,
ApplicationMode mode, boolean left, boolean expanded) {
Set<MapWidgetRegInfo> s = left ? this.left : this.right;
for (MapWidgetRegInfo r : s) {
if (r.visible(mode) || r.widget.isExplicitlyVisible()) {
stack.addView(r.widget.getView());
}
}
if (expanded) {
for (MapWidgetRegInfo r : s) {
if (r.visibleCollapsed(mode) &&
!r.widget.isExplicitlyVisible()) {
stack.addView(r.widget.getView());
}
}
}
}
public boolean hasCollapsibles(ApplicationMode mode) {
for (MapWidgetRegInfo r : left) {
if (r.visibleCollapsed(mode)) {
return true;
}
}
for (MapWidgetRegInfo r : right) {
if (r.visibleCollapsed(mode)) {
return true;
}
}
return false;
}
public MapWidgetRegInfo registerTopWidget(View m, int drawableDark, int drawableLight, int messageId, String key,
int left, int priorityOrder) {
MapWidgetRegInfo ii = new MapWidgetRegInfo();
ii.key = key;
ii.visibleModes = new LinkedHashSet<ApplicationMode>();
ii.visibleCollapsible = null;
public void updateInfo(ApplicationMode mode, DrawSettings drawSettings, boolean expanded) {
update(mode, drawSettings, expanded, left);
update(mode, drawSettings, expanded, right);
}
private void update(ApplicationMode mode, DrawSettings drawSettings, boolean expanded, Set<MapWidgetRegInfo> l) {
for (MapWidgetRegInfo r : l) {
if (r.visible(mode) || (r.visibleCollapsed(mode) && expanded)) {
r.widget.updateInfo(drawSettings);
}
}
}
public MapWidgetRegInfo registerSideWidgetInternal(TextInfoWidget widget, int drawableDark,int drawableLight,
int messageId, String key, boolean left, int priorityOrder) {
MapWidgetRegInfo ii = new MapWidgetRegInfo(key, widget, drawableDark, drawableLight,
messageId, priorityOrder, left);
for (ApplicationMode ms : ApplicationMode.values(settings)) {
boolean collapse = ms.isWidgetCollapsible(key);
boolean def = ms.isWidgetVisible(key);
Set<String> set = visibleElementsFromSettings.get(ms);
if (set != null) {
if (set.contains(key)) {
def = true;
collapse = false;
} else if (set.contains("-" + key)) {
def = false;
collapse = false;
} else if (set.contains("+" + key)) {
def = false;
collapse = true;
}
}
if (def) {
ii.visibleModes.add(ms);
}
}
if (m != null)
m.setContentDescription(m.getContext().getString(messageId));
ii.drawableDark = drawableDark;
ii.drawableLight = drawableLight;
ii.messageId = messageId;
ii.m = m;
ii.priorityOrder = priorityOrder;
ii.position = left;
this.top.add(ii);
return ii;
}
public void registerSideWidget(BaseMapWidget m, int drawableDark,int drawableLight, int messageId, String key, boolean left, int priorityOrder) {
MapWidgetRegInfo ii = new MapWidgetRegInfo();
ii.key = key;
ii.visibleModes = new LinkedHashSet<ApplicationMode>();
ii.visibleCollapsible = new LinkedHashSet<ApplicationMode>();
for(ApplicationMode ms : ApplicationMode.values(settings) ) {
boolean collapse = ms.isWidgetCollapsible(key);
boolean def = ms.isWidgetVisible(key);
Set<String> set = visibleElementsFromSettings.get(ms);
if(set != null) {
if (set.contains(key)) {
def = true;
collapse = false;
} else if (set.contains("-" + key)) {
def = false;
collapse = false;
} else if(set.contains("+"+key)){
def = false;
collapse = true;
}
}
if(def){
ii.visibleModes.add(ms);
} else if(collapse) {
} else if (collapse) {
ii.visibleCollapsible.add(ms);
}
}
if (m != null)
m.setContentTitle(m.getContext().getString(messageId));
ii.drawableDark = drawableDark;
ii.drawableLight = drawableLight;
ii.messageId = messageId;
ii.m = m;
ii.priorityOrder = priorityOrder;
if (widget != null) {
widget.setContentTitle(messageId);
}
if(left) {
this.left.add(ii);
} else {
this.right.add(ii);
}
return ii;
}
private void restoreModes(Set<String> set, Set<MapWidgetRegInfo> mi, ApplicationMode mode) {
for (MapWidgetRegInfo m : mi) {
if (m.preference == null) {
if (m.visibleModes.contains(mode)) {
set.add(m.key);
} else if (m.visibleCollapsible != null && m.visibleCollapsible.contains(mode)) {
set.add("+" + m.key);
} else {
set.add("-" + m.key);
}
if (m.visibleModes.contains(mode)) {
set.add(m.key);
} else if (m.visibleCollapsible != null && m.visibleCollapsible.contains(mode)) {
set.add("+" + m.key);
} else {
set.add("-" + m.key);
}
}
}
public void changeVisibility(MapWidgetRegInfo m) {
boolean selecteable = m.selecteable();
if (selecteable) {
ApplicationMode mode = settings.APPLICATION_MODE.get();
boolean visible = m.visible(mode);
boolean collapseEnabled = m.collapseEnabled(mode);
boolean collapse = m.visibleCollapsed(mode);
if (this.visibleElementsFromSettings.get(mode) == null) {
LinkedHashSet<String> set = new LinkedHashSet<String>();
restoreModes(set, left, mode);
restoreModes(set, right, mode);
restoreModes(set, top, mode);
this.visibleElementsFromSettings.put(mode, set);
}
// clear everything
this.visibleElementsFromSettings.get(mode).remove(m.key);
this.visibleElementsFromSettings.get(mode).remove("+" + m.key);
this.visibleElementsFromSettings.get(mode).remove("-" + m.key);
m.visibleModes.remove(mode);
if (m.visibleCollapsible != null) {
m.visibleCollapsible.remove(mode);
}
if (visible || collapse) {
if (collapseEnabled && !collapse) {
m.visibleCollapsible.add(mode);
this.visibleElementsFromSettings.get(mode).add("+" + m.key);
} else {
this.visibleElementsFromSettings.get(mode).add("-" + m.key);
}
ApplicationMode mode = settings.APPLICATION_MODE.get();
boolean visible = m.visible(mode);
boolean collapse = m.visibleCollapsed(mode);
defineDefaultSettingsElement(mode);
// clear everything
this.visibleElementsFromSettings.get(mode).remove(m.key);
this.visibleElementsFromSettings.get(mode).remove("+" + m.key);
this.visibleElementsFromSettings.get(mode).remove("-" + m.key);
m.visibleModes.remove(mode);
m.visibleCollapsible.remove(mode);
if (visible || collapse) {
if (!collapse) {
m.visibleCollapsible.add(mode);
this.visibleElementsFromSettings.get(mode).add("+" + m.key);
} else {
m.visibleModes.add(mode);
this.visibleElementsFromSettings.get(mode).add("" + m.key);
this.visibleElementsFromSettings.get(mode).add("-" + m.key);
}
StringBuilder bs = new StringBuilder();
for (String ks : this.visibleElementsFromSettings.get(mode)) {
bs.append(ks).append(";");
}
settings.MAP_INFO_CONTROLS.set(bs.toString());
} else {
m.visibleModes.add(mode);
this.visibleElementsFromSettings.get(mode).add("" + m.key);
}
if(m.stateChangeListener != null) {
saveVisibleElementsToSettings(mode);
if (m.stateChangeListener != null) {
m.stateChangeListener.run();
}
}
public Set<MapWidgetRegInfo> getLeft() {
return left;
}
public Set<MapWidgetRegInfo> getRight() {
return right;
}
public Set<MapWidgetRegInfo> getTop() {
return top;
}
public Set<MapWidgetRegInfo> getAppearanceWidgets() {
return appearanceWidgets;
}
public void populateStackControl(StackWidgetView stack, OsmandMapTileView v, boolean left){
ApplicationMode appMode = settings.getApplicationMode();
Set<MapWidgetRegInfo> st = left ? this.left : this.right;
for (MapWidgetRegInfo r : st) {
if (r.visibleCollapsible != null && r.visibleCollapsible.contains(appMode)) {
stack.addCollapsedView((BaseMapWidget) r.m);
} else if (r.visibleModes.contains(appMode)) {
stack.addStackView((BaseMapWidget) r.m);
}
private void defineDefaultSettingsElement(ApplicationMode mode) {
if (this.visibleElementsFromSettings.get(mode) == null) {
LinkedHashSet<String> set = new LinkedHashSet<String>();
restoreModes(set, left, mode);
restoreModes(set, right, mode);
this.visibleElementsFromSettings.put(mode, set);
}
}
public void populateStatusBar(ViewGroup statusBar){
ApplicationMode appMode = settings.getApplicationMode();
for (MapWidgetRegInfo r : top) {
boolean main = r.position == MAIN_CONTROL;
if (r.visibleModes.contains(appMode)) {
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, main? 1 : 0);
statusBar.addView((View) r.m, params);
} else if (main) {
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1);
statusBar.addView(new TextView(((View) r.m).getContext()), params);
}
private void saveVisibleElementsToSettings(ApplicationMode mode) {
StringBuilder bs = new StringBuilder();
for (String ks : this.visibleElementsFromSettings.get(mode)) {
bs.append(ks).append(";");
}
settings.MAP_INFO_CONTROLS.set(bs.toString());
}
private void resetDefault(ApplicationMode mode, Set<MapWidgetRegInfo> set ){
for(MapWidgetRegInfo ri : set) {
if(ri.preference != null) {
ri.preference.resetToDefault();
} else {
if (ri.visibleCollapsible != null) {
ri.visibleCollapsible.remove(mode);
}
ri.visibleModes.remove(mode);
if (mode.isWidgetVisible(ri.key)) {
if (mode.isWidgetCollapsible(ri.key)) {
ri.visibleCollapsible.add(mode);
} else {
ri.visibleModes.add(mode);
}
for (MapWidgetRegInfo ri : set) {
ri.visibleCollapsible.remove(mode);
ri.visibleModes.remove(mode);
if (mode.isWidgetVisible(ri.key)) {
if (mode.isWidgetCollapsible(ri.key)) {
ri.visibleCollapsible.add(mode);
} else {
ri.visibleModes.add(mode);
}
}
}
@ -281,12 +202,51 @@ public class MapWidgetRegistry {
ApplicationMode appMode = settings.getApplicationMode();
resetDefault(appMode, left);
resetDefault(appMode, right);
resetDefault(appMode, top);
resetDefault(appMode, appearanceWidgets);
resetDefaultAppearance(appMode);
this.visibleElementsFromSettings.put(appMode, null);
settings.MAP_INFO_CONTROLS.set("");
}
private void resetDefaultAppearance(ApplicationMode appMode) {
// settings.SHOW_RULER.resetToDefault();
settings.SHOW_DESTINATION_ARROW.resetToDefault();
settings.TRANSPARENT_MAP_THEME.resetToDefault();
settings.CENTER_POSITION_ON_MAP.resetToDefault();
}
public void addControlsAppearance(final MapInfoLayer mil, ContextMenuAdapter cm, ApplicationMode mode) {
// addControlId(mil, cm, R.string.map_widget_show_ruler, settings.SHOW_RULER);
addControlId(mil, cm, R.string.map_widget_show_destination_arrow, settings.SHOW_DESTINATION_ARROW);
addControlId(mil, cm, R.string.map_widget_transparent, settings.TRANSPARENT_MAP_THEME);
addControlId(mil, cm, R.string.always_center_position_on_map, settings.CENTER_POSITION_ON_MAP);
}
private void addControlId(final MapInfoLayer mil, ContextMenuAdapter cm, int stringId, OsmandPreference<Boolean> pref) {
cm.item(stringId).selected( pref.get() ? 1 : 0)
// .icons(r.drawableDark, r.drawableLight)
.listen(new ApearanceOnContextMenuClick(pref, mil.getMapActivity())).reg();
}
class ApearanceOnContextMenuClick implements OnContextMenuClick {
private MapActivity map;
private OsmandPreference<Boolean> pref;
public ApearanceOnContextMenuClick(OsmandPreference<Boolean> pref, MapActivity map) {
this.pref = pref;
this.map = map;
}
@Override
public boolean onContextMenuClick(ArrayAdapter<?> a, int itemId, int pos, boolean isChecked) {
pref.set(!pref.get());
map.updateApplicationModeSettings();
a.notifyDataSetInvalidated();
return false;
}
};
public static boolean distChanged(int oldDist, int dist){
if(oldDist != 0 && oldDist - dist < 100 && Math.abs(((float) dist - oldDist)/oldDist) < 0.01){
return false;
@ -294,40 +254,81 @@ public class MapWidgetRegistry {
return true;
}
public void addControls(MapInfoLayer mil, ContextMenuAdapter cm, ApplicationMode mode) {
cm.item(R.string.map_widget_right).setCategory(true).layout(R.layout.drawer_list_sub_header).reg();
addControls(mil, cm, right, mode);
if(mode != ApplicationMode.DEFAULT) {
cm.item(R.string.map_widget_left).setCategory(true).layout(R.layout.drawer_list_sub_header).reg();
addControls(mil, cm, left, mode);
}
cm.item(R.string.map_widget_appearance_rem).setCategory(true).layout(R.layout.drawer_list_sub_header).reg();
addControlsAppearance(mil, cm, mode);
}
public String getText(Context ctx, final ApplicationMode mode, final MapWidgetRegInfo r) {
return (r.visibleCollapsed(mode)? " + " : " ") + ctx.getString(r.messageId);
}
public Set<MapWidgetRegInfo> getRight() {
return right;
}
public Set<MapWidgetRegInfo> getLeft() {
return left;
}
private void addControls(final MapInfoLayer mil, final ContextMenuAdapter adapter, Set<MapWidgetRegInfo> top, final ApplicationMode mode) {
for(final MapWidgetRegInfo r : top){
adapter.item(r.messageId).selected(r.visibleCollapsed(mode) || r.visible(mode) ? 1 : 0)
.icons(r.drawableDark, r.drawableLight).listen(new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> a, int itemId, int pos, boolean isChecked) {
changeVisibility(r);
mil.recreateControls();
adapter.setItemName(pos, getText(mil.getMapActivity(), mode, r));
adapter.setSelection(pos, r.visibleCollapsed(mode) || r.visible(mode) ? 1 : 0);
a.notifyDataSetInvalidated();
return false;
}
}).reg();
adapter.setItemName(adapter.length() - 1, getText(mil.getMapActivity(), mode, r));
}
}
public static class MapWidgetRegInfo implements Comparable<MapWidgetRegInfo> {
public View m;
public int drawableDark;
public int drawableLight;
public int messageId;
private String key;
private int position;
private Set<ApplicationMode> visibleModes;
private Set<ApplicationMode> visibleCollapsible;
private OsmandPreference<?> preference = null;
public final TextInfoWidget widget;
public final int drawableDark;
public final int drawableLight;
public final int messageId;
public final String key;
public final boolean left;
public final int priorityOrder;
private final Set<ApplicationMode> visibleCollapsible = new LinkedHashSet<ApplicationMode>();
private final Set<ApplicationMode> visibleModes = new LinkedHashSet<ApplicationMode>();
private Runnable stateChangeListener = null;
public int priorityOrder;
public MapWidgetRegInfo(String key, TextInfoWidget widget, int drawableDark, int drawableLight, int messageId, int priorityOrder,
boolean left) {
this.key = key;
this.widget = widget;
this.drawableDark = drawableDark;
this.drawableLight = drawableLight;
this.messageId = messageId;
this.priorityOrder = priorityOrder;
this.left = left;
}
public boolean visibleCollapsed(ApplicationMode mode){
return preference == null && visibleCollapsible != null && visibleCollapsible.contains(mode);
}
public boolean collapseEnabled(ApplicationMode mode){
return visibleCollapsible != null && preference == null;
}
public boolean selecteable(){
return preference == null || (preference.get() instanceof Boolean);
return visibleCollapsible.contains(mode);
}
public boolean visible(ApplicationMode mode){
if(preference != null) {
Object value = preference.getModeValue(mode);
if(value instanceof Boolean) {
return (Boolean) value;
}
return true;
}
return visibleModes.contains(mode);
}
@ -336,10 +337,6 @@ public class MapWidgetRegistry {
return this;
}
public void setPreference(CommonPreference<Boolean> blPreference) {
this.preference = blPreference;
}
public void setStateChangeListener(Runnable stateChangeListener) {
this.stateChangeListener = stateChangeListener;
@ -373,4 +370,5 @@ public class MapWidgetRegistry {
return priorityOrder - another.priorityOrder;
}
}
}

View file

@ -3,152 +3,189 @@ package net.osmand.plus.views.mapwidgets;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.TurnPathHelper;
import net.osmand.router.TurnType;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
public class NextTurnInfoWidget extends BaseMapWidget {
public class NextTurnInfoWidget extends TextInfoWidget {
private float scaleCoefficient = MapInfoLayer.scaleCoefficient;
private float width;
private float height ;
private static final float miniCoeff = 2.5f;
protected double deviatedPath = 0;
protected Path pathForTurn = new Path();
protected TurnType turnType = null;
protected String exitOut = null;
protected int nextTurnDirection = 0;
protected Paint textPaint;
protected Paint subtextPaint;
private Paint paintBlack;
private Paint paintRouteDirection;
protected boolean deviatedFromRoute;
protected int turnImminent;
protected boolean horisontalMini;
public NextTurnInfoWidget(Context ctx, Paint textPaint, Paint subtextPaint, boolean horisontalMini) {
super(ctx);
this.textPaint = textPaint;
this.subtextPaint = subtextPaint;
paintBlack = new Paint();
paintBlack.setStyle(Style.STROKE);
paintBlack.setColor(Color.BLACK);
paintBlack.setAntiAlias(true);
paintBlack.setStrokeWidth(2.5f);
paintRouteDirection = new Paint();
paintRouteDirection.setStyle(Style.FILL);
paintRouteDirection.setColor(getResources().getColor(R.color.nav_arrow));
paintRouteDirection.setAntiAlias(true);
pathTransform = new Matrix();
updateHorisontalMini(horisontalMini);
}
protected void updateHorisontalMini(boolean horisontalMini) {
this.horisontalMini = horisontalMini;
if (horisontalMini) {
pathTransform.postScale(scaleCoefficient / miniCoeff, scaleCoefficient / miniCoeff);
width = 72 * scaleCoefficient / miniCoeff;
height = 72 * scaleCoefficient / miniCoeff;
} else {
pathTransform.postScale(scaleCoefficient, scaleCoefficient);
width = 72 * scaleCoefficient;
height = 72 * scaleCoefficient;
}
requestLayout();
}
protected int deviatedPath = 0;
protected int nextTurnDistance = 0;
private TurnDrawable turnDrawable;
private OsmandApplication app;
protected Matrix pathTransform = new Matrix();
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int h = 0;
int w = 0;
if (!horisontalMini) {
h = (int) (8 * scaleCoefficient + Math.max(textPaint.getTextSize(), subtextPaint.getTextSize()));
public NextTurnInfoWidget(Activity activity, OsmandApplication app, boolean horisontalMini) {
super(activity);
this.app = app;
this.horisontalMini = horisontalMini;
turnDrawable = new TurnDrawable(activity);
if(horisontalMini) {
setImageDrawable(turnDrawable, false);
setTopImageDrawable(null, true);
} else {
h = (int) (7 * scaleCoefficient);
w = (int) textPaint.measureText(OsmAndFormatter.getFormattedDistance(nextTurnDirection, getClientContext()));
setImageDrawable(null, false);
setTopImageDrawable(turnDrawable, true);
}
}
public TurnType getTurnType() {
return turnDrawable.turnType;
}
public void setTurnType(TurnType turnType) {
updateVisibility(turnType != null);
if (turnDrawable.setTurnType(turnType)) {
if(horisontalMini) {
setImageDrawable(turnDrawable, false);
} else {
setTopImageDrawable(turnDrawable, true);
}
}
}
public void setTurnImminent(int turnImminent, boolean deviatedFromRoute) {
if(turnDrawable.turnImminent != turnImminent || turnDrawable.deviatedFromRoute != deviatedFromRoute) {
turnDrawable.setTurnImminent(turnImminent, deviatedFromRoute);
updateDistance();
}
}
public void setDeviatePath(int deviatePath) {
if (RouteInfoWidgetsFactory.distChanged(deviatePath, this.deviatedPath)) {
this.deviatedPath = deviatePath;
updateDistance();
}
setWDimensions((int) width + w, (int) height + h);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (pathForTurn != null) {
//if user deviates from route that we should draw grey arrow
if (deviatedFromRoute){
paintRouteDirection.setColor(getResources().getColor(R.color.nav_arrow_distant));
} else if (turnImminent > 0) {
paintRouteDirection.setColor(getResources().getColor(R.color.nav_arrow));
} else if (turnImminent == 0) {
paintRouteDirection.setColor(getResources().getColor(R.color.nav_arrow_imminent));
} else {
paintRouteDirection.setColor(getResources().getColor(R.color.nav_arrow_distant));
}
// small indent
canvas.translate(0, 3 * scaleCoefficient);
canvas.drawPath(pathForTurn, paintRouteDirection);
canvas.drawPath(pathForTurn, paintBlack);
if (exitOut != null && !horisontalMini && !deviatedFromRoute) {
drawShadowText(canvas, exitOut, width / 2 - 7 * scaleCoefficient,
height / 2 + textPaint.getTextSize() / 2 - 3 * scaleCoefficient, textPaint);
}
String text = OsmAndFormatter.getFormattedDistance(nextTurnDirection, getClientContext());
String subtext = null;
public void setTurnDistance(int nextTurnDistance) {
if (RouteInfoWidgetsFactory.distChanged(nextTurnDistance, this.nextTurnDistance)) {
this.nextTurnDistance = nextTurnDistance;
updateDistance();
}
}
if (deviatedFromRoute) {
text = OsmAndFormatter.getFormattedDistance((float) deviatedPath, (OsmandApplication)getContext().getApplicationContext());
}
int ls = text.lastIndexOf(' ');
float st = 0;
if (ls != -1) {
subtext = text.substring(ls + 1);
text = text.substring(0, ls);
st = textPaint.measureText(subtext);
}
float mt = textPaint.measureText(text);
if (!horisontalMini) {
float startX = Math.max((getWWidth() - st - mt) / 2, 2 * scaleCoefficient);
drawShadowText(canvas, text, startX, getWHeight() - 5 * scaleCoefficient, textPaint);
if (subtext != null) {
drawShadowText(canvas, subtext, startX + 2 * scaleCoefficient + mt, getWHeight() - 5 * scaleCoefficient, subtextPaint);
}
} else {
drawShadowText(canvas, text, 72 * scaleCoefficient / miniCoeff + 2 * scaleCoefficient,
height / 2 + 7 * scaleCoefficient, textPaint);
if (subtext != null) {
drawShadowText(canvas, subtext, 72 * scaleCoefficient / miniCoeff + mt
+ 2 * scaleCoefficient, height / 2 + 7 * scaleCoefficient, subtextPaint);
}
}
private void updateDistance() {
int deviatePath = turnDrawable.deviatedFromRoute ? deviatedPath : nextTurnDistance;
String ds = OsmAndFormatter.getFormattedDistance(deviatePath, app);
int ls = ds.lastIndexOf(' ');
if (ls == -1) {
setTextNoUpdateVisibility(ds, null);
} else {
setTextNoUpdateVisibility(ds.substring(0, ls), ds.substring(ls + 1));
}
}
public void setExitOut(int exit) {
// TODO exit
// if(turnDrawable.exitOut != exit) {
// turnDrawable.e
// }
// TODO;
}
@Override
public boolean updateInfo(DrawSettings drawSettings) {
return false;
}
public static class TurnDrawable extends Drawable {
protected Paint paintBlack;
protected Paint paintRouteDirection;
protected Path pathForTurn = new Path();
protected TurnType turnType = null;
protected int turnImminent;
protected boolean deviatedFromRoute;
private Context ctx;
public TurnDrawable(Context ctx) {
this.ctx = ctx;
paintBlack = new Paint();
paintBlack.setStyle(Style.STROKE);
paintBlack.setColor(Color.BLACK);
paintBlack.setAntiAlias(true);
paintBlack.setStrokeWidth(2.5f);
paintRouteDirection = new Paint();
paintRouteDirection.setStyle(Style.FILL);
paintRouteDirection.setColor(ctx.getResources().getColor(R.color.nav_arrow));
paintRouteDirection.setAntiAlias(true);
}
@Override
protected void onBoundsChange(Rect bounds) {
if (pathForTurn != null) {
Matrix m = new Matrix();
m.setScale(bounds.width() / 72f, bounds.height() / 72f);
pathForTurn.transform(m, pathForTurn);
}
}
public void setTurnImminent(int turnImminent, boolean deviatedFromRoute) {
//if user deviates from route that we should draw grey arrow
this.turnImminent = turnImminent;
this.deviatedFromRoute = deviatedFromRoute;
if (deviatedFromRoute){
paintRouteDirection.setColor(ctx.getResources().getColor(R.color.nav_arrow_distant));
} else if (turnImminent > 0) {
paintRouteDirection.setColor(ctx.getResources().getColor(R.color.nav_arrow));
} else if (turnImminent == 0) {
paintRouteDirection.setColor(ctx.getResources().getColor(R.color.nav_arrow_imminent));
} else {
paintRouteDirection.setColor(ctx.getResources().getColor(R.color.nav_arrow_distant));
}
}
@Override
public void draw(Canvas canvas) {
/// small indent
// canvas.translate(0, 3 * scaleCoefficient);
canvas.drawPath(pathForTurn, paintRouteDirection);
canvas.drawPath(pathForTurn, paintBlack);
}
@Override
public void setAlpha(int alpha) {
paintRouteDirection.setAlpha(alpha);
}
@Override
public void setColorFilter(ColorFilter cf) {
paintRouteDirection.setColorFilter(cf);
}
@Override
public int getOpacity() {
return 0;
}
public boolean setTurnType(TurnType turnType) {
if(turnType != this.turnType) {
this.turnType = turnType;
TurnPathHelper.calcTurnPath(pathForTurn, turnType, null);
onBoundsChange(getBounds());
return true;
}
return false;
}
}
}

View file

@ -1,261 +0,0 @@
package net.osmand.plus.views.mapwidgets;
import java.util.ArrayList;
import java.util.List;
import net.osmand.plus.R;
import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
public class StackWidgetView extends ViewGroup {
List<BaseMapWidget> stackViews = new ArrayList<BaseMapWidget>();
List<BaseMapWidget> collapsedViews = new ArrayList<BaseMapWidget>();
ImageView expandView;
// by default opened
private boolean isCollapsed = false;
private boolean isCollapsible = true;
private Drawable topDrawable;
List<Drawable> cacheStackDrawables = new ArrayList<Drawable>();
private int stackDrawable;
public StackWidgetView(Context context) {
super(context);
final Bitmap arrowDown = BitmapFactory.decodeResource(context.getResources(), R.drawable.arrow_down);
final Bitmap arrowUp = BitmapFactory.decodeResource(context.getResources(), R.drawable.arrow_up);
final Paint paintImg = new Paint();
paintImg.setAntiAlias(true);
expandView = new ImageView(context) {
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int cx = (getLeft() + getRight()) / 2 - getLeft();
int t = (int) (10 * MapInfoLayer.scaleCoefficient);
if (!isCollapsed) {
canvas.drawBitmap(arrowUp, cx - arrowUp.getWidth() / 2, t , paintImg);
} else {
canvas.drawBitmap(arrowDown, cx - arrowDown.getWidth() / 2, t , paintImg);
}
}
};
expandView.setImageDrawable(context.getResources().getDrawable(R.drawable.box_expand));
expandView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
isCollapsed = !isCollapsed;
StackWidgetView.this.requestLayout();
StackWidgetView.this.invalidate();
}
});
StackWidgetView.this.addView(expandView);
}
public void setExpandImageDrawable(Drawable d) {
expandView.setImageDrawable(d);
}
public void setTopDrawable(Drawable topDrawable) {
this.topDrawable = topDrawable;
}
public void setStackDrawable(int stackDrawable) {
this.stackDrawable = stackDrawable;
this.cacheStackDrawables.clear();
}
public void updateInfo(DrawSettings drawSettings) {
for (BaseMapWidget v : stackViews) {
v.updateInfo(drawSettings);
}
// update even if collapsed to know if view becomes visible
for (BaseMapWidget v : collapsedViews) {
v.updateInfo(drawSettings);
}
}
public void addStackView(BaseMapWidget v) {
stackViews.add(v);
v.setShadowColor(shadowColor);
StackWidgetView.this.addView(v, getChildCount());
}
public void addCollapsedView(BaseMapWidget v) {
collapsedViews.add(v);
v.setShadowColor(shadowColor);
StackWidgetView.this.addView(v, getChildCount());
}
public void clearAllViews(){
stackViews.clear();
collapsedViews.clear();
while(getChildCount() > 1){
removeViewAt(1);
}
}
public List<BaseMapWidget> getStackViews() {
return stackViews;
}
public List<BaseMapWidget> getCollapsedViews() {
return collapsedViews;
}
public List<BaseMapWidget> getAllViews(){
List<BaseMapWidget> l = new ArrayList<BaseMapWidget>();
l.addAll(stackViews);
l.addAll(collapsedViews);
return l;
}
public boolean isCollapsed() {
return isCollapsed;
}
public boolean isCollapsible() {
return isCollapsible;
}
private Drawable getStackDrawable(int i){
while(i >= cacheStackDrawables.size()) {
Drawable d = getResources().getDrawable(stackDrawable);
if(Build.VERSION_CODES.FROYO <= Build.VERSION.SDK_INT) {
d = d.mutate();
}
cacheStackDrawables.add(d);
}
return cacheStackDrawables.get(i);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int w = 0;
int h = 0;
int prevBot = 0;
boolean first = true;
int cacheStack = 0;
if (stackViews != null) {
for (BaseMapWidget c : stackViews) {
cacheStack++;
if (c.getVisibility() != View.GONE) {
c.setBackgroundDrawable(first ? topDrawable : getStackDrawable(cacheStack));
first = false;
c.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
w = Math.max(w, c.getMeasuredWidth());
if (h > 0) {
h -= prevBot;
} else {
h += c.getPaddingTop();
}
h += c.getMeasuredHeight();
prevBot = c.getPaddingBottom();
}
}
isCollapsible = false;
for (BaseMapWidget c : collapsedViews) {
cacheStack++;
if (c.getVisibility() != View.GONE) {
isCollapsible = true;
if (!isCollapsed) {
c.setBackgroundDrawable(first ? topDrawable : getStackDrawable(cacheStack));
first = false;
c.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
w = Math.max(w, c.getMeasuredWidth());
h -= c.getPaddingBottom();
if (h > 0) {
h -= prevBot;
}
h += c.getMeasuredHeight();
prevBot = c.getPaddingBottom();
} else {
if (h == 0) {
// measure one of the figure if it is collapsed and no top elements
c.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
h += c.getPaddingTop();
}
}
}
}
if (isCollapsible) {
h += expandView.getDrawable().getMinimumHeight();
w = Math.max(w, expandView.getDrawable().getMinimumWidth());
}
}
setMeasuredDimension(w, h);
}
// magic constant (should be removed when image will be recropped)
private final static int MAGIC_CONSTANT_STACK = 8;
private int shadowColor;
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
int y = 0;
int cw = right - left;
for (View c : stackViews) {
if (c.getVisibility() != View.GONE) {
if (y == 0) {
y += c.getPaddingTop();
}
y -= MAGIC_CONSTANT_STACK;
c.layout(0, y, cw, y + c.getMeasuredHeight());
y += c.getMeasuredHeight();
y -= c.getPaddingBottom();
}
}
for (View c : collapsedViews) {
if (!isCollapsed) {
if (c.getVisibility() != View.GONE) {
if (y == 0) {
y += c.getPaddingTop();
}
y -= MAGIC_CONSTANT_STACK;
c.layout(0, y, cw, y + c.getMeasuredHeight());
y += c.getMeasuredHeight();
y -= c.getPaddingBottom();
}
} else {
c.layout(0, 0, 0, 0);
if(y == 0){
y += c.getPaddingTop();
}
}
}
if (isCollapsible) {
y -= MAGIC_CONSTANT_STACK;
expandView.setVisibility(VISIBLE);
int w = expandView.getDrawable().getMinimumWidth();
int h = expandView.getDrawable().getMinimumHeight();
expandView.layout((cw - w) / 2, y, (cw + w) / 2, y + h);
} else {
expandView.setVisibility(GONE);
}
}
public void setShadowColor(int shadowColor) {
this.shadowColor = shadowColor;
for(BaseMapWidget c : stackViews) {
c.setShadowColor(shadowColor);
}
for(BaseMapWidget c : collapsedViews) {
c.setShadowColor(shadowColor);
}
}
}

View file

@ -1,115 +1,159 @@
package net.osmand.plus.views.mapwidgets;
import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.R;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.app.Activity;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;
public class TextInfoWidget extends BaseMapWidget {
public class TextInfoWidget {
String text;
Paint textPaint;
String subtext;
Paint subtextPaint;
int leftMargin = 0;
private Drawable imageDrawable;
private float scaleCoefficient;
private String contentTitle;
private View view;
private ImageView imageView;
private TextView textView;
private TextView smallTextView;
private ImageView topImageView;
public TextInfoWidget(Context ctx, int leftMargin, Paint textPaint, Paint subtextPaint) {
super(ctx);
scaleCoefficient = MapInfoLayer.scaleCoefficient;
this.leftMargin = leftMargin;
this.textPaint = textPaint;
this.subtextPaint = subtextPaint;
private boolean explicitlyVisible;
public TextInfoWidget(Activity activity) {
view = activity.getLayoutInflater().inflate(R.layout.map_hud_widget, null);
topImageView = (ImageView) view.findViewById(R.id.widget_top_icon);
imageView = (ImageView) view.findViewById(R.id.widget_icon);
textView = (TextView) view.findViewById(R.id.widget_text);
smallTextView = (TextView) view.findViewById(R.id.widget_text_small);
}
public View getView() {
return view;
}
public void setImageDrawable(Drawable imageDrawable) {
this.imageDrawable = imageDrawable;
setImageDrawable(imageDrawable, false);
}
public Drawable getImageDrawable() {
return imageDrawable;
public void setImageDrawable(Drawable imageDrawable, boolean gone) {
if(imageDrawable != null) {
imageView.setImageDrawable(imageDrawable);
imageView.setVisibility(View.VISIBLE);
} else {
imageView.setVisibility(gone ? View.GONE : View.INVISIBLE);
}
imageView.invalidate();
}
@Override
protected void onWLayout(int w, int h) {
if (imageDrawable != null) {
// Unknown reason to add 3*scaleCoefficient
imageDrawable.setBounds(0, (int) (3 * scaleCoefficient), imageDrawable.getMinimumWidth(), imageDrawable.getMinimumHeight()
+ (int) (3 * scaleCoefficient));
public void setTopImageDrawable(Drawable imageDrawable, boolean gone) {
if(imageDrawable != null) {
topImageView.setImageDrawable(imageDrawable);
topImageView.setVisibility(View.VISIBLE);
} else {
topImageView.setVisibility(gone ? View.GONE : View.INVISIBLE);
}
topImageView.invalidate();
}
public void setContentDescription(CharSequence text) {
if (contentTitle != null) {
view.setContentDescription(contentTitle + " " + text); //$NON-NLS-1$
} else {
view.setContentDescription(text);
}
}
public void setContentTitle(int messageId) {
setContentTitle(view.getContext().getString(messageId));
}
public void setContentTitle(String text) {
contentTitle = text;
view.setContentDescription(text);
}
public void setText(String text, String subtext) {
this.text = text;
this.subtext = subtext;
setTextNoUpdateVisibility(text, subtext);
updateVisibility(text != null);
}
protected void setTextNoUpdateVisibility(String text, String subtext) {
if (text != null) {
if (subtext != null)
if (subtext != null) {
setContentDescription(text + " " + subtext); //$NON-NLS-1$
else setContentDescription(text);
} else {
} else {
setContentDescription(text);
}
} else if(subtext != null){
setContentDescription(subtext);
}
if(this.text != null && this.text.length() > 7) {
this.text = this.text.substring(0, 6) +"..";
// if(this.text != null && this.text.length() > 7) {
// this.text = this.text.substring(0, 6) +"..";
// }
if(text == null) {
textView.setText("");
} else {
textView.setText(text);
}
updateVisibility(text != null);
requestLayout();
invalidate();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// ignore attributes
int w = 0;
int h = 0;
if (text != null) {
if (imageDrawable != null) {
w += imageDrawable.getMinimumWidth() + 2 * scaleCoefficient;
}
w += leftMargin;
w += textPaint.measureText(text);
if (subtext != null) {
w += subtextPaint.measureText(subtext) + 2 * scaleCoefficient;
}
h = (int) (5 * scaleCoefficient + Math.max(textPaint.getTextSize(), subtextPaint.getTextSize()));
if (imageDrawable != null) {
h = Math.max(h, (int) (imageDrawable.getMinimumHeight()));
}
}
setWDimensions(w, h);
}
@Override
protected void onDraw(Canvas cv) {
super.onDraw(cv);
if (isVisible()) {
int margin = 0;
if (imageDrawable != null) {
imageDrawable.draw(cv);
margin = (int) (imageDrawable.getBounds().width() + 2 * scaleCoefficient);
}
margin += leftMargin;
drawShadowText(cv, text, margin, getWHeight() - 3 * scaleCoefficient, textPaint);
if (subtext != null) {
drawShadowText(cv, subtext, margin + 2 * scaleCoefficient + textPaint.measureText(text), getWHeight() - 3
* scaleCoefficient, subtextPaint);
}
if(subtext == null) {
smallTextView.setText("");
} else {
smallTextView.setText(subtext);
}
}
public boolean isVisible() {
return text != null && (text.length() > 0 || subtext != null);
}
@Override
public boolean updateInfo(DrawSettings drawSettings) {
protected boolean updateVisibility(boolean visible) {
if (visible != (view.getVisibility() == View.VISIBLE)) {
if (visible) {
view.setVisibility(View.VISIBLE);
} else {
view.setVisibility(View.GONE);
}
view.invalidate();
return true;
}
return false;
}
public boolean isVisible() {
return view.getVisibility() == View.VISIBLE && view.getParent() != null;
}
public boolean updateInfo(DrawSettings drawSettings) {
return false;
}
public void setOnClickListener(OnClickListener onClickListener) {
view.setOnClickListener(onClickListener);
}
public void setExplicitlyVisible(boolean explicitlyVisible) {
this.explicitlyVisible = explicitlyVisible;
}
public boolean isExplicitlyVisible() {
return explicitlyVisible;
}
public void updateTextColor(int textColor, int textShadowColor, boolean bold, int rad) {
updateTextColor(smallTextView, textColor, textShadowColor, bold, rad);
updateTextColor(textView, textColor, textShadowColor, bold, rad);
}
private void updateTextColor(TextView tv, int textColor, int textShadowColor, boolean textBold, int rad) {
tv.setTextColor(textColor);
tv.setShadowLayer(rad, 0, 0, textShadowColor);
tv.setTypeface(Typeface.DEFAULT, textBold ? Typeface.BOLD : Typeface.NORMAL);
}
}

View file

@ -1,11 +0,0 @@
package net.osmand.plus.views.mapwidgets;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
public interface UpdateableWidget {
public boolean updateInfo(DrawSettings drawSettings);
}

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="src" path="java"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>

2
eclipse-compile/fab/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
bin
gen

View file

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ShellFab</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2015 Shell Software Inc.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
~ File created: 2015-01-17 10:10:53
-->
<manifest
package="com.software.shell.fab"
/>

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,74 @@
/*
* Copyright 2015 Shell Software Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* File created: 2015-02-25 19:54:28
*/
package com.software.shell.fab;
import android.annotation.TargetApi;
import android.graphics.Outline;
import android.os.Build;
import android.view.View;
import android.view.ViewOutlineProvider;
/**
* An implementation of the {@link android.view.ViewOutlineProvider}
* for <b>Action Button</b>
*
* Used for drawing the elevation shadow for {@code API 21 Lollipop} and higher
*
* @author Vladislav
* @version 1.0.0
* @since 1.0.0
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
class ActionButtonOutlineProvider extends ViewOutlineProvider {
/**
* Outline provider width
*/
private int width;
/**
* Outline provider height
*/
private int height;
/**
* Creates an instance of the {@link com.software.shell.fab.ActionButtonOutlineProvider}
*
* @param width initial outline provider width
* @param height initial outline provider height
*/
ActionButtonOutlineProvider(int width, int height) {
this.width = width;
this.height = height;
}
/**
* Called to get the provider to populate the Outline. This method will be called by a View
* when its owned Drawables are invalidated, when the View's size changes, or if invalidateOutline()
* is called explicitly. The input outline is empty and has an alpha of 1.0f
*
* @param view a view, which builds the outline
* @param outline an empty outline, which is to be populated
*/
@Override
public void getOutline(View view, Outline outline) {
outline.setOval(0, 0, width, height);
}
}

View file

@ -0,0 +1,198 @@
/*
* Copyright 2015 Shell Software Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* File created: 2015-02-16 10:56:57
*/
package com.software.shell.fab;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.Log;
import android.view.animation.Animation;
/**
* Deprecated since version <b>1.0.2</b>. Use {@link com.software.shell.fab.ActionButton}
* class instead.
* The reason is the rename of base class name from <b>FloatingActionButton</b> to
* <b>ActionButton</b> and some of the methods, which are present in this class.
* <p>
* Will be removed in version 2.0.0. Please use {@link com.software.shell.fab.ActionButton} and
* methods declared there instead
*
* @author Vladislav
* @version 1.0.0
* @since 1.0.0
*/
@Deprecated
public class FloatingActionButton extends ActionButton{
private static final String LOG_TAG = "FAB";
public FloatingActionButton(Context context) {
super(context);
}
public FloatingActionButton(Context context, AttributeSet attrs) {
super(context, attrs);
initActionButton(context, attrs, 0, 0);
}
public FloatingActionButton(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initActionButton(context, attrs, defStyleAttr, 0);
}
public FloatingActionButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
initActionButton(context, attrs, defStyleAttr, defStyleRes);
}
/**
* Returns an animation, which is used while showing <b>Floating Action Button</b>
* @deprecated since version <b>1.0.2</b>. Please use {@link #getShowAnimation()} instead
*
* @return animation, which is used while showing <b>Floating Action Button</b>
*/
@Deprecated
public Animation getAnimationOnShow() {
return getShowAnimation();
}
/**
* Sets the animation, which is used while showing <b>Floating Action Button</b>
* @deprecated since version <b>1.0.2</b>. Please use
* {@link #setShowAnimation(android.view.animation.Animation)} instead
*
* @param animation animation, which is to be used while showing
* <b>Floating Action Button</b>
*/
@Deprecated
public void setAnimationOnShow(Animation animation) {
setShowAnimation(animation);
}
/**
* Sets one of the {@link Animations} as animation, which is used while showing
* <b>Floating Action Button</b>
* @deprecated since version <b>1.0.2</b>. Please use
* {@link #setShowAnimation(com.software.shell.fab.ActionButton.Animations)} instead
*
* @param animation one of the {@link Animations}, which is to be used while
* showing <b>Floating Action Button</b>
*/
@Deprecated
public void setAnimationOnShow(Animations animation) {
setShowAnimation(animation);
}
/**
* Returns an animation, which is used while hiding <b>Floating Action Button</b>
* @deprecated since version <b>1.0.2</b>. Please use {@link #getHideAnimation()}
* instead
*
* @return animation, which is used while hiding <b>Floating Action Button</b>
*/
@Deprecated
public Animation getAnimationOnHide() {
return getHideAnimation();
}
/**
* Sets the animation, which is used while hiding <b>Floating Action Button</b>
* @deprecated since version <b>1.0.2</b>. Please use
* {@link #setHideAnimation(android.view.animation.Animation)} instead
*
* @param animation animation, which is to be used while hiding
* <b>Floating Action Button</b>
*/
@Deprecated
public void setAnimationOnHide(Animation animation) {
setHideAnimation(animation);
}
/**
* Sets one of the {@link Animations} as animation, which is used while hiding
* <b>Floating Action Button</b>
* @deprecated since version <b>1.0.2</b>. Please use
* {@link #setHideAnimation(com.software.shell.fab.ActionButton.Animations)} )} instead
*
* @param animation one of the {@link Animations}, which is to be used while
* hiding <b>Floating Action Button</b>
*/
@Deprecated
public void setAnimationOnHide(Animations animation) {
setHideAnimation(animation);
}
private void initActionButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
TypedArray attributes = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ActionButton,
defStyleAttr, defStyleRes);
try {
initType(attributes);
initShowAnimation(attributes);
initHideAnimation(attributes);
} catch (Exception e) {
Log.e(LOG_TAG, "Unable to read attr", e);
} finally {
attributes.recycle();
}
Log.v(LOG_TAG, "Floating Action Button initialized");
}
private void initType(TypedArray attrs) {
if (attrs.hasValue(R.styleable.ActionButton_type)) {
final int id = attrs.getInteger(R.styleable.ActionButton_type, 0);
setType(Type.forId(id));
Log.v(LOG_TAG, "Initialized type: " + getType());
}
}
/**
* Initializes the animation, which is used while showing
* <b>Action Button</b>
* @deprecated since 1.0.2 and will be removed in version 2.0.0.
* Use <b>show_animation</b> and <b>hide_animation</b> in XML instead
*
* @param attrs attributes of the XML tag that is inflating the view
*/
@Deprecated
private void initShowAnimation(TypedArray attrs) {
if (attrs.hasValue(R.styleable.ActionButton_animation_onShow)) {
final int animResId = attrs.getResourceId(R.styleable.ActionButton_animation_onShow,
Animations.NONE.animResId);
setShowAnimation(Animations.load(getContext(), animResId));
}
}
/**
* Initializes the animation, which is used while hiding or dismissing
* <b>Action Button</b>
* @deprecated since 1.0.2 and will be removed in version 2.0.0
* Use <b>show_animation</b> and <b>hide_animation</b> in XML instead
*
* @param attrs attributes of the XML tag that is inflating the view
*/
@Deprecated
private void initHideAnimation(TypedArray attrs) {
if (attrs.hasValue(R.styleable.ActionButton_animation_onHide)) {
final int animResId = attrs.getResourceId(R.styleable.ActionButton_animation_onHide,
Animations.NONE.animResId);
setHideAnimation(Animations.load(getContext(), animResId));
}
}
}

View file

@ -0,0 +1,50 @@
/*
* Copyright 2015 Shell Software Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* File created: 2015-01-30 22:55:44
*/
package com.software.shell.fab;
import android.content.Context;
/**
* Contains utility methods for metrics conversion
*
* @author Vladislav
* @version 1.0.0
* @since 1.0.0
*/
public final class MetricsConverter {
/**
* Prevents from creating {@link com.software.shell.fab.MetricsConverter} instances
*/
private MetricsConverter() {
}
/**
* Converts the density-independent value into real pixel value based on display metrics
*
* @param context application context
* @param dp density-independent value
* @return converted real pixel value
*/
public static float dpToPx(Context context, float dp) {
final float scale = context.getResources().getDisplayMetrics().density;
return dp * scale;
}
}

View file

@ -0,0 +1,15 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "ant.properties", and override values to adapt the script to your
# project structure.
# Indicates whether an apk should be generated for each density.
split.density=false
# Project target.
target=android-21
dex.force.jumbo=true
android.library=true

View file

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2015 Shell Software Inc.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
~ File created: 2015-01-17 10:25:12
-->
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:interpolator/decelerate_cubic">
<scale
android:fromXScale="0.0"
android:toXScale="1.0"
android:fromYScale="0.0"
android:toYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="500"
/>
<translate
android:fromYDelta="30%p"
android:toYDelta="0"
android:duration="500"
/>
</set>

View file

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2015 Shell Software Inc.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
~ File created: 2015-01-17 10:25:38
-->
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:interpolator/decelerate_cubic">
<scale
android:fromXScale="0.0"
android:toXScale="1.0"
android:fromYScale="0.0"
android:toYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="500"
/>
<translate
android:fromXDelta="30%p"
android:toXDelta="0"
android:duration="500"
/>
</set>

Some files were not shown because too many files have changed in this diff Show more