Java Code Examples for android.graphics.Path#setLastPoint()

The following examples show how to use android.graphics.Path#setLastPoint() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TrackList.java    From Androzic with GNU General Public License v3.0 6 votes vote down vote up
public TrackListAdapter(Context context)
{
	mItemLayout = R.layout.list_item_track_swipe;
	mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	mDensity = context.getResources().getDisplayMetrics().density;

	SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);

	mLinePath = new Path();
	mLinePath.setLastPoint(12 * mDensity, 5 * mDensity);
	mLinePath.lineTo(24 * mDensity, 12 * mDensity);
	mLinePath.lineTo(15 * mDensity, 24 * mDensity);
	mLinePath.lineTo(28 * mDensity, 35 * mDensity);

	mTrackWidth = settings.getInt(context.getString(R.string.pref_tracking_linewidth), context.getResources().getInteger(R.integer.def_track_linewidth));
	mLinePaint = new Paint();
	mLinePaint.setAntiAlias(true);
	mLinePaint.setStrokeWidth(mTrackWidth * mDensity);
	mLinePaint.setStyle(Paint.Style.STROKE);
	mLinePaint.setColor(context.getResources().getColor(R.color.routeline));

	application = Androzic.getApplication();
}
 
Example 2
Source File: RouteOverlay.java    From Androzic with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onPrepareBuffer(final Viewport viewport, final Canvas c)
{
	if (!route.show)
		return;

	final int[] cxy = viewport.mapCenterXY;

	final Path path = new Path();
	int i = 0;
	int lastX = 0, lastY = 0;
	List<Waypoint> waypoints = route.getWaypoints();
	synchronized (waypoints)
	{
		for (Waypoint wpt : waypoints)
		{
			int[] xy = application.getXYbyLatLon(wpt.latitude, wpt.longitude);

			if (i == 0)
			{
				path.setLastPoint(xy[0] - cxy[0], xy[1] - cxy[1]);
				lastX = xy[0];
				lastY = xy[1];
			}
			else
			{
				if (Math.abs(lastX - xy[0]) > 2 || Math.abs(lastY - xy[1]) > 2)
				{
					path.lineTo(xy[0] - cxy[0], xy[1] - cxy[1]);
					lastX = xy[0];
					lastY = xy[1];
				}
			}
			i++;
		}
	}
	c.drawPath(path, linePaint);
}
 
Example 3
Source File: RouteList.java    From Androzic with GNU General Public License v3.0 5 votes vote down vote up
public RouteListAdapter(Context context)
{
	mItemLayout = R.layout.list_item_route_swipe;
	mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	mDensity = context.getResources().getDisplayMetrics().density;

	SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);

	mLinePath = new Path();
	mLinePath.setLastPoint(12 * mDensity, 5 * mDensity);
	mLinePath.lineTo(24 * mDensity, 12 * mDensity);
	mLinePath.lineTo(15 * mDensity, 24 * mDensity);
	mLinePath.lineTo(28 * mDensity, 35 * mDensity);

	mPointWidth = settings.getInt(context.getString(R.string.pref_waypoint_width), context.getResources().getInteger(R.integer.def_waypoint_width));
	mRouteWidth = settings.getInt(context.getString(R.string.pref_route_linewidth), context.getResources().getInteger(R.integer.def_route_linewidth));
	mFillPaint = new Paint();
	mFillPaint.setAntiAlias(false);
	mFillPaint.setStrokeWidth(1);
	mFillPaint.setStyle(Paint.Style.FILL_AND_STROKE);
	mFillPaint.setColor(context.getResources().getColor(R.color.routewaypoint));
	mLinePaint = new Paint();
	mLinePaint.setAntiAlias(true);
	mLinePaint.setStrokeWidth(mRouteWidth * mDensity);
	mLinePaint.setStyle(Paint.Style.STROKE);
	mLinePaint.setColor(context.getResources().getColor(R.color.routeline));
	mBorderPaint = new Paint();
	mBorderPaint.setAntiAlias(true);
	mBorderPaint.setStrokeWidth(1);
	mBorderPaint.setStyle(Paint.Style.STROKE);
	mBorderPaint.setColor(context.getResources().getColor(R.color.routeline));

	application = Androzic.getApplication();
}
 
Example 4
Source File: SearchableActivity.java    From Androzic with GNU General Public License v3.0 4 votes vote down vote up
public SearchResultsListAdapter(Context context, List<Object> items)
{
	mItems = items;

	mCoordinatesItemLayout = R.layout.list_item_coordinates;
	mWaypointItemLayout = R.layout.list_item_waypoint;
	mRouteItemLayout = R.layout.list_item_route;
	mTrackItemLayout = R.layout.list_item_track;
	mAddressItemLayout = R.layout.list_item_address;
	mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	mDensity = context.getResources().getDisplayMetrics().density;

	SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);

	mPointWidth = settings.getInt(context.getString(R.string.pref_waypoint_width), context.getResources().getInteger(R.integer.def_waypoint_width));
	mWaypointFillPaint = new Paint();
	mWaypointFillPaint.setAntiAlias(false);
	mWaypointFillPaint.setStrokeWidth(1);
	mWaypointFillPaint.setStyle(Paint.Style.FILL_AND_STROKE);
	mWaypointFillPaint.setColor(settings.getInt(context.getString(R.string.pref_waypoint_color), context.getResources().getColor(R.color.waypoint)));
	mWaypointBorderPaint = new Paint();
	mWaypointBorderPaint.setAntiAlias(false);
	mWaypointBorderPaint.setStrokeWidth(1);
	mWaypointBorderPaint.setStyle(Paint.Style.STROKE);
	mWaypointBorderPaint.setColor(context.getResources().getColor(R.color.waypointtext));
	mWaypointBorderPaint.setColor(settings.getInt(context.getString(R.string.pref_waypoint_namecolor), context.getResources().getColor(R.color.waypointtext)));

	mRouteWidth = settings.getInt(context.getString(R.string.pref_route_linewidth), context.getResources().getInteger(R.integer.def_route_linewidth));
	mRouteLinePath = new Path();
	mRouteLinePath.setLastPoint(12 * mDensity, 5 * mDensity);
	mRouteLinePath.lineTo(24 * mDensity, 12 * mDensity);
	mRouteLinePath.lineTo(15 * mDensity, 24 * mDensity);
	mRouteLinePath.lineTo(28 * mDensity, 35 * mDensity);
	mRouteFillPaint = new Paint();
	mRouteFillPaint.setAntiAlias(false);
	mRouteFillPaint.setStrokeWidth(1);
	mRouteFillPaint.setStyle(Paint.Style.FILL_AND_STROKE);
	mRouteFillPaint.setColor(context.getResources().getColor(R.color.routewaypoint));
	mRouteLinePaint = new Paint();
	mRouteLinePaint.setAntiAlias(true);
	mRouteLinePaint.setStrokeWidth(mRouteWidth * mDensity);
	mRouteLinePaint.setStyle(Paint.Style.STROKE);
	mRouteLinePaint.setColor(context.getResources().getColor(R.color.routeline));
	mRouteBorderPaint = new Paint();
	mRouteBorderPaint.setAntiAlias(true);
	mRouteBorderPaint.setStrokeWidth(1);
	mRouteBorderPaint.setStyle(Paint.Style.STROKE);
	mRouteBorderPaint.setColor(context.getResources().getColor(R.color.routeline));

	mApplication = Androzic.getApplication();
	mLocation = mApplication.getLocation();
}
 
Example 5
Source File: TrackOverlay.java    From Androzic with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onPrepareBuffer(final Viewport viewport, final Canvas c)
{
	if (!track.show)
		return;

	final int[] cxy = viewport.mapCenterXY;

	int w2 = viewport.canvasWidth / 2;
	int h2 = viewport.canvasHeight / 2;
	int left = cxy[0] - w2;
	int right = cxy[0] + w2;
	int top = cxy[1] - h2;
	int bottom = cxy[1] + h2;

	final Path path = new Path();
	boolean first = true;
	boolean skipped = false;
	int lastX = 0, lastY = 0;
	int[] xy = new int[2];
	
	synchronized (track)
	{
		for (Track.TrackSegment segment : track.getSegments())
		{
			if (! viewport.mapArea.intersects(segment.bounds))
				continue;
			synchronized (segment)
			{
				List<Track.TrackPoint> points = segment.getPoints();
				if (points.size() == 0)
					continue;
				for (Track.TrackPoint tp : points)
				{
					if (tp.dirty)
					{
						application.getXYbyLatLon(tp.latitude, tp.longitude, xy);
						tp.x = xy[0];
						tp.y = xy[1];
						tp.dirty = false;
					}
					else
					{
						xy[0] = tp.x;
						xy[1] = tp.y;
					}
	
					if (first)
					{
						path.setLastPoint(xy[0] - cxy[0], xy[1] - cxy[1]);
						lastX = xy[0];
						lastY = xy[1];
						first = false;
						continue;
					}
					if ((lastX == xy[0] && lastY == xy[1]) ||
						lastX < left && cxy[0] < left ||
						lastX > right && cxy[0] > right ||
						lastY < top && cxy[1] < top ||
						lastY > bottom && cxy[1] > bottom)
					{
						lastX = xy[0];
						lastY = xy[1];
						skipped = true;
						continue;
					}
					if (skipped)
					{
						path.moveTo(lastX - cxy[0], lastY - cxy[1]);
						skipped = false;
					}
					if (tp.continous)
						path.lineTo(xy[0] - cxy[0], xy[1] - cxy[1]);
					else
						path.moveTo(xy[0] - cxy[0], xy[1] - cxy[1]);
					lastX = xy[0];
					lastY = xy[1];
				}
			}
		}
	}
	c.drawPath(path, paint);
}