How to display multiple images from a site in recyclerview kotlin - android

I want to display images like this :
This site has well over 200 apps and i am trying to show their apps in my recycler view. I don't want to save them one by one but i couldn't find any documentation on how to pull image data from URL in Kotlin.
data class PostModel(
val role : String = "listitem",
val clazz : String = "Zc7IjY"
)
I tried getting their id numbers but failed.
I want to access the url below inside my main url. But not just for one image, i want to access it for all of the images.
#font-face {
font-display: block;
font-family: 'Montserrat';
font-style: italic;
font-weight: 400;
src: local('Montserrat Italic'), local('Montserrat-Italic'),
url("//static.parastorage.com/tag-bundler/api/v1/fonts-cache/googlefont/woff2/s/montserrat/v14/JTUQjIg1_i6t8kCHKm459WxRzS7m0dR9pBOi.woff2") format('woff2');
unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

The easiest way to do it is using a library like Picasso or Glide.
If you want to do it on your own you will have to decode the image yourself then transform it into a object that is accepted by an ImageView, you can refer to this other question https://stackoverflow.com/a/25463200/4632435

Related

Assign font family to text using HTML string in to TextView or load into WebView

My need is to set HTML string into TextView but the problem is the <p style=\"text-align:center\"><span style=\"font-family:montserrat\"><span style=\"color:#660099\"><strong>Hello World</strong></span></span></p>\r\n
That font-family:montserrat is not applied to Text.
Note: I tried to load this HTML string using WebView but there is also same problem is raising.
Please suggest a workaround.
Thanks
Add your font file to your android project, in your case:
montserrat.tff
Define like this in your html string:
#font-face { font-family: montserrat; src: url('fonts/montserrat.ttf'); }
Then try like this:
yourWebView.loadDataWithBaseURL("file:///android_asset/",htmlString,"text/html","utf-8",null);

Injecting css for Webview with custom font

I have working with webview in which i want to inject css to webview that i have achieved with the following link.
But if i want to add custom font to css i have using the following code
#font-face {
font-family: 'avenir_next'; /*a name to be used later*/
src: url('OTF_FILE_LINK'); /*URL to font*/
}
body {
font-family: avenir_next;
}
I need to know that its is possible to load otf file from the Android Asset folder insted of using 'OTF_FILE_LINK'.

How to refer to files in asset folder from outside html

This problem seems familiar but it's not! I have a webpage on a web server and a webview in Android application that loads the webpage. And instead of loading some font from the Internet (or website), i want to load fonts directly from asset folder of Android device (to save data and faster). What i have done is to embed this code in the website with the hope it can use the font in Android asset folder instead:
#font-face {
font-family: 'DejaVuSans';
src: url('file:///android_asset/fonts/DejaVuSans.ttf'); /* but this does not work*/
}
body {
font-family: 'DejaVuSans';
color: red;
}
(link Change WebView font using CSS; font file in asset folder. (problem))
I currently test with android 4.+. Can anyone have the solution? Thanks
file: urls retrieve files from within one's own computer. For websites you should use relative or absolute urls. Here's a relative url example:
src: url('android_asset/fonts/DejaVuSans.ttf');
Here's a absolute url example:
src: url('http://www.example.com/android_asset/fonts/DejaVuSans.ttf');

Android - local image in online page

I am working on a fullscreen webapp to androidPage Not Found We couldn't find the page you requested. I have everything done but can I possible add all the images offline in the app and the html online?
I am using:We did, webView.loadUrl("http://site.com/Sd34DsX.html");
And I wonder if i could host the images in the HTML file like this:
#fotball
background-image: url('file:///android_asset/fotball.png');
background-repeat:no-repeat;
float: left;
position:fixed
almost, but no, because you can't write to the asset folder from within the app. you only use that to store resources which your app will use after compiling.
what you can do is get the entire HTML as a string, and do a string search for all of the image paths. You can then retrieve those images in their own http requests, and save them to a folder in external storage.
you can then modify your html string to replace all of the image paths with local paths.
your webview can use string data as a webpage.
Instead of:
background-image: url('file:///android_asset/fotball.png');
try a data url, which has no cross-domain restriction:
background-image: url('data:image/format;base64,IMAGEDATA');

Access CSS fonts from Android 'Assets' folder

I'm trying to change the font of web pages loaded in to a Browser app developed for Android. Currently my custom font is hosted in a URL & I access the font from there by injecting a JavaScript to the page to change the style sheet (CSS) font face.
Here is the current code:
var css = '#font-face {font-family: "dhanika"; src: url(http://www.sample.lk/DhanikaWeb.ttf);} si {font-family: "dhanika"}';
var style = document.getElementsByTagName("style")[0];
style.appendChild(document.createTextNode(css));
This code works perfectly. But it takes some time to load the font from the URL. And also it is not good to load the font each time since it may incur data charges.
Therefore I wanna know weather there is a method to access my custom font from the JavaScript, if I place my font in my app's 'Assets' folder. Glad if anyone can provide the code.
Any help is appreciated!
From what I know about Android and #font-face, Android currently chokes on the local() declaration. The best method for using #font-face with all browsers is to use double declarations. Example
#font-face { font-family:'fontName'; src:url('fontName.eot'); font-weight:normal; font-style:normal; }
#font-face { font-family:'fontName'; src:url(//:) format('no404'), url('fontName.woff') format('woff'), url('fontName.ttf') format('truetype'), url('fontName.svg') format('svg'); font-weight:normal; font-style:normal; }
The Easiest way to do this is to use FontSquirrel's #font-face generator

Categories

Resources