diff --git a/OsmAnd/res/drawable-hdpi/ic_destination_arrow.png b/OsmAnd/res/drawable-hdpi/ic_destination_arrow.png new file mode 100644 index 0000000000..602319fac1 Binary files /dev/null and b/OsmAnd/res/drawable-hdpi/ic_destination_arrow.png differ diff --git a/OsmAnd/res/drawable-mdpi/ic_destination_arrow.png b/OsmAnd/res/drawable-mdpi/ic_destination_arrow.png new file mode 100644 index 0000000000..cd973c7e77 Binary files /dev/null and b/OsmAnd/res/drawable-mdpi/ic_destination_arrow.png differ diff --git a/OsmAnd/res/drawable-xhdpi/ic_destination_arrow.png b/OsmAnd/res/drawable-xhdpi/ic_destination_arrow.png new file mode 100644 index 0000000000..bb3e1ac68b Binary files /dev/null and b/OsmAnd/res/drawable-xhdpi/ic_destination_arrow.png differ diff --git a/OsmAnd/res/drawable-xxhdpi/ic_destination_arrow.png b/OsmAnd/res/drawable-xxhdpi/ic_destination_arrow.png new file mode 100644 index 0000000000..4a926851a6 Binary files /dev/null and b/OsmAnd/res/drawable-xxhdpi/ic_destination_arrow.png differ diff --git a/OsmAnd/res/layout/dash_favorites_item.xml b/OsmAnd/res/layout/dash_favorites_item.xml index c053fae24e..0d9a34a93a 100644 --- a/OsmAnd/res/layout/dash_favorites_item.xml +++ b/OsmAnd/res/layout/dash_favorites_item.xml @@ -28,11 +28,20 @@ android:textColor="@color/dashboard_black" android:layout_width="wrap_content" android:layout_height="wrap_content"/> - + + + + + () { - 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() { + 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); + } } diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java index 1ba7fbc49a..2c1c730b24 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java @@ -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 arrows = new ArrayList(); + List points = new ArrayList(); + @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 points = new ArrayList(helper.getFavouritePoints()); + points = new ArrayList(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 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); + } } diff --git a/OsmAnd/src/net/osmand/plus/views/DirectionDrawable.java b/OsmAnd/src/net/osmand/plus/views/DirectionDrawable.java new file mode 100644 index 0000000000..97058023f5 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/views/DirectionDrawable.java @@ -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; + } + +}