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

Commit 299d3c67 authored by Mohammed Althaf T's avatar Mohammed Althaf T 😊 Committed by Nishith Khanna
Browse files

Contacts: Support changing vCard export version

Change-Id: Ib275eeb002f71ea74490b2c2c780a734dbc3cac0
parent 949626cf
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2022 MURENA SAS

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<resources>
    <string-array name="menu_vcf_export_types" translatable="false">
        <item>@string/menu_export_type_vcf_21</item>
        <item>@string/menu_export_type_vcf_30</item>
        <item>@string/menu_export_type_vcf_40</item>
    </string-array>

    <string-array name="menu_vcf_export_values" translatable="false">
        <item>@string/menu_export_type_vcf_21_value</item>
        <item>@string/menu_export_type_vcf_30_value</item>
        <item>@string/menu_export_type_vcf_40_value</item>
    </string-array>
</resources>
+8 −0
Original line number Diff line number Diff line
@@ -30,4 +30,12 @@
    <string name="preferences_app_info_title">Contacts information</string>
    <string name="preferences_app_info">Contacts is an open source App for Android</string>

    <!-- VCF Export -->
    <string name="menu_export_type_title">Export vCard version</string>
    <string name="menu_export_type_vcf_21" translatable="false">VCF 2.1</string>
    <string name="menu_export_type_vcf_30" translatable="false">VCF 3.0</string>
    <string name="menu_export_type_vcf_40" translatable="false">VCF 4.0</string>
    <string name="menu_export_type_vcf_21_value" translatable="false">v21_generic</string>
    <string name="menu_export_type_vcf_30_value" translatable="false">v30_generic</string>
    <string name="menu_export_type_vcf_40_value" translatable="false">v40_generic</string>
</resources>
+8 −0
Original line number Diff line number Diff line
@@ -65,6 +65,14 @@
        android:key="export"
        android:title="@string/menu_export"/>

    <ListPreference
        android:icon="@null"
        android:key="exportToVcfType"
        android:entries="@array/menu_vcf_export_types"
        android:entryValues="@array/menu_vcf_export_values"
        android:defaultValue="v40_generic"
        android:title="@string/menu_export_type_title"/>

    <Preference
        android:icon="@null"
        android:key="blockedNumbers"
+23 −10
Original line number Diff line number Diff line
@@ -15,25 +15,29 @@
 */
package com.android.contacts.vcard;

import static com.android.vcard.VCardConfig.VCARD_TYPE_V21_GENERIC;
import static com.android.vcard.VCardConfig.VCARD_TYPE_V30_GENERIC;
import static com.android.vcard.VCardConfig.VCARD_TYPE_V40_GENERIC;

import android.app.Notification;
import android.app.NotificationManager;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.RawContactsEntity;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;

import com.android.contacts.R;
import com.android.contactsbind.FeedbackHelper;
import com.android.vcard.VCardComposer;
import com.android.vcard.VCardConfig;

import java.io.BufferedWriter;
import java.io.FileNotFoundException;
@@ -41,6 +45,8 @@ import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;

/**
 * Class for processing one export request from a user. Dropped after exporting requested Uri(s).
@@ -50,6 +56,11 @@ public class ExportProcessor extends ProcessorBase {
    private static final String LOG_TAG = "VCardExport";
    private static final boolean DEBUG = VCardService.DEBUG;

    private static final String KEY_EXPORT_TYPE = "exportToVcfType";
    private static final String VCARD_TYPE_V21_GENERIC_STR = "v21_generic";
    private static final String VCARD_TYPE_V30_GENERIC_STR = "v30_generic";
    private static final String VCARD_TYPE_V40_GENERIC_STR = "v40_generic";

    private final VCardService mService;
    private final ContentResolver mResolver;
    private final NotificationManager mNotificationManager;
@@ -139,14 +150,16 @@ public class ExportProcessor extends ProcessorBase {
                return;
            }

            final String exportType = request.exportType;
            final int vcardType;
            if (TextUtils.isEmpty(exportType)) {
                vcardType = VCardConfig.getVCardTypeFromString(
                        mService.getString(R.string.config_export_vcard_type));
            } else {
                vcardType = VCardConfig.getVCardTypeFromString(exportType);
            }
            Map<String, Integer> sVCardTypeMap = new HashMap<>();
            sVCardTypeMap.put(VCARD_TYPE_V21_GENERIC_STR, VCARD_TYPE_V21_GENERIC);
            sVCardTypeMap.put(VCARD_TYPE_V30_GENERIC_STR, VCARD_TYPE_V30_GENERIC);
            sVCardTypeMap.put(VCARD_TYPE_V40_GENERIC_STR, VCARD_TYPE_V40_GENERIC);

            final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(
                    mService.getApplicationContext());
            final String defVcfType = pref.getString(KEY_EXPORT_TYPE,
                    VCARD_TYPE_V40_GENERIC_STR);
            final int vcardType = sVCardTypeMap.get(defVcfType);

            composer = new VCardComposer(mService, vcardType, true);