Skip to content

Commit

Permalink
Added listener to list's items and a second activity for kanjis
Browse files Browse the repository at this point in the history
  • Loading branch information
louisld committed Dec 11, 2016
1 parent e3b89cd commit 1f9b237
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 19 deletions.
13 changes: 12 additions & 1 deletion app/src/main/java/fr/bloome/kanjidex/HomeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.database.Cursor;
import android.nfc.Tag;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
Expand All @@ -34,6 +37,7 @@ public class HomeActivity extends AppCompatActivity {

// URL to get contacts JSON
private static String url = "http://slyldcorp.esy.es";
public final static String NUMBER = "fr.bloome.kanjidex.intent.NUMBER";

ArrayList<HashMap<String, String>> kanjisList;
ArrayList<Kanji> kanjisList2;
Expand All @@ -46,6 +50,14 @@ protected void onCreate(Bundle savedInstanceState) {
kanjisList = new ArrayList<>();
kanjisList2 = new ArrayList<>();
mList = (ListView) findViewById(R.id.ListView);
mList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent = new Intent(HomeActivity.this, MainActivity.class);
intent.putExtra(NUMBER, i + 1);
startActivity(intent);
}
});
new GetKanjis().execute();

}
Expand Down Expand Up @@ -146,7 +158,6 @@ protected void onPostExecute(Void result) {
kDAO.open();
if(kanjisList2.size() > 0){
kDAO.clear();
Log.e(TAG, "\\o/");
}
for(Kanji k : kanjisList2){
kDAO.ajouter(k);
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/fr/bloome/kanjidex/KanjiDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,13 @@ public Cursor selectAll() {
return null;
}
}

public Kanji select(int number){
Log.e("Miaou", String.valueOf(number));
Cursor c = mDb.rawQuery("SELECT * FROM " + TABLE_NAME + " WHERE kanji_id=?", new String[]{String.valueOf(number)});
while(c.moveToNext()) {
return new Kanji(c.getInt(1), c.getString(3), c.getString(2), c.getInt(4));
}
return null;
}
}
29 changes: 29 additions & 0 deletions app/src/main/java/fr/bloome/kanjidex/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,42 @@
package fr.bloome.kanjidex;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import org.w3c.dom.Text;

public class MainActivity extends AppCompatActivity {

private TextView pKanji;
private TextView pNumber;
private TextView pHurigana;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

pKanji = (TextView) findViewById(R.id.kanjiTextView);
pHurigana = (TextView) findViewById(R.id.huriganaTextView);
pNumber = (TextView) findViewById(R.id.numberTextView);

Intent i = getIntent();
int number = i.getIntExtra(HomeActivity.NUMBER, 1);
Log.e("OUAF", String.valueOf(number));
KanjiDAO kDAO = new KanjiDAO(getApplicationContext());
kDAO.open();
Kanji kanji = kDAO.select(number);
kDAO.close();
pKanji.setText(kanji.getKanji());
if(kanji.getNumber() < 10){
pNumber.setText("N°\n0\n0\n" + kanji.getNumber());
}else if(kanji.getNumber() < 100){
pNumber.setText("N°\n0\n" + kanji.getNumber() / 10 + "\n" + kanji.getNumber() % 10);
}else{
pNumber.setText("N°\n" + kanji.getNumber() / 100 + "\n" + kanji.getNumber() / 10 % 10 + "\n" + kanji.getNumber() % 10);
}
}
}
4 changes: 4 additions & 0 deletions app/src/main/res/drawable/ic_action_refresh.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<vector android:height="24dp" android:viewportHeight="24.0"
android:viewportWidth="24.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#000000" android:pathData="M17.65,6.35C16.2,4.9 14.21,4 12,4c-4.42,0 -7.99,3.58 -7.99,8s3.57,8 7.99,8c3.73,0 6.84,-2.55 7.73,-6h-2.08c-0.82,2.33 -3.04,4 -5.65,4 -3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6c1.66,0 3.14,0.69 4.22,1.78L13,11h7V4l-2.35,2.35z"/>
</vector>
6 changes: 0 additions & 6 deletions app/src/main/res/drawable/kanji_1.xml

This file was deleted.

4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions"
android:text="漢字"
android:ems="10"
android:layout_below="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/editText"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
android:layout_alignParentEnd="true"
android:contentDescription="漢字" />

<ListView
android:layout_width="match_parent"
Expand Down
22 changes: 12 additions & 10 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,33 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/textView3"
android:id="@+id/numberTextView"
android:textSize="36sp"
android:gravity="right|center_vertical"
android:textColor="@android:color/black"
android:text="N°\n0\n0\n1" />

<ImageView
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:srcCompat="@drawable/kanji_1"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/imageView"
android:layout_weight="1" />
android:layout_height="wrap_content"
android:id="@+id/kanjiTextView"
android:layout_weight="1"
tools:text=""
android:textSize="170sp"
android:textColor="@android:color/black"
android:textAlignment="center"
android:gravity="center_vertical" />

<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/textView2"
android:id="@+id/huriganaTextView"
android:gravity="center_vertical|center_horizontal"
android:textSize="36sp"
android:textColor="@android:color/black"
android:text="に\nち" />
</LinearLayout>

</LinearLayout>

</RelativeLayout>
10 changes: 10 additions & 0 deletions app/src/main/res/menu/home_menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">

<item
android:id="@+id/menu_refresh"
android:icon="@drawable/ic_action_refresh"
app:showAsAction="ifRoom"
android:title="Refresh"/>
</menu>

0 comments on commit 1f9b237

Please sign in to comment.