嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 5 元微信扫码支付:5 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
仿按键精灵手机版抓抓
using System;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
using System.Xml;
using log4net;
using System.Collections.Generic;
using System.Threading;
using System.Drawing;
using ADevelop;
namespace AndroidDataTransform
{
public partial class FormDataSelect : Form
{
/// <summary>
/// PAD 数据上传下载
/// </summary>
/// <param name="Tag">默认0:PAD-》PC,1:PC-》PAD</param>
public FormDataSelect(int Tag)
{
InitializeComponent();
m_Tag = Tag;
switch (m_Tag)
{
case 1:
break;
default:
break;
}
}
#region 成员变量
static ILog m_log = LogManager.GetLogger(typeof(FormDataSelect));
/// <summary>
/// 判断当前是上传(0),还是下载(1)
/// </summary>
int m_Tag = 0;
#endregion
#region 窗体事件
private void Form1_Load(object sender, EventArgs e)
{
ReadConfig();
string sPath = "c:\\ADevelopTemp";
if (!Directory.Exists(sPath))
{
Directory.CreateDirectory(sPath);
}
}
private void cbbDevices_SelectedIndexChanged(object sender, EventArgs e)
{
var deviceNo = Convert.ToString(cbbDevices.SelectedItem);
txbDeviceInfo.Text = string.Format("{0} {1} {2}({3})"
, AdbHelper.GetDeviceBrand(deviceNo)
, AdbHelper.GetDeviceModel(deviceNo)
, AdbHelper.GetDeviceVersionRelease(deviceNo)
, AdbHelper.GetDeviceVersionSdk(deviceNo));
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
//ProcessHelper.WaitTime = (int)nudWaitTime.Value;
}
#endregion
#region 成员函数
private void GetInfo()
{
Cursor.Current = Cursors.WaitCursor;
ShowInfo("获取信息中···");
try
{
//启动服务
if (!AdbHelper.StartServer())
{
ShowInfo("服务启动失败!");
return;
}
//获取设备列表
var devs = AdbHelper.GetDevices();
if (devs.Length == 0 )
{
ShowInfo("没有连接设备!");
return;
}
if (txbDeviceInfo.Text.Contains("error: device offline"))
{
ShowInfo("设备连接失败,请重新拔插USB线!");
return;
}
cbbDevices.Items.Clear();
cbbDevices.Items.AddRange(devs);
cbbDevices.SelectedIndex = 0;
ShowInfo("信息获取完毕。");
cbbDevices.SelectedItem = mConfig[IndexOfDevices];
}
finally
{
Cursor.Current = Cursors.Default;
}
}
private void ShowInfo(string info)
{
statusStrip.Text = info;
}
#endregion
#region 设置相关
private const int IndexOfDevices = 0;
private const int IndexOfPackages = 1;
private const int IndexOfDbNames = 2;
private const int IndexOfPcPath = 3;
private const int IndexOfWaitTime = 4;
private const int IndexOfExcelPath = 5;
private string[] mConfig = new[] { "", "", "", "", "", "" };
private readonly string mConfigPath = Path.Combine(Application.StartupPath, "adb.ini");
private Thread screenThread;
private Image image;
private int selId = 0;
private void ReadConfig()
{
if (!File.Exists(mConfigPath))
return;
mConfig = File.ReadAllLines(mConfigPath);
if (mConfig == null || mConfig.Length != 6)
mConfig = new[] { "", "", "", "", "", "" };
}
private void SaveConfig()
{
File.WriteAllLines(mConfigPath, mConfig);
}
#endregion
private void startScreenshot()
{
CheckForIllegalCrossThreadCalls = false;
ShowInfo("正在截屏...");
var screen = AdbHelper.getScreenshot();
if(screen == "")
{
ShowInfo("截屏失败!");
}
else
{
ShowInfo("截屏完毕。");
this.image = Image.FromFile(screen, false);
addscreenshot();
}
}
private void addscreenshot()
{
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(delegate { addscreenshot(); }));
return;
}
screenshotPicture.Width = image.Width;
screenshotPicture.Height = image.Height;
screenshotPicture.Image = image;
imgPanel.Controls.Add(screenshotPicture);
}
private void btnRefresh_Click_1(object sender, EventArgs e)
{
GetInfo();
}
bool bDrawStart = false;
Point pointStart = Point.Empty;
Point pointContinue = Point.Empty;
Graphics RegionSelGraphics;
private void screenshotPicture_MouseMove(object sender, MouseEventArgs e)
{
statusStrip.Text = e.X.ToString() ", " e.Y.ToString();
if (bDrawStart)
{
pointContinue = e.Location;
Refresh();
}
}
private void screenshotPicture_MouseUp(object sender, MouseEventArgs e)
{
bDrawStart = false;
}
private void screenshotPicture_Paint(object sender, PaintEventArgs e)
{
if (bDrawStart)
{
int startX = pointStart.X;
int startY = pointStart.Y;
int endX = pointContinue.X - pointStart.X;
int endY = pointContinue.Y - pointStart.Y;
//实时的画矩形
RegionSelGraphics = e.Graphics;
RegionSelGraphics.DrawRectangle(Pens.Black, startX, startY, endX, endY);
selRegionText.Text = startX "," startY "," pointContinue.X "," pointContinue.Y;
}
}
private void screenshotPicture_MouseDown(object sender, MouseEventArgs e)
{
int x = e.X;
int y = e.Y;
string position = x "," y;
Bitmap myBitmap = (Bitmap)screenshotPicture.Image;
Color pixelColor = myBitmap.GetPixel(x, y);
int r = pixelColor.R;
int g = pixelColor.G;
int b = pixelColor.B;
string getColor = ColorTranslator.ToHtml(Color.FromArgb(r, g, b));
switch (this.selId)
{
case -1:
if (bDrawStart)
{
bDrawStart = false;
}
else
{
bDrawStart = true;
pointStart = e.Location;
}
break;
case 1:
button1.BackColor = pixelColor;
posText1.Text = position;
rText1.Text = r.ToString();
gText1.Text = g.ToString();
bText1.Text = b.ToString();
colorText1.Text = getColor;
break;
case 2:
button2.BackColor = pixelColor;
posText2.Text = position;
rText2.Text = r.ToString();
gText2.Text = g.ToString();
bText2.Text = b.ToString();
colorText2.Text = getColor;
break;
case 3:
button3.BackColor = pixelColor;
posText3.Text = position;
rText3.Text = r.ToString();
gText3.Text = g.ToString();
bText3.Text = b.ToString();
colorText3.Text = getColor;
break;
case 4:
button4.BackColor = pixelColor;
posText4.Text = position;
rText4.Text = r.ToString();
gText4.Text = g.ToString();
bText4.Text = b.ToString();
colorText4.Text = getColor;
break;
case 5:
button5.BackColor = pixelColor;
posText5.Text = position;
rText5.Text = r.ToString();
gText5.Text = g.ToString();
bText5.Text = b.ToString();
colorText5.Text = getColor;
break;
case 6:
button6.BackColor = pixelColor;
posText6.Text = position;
rText6.Text = r.ToString();
gText6.Text = g.ToString();
bText6.Text = b.ToString();
colorText6.Text = getColor;
break;
case 7:
button7.BackColor = pixelColor;
posText7.Text = position;
rText7.Text = r.ToString();
gText7.Text = g.ToString();
bText7.Text = b.ToString();
colorText7.Text = getColor;
break;
case 8:
button8.BackColor = pixelColor;
posText8.Text = position;
rText8.Text = r.ToString();
gText8.Text = g.ToString();
bText8.Text = b.ToString();
colorText8.Text = getColor;
break;
case 9:
button9.BackColor = pixelColor;
posText9.Text = position;
rText9.Text = r.ToString();
gText9.Text = g.ToString();
bText9.Text = b.ToString();
colorText9.Text = getColor;
break;
case 10:
button10.BackColor = pixelColor;
posText10.Text = position;
rText10.Text = r.ToString();
gText10.Text = g.ToString();
bText10.Text = b.ToString();
colorText10.Text = getColor;
break;
default:
break;
}
if (this.selId >= 1)
{
TextBox[] posText = new TextBox[11];
TextBox[] rText = new TextBox[11];
TextBox[] gText = new TextBox[11];
TextBox[] bText = new TextBox[11];
TextBox[] colorText = new TextBox[11];
string code;
foreach (System.Windows.Forms.Control control in this.colorCtrlPanel.Controls)
{
if (control.Name.IndexOf("posText") > -1)
{
code = control.Name.Substring(7);
posText[int.Parse(code)] = (TextBox)control;
}
if (control.Name.Substring(1, 5) == "rText")
{
code = control.Name.Substring(5);
rText[int.Parse(code)] = (TextBox)control;
}
if (control.Name.IndexOf("gText") > -1)
{
code = control.Name.Substring(5);
gText[int.Parse(code)] = (TextBox)control;
}
if (control.Name.IndexOf("bText") > -1)
{
code = control.Name.Substring(5);
bText[int.Parse(code)] = (TextBox)control;
}
if (control.Name.IndexOf("colorText") > -1)
{
code = control.Name.Substring(9);
colorText[int.Parse(code)] = (TextBox)control;
}
}
string colorContent = "";
if (posText[1].Text != "")
{
colorContent = "\"" colorText[1].Text.Replace("#", "") "\",\"";
string colors = "";
for (int i = 2; i <= 10; i )
{
string[] firstPos = posText[1].Text.Split(',');
int firstX = int.Parse(firstPos[0]);
int firstY = int.Parse(firstPos[1]);
if (posText[i].Text != "")
{
string[] thisPos = posText[i].Text.Split(',');
int thisX = int.Parse(thisPos[0]);
int thisY = int.Parse(thisPos[1]);
colors = (thisX - firstX).ToString() "|" (thisY - firstY).ToString() "|" colorText[i].Text.Replace("#", "") ",";
}
else
{
break;
}
}
if (colors.Length > 0)
{
colors = colors.Substring(0, colors.Length - 1);
}
colorContent = colors "\"";
multiColorContentText.Text = colorContent;
}
}
}
private void screenshotsBtn_Click(object sender, EventArgs e)
{
if (image != null)
{
image.Dispose();
}
this.screenThread = new Thread(startScreenshot);
this.screenThread.Start();
}
private void button1_Click(object sender, EventArgs e)
{
this.selId = 1;
}
private void button2_Click(object sender, EventArgs e)
{
this.selId = 2;
}
private void button3_Click(object sender, EventArgs e)
{
this.selId = 3;
}
private void button4_Click(object sender, EventArgs e)
{
this.selId = 4;
}
private void button5_Click(object sender, EventArgs e)
{
this.selId = 5;
}
private void button6_Click(object sender, EventArgs e)
{
this.selId = 6;
}
private void button7_Click(object sender, EventArgs e)
{
this.selId = 7;
}
private void button8_Click(object sender, EventArgs e)
{
this.selId = 8;
}
private void button9_Click(object sender, EventArgs e)
{
this.selId = 9;
}
private void button10_Click(object sender, EventArgs e)
{
this.selId = 10;
}
private void copyColorContentBtn_Click(object sender, EventArgs e)
{
if (multiColorContentText.Text != "")
{
Clipboard.SetDataObject(multiColorContentText.Text);
}
}
private void clearMultiMsgBtn_Click(object sender, EventArgs e)
{
foreach (System.Windows.Forms.Control control in this.colorCtrlPanel.Controls)
{
string typename = control.GetType().FullName;
switch(typename)
{
case "System.Windows.Forms.TextBox":
control.Text = "";
break;
case "System.Windows.Forms.Button":
if(control.Name.Substring(0, 6) == "button")
{
control.BackColor = Color.Empty;
}
break;
default:
break;
}
}
}
private void regionBtn_Click(object sender, EventArgs e)
{
this.selId = -1;
}
private void pointSingleGetColorBtn_Click(object sender, EventArgs e)
{
this.selId = 0;
}
private void cpRegionCodeBtn_Click(object sender, EventArgs e)
{
if (selRegionText.Text != "")
{
Clipboard.SetDataObject(selRegionText.Text);
}
}
private void restartAdbBtn_Click(object sender, EventArgs e)
{
Thread restartThread = new Thread(restartAdb);
restartThread.Start();
}
private void restartAdb()
{
ShowInfo("正在重启....");
AdbHelper.KillServer();
AdbHelper.StartServer();
ShowInfo("重启完成!");
MessageBox.Show("重启完成!");
}
}
}