Example #1
0
        private void ConfigurationActivity_OkClick(object sender, EventArgs e)
        {
            var prefs  = PrefsKeys.GetPrefs(this);
            var editor = prefs.Edit();

            foreach (var colorSetting in _tbColorSettings)
            {
                colorSetting.Save(editor, _widgetId);
            }
            foreach (var intSetting in _tbIntSettings)
            {
                intSetting.Save(editor, _widgetId);
            }
            foreach (var boolSetting in _tbBoolSettings)
            {
                boolSetting.Save(editor, _widgetId);
            }

            editor.Commit();

            WidgetsUpdater.Update(this);

            Intent resultValue = new Intent();

            resultValue.PutExtra(AppWidgetManager.ExtraAppwidgetId, _widgetId);
            SetResult(Result.Ok, resultValue);
            Finish();
        }
Example #2
0
 public BoolSetting(Activity activity, int idCheckBox, string saveKey)
 {
     _savekey = saveKey;
     using (var prefs = PrefsKeys.GetPrefs(activity))
     {
         _checkBox = activity.FindViewById <CheckBox>(idCheckBox);
         var defaultValue = prefs.GetBoolean(_savekey + PrefsKeys.DefaultValue, true);
         _checkBox.Checked = defaultValue;
     }
 }
Example #3
0
 public IntSetting(Activity activity, int idEdit, string saveKey, int defaultValue)
 {
     _savekey = saveKey;
     using (var prefs = PrefsKeys.GetPrefs(activity))
     {
         _editText = activity.FindViewById <EditText>(idEdit);
         var savedValue = prefs.GetInt(_savekey + PrefsKeys.DefaultValue, defaultValue);
         if (savedValue != defaultValue)
         {
             _editText.Text = savedValue.ToString();
         }
     }
 }
Example #4
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.configuration_layout);

            var prefs = PrefsKeys.GetPrefs(this);

            _tbColorSettings = new ColorSetting[] {
                new ColorSetting(this, Resource.Id.backround_picker, Resource.Color.background, true, PrefsKeys.BackgroundColor),
                new ColorSetting(this, Resource.Id.time_picker, Resource.Color.time, true, PrefsKeys.TimeColor),
                new ColorSetting(this, Resource.Id.date_picker, Resource.Color.date, true, PrefsKeys.DateColor),
                new ColorSetting(this, Resource.Id.icon_picker, Resource.Color.icon, true, PrefsKeys.IconColor)
            };

            _tbIntSettings = new IntSetting[]
            {
                new IntSetting(this, Resource.Id.time_textsize, PrefsKeys.TimeTextSize, -1),
                new IntSetting(this, Resource.Id.date_textsize, PrefsKeys.DateTextSize, -1),
                new IntSetting(this, Resource.Id.time_offset, PrefsKeys.TimeOffset, 0),
            };

            _tbBoolSettings = new BoolSetting[]
            {
                new BoolSetting(this, Resource.Id.date_usetodtom, PrefsKeys.DateUseTodTom)
            };

            Bundle extras = Intent.Extras;

            if (extras != null)
            {
                _widgetId = extras.GetInt(AppWidgetManager.ExtraAppwidgetId, AppWidgetManager.InvalidAppwidgetId);
            }

            Intent resultValue = new Intent();

            resultValue.PutExtra(AppWidgetManager.ExtraAppwidgetId, _widgetId);
            SetResult(Result.Canceled, resultValue);

            FindViewById <Button>(Resource.Id.ok_button).Click      += ConfigurationActivity_OkClick;
            FindViewById <Button>(Resource.Id.default_button).Click += ConfigurationActivity_DefaultClick;
        }
Example #5
0
        public ColorSetting(Activity activity, int idPicker, int idDefaultColor, bool useAlpha, string saveKey)
        {
            _activity       = activity;
            _idDefaultColor = idDefaultColor;
            _savekey        = saveKey;
            _colorPicker    = activity.FindViewById <ColorPickerPanelView>(idPicker);

            using (var prefs = PrefsKeys.GetPrefs(activity))
            {
                var defaultColor = new Color(prefs.GetInt(_savekey + PrefsKeys.DefaultValue, activity.GetCompatColor(idDefaultColor)));

                _colorPicker.Color         = defaultColor;
                _colorPicker.PanelClicked += (sender, e) =>
                {
                    var colorPickerDialog = new ColorPickerDialog(activity, _colorPicker.Color);
                    colorPickerDialog.AlphaSliderVisible = useAlpha;
                    colorPickerDialog.ColorChanged      += (o, args) => _colorPicker.Color = args.Color;
                    colorPickerDialog.Show();
                };
            }
        }
Example #6
0
        public static void Update(Context context, NextAlarm nextAlarm, int[] appWidgetIds = null)
        {
            AppWidgetManager appWidgetManager = AppWidgetManager.GetInstance(context);
            ComponentName    thisWidget       = new ComponentName(context, Class.FromType(typeof(Widget)).Name);

            if (appWidgetIds == null)
            {
                appWidgetIds = appWidgetManager.GetAppWidgetIds(thisWidget);
            }
            var prefs = PrefsKeys.GetPrefs(context);

            foreach (var appWidgetId in appWidgetIds)
            {
                var timeOffset = prefs.GetInt(PrefsKeys.TimeOffset + appWidgetId, 0);
                nextAlarm.RefreshDisplay(context, timeOffset);

                RemoteViews updateViews = new RemoteViews(context.PackageName, Resource.Layout.widget);
                var         useTodDom   = prefs.GetBoolean(PrefsKeys.DateUseTodTom + appWidgetId, true);
                if (useTodDom)
                {
                    updateViews.SetTextViewText(Resource.Id.alarm_date, nextAlarm.DayAbbreviated);
                }
                else
                {
                    updateViews.SetTextViewText(Resource.Id.alarm_date, nextAlarm.Day);
                }
                if (nextAlarm.Time.Length > 5)
                {
                    updateViews.SetTextViewText(Resource.Id.alarm_time_12, nextAlarm.Time);
                    updateViews.SetViewVisibility(Resource.Id.alarm_time_12, ViewStates.Visible);
                    updateViews.SetViewVisibility(Resource.Id.alarm_time_24, ViewStates.Gone);
                }
                else
                {
                    updateViews.SetTextViewText(Resource.Id.alarm_time_24, nextAlarm.Time);
                    updateViews.SetViewVisibility(Resource.Id.alarm_time_24, ViewStates.Visible);
                    updateViews.SetViewVisibility(Resource.Id.alarm_time_12, ViewStates.Gone);
                }

                var dateColor = new Color(prefs.GetInt(PrefsKeys.DateColor + appWidgetId, context.GetCompatColor(Resource.Color.date)));
                updateViews.SetTextColor(Resource.Id.alarm_date, dateColor);
                var dateTextSize = prefs.GetInt(PrefsKeys.DateTextSize + appWidgetId, -1);
                if (dateTextSize != -1)
                {
                    updateViews.SetTextViewTextSize(Resource.Id.alarm_date, (int)ComplexUnitType.Dip, dateTextSize);
                }


                var timeColor = new Color(prefs.GetInt(PrefsKeys.TimeColor + appWidgetId, context.GetCompatColor(Resource.Color.time)));
                updateViews.SetTextColor(Resource.Id.alarm_time_24, timeColor);
                updateViews.SetTextColor(Resource.Id.alarm_time_12, timeColor);

                var timeTextSize = prefs.GetInt(PrefsKeys.TimeTextSize + appWidgetId, -1);
                if (timeTextSize != -1)
                {
                    updateViews.SetTextViewTextSize(Resource.Id.alarm_time_24, (int)ComplexUnitType.Dip, timeTextSize);
                    updateViews.SetTextViewTextSize(Resource.Id.alarm_time_12, (int)ComplexUnitType.Dip, timeTextSize);
                }

                var         iconColor    = new Color(prefs.GetInt(PrefsKeys.IconColor + appWidgetId, context.GetCompatColor(Resource.Color.icon)));
                Bitmap      sourceBitmap = BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.ic_alarm_white_18dp);
                Bitmap      resultBitmap = Bitmap.CreateBitmap(sourceBitmap.Width, sourceBitmap.Height, Bitmap.Config.Argb8888);
                Paint       p            = new Paint();
                float[]     matrix       = { 0, 0, 0, iconColor.R / 255f, 0,
                                             0,           0, 0, iconColor.G / 255f, 0,
                                             0,           0, 0, iconColor.B / 255f, 0,
                                             0,           0, 0, iconColor.A / 255f, 0 };
                ColorFilter filter = new ColorMatrixColorFilter(matrix);
                p.SetColorFilter(filter);
                Canvas canvas = new Canvas(resultBitmap);
                canvas.DrawBitmap(sourceBitmap, 0, 0, p);
                updateViews.SetImageViewBitmap(Resource.Id.alarm_icon, resultBitmap);

                var backgroundColor = new Color(prefs.GetInt(PrefsKeys.BackgroundColor + appWidgetId, context.GetCompatColor(Resource.Color.background)));
                updateViews.SetInt(Resource.Id.background, "setColorFilter", backgroundColor.ToArgb());
                updateViews.SetInt(Resource.Id.background, "setAlpha", backgroundColor.A);

                updateViews.SetOnClickPendingIntent(Resource.Id.widget_root, nextAlarm.RelayIntent);
                appWidgetManager.UpdateAppWidget(appWidgetId, updateViews);
            }

            ScheduleMidnightUpdate(context);
        }