Loading src/com/android/server/telecom/QuickResponseUtils.java +44 −0 Original line number Diff line number Diff line Loading @@ -117,4 +117,48 @@ public class QuickResponseUtils { Log.d(LOG_TAG, "maybeMigrateLegacyQuickResponses() - Done."); return; } /** * Determine if the user has changed any of the quick responses back to exactly the same text as * the default text. If they did, clear the preference so we'll rely on the default value and * still be able to re-translate automatically when language changes occur. * * @param context The current context. * @param prefs The quick response shared prefs. */ public static void maybeResetQuickResponses(Context context, SharedPreferences prefs) { final Resources res = context.getResources(); String defaultResponse1 = res.getString(R.string.respond_via_sms_canned_response_1); String currentValue1 = prefs.getString(QuickResponseUtils.KEY_CANNED_RESPONSE_PREF_1, ""); if (currentValue1.equals(defaultResponse1)) { prefs.edit().remove(QuickResponseUtils.KEY_CANNED_RESPONSE_PREF_1).apply(); Log.i(QuickResponseUtils.class, "maybeResetQuickResponses: response 1 is identical to default; clear pref."); } String defaultResponse2 = res.getString(R.string.respond_via_sms_canned_response_2); String currentValue2 = prefs.getString(QuickResponseUtils.KEY_CANNED_RESPONSE_PREF_2, ""); if (currentValue2.equals(defaultResponse2)) { prefs.edit().remove(QuickResponseUtils.KEY_CANNED_RESPONSE_PREF_2).apply(); Log.i(QuickResponseUtils.class, "maybeResetQuickResponses: response 2 is identical to default; clear pref."); } String defaultResponse3 = res.getString(R.string.respond_via_sms_canned_response_3); String currentValue3 = prefs.getString(QuickResponseUtils.KEY_CANNED_RESPONSE_PREF_3, ""); if (currentValue3.equals(defaultResponse3)) { prefs.edit().remove(QuickResponseUtils.KEY_CANNED_RESPONSE_PREF_3).apply(); Log.i(QuickResponseUtils.class, "maybeResetQuickResponses: response 3 is identical to default; clear pref."); } String defaultResponse4 = res.getString(R.string.respond_via_sms_canned_response_4); String currentValue4 = prefs.getString(QuickResponseUtils.KEY_CANNED_RESPONSE_PREF_4, ""); if (currentValue4.equals(defaultResponse4)) { prefs.edit().remove(QuickResponseUtils.KEY_CANNED_RESPONSE_PREF_4).apply(); Log.i(QuickResponseUtils.class, "maybeResetQuickResponses: response 4 is identical to default; clear pref."); } } } src/com/android/server/telecom/RespondViaSmsManager.java +5 −0 Original line number Diff line number Diff line Loading @@ -105,6 +105,11 @@ public class RespondViaSmsManager extends CallsManagerListenerBase { final ArrayList<String> textMessages = new ArrayList<>( QuickResponseUtils.NUM_CANNED_RESPONSES); // Where the user has changed a quick response back to the same text as the // original text, clear the shared pref. This ensures we always load the resource // in the current active language. QuickResponseUtils.maybeResetQuickResponses(context, prefs); // Note the default values here must agree with the corresponding // android:defaultValue attributes in respond_via_sms_settings.xml. textMessages.add(0, prefs.getString(QuickResponseUtils.KEY_CANNED_RESPONSE_PREF_1, Loading src/com/android/server/telecom/RespondViaSmsSettings.java +4 −0 Original line number Diff line number Diff line Loading @@ -54,6 +54,7 @@ public class RespondViaSmsSettings extends PreferenceActivity getPreferenceManager().setSharedPreferencesName(QuickResponseUtils.SHARED_PREFERENCES_NAME); mPrefs = getPreferenceManager().getSharedPreferences(); QuickResponseUtils.maybeResetQuickResponses(this, mPrefs); } @Override Loading Loading @@ -108,6 +109,9 @@ public class RespondViaSmsSettings extends PreferenceActivity SharedPreferences.Editor editor = mPrefs.edit(); editor.putString(pref.getKey(), (String) newValue).commit(); // If the user just reset the quick response to its original text, clear the pref. QuickResponseUtils.maybeResetQuickResponses(this, mPrefs); return true; // means it's OK to update the state of the Preference with the new value } Loading Loading
src/com/android/server/telecom/QuickResponseUtils.java +44 −0 Original line number Diff line number Diff line Loading @@ -117,4 +117,48 @@ public class QuickResponseUtils { Log.d(LOG_TAG, "maybeMigrateLegacyQuickResponses() - Done."); return; } /** * Determine if the user has changed any of the quick responses back to exactly the same text as * the default text. If they did, clear the preference so we'll rely on the default value and * still be able to re-translate automatically when language changes occur. * * @param context The current context. * @param prefs The quick response shared prefs. */ public static void maybeResetQuickResponses(Context context, SharedPreferences prefs) { final Resources res = context.getResources(); String defaultResponse1 = res.getString(R.string.respond_via_sms_canned_response_1); String currentValue1 = prefs.getString(QuickResponseUtils.KEY_CANNED_RESPONSE_PREF_1, ""); if (currentValue1.equals(defaultResponse1)) { prefs.edit().remove(QuickResponseUtils.KEY_CANNED_RESPONSE_PREF_1).apply(); Log.i(QuickResponseUtils.class, "maybeResetQuickResponses: response 1 is identical to default; clear pref."); } String defaultResponse2 = res.getString(R.string.respond_via_sms_canned_response_2); String currentValue2 = prefs.getString(QuickResponseUtils.KEY_CANNED_RESPONSE_PREF_2, ""); if (currentValue2.equals(defaultResponse2)) { prefs.edit().remove(QuickResponseUtils.KEY_CANNED_RESPONSE_PREF_2).apply(); Log.i(QuickResponseUtils.class, "maybeResetQuickResponses: response 2 is identical to default; clear pref."); } String defaultResponse3 = res.getString(R.string.respond_via_sms_canned_response_3); String currentValue3 = prefs.getString(QuickResponseUtils.KEY_CANNED_RESPONSE_PREF_3, ""); if (currentValue3.equals(defaultResponse3)) { prefs.edit().remove(QuickResponseUtils.KEY_CANNED_RESPONSE_PREF_3).apply(); Log.i(QuickResponseUtils.class, "maybeResetQuickResponses: response 3 is identical to default; clear pref."); } String defaultResponse4 = res.getString(R.string.respond_via_sms_canned_response_4); String currentValue4 = prefs.getString(QuickResponseUtils.KEY_CANNED_RESPONSE_PREF_4, ""); if (currentValue4.equals(defaultResponse4)) { prefs.edit().remove(QuickResponseUtils.KEY_CANNED_RESPONSE_PREF_4).apply(); Log.i(QuickResponseUtils.class, "maybeResetQuickResponses: response 4 is identical to default; clear pref."); } } }
src/com/android/server/telecom/RespondViaSmsManager.java +5 −0 Original line number Diff line number Diff line Loading @@ -105,6 +105,11 @@ public class RespondViaSmsManager extends CallsManagerListenerBase { final ArrayList<String> textMessages = new ArrayList<>( QuickResponseUtils.NUM_CANNED_RESPONSES); // Where the user has changed a quick response back to the same text as the // original text, clear the shared pref. This ensures we always load the resource // in the current active language. QuickResponseUtils.maybeResetQuickResponses(context, prefs); // Note the default values here must agree with the corresponding // android:defaultValue attributes in respond_via_sms_settings.xml. textMessages.add(0, prefs.getString(QuickResponseUtils.KEY_CANNED_RESPONSE_PREF_1, Loading
src/com/android/server/telecom/RespondViaSmsSettings.java +4 −0 Original line number Diff line number Diff line Loading @@ -54,6 +54,7 @@ public class RespondViaSmsSettings extends PreferenceActivity getPreferenceManager().setSharedPreferencesName(QuickResponseUtils.SHARED_PREFERENCES_NAME); mPrefs = getPreferenceManager().getSharedPreferences(); QuickResponseUtils.maybeResetQuickResponses(this, mPrefs); } @Override Loading Loading @@ -108,6 +109,9 @@ public class RespondViaSmsSettings extends PreferenceActivity SharedPreferences.Editor editor = mPrefs.edit(); editor.putString(pref.getKey(), (String) newValue).commit(); // If the user just reset the quick response to its original text, clear the pref. QuickResponseUtils.maybeResetQuickResponses(this, mPrefs); return true; // means it's OK to update the state of the Preference with the new value } Loading