using System;
|
using System.Collections.Generic;
|
using System.Text;
|
|
namespace Shared.Phone
|
{
|
/// <summary>
|
/// 行条类型的进度条控件
|
/// </summary>
|
public class ProgressRowBar : FrameLayout
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// 进度条能否往回走(默认不可以)
|
/// </summary>
|
public bool ProgressBarGoback = false;
|
/// <summary>
|
/// 会移动的进度条
|
/// </summary>
|
private FrameLayout btnProgressBar = null;
|
/// <summary>
|
/// 数值百分比文本的容器
|
/// </summary>
|
private FrameLayout frameProgressBack = null;
|
/// <summary>
|
/// 显示数值百分比的控件
|
/// </summary>
|
private NormalViewControl btnProgressTextView = null;
|
/// <summary>
|
/// 线程是否运行
|
/// </summary>
|
private bool isThreadAction = false;
|
/// <summary>
|
/// 模式区分
|
/// </summary>
|
private int m_ModeDiv = -1;
|
|
/// <summary>
|
/// 进度条是否可视
|
/// </summary>
|
public new bool Visible
|
{
|
get { return base.Visible; }
|
set
|
{
|
if (this.frameProgressBack != null)
|
{
|
this.frameProgressBack.Visible = value;
|
}
|
base.Visible = value;
|
}
|
}
|
|
#endregion
|
|
#region ■ 初始化_____________________________
|
|
/// <summary>
|
/// 行条类型的进度条控件
|
/// </summary>
|
/// <param name="width">
|
/// <para>模式1:会动的那个进度条的宽度(非真实值)</para>
|
/// <para>模式2:进度条在持续无限的来回移动的区域宽度(非真实值)</para>
|
/// </param>
|
/// <param name="height">
|
/// <para>模式1:会动的那个进度条的高度(非真实值)</para>
|
/// <para>模式2:进度条在持续无限的来回移动的高度(非真实值)</para>
|
/// </param>
|
public ProgressRowBar(int width, int height)
|
{
|
this.Height = Application.GetRealHeight(height);
|
this.Width = Application.GetRealWidth(width);
|
this.BackgroundColor = 0xffe6e6e6;
|
this.Radius = (uint)Application.GetRealHeight(height) / 2;
|
}
|
|
#endregion
|
|
#region ■ 模式1______________________________
|
|
/// <summary>
|
/// 模式1 该模式为:手动填写进度值
|
/// </summary>
|
/// <param name="showText">
|
/// <para>是否在进度条上方显示数值百分比</para>
|
/// <para>请确保控件的上方有足够的区域(注:请不要扩大此控件的高度)</para>
|
/// </param>
|
public void StartMode1(bool showText = false)
|
{
|
if (m_ModeDiv != -1) { return; }
|
this.m_ModeDiv = 1;
|
|
//会移动的进度条
|
this.btnProgressBar = new FrameLayout();
|
btnProgressBar.Width = 0;
|
btnProgressBar.Height = this.Height;
|
btnProgressBar.BackgroundColor = 0xfffb744a;
|
btnProgressBar.Radius = (uint)this.Height / 2;
|
this.AddChidren(btnProgressBar);
|
|
if (showText == true)
|
{
|
//进度值文本
|
this.frameProgressBack = new FrameLayout();
|
frameProgressBack.Width = Application.GetRealWidth(120);
|
frameProgressBack.Height = Application.GetRealHeight(60);
|
frameProgressBack.Y = this.Y - Application.GetRealHeight(60);
|
frameProgressBack.X = this.X - Application.GetRealWidth(84) / 2;
|
this.Parent.AddChidren(frameProgressBack);
|
|
var btnProgressPic = new PicViewControl(84, 60);
|
btnProgressPic.UnSelectedImagePath = "Item/ProgressMsg.png";
|
btnProgressPic.Gravity = Gravity.CenterHorizontal;
|
frameProgressBack.AddChidren(btnProgressPic);
|
this.btnProgressTextView = new NormalViewControl(120, 45, true);
|
btnProgressTextView.TextSize = 10;
|
btnProgressTextView.TextAlignment = TextAlignment.Center;
|
btnProgressTextView.Text = "0%";
|
btnProgressTextView.Gravity = Gravity.CenterHorizontal;
|
frameProgressBack.AddChidren(btnProgressTextView);
|
}
|
}
|
|
/// <summary>
|
/// 重置进度条(只对模式1有效)
|
/// </summary>
|
public void ResetProgressBar()
|
{
|
if (this.m_ModeDiv == 1 && this.btnProgressBar != null)
|
{
|
this.btnProgressBar.Width = 0;
|
}
|
}
|
|
/// <summary>
|
/// 设置进度值
|
/// </summary>
|
/// <param name="value">此值为百分比值(也就是小于或者等于1的)</param>
|
public void SetValue(decimal value)
|
{
|
this.SetValueEx(value);
|
}
|
|
/// <summary>
|
/// 设置进度值
|
/// </summary>
|
/// <param name="value">进度值,内部会除以maxValue</param>
|
/// <param name="maxValue">最大值</param>
|
public void SetValue(decimal value, decimal maxValue)
|
{
|
decimal result = value / maxValue;
|
this.SetValueEx(result);
|
}
|
|
/// <summary>
|
/// 设置进度值
|
/// </summary>
|
/// <param name="value"></param>
|
private void SetValueEx(decimal value)
|
{
|
if (btnProgressBar == null || this.m_ModeDiv != 1)
|
{
|
return;
|
}
|
if (value > 1) { value = 1; }
|
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
int width = (int)(value * this.Width);
|
if (this.ProgressBarGoback == false && btnProgressBar.Width >= width)
|
{
|
//不能让进度条往回走
|
return;
|
}
|
btnProgressBar.Width = width;
|
if (this.btnProgressTextView != null)
|
{
|
//文本显示
|
btnProgressTextView.Text = ((int)(value * 100)) + "%";
|
//文本显示的那个图片框移动
|
this.frameProgressBack.X = this.X + btnProgressBar.Right - frameProgressBack.Width / 2;
|
}
|
});
|
}
|
|
#endregion
|
|
#region ■ 模式2______________________________
|
|
/// <summary>
|
/// 模式2 该模式为:不能手动指定进度值,由内部线程处理,进度条在持续无限的来回移动
|
/// </summary>
|
/// <param name="proWidth">持续无限的来回移动的进度条的宽度(非真实值)</param>
|
public void StartMode2(int proWidth = 100)
|
{
|
if (m_ModeDiv != -1) { return; }
|
this.m_ModeDiv = 2;
|
|
//会移动的进度条
|
this.btnProgressBar = new FrameLayout();
|
btnProgressBar.Width = Application.GetRealWidth(proWidth);
|
btnProgressBar.Height = this.Height;
|
btnProgressBar.BackgroundColor = 0xfffb744a;
|
btnProgressBar.Radius = (uint)this.Height / 2;
|
this.AddChidren(btnProgressBar);
|
|
//开启模式2的线程
|
this.StartMode2Thread();
|
}
|
|
/// <summary>
|
/// 重新开启模式2
|
/// </summary>
|
public void ReStartMode2()
|
{
|
//开启模式2的线程
|
this.StartMode2Thread();
|
}
|
|
/// <summary>
|
/// 暂停模式2
|
/// </summary>
|
public void StopMode2()
|
{
|
this.isThreadAction = false;
|
}
|
|
/// <summary>
|
/// 开启模式2的线程
|
/// </summary>
|
private void StartMode2Thread()
|
{
|
if (this.isThreadAction == true)
|
{
|
return;
|
}
|
this.isThreadAction = true;
|
int moveLength = Application.GetRealWidth(30);
|
HdlThreadLogic.Current.RunThread(() =>
|
{
|
while (this.Parent != null && isThreadAction == true)
|
{
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
if (this.btnProgressBar.X >= this.Width)
|
{
|
//超出右边之后,再次从左边循环
|
this.btnProgressBar.X = -this.btnProgressBar.Width;
|
return;
|
}
|
this.btnProgressBar.X += moveLength;
|
}, ShowErrorMode.NO);
|
System.Threading.Thread.Sleep(150);
|
}
|
});
|
}
|
|
#endregion
|
}
|
}
|