示例#1
0
 public override bool OnGenericMotionEvent(MotionEvent ev)
 {
     if (ev.Action == MotionEventActions.Scroll &&
         RotaryEncoder.IsFromRotaryEncoder(ev))
     {
         float delta = -RotaryEncoder.GetRotaryAxisValue(ev) * RotaryEncoder.GetScaledScrollFactor(this.Context);
         this.Delta = Math.Clamp(delta, -PaddleView.RotationLimit, PaddleView.RotationLimit);
         return(true);
     }
     return(base.OnGenericMotionEvent(ev));
 }
示例#2
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            // Use this to return your custom view for this Fragment
            View outerView = base.OnCreateView(inflater, container, savedInstanceState);
            View view      = inflater.Inflate(Resource.Layout.fragment_weather_details, outerView as ViewGroup, true);

            outerView.FocusableInTouchMode = true;
            outerView.GenericMotion       += (sender, e) =>
            {
                if (e.Event.Action == MotionEventActions.Scroll && RotaryEncoder.IsFromRotaryEncoder(e.Event))
                {
                    // Don't forget the negation here
                    float delta = -RotaryEncoder.GetRotaryAxisValue(e.Event) * RotaryEncoder.GetScaledScrollFactor(Activity);

                    // Swap these axes if you want to do horizontal scrolling instead
                    scrollView.ScrollBy(0, (int)Math.Round(delta));

                    e.Handled = true;
                }

                e.Handled = false;
            };

            scrollView = view.FindViewById <NestedScrollView>(Resource.Id.scrollView);
            // Details
            detailsPanel  = view.FindViewById(Resource.Id.details_panel);
            humidity      = view.FindViewById <TextView>(Resource.Id.humidity);
            pressureState = view.FindViewById <TextView>(Resource.Id.pressure_state);
            pressure      = view.FindViewById <TextView>(Resource.Id.pressure);
            visiblity     = view.FindViewById <TextView>(Resource.Id.visibility_val);
            feelslike     = view.FindViewById <TextView>(Resource.Id.feelslike);
            windDirection = view.FindViewById <TextView>(Resource.Id.wind_direction);
            windSpeed     = view.FindViewById <TextView>(Resource.Id.wind_speed);
            sunrise       = view.FindViewById <TextView>(Resource.Id.sunrise_time);
            sunset        = view.FindViewById <TextView>(Resource.Id.sunset_time);

            // Additional Details
            precipitationPanel            = view.FindViewById <RelativeLayout>(Resource.Id.precipitation_card);
            precipitationPanel.Visibility = ViewStates.Gone;
            chanceLabel     = view.FindViewById <TextView>(Resource.Id.chance_label);
            chance          = view.FindViewById <TextView>(Resource.Id.chance_val);
            cloudinessLabel = view.FindViewById <TextView>(Resource.Id.cloudiness_label);
            cloudiness      = view.FindViewById <TextView>(Resource.Id.cloudiness);
            qpfRain         = view.FindViewById <TextView>(Resource.Id.qpf_rain_val);
            qpfSnow         = view.FindViewById <TextView>(Resource.Id.qpf_snow_val);

            // Cloudiness only supported by OWM
            cloudinessLabel.Visibility = ViewStates.Gone;
            cloudiness.Visibility      = ViewStates.Gone;

            weatherCredit = view.FindViewById <TextView>(Resource.Id.weather_credit);

            return(outerView);
        }
示例#3
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            // Inflate the layout for this fragment
            View view = inflater.Inflate(Resource.Layout.fragment_weather_now, container, false);

            view.FocusableInTouchMode = true;
            view.GenericMotion       += (sender, e) =>
            {
                if (e.Event.Action == MotionEventActions.Scroll && RotaryEncoder.IsFromRotaryEncoder(e.Event))
                {
                    // Don't forget the negation here
                    float delta = -RotaryEncoder.GetRotaryAxisValue(e.Event) * RotaryEncoder.GetScaledScrollFactor(Activity);

                    // Swap these axes if you want to do horizontal scrolling instead
                    scrollView.ScrollBy(0, (int)Math.Round(delta));

                    e.Handled = true;
                }

                e.Handled = false;
            };

            refreshLayout = (SwipeRefreshLayout)view;
            scrollView    = view.FindViewById <NestedScrollView>(Resource.Id.fragment_weather_now);
            // Condition
            locationName     = view.FindViewById <TextView>(Resource.Id.label_location_name);
            updateTime       = view.FindViewById <TextView>(Resource.Id.label_updatetime);
            weatherIcon      = view.FindViewById <TextView>(Resource.Id.weather_icon);
            weatherCondition = view.FindViewById <TextView>(Resource.Id.weather_condition);
            weatherTemp      = view.FindViewById <TextView>(Resource.Id.weather_temp);

            // SwipeRefresh
            refreshLayout.SetColorSchemeColors(ContextCompat.GetColor(Activity, Resource.Color.colorPrimary));
            refreshLayout.Refresh += delegate
            {
                Task.Run(async() =>
                {
                    if (Settings.FollowGPS && await UpdateLocation())
                    {
                        // Setup loader from updated location
                        wLoader = new WeatherDataLoader(this.location, this, this);
                    }

                    await RefreshWeather(true);
                });
            };

            weatherCredit = view.FindViewById <TextView>(Resource.Id.weather_credit);

            loaded = true;
            refreshLayout.Refreshing = true;

            timer          = new System.Timers.Timer(30000); // 30sec
            timer.Elapsed += async(sender, e) =>
            {
                // We hit the interval
                // Data syncing is taking a long time to setup
                // Stop and load saved data
                await CancelDataSync();
            };

            return(view);
        }