Beispiel #1
0
        private void OnDispose()
        {
            if (_drawableCache != null)
            {
                foreach (var p in _drawableCache)
                {
                    p.Value?.Dispose();
                }

                _drawableCache.Clear();
                _drawableCache = null;
            }
            if (_windDirectionBitmapCache != null)
            {
                foreach (var p in _windDirectionBitmapCache)
                {
                    p.Value?.Recycle();
                }

                _windDirectionBitmapCache.Clear();
                _windDirectionBitmapCache = null;
            }

            _appCompatDrawableUtil = null;
            _drawableUtil          = null;
            _windTools             = null;
        }
Beispiel #2
0
        private Drawable ApplyTintColor(Context context, int drawableId, int tintColor)
        {
            var compatDrawableUtil = new AppCompatDrawableUtil();
            var icon = compatDrawableUtil.GetDrawable(context.Resources, drawableId, context.Theme);

            return(compatDrawableUtil.ChangeColorTint(icon, tintColor));
        }
Beispiel #3
0
        public Drawable GetConditionIcon(WidgetTypes widgetType, IconStyles?iconStyles, IWeatherDataPoint dataPoint,
                                         bool useTwilight, bool isCurrently)
        {
            var cachekey = GetConditionIconId(widgetType, iconStyles, dataPoint, useTwilight, isCurrently);

            if (!_drawableCache.ContainsKey(cachekey))
            {
                if (_appCompatDrawableUtil == null)
                {
                    _appCompatDrawableUtil = new AppCompatDrawableUtil();
                }

                _drawableCache[cachekey] = _appCompatDrawableUtil.GetDrawable(_appContext.Resources, cachekey,
                                                                              _appContext.Theme);
            }

            return(_drawableCache[cachekey]);
        }
 public MenuAdapter(IEnumerable <MenuItem> menu, MenuItem[] weatherProviders, int currentWeatherProviderId,
                    int currentLocationId, int wetherProviderIconId)
 {
     MenuItems        = new List <MenuItem>(menu);
     WeatherProviders = weatherProviders;
     if (currentWeatherProviderId != -1)
     {
         _selectedProviderId = currentWeatherProviderId;
     }
     if (currentLocationId != -1)
     {
         _selectedLocationId = currentLocationId;
         ChangeSelectedPosition(_selectedLocationId.Value, ref _selectedLocationPosition,
                                new[] { MenuItemTypes.CurrentLocation, MenuItemTypes.Location }, false);
     }
     _wetherProviderIconId = wetherProviderIconId;
     _compatDrawableUtil   = new AppCompatDrawableUtil();
 }
Beispiel #5
0
        private void InitializeIcon()
        {
            _xD = GetCompoundDrawables()[(int)IconLocation];
            if (_xD == null)
            {
                var compatDrawableUtil = new AppCompatDrawableUtil();
                _xD = compatDrawableUtil.GetDrawable(Resources, Resource.Drawable.ic_delete, Context.Theme);
                if (UseDefaultColor)
                {
                    _xD = compatDrawableUtil.ChangeColorTint(_xD, TextColors.DefaultColor);
                }
            }

            //var iconsize = 2 * _xD.IntrinsicHeight;
            _xD.SetBounds(0, 0, _xD.IntrinsicWidth, _xD.IntrinsicHeight);
            //_xD.SetBounds(0, 0, iconsize, iconsize);
            var min = PaddingTop + _xD.IntrinsicHeight + PaddingBottom;

            if (SuggestedMinimumHeight < min)
            {
                SetMinimumHeight(min);
            }
        }
Beispiel #6
0
        public override void OnBindViewHolder(RecyclerView.ViewHolder viewHolder, int position)
        {
            var holder = (ApiKeysManagementViewHolder)viewHolder;
            var item   = _providers[position];

            if (_compatDrawableUtil == null)
            {
                _compatDrawableUtil = new AppCompatDrawableUtil();
            }
            var resources = holder.ItemView.Resources;
            var context   = holder.ItemView.Context;

            var      transparent    = ContextCompat.GetColor(context, Android.Resource.Color.Transparent);
            Drawable editDrawable   = null;
            Drawable deleteDrawable = null;
            Drawable existsDrawable = null;

            if (!item.IsReadOnly)
            {
                editDrawable =
                    _compatDrawableUtil.GetDrawable(resources, Resource.Drawable.ic_menu_edit, context.Theme);
            }

            if (ApiKeys != null && ApiKeys.ContainsKey(item.Id))
            {
                if (!item.IsReadOnly)
                {
                    deleteDrawable =
                        _compatDrawableUtil.GetDrawable(resources, Resource.Drawable.ic_delete, context.Theme);
                }
                existsDrawable = _compatDrawableUtil.GetDrawable(resources, Resource.Drawable.ic_check, context.Theme);
            }

            if (editDrawable == null)
            {
                holder.EditButton.SetImageResource(transparent);
            }
            else
            {
                holder.EditButton.SetImageDrawable(editDrawable);
            }

            if (deleteDrawable == null)
            {
                holder.DeleteButton.SetImageResource(transparent);
            }
            else
            {
                holder.DeleteButton.SetImageDrawable(deleteDrawable);
            }

            if (existsDrawable == null)
            {
                holder.ExistsApiKey.SetImageResource(transparent);
            }
            else
            {
                holder.ExistsApiKey.SetImageDrawable(existsDrawable);
            }

            holder.ProviderName.MovementMethod = null;
            var title     = context.GetString(item.TitleId);
            var spannable = new SpannableString(title);

            if (item.UrlApiId.HasValue)
            {
                spannable.SetSpan(new URLSpan(context.GetString(item.UrlApiId.Value)), 0,
                                  title.Length, SpanTypes.ExclusiveExclusive);
                holder.ProviderName.MovementMethod = LinkMovementMethod.Instance;
            }
            holder.ProviderName.TextFormatted = spannable;
        }
Beispiel #7
0
        protected override void Dispose(bool disposing)
        {
            _compatDrawableUtil = null;

            base.Dispose(disposing);
        }