how to set drawableleft image from url with picasso library? - picasso

I need to load an image at drawableLeft from url. Is this possible?
<TextView
android:id="#+id/txt_check_opportunity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="0dp"
android:drawableLeft="#drawable/ic_star_yellow_24dp"
android:layout_toRightOf="#+id/checkbox_opportunity"
android:text="#string/opportunity"
android:textSize="#dimen/text_large_size"
android:textStyle="bold" />

You need to create a Picasso Target, load the image from the URL into the target and call setCompoundDrawablesWithIntrinsicBounds on the TextView with the Bitmap from the onBitmapLoaded callback of Picasso Target.
You need to also keep in mind that the Picasso Targets are weakly referenced so you need to be careful and keep strong references to your target.
I have implemented a widget called PicassoTargetableTextView that does all of that. You can use the PicassoTargetableTextView.load(left, top, right, bottom) to load drawables into the TextView at runtime.

Related

How to put ImageView in Xamarin.Android App which resizes itself depending on device screen size?

I have created an image with in Android Asset Studio and it gave me zip file containing folders: drawable-hdpi, drawable-mdpi, drawable-xhdpi, drawable-xxhdpi, drawable-xxxhdpi, each folder contains the png image with different proportions. I pasted these folders in Resources/drawable folder in my android project. Then I created:
<ImageView
android:src="#android:drawable/ic_ac_unit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/imageView1" />
But nothing displays on screen. In google there are a lot of examples but it seems they are for android with java because when I follow them using Xamarin.Android it's not working.
So I think your problem is that your ImageView's image is from the Android system, please try the following:
<ImageView
android:src="#drawable/ic_ac_unit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/imageView1" />
This should be corrected. As you might have noticed I changed the android:src. The value you had was :
android:src="#android:drawable/ic_ac_unit"
And that is trying to get the drawable with the name "ic_ac_unit" from the Android OS's predefined drawables, and not from your drawables. That is the issue that I'm seeing.
Also your "drawable-resolution" folders, created by the Android Asset Studio should be pasted directly in the Resources folder of your project and not inside the Resource/drawable folder.

Mvvmcross Android TextInputEditText Binding Enabled

I have a Switch and a TextInputEditText. Both 'Enabled' are bound to the same field in the viewmodel.
When the activity is loaded, the bound field is set to false. The Switch is disabled as expected. However, the TextInputEditText is enabled. The 'Clickable' has the same issue. Text is bound successfully.
After changed the bound field to true and then false, the TextInputEditText Enable & Clickable work correctly. It seems that it only happens when it is loaded initially.
<android.support.v7.widget.SwitchCompat
style="#style/EntryTextStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
local:MvxLang="Text LabelDeferArrivalNotice"
local:MvxBind="Checked RouteMarker.DeferArrivalNotice; Enabled RouteMarker.ArrivalNotice" />
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="#+id/edittext_route_marker_EffectiveFromDateTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:editable="false"
android:focusableInTouchMode="false"
style="#style/EntryTextStyle"
local:MvxLang="Hint LabelEffectiveFromTime"
local:MvxBind="Text DateTimeToString(RouteMarker.EffectiveFromDateTime);
Enabled RouteMarker.ArrivalNotice;
Clickable RouteMarker.ArrivalNotice;
Click PromptDeferTimeCommand" />
Is there anything special I have to do with the TextInputEditText?
Thanks
This is an issue with MvvmCross, as Stuart said, there are some interaction between ICommand.CanExecute and the Enabled property. Switching the binding to :
local:MvxBind="Click PromptDeferTimeCommand;Enabled RouteMarker.ArrivalNotice;Clickable RouteMarker.ArrivalNotice;"
Hope to help somebody who searched this problem.

LinearLayout just ignores MvxBind (MvvmCross)

I'm trying to bind LinearLayout to show/hide in accordance with ViewModel State.
For some reason it works great for buttons and textviews but not for LinearLayout.
What could be the reason?
<LinearLayout
android:orientation="vertical"
android:minWidth="25dp"
android:minHeight="25dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
local:MvxBind="Visibility WaitingForConfirmation">
I just tried a quick test using the bool Visible pseudo-property and it worked for both TextView and for LinearLayout
<TextView
android:text="Random text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
local:MvxBind="Visible Generosity > 12" />
<LinearLayout
android:orientation="vertical"
android:minWidth="25dp"
android:minHeight="25dp"
android:background="#ff0000"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
local:MvxBind="Visible Generosity > 12" />
The Visibility property binds to the same underlying Android hide/display mechanism - it just uses the Visibility plugin to convert bool->Visibility enum - so the code should work for that too...
Update: I also tried within the Droid sample https://github.com/slodge/MvvmCross-Tutorials/tree/master/ValueConversion
Within this I just changed the displayed view to LinearLayout in https://github.com/slodge/MvvmCross-Tutorials/blob/master/ValueConversion/ValueConversion.UI.Droid/Resources/Layout/View_Visibility.axml
This sample worked fine:
What is WaitingForConfirmation? I suspect it's a bool, in which case you will need to use a visibility converter, just as you do in Windows binding. A standard visibility converter is provided in the Visibility plugin, and can be used:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="200dp"
android:background="#ff0000"
local:MvxBind="Visibility MakeItVisible, Converter=Visibility" />
One final note: MvvmCross does continue to adapt (and hopefully improve) its binding type conversion - so at some point you may be able to get away with using bools with Visibility enums - but this probably isn't ever going to be recommended practice - normally it's better to use value converters to take control of your binding operations (just like in Windows).

Android: It is impossible to input into editText text after crop image

My interface consists of two parts: editText and imageView used to show image
I use intent MediaStore.ACTION_IMAGE_CAPTURE to take photo, then intent com.android.camera.action.CROP is used to crop that photo.
After cropping, Inputting text into editText but can't be performed though keyboard is displayed (sometimes i can input)
If i input text into edit text before cropping, this manipulation is performed normally.
I tried setting focus for editText but this problem was not solved:
editText.setEnabled(true);
editText.requestFocus();
editText.setFocusable(true);
editText.setFocusableInTouchMode(true);
Hope for your help.
Thanks !
http://blog.csdn.net/mmorss/article/details/19190833
I found this blog, it says, adding an invisble edittext would fix your problem. And I tried it, success.
Following is how I did it:
I add this extra edittext named et_none:
<EditText
android:id="#+id/et_none"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:background="#drawable/bg_white_box"
android:gravity="top"
android:inputType="textMultiLine"
android:padding="10dp" />
After crop, I add this code:
et_none.requestFocus();
And this bug never appear.
This bug only appear on Htc G11 at about every two times.

How to use multiline textview with scrollbars in monodevelop/monoandroid

I am new in monodevelop/monoandroid.I need code for showing multiline text in textview I have tried bellow but still its not working.I think there should be some code that I have to include in .cs file,but I am not getting what to use there.
I have used c# code also but its not working. I think ellipsize is a android attribute thats why its not working.Please give me some solution.
<ScrollView
android:id="#+id/scrollView2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="10dip"
android:orientation="vertical"
android:layout_gravity="center" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_marginTop="10dip">
<TextView
android:id="#+id/tv_policy1"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:text="Terms of Service O-job Information Terms of Service O-job Information Terms of Service O-job Information Terms of Service O-job Information for Personal non-commercialaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaa aaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaa use only sdfjkj asdfjklfj sdfjkljdf sdfjkljflkj sdfskjfkl sdfjklsdjf sdfkljsdklfj sdfjhsdkfh"
android:textColor="#000000"
android:maxLines="3"
android:singleLine="false"
android:textSize="14dip" />
</RelativeLayout>
</ScrollView>
Please advice....
Thanks in advance!
Try this format:
<ScrollView>
<RelativeLayout>
<TextView/>
<TextView/>
<RelativeLayout/>
<ScrollView/>
Then you can use the align methods given in a RelativeLayout.
Edit:
Explain what your problem is! Do you get an error when compiling or is the text not shown properly? Be more specific.
Also, why do you use attributes like : android:maxLines="3" or android:singleLine="false" or android:layout_height="60dip" in your TextView. Translated this means: The text must have more than one line but a maximum of 3. Also it can't be longer than 60dip.
Depending on the Text that are very strict rules. Use these rules android:layout_width="match_parent" android:layout_height="wrap_content" to make sure that the text can be displayed correctly, remove the attributes I mentioned before in your TextView.

Resources