#StackBounty: #c# #android #xamarin Xamarin Editor Control CursorPosition on Android

Bounty: 100

I’m currently working on a project that requires alot of text manipulation and i’m trying to create a function that can insert text at the current CursorPosition. I’m using a Editor as my Text Control and i noticed that Xamarin does not provide an implementation for CursorPosition yet.

I found out that the Xamarin developers have this on their backlog but I can’t wait for this as I am on a deadline.

I made my own CustomRenderer for the Editor control and i got CursorPosition working for UWP. When i tried to do the same thing for Android however I noticed that I need to use an the event EventHandler SelectionChanged; in the IFormsEditText interface that is not available to me as they marked the interface internal.

Little snippit of code to display progress:

internal class EditorRenderer : Xamarin.Forms.Platform.Android.EditorRenderer
{
    bool _cursorPositionChangePending;
    bool _nativeSelectionIsUpdating;

    IElementController ElementController => Element as IElementController;

    public EditorRenderer(Context context) : base(context) { }

    private Editor _editor;

    protected override void OnElementChanged(ElementChangedEventArgs<XamarinForms.Editor> e)
    {
        base.OnElementChanged(e);

        _editor = (Editor)Element;

        _cursorPositionChangePending = Element.IsSet(Editor.CursorPositionProperty);

        // I wanted to do something along the lines of this
        //if (Control is IFormsEditText editText)
        //{
        //    editText.SelectionChanged += SelectionChanged;
        //}

        if (_cursorPositionChangePending)
            UpdateCursorSelection();
    }

    protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        base.OnElementPropertyChanged(sender, e);
        if (e.PropertyName == Editor.CursorPositionProperty.PropertyName)
        {
            UpdateCursorSelection();
        }
    }
    void SelectionChanged(object sender, XamarinFormsDroid.SelectionChangedEventArgs e)
    {
        if (_nativeSelectionIsUpdating || Control == null || Element == null)
            return;

        int cursorPosition = _editor.CursorPosition;
        int selectionStart = EditText.SelectionStart;

        if (!_cursorPositionChangePending)
        {
            var start = cursorPosition;

            if (selectionStart != start)
                SetCursorPositionFromRenderer(selectionStart);
        }

        if (!_selectionLengthChangePending)
        {
            int elementSelectionLength = Math.Min(EditText.Text.Length - cursorPosition, _editor.SelectionLength);

            var controlSelectionLength = EditText.SelectionEnd - selectionStart;
            if (controlSelectionLength != elementSelectionLength)
                SetSelectionLengthFromRenderer(controlSelectionLength);
        }
    }

Has anyone tried making their own renderer for android with a working implementation for CursorPosition ? Or does anyone have any idea on how this could be realized ? Please let me know.


Get this bounty!!!

#StackBounty: #web-services #xamarin #master-detail #project-template Is Xamarin Master-Detail Template Broken When used with Azure Bac…

Bounty: 50

The Master-Detail template in Xamarin has typically been a great starting point for many of my apps that work with .Net Core Backing Service. For review it has a Dependency service in the Client that allows Mocking of the Azure Backing Service or connection to a real or local service while in development.

The control variable generated by the template is public static bool UseMockDataStore = true;

All Code discussed is completely found here: https://github.com/BicycleMark/SignalRGB

I created a Xamarin Master-Detail project naming it SignalRGB and did the following:

  1. The solution project structure looks like:
    Solution Explored Visual Studio 2019
  2. I start Instance one Visual Studio 2019 And Run SignalRGB.Web
    enter image description here

3) Made Note of url: [https://localhost:44300]
4) Opened another Instance of Visual Studio (2) to run client with UseMockDataSource=false / The default it displayed results in Client using MockDataSource

5)went to these lines and updated Client for talking to my local server waiting for an http request :

 public static string AzureBackendUrl =
            //DeviceInfo.Platform == DevicePlatform.Android ? "http://10.0.2.2:5000" : "http://localhost:44300";
            DeviceInfo.Platform == DevicePlatform.Android ? "http://localhost:44300" : "http://localhost:44300";
        public static bool UseMockDataStore = false;
        public App()
        {
            InitializeComponent();
            if (UseMockDataStore)
            {
                DependencyService.Register<MockDataStore>();
            }
            else
            {
                DependencyService.Register<AzureDataStore>();
            }
            MainPage = new MainPage();
        }
  1. Went and ran SignalRGB.UWP from VS Instance(2) and client application hung on the line GetStringAsync():
         bool IsConnected => Connectivity.NetworkAccess == NetworkAccess.Internet;
         public async Task<IEnumerable<Item>> GetItemsAsync(bool forceRefresh = false)
         {
             if (forceRefresh && IsConnected)
             {
                 var json = await client.GetStringAsync ($"api/item");
                 items = await Task.Run(() => JsonConvert.DeserializeObject<IEnumerable<Item>>(json));
             }
    
             return items;
         }
    

I have tried other platforms iOS and get same result:

What Am I doing wrong here?


Get this bounty!!!

#StackBounty: #xamarin #xamarin.forms How can I change the background color of the Android tab with a renderer, while using a custom re…

Bounty: 500

I create a custom renderer to add some side padding to the tabs on Android:

public class MarginedTabBarAppearance : IShellBottomNavViewAppearanceTracker
{
    public void Dispose()
    {
    }

    public void SetAppearance(BottomNavigationView bottomView, IShellAppearanceElement appearance)
    {
        if (App.devWidth == SIZE.L)
            bottomView.SetPadding(400, 0, 400, 0);
    }

    public void ResetAppearance(BottomNavigationView bottomView)
    {
    }
}

Unfortunately this also has a side effect in that it sets the background color to white.

Does anyone have any knowledge of how I use this renderer and also change the background color?


Get this bounty!!!

#StackBounty: #c# #xamarin #xamarin.forms Binding issue on properties with get; vs with get; set; in Xamarin.Android

Bounty: 100

I have a XF app. In my ViewModel I have the following:

public ICommand ActBtnCmd { get; }
public ICommand AdpBtnCmd { get; }

public SettingsTabViewModel(SettingsTabPage settingsTabPage)
{
   ActBtnCmd = new Command<Templates.Button>((btn) => MessagingCenter.Send(this, "ActBtn", btn));
   AdpBtnCmd = new Command<Templates.Button>((btn) => MessagingCenter.Send(this, "AdpBtn", btn));
}

And in my XAML:

<t:Button Text="{Binding ActBtnText}" 
          TapCommand="{Binding ActBtnCmd}" 
          WidthRequest="30" 
          Theme="{Binding Theme}" />

Debugging in iOS is no problem. But when I debug the app in Android I get these messages in Application Output window:

Binding: 'ActBtnCmd' property not found on 'xxx.SettingsTabViewModel', target property: 'xxx.Templates.Button.TapCommand'
Binding: 'AdpBtnCmd' property not found on 'xxx.SettingsTabViewModel', target property: 'xxx.Templates.Button.TapCommand'

But when I changed my property like below then the messages are gone:

public ICommand ActBtnCmd { get; set; }
public ICommand AdpBtnCmd { get; set; }

Can anyone explain to me why am I getting these messages? And why am I only getting it in Android?


Get this bounty!!!

#StackBounty: #android #tensorflow #xamarin #xamarin.android TensorFlow object detection fails on Xamarin Android with a reshape issue

Bounty: 50

I am following this blog post and GitHub almost exactly:

Blog

Github

But when I run, take a picture and call this line:

var outputs = new float[tfLabels.Count];
tfInterface.Feed("Placeholder", floatValues, 1, 227, 227, 3);
tfInterface.Run(new[] { "loss" });
tfInterface.Fetch("loss", outputs);

The app actually crashes and generates the error below on the .Run line.

I get this error in the output window (and the app crashes):

04-04 17:39:12.575 E/TensorFlowInferenceInterface( 8017): Failed to
run TensorFlow inference with inputs:[Placeholder], outputs:[loss]
Unhandled Exception:

Java.Lang.IllegalArgumentException: Input to reshape is a tensor with
97556 values, but the requested shape requires a multiple of 90944
[[Node: block0_0_reshape0 = Reshape[T=DT_FLOAT, Tshape=DT_INT32,
_device=”/job:localhost/replica:0/task:0/device:CPU:0″](block0_0_concat,
block0_0_reshape0/shape)]]

According to the posts I am reading from the searching I am doing on this error, I sort of understand this is due to the image not fitting the expected size exactly but in the example I am following, this is resized to fit 227×227 everytime and converted to float like in these lines:

var resizedBitmap = Bitmap.CreateScaledBitmap(bitmap, 227, 227, false).Copy(Bitmap.Config.Argb8888, false);

var floatValues = new float[227 * 227 * 3];
var intValues = new int[227 * 227];

resizedBitmap.GetPixels(intValues, 0, 227, 0, 0, 227, 227);

for(int i = 0; i < intValues.Length; i++)
{
     var val = intValues[i];
     floatValues[i * 3 + 0] = ((val & 0xFF) - 104);
     floatValues[i * 3 + 1] = (((val >> 8) & 0xFF) - 117);
     floatValues[i * 3 + 2] = (((val >> 16) & 0xFF) - 123);
}

So, I don’t understand what is causing this or how to fix it. Please help!

UPDATE: I found out the issue is with my model or my labels. I found this out by simply swapping in the model and label file from the sample/github above while leaving all my code the same. When I did this, I no longer get the error. HOWEVER, this still doesn’t tell me much. The error is not very explanatory to point me in a direction of what could be wrong with my model. I assume it is the model because the labels file is simply just a text file with labels on each line. I used Custom Vision Service on Azure to create my model. It trained fine and tests just fine on the web portal. I then exported it as TensorFlow. So, I am not sure what I could have done wrong or how to fix it.

Thanks!


Get this bounty!!!

#StackBounty: #java #c# #android #visual-studio #xamarin Release Mode and Debug Mode in VS

Bounty: 50

I currently work on an Android application, and I messed around a bit with the VS.

I was wandering, what are the real differences between the two modes? I did some research, but I didn’t completely get the real differences and the advantages of each one, as well as when to use a specific mode.

During my research, I came across those questions 1, 2 and 3, talking about the differences between the two.

  1. Why debug mode runs slower than release mode?
  2. When releasing an application to Google Play, which mode should I use and why?
  3. Can I create my own mode?

My app seems to be built fine in Debug mode, yet in Release mode I get a lot of warnings about “no debug symbols file was found”.

  1. What are those debug symbols?
  2. What is the “81” folder in the obj/Debug or obj/Release?
  3. I also noticed that sometimes, when switching from Debug to Release, some Resource.Id are not found, and I need to recreate the axml file for the layouts plus cleaning the sln. How can I prevent it?

As I understood, debug mode uses some files that release mode doesn’t need in order to run, I assume that the missing files are those “debug symbols”?. Maybe it’s a problem with Xamarin or with VS?
These are the warnings I get:

Warning     Directory objRelease81android/assets contains Xamarin.Android.Support.v7.AppCompat.dll but no debug symbols file was found.          0   
Warning     Directory objRelease81android/assets contains Java.Interop.dll but no debug symbols file was found.          0   
Warning     Directory objRelease81android/assets contains Xamarin.Android.Arch.Core.Common.dll but no debug symbols file was found.          0   
Warning     Directory objRelease81android/assets contains Xamarin.Android.Arch.Lifecycle.Common.dll but no debug symbols file was found.         0   
Warning     Directory objRelease81android/assets contains Xamarin.Android.Arch.Lifecycle.Runtime.dll but no debug symbols file was found.            0   
Warning     Directory objRelease81android/assets contains Xamarin.Android.Support.Animated.Vector.Drawable.dll but no debug symbols file was found.          0   
Warning     Directory objRelease81android/assets contains Xamarin.Android.Support.Annotations.dll but no debug symbols file was found.           0   
Warning     Directory objRelease81android/assets contains Xamarin.Android.Support.Compat.dll but no debug symbols file was found.            0   
Warning     Directory objRelease81android/assets contains Xamarin.Android.Support.Core.UI.dll but no debug symbols file was found.           0   
Warning     Directory objRelease81android/assets contains Xamarin.Android.Support.Core.Utils.dll but no debug symbols file was found.            0   
Warning     Directory objRelease81android/assets contains Xamarin.Android.Support.Design.dll but no debug symbols file was found.            0   
Warning     Directory objRelease81android/assets contains Xamarin.Android.Support.Fragment.dll but no debug symbols file was found.          0   
Warning     Directory objRelease81android/assets contains Xamarin.Android.Support.Media.Compat.dll but no debug symbols file was found.          0   
Warning     Directory objRelease81android/assets contains Xamarin.Android.Support.Transition.dll but no debug symbols file was found.            0   
Warning     Directory objRelease81android/assets contains Xamarin.Android.Support.v4.dll but no debug symbols file was found.            0   
Warning     Directory objRelease81android/assets contains Xamarin.Android.Support.v7.RecyclerView.dll but no debug symbols file was found.           0   
Warning     Directory objRelease81android/assets contains Xamarin.Android.Support.Vector.Drawable.dll but no debug symbols file was found.           0   
Warning     Directory objRelease81android/assets contains Xamarin.GooglePlayServices.Base.dll but no debug symbols file was found.           0   
Warning     Directory objRelease81android/assets contains Xamarin.GooglePlayServices.Basement.dll but no debug symbols file was found.           0   
Warning     Directory objRelease81android/assets contains Xamarin.GooglePlayServices.Maps.dll but no debug symbols file was found.           0   
Warning     Directory objRelease81android/assets contains Xamarin.GooglePlayServices.Tasks.dll but no debug symbols file was found.          0   
  1. Are those warning really something I need to worry about when releasing an app? Can they cause any further bugs?

I already tried:

  1. Deleting those files.

  2. Cleaning the solution and the whole project.
    • I hope you could help me with all the questions I asked and provide a fully detailed answer.


Get this bounty!!!