吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 10046|回复: 29
收起左侧

[Android工具] C# Xamarin Android 计算器

  [复制链接]
南语喃 发表于 2017-11-26 16:39
本帖最后由 南语喃 于 2017-11-27 18:11 编辑

平台:VS2017 Xamarin Android
语言:C#
大小:4.2M
用C#写Android包有点大。避免不了。抱歉。
核心是自己写的一个脚本引擎。原理简单,但是耗费心血设计。
要求:Android 6.0以上
下载地址:https://pan.baidu.com/s/1c2jNzNE
cal.png

免费评分

参与人数 6吾爱币 +10 热心值 +6 收起 理由
szqever + 1 谢谢@Thanks!
lkjlkjhong + 1 + 1 谢谢@Thanks!
Hmily + 6 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
柠檬果糖 + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
a6133616 + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
AMAOMAOA + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| 南语喃 发表于 2017-11-27 12:36
psx1lin 发表于 2017-11-27 10:06
真的..那我來試看看.
有源碼學習?
3q

关于Xamarin,国内的资源非常缺乏。
我也是刚接触Xamarin,手动百度Android,然后翻译成C#。
源码就自己做的一个计算器。
using Android.App;
using Android.Widget;
using Android.OS;
using Android.Graphics;
using System.Collections.Generic;
using Android.Views;
using TidyScriptCore;
using Android.Text;
using Android.Views.InputMethods;
using Android.Content;
using System;
using Android.Runtime;
using System.Threading;

namespace Calculator
{
    [Activity(Label = "Calculator", MainLauncher = true,WindowSoftInputMode = (SoftInput.StateHidden))]
    public class MainActivity : Activity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            RequestWindowFeature( Android.Views.WindowFeatures.NoTitle);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            //
            //界面设计
            //Code 1/2
            //Bs 1/4
            //Result 1/4
            WindowsInfo Info = new WindowsInfo();
            Info.activity = this;
            int Height = Info.Height;
            int Width = Info.Width;
            //
            List<string> Keys = new List<string>();
            Keys.AddRange(new List<string>() { "A", "Cos()", "Sin()", "Tan()" });
            Keys.AddRange(new List<string>() { "Rand()",",","*","/"});
            Keys.AddRange(new List<string>() { "()", "[]", "+", "-" });
            Keys.AddRange(new List<string>() { "1","2","3","=","4","5","6","←","7","8","9","Enter","^","0",".","Ans","X","Y","3.14159","Figure"});
            //
            EditText tBox_Code = (EditText)FindViewById(Resource.Id.tBox_Code);
            LinearLayout llV = (LinearLayout)FindViewById(Resource.Id.llV);
            TextView tBox_Result = (TextView)FindViewById(Resource.Id.tBox_Result);
            CheckBox cBox = (CheckBox)FindViewById(Resource.Id.cBox);
            //
            tBox_Result.Text = "\nBy 南语喃";
            tBox_Code.Top = 0;
            ViewGroup.LayoutParams lp = tBox_Code.LayoutParameters;
            lp.Height = Height / 5;
            lp = tBox_Result.LayoutParameters;
            lp.Height = Height / 7;
            lp = cBox.LayoutParameters;
            lp.Height = 50;

            //
            while (Keys.Count != 0)
            {
                LinearLayout Liner = new LinearLayout(Application.Context);
                Liner.Orientation = Orientation.Horizontal;
                Liner.Measure(0, 0);
                Button b = new Button(Application.Context);
                b.Text = Keys[0];
                b.Measure(0, 0);
                b.Click += B_Click;
                Process_LongCB(b);
                Keys.RemoveAt(0);
                Liner.AddView(b);
                int CountOfB = 0;
                while (CountOfB < 3 && Keys.Count != 0)
                {
                    CountOfB++;
                    b = new Button(Application.Context);
                    b.Text = Keys[0];
                    b.Measure(0, 0);
                    b.Click += B_Click;
                    Process_LongCB(b);
                    Keys.RemoveAt(0);
                    Liner.AddView(b);
                }

                llV.AddView(Liner);
            }
            tBox_Code.Click += (sender, e) =>
            {
                if (cBox.Checked)
                {
                    HideInput(Application, tBox_Code);
                }
               
            };

            
        }

        private class OTouchL : Activity,View.IOnTouchListener
        {
            public LongDelete LD = new LongDelete();
            public bool OnTouch(View v, MotionEvent e)
            {
               
                Button b = (Button)v;
                if (b.Text.ToLower() == "←")
                {
                    if (e.Action == MotionEventActions.Down)
                    {
                        LD.Start();
                    }else if(e.Action == MotionEventActions.Up)
                    {
                        LD.Finish();
                    }
                }
                return true;
            }
        }
        private void Process_LongCB(Button b)
        {
            if (b.Text.ToLower() == "←")
            {
                EditText tBox_Code = (EditText)FindViewById(Resource.Id.tBox_Code);
                OTouchL OTL = new OTouchL();
                MHandler mh = new MHandler();
                mh.tBox = tBox_Code;
                OTL.LD.hd = mh;
                b.SetOnTouchListener(OTL);
            }
        }
        public static void HideInput(Context context, View view)
        {
            InputMethodManager inputMethodManager = (InputMethodManager)context.GetSystemService(Context.InputMethodService);
            inputMethodManager.HideSoftInputFromWindow(view.WindowToken, 0);
        }
        private void B_Click(object sender, System.EventArgs e)
        {
            Button b = (Button)sender;
            EditText tBox_Code = (EditText)FindViewById(Resource.Id.tBox_Code);
            TextView tBox_Result = (TextView)FindViewById(Resource.Id.tBox_Result);
            if (b.Text.ToLower() == "figure")
            {
                UScript Script = new UScript();
                Config.FileSplit = "/";
                Config.StartPath = Application.Context.FilesDir.AbsolutePath;
                Script.Eval_Caclulator(tBox_Code.Text);
                tBox_Result.Text = Log.ToString();
            }
            else if (b.Text.ToLower() == "←")
            {
               
                Delete();
            }
            else if (b.Text.ToLower() == "enter")
            {
                Inset("\n");

            }else if(b.Text .ToLower().IndexOf("()")!=-1|| b.Text.ToLower().IndexOf("[]") != -1)
            {
                Inset(b.Text);
                tBox_Code.SetSelection(tBox_Code.SelectionStart-1);
            }
            else
            {
                Inset(b.Text);
            }
        }
        private void Delete()
        {
            EditText tBox_Code = (EditText)FindViewById(Resource.Id.tBox_Code);
            IEditable edit = tBox_Code.EditableText;
            int Index = tBox_Code.SelectionStart;
            if (Index != 0 && tBox_Code.Text.Length != 0)
            {
                edit.Delete(Index - 1, Index);
            }
        }
        private void Inset(string Content)
        {
            EditText tBox_Code = (EditText)FindViewById(Resource.Id.tBox_Code);
            int Index = tBox_Code.SelectionStart;
            IEditable edit = tBox_Code.EditableText;
            if (Index < 0 || Index > tBox_Code.Text.Length)
            {
                edit.Append(Content);
            }
            else
            {
                edit.Insert(Index, Content);
            }
        }
    }
    public class WindowsInfo
    {
        private Activity _activity = new Activity();
        public Activity activity
        {
            get
            {
                return _activity;
            }
            set
            {
                _activity = value;
                _activity.Window.WindowManager.DefaultDisplay.GetSize(Size);
            }
        }
        //
        private Point Size = new Point();
        public int Width
        {
            get
            {
                return Size.X;
            }
        }
        public int Height
        {
            get
            {
                return Size.Y;
            }
        }
    }
    public class LongDelete
    {
        public bool Switch = false;
        private bool First = true;
        public int Span = 100;
        public Handler hd;
        private void Run()
        {
            FlagStart:
            int LSpan = Span;
            int Count = 0;
            while (Switch)
            {
                if (Count >= 20)
                {
                    Message message = new Message();
                    message.Arg1 = 2;
                    hd.SendMessage(message);
                    Switch = false;
                }
                else
                {
                    Message message = new Message();
                    message.Arg1 = 1;
                    hd.SendMessage(message);
                    Thread.Sleep(LSpan);
                    if (LSpan > 50)
                    {
                        LSpan = LSpan - 10;
                    }
                }
                Count++;
               
            }
            while (!Switch)
            {
                Thread.Sleep(Span);
            }
            goto FlagStart;
        }
        //
        public void Start()
        {
            Switch=true;
            if (First)
            {
                First = false;
                Thread t = new Thread(Run);
                t.Start();
               
            }
               
        }
        public void Finish()
        {
            Switch = false;
        }
    }
    public class MHandler : Handler
    {
        public EditText tBox;
        public override void HandleMessage(Message msg)
        {
            base.HandleMessage(msg);
            if (msg.Arg1 == 1)
            {
                Delete();
            }else if(msg.Arg1 == 2)
            {
                tBox.Text = string.Empty;
            }
            
        }
        private void Delete()
        {
            IEditable edit = tBox.EditableText;
            int Index = tBox.SelectionStart;
            if (Index != 0 && tBox.Text.Length != 0)
            {
                edit.Delete(Index - 1, Index);
            }
        }
    }
}

 楼主| 南语喃 发表于 2017-11-27 18:09
本帖最后由 南语喃 于 2017-11-27 18:12 编辑
Hmily 发表于 2017-11-27 17:09
@南语喃 下载地址请给出软件直接地址,禁止用一个通用地址,让别人去找软件,这样链接里软件都要审核,并且 ...

好的。抱歉。地址已改。
 楼主| 南语喃 发表于 2017-11-26 16:41
Tsiang 发表于 2017-11-27 09:11 来自手机
好早!!!
psx1lin 发表于 2017-11-27 09:33
Xamarin
不是要綁帳號?
 楼主| 南语喃 发表于 2017-11-27 09:41
psx1lin 发表于 2017-11-27 09:33
Xamarin
不是要綁帳號?

Xamarin开源了,并且免费了。
psx1lin 发表于 2017-11-27 10:06
南语喃 发表于 2017-11-27 09:41
Xamarin开源了,并且免费了。

真的..那我來試看看.
有源碼學習?
3q
他与城 发表于 2017-11-27 17:05 来自手机
支持一下
Hmily 发表于 2017-11-27 17:09
@南语喃 下载地址请给出软件直接地址,禁止用一个通用地址,让别人去找软件,这样链接里软件都要审核,并且原创区也禁止发搜索类程序。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 提醒:禁止复制他人回复等『恶意灌水』行为,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-27 07:50

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表