forked from organicmaps/organicmaps
[AND] Added JNI for tracks. Refactoring.
This commit is contained in:
parent
01e2e2d4e5
commit
6697facb90
12 changed files with 175 additions and 56 deletions
android
jni/com/mapswithme/maps
src/com/mapswithme/maps
|
@ -617,6 +617,13 @@ namespace android
|
|||
return res;
|
||||
}
|
||||
|
||||
void Framework::ShowTrack(int category, int track)
|
||||
{
|
||||
Track const * nTrack = NativeFramework()->GetBmCategory(category)->GetTrack(track);
|
||||
m_doLoadState = false;
|
||||
NativeFramework()->ShowTrack(*nTrack);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//============ GLUE CODE for com.mapswithme.maps.Framework class =============//
|
||||
|
@ -869,4 +876,9 @@ extern "C"
|
|||
return jLatLon;
|
||||
}
|
||||
|
||||
JNIEXPORT void Java_com_mapswithme_maps_Framework_nativeShowTrackRect(JNIEnv * env, jclass clazz, jint cat, jint track)
|
||||
{
|
||||
g_framework->ShowTrack(cat, track);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -130,6 +130,8 @@ namespace android
|
|||
void DeactivatePopup();
|
||||
|
||||
string GetOutdatedCountriesString();
|
||||
|
||||
void ShowTrack(int category, int track);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "../../Framework.hpp"
|
||||
#include "../../../../../../../map/measurement_utils.hpp"
|
||||
|
||||
#include "../../../core/jni_helper.hpp"
|
||||
|
||||
|
@ -52,7 +53,68 @@ extern "C"
|
|||
JNIEXPORT jint JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_getSize(
|
||||
JNIEnv * env, jobject thiz, jint id)
|
||||
{
|
||||
BookmarkCategory * category = getBmCategory(id);
|
||||
return category->GetBookmarksCount() + category->GetTracksCount();
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_getBookmarksCount(
|
||||
JNIEnv * env, jobject thiz, jint id)
|
||||
{
|
||||
return getBmCategory(id)->GetBookmarksCount();
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_getTracksCount(
|
||||
JNIEnv * env, jobject thiz, jint id)
|
||||
{
|
||||
return getBmCategory(id)->GetTracksCount();
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_getBookmark(
|
||||
JNIEnv * env, jobject thiz, jint id, jint index, jclass bookmarkClazz)
|
||||
{
|
||||
// Bookmark(int categoryId, int bookmarkId, String name)
|
||||
static jmethodID cId = env->GetMethodID(bookmarkClazz, "<init>", "(IILjava/lang/String;)V");
|
||||
|
||||
BookmarkCategory * category = getBmCategory(id);
|
||||
Bookmark const * nBookmark = category->GetBookmark(index);
|
||||
|
||||
ASSERT(nBookmark, ("Bookmark must not be null with index:)", index));
|
||||
|
||||
return env->NewObject(bookmarkClazz, cId,
|
||||
id, index, jni::ToJavaString(env, nBookmark->GetName()));
|
||||
}
|
||||
|
||||
static uint32_t shift(uint32_t v, uint8_t bitCount) { return v << bitCount; }
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_getTrack(
|
||||
JNIEnv * env, jobject thiz, jint id, jint index, jclass trackClazz)
|
||||
{
|
||||
// Track(int trackId, int categoryId, String name, String lengthString, int color)
|
||||
static jmethodID cId = env->GetMethodID(trackClazz, "<init>",
|
||||
"(IILjava/lang/String;Ljava/lang/String;I)V");
|
||||
|
||||
BookmarkCategory * category = getBmCategory(id);
|
||||
Track const * nTrack = category->GetTrack(index);
|
||||
|
||||
ASSERT(nTrack, ("Track must not be null with index:)", index));
|
||||
|
||||
string formattedLenght;
|
||||
MeasurementUtils::FormatDistance(nTrack->GetLengthMeters(), formattedLenght);
|
||||
|
||||
graphics::Color nColor = nTrack->GetColor();
|
||||
|
||||
jint androidColor = shift(nColor.a, 24) +
|
||||
shift(nColor.r, 16) +
|
||||
shift(nColor.g, 8) +
|
||||
nColor.b;
|
||||
|
||||
return env->NewObject(trackClazz, cId,
|
||||
index, id, jni::ToJavaString(env, nTrack->GetName()),
|
||||
jni::ToJavaString(env, formattedLenght), androidColor);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.mapswithme.maps;
|
|||
|
||||
import com.mapswithme.maps.MapStorage.Index;
|
||||
import com.mapswithme.maps.bookmarks.data.DistanceAndAzimut;
|
||||
import com.mapswithme.maps.bookmarks.data.Track;
|
||||
import com.mapswithme.maps.guides.GuideInfo;
|
||||
|
||||
/**
|
||||
|
@ -80,6 +81,12 @@ public class Framework
|
|||
nativeUpdateSavedDataVersion();
|
||||
}
|
||||
|
||||
public static void showTrackRect(Track track)
|
||||
{
|
||||
nativeShowTrackRect(track.getCategoryId(), track.getTrackId());
|
||||
}
|
||||
private static native void nativeShowTrackRect(int category, int track);
|
||||
|
||||
public native static GuideInfo getGuideInfoForIndex(Index idx);
|
||||
public native static GuideInfo[] getGuideInfosForDownloadedMaps();
|
||||
public native static void setWasAdvertised(String appId);
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.annotation.TargetApi;
|
|||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Pair;
|
||||
import android.view.ContextMenu;
|
||||
|
@ -22,7 +23,6 @@ import android.widget.Button;
|
|||
import android.widget.PopupMenu;
|
||||
import android.widget.PopupMenu.OnMenuItemClickListener;
|
||||
import android.widget.TextView;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
import com.mapswithme.maps.api.ParsedMmwRequest;
|
||||
import com.mapswithme.maps.bookmarks.BookmarkActivity;
|
||||
|
@ -84,7 +84,7 @@ public class MapObjectFragment extends Fragment
|
|||
UiUtils.show(mEditBmk);
|
||||
UiUtils.hide(mOpenWith);
|
||||
|
||||
setTexts(bookmark.getName(), null , bookmark.getCategoryName(), bookmark.getBookmarkDescription(), bookmark.getLat(), bookmark.getLon());
|
||||
setTexts(bookmark.getName(), null , bookmark.getCategoryName(getActivity()), bookmark.getBookmarkDescription(), bookmark.getLat(), bookmark.getLon());
|
||||
|
||||
final int circleSize = (int) (getResources().getDimension(R.dimen.margin_medium) + .5);
|
||||
final Drawable icon = UiUtils.drawCircleForPin(bookmark.getIcon().getType(), circleSize, getResources());
|
||||
|
|
|
@ -136,7 +136,7 @@ public class BookmarkActivity extends AbstractBookmarkActivity
|
|||
|
||||
|
||||
Utils.setStringAndCursorToEnd(mName, mPin.getName());
|
||||
mSet.setText(mPin.getCategoryName());
|
||||
mSet.setText(mPin.getCategoryName(this));
|
||||
mDescr.setText(mPin.getBookmarkDescription());
|
||||
}
|
||||
|
||||
|
@ -227,7 +227,7 @@ public class BookmarkActivity extends AbstractBookmarkActivity
|
|||
final IconsAdapter adapter = new IconsAdapter(this, mIcons);
|
||||
adapter.chooseItem(mIcons.indexOf(mPin.getIcon()));
|
||||
|
||||
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
||||
final LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
||||
final int padSide = (int) getResources().getDimension(R.dimen.dp_x_8);
|
||||
final int padTopB = (int) getResources().getDimension(R.dimen.dp_x_6);
|
||||
|
||||
|
@ -264,7 +264,7 @@ public class BookmarkActivity extends AbstractBookmarkActivity
|
|||
if (requestCode == REQUEST_CODE_SET && resultCode == RESULT_OK)
|
||||
{
|
||||
|
||||
Point pin = ((ParcelablePoint)data.getParcelableExtra(PIN)).getPoint();
|
||||
final Point pin = ((ParcelablePoint)data.getParcelableExtra(PIN)).getPoint();
|
||||
mPin = mManager.getBookmark(pin.x, pin.y);
|
||||
refreshValuesInViews();
|
||||
|
||||
|
|
|
@ -19,12 +19,14 @@ import android.widget.AdapterView.OnItemClickListener;
|
|||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
||||
import com.mapswithme.maps.Framework;
|
||||
import com.mapswithme.maps.MWMActivity;
|
||||
import com.mapswithme.maps.MWMApplication;
|
||||
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.ParcelablePoint;
|
||||
import com.mapswithme.maps.bookmarks.data.Track;
|
||||
import com.mapswithme.util.ShareAction;
|
||||
import com.mapswithme.util.Utils;
|
||||
|
||||
|
@ -60,19 +62,22 @@ public class BookmarkListActivity extends AbstractBookmarkListActivity
|
|||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
|
||||
{
|
||||
|
||||
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);
|
||||
final Bookmark bmk = (Bookmark) mPinAdapter.getItem(position);
|
||||
mManager.showBookmarkOnMap(setIndex, bmk.getBookmarkId());
|
||||
}
|
||||
else
|
||||
{
|
||||
Utils.toastShortcut(BookmarkListActivity.this, mEditedSet.getTrack(position).getName() + position);
|
||||
// TODO show map
|
||||
final Track track = (Track) mPinAdapter.getItem(position);
|
||||
Framework.showTrackRect(track);
|
||||
}
|
||||
|
||||
final Intent i = new Intent(BookmarkListActivity.this, MWMActivity.class);
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
startActivity(i);
|
||||
}
|
||||
});
|
||||
registerForContextMenu(getListView());
|
||||
|
|
|
@ -72,7 +72,7 @@ public class BookmarkListAdapter extends BaseAdapter implements LocationService.
|
|||
final PinHolder holder = (PinHolder) convertView.getTag();
|
||||
|
||||
if (type == TYPE_BMK)
|
||||
holder.set(mCategory.getBookmark(position));
|
||||
holder.set(mCategory.getBookmark(position - mCategory.getTracksCount()));
|
||||
else
|
||||
holder.set(mCategory.getTrack(position));
|
||||
|
||||
|
@ -86,9 +86,12 @@ public class BookmarkListAdapter extends BaseAdapter implements LocationService.
|
|||
}
|
||||
|
||||
@Override
|
||||
public Bookmark getItem(int position)
|
||||
public Object getItem(int position)
|
||||
{
|
||||
return mCategory.getBookmark(position);
|
||||
if (getItemViewType(position) == TYPE_TRACK)
|
||||
return mCategory.getTrack(position);
|
||||
else
|
||||
return mCategory.getBookmark(position - mCategory.getTracksCount());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -8,8 +8,7 @@ import com.mapswithme.maps.R;
|
|||
|
||||
public class Bookmark extends MapObject
|
||||
{
|
||||
private Icon mIcon;
|
||||
private Context mContext;
|
||||
private final Icon mIcon;
|
||||
private int mCategoryId;
|
||||
private int mBookmark;
|
||||
private double mMerX;
|
||||
|
@ -17,18 +16,21 @@ public class Bookmark extends MapObject
|
|||
private double mLon;
|
||||
private double mLat;
|
||||
|
||||
//{@ Populate on creation or lazily?
|
||||
private String mName;
|
||||
//{@
|
||||
|
||||
Bookmark(Context context, int c, int b)
|
||||
|
||||
/* package */ Bookmark(int categoryId, int bookmarkId, String name)
|
||||
{
|
||||
mContext = context.getApplicationContext();
|
||||
mCategoryId = c;
|
||||
mBookmark = b;
|
||||
mCategoryId = categoryId;
|
||||
mBookmark = bookmarkId;
|
||||
mName = name;
|
||||
mIcon = getIconInternal();
|
||||
getXY();
|
||||
}
|
||||
|
||||
private native ParcelablePointD getXY(int c, long b);
|
||||
private native String getName(int c, long b);
|
||||
private native String getIcon(int c, long b);
|
||||
|
||||
private native double getScale(int category, long bookmark);
|
||||
|
@ -47,7 +49,7 @@ public class Bookmark extends MapObject
|
|||
|
||||
private void getXY()
|
||||
{
|
||||
ParcelablePointD ll = getXY(mCategoryId, mBookmark);
|
||||
final ParcelablePointD ll = getXY(mCategoryId, mBookmark);
|
||||
mMerX = ll.x;
|
||||
mMerY = ll.y;
|
||||
|
||||
|
@ -70,7 +72,7 @@ public class Bookmark extends MapObject
|
|||
|
||||
private Icon getIconInternal()
|
||||
{
|
||||
return BookmarkManager.getBookmarkManager(mContext).getIconByName((mCategoryId >= 0) ? getIcon(mCategoryId, mBookmark) : "");
|
||||
return BookmarkManager.getBookmarkManager().getIconByName((mCategoryId >= 0) ? getIcon(mCategoryId, mBookmark) : "");
|
||||
}
|
||||
|
||||
public Icon getIcon()
|
||||
|
@ -81,26 +83,19 @@ public class Bookmark extends MapObject
|
|||
@Override
|
||||
public String getName()
|
||||
{
|
||||
if (mCategoryId >= 0 && BookmarkManager.getBookmarkManager(mContext).getCategoryById(mCategoryId).getSize() > mBookmark)
|
||||
{
|
||||
return getName(mCategoryId, mBookmark);
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return mName;
|
||||
}
|
||||
|
||||
public String getCategoryName()
|
||||
public String getCategoryName(Context context)
|
||||
{
|
||||
if (mCategoryId >= 0)
|
||||
{
|
||||
return BookmarkManager.getBookmarkManager(mContext).getCategoryById(mCategoryId).getName();
|
||||
return BookmarkManager.getBookmarkManager().getCategoryById(mCategoryId).getName();
|
||||
}
|
||||
else
|
||||
{
|
||||
mCategoryId = 0;
|
||||
return mContext.getString(R.string.my_places);
|
||||
return context.getString(R.string.my_places);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -119,7 +114,10 @@ public class Bookmark extends MapObject
|
|||
icon = mIcon;
|
||||
|
||||
if (!name.equals(getName()) || icon != mIcon || !descr.equals(getBookmarkDescription()))
|
||||
{
|
||||
setBookmarkParams(mCategoryId, mBookmark, name, icon.getType(), descr);
|
||||
mName = name;
|
||||
}
|
||||
}
|
||||
|
||||
public int getCategoryId()
|
||||
|
|
|
@ -8,20 +8,13 @@ public class BookmarkCategory
|
|||
private final int mId;
|
||||
private String mName;
|
||||
private final Context mContext;
|
||||
|
||||
BookmarkCategory(Context c, int id)
|
||||
{
|
||||
mContext = c;
|
||||
mId = id;
|
||||
}
|
||||
|
||||
private native boolean isVisible(int id);
|
||||
private native void setVisibility(int id, boolean v);
|
||||
|
||||
private native String getName(int id);
|
||||
private native void setName(int old, String n);
|
||||
|
||||
private native int getSize(int id);
|
||||
|
||||
public int getId()
|
||||
{
|
||||
return mId;
|
||||
|
@ -50,26 +43,39 @@ public class BookmarkCategory
|
|||
|
||||
public int getSize()
|
||||
{
|
||||
return getBookmarksCount() + getTracksCount();
|
||||
return getSize(mId);
|
||||
}
|
||||
|
||||
public int getBookmarksCount()
|
||||
{
|
||||
return getSize(mId);
|
||||
return getBookmarksCount(mId);
|
||||
}
|
||||
|
||||
public int getTracksCount()
|
||||
{
|
||||
return 3; //TODO add native
|
||||
return getTracksCount(mId);
|
||||
}
|
||||
|
||||
public Bookmark getBookmark(int b)
|
||||
public Bookmark getBookmark(int index)
|
||||
{
|
||||
return new Bookmark(mContext, mId, b - 3); //TODO remove - 3
|
||||
return getBookmark(mId, index, Bookmark.class);
|
||||
}
|
||||
|
||||
public Track getTrack(int index)
|
||||
{
|
||||
return new Track(); // TODO: add native
|
||||
return getTrack(mId, index, Track.class);
|
||||
}
|
||||
|
||||
private native int getBookmarksCount(int id);
|
||||
private native int getTracksCount(int id);
|
||||
private native int getSize(int id);
|
||||
|
||||
private native Bookmark getBookmark(int id, int index, Class<Bookmark> bookmarkClazz);
|
||||
private native Track getTrack(int id, int index, Class<Track> trackClazz);
|
||||
|
||||
private native boolean isVisible(int id);
|
||||
private native void setVisibility(int id, boolean v);
|
||||
|
||||
private native String getName(int id);
|
||||
private native void setName(int old, String n);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.content.Context;
|
|||
import android.graphics.Point;
|
||||
import android.util.Pair;
|
||||
|
||||
import com.mapswithme.maps.MWMApplication;
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
|
||||
public class BookmarkManager
|
||||
|
@ -14,8 +15,8 @@ public class BookmarkManager
|
|||
private static BookmarkManager sManager;
|
||||
private List<Bookmark> mPins;
|
||||
private List<BookmarkCategory> mPinSets;
|
||||
private Context mContext;
|
||||
private BookmarkIconManager mIconManager;
|
||||
private final Context mContext;
|
||||
private final BookmarkIconManager mIconManager;
|
||||
|
||||
private BookmarkManager(Context context)
|
||||
{
|
||||
|
@ -31,6 +32,11 @@ public class BookmarkManager
|
|||
return sManager;
|
||||
}
|
||||
|
||||
public static BookmarkManager getBookmarkManager()
|
||||
{
|
||||
return getBookmarkManager(MWMApplication.get());
|
||||
}
|
||||
|
||||
private native void loadBookmarks();
|
||||
|
||||
public void deleteBookmark(Bookmark bmk)
|
||||
|
@ -81,7 +87,7 @@ public class BookmarkManager
|
|||
|
||||
public Bookmark getBookmark(int cat, int bmk)
|
||||
{
|
||||
return new Bookmark(mContext, cat, bmk);
|
||||
return getCategoryById(cat).getBookmark(bmk);
|
||||
}
|
||||
|
||||
private native int createCategory(String name);
|
||||
|
|
|
@ -1,13 +1,31 @@
|
|||
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; }
|
||||
//{@ Populate on create
|
||||
private final int mTrackId;
|
||||
private final int mCategoryId;
|
||||
private final String mName;
|
||||
private final String mLengthString;
|
||||
private final int mColor;
|
||||
//}@
|
||||
|
||||
|
||||
/* package */ Track(int trackId, int categoryId, String name, String lengthString, int color)
|
||||
{
|
||||
mTrackId = trackId;
|
||||
mCategoryId = categoryId;
|
||||
mName = name;
|
||||
mLengthString = lengthString;
|
||||
mColor = color;
|
||||
}
|
||||
|
||||
public String getName() { return mName; }
|
||||
public String getLengthString() { return mLengthString;}
|
||||
public int getColor() { return mColor; }
|
||||
|
||||
public int getTrackId() { return mTrackId; }
|
||||
public int getCategoryId() { return mCategoryId; }
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue