From 755569c73e71f03fa2b17f1d79314a71b80d79f4 Mon Sep 17 00:00:00 2001 From: Margaux Clerc Date: Thu, 30 Jul 2015 16:59:11 +0200 Subject: [PATCH] Start rework incall view --- res/layout/incall.xml | 131 ++++++-------- res/layout/incoming.xml | 55 ++++-- res/layout/main.xml | 2 +- src/org/linphone/InCallActivity.java | 44 ++--- src/org/linphone/IncomingCallActivity.java | 17 ++ src/org/linphone/OutgoingCallActivity.java | 192 +++++++++++++++++++++ 6 files changed, 327 insertions(+), 114 deletions(-) create mode 100644 src/org/linphone/OutgoingCallActivity.java diff --git a/res/layout/incall.xml b/res/layout/incall.xml index 32aed4578..5d96f1e80 100644 --- a/res/layout/incall.xml +++ b/res/layout/incall.xml @@ -27,7 +27,7 @@ android:id="@+id/status" android:name="org.linphone.StatusFragment" android:layout_width="match_parent" - android:layout_height="wrap_content" + android:layout_height="40dp" tools:layout="@layout/status" /> @@ -120,19 +120,15 @@ android:text="@string/button_receiver" android:gravity="center" android:paddingTop="40dp" - android:textColor="@drawable/text_incall_button_color" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0.5" /> - @@ -159,22 +155,17 @@ - @@ -183,23 +174,22 @@ + android:layout_gravity="center"> - - - - - @@ -261,43 +241,42 @@ - - - + - + - - + diff --git a/res/layout/incoming.xml b/res/layout/incoming.xml index d6c0d1481..0bfcc58b0 100644 --- a/res/layout/incoming.xml +++ b/res/layout/incoming.xml @@ -5,37 +5,62 @@ android:layout_height="match_parent" android:background="@color/background"> + + + + + + + + - + android:orientation="vertical" + android:paddingTop="10dp" + android:weightSum="1"> + android:layout_marginTop="10dp" + android:layout_weight="1.30"/> + + + android:layout_gravity="center_horizontal"/> diff --git a/res/layout/main.xml b/res/layout/main.xml index 39e0d77df..1dc4e4721 100644 --- a/res/layout/main.xml +++ b/res/layout/main.xml @@ -165,7 +165,7 @@ android:layout_height="25dp" android:layout_alignParentRight="true" android:layout_alignParentTop="true" - android:background="@drawable/missed_calls_bg" + android:background="@drawable/history_chat_indicator" android:gravity="center" android:textSize="20sp" android:visibility="gone" /> diff --git a/src/org/linphone/InCallActivity.java b/src/org/linphone/InCallActivity.java index e160c88ec..7cf3a06b4 100644 --- a/src/org/linphone/InCallActivity.java +++ b/src/org/linphone/InCallActivity.java @@ -77,7 +77,7 @@ public class InCallActivity extends Activity implements OnClickListener { private Handler mControlsHandler = new Handler(); private Runnable mControls; private ImageView switchCamera; - private TextView pause, hangUp, dialer, video, micro, speaker, options, addCall, transfer, conference; + private ImageView pause, hangUp, dialer, video, micro, speaker, options, addCall, transfer, conference; private TextView audioRoute, routeSpeaker, routeReceiver, routeBluetooth; private LinearLayout routeLayout; private ProgressBar videoProgress; @@ -171,7 +171,7 @@ public class InCallActivity extends Activity implements OnClickListener { LinphoneManager.getLc().enableSpeaker(isSpeakerEnabled); isMicMuted = LinphoneManager.getLc().isMicMuted(); - enableAndRefreshInCallActions(); + //enableAndRefreshInCallActions(); if (status != null) { videoProgress.setVisibility(View.GONE); @@ -179,9 +179,9 @@ public class InCallActivity extends Activity implements OnClickListener { } } - refreshInCallActions(); + //refreshInCallActions(); - refreshCallList(getResources()); + //refreshCallList(getResources()); if (state == State.CallUpdatedByRemote) { // If the correspondent proposes video while audio call @@ -236,7 +236,7 @@ public class InCallActivity extends Activity implements OnClickListener { LinphoneCall call = LinphoneManager.getLc().getCalls()[0]; if (LinphoneUtils.isCallEstablished(call)) { - enableAndRefreshInCallActions(); + //enableAndRefreshInCallActions(); } } @@ -245,7 +245,7 @@ public class InCallActivity extends Activity implements OnClickListener { isSpeakerEnabled = savedInstanceState.getBoolean("Speaker"); isMicMuted = savedInstanceState.getBoolean("Mic"); isVideoCallPaused = savedInstanceState.getBoolean("VideoCallPaused"); - refreshInCallActions(); + //refreshInCallActions(); return; } @@ -303,35 +303,35 @@ public class InCallActivity extends Activity implements OnClickListener { } - video = (TextView) findViewById(R.id.video); + video = (ImageView) findViewById(R.id.video); video.setOnClickListener(this); video.setEnabled(false); - micro = (TextView) findViewById(R.id.micro); + micro = (ImageView) findViewById(R.id.micro); micro.setOnClickListener(this); // micro.setEnabled(false); - speaker = (TextView) findViewById(R.id.speaker); + speaker = (ImageView) findViewById(R.id.speaker); speaker.setOnClickListener(this); if(isTablet()){ speaker.setEnabled(false); } // speaker.setEnabled(false); - addCall = (TextView) findViewById(R.id.addCall); + addCall = (ImageView) findViewById(R.id.addCall); addCall.setOnClickListener(this); addCall.setEnabled(false); - transfer = (TextView) findViewById(R.id.transfer); + transfer = (ImageView) findViewById(R.id.transfer); transfer.setOnClickListener(this); transfer.setEnabled(false); - options = (TextView) findViewById(R.id.options); + options = (ImageView) findViewById(R.id.options); options.setOnClickListener(this); options.setEnabled(false); - pause = (TextView) findViewById(R.id.pause); - pause.setOnClickListener(this); - pause.setEnabled(false); - hangUp = (TextView) findViewById(R.id.hangUp); + //pause = (ImageView) findViewById(R.id.pause); + //pause.setOnClickListener(this); + //pause.setEnabled(false); + hangUp = (ImageView) findViewById(R.id.hangUp); hangUp.setOnClickListener(this); - conference = (TextView) findViewById(R.id.conference); - conference.setOnClickListener(this); - dialer = (TextView) findViewById(R.id.dialer); + //conference = (ImageView) findViewById(R.id.conference); + //conference.setOnClickListener(this); + dialer = (ImageView) findViewById(R.id.dialer); dialer.setOnClickListener(this); dialer.setEnabled(false); numpad = (Numpad) findViewById(R.id.numpad); @@ -339,7 +339,7 @@ public class InCallActivity extends Activity implements OnClickListener { videoProgress.setVisibility(View.GONE); - try { + /*try { routeLayout = (LinearLayout) findViewById(R.id.routesLayout); audioRoute = (TextView) findViewById(R.id.audioRoute); audioRoute.setOnClickListener(this); @@ -351,7 +351,7 @@ public class InCallActivity extends Activity implements OnClickListener { routeBluetooth.setOnClickListener(this); } catch (NullPointerException npe) { Log.e("Bluetooth: Audio routes menu disabled on tablets for now (1)"); - } + }*/ switchCamera = (ImageView) findViewById(R.id.switchCamera); switchCamera.setOnClickListener(this); @@ -457,7 +457,7 @@ public class InCallActivity extends Activity implements OnClickListener { speaker.setEnabled(true); } transfer.setEnabled(true); - pause.setEnabled(true); + //pause.setEnabled(true); dialer.setEnabled(true); conference.setEnabled(true); diff --git a/src/org/linphone/IncomingCallActivity.java b/src/org/linphone/IncomingCallActivity.java index 1e04f85fa..f32889de2 100644 --- a/src/org/linphone/IncomingCallActivity.java +++ b/src/org/linphone/IncomingCallActivity.java @@ -34,6 +34,7 @@ import android.app.Activity; import android.net.Uri; import android.os.Bundle; import android.view.KeyEvent; +import android.view.View; import android.view.WindowManager; import android.widget.ImageView; import android.widget.TextView; @@ -76,6 +77,22 @@ public class IncomingCallActivity extends Activity implements LinphoneSliderTrig int flags = WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; getWindow().addFlags(flags); + ImageView accept = (ImageView) findViewById(R.id.accept); + accept.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + answer(); + } + }); + + ImageView decline = (ImageView) findViewById(R.id.decline); + decline.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + decline(); + } + }); + // "Dial-to-answer" widget for incoming calls. mListener = new LinphoneCoreListenerBase(){ diff --git a/src/org/linphone/OutgoingCallActivity.java b/src/org/linphone/OutgoingCallActivity.java new file mode 100644 index 000000000..ddf42f3d3 --- /dev/null +++ b/src/org/linphone/OutgoingCallActivity.java @@ -0,0 +1,192 @@ +/* +IncomingCallActivity.java +Copyright (C) 2011 Belledonne Communications, Grenoble, France + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ +package org.linphone; + +import java.util.List; + +import org.linphone.core.LinphoneAddress; +import org.linphone.core.LinphoneCall; +import org.linphone.core.LinphoneCall.State; +import org.linphone.core.LinphoneCallParams; +import org.linphone.core.LinphoneCore; +import org.linphone.core.LinphoneCoreListenerBase; +import org.linphone.mediastream.Log; +import org.linphone.ui.LinphoneSliders; +import org.linphone.ui.LinphoneSliders.LinphoneSliderTriggered; + +import android.app.Activity; +import android.net.Uri; +import android.os.Bundle; +import android.view.KeyEvent; +import android.view.WindowManager; +import android.widget.ImageView; +import android.widget.TextView; +import android.widget.Toast; + +/** + * Activity displayed when a call comes in. + * It should bypass the screen lock mechanism. + * + * @author Guillaume Beraudo + */ +public class OutgoingCallActivity extends Activity { + + private static OutgoingCallActivity instance; + + private TextView mNameView; + private TextView mNumberView; + private ImageView mPictureView; + private LinphoneCall mCall; + private LinphoneCoreListenerBase mListener; + + public static OutgoingCallActivity instance() { + return instance; + } + + public static boolean isInstanciated() { + return instance != null; + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + setContentView(R.layout.incoming); + + mNameView = (TextView) findViewById(R.id.incoming_caller_name); + mNumberView = (TextView) findViewById(R.id.incoming_caller_number); + mPictureView = (ImageView) findViewById(R.id.incoming_picture); + + // set this flag so this activity will stay in front of the keyguard + int flags = WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; + getWindow().addFlags(flags); + + // "Dial-to-answer" widget for incoming calls. + + mListener = new LinphoneCoreListenerBase(){ + @Override + public void callState(LinphoneCore lc, LinphoneCall call, LinphoneCall.State state, String message) { + if (call == mCall && State.CallEnd == state) { + finish(); + } + if (state == State.StreamsRunning) { + // The following should not be needed except some devices need it (e.g. Galaxy S). + LinphoneManager.getLc().enableSpeaker(LinphoneManager.getLc().isSpeakerEnabled()); + } + } + }; + + super.onCreate(savedInstanceState); + instance = this; + } + + @Override + protected void onResume() { + super.onResume(); + instance = this; + LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); + if (lc != null) { + lc.addListener(mListener); + } + + // Only one call ringing at a time is allowed + if (LinphoneManager.getLcIfManagerNotDestroyedOrNull() != null) { + List calls = LinphoneUtils.getLinphoneCalls(LinphoneManager.getLc()); + for (LinphoneCall call : calls) { + if (State.IncomingReceived == call.getState()) { + mCall = call; + break; + } + } + } + if (mCall == null) { + Log.e("Couldn't find incoming call"); + finish(); + return; + } + LinphoneAddress address = mCall.getRemoteAddress(); + // May be greatly sped up using a drawable cache + Contact contact = ContactsManager.getInstance().findContactWithAddress(getContentResolver(), address); + //LinphoneUtils.setImagePictureFromUri(this, mPictureView, contact != null ? contact.getPhotoUri() : null, + // contact != null ? contact.getThumbnailUri() : null, R.drawable.unknown_small); + + // To be done after findUriPictureOfContactAndSetDisplayName called + mNameView.setText(contact != null ? contact.getName() : ""); + if (getResources().getBoolean(R.bool.only_display_username_if_unknown)) { + mNumberView.setText(address.getUserName()); + } else { + mNumberView.setText(address.asStringUriOnly()); + } + } + + @Override + protected void onPause() { + LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); + if (lc != null) { + lc.removeListener(mListener); + } + super.onPause(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + instance = null; + } + + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) { + if (LinphoneManager.isInstanciated() && (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_HOME)) { + LinphoneManager.getLc().terminateCall(mCall); + finish(); + } + return super.onKeyDown(keyCode, event); + } + + + + private void decline() { + LinphoneManager.getLc().terminateCall(mCall); + } + + private void answer() { + LinphoneCallParams params = LinphoneManager.getLc().createDefaultCallParameters(); + + boolean isLowBandwidthConnection = !LinphoneUtils.isHighBandwidthConnection(this); + if (isLowBandwidthConnection) { + params.enableLowBandwidth(true); + Log.d("Low bandwidth enabled in call params"); + } + + if (!LinphoneManager.getInstance().acceptCallWithParams(mCall, params)) { + // the above method takes care of Samsung Galaxy S + Toast.makeText(this, R.string.couldnt_accept_call, Toast.LENGTH_LONG).show(); + } else { + if (!LinphoneActivity.isInstanciated()) { + return; + } + final LinphoneCallParams remoteParams = mCall.getRemoteParams(); + if (remoteParams != null && remoteParams.getVideoEnabled() && LinphonePreferences.instance().shouldAutomaticallyAcceptVideoRequests()) { + LinphoneActivity.instance().startVideoActivity(mCall); + } else { + LinphoneActivity.instance().startIncallActivity(mCall); + } + } + } + +}