forked from organicmaps/organicmaps
[android] Bookmark views activity refactoring.
This commit is contained in:
parent
a10565dbed
commit
3a00d39919
10 changed files with 185 additions and 280 deletions
|
@ -1,48 +0,0 @@
|
|||
package com.mapswithme.maps.bookmarks;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.ActionBar;
|
||||
import android.app.Activity;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
import com.mapswithme.maps.base.MapsWithMeBaseActivity;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
|
||||
public abstract class AbstractBookmarkActivity extends MapsWithMeBaseActivity
|
||||
{
|
||||
protected BookmarkManager mManager;
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
mManager = BookmarkManager.getBookmarkManager(getApplicationContext());
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
|
||||
{
|
||||
// http://stackoverflow.com/questions/6867076/getactionbar-returns-null
|
||||
ActionBar bar = getActionBar();
|
||||
if (bar != null)
|
||||
bar.setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item)
|
||||
{
|
||||
if (item.getItemId() == android.R.id.home)
|
||||
{
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
|
||||
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
|
||||
onBackPressed();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
|
@ -1,65 +1,30 @@
|
|||
package com.mapswithme.maps.bookmarks;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.os.Bundle;
|
||||
import android.widget.BaseAdapter;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.MapsWithMeBaseListActivity;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
|
||||
public abstract class AbstractBookmarkCategoryActivity extends AbstractBookmarkListActivity
|
||||
public abstract class AbstractBookmarkCategoryActivity extends MapsWithMeBaseListActivity
|
||||
{
|
||||
private int mSelectedPosition;
|
||||
protected BookmarkManager mManager;
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
final AbstractBookmarkCategoryAdapter absAdapter = getAdapter();
|
||||
if (menuInfo instanceof AdapterView.AdapterContextMenuInfo &&
|
||||
absAdapter instanceof BookmarkCategoriesAdapter)
|
||||
{
|
||||
final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
|
||||
final BookmarkCategoriesAdapter adapter = (BookmarkCategoriesAdapter)absAdapter;
|
||||
if (adapter.isActiveItem(info.position))
|
||||
{
|
||||
mSelectedPosition = info.position;
|
||||
menu.setHeaderTitle(mManager.getCategoryById(mSelectedPosition).getName());
|
||||
}
|
||||
}
|
||||
super.onCreateContextMenu(menu, v, menuInfo);
|
||||
}
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem item)
|
||||
{
|
||||
final int itemId = item.getItemId();
|
||||
if (itemId == R.id.set_edit)
|
||||
{
|
||||
startActivity(new Intent(this, BookmarkListActivity.class).
|
||||
putExtra(BookmarkActivity.PIN_SET, mSelectedPosition).
|
||||
putExtra(BookmarkListActivity.EDIT_CONTENT, enableEditing()));
|
||||
}
|
||||
else if (itemId == R.id.set_delete)
|
||||
{
|
||||
mManager.deleteCategory(mSelectedPosition);
|
||||
getAdapter().notifyDataSetChanged();
|
||||
}
|
||||
return super.onContextItemSelected(item);
|
||||
}
|
||||
|
||||
protected abstract boolean enableEditing();
|
||||
|
||||
protected AbstractBookmarkCategoryAdapter getAdapter()
|
||||
{
|
||||
return ((AbstractBookmarkCategoryAdapter) getListView().getAdapter());
|
||||
mManager = BookmarkManager.getBookmarkManager(getApplicationContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
super.onStart();
|
||||
|
||||
getAdapter().notifyDataSetChanged();
|
||||
}
|
||||
|
||||
protected abstract BaseAdapter getAdapter();
|
||||
}
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
package com.mapswithme.maps.bookmarks;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.mapswithme.maps.base.MapsWithMeBaseListActivity;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
|
||||
public abstract class AbstractBookmarkListActivity extends MapsWithMeBaseListActivity
|
||||
{
|
||||
protected BookmarkManager mManager;
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
mManager = BookmarkManager.getBookmarkManager(getApplicationContext());
|
||||
}
|
||||
}
|
|
@ -28,14 +28,16 @@ import android.widget.ImageView;
|
|||
import android.widget.TextView;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.MapsWithMeBaseActivity;
|
||||
import com.mapswithme.maps.bookmarks.data.Bookmark;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.maps.bookmarks.data.Icon;
|
||||
import com.mapswithme.maps.bookmarks.data.ParcelablePoint;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
import com.mapswithme.util.Utils;
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
|
||||
public class BookmarkActivity extends AbstractBookmarkActivity
|
||||
public class BookmarkActivity extends MapsWithMeBaseActivity
|
||||
{
|
||||
private static final int BOOKMARK_COLOR_DIALOG = 11002;
|
||||
|
||||
|
@ -46,6 +48,7 @@ public class BookmarkActivity extends AbstractBookmarkActivity
|
|||
public static final int REQUEST_CODE_SET = 0x1;
|
||||
public static final String BOOKMARK_NAME = "bookmark_name";
|
||||
|
||||
private BookmarkManager mManager;
|
||||
private Bookmark mPin;
|
||||
private EditText mName;
|
||||
private View mClearName;
|
||||
|
@ -73,18 +76,18 @@ public class BookmarkActivity extends AbstractBookmarkActivity
|
|||
|
||||
setContentView(R.layout.add_or_edit_bookmark);
|
||||
|
||||
// Note that Point result from the intent is actually a pair of (category index, bookmark index in category).
|
||||
assert(getIntent().getExtras().containsKey(PIN));
|
||||
// Note that Point result from the intent is actually a pair of
|
||||
// (category index, bookmark index in category).
|
||||
final Point cab = ((ParcelablePoint)getIntent().getParcelableExtra(PIN)).getPoint();
|
||||
|
||||
mManager = BookmarkManager.getBookmarkManager(getApplicationContext());
|
||||
mPin = mManager.getBookmark(cab.x, cab.y);
|
||||
mCurrentCategoryId = mPin.getCategoryId();
|
||||
|
||||
setTitle(mPin.getName());
|
||||
setUpViews();
|
||||
|
||||
|
||||
|
||||
// Adapt UI according to API version: leave ActionBar or Buttons.
|
||||
if (Utils.apiEqualOrGreaterThan(11) && getActionBar() != null)
|
||||
{
|
||||
final ActionBar ab = getActionBar();
|
||||
|
@ -111,11 +114,11 @@ public class BookmarkActivity extends AbstractBookmarkActivity
|
|||
onDeleteClick(null);
|
||||
}
|
||||
});
|
||||
|
||||
UiUtils.hide(findViewById(R.id.btn_done), findViewById(R.id.btn_delete));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void updateColorChooser(Icon icon)
|
||||
{
|
||||
if (mIcon != null)
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.content.Intent;
|
|||
import android.os.Bundle;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
|
@ -13,29 +14,35 @@ import com.mapswithme.maps.R;
|
|||
|
||||
public class BookmarkCategoriesActivity extends AbstractBookmarkCategoryActivity
|
||||
{
|
||||
private int mSelectedPosition;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
protected BookmarkCategoriesAdapter getAdapter()
|
||||
{
|
||||
return (BookmarkCategoriesAdapter) getListView().getAdapter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.categories);
|
||||
final ListView listView = getListView();
|
||||
final BookmarkCategoriesAdapter adapter = new BookmarkCategoriesAdapter(this);
|
||||
listView.setAdapter(adapter);
|
||||
listView.setOnItemClickListener(new OnItemClickListener()
|
||||
{
|
||||
|
||||
final ListView lv = getListView();
|
||||
lv.setAdapter(new BookmarkCategoriesAdapter(this));
|
||||
lv.setOnItemClickListener(new OnItemClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
|
||||
{
|
||||
if (adapter.isActiveItem(position))
|
||||
if (getAdapter().isActiveItem(position))
|
||||
{
|
||||
startActivity(new Intent(BookmarkCategoriesActivity.this, BookmarkListActivity.class)
|
||||
.putExtra(BookmarkActivity.PIN_SET, position));
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
registerForContextMenu(getListView());
|
||||
}
|
||||
|
||||
|
@ -43,17 +50,28 @@ public class BookmarkCategoriesActivity extends AbstractBookmarkCategoryActivity
|
|||
public void onCreateContextMenu(ContextMenu menu, View v,
|
||||
ContextMenuInfo menuInfo)
|
||||
{
|
||||
final BookmarkCategoriesAdapter adapter = (BookmarkCategoriesAdapter)getAdapter();
|
||||
if (adapter.isActiveItem(((AdapterView.AdapterContextMenuInfo)menuInfo).position))
|
||||
mSelectedPosition = ((AdapterView.AdapterContextMenuInfo)menuInfo).position;
|
||||
if (getAdapter().isActiveItem(mSelectedPosition))
|
||||
{
|
||||
getMenuInflater().inflate(R.menu.bookmark_categories_context_menu, menu);
|
||||
menu.setHeaderTitle(mManager.getCategoryById(mSelectedPosition).getName());
|
||||
|
||||
super.onCreateContextMenu(menu, v, menuInfo);
|
||||
}
|
||||
else
|
||||
mSelectedPosition = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean enableEditing()
|
||||
public boolean onContextItemSelected(MenuItem item)
|
||||
{
|
||||
return true;
|
||||
if (item.getItemId() == R.id.set_delete)
|
||||
{
|
||||
assert (mSelectedPosition != -1);
|
||||
mManager.deleteCategory(mSelectedPosition);
|
||||
getAdapter().notifyDataSetChanged();
|
||||
}
|
||||
|
||||
return super.onContextItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,11 @@ public class BookmarkCategoriesAdapter extends AbstractBookmarkCategoryAdapter
|
|||
private final static int ITEM = 0;
|
||||
private final static int HELP = 1;
|
||||
|
||||
public boolean isActiveItem(int position)
|
||||
{
|
||||
return getItemViewType(position) != HELP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount()
|
||||
{
|
||||
|
@ -31,8 +36,7 @@ public class BookmarkCategoriesAdapter extends AbstractBookmarkCategoryAdapter
|
|||
@Override
|
||||
public int getItemViewType(int position)
|
||||
{
|
||||
if (position == getCount() - 1) return HELP;
|
||||
return ITEM;
|
||||
return (position == getCount() - 1) ? HELP : ITEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -41,13 +45,6 @@ public class BookmarkCategoriesAdapter extends AbstractBookmarkCategoryAdapter
|
|||
return 2;
|
||||
}
|
||||
|
||||
public boolean isActiveItem(int position)
|
||||
{
|
||||
return getItemViewType(position) != HELP
|
||||
&& position < getCount()
|
||||
&& position >= 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent)
|
||||
{
|
||||
|
@ -84,7 +81,7 @@ public class BookmarkCategoriesAdapter extends AbstractBookmarkCategoryAdapter
|
|||
psh.categoryId = position;
|
||||
// name
|
||||
psh.name.setText(set.getName() + " ("+String.valueOf(set.getSize())+")");
|
||||
// visiblity
|
||||
// visibility
|
||||
psh.visibilityCheckBox.setChecked(set.isVisible());
|
||||
|
||||
return convertView;
|
||||
|
|
|
@ -23,24 +23,25 @@ import com.mapswithme.maps.Framework;
|
|||
import com.mapswithme.maps.MWMActivity;
|
||||
import com.mapswithme.maps.MWMApplication;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.MapsWithMeBaseListActivity;
|
||||
import com.mapswithme.maps.bookmarks.data.Bookmark;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.maps.bookmarks.data.ParcelablePoint;
|
||||
import com.mapswithme.maps.bookmarks.data.Track;
|
||||
import com.mapswithme.util.ShareAction;
|
||||
import com.mapswithme.util.Utils;
|
||||
|
||||
|
||||
public class BookmarkListActivity extends AbstractBookmarkListActivity
|
||||
public class BookmarkListActivity extends MapsWithMeBaseListActivity
|
||||
{
|
||||
public static final String TAG = "BookmarkListActivity";
|
||||
public static final String EDIT_CONTENT = "edit_content";
|
||||
|
||||
private BookmarkManager mManager;
|
||||
private EditText mSetName;
|
||||
private BookmarkCategory mEditedSet;
|
||||
private int mSelectedPosition;
|
||||
private BookmarkListAdapter mPinAdapter;
|
||||
private boolean mEditContent;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
|
@ -48,35 +49,38 @@ public class BookmarkListActivity extends AbstractBookmarkListActivity
|
|||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.bookmarks_list);
|
||||
|
||||
final int setIndex = getIntent().getIntExtra(BookmarkActivity.PIN_SET, -1);
|
||||
mEditContent = getIntent().getBooleanExtra(EDIT_CONTENT, true);
|
||||
mEditedSet = mManager.getCategoryById(setIndex);
|
||||
setTitle(mEditedSet.getName());
|
||||
mManager = BookmarkManager.getBookmarkManager(getApplicationContext());
|
||||
|
||||
if (mEditedSet != null)
|
||||
createListAdapter();
|
||||
// Initialize with passed edited set.
|
||||
final int setIndex = getIntent().getIntExtra(BookmarkActivity.PIN_SET, -1);
|
||||
mEditedSet = mManager.getCategoryById(setIndex);
|
||||
|
||||
setTitle(mEditedSet.getName());
|
||||
createListAdapter();
|
||||
|
||||
setUpViews();
|
||||
|
||||
getListView().setOnItemClickListener(new OnItemClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
|
||||
{
|
||||
|
||||
final int type = mPinAdapter.getItemViewType(position);
|
||||
|
||||
if (type == BookmarkListAdapter.TYPE_SECTION)
|
||||
return;
|
||||
|
||||
if (type == BookmarkListAdapter.TYPE_BMK)
|
||||
switch (mPinAdapter.getItemViewType(position))
|
||||
{
|
||||
final Bookmark bmk = (Bookmark) mPinAdapter.getItem(position);
|
||||
mManager.showBookmarkOnMap(setIndex, bmk.getBookmarkId());
|
||||
}
|
||||
else
|
||||
{
|
||||
final Track track = (Track) mPinAdapter.getItem(position);
|
||||
Framework.showTrackRect(track);
|
||||
case BookmarkListAdapter.TYPE_SECTION:
|
||||
return;
|
||||
case BookmarkListAdapter.TYPE_BMK:
|
||||
{
|
||||
final Bookmark bmk = (Bookmark) mPinAdapter.getItem(position);
|
||||
mManager.showBookmarkOnMap(setIndex, bmk.getBookmarkId());
|
||||
break;
|
||||
}
|
||||
case BookmarkListAdapter.TYPE_TRACK:
|
||||
{
|
||||
final Track track = (Track) mPinAdapter.getItem(position);
|
||||
Framework.showTrackRect(track);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
final Intent i = new Intent(BookmarkListActivity.this, MWMActivity.class);
|
||||
|
@ -97,7 +101,7 @@ public class BookmarkListActivity extends AbstractBookmarkListActivity
|
|||
shareButton.setOnClickListener(new OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v) { onSendEMail(shareButton); }
|
||||
public void onClick(View v) { onSendEMail(); }
|
||||
});
|
||||
}
|
||||
else
|
||||
|
@ -106,29 +110,26 @@ public class BookmarkListActivity extends AbstractBookmarkListActivity
|
|||
|
||||
private void createListAdapter()
|
||||
{
|
||||
setListAdapter(mPinAdapter = new BookmarkListAdapter(this,
|
||||
((MWMApplication) getApplication()).getLocationService(),
|
||||
mEditedSet));
|
||||
mPinAdapter = new BookmarkListAdapter(this,
|
||||
((MWMApplication) getApplication()).getLocationService(),
|
||||
mEditedSet);
|
||||
|
||||
setListAdapter(mPinAdapter);
|
||||
|
||||
mPinAdapter.startLocationUpdate();
|
||||
}
|
||||
|
||||
private void assignCategoryParams()
|
||||
{
|
||||
if (mEditedSet != null)
|
||||
{
|
||||
final String name = mSetName.getText().toString();
|
||||
if (!name.equals(mEditedSet.getName()))
|
||||
mManager.setCategoryName(mEditedSet, name);
|
||||
}
|
||||
final String name = mSetName.getText().toString();
|
||||
if (!name.equals(mEditedSet.getName()))
|
||||
mManager.setCategoryName(mEditedSet, name);
|
||||
}
|
||||
|
||||
private void setUpViews()
|
||||
{
|
||||
mSetName = (EditText) findViewById(R.id.pin_set_name);
|
||||
if (mEditedSet != null)
|
||||
mSetName.setText(mEditedSet.getName());
|
||||
|
||||
mSetName.setText(mEditedSet.getName());
|
||||
mSetName.addTextChangedListener(new TextWatcher()
|
||||
{
|
||||
@Override
|
||||
|
@ -150,41 +151,39 @@ public class BookmarkListActivity extends AbstractBookmarkListActivity
|
|||
{
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
|
||||
{
|
||||
if (mEditContent)
|
||||
assignCategoryParams();
|
||||
|
||||
// Some list views can be section delimiters.
|
||||
if (menuInfo instanceof AdapterView.AdapterContextMenuInfo)
|
||||
{
|
||||
assignCategoryParams();
|
||||
final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
|
||||
|
||||
if (menuInfo instanceof AdapterView.AdapterContextMenuInfo)
|
||||
mSelectedPosition = info.position;
|
||||
final Object obj = mPinAdapter.getItem(mSelectedPosition);
|
||||
final int type = mPinAdapter.getItemViewType(mSelectedPosition);
|
||||
|
||||
if (type == BookmarkListAdapter.TYPE_BMK)
|
||||
{
|
||||
final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
|
||||
mSelectedPosition = info.position;
|
||||
final MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.pin_sets_context_menu, menu);
|
||||
|
||||
final int type = mPinAdapter.getItemViewType(mSelectedPosition);
|
||||
if (type == BookmarkListAdapter.TYPE_BMK)
|
||||
for (final ShareAction sa : ShareAction.ACTIONS.values())
|
||||
{
|
||||
final MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.pin_sets_context_menu, menu);
|
||||
if (sa.isSupported(this))
|
||||
menu.add(Menu.NONE, sa.getId(), sa.getId(), getResources().getString(sa.getNameResId()));
|
||||
}
|
||||
|
||||
for (final ShareAction sa : ShareAction.ACTIONS.values())
|
||||
{
|
||||
if (sa.isSupported(this))
|
||||
menu.add(Menu.NONE, sa.getId(), sa.getId(), getResources().getString(sa.getNameResId()));
|
||||
}
|
||||
final Bookmark bmk = (Bookmark) mPinAdapter.getItem(mSelectedPosition);
|
||||
menu.setHeaderTitle(bmk.getName());
|
||||
}
|
||||
else if (type == BookmarkListAdapter.TYPE_TRACK)
|
||||
{
|
||||
menu.add(Menu.NONE, MENU_DELETE_TRACK, MENU_DELETE_TRACK, getString(R.string.delete));
|
||||
final Track trk = (Track) mPinAdapter.getItem(mSelectedPosition);
|
||||
menu.setHeaderTitle(trk.getName());
|
||||
}
|
||||
menu.setHeaderTitle(((Bookmark) obj).getName());
|
||||
}
|
||||
else if (type == BookmarkListAdapter.TYPE_TRACK)
|
||||
{
|
||||
menu.add(Menu.NONE, MENU_DELETE_TRACK, MENU_DELETE_TRACK, getString(R.string.delete));
|
||||
menu.setHeaderTitle(((Track) obj).getName());
|
||||
}
|
||||
|
||||
super.onCreateContextMenu(menu, v, menuInfo);
|
||||
|
@ -196,26 +195,25 @@ public class BookmarkListActivity extends AbstractBookmarkListActivity
|
|||
public boolean onContextItemSelected(MenuItem item)
|
||||
{
|
||||
final int itemId = item.getItemId();
|
||||
final Object obj = mPinAdapter.getItem(mSelectedPosition);
|
||||
|
||||
if (itemId == R.id.set_edit)
|
||||
{
|
||||
final Bookmark bmk = (Bookmark) mPinAdapter.getItem(mSelectedPosition);
|
||||
startPinActivity(mEditedSet.getId(), bmk.getBookmarkId());
|
||||
startPinActivity(mEditedSet.getId(), ((Bookmark) obj).getBookmarkId());
|
||||
}
|
||||
else if (itemId == R.id.set_delete)
|
||||
{
|
||||
mManager.deleteBookmark((Bookmark) mPinAdapter.getItem(mSelectedPosition));
|
||||
mManager.deleteBookmark((Bookmark) obj);
|
||||
mPinAdapter.notifyDataSetChanged();
|
||||
}
|
||||
else if (ShareAction.ACTIONS.containsKey(itemId))
|
||||
{
|
||||
final ShareAction shareAction = ShareAction.ACTIONS.get(itemId);
|
||||
final Bookmark bmk = (Bookmark) mPinAdapter.getItem(mSelectedPosition);
|
||||
shareAction.shareMapObject(this, bmk);
|
||||
shareAction.shareMapObject(this, (Bookmark) obj);
|
||||
}
|
||||
else if (itemId == MENU_DELETE_TRACK)
|
||||
{
|
||||
final Track track = (Track) mPinAdapter.getItem(mSelectedPosition);
|
||||
mManager.deleteTrack(track);
|
||||
mManager.deleteTrack((Track) obj);
|
||||
mPinAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
@ -233,8 +231,7 @@ public class BookmarkListActivity extends AbstractBookmarkListActivity
|
|||
{
|
||||
super.onStart();
|
||||
|
||||
if (mPinAdapter != null)
|
||||
mPinAdapter.notifyDataSetChanged();
|
||||
mPinAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -242,8 +239,7 @@ public class BookmarkListActivity extends AbstractBookmarkListActivity
|
|||
{
|
||||
assignCategoryParams();
|
||||
|
||||
if (mPinAdapter != null)
|
||||
mPinAdapter.stopLocationUpdate();
|
||||
mPinAdapter.stopLocationUpdate();
|
||||
|
||||
super.onPause();
|
||||
}
|
||||
|
@ -253,11 +249,10 @@ public class BookmarkListActivity extends AbstractBookmarkListActivity
|
|||
{
|
||||
super.onResume();
|
||||
|
||||
if (mPinAdapter != null)
|
||||
mPinAdapter.startLocationUpdate();
|
||||
mPinAdapter.startLocationUpdate();
|
||||
}
|
||||
|
||||
public void onSendEMail(View v)
|
||||
private void onSendEMail()
|
||||
{
|
||||
assignCategoryParams();
|
||||
|
||||
|
@ -265,7 +260,7 @@ public class BookmarkListActivity extends AbstractBookmarkListActivity
|
|||
final String name = mManager.saveToKMZFile(mEditedSet.getId(), path);
|
||||
if (name == null)
|
||||
{
|
||||
// some error occured
|
||||
// some error occurred
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -310,10 +305,9 @@ public class BookmarkListActivity extends AbstractBookmarkListActivity
|
|||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item)
|
||||
{
|
||||
|
||||
if (item.getItemId() == ID_SEND_BY_EMAIL)
|
||||
{
|
||||
onSendEMail(null);
|
||||
onSendEMail();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@ public class BookmarkListAdapter extends BaseAdapter
|
|||
{
|
||||
private final Activity mContext;
|
||||
private final BookmarkCategory mCategory;
|
||||
private double mNorth = -1;
|
||||
private final LocationService mLocation;
|
||||
|
||||
// reuse drawables
|
||||
|
@ -59,19 +58,22 @@ public class BookmarkListAdapter extends BaseAdapter
|
|||
{
|
||||
return 3; // bookmark + track + section
|
||||
}
|
||||
final static int TYPE_TRACK = 0;
|
||||
final static int TYPE_BMK = 1;
|
||||
final static int TYPE_SECTION = 2;
|
||||
final static int TYPE_TRACK = 0;
|
||||
final static int TYPE_BMK = 1;
|
||||
final static int TYPE_SECTION = 2;
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position)
|
||||
{
|
||||
if (position == getBookmarksSectionPosition() || position == getTracksSectionPosition())
|
||||
final int bmkPos = getBookmarksSectionPosition();
|
||||
final int trackPos = getTracksSectionPosition();
|
||||
|
||||
if (position == bmkPos || position == trackPos)
|
||||
return TYPE_SECTION;
|
||||
|
||||
if (position > getBookmarksSectionPosition() && !isSectionEmpty(SECTION_BMKS))
|
||||
if (position > bmkPos && !isSectionEmpty(SECTION_BMKS))
|
||||
return TYPE_BMK;
|
||||
else if (position > getTracksSectionPosition() && !isSectionEmpty(SECTION_TRACKS))
|
||||
else if (position > trackPos && !isSectionEmpty(SECTION_TRACKS))
|
||||
return TYPE_TRACK;
|
||||
|
||||
throw new IllegalArgumentException("Position not found: " + position);
|
||||
|
@ -98,6 +100,7 @@ public class BookmarkListAdapter extends BaseAdapter
|
|||
sectionView = convertView;
|
||||
sectionName = (TextView) sectionView.getTag();
|
||||
}
|
||||
|
||||
final int sectionIndex = getSectionForPosition(position);
|
||||
sectionName.setText(getSections().get(sectionIndex));
|
||||
return sectionView;
|
||||
|
@ -105,12 +108,12 @@ public class BookmarkListAdapter extends BaseAdapter
|
|||
|
||||
if (convertView == null)
|
||||
{
|
||||
final int lId = type == TYPE_BMK ? R.layout.list_item_bookmark : R.layout.list_item_track;
|
||||
convertView = LayoutInflater.from(mContext).inflate(lId, null);
|
||||
final int id = (type == TYPE_BMK) ? R.layout.list_item_bookmark : R.layout.list_item_track;
|
||||
convertView = LayoutInflater.from(mContext).inflate(id, null);
|
||||
convertView.setTag(new PinHolder(convertView));
|
||||
}
|
||||
final PinHolder holder = (PinHolder) convertView.getTag();
|
||||
|
||||
final PinHolder holder = (PinHolder) convertView.getTag();
|
||||
if (type == TYPE_BMK)
|
||||
holder.set((Bookmark)getItem(position));
|
||||
else
|
||||
|
@ -152,15 +155,7 @@ public class BookmarkListAdapter extends BaseAdapter
|
|||
@Override
|
||||
public void onCompassUpdated(long time, double magneticNorth, double trueNorth, double accuracy)
|
||||
{
|
||||
final double north[] = { magneticNorth, trueNorth };
|
||||
mLocation.correctCompassAngles(mContext.getWindowManager().getDefaultDisplay(), north);
|
||||
final double ret = (north[1] >= 0.0 ? north[1] : north[0]);
|
||||
|
||||
if (mNorth == -1 || Math.abs(mNorth - ret) > 0.02)
|
||||
{
|
||||
mNorth = ret;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
// We don't show any arrows for bookmarks any more.
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -196,7 +191,7 @@ public class BookmarkListAdapter extends BaseAdapter
|
|||
final Location loc = mLocation.getLastKnown();
|
||||
if (loc != null)
|
||||
{
|
||||
final DistanceAndAzimut daa = bmk.getDistanceAndAzimut(loc.getLatitude(), loc.getLongitude(), mNorth);
|
||||
final DistanceAndAzimut daa = bmk.getDistanceAndAzimut(loc.getLatitude(), loc.getLongitude(), 0.0);
|
||||
distance.setText(daa.getDistance());
|
||||
}
|
||||
else
|
||||
|
@ -230,7 +225,7 @@ public class BookmarkListAdapter extends BaseAdapter
|
|||
{
|
||||
final Resources res = mContext.getResources();
|
||||
final int circleSize = (int) (res.getDimension(R.dimen.circle_size) + .5);
|
||||
// colors could be different, so dont use cache
|
||||
// colors could be different, so don't use cache
|
||||
final Drawable circle = UiUtils.drawCircle(trk.getColor(), circleSize, res);
|
||||
icon.setImageDrawable(circle);
|
||||
}
|
||||
|
|
|
@ -4,8 +4,7 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.graphics.Point;
|
||||
import android.os.Bundle;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
import android.text.Editable;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
|
@ -26,15 +25,29 @@ import com.mapswithme.util.statistics.Statistics;
|
|||
|
||||
public class ChooseBookmarkCategoryActivity extends AbstractBookmarkCategoryActivity
|
||||
{
|
||||
private static final int REQUEST_CREATE_CATEGORY = 1000;
|
||||
private ChooseBookmarkCategoryAdapter mAdapter;
|
||||
private FooterHandler m_handler;
|
||||
|
||||
private Bookmark getBookmarkFromIntent()
|
||||
{
|
||||
// Note that Point result from the intent is actually a pair
|
||||
// of (category index, bookmark index in category).
|
||||
final Point cab = ((ParcelablePoint) getIntent().getParcelableExtra(BookmarkActivity.PIN)).getPoint();
|
||||
return mManager.getBookmark(cab.x, cab.y);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ChooseBookmarkCategoryAdapter getAdapter()
|
||||
{
|
||||
return (ChooseBookmarkCategoryAdapter) ((HeaderViewListAdapter) getListView().getAdapter()).getWrappedAdapter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setListAdapter(new ChooseBookmarkCategoryAdapter(this, getIntent().getIntExtra(BookmarkActivity.PIN_SET, 0)));
|
||||
|
||||
m_handler = new FooterHandler();
|
||||
getListView().setOnItemClickListener(new OnItemClickListener()
|
||||
{
|
||||
|
@ -42,18 +55,17 @@ public class ChooseBookmarkCategoryActivity extends AbstractBookmarkCategoryActi
|
|||
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
|
||||
{
|
||||
m_handler.switchToAddButton();
|
||||
mAdapter.chooseItem(position);
|
||||
getAdapter().chooseItem(position);
|
||||
|
||||
// Note that Point result from the intent is actually a pair of (category index, bookmark index in category).
|
||||
final Point cab = ((ParcelablePoint)getIntent().getParcelableExtra(BookmarkActivity.PIN)).getPoint();
|
||||
Bookmark bmk = mManager.getBookmark(cab.x, cab.y);
|
||||
final Bookmark bmk = getBookmarkFromIntent();
|
||||
bmk.setCategoryId(position);
|
||||
getIntent().putExtra(BookmarkActivity.PIN, new ParcelablePoint(position, bmk.getBookmarkId()));
|
||||
getIntent().putExtra(BookmarkActivity.PIN,
|
||||
new ParcelablePoint(bmk.getCategoryId(), bmk.getBookmarkId()));
|
||||
|
||||
onBackPressed();
|
||||
}
|
||||
});
|
||||
setListAdapter(mAdapter = new ChooseBookmarkCategoryAdapter(this, getIntent().getIntExtra(BookmarkActivity.PIN_SET, -1)));
|
||||
|
||||
registerForContextMenu(getListView());
|
||||
}
|
||||
|
||||
|
@ -61,40 +73,23 @@ public class ChooseBookmarkCategoryActivity extends AbstractBookmarkCategoryActi
|
|||
public void onBackPressed()
|
||||
{
|
||||
m_handler.createCategoryIfNeeded();
|
||||
|
||||
setResult(RESULT_OK, new Intent().putExtra(BookmarkActivity.PIN, getIntent().getParcelableExtra(BookmarkActivity.PIN)));
|
||||
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View v,
|
||||
ContextMenuInfo menuInfo)
|
||||
{
|
||||
getMenuInflater().inflate(R.menu.choose_pin_sets_context_menu, menu);
|
||||
super.onCreateContextMenu(menu, v, menuInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ChooseBookmarkCategoryAdapter getAdapter()
|
||||
{
|
||||
return (ChooseBookmarkCategoryAdapter)((HeaderViewListAdapter) getListView().getAdapter()).getWrappedAdapter();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||
{
|
||||
if (requestCode == REQUEST_CREATE_CATEGORY && resultCode == RESULT_OK)
|
||||
if (resultCode == RESULT_OK)
|
||||
{
|
||||
mAdapter.chooseItem(data.getIntExtra(BookmarkActivity.PIN_SET, 0));
|
||||
getAdapter().chooseItem(data.getIntExtra(BookmarkActivity.PIN_SET, 0));
|
||||
|
||||
getIntent().putExtra(BookmarkActivity.PIN, data.getParcelableExtra(BookmarkActivity.PIN));
|
||||
}
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean enableEditing()
|
||||
{
|
||||
return false;
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
private class FooterHandler implements View.OnClickListener
|
||||
|
@ -104,13 +99,16 @@ public class ChooseBookmarkCategoryActivity extends AbstractBookmarkCategoryActi
|
|||
Button mAddButton;
|
||||
ImageButton mCancel;
|
||||
View mNewLayout;
|
||||
|
||||
InputMethodManager mImm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
|
||||
private void createCategory()
|
||||
{
|
||||
if (mNewName.getText().length() > 0)
|
||||
final Editable e = mNewName.getText();
|
||||
if (e.length() > 0)
|
||||
{
|
||||
createNewCategory(mNewName.getText().toString());
|
||||
createNewCategory(e.toString());
|
||||
|
||||
mImm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
|
||||
}
|
||||
}
|
||||
|
@ -128,6 +126,7 @@ public class ChooseBookmarkCategoryActivity extends AbstractBookmarkCategoryActi
|
|||
{
|
||||
mRootView = getLayoutInflater().inflate(R.layout.choose_category_footer, null);
|
||||
getListView().addFooterView(mRootView);
|
||||
|
||||
mNewName = (EditText)mRootView.findViewById(R.id.chs_footer_field);
|
||||
|
||||
mAddButton = (Button)mRootView.findViewById(R.id.chs_footer_button);
|
||||
|
@ -147,13 +146,15 @@ public class ChooseBookmarkCategoryActivity extends AbstractBookmarkCategoryActi
|
|||
mCancel.setOnClickListener(this);
|
||||
|
||||
mNewLayout = mRootView.findViewById(R.id.chs_footer_new_layout);
|
||||
|
||||
mNewName.setOnEditorActionListener(new EditText.OnEditorActionListener()
|
||||
{
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
|
||||
{
|
||||
if (actionId == EditorInfo.IME_ACTION_DONE ||
|
||||
(event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER))
|
||||
(event.getAction() == KeyEvent.ACTION_DOWN &&
|
||||
event.getKeyCode() == KeyEvent.KEYCODE_ENTER))
|
||||
{
|
||||
createCategory();
|
||||
return true;
|
||||
|
@ -165,9 +166,7 @@ public class ChooseBookmarkCategoryActivity extends AbstractBookmarkCategoryActi
|
|||
|
||||
private void createNewCategory(String name)
|
||||
{
|
||||
// Note that Point result from the intent is actually a pair of (category index, bookmark index in category).
|
||||
final Point cab = ((ParcelablePoint)getIntent().getParcelableExtra(BookmarkActivity.PIN)).getPoint();
|
||||
final int index = mManager.createCategory(mManager.getBookmark(cab.x, cab.y), name);
|
||||
final int index = mManager.createCategory(getBookmarkFromIntent(), name);
|
||||
|
||||
getIntent().putExtra(BookmarkActivity.PIN_SET, index)
|
||||
.putExtra(BookmarkActivity.PIN, new ParcelablePoint(index, 0));
|
||||
|
|
|
@ -29,11 +29,13 @@ public class ChooseBookmarkCategoryAdapter extends AbstractBookmarkCategoryAdapt
|
|||
convertView.setTag(new SingleChoiceHolder((TextView) convertView.findViewById(R.id.sci_set_name),
|
||||
(RadioButton) convertView.findViewById(R.id.sci_checkbox)));
|
||||
}
|
||||
SingleChoiceHolder holder = (SingleChoiceHolder) convertView.getTag();
|
||||
|
||||
final SingleChoiceHolder holder = (SingleChoiceHolder) convertView.getTag();
|
||||
boolean checked = mCheckedPosition == position;
|
||||
holder.name.setText(getItem(position).getName());
|
||||
holder.name.setTextAppearance(getContext(), checked ? android.R.style.TextAppearance_Large : android.R.style.TextAppearance_Medium);
|
||||
holder.checked.setChecked(checked);
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue