using System.Text;
namespace PhonewordApp
{
public static class PhonewordTranslator
{
public static string ToNumber(string raw)
{
if (string.IsNullOrWhiteSpace(raw))
{
return "";
}
else
{
raw = raw.ToUpperInvariant();
}
var newNumber = new StringBuilder();
foreach (var c in raw)
{
if ("- 0123456789".Contains(c))
newNumber.Append(c);
else
{
var result = TranslateToNumber(c);
if (result != null)
newNumber.Append(result);
}
}
return newNumber.ToString();
}
static bool Contains(this string keyString, char c)
{
return keyString.IndexOf(c) >= 0;
}
static int? TranslateToNumber(char c)
{
if ("ABC".Contains(c))
return 2;
else if ("DEF".Contains(c))
return 3;
else if ("GHI".Contains(c))
return 4;
else if ("JKL".Contains(c))
return 5;
else if ("MNO".Contains(c))
return 6;
else if ("PQRS".Contains(c))
return 7;
else if ("TUV".Contains(c))
return 8;
else if ("WXYZ".Contains(c))
return 9;
return null;
}
}
}
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using System.Collections.Generic;
namespace PhonewordApp
{
[Activity(Label = "PhonewordApp", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
static readonly List<string> phoneNumbers = new List<string>();
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
var phoneNumberText = FindViewById<EditText>(Resource.Id.PhoneNumberText);
var buttonTranslate = FindViewById<Button>(Resource.Id.buttonTranslate);
var buttonCall = FindViewById<Button>(Resource.Id.buttonCall);
buttonCall.Enabled = false; //禁用【拨号】按钮
string translatedNumber = string.Empty;
buttonTranslate.Click += (s, e) =>
{
translatedNumber = PhonewordTranslator.ToNumber(phoneNumberText.Text);
if (string.IsNullOrWhiteSpace(translatedNumber))
{
buttonCall.Text = "拨号";
buttonCall.Enabled = false;
}
else
{
buttonCall.Text = "播出号码:" + translatedNumber + ",单击确认!";
buttonCall.Enabled = true;
}
};
var buttonCallHistory = FindViewById<Button>(Resource.Id.buttonCallHistory);
buttonCallHistory.Click += (sender, e) =>
{
var intent = new Intent(this, typeof(CallHistoryActivity));
intent.PutStringArrayListExtra("phone_numbers", phoneNumbers);
StartActivity(intent);
};
buttonCall.Click += (s, e) =>
{
phoneNumbers.Add(translatedNumber);
buttonCallHistory.Enabled = true;
// 当单击【拨号】时,尝试拨号
var callDialog = new AlertDialog.Builder(this);
callDialog.SetMessage("电话:" + translatedNumber + ",拨号吗?");
callDialog.SetNeutralButton("拨号", delegate
{
var callIntent = new Intent(Intent.ActionCall);
callIntent.SetData(Android.Net.Uri.Parse("tel:" + translatedNumber));
StartActivity(callIntent);
});
callDialog.SetNegativeButton("取消", delegate { });
callDialog.Show();
};
}
}
}
<?xml version="1.0" encoding="utf-8"?> <resources> …… <string name="CallHistory">拨号记录</string> </resources>
namespace PhonewordApp
{
[Activity(Label = "CallHistoryActivity")]
public class CallHistoryActivity : ListActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
var phoneNumbers =
Intent.Extras.GetStringArrayList("phone_numbers") ?? new string[0];
this.ListAdapter = new ArrayAdapter<string>(this,
Android.Resource.Layout.SimpleListItem1, phoneNumbers);
}
}
}
……
using System.Collections.Generic;
namespace E01PhonewordApp
{
[Activity(Label = "E01PhonewordApp", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
static readonly List<string> phoneNumbers = new List<string>();
protected override void OnCreate(Bundle bundle)
{
……
var buttonCallHistory =
FindViewById<Button>(Resource.Id.buttonCallHistory);
buttonCallHistory.Click += (sender, e) =>
{
var intent = new Intent(this, typeof(CallHistoryActivity));
intent.PutStringArrayListExtra("phone_numbers",
phoneNumbers);
StartActivity(intent);
};
buttonCall.Click += (s, e) =>
{
phoneNumbers.Add(translatedNumber);
buttonCallHistory.Enabled = true;
// 当单击【拨号】时,尝试拨号
var callDialog = new AlertDialog.Builder(this);
callDialog.SetMessage("播出号码:" + translatedNumber +
",拨号吗?");
callDialog.SetNeutralButton("拨号", delegate
{
// Create intent to dial phone
var callIntent = new Intent(Intent.ActionCall);
callIntent.SetData(Android.Net.Uri.Parse("tel:" +
translatedNumber));
StartActivity(callIntent);
});
callDialog.SetNegativeButton("取消", delegate { });
callDialog.Show();
};
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有