Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Kunin <dkunin@mapswith.me>2013-09-20 16:31:38 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 02:02:04 +0300
commitc41ef045f7286cc7fee42acab1dbb1785e17f4bb (patch)
treeb9ef67db17fc3d4ba9578c49643d925b88545f19
parentcb9b9dda515df82b2f7cf44d9b2a52b7bdc77f43 (diff)
[and] Bookmark hint as list item. Removed strange code.
-rw-r--r--android/res/layout/bookmark_hint.xml17
-rw-r--r--android/res/layout/bookmarks_list.xml7
-rw-r--r--android/res/layout/categories.xml16
-rw-r--r--android/src/com/mapswithme/maps/bookmarks/AbstractBookmarkCategoryActivity.java6
-rw-r--r--android/src/com/mapswithme/maps/bookmarks/AbstractBookmarkCategoryAdapter.java28
-rw-r--r--android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesActivity.java28
-rw-r--r--android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesAdapter.java23
-rw-r--r--android/src/com/mapswithme/maps/bookmarks/BookmarkListActivity.java24
-rw-r--r--android/src/com/mapswithme/maps/bookmarks/BookmarkListAdapter.java34
9 files changed, 87 insertions, 96 deletions
diff --git a/android/res/layout/bookmark_hint.xml b/android/res/layout/bookmark_hint.xml
new file mode 100644
index 0000000000..c467313240
--- /dev/null
+++ b/android/res/layout/bookmark_hint.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" >
+
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:gravity="center"
+ android:paddingBottom="@dimen/dp_x_3"
+ android:paddingLeft="@dimen/dp_x_8"
+ android:paddingRight="@dimen/dp_x_8"
+ android:paddingTop="@dimen/dp_x_3"
+ android:text="@string/bookmarks_usage_hint"
+ android:textSize="@dimen/sp_x_3" />
+
+</FrameLayout> \ No newline at end of file
diff --git a/android/res/layout/bookmarks_list.xml b/android/res/layout/bookmarks_list.xml
index 7e20ceca91..68c5d5e9ba 100644
--- a/android/res/layout/bookmarks_list.xml
+++ b/android/res/layout/bookmarks_list.xml
@@ -23,13 +23,6 @@
android:layout_height="wrap_content"
android:text="@string/bookmarks" />
- <TextView
- android:id="@+id/bookmark_usage_hint"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:padding="5dp"
- android:text="@string/bookmarks_usage_hint" />
-
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
diff --git a/android/res/layout/categories.xml b/android/res/layout/categories.xml
index 1685141899..b06b9683f7 100644
--- a/android/res/layout/categories.xml
+++ b/android/res/layout/categories.xml
@@ -1,18 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
- android:layout_height="match_parent" >
- <TextView
- android:id="@+id/bookmark_usage_hint"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:padding="5dp"
- android:text="@string/bookmarks_usage_hint" />
+ android:layout_height="wrap_content"
+ android:orientation="vertical" >
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
- android:layout_height="wrap_content" >
- </ListView>
+ android:layout_height="match_parent" />
-</FrameLayout> \ No newline at end of file
+</LinearLayout> \ No newline at end of file
diff --git a/android/src/com/mapswithme/maps/bookmarks/AbstractBookmarkCategoryActivity.java b/android/src/com/mapswithme/maps/bookmarks/AbstractBookmarkCategoryActivity.java
index 30d41c3b47..8a8f17a664 100644
--- a/android/src/com/mapswithme/maps/bookmarks/AbstractBookmarkCategoryActivity.java
+++ b/android/src/com/mapswithme/maps/bookmarks/AbstractBookmarkCategoryActivity.java
@@ -18,8 +18,8 @@ public abstract class AbstractBookmarkCategoryActivity extends AbstractBookmarkL
{
if (menuInfo instanceof AdapterView.AdapterContextMenuInfo)
{
- AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
- if (info.position < getAdapter().getCount())
+ final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
+ if (getAdapter().isActiveItem(info.position))
{
mSelectedPosition = info.position;
menu.setHeaderTitle(mManager.getCategoryById(mSelectedPosition).getName());
@@ -31,7 +31,7 @@ public abstract class AbstractBookmarkCategoryActivity extends AbstractBookmarkL
@Override
public boolean onContextItemSelected(MenuItem item)
{
- int itemId = item.getItemId();
+ final int itemId = item.getItemId();
if (itemId == R.id.set_edit)
{
startActivity(new Intent(this, BookmarkListActivity.class).
diff --git a/android/src/com/mapswithme/maps/bookmarks/AbstractBookmarkCategoryAdapter.java b/android/src/com/mapswithme/maps/bookmarks/AbstractBookmarkCategoryAdapter.java
index f6d67cf66f..d699f53da2 100644
--- a/android/src/com/mapswithme/maps/bookmarks/AbstractBookmarkCategoryAdapter.java
+++ b/android/src/com/mapswithme/maps/bookmarks/AbstractBookmarkCategoryAdapter.java
@@ -8,8 +8,8 @@ import android.widget.BaseAdapter;
public abstract class AbstractBookmarkCategoryAdapter extends BaseAdapter
{
- private BookmarkManager mManager;
- private Context mContext;
+ private final BookmarkManager mManager;
+ private final Context mContext;
public AbstractBookmarkCategoryAdapter(Context context)
{
@@ -30,7 +30,7 @@ public abstract class AbstractBookmarkCategoryAdapter extends BaseAdapter
@Override
public int getCount()
{
- return mManager.getCategoriesCount();
+ return mManager.getCategoriesCount() + 1;
}
@Override
@@ -39,6 +39,28 @@ public abstract class AbstractBookmarkCategoryAdapter extends BaseAdapter
return position;
}
+ public final static int ITEM = 0;
+ public final static int HELP = 1;
+ @Override
+ public int getItemViewType(int position)
+ {
+ if (position == getCount() - 1) return HELP;
+ return ITEM;
+ }
+
+ @Override
+ public int getViewTypeCount()
+ {
+ return 2;
+ }
+
+ public boolean isActiveItem(int position)
+ {
+ return getItemViewType(position) != HELP
+ && position < getCount()
+ && position >= 0;
+ }
+
@Override
public BookmarkCategory getItem(int position)
{
diff --git a/android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesActivity.java b/android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesActivity.java
index efebe92dbb..c68561ba3a 100644
--- a/android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesActivity.java
+++ b/android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesActivity.java
@@ -10,7 +10,6 @@ import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import com.mapswithme.maps.R;
-import com.mapswithme.maps.bookmarks.BookmarkListAdapter.DataChangedListener;
public class BookmarkCategoriesActivity extends AbstractBookmarkCategoryActivity
{
@@ -20,24 +19,22 @@ public class BookmarkCategoriesActivity extends AbstractBookmarkCategoryActivity
{
super.onCreate(savedInstanceState);
setContentView(R.layout.categories);
- ListView listView = getListView();
- listView.setAdapter(new BookmarkCategoriesAdapter(this, new DataChangedListener()
- {
- @Override
- public void onDataChanged(int vis)
- {
- findViewById(R.id.bookmark_usage_hint).setVisibility(vis);
- }
- }));
+ final ListView listView = getListView();
+ final BookmarkCategoriesAdapter adapter = new BookmarkCategoriesAdapter(this);
+ listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
- startActivity(new Intent(BookmarkCategoriesActivity.this, BookmarkListActivity.class)
- .putExtra(BookmarkActivity.PIN_SET, position));
+ if (adapter.isActiveItem(position))
+ {
+ startActivity(new Intent(BookmarkCategoriesActivity.this, BookmarkListActivity.class)
+ .putExtra(BookmarkActivity.PIN_SET, position));
+ }
}
+
});
registerForContextMenu(getListView());
}
@@ -46,8 +43,11 @@ public class BookmarkCategoriesActivity extends AbstractBookmarkCategoryActivity
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo)
{
- getMenuInflater().inflate(R.menu.bookmark_categories_context_menu, menu);
- super.onCreateContextMenu(menu, v, menuInfo);
+ if (getAdapter().isActiveItem(((AdapterView.AdapterContextMenuInfo)menuInfo).position))
+ {
+ getMenuInflater().inflate(R.menu.bookmark_categories_context_menu, menu);
+ super.onCreateContextMenu(menu, v, menuInfo);
+ }
}
@Override
diff --git a/android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesAdapter.java b/android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesAdapter.java
index b503935162..6105bbb039 100644
--- a/android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesAdapter.java
+++ b/android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesAdapter.java
@@ -10,21 +10,22 @@ import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
import com.mapswithme.maps.R;
-import com.mapswithme.maps.bookmarks.BookmarkListAdapter.DataChangedListener;
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
public class BookmarkCategoriesAdapter extends AbstractBookmarkCategoryAdapter
{
- private DataChangedListener mListener;
- public BookmarkCategoriesAdapter(Context context, DataChangedListener dcl)
+ public BookmarkCategoriesAdapter(Context context)
{
super(context);
- mListener = dcl;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
+ if (getItemViewType(position) == HELP)
+ return LayoutInflater.from(getContext()).inflate(R.layout.bookmark_hint, null);
+
+
if (convertView == null)
{
convertView = LayoutInflater.from(getContext()).inflate(R.layout.bmk_category_item, null);
@@ -44,8 +45,8 @@ public class BookmarkCategoriesAdapter extends AbstractBookmarkCategoryAdapter
});
}
- PinSetHolder psh = (PinSetHolder) convertView.getTag();
- BookmarkCategory set = getItem(position);
+ final PinSetHolder psh = (PinSetHolder) convertView.getTag();
+ final BookmarkCategory set = getItem(position);
// category ID
psh.categoryId = position;
// name
@@ -70,14 +71,4 @@ public class BookmarkCategoriesAdapter extends AbstractBookmarkCategoryAdapter
this.visibilityCheckBox = visibilityCheckBox;
}
}
-
- @Override
- public void notifyDataSetChanged()
- {
- super.notifyDataSetChanged();
- if (mListener != null)
- {
- mListener.onDataChanged(isEmpty() ? View.VISIBLE : View.GONE);
- }
- }
}
diff --git a/android/src/com/mapswithme/maps/bookmarks/BookmarkListActivity.java b/android/src/com/mapswithme/maps/bookmarks/BookmarkListActivity.java
index 87b9150994..d0d9b26e76 100644
--- a/android/src/com/mapswithme/maps/bookmarks/BookmarkListActivity.java
+++ b/android/src/com/mapswithme/maps/bookmarks/BookmarkListActivity.java
@@ -22,7 +22,6 @@ import android.widget.EditText;
import com.mapswithme.maps.MWMActivity;
import com.mapswithme.maps.MWMApplication;
import com.mapswithme.maps.R;
-import com.mapswithme.maps.bookmarks.BookmarkListAdapter.DataChangedListener;
import com.mapswithme.maps.bookmarks.data.Bookmark;
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
import com.mapswithme.maps.bookmarks.data.ParcelablePoint;
@@ -61,7 +60,7 @@ public class BookmarkListActivity extends AbstractBookmarkListActivity
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
- Intent i = new Intent(BookmarkListActivity.this, MWMActivity.class);
+ final Intent i = new Intent(BookmarkListActivity.this, MWMActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
mManager.showBookmarkOnMap(setIndex, position);
startActivity(i);
@@ -91,14 +90,7 @@ public class BookmarkListActivity extends AbstractBookmarkListActivity
{
setListAdapter(mPinAdapter = new BookmarkListAdapter(this,
((MWMApplication) getApplication()).getLocationService(),
- mEditedSet, new DataChangedListener()
- {
- @Override
- public void onDataChanged(int vis)
- {
- findViewById(R.id.bookmark_usage_hint).setVisibility(vis);
- }
- }));
+ mEditedSet));
mPinAdapter.startLocationUpdate();
}
@@ -152,13 +144,13 @@ public class BookmarkListActivity extends AbstractBookmarkListActivity
if (menuInfo instanceof AdapterView.AdapterContextMenuInfo)
{
- AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
+ final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
mSelectedPosition = info.position;
- MenuInflater inflater = getMenuInflater();
+ final MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.pin_sets_context_menu, menu);
- for (ShareAction sa : ShareAction.ACTIONS.values())
+ for (final ShareAction sa : ShareAction.ACTIONS.values())
{
if (sa.isSupported(this))
menu.add(Menu.NONE, sa.getId(), sa.getId(), getResources().getString(sa.getNameResId()));
@@ -180,7 +172,7 @@ public class BookmarkListActivity extends AbstractBookmarkListActivity
@Override
public boolean onContextItemSelected(MenuItem item)
{
- int itemId = item.getItemId();
+ final int itemId = item.getItemId();
if (itemId == R.id.set_edit)
{
startPinActivity(mEditedSet.getId(), mSelectedPosition);
@@ -255,7 +247,7 @@ public class BookmarkListActivity extends AbstractBookmarkListActivity
{
startActivity(Intent.createChooser(intent, getString(R.string.share_by_email)));
}
- catch (Exception ex)
+ catch (final Exception ex)
{
Log.i(TAG, "Can't run E-Mail activity" + ex);
}
@@ -268,7 +260,7 @@ public class BookmarkListActivity extends AbstractBookmarkListActivity
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
- MenuItem menuItem = menu.add(Menu.NONE,
+ final MenuItem menuItem = menu.add(Menu.NONE,
ID_SEND_BY_EMAIL,
ID_SEND_BY_EMAIL,
R.string.share_by_email);
diff --git a/android/src/com/mapswithme/maps/bookmarks/BookmarkListAdapter.java b/android/src/com/mapswithme/maps/bookmarks/BookmarkListAdapter.java
index 7883931b8c..fa70693c8e 100644
--- a/android/src/com/mapswithme/maps/bookmarks/BookmarkListAdapter.java
+++ b/android/src/com/mapswithme/maps/bookmarks/BookmarkListAdapter.java
@@ -19,19 +19,17 @@ import com.mapswithme.maps.location.LocationService;
public class BookmarkListAdapter extends BaseAdapter implements LocationService.Listener
{
- private Activity mContext;
- private BookmarkCategory mCategory;
+ private final Activity mContext;
+ private final BookmarkCategory mCategory;
private double mNorth = -1;
- private LocationService mLocation;
- private DataChangedListener mDataChangedListener;
+ private final LocationService mLocation;
public BookmarkListAdapter(Activity context, LocationService location,
- BookmarkCategory cat, DataChangedListener dcl)
+ BookmarkCategory cat)
{
mContext = context;
mLocation = location;
mCategory = cat;
- mDataChangedListener = dcl;
}
public void startLocationUpdate()
@@ -54,15 +52,15 @@ public class BookmarkListAdapter extends BaseAdapter implements LocationService.
convertView.setTag(new PinHolder(convertView));
}
- Bookmark item = mCategory.getBookmark(position);
- PinHolder holder = (PinHolder) convertView.getTag();
+ 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)
{
- DistanceAndAzimut daa = item.getDistanceAndAzimut(loc.getLatitude(), loc.getLongitude(), mNorth);
+ final DistanceAndAzimut daa = item.getDistanceAndAzimut(loc.getLatitude(), loc.getLongitude(), mNorth);
holder.distance.setText(daa.getDistance());
if (daa.getAthimuth() >= 0.0)
@@ -81,17 +79,6 @@ public class BookmarkListAdapter extends BaseAdapter implements LocationService.
}
@Override
- public void notifyDataSetChanged()
- {
- super.notifyDataSetChanged();
-
- if (mDataChangedListener != null)
- {
- mDataChangedListener.onDataChanged(isEmpty() ? View.VISIBLE : View.GONE);
- }
- }
-
- @Override
public int getCount()
{
return mCategory.getSize();
@@ -118,7 +105,7 @@ public class BookmarkListAdapter extends BaseAdapter implements LocationService.
@Override
public void onCompassUpdated(long time, double magneticNorth, double trueNorth, double accuracy)
{
- double north[] = { magneticNorth, trueNorth };
+ final double north[] = { magneticNorth, trueNorth };
mLocation.correctCompassAngles(mContext.getWindowManager().getDefaultDisplay(), north);
final double ret = (north[1] >= 0.0 ? north[1] : north[0]);
@@ -152,9 +139,4 @@ public class BookmarkListAdapter extends BaseAdapter implements LocationService.
distance = (TextView) convertView.findViewById(R.id.pi_distance);
}
}
-
- public interface DataChangedListener
- {
- void onDataChanged(int vis);
- }
}