forked from organicmaps/organicmaps
Material-styled dialog for new bookmark set dialogs.
This commit is contained in:
parent
03f1d7fa6b
commit
b997575dc9
17 changed files with 276 additions and 236 deletions
|
@ -1,65 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/chs_footer_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
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: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"
|
||||
android:inputType="textCapWords"
|
||||
android:singleLine="true" />
|
||||
|
||||
<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>
|
28
android/res/layout/dialog_edit_text.xml
Normal file
28
android/res/layout/dialog_edit_text.xml
Normal file
|
@ -0,0 +1,28 @@
|
|||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="@dimen/margin_medium_and_half">
|
||||
<TextView
|
||||
android:id="@+id/tv__title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/margin_medium"
|
||||
android:textAppearance="@style/MwmTextAppearance.Title"/>
|
||||
|
||||
<com.mapswithme.maps.widget.CustomTextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/et__input"
|
||||
style="@style/MwmWidget.PlacePage.EditText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/name"
|
||||
android:singleLine="true"/>
|
||||
|
||||
</com.mapswithme.maps.widget.CustomTextInputLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
|
@ -38,7 +38,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:hint="@string/edit_description_hint"
|
||||
android:includeFontPadding="false"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body1"/>
|
||||
android:inputType="textMultiLine"/>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
|
|
26
android/res/layout/item_bookmark_set_chooser.xml
Normal file
26
android/res/layout/item_bookmark_set_chooser.xml
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:paddingLeft="@dimen/margin_medium"
|
||||
android:paddingRight="@dimen/margin_medium">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv__set_name"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body1"/>
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/rb__selected"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="false"
|
||||
android:focusable="false"/>
|
||||
|
||||
</LinearLayout>
|
17
android/res/layout/item_bookmark_set_create.xml
Normal file
17
android/res/layout/item_bookmark_set_create.xml
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:paddingLeft="@dimen/margin_medium"
|
||||
android:paddingRight="@dimen/margin_medium">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/chs_footer_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:text="@string/add_new_set"
|
||||
android:textAppearance="@style/MwmTextAppearance.Button"/>
|
||||
|
||||
</RelativeLayout>
|
|
@ -1,26 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="10dp" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sci_set_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toLeftOf="@+id/sci_checkbox"
|
||||
android:gravity="center_vertical"
|
||||
android:singleLine="true" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/sci_checkbox"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:clickable="false"
|
||||
android:focusable="false" />
|
||||
|
||||
</RelativeLayout>
|
|
@ -1,5 +1,10 @@
|
|||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item
|
||||
android:id="@+id/set_edit"
|
||||
android:title="@string/edit"/>
|
||||
<item
|
||||
android:id="@+id/set_delete"
|
||||
android:title="@string/delete"/>
|
||||
|
||||
</menu>
|
|
@ -1,4 +1,7 @@
|
|||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item android:id="@+id/set_edit" android:title="@string/edit"/>
|
||||
<item android:id="@+id/set_delete" android:title="@string/delete"/>
|
||||
|
||||
</menu>
|
|
@ -1,7 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
<item android:id="@+id/set_edit" android:title="@string/edit"></item>
|
||||
<item android:id="@+id/set_delete" android:title="@string/delete"></item>
|
||||
|
||||
|
||||
</menu>
|
|
@ -81,6 +81,9 @@
|
|||
<item name="android:imeOptions">actionDone</item>
|
||||
<item name="android:textColor">@color/text_place_page</item>
|
||||
<item name="android:textCursorDrawable">@null</item>
|
||||
<item name="android:textColorHint">@color/text_dark_hint</item>
|
||||
<item name="android:textSize">@dimen/text_size_body_1</item>
|
||||
<item name="android:fontFamily">@string/robotoRegular</item>
|
||||
</style>
|
||||
|
||||
<style name="MwmWidget.Toolbar" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
|
||||
|
|
|
@ -20,7 +20,7 @@ public class BookmarkCategoriesActivity extends BaseMwmFragmentActivity
|
|||
final Toolbar toolbar = getToolbar();
|
||||
toolbar.setTitle(R.string.bookmarks);
|
||||
// TODO add menu with search
|
||||
// toolbar.inflateMenu(R.menu.bookmark_categories_context_menu);
|
||||
// toolbar.inflateMenu(R.menu.menu_bookmark_categories);
|
||||
UiUtils.showHomeUpButton(toolbar);
|
||||
displayToolbarAsActionBar();
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.mapswithme.maps.bookmarks;
|
|||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
|
@ -12,9 +13,11 @@ import android.widget.ListView;
|
|||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseMwmListFragment;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.maps.dialog.EditTextDialogFragment;
|
||||
|
||||
public class BookmarkCategoriesFragment extends BaseMwmListFragment
|
||||
public class BookmarkCategoriesFragment extends BaseMwmListFragment implements EditTextDialogFragment.OnTextSaveListener
|
||||
{
|
||||
private int mSelectedPosition;
|
||||
private BookmarkCategoriesAdapter mAdapter;
|
||||
|
@ -59,19 +62,38 @@ public class BookmarkCategoriesFragment extends BaseMwmListFragment
|
|||
{
|
||||
mSelectedPosition = ((AdapterView.AdapterContextMenuInfo) menuInfo).position;
|
||||
|
||||
getActivity().getMenuInflater().inflate(R.menu.bookmark_categories_context_menu, menu);
|
||||
getActivity().getMenuInflater().inflate(R.menu.menu_bookmark_categories, menu);
|
||||
menu.setHeaderTitle(BookmarkManager.INSTANCE.getCategoryById(mSelectedPosition).getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem item)
|
||||
{
|
||||
if (item.getItemId() == R.id.set_delete)
|
||||
switch (item.getItemId())
|
||||
{
|
||||
case R.id.set_delete:
|
||||
BookmarkManager.INSTANCE.deleteCategory(mSelectedPosition);
|
||||
((BookmarkCategoriesAdapter) getListAdapter()).notifyDataSetChanged();
|
||||
break;
|
||||
case R.id.set_edit:
|
||||
final Bundle args = new Bundle();
|
||||
args.putString(EditTextDialogFragment.EXTRA_TITLE, getString(R.string.bookmark_set_name));
|
||||
args.putString(EditTextDialogFragment.EXTRA_POSITIVE_BUTTON, getString(R.string.edit));
|
||||
final EditTextDialogFragment fragment = (EditTextDialogFragment) Fragment.instantiate(getActivity(), EditTextDialogFragment.class.getName());
|
||||
fragment.setOnTextSaveListener(this);
|
||||
fragment.setArguments(args);
|
||||
fragment.show(getActivity().getSupportFragmentManager(), EditTextDialogFragment.class.getName());
|
||||
break;
|
||||
}
|
||||
|
||||
return super.onContextItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveText(String text)
|
||||
{
|
||||
final BookmarkCategory category = BookmarkManager.INSTANCE.getCategoryById(mSelectedPosition);
|
||||
category.setName(text);
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ public class BookmarkListActivity extends BaseMwmFragmentActivity
|
|||
final Toolbar toolbar = getToolbar();
|
||||
toolbar.setTitle(R.string.bookmarks);
|
||||
// TODO add menu with search
|
||||
// toolbar.inflateMenu(R.menu.bookmark_categories_context_menu);
|
||||
// toolbar.inflateMenu(R.menu.menu_bookmark_categories);
|
||||
UiUtils.showHomeUpButton(toolbar);
|
||||
displayToolbarAsActionBar();
|
||||
|
||||
|
|
|
@ -147,7 +147,7 @@ public class BookmarksListFragment extends BaseMwmListFragment
|
|||
if (type == BookmarkListAdapter.TYPE_BOOKMARK)
|
||||
{
|
||||
final MenuInflater inflater = getActivity().getMenuInflater();
|
||||
inflater.inflate(R.menu.pin_sets_context_menu, menu);
|
||||
inflater.inflate(R.menu.menu_bookmarks, menu);
|
||||
|
||||
for (final ShareAction action : ShareAction.ACTIONS.values())
|
||||
{
|
||||
|
|
|
@ -11,7 +11,10 @@ import com.mapswithme.maps.R;
|
|||
|
||||
public class ChooseBookmarkCategoryAdapter extends AbstractBookmarkCategoryAdapter
|
||||
{
|
||||
private int mCheckedPosition = -1;
|
||||
private int mCheckedPosition;
|
||||
|
||||
public static final int VIEW_TYPE_CATEGORY = 0;
|
||||
public static final int VIEW_TYPE_ADD_NEW = 1;
|
||||
|
||||
public ChooseBookmarkCategoryAdapter(Context context, int pos)
|
||||
{
|
||||
|
@ -19,22 +22,46 @@ public class ChooseBookmarkCategoryAdapter extends AbstractBookmarkCategoryAdapt
|
|||
mCheckedPosition = pos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewTypeCount()
|
||||
{
|
||||
return super.getViewTypeCount() + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount()
|
||||
{
|
||||
return super.getCount() + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position)
|
||||
{
|
||||
return position == getCount() - 1 ? VIEW_TYPE_ADD_NEW : VIEW_TYPE_CATEGORY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent)
|
||||
{
|
||||
final int viewType = getItemViewType(position);
|
||||
if (convertView == null)
|
||||
{
|
||||
convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_set_chooser, parent, false);
|
||||
|
||||
convertView.setTag(new SingleChoiceHolder((TextView) convertView.findViewById(R.id.sci_set_name),
|
||||
(RadioButton) convertView.findViewById(R.id.sci_checkbox)));
|
||||
if (viewType == VIEW_TYPE_CATEGORY)
|
||||
{
|
||||
convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_bookmark_set_chooser, parent, false);
|
||||
convertView.setTag(new SingleChoiceHolder(convertView));
|
||||
}
|
||||
else
|
||||
convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_bookmark_set_create, parent, false);
|
||||
}
|
||||
|
||||
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);
|
||||
if (viewType == VIEW_TYPE_CATEGORY)
|
||||
{
|
||||
final SingleChoiceHolder holder = (SingleChoiceHolder) convertView.getTag();
|
||||
boolean checked = mCheckedPosition == position;
|
||||
holder.name.setText(getItem(position).getName());
|
||||
holder.checked.setChecked(checked);
|
||||
}
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
@ -44,10 +71,10 @@ public class ChooseBookmarkCategoryAdapter extends AbstractBookmarkCategoryAdapt
|
|||
TextView name;
|
||||
RadioButton checked;
|
||||
|
||||
public SingleChoiceHolder(TextView name, RadioButton checked)
|
||||
public SingleChoiceHolder(View convertView)
|
||||
{
|
||||
this.name = name;
|
||||
this.checked = checked;
|
||||
name = (TextView) convertView.findViewById(R.id.tv__set_name);
|
||||
checked = (RadioButton) convertView.findViewById(R.id.rb__selected);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,56 +1,48 @@
|
|||
package com.mapswithme.maps.bookmarks;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Point;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.view.KeyEvent;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseMwmListFragment;
|
||||
import com.mapswithme.maps.bookmarks.data.Bookmark;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.maps.bookmarks.data.ParcelablePoint;
|
||||
import com.mapswithme.maps.dialog.EditTextDialogFragment;
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
|
||||
public class ChooseBookmarkCategoryFragment extends BaseMwmListFragment
|
||||
public class ChooseBookmarkCategoryFragment extends BaseMwmListFragment implements EditTextDialogFragment.OnTextSaveListener
|
||||
{
|
||||
private FooterHelper mFooterHelper;
|
||||
private ChooseBookmarkCategoryAdapter mAdapter;
|
||||
private Bookmark mBookmark;
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState)
|
||||
{
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
final ListView listView = getListView();
|
||||
mFooterHelper = new FooterHelper(listView);
|
||||
// Set adapter only after FooterHandler is initialized and added into layout.
|
||||
mAdapter = new ChooseBookmarkCategoryAdapter(getActivity(), getArguments().getInt(ChooseBookmarkCategoryActivity.BOOKMARK_SET, 0));
|
||||
setListAdapter(mAdapter);
|
||||
registerForContextMenu(listView);
|
||||
mBookmark = getBookmarkFromIntent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, int position, long id)
|
||||
{
|
||||
mFooterHelper.switchToAddButton();
|
||||
mAdapter.chooseItem(position);
|
||||
if (mAdapter.getItemViewType(position) == ChooseBookmarkCategoryAdapter.VIEW_TYPE_ADD_NEW)
|
||||
showCreateCategoryDialog();
|
||||
else
|
||||
{
|
||||
mAdapter.chooseItem(position);
|
||||
|
||||
final Bookmark bmk = getBookmarkFromIntent();
|
||||
bmk.setCategoryId(position);
|
||||
getActivity().getIntent().putExtra(ChooseBookmarkCategoryActivity.BOOKMARK,
|
||||
new ParcelablePoint(bmk.getCategoryId(), bmk.getBookmarkId()));
|
||||
mBookmark.setCategoryId(position);
|
||||
getActivity().getIntent().putExtra(ChooseBookmarkCategoryActivity.BOOKMARK,
|
||||
new ParcelablePoint(mBookmark.getCategoryId(), mBookmark.getBookmarkId()));
|
||||
|
||||
getActivity().onBackPressed();
|
||||
getActivity().onBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
private Bookmark getBookmarkFromIntent()
|
||||
|
@ -61,101 +53,32 @@ public class ChooseBookmarkCategoryFragment extends BaseMwmListFragment
|
|||
return BookmarkManager.INSTANCE.getBookmark(cab.x, cab.y);
|
||||
}
|
||||
|
||||
private class FooterHelper implements View.OnClickListener
|
||||
private void showCreateCategoryDialog()
|
||||
{
|
||||
View mRootView;
|
||||
EditText mNewName;
|
||||
Button mAddButton;
|
||||
View mNewLayout;
|
||||
|
||||
InputMethodManager mImm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
|
||||
public FooterHelper(ViewGroup root)
|
||||
{
|
||||
mRootView = getActivity().getLayoutInflater().inflate(R.layout.choose_category_footer, root, false);
|
||||
getListView().addFooterView(mRootView);
|
||||
|
||||
mAddButton = (Button) mRootView.findViewById(R.id.chs_footer_button);
|
||||
mAddButton.setOnClickListener(this);
|
||||
mNewLayout = mRootView.findViewById(R.id.chs_footer_new_layout);
|
||||
mNewLayout.findViewById(R.id.chs_footer_create_button).setOnClickListener(this);
|
||||
mNewLayout.findViewById(R.id.chs_footer_cancel_button).setOnClickListener(this);
|
||||
mNewName = (EditText) mNewLayout.findViewById(R.id.chs_footer_field);
|
||||
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))
|
||||
{
|
||||
createCategory();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void createCategory()
|
||||
{
|
||||
final Editable e = mNewName.getText();
|
||||
if (e.length() > 0)
|
||||
{
|
||||
createCategory(e.toString());
|
||||
mImm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private void createCategory(String name)
|
||||
{
|
||||
final int category = BookmarkManager.INSTANCE.createCategory(name);
|
||||
getBookmarkFromIntent().setCategoryId(category);
|
||||
|
||||
getActivity().getIntent().putExtra(ChooseBookmarkCategoryActivity.BOOKMARK_SET, category)
|
||||
.putExtra(ChooseBookmarkCategoryActivity.BOOKMARK, new ParcelablePoint(category, 0));
|
||||
|
||||
getArguments().putInt(ChooseBookmarkCategoryActivity.BOOKMARK_SET, category);
|
||||
getArguments().putParcelable(ChooseBookmarkCategoryActivity.BOOKMARK, new ParcelablePoint(category, 0));
|
||||
|
||||
switchToAddButton();
|
||||
|
||||
mAdapter.chooseItem(category);
|
||||
|
||||
Statistics.INSTANCE.trackGroupCreated();
|
||||
}
|
||||
|
||||
private void switchToAddButton()
|
||||
{
|
||||
if (mAddButton.getVisibility() != View.VISIBLE)
|
||||
{
|
||||
mNewName.setText("");
|
||||
mAddButton.setVisibility(View.VISIBLE);
|
||||
mNewLayout.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
switch (v.getId())
|
||||
{
|
||||
case R.id.chs_footer_create_button:
|
||||
createCategory();
|
||||
getActivity().onBackPressed();
|
||||
break;
|
||||
case R.id.chs_footer_button:
|
||||
mAddButton.setVisibility(View.INVISIBLE);
|
||||
mNewLayout.setVisibility(View.VISIBLE);
|
||||
mNewName.requestFocus();
|
||||
mImm.showSoftInput(mNewName, InputMethodManager.SHOW_IMPLICIT);
|
||||
break;
|
||||
case R.id.chs_footer_cancel_button:
|
||||
switchToAddButton();
|
||||
break;
|
||||
}
|
||||
}
|
||||
final Bundle args = new Bundle();
|
||||
args.putString(EditTextDialogFragment.EXTRA_TITLE, "New group");
|
||||
final EditTextDialogFragment fragment = (EditTextDialogFragment) Fragment.instantiate(getActivity(), EditTextDialogFragment.class.getName());
|
||||
fragment.setOnTextSaveListener(this);
|
||||
fragment.setArguments(args);
|
||||
fragment.show(getActivity().getSupportFragmentManager(), EditTextDialogFragment.class.getName());
|
||||
}
|
||||
|
||||
private void createCategory(String name)
|
||||
{
|
||||
final int category = BookmarkManager.INSTANCE.createCategory(name);
|
||||
mBookmark.setCategoryId(category);
|
||||
|
||||
getActivity().getIntent().putExtra(ChooseBookmarkCategoryActivity.BOOKMARK_SET, category)
|
||||
.putExtra(ChooseBookmarkCategoryActivity.BOOKMARK, new ParcelablePoint(category, 0));
|
||||
|
||||
mAdapter.chooseItem(category);
|
||||
|
||||
Statistics.INSTANCE.trackGroupCreated();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveText(String text)
|
||||
{
|
||||
createCategory(text);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
package com.mapswithme.maps.dialog;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseMwmDialogFragment;
|
||||
|
||||
public class EditTextDialogFragment extends BaseMwmDialogFragment
|
||||
{
|
||||
public static final String EXTRA_TITLE = "DialogTitle";
|
||||
public static final String EXTRA_POSITIVE_BUTTON = "PositiveText";
|
||||
public static final String EXTRA_NEGATIVE_BUTTON = "NegativeText";
|
||||
|
||||
private String mTitle;
|
||||
private EditText mEtInput;
|
||||
|
||||
public interface OnTextSaveListener
|
||||
{
|
||||
void onSaveText(String text);
|
||||
}
|
||||
|
||||
private OnTextSaveListener mTextSaveListener;
|
||||
|
||||
public EditTextDialogFragment() {}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState)
|
||||
{
|
||||
final Bundle args = getArguments();
|
||||
String positiveButtonText = getString(R.string.ok);
|
||||
String negativeButtonText = getString(R.string.cancel);
|
||||
if (args != null)
|
||||
{
|
||||
mTitle = args.getString(EXTRA_TITLE);
|
||||
positiveButtonText = args.getString(EXTRA_POSITIVE_BUTTON);
|
||||
negativeButtonText = args.getString(EXTRA_NEGATIVE_BUTTON);
|
||||
}
|
||||
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).
|
||||
setView(buildView()).
|
||||
setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
if (mTextSaveListener != null)
|
||||
mTextSaveListener.onSaveText(mEtInput.getText().toString());
|
||||
}
|
||||
}
|
||||
).setNegativeButton(negativeButtonText, new DialogInterface.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
public void setOnTextSaveListener(OnTextSaveListener listener)
|
||||
{
|
||||
mTextSaveListener = listener;
|
||||
}
|
||||
|
||||
private View buildView()
|
||||
{
|
||||
@SuppressLint("InflateParams") final View root = getActivity().getLayoutInflater().inflate(R.layout.dialog_edit_text, null);
|
||||
mEtInput = (EditText) root.findViewById(R.id.et__input);
|
||||
((TextView) root.findViewById(R.id.tv__title)).setText(mTitle);
|
||||
return root;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue