protected override void OnElementChanged (ElementChangedEventArgs<Page> e) { base.OnElementChanged (e); if (e.OldElement != null || Element == null) return; try { activity = this.Context as Activity; view = activity.LayoutInflater.Inflate(Resource.Layout.CameraLayout, this, false); cameraType = CameraFacing.Back; textureView = view.FindViewById<TextureView> (Resource.Id.textureView); textureView.SurfaceTextureListener = this; takePhotoButton = view.FindViewById<global::Android.Widget.Button> (Resource.Id.takePhotoButton); takePhotoButton.Click += TakePhotoButtonTapped; switchCameraButton = view.FindViewById<global::Android.Widget.Button> (Resource.Id.switchCameraButton); switchCameraButton.Click += SwitchCameraButtonTapped; toggleFlashButton = view.FindViewById<global::Android.Widget.Button> (Resource.Id.toggleFlashButton); toggleFlashButton.Click += ToggleFlashButtonTapped; AddView (view); } catch (Exception ex) { //Xamarin.Insights.Report (ex); } }
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Button> e) { base.OnElementChanged(e); if (e.OldElement == null) { androidButton = (global::Android.Widget.Button)Control; formsElement = (CustomImageButton)this.Element; androidButton.SetPadding(20, 20, 20, 20); androidButton.SetAllCaps(false); if (formsElement.ImageName != null) androidButton.SetBackgroundDrawable(Context.Resources.GetDrawable(formsElement.ImageName)); if (formsElement.TextOrientation != null) { if (Convert.ToString(formsElement.TextOrientation) == "Left") { androidButton.Gravity = Android.Views.GravityFlags.Left; } else if (Convert.ToString(formsElement.TextOrientation) == "Right") { androidButton.Gravity = Android.Views.GravityFlags.Right; } else { androidButton.Gravity = Android.Views.GravityFlags.Center; } } } }
void SetupEventHandlers () { takePhotoButton = view.FindViewById<global::Android.Widget.Button> (Resource.Id.takePhotoButton); takePhotoButton.Click += TakePhotoButtonTapped; switchCameraButton = view.FindViewById<global::Android.Widget.Button> (Resource.Id.switchCameraButton); switchCameraButton.Click += SwitchCameraButtonTapped; toggleFlashButton = view.FindViewById<global::Android.Widget.Button> (Resource.Id.toggleFlashButton); toggleFlashButton.Click += ToggleFlashButtonTapped; }
public float ButtonTextSize(string text, double fontSize) { if (_button == null) { _button = new global::Android.Widget.Button(Forms.Context); // _button.SetPadding(10, _button.PaddingTop, 10, _button.PaddingBottom); _button.SetPadding(0, _button.PaddingTop, 0, _button.PaddingBottom); } if (fontSize != 0) { _button.TextSize = (float)fontSize; } var widgetPadding = 8; var bounds = new Rect(); _button.Text = text; _button.Paint.GetTextBounds(text, 0, text.Length, bounds); // Add two times the widgetPadding of 8 dp, because the button has this min size and than resize to the next multi of 8. // http://developer.android.com/guide/practices/ui_guidelines/widget_design.html return (float)Math.Ceiling((bounds.Width() / Resources.System.DisplayMetrics.Density + _button.PaddingLeft + _button.PaddingRight + 2 * widgetPadding) / 8) * 8; }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); if (this.Intent != null) { var receiverID = this.Intent.GetStringExtra(KEY_RECEIVER_ID); if(receiverID != null) _receiverID = new Guid(receiverID); } this.SetContentView(Resource.Layout.activity_camera); try { cameraType = CameraFacing.Back; textureView = this.FindViewById<TextureView>(Resource.Id.textureView); textureView.SurfaceTextureListener = this; takePhotoButton = this.FindViewById<global::Android.Widget.Button>(Resource.Id.takePhotoButton); takePhotoButton.Click += TakePhotoButtonTapped; switchCameraButton = this.FindViewById<global::Android.Widget.Button>(Resource.Id.switchCameraButton); switchCameraButton.Click += SwitchCameraButtonTapped; toggleFlashButton = this.FindViewById<global::Android.Widget.Button>(Resource.Id.toggleFlashButton); toggleFlashButton.Click += ToggleFlashButtonTapped; } catch (Exception ex) { Xamarin.Insights.Report(ex); } }
public Camera2Page() { Activity = this.Context as MainActivity; Activity.CamPage = this; if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { view = Activity.LayoutInflater.Inflate(Resource.Layout.CameraLayout, this, false); } else { view = Activity.LayoutInflater.Inflate(Resource.Layout.CameraLayoutOld, this, false); } previousPhoto = view.FindViewById <ImageViewAsync>(Resource.Id.previousPhoto); OverlaySeekbar = view.FindViewById <SeekBar>(Resource.Id.overlaySeekbar); OverlaySeekbar.SetOnSeekBarChangeListener(this); if (App.SelectedCondition.Photos != null && App.SelectedCondition.Photos.Count > 0) { ShowHidePreviousPhoto(App.SelectedCondition.Photos[App.SelectedCondition.Photos.Count - 1]); } OverlaySeekbar.Visibility = (App.SelectedCondition.Photos.Count > 0) ? ViewStates.Visible : ViewStates.Gone; takePhotoButton = view.FindViewById <global::Android.Widget.Button>(Resource.Id.takePhotoButton); takePhotoButton.Click += TakePictureTapped; takePhotoButton.Enabled = false; switchCameraButton = view.FindViewById <global::Android.Widget.Button>(Resource.Id.switchCameraButton); switchCameraButton.Click += SwitchCameraButton_Click; switchCameraButton.Enabled = false; switchCameraButton.Visibility = ViewStates.Gone; spinner = view.FindViewById <Android.Widget.ProgressBar>(Resource.Id.progressBar1); spinner.Indeterminate = true; spinner.Visibility = ViewStates.Gone; if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop) { mStateListener = new CameraStateListener() { Page = this }; mSurfaceTextureListener = new CameraSurfaceTextureListener(this); ORIENTATIONS.Append((int)SurfaceOrientation.Rotation0, 90); ORIENTATIONS.Append((int)SurfaceOrientation.Rotation90, 0); ORIENTATIONS.Append((int)SurfaceOrientation.Rotation180, 270); ORIENTATIONS.Append((int)SurfaceOrientation.Rotation270, 180); textureView = view.FindViewById <AutoFitTextureView>(Resource.Id.textureView); textureView.SurfaceTextureListener = mSurfaceTextureListener; string[] camPermissions = { Android.Manifest.Permission.Camera }; // Make sure we can use the camera if ((int)Android.OS.Build.VERSION.SdkInt >= 23 && Activity.CheckSelfPermission(camPermissions[0]) != (Permission.Granted)) { Toast.MakeText(Activity, AppResources.Camera_permissionNeeded, ToastLength.Long).Show(); Activity.RequestPermissions(camPermissions, CamPermReqId); } else { OpenCamera(); } } else { cameraType = CameraFacing.Back; textureView1 = view.FindViewById <TextureView>(Resource.Id.textureView); textureView1.SurfaceTextureListener = this; } AddView(view); }
static void n_SetScheduleOption_Landroid_widget_Button_(IntPtr jnienv, IntPtr native__this, IntPtr native_p0) { global::Com.Applozic.Mobicomkit.Uiwidgets.Schedule.ConversationScheduler __this = global::Java.Lang.Object.GetObject <global::Com.Applozic.Mobicomkit.Uiwidgets.Schedule.ConversationScheduler> (jnienv, native__this, JniHandleOwnership.DoNotTransfer); global::Android.Widget.Button p0 = global::Java.Lang.Object.GetObject <global::Android.Widget.Button> (native_p0, JniHandleOwnership.DoNotTransfer); __this.SetScheduleOption(p0); }
/// <summary> /// Sets the image source. /// </summary> /// <param name="targetButton">The target button.</param> /// <param name="model">The model.</param> /// <returns>A <see cref="Task"/> for the awaited operation.</returns> private async Task SetImageSourceAsync(global::Android.Widget.Button targetButton, CustomImageButton model) { if (targetButton == null || targetButton.Handle == IntPtr.Zero || model == null) { return; } // const int Padding = 10; var source = model.IsEnabled ? model.Source : model.DisabledSource ?? model.Source; using (var bitmap = await GetBitmapAsync(source).ConfigureAwait(false)) { if (bitmap == null) { targetButton.SetCompoundDrawables(null, null, null, null); } else { var drawable = new BitmapDrawable(bitmap); var tintColor = model.IsEnabled ? model.ImageTintColor : model.DisabledImageTintColor; if (tintColor != Xamarin.Forms.Color.Transparent) { drawable.SetTint(tintColor.ToAndroid()); drawable.SetTintMode(PorterDuff.Mode.SrcIn); } using (var scaledDrawable = GetScaleDrawable(drawable, GetWidth(model.ImageWidthRequest), GetHeight(model.ImageHeightRequest))) { Drawable left = null; Drawable right = null; Drawable top = null; Drawable bottom = null; //System.Diagnostics.Debug.WriteLine($"SetImageSourceAsync intptr{targetButton.Handle}"); int padding = 10; // model.Padding targetButton.CompoundDrawablePadding = RequestToPixels(padding); switch (model.Orientation) { case ImageOrientation.ImageToLeft: targetButton.Gravity = GravityFlags.Left | GravityFlags.CenterVertical; left = scaledDrawable; break; case ImageOrientation.ImageToRight: targetButton.Gravity = GravityFlags.Right | GravityFlags.CenterVertical; right = scaledDrawable; break; case ImageOrientation.ImageOnTop: targetButton.Gravity = GravityFlags.Top | GravityFlags.CenterHorizontal; top = scaledDrawable; break; case ImageOrientation.ImageOnBottom: targetButton.Gravity = GravityFlags.Bottom | GravityFlags.CenterHorizontal; bottom = scaledDrawable; break; case ImageOrientation.ImageCentered: targetButton.Gravity = GravityFlags.Center; // | GravityFlags.Fill; top = scaledDrawable; break; } targetButton.SetCompoundDrawables(left, top, right, bottom); } } } }
public void ClickButton(global::Android.Widget.Button button) { button.PerformClick(); }