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

Commit a61c9f0e authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 4748783 from 7488b373 to qt-release

Change-Id: I0439a78fb3a6fefb7a97d4e521b3b94da3095cd5
parents 0cefc459 7488b373
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -54,14 +54,15 @@
        android:includeFontPadding="false"
        android:maxLines="1"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="@color/dialer_secondary_text_color"
        android:visibility="gone"/>
    <TextView
        android:id="@+id/hint"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:includeFontPadding="false"
        android:maxLines="1"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="@color/dialer_secondary_text_color"
        android:visibility="gone"/>
  </LinearLayout>

+72 −115
Original line number Diff line number Diff line
@@ -47,10 +47,9 @@ import com.android.contacts.common.R;
import com.android.contacts.common.compat.PhoneAccountCompat;
import com.android.dialer.location.GeoUtil;
import com.android.dialer.phonenumberutil.PhoneNumberHelper;
import com.android.dialer.protos.ProtoParsers;
import com.android.dialer.telecom.TelecomUtil;
import com.google.common.base.Optional;
import java.util.ArrayList;
import java.util.List;

/**
 * Dialog that allows the user to select a phone accounts for a given action. Optionally provides
@@ -58,128 +57,74 @@ import java.util.List;
 */
public class SelectPhoneAccountDialogFragment extends DialogFragment {

  private static final String ARG_TITLE_RES_ID = "title_res_id";
  private static final String ARG_CAN_SET_DEFAULT = "can_set_default";
  private static final String ARG_SET_DEFAULT_RES_ID = "set_default_res_id";
  private static final String ARG_ACCOUNT_HANDLES = "account_handles";
  private static final String ARG_IS_DEFAULT_CHECKED = "is_default_checked";
  private static final String ARG_LISTENER = "listener";
  private static final String ARG_CALL_ID = "call_id";
  private static final String ARG_HINTS = "hints";
  @VisibleForTesting public static final String ARG_OPTIONS = "options";

  private List<PhoneAccountHandle> mAccountHandles;
  private List<String> mHints;
  private boolean mIsSelected;
  private boolean mIsDefaultChecked;
  private SelectPhoneAccountListener mListener;
  private static final String ARG_IS_DEFAULT_CHECKED = "is_default_checked";

  public SelectPhoneAccountDialogFragment() {}
  private SelectPhoneAccountDialogOptions options =
      SelectPhoneAccountDialogOptions.getDefaultInstance();
  private SelectPhoneAccountListener listener;

  /**
   * Create new fragment instance with default title and no option to set as default.
   *
   * @param accountHandles The {@code PhoneAccountHandle}s available to select from.
   * @param listener The listener for the results of the account selection.
   */
  public static SelectPhoneAccountDialogFragment newInstance(
      List<PhoneAccountHandle> accountHandles,
      SelectPhoneAccountListener listener,
      @Nullable String callId) {
    return newInstance(
        R.string.select_account_dialog_title, false, 0, accountHandles, listener, callId, null);
  }
  private boolean isDefaultChecked;
  private boolean isSelected;

  /**
   * Create new fragment instance. This method also allows specifying a custom title and "set
   * default" checkbox.
   *
   * @param titleResId The resource ID for the string to use in the title of the dialog.
   * @param canSetDefault {@code true} if the dialog should include an option to set the selection
   *     as the default. False otherwise.
   * @param setDefaultResId The resource ID for the string to use in the "set as default" checkbox
   * @param accountHandles The {@code PhoneAccountHandle}s available to select from.
   * @param listener The listener for the results of the account selection.
   * @param callId The callId to be passed back to the listener in {@link
   *     SelectPhoneAccountListener#EXTRA_CALL_ID}
   * @param hints Additional information to be shown underneath the phone account to help user
   *     choose. Index must match {@code accountHandles}
   */
  /** Create new fragment instance. */
  public static SelectPhoneAccountDialogFragment newInstance(
      int titleResId,
      boolean canSetDefault,
      int setDefaultResId,
      List<PhoneAccountHandle> accountHandles,
      SelectPhoneAccountListener listener,
      @Nullable String callId,
      @Nullable List<String> hints) {
    ArrayList<PhoneAccountHandle> accountHandlesCopy = new ArrayList<>();
    if (accountHandles != null) {
      accountHandlesCopy.addAll(accountHandles);
    }
      SelectPhoneAccountDialogOptions options, SelectPhoneAccountListener listener) {
    SelectPhoneAccountDialogFragment fragment = new SelectPhoneAccountDialogFragment();
    final Bundle args = new Bundle();
    args.putInt(ARG_TITLE_RES_ID, titleResId);
    args.putBoolean(ARG_CAN_SET_DEFAULT, canSetDefault);
    if (setDefaultResId != 0) {
      args.putInt(ARG_SET_DEFAULT_RES_ID, setDefaultResId);
    }
    args.putParcelableArrayList(ARG_ACCOUNT_HANDLES, accountHandlesCopy);
    args.putParcelable(ARG_LISTENER, listener);
    args.putString(ARG_CALL_ID, callId);
    if (hints != null) {
      args.putStringArrayList(ARG_HINTS, new ArrayList<>(hints));
    }
    fragment.setArguments(args);
    fragment.setListener(listener);
    Bundle arguments = new Bundle();
    ProtoParsers.put(arguments, ARG_OPTIONS, options);
    fragment.setArguments(arguments);
    return fragment;
  }

  public void setListener(SelectPhoneAccountListener listener) {
    mListener = listener;
    this.listener = listener;
  }

  @Nullable
  @VisibleForTesting
  public SelectPhoneAccountListener getListener() {
    return mListener;
    return listener;
  }

  @VisibleForTesting
  public boolean canSetDefault() {
    return getArguments().getBoolean(ARG_CAN_SET_DEFAULT);
    return options.getCanSetDefault();
  }

  @Override
  public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putBoolean(ARG_IS_DEFAULT_CHECKED, mIsDefaultChecked);
    outState.putBoolean(ARG_IS_DEFAULT_CHECKED, isDefaultChecked);
  }

  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    int titleResId = getArguments().getInt(ARG_TITLE_RES_ID);
    boolean canSetDefault = getArguments().getBoolean(ARG_CAN_SET_DEFAULT);
    mAccountHandles = getArguments().getParcelableArrayList(ARG_ACCOUNT_HANDLES);
    mListener = getArguments().getParcelable(ARG_LISTENER);
    mHints = getArguments().getStringArrayList(ARG_HINTS);
    options =
        ProtoParsers.getTrusted(
            getArguments(), ARG_OPTIONS, SelectPhoneAccountDialogOptions.getDefaultInstance());
    if (savedInstanceState != null) {
      mIsDefaultChecked = savedInstanceState.getBoolean(ARG_IS_DEFAULT_CHECKED);
      isDefaultChecked = savedInstanceState.getBoolean(ARG_IS_DEFAULT_CHECKED);
    }
    mIsSelected = false;
    isSelected = false;

    final DialogInterface.OnClickListener selectionListener =
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            mIsSelected = true;
            PhoneAccountHandle selectedAccountHandle = mAccountHandles.get(which);
            isSelected = true;
            PhoneAccountHandle selectedAccountHandle =
                SelectPhoneAccountDialogOptionsUtil.getPhoneAccountHandle(
                    options.getEntriesList().get(which));
            Bundle result = new Bundle();
            result.putParcelable(
                SelectPhoneAccountListener.EXTRA_SELECTED_ACCOUNT_HANDLE, selectedAccountHandle);
            result.putBoolean(SelectPhoneAccountListener.EXTRA_SET_DEFAULT, mIsDefaultChecked);
            result.putBoolean(SelectPhoneAccountListener.EXTRA_SET_DEFAULT, isDefaultChecked);
            result.putString(SelectPhoneAccountListener.EXTRA_CALL_ID, getCallId());
            if (mListener != null) {
              mListener.onReceiveResult(SelectPhoneAccountListener.RESULT_SELECTED, result);
            if (listener != null) {
              listener.onReceiveResult(SelectPhoneAccountListener.RESULT_SELECTED, result);
            }
          }
        };
@@ -188,22 +133,23 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment {
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton check, boolean isChecked) {
            mIsDefaultChecked = isChecked;
            isDefaultChecked = isChecked;
          }
        };

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    ListAdapter selectAccountListAdapter =
        new SelectAccountListAdapter(
            builder.getContext(), R.layout.select_account_list_item, mAccountHandles, mHints);
            builder.getContext(), R.layout.select_account_list_item, options);

    AlertDialog dialog =
        builder
            .setTitle(titleResId)
            .setTitle(
                options.hasTitle() ? options.getTitle() : R.string.select_account_dialog_title)
            .setAdapter(selectAccountListAdapter, selectionListener)
            .create();

    if (canSetDefault) {
    if (options.getCanSetDefault()) {
      // Generate custom checkbox view, lint suppressed since no appropriate parent (is dialog)
      @SuppressLint("InflateParams")
      LinearLayout checkboxLayout =
@@ -213,11 +159,13 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment {

      CheckBox checkBox = checkboxLayout.findViewById(R.id.default_account_checkbox_view);
      checkBox.setOnCheckedChangeListener(checkListener);
      checkBox.setChecked(mIsDefaultChecked);
      checkBox.setChecked(isDefaultChecked);

      TextView textView = checkboxLayout.findViewById(R.id.default_account_checkbox_text);
      int setDefaultResId =
          getArguments().getInt(ARG_SET_DEFAULT_RES_ID, R.string.set_default_account);
          options.hasSetDefaultLabel()
              ? options.getSetDefaultLabel()
              : R.string.set_default_account;
      textView.setText(setDefaultResId);
      textView.setOnClickListener((view) -> checkBox.performClick());
      checkboxLayout.setOnClickListener((view) -> checkBox.performClick());
@@ -230,17 +178,17 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment {

  @Override
  public void onCancel(DialogInterface dialog) {
    if (!mIsSelected && mListener != null) {
    if (!isSelected && listener != null) {
      Bundle result = new Bundle();
      result.putString(SelectPhoneAccountListener.EXTRA_CALL_ID, getCallId());
      mListener.onReceiveResult(SelectPhoneAccountListener.RESULT_DISMISSED, result);
      listener.onReceiveResult(SelectPhoneAccountListener.RESULT_DISMISSED, result);
    }
    super.onCancel(dialog);
  }

  @Nullable
  private String getCallId() {
    return getArguments().getString(ARG_CALL_ID);
    return options.getCallId();
  }

  public static class SelectPhoneAccountListener extends ResultReceiver {
@@ -274,21 +222,29 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment {
    public void onDialogDismissed(@Nullable String callId) {}
  }

  private static class SelectAccountListAdapter extends ArrayAdapter<PhoneAccountHandle> {
  static class SelectAccountListAdapter
      extends ArrayAdapter<SelectPhoneAccountDialogOptions.Entry> {

    private int mResId;
    private final List<String> mHints;
    private final SelectPhoneAccountDialogOptions options;

    SelectAccountListAdapter(
        Context context,
        int resource,
        List<PhoneAccountHandle> accountHandles,
        @Nullable List<String> hints) {
      super(context, resource, accountHandles);
      mHints = hints;
        Context context, int resource, SelectPhoneAccountDialogOptions options) {
      super(context, resource, options.getEntriesList());
      this.options = options;
      mResId = resource;
    }

    @Override
    public boolean areAllItemsEnabled() {
      return false;
    }

    @Override
    public boolean isEnabled(int position) {
      return options.getEntries(position).getEnabled();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      LayoutInflater inflater =
@@ -311,7 +267,9 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment {
        holder = (ViewHolder) rowView.getTag();
      }

      PhoneAccountHandle accountHandle = getItem(position);
      SelectPhoneAccountDialogOptions.Entry entry = getItem(position);
      PhoneAccountHandle accountHandle =
          SelectPhoneAccountDialogOptionsUtil.getPhoneAccountHandle(entry);
      PhoneAccount account =
          getContext().getSystemService(TelecomManager.class).getPhoneAccount(accountHandle);
      if (account == null) {
@@ -331,18 +289,17 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment {
      }
      holder.imageView.setImageDrawable(
          PhoneAccountCompat.createIconDrawable(account, getContext()));
      if (mHints != null && position < mHints.size()) {
        String hint = mHints.get(position);
        if (TextUtils.isEmpty(hint)) {

      if (TextUtils.isEmpty(entry.getHint())) {
        holder.hintTextView.setVisibility(View.GONE);
      } else {
        holder.hintTextView.setVisibility(View.VISIBLE);
          holder.hintTextView.setText(hint);
        }
      } else {
        holder.hintTextView.setVisibility(View.GONE);
        holder.hintTextView.setText(entry.getHint());
      }

      holder.labelTextView.setEnabled(entry.getEnabled());
      holder.numberTextView.setEnabled(entry.getEnabled());
      holder.hintTextView.setEnabled(entry.getEnabled());
      holder.imageView.setImageAlpha(entry.getEnabled() ? 255 : 97 /* 38%*/);
      return rowView;
    }

@@ -356,7 +313,7 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment {
      return info.get().getCountryIso().toUpperCase();
    }

    private static final class ViewHolder {
    static final class ViewHolder {

      TextView labelTextView;
      TextView numberTextView;
+55 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * 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.
 */

package com.android.contacts.common.widget;

import android.telecom.PhoneAccountHandle;
import com.android.dialer.common.Assert;
import com.android.dialer.telecom.TelecomUtil;
import java.util.Collection;

/** Provides common operation on a {@link SelectPhoneAccountDialogOptions} */
public final class SelectPhoneAccountDialogOptionsUtil {
  private SelectPhoneAccountDialogOptionsUtil() {}

  public static PhoneAccountHandle getPhoneAccountHandle(
      SelectPhoneAccountDialogOptions.Entry entry) {
    return Assert.isNotNull(
        TelecomUtil.composePhoneAccountHandle(
            entry.getPhoneAccountHandleComponentName(), entry.getPhoneAccountHandleId()));
  }

  public static SelectPhoneAccountDialogOptions.Entry.Builder setPhoneAccountHandle(
      SelectPhoneAccountDialogOptions.Entry.Builder entryBuilder,
      PhoneAccountHandle phoneAccountHandle) {
    entryBuilder.setPhoneAccountHandleComponentName(
        phoneAccountHandle.getComponentName().flattenToString());
    entryBuilder.setPhoneAccountHandleId(phoneAccountHandle.getId());
    return entryBuilder;
  }

  public static SelectPhoneAccountDialogOptions.Builder builderWithAccounts(
      Collection<PhoneAccountHandle> phoneAccountHandles) {
    SelectPhoneAccountDialogOptions.Builder optionsBuilder =
        SelectPhoneAccountDialogOptions.newBuilder();
    for (PhoneAccountHandle phoneAccountHandle : phoneAccountHandles) {
      optionsBuilder.addEntries(
          SelectPhoneAccountDialogOptionsUtil.setPhoneAccountHandle(
              SelectPhoneAccountDialogOptions.Entry.newBuilder(), phoneAccountHandle));
    }
    return optionsBuilder;
  }
}
+54 −0
Original line number Diff line number Diff line
// Copyright (C) 2018 The Android Open Source Project
//
// 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

syntax = "proto2";

option java_package = "com.android.contacts.common.widget";
option java_multiple_files = true;
option optimize_for = LITE_RUNTIME;


package com.android.contacts.common.widget;

// Parameters for SelectPhoneAccountDialogFragment
message SelectPhoneAccountDialogOptions {
  // The resource ID for the title. Defaults to
  // R.string.select_account_dialog_title
  optional int32 title = 1;
  // Whether the dialog should include a "set as default" checkbox. Defaults to
  // false
  optional bool can_set_default = 2;
  // The label on the "set as default" checkbox. Defaults
  // R.string.set_default_account
  optional int32 set_default_label = 3;
  // The call ID to pass back to the callback
  optional string call_id = 4;
  // Phone accounts to show in the dialog
  repeated Entry entries = 5;

  message Entry {
    // PhoneAccountHandle.getComponentName().flattenToString()
    optional string phone_account_handle_component_name = 1;
    // PhoneAccountHandle.getId()
    optional string phone_account_handle_id = 2;
    // The hint to show under the phone account, for example showing the user
    // the account was selected frequently before.
    optional string hint = 3;
    // Whether the account is actually selectable. Defaults to true. Sometimes
    // an account will be temporarily unusable, for example the user is already
    // in a call so the other SIM cannot be used. Hint should also be set to
    // inform the user why the account is unavailable.
    optional bool enabled = 4 [default = true];
  }
}
 No newline at end of file
+48 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * 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
 */

package com.android.dialer.activecalls;

import android.support.annotation.Nullable;
import android.telecom.PhoneAccountHandle;
import com.google.auto.value.AutoValue;
import com.google.common.base.Optional;

/** Info of an active call */
@AutoValue
@SuppressWarnings("Guava")
public abstract class ActiveCallInfo {

  /** The {@link PhoneAccountHandle} the call is made with */
  public abstract Optional<PhoneAccountHandle> phoneAccountHandle();

  public static Builder builder() {
    return new AutoValue_ActiveCallInfo.Builder();
  }

  /** Builder for {@link ActiveCallInfo}. Only In Call UI should create ActiveCallInfo */
  @AutoValue.Builder
  public abstract static class Builder {

    public Builder setPhoneAccountHandle(@Nullable PhoneAccountHandle phoneAccountHandle) {
      return setPhoneAccountHandle(Optional.fromNullable(phoneAccountHandle));
    }

    public abstract Builder setPhoneAccountHandle(Optional<PhoneAccountHandle> phoneAccountHandle);

    public abstract ActiveCallInfo build();
  }
}
Loading