I have successfully used MvxImageView with ImageUrl, but how can I set a drawable icon as a default for those users which don't have a profilepicture (that is, where ProfileThumbnailImageUrl is empty)?
<MvxImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
local:MvxBind="ImageUrl ProfileThumbnailImageUrl"
DefaultImagePath="#drawable/ic_action_user"/>
If this view is just being used once (e.g. not reused in a list) then you can just use android:src for your default image.
If you need to use DefaultImagePath then you can do this in a binding:
local:MvxBind="ImageUrl ProfileThumbnailImageUrl; DefaultImagePath DefaultImageUrl"
where DefaultImageUrl is a drawable accessed as res:name - e.g. res:ic_action_user, a file path (saved using the File plugin), or an http url
You should also be able to do this as a string literal:
local:MvxBind="ImageUrl ProfileThumbnailImageUrl; DefaultImagePath 'res:ic_action_user'"
Related
I am getting a response from JSON API where a "Video" tag contains a video or image name with its extension as shown below. I want to show video if that tag contains video (I am loading video in Web view) then hide Image view, or show image if it contains image then hide Web view.
Problem coming is that webview visibility is gone if the response postion has .mp4 and image view is visible but response image is not showing in Picasso.
Response:
[
{
"Video": "8100931.mp4"
},
{
"Video": "218519.jpeg",
}]
Layout:
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/llVideoPost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="visible">
<WebView
android:id="#+id/wvPostVideo"
android:layout_width="match_parent"
android:layout_height="0dp"
android:focusable="false"
android:screenReaderFocusable="false"
android:visibility="visible"
app:layout_constraintDimensionRatio="1:1"
tools:ignore="MissingConstraints" />
<ImageView
android:id="#+id/imgPostImage"
android:layout_width="match_parent"
android:layout_height="0dp"
android:contentDescription="#string/todo"
android:scaleType="fitXY"
android:visibility="gone"
app:layout_constraintDimensionRatio="1:1"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>
I tried this code
Code for calling response:
String videoTag= businessList.get(position).getVideo();
if (businessList.get(position).getVideo().endsWith(".mp4")) {
holder.wvPostVideo.setVisibility(View.VISIBLE);
holder.imgPostImage.setVisibility(View.GONE);
holder.wvPostVideo.loadUrl("https://smakerspace.s3.ap-south-1.amazonaws.com/Video/" + videoTag);
} else if (businessList.get(position).getVideo().endsWith(".jpeg")) {
holder.wvPostVideo.setVisibility(View.GONE);
holder.imgPostImage.setVisibility(View.VISIBLE);
Picasso.get()
.load("https://smakerspace.s3.ap-south-1.amazonaws.com/upload/"+videoTag)
.rotate(90)
.into(holder.imgPostImage);
}
replace https://smakerspace.s3.ap-south-1.amazonaws.com/upload/ with https://smakerspace.s3.ap-south-1.amazonaws.com/Video/
Becuase you have stored these image and video file into one db folder
And please use Videoview for video player its make eassy to play a video into android
Instead of passing url to picasso, can you please first try to download the image programmatically and then try to set to any ImageView.
Or you can use any rest clients to validate if APIs are working fine and returning valid image.
Once above is validated and found to be working fine, next step is to check if we got right instance of imgPostImage
I am receiving a base64 image from an api that is 192x192 in size. I am using the following code to change the base64 data into a Bitmap.
fun Base64ToBitmap(myImageData: String): Bitmap {
val imageAsBytes = Base64.decode(myImageData.toByteArray(), Base64.DEFAULT)
return BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.size)
}
Then I am using the following code to replace the previous contents of my ImageView.
ImageHeader.setImageBitmap(img)
The xml for that ImageHeader are as follows.
<ImageView
android:id="#+id/ImageHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:contentDescription="#string/ImageHeader1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/text_home"
app:srcCompat="#drawable/defaultpng" />
As expected this makes a very small image on the app. Is there anyway I can scale it's size x2 or x4 without having to create a larger image from my base php api? Sending extra data over the API seems like a waste.
You can use Glide to resize your bitmap, see below
Glide.with(requireActivity())
.override(THUMBNAIL_SIZE, THUMBNAIL_SIZE)
.load(yourBitmap)
.into(yourImageView)
I want to bind my ImageView control to my property URL (it's my image local path like this : /storage/emulated/0/MyFolder/IMG_20160411_094834.JPEG
I try to bind my control like this :
<ImageView
android:src="#android:drawable/ic_menu_gallery"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/ImagePreview"
local:MvxBind="ImageUrl ImagePath" />
ImagePath is my property but i can't use this method.
Can you help me ?
Thank you
You have to use Mvx.MvxImageView.
Changing ImageView to Mvx.MvxImageView should fix it.
Ensure, that you have installed the
File plugin (https://www.nuget.org/packages/MvvmCross.Plugin.File/)
DownloadCache plugin (https://www.nuget.org/packages/MvvmCross.Plugin.DownloadCache/)
in your android and core project.
I have a textview in a layout (called - t_c) with the code:-
<TextView
android:id="#+id/GoToTCContacting"
android:layout_width="360dp"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_weight="2"
android:background="#drawable/border2"
android:clickable="true"
android:onClick="GoToTCContacting"
android:padding="10dp"
android:text="Contacting"
android:textColor="#FFF"
android:textSize="18sp" />
I want the textview to open another layout (called - t_c_contacting) on click which has a webview in and that webview to open a html file I have in my layout folder called con.html.
This is how the t_c_contacting layout is coded:-
<WebView
android:id="#+id/contactingView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
This is how my class is set up to open t_c_contacting which works fine but I can't work out how to populate the webview with my file.
public void GoToTCContacting(View view)
{
setContentView(R.layout.t_c_contacting);
}
If you already have the HTML stored localy, simply call:
webView.loadDataWithBaseURL(mUrl, mHtmlData, MIME_TYPE, CHARSET, "");
Where:
mUrl can be a dummy Url if you want, or the actual URL of the page, so the WebView can figure out how to place some UI elements such as Images.
mHtmlData is a String that contains the actual HTML content.
MIME_TYPE is a String that represents the mimeType of the data, say: "text/html"
CHARSET is a String that represents the encoding of the data, say: "utf-8"
I hope that helps.
I have an xml file that specifies a set of image button names. Also, I would like to specify the image resource id as an attribute of an xml node as shown below:
<button name="close" resLocation="R.drawable.close" />
I am parsing the xml in the code, I would like to set the image background for the dynamically created button using the resLocation attribute. Since resLocation is a string, I cannot convert to a Drawable object directly. Is there a way I can workaround?
You can use get getResources().getIdentifier:
String myResourceId = "close"; // Parsed from XML in your case
getResources().getIdentifier(myResourceId, "drawable", "com.my.package.name");
This would require your XML to be a little different:
<button name="close" resLocation="close" />
If you need to keep the R.type.id format in your XML, then you would just need to parse out the type and id:
String myResourceId = "R.drawable.close";
String[] resourceParts = myResourceId.split("\\.");
getResources().getIdentifier(resourceParts[2], resourceParts[1], "com.my.package.name");
You can try
<button name="close" resLocation="#drawable/close" />
or try
ImageButton imgButton=new ImageButton(this);
imgButton.setImageResource(getResources().getDrawable(R.drawable.close));