Début ajout menu avec à propos et aide

This commit is contained in:
Jacques Foucry 2016-06-12 18:46:19 +02:00
parent 61b0f08d76
commit 4bd6c06c50
5 changed files with 90 additions and 0 deletions

View file

@ -0,0 +1,43 @@
package net.foucry.pilldroid;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Html;
import android.widget.TextView;
/**
* 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>";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about);
TextView htmlTextView = (TextView)findViewById(R.id.aboutHtml);
htmlTextView.setText(Html.fromHtml(htmlText, new ImageGetter(), null));
}
private class ImageGetter implements Html.ImageGetter {
public Drawable getDrawable(String source) {
int id;
if (source.equals("ic_launcher.png")) {
id = R.mipmap.ic_launcher;
} else {
return null;
}
Drawable d = getResources().getDrawable(id);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
return d;
}
}
}

View file

@ -11,6 +11,9 @@ import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
@ -147,6 +150,25 @@ public class MedicamentListActivity extends AppCompatActivity {
}
}
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.about, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.about:
startActivity(new Intent(this, About.class));
return true;
case R.id.help:
//startActivity(new Intent(this, Help.class));
return true;
}
return super.onOptionsItemSelected(item);
}
public void scanNow(View view) {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
//intent.putExtra("SCAN_MODE", "CODE_128");

View file

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/aboutTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/about"/>
<TextView
android:id="@+id/aboutHtml"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/about"
android:title="@string/about"/>
<item android:id="@+id/help"
android:title="@string/help"/>
</menu>

View file

@ -126,4 +126,6 @@
<string name="sbc_name">Google Book Search</string>
<string name="wifi_changing_network">Requesting connection to network\u2026</string>
<string name="msgNotFound">Médicament introuvable dans la base de données</string>
<string name="about">À propos</string>
<string name="help">Aide</string>
</resources>