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

Commit aa47351b authored by Jordan Hayes's avatar Jordan Hayes Committed by Android (Google) Code Review
Browse files

Merge "Format files needed for Android B integration" into main

parents a473e2b9 e1c22702
Loading
Loading
Loading
Loading
+40 −32
Original line number Diff line number Diff line
@@ -31,21 +31,21 @@ import com.android.contacts.model.account.AccountType;
import com.google.i18n.phonenumbers.NumberParseException;
import com.google.i18n.phonenumbers.PhoneNumberUtil;

/**
 * Shared static contact utility methods.
 */
/** Shared static contact utility methods. */
public class MoreContactUtils {

    private static final String WAIT_SYMBOL_AS_STRING = String.valueOf(PhoneNumberUtils.WAIT);

    /**
     * Returns true if two data with mimetypes which represent values in contact entries are
     * considered equal for collapsing in the GUI. For caller-id, use
     * {@link android.telephony.PhoneNumberUtils#compare(android.content.Context, String, String)}
     * instead
     * considered equal for collapsing in the GUI. For caller-id, use {@link
     * android.telephony.PhoneNumberUtils#compare(android.content.Context, String, String)} instead
     */
    public static boolean shouldCollapse(CharSequence mimetype1, CharSequence data1,
              CharSequence mimetype2, CharSequence data2) {
    public static boolean shouldCollapse(
            CharSequence mimetype1,
            CharSequence data1,
            CharSequence mimetype2,
            CharSequence data2) {
        // different mimetypes? don't collapse
        if (!TextUtils.equals(mimetype1, mimetype2)) return false;

@@ -57,8 +57,8 @@ public class MoreContactUtils {

        // if this is not about phone numbers, we know this is not a match (of course, some
        // mimetypes could have more sophisticated matching is the future, e.g. addresses)
        if (!TextUtils.equals(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE,
                mimetype1)) {
        if (!TextUtils.equals(
                ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE, mimetype1)) {
            return false;
        }

@@ -165,18 +165,18 @@ public class MoreContactUtils {
                case SHORT_NSN_MATCH:
                    return false;
                default:
                    throw new IllegalStateException("Unknown result value from phone number " +
                            "library");
                    throw new IllegalStateException(
                            "Unknown result value from phone number " + "library");
            }
        }
        return true;
    }

    /**
     * Returns the {@link android.graphics.Rect} with left, top, right, and bottom coordinates
     * that are equivalent to the given {@link android.view.View}'s bounds. This is equivalent to
     * how the target {@link android.graphics.Rect} is calculated in
     * {@link android.provider.ContactsContract.QuickContact#showQuickContact}.
     * Returns the {@link android.graphics.Rect} with left, top, right, and bottom coordinates that
     * are equivalent to the given {@link android.view.View}'s bounds. This is equivalent to how the
     * target {@link android.graphics.Rect} is calculated in {@link
     * android.provider.ContactsContract.QuickContact#showQuickContact}.
     */
    public static Rect getTargetRectFromView(View view) {
        final int[] pos = new int[2];
@@ -191,8 +191,8 @@ public class MoreContactUtils {
    }

    /**
     * Returns a header view based on the R.layout.list_separator, where the
     * containing {@link android.widget.TextView} is set using the given textResourceId.
     * Returns a header view based on the R.layout.list_separator, where the containing {@link
     * android.widget.TextView} is set using the given textResourceId.
     */
    public static TextView createHeaderView(Context context, int textResourceId) {
        final TextView textView = (TextView) View.inflate(context, R.layout.list_separator, null);
@@ -201,29 +201,37 @@ public class MoreContactUtils {
    }

    /**
     * Set the top padding on the header view dynamically, based on whether the header is in
     * the first row or not.
     * Set the top padding on the header view dynamically, based on whether the header is in the
     * first row or not.
     */
    public static void setHeaderViewBottomPadding(Context context, TextView textView,
            boolean isFirstRow) {
    public static void setHeaderViewBottomPadding(
            Context context, TextView textView, boolean isFirstRow) {
        final int topPadding;
        if (isFirstRow) {
            topPadding = (int) context.getResources().getDimension(
                    R.dimen.frequently_contacted_title_top_margin_when_first_row);
            topPadding =
                    (int)
                            context.getResources()
                                    .getDimension(
                                            R.dimen
                                                    .frequently_contacted_title_top_margin_when_first_row);
        } else {
            topPadding = (int) context.getResources().getDimension(
                    R.dimen.frequently_contacted_title_top_margin);
            topPadding =
                    (int)
                            context.getResources()
                                    .getDimension(R.dimen.frequently_contacted_title_top_margin);
        }
        textView.setPaddingRelative(textView.getPaddingStart(), topPadding,
                textView.getPaddingEnd(), textView.getPaddingBottom());
        textView.setPaddingRelative(
                textView.getPaddingStart(),
                topPadding,
                textView.getPaddingEnd(),
                textView.getPaddingBottom());
    }


    /**
     * Returns the intent to launch for the given invitable account type and contact lookup URI.
     * This will return null if the account type is not invitable (i.e. there is no
     * {@link AccountType#getInviteContactActivityClassName()} or
     * {@link AccountType#syncAdapterPackageName}).
     * This will return null if the account type is not invitable (i.e. there is no {@link
     * AccountType#getInviteContactActivityClassName()} or {@link
     * AccountType#syncAdapterPackageName}).
     */
    public static Intent getInvitableIntent(AccountType accountType, Uri lookupUri) {
        String syncAdapterPackageName = accountType.syncAdapterPackageName;
+93 −82
Original line number Diff line number Diff line
@@ -22,14 +22,6 @@ import android.content.Context;
import android.content.IntentFilter;
import android.content.Loader;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.material.snackbar.Snackbar;

import androidx.collection.ArrayMap;
import androidx.core.view.ViewCompat;
import androidx.core.widget.ContentLoadingProgressBar;
import androidx.appcompat.widget.Toolbar;
import android.util.SparseBooleanArray;
import android.view.LayoutInflater;
import android.view.View;
@@ -40,6 +32,13 @@ import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.collection.ArrayMap;
import androidx.core.view.ViewCompat;
import androidx.core.widget.ContentLoadingProgressBar;

import com.android.contacts.compat.CompatUtils;
import com.android.contacts.database.SimContactDao;
import com.android.contacts.editor.AccountHeaderPresenter;
@@ -51,6 +50,8 @@ import com.android.contacts.model.account.AccountWithDataSet;
import com.android.contacts.preference.ContactsPreferences;
import com.android.contacts.util.concurrent.ContactsExecutors;
import com.android.contacts.util.concurrent.ListenableFutureLoader;

import com.google.android.material.snackbar.Snackbar;
import com.google.common.base.Function;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
@@ -70,7 +71,8 @@ import java.util.concurrent.Callable;
 */
public class SimImportFragment extends Fragment
        implements LoaderManager.LoaderCallbacks<SimImportFragment.LoaderResult>,
        AdapterView.OnItemClickListener, AbsListView.OnScrollListener {
                AdapterView.OnItemClickListener,
                AbsListView.OnScrollListener {

    private static final String KEY_SUFFIX_SELECTED_IDS = "_selectedIds";
    private static final String ARG_SUBSCRIPTION_ID = "subscriptionId";
@@ -102,8 +104,10 @@ public class SimImportFragment extends Fragment
        mAdapter = new SimContactAdapter(getActivity());

        final Bundle args = getArguments();
        mSubscriptionId = args == null ? SimCard.NO_SUBSCRIPTION_ID :
                args.getInt(ARG_SUBSCRIPTION_ID, SimCard.NO_SUBSCRIPTION_ID);
        mSubscriptionId =
                args == null
                        ? SimCard.NO_SUBSCRIPTION_ID
                        : args.getInt(ARG_SUBSCRIPTION_ID, SimCard.NO_SUBSCRIPTION_ID);
    }

    @Override
@@ -114,15 +118,14 @@ public class SimImportFragment extends Fragment

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
    public View onCreateView(
            LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        final View view = inflater.inflate(R.layout.fragment_sim_import, container, false);

        mAccountHeaderContainer = view.findViewById(R.id.account_header_container);
        mAccountScrolledElevationPixels = getResources()
                .getDimension(R.dimen.contact_list_header_elevation);
        mAccountHeaderPresenter = new AccountHeaderPresenter(
                mAccountHeaderContainer);
        mAccountScrolledElevationPixels =
                getResources().getDimension(R.dimen.contact_list_header_elevation);
        mAccountHeaderPresenter = new AccountHeaderPresenter(mAccountHeaderContainer);
        if (savedInstanceState != null) {
            mAccountHeaderPresenter.onRestoreInstanceState(savedInstanceState);
        } else {
@@ -130,7 +133,8 @@ public class SimImportFragment extends Fragment
            // after they are loaded.
            mAccountHeaderPresenter.setCurrentAccount(mPreferences.getDefaultAccount());
        }
        mAccountHeaderPresenter.setObserver(new AccountHeaderPresenter.Observer() {
        mAccountHeaderPresenter.setObserver(
                new AccountHeaderPresenter.Observer() {
                    @Override
                    public void onChange(AccountHeaderPresenter sender) {
                        rememberSelectionsForCurrentAccount();
@@ -147,7 +151,8 @@ public class SimImportFragment extends Fragment
        mListView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
        mListView.setOnItemClickListener(this);
        mImportButton = view.findViewById(R.id.import_button);
        mImportButton.setOnClickListener(new View.OnClickListener() {
        mImportButton.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        importCurrentSelections();
@@ -158,7 +163,8 @@ public class SimImportFragment extends Fragment
                });

        mToolbar = (Toolbar) view.findViewById(R.id.toolbar);
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
        mToolbar.setNavigationOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        getActivity().setResult(Activity.RESULT_CANCELED);
@@ -188,8 +194,8 @@ public class SimImportFragment extends Fragment
            return;
        }
        for (int i = 0, len = mListView.getCount(); i < len; i++) {
            mListView.setItemChecked(i,
                    Arrays.binarySearch(ids, mListView.getItemIdAtPosition(i)) >= 0);
            mListView.setItemChecked(
                    i, Arrays.binarySearch(ids, mListView.getItemIdAtPosition(i)) >= 0);
        }
    }

@@ -243,8 +249,7 @@ public class SimImportFragment extends Fragment
    }

    @Override
    public void onLoadFinished(Loader<LoaderResult> loader,
            LoaderResult data) {
    public void onLoadFinished(Loader<LoaderResult> loader, LoaderResult data) {
        mLoadingIndicator.hide();
        if (data == null) {
            return;
@@ -259,8 +264,7 @@ public class SimImportFragment extends Fragment
    }

    @Override
    public void onLoaderReset(Loader<LoaderResult> loader) {
    }
    public void onLoaderReset(Loader<LoaderResult> loader) {}

    private void restoreAdapterSelectedStates(List<AccountInfo> accounts) {
        if (mSavedInstanceState == null) {
@@ -268,7 +272,8 @@ public class SimImportFragment extends Fragment
        }

        for (AccountInfo account : accounts) {
            final long[] selections = mSavedInstanceState.getLongArray(
            final long[] selections =
                    mSavedInstanceState.getLongArray(
                            account.getAccount().stringify() + KEY_SUFFIX_SELECTED_IDS);
            mPerAccountCheckedIds.put(account.getAccount(), selections);
        }
@@ -282,8 +287,8 @@ public class SimImportFragment extends Fragment

        // Make sure the selections are up-to-date
        for (Map.Entry<AccountWithDataSet, long[]> entry : mPerAccountCheckedIds.entrySet()) {
            outState.putLongArray(entry.getKey().stringify() + KEY_SUFFIX_SELECTED_IDS,
                    entry.getValue());
            outState.putLongArray(
                    entry.getKey().stringify() + KEY_SUFFIX_SELECTED_IDS, entry.getValue());
        }
    }

@@ -297,14 +302,17 @@ public class SimImportFragment extends Fragment
                importableContacts.add(mAdapter.getItem(checked.keyAt(i)));
            }
        }
        SimImportService.startImport(getContext(), mSubscriptionId, importableContacts,
        SimImportService.startImport(
                getContext(),
                mSubscriptionId,
                importableContacts,
                mAccountHeaderPresenter.getCurrentAccount());
    }

    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        if (mAdapter.existsInCurrentAccount(position)) {
            Snackbar.make(getView(), R.string.sim_import_contact_exists_toast,
                    Snackbar.LENGTH_LONG).show();
            Snackbar.make(getView(), R.string.sim_import_contact_exists_toast, Snackbar.LENGTH_LONG)
                    .show();
        } else {
            updateToolbarWithCurrentSelections();
        }
@@ -321,8 +329,8 @@ public class SimImportFragment extends Fragment
    public void onScrollStateChanged(AbsListView view, int scrollState) {}

    @Override
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
            int totalItemCount) {
    public void onScroll(
            AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        int firstCompletelyVisibleItem = firstVisibleItem;
        if (view != null && view.getChildAt(0) != null && view.getChildAt(0).getTop() < 0) {
            firstCompletelyVisibleItem++;
@@ -335,9 +343,7 @@ public class SimImportFragment extends Fragment
        }
    }

    /**
     * Creates a fragment that will display contacts stored on the default SIM card
     */
    /** Creates a fragment that will display contacts stored on the default SIM card */
    public static SimImportFragment newInstance() {
        return new SimImportFragment();
    }
@@ -394,9 +400,10 @@ public class SimImportFragment extends Fragment
        public View getView(int position, View convertView, ViewGroup parent) {
            TextView text = (TextView) convertView;
            if (text == null) {
                final int layoutRes = existsInCurrentAccount(position) ?
                        R.layout.sim_import_list_item_disabled :
                        R.layout.sim_import_list_item;
                final int layoutRes =
                        existsInCurrentAccount(position)
                                ? R.layout.sim_import_list_item_disabled
                                : R.layout.sim_import_list_item;
                text = (TextView) mInflater.inflate(layoutRes, parent, false);
            }
            text.setText(getItemLabel(getItem(position)));
@@ -444,7 +451,6 @@ public class SimImportFragment extends Fragment
        }
    }


    private static class SimContactLoader extends ListenableFutureLoader<LoaderResult> {
        private SimContactDao mDao;
        private AccountTypeManager mAccountTypeManager;
@@ -459,17 +465,21 @@ public class SimImportFragment extends Fragment

        @Override
        protected ListenableFuture<LoaderResult> loadData() {
            final ListenableFuture<List<Object>> future = Futures.<Object>allAsList(
                    mAccountTypeManager
                            .filterAccountsAsync(AccountTypeManager.writableFilter()),
                    ContactsExecutors.getSimReadExecutor().<Object>submit(
            final ListenableFuture<List<Object>> future =
                    Futures.<Object>allAsList(
                            mAccountTypeManager.filterAccountsAsync(
                                    AccountTypeManager.writableFilter()),
                            ContactsExecutors.getSimReadExecutor()
                                    .<Object>submit(
                                            new Callable<Object>() {
                                                @Override
                                                public LoaderResult call() throws Exception {
                                                    return loadFromSim();
                                                }
                                            }));
            return Futures.transform(future, new Function<List<Object>, LoaderResult>() {
            return Futures.transform(
                    future,
                    new Function<List<Object>, LoaderResult>() {
                        @Override
                        public LoaderResult apply(List<Object> input) {
                            final List<AccountInfo> accounts = (List<AccountInfo>) input.get(0);
@@ -477,7 +487,8 @@ public class SimImportFragment extends Fragment
                            simLoadResult.accounts = accounts;
                            return simLoadResult;
                        }
            }, MoreExecutors.directExecutor());
                    },
                    MoreExecutors.directExecutor());
        }

        private LoaderResult loadFromSim() {
+90 −74

File changed.

Preview size limit exceeded, changes collapsed.

+71 −54
Original line number Diff line number Diff line
@@ -42,12 +42,11 @@ import com.android.contacts.util.ImplicitIntentsUtil;
import java.util.List;

/**
 * This activity can be shown to the user when creating a new contact to inform the user about
 * which account the contact will be saved in. There is also an option to add an account at
 * this time. The {@link Intent} in the activity result will contain an extra
 * {@link #Intents.Insert.ACCOUNT} that contains the {@link AccountWithDataSet} to create
 * the new contact in. If the activity result doesn't contain intent data, then there is no
 * account for this contact.
 * This activity can be shown to the user when creating a new contact to inform the user about which
 * account the contact will be saved in. There is also an option to add an account at this time. The
 * {@link Intent} in the activity result will contain an extra {@link #Intents.Insert.ACCOUNT} that
 * contains the {@link AccountWithDataSet} to create the new contact in. If the activity result
 * doesn't contain intent data, then there is no account for this contact.
 */
public class ContactEditorAccountsChangedActivity extends Activity
        implements AccountsLoader.AccountsListener {
@@ -57,7 +56,8 @@ public class ContactEditorAccountsChangedActivity extends Activity
    private ContactEditorUtils mEditorUtils;
    private AlertDialog mDialog;

    private final OnItemClickListener mAccountListItemClickListener = new OnItemClickListener() {
    private final OnItemClickListener mAccountListItemClickListener =
            new OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    if (mAccountListAdapter == null) {
@@ -67,7 +67,8 @@ public class ContactEditorAccountsChangedActivity extends Activity
                }
            };

    private final OnClickListener mAddAccountClickListener = new OnClickListener() {
    private final OnClickListener mAddAccountClickListener =
            new OnClickListener() {
                @Override
                public void onClick(View v) {
                    final Intent intent = ImplicitIntentsUtil.getIntentForAddingGoogleAccount();
@@ -127,8 +128,11 @@ public class ContactEditorAccountsChangedActivity extends Activity
        if (numAccounts >= 2) {
            // When the user has 2+ writable accounts, show a list of accounts so the user can pick
            // which account to create a contact in.
            view = View.inflate(this,
                    R.layout.contact_editor_accounts_changed_activity_with_picker, null);
            view =
                    View.inflate(
                            this,
                            R.layout.contact_editor_accounts_changed_activity_with_picker,
                            null);

            final TextView textView = (TextView) view.findViewById(R.id.text);
            textView.setText(getString(R.string.contact_editor_prompt_multiple_accounts));
@@ -145,15 +149,20 @@ public class ContactEditorAccountsChangedActivity extends Activity
                && !accounts.get(0).getAccount().equals(AccountWithDataSet.getLocalAccount(this))) {
            // If the user has 1 writable account we will just show the user a message with 2
            // possible action buttons.
            view = View.inflate(this,
                    R.layout.contact_editor_accounts_changed_activity_with_text, null);
            view =
                    View.inflate(
                            this,
                            R.layout.contact_editor_accounts_changed_activity_with_text,
                            null);

            final TextView textView = (TextView) view.findViewById(R.id.text);
            final Button leftButton = (Button) view.findViewById(R.id.left_button);
            final Button rightButton = (Button) view.findViewById(R.id.right_button);

            final AccountInfo accountInfo = accounts.get(0);
            textView.setText(getString(R.string.contact_editor_prompt_one_account,
            textView.setText(
                    getString(
                            R.string.contact_editor_prompt_one_account,
                            accountInfo.getNameLabel()));

            // This button allows the user to add a new account to the device and return to
@@ -164,7 +173,8 @@ public class ContactEditorAccountsChangedActivity extends Activity
            // This button allows the user to continue creating the contact in the specified
            // account.
            rightButton.setText(getString(android.R.string.ok));
            rightButton.setOnClickListener(new OnClickListener() {
            rightButton.setOnClickListener(
                    new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            saveAccountAndReturnResult(accountInfo.getAccount());
@@ -173,8 +183,11 @@ public class ContactEditorAccountsChangedActivity extends Activity
        } else {
            // If the user has 0 writable accounts, we will just show the user a message with 2
            // possible action buttons.
            view = View.inflate(this,
                    R.layout.contact_editor_accounts_changed_activity_with_text, null);
            view =
                    View.inflate(
                            this,
                            R.layout.contact_editor_accounts_changed_activity_with_text,
                            null);

            final TextView textView = (TextView) view.findViewById(R.id.text);
            final Button leftButton = (Button) view.findViewById(R.id.left_button);
@@ -185,10 +198,12 @@ public class ContactEditorAccountsChangedActivity extends Activity
            // This button allows the user to continue editing the contact as a phone-only
            // local contact.
            leftButton.setText(getString(android.R.string.cancel));
            leftButton.setOnClickListener(new OnClickListener() {
            leftButton.setOnClickListener(
                    new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                    // Remember that the user wants to create local contacts, so the user is not
                            // Remember that the user wants to create local contacts, so the user is
                            // not
                            // prompted again with this activity.
                            saveAccountAndReturnResult(AccountWithDataSet.getNullAccount());
                            finish();
@@ -204,9 +219,11 @@ public class ContactEditorAccountsChangedActivity extends Activity
        if (mDialog != null && mDialog.isShowing()) {
            mDialog.dismiss();
        }
        mDialog = new AlertDialog.Builder(this)
        mDialog =
                new AlertDialog.Builder(this)
                        .setView(view)
                .setOnCancelListener(new DialogInterface.OnCancelListener() {
                        .setOnCancelListener(
                                new DialogInterface.OnCancelListener() {
                                    @Override
                                    public void onCancel(DialogInterface dialog) {
                                        finish();
+66 −101

File changed.

Preview size limit exceeded, changes collapsed.

Loading