示例#1
0
        protected async override void OnCreate(Bundle savedInstanceState)
        {
            AndHUD.Shared.Dismiss();

            base.OnCreate(savedInstanceState);

            // Create your application here
            SetContentView(Resource.Layout.ViewWebSite);

            ActionBar.Title = "APRS";
            ActionBar.SetDisplayHomeAsUpEnabled(true);
            ActionBar.SetDisplayShowHomeEnabled(true);

            string filePath = Intent.GetStringExtra("filePath");

            string resultURL = string.Empty;
            string error_val = "Server not respone!";

            try
            {
                resultURL = await WebRequest.SendPostFile(filePath);
            }
            catch (Exception ex)
            {
                error_val = ex.ToString();
            }


            if (resultURL == string.Empty)
            {
                AlertDialog.Builder alert = new AlertDialog.Builder(this);
                alert.SetMessage(error_val);
                alert.SetTitle("Error!");
                alert.SetPositiveButton("Ok", (senderAlert, args) =>
                {
                    //change value write your own set of instructions
                    //you can also create an event for the same in xamarin
                    //instead of writing things here
                });

                RunOnUiThread(() => {
                    alert.Show();
                });
            }
            else
            {
                Context        mContext = Android.App.Application.Context;
                AppPreferences ap       = new AppPreferences(mContext);

                webView = FindViewById <WebView>(Resource.Id.webView);
                webView.SetWebViewClient(new ExtentWebViewClient());
                webView.LoadUrl(ap.getURL_String() + resultURL);

                WebSettings wset = webView.Settings;
                wset.JavaScriptEnabled = true;
            }
        }
示例#2
0
        protected async override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here
            SetContentView(Resource.Layout.SettingsLayout);

            ActionBar.Title = GetString(Resource.String.m_settings);
            ActionBar.SetDisplayHomeAsUpEnabled(true);
            ActionBar.SetDisplayShowHomeEnabled(true);

            Button btn_save = FindViewById <Button>(Resource.Id.btn_save);

            btn_save.Click += Btn_save_Click;

            Context        mContext = Android.App.Application.Context;
            AppPreferences ap       = new AppPreferences(mContext);

            var connString = FindViewById <AutoCompleteTextView>(Resource.Id.connString);

            connString.Text = ap.getURL_String();

            //Alekseenko-//////////////////////////////////////////////////////////////////////////
            //return при повторном входе
            listnames = FindViewById <ListView>(Resource.Id.listviewFiles);
            Context        mContextCascade = Android.App.Application.Context;
            AppPreferences apCascade       = new AppPreferences(mContextCascade);
            var            position        = apCascade.getCascade_Position();

            listnames.SetItemChecked(position, true);    ////////////////Устанавливает позицию 0 или новую после сохранения
            listnames.ChoiceMode = ChoiceMode.Single;
            itemlist             = new List <string>();

            //вытягиваем и записываем файлы каскадов из папки files

            var get_path = MainActivity.App._APRSDir.AbsolutePath;

            string[]      filename = Directory.GetFiles(get_path, "*.xml");
            List <string> lst      = new List <string>(filename);

            foreach (string cascade in lst)
            {
                FileInfo nameFile = new FileInfo(cascade);
                itemlist.Add(nameFile.Name);
            }

            ArrayAdapter <string> adapter = new ArrayAdapter <String>(this, Android.Resource.Layout.SimpleListItemSingleChoice, itemlist);

            listnames.Adapter = adapter;
            listnames.SetItemChecked(position, true);
            listnames.ChoiceMode = ChoiceMode.Single;
            listnames.ItemClick += Listnames_ItemClick;
            //////////////////////////////////////////////////////////////////////////
        }
示例#3
0
        private void Btn_save_Click(object sender, EventArgs e)
        {
            var connString = FindViewById <AutoCompleteTextView>(Resource.Id.connString);

            Context        mContext = Android.App.Application.Context;
            AppPreferences ap       = new AppPreferences(mContext);

            //Сохранение выбраного каскада
            Context        mContextCascade = Android.App.Application.Context;
            AppPreferences apCascade       = new AppPreferences(mContextCascade);

            apCascade.saveCascade_String(positionCascade);

            ap.saveURL_String(connString.Text);
            this.Finish();
        }
示例#4
0
        public static async Task <string> SendPostFile(string p_filePath)
        {
            using (var client = new HttpClient())
                using (var content = new MultipartFormDataContent())
                {
                    Context        mContext = Android.App.Application.Context;
                    AppPreferences ap       = new AppPreferences(mContext);

                    client.BaseAddress = new System.Uri(ap.getURL_String());
                    var values = new[]
                    {
                        new KeyValuePair <string, string>("Name", "filename"),
                        new KeyValuePair <string, string>("id", "id"),
                    };
                    foreach (var keyValuePair in values)
                    {
                        content.Add(new StringContent(keyValuePair.Value), keyValuePair.Key);
                    }
                    string fileName    = p_filePath;
                    var    fileContent = new ByteArrayContent(System.IO.File.ReadAllBytes(fileName));
                    fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                    {
                        FileName = Path.GetFileName(fileName)
                    };
                    content.Add(fileContent);

                    var requestUri = "api/apisrv/";

                    var result = client.PostAsync(requestUri, content).Result;

                    string contents = result.Content.ReadAsStringAsync().Result.ToString().Replace(@"\", string.Empty).Replace("\"", "'").Replace("'{", "{").Replace("}'", "}");

                    ResultResponse resultURL = JsonConvert.DeserializeObject <ResultResponse>(contents);

                    return(resultURL.UrlString);
                }
        }