Beispiel #1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);

            tvStatus = FindViewById<TextView>(Resource.Id.tvStatus);
            btnConnect = FindViewById<Button>(Resource.Id.btnConnect);
            pbDownload = FindViewById<ProgressBar>(Resource.Id.pbDownLoad);

            btnConnect.Click += BtnClick;

            h = new Handler(new Action<Message>((Message msg) =>
            {
                switch (msg.What)
                {
                    case STATUS_NONE:
                        btnConnect.Enabled = true;
                        tvStatus.Text = "Not connected";
                        pbDownload.Visibility = ViewStates.Gone;
                        break;
                    case STATUS_CONNECTING:
                        btnConnect.Enabled = false;
                        tvStatus.Text = "Connecting";
                        break;
                    case STATUS_CONNECTED:
                        tvStatus.Text = "Connected";
                        break;
                    case STATUS_DOWNLOAD_START:
                        tvStatus.Text = String.Format("Start download {0} files.",msg.Arg1);
                        pbDownload.Max = msg.Arg1;
                        pbDownload.Progress = 0;
                        pbDownload.Visibility = ViewStates.Visible;
                        break;
                    case STATUS_DOWNLOAD_FILE:
                        tvStatus.Text = String.Format("Downloading. {0} files left.", msg.Arg2);
                        pbDownload.Progress = msg.Arg1;
                        SaveFile((byte[])msg.Obj);
                        break;
                    case STATUS_DOWNLOAD_END:
                        tvStatus.Text = String.Format("Download comlete.");
                        break;
                    case STATUS_DOWNLOAD_NONE:
                        tvStatus.Text = String.Format("No files for download.");
                        break;
                    default:
                        break;
                }
            }));
            h.SendEmptyMessage(STATUS_NONE);
        }