public void Close() { var snackbar = _snackbar; if (snackbar == null) return; _snackbar = null; snackbar.Dismiss(); }
/// <summary> /// A overloaded helpermethod, for setting the color of a snackbars text. /// </summary> /// <param name="snack">The snackbar which textcolor should be set.</param> /// <param name="context">The context for getting resources.</param> /// <returns>The finished snackbar.</returns> private static Snackbar Make(Snackbar snack, Context context) { // Finds the textview in the snackbar, and the sets the color. snack.View.FindViewById<TextView>(Resource.Id.snackbar_text) .SetTextColor(context.Resources.GetColor(Resource.Color.accent_text)); return snack; }
public void OnActionClicked(Snackbar snackbar) { foreach (int position in changed) { items.Insert(position, backup[position]); adapter.NotifyItemInserted(position); } adapter.NotifyDataSetChanged(); adapter.NotifyItemRangeChanged(0, items.Count); saved = true; }
// display results on refresh private void DisplayRefresher() { swipeRefreshLayout.Refreshing = false; filter_button.Visibility = ViewStates.Visible; filter_button.Text = show_all; state = 0; if (mResponse.Success == true) { mRecyclerView.SetLayoutManager(mLayoutManager); accountSummaries = mResponse.Content.Where(u => u.AmountSystem != 0).ToList <AccountSummary>(); mRecyclerViewAdapter = new RecyclerViewAdapterAccountSummary(accountSummaries, this, MainActivity.user); mRecyclerViewAdapter.ItemClick += MRecyclerViewAdapter_ItemClick; mRecyclerView.SetAdapter(mRecyclerViewAdapter); } else { Snackbar.Make(linearLayout, mResponse.Message ?? "An Error Occured", Snackbar.LengthLong).Show(); } }
private async void SetupUI() { PreferenceHelper.Init(this); loadingCircle.Visibility = ViewStates.Visible; if (File.Exists(ideasdbPath)) { var cachedDb = await DBAssist.DeserializeDBAsync <List <Category> >(ideasdbPath); if (cachedDb != null) { Global.Categories = cachedDb; categoryList.AddRange(cachedDb); SetupList(); CloudDBManager.StartLowkeyInvalidation(); } else { File.Delete(ideasdbPath); SetupUI(); } } else { var snack = Snackbar.Make(bookmarksFab, "Getting ideas from server. Please wait.", Snackbar.LengthIndefinite); snack.Show(); var db = await CloudDBManager.DownloadDB(SetupUI, snack); if (db != null) { Global.Categories = db; snack.Dismiss(); categoryList = db; SetupList(); } else { loadingCircle.Visibility = ViewStates.Gone; } } }
private void RequestBluetoothPermission() { var currentActivity = MainActivity.Instance; if (currentActivity.ShouldShowRequestPermissionRationale(Manifest.Permission.Bluetooth)) { Snackbar.Make(currentActivity.FindViewById(Android.Resource.Id.Content), "应用程序需要蓝牙权限.", Snackbar.LengthIndefinite).SetAction("Ok", v => { currentActivity.RequestPermissions(permissions, REQUEST_BLUETOOTH); }).Show(); } else { currentActivity.RequestPermissions(permissions, REQUEST_BLUETOOTH); } }
private void RequestMicPermission() { var currentActivity = MainActivity.Instance; if (ShouldShowRequestPermissionRationale(currentActivity, Manifest.Permission.RecordAudio)) { Snackbar.Make(currentActivity.FindViewById(Android.Resource.Id.Content), "App requires microphone permission.", Snackbar.LengthIndefinite).SetAction("Ok", v => { currentActivity.RequestPermissions(permissions, REQUEST_MIC); }).Show(); } else { RequestPermissions(currentActivity, permissions, REQUEST_MIC); } }
private async Task RegisterUser(LoginData data) { var response = await IdeaBagApi.Instance.RegisterAsync(data); if (response.Payload != null) { Global.AuthUser(response.Payload); var expirationDate = DateTime.Now.AddMilliseconds(response.Payload.ExpiresInMillis); PreferenceManager.Instance.AddEntry("expiresIn", JsonConvert.SerializeObject(expirationDate)); OnUserLoggedIn?.Invoke(this, response.Payload.Email); Dismiss(); } else { Snackbar.Make(loadingCircle, response.ErrorMessage, Snackbar.LengthLong).Show(); } }
private void checkWriteExternal() { if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.WriteExternalStorage) != (int)Permission.Granted) { if (ShouldShowRequestPermissionRationale(Manifest.Permission.WriteExternalStorage)) { Snackbar.Make(layout, "Please allow requst Write External", Snackbar.LengthIndefinite).SetAction("ok", new Action<View>(delegate (View obj) { RequestPermissions(new string[] { Manifest.Permission.WriteExternalStorage }, WRITE_EXTERNAL); })).Show(); } else { RequestPermissions(new string[] { Manifest.Permission.WriteExternalStorage }, WRITE_EXTERNAL); } } }
void RequestLocationPermission() { if (Android.Support.V4.App.ActivityCompat.ShouldShowRequestPermissionRationale(this, Manifest.Permission.AccessFineLocation)) { var layout = FindViewById(Android.Resource.Id.Content); Snackbar.Make(layout, Resource.String.permission_location_rationale, Snackbar.LengthIndefinite) .SetAction(Resource.String.ok, new Action <View>(delegate { Android.Support.V4.App.ActivityCompat.RequestPermissions(this, REQUIRED_PERMISSIONS, RC_REQUEST_LOCATION_PERMISSION); }) ).Show(); } else { Android.Support.V4.App.ActivityCompat.RequestPermissions(this, REQUIRED_PERMISSIONS, RC_REQUEST_LOCATION_PERMISSION); } }
private void TextFromKotlinEvent(object sender, EventArgs eventArgs) { View view = (View)sender; HideKeyboard(this); string kotlinString = string.Empty; try { kotlinString = LoymaxKotlinIntence.KotlinMethod(); } catch (Exception ex) { Snackbar.Make(view, ex.Message, Snackbar.LengthLong).SetAction("Action", (View.IOnClickListener)null).Show(); } Snackbar.Make(view, kotlinString, Snackbar.LengthLong).SetAction("Action", (View.IOnClickListener)null).Show(); HideKeyboard(this); }
private void GoogleMap_MyLocationButtonClick(object sender, GoogleMap.MyLocationButtonClickEventArgs e) { snackbar?.Dismiss(); float zoom = googleMap.CameraPosition.Zoom; Location location = googleMap.MyLocation; if (location == null) { snackbar = Snackbar.Make(view, "Données GPS non disponibles", Snackbar.LengthIndefinite); snackbar.Show(); return; } CameraUpdate cameraUpdate = CameraUpdateFactory.NewLatLngZoom(new LatLng(location.Latitude, location.Longitude), Math.Max(zoom, TramUrWayApplication.MyLocationZoom)); googleMap.AnimateCamera(cameraUpdate); }
public void OnClick(View v) { switch (v.Id) { case Resource.Id.btn_login: AttemptLogin(); break; case Resource.Id.btn_forgot_password: Snackbar.Make(v, GetString(Resource.String.snackbar_forgot_password), Snackbar.LengthLong) .SetAction("^_^", (view) => { }).Show(); break; case Resource.Id.btn_forgot_register: Snackbar.Make(v, GetString(Resource.String.snackbar_register), Snackbar.LengthLong) .SetAction("^_^", (view) => { }).Show(); break; } }
/// <summary> /// Gets the location async. /// </summary> /// <returns>The location async.</returns> public async Task GetLocationAsync() { try { if (IsGooglePlayServicesInstalled() && UseGooglePlayLocations) { Report("Getting gplay services location async...", 0); // register for location updates await Task.Run(() => { googleApiClient = new GoogleApiClient.Builder(this) .AddApi(LocationServices.API) .AddConnectionCallbacks(this) .AddOnConnectionFailedListener(this) .Build(); googleApiClient.Connect(); }); } else { Report("Getting provider location async...", 0); // try get location via gps directly await Task.Run(() => { RunOnUiThread(() => { InitializeLocationManager(); LocationManager.RequestLocationUpdates(LocationProvider, 0, 0, this); }); }); } } catch (Exception ex) { Report("Unable to get location\nDBG Exception: " + ex, 2); Report(GetString(Resource.String.common_google_play_services_unsupported_text), 0); Snackbar.Make(coordinatorView, Resource.String.error_play_missing, Snackbar.LengthIndefinite) .SetAction(Resource.String.snackbar_button_ok, v => HandleConnections()) .Show(); } }
public void OnComplete(Task task) { if (task.IsSuccessful == true) { //get the current user now that they are authenticated FirebaseUser user = auth.CurrentUser; //insert into database WriteRecord(user); Snackbar snackbar = Snackbar.Make(activity_sign_up, "Register Successfully ", Snackbar.LengthShort); snackbar.Show(); } else { Snackbar snackbar = Snackbar.Make(activity_sign_up, "Register Failed ", Snackbar.LengthShort); snackbar.Show(); } }
private void RequestMicPermission() { var currentActivity = MainActivity.Instance; if (currentActivity.ShouldShowRequestPermissionRationale(Manifest.Permission.RequestIgnoreBatteryOptimizations)) { Snackbar.Make(currentActivity.FindViewById(Android.Resource.Id.Content), "App requires IgnoreBattery permission.", Snackbar.LengthIndefinite).SetAction("Ok", v => { currentActivity.RequestPermissions(permissions, 1); }).Show(); } else { currentActivity.RequestPermissions(permissions, 1); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Create your application here SetContentView(Resource.Layout.Maplayout); var toolbar = FindViewById <Toolbar>(Resource.Id.toolbar); toolbar.SetBackgroundColor(Color.ParseColor("#cf2a27")); //Toolbar will now take on default Action Bar characteristics SetActionBar(toolbar); //You can now use and reference the ActionBar ActionBar.SetHomeButtonEnabled(true); ActionBar.SetDisplayHomeAsUpEnabled(true); ActionBar.Title = "Map"; const string permission = Manifest.Permission.AccessCoarseLocation; if (CheckSelfPermission(permission) == (int)Permission.Granted) { RequestPermissions(PermissionsLocation, RequestLocationId); SetUpMap(); } else { if (ShouldShowRequestPermissionRationale(permission)) { //Explain to the user why we need to read the contacts Snackbar.Make(FindViewById(Resource.Layout.Maplayout), "Location access is required to show coffee shops nearby.", Snackbar.LengthIndefinite) .SetAction("OK", v => RequestPermissions(PermissionsLocation, RequestLocationId)) .Show(); return; } //Finally request permissions with the list of permissions and Id RequestPermissions(PermissionsLocation, RequestLocationId); SetUpMap(); } //SetUpMap(); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_main); var toolbar = FindViewById <V7Toolbar>(Resource.Id.toolbar); SetSupportActionBar(toolbar); SupportActionBar.SetHomeAsUpIndicator(Resource.Drawable.ic_menu); SupportActionBar.SetDisplayHomeAsUpEnabled(true); drawerLayout = FindViewById <DrawerLayout> (Resource.Id.drawer_layout); var navigationView = FindViewById <NavigationView> (Resource.Id.nav_view); if (navigationView != null) { setupDrawerContent(navigationView); } var viewPager = FindViewById <Android.Support.V4.View.ViewPager> (Resource.Id.viewpager); if (viewPager != null) { setupViewPager(viewPager); } var fab = FindViewById <FloatingActionButton> (Resource.Id.fab); fab.Click += (sender, e) => { Snackbar.Make(fab, "Here's a snackbar!", Snackbar.LengthLong).SetAction("Action", new ClickListener(v => { Console.WriteLine("Action handler"); })).Show(); }; var tabLayout = FindViewById <TabLayout> (Resource.Id.tabs); tabLayout.SetupWithViewPager(viewPager); }
protected override async Task OnInitializedAsync() { Snackbar.Clear(); if (!string.IsNullOrWhiteSpace(this.SnippetId)) { try { this.CodeFiles = (await this.SnippetsService.GetSnippetContentAsync(this.SnippetId)).ToDictionary(f => f.Path, f => f); if (!this.CodeFiles.Any()) { this.errorMessage = "No files in snippet."; } else { this.activeCodeFile = this.CodeFiles.First().Value; } } catch (ArgumentException) { this.errorMessage = "Invalid Snippet ID."; } catch (Exception) { this.errorMessage = "Unable to get snippet content. Please try again later."; } } if (!this.CodeFiles.Any()) { this.activeCodeFile = new CodeFile { Path = CoreConstants.MainComponentFilePath, Content = CoreConstants.MainComponentDefaultFileContent, }; this.CodeFiles.Add(CoreConstants.MainComponentFilePath, this.activeCodeFile); } this.CodeFileNames = this.CodeFiles.Keys.ToList(); await base.OnInitializedAsync(); }
private async void LoadCourses() { loadingCircle.Visibility = ViewStates.Visible; var details = PreferenceManager.Instance.GetJsonEntryAs <LoginResponse>("cred").Details; var teacherId = (int)details["Id"]; var response = await PresentSirApi.Instance.GetTeacherCourses(30, 1, teacherId); if (response.Data?.Data != null) { HideEmptyState(); collection = new ObservableCollection <Class>(response.Data.Data); var adapter = new TeacherCoursesAdapter(collection, coursesRecycler); coursesRecycler.SetLayoutManager(new LinearLayoutManager(this)); coursesRecycler.SetAdapter(adapter); coursesRecycler.SetItemAnimator(new DefaultItemAnimator()); adapter.ItemClicked += (pos) => { var intent = new Intent(this, typeof(AttendanceDetailActivity)); intent.PutExtra("classId", collection[pos].Id); StartActivity(intent); }; if (collection.Count == 0) { ShowEmptyState(); } adapter.OnMoreClicked += Adapter_OnMoreClicked; } else { Snackbar.Make(coursesRecycler, response.ErrorMessage, Snackbar.LengthIndefinite) .SetAction("Retry", (v) => LoadCourses()) .Show(); } loadingCircle.Visibility = ViewStates.Gone; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); _textUsuario = FindViewById <EditText>(Resource.Id.TextUsuario); _textSenha = FindViewById <EditText>(Resource.Id.TextSenha); _btnLogin = FindViewById <Button>(Resource.Id.BtnLogin); _btnLogin.Click += async(sender, e) => { EnableCampos(false); try { var result = await new AutenticacaoRepositorio().Autenticar(_textUsuario.Text, _textSenha.Text); App.Instancia.Login(result); StartActivity(new Intent(this, typeof(MainActivity))); Finish(); } catch (WebException ex) when(ex.Status == WebExceptionStatus.ProtocolError) { EnableCampos(true); if (ex.Response is HttpWebResponse response && response.StatusCode == HttpStatusCode.Unauthorized) { Snackbar.Make(ContentLayout, Resource.String.erroNaoAutorizado, Snackbar.LengthIndefinite) .SetAction(Resource.String.ok, v => { }) .Show(); } } catch { EnableCampos(true); Snackbar.Make(ContentLayout, Resource.String.erroRequisicao, Snackbar.LengthIndefinite) .SetAction(Resource.String.ok, v => { }) .Show(); } }; }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.activity_main); // Get our button from the layout resource, // and attach an event to it viewpager = FindViewById <Android.Support.V4.View.ViewPager>(Resource.Id.viewpager); var toolbar = FindViewById <V7Toolbar>(Resource.Id.toolbar); SetSupportActionBar(toolbar); SupportActionBar.SetIcon(Resource.Drawable.whatsapp); SupportActionBar.SetDisplayHomeAsUpEnabled(false); SupportActionBar.SetDisplayShowTitleEnabled(false); SupportActionBar.SetHomeButtonEnabled(false); if (viewpager.Adapter == null) { setupViewPager(viewpager); } else { viewpager.Adapter.NotifyDataSetChanged(); } var fab = FindViewById <FloatingActionButton>(Resource.Id.fab); fab.Click += (sender, e) => { // Show a snackbar Snackbar.Make(fab, "Sorry! Contacts can't be added.", Snackbar.LengthLong).SetAction("OK", v => Console.WriteLine("Action handler")).Show(); }; var tabLayout = FindViewById <TabLayout>(Resource.Id.tabs); tabLayout.SetupWithViewPager(viewpager); }
/** * Callback received when a permissions request has been completed. */ public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults) { if (requestCode == REQUEST_CAMERA) { // Received permission result for camera permission. Log.Info(TAG, "Received response for Camera permission request."); // Check if the only required permission has been granted if (grantResults.Length == 1 && grantResults[0] == Permission.Granted) { // Camera permission has been granted, preview can be displayed Log.Info(TAG, "CAMERA permission has now been granted. Showing preview."); Snackbar.Make(layout, Resource.String.permission_available_camera, Snackbar.LengthShort).Show(); } else { Log.Info(TAG, "CAMERA permission was NOT granted."); Snackbar.Make(layout, Resource.String.permissions_not_granted, Snackbar.LengthShort).Show(); } } else if (requestCode == REQUEST_CONTACTS) { Log.Info(TAG, "Received response for contact permissions request."); // We have requested multiple permissions for contacts, so all of them need to be // checked. if (PermissionUtil.VerifyPermissions(grantResults)) { // All required permissions have been granted, display contacts fragment. Snackbar.Make(layout, Resource.String.permission_available_contacts, Snackbar.LengthShort).Show(); } else { Log.Info(TAG, "Contacts permissions were NOT granted."); Snackbar.Make(layout, Resource.String.permissions_not_granted, Snackbar.LengthShort).Show(); } } else { base.OnRequestPermissionsResult(requestCode, permissions, grantResults); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); drawerLayout = this.FindViewById <DrawerLayout> (Resource.Id.drawer_layout); //Set hamburger items menu SupportActionBar.SetHomeAsUpIndicator(Resource.Drawable.ic_menu); //setup navigation view navigationView = FindViewById <NavigationView>(Resource.Id.nav_view); //handle navigation navigationView.NavigationItemSelected += (sender, e) => { e.MenuItem.SetChecked(true); switch (e.MenuItem.ItemId) { case Resource.Id.nav_home_1: ListItemClicked(0); break; case Resource.Id.nav_home_2: ListItemClicked(1); break; } Snackbar.Make(drawerLayout, "You selected: " + e.MenuItem.TitleFormatted, Snackbar.LengthLong) .Show(); drawerLayout.CloseDrawers(); }; //if first time you will want to go ahead and click first item. if (savedInstanceState == null) { ListItemClicked(0); } }
private async void StartProgress(object sender, EventArgs e) { Snackbar.Make(coordinatorLayout, "Progress Bar Started!", Snackbar.LengthLong).Show(); fabCancel.Visibility = ViewStates.Visible; fabStart.Visibility = ViewStates.Invisible; // cancel any previous tasks if (cts != null) { cts.Cancel(); } cts = new CancellationTokenSource(); try { elasticDownloadView.Progress = 0; // intro delay if (firstRun) { firstRun = false; elasticDownloadView.StartIntro(); await Task.Delay(1000, cts.Token); } // progress var progress = 0; while (progress < 100) { await Task.Delay(1000, cts.Token); progress += 10; elasticDownloadView.Progress = progress; } // finish elasticDownloadView.Success(); } catch (Exception) { // fail elasticDownloadView.Fail(); } cts = null; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_detail); var toolbar = FindViewById <Toolbar>(Resource.Id.toolbar); SetSupportActionBar(toolbar); var productId = Intent.GetStringExtra(MainActivity.PRODUCT_ID); var product = DataProvider.GetProduct(productId); var tv = FindViewById <TextView>(Resource.Id.nameText); tv.Text = product.Name; var descView = FindViewById <TextView>(Resource.Id.descriptionText); descView.Text = product.Description; var formatter = NumberFormat.CurrencyInstance; var price = formatter.Format(product.Price); var priceText = FindViewById <TextView>(Resource.Id.priceText); priceText.Text = price; var iv = FindViewById <ImageView>(Resource.Id.imageView); var bitmap = getBitmapFromAsset(product.ProductId); iv.SetImageBitmap(bitmap); var fab = FindViewById <FloatingActionButton>(Resource.Id.fab); fab.Click += delegate { var rootView = FindViewById <CoordinatorLayout>(Resource.Id.coordinator); Snackbar.Make(rootView, "Replace with your own action", Snackbar.LengthLong).SetAction("Action", (t) => { }).Show(); }; SupportActionBar.SetDisplayHomeAsUpEnabled(true); }
private void RequestReadPermission() { if (ActivityCompat.ShouldShowRequestPermissionRationale(this, Manifest.Permission.ReadExternalStorage)) { // Provide an additional rationale to the user if the permission was not granted // and the user would benefit from additional context for the use of the permission. // For example if the user has previously denied the permission. Snackbar.Make(layout, Resource.String.permission_read_rationale, Snackbar.LengthIndefinite).SetAction(Resource.String.ok, new Action <View>(delegate(View obj) { ActivityCompat.RequestPermissions(this, new String[] { Manifest.Permission.ReadExternalStorage }, REQUEST_READ); })).Show(); } else { // Read permission has not been granted yet. Request it directly. ActivityCompat.RequestPermissions(this, new String[] { Manifest.Permission.ReadExternalStorage }, REQUEST_READ); } }
public MainWindow() { InitializeComponent(); Task.Factory.StartNew(() => { Thread.Sleep(2500); }).ContinueWith(t => { //note you can use the message queue from any thread, but just for the demo here we //need to get the message queue from the snackbar, so need to be on the dispatcher MainSnackbar.MessageQueue.Enqueue("Welcome to Material Design In XAML Tookit"); }, TaskScheduler.FromCurrentSynchronizationContext()); DataContext = new MainWindowViewModel(MainSnackbar.MessageQueue); Snackbar = MainSnackbar; WindowStartupLocation = WindowStartupLocation.CenterScreen; }
public void RequestPermission() { string[] permissions = new string[2] { "android.permission.READ_EXTERNAL_STORAGE", "android.permission.WRITE_EXTERNAL_STORAGE" }; if (MainActivity.instance == null) { Toast.MakeText(Application.get_Context(), "A csatolmányok letöltéséhez engedélyeznie kell a külső tárolóhoz való hozzáférést!", (ToastLength)1).Show(); } else if (ActivityCompat.ShouldShowRequestPermissionRationale((Activity)MainActivity.instance, "android.permission.WRITE_EXTERNAL_STORAGE")) { ((BaseTransientBottomBar)Snackbar.Make(((Activity)MainActivity.instance).FindViewById(16908290), "A csatolmányok letöltéséhez engedélyeznie kell a külső tárolóhoz való hozzáférést!", -2).SetAction("OK", (Action <View>)(v => ActivityCompat.RequestPermissions((Activity)MainActivity.instance, permissions, 1)))).Show(); } else { ActivityCompat.RequestPermissions((Activity)MainActivity.instance, permissions, 1); } }
public override bool OnOptionsItemSelected(IMenuItem item) { //if (item.ItemId == Android.Resource.Id.Home) //{ // OnBackPressed(); //} if (item.ItemId == Resource.Id.action_config) { //Intent intent = new Intent(this, typeof(second_activity)); //StartActivity(intent); return(true); } if (item.ItemId == Resource.Id.action_about) { Snackbar.Make(layout, "Ver 1.0", Snackbar.LengthShort).Show(); return(true); } return(base.OnOptionsItemSelected(item)); }
public static void RequestPermissionsForApp(Activity activity) { var showRequestRationale = ActivityCompat.ShouldShowRequestPermissionRationale(activity, Manifest.Permission.AccessFineLocation) || ActivityCompat.ShouldShowRequestPermissionRationale(activity, Manifest.Permission.AccessCoarseLocation); if (showRequestRationale) { var rootView = activity.FindViewById(AndroidResource.Id.Content); Snackbar.Make(rootView, AppResource.String.request_location_permissions, Snackbar.LengthIndefinite) .SetAction(AppResource.String.ok, v => { activity.RequestPermissions(LOCATION_PERMISSIONS, RC_LOCATION_PERMISSIONS); }) .Show(); } else { activity.RequestPermissions(LOCATION_PERMISSIONS, RC_LOCATION_PERMISSIONS); } }
async Task GetLocationPermissionAsync() { const string permission = "android.permission.ACCESS_FINE_LOCATION" ; if (ShouldShowRequestPermissionRationale(permission)) { //Explain to the user why we need to read the contacts Snackbar.Make(layout, "Location access is required to show directions to lecture venues.", Snackbar.LengthIndefinite) .SetAction("OK", v => RequestPermissions(PermissionsLocation, RequestLocationId)) .Show(); return; } for (int i = 0; i < PermissionsLocation.Length; i++) { RequestPermissions(PermissionsLocation, i); } }
private void AttachmentAdapter_AttachmentRetrieveError(object sender, Adapters.AttachmentRetrieveErrorEventArgs e) { var ErrorText = e.Reason switch { Adapters.AttachmentRetrieveErrorReason.CONNECTION_LOST => GetString(Resource.String.main_snack_connect), Adapters.AttachmentRetrieveErrorReason.RELOGIN_REQUIRED => GetString(Resource.String.main_snack_relogin), _ => GetString(Resource.String.main_snack_error), }; if (string.IsNullOrWhiteSpace(ErrorText)) { return; } //Snackbar aufrufen View rootView = this.Window.DecorView.FindViewById(Android.Resource.Id.Content); Snackbar snack = Snackbar.Make(rootView, ErrorText, Snackbar.LengthLong); snack.Show(); }
// Temporal hack to change the // action color in snack bar private void ChangeSnackBarColor (Snackbar snack) { var group = (ViewGroup) snack.View; for (int i = 0; i < group.ChildCount; i++) { View v = group.GetChildAt (i); var textView = v as TextView; if (textView != null) { TextView t = textView; if (t.Text == Resources.GetString (Resource.String.UndoBarButtonText)) { t.SetTextColor (Resources.GetColor (Resource.Color.material_green)); } } } }
public void OnShown(Snackbar snackbar) { }
public void Close() { var toast = _toast; if (toast == null) { var snackbar = _snackbar; if (snackbar == null) return; _snackbar = null; snackbar.Dismiss(); } else { _toast = null; toast.Close(); } }
public override void OnDismissed(Snackbar snackbar, int evt) { base.OnDismissed(snackbar, evt); _tcs.TrySetResult(null); }
public void OnDismiss(Snackbar snackbar) { }
public void OnDismissed(Snackbar snackbar) { if (!saved) DismissFeedItems(); }
protected static TextView FindTextView(Snackbar bar) { var group = (ViewGroup)bar.View; for (var i = 0; i < group.ChildCount; i++) { var txt = group.GetChildAt(i) as TextView; if (txt != null) return txt; } throw new Exception("No textview found on snackbar"); }
//private Color GetArgb(int argb) //{ // return Color.Argb(Color.GetAlphaComponent(argb), Color.GetRedComponent(argb), Color.GetGreenComponent(argb), Color.GetBlueComponent(argb)); //} public void CheckListItem(bool checkValue = false) { try { SparseBooleanArray checkedList = listView.CheckedItemPositions; for (int i = 0; i < checkedList.Size(); i++) { if (checkedList.ValueAt(i)) { var pos = checkedList.KeyAt(i); listView.SetItemChecked(pos, checkValue); wcdListAdapter[pos].ItemChecked = checkValue; } } if (wcdListAdapter.Count == 0) fabWcd.SetImageResource(Resource.Drawable.ic_refresh_white); else if (listView.CheckedItemCount == 0) fabWcd.SetImageResource(Resource.Drawable.ic_subject_white); else fabWcd.SetImageResource(Resource.Drawable.ic_edit_white); wcdListAdapter.NotifyDataSetChanged(); } catch { } if (snackbar != null) { snackbar.Dismiss(); snackbar = null; } }
public override void OnDismissed (Snackbar snackbar, int evt) { if (evt == 2) { System.Diagnostics.Debug.WriteLine ("cancelled"); SetPermissions.FailedResultHandler (this.Parent.ID); } else { ActivityCompat.RequestPermissions (Xamarin.Forms.Forms.Context as MainActivity, Parent.Permissions, Parent.ID); } base.OnDismissed (snackbar, evt); }
public void Show(Snackbar snackbar, float duration) { _snackbar = snackbar; _snackbar.SetCallback(this).SetDuration((int)duration).Show(); }
private void FabWcd_Click(object sender, EventArgs e) { if (snackbar != null) { snackbar.Dismiss(); snackbar = null; } if (wcdListAdapter.Count == 0) { Refresh(); if (wcdListAdapter.Count == 0) Show("항목이 없습니다"); return; } List<int> positions = new List<int>(); try { SparseBooleanArray checkedList = listView.CheckedItemPositions; for (int i = 0; i < checkedList.Size(); i++) { if (checkedList.ValueAt(i)) { positions.Add(checkedList.KeyAt(i)); } } if (positions.Count == 0) lastPosition = 0; } catch { return; } View dialogView = LayoutInflater.From(Context).Inflate(Resource.Layout.weld_condition_editor, null); AlertDialog.Builder dialog = new AlertDialog.Builder(Context); dialog.SetView(dialogView); // 에디트텍스트 IList<EditText> etList = new List<EditText>(); etList.Add(dialogView.FindViewById<EditText>(Resource.Id.etOutputData)); etList.Add(dialogView.FindViewById<EditText>(Resource.Id.etOutputType)); etList.Add(dialogView.FindViewById<EditText>(Resource.Id.etSqueezeForce)); etList.Add(dialogView.FindViewById<EditText>(Resource.Id.etMoveTipClearance)); etList.Add(dialogView.FindViewById<EditText>(Resource.Id.etFixedTipClearance)); etList.Add(dialogView.FindViewById<EditText>(Resource.Id.etPannelThickness)); etList.Add(dialogView.FindViewById<EditText>(Resource.Id.etCommandOffset)); int[] etMax = { 2000, 100, 350, 500, 500, 500, 500, 1000, 1000 }; // 임계치 InputMethodManager imm = (InputMethodManager)Context.GetSystemService(Context.InputMethodService); for (int i = 0; i < etList.Count; i++) { EditText et = etList[i]; if (i == 0) // outputData et.Text = wcdListAdapter[lastPosition][i]; // 기본선택된 자료값 가져오기 int maxValue = etMax[i]; // 임계치 설정 et.FocusChange += (object sender1, View.FocusChangeEventArgs e1) => { int n; if (Int32.TryParse(et.Text, out n)) { if (n > maxValue) { n = maxValue; et.Text = n.ToString(); } } }; et.KeyPress += (object sender1, View.KeyEventArgs e1) => { // KeyEventArgs.Handled // 라우트된 이벤트를 처리된 것으로 표시하려면 true이고, // 라우트된 이벤트를 처리되지 않은 것으로 두어 이벤트가 추가로 라우트되도록 허용하려면 false입니다. // 기본값은 false입니다. e1.Handled = false; if (e1.KeyCode == Keycode.Enter || e1.KeyCode == Keycode.Back || e1.KeyCode == Keycode.Escape) { imm.HideSoftInputFromWindow(et.WindowToken, 0); et.ClearFocus(); e1.Handled = true; } }; } var statusText = dialogView.FindViewById<TextView>(Resource.Id.statusText); statusText.Text = wcdListAdapter[lastPosition][0]; if (positions.Count > 0) { StringBuilder sb = new StringBuilder(); foreach (int pos in positions) { sb.Append(pos + 1); sb.Append(" "); } statusText.Text = "수정 항목: " + sb.ToString().TrimEnd(); } else { statusText.Text = "수정 항목: " + (lastPosition + 1).ToString(); } var sampleSeekBar = dialogView.FindViewById<SeekBar>(Resource.Id.sampleSeekBar); sampleSeekBar.Max = wcdListAdapter.Count - 1; sampleSeekBar.Progress = Convert.ToInt32(wcdListAdapter[lastPosition][0]) - 1; sampleSeekBar.ProgressChanged += (object sender1, SeekBar.ProgressChangedEventArgs e1) => { for (int i = 0; i < wcdListAdapter[sampleSeekBar.Progress].Count; i++) { if (etList[i].Text != "") etList[i].Text = wcdListAdapter[sampleSeekBar.Progress][i]; } if (positions.Count == 0) { lastPosition = sampleSeekBar.Progress; statusText.Text = "수정 항목: " + (lastPosition + 1).ToString(); } }; // 선택 시작 var beginSeekBar = dialogView.FindViewById<SeekBar>(Resource.Id.sbBegin); beginSeekBar.Max = wcdListAdapter.Count - 1; beginSeekBar.Progress = 0; // 선택 끝 var endSeekBar = dialogView.FindViewById<SeekBar>(Resource.Id.sbEnd); endSeekBar.Max = wcdListAdapter.Count - 1; endSeekBar.Progress = endSeekBar.Max; beginSeekBar.ProgressChanged += (object sender1, SeekBar.ProgressChangedEventArgs e1) => { if (e1.FromUser) { int sb1Progress = beginSeekBar.Progress; int sb2Progress = endSeekBar.Max - endSeekBar.Progress; if (sb1Progress > sb2Progress) { sb2Progress = sb1Progress; endSeekBar.Progress = endSeekBar.Max - sb1Progress; } if (sb1Progress == 0 && sb2Progress == 0 || sb1Progress == beginSeekBar.Max && sb2Progress == endSeekBar.Max) { if (positions.Count > 0) { StringBuilder sb = new StringBuilder(); foreach (int pos in positions) { sb.Append(pos + 1); sb.Append(" "); } statusText.Text = "수정 항목: " + sb.ToString().TrimEnd(); } else { statusText.Text = "수정 항목: " + (lastPosition + 1).ToString(); } } else { statusText.Text = "수정 범위: " + string.Format("{0}", sb1Progress + 1) + " ~ " + string.Format("{0}", sb2Progress + 1); } } }; endSeekBar.ProgressChanged += (object sender2, SeekBar.ProgressChangedEventArgs e2) => { if (e2.FromUser) { int sb1Progress = beginSeekBar.Progress; int sb2Progress = endSeekBar.Max - endSeekBar.Progress; if (sb2Progress < sb1Progress) { sb1Progress = sb2Progress; beginSeekBar.Progress = sb2Progress; } if (sb1Progress == 0 && sb2Progress == 0 || sb1Progress == beginSeekBar.Max && sb2Progress == endSeekBar.Max) { if (positions.Count > 0) { StringBuilder sb = new StringBuilder(); foreach (int pos in positions) { sb.Append(pos + 1); sb.Append(" "); } statusText.Text = "수정 항목: " + sb.ToString().TrimEnd(); } else { statusText.Text = "수정 항목: " + (lastPosition + 1).ToString(); } } else { statusText.Text = "수정 범위: " + string.Format("{0}", sb1Progress + 1) + " ~ " + string.Format("{0}", sb2Progress + 1); } } }; dialog.SetNegativeButton("취소", delegate { CheckListItem(false); }); dialog.SetPositiveButton("저장", async delegate { int seekBegin = beginSeekBar.Progress + 1; int seekEnd = endSeekBar.Max - endSeekBar.Progress + 1; bool isSeek = !((seekBegin == 1 && seekEnd == 1) || (seekBegin == beginSeekBar.Max + 1 && seekEnd == endSeekBar.Max + 1)); bool isUpdate = false; if (positions.Count == 0) positions.Add(lastPosition); if (isSeek) { positions.Clear(); for (int rowNum = seekBegin - 1; rowNum < seekEnd; rowNum++) { positions.Add(rowNum); } } foreach (int rowNum in positions) { for (int colNum = 1; colNum < wcdListAdapter[rowNum].Count; colNum++) { if (etList[colNum].Text != "") { wcdListAdapter[rowNum][colNum] = etList[colNum].Text; isUpdate = true; } } listView.SetItemChecked(rowNum, false); wcdListAdapter[rowNum].ItemChecked = false; } if (isUpdate) { wcdListAdapter.NotifyDataSetChanged(); await UpdateFileAsync(robotPath, wcdListAdapter); } else { CheckListItem(false); } try { if (wcdListAdapter.Count == 0) fabWcd.SetImageResource(Resource.Drawable.ic_refresh_white); else if (listView.CheckedItemCount == 0) fabWcd.SetImageResource(Resource.Drawable.ic_subject_white); else fabWcd.SetImageResource(Resource.Drawable.ic_edit_white); } catch { } }); dialog.Show(); }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { view = inflater.Inflate(Resource.Layout.weld_condition_fragment, container, false); coordinatorLayout = view.FindViewById<CoordinatorLayout>(Resource.Id.coordinator_layout); selectedBackGroundColor = Context.Resources.GetColor(Resource.Color.tab3_textview_background); listView = view.FindViewById<ListView>(Resource.Id.wcdListView); listView.Adapter = wcdListAdapter; listView.FastScrollEnabled = false; listView.ChoiceMode = ChoiceMode.Multiple; listView.ItemClick += (object sender, AdapterView.ItemClickEventArgs e) => { wcdListAdapter[e.Position].ItemChecked = listView.IsItemChecked(e.Position); if (listView.IsItemChecked(e.Position)) { lastPosition = e.Position; e.View.SetBackgroundColor(selectedBackGroundColor); } else { e.View.SetBackgroundColor(defaultBackgroundColor); // 기본 백그라운드 색깔 } try { if (wcdListAdapter.Count == 0) fabWcd.SetImageResource(Resource.Drawable.ic_refresh_white); else if (listView.CheckedItemCount == 0) fabWcd.SetImageResource(Resource.Drawable.ic_subject_white); else fabWcd.SetImageResource(Resource.Drawable.ic_edit_white); } catch { } if (snackbar == null) snackbar = Snackbar.Make(coordinatorLayout, listView.CheckedItemCount.ToString() + "개 항목 선택됨", Snackbar.LengthIndefinite) .SetAction("선택 취소", (view) => { CheckListItem(); snackbar = null; }); if (listView.CheckedItemCount > 0) { if (snackbar.IsShown) snackbar.SetText(listView.CheckedItemCount.ToString() + "개 항목 선택됨"); else snackbar.Show(); } else if (snackbar != null) { snackbar.Dismiss(); snackbar = null; } }; listView.ItemLongClick += (object sender, AdapterView.ItemLongClickEventArgs e) => { FabWcd_Click(sender, e); }; var refresher = view.FindViewById<SwipeRefreshLayout>(Resource.Id.srl); if (refresher != null) { refresher.Refresh += delegate { Refresh(forced: true); refresher.Refreshing = false; }; } // 떠 있는 액션버튼 fabWcd = view.FindViewById<FloatingActionButton>(Resource.Id.fab_wcd); fabWcd.Click += (object sender, EventArgs e) => { if (listView.CheckedItemCount == 0) Pref.TextViewDialog(Context, robotPath); else FabWcd_Click(sender, e); }; try { if (wcdListAdapter.Count == 0) fabWcd.SetImageResource(Resource.Drawable.ic_refresh_white); else if (listView.CheckedItemCount == 0) fabWcd.SetImageResource(Resource.Drawable.ic_subject_white); else fabWcd.SetImageResource(Resource.Drawable.ic_edit_white); } catch { } return view; }