forked from organicmaps/organicmaps
[and] Bookmark hint as list item. Removed strange code.
This commit is contained in:
parent
cb9b9dda51
commit
c41ef045f7
9 changed files with 87 additions and 96 deletions
17
android/res/layout/bookmark_hint.xml
Normal file
17
android/res/layout/bookmark_hint.xml
Normal file
|
@ -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>
|
|
@ -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"
|
||||
|
|
|
@ -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>
|
||||
</LinearLayout>
|
|
@ -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).
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
@ -80,17 +78,6 @@ public class BookmarkListAdapter extends BaseAdapter implements LocationService.
|
|||
return convertView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyDataSetChanged()
|
||||
{
|
||||
super.notifyDataSetChanged();
|
||||
|
||||
if (mDataChangedListener != null)
|
||||
{
|
||||
mDataChangedListener.onDataChanged(isEmpty() ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount()
|
||||
{
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue