From 5eb48ce9a1f839397637e8c33daec0893cd1e400 Mon Sep 17 00:00:00 2001 From: louisld Date: Sun, 11 Dec 2016 11:46:50 +0100 Subject: [PATCH] Bugs corrections --- app/src/main/AndroidManifest.xml | 4 +- .../java/fr/bloome/kanjidex/HomeActivity.java | 46 +++++++++++++++---- app/src/main/res/drawable/my_border.xml | 7 +++ app/src/main/res/layout/activity_home.xml | 4 +- app/src/main/res/layout/activity_main.xml | 25 ++++++++++ app/src/main/res/values-en/strings.xml | 5 ++ app/src/main/res/values/colors.xml | 2 +- app/src/main/res/values/strings.xml | 4 +- 8 files changed, 84 insertions(+), 13 deletions(-) create mode 100644 app/src/main/res/drawable/my_border.xml create mode 100644 app/src/main/res/values-en/strings.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e689a45..40a5f5e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -12,14 +12,14 @@ android:theme="@style/AppTheme"> - + - \ No newline at end of file diff --git a/app/src/main/java/fr/bloome/kanjidex/HomeActivity.java b/app/src/main/java/fr/bloome/kanjidex/HomeActivity.java index 2210337..01c2ffd 100644 --- a/app/src/main/java/fr/bloome/kanjidex/HomeActivity.java +++ b/app/src/main/java/fr/bloome/kanjidex/HomeActivity.java @@ -2,6 +2,7 @@ import android.app.Activity; import android.app.ProgressDialog; +import android.content.ClipData; import android.content.Intent; import android.database.Cursor; import android.nfc.Tag; @@ -9,6 +10,8 @@ import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.ListAdapter; @@ -58,9 +61,40 @@ public void onItemClick(AdapterView adapterView, View view, int i, long l) { startActivity(intent); } }); - new GetKanjis().execute(); + showKanjis(); + } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.home_menu, menu); + return true; } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle item selection + switch (item.getItemId()) { + case R.id.menu_refresh: + new GetKanjis().execute(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + public void showKanjis(){ + KanjiDAO kDAO = new KanjiDAO(getApplicationContext()); + kDAO.open(); + Cursor cursor = kDAO.selectAll(); + + SimpleCursorAdapter adapter = new SimpleCursorAdapter( + HomeActivity.this, + R.layout.list_item, cursor, new String[]{KanjiDAO.NUMBER, KanjiDAO.KANJI, KanjiDAO.HURIGANA}, new int[]{R.id.number_list_item, + R.id.kanji_list_item, R.id.hurigana_list_item}); + + mList.setAdapter(adapter); + } + private class GetKanjis extends AsyncTask { @Override @@ -84,6 +118,7 @@ protected Void doInBackground(Void... arg0) { Log.e(TAG, "Response from url: " + jsonStr); if (jsonStr != null) { + kanjisList2.clear(); try { JSONObject jsonObj = new JSONObject(jsonStr); @@ -99,19 +134,14 @@ protected Void doInBackground(Void... arg0) { String number = c.getString("kanji_number"); // tmp hash map for single contact - HashMap kanji = new HashMap<>(); Kanji kanji2 = new Kanji(); // adding each child node to HashMap key => value - kanji.put("kanji", kanji_kanji); - kanji.put("hurigana", hurigana); - kanji.put("number", number); kanji2.setKanji(kanji_kanji); kanji2.setHurigana(hurigana); kanji2.setNumber(Integer.parseInt(number)); // adding contact to contact list - kanjisList.add(kanji); kanjisList2.add(kanji2); } } catch (final JSONException e) { @@ -159,12 +189,12 @@ protected void onPostExecute(Void result) { if(kanjisList2.size() > 0){ kDAO.clear(); } - for(Kanji k : kanjisList2){ + for(Kanji k : kanjisList2) { kDAO.ajouter(k); Log.i(TAG, k.toString()); } - Cursor cursor = kDAO.selectAll(); + Cursor cursor = kDAO.selectAll(); SimpleCursorAdapter adapter = new SimpleCursorAdapter( HomeActivity.this, R.layout.list_item, cursor, new String[]{KanjiDAO.NUMBER, KanjiDAO.KANJI, KanjiDAO.HURIGANA}, new int[]{R.id.number_list_item, diff --git a/app/src/main/res/drawable/my_border.xml b/app/src/main/res/drawable/my_border.xml new file mode 100644 index 0000000..e7261ab --- /dev/null +++ b/app/src/main/res/drawable/my_border.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_home.xml b/app/src/main/res/layout/activity_home.xml index 24c5139..85d3307 100644 --- a/app/src/main/res/layout/activity_home.xml +++ b/app/src/main/res/layout/activity_home.xml @@ -31,7 +31,9 @@ android:id="@+id/editText" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" - android:contentDescription="漢字" /> + android:contentDescription="漢字" + android:selectAllOnFocus="true" + android:singleLine="false" /> + + + + + + diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml new file mode 100644 index 0000000..1db1caa --- /dev/null +++ b/app/src/main/res/values-en/strings.xml @@ -0,0 +1,5 @@ + + + Kanjidex + First grade + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index fbe1e87..8b2f660 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -1,6 +1,6 @@ #3f51b5 - #303F9F + #303f9f #ff4081 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7f786a6..b0a98e9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,5 @@ + Kanjidex - + Palier 1 + \ No newline at end of file