From 1efe5fd245ead0e27664a10e79ca1ad6eddc07fb Mon Sep 17 00:00:00 2001 From: Jacques Foucry Date: Sun, 19 Jun 2016 00:57:40 +0200 Subject: [PATCH] =?UTF-8?q?Nouvelle=20fa=C3=A7on=20de=20lire=20et=20affich?= =?UTF-8?q?er=20about?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/about.html | 17 +++++++ .../main/java/net/foucry/pilldroid/About.java | 44 +++++++++++++++---- app/src/main/res/layout/about.xml | 2 +- app/src/main/res/values/strings.xml | 20 --------- 4 files changed, 54 insertions(+), 29 deletions(-) create mode 100644 app/src/main/assets/about.html diff --git a/app/src/main/assets/about.html b/app/src/main/assets/about.html new file mode 100644 index 0000000..757779c --- /dev/null +++ b/app/src/main/assets/about.html @@ -0,0 +1,17 @@ +

À propos de PillDroid

+

Gestion de stock de médicaments

+

This is some html. Look, here\'s an underline.

+

Look, this is emphasized. And here\'s some bold.

+

This is a UL list: +

+

This is an OL list: +

    +
  1. One
  2. +
  3. Two
  4. +
  5. Three
  6. +
+ \ No newline at end of file diff --git a/app/src/main/java/net/foucry/pilldroid/About.java b/app/src/main/java/net/foucry/pilldroid/About.java index 6a68da4..45b0987 100644 --- a/app/src/main/java/net/foucry/pilldroid/About.java +++ b/app/src/main/java/net/foucry/pilldroid/About.java @@ -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 = "" + - "

À propos de " + R.string.app_name + "

" + - "" + - ""; + 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; } diff --git a/app/src/main/res/layout/about.xml b/app/src/main/res/layout/about.xml index 234323c..54a2cca 100644 --- a/app/src/main/res/layout/about.xml +++ b/app/src/main/res/layout/about.xml @@ -3,7 +3,7 @@ android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9ee4201..d0c5ac7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -128,24 +128,4 @@ Médicament introuvable dans la base de données À propos Aide - - À propos de PillDroid -

Gestion de stock de médicaments

-

This is some html. Look, here\'s an underline.

-

Look, this is emphasized. And here\'s some bold.

-

This is a UL list: -

    -
  • One
  • -
  • Two
  • -
  • Three
  • -
-

This is an OL list: -

    -
  1. One
  2. -
  3. Two
  4. -
  5. Three
  6. -
- ]]> -