Skip to content

Instantly share code, notes, and snippets.

@dbeattie71
Forked from slodge/TextViewImeActionBinding
Created March 27, 2014 03:06
Show Gist options
  • Save dbeattie71/9799279 to your computer and use it in GitHub Desktop.
Save dbeattie71/9799279 to your computer and use it in GitHub Desktop.
public class TextViewImeActionBinding : MvxAndroidTargetBinding
{
private bool subscribed;
private ICommand _command;
protected TextView TextView
{
get { return Target as TextView; }
}
public static void Register(IMvxTargetBindingFactoryRegistry registry)
{
registry.RegisterCustomBindingFactory<TextView>("ImeAction", view => new TextViewImeActionBinding(view));
}
public TextViewImeActionBinding(TextView view) : base(view)
{
if (view == null)
Mvx.Trace(MvxTraceLevel.Error, "TextViewImeActionBinding : view is null");
if (view != null)
{
TextView.EditorAction += ViewOnEditorAction;
subscribed = true;
}
}
private void ViewOnEditorAction(object sender, TextView.EditorActionEventArgs args)
{
FireValueChanged(args.ActionId);
//args.ActionId
args.Handled = true;
if (_command == null)
return;
_command.Execute(((TextView)sender).Text);
}
public override Type TargetType
{
get { return typeof(ICommand); }
}
public override MvxBindingMode DefaultMode
{
get { return MvxBindingMode.OneWay; }
}
protected override void SetValueImpl(object target, object value)
{
_command = (ICommand)value;
}
protected override void Dispose(bool isDisposing)
{
if (isDisposing)
{
var view = TextView;
if (view != null && subscribed)
{
view.EditorAction -= ViewOnEditorAction;
}
}
base.Dispose(isDisposing);
}
}
<TextView
local:MvxBind="Text PasswordConfirm; ImeAction RegisterCommand"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
android:imeOptions="actionSend" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment