Exemple #1
0
 void SaveStations(string resultString)
 {
     var dbStation = new StationCommands (this);
     var result = JsonValue.Parse (resultString);
     var stationArray = result ["station"];
     var allStations = JsonArray.Parse (stationArray.ToString ());
     foreach (var _station in allStations) {
         var stationString = JsonValue.Parse (_station.ToString ());
         var id = stationString ["id"];
         var locationX = stationString ["locationX"];
         var locationY = stationString ["locationY"];
         var name = stationString ["name"];
         var standardName = stationString ["standardname"];
         Station station = new Station (id, locationX, locationY, name, standardName);
         dbStation.AddStation (station);
     }
     dbStation.Close ();
 }
Exemple #2
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);
            Window.RequestFeature (WindowFeatures.NoTitle);
            SetContentView (Resource.Layout.Main);
            Window.SetBackgroundDrawableResource (Resource.Drawable.empty);
            Window.SetFeatureInt (WindowFeatures.NoTitle,0);
            Window.ClearFlags (WindowManagerFlags.DimBehind);

            kalinga = Typeface.CreateFromAsset (this.Assets, "fonts/kalinga.ttf");
            kalingab = Typeface.CreateFromAsset (this.Assets, "fonts/kalingab.ttf");

            prefs = GetPreferences (FileCreationMode.Append);
            firstTime = prefs.GetBoolean (FIRST, true);
            tSel = prefs.GetBoolean (TIMESEL, true);

            flipper = FindViewById<ViewFlipper> (Resource.Id.viewFlipper1);
            viewStart = FindViewById<LinearLayout> (Resource.Id.view1);
            viewSearch = FindViewById<LinearLayout> (Resource.Id.view2);
            ibSearch = FindViewById<ImageButton> (Resource.Id.ibSearch);
            ibTravel = FindViewById<ImageButton> (Resource.Id.ibTravel);
            ibPrevious = FindViewById<ImageButton> (Resource.Id.ibPrevious);
            main = FindViewById<LinearLayout> (Resource.Id.llMain);
            from = FindViewById<TextView> (Resource.Id.tvFrom);
            fromInput = FindViewById<AutoCompleteTextView> (Resource.Id.atvFrom);
            toInput = FindViewById<AutoCompleteTextView> (Resource.Id.atvTo);
            to = FindViewById<TextView> (Resource.Id.tvTo);
            dateLabel = FindViewById<Button> (Resource.Id.tvDate);
            timeLabel = FindViewById<Button> (Resource.Id.tvTime);
            rbDepart = FindViewById<RadioButton> (Resource.Id.rbDeparture);
            rbArrive = FindViewById<RadioButton> (Resource.Id.rbArrival);
            var dateButton = FindViewById<ImageButton> (Resource.Id.btnDate);
            var timeButton = FindViewById<ImageButton> (Resource.Id.btnTime);
            var btnGo = FindViewById<Button> (Resource.Id.btnGo);

            dateButton.Click += DatePicker_Dialog;
            dateLabel.Click += DatePicker_Dialog;
            timeButton.Click += TimePicker_Dialog;
            timeLabel.Click += TimePicker_Dialog;
            btnGo.Click += Download_Itinerary;
            rbDepart.Click += RadioButtonClick;
            rbArrive.Click += RadioButtonClick;
            btnGo.Click += CloseKeyBoard;
            main.Click += CloseKeyBoard;
            from.Click += ShowFocus;
            to.Click += ShowFocus;
            fromInput.TextChanged += ChangeGravity;
            toInput.TextChanged += ChangeGravity;
            ibSearch.Click += NextView;
            ibPrevious.Click += PreviousView;
            ibTravel.Click += delegate {
                StartActivity (typeof (ActivityUnderConstruction));
            };

            DateTime now = DateTime.Now;
            var day = XTool.CatchZero (now.Day);
            var month = XTool.CatchZero (now.Month);
            var year = XTool.CatchZero (now.Year - 2000);
            var hour = XTool.CatchZero (now.Hour);
            var minute = XTool.CatchZero (now.Minute);

            RunOnUiThread (() => {
                dateLabel.Text = String.Format ("{0}/{1}/{2}", day, month, year);
                timeLabel.Text = String.Format ("{0}:{1}", hour, minute);

                rbDepart.Checked = tSel;
                rbArrive.Checked = !tSel;
                from.Typeface = kalinga;
                fromInput.Typeface = kalingab;
                to.Typeface = kalinga;
                toInput.Typeface = kalingab;
                dateLabel.Typeface = kalinga;
                timeLabel.Typeface = kalinga;
                rbArrive.Typeface = tSel ? kalinga : kalingab;
                rbDepart.Typeface = tSel ? kalingab : kalinga;
                btnGo.Typeface = kalingab;
            });

            if (firstTime) {
                Download_Stations ();
            } else {
            //				using (StreamReader reader = new StreamReader(Assets.Open ("stations.txt")))
            //				{
            //					var line = reader.ReadToEnd ();
            //					reader.Close ();
            //					SaveStations (line);
            //				}
            }

            var dbStation = new StationCommands (this);
            List<string> list = new List<string> ();
            list = dbStation.All;
            dbStation.Close ();
            autoCompleteAdapter = new ArrayAdapter (this, Resource.Layout.autocomplete, list.ToArray ());
            fromInput.Adapter = autoCompleteAdapter;
            toInput.Adapter = autoCompleteAdapter;
        }