Skip to content

Commit

Permalink
Added word UI support. Some optimizations on UI have to be done
Browse files Browse the repository at this point in the history
  • Loading branch information
louisld committed Dec 14, 2016
1 parent bc3e79a commit 90bc70d
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 63 deletions.
43 changes: 38 additions & 5 deletions app/src/main/java/fr/bloome/kanjidex/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package fr.bloome.kanjidex;

import android.content.Intent;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
Expand All @@ -18,6 +20,7 @@
import java.util.ArrayList;

import static android.icu.lang.UCharacter.GraphemeClusterBreak.L;
import static android.icu.lang.UCharacter.GraphemeClusterBreak.T;
import static android.icu.lang.UCharacter.GraphemeClusterBreak.V;

public class MainActivity extends AppCompatActivity {
Expand All @@ -26,6 +29,7 @@ public class MainActivity extends AppCompatActivity {
private TextView pNumber;
private TextView pHurigana;

@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -55,11 +59,35 @@ protected void onCreate(Bundle savedInstanceState) {
huriganaTmp += c + "\n";
}
pHurigana.setText(huriganaTmp);
fillGrades(1, kanji);
fillGrades(2, kanji);
fillGrades(3, kanji);

}

@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public void fillGrades(int grade, Kanji kanji){
WordDAO wDAO = new WordDAO(getApplicationContext());
wDAO.open();
ArrayList<Word> words = wDAO.getWordWithGrade(kanji.getNumber(), 1);
LinearLayout lLayout = (LinearLayout) findViewById(R.id.gradeOne);
ArrayList<Word> words = wDAO.getWordWithGrade(kanji.getNumber(), grade);
LinearLayout lLayout;
switch(grade)
{
case 1:
lLayout = (LinearLayout) findViewById(R.id.gradeOne);
break;
case 2:
lLayout = (LinearLayout) findViewById(R.id.gradeTwo);
break;
default:
lLayout = (LinearLayout) findViewById(R.id.gradeThree);
break;
}
if(words.size() == 0){
lLayout.setVisibility(View.GONE);
}
for(Word w : words){
String[] huriganasList = w.getKanji_hurigana().split("/");
LinearLayout lGlob = new LinearLayout(this);
LinearLayout lTmp = new LinearLayout(this);
lGlob.setOrientation(LinearLayout.HORIZONTAL);
Expand All @@ -68,23 +96,28 @@ protected void onCreate(Bundle savedInstanceState) {

TextView huriganas = new TextView(this);
TextView kanjis = new TextView(this);
TextView huriganas2 = new TextView(this);
TextView traduction = new TextView(this);

kanjis.setText(w.getKanjis());
kanjis.setTextSize(30.0f);
kanjis.setTextColor(ContextCompat.getColor(this, R.color.colorPrimaryDark));
huriganas.setText(w.getKanji_hurigana());
huriganas.setText(huriganasList[0]);
huriganas.setTextColor(ContextCompat.getColor(this, R.color.colorAccent));
if(huriganasList.length > 1)
huriganas2.setText(huriganasList[1]);
huriganas2.setTextColor(ContextCompat.getColor(this, R.color.colorAccent));
traduction.setText(w.getTraduction());
traduction.setTextSize(24.0f);
traduction.setTextSize(22.0f);
traduction.setGravity(Gravity.CENTER_HORIZONTAL);
traduction.setGravity(Gravity.CENTER_VERTICAL);

lTmp.addView(huriganas);
lTmp.addView(kanjis);
lTmp.setGravity(Gravity.CENTER_VERTICAL);
lTmp.setPaddingRelative(10, 5, 5, 5);
lTmp.setPaddingRelative(15, 5, 5, 5);
lGlob.addView(lTmp);
lGlob.addView(huriganas2);
lGlob.addView(traduction);
lLayout.addView(lGlob);
}
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/fr/bloome/kanjidex/WordDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,13 @@ public ArrayList<Word> getWordWithGrade(int kanjiNumber, int grade){
c.close();
return words;
}

public boolean isGrade(int kanjiNumber, int grade){
boolean result;
Cursor c = mDb.rawQuery("SELECT * FROM " + TABLE_NAME + " WHERE word_kanji_number=? AND word_grade=?", new String[]{String.valueOf(kanjiNumber), String.valueOf(grade)});
if(c.getCount() != 0)
return true;
else
return false;
}
}
169 changes: 112 additions & 57 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,75 +11,130 @@
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="fr.bloome.kanjidex.MainActivity">

<LinearLayout
android:orientation="vertical"
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
android:layout_height="match_parent">

<LinearLayout
android:orientation="horizontal"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">

<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/numberTextView"
android:textSize="36sp"
android:gravity="right|center_vertical"
android:textColor="@android:color/black"
android:text="N°\n0\n0\n1" />

<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/numberTextView"
android:textSize="36sp"
android:gravity="right|center_vertical"
android:textColor="@android:color/black"
android:text="N°\n0\n0\n1" />
<TextView
android:layout_width="wrap_content"
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"
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/huriganaTextView"
android:gravity="center_vertical|center_horizontal"
android:textSize="36sp"
android:textColor="@android:color/black"
android:text="に\nち" />

</LinearLayout>

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
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" />
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:background="@drawable/my_border"
android:paddingTop="0dp"
android:paddingLeft="0dp"
android:id="@+id/gradeOne">

<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/huriganaTextView"
android:gravity="center_vertical|center_horizontal"
android:textSize="36sp"
android:textColor="@android:color/black"
android:text="に\nち" />
<TextView
android:id="@+id/palier1Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryDark"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="@string/first_grade"
android:textSize="22sp"
android:textColor="@color/colorAccent"
android:paddingTop="5dp"
android:paddingBottom="5dp" />
</LinearLayout>

</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:background="@drawable/my_border"
android:paddingTop="0dp"
android:paddingLeft="0dp"
android:id="@+id/gradeTwo">

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:background="@drawable/my_border"
android:paddingTop="0dp"
android:paddingLeft="0dp"
android:id="@+id/gradeOne">
<TextView
android:id="@+id/palier2Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryDark"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="@string/second_grade"
android:textSize="22sp"
android:textColor="@color/colorAccent"
android:paddingTop="5dp"
android:paddingBottom="5dp" />
</LinearLayout>

<TextView
android:id="@+id/palier1Text"
android:layout_width="wrap_content"
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryDark"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="@string/first_grade"
android:textSize="22sp"
android:textColor="@color/colorAccent"
android:paddingTop="5dp"
android:paddingBottom="5dp" />
</LinearLayout>
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:background="@drawable/my_border"
android:paddingTop="0dp"
android:paddingLeft="0dp"
android:id="@+id/gradeThree">

<TextView
android:id="@+id/palier3Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryDark"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="@string/third_grade"
android:textSize="22sp"
android:textColor="@color/colorAccent"
android:paddingTop="5dp"
android:paddingBottom="5dp" />
</LinearLayout>

</LinearLayout>
</LinearLayout>
</ScrollView>

</RelativeLayout>
4 changes: 3 additions & 1 deletion app/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Kanjidex</string>
<string name="first_grade">First grade</string>
<string name="first_grade">Grade 1</string>
<string name="second_grade">Grade 2</string>
<string name="third_grade">Grade 3</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
<resources>
<string name="app_name">Kanjidex</string>
<string name="first_grade">Palier 1</string>
<string name="second_grade">Palier 2</string>
<string name="third_grade">Palier 3</string>
</resources>

0 comments on commit 90bc70d

Please sign in to comment.