forked from organicmaps/organicmaps
[AND] Base code for UI track support.
This commit is contained in:
parent
a08b17fa8a
commit
01e2e2d4e5
6 changed files with 173 additions and 51 deletions
|
@ -1,19 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="?android:attr/listPreferredItemHeight"
|
||||
android:paddingLeft="3dp"
|
||||
android:paddingRight="3dp" >
|
||||
|
||||
<com.mapswithme.maps.ArrowImage
|
||||
android:id="@+id/pi_arrow"
|
||||
android:layout_width="34dip"
|
||||
android:layout_height="34dip"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginLeft="6dip"
|
||||
android:scaleType="center" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/pi_pin_color"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -23,22 +14,24 @@
|
|||
android:padding="10dp"
|
||||
android:src="@drawable/placemark_red" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/pi_distance"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toLeftOf="@id/pi_arrow"
|
||||
android:textAppearance="@style/Holo.TextAppearance.Small.Light" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/pi_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toLeftOf="@id/pi_distance"
|
||||
android:layout_toLeftOf="@+id/pi_distance"
|
||||
android:layout_toRightOf="@id/pi_pin_color"
|
||||
android:text="my name is"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="@style/Holo.TextAppearance.Large.Light" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/pi_distance"
|
||||
android:text="2333"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:textAppearance="@style/Holo.TextAppearance.Small.Light" />
|
||||
|
||||
</RelativeLayout>
|
40
android/res/layout/list_item_track.xml
Normal file
40
android/res/layout/list_item_track.xml
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?android:attr/listPreferredItemHeight"
|
||||
android:paddingLeft="3dp"
|
||||
android:paddingRight="3dp" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/pi_pin_color"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:padding="10dp"
|
||||
android:src="@drawable/placemark_red" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_toRightOf="@+id/pi_pin_color"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/pi_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:text="my name is"
|
||||
android:textAppearance="@style/Holo.TextAppearance.Large.Light" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/pi_distance"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="333"
|
||||
android:textAppearance="@style/Holo.TextAppearance.Small.Light" />
|
||||
</LinearLayout>
|
||||
|
||||
</RelativeLayout>
|
|
@ -60,10 +60,19 @@ public class BookmarkListActivity extends AbstractBookmarkListActivity
|
|||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
|
||||
{
|
||||
final Intent i = new Intent(BookmarkListActivity.this, MWMActivity.class);
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
mManager.showBookmarkOnMap(setIndex, position);
|
||||
startActivity(i);
|
||||
final int type = mPinAdapter.getItemViewType(position);
|
||||
if (type == BookmarkListAdapter.TYPE_BMK)
|
||||
{
|
||||
final Intent i = new Intent(BookmarkListActivity.this, MWMActivity.class);
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
mManager.showBookmarkOnMap(setIndex, position - 3); // TODO: this is not true
|
||||
startActivity(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
Utils.toastShortcut(BookmarkListActivity.this, mEditedSet.getTrack(position).getName() + position);
|
||||
// TODO show map
|
||||
}
|
||||
}
|
||||
});
|
||||
registerForContextMenu(getListView());
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.mapswithme.maps.bookmarks;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.location.Location;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -9,12 +11,13 @@ import android.widget.BaseAdapter;
|
|||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mapswithme.maps.ArrowImage;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.bookmarks.data.Bookmark;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
import com.mapswithme.maps.bookmarks.data.DistanceAndAzimut;
|
||||
import com.mapswithme.maps.bookmarks.data.Track;
|
||||
import com.mapswithme.maps.location.LocationService;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
|
||||
|
||||
public class BookmarkListAdapter extends BaseAdapter implements LocationService.Listener
|
||||
|
@ -42,39 +45,37 @@ public class BookmarkListAdapter extends BaseAdapter implements LocationService.
|
|||
mLocation.stopUpdate(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewTypeCount()
|
||||
{
|
||||
return 2; // bookmark + track
|
||||
}
|
||||
final static int TYPE_TRACK = 0;
|
||||
final static int TYPE_BMK = 1;
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position)
|
||||
{
|
||||
return position < mCategory.getTracksCount() ? TYPE_TRACK : TYPE_BMK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent)
|
||||
{
|
||||
final int type = getItemViewType(position);
|
||||
if (convertView == null)
|
||||
{
|
||||
convertView = LayoutInflater.from(mContext).inflate(R.layout.bookmark_item, null);
|
||||
final int lId = type == TYPE_BMK ? R.layout.list_item_bookmark : R.layout.list_item_track;
|
||||
convertView = LayoutInflater.from(mContext).inflate(lId, null);
|
||||
convertView.setTag(new PinHolder(convertView));
|
||||
}
|
||||
|
||||
final Bookmark item = mCategory.getBookmark(position);
|
||||
final PinHolder holder = (PinHolder) convertView.getTag();
|
||||
holder.name.setText(item.getName());
|
||||
holder.icon.setImageBitmap(item.getIcon().getIcon());
|
||||
|
||||
final Location loc = mLocation.getLastKnown();
|
||||
if (loc != null)
|
||||
{
|
||||
final DistanceAndAzimut daa = item.getDistanceAndAzimut(loc.getLatitude(), loc.getLongitude(), mNorth);
|
||||
holder.distance.setText(daa.getDistance());
|
||||
|
||||
if (daa.getAthimuth() >= 0.0)
|
||||
holder.arrow.setAzimut(daa.getAthimuth());
|
||||
else
|
||||
holder.arrow.clear();
|
||||
}
|
||||
if (type == TYPE_BMK)
|
||||
holder.set(mCategory.getBookmark(position));
|
||||
else
|
||||
{
|
||||
holder.distance.setText("");
|
||||
holder.arrow.clear();
|
||||
}
|
||||
holder.set(mCategory.getTrack(position));
|
||||
|
||||
//Log.d("lat lot", item.getLat() + " " + item.getLon());
|
||||
return convertView;
|
||||
}
|
||||
|
||||
|
@ -124,19 +125,70 @@ public class BookmarkListAdapter extends BaseAdapter implements LocationService.
|
|||
{
|
||||
}
|
||||
|
||||
private static class PinHolder
|
||||
private class PinHolder
|
||||
{
|
||||
ArrowImage arrow;
|
||||
ImageView icon;
|
||||
TextView name;
|
||||
TextView distance;
|
||||
|
||||
public PinHolder(View convertView)
|
||||
{
|
||||
arrow = (ArrowImage) convertView.findViewById(R.id.pi_arrow);
|
||||
icon = (ImageView) convertView.findViewById(R.id.pi_pin_color);
|
||||
name = (TextView) convertView.findViewById(R.id.pi_name);
|
||||
distance = (TextView) convertView.findViewById(R.id.pi_distance);
|
||||
}
|
||||
|
||||
void setName(Bookmark bmk)
|
||||
{
|
||||
name.setText(bmk.getName());
|
||||
}
|
||||
|
||||
void setName(Track trk)
|
||||
{
|
||||
name.setText(trk.getName());
|
||||
}
|
||||
|
||||
void setDistance(Bookmark bmk)
|
||||
{
|
||||
final Location loc = mLocation.getLastKnown();
|
||||
if (loc != null)
|
||||
{
|
||||
final DistanceAndAzimut daa = bmk.getDistanceAndAzimut(loc.getLatitude(), loc.getLongitude(), mNorth);
|
||||
distance.setText(daa.getDistance());
|
||||
}
|
||||
else
|
||||
distance.setText(null);
|
||||
}
|
||||
|
||||
void setDistance(Track trk)
|
||||
{
|
||||
distance.setText(trk.getLengthString());
|
||||
}
|
||||
|
||||
void setIcon(Bookmark bmk)
|
||||
{
|
||||
icon.setImageBitmap(bmk.getIcon().getIcon());
|
||||
}
|
||||
|
||||
void setIcon(Track trk)
|
||||
{
|
||||
final Resources res = mContext.getResources();
|
||||
final Drawable circle = UiUtils.drawCircle(trk.getColor(), (int) (res.getDimension(R.dimen.icon_size)), res);
|
||||
icon.setImageDrawable(circle);
|
||||
}
|
||||
|
||||
void set(Bookmark bmk)
|
||||
{
|
||||
setName(bmk);
|
||||
setDistance(bmk);
|
||||
setIcon(bmk);
|
||||
}
|
||||
|
||||
void set(Track track)
|
||||
{
|
||||
setName(track);
|
||||
setDistance(track);
|
||||
setIcon(track);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@ import android.content.Context;
|
|||
|
||||
public class BookmarkCategory
|
||||
{
|
||||
private int mId;
|
||||
private final int mId;
|
||||
private String mName;
|
||||
private Context mContext;
|
||||
private final Context mContext;
|
||||
BookmarkCategory(Context c, int id)
|
||||
{
|
||||
mContext = c;
|
||||
|
@ -49,12 +49,27 @@ public class BookmarkCategory
|
|||
}
|
||||
|
||||
public int getSize()
|
||||
{
|
||||
return getBookmarksCount() + getTracksCount();
|
||||
}
|
||||
|
||||
public int getBookmarksCount()
|
||||
{
|
||||
return getSize(mId);
|
||||
}
|
||||
|
||||
public int getTracksCount()
|
||||
{
|
||||
return 3; //TODO add native
|
||||
}
|
||||
|
||||
public Bookmark getBookmark(int b)
|
||||
{
|
||||
return new Bookmark(mContext, mId, b);
|
||||
return new Bookmark(mContext, mId, b - 3); //TODO remove - 3
|
||||
}
|
||||
|
||||
public Track getTrack(int index)
|
||||
{
|
||||
return new Track(); // TODO: add native
|
||||
}
|
||||
}
|
||||
|
|
13
android/src/com/mapswithme/maps/bookmarks/data/Track.java
Normal file
13
android/src/com/mapswithme/maps/bookmarks/data/Track.java
Normal file
|
@ -0,0 +1,13 @@
|
|||
package com.mapswithme.maps.bookmarks.data;
|
||||
|
||||
import android.graphics.Color;
|
||||
|
||||
public class Track
|
||||
{
|
||||
private final int mNativeHandle = -1;
|
||||
|
||||
public String getName() { return "Name"; }
|
||||
public String getLengthString() { return "Far Away: 99999999";}
|
||||
public int getColor() { return Color.GREEN; }
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue