Text imported from realm DB not clickable - java

I'm helping to build an app which ask you a series of questions and returns the appropriate stone (geological app). The app also has an encyclopedia and a guide.
There are link to explanations in the guide when asking questions and these work fine.
The problem occurs when I want to use the links in the guide itself.
The guide uses a Realm DB for the info and puts it in an expandable list, while the questions use a string resource.
I want to be able to use the link in the text that I put in the Realm DB, but currently it just prints it as a normal string like so
".. ali več različnih mineralnih zrn , nekatere ..."
This is the same code that works fine in the questions section.
The code I use to "try" and convert the strings to links from the DB is bellow.
convertView = layoutInflater.inflate(R.layout.kamnina_item_second, null);
TextView opis = (TextView) convertView.findViewById(R.id.opis_kamnine);
String stone_opis_string = expandableListDetail.get("OPIS_POJMA").get(0);
opis.setText(stone_opis_string);
Linkify.addLinks(opis,Linkify.ALL);
opis.setMovementMethod(LinkMovementMethod.getInstance());

You could try:
String stone_opis_string = expandableListDetail.get("OPIS_POJMA").get(0);
opis.setText(Html.fromHtml(stone_opis_string));
// Linkify.addLinks(opis,Linkify.ALL);
opis.setMovementMethod(LinkMovementMethod.getInstance());

Related

Convert Android view to PDF of A4 size

I have an android resume building application. I want to generate a PDF of size A4 from my view. Here's how my layout looks like - At the top I have a Top App Bar, and the whole view in encapsulated in drawer. The main part which contains user's details is encapsulated in nestedScrollView, which contains multiple LinearLayout and TextView. In this screenshot below, I have populated it with mock data, but in actuality, I am fetching data from the Firebase Realtime Database and displaying it on the UI.
I tried to understand iTextPdf solution and multiple question of similar type that has been asked here, but I couldn't find something solid. Please help me out, it would be of great help.
Also, please don't close this question by giving a reason that the question doesn't contain any code. It doesn't because I don't have any. I am trying to solve this problem from scratch. I have tried to describe my problem as much as I could.
try this:
create a WebView and copy the text of your edittext in it:
webview.loadData(youredittext.gettext().tostring, "text/html", "UTF-8");
and convert webview to pdf by below function:
private void createWebPrintJob(WebView webView) {
PrintManager printManager = (PrintManager) this
.getSystemService(Context.PRINT_SERVICE);
PrintDocumentAdapter printAdapter =
webView.createPrintDocumentAdapter();
String jobName = getString(R.string.app_name) + " Print Test";
if (printManager != null) {
printManager.print(jobName, printAdapter,
new PrintAttributes.Builder().build());
}
}
after that user can select page size for example A4
There are a lot of libraries that convert layouts to PDF, but let's opt for popular one so we could find answers if we're stuck.
The libraries I listed works like so : They take screenshot of your layout as bitmap image and convert it to pdf.
- 1st solution: iTextPDF https://github.com/itext/itext7 (New Version).
check this detailed tutorial which treates also the case of taking screenshot of a scrollview https://www.codeproject.com/Articles/989236/How-to-Convert-Android-View-to-PDF-2
and this stackoverflow answer https://stackoverflow.com/a/29731275/12802591
- 2nd solution: PdfMyXML library https://github.com/HendrixString/Android-PdfMyXml just follow the steps in the documentation.
They may be other solutions, but these are the popular ones.
Let Me know if it works for you and also if you're stuck. Thank you!

Arabic data fetched from Microsoft SQL is not showing properly

I developed a web service using java which request from the database Arabic data.
I'm using this web service in android using volley.
The problem is when i get the data and set it in text field it's show some weird symbols (اÙÙÙسÙ).
The collation in database is : Arabic_CI_AS
I tried many solutions but nothing works!
I would really appreciate your help
This might be related to text direction attribute for the TextView, you have to set it to "anyRtl". Not sure which version that you are working on but this is available since 17+.
This above attribute can be set in one of the following ways:
From XML: Add this line: android:textDirection="anyRtl" to your
TextView tag.
From code:
textview.setTextDirection(View.TEXT_DIRECTION_ANY_RTL);
Haven't tried it though, hope this helps.
Few Links:
https://android.stackexchange.com/questions/25359/how-to-make-an-android-device-to-display-complex-rendering-of-indic-characters
Display Arabic text in android textview
https://developer.android.com/reference/android/text/TextDirectionHeuristics

How to add title and content after Facebook deprecation?

Here's some code that successfully shares a link to Facebook after a button click:
public void onClick(View view) {
if (ShareDialog.canShow(ShareLinkContent.class)) {
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle("A title")
.setContentDescription("Some description.")
.setContentUrl(Uri.parse("www.website.com"))
.build();
shareDialog.show(linkContent);
}
}
Using Android Studio, the ".setContentTitle" and ".setContentDescription" are deprecated, with a line through them. When I post the link, it is shared without the title and description. I assume this is because they are deprecated.
How could I add a title and description in? What were the deprecated terms replaced with? This isn't pre-filling a a post, and it wouldn't make sense for Facebook to get rid of these features completely. I have tried a few different links as the URL, none made a difference to this issue.
Many thanks in advance.
Edit: Please note that meta tags aren't an option, because if I were to link to an app in the Google Play Store, I can't control what tags the page has. I am looking to provide a title/description from the app, as was previously possible using the deprecated features mentioned.
I have found a suitable way around this, though not one that specifically replaces title and description. Another way to automatically add text to a post without pre-filling the user's text box is to use .setQuote().
For example with the code I provided above:
public void onClick(View view) {
if (ShareDialog.canShow(ShareLinkContent.class)) {
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setQuote("This may be used to replace setTitle and setDescription.")
.setContentUrl(Uri.parse("www.website.com"))
.build();
shareDialog.show(linkContent);
}
}
If anyone knows a way to replace the deprecated functions properly, without such a different alternative like the one I just provided, please post it and I'll mark it as solved.
Many thanks.
You can use ShareOpenGraphContent that uses ShareOpenGraphAction and ShareOpenGraphObject.
Look at the code I answered in this question.
https://stackoverflow.com/a/46459350/4107421
That way you can add a title, description and even an image to your post.
It works for ShareDialog.show() but unfortunately on my experience it doesn't on MessageDialog.show()

Google+ API - issue getting posts on business page

So I am using java API to get public posts from a google+ business page.
` String businessPageId = "104451189002914239318"; `
`List<Activity> activities = plus.activities().list(businessPageId, "public").execute().getItems(); // no activities returned `
Even though there are public posts, the above call does not return any posts.
I did discover that , getting the Person for that page as
`String personId = plus.people().get(businessPageId).execute().getId();`
and using personId instead of businessPageId gets the posts.
What does the above call represent.? is it the page owner.?
Can anyone shed light what's going on here.?
It's two pages that have been merged together. If you visit https://plus.google.com/104451189002914239318 you will see it redirect to https://plus.google.com/108277438040092360159. Use the second ID and you should be all set.

Display Images in TextView html

I state that I have already read all the other questions but none is right for me.My app retrieves data from a database. If I put in the database in the app does not display the image, while the other tag html yes because i put:
Text = (TextView) this.findViewById(R.article.text);
String formattedText = db.getText();
Text.setText(Html.fromHtml(formattedText));
For images I would like something that the download so that they are always available. I tried to put ImageGetter but with the loading time of an article in the app increased a lot and very often said that Android is not responding (ANR). I also need something that resizes images depending on the display. Any ideas?
Take a look at AQuery download the latest jar add it in your project
and use it like following
AQuerymAQuery;
mAquery=new AQuery(context);
mAquery.id(ImageView).auth(handle).image(ImagePath,true,true,400,0,null,0,0.0f);

Categories