Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bf9dddc9 authored by avipul's avatar avipul
Browse files

Added preference for the display of phonetic name fields.

The new preference is available on settings page.
Users can choose to show phonetic name fields always
even when all fields are empty. By default these fields are only
displayed if they are not empty or after "More fields" is selected.

Test:
1. Tap on setting from the navigation drawer
2. Tap on "Phonetic name fields display" option
3. Select "Show always"
4. Press back and go to create new contact
5. Notice that all phonetic name fields are visible
6. Go back to settings and now choose "Hide if empty"
7. Go to create new contact
8. Notice that Phonetic name fields are not visible
9. Tap on "More Fields"
10. All phonetic name fields are visible

Bug: 22413772
Change-Id: I3c906f78fc21ce2288a1853048b593bfb850a373
parent adddba9d
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -43,6 +43,9 @@
    <!-- If true, the default sort order is primary (i.e. by given name) -->
    <bool name="config_default_display_order_primary">true</bool>

    <!-- If true, phonetic name fields are not visible when empty -->
    <bool name="config_default_hide_phonetic_name_if_empty">true</bool>

    <!-- If true, the order of name fields in the editor is primary (i.e. given name first) -->
    <bool name="config_editor_field_order_primary">true</bool>

+11 −0
Original line number Diff line number Diff line
@@ -1318,6 +1318,17 @@
    <!-- Label of the "sort by" display option -->
    <string name="display_options_sort_list_by">Sort by</string>

    <!-- Label of the "phonetic name fields" display option. [CHAR LIMIT=50] -->
    <string name="display_options_phonetic_name_fields">Phonetic name</string>

    <!-- Option to initially show the phonetic name input fields on the contact editor even if the
    contact does not have a phonetic name. [CHAR LIMIT=25]  -->
    <string name="editor_options_always_show_phonetic_names">Always show</string>

    <!-- Option to initially hide the phonetic name input fields on the contact editor if the
    contact being edited doesn't have a phonetic name. [CHAR LIMIT=25]  -->
    <string name="editor_options_hide_phonetic_names_if_empty">Hide if empty</string>

    <!-- An allowable value for the "sort list by" contact display option  -->
    <string name="display_options_sort_by_given_name">First name</string>

+6 −0
Original line number Diff line number Diff line
@@ -49,6 +49,12 @@
        android:title="@string/display_options_view_names_as"
        android:dialogTitle="@string/display_options_view_names_as" />

    <com.android.contacts.preference.PhoneticNameDisplayPreference
        android:icon="@null"
        android:key="phoneticNameDisplay"
        android:title="@string/display_options_phonetic_name_fields"
        android:dialogTitle="@string/display_options_phonetic_name_fields"/>

    <Preference
        android:icon="@null"
        android:key="import"
+4 −2
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import com.android.contacts.model.RawContactModifier;
import com.android.contacts.model.ValuesDelta;
import com.android.contacts.model.account.AccountType;
import com.android.contacts.model.dataitem.DataKind;
import com.android.contacts.preference.ContactsPreferences;

import java.util.ArrayList;
import java.util.List;
@@ -348,8 +349,7 @@ public class KindSectionView extends LinearLayout {
                    nameValuesDelta, rawContactDelta.getRawContactId(), mListener));
        }
        nameView.setDeletable(false);
        nameView.setValues(
                accountType.getKindForMimetype(DataKind.PSEUDO_MIME_TYPE_NAME),
        nameView.setValues(accountType.getKindForMimetype(DataKind.PSEUDO_MIME_TYPE_NAME),
                nameValuesDelta, rawContactDelta, /* readOnly =*/ false, mViewIdGenerator);

        // Correct start margin since there is a second icon in the structured name layout
@@ -376,6 +376,8 @@ public class KindSectionView extends LinearLayout {
        layoutParams.setMargins(0, 0, 0, 0);
        phoneticNameView.setLayoutParams(layoutParams);
        mEditors.addView(phoneticNameView);
        // Display of phonetic name fields is controlled from settings preferences.
        mHideIfEmpty = new ContactsPreferences(getContext()).shouldHidePhoneticNamesIfEmpty();
    }

    private void addGroupEditorView(RawContactDelta rawContactDelta, DataKind dataKind) {
+42 −0
Original line number Diff line number Diff line
@@ -69,6 +69,8 @@ public class ContactsPreferences implements OnSharedPreferenceChangeListener {

    public static final boolean PREF_DISPLAY_ONLY_PHONES_DEFAULT = false;

    public static final String PHONETIC_NAME_DISPLAY_KEY = "Phonetic_name_display";

    /**
     * Value to use when a preference is unassigned and needs to be read from the shared preferences
     */
@@ -77,6 +79,8 @@ public class ContactsPreferences implements OnSharedPreferenceChangeListener {
    private final Context mContext;
    private int mSortOrder = PREFERENCE_UNASSIGNED;
    private int mDisplayOrder = PREFERENCE_UNASSIGNED;
    private int mPhoneticNameDisplayPreference = PREFERENCE_UNASSIGNED;

    private AccountWithDataSet mDefaultAccount = null;
    private ChangeListener mListener = null;
    private Handler mHandler;
@@ -165,6 +169,34 @@ public class ContactsPreferences implements OnSharedPreferenceChangeListener {
        mBackupManager.dataChanged();
    }

    public int getDefaultPhoneticNameDisplayPreference() {
        if (mContext.getResources().getBoolean(R.bool.config_default_hide_phonetic_name_if_empty)) {
            return PhoneticNameDisplayPreference.HIDE_IF_EMPTY;
        } else {
            return PhoneticNameDisplayPreference.SHOW_ALWAYS;
        }
    }

    public void setPhoneticNameDisplayPreference(int phoneticNameDisplayPreference) {
        mPhoneticNameDisplayPreference = phoneticNameDisplayPreference;
        final Editor editor = mPreferences.edit();
        editor.putInt(PHONETIC_NAME_DISPLAY_KEY, phoneticNameDisplayPreference);
        editor.commit();
        mBackupManager.dataChanged();
    }

    public int getPhoneticNameDisplayPreference() {
        if (mPhoneticNameDisplayPreference == PREFERENCE_UNASSIGNED) {
            mPhoneticNameDisplayPreference = mPreferences.getInt(PHONETIC_NAME_DISPLAY_KEY,
                    getDefaultPhoneticNameDisplayPreference());
        }
        return mPhoneticNameDisplayPreference;
    }

    public boolean shouldHidePhoneticNamesIfEmpty() {
        return getPhoneticNameDisplayPreference() == PhoneticNameDisplayPreference.HIDE_IF_EMPTY;
    }

    public boolean isDefaultAccountUserChangeable() {
        return mIsDefaultAccountUserChangeable;
    }
@@ -326,6 +358,16 @@ public class ContactsPreferences implements OnSharedPreferenceChangeListener {
            setDisplayOrder(displayOrder);
        }

        if (!mPreferences.contains(PHONETIC_NAME_DISPLAY_KEY)) {
            int phoneticNameFieldsDisplay = getDefaultPhoneticNameDisplayPreference();
            try {
                phoneticNameFieldsDisplay = Settings.System.getInt(mContext.getContentResolver(),
                        PHONETIC_NAME_DISPLAY_KEY);
            } catch (SettingNotFoundException e) {
            }
            setPhoneticNameDisplayPreference(phoneticNameFieldsDisplay);
        }

        if (!mPreferences.contains(mDefaultAccountKey)) {
            final SharedPreferences previousPrefs =
                    PreferenceManager.getDefaultSharedPreferences(mContext);
Loading