From dac257ac3f5541d968e735968670eb46a813cf72 Mon Sep 17 00:00:00 2001 From: Kazuki Yamaguchi Date: Wed, 7 Dec 2016 22:27:26 +0900 Subject: bye-byte morse --- .../java/net/lacolaco/smileessence/util/Morse.java | 108 --------------------- .../smileessence/viewmodel/StatusViewModel.java | 10 +- app/src/main/res/values/keys.xml | 1 - app/src/main/res/values/strings.xml | 1 - app/src/main/res/xml/setting.xml | 4 - 5 files changed, 1 insertion(+), 123 deletions(-) delete mode 100644 app/src/main/java/net/lacolaco/smileessence/util/Morse.java diff --git a/app/src/main/java/net/lacolaco/smileessence/util/Morse.java b/app/src/main/java/net/lacolaco/smileessence/util/Morse.java deleted file mode 100644 index 3c4f63a2..00000000 --- a/app/src/main/java/net/lacolaco/smileessence/util/Morse.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2012-2014 lacolaco.net - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package net.lacolaco.smileessence.util; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class Morse { - - // ------------------------------ FIELDS ------------------------------ - - private static final HashMap mcJa; - private static final Pattern morsePattern = Pattern.compile("[-・]+"); - - // -------------------------- STATIC METHODS -------------------------- - - /** - * 与えられた文字列がモールス文を含むかどうかを返す - * - * @param mc 判定する文字列 - * @return モールスを含むならtrue, そうでなければfalse - */ - public static boolean isMorse(String mc) { - Matcher matcher = morsePattern.matcher(mc); - ArrayList list = new ArrayList<>(); - while (matcher.find()) { - list.add(matcher.group()); - } - if (list.size() <= 2) { - return false; - } else { - for (String s : list) { - if (!"・・・".equals(s) && !"・・".equals(s) && !"・".equals(s)) { - return true; - } - } - return false; - } - } - - /** - * 和文モールスをカタカナ・数字に復元する * - * - * @param str 復元したい文字列 - * @return 復元部分が置換された文字列 - */ - public static String morseToJa(String str) { - String[] strArr = toRightMorse(str).split(" "); - StringBuilder sb = new StringBuilder(); - for (String tok : strArr) { - sb.append(mcJa.containsKey(tok) ? mcJa.get(tok) : tok); - } - return sb.toString(); - } - - private static String toRightMorse(String str) { - str = str.replace("‐", "-").replace(" ", " ").trim(); - Pattern pattern = Pattern.compile("[^・- ][・-]"); - StringBuilder sb = new StringBuilder(str); - Matcher matcher = pattern.matcher(str); - while (matcher.find()) { - int i = matcher.start(); - sb.insert(i + 1, " "); - matcher.reset(sb); - } - pattern = Pattern.compile("[・-][^・- ]"); - matcher = pattern.matcher(sb); - while (matcher.find()) { - int i = matcher.start(); - sb.insert(i + 1, " "); - matcher.reset(sb); - } - return sb.toString(); - } - - static { - mcJa = new HashMap<>(); - - String[][] ja2 = {{"・-", "イ"}, {"・-・-", "ロ"}, {"-・・・", "ハ"}, {"-・-・", "ニ"}, {"-・・", "ホ"}, {"・", "ヘ"}, {"・・-・・", "ト"}, {"・・-・", "チ"}, {"--・", "リ"}, {"・・・・", "ヌ"}, {"-・--・", "ル"}, {"・---", "ヲ"}, {"-・-", "ワ"}, {"・-・・", "カ"}, {"--", "ヨ"}, {"-・", "タ"}, {"---", "レ"}, {"---・", "ソ"}, {"・--・", "ツ"}, {"--・-", "ネ"}, {"・-・", "ナ"}, {"・・・", "ラ"}, {"-", "ム"}, {"・・-", "ウ"}, {"・-・・-", "ヰ"}, {"・・--", "ノ"}, {"・-・・・", "オ"}, {"・・・-", "ク"}, {"・--", "ヤ"}, {"-・・-", "マ"}, {"-・--", "ケ"}, {"--・・", "フ"}, {"----", "コ"}, {"-・---", "エ"}, {"・-・--", "テ"}, {"--・--", "ア"}, {"-・-・-", "サ"}, {"-・-・・", "キ"}, {"-・・--", "ユ"}, {"-・・・-", "メ"}, {"・・-・-", "ミ"}, {"--・-・", "シ"}, {"・--・・", "ヱ"}, {"--・・-", "ヒ"}, {"-・・-・", "モ"}, {"・---・", "セ"}, {"---・-", "ス"}, {"・-・-・", "ン"}, {"・・", "゛"}, {"・・--・", "゜"}, {"・--・-", "ー"}, {"・-・-・-", "、"}, {"-・--・-", "("}, {"・-・・-・", ")"}, {"・----", "1"}, {"・・---", "2"}, {"・・・--", "3"}, {"・・・・-", "4"}, {"・・・・・", "5"}, {"-・・・・", "6"}, {"--・・・", "7"}, {"---・・", "8"}, {"----・", "9"}, {"-----", "0"}, {"", ""}}; - for (String[] pr : ja2) { - mcJa.put(pr[0], pr[1]); - } - } -} diff --git a/app/src/main/java/net/lacolaco/smileessence/viewmodel/StatusViewModel.java b/app/src/main/java/net/lacolaco/smileessence/viewmodel/StatusViewModel.java index 64f20567..608c0186 100644 --- a/app/src/main/java/net/lacolaco/smileessence/viewmodel/StatusViewModel.java +++ b/app/src/main/java/net/lacolaco/smileessence/viewmodel/StatusViewModel.java @@ -156,11 +156,7 @@ public class StatusViewModel implements IViewModel, IdObject { int colorNormal = Themes.getStyledColor(activity, R.attr.color_status_text_normal); content.setTextColor(colorNormal); String rawText = tweet.getOriginalTweet().getText(); - if (isReadMorseEnabled() && Morse.isMorse(rawText)) { - content.setText(String.format("%s\n(%s)", rawText, Morse.morseToJa(rawText))); - } else { - content.setText(rawText); - } + content.setText(rawText); TextView footer = (TextView) convertedView.findViewById(R.id.textview_status_footer); footer.setTextSize(textSize - 2); int colorFooter = Themes.getStyledColor(activity, R.attr.color_status_text_footer); @@ -213,10 +209,6 @@ public class StatusViewModel implements IViewModel, IdObject { } } - private boolean isReadMorseEnabled() { - return UserPreferenceHelper.getInstance().get(R.string.key_setting_read_morse, true); - } - private void onClick(Activity activity) { StatusDetailDialogFragment fragment = new StatusDetailDialogFragment(); fragment.setStatusID(tweet.getId()); diff --git a/app/src/main/res/values/keys.xml b/app/src/main/res/values/keys.xml index f0b94fcc..3daa9609 100644 --- a/app/src/main/res/values/keys.xml +++ b/app/src/main/res/values/keys.xml @@ -29,7 +29,6 @@ manageAccounts unfavNotify confirm - morse theme appInfo licenseNotice diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 35649e41..a99468b4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -62,7 +62,6 @@ Set a value between 8\-24 Theme Choose theme - Enable morse System Setting Safe mode Show confirm dialog diff --git a/app/src/main/res/xml/setting.xml b/app/src/main/res/xml/setting.xml index f3d000a0..fd8843dd 100644 --- a/app/src/main/res/xml/setting.xml +++ b/app/src/main/res/xml/setting.xml @@ -50,10 +50,6 @@ android:entryValues="@array/setting_theme_ids" android:key="@string/key_setting_theme" android:title="@string/setting_theme_title" /> -