Enabled attribute not working in button - android

I'm using this link (http://robobinding.github.io/RoboBinding/old_binding_attributes.html) to check which attributes are available.
I'm trying to use the "enable" attribute in a button like this:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="start"
android:id="#+id/start_button"
bind:enable="{canStart}" />
But whenever I run the application, I'm getting the following error:
enabled: Unrecognized attribute 'enabled'
-------------------------The first error stack trace-----------------------
enabled: Unrecognized attribute 'enabled'
at org.robobinding.PendingAttributesForViewImpl.getResolutionErrors(PendingAttributesForViewImpl.java:43)
at org.robobinding.binder.BindingAttributeResolver.resolve(BindingAttributeResolver.java:39)
at org.robobinding.binder.BindingViewInflater.resolveAndAddViewBindingAttributes(BindingViewInflater.java:90)
at org.robobinding.binder.BindingViewInflater.onViewCreated(BindingViewInflater.java:85)
at org.robobinding.ViewFactory.notifyViewCreatedIfNotNull(ViewFactory.java:65)
at org.robobinding.ViewFactory.onCreateView(ViewFactory.java:58)
at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:177)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
......
If I change to "visibility" attribute it works fine.
Is the "enabled" attribute supported in buttons?

You should use new 'API and Binding Attributes JavaDocs' link from RoboBinding home page.
All simpleOneWayProperties are removed from RoboBinding framework, as they can be declared when required. The following example can be found from RoboBinding Gallery project.
#ViewBinding(simpleOneWayProperties = {"enabled"})
public class ViewBindingForView extends CustomViewBinding< View> {
}
register it:
reusableBinderFactory = new BinderFactoryBuilder()
.add(new ViewBindingForView().extend(View.class))
.build();
View Visibility is an OneWayMultiTypeProperty, as it support Boolean and Integer. Source code here - https://github.com/RoboBinding/RoboBinding/blob/develop/framework/src/main/java/org/robobinding/widget/view/ViewBindingForView.java
For supported attribute bindings for a widget, except for looking into javadoc, you can also find the implemented binding information in ViewBinding implementation, e.g., RatingBar - https://github.com/RoboBinding/RoboBinding/blob/develop/framework/src/main/java/org/robobinding/widget/ratingbar/RatingBarBinding.java

Related

Xamarin how to solve accessibility content labeling problem?

When i upload a relese to Google Play Console, after internal testing y have a warning (Accessibility => Content labeling) associated to this component.
<ImageButton .../>
Here the recomendation is use android:contentDescription
Then i add xmlns:android="http://schemas.android.com/apk/res/android"
and:
<ImageButton android:contentDescription="bla bla" .../>
But i get an error: The property contentDescription was not found in type ImageButton.
I try to use xct:SemanticEffect.Description and i have not compiler error but in Google Play Console i still see the warning.
More Information:
Full component code:
<ImageButton BackgroundColor="Transparent" Margin="5" xct:SemanticEffect.Description="abrir menú" Clicked="OnBackButtonClicked" >
<ImageButton.Source>
<FontImageSource FontFamily="FAL" Glyph="" Color="{StaticResource Gray3}" Size="25"/>
</ImageButton.Source>
</ImageButton>
Google Play Console - Pre-launch report details - Accesibility tab
Content labeling warning for this component
As already pointed out, you cannot add android:contentDescription="bla bla" directly to the ImageButton one is from the Android platform, the latter is on the Xamarin.Forms level.
If you use the Xamarin Community Toolkit and apply the SemanticEffect.Description="bla bla" that should translate into the contentDescription on Android. If that is not the case, I would be curious to know what the exact warning is that you get after applying it.

Androidx SeekBarPreference xml attribute setMax not found

I'm trying to implement androidx SeekBarPreference, according to the docs I might be able to use setMax attribute in my xml, yet I get the following error when doing so:
in xml:
<SeekBarPreference
app:key="preference_key"
app:title="#string/preference"
app:showSeekBarValue="true"
app:setMax="10"/>
the error:
root_preferences.xml:53: AAPT: error: attribute setMax (aka
gls.dev.MyApplication:setMax) not found.
However, when setting the properties in code it works like a charm:
findPreference<SeekBarPreference>("preference_key")?.apply {
max = 10
min = 1
seekBarIncrement = 1
isAdjustable = true
}
The max attribute currently only exists in the android: namespace, so you will need to use:
<SeekBarPreference
app:key="preference_key"
app:title="#string/preference"
app:showSeekBarValue="true"
android:max="10"/>
You can set up your seek bar like this:
<SeekBarPreference
app:title="Choose value:"
app:defaultValue="2"
app:min="2"
app:seekBarIncrement="1"
android:max="12"
app:key="key"
app:adjustable="true"
app:isPreferenceVisible="true"
app:showSeekBarValue="true"/>
You'll also need to add this to your root tag:
xmlns:android="http://schemas.android.com/apk/res/android"
The attribute is max not setMax. You have to do:
app:max="10"
You should try this
In your XML
<SeekBarPreference
app:key="preference_key"
app:title="#string/preference"
app:showSeekBarValue="true"
app:max="10"/>
It will work

Disabling Android O auto-fill service for an application

Android O has the feature to support Auto-filling for fields. Is there any way I can disable it for a specific application. That is I want to force my application not to use the auto-fill service.
Is it possible ?
To block autofill for an entire activity, use this in onCreate() of the activity:
getWindow()
.getDecorView()
.setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS);
Is there any better method than this ?
Currently there is no direct way to disable the autofill for an entire application, since the autofill feature is View specific.
You can still try this way and call BaseActivity everywhere.
public class BaseActivity extends AppCompatActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
disableAutofill();
}
#TargetApi(Build.VERSION_CODES.O)
private void disableAutofill() {
getWindow().getDecorView().setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS);
}
}
You can also force request autofill this way.
public void forceAutofill() {
AutofillManager afm = context.getSystemService(AutofillManager.class);
if (afm != null) {
afm.requestAutofill();
}
}
Note: At the moment autofill feature is only available in API 26 Android Oreo 8.0
Hope this helps!
I believe the accepted answer is incorrect:
So I have my own class which is extends the android.support.v7.widget.AppCompatEditText and all I did is overwrote the following method with the following value:
#Override
public int getAutofillType() {
return AUTOFILL_TYPE_NONE;
}
no other solutions worked, not even android:importantForAutofill="no".
getAutofillType() comes from the View class, so it should work for every other class such as TextInputEditText too!
I ran into this too. It turns out the issue was caused by setting the hint text on the EditText nested inside the TextInputLayout.
I did some digging and found this nugget in the 26.0.0 Beta 2 release notes.
Andorid Support Release Notes June 2017
TextInputLayout must set hints on onProvideAutofillStructure()
That led me to try setting the hint on the TextInputLayout instead of the nested EditText.
This resolved the crashing issue for me.
Example:
<android.support.design.widget.TextInputLayout
android:id="#+id/textInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Some Hint Text"
android.support.design:hintAnimationEnabled="true"
android.support.design:hintEnabled="true"
android.support.design:layout_marginTop="16dp">
<android.support.design.widget.TextInputEditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.design.widget.TextInputLayout>
Seems to be a bug that needs to be fixed : https://issuetracker.google.com/issues/67675432
In the meanwhile a workaround for now is to disable the AutoFill feature for the whole project.
You can add in the values-v26/styles.xml file the following style or you can edit your BaseEditTextStyle if you are using a specific style for your EditText views.
<style name="App_EditTextStyle" parent="#android:style/Widget.EditText">
<item name="android:importantForAutofill">noExcludeDescendants</item>
</style>
and in the values-v26/themes.xml file you can simply add to the default theme that you are using in your app the items editTextStyle and android:editTextStyle like following :
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
...
<item name="android:editTextStyle">#style/App_EditTextStyle</item>
<item name="editTextStyle">#style/App_EditTextStyle</item>
</style>
this way you can apply this changes for all your EditTexts without needing to change your layout files or Activities (and later on you can easily remove it when the bug is fixed).
Is it possible ?
Not that I am aware of. Certainly, nothing is documented.
Is there any better method than this ?
Not that I am aware of.
In your EditText attributes add android:importantForAutofill="no"
This should be a temporary fix and will only apply to api 26+
Create custom EditText style and set android:importantForAutofill to no.
<style name="EditTextStyleWithoutAutoFill" parent="Widget.AppCompat.EditText">
<item name="android:importantForAutofill">no</item>
</style>
Then in your activity theme set this style for editTextStyle.
<item name="android:editTextStyle">#style/EditTextStyleWithoutAutoFill</item>
In my case, our app targets SDK version 21 but newer devices (26+) were still popping up the autocomplete. Pretty big problem if the app runs on devices that are shared between people. Using just android:importantForAutofill="no" did not work for me.
The only solution that I found to work in my case was:
<EditText
android:importantForAutofill="no"
tools:targetApi="o"
android:autofillHints="AUTOFILL_HINT_SMS_OTP" ...
The reason I added android:autofillHints="AUTOFILL_HINT_SMS_OTP" was because if you long-pressed on the EditText it would still bring up autofill. Basically, I told the field's autofill that it is waiting for a text message that will never be sent. Bit of a hack, I know...
Note: you may have to add xmlns:tools="http://schemas.android.com/tools" to your schemas' if it is not there already.
Had the same problem with API 28+ and disable Autofill. For me the only solution was to disable long click for my views.
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:longClickable="false"
android:text="#={model.emailAdress}"/>
With reference to Google issue tracker, it has been fixed.
This is fixed on Android 8.1
If any issue persists, please report at Google issue tracker they will re-open to examine.

MvvmCross Android BackgroundColor not binding to ViewModel

I'm having a tough time getting a basic MvvmCross Android example working where the BackgroundColor of the RelativeLayout is bound to the ViewModel.
The app runs, some text appears, and I'm expecting my background to turn Yellow. The background color, however, remains unchanged.
I have included the Hot Tuna starter pack in both my Core and Droid projects as well as the MvvmCross - Color Plugin. My Droid project was automatically given ColorPluginBootstrap.cs
Layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
local:MvxBind="BackgroundColor NativeColor(BackgroundColor)">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="20sp"
android:gravity="center"
android:text="Text to make sure the layout inflates" />
</RelativeLayout>
ViewModel
public class ViewModel : MvxViewModel
{
RGBAColorConverter _rgbaConverter;
public ViewModel()
{
var color = "#ffedff00";
_rgbaConverter = new RGBAColorConverter();
BackgroundColor = _rgbaConverter.Convert(color);
}
private MvxColor _backgroundColor;
public MvxColor BackgroundColor
{
get { return _backgroundColor; }
set
{
_backgroundColor = value;
RaisePropertyChanged(() => BackgroundColor);
}
}
}
Binding works - I've tried making other ViewModel properties that were string to do simple text binding. All of that seems just fine.
I've placed debugging break points on the getter of the BackgroundColor ViewModel property and I can see the MvxColor as expected.
What am I missing for my color binding scenario?
I haven't done anything extra in the Setup.cs
I haven't created any other wiring up classes in my Droid project
I haven't created any Android-specific color converter implementations
I've just written a test app and it seems to work for me - using 3.0.14 nuget binaries.
Also, the ValueConverters test app seemed to work OK - https://github.com/MvvmCross/MvvmCross-Tutorials/tree/master/ValueConversion
Looking at your sample, the only thing I can think of is that maybe you are only testing transparent colours (RGBA #ffedff00 has Alpha=0)
If that isn't it, can you post more - perhaps a full sample somewhere?

MvxSpinner/MvxListView doesn't work with MvvmCross Light (Chimp) from axml

In Android project I'm trying to add databindings using CrossLight part of MvvmCross.
Bindings to standard TextView/Buttons work great. But simplest markup with Mvx.Control:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
<Mvx.MvxListView />
</LinearLayout>
Gives an error
"Binary XML file line #1: Error inflating class Mvx.MvxListView"
The same thing is with Mvx.Spinner.
However, when instantiating it from code in Activity.OnCreate:
_bindingContext = new MvxAndroidBindingContext(this, new LayoutInflaterProvider(LayoutInflater), _viewModel);
var view = (LinearLayout)_bindingContext.BindingInflate(Resource.Layout.Main, null);
SetContentView(view);
var spinner = new MvxSpinner(this, null, new MvxAdapter(this, _bindingContext));
view.AddView(spinner);
Everything works great (including bindings). What am I doing wrong? Is this scenario supported in general?
Or maybe I should reference anything else except nuget MvvmCross.HotTuna.CrossCore?
P.S. Haven't found any samples with custom controls and CrossLight neither on github, nor on N+1 videos
If you want to use namespace abbreviations within your non-MvvmCross application, then you'll need to add those abbreviations. This can be done using a custom binding builder or using a 'light' setup step like:
var viewResolver = Mvx.Resolve<IMvxAxmlNameViewTypeResolver>();
viewResolver.ViewNamespaceAbbreviations["Mvx"] = "Cirrious.MvvmCross.Binding.Droid.Views";
viewResolver.ViewNamespaceAbbreviations["MyApp"] = "MyApp.Controls";
When doing this within a full MvvmCross application, then you can override the Setup property ViewNamespaceAbbreviations
protected override IDictionary<string, string> ViewNamespaceAbbreviations
{
get
{
var toReturn = base.ViewNamespaceAbbreviations;
toReturn["MyApp"] = "MyApp.UI.Droid.Controls";
return toReturn;
}
}
When markup was changed to using the full namespace and layout_width and layout_height attribute was added it started to work!
<Cirrious.MvvmCross.Binding.Droid.Views.MvxSpinner
android:id="#+id/MySpinner"
android:layout_width="fill_parent"
android:layout_height="20dp"
/>
It was found when I switched to default Android inflater and it was complaining about missing layout_width in Exceptions.

Categories

Resources