From b52d49b04a5a09d263aec53f9ac0a490103c6cf3 Mon Sep 17 00:00:00 2001 From: Tony Mak Date: Sat, 7 May 2016 17:58:28 +0100 Subject: [PATCH] Add setting to toogle copy to lookup Fix #18 --- app/app.iml | 16 +++++------ .../SettingFragment.java | 25 +++++++++++++++--- .../service/ClipboardService.java | 14 +++++++++- .../res/drawable-hdpi/ic_settings_24dp.png | Bin 0 -> 612 bytes .../res/drawable-mdpi/ic_settings_24dp.png | Bin 0 -> 392 bytes .../res/drawable-xhdpi/ic_settings_24dp.png | Bin 0 -> 794 bytes .../res/drawable-xxhdpi/ic_settings_24dp.png | Bin 0 -> 1432 bytes app/src/main/res/menu/drawer_view.xml | 2 +- app/src/main/res/values-v21/styles.xml | 2 +- app/src/main/res/xml/settings.xml | 6 +++-- sqlite-assest-helper/sqlite-assest-helper.iml | 20 ++++++-------- 11 files changed, 56 insertions(+), 29 deletions(-) create mode 100644 app/src/main/res/drawable-hdpi/ic_settings_24dp.png create mode 100644 app/src/main/res/drawable-mdpi/ic_settings_24dp.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_settings_24dp.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_settings_24dp.png diff --git a/app/app.iml b/app/app.iml index 8b42d7f..6fd2904 100644 --- a/app/app.iml +++ b/app/app.iml @@ -64,14 +64,6 @@ - - - - - - - - @@ -80,6 +72,14 @@ + + + + + + + + diff --git a/app/src/main/java/com/madeinhk/english_chinesedictionary/SettingFragment.java b/app/src/main/java/com/madeinhk/english_chinesedictionary/SettingFragment.java index 1b128c4..2550343 100644 --- a/app/src/main/java/com/madeinhk/english_chinesedictionary/SettingFragment.java +++ b/app/src/main/java/com/madeinhk/english_chinesedictionary/SettingFragment.java @@ -1,14 +1,31 @@ package com.madeinhk.english_chinesedictionary; import android.os.Bundle; +import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceFragmentCompat; -/** - * Created by tonymak on 5/7/16. - */ -public class SettingFragment extends PreferenceFragmentCompat { +import com.madeinhk.english_chinesedictionary.service.ClipboardService; + +public class SettingFragment extends PreferenceFragmentCompat implements + Preference.OnPreferenceChangeListener { + public static final String KEY_COPY_TO_LOOKUP = "copy_lookup"; @Override public void onCreatePreferences(Bundle bundle, String s) { addPreferencesFromResource(R.xml.settings); + findPreference(KEY_COPY_TO_LOOKUP).setOnPreferenceChangeListener(this); + } + + @Override + public boolean onPreferenceChange(Preference preference, Object o) { + if (KEY_COPY_TO_LOOKUP.equals(preference.getKey())) { + boolean newValue = (boolean) o; + if (newValue) { + ClipboardService.start(getActivity()); + } else { + + } + return true; + } + return false; } } diff --git a/app/src/main/java/com/madeinhk/english_chinesedictionary/service/ClipboardService.java b/app/src/main/java/com/madeinhk/english_chinesedictionary/service/ClipboardService.java index d3cc423..049bd3e 100644 --- a/app/src/main/java/com/madeinhk/english_chinesedictionary/service/ClipboardService.java +++ b/app/src/main/java/com/madeinhk/english_chinesedictionary/service/ClipboardService.java @@ -7,11 +7,14 @@ import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.os.Build; import android.os.IBinder; +import android.support.v7.preference.PreferenceManager; import android.text.TextUtils; import android.util.Log; +import com.madeinhk.english_chinesedictionary.SettingFragment; import com.madeinhk.model.ECDictionary; import com.madeinhk.model.Word; import com.madeinhk.utils.Stemmer; @@ -40,7 +43,7 @@ public void onCreate() { } public static void start(Context context) { - context.startService(new Intent(context, ClipboardService.class)); + context.startService(new Intent(context.getApplicationContext(), ClipboardService.class)); } @Override @@ -59,6 +62,10 @@ public IBinder onBind(Intent intent) { new ClipboardManager.OnPrimaryClipChangedListener() { @Override public void onPrimaryClipChanged() { + if (!isFeatureEnabled()) { + return; + } + final ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); ClipData data = clipboard.getPrimaryClip(); @@ -135,4 +142,9 @@ public void onDestroy() { clipboardManager.removePrimaryClipChangedListener(mClipListener); } } + + private boolean isFeatureEnabled() { + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); + return preferences.getBoolean(SettingFragment.KEY_COPY_TO_LOOKUP, true); + } } diff --git a/app/src/main/res/drawable-hdpi/ic_settings_24dp.png b/app/src/main/res/drawable-hdpi/ic_settings_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..9fd31befb578ee37d0a8b1da5abaa0c54fd52990 GIT binary patch literal 612 zcmV-q0-ODbP)^fuQ0LR{=^9Dat7aVkE9W6*{gmY2XXuh9f0cD3Bt;-}0X1pvbZ}YuI(x z(vCE8Vy|c3jA!TAsVPgAELpN-$u3FJ`f15Z@AvT>+8j0aTEVNk@o{%!2@sbUCQufQRX9cXfpr`4#NP+0GE9a z_l~rHFBA$3FyJ{Z&_5XV;=1mlaswdvQaAV!Bd(N!_hbAsCXiP@);<1?^DcGOYPBtu z-fzZG{*G&%`JNk+?AHfZR3k$8Txo%V5w|kn`L&|t(5o^=P?z$8=cmw9a9^OjE|JMx zfdl%~p)-|ckd5}Bldh3ed#TD2qyrLe^ud3>GqaK29M+ zr`j~8l?aRZajgW~ZPn9OV$B@DU!=C3rVi>#?LY%QNNl9U-nix*%h3>EIgrU7JpUAg-c?U5r43%YeaK0JPM| zz`#HN$W8#Vr(+3$=^#0f8jxC$9w06QnL)PgK*Oxi;&}!ZpU=dn24n_VmOD5&Z~zVH zB4i;U3=EBKkXhu!a{vK@8-a8P2t(QU)CQ2_0COOoio?)|hK2?vm|76q(9kdfhvid2 zW|0*Q78Vu?K+PTKK1a43*%9a=0n!UHgQ9Ez^qD7`uR`#IS}2-YPm1&5fI7g;%uJEQ zC}^Tu6ae$H1+GL0N^t0j5GWo=)kFv^K>P`1Lr{=IaT9^^z<2lbZl7 zDJ_aYQAtr{1T>%&7{vKN!wjJnO+2p32r9=9QVXh#OifKoD5{J|sg6Nn1KJ<~;v{-D m$=tETz58fmbrg&OasUADKQ48Mv0&N&0000g|E=E#Ez~7W zW_GhP@ZR;y*K z*{_f_7dMkoUc?W zXK~%Z^`5TbBZ%0;yV`sg-^q6;g5@Xb;EVt$@KB-r&$Nb{ybC%!a$-DlH5A*Ql#v<8 z*@s+o5!6;(8-I+1727%eDqQcEF9cARIF7H`vcHHy-}++wF)!FmW}sYvXk5!UTRRL~ z@S;nM;1qu5cliBtMk4CD6VT~&Zh`G#N(En)N~P0^w0g#*U`lwvkh)n}1Mq?y7;xLv zcuf~Anvy_WVElC#X>dc=?Nu{B$`f>#19VtttL>x~7z_p{pv1BU0mj7&o?Fl$;3;+R zq0v#6y9{zEdW_3sX8wye4bixoAWgjv15b@1;J~L=_h8xynD`Pv2RP^b5?}yAN_>__ z5CmyDL2%hw5M&yJ@vn8$AXA%38srRXroj#CyT~krXp~{GvZ`AMaZAj!yrxdJHaDZR zr7%fQc>;ekHQstDj6tdy8x~f03(WJ3^b`g>u6bRzS9n6jN;`~!-uTuIGagO#h6o6_ zV*8-ug+~NDpXN=`@6NhG4E{hBl_zNAP_g#seLEO=j~H>EhZ%59TsC(z7`_W>{Oe$Z z*G>;cj*iCI3oyqY=Hb7JonEgu17#nZEEnDjgBSVihz;3@wF1eBXHhog{}!JQ7% z3k-7lVsHeQ{6PZV(hZIPlfTGVYiw-7^Ch0)apv5C{YUfgo4> Y0hT~>1XD_(_y7O^07*qoM6N<$g1EqE@&Et; literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxhdpi/ic_settings_24dp.png b/app/src/main/res/drawable-xxhdpi/ic_settings_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..3c04f5a2eb7639fce3baafb9f4cb54e704917462 GIT binary patch literal 1432 zcmV;J1!ww+P)4#{m;JBI&H%X(u{82;&ErxL{O_5&at5FD@7{l2O#m;*v=;`fukP zsFp{xLuz@Qs+V)%(oOeU>fZb6*4^s0wF!bC2!bF8f*=TjAP9mW2!bF8g0O<<>+9?6 z@9%#;Ffj1NhH%al&y@r{Fg-oJ7D7A^`fRHJbIt``Ly~kvtybFvL5|r9KSSfZh9v2T zo}QlVy}iA4R|UWf-5(wv-XTdkqEe~s!wh)pp@3(+h9v0-2=D-C##I4O-e0_iB0;g~o!9D5C)|KQxaW}L~}@!!GBd}d*Mhu`XhgM+8& zp=5>9+1a@f$J9WNam>d6=BJ^AkGSt6-1E1tuC5JPWpfN13y!_V7#o54nntMOzSehLF2DByBD0Us5tkLCq zE7@7n0-9g0cSVy#UXoKlxm-Tn?CDR5$OG4gq=ety-TedeFg`wfL<(2{-6l^dExZ*> z-MQ3-zsO`&k`O*U8RlRLB>b=Sg(Nbo@MKQ87Y;O*2jne@E(<2GFz6B5 zZ6BK-A{|U6WV4(u<6vDPxuhHeGB7^mn$zck8)_^V$7RPcyde+dCCQ8^rz;paZW|fX zouo$-a7K36x~S~ND3wZGg=p+zbPNIfXCVOk^xHyKxOdLewe0@is(nf3;fO86Xug zl0+)PcpL5PLJN@qV@laa2_chlOfZtSXiXARwB>TSgh5UQPDhWsD8bYOLZ_oAqfJMf zg3MG-1sSWYMl?I-$n?qDSvXN$DVdLS>VR3__sS1wKWm+ zG?{=5KJ#Fansb@Qf=fG)OeAcI^0$i8o{r~fEV-gQH)!PPmbQ>y!Non4Tr!T)BHdDp zp3AuwE~s-B^@%GXvX*HZ} z_Vg#)l9E{uzS*YAt_QlS@TvD^lUq1;z1h?IAoMm>UejEAeKvV$UI;?hd16rnJFK%TLjXkM)ajXAA++o{U*XV4+0(?*s6a+yK1VIo4 mK@bE%5ClOG1VIplmBjxUfETR-MF=ne0000 true true @android:color/transparent - + @style/PreferenceThemeOverlay \ No newline at end of file diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index a628f37..20164a8 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -1,8 +1,10 @@ - \ No newline at end of file diff --git a/sqlite-assest-helper/sqlite-assest-helper.iml b/sqlite-assest-helper/sqlite-assest-helper.iml index f98b2a0..a931c3a 100644 --- a/sqlite-assest-helper/sqlite-assest-helper.iml +++ b/sqlite-assest-helper/sqlite-assest-helper.iml @@ -65,14 +65,6 @@ - - - - - - - - @@ -81,8 +73,14 @@ - - + + + + + + + + @@ -90,10 +88,8 @@ - -