[android] [bookmarks] change bookmark category choosing mechanism

This commit is contained in:
Alexei Vitenko 2013-01-24 20:25:18 +03:00 committed by Alex Zolotarev
parent 96921d7ed5
commit 846981eddb
3 changed files with 72 additions and 29 deletions

View file

@ -44,6 +44,10 @@ public class BookmarkActivity extends AbstractBookmarkActivity
private ImageView mChooserImage;
private TextView mChooserName;
private IconsAdapter mIconsAdapter;
private EditText mDescr;
private TextWatcher mNameWatcher;
private TextWatcher mDescrWatcher;
@Override
public void onCreate(Bundle savedInstanceState)
@ -74,13 +78,23 @@ public class BookmarkActivity extends AbstractBookmarkActivity
//mChooserName.setText(mIcons.get(position).getName());
}
private void refreshValuesInViews()
{
updateColorChooser(mIcons.indexOf(mPin.getIcon()));
mSetName.setText(mPin.getCategoryName());
// This hack move cursor to the end of bookmark name
mName.setText("");
mName.append(mPin.getName());
mDescr.setText(mPin.getBookmarkDescription());
}
private void setUpViews()
{
View colorChooser = findViewById(R.id.pin_color_chooser);
mChooserImage = (ImageView)colorChooser.findViewById(R.id.row_color_image);
mIcons = mManager.getIcons();
updateColorChooser(mIcons.indexOf(mPin.getIcon()));
colorChooser.setOnClickListener(new OnClickListener()
{
@ -103,12 +117,11 @@ public class BookmarkActivity extends AbstractBookmarkActivity
}
});
mSetName = (TextView) findViewById(R.id.pin_button_set_name);
mSetName.setText(mPin.getCategoryName());
mName = (EditText) findViewById(R.id.pin_name);
// This hack move cursor to the end of bookmark name
mName.setText("");
mName.append(mPin.getName());
mName.addTextChangedListener(new TextWatcher()
mDescr = (EditText)findViewById(R.id.pin_description);
refreshValuesInViews();
mNameWatcher = new TextWatcher()
{
@Override
@ -127,11 +140,8 @@ public class BookmarkActivity extends AbstractBookmarkActivity
public void afterTextChanged(Editable s)
{
}
});
EditText descr = (EditText)findViewById(R.id.pin_description);
descr.setText(mPin.getBookmarkDescription());
descr.addTextChangedListener(new TextWatcher()
};
mDescrWatcher = new TextWatcher()
{
@Override
@ -149,7 +159,34 @@ public class BookmarkActivity extends AbstractBookmarkActivity
public void afterTextChanged(Editable s)
{
}
});
};
// Set up text watchers only after filling text fields
}
private void setUpWatchers()
{
mName.addTextChangedListener(mNameWatcher);
mDescr.addTextChangedListener(mDescrWatcher);
}
private void removeWatchers()
{
mName.removeTextChangedListener(mNameWatcher);
mDescr.removeTextChangedListener(mDescrWatcher);
}
@Override
protected void onStart()
{
super.onStart();
setUpWatchers();
}
@Override
protected void onStop()
{
removeWatchers();
super.onStop();
}
@Override
@ -226,14 +263,10 @@ public class BookmarkActivity extends AbstractBookmarkActivity
{
if (requestCode == REQUEST_CODE_SET && resultCode == RESULT_OK)
{
int candidate = data.getIntExtra(PIN_SET, -1);
BookmarkCategory set = mManager.getCategoryById(candidate);
if (set != null)
{
if (mCurrentCategoryId != candidate)
mPin.setCategory(set.getName(), mCurrentCategoryId = candidate);
mSetName.setText(set.getName());
}
Point pin = ((ParcelablePoint)data.getParcelableExtra(PIN)).getPoint();
mPin = mManager.getBookmark(pin.x, pin.y);
refreshValuesInViews();
mCurrentCategoryId = mPin.getCategoryId();
}
super.onActivityResult(requestCode, resultCode, data);
}

View file

@ -1,14 +1,19 @@
package com.mapswithme.maps.bookmarks;
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.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import com.mapswithme.maps.R;
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
import com.mapswithme.maps.bookmarks.data.ParcelablePoint;
public class ChooseBookmarkCategoryActivity extends AbstractBookmarkCategoryActivity
{
@ -21,14 +26,25 @@ public class ChooseBookmarkCategoryActivity extends AbstractBookmarkCategoryActi
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bmk_categories);
setListAdapter(mAdapter = new ChooseBookmarkCategoryAdapter(this, getIntent().getIntExtra(BookmarkActivity.PIN_SET, -1)));
getListView().setOnItemClickListener(mAdapter);
getListView().setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
mAdapter.chooseItem(position);
Point cab = ((ParcelablePoint)getIntent().getParcelableExtra(BookmarkActivity.PIN)).getPoint();
BookmarkCategory cat = mManager.getCategoryById(position);
mManager.getBookmark(cab.x, cab.y).setCategory(cat.getName(), position);
getIntent().putExtra(BookmarkActivity.PIN, new ParcelablePoint(position, cat.getSize()-1));
}
});
registerForContextMenu(getListView());
}
@Override
public void onBackPressed()
{
setResult(RESULT_OK, new Intent().putExtra(BookmarkActivity.PIN_SET, mAdapter.getCheckedItemPosition()));
setResult(RESULT_OK, new Intent().putExtra(BookmarkActivity.PIN, getIntent().getParcelableExtra(BookmarkActivity.PIN)));
super.onBackPressed();
}

View file

@ -11,7 +11,7 @@ import android.widget.TextView;
import com.mapswithme.maps.R;
public class ChooseBookmarkCategoryAdapter extends AbstractBookmarkCategoryAdapter implements OnItemClickListener, Chooseable
public class ChooseBookmarkCategoryAdapter extends AbstractBookmarkCategoryAdapter implements Chooseable
{
private int mCheckedPosition = -1;
@ -62,10 +62,4 @@ public class ChooseBookmarkCategoryAdapter extends AbstractBookmarkCategoryAdapt
{
return mCheckedPosition;
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
chooseItem(position);
}
}