Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
c538d2dc39
12 changed files with 310 additions and 153 deletions
BIN
OsmAnd/res/drawable-hdpi/ic_destination_arrow.png
Normal file
BIN
OsmAnd/res/drawable-hdpi/ic_destination_arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
BIN
OsmAnd/res/drawable-mdpi/ic_destination_arrow.png
Normal file
BIN
OsmAnd/res/drawable-mdpi/ic_destination_arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
BIN
OsmAnd/res/drawable-xhdpi/ic_destination_arrow.png
Normal file
BIN
OsmAnd/res/drawable-xhdpi/ic_destination_arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
BIN
OsmAnd/res/drawable-xxhdpi/ic_destination_arrow.png
Normal file
BIN
OsmAnd/res/drawable-xxhdpi/ic_destination_arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
|
@ -28,11 +28,20 @@
|
|||
android:textColor="@color/dashboard_black"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
<TextView android:id="@+id/distance"
|
||||
android:textSize="12sp"
|
||||
android:textColor="@color/dashboard_blue"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
<LinearLayout android:orientation="horizontal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
<ImageView android:visibility="gone"
|
||||
android:id="@+id/direction"
|
||||
android:layout_width="10dp"
|
||||
android:layout_height="10dp"/>
|
||||
<TextView android:id="@+id/distance"
|
||||
android:textSize="12sp"
|
||||
android:textColor="@color/dashboard_blue"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ImageButton android:id="@+id/navigate_to"
|
||||
|
|
|
@ -451,6 +451,11 @@ public class MainMenuActivity extends BaseDownloadActivity {
|
|||
((DashUpdatesFragment) f).updatedDownloadsList(list);
|
||||
}
|
||||
}
|
||||
if(f instanceof DashDownloadMapsFragment) {
|
||||
if(!f.isDetached()) {
|
||||
((DashDownloadMapsFragment) f).refreshData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ import net.osmand.plus.activities.MapActivityActions;
|
|||
import net.osmand.plus.activities.OsmandListActivity;
|
||||
import net.osmand.plus.dialogs.DirectionsDialogs;
|
||||
import net.osmand.plus.render.RenderingIcons;
|
||||
import net.osmand.plus.views.DirectionDrawable;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.util.OpeningHoursParser;
|
||||
import net.osmand.util.OpeningHoursParser.OpeningHours;
|
||||
|
@ -117,7 +118,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
|
|||
|
||||
private Handler uiHandler;
|
||||
private OsmandSettings settings;
|
||||
private Path directionPath = new Path();
|
||||
|
||||
private float width = 24;
|
||||
private float height = 24;
|
||||
|
||||
|
@ -235,8 +236,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
|
|||
uiHandler = new Handler();
|
||||
searchFilter = (EditText) findViewById(R.id.SearchFilter);
|
||||
searchFilterLayout = findViewById(R.id.SearchFilterLayout);
|
||||
directionPath = createDirectionPath();
|
||||
|
||||
|
||||
settings = ((OsmandApplication) getApplication()).getSettings();
|
||||
|
||||
searchFilter.addTextChangedListener(new TextWatcher(){
|
||||
|
@ -296,33 +296,6 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
|
|||
getListView().addFooterView(ll);
|
||||
}
|
||||
|
||||
private Path createDirectionPath() {
|
||||
int h = 15;
|
||||
int w = 4;
|
||||
float sarrowL = 8; // side of arrow
|
||||
float harrowL = (float) Math.sqrt(2) * sarrowL; // hypotenuse of arrow
|
||||
float hpartArrowL = (float) (harrowL - w) / 2;
|
||||
Path path = new Path();
|
||||
path.moveTo(width / 2, height - (height - h) / 3);
|
||||
path.rMoveTo(w / 2, 0);
|
||||
path.rLineTo(0, -h);
|
||||
path.rLineTo(hpartArrowL, 0);
|
||||
path.rLineTo(-harrowL / 2, -harrowL / 2); // center
|
||||
path.rLineTo(-harrowL / 2, harrowL / 2);
|
||||
path.rLineTo(hpartArrowL, 0);
|
||||
path.rLineTo(0, h);
|
||||
|
||||
Matrix pathTransform = new Matrix();
|
||||
WindowManager mgr = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
|
||||
DisplayMetrics dm = new DisplayMetrics();
|
||||
mgr.getDefaultDisplay().getMetrics(dm);
|
||||
pathTransform.postScale(dm.density, dm.density);
|
||||
path.transform(pathTransform);
|
||||
width *= dm.density;
|
||||
height *= dm.density;
|
||||
return path;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
@ -793,7 +766,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
|
|||
}
|
||||
}
|
||||
if(loc != null){
|
||||
DirectionDrawable draw = new DirectionDrawable();
|
||||
DirectionDrawable draw = new DirectionDrawable(SearchPOIActivity.this, width, height, false);
|
||||
Float h = heading;
|
||||
float a = h != null ? h : 0;
|
||||
draw.setAngle(mes[1] - a + 180);
|
||||
|
@ -903,56 +876,4 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
|
|||
b.show();
|
||||
}
|
||||
|
||||
|
||||
class DirectionDrawable extends Drawable {
|
||||
Paint paintRouteDirection;
|
||||
|
||||
private float angle;
|
||||
|
||||
public DirectionDrawable(){
|
||||
paintRouteDirection = new Paint();
|
||||
paintRouteDirection.setStyle(Style.FILL_AND_STROKE);
|
||||
paintRouteDirection.setColor(getResources().getColor(R.color.color_unknown));
|
||||
paintRouteDirection.setAntiAlias(true);
|
||||
}
|
||||
|
||||
public void setOpenedColor(int opened){
|
||||
if(opened == 0){
|
||||
paintRouteDirection.setColor(getResources().getColor(R.color.color_ok));
|
||||
} else if(opened == -1){
|
||||
paintRouteDirection.setColor(getResources().getColor(R.color.color_unknown));
|
||||
} else {
|
||||
paintRouteDirection.setColor(getResources().getColor(R.color.color_warning));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setAngle(float angle){
|
||||
this.angle = angle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
canvas.rotate(angle, width/2, height/2);
|
||||
canvas.drawPath(directionPath, paintRouteDirection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOpacity() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlpha(int alpha) {
|
||||
paintRouteDirection.setAlpha(alpha);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColorFilter(ColorFilter cf) {
|
||||
paintRouteDirection.setColorFilter(cf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -34,53 +34,7 @@ public class DashDownloadMapsFragment extends DashBaseFragment {
|
|||
final TextView message =((TextView) view.findViewById(R.id.message));
|
||||
final Button local = ((Button) view.findViewById(R.id.local_downloads));
|
||||
message.setTypeface(typeface);
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
int countMaps = 0;
|
||||
long size = 0;
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
updateCount(IndexConstants.MAPS_PATH);
|
||||
updateCount(IndexConstants.SRTM_INDEX_DIR);
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void updateCount(String s) {
|
||||
File ms = getMyApplication().getAppPath(s);
|
||||
if (ms.exists()) {
|
||||
File[] lf = ms.listFiles();
|
||||
if (lf != null) {
|
||||
for (File f : ms.listFiles()) {
|
||||
if (f.getName().endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) {
|
||||
size += f.length();
|
||||
countMaps++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
super.onPostExecute(result);
|
||||
if(countMaps > 0) {
|
||||
long mb = 1 << 20;
|
||||
long gb = 1 << 30;
|
||||
String sz = size > gb ?
|
||||
formatGb.format(new Object[] { (float) size / (gb) }) :
|
||||
formatMb.format(new Object[] { (float) size / mb }) ;
|
||||
message.setText(getString(R.string.dash_download_msg, countMaps+"") + " (" + sz +")");
|
||||
local.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
message.setText(getString(R.string.dash_download_msg_none));
|
||||
local.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
}
|
||||
}.execute((Void)null);
|
||||
|
||||
|
||||
|
||||
|
||||
local.setTypeface(typeface);
|
||||
local.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
|
@ -106,4 +60,63 @@ public class DashDownloadMapsFragment extends DashBaseFragment {
|
|||
});
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
refreshData();
|
||||
}
|
||||
|
||||
public void refreshData() {
|
||||
if (getView() == null){
|
||||
return;
|
||||
}
|
||||
|
||||
final TextView message =((TextView) getView().findViewById(R.id.message));
|
||||
final Button local = ((Button) getView().findViewById(R.id.local_downloads));
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
int countMaps = 0;
|
||||
long size = 0;
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
updateCount(IndexConstants.MAPS_PATH);
|
||||
updateCount(IndexConstants.SRTM_INDEX_DIR);
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void updateCount(String s) {
|
||||
File ms = getMyApplication().getAppPath(s);
|
||||
if (ms.exists()) {
|
||||
File[] lf = ms.listFiles();
|
||||
if (lf != null) {
|
||||
for (File f : ms.listFiles()) {
|
||||
if (f.getName().endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) {
|
||||
size += f.length();
|
||||
countMaps++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
super.onPostExecute(result);
|
||||
if(countMaps > 0) {
|
||||
long mb = 1 << 20;
|
||||
long gb = 1 << 30;
|
||||
String sz = size > gb ?
|
||||
formatGb.format(new Object[] { (float) size / (gb) }) :
|
||||
formatMb.format(new Object[] { (float) size / mb }) ;
|
||||
message.setText(getString(R.string.dash_download_msg, countMaps+"") + " (" + sz +")");
|
||||
local.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
message.setText(getString(R.string.dash_download_msg_none));
|
||||
local.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
}
|
||||
}.execute((Void)null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.plus.dashboard;
|
|||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.TypedValue;
|
||||
|
@ -13,16 +14,16 @@ import android.widget.Button;
|
|||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import net.osmand.Location;
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.OsmAndAppCustomization;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.*;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.search.SearchPOIActivity;
|
||||
import net.osmand.plus.base.FavoriteImageDrawable;
|
||||
import net.osmand.plus.dialogs.DirectionsDialogs;
|
||||
import net.osmand.plus.helpers.FontCache;
|
||||
import net.osmand.plus.views.DirectionDrawable;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -33,8 +34,13 @@ import java.util.List;
|
|||
/**
|
||||
* Created by Denis on 24.11.2014.
|
||||
*/
|
||||
public class DashFavoritesFragment extends DashBaseFragment {
|
||||
public class DashFavoritesFragment extends DashBaseFragment implements OsmAndLocationProvider.OsmAndCompassListener, OsmAndLocationProvider.OsmAndLocationListener {
|
||||
public static final String TAG = "DASH_FAVORITES_FRAGMENT";
|
||||
private net.osmand.Location location = null;
|
||||
private Float heading = null;
|
||||
private List<ImageView> arrows = new ArrayList<ImageView>();
|
||||
List<FavouritePoint> points = new ArrayList<FavouritePoint>();
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = getActivity().getLayoutInflater().inflate(R.layout.dash_favorites_fragment, container, false);
|
||||
|
@ -53,19 +59,49 @@ public class DashFavoritesFragment extends DashBaseFragment {
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
getLocationProvider().removeCompassListener(this);
|
||||
getLocationProvider().removeLocationListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (getMyApplication().getFavorites().getFavouritePoints().size() > 0) {
|
||||
registerListeners();
|
||||
if(!getMyApplication().getSettings().isLastKnownMapLocation()) {
|
||||
// show first time when application ran
|
||||
location = getMyApplication().getLocationProvider().getFirstTimeRunDefaultLocation();
|
||||
} else {
|
||||
location = getLocationProvider().getLastKnownLocation();
|
||||
}
|
||||
updateLocation(location);
|
||||
}
|
||||
|
||||
|
||||
setupFavorites();
|
||||
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
getLocationProvider().addLocationListener(this);
|
||||
getLocationProvider().addCompassListener(this);
|
||||
getLocationProvider().registerOrUnregisterCompassListener(true);
|
||||
getLocationProvider().resumeAllUpdates();
|
||||
}
|
||||
|
||||
private void setupFavorites(){
|
||||
View mainView = getView();
|
||||
final FavouritesDbHelper helper = getMyApplication().getFavorites();
|
||||
final List<FavouritePoint> points = new ArrayList<FavouritePoint>(helper.getFavouritePoints());
|
||||
points = new ArrayList<FavouritePoint>(helper.getFavouritePoints());
|
||||
arrows.clear();
|
||||
if (points.size() == 0){
|
||||
(mainView.findViewById(R.id.main_fav)).setVisibility(View.GONE);
|
||||
return;
|
||||
|
@ -96,6 +132,13 @@ public class DashFavoritesFragment extends DashBaseFragment {
|
|||
TextView name = (TextView) view.findViewById(R.id.name);
|
||||
TextView label = (TextView) view.findViewById(R.id.distance);
|
||||
ImageView icon = (ImageView) view.findViewById(R.id.icon);
|
||||
ImageView direction = (ImageView) view.findViewById(R.id.direction);
|
||||
|
||||
if(location != null){
|
||||
direction.setVisibility(View.VISIBLE);
|
||||
updateArrow(point, direction);
|
||||
}
|
||||
arrows.add(direction);
|
||||
name.setText(point.getName());
|
||||
icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(getActivity(), point.getColor()));
|
||||
LatLon lastKnownMapLocation = getMyApplication().getSettings().getLastKnownMapLocation();
|
||||
|
@ -125,4 +168,46 @@ public class DashFavoritesFragment extends DashBaseFragment {
|
|||
favorites.addView(view);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateArrows() {
|
||||
if (location == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for(int i =0; i<arrows.size(); i++){
|
||||
arrows.get(i).setVisibility(View.VISIBLE);
|
||||
updateArrow(points.get(i), arrows.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
private void updateArrow(FavouritePoint point, ImageView direction) {
|
||||
float[] mes = new float[2];
|
||||
LatLon l = new LatLon(point.getLatitude(), point.getLongitude());
|
||||
Location.distanceBetween(l.getLatitude(), l.getLongitude(), location.getLatitude(), location.getLongitude(), mes);
|
||||
DirectionDrawable draw = new DirectionDrawable(getActivity(), 10, 10, true);
|
||||
Float h = heading;
|
||||
float a = h != null ? h : 0;
|
||||
draw.setAngle(mes[1] - a + 180);
|
||||
direction.setImageDrawable(draw);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCompassValue(float value) {
|
||||
heading = value;
|
||||
updateArrows();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateLocation(Location location) {
|
||||
if (location == null){
|
||||
return;
|
||||
}
|
||||
this.location = location;
|
||||
updateArrows();
|
||||
|
||||
}
|
||||
|
||||
private OsmAndLocationProvider getLocationProvider() {
|
||||
return getMyApplication().getLocationProvider();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.util.Collections;
|
|||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import android.media.Image;
|
||||
import android.widget.*;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.BasicProgressAsyncTask;
|
||||
|
@ -110,7 +111,12 @@ public class DashUpdatesFragment extends DashBaseFragment {
|
|||
downloadButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
getDownloadActivity().startDownload(item);
|
||||
if (getDownloadActivity().isInQueue(item)) {
|
||||
getDownloadActivity().removeFromQueue(item);
|
||||
((ImageButton)view).setImageResource(R.drawable.download_button);
|
||||
} else if (!getDownloadActivity().startDownload(item)) {
|
||||
((ImageButton)view).setImageResource(R.drawable.cancel_button);
|
||||
}
|
||||
}
|
||||
});
|
||||
downloadButtons.add((ImageButton) downloadButton);
|
||||
|
@ -150,7 +156,7 @@ public class DashUpdatesFragment extends DashBaseFragment {
|
|||
cancelButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
getDownloadActivity().makeSureUserCancelDownload();
|
||||
getDownloadActivity().cancelDownload();
|
||||
}
|
||||
});
|
||||
boolean intermediate = basicProgressAsyncTask.isIndeterminate();
|
||||
|
|
|
@ -113,14 +113,14 @@ public class BaseDownloadActivity extends SherlockFragmentActivity {
|
|||
|
||||
}
|
||||
|
||||
public void startDownload(IndexItem item) {
|
||||
public boolean startDownload(IndexItem item) {
|
||||
if (downloadListIndexThread.getCurrentRunningTask() != null && getEntriesToDownload().get(item) == null) {
|
||||
downloadQueue.add(item);
|
||||
Toast.makeText(this, "Added to download queue", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
addToDownload(item);
|
||||
downloadFilesCheckFreeVersion();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void addToDownload(IndexItem item) {
|
||||
|
@ -213,20 +213,24 @@ public class BaseDownloadActivity extends SherlockFragmentActivity {
|
|||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
BasicProgressAsyncTask<?, ?, ?> t = DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
|
||||
if (t != null) {
|
||||
t.setInterrupted(true);
|
||||
}
|
||||
// list of items to download need to be cleared in case of dashboard activity
|
||||
if (BaseDownloadActivity.this instanceof MainMenuActivity) {
|
||||
getEntriesToDownload().clear();
|
||||
}
|
||||
cancelDownload();
|
||||
}
|
||||
});
|
||||
bld.setNegativeButton(R.string.default_buttons_no, null);
|
||||
bld.show();
|
||||
}
|
||||
|
||||
public void cancelDownload() {
|
||||
BasicProgressAsyncTask<?, ?, ?> t = DownloadActivity.downloadListIndexThread.getCurrentRunningTask();
|
||||
if (t != null) {
|
||||
t.setInterrupted(true);
|
||||
}
|
||||
// list of items to download need to be cleared in case of dashboard activity
|
||||
if (this instanceof MainMenuActivity) {
|
||||
getEntriesToDownload().clear();
|
||||
}
|
||||
}
|
||||
|
||||
private void prepareDownloadDirectory() {
|
||||
if (getMyApplication().getResourceManager().getIndexFileNames().isEmpty()) {
|
||||
boolean showedDialog = false;
|
||||
|
@ -319,5 +323,13 @@ public class BaseDownloadActivity extends SherlockFragmentActivity {
|
|||
};
|
||||
task.execute();
|
||||
}
|
||||
|
||||
public boolean isInQueue(IndexItem item) {
|
||||
return downloadQueue.contains(item);
|
||||
}
|
||||
|
||||
public void removeFromQueue(IndexItem item) {
|
||||
downloadQueue.remove(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
106
OsmAnd/src/net/osmand/plus/views/DirectionDrawable.java
Normal file
106
OsmAnd/src/net/osmand/plus/views/DirectionDrawable.java
Normal file
|
@ -0,0 +1,106 @@
|
|||
package net.osmand.plus.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.*;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.WindowManager;
|
||||
import net.osmand.plus.R;
|
||||
|
||||
/**
|
||||
* Created by Denis on 10.12.2014.
|
||||
*/
|
||||
public class DirectionDrawable extends Drawable {
|
||||
Paint paintRouteDirection;
|
||||
float width;
|
||||
float height;
|
||||
Context ctx;
|
||||
boolean favorite;
|
||||
private float angle;
|
||||
|
||||
|
||||
public DirectionDrawable(Context ctx, float width, float height, boolean favorite) {
|
||||
this.favorite = favorite;
|
||||
this.ctx = ctx;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
paintRouteDirection = new Paint();
|
||||
paintRouteDirection.setStyle(Paint.Style.FILL_AND_STROKE);
|
||||
paintRouteDirection.setColor(ctx.getResources().getColor(R.color.color_unknown));
|
||||
paintRouteDirection.setAntiAlias(true);
|
||||
}
|
||||
|
||||
public void setOpenedColor(int opened) {
|
||||
if (opened == 0) {
|
||||
paintRouteDirection.setColor(ctx.getResources().getColor(R.color.color_ok));
|
||||
} else if (opened == -1) {
|
||||
paintRouteDirection.setColor(ctx.getResources().getColor(R.color.color_unknown));
|
||||
} else {
|
||||
paintRouteDirection.setColor(ctx.getResources().getColor(R.color.color_warning));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setAngle(float angle) {
|
||||
this.angle = angle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
|
||||
if (favorite) {
|
||||
canvas.rotate(angle, canvas.getHeight()/2, canvas.getWidth()/2);
|
||||
Bitmap arrow = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.ic_destination_arrow);
|
||||
canvas.drawBitmap(arrow, 0, 0, new Paint());
|
||||
} else {
|
||||
canvas.rotate(angle, width / 2, height / 2);
|
||||
Path directionPath = createDirectionPath();
|
||||
canvas.drawPath(directionPath, paintRouteDirection);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOpacity() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlpha(int alpha) {
|
||||
paintRouteDirection.setAlpha(alpha);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColorFilter(ColorFilter cf) {
|
||||
paintRouteDirection.setColorFilter(cf);
|
||||
}
|
||||
|
||||
private Path createDirectionPath() {
|
||||
int h = 15;
|
||||
int w = 4;
|
||||
float sarrowL = 8; // side of arrow
|
||||
float harrowL = (float) Math.sqrt(2) * sarrowL; // hypotenuse of arrow
|
||||
float hpartArrowL = (float) (harrowL - w) / 2;
|
||||
Path path = new Path();
|
||||
path.moveTo(width / 2, height - (height - h) / 3);
|
||||
path.rMoveTo(w / 2, 0);
|
||||
path.rLineTo(0, -h);
|
||||
path.rLineTo(hpartArrowL, 0);
|
||||
path.rLineTo(-harrowL / 2, -harrowL / 2); // center
|
||||
path.rLineTo(-harrowL / 2, harrowL / 2);
|
||||
path.rLineTo(hpartArrowL, 0);
|
||||
path.rLineTo(0, h);
|
||||
|
||||
DisplayMetrics dm = new DisplayMetrics();
|
||||
Matrix pathTransform = new Matrix();
|
||||
WindowManager mgr = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
|
||||
mgr.getDefaultDisplay().getMetrics(dm);
|
||||
pathTransform.postScale(dm.density, dm.density);
|
||||
path.transform(pathTransform);
|
||||
width *= dm.density;
|
||||
height *= dm.density;
|
||||
return path;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue