Fixed problem with highlighting the selected item in the file storage list

This commit is contained in:
Philipp Crocoll 2013-09-20 22:01:40 +02:00
parent 176ad6244d
commit 6cb44497d1
3 changed files with 121 additions and 11 deletions

View File

@ -11,7 +11,12 @@ using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using KeePassLib;
using KeePassLib.Keys;
using KeePassLib.Security;
using KeePassLib.Serialization;
using keepass2android.Io;
using keepass2android.view;
using Object = Java.Lang.Object;
namespace keepass2android
@ -20,9 +25,11 @@ namespace keepass2android
public class FileStorageSelectionActivity : ListActivity
{
private string _protocolToSetup;
private FileStorageAdapter _fileStorageAdapter;
class FileStorageAdapter: BaseAdapter
{
private readonly FileStorageSelectionActivity _context;
private List<string> _protocolIds = new List<string>();
@ -39,7 +46,7 @@ namespace keepass2android
public override Object GetItem(int position)
{
return position;
return _protocolIds[position];
}
public override long GetItemId(int position)
@ -49,14 +56,9 @@ namespace keepass2android
public override View GetView(int position, View convertView, ViewGroup parent)
{
LayoutInflater inflater = (LayoutInflater)_context.GetSystemService(LayoutInflaterService);
View v = inflater.Inflate(Resource.Layout.filestorage_selection_listitem, null);
((TextView)v.FindViewById(Resource.Id.filestorage_label)).Text =
App.Kp2a.GetResourceString("filestoragename_"+_protocolIds[position] );
Drawable drawable = App.Kp2a.GetResourceDrawable("ic_storage_" + _protocolIds[position]);
((ImageView)v.FindViewById(Resource.Id.filestorage_logo)).SetImageDrawable(drawable);
v.Click += (sender, args) => _context.OnItemSelected(_protocolIds[position]);
return v;
var view = new FileStorageView(_context, _protocolIds[position], position);
return view;
}
public override int Count
@ -105,9 +107,11 @@ namespace keepass2android
SetContentView(Resource.Layout.filestorage_selection);
this.ListAdapter = new FileStorageAdapter(this);
_fileStorageAdapter = new FileStorageAdapter(this);
this.ListAdapter = _fileStorageAdapter;
FindViewById<ListView>(Android.Resource.Id.List).ItemClick +=
(sender, args) => OnItemSelected((string)_fileStorageAdapter.GetItem(args.Position));
}
protected override void OnSaveInstanceState(Bundle outState)

View File

@ -105,6 +105,7 @@
<Compile Include="views\GroupView.cs" />
<Compile Include="views\GroupRootView.cs" />
<Compile Include="PwGroupListAdapter.cs" />
<Compile Include="views\FileStorageView.cs" />
<Compile Include="views\PwGroupView.cs" />
<Compile Include="settings\PrefsUtil.cs" />
<Compile Include="views\PwEntryView.cs" />

View File

@ -0,0 +1,105 @@
/*
This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file is based on Keepassdroid, Copyright Brian Pellin.
Keepass2Android is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
Keepass2Android is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using Android.App;
using Android.Graphics;
using Android.Graphics.Drawables;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using KeePassLib;
using Android.Text;
using Android.Text.Style;
using Android.Preferences;
using keepass2android.Io;
namespace keepass2android.view
{
public sealed class FileStorageView : ClickView
{
private readonly Activity _activity;
private readonly TextView _textView;
private readonly TextView _textviewDetails;
private int _pos;
private int? _defaultTextColor;
public FileStorageView(IntPtr javaReference, JniHandleOwnership transfer)
: base(javaReference, transfer)
{
}
public FileStorageView(Activity activity, string protocolId, int pos)
: base(activity)
{
_activity = activity;
View ev = Inflate(activity, Resource.Layout.entry_list_entry, null);
_textView = (TextView)ev.FindViewById(Resource.Id.entry_text);
_textView.TextSize = PrefsUtil.GetListTextSize(activity);
_textviewDetails = (TextView)ev.FindViewById(Resource.Id.entry_text_detail);
_textviewDetails.TextSize = PrefsUtil.GetListDetailTextSize(activity);
PopulateView(ev, protocolId, pos);
LayoutParams lp = new LayoutParams(ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.WrapContent);
AddView(ev, lp);
}
private void PopulateView(View ev, string protocolId, int pos)
{
_pos = pos;
ImageView iv = (ImageView)ev.FindViewById(Resource.Id.entry_icon);
Drawable drawable = App.Kp2a.GetResourceDrawable("ic_storage_" + protocolId);
iv.SetImageDrawable(drawable);
String title = App.Kp2a.GetResourceString("filestoragename_" + protocolId);
var str = new SpannableString(title);
_textView.TextFormatted = str;
_textviewDetails.Visibility = ViewStates.Gone;
}
public override void OnClick()
{
}
public override void OnCreateMenu(IContextMenu menu, IContextMenuContextMenuInfo menuInfo)
{
}
public override bool OnContextItemSelected(IMenuItem item)
{
return false;
}
}
}