Add radical size preference
CHANGELOG.md
| 4 | 4 | Changes Since 0.2 | |
| 5 | 5 | ----------------- | |
| 6 | 6 | ||
| 7 | + | ### Features | |
| 8 | + | ||
| 9 | + | * New settings: radical size | |
| 10 | + | ||
| 7 | 11 | ### Bug Fixes | |
| 8 | 12 | ||
| 9 | 13 | * Show dictionary sizes in appropriate unit, to prevent showing 0MB on | |
… | |||
| 13 | 17 | ||
| 14 | 18 | ### Translations | |
| 15 | 19 | ||
| 16 | - | * Updat efr translation | |
| 20 | + | * Update fr translation | |
| 17 | 21 | ||
| 18 | - | Changes Since 0.1 | |
| 22 | + | Changes In 0.2 | |
| 19 | 23 | ----------------- | |
| 20 | 24 | ||
| 21 | 25 | ### Features | |
app/build.gradle
| 21 | 21 | dependencies { | |
| 22 | 22 | implementation fileTree(dir: 'libs', include: ['*.jar']) | |
| 23 | 23 | implementation 'androidx.appcompat:appcompat:1.1.0' | |
| 24 | + | implementation 'androidx.preference:preference:1.1.1' | |
| 24 | 25 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' | |
| 25 | 26 | implementation 'com.google.android.material:material:1.1.0' | |
| 26 | 27 | implementation 'com.andree-surya:moji4j:1.0.0' | |
| 27 | 28 | implementation 'com.google.android:flexbox:2.0.1' | |
| 28 | 29 | implementation project(path: ':furiganatextview') | |
| 30 | + | implementation 'androidx.legacy:legacy-support-v4:1.0.0' | |
| 29 | 31 | testImplementation 'junit:junit:4.12' | |
| 30 | 32 | androidTestImplementation 'androidx.test.ext:junit:1.1.1' | |
| 31 | 33 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' |
app/src/main/AndroidManifest.xml
| 2 | 2 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
| 3 | 3 | package="eu.lepiller.nani"> | |
| 4 | 4 | ||
| 5 | + | <uses-permission android:name="android.permission.INTERNET" /> | |
| 6 | + | ||
| 5 | 7 | <application | |
| 6 | 8 | android:allowBackup="true" | |
| 7 | 9 | android:icon="@mipmap/ic_launcher" | |
… | |||
| 9 | 11 | android:roundIcon="@mipmap/ic_launcher_round" | |
| 10 | 12 | android:supportsRtl="true" | |
| 11 | 13 | android:theme="@style/AppTheme"> | |
| 12 | - | <activity android:name=".DictionaryDownloadActivity"></activity> | |
| 14 | + | <activity android:name=".SettingsActivity"></activity> | |
| 15 | + | <activity android:name=".DictionaryDownloadActivity" /> | |
| 13 | 16 | <activity android:name=".AboutActivity" /> | |
| 14 | 17 | <activity | |
| 15 | 18 | android:name=".DictionaryActivity" | |
… | |||
| 27 | 30 | </activity> | |
| 28 | 31 | </application> | |
| 29 | 32 | ||
| 30 | - | <uses-permission android:name="android.permission.INTERNET" /> | |
| 31 | - | ||
| 32 | 33 | </manifest> | |
| 32 | 33 | = | |
| 33 | 34 | = | \ No newline at end of file |
app/src/main/java/eu/lepiller/nani/MainActivity.java
| 3 | 3 | import android.app.NotificationChannel; | |
| 4 | 4 | import android.app.NotificationManager; | |
| 5 | 5 | import android.content.Intent; | |
| 6 | + | import android.content.SharedPreferences; | |
| 6 | 7 | import android.os.AsyncTask; | |
| 7 | 8 | import android.os.Bundle; | |
| 8 | 9 | import com.google.android.material.snackbar.Snackbar; | |
| 9 | 10 | import androidx.appcompat.app.AppCompatActivity; | |
| 10 | 11 | import androidx.appcompat.widget.Toolbar; | |
| 12 | + | import androidx.preference.PreferenceManager; | |
| 13 | + | ||
| 11 | 14 | import android.view.View; | |
| 12 | 15 | import android.view.Menu; | |
| 13 | 16 | import android.view.MenuItem; | |
… | |||
| 28 | 31 | import eu.lepiller.nani.result.Result; | |
| 29 | 32 | import se.fekete.furiganatextview.furiganaview.FuriganaTextView; | |
| 30 | 33 | ||
| 31 | - | public class MainActivity extends AppCompatActivity implements OnTaskCompleted<SearchResult> { | |
| 34 | + | public class MainActivity extends AppCompatActivity implements OnTaskCompleted<SearchResult>, SharedPreferences.OnSharedPreferenceChangeListener { | |
| 32 | 35 | private LinearLayout result_view, result_layout; | |
| 33 | 36 | private Button search_button; | |
| 34 | 37 | private TextView feedback_text; | |
… | |||
| 60 | 63 | manager.createNotificationChannel(channel); | |
| 61 | 64 | } | |
| 62 | 65 | ||
| 66 | + | PreferenceManager.setDefaultValues(this, R.xml.preferences, false); | |
| 67 | + | ||
| 68 | + | SharedPreferences sharedPref = | |
| 69 | + | PreferenceManager.getDefaultSharedPreferences(this); | |
| 70 | + | sharedPref.registerOnSharedPreferenceChangeListener(this); | |
| 71 | + | int radSizePref = Integer.parseInt(sharedPref.getString | |
| 72 | + | (SettingsActivity.KEY_PREF_RAD_SIZE, "122")); | |
| 73 | + | ||
| 63 | 74 | try { | |
| 75 | + | radical_selector.setRadSize(radSizePref); | |
| 64 | 76 | radical_selector.setDictionary(DictionaryFactory.getRadicalDictionary(getApplicationContext())); | |
| 65 | 77 | } catch (NoDictionaryException e) { | |
| 66 | 78 | e.printStackTrace(); | |
… | |||
| 121 | 133 | } | |
| 122 | 134 | } | |
| 123 | 135 | ||
| 136 | + | @Override | |
| 137 | + | public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { | |
| 138 | + | if(key.compareTo(SettingsActivity.KEY_PREF_RAD_SIZE) == 0) { | |
| 139 | + | int radSizePref = Integer.parseInt(sharedPreferences.getString | |
| 140 | + | (SettingsActivity.KEY_PREF_RAD_SIZE, "122")); | |
| 141 | + | radical_selector.setRadSize(radSizePref); | |
| 142 | + | } | |
| 143 | + | } | |
| 144 | + | ||
| 124 | 145 | private static class SearchTask extends AsyncTask<String, Integer, SearchResult> { | |
| 125 | 146 | OnTaskCompleted<SearchResult> callback; | |
| 126 | 147 | SearchTask(OnTaskCompleted<SearchResult> callback) { | |
… | |||
| 274 | 295 | ||
| 275 | 296 | //noinspection SimplifiableIfStatement | |
| 276 | 297 | if (id == R.id.action_settings) { | |
| 298 | + | Intent intent = new Intent(this, SettingsActivity.class); | |
| 299 | + | startActivity(intent); | |
| 277 | 300 | return true; | |
| 278 | 301 | } else if (id == R.id.action_dictionaries) { | |
| 279 | 302 | Intent intent = new Intent(this, DictionaryActivity.class); | |
app/src/main/java/eu/lepiller/nani/RadicalSelectorView.java
| 1 | 1 | package eu.lepiller.nani; | |
| 2 | 2 | ||
| 3 | 3 | import android.content.Context; | |
| 4 | + | import android.content.SharedPreferences; | |
| 4 | 5 | import android.os.AsyncTask; | |
| 5 | 6 | import android.os.Build; | |
| 6 | 7 | import android.util.AttributeSet; | |
… | |||
| 32 | 33 | final List<String> selected = new ArrayList<>(); | |
| 33 | 34 | View.OnClickListener kanjiSelectionListener; | |
| 34 | 35 | RadicalDict dictionary; | |
| 36 | + | private int radSize = 122; | |
| 35 | 37 | ||
| 36 | 38 | public RadicalSelectorView(Context context) { | |
| 37 | 39 | this(context, null, 0); | |
… | |||
| 63 | 65 | new DictionaryUpdateTask(this).execute(dict); | |
| 64 | 66 | } | |
| 65 | 67 | ||
| 68 | + | public void setRadSize(int size) { | |
| 69 | + | radSize = size; | |
| 70 | + | resizeRadicals(); | |
| 71 | + | } | |
| 72 | + | ||
| 73 | + | public float getRadFontSize() { | |
| 74 | + | return radSize / 8; | |
| 75 | + | } | |
| 76 | + | ||
| 66 | 77 | @Override | |
| 67 | 78 | public void onTaskCompleted(Map<Integer, List<String>> radicals) { | |
| 68 | 79 | if(radicals == null) | |
… | |||
| 82 | 93 | radicalButton.setTextOff(radical); | |
| 83 | 94 | radicalButton.setTextOn(radical); | |
| 84 | 95 | radicalButton.setText(radical); | |
| 85 | - | radicalButton.setLayoutParams(new FlexboxLayout.LayoutParams(122, 122)); | |
| 96 | + | radicalButton.setTextSize(getRadFontSize()); | |
| 97 | + | radicalButton.setLayoutParams(new FlexboxLayout.LayoutParams(radSize, radSize)); | |
| 86 | 98 | ||
| 87 | 99 | radicalButton.setOnClickListener(new OnClickListener() { | |
| 88 | 100 | @Override | |
… | |||
| 210 | 222 | Button kanji_button = new Button(getContext()); | |
| 211 | 223 | kanji_button.setText(k); | |
| 212 | 224 | kanji_button.setOnClickListener(kanjiSelectionListener); | |
| 213 | - | kanji_button.setLayoutParams(new LayoutParams(122, 122)); | |
| 225 | + | kanji_button.setLayoutParams(new LayoutParams(radSize, radSize)); | |
| 226 | + | kanji_button.setTextSize(getRadFontSize()); | |
| 214 | 227 | row.addView(kanji_button); | |
| 215 | 228 | ||
| 216 | 229 | if (number > total / 2) | |
… | |||
| 233 | 246 | } | |
| 234 | 247 | } | |
| 235 | 248 | } | |
| 249 | + | ||
| 250 | + | private void resizeRadicals() { | |
| 251 | + | for(int row=0; row < radical_table.getChildCount(); row++) { | |
| 252 | + | View r = radical_table.getChildAt(row); | |
| 253 | + | if(r instanceof FlexboxLayout) { | |
| 254 | + | for(int col = 0; col < ((FlexboxLayout) r).getChildCount(); col++) { | |
| 255 | + | View child = ((FlexboxLayout) r).getChildAt(col); | |
| 256 | + | if(child instanceof ToggleButton) { | |
| 257 | + | child.setLayoutParams(new FlexboxLayout.LayoutParams(radSize, radSize)); | |
| 258 | + | ((ToggleButton)child).setTextSize(getRadFontSize()); | |
| 259 | + | } | |
| 260 | + | } | |
| 261 | + | } | |
| 262 | + | } | |
| 263 | + | for(int kanji = 0; kanji < kanji_row1.getChildCount(); kanji++) { | |
| 264 | + | View k = kanji_row1.getChildAt(kanji); | |
| 265 | + | if(k instanceof Button) { | |
| 266 | + | ((Button) k).setTextSize(getRadFontSize()); | |
| 267 | + | k.setLayoutParams(new LayoutParams(radSize, radSize)); | |
| 268 | + | } | |
| 269 | + | } | |
| 270 | + | for(int kanji = 0; kanji < kanji_row2.getChildCount(); kanji++) { | |
| 271 | + | View k = kanji_row2.getChildAt(kanji); | |
| 272 | + | if(k instanceof Button) { | |
| 273 | + | ((Button) k).setTextSize(getRadFontSize()); | |
| 274 | + | k.setLayoutParams(new LayoutParams(radSize, radSize)); | |
| 275 | + | } | |
| 276 | + | } | |
| 277 | + | } | |
| 236 | 278 | } | |
app/src/main/java/eu/lepiller/nani/SettingsActivity.java unknown status 1
| 1 | + | package eu.lepiller.nani; | |
| 2 | + | ||
| 3 | + | import androidx.appcompat.app.AppCompatActivity; | |
| 4 | + | ||
| 5 | + | import android.os.Bundle; | |
| 6 | + | ||
| 7 | + | public class SettingsActivity extends AppCompatActivity { | |
| 8 | + | public static final String KEY_PREF_RAD_SIZE = "rad_size"; | |
| 9 | + | ||
| 10 | + | @Override | |
| 11 | + | protected void onCreate(Bundle savedInstanceState) { | |
| 12 | + | super.onCreate(savedInstanceState); | |
| 13 | + | getSupportFragmentManager().beginTransaction() | |
| 14 | + | .replace(android.R.id.content, new SettingsFragment()) | |
| 15 | + | .commit(); | |
| 16 | + | } | |
| 17 | + | } |
app/src/main/java/eu/lepiller/nani/SettingsFragment.java unknown status 1
| 1 | + | package eu.lepiller.nani; | |
| 2 | + | ||
| 3 | + | import android.os.Bundle; | |
| 4 | + | ||
| 5 | + | import androidx.fragment.app.Fragment; | |
| 6 | + | import androidx.preference.PreferenceFragmentCompat; | |
| 7 | + | ||
| 8 | + | import android.view.LayoutInflater; | |
| 9 | + | import android.view.View; | |
| 10 | + | import android.view.ViewGroup; | |
| 11 | + | import android.widget.TextView; | |
| 12 | + | ||
| 13 | + | /** | |
| 14 | + | * A simple {@link Fragment} subclass. | |
| 15 | + | */ | |
| 16 | + | public class SettingsFragment extends PreferenceFragmentCompat { | |
| 17 | + | @Override | |
| 18 | + | public void onCreatePreferences(Bundle savedInstanceState, | |
| 19 | + | String rootKey) { | |
| 20 | + | setPreferencesFromResource(R.xml.preferences, rootKey); | |
| 21 | + | } | |
| 22 | + | } |
app/src/main/res/drawable/ic_rad.xml unknown status 1
| 1 | + | <vector android:height="32dp" android:viewportHeight="14" | |
| 2 | + | android:viewportWidth="14" android:width="32dp" xmlns:android="http://schemas.android.com/apk/res/android"> | |
| 3 | + | <path android:fillColor="#e6e6e6" | |
| 4 | + | android:pathData="M7,7m-7,0a7,7 0,1 1,14 0a7,7 0,1 1,-14 0" android:strokeWidth="0.26458332"/> | |
| 5 | + | <path android:fillAlpha="1" android:fillColor="#1a1a1a" | |
| 6 | + | android:pathData="m4.2555,2.9731c0.7303,0.3704 1.6616,0.9419 2.1272,1.3335l0.4974,-0.6456c-0.4868,-0.381 -1.4393,-0.9208 -2.1484,-1.2488zM3.3453,5.8094c0.7726,0.3281 1.778,0.8572 2.286,1.2277l0.4551,-0.6668c-0.5186,-0.381 -1.5452,-0.8678 -2.2966,-1.1536zM4.0544,11.2492 L4.7105,11.9054c0.7937,-1.0477 1.7463,-2.4448 2.4871,-3.6195l-0.5503,-0.6244c-0.8149,1.2806 -1.8838,2.7517 -2.5929,3.5877z" | |
| 7 | + | android:strokeColor="#00000000" android:strokeWidth="0.26458332"/> | |
| 8 | + | </vector> |
app/src/main/res/values-fr/strings.xml
| 30 | 30 | <string name="feedback_progress">Recherche???</string> | |
| 31 | 31 | <string name="feedback_didyoumean">Vouliez-vous dire ?? %s ?? ?</string> | |
| 32 | 32 | ||
| 33 | + | <!-- Preferences --> | |
| 34 | + | <string name="pref_rad_size">Taille des radicaux</string> | |
| 35 | + | <string-array name="pref_rad_size_choice"> | |
| 36 | + | <item>plus gros</item> | |
| 37 | + | <item>normale</item> | |
| 38 | + | <item>plus petit</item> | |
| 39 | + | </string-array> | |
| 40 | + | ||
| 33 | 41 | <!-- Dictionnary descriptions --> | |
| 34 | 42 | ||
| 35 | 43 | <string name="dico_jmdict_e">Dictionnaire japonais/anglais de l???Electronic Dictionary Research and Development Group.\n~56???Mo, ~180???000 entr??es.</string> |
app/src/main/res/values/strings.xml
| 26 | 26 | <string name="feedback_progress">Searching???</string> | |
| 27 | 27 | <string name="feedback_didyoumean">Did you mean "%s"?</string> | |
| 28 | 28 | ||
| 29 | + | <!-- Preferences --> | |
| 30 | + | <string name="pref_rad_size">Radicals Size</string> | |
| 31 | + | <string-array name="pref_rad_size_choice"> | |
| 32 | + | <item>bigger</item> | |
| 33 | + | <item>normal</item> | |
| 34 | + | <item>smaller</item> | |
| 35 | + | </string-array> | |
| 36 | + | <string-array name="pref_rad_size_values" translatable="false"> | |
| 37 | + | <item>158</item> | |
| 38 | + | <item>122</item> | |
| 39 | + | <item>96</item> | |
| 40 | + | </string-array> | |
| 41 | + | ||
| 29 | 42 | <!-- Dictionnary descriptions --> | |
| 30 | 43 | <string name="dico_jmdict_e">Japanese/English dictionary from the Electronic Dictionary Research and Development Group.\n~56 MB, ~180,000 entries.</string> | |
| 31 | 44 | <string name="dico_jmdict_dut">Japanese/Dutch dictionary from the Electronic Dictionary Research and Development Group.\n~19 MB, ~35,000 entries.</string> | |
… | |||
| 79 | 92 | </string> | |
| 80 | 93 | <string name="data_licenses">Data Licenses</string> | |
| 81 | 94 | <string name="data_intro">Nani? uses data from third party distributed under different licenses.</string> | |
| 82 | - | ||
| 95 | + | ||
| 83 | 96 | <string name="erdrg_title">Electronic Dictionary Research and Development Group</string> | |
| 84 | 97 | <string name="erdrg_descr">The Electronic Dictionary Research and Development Group was | |
| 85 | 98 | established in 2000 within the Faculty of Information Technology, Monash University. | |
… | |||
| 105 | 118 | covers the 13,108 kanji in three main Japanese standards. | |
| 106 | 119 | </string> | |
| 107 | 120 | <string name="kanjidic_license">This source is licensed under Creative Commons Share-Alike.</string> | |
| 121 | + | ||
| 122 | + | <!-- TODO: Remove or change this placeholder text --> | |
| 123 | + | <string name="hello_blank_fragment">Hello blank fragment</string> | |
| 108 | 124 | </resources> | |
app/src/main/res/values/styles.xml
| 6 | 6 | <item name="colorPrimary">@color/colorPrimary</item> | |
| 7 | 7 | <item name="colorPrimaryDark">@color/colorPrimaryDark</item> | |
| 8 | 8 | <item name="colorAccent">@color/colorAccent</item> | |
| 9 | + | <item name="preferenceTheme">@style/PreferenceThemeOverlay</item> | |
| 9 | 10 | </style> | |
| 10 | 11 | ||
| 11 | 12 | <style name="AppTheme.NoActionBar"> |
app/src/main/res/xml/preferences.xml unknown status 1
| 1 | + | <?xml version="1.0" encoding="utf-8"?> | |
| 2 | + | <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> | |
| 3 | + | <ListPreference | |
| 4 | + | android:entries="@array/pref_rad_size_choice" | |
| 5 | + | android:entryValues="@array/pref_rad_size_values" | |
| 6 | + | android:key="rad_size" | |
| 7 | + | android:title="@string/pref_rad_size" | |
| 8 | + | android:defaultValue="66" | |
| 9 | + | android:icon="@drawable/ic_rad"/> | |
| 10 | + | </PreferenceScreen> | |
| 10 | < | ||
| 0 | 11 | < | \ No newline at end of file |