forked from organicmaps/organicmaps-tmp
[android] [bookmarks] create new category in ChooseBmkCategoriesActivity
This commit is contained in:
parent
846981eddb
commit
ad84d45d9c
6 changed files with 180 additions and 61 deletions
|
@ -1,12 +0,0 @@
|
|||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<ListView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" >
|
||||
</ListView>
|
||||
|
||||
</RelativeLayout>
|
13
android/res/layout/activity_choose_bmk_categories.xml
Normal file
13
android/res/layout/activity_choose_bmk_categories.xml
Normal file
|
@ -0,0 +1,13 @@
|
|||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<ListView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1." >
|
||||
</ListView>
|
||||
</LinearLayout>
|
63
android/res/layout/choose_category_footer.xml
Normal file
63
android/res/layout/choose_category_footer.xml
Normal file
|
@ -0,0 +1,63 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/chs_footer_button"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignBottom="@+id/chs_footer_new_layout"
|
||||
android:layout_alignTop="@+id/chs_footer_new_layout"
|
||||
android:background="@android:drawable/list_selector_background"
|
||||
android:drawableLeft="@android:drawable/ic_input_add"
|
||||
android:drawablePadding="10dp"
|
||||
android:gravity="center_vertical"
|
||||
android:padding="10dp"
|
||||
android:text="@string/add_new_set"
|
||||
android:textAppearance="@android:style/TextAppearance.Large"
|
||||
android:textColor="?android:textColorPrimary" />
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/chs_footer_new_layout"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:visibility="invisible" >
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/chs_footer_cancel_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignBottom="@+id/chs_footer_field"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:background="@android:drawable/list_selector_background"
|
||||
android:padding="10dp"
|
||||
android:src="@android:drawable/ic_delete" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/chs_footer_field"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginBottom="3dp"
|
||||
android:layout_marginTop="6dp"
|
||||
android:layout_toLeftOf="@+id/chs_footer_create_button"
|
||||
android:layout_toRightOf="@+id/chs_footer_cancel_button"
|
||||
android:hint="@string/name" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/chs_footer_create_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignBottom="@+id/chs_footer_field"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:background="@android:drawable/list_selector_background"
|
||||
android:padding="10dp"
|
||||
android:src="@android:drawable/ic_input_add" />
|
||||
</RelativeLayout>
|
||||
|
||||
</RelativeLayout>
|
|
@ -26,8 +26,11 @@ public abstract class AbstractBookmarkCategoryActivity extends AbstractBookmarkL
|
|||
if (menuInfo instanceof AdapterView.AdapterContextMenuInfo)
|
||||
{
|
||||
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
|
||||
mSelectedPosition = info.position;
|
||||
menu.setHeaderTitle(mManager.getCategoryById(mSelectedPosition).getName());
|
||||
if (info.position < getAdapter().getCount())
|
||||
{
|
||||
mSelectedPosition = info.position;
|
||||
menu.setHeaderTitle(mManager.getCategoryById(mSelectedPosition).getName());
|
||||
}
|
||||
}
|
||||
super.onCreateContextMenu(menu, v, menuInfo);
|
||||
}
|
||||
|
|
|
@ -46,16 +46,8 @@ public class BookmarkListActivity extends AbstractBookmarkListActivity
|
|||
setContentView(R.layout.pins);
|
||||
final int setIndex = getIntent().getIntExtra(BookmarkActivity.PIN_SET, -1);
|
||||
mEditContent = getIntent().getBooleanExtra(EDIT_CONTENT, true);
|
||||
if ((mEditedSet = mManager.getCategoryById(setIndex)) == null)
|
||||
{
|
||||
Point bmk = ((ParcelablePoint)getIntent().getParcelableExtra(BookmarkActivity.PIN)).getPoint();
|
||||
mBookmark = mManager.getBookmark(bmk.x, bmk.y);
|
||||
setTitle(R.string.add_new_set);
|
||||
}
|
||||
else
|
||||
{
|
||||
setTitle(mEditedSet.getName());
|
||||
}
|
||||
mEditedSet = mManager.getCategoryById(setIndex);
|
||||
setTitle(mEditedSet.getName());
|
||||
|
||||
mLocation = ((MWMApplication) getApplication()).getLocationService();
|
||||
|
||||
|
@ -101,21 +93,7 @@ public class BookmarkListActivity extends AbstractBookmarkListActivity
|
|||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count)
|
||||
{
|
||||
if (mEditedSet == null)
|
||||
{
|
||||
mEditedSet = mManager.createCategory(mBookmark, s.toString());
|
||||
createListAdapter();
|
||||
setResult(RESULT_OK,
|
||||
new Intent().putExtra(BookmarkActivity.PIN_SET, mManager.getCategoriesCount()-1).
|
||||
putExtra(BookmarkActivity.PIN, new ParcelablePoint(mManager.getCategoriesCount()-1, mEditedSet.getSize()-1))
|
||||
);
|
||||
mIsVisible.setChecked(true);
|
||||
mPinAdapter.notifyDataSetChanged();
|
||||
}
|
||||
else
|
||||
{
|
||||
mEditedSet.setName(s.toString());
|
||||
}
|
||||
mEditedSet.setName(s.toString());
|
||||
setTitle(s.toString());
|
||||
}
|
||||
|
||||
|
|
|
@ -1,15 +1,22 @@
|
|||
package com.mapswithme.maps.bookmarks;
|
||||
|
||||
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.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.View.OnKeyListener;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.HeaderViewListAdapter;
|
||||
import android.widget.ImageButton;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
|
@ -24,13 +31,13 @@ public class ChooseBookmarkCategoryActivity extends AbstractBookmarkCategoryActi
|
|||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_bmk_categories);
|
||||
setListAdapter(mAdapter = new ChooseBookmarkCategoryAdapter(this, getIntent().getIntExtra(BookmarkActivity.PIN_SET, -1)));
|
||||
final FooterHandler handler = new FooterHandler();
|
||||
getListView().setOnItemClickListener(new OnItemClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
|
||||
{
|
||||
handler.switchToAddButton();
|
||||
mAdapter.chooseItem(position);
|
||||
Point cab = ((ParcelablePoint)getIntent().getParcelableExtra(BookmarkActivity.PIN)).getPoint();
|
||||
BookmarkCategory cat = mManager.getCategoryById(position);
|
||||
|
@ -38,6 +45,7 @@ public class ChooseBookmarkCategoryActivity extends AbstractBookmarkCategoryActi
|
|||
getIntent().putExtra(BookmarkActivity.PIN, new ParcelablePoint(position, cat.getSize()-1));
|
||||
}
|
||||
});
|
||||
setListAdapter(mAdapter = new ChooseBookmarkCategoryAdapter(this, getIntent().getIntExtra(BookmarkActivity.PIN_SET, -1)));
|
||||
registerForContextMenu(getListView());
|
||||
}
|
||||
|
||||
|
@ -57,25 +65,9 @@ public class ChooseBookmarkCategoryActivity extends AbstractBookmarkCategoryActi
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu)
|
||||
protected ChooseBookmarkCategoryAdapter getAdapter()
|
||||
{
|
||||
getMenuInflater().inflate(R.menu.activity_pin_sets, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item)
|
||||
{
|
||||
if (item.getItemId() == R.id.pinsets_add)
|
||||
{
|
||||
startActivityForResult(
|
||||
new Intent(this, BookmarkListActivity.class).
|
||||
putExtra(BookmarkActivity.PIN_SET, mManager.getCategoriesCount()).
|
||||
putExtra(BookmarkActivity.PIN, getIntent().getParcelableExtra(BookmarkActivity.PIN)).
|
||||
putExtra(BookmarkListActivity.EDIT_CONTENT, enableEditing()),
|
||||
REQUEST_CREATE_CATEGORY);
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
return (ChooseBookmarkCategoryAdapter)((HeaderViewListAdapter) getListView().getAdapter()).getWrappedAdapter();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -94,4 +86,86 @@ public class ChooseBookmarkCategoryActivity extends AbstractBookmarkCategoryActi
|
|||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
private class FooterHandler implements View.OnClickListener
|
||||
{
|
||||
View mRootView;
|
||||
EditText mNewName;
|
||||
Button mAddButton;
|
||||
ImageButton mCancel;
|
||||
View mNewLayout;
|
||||
InputMethodManager mImm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
|
||||
public FooterHandler()
|
||||
{
|
||||
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);
|
||||
mAddButton.setOnClickListener(this);
|
||||
mRootView.findViewById(R.id.chs_footer_create_button).setOnClickListener(new OnClickListener()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
if ( mNewName.getText().length() > 0) {
|
||||
createNewCategory(mNewName.getText().toString());
|
||||
mImm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
mCancel = (ImageButton)mRootView.findViewById(R.id.chs_footer_cancel_button);
|
||||
mCancel.setOnClickListener(this);
|
||||
mNewLayout = mRootView.findViewById(R.id.chs_footer_new_layout);
|
||||
mNewName.setOnKeyListener(new OnKeyListener() {
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
// If the event is a key-down event on the "enter" button
|
||||
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
|
||||
(keyCode == KeyEvent.KEYCODE_ENTER && mNewName.getText().length() > 0)) {
|
||||
// Perform action on key press
|
||||
createNewCategory(mNewName.getText().toString());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void createNewCategory(String name)
|
||||
{
|
||||
Point cab = ((ParcelablePoint)getIntent().getParcelableExtra(BookmarkActivity.PIN)).getPoint();
|
||||
mManager.createCategory(mManager.getBookmark(cab.x, cab.y), name);
|
||||
getIntent().putExtra(BookmarkActivity.PIN_SET, mManager.getCategoriesCount()-1).
|
||||
putExtra(BookmarkActivity.PIN, new ParcelablePoint(mManager.getCategoriesCount()-1, 0));
|
||||
switchToAddButton();
|
||||
getAdapter().chooseItem(mManager.getCategoriesCount()-1);
|
||||
}
|
||||
|
||||
private void switchToAddButton()
|
||||
{
|
||||
if (mAddButton.getVisibility() != View.VISIBLE)
|
||||
{
|
||||
mNewName.setText("");
|
||||
mAddButton.setVisibility(View.VISIBLE);
|
||||
mNewLayout.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
if (v.getId() == R.id.chs_footer_button)
|
||||
{
|
||||
mAddButton.setVisibility(View.INVISIBLE);
|
||||
mNewLayout.setVisibility(View.VISIBLE);
|
||||
mNewName.requestFocus();
|
||||
mImm.showSoftInput(mNewName, InputMethodManager.SHOW_IMPLICIT);
|
||||
}
|
||||
else if (v.getId() == R.id.chs_footer_cancel_button)
|
||||
{
|
||||
switchToAddButton();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue