Mono的简单例子
一直对移动端开发有些兴趣,但苦于不会Java,好在终于找到了个好玩的。
安装方法略了,先建立一个玩玩

不多说,贴代码了,需要注意的只有些JAVA和C#写法不太一样的地方,不细介绍了,因为没什么经验,乱试的,所以也没什么规范,随便看看就好
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 Java.Util; namespace AndroidHotelServiceTest
{
[Activity(Label = "My Activity")]
public class ActivityCalendar : Activity
{
protected override Dialog OnCreateDialog(int id)
{
if (id == 1)
{
return new DatePickerDialog(this, new DDialogLisetener(this), 2013, 11, 11);
}
return base.OnCreateDialog(0);
} protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Create your application here
SetContentView(Resource.Layout.CalendarView);
Button button = FindViewById<Button>(Resource.Id.btClose);
button.Click += delegate
{
Intent intent = new Intent();
intent.SetClass(this, typeof(ActivityHotel));
StartActivity(intent);
}; ShowDialog(1); }
} public class DDialogLisetener : DatePickerDialog.IOnDateSetListener
{
private Context _context;
public DDialogLisetener(Context context)
{
_context = context;
} public void OnDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth)
{
String sDayOfWeek = getDayOfWeek(year, monthOfYear, dayOfMonth);
//Toast.makeText(CreateParty.this, "sdf", Toast.LENGTH_LONG).show();
int m_nYear = year;
int m_nMonth = monthOfYear + 1;
int m_nDay = dayOfMonth;
Toast.MakeText(_context, "ddd", ToastLength.Long).Show();
Toast.MakeText(_context, m_nYear + "年" + m_nMonth + "月" + m_nDay + "日 ", ToastLength.Long).Show();
} private string getDayOfWeek(int tmpYear, int tmpMonth, int tmpDay)
{
String myWeek = null;
String sYear = tmpYear.ToString();
// 取年的后两位
String sYearTwo = sYear.Substring(sYear.Length - 2); int y = tmpYear; int m = tmpMonth + 1;
int c = 20;
int d = tmpDay;
int w = (y + (y / 4) + (c / 4) - 2 * c
+ (26 * (m + 1) / 10) + d - 1) % 7; switch (w)
{
case 0:
myWeek = "日";
break;
case 1:
myWeek = "一";
break;
case 2:
myWeek = "二";
break;
case 3:
myWeek = "三";
break;
case 4:
myWeek = "四";
break;
case 5:
myWeek = "五";
break;
case 6:
myWeek = "六";
break;
default:
break;
}
return myWeek; } public void Dispose()
{
this.Dispose();
} public IntPtr Handle
{
get { return IntPtr.Zero; }
}
}
}
参考了不少网上的代码
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.Media;
using Android.Content.Res;
using Java.IO; namespace AndroidHotelServiceTest
{
public class BeepManager
{
private static Activity m_CurrentActivity;
private static MediaPlayer m_MediaPlayer = null; private static MediaPlayer BuildMediaPlayer(Context context)
{
MediaPlayer player = new MediaPlayer();
player.SetAudioStreamType(Android.Media.Stream.Music);
player.Completion += new EventHandler(mediaplayer_Completion); AssetFileDescriptor assetfiledescriptor = context.Resources.OpenRawResourceFd(0x7f040000);
try
{
player.SetDataSource(assetfiledescriptor.FileDescriptor, assetfiledescriptor.StartOffset, assetfiledescriptor.Length);
assetfiledescriptor.Close();
player.SetVolume(0.1F, 0.1F);
player.Prepare();
m_MediaPlayer = player;
}
catch (IOException ioexception)
{
player = null;
} return player;
} static void mediaplayer_Completion(object sender, EventArgs e)
{
m_MediaPlayer.SeekTo(0);
} public static void PlayBeepSound(Activity activity)
{
m_CurrentActivity = activity;
if (m_MediaPlayer == null)
{
m_MediaPlayer = BuildMediaPlayer(m_CurrentActivity);
}
m_MediaPlayer.Start();
} public static void Stop()
{
if (m_MediaPlayer != null)
{
m_MediaPlayer.Stop();
m_MediaPlayer = null;
}
} //private void prepareToPlay()
//{
// try
// {
// //获取当前音频流的路径后我们需要通过MediaPlayer的setDataSource来设置,然后调用prepareAsync()来完成缓存加载
// String path = pathList.get(currPosition);
// player.setDataSource(path);
// //之所以使用prepareAsync是因为该方法是异步的,因为访问音频流是网络操作,在缓冲和准备播放时需要花费
// //较长的时间,这样用户界面就可能出现卡死的现象
// //该方法执行完成后,会执行onPreparedListener的onPrepared()方法。
// player.prepareAsync(); // }
// catch (IllegalArgumentException e)
// {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// catch (IllegalStateException e)
// {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// catch (IOException e)
// {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
//}
}
}
调用WCF验证登陆
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 System.ServiceModel;
using System.Threading; namespace AndroidHotelServiceTest
{
[Activity(Label = "登陆", MainLauncher = true)]
public class ActivityLogin : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Login);
// Create your application here Button button = FindViewById<Button>(Resource.Id.login);
EditText txtUser = FindViewById<EditText>(Resource.Id.edtuser);
EditText txtPassword = FindViewById<EditText>(Resource.Id.edtpsd); button.Click += delegate
{
Login(txtUser.Text, txtPassword.Text);
};
} public void Login(string user, string password)
{
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
var timeout = new TimeSpan(0, 1, 0);
binding.SendTimeout = timeout;
binding.OpenTimeout = timeout;
binding.ReceiveTimeout = timeout; IHotelService service = ChannelFactory<IHotelService>.CreateChannel(binding,
new EndpointAddress("http://172.25.16.50:90/HotelService.svc"));
string loginUser = service.Login(user, password);
if (!string.IsNullOrEmpty(loginUser))
{
Intent intent = new Intent();
intent.SetClass(this, typeof(ActivityHotel));
intent.PutExtra("User", user);
StartActivity(intent);
}
}
}
}
总之,大概就这样了,页面布局什么的也没什么特别的。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="25px"
android:minHeight="25px">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="账号:" />
<EditText
android:layout_width="240dip"
android:layout_height="wrap_content"
android:text="aaa"
android:id="@+id/edtuser" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="密码:" />
<EditText
android:layout_width="240dip"
android:layout_height="wrap_content"
android:password="true"
android:id="@+id/edtpsd" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical">
<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="记住密码" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<Button
android:id="@+id/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="登录" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
至于服务端,就是VS自动生成的代码加了一个登陆判断而已
[ServiceContract]
public interface IHotelService
{
[OperationContract]
string Login(string user, string password);
}
Mono的简单例子的更多相关文章
- Hibernate4.2.4入门(一)——环境搭建和简单例子
一.前言 发下牢骚,这段时间要做项目,又要学框架,搞得都没时间写笔记,但是觉得这知识学过还是要记录下.进入主题了 1.1.Hibernate简介 什么是Hibernate?Hibernate有什么用? ...
- AgileEAS.NET SOA 中间件平台.Net Socket通信框架-简单例子-实现简单的服务端客户端消息应答
一.AgileEAS.NET SOA中间件Socket/Tcp框架介绍 在文章AgileEAS.NET SOA 中间件平台Socket/Tcp通信框架介绍一文之中我们对AgileEAS.NET SOA ...
- spring mvc(注解)上传文件的简单例子
spring mvc(注解)上传文件的简单例子,这有几个需要注意的地方1.form的enctype=”multipart/form-data” 这个是上传文件必须的2.applicationConte ...
- ko 简单例子
Knockout是在下面三个核心功能是建立起来的: 监控属性(Observables)和依赖跟踪(Dependency tracking) 声明式绑定(Declarative bindings) 模板 ...
- mysql定时任务简单例子
mysql定时任务简单例子 ? 1 2 3 4 5 6 7 8 9 如果要每30秒执行以下语句: [sql] update userinfo set endtime = now() WHE ...
- java socket编程开发简单例子 与 nio非阻塞通道
基本socket编程 1.以下只是简单例子,没有用多线程处理,只能一发一收(由于scan.nextLine()线程会进入等待状态),使用时可以根据具体项目功能进行优化处理 2.以下代码使用了1.8新特 ...
- 一个简单例子:贫血模型or领域模型
转:一个简单例子:贫血模型or领域模型 贫血模型 我们首先用贫血模型来实现.所谓贫血模型就是模型对象之间存在完整的关联(可能存在多余的关联),但是对象除了get和set方外外几乎就没有其它的方法,整个 ...
- [转] 3个学习Socket编程的简单例子:TCP Server/Client, Select
以前都是采用ACE的编写网络应用,最近由于工作需要,需要直接只用socket接口编写CS的代码,重新学习这方面的知识,给出自己所用到的3个简单例子,都是拷贝别人的程序.如果你能完全理解这3个例子,估计 ...
- jsonp的简单例子
jsonp的简单例子 index.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8&q ...
随机推荐
- Ubuntu下使用nvm
写在前面:刚写着写着博客就跨年了,希望新的一年大家万事如意,一切向"前"看! 安装 wget -qO- https://raw.githubusercontent.com/crea ...
- tLinux 2.2下安装Mono 4.8
Tlinux2.2发行版基于CentOS 7.2.1511研发而成,内核版本与Tlinux2.0发行版保持完全一致,更加稳定,并保持对Tlinux2.0的完全兼容.Mono 4版本要求CentOS 7 ...
- 再谈C#采集,一个绕过高强度安全验证的采集方案?方案很Low,慎入
说起采集,其实我是个外行,以前拔过阿里巴巴的客户数据,在我博客的文章:C#+HtmlAgilityPack+XPath带你采集数据(以采集天气数据为例子) 中,介绍过采集用的工具,其实很Low的,分析 ...
- Android学习探索之Java 8 在Android 开发中的应用
前言: Java 8推出已经将近2年多了,引入很多革命性变化,加入了函数式编程的特征,使基于行为的编程成为可能,同时减化了各种设计模式的实现方式,是Java有史以来最重要的更新.但是Android上, ...
- 卸载oracle之后,如何清除注册表
之前卸载了oracle,今天偶然间发现,在服务和应用程序里面,还残存着之前的oracle服务.原来,还需要去清理下注册表. 在开始菜单的这个框里面 输入regedit,进入注册表.找到这个目录 HKE ...
- java面向对象中的关键字
1,super关键字 super:父类的意思 1. super.属性名 (调用父类的属性) 2. super.方法名 (调用父类的方法) 3. super([参数列表])(调用父类的构造方法) 注意: ...
- 熊乐:H3 BPM为加速企业流程管理提供源动力
近日,在北京·金隅喜来登酒店,H3 BPM以"让天下没有难用的流程"为主题,正式发布H3 BPM10.0版本.全新的业务流程管理系统在易用性方面大大提升,并且全面支持Java与.N ...
- linux系统维护时的一些小技巧,包括系统挂载新磁盘的方法!可收藏!
这里发布一些平时所用到的小技巧,不多,不过会持续更新.... 1.需要将history创建硬链接ln 全盘需要备份硬链接 ln /etc/xxx /home/xxx 2.root用户不可以远程 /et ...
- windows 7(32/64位)GHO安装指南(序篇)~
大家好,本人是高三刚毕业,即将踏入校园的程序猿~我写这篇文章呢,主要是想巩固一下之前对于电脑的基础知识理论,也希望能帮助没有电脑基础的同学能维护一下自己的电脑,要是能帮助女生修电脑那就是更好啦~~哈哈 ...
- NYOJ 998
这道题是欧拉函数的使用,这里简要介绍下欧拉函数. 欧拉函数定义为:对于正整数n,欧拉函数是指不超过n且与n互质的正整数的个数. 欧拉函数的性质:1.设n = p1a1p2a2p3a3p4a4...pk ...