Ejemplo n.º 1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.activity_main);

            Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
            SetSupportActionBar(toolbar);

            listView = FindViewById <ListView>(Resource.Id.listView);

            listAdapter      = new ActivityListAdapter(this);
            listView.Adapter = listAdapter;

            //adapt height of listView so it fits.
            Util.SetListViewHeightBasedOnChildren(listView, this);

            listView.ItemClick -= ListView_ItemClick;
            listView.ItemClick += ListView_ItemClick;

            int REQUEST_CAMERA = 0;

            if (ContextCompat.CheckSelfPermission(this, Android.Manifest.Permission.Camera) != Permission.Granted)
            {
                // Should we show an explanation?
                if (!ActivityCompat.ShouldShowRequestPermissionRationale(this, Android.Manifest.Permission.Camera))
                {
                    // No explanation needed, we can request the permission.
                    ActivityCompat.RequestPermissions(this, new string[] { Android.Manifest.Permission.Camera }, REQUEST_CAMERA);
                }
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("Permission Granted!");
            }
        }
        private void AskForLocationPermission()
        {
            // Only check if permission hasn't been granted yet.
            if (ContextCompat.CheckSelfPermission(this, LocationService) != Permission.Granted)
            {
                // The Fine location permission will be requested.
                var requiredPermissions = new[] { Manifest.Permission.AccessFineLocation };

                // Only prompt the user first if the system says to.
                if (ActivityCompat.ShouldShowRequestPermissionRationale(this, Manifest.Permission.AccessFineLocation))
                {
                    // A snackbar is a small notice that shows on the bottom of the view.
                    Snackbar.Make(_myMapView,
                                  "Location permission is needed to display location on the map.",
                                  Snackbar.LengthIndefinite)
                    .SetAction("OK",
                               delegate
                    {
                        // When the user presses 'OK', the system will show the standard permission dialog.
                        // Once the user has accepted or denied, OnRequestPermissionsResult is called with the result.
                        ActivityCompat.RequestPermissions(this, requiredPermissions, LocationPermissionRequestCode);
                    }
                               ).Show();
                }
                else
                {
                    // When the user presses 'OK', the system will show the standard permission dialog.
                    // Once the user has accepted or denied, OnRequestPermissionsResult is called with the result.
                    this.RequestPermissions(requiredPermissions, LocationPermissionRequestCode);
                }
            }
            else
            {
                HandleLocationReady();
            }
        }
Ejemplo n.º 3
0
        public static void SetWindowBackground(this AView view)
        {
            Context context = view.Context;

            using (var background = new TypedValue())
            {
                if (context.Theme.ResolveAttribute(global::Android.Resource.Attribute.WindowBackground, background, true))
                {
                    string type = context.Resources.GetResourceTypeName(background.ResourceId).ToLower();
                    switch (type)
                    {
                    case "color":
                        var color = new AColor(ContextCompat.GetColor(context, background.ResourceId));
                        view.SetBackgroundColor(color);
                        break;

                    case "drawable":
                        using (Drawable drawable = ContextCompat.GetDrawable(context, background.ResourceId))
                            view.SetBackground(drawable);
                        break;
                    }
                }
            }
        }
        public void ShowWarningAlert(string message, string warningButtonText)
        {
            var dialog = new Dialog(CrossCurrentActivity.Current.Activity);

            dialog.Window.SetBackgroundDrawable(ContextCompat.GetDrawable(CrossCurrentActivity.Current.Activity, Android.Resource.Color.Transparent));
            dialog.SetContentView(Resource.Layout.CustomAlert);

            TextView text = (TextView)dialog.FindViewById(Resource.Id.alertText);

            text.SetText(message, TextView.BufferType.Normal);

            ImageView imgView = (ImageView)dialog.FindViewById(Resource.Id.alertImage);

            imgView.SetImageResource(Resource.Drawable.InfoIcon);

            Button button = (Button)dialog.FindViewById(Resource.Id.alertApplyButton);

            button.SetText(warningButtonText, TextView.BufferType.Normal);
            dialog.Show();
            button.Click += (sender, args) =>
            {
                dialog.Dismiss();
            };
        }
Ejemplo n.º 5
0
        private void AttemptToBindAppService()
        {
            var manager = GetSystemService(BluetoothService) as BluetoothManager;
            var adapter = manager.Adapter;

            if (Permission.Granted != ContextCompat.CheckSelfPermission(this, Android.Manifest.Permission.AccessFineLocation))
            {
                var adb = new AlertDialog.Builder(this);
                adb.SetTitle("Feed me permissions!");
                adb.SetMessage("We need location permissions to work!");
                adb.SetNegativeButton("Become Usless", (sender, e) => {
                    Toast.MakeText(this, "Good luck making me do anything for you, then", ToastLength.Long).Show();
                });
                adb.SetPositiveButton("Give Perms", (sender, e) => {
                    RequestLocationPermission();
                });
                adb.Show();
            }
            else if (!adapter.IsEnabled)
            {
                var adb = new AlertDialog.Builder(this);
                adb.SetTitle("Feed me blueteeth!");
                adb.SetMessage("We need blueteeth to make bluetooth do anything.");
                adb.SetNegativeButton("Starve", (sender, e) => {
                    Toast.MakeText(this, "Fine. Sit here", ToastLength.Long).Show();
                });
                adb.SetPositiveButton("Feed", (sender, e) => {;
                                                              var intent = new Intent(BluetoothAdapter.ActionRequestEnable);
                                                              StartActivityForResult(intent, REQUEST_BLUETOOTH_ENABLE); });
                adb.Show();
            }
            else
            {
                BindService(new Intent(this, typeof(AppService)), this, Bind.AutoCreate);
            }
        }
Ejemplo n.º 6
0
        // Replace the contents of a view (invoked by the layout manager)
        public override void OnBindViewHolder(RecyclerView.ViewHolder viewHolder, int position)
        {
            var item = Categories[position];

            // Replace the contents of the view with that element
            var holder = viewHolder as FragmentHomeAdapterViewHolder;

            //holder.TextView.Text = items[position];
            holder.TextCategory.Text = item.Name;
            holder.ImageCategory.SetImageDrawable(ContextCompat.GetDrawable(itemView.Context, item.Icon));
            if (!isSub)
            {
                holder.Layout.Background = new ColorDrawable {
                    Color = Color.ParseColor(item.Color)
                }
            }
            ;
            else
            {
                holder.Layout.Background = new ColorDrawable {
                    Color = Color.ParseColor(this.Col)
                };
            }
        }
        private void InitTabs()
        {
            for (var i = 0; i < _adapter.TabIconsInactive.Length; i++)
            {
                var tab     = _tabLayout.NewTab();
                var tabView = new ImageView(this)
                {
                    Id = Android.Resource.Id.Icon
                };
                tabView.SetScaleType(ImageView.ScaleType.CenterInside);
                tabView.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, _tabHeight);
                tab.SetCustomView(tabView);

                _tabLayout.AddTab(tab);
                if (i == _adapter.TabIconsInactive.Length - 1)
                {
                    SetProfileChart(_tabLayout.LayoutParameters.Height);
                }
                tab.SetIcon(ContextCompat.GetDrawable(this, _adapter.TabIconsInactive[i]));
            }
            SelectTab(BasePresenter.User.SelectedTab);
            _prevTab = _tabLayout.GetTabAt(BasePresenter.User.SelectedTab);
            _viewPager.OffscreenPageLimit = _adapter.Count - 1;
        }
        private void setTextViewTextColorFallbackColorWhenMissingStyleAttrs(AppCompatTextView textView)
        {
            var useDefaultColor = false;

            try
            {
                TextViewCompat.SetTextAppearance(textView, textHelperTextAppearance);
                if (MarshmallowApis.AreAvailable && textView.TextColors.DefaultColor == fallbackTextColorAfterMarshmallow)
                {
                    useDefaultColor = true;
                }
            }
            catch (Exception e)
            {
                useDefaultColor = true;
            }

            if (useDefaultColor)
            {
                TextViewCompat.SetTextAppearance(textView, Resource.Style.TextAppearance_AppCompat_Caption);
                Color defaultTextColor = new Color(ContextCompat.GetColor(Context, Resource.Color.defaultText));
                textView.SetTextColor(defaultTextColor);
            }
        }
Ejemplo n.º 9
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            FirebasePushNotificationManager.ProcessIntent(this, Intent);
            CrossFirebasePushNotification.Current.Subscribe(new string[] { "all" });

            if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.AccessFineLocation) == (int)Permission.Granted)
            {
            }
            else
            {
                var requiredPermissions = new string[] { Manifest.Permission.AccessFineLocation };
                ActivityCompat.RequestPermissions(this, requiredPermissions, 1);
            }


            LoadApplication(new App());
        }
Ejemplo n.º 10
0
        public static void DisplayAlert(Context context, int message, Action action)
        {
            var messageView = new TextView(context)
            {
                TextSize = 16
            };

            messageView.SetText(message);
            messageView.SetTextColor(Color.White);
            messageView.SetPadding(5, 5, 5, 5);

            var dialog = new AlertDialog.Builder(context, Resource.Style.AlertsDialogTheme)
                         .SetCancelable(false)
                         .SetPositiveButton("OK", (s, args) =>
            {
                action();
                ((Dialog)s).Dismiss();
            })
                         .SetCustomTitle(messageView)
                         .Create();

            dialog.Window.SetBackgroundDrawable(ContextCompat.GetDrawable(context, Resource.Drawable.rounded_border_dark));
            dialog.Show();
        }
Ejemplo n.º 11
0
        public static void DisplayDialog(Context context, string title, string message, Action positiveAction)
        {
            var titleView = new TextView(context)
            {
                Text     = title,
                TextSize = 20,
                Gravity  = GravityFlags.Center,
            };

            titleView.SetTextColor(Color.White);
            titleView.SetPadding(5, 5, 5, 2);
            titleView.SetCompoundDrawablesWithIntrinsicBounds(Resource.Drawable.ic_menu_notifications, 0, 0, 0);

            var dialog = new AlertDialog.Builder(context, Resource.Style.AlertsDialogTheme)
                         .SetCustomTitle(titleView)
                         .SetMessage(message)
                         .SetCancelable(true)
                         .SetNegativeButton("Cancel", (s, args) => { })
                         .SetPositiveButton("OK", (s, args) => positiveAction())
                         .Create();

            dialog.Window.SetBackgroundDrawable(ContextCompat.GetDrawable(context, Resource.Drawable.rounded_border_dark));
            dialog.Show();
        }
Ejemplo n.º 12
0
        public static AlertDialog BuildForm(Context context, string title, Action action, params View[] formContents)
        {
            var titleView = new TextView(context)
            {
                Text     = title,
                TextSize = 20,
                Gravity  = GravityFlags.Center,
            };

            titleView.SetTextColor(Color.White);
            titleView.SetPadding(10, 16, 6, 6);
            titleView.SetCompoundDrawablesWithIntrinsicBounds(Resource.Drawable.ic_menu_myplaces, 0, 0, 0);

            var layout = new LinearLayout(context)
            {
                Orientation = Android.Widget.Orientation.Vertical
            };

            layout.SetPadding(10, 16, 6, 6);

            foreach (var content in formContents)
            {
                layout.AddView(content);
            }

            var dialog = new AlertDialog.Builder(context, Resource.Style.AlertsDialogTheme)
                         .SetCustomTitle(titleView)
                         .SetView(layout)
                         .SetCancelable(true)
                         .SetNegativeButton("Cancel", (s, args) => { })
                         .SetPositiveButton("OK", (s, args) => action())
                         .Create();

            dialog.Window.SetBackgroundDrawable(ContextCompat.GetDrawable(context, Resource.Drawable.rounded_border_dark));
            return(dialog);
        }
Ejemplo n.º 13
0
        public static void DisplayLegend(Context context, string title, params LinearLayout[] rows)
        {
            var titleView = new TextView(context)
            {
                Text     = title,
                TextSize = 20,
                Gravity  = GravityFlags.Center,
            };

            titleView.SetTextColor(Color.White);
            titleView.SetPadding(5, 5, 5, 2);
            titleView.SetCompoundDrawablesWithIntrinsicBounds(Resource.Drawable.ic_menu_add, 0, 0, 0);

            var layout = new LinearLayout(context)
            {
                Orientation = Android.Widget.Orientation.Vertical
            };

            layout.SetPadding(100, 10, 100, 10);
            layout.SetClipToPadding(true);

            foreach (var row in rows)
            {
                layout.AddView(row);
            }

            var dialog = new AlertDialog.Builder(context, Resource.Style.AlertsDialogTheme)
                         .SetCustomTitle(titleView)
                         .SetView(layout)
                         .SetCancelable(true)
                         .SetNegativeButton("OK", (s, args) => { })
                         .Create();

            dialog.Window.SetBackgroundDrawable(ContextCompat.GetDrawable(context, Resource.Drawable.rounded_border_dark));
            dialog.Show();
        }
Ejemplo n.º 14
0
        public void AddAction(int colorId, int drawableId, Action onClick)
        {
            var newFab = new FloatingActionButton(Context);

            newFab.UseCompatPadding = true;
            var layoutParams = new LayoutParams(
                ViewGroup.LayoutParams.WrapContent,
                ViewGroup.LayoutParams.WrapContent);

            layoutParams.AddRule(LayoutRules.AlignParentBottom);
            layoutParams.AddRule(LayoutRules.AlignParentRight);
            newFab.LayoutParameters   = layoutParams;
            newFab.Size               = FloatingActionButton.SizeMini;
            newFab.Visibility         = ViewStates.Invisible;
            newFab.BackgroundTintList = ColorStateList.ValueOf(new Color(ContextCompat.GetColor(Context, colorId)));
            newFab.SetImageDrawable(ContextCompat.GetDrawable(Context, drawableId));
            newFab.Click += (sender, e) =>
            {
                onClick?.Invoke();
            };

            container.AddView(newFab, 0);
            fabs.Add(newFab);
        }
Ejemplo n.º 15
0
        private void UpdateUI()
        {
            RunOnUiThread(async() =>
            {
                bool isRunning                  = await IsRunning();
                _activityStatusText.Text        = await _viewModel.StatusTxt(isRunning);
                _activityStatusDescription.Text = await _viewModel.StatusTxtDescription(isRunning);

                Color enabledColor =
                    new Color(ContextCompat.GetColor(this, Resource.Color.infectionStatusButtonOnGreen));
                Color disabledColor =
                    new Color(ContextCompat.GetColor(this, Resource.Color.infectionStatusButtonOffRed));
                _statusLinearLayout.SetBackgroundColor(isRunning ? enabledColor : disabledColor);
                _toolbarLinearLayout.SetBackgroundColor(isRunning ? enabledColor : disabledColor);
                Window.SetStatusBarColor(isRunning ? enabledColor : disabledColor);

                //Accessibility
                _activityStatusText.ContentDescription =
                    SMITTESPORING_APP_TITLE_ACCESSIBILITY + await _viewModel.StatusTxt(isRunning);

                if (isRunning)
                {
                    _onOffButton.Text = INFECTION_STATUS_STOP_BUTTON_TEXT;
                    _onOffButton.ContentDescription = INFECTION_STATUS_STOP_BUTTON_ACCESSIBILITY_TEXT;
                    _onOffButton.Background         = ContextCompat.GetDrawable(this, Resource.Drawable.ic_secondary_button);
                    _onOffButton.SetTextColor(new Color(ContextCompat.GetColor(this, Resource.Color.primaryText)));
                }
                else
                {
                    _onOffButton.Text = INFECTION_STATUS_START_BUTTON_TEXT;
                    _onOffButton.ContentDescription = INFECTION_STATUS_START_BUTTON_ACCESSIBILITY_TEXT;
                    _onOffButton.Background         = ContextCompat.GetDrawable(this, Resource.Drawable.ic_default_button);
                    _onOffButton.SetTextColor(new Color(ContextCompat.GetColor(this, Resource.Color.secondaryText)));
                }
            });
        }
Ejemplo n.º 16
0
        private void RefreshUI(Activity ctx)
        {
            TypedValue typedValue = new TypedValue();
            var        theme      = ctx.Theme;

            theme.ResolveAttribute(Resource.Color.colorPrimary, typedValue, true);
            foreach (AttrEntity <View> entity in BackGroundViews)
            {
                theme.ResolveAttribute(entity.ColorId, typedValue, true);
                entity.View.SetBackgroundResource(typedValue.ResourceId);
            }
            foreach (AttrEntity <View> entity in BackGroundDrawableViews)
            {
                theme.ResolveAttribute(entity.ColorId, typedValue, true);
                entity.View.SetBackgroundResource(typedValue.ResourceId);
            }
            foreach (AttrEntity <TextView> entity in TextColorViews)
            {
                theme.ResolveAttribute(entity.ColorId, typedValue, true);
                var color = new Color(ContextCompat.GetColor(ctx, typedValue.ResourceId));
                entity.View.SetTextColor(color);
            }
            RefreshStatusBar(ctx);
        }
Ejemplo n.º 17
0
        public async void InitLocation()
        {
            try
            {
                if (ContextCompat.CheckSelfPermission(CrossCurrentActivity.Current.AppContext, Manifest.Permission.AccessFineLocation) == Permission.Granted)
                {
                    //locationManager = (LocationManager)CrossCurrentActivity.Current.AppContext.GetSystemService(Context.LocationService);

                    InitLocationRequest();
                    await StartRequestingLocationUpdates();

                    isRequestingLocationUpdates = true;
                }
                else
                {
                    // The app does not have permission ACCESS_FINE_LOCATION
                    RequestLocationPermission(2444);
                }
            }
            catch (Exception ex)
            {
                Log.Error("GPS EXCEPTION", ex.StackTrace);
            }
        }
Ejemplo n.º 18
0
        private void CropImage(Uri selectedImageURI)
        {
            Uri destinationUri = Uri.FromFile(new File(Context.CacheDir, QueryName(Context.ContentResolver, selectedImageURI)));

            UCrop.Options options = new UCrop.Options();
            options.SetCompressionQuality(IMAGE_COMPRESSION);
            options.SetToolbarColor(ContextCompat.GetColor(Context, Resource.Color.colorPrimary));
            options.SetStatusBarColor(ContextCompat.GetColor(Context, Resource.Color.colorPrimaryDark));
            options.SetActiveControlsWidgetColor(ContextCompat.GetColor(Context, Resource.Color.colorAccent));

            if (lockAspectRatio)
            {
                options.WithAspectRatio(ASPECT_RATIO_X, ASPECT_RATIO_Y);
            }

            if (setBitmapMaxWidthHeight)
            {
                options.WithMaxResultSize(bitmapMaxWidth, bitmapMaxHeight);
            }

            UCrop.Of(selectedImageURI, destinationUri)
            .WithOptions(options)
            .Start(Context, this, UCROP_REQUEST);
        }
Ejemplo n.º 19
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_main);
            if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.AccessCoarseLocation) ==
                Permission.Denied || ContextCompat.CheckSelfPermission(this, Manifest.Permission.AccessFineLocation) ==
                Permission.Denied)
            {
                GetGpsAccess(this, FindViewById(Resource.Layout.activity_main));
            }
            else
            {
                ShowMap();
            }

            AutoCompleteTextView autoCompleteSource      = FindViewById <AutoCompleteTextView>(Resource.Id.autoCompleteSource);
            AutoCompleteTextView autoCompleteDestination = FindViewById <AutoCompleteTextView>(Resource.Id.autoCompleteDestination);

            adapter = new CustomArrayAdapter(this, Resource.Layout.list_view, location.getLocationByText);

            autoCompleteSource.Adapter    = adapter;
            autoCompleteSource.Threshold  = 2;
            autoCompleteSource.ItemClick += AutoCompleteSource_ItemClick;

            autoCompleteDestination.Adapter    = adapter;
            autoCompleteDestination.Threshold  = 2;
            autoCompleteDestination.ItemClick += AutoCompleteSource_ItemClick;

            location.getLocationByText("India");

            inputManager = (InputMethodManager)GetSystemService(InputMethodService);
            if (!location.allSites.Any())
            {
                location.UpdateSitesData().Wait();
            }
        }
Ejemplo n.º 20
0
        protected override void OnResume()
        {
            base.OnResume();

            Task.Run(async() =>
            {
                try
                {
                    await YoutubeApiClient.Search();
                }
                catch (Exception ex)
                {
                    GoogleAnalyticsService.Instance.TrackAppException(ex.Message, true);
                    RunOnUiThread(new Runnable(
                                      () => Toast.MakeText(Application.Context, "Could not connect, please check your internet connection", ToastLength.Long).Show()));
                };
            });

            if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.WriteExternalStorage) == Permission.Granted &&
                ContextCompat.CheckSelfPermission(this, Manifest.Permission.ReadExternalStorage) == Permission.Granted)
            {
                StartActivity(new Intent(Application.Context, typeof(SongsPlayer)));
            }
        }
Ejemplo n.º 21
0
        EditText CreateEditText()
        {
            EditTextControl = string.IsNullOrEmpty(Mask) ? new TextInputEditText(Context) : new MaskedEditText(Context, Mask);

            var lpEditText = new LinearLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent);

            EditTextControl.LayoutParameters = lpEditText;
            EditTextControl.Hint             = TextHint;
            EditTextControl.Text             = Text;
            EditTextControl.ImeOptions       = ImeOptions;
            EditTextControl.SetTextColor(TextColor ?? ContextCompat.GetColorStateList(Context, Resource.Color.text));
            EditTextControl.SetHintTextColor(TextHintColor ?? ContextCompat.GetColorStateList(Context, Resource.Color.text));
            EditTextControl.Background   = null;
            EditTextControl.InputType    = InputType;
            EditTextControl.ImeOptions   = ImeAction.Done;
            EditTextControl.FocusChange += EditText_FocusChange;
            EditTextControl.TextChanged += EditText_TextChanged;

            UpdateLabelSize(Text?.Length > 0);

            EditTextControl.SetCompoundDrawablesWithIntrinsicBounds(null, null, DrawableRight, null);

            return(EditTextControl);
        }
Ejemplo n.º 22
0
        public void SelectPosition(int index)
        {
            if (index >= 0)
            {
                _currentPosition = index;
                for (int i = 0; i < _slideCount; i++)
                {
                    var drawableId = (i == index)
                        ? (Resource.Drawable.indicator_dot_white)
                        : (Resource.Drawable.indicator_dot_grey);

                    Drawable drawable = ContextCompat.GetDrawable(_context, drawableId);
                    if (selectedDotColor != DEFAULT_COLOR && i == index)
                    {
                        drawable.Mutate().SetColorFilter(new Color(selectedDotColor), PorterDuff.Mode.SrcIn);
                    }
                    if (unselectedDotColor != DEFAULT_COLOR && i != index)
                    {
                        drawable.Mutate().SetColorFilter(new Color(unselectedDotColor), PorterDuff.Mode.SrcIn);
                    }
                    _dots[i].SetImageDrawable(drawable);
                }
            }
        }
Ejemplo n.º 23
0
        protected override void OnCreate(Bundle bundle)
        {
            _externalFilesDir = Application.Context.GetExternalFilesDir(null).AbsolutePath;
            AppDomain.CurrentDomain.UnhandledException += OnAppDomainUnhandledException;
            TaskScheduler.UnobservedTaskException      += OnTaskSchedulerOnUnobservedTaskException;

            //base.SetTheme(Resource.Style.AppTheme);
            base.OnCreate(bundle);
            Xamarin.Forms.Forms.Init(this, bundle);

            if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.Camera) != Permission.Granted ||
                ContextCompat.CheckSelfPermission(this, Manifest.Permission.AccessFineLocation) != Permission.Granted ||
                ContextCompat.CheckSelfPermission(this, Manifest.Permission.ReadExternalStorage) != Permission.Granted ||
                ContextCompat.CheckSelfPermission(this, Manifest.Permission.WriteExternalStorage) != Permission.Granted ||
                ContextCompat.CheckSelfPermission(this, Manifest.Permission.ReadUserDictionary) != Permission.Granted ||
                ContextCompat.CheckSelfPermission(this, Manifest.Permission.WriteUserDictionary) != Permission.Granted)
            {
                RequestPermissions();
            }
            else
            {
                InitializeContext();
            }
        }
        private void ChangeCursorColor()
        {
            try
            {
                var field = Java.Lang.Class.FromType(typeof(Android.Widget.TextView)).GetDeclaredField("mCursorDrawableRes");
                field.Accessible = true;
                int resId = field.GetInt(this.Control);

                field            = Java.Lang.Class.FromType(typeof(Android.Widget.TextView)).GetDeclaredField("mEditor");
                field.Accessible = true;

                var cursorDrawable = ContextCompat.GetDrawable(this.Context, resId);
                cursorDrawable.SetColorFilter((this.Element as MaterialEntry).TintColor.ToAndroid(), Android.Graphics.PorterDuff.Mode.SrcIn);

                var editor = field.Get(this.Control);
                field            = editor.Class.GetDeclaredField("mCursorDrawable");
                field.Accessible = true;
                field.Set(editor, new Drawable[] { cursorDrawable, cursorDrawable });
            }
            catch (Java.Lang.NoSuchFieldException)
            {
                System.Diagnostics.Debug.WriteLine("Cannot change Textfield's cursor color.");
            }
        }
 private void RequestPermissions()
 {
     if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.AccessCoarseLocation) != (int)Permission.Granted ||
         ContextCompat.CheckSelfPermission(this, Manifest.Permission.AccessFineLocation) != (int)Permission.Granted ||
         ContextCompat.CheckSelfPermission(this, Manifest.Permission.WriteExternalStorage) != (int)Permission.Granted ||
         ContextCompat.CheckSelfPermission(this, Manifest.Permission.ReadExternalStorage) != (int)Permission.Granted ||
         ContextCompat.CheckSelfPermission(this, Manifest.Permission.Internet) != (int)Permission.Granted)
     {
         ActivityCompat.RequestPermissions(this,
                                           new System.String[]
         {
             Manifest.Permission.AccessCoarseLocation,
             Manifest.Permission.AccessFineLocation,
             Manifest.Permission.WriteExternalStorage,
             Manifest.Permission.ReadExternalStorage,
             Manifest.Permission.Internet
         },
                                           100);
     }
     else
     {
         GetCurrentPosition();
     }
 }
Ejemplo n.º 26
0
        public byte[] GetPinIconForColor(Color color)
        {
            var context = CrossCurrentActivity.Current.Activity;

            using (var drawable =
                       (BitmapDrawable)ContextCompat.GetDrawable(context, Resource.Drawable.ic_pin_disabled).Mutate())
                using (var bitmap =
                           Bitmap.CreateBitmap(drawable.Bitmap.Width, drawable.Bitmap.Height, Bitmap.Config.Argb8888))
                {
                    using (var canvas = new Canvas(bitmap))
                    {
                        drawable.SetBounds(0, 0, canvas.Width, canvas.Height);
                        drawable.SetColorFilter(color.ToAndroid(), PorterDuff.Mode.SrcAtop);
                        drawable.Draw(canvas);
                    }

                    using (var stream = new MemoryStream())
                    {
                        bitmap.Compress(Bitmap.CompressFormat.Png, 100, stream);

                        return(stream.ToArray());
                    }
                }
        }
        private void Initialize()
        {
            try
            {
                Models = new List <MeowBottomNavigation.Model>
                {
                    new MeowBottomNavigation.Model(0, ContextCompat.GetDrawable(MainContext, Resource.Drawable.icon_home_vector)),
                    new MeowBottomNavigation.Model(1, ContextCompat.GetDrawable(MainContext, Resource.Drawable.icon_notification_vector)),
                };

                if (AppSettings.ShowTrendingPage)
                {
                    Models.Add(new MeowBottomNavigation.Model(2, ContextCompat.GetDrawable(MainContext, Resource.Drawable.icon_fire_vector)));
                }

                Models.Add(new MeowBottomNavigation.Model(3, ContextCompat.GetDrawable(MainContext, Resource.Drawable.ic_menu)));

                NavigationTabBar.AddModel(Models);

                NavigationTabBar.SetDefaultIconColor(Color.ParseColor("#bfbfbf"));
                NavigationTabBar.SetSelectedIconColor(Color.ParseColor(AppSettings.MainColor));

                NavigationTabBar.SetBackgroundBottomColor(AppSettings.SetTabDarkTheme ? Color.Black : Color.White);
                NavigationTabBar.SetCircleColor(AppSettings.SetTabDarkTheme ? Color.Black : Color.White);

                NavigationTabBar.SetCountTextColor(Color.White);
                NavigationTabBar.SetCountBackgroundColor(Color.ParseColor(AppSettings.MainColor));

                NavigationTabBar.SetOnClickMenuListener(this);
                NavigationTabBar.SetOnReselectListener(this);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Check whether the current app has the necessary permissions (by default, the camera permission is required).
        /// If not, apply for the permission. This method should be called in the onResume method of the main activity.
        /// </summary>
        /// <param name="activity"></param>
        public static void CheckPermission(Activity activity)
        {
            foreach (string permission in PERMISSIONS_ARRAYS)
            {
                if (ContextCompat.CheckSelfPermission(activity, permission) != Permission.Granted)
                {
                    isHasPermission = false;
                    break;
                }
            }

            if (!isHasPermission)
            {
                foreach (string permission in PERMISSIONS_ARRAYS)
                {
                    if (ContextCompat.CheckSelfPermission(activity, permission) != Permission.Granted)
                    {
                        permissionsList.Add(permission);
                    }
                }
                ActivityCompat.RequestPermissions(activity,
                                                  permissionsList.ToArray(), REQUEST_CODE_ASK_PERMISSIONS);
            }
        }
Ejemplo n.º 29
0
        void ShowList(int id)
        {
            if (CombatListButton != null)
            {
                //get a context, any context
                Context c = CombatListButton.Context;

                CMPreferences.SetLastCombatTab(CombatListButton.Context, id);


                CombatListButton.Background = ContextCompat.GetDrawable(c, (id == 0) ?
                                                                        Resource.Drawable.blue_button_inverse : Resource.Drawable.blue_button);
                CombatListLayout.Visibility = (id == 0) ? ViewStates.Visible : ViewStates.Gone;
                PlayerListButton.Background = ContextCompat.GetDrawable(c, (id == 1) ?
                                                                        Resource.Drawable.blue_button_inverse : Resource.Drawable.blue_button);
                PlayerListLayout.Visibility  = (id == 1) ? ViewStates.Visible : ViewStates.Gone;
                MonsterListButton.Background = ContextCompat.GetDrawable(c, (id == 2) ?
                                                                         Resource.Drawable.blue_button_inverse : Resource.Drawable.blue_button);
                MonsterListLayout.Visibility = (id == 2) ? ViewStates.Visible : ViewStates.Gone;

                characterView.Visibility   = (id == 0) ? ViewStates.Visible : ViewStates.Gone;
                dieRollerLayout.Visibility = (id != 0) ? ViewStates.Visible : ViewStates.Gone;
            }
        }
Ejemplo n.º 30
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View view = inflater.Inflate(Resource.Layout.PaylasimSayisiSecDialogFragment, container, false);

            //view.FindViewById<RelativeLayout>(Resource.Id.rootView).ClipToOutline = true;
            DevamEt          = view.FindViewById <Button>(Resource.Id.button1);
            DevamEt.Click   += DevamEt_Click;
            PlusCard         = view.FindViewById <CardView>(Resource.Id.card_view1);
            GoldCard         = view.FindViewById <CardView>(Resource.Id.card_view2);
            PlatinumCard     = view.FindViewById <CardView>(Resource.Id.card_view3);
            IsletmeLogo      = view.FindViewById <CircleImageView>(Resource.Id.profile_image);
            PlusCard.Tag     = 0;
            GoldCard.Tag     = 1;
            PlatinumCard.Tag = 2;

            PlusCard.Click     += PlusCard_Click;
            GoldCard.Click     += PlusCard_Click;
            PlatinumCard.Click += PlusCard_Click;
            MarginleriSifirla(1);
            var CompanyInfo = DataBase.COMPANY_INFORMATION_GETIR()[0];

            new SetImageHelper().SetImage(this.Activity, IsletmeLogo, CompanyInfo.logoPath);
            //DataBase.YUKLENECEK_SABLON_TEMIZLE();
            if (ContextCompat.CheckSelfPermission(this.Activity, Android.Manifest.Permission.ReadExternalStorage) == Permission.Granted &&
                ContextCompat.CheckSelfPermission(this.Activity, Android.Manifest.Permission.WriteExternalStorage) == Permission.Granted &&
                ContextCompat.CheckSelfPermission(this.Activity, Android.Manifest.Permission.Camera) == Permission.Granted)
            {
                var DevamEdenSablonVarmi = DataBase.YUKLENECEK_SABLON_GETIR();
                if (DevamEdenSablonVarmi.Count > 0)
                {
                    YuklenecekMediaCountHelper.Countt = DevamEdenSablonVarmi[0].maxMediaCount;
                    this.Activity.StartActivity(typeof(YeniSablonOlusturBaseActivity));
                }
            }
            return(view);
        }