|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using Android.App;
|
using Android.Content;
|
using Android.OS;
|
using Android.Runtime;
|
using Android.Views;
|
using Android.Widget;
|
using Android.Util;
|
using Android.Views.InputMethods;
|
using Android.Text;
|
|
namespace Shared
|
{
|
/// <summary>
|
/// TextView
|
/// </summary>
|
public class TextView : View
|
{
|
/// <summary>
|
/// 当前视图
|
/// </summary>
|
/// <value>The android text.</value>
|
AndroidTextView currentAndroidTextView
|
{
|
get
|
{
|
return AndroidView as AndroidTextView;
|
}
|
set
|
{
|
AndroidView = value;
|
}
|
}
|
public TextView()
|
{
|
currentAndroidTextView = new AndroidTextView(Application.Activity,this);
|
}
|
/// <summary>
|
/// 文字大小
|
/// </summary>
|
/// <value>The size of the text.</value>
|
public float TextSize
|
{
|
get
|
{
|
return currentAndroidTextView.TextSize;
|
}
|
set
|
{
|
currentAndroidTextView.SetTextSize(ComplexUnitType.Sp, value);
|
}
|
}
|
|
/// <summary>
|
/// 文本
|
/// </summary>
|
/// <value>The text.</value>
|
public string Text
|
{
|
get
|
{
|
return currentAndroidTextView.Text;
|
}
|
set
|
{
|
|
if (currentAndroidTextView.Text == value)
|
{
|
return;
|
}
|
currentAndroidTextView.Text = value;
|
}
|
}
|
int textID;
|
/// <summary>
|
/// 根据ID获取对应的备注
|
/// </summary>
|
/// <value>The text I.</value>
|
public int TextID
|
{
|
get
|
{
|
return textID;
|
}
|
set
|
{
|
textID = value;
|
Text = Language.StringByID(TextID);
|
}
|
}
|
|
|
bool isSelected;
|
/// <summary>
|
/// Gets or sets a value indicating whether this instance is selected.
|
/// </summary>
|
/// <value><c>true</c> if this instance is selected; otherwise, <c>false</c>.</value>
|
public bool IsSelected
|
{
|
get
|
{
|
return isSelected;
|
}
|
set
|
{
|
isSelected = value;
|
|
if (!IsCanRefresh)
|
{
|
return;
|
}
|
if (isSelected)
|
{
|
|
if (!Background(SelectedImagePath))
|
{
|
BackgroundColor = BackgroundColor;
|
}
|
}
|
else
|
{
|
if (!Background(UnSelectedImagePath))
|
{
|
BackgroundColor = BackgroundColor;
|
}
|
}
|
}
|
}
|
|
/// <summary>
|
/// 刷新大小
|
/// </summary>
|
public override void Refresh()
|
{
|
base.Refresh();
|
IsSelected = isSelected;
|
currentAndroidTextView.Gravity = GravityFlags.Center;
|
}
|
|
uint textColor;
|
/// <summary>
|
/// 文字颜色
|
/// </summary>
|
/// <value>The color of the text.</value>
|
public uint TextColor
|
{
|
get
|
{
|
return textColor;
|
}
|
set
|
{
|
textColor = value;
|
byte r, g, b, a;
|
r = (byte)(textColor / 256 / 256 % 256);
|
g = (byte)(textColor / 256 % 256);
|
b = (byte)(textColor % 256);
|
a = (byte)(textColor / 256 / 256 / 256 % 256);
|
currentAndroidTextView.SetTextColor(Android.Graphics.Color.Argb(a, r, g, b));
|
}
|
}
|
|
bool isMoreLines;
|
public bool IsMoreLines
|
{
|
get
|
{
|
return isMoreLines;
|
}
|
set
|
{
|
isMoreLines = value;
|
currentAndroidTextView.SetSingleLine(!value);
|
}
|
}
|
|
|
/// <summary>
|
/// 选择时背景图路径
|
/// </summary>
|
/// <value>The selected image path.</value>
|
public string SelectedImagePath { get; set; }
|
|
/// <summary>
|
/// 非选中状态的背景图路径
|
/// </summary>
|
/// <value>The un selected image path.</value>
|
public string UnSelectedImagePath { get; set; }
|
|
class AndroidTextView : Android.Widget.TextView
|
{
|
View _view;
|
public AndroidTextView(Context context, View view)
|
: base(context)
|
{
|
_view = view;
|
SetTextColor(Android.Graphics.Color.White);
|
SetPadding(0, 0, 0, 0);
|
TextAlignment = Android.Views.TextAlignment.Center;
|
SetSingleLine(true);
|
SetTextSize(ComplexUnitType.Sp, 10);
|
Ellipsize = TextUtils.TruncateAt.Marquee;
|
SetMarqueeRepeatLimit(int.MaxValue);
|
System.Threading.Tasks.Task.Run(() =>
|
{
|
System.Threading.Thread.Sleep(1000);
|
Application.RunOnMainThread(() =>
|
{
|
Selected = true;
|
});
|
});
|
|
}
|
|
public override bool IsFocused
|
{
|
get
|
{
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// 重写点击事件
|
/// </summary>
|
/// <returns><c>true</c>, if touch event was oned, <c>false</c> otherwise.</returns>
|
/// <param name="e">E.</param>
|
public override bool OnTouchEvent(MotionEvent e)
|
{
|
if (_view != null)
|
{
|
_view.TouchEvent(e);
|
}
|
return base.OnTouchEvent(e);
|
}
|
}
|
}
|
}
|