Nouvelle façon de lire et afficher about

This commit is contained in:
Jacques Foucry 2016-06-19 00:57:40 +02:00
parent 70db533060
commit 1efe5fd245
4 changed files with 54 additions and 29 deletions

View file

@ -0,0 +1,17 @@
<center><h1>À propos de PillDroid</h1>
<h2>Gestion de stock de médicaments</h2></center>
<p>This is some html. Look, here\'s an <u>underline</u>.</p>
<p>Look, this is <em>emphasized.</em> And here\'s some <b>bold</b>.</p>
<p>This is a UL list:
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
<p>This is an OL list:
<ol>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ol>
<img src="ic_laucnher.png"/>

View file

@ -2,31 +2,58 @@ package net.foucry.pilldroid;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v7.app.AppCompatActivity;
import android.text.Html;
import android.text.Spanned;
import android.util.Log;
import android.webkit.WebView;
import android.widget.TextView;
import java.io.IOException;
import java.io.InputStream;
/**
* Created by jacques on 12/06/16.
*/
public class About extends AppCompatActivity{
private final String htmlText = "<body>" +
"<h1>À propos de " + R.string.app_name + "</h1>" +
"<img src=\"ic_launcher.png\">" +
"</body>";
private WebView aboutView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about);
String htmlAsString = getString(R.string.html);
Spanned htmlAsSpanned = Html.fromHtml(htmlAsString);
String htmlString = null;
WebView webView = (WebView) findViewById(R.id.aboutHtml);
webView.loadDataWithBaseURL(null, htmlAsString, "text/html", "utf-8", null);
/* aboutView = (WebView) findViewById(R.id.aboutHtml);
aboutView.loadUrl("file:///android_asset/about.html");
aboutView.clearCache(true);
aboutView.clearHistory();
aboutView.getSettings().setJavaScriptEnabled(true);
aboutView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);*/
try {
InputStream is = getAssets().open("about.html");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
htmlString = new String(buffer);
} catch (IOException e) {
throw new RuntimeException(e);
}
TextView htmlTextView = (TextView)findViewById(R.id.aboutHtml);
htmlTextView.setText(Html.fromHtml(htmlString, new ImageGetter(), null));
Log.i("PillDroid", htmlTextView.getText().toString());
}
private class ImageGetter implements Html.ImageGetter {
@ -40,6 +67,7 @@ public class About extends AppCompatActivity{
}
Drawable d = getResources().getDrawable(id);
// Drawable d = ResourcesCompat.getDrawable(getResources(),id, null);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
return d;
}

View file

@ -3,7 +3,7 @@
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
<TextView
android:id="@+id/aboutHtml"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

View file

@ -128,24 +128,4 @@
<string name="msgNotFound">Médicament introuvable dans la base de données</string>
<string name="about">À propos</string>
<string name="help">Aide</string>
<string name="html">
<![CDATA[
<h1>À propos de PillDroid</h1>
<h2>Gestion de stock de médicaments</h2>
<p>This is some html. Look, here\'s an <u>underline</u>.</p>
<p>Look, this is <em>emphasized.</em> And here\'s some <b>bold</b>.</p>
<p>This is a UL list:
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
<p>This is an OL list:
<ol>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ol>
]]>
</string>
</resources>