Update rotate drawable

This commit is contained in:
Victor Shcherb 2015-03-31 01:21:57 +02:00
parent 262d7c91b3
commit d6cbfa18f8
5 changed files with 23 additions and 20 deletions

View file

@ -21,7 +21,7 @@
android:layout_marginLeft="@dimen/dashboard_parking_left_margin"
android:layout_marginRight="@dimen/dashFavIconMargin"
android:src="@drawable/ic_action_start_navigation"
android:scaleType="center"
android:scaleType="centerInside"
android:background="@drawable/btn_inset_circle_no_shadow"/>
<LinearLayout

View file

@ -18,7 +18,7 @@
<dimen name="map_alarm_bottom_margin">140dp</dimen>
<dimen name="map_alarm_bottom_margin_land">78dp</dimen>
<dimen name="map_button_shadow_height">127dp</dimen>
<dimen name="map_button_shadow_height">112dp</dimen>
<dimen name="map_widget_icon">32dp</dimen>
<dimen name="map_widget_height">48dp</dimen>
<dimen name="map_widget_image">120dp</dimen>

View file

@ -134,11 +134,7 @@ public abstract class DashLocationFragment extends DashBaseFragment {
arrowResId = R.drawable.ic_destination_arrow_white;
}
DirectionDrawable dd = (DirectionDrawable) arrow.getDrawable();
if (paint) {
dd.setImage(arrowResId, useCenter ? R.color.color_distance : R.color.color_myloc_distance);
} else {
dd.setImage(arrowResId, useCenter ? R.color.color_distance : R.color.color_white);
}
dd.setImage(arrowResId, useCenter ? R.color.color_distance : R.color.color_myloc_distance);
if (fromLoc == null || h == null) {
dd.setAngle(0);
} else {

View file

@ -4,6 +4,7 @@ import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@ -11,7 +12,6 @@ import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.OsmandPlugin;
@ -19,6 +19,7 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dashboard.DashLocationFragment;
import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.views.DirectionDrawable;
import java.util.Calendar;
@ -113,6 +114,11 @@ public class DashParkingFragment extends DashLocationFragment {
ImageView direction = (ImageView) mainView.findViewById(R.id.direction_icon);
if (loc != null) {
DashLocationView dv = new DashLocationView(direction, (TextView) mainView.findViewById(R.id.distance), position);
// Drawable dds = getMyApplication().getIconsCache().getIcon(R.drawable.ic_action_start_navigation,
// R.color.color_distance);
// DirectionDrawable dd = new DirectionDrawable(mainView.getContext(),
// dds.getIntrinsicWidth(), dds.getIntrinsicHeight());
// direction.setImageDrawable(dd);
dv.paint = false;
dv.arrowResId = R.drawable.ic_action_start_navigation;
distances.add(dv);

View file

@ -35,13 +35,12 @@ public class DirectionDrawable extends Drawable {
this.resourceId = resourceId;
}
public void setImage(int resourceId){
public void setImage(int resourceId) {
IconsCache iconsCache = ((OsmandApplication) ctx.getApplicationContext()).getIconsCache();
arrowImage = iconsCache.getIcon(resourceId, 0);
this.resourceId = resourceId;
}
public DirectionDrawable(Context ctx, float width, float height) {
this.ctx = ctx;
this.width = width;
@ -77,21 +76,23 @@ public class DirectionDrawable extends Drawable {
@Override
public void draw(Canvas canvas) {
canvas.save();
if (arrowImage != null) {
canvas.rotate(angle, canvas.getHeight() / 2, canvas.getWidth() / 2);
arrowImage.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
int w = arrowImage.getIntrinsicWidth();
int h = arrowImage.getIntrinsicHeight();
int dx = canvas.getWidth() - w;
int dy = canvas.getHeight() - h;
arrowImage.setBounds(0, 0, w, h);
canvas.rotate(angle, canvas.getWidth() / 2, canvas.getHeight() / 2);
canvas.translate(dx/2, dy/2);
arrowImage.draw(canvas);
// TODO delete?
// Bitmap arrow = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888);
// Canvas canv = new Canvas(arrow);
// arrowImage.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
// arrowImage.draw(canv);
// canvas.drawBitmap(arrow, null, new Rect(0, 0, arrow.getHeight(), arrow.getWidth()), null);
} else {
canvas.rotate(angle, canvas.getHeight()/2, canvas.getWidth() / 2);
canvas.rotate(angle, canvas.getWidth() / 2, canvas.getHeight() / 2);
Path directionPath = createDirectionPath();
canvas.drawPath(directionPath, paintRouteDirection);
}
canvas.restore();
}
@Override