Bookmark refactoring & adaptation for new PP.

This commit is contained in:
Dmitry Yunitsky 2015-02-17 15:38:39 +03:00 committed by Alex Zolotarev
parent f22a7e46c6
commit 021ddcc103
25 changed files with 387 additions and 331 deletions

View file

@ -117,14 +117,13 @@ public class MonkeyEventsReceiver extends BroadcastReceiver
@Override
public boolean run(final MWMActivity target)
{
final BookmarkManager bmkManager = BookmarkManager.getBookmarkManager();
final int categoriesCount = bmkManager.getCategoriesCount();
final int categoriesCount = BookmarkManager.INSTANCE.getCategoriesCount();
// find category
BookmarkCategory categoryToShow = null;
for (int i = 0; i < categoriesCount; i++)
{
categoryToShow = bmkManager.getCategoryById(i);
categoryToShow = BookmarkManager.INSTANCE.getCategoryById(i);
if (categoryToShow.getName().contains(mName))
break;
else
@ -159,12 +158,12 @@ public class MonkeyEventsReceiver extends BroadcastReceiver
// bring foreground
mActivity.startActivity(new Intent(mActivity, MWMActivity.class));
final Bookmark bookmark = bmkManager.getBookmark(mCatId, mBmkId);
final BookmarkCategory category = bmkManager.getCategoryById(mCatId);
final Bookmark bookmark = BookmarkManager.INSTANCE.getBookmark(mCatId, mBmkId);
final BookmarkCategory category = BookmarkManager.INSTANCE.getCategoryById(mCatId);
final String desc = bookmark.getBookmarkDescription();
// Center camera at bookmark
bmkManager.showBookmarkOnMap(mCatId, mBmkId);
BookmarkManager.INSTANCE.showBookmarkOnMap(mCatId, mBmkId);
// N2DP (Nataha to Dmitry Protocol)
// Bookmark has no description: show map

View file

@ -43,7 +43,7 @@
<EditText
android:id="@+id/pin_name"
style="@style/PinEditableParam"
style="@style/PlaceEditableParam"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
@ -74,7 +74,7 @@
<TextView
android:id="@+id/pin_set_chooser"
style="@style/PinEditableParam"
style="@style/PlaceEditableParam"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="@dimen/dp_x_4"
@ -94,7 +94,7 @@
<EditText
android:id="@+id/pin_description"
style="@style/PinEditableParam"
style="@style/PlaceEditableParam"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/description"/>

View file

@ -93,13 +93,6 @@
android:scaleType="center"
android:src="@drawable/ic_bookmark_off"/>
<ProgressBar
android:id="@+id/pb__routing_progress"
android:layout_width="@dimen/routing_progress_size"
android:layout_height="@dimen/routing_progress_size"
android:layout_centerInParent="true"
android:visibility="gone"/>
<TextView
android:id="@+id/tv__bookmark"
android:layout_width="wrap_content"
@ -132,6 +125,13 @@
android:scaleType="center"
android:src="@drawable/ic_route"/>
<ProgressBar
android:id="@+id/pb__routing_progress"
android:layout_width="@dimen/routing_progress_size"
android:layout_height="@dimen/routing_progress_size"
android:layout_centerInParent="true"
android:visibility="gone"/>
<TextView
android:id="@+id/tv__route"
android:layout_width="wrap_content"

View file

@ -1,24 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/dp_x_1"
android:background="@null" >
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/clickableBackground"
android:padding="@dimen/margin_small">
<ImageView
android:id="@+id/row_color_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@null"
android:padding="@dimen/dp_x_1"
android:scaleType="centerInside" />
<ImageView
android:id="@+id/selected_mark"
android:layout_width="@dimen/dp_x_8"
android:layout_height="@dimen/dp_x_8"
android:layout_centerInParent="true"
android:background="@null" />
<ImageView
android:id="@+id/iv__color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@null"
android:contentDescription="@null"
android:scaleType="center"/>
</RelativeLayout>

View file

@ -40,8 +40,11 @@
android:id="@+id/ll__place_phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_medium"
android:orientation="horizontal">
android:layout_marginTop="@dimen/margin_small"
android:background="?attr/clickableBackground"
android:orientation="horizontal"
android:paddingBottom="@dimen/margin_small"
android:paddingTop="@dimen/margin_small">
<ImageView
android:id="@+id/iv__place_phone"
@ -64,8 +67,10 @@
android:id="@+id/ll__place_website"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_medium"
android:orientation="horizontal">
android:background="?attr/clickableBackground"
android:orientation="horizontal"
android:paddingBottom="@dimen/margin_small"
android:paddingTop="@dimen/margin_small">
<ImageView
android:id="@+id/iv__place_website"
@ -87,8 +92,10 @@
android:id="@+id/ll__place_schedule"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_medium"
android:orientation="horizontal">
android:background="?attr/clickableBackground"
android:orientation="horizontal"
android:paddingBottom="@dimen/margin_small"
android:paddingTop="@dimen/margin_small">
<ImageView
android:id="@+id/iv__place_schedule"
@ -110,8 +117,10 @@
android:id="@+id/ll__place_latlon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_medium"
android:orientation="horizontal">
android:background="?attr/clickableBackground"
android:orientation="horizontal"
android:paddingBottom="@dimen/margin_small"
android:paddingTop="@dimen/margin_small">
<ImageView
android:id="@+id/iv__place_latlon"
@ -183,30 +192,33 @@
android:textColor="@color/text_place_page_subtitle"
android:textSize="@dimen/place_page_sub_subtitle"/>
<TextView
android:id="@+id/tv__bookmark_name"
<EditText
android:id="@+id/et__bookmark_name"
style="@style/PlaceEditableParam"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tv__bookmark_title"
android:layout_marginTop="@dimen/margin_tiny"
android:layout_toRightOf="@id/iv__bookmark"
android:hint="@string/name"
android:inputType="textCapWords"
android:lineSpacingMultiplier="1.43"
android:text="Great bookmark"
android:singleLine="true"
android:textColor="@color/text_place_page"
android:textSize="@dimen/place_page_subtitle"/>
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_below="@id/tv__bookmark_name"
android:layout_marginTop="@dimen/margin_medium_and_half"
android:layout_below="@id/et__bookmark_name"
android:layout_marginTop="@dimen/margin_small"
android:background="?attr/dividerHorizontal"/>
<TextView
android:id="@+id/tv__bookmark_group_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tv__bookmark_name"
android:layout_below="@id/et__bookmark_name"
android:layout_marginTop="@dimen/margin_medium_and_half"
android:layout_toRightOf="@id/iv__bookmark"
android:lineSpacingMultiplier="1.67"
@ -237,6 +249,7 @@
android:textSize="@dimen/place_page_subtitle"/>
<ImageView
android:id="@+id/iv__bookmark_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_medium"
@ -247,7 +260,7 @@
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_below="@id/ll__group"
android:layout_marginTop="@dimen/margin_medium_and_half"
android:layout_marginTop="@dimen/margin_small"
android:background="?android:attr/listDivider"/>
<TextView
@ -264,14 +277,17 @@
<EditText
android:id="@+id/et__bookmark_notes"
style="@style/PlaceEditableParam"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tv__bookmark_notes_title"
android:layout_marginTop="@dimen/margin_tiny"
android:layout_toRightOf="@id/iv__bookmark"
android:background="@null"
android:hint="Notes"
android:inputType="text"
android:lineSpacingMultiplier="1.43"
android:text="Enter notes here"
android:singleLine="true"
android:textColor="@color/text_place_page"
android:textSize="@dimen/place_page_subtitle"/>
</RelativeLayout>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<GridView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/margin_small"
android:gravity="center"
android:numColumns="4"/>

View file

@ -81,13 +81,8 @@
<item name="android:textStyle">bold</item>
</style>
<style name="PinEditableParam" parent="Widget.AppCompat.EditText">
<style name="PlaceEditableParam" parent="Widget.AppCompat.EditText">
<item name="android:imeOptions">actionDone</item>
<item name="android:textSize">@dimen/sp_x_4</item>
<item name="colorPrimary">@color/green</item>
<item name="colorPrimaryDark">@color/semitransparent_black</item>
<item name="colorAccent">@color/downloader_red</item>
</style>
<style name="DrawerSeparatorNoPadding">

View file

@ -115,12 +115,14 @@ public class MWMActivity extends NvEventQueueActivity
private ImageButton mLocationButton;
// Place page
private PlacePageView mPlacePage;
private View mIvStartRouting;
private View mRlStartRouting;
private ProgressBar mPbRoutingProgress;
private TextView mTvStartRouting;
private ImageView mIvStartRouting;
// Routing
private TextView mTvRoutingDistance;
private RelativeLayout mRlRoutingBox;
private RelativeLayout mLayoutRoutingGo;
private ProgressBar mPbRoutingProgress;
private RelativeLayout mRlTurnByTurnBox;
private TextView mTvTotalDistance;
private TextView mTvTotalTime;
@ -144,7 +146,6 @@ public class MWMActivity extends NvEventQueueActivity
private static final String IS_KML_MOVED = "KmlBeenMoved";
private static final String IS_KITKAT_MIGRATION_COMPLETED = "KitKatMigrationCompleted";
// for routing
private static final String IS_FIRST_ROUTING_VERSION_RUN = "IsFirstRoutingRun";
private static final String IS_ROUTING_DISCLAIMER_APPROVED = "IsDisclaimerApproved";
// ads in vertical toolbar
private static final String MENU_ADS_ENABLED = "MenuLinksEnabled";
@ -808,9 +809,11 @@ public class MWMActivity extends NvEventQueueActivity
{
mPlacePage = (PlacePageView) findViewById(R.id.info_box);
mPlacePage.setOnVisibilityChangedListener(this);
mIvStartRouting = mPlacePage.findViewById(R.id.rl__route);
mIvStartRouting.setOnClickListener(this);
mPbRoutingProgress = (ProgressBar) mPlacePage.findViewById(R.id.pb__routing_progress);
mRlStartRouting = mPlacePage.findViewById(R.id.rl__route);
mRlStartRouting.setOnClickListener(this);
mTvStartRouting = (TextView) mRlStartRouting.findViewById(R.id.tv__route);
mIvStartRouting = (ImageView) mRlStartRouting.findViewById(R.id.iv__route);
mPbRoutingProgress = (ProgressBar) mRlStartRouting.findViewById(R.id.pb__routing_progress);
}
private void setUpRoutingBox()
@ -1323,6 +1326,7 @@ public class MWMActivity extends NvEventQueueActivity
mPlacePage.setMapObject(apiPoint);
mPlacePage.setState(State.PREVIEW_ONLY);
mIvStartRouting.setVisibility(View.VISIBLE);
mTvStartRouting.setVisibility(View.VISIBLE);
mPbRoutingProgress.setVisibility(View.GONE);
if (popFragment() && isMapFaded())
fadeMap(FADE_VIEW_ALPHA, 0);
@ -1348,6 +1352,7 @@ public class MWMActivity extends NvEventQueueActivity
mPlacePage.setMapObject(poi);
mPlacePage.setState(State.PREVIEW_ONLY);
mIvStartRouting.setVisibility(View.VISIBLE);
mTvStartRouting.setVisibility(View.VISIBLE);
mPbRoutingProgress.setVisibility(View.GONE);
if (popFragment() && isMapFaded())
fadeMap(FADE_VIEW_ALPHA, 0);
@ -1365,12 +1370,13 @@ public class MWMActivity extends NvEventQueueActivity
public void run()
{
mPlacePage.bringToFront();
final Bookmark b = BookmarkManager.getBookmarkManager().getBookmark(category, bookmarkIndex);
final Bookmark b = BookmarkManager.INSTANCE.getBookmark(category, bookmarkIndex);
if (!mPlacePage.hasMapObject(b))
{
mPlacePage.setMapObject(b);
mPlacePage.setState(State.PREVIEW_ONLY);
mIvStartRouting.setVisibility(View.VISIBLE);
mTvStartRouting.setVisibility(View.VISIBLE);
mPbRoutingProgress.setVisibility(View.GONE);
if (popFragment() && isMapFaded())
fadeMap(FADE_VIEW_ALPHA, 0);
@ -1397,6 +1403,7 @@ public class MWMActivity extends NvEventQueueActivity
mPlacePage.setMapObject(mypos);
mPlacePage.setState(State.PREVIEW_ONLY);
mIvStartRouting.setVisibility(View.GONE);
mTvStartRouting.setVisibility(View.GONE);
mPbRoutingProgress.setVisibility(View.GONE);
if (popFragment() && isMapFaded())
fadeMap(FADE_VIEW_ALPHA, 0);
@ -1420,8 +1427,9 @@ public class MWMActivity extends NvEventQueueActivity
{
mPlacePage.setMapObject(sr);
mPlacePage.setState(State.PREVIEW_ONLY);
mPbRoutingProgress.setVisibility(View.GONE);
mIvStartRouting.setVisibility(View.VISIBLE);
mTvStartRouting.setVisibility(View.VISIBLE);
mPbRoutingProgress.setVisibility(View.GONE);
if (popFragment() && isMapFaded())
fadeMap(FADE_VIEW_ALPHA, 0);
}
@ -1500,7 +1508,7 @@ public class MWMActivity extends NvEventQueueActivity
setVerticalToolbarVisible(false);
showDownloader(false);
break;
case R.id.iv__start_routing:
case R.id.rl__route:
buildRoute();
break;
case R.id.iv__routing_close:
@ -1543,7 +1551,8 @@ public class MWMActivity extends NvEventQueueActivity
final MapObject mapObject = mPlacePage.getMapObject();
if (mapObject != null)
{
mIvStartRouting.setVisibility(View.INVISIBLE);
mIvStartRouting.setVisibility(View.GONE);
mTvStartRouting.setVisibility(View.GONE);
mPbRoutingProgress.setVisibility(View.VISIBLE);
Framework.nativeBuildRoute(mapObject.getLat(), mapObject.getLon());
}
@ -1583,7 +1592,7 @@ public class MWMActivity extends NvEventQueueActivity
mPlacePage.bringToFront();
mRlRoutingBox.clearAnimation();
UiUtils.hide(mRlRoutingBox, mPbRoutingProgress, mRlTurnByTurnBox);
mIvStartRouting.setVisibility(View.VISIBLE);
mRlStartRouting.setVisibility(View.VISIBLE);
Framework.nativeCloseRouting();
}

View file

@ -133,7 +133,7 @@ public class MWMApplication extends android.app.Application implements ActiveCou
nativeAddLocalization("routing_failed_internal_error", getString(R.string.routing_failed_internal_error));
// init BookmarkManager (automatically loads bookmarks)
BookmarkManager.getBookmarkManager();
BookmarkManager.INSTANCE.getIcons();
}
private void initMrgs()

View file

@ -8,13 +8,11 @@ import com.mapswithme.maps.bookmarks.data.BookmarkManager;
public abstract class AbstractBookmarkCategoryAdapter extends BaseAdapter
{
private final BookmarkManager mManager;
private final Context mContext;
public AbstractBookmarkCategoryAdapter(Context context)
{
mContext = context;
mManager = BookmarkManager.getBookmarkManager();
}
protected Context getContext()
@ -22,15 +20,10 @@ public abstract class AbstractBookmarkCategoryAdapter extends BaseAdapter
return mContext;
}
protected BookmarkManager getBookmarkManager()
{
return mManager;
}
@Override
public int getCount()
{
return mManager.getCategoriesCount();
return BookmarkManager.INSTANCE.getCategoriesCount();
}
@Override
@ -42,6 +35,6 @@ public abstract class AbstractBookmarkCategoryAdapter extends BaseAdapter
@Override
public BookmarkCategory getItem(int position)
{
return getBookmarkManager().getCategoryById(position);
return BookmarkManager.INSTANCE.getCategoryById(position);
}
}

View file

@ -61,7 +61,7 @@ public class BookmarkActivity extends MWMFragmentActivity
// (category index, bookmark index in category).
final Point cab = ((ParcelablePoint) getIntent().getParcelableExtra(PIN)).getPoint();
mManager = BookmarkManager.getBookmarkManager();
mManager = BookmarkManager.INSTANCE;
mPin = mManager.getBookmark(cab.x, cab.y);
mCurrentCategoryId = mPin.getCategoryId();

View file

@ -11,6 +11,7 @@ import android.widget.TextView;
import com.mapswithme.maps.R;
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
public class BookmarkCategoriesAdapter extends AbstractBookmarkCategoryAdapter
{
@ -68,8 +69,7 @@ public class BookmarkCategoriesAdapter extends AbstractBookmarkCategoryAdapter
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
BookmarkCategoriesAdapter.this
.getBookmarkManager()
BookmarkManager.INSTANCE
.getCategoryById(holder.categoryId)
.setVisibility(isChecked);
}

View file

@ -45,7 +45,7 @@ public class BookmarkCategoriesFragment extends MWMListFragment
{
mSelectedPosition = ((AdapterView.AdapterContextMenuInfo) menuInfo).position;
getActivity().getMenuInflater().inflate(R.menu.bookmark_categories_context_menu, menu);
menu.setHeaderTitle(BookmarkManager.getBookmarkManager().getCategoryById(mSelectedPosition).getName());
menu.setHeaderTitle(BookmarkManager.INSTANCE.getCategoryById(mSelectedPosition).getName());
}
@Override
@ -53,7 +53,7 @@ public class BookmarkCategoriesFragment extends MWMListFragment
{
if (item.getItemId() == R.id.set_delete)
{
BookmarkManager.getBookmarkManager().deleteCategory(mSelectedPosition);
BookmarkManager.INSTANCE.deleteCategory(mSelectedPosition);
((BookmarkCategoriesAdapter) getListAdapter()).notifyDataSetChanged();
}

View file

@ -189,7 +189,7 @@ public class BookmarkListAdapter extends BaseAdapter
final Location loc = LocationHelper.INSTANCE.getLastLocation();
if (loc != null)
{
final DistanceAndAzimut daa = bmk.getDistanceAndAzimut(loc.getLatitude(), loc.getLongitude(), 0.0);
final DistanceAndAzimut daa = bmk.getDistanceAndAzimuth(loc.getLatitude(), loc.getLongitude(), 0.0);
distance.setText(daa.getDistance());
}
else

View file

@ -36,7 +36,6 @@ public class BookmarksListFragment extends MWMListFragment
{
public static final String TAG = "BookmarkListActivity";
private BookmarkManager mManager;
private EditText mSetName;
private BookmarkCategory mEditedSet;
private int mSelectedPosition;
@ -69,11 +68,9 @@ public class BookmarksListFragment extends MWMListFragment
{
super.onCreate(savedInstanceState);
mManager = BookmarkManager.getBookmarkManager();
// Initialize with passed edited set.
mIndex = getArguments().getInt(BookmarkActivity.PIN_SET, -1);
mEditedSet = mManager.getCategoryById(mIndex);
mEditedSet = BookmarkManager.INSTANCE.getCategoryById(mIndex);
}
@Override
@ -85,7 +82,7 @@ public class BookmarksListFragment extends MWMListFragment
return;
case BookmarkListAdapter.TYPE_BMK:
final Bookmark bmk = (Bookmark) mPinAdapter.getItem(position);
mManager.showBookmarkOnMap(mIndex, bmk.getBookmarkId());
BookmarkManager.INSTANCE.showBookmarkOnMap(mIndex, bmk.getBookmarkId());
break;
case BookmarkListAdapter.TYPE_TRACK:
final Track track = (Track) mPinAdapter.getItem(position);
@ -111,7 +108,7 @@ public class BookmarksListFragment extends MWMListFragment
{
final String name = mSetName.getText().toString();
if (!name.equals(mEditedSet.getName()))
mManager.setCategoryName(mEditedSet, name);
BookmarkManager.INSTANCE.setCategoryName(mEditedSet, name);
}
private void setUpViews(ViewGroup root)
@ -186,7 +183,7 @@ public class BookmarksListFragment extends MWMListFragment
}
else if (itemId == R.id.set_delete)
{
mManager.deleteBookmark((Bookmark) obj);
BookmarkManager.INSTANCE.deleteBookmark((Bookmark) obj);
mPinAdapter.notifyDataSetChanged();
}
else if (ShareAction.ACTIONS.containsKey(itemId))
@ -196,7 +193,7 @@ public class BookmarksListFragment extends MWMListFragment
}
else if (itemId == MENU_DELETE_TRACK)
{
mManager.deleteTrack((Track) obj);
BookmarkManager.INSTANCE.deleteTrack((Track) obj);
mPinAdapter.notifyDataSetChanged();
}
@ -240,7 +237,7 @@ public class BookmarksListFragment extends MWMListFragment
assignCategoryParams();
String path = MWMApplication.get().getTempPath();
final String name = mManager.saveToKMZFile(mEditedSet.getId(), path);
final String name = BookmarkManager.INSTANCE.saveToKMZFile(mEditedSet.getId(), path);
if (name == null)
{
// some error occurred

View file

@ -58,7 +58,7 @@ public class ChooseBookmarkCategoryFragment extends MWMListFragment
// Note that Point result from the intent is actually a pair
// of (category index, bookmark index in category).
final Point cab = ((ParcelablePoint) getArguments().getParcelable(BookmarkActivity.PIN)).getPoint();
return BookmarkManager.getBookmarkManager().getBookmark(cab.x, cab.y);
return BookmarkManager.INSTANCE.getBookmark(cab.x, cab.y);
}
private class FooterHelper implements View.OnClickListener
@ -117,7 +117,7 @@ public class ChooseBookmarkCategoryFragment extends MWMListFragment
private void createCategory(String name)
{
final int index = BookmarkManager.getBookmarkManager().createCategory(getBookmarkFromIntent(), name);
final int index = BookmarkManager.INSTANCE.createCategory(getBookmarkFromIntent(), name);
getActivity().getIntent().putExtra(BookmarkActivity.PIN_SET, index)
.putExtra(BookmarkActivity.PIN, new ParcelablePoint(index, 0));

View file

@ -1,7 +1,6 @@
package com.mapswithme.maps.bookmarks;
import android.content.Context;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -10,14 +9,12 @@ import android.widget.ImageView;
import com.mapswithme.maps.R;
import com.mapswithme.maps.bookmarks.data.Icon;
import com.mapswithme.util.UiUtils;
import java.util.List;
/// SingleChoise list view don't add radio button to custom view.
public class IconsAdapter extends ArrayAdapter<Icon>
{
private int mCheckedPosition = 0;
private String mCheckedIconType;
public IconsAdapter(Context context, List<Icon> list)
{
@ -27,26 +24,22 @@ public class IconsAdapter extends ArrayAdapter<Icon>
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
final Resources res = getContext().getResources();
SpinnerViewHolder holder;
if (convertView == null)
{
LayoutInflater inflater = LayoutInflater.from(getContext());
convertView = inflater.inflate(R.layout.color_row, parent, false);
convertView.setTag(new SpinnerViewHolder((ImageView) convertView.findViewById(R.id.row_color_image),
(ImageView) convertView.findViewById(R.id.selected_mark)));
}
SpinnerViewHolder holder = (SpinnerViewHolder) convertView.getTag();
if (position == mCheckedPosition)
{
UiUtils.show(holder.tick);
holder.tick.setImageDrawable(
UiUtils.drawCircle(0xCCFFFFFF, (int) res.getDimension(R.dimen.dp_x_8), res));
holder = new SpinnerViewHolder(convertView);
convertView.setTag(holder);
}
else
UiUtils.hide(holder.tick);
holder = (SpinnerViewHolder) convertView.getTag();
holder.icon.setImageDrawable(
UiUtils.drawCircleForPin(getItem(position).getType(), (int) res.getDimension(R.dimen.dp_x_16), res));
final Icon icon = getItem(position);
if (icon.getType().equals(mCheckedIconType))
holder.icon.setImageResource(getItem(position).getSelectedResId());
else
holder.icon.setImageResource(getItem(position).getResId());
return convertView;
}
@ -54,23 +47,16 @@ public class IconsAdapter extends ArrayAdapter<Icon>
private class SpinnerViewHolder
{
ImageView icon;
ImageView tick;
public SpinnerViewHolder(ImageView icon, ImageView tick)
public SpinnerViewHolder(View convertView)
{
this.icon = icon;
this.tick = tick;
icon = (ImageView) convertView.findViewById(R.id.iv__color);
}
}
public void chooseItem(int position)
public void chooseItem(String position)
{
mCheckedPosition = position;
mCheckedIconType = position;
notifyDataSetChanged();
}
public int getCheckedItemPosition()
{
return mCheckedPosition;
}
}

View file

@ -14,7 +14,7 @@ public class Bookmark extends MapObject
private double mMerX;
private double mMerY;
/* package */ Bookmark(int categoryId, int bookmarkId, String name)
Bookmark(int categoryId, int bookmarkId, String name)
{
super(name, 0, 0, "");
@ -57,7 +57,7 @@ public class Bookmark extends MapObject
mLon = ll.x;
}
public DistanceAndAzimut getDistanceAndAzimut(double cLat, double cLon, double north)
public DistanceAndAzimut getDistanceAndAzimuth(double cLat, double cLon, double north)
{
return Framework.nativeGetDistanceAndAzimut(mMerX, mMerY, cLat, cLon, north);
}
@ -70,8 +70,7 @@ public class Bookmark extends MapObject
private Icon getIconInternal()
{
return BookmarkManager.getBookmarkManager()
.getIconByName((mCategoryId >= 0) ? getIcon(mCategoryId, mBookmark) : "");
return BookmarkManager.INSTANCE.getIconByType((mCategoryId >= 0) ? getIcon(mCategoryId, mBookmark) : "");
}
public Icon getIcon()
@ -89,7 +88,7 @@ public class Bookmark extends MapObject
{
if (mCategoryId >= 0)
{
return BookmarkManager.getBookmarkManager().getCategoryById(mCategoryId).getName();
return BookmarkManager.INSTANCE.getCategoryById(mCategoryId).getName();
}
else
{
@ -153,6 +152,6 @@ public class Bookmark extends MapObject
@Override
public String getPoiTypeName()
{
return BookmarkManager.getBookmarkManager().getCategoryById(mCategoryId).getName();
return BookmarkManager.INSTANCE.getCategoryById(mCategoryId).getName();
}
}

View file

@ -1,27 +0,0 @@
package com.mapswithme.maps.bookmarks.data;
import java.util.HashMap;
public class BookmarkIconManager
{
private static String[] ICONS = {
"placemark-red", "placemark-blue", "placemark-purple", "placemark-yellow",
"placemark-pink", "placemark-brown", "placemark-green", "placemark-orange"
};
static Icon getIcon(String type)
{
return new Icon(type, type);
}
static HashMap<String, Icon> getAll()
{
final HashMap<String, Icon> all = new HashMap<String, Icon>();
for (int i = 0; i < ICONS.length; i++)
{
all.put(ICONS[i], getIcon(ICONS[i]));
}
return all;
}
}

View file

@ -2,27 +2,32 @@ package com.mapswithme.maps.bookmarks.data;
import android.util.Pair;
import com.mapswithme.maps.R;
import com.mapswithme.util.statistics.Statistics;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class BookmarkManager
public enum BookmarkManager
{
private static BookmarkManager sManager;
INSTANCE;
private static Icon[] sIcons = {
new Icon("placemark-red", "placemark-red", R.drawable.color_picker_red_off, R.drawable.color_picker_red_on),
new Icon("placemark-blue", "placemark-blue", R.drawable.color_picker_blue_off, R.drawable.color_picker_blue_on),
new Icon("placemark-purple", "placemark-purple", R.drawable.color_picker_purple_off, R.drawable.color_picker_purple_on),
new Icon("placemark-yellow", "placemark-yellow", R.drawable.color_picker_yellow_off, R.drawable.color_picker_yellow_on),
new Icon("placemark-pink", "placemark-pink", R.drawable.color_picker_pink_off, R.drawable.color_picker_pink_on),
new Icon("placemark-brown", "placemark-brown", R.drawable.color_picker_brown_off, R.drawable.color_picker_brown_on),
new Icon("placemark-green", "placemark-green", R.drawable.color_picker_green_off, R.drawable.color_picker_green_on),
new Icon("placemark-orange", "placemark-orange", R.drawable.color_picker_orange_off, R.drawable.color_picker_orange_on)
};
private BookmarkManager()
{
loadBookmarks();
}
public static BookmarkManager getBookmarkManager()
{
if (sManager == null)
sManager = new BookmarkManager();
return sManager;
}
private native void loadBookmarks();
public void deleteBookmark(Bookmark bmk)
@ -53,27 +58,29 @@ public class BookmarkManager
public BookmarkCategory getCategoryById(int id)
{
if (id < getCategoriesCount())
{
return new BookmarkCategory(id);
}
else
{
return null;
}
}
public native int getCategoriesCount();
public native boolean deleteCategory(int index);
public Icon getIconByName(String name)
public Icon getIconByType(String type)
{
return BookmarkIconManager.getIcon(name);
for (Icon icon : sIcons)
{
if (icon.getType().equals(type))
return icon;
}
// return default icon
return sIcons[0];
}
public List<Icon> getIcons()
{
return new ArrayList<Icon>(BookmarkIconManager.getAll().values());
return Arrays.asList(sIcons);
}
public Bookmark getBookmark(Pair<Integer, Integer> catAndBmk)
@ -105,7 +112,7 @@ public class BookmarkManager
final int cat = getLastEditedCategory();
final int bmk = addBookmarkToLastEditedCategory(name, lat, lon);
return new Pair<Integer, Integer>(cat, bmk);
return new Pair<>(cat, bmk);
}
public native void showBookmarkOnMap(int c, int b);

View file

@ -5,12 +5,15 @@ public class Icon
{
private final String mName;
private final String mType;
private final int mResId;
private final int mSelectedResId;
public Icon(String Name, String type)
public Icon(String Name, String type, int resId, int selectedResId)
{
super();
this.mName = Name;
mName = Name;
mType = type;
mResId = resId;
mSelectedResId = selectedResId;
}
public String getType()
@ -23,9 +26,28 @@ public class Icon
return mName;
}
public int getResId()
{
return mResId;
}
public int getSelectedResId()
{
return mSelectedResId;
}
@Override
public boolean equals(Object o)
{
return mType.equals(((Icon) o).getType());
if (o == null || !(o instanceof Icon))
return false;
final Icon comparedIcon = (Icon) o;
return mType.equals(comparedIcon.getType());
}
@Override
public int hashCode()
{
return mType.hashCode();
}
}

View file

@ -0,0 +1,83 @@
package com.mapswithme.maps.widget.placepage;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import com.mapswithme.maps.R;
import com.mapswithme.maps.bookmarks.IconsAdapter;
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
import com.mapswithme.maps.bookmarks.data.Icon;
import java.util.List;
public class BookmarkColorDialogFragment extends DialogFragment
{
public static final String ICON_TYPE = "ExtraIconType";
private String mIconType;
interface OnBookmarkColorChangeListener
{
void onBookmarkColorSet(int colorPos);
}
private OnBookmarkColorChangeListener mColorSetListener;
public BookmarkColorDialogFragment() {}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
if (getArguments() != null)
mIconType = getArguments().getString(ICON_TYPE);
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setView(buildView()).
setTitle(R.string.bookmark_color).
setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
}
});
return builder.create();
}
public void setOnColorSetListener(OnBookmarkColorChangeListener listener)
{
mColorSetListener = listener;
}
private View buildView()
{
final List<Icon> icons = BookmarkManager.INSTANCE.getIcons();
final IconsAdapter adapter = new IconsAdapter(getActivity(), icons);
adapter.chooseItem(mIconType);
final GridView gView = (GridView) LayoutInflater.from(getActivity()).inflate(R.layout.fragment_color_grid, null);
gView.setAdapter(adapter);
gView.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View who, int pos, long id)
{
if (mColorSetListener != null)
mColorSetListener.onBookmarkColorSet(pos);
dismiss();
}
});
return gView;
}
}

View file

@ -1,26 +1,26 @@
package com.mapswithme.maps.widget.placepage;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.graphics.drawable.ColorDrawable;
import android.location.Location;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentActivity;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupMenu;
@ -31,7 +31,6 @@ import android.widget.TextView;
import com.mapswithme.maps.Framework;
import com.mapswithme.maps.R;
import com.mapswithme.maps.api.ParsedMmwRequest;
import com.mapswithme.maps.bookmarks.IconsAdapter;
import com.mapswithme.maps.bookmarks.data.Bookmark;
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
import com.mapswithme.maps.bookmarks.data.DistanceAndAzimut;
@ -42,17 +41,12 @@ import com.mapswithme.maps.bookmarks.data.MapObject.Poi;
import com.mapswithme.maps.bookmarks.data.MapObject.SearchResult;
import com.mapswithme.maps.location.LocationHelper;
import com.mapswithme.util.ShareAction;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.Utils;
import com.mapswithme.util.statistics.Statistics;
import java.util.List;
public class PlacePageView extends LinearLayout implements View.OnClickListener, View.OnLongClickListener
public class PlacePageView extends LinearLayout implements View.OnClickListener, View.OnLongClickListener, TextView.OnEditorActionListener
{
private static final int COLOR_CHOOSER_COLUMN_NUM = 4;
private LayoutInflater mInflater;
// Preview
private TextView mTvTitle;
@ -73,7 +67,12 @@ public class PlacePageView extends LinearLayout implements View.OnClickListener,
private TextView mTvLatlon;
private LinearLayout mLlSchedule;
private TextView mTvSchedule;
// Bookmark
private RelativeLayout mRlBookmarkDetails;
private ImageView mIvColor;
private EditText mEtBookmarkName;
private EditText mEtBookmarkNotes;
private TextView mTvBookmarkGroup;
// Place page buttons
private RelativeLayout mRlApiBack;
private ImageView mIvBookmark;
@ -82,8 +81,7 @@ public class PlacePageView extends LinearLayout implements View.OnClickListener,
// Data
private MapObject mMapObject;
private State mCurrentState = State.HIDDEN;
private BookmarkManager mBookmarkManager;
private List<Icon> mIcons;
private MapObject mBookmarkedMapObject;
private boolean mIsLatLonDms;
private static final String PREF_USE_DMS = "use_dms";
@ -115,9 +113,6 @@ public class PlacePageView extends LinearLayout implements View.OnClickListener,
mInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
initViews();
mBookmarkManager = BookmarkManager.getBookmarkManager();
mIcons = mBookmarkManager.getIcons();
initAnimationController(attrs, defStyleAttr);
setVisibility(View.GONE);
}
@ -133,22 +128,34 @@ public class PlacePageView extends LinearLayout implements View.OnClickListener,
mTvOpened = (TextView) ppPreview.findViewById(R.id.tv__opened_till);
mTvDistance = (TextView) ppPreview.findViewById(R.id.tv__straight_distance);
mAvDirection = (ImageView) ppPreview.findViewById(R.id.iv__direction);
// mAvDirection.setDrawCircle(true);
// mAvDirection.setVisibility(View.GONE); // should be hidden until first compass update
// TODO direction arrow & screen
mPpDetails = (ViewGroup) mView.findViewById(R.id.pp__details);
mLlAddress = (LinearLayout) mPpDetails.findViewById(R.id.ll__place_name);
mTvAddress = (TextView) mPpDetails.findViewById(R.id.tv__place_address);
mLlPhone = (LinearLayout) mPpDetails.findViewById(R.id.ll__place_phone);
mLlPhone.setOnClickListener(this);
mTvPhone = (TextView) mPpDetails.findViewById(R.id.tv__place_phone);
mLlWebsite = (LinearLayout) mPpDetails.findViewById(R.id.ll__place_website);
mLlWebsite.setOnClickListener(this);
mTvWebsite = (TextView) mPpDetails.findViewById(R.id.tv__place_website);
mLlLatlon = (LinearLayout) mPpDetails.findViewById(R.id.ll__place_latlon);
mTvLatlon = (TextView) mPpDetails.findViewById(R.id.tv__place_latlon);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
mTvLatlon.setOnLongClickListener(this);
mLlLatlon.setOnLongClickListener(this);
mLlLatlon.setOnClickListener(this);
mLlSchedule = (LinearLayout) mPpDetails.findViewById(R.id.ll__place_schedule);
mLlSchedule.setOnClickListener(this);
mTvSchedule = (TextView) mPpDetails.findViewById(R.id.tv__place_schedule);
mIvColor = (ImageView) mPpDetails.findViewById(R.id.iv__bookmark_color);
mIvColor.setOnClickListener(this);
mRlBookmarkDetails = (RelativeLayout) mPpDetails.findViewById(R.id.rl__bookmark_details);
mEtBookmarkName = (EditText) mPpDetails.findViewById(R.id.et__bookmark_name);
mEtBookmarkName.setOnEditorActionListener(this);
mEtBookmarkNotes = (EditText) mPpDetails.findViewById(R.id.et__bookmark_notes);
mEtBookmarkNotes.setOnEditorActionListener(this);
mTvBookmarkGroup = (TextView) mPpDetails.findViewById(R.id.tv__bookmark_group);
ViewGroup ppButtons = (ViewGroup) mView.findViewById(R.id.pp__buttons);
mRlApiBack = (RelativeLayout) ppButtons.findViewById(R.id.rl__api_back);
@ -157,7 +164,6 @@ public class PlacePageView extends LinearLayout implements View.OnClickListener,
bookmarkGroup.setOnClickListener(this);
mIvBookmark = (ImageView) bookmarkGroup.findViewById(R.id.iv__bookmark);
ppButtons.findViewById(R.id.rl__share).setOnClickListener(this);
ppButtons.findViewById(R.id.rl__route).setOnClickListener(this);
// Place Page
mPlacePageContainer = (ScrollView) mPpDetails.findViewById(R.id.place_page_container);
@ -167,7 +173,6 @@ public class PlacePageView extends LinearLayout implements View.OnClickListener,
{
final TypedArray attrArray = getContext().obtainStyledAttributes(attrs, R.styleable.PlacePageView, defStyleAttr, 0);
final int animationType = attrArray.getInt(R.styleable.PlacePageView_animationType, 0);
Log.d("TEST", "AnimationType = " + animationType);
attrArray.recycle();
switch (animationType)
{
@ -198,9 +203,7 @@ public class PlacePageView extends LinearLayout implements View.OnClickListener,
@Override
public boolean onInterceptTouchEvent(MotionEvent event)
{
boolean res = mAnimationController.onInterceptTouchEvent(event);
Log.d("TEST", "Intercept - " + res);
return res;
return mAnimationController.onInterceptTouchEvent(event);
}
public State getState()
@ -249,14 +252,12 @@ public class PlacePageView extends LinearLayout implements View.OnClickListener,
{
mMapObject.setDefaultIfEmpty(getResources());
boolean isChecked = false;
switch (mMapObject.getType())
{
case POI:
fillPlacePagePoi(mMapObject);
break;
case BOOKMARK:
isChecked = true;
fillPlacePageBookmark((Bookmark) mMapObject);
break;
case ADDITIONAL_LAYER:
@ -270,9 +271,6 @@ public class PlacePageView extends LinearLayout implements View.OnClickListener,
throw new IllegalArgumentException("Unknown MapObject type:" + mo.getType());
}
// TODO
// mIvBookmark.setChecked(isChecked);
refreshPreview();
refreshDetails();
refreshButtons();
@ -289,6 +287,7 @@ public class PlacePageView extends LinearLayout implements View.OnClickListener,
{
mTvTitle.setText(mMapObject.getName());
mTvSubtitle.setText(mMapObject.getPoiTypeName());
// TODO
// mTvOpened
// mTvDistance
// mAvDirection
@ -367,8 +366,7 @@ public class PlacePageView extends LinearLayout implements View.OnClickListener,
if (da.getAthimuth() >= 0)
{
mAvDirection.setVisibility(View.VISIBLE);
// mAvDirection.setAzimut(da.getAthimuth());
// TODO update direction
}
}
}
@ -376,70 +374,34 @@ public class PlacePageView extends LinearLayout implements View.OnClickListener,
private void fillPlacePagePoi(MapObject poi)
{
// mPlacePageContainer.removeAllViews();
// final View poiView = mInflater.inflate(R.layout.info_box_poi, this, false);
// mPlacePageContainer.addView(poiView);
mRlBookmarkDetails.setVisibility(View.GONE);
// TODO
mIvBookmark.setImageResource(R.drawable.ic_bookmark_off);
}
private void fillPlacePageBookmark(final Bookmark bmk)
{
// mPlacePageContainer.removeAllViews();
// final View bmkView = mInflater.inflate(R.layout.info_box_bookmark, this, false);
// bmkView.setOnClickListener(this);
mRlBookmarkDetails.setVisibility(View.VISIBLE);
mEtBookmarkName.setText(bmk.getName());
mEtBookmarkNotes.setText(bmk.getBookmarkDescription());
// TODO add HTML & webview support
// Description of BMK
// final WebView descriptionWv = (WebView) bmkView.findViewById(R.id.info_box_bookmark_descr);
// final String descriptionTxt = bmk.getBookmarkDescription();
//
// if (TextUtils.isEmpty(descriptionTxt))
// UiUtils.hide(descriptionWv);
// else
// {
// descriptionWv.loadData(descriptionTxt, "text/html; charset=UTF-8", null);
// descriptionWv.setBackgroundColor(Color.TRANSPARENT);
// descriptionWv.setOnTouchListener(new OnTouchListener()
// {
// @Override
// public boolean onTouch(View v, MotionEvent event)
// {
// switch (event.getAction())
// {
// case MotionEvent.ACTION_DOWN:
// PlacePageView.this.requestDisallowInterceptTouchEvent(true);
// break;
// case MotionEvent.ACTION_UP:
// PlacePageView.this.requestDisallowInterceptTouchEvent(false);
// break;
// }
//
// v.onTouchEvent(event);
// return true;
// }
// });
//
// UiUtils.show(descriptionWv);
// }
//
// mIvColor = (ImageView) bmkView.findViewById(R.id.color_image);
// mIvColor.setOnClickListener(this);
// mIvColor.setVisibility(View.VISIBLE);
// updateColorChooser(bmk.getIcon());
//
// mPlacePageContainer.addView(bmkView);
mIvColor.setImageResource(bmk.getIcon().getSelectedResId());
mIvBookmark.setImageResource(R.drawable.ic_bookmark_on);
}
private void fillPlacePageLayer(SearchResult sr)
{
// mPlacePageContainer.removeAllViews();
// final View addLayerView = mInflater.inflate(R.layout.info_box_additional_layer, this, false);
// mPlacePageContainer.addView(addLayerView);
mRlBookmarkDetails.setVisibility(View.GONE);
// TODO
mIvBookmark.setImageResource(R.drawable.ic_bookmark_off);
}
private void fillPlacePageApi(MapObject mo)
{
// mPlacePageContainer.removeAllViews();
// final View apiView = mInflater.inflate(R.layout.info_box_api, this, false);
// mPlacePageContainer.addView(apiView);
mRlBookmarkDetails.setVisibility(View.GONE);
// TODO
mIvBookmark.setImageResource(R.drawable.ic_bookmark_off);
}
public void setOnVisibilityChangedListener(BasePlacePageAnimationController.OnVisibilityChangedListener listener)
@ -474,11 +436,11 @@ public class PlacePageView extends LinearLayout implements View.OnClickListener,
final Bookmark bmk = (Bookmark) mMapObject;
boolean deleted = false;
if (mBookmarkManager.getCategoriesCount() <= bmk.getCategoryId())
if (BookmarkManager.INSTANCE.getCategoriesCount() <= bmk.getCategoryId())
deleted = true;
else if (mBookmarkManager.getCategoryById(bmk.getCategoryId()).getBookmarksCount() <= bmk.getBookmarkId())
else if (BookmarkManager.INSTANCE.getCategoryById(bmk.getCategoryId()).getBookmarksCount() <= bmk.getBookmarkId())
deleted = true;
else if (mBookmarkManager.getBookmark(bmk.getCategoryId(), bmk.getBookmarkId()).getLat() != bmk.getLat())
else if (BookmarkManager.INSTANCE.getBookmark(bmk.getCategoryId(), bmk.getBookmarkId()).getLat() != bmk.getLat())
deleted = true;
// We can do check above, because lat/lon cannot be changed from edit screen.
@ -492,71 +454,20 @@ public class PlacePageView extends LinearLayout implements View.OnClickListener,
else
{
// Update data for current bookmark
final Bookmark updatedBmk = mBookmarkManager.getBookmark(bmk.getCategoryId(), bmk.getBookmarkId());
final Bookmark updatedBmk = BookmarkManager.INSTANCE.getBookmark(bmk.getCategoryId(), bmk.getBookmarkId());
setMapObject(null);
setMapObject(updatedBmk);
}
}
}
private void showColorChooser()
{
final IconsAdapter adapter = new IconsAdapter(getContext(), mIcons);
final Icon icon = ((Bookmark) mMapObject).getIcon();
adapter.chooseItem(mIcons.indexOf(icon));
final ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.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);
final GridView gView = new GridView(getContext());
gView.setAdapter(adapter);
gView.setNumColumns(COLOR_CHOOSER_COLUMN_NUM);
gView.setGravity(Gravity.CENTER);
gView.setPadding(padSide, padTopB, padSide, padTopB);
gView.setLayoutParams(params);
gView.setSelector(new ColorDrawable(Color.TRANSPARENT));
final Dialog dialog = new AlertDialog.Builder(getContext())
.setTitle(R.string.bookmark_color)
.setView(gView)
.create();
gView.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View who, int pos, long id)
{
Icon icon = mIcons.get(pos);
Bookmark bmk = (Bookmark) mMapObject;
bmk.setParams(bmk.getName(), icon, bmk.getBookmarkDescription());
bmk = mBookmarkManager.getBookmark(bmk.getCategoryId(), bmk.getBookmarkId());
setMapObject(bmk);
dialog.dismiss();
}
});
dialog.show();
}
private void updateColorChooser(Icon icon)
{
final Icon oldIcon = ((Bookmark) mMapObject).getIcon();
final String from = oldIcon.getName();
final String to = icon.getName();
if (!TextUtils.equals(from, to))
Statistics.INSTANCE.trackColorChanged(from, to);
mIvColor.setImageDrawable(UiUtils
.drawCircleForPin(to, (int) getResources().getDimension(R.dimen.color_chooser_radius), getResources()));
}
@Override
public void onClick(View v)
{
switch (v.getId())
{
case R.id.color_image:
showColorChooser();
case R.id.iv__bookmark_color:
selectBookmarkColor();
break;
case R.id.rl__bookmark:
if (mMapObject == null)
@ -571,23 +482,18 @@ public class PlacePageView extends LinearLayout implements View.OnClickListener,
else
p = Framework.nativeGetMapObjectForPoint(mMapObject.getLat(), mMapObject.getLon());
mBookmarkManager.deleteBookmark((Bookmark) mMapObject);
BookmarkManager.INSTANCE.deleteBookmark((Bookmark) mMapObject);
setMapObject(p);
}
else
{
mBookmarkedMapObject = mMapObject;
final Bookmark newBmk = mBookmarkManager.getBookmark(mBookmarkManager.addNewBookmark(
final Bookmark newBmk = BookmarkManager.INSTANCE.getBookmark(BookmarkManager.INSTANCE.addNewBookmark(
mMapObject.getName(), mMapObject.getLat(), mMapObject.getLon()));
setMapObject(newBmk);
}
Framework.invalidate();
break;
case R.id.info_box:
// TODO
// without listening this event some bug may appear.
// check that and remove after investigation
break;
case R.id.rl__share:
ShareAction.getAnyShare().shareMapObject((Activity) getContext(), mMapObject);
break;
@ -602,11 +508,55 @@ public class PlacePageView extends LinearLayout implements View.OnClickListener,
Context.MODE_PRIVATE).edit().putBoolean(PREF_USE_DMS, mIsLatLonDms).commit();
refreshLatLon();
break;
case R.id.ll__place_phone:
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + mTvPhone.getText()));
getContext().startActivity(intent);
break;
case R.id.ll__place_website:
intent = new Intent(Intent.ACTION_VIEW);
String website = mTvWebsite.getText().toString();
if (!website.startsWith("http://") && !website.startsWith("https://"))
website = "http://" + website;
intent.setData(Uri.parse(website));
getContext().startActivity(intent);
break;
case R.id.ll__place_schedule:
// TODO expand/collapse schedule if needed
break;
default:
break;
}
}
private void selectBookmarkColor()
{
final Bundle args = new Bundle();
args.putString(BookmarkColorDialogFragment.ICON_TYPE, ((Bookmark) mMapObject).getIcon().getType());
final BookmarkColorDialogFragment dialogFragment = (BookmarkColorDialogFragment) BookmarkColorDialogFragment.
instantiate(getContext(), BookmarkColorDialogFragment.class.getName(), args);
dialogFragment.setOnColorSetListener(new BookmarkColorDialogFragment.OnBookmarkColorChangeListener()
{
@Override
public void onBookmarkColorSet(int colorPos)
{
Bookmark bmk = (Bookmark) mMapObject;
final Icon newIcon = BookmarkManager.INSTANCE.getIcons().get(colorPos);
final String from = bmk.getIcon().getName();
final String to = newIcon.getName();
if (!TextUtils.equals(from, to))
Statistics.INSTANCE.trackColorChanged(from, to);
bmk.setParams(bmk.getName(), newIcon, bmk.getBookmarkDescription());
bmk = BookmarkManager.INSTANCE.getBookmark(bmk.getCategoryId(), bmk.getBookmarkId());
setMapObject(bmk);
}
});
dialogFragment.show(((FragmentActivity) getContext()).getSupportFragmentManager(), null);
}
@Override
public boolean onLongClick(View v)
{
@ -643,4 +593,31 @@ public class PlacePageView extends LinearLayout implements View.OnClickListener,
popup.show();
return true;
}
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
{
if (actionId == EditorInfo.IME_ACTION_DONE)
{
switch (v.getId())
{
case R.id.et__bookmark_name:
Bookmark bookmark = (Bookmark) mMapObject;
final String name = mEtBookmarkName.getText().toString().trim();
bookmark.setParams(name, null, bookmark.getBookmarkDescription());
break;
case R.id.et__bookmark_notes:
// TODO multiline notes & webview
bookmark = (Bookmark) mMapObject;
final String notes = mEtBookmarkNotes.getText().toString().trim();
final String oldNotes = bookmark.getBookmarkDescription().trim();
if (!TextUtils.equals(notes, oldNotes))
Statistics.INSTANCE.trackDescriptionChanged();
bookmark.setParams(mEtBookmarkName.getText().toString(), null, notes);
break;
}
}
return false;
}
}

View file

@ -330,14 +330,13 @@ public enum Statistics
mEventBuilder.setName(EventParam.PRO_STAT);
// Number of sets
final BookmarkManager manager = BookmarkManager.getBookmarkManager();
final int categoriesCount = manager.getCategoriesCount();
final int categoriesCount = BookmarkManager.INSTANCE.getCategoriesCount();
if (categoriesCount > 0)
{
// Calculate average number of bookmarks in category
final double[] sizes = new double[categoriesCount];
for (int catIndex = 0; catIndex < categoriesCount; catIndex++)
sizes[catIndex] = manager.getCategoryById(catIndex).getSize();
sizes[catIndex] = BookmarkManager.INSTANCE.getCategoryById(catIndex).getSize();
final double average = MathUtils.average(sizes);
mEventBuilder.addParam(EventParam.BOOKMARK_NUMBER_AVG, String.valueOf(average));

View file

@ -38,7 +38,7 @@ public class MapObjectActivityBMKTest extends ActivityInstrumentationTestCase2<M
{
super.setUp();
bookmarkManager = BookmarkManager.getBookmarkManager();
bookmarkManager = BookmarkManager.INSTANCE;
catbmk = bookmarkManager.addNewBookmark(BMK_NAME, BMK_LAT, BMK_LON);
}