summaryrefslogtreecommitdiffstats
path: root/src/com/android/incallui/CallButtonFragment.java
diff options
context:
space:
mode:
authorRichard MacGregor <rmacgregor@cyngn.com>2016-01-22 14:38:50 -0800
committerRichard MacGregor <rmacgregor@cyngn.com>2016-04-08 08:53:14 -0700
commit91d03c80740f1451bc881a5750a57a2184ccc9e4 (patch)
tree923245d948475d35e1c4c15b2a0ddb53cc7efe19 /src/com/android/incallui/CallButtonFragment.java
parentd69ce6c2a65c3d451dfb5837678221e56fef1880 (diff)
downloadpackages_apps_InCallUI-91d03c80740f1451bc881a5750a57a2184ccc9e4.tar.gz
packages_apps_InCallUI-91d03c80740f1451bc881a5750a57a2184ccc9e4.tar.bz2
packages_apps_InCallUI-91d03c80740f1451bc881a5750a57a2184ccc9e4.zip
InCallAPI Handover M-bringup
Integrate Call handover to InCallAPI plugins Integrate InCallAPI snackbar Change-Id: I88897172dde3d01f33c94e24fa78da4048dcb75b
Diffstat (limited to 'src/com/android/incallui/CallButtonFragment.java')
-rw-r--r--src/com/android/incallui/CallButtonFragment.java187
1 files changed, 183 insertions, 4 deletions
diff --git a/src/com/android/incallui/CallButtonFragment.java b/src/com/android/incallui/CallButtonFragment.java
index 34eca3cc..8712637f 100644
--- a/src/com/android/incallui/CallButtonFragment.java
+++ b/src/com/android/incallui/CallButtonFragment.java
@@ -19,10 +19,14 @@ package com.android.incallui;
import static com.android.incallui.CallButtonFragment.Buttons.*;
import android.annotation.NonNull;
+import android.app.AlertDialog;
+import android.app.PendingIntent;
import android.content.Context;
+import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.content.res.ColorStateList;
import android.content.res.Resources;
+import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.GradientDrawable;
@@ -31,6 +35,7 @@ import android.graphics.drawable.StateListDrawable;
import android.os.Bundle;
import android.telecom.CallAudioState;
import android.util.SparseIntArray;
+import android.text.TextUtils;
import android.view.ContextThemeWrapper;
import android.view.HapticFeedbackConstants;
import android.view.LayoutInflater;
@@ -38,11 +43,21 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import android.widget.ImageButton;
+import android.widget.ImageView;
+import android.widget.ListAdapter;
import android.widget.PopupMenu;
import android.widget.PopupMenu.OnDismissListener;
import android.widget.PopupMenu.OnMenuItemClickListener;
+import android.widget.TextView;
+
+import com.android.incallui.incallapi.InCallPluginInfo;
+
+import java.lang.Override;
+import java.util.ArrayList;
+import java.util.List;
import com.android.contacts.common.util.MaterialColorMapUtils.MaterialPalette;
@@ -53,6 +68,9 @@ public class CallButtonFragment
extends BaseFragment<CallButtonPresenter, CallButtonPresenter.CallButtonUi>
implements CallButtonPresenter.CallButtonUi, OnMenuItemClickListener, OnDismissListener,
View.OnClickListener {
+ private static final String TAG = CallButtonFragment.class.getSimpleName();
+ private static final boolean DEBUG = false;
+
private static final int INVALID_INDEX = -1;
private int mButtonMaxVisible;
// The button is currently visible in the UI
@@ -68,9 +86,9 @@ public class CallButtonFragment
public static final int BUTTON_AUDIO = 0;
public static final int BUTTON_MUTE = 1;
public static final int BUTTON_DIALPAD = 2;
- public static final int BUTTON_HOLD = 3;
- public static final int BUTTON_SWAP = 4;
- public static final int BUTTON_UPGRADE_TO_VIDEO = 5;
+ public static final int BUTTON_UPGRADE_TO_VIDEO = 3;
+ public static final int BUTTON_HOLD = 4;
+ public static final int BUTTON_SWAP = 5;
public static final int BUTTON_SWITCH_CAMERA = 6;
public static final int BUTTON_ADD_CALL = 7;
public static final int BUTTON_MERGE = 8;
@@ -225,7 +243,7 @@ public class CallButtonFragment
getPresenter().addParticipantClicked();
break;
case R.id.changeToVideoButton:
- getPresenter().changeToVideoClicked();
+ getPresenter().switchToVideoCall();
break;
case R.id.switchCameraButton:
getPresenter().switchCameraClicked(
@@ -447,6 +465,61 @@ public class CallButtonFragment
mSwitchCameraButton.setSelected(isBackFacingCamera);
}
+ public void modifyChangeToVideoButton() {
+ boolean canVideoCall = getPresenter().canVideoCall();
+ List<InCallPluginInfo> contactInCallPlugins =
+ getPresenter().getContactInCallPluginInfoList();
+ int listSize = (contactInCallPlugins != null) ? contactInCallPlugins.size() : 0;
+ if (!canVideoCall && listSize == 1) {
+ InCallPluginInfo info = contactInCallPlugins.get(0);
+ if (info != null && info.getPluginSingleColorIcon() != null) {
+ LayerDrawable layerDrawable =
+ (LayerDrawable) getResources().getDrawable(R.drawable.btn_change_to_video)
+ .mutate();
+
+ int buttonWidth = mChangeToVideoButton.getWidth();
+ int buttonHeight = mChangeToVideoButton.getWidth();
+ if (buttonWidth == 0 || buttonHeight == 0) {
+ buttonWidth =
+ getResources().getDimensionPixelSize(R.dimen.in_call_button_dimension);
+ buttonHeight =
+ getResources().getDimensionPixelSize(R.dimen.in_call_button_dimension);
+ }
+ int xInset = buttonWidth - layerDrawable.getIntrinsicWidth();
+ if (xInset > 0) {
+ xInset = xInset / 2;
+ } else {
+ xInset = 0;
+ }
+ int yInset = buttonHeight - layerDrawable.getIntrinsicHeight();
+ if (yInset > 0) {
+ yInset = yInset / 2;
+ } else {
+ yInset = 0;
+ }
+
+ if (DEBUG) {
+ Log.i(TAG, "mChangeToVideoButton: [w h] [" + mChangeToVideoButton.getWidth() +
+ " " + mChangeToVideoButton.getHeight() + "]");
+ Log.i(TAG, "adjusted button: [w h] [" + buttonWidth + " " + buttonHeight + "]");
+ Log.i(TAG, "layerDrawable: [w h] [" + layerDrawable.getIntrinsicWidth() + " " +
+ layerDrawable.getIntrinsicHeight() + "]");
+ Log.i(TAG, "xInset = " + xInset);
+ Log.i(TAG, "xInset = " + yInset);
+ }
+
+ Drawable icon = info.getPluginSingleColorIcon();
+ icon.setTintList(getResources().getColorStateList(R.color.selectable_icon_tint));
+ icon.setAutoMirrored(false);
+
+ // layer 0 is background, layer 1 is the icon to use.
+ layerDrawable.setLayerInset(1, xInset, yInset, xInset, yInset);
+ layerDrawable.setDrawableByLayerId(R.id.foregroundItem, icon);
+ mChangeToVideoButton.setBackground(layerDrawable);
+ }
+ }
+ }
+
@Override
public void setVideoPaused(boolean isPaused) {
mPauseVideoButton.setSelected(isPaused);
@@ -542,6 +615,69 @@ public class CallButtonFragment
}
}
+ /**The function is called when Video Call button gets pressed. The function creates and
+ * displays video call options.
+ */
+ @Override
+ public void displayVideoCallOptions() {
+ CallButtonPresenter.CallButtonUi ui = getUi();
+ if (ui == null) {
+ Log.e(this, "Cannot display VideoCallOptions as ui is null");
+ return;
+ }
+
+ Context context = getContext();
+
+ final ArrayList<Drawable> icons = new ArrayList<Drawable>();
+ final ArrayList<String> items = new ArrayList<String>();
+ final ArrayList<Integer> itemToCallType = new ArrayList<Integer>();
+ final Resources res = ui.getContext().getResources();
+
+ // Prepare the string array and mapping.
+ List<InCallPluginInfo> contactInCallPlugins =
+ getPresenter().getContactInCallPluginInfoList();
+ if (contactInCallPlugins != null && !contactInCallPlugins.isEmpty()) {
+ int i = 0;
+ for (InCallPluginInfo info : contactInCallPlugins) {
+ items.add(info.getPluginTitle());
+ icons.add(info.getPluginColorIcon());
+ itemToCallType.add(i++);
+ }
+ }
+
+ boolean canVideoCall = getPresenter().canVideoCall();
+ if (canVideoCall) {
+ // First item, if available is VT IMS call
+ items.add(res.getString(R.string.modify_call_option_vt));
+ Drawable icon = res.getDrawable(R.drawable.ic_toolbar_video);
+ icon.setTint(res.getColor(R.color.vidoecall_handoff_default_video_call_color));
+ icons.add(icon);
+ itemToCallType.add(-1);
+ }
+
+ ListAdapter adapter = new ListItemWithImageArrayAdapter(context.getApplicationContext(),
+ R.layout.videocall_handoff_item, items, icons);
+ DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int item) {
+ final int selCallType = itemToCallType.get(item);
+ if (selCallType < 0) {
+ // VT Call selected
+ getPresenter().changeToVideoClicked();
+ } else {
+ // InCall Plugin selected
+ getPresenter().handoverCallToVoIPPlugin(selCallType);
+ }
+ dialog.dismiss();
+ }
+ };
+ AlertDialog.Builder builder = new AlertDialog.Builder(getUi().getContext());
+ builder.setTitle(R.string.video_call_option_title);
+ builder.setAdapter(adapter, listener);
+ final AlertDialog alert;
+ alert = builder.create();
+ alert.show();
+ }
+
@Override
public void setAudio(int mode) {
updateAudioButtons(getPresenter().getSupportedAudio());
@@ -871,4 +1007,47 @@ public class CallButtonFragment
public Context getContext() {
return getActivity();
}
+
+ @Override
+ public void showInviteSnackbar(final PendingIntent inviteIntent, String inviteText) {
+ if (TextUtils.isEmpty(inviteText)) {
+ return;
+ }
+ final InCallActivity activity = (InCallActivity) getActivity();
+ if (activity != null) {
+ activity.showInviteSnackbar(inviteIntent, inviteText);
+ }
+ }
+
+ /**
+ * Adapter used to Array adapter with an icon and custom item layout
+ */
+ private class ListItemWithImageArrayAdapter extends ArrayAdapter<String> {
+ private int mLayout;
+ private List<Drawable> mIcons;
+
+ public ListItemWithImageArrayAdapter(Context context, int layout, List<String> titles,
+ List<Drawable> icons) {
+ super(context, 0, titles);
+ mLayout = layout;
+ mIcons = icons;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ String title = getItem(position);
+ Drawable icon = mIcons.get(position);
+ if (convertView == null) {
+ convertView = LayoutInflater.from(getContext()).inflate(mLayout, parent, false);
+ }
+
+ TextView textView = (TextView) convertView.findViewById(R.id.title);
+ textView.setText(title);
+
+ ImageView msgIcon = (ImageView) convertView.findViewById(R.id.icon);
+ msgIcon.setImageDrawable(icon);
+
+ return convertView;
+ }
+ }
}