Merge branch 'feature/qrcode_integration' into feature/release-4.1
This commit is contained in:
commit
5d44961eda
10 changed files with 201 additions and 30 deletions
|
@ -1450,6 +1450,9 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
|
||||||
@Override
|
@Override
|
||||||
public void onChatRoomStateChanged(Core lc, ChatRoom cr, ChatRoom.State state) {}
|
public void onChatRoomStateChanged(Core lc, ChatRoom cr, ChatRoom.State state) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onQrcodeFound(Core lc, String result) {}
|
||||||
|
|
||||||
public void onCallEncryptionChanged(
|
public void onCallEncryptionChanged(
|
||||||
Core lc, Call call, boolean encrypted, String authenticationToken) {}
|
Core lc, Call call, boolean encrypted, String authenticationToken) {}
|
||||||
|
|
||||||
|
@ -2017,8 +2020,6 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onQrcodeFound(Core lc, String something) {}
|
|
||||||
|
|
||||||
public interface AddressType {
|
public interface AddressType {
|
||||||
CharSequence getText();
|
CharSequence getText();
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.res.Configuration;
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -85,6 +86,7 @@ public class AssistantActivity extends Activity
|
||||||
ActivityCompat.OnRequestPermissionsResultCallback,
|
ActivityCompat.OnRequestPermissionsResultCallback,
|
||||||
AccountCreatorListener {
|
AccountCreatorListener {
|
||||||
private static final int PERMISSIONS_REQUEST_RECORD_AUDIO = 201;
|
private static final int PERMISSIONS_REQUEST_RECORD_AUDIO = 201;
|
||||||
|
private static final int PERMISSIONS_REQUEST_CAMERA = 202;
|
||||||
private static AssistantActivity instance;
|
private static AssistantActivity instance;
|
||||||
public DialPlan country;
|
public DialPlan country;
|
||||||
public String phone_number;
|
public String phone_number;
|
||||||
|
@ -334,6 +336,8 @@ public class AssistantActivity extends Activity
|
||||||
} else {
|
} else {
|
||||||
displayCreateAccount();
|
displayCreateAccount();
|
||||||
}
|
}
|
||||||
|
} else if (currentFragment == AssistantFragmentsEnum.QRCODE_READER) {
|
||||||
|
displayRemoteProvisioning("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,7 +351,12 @@ public class AssistantActivity extends Activity
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkAndRequestAudioPermission() {
|
public void checkAndRequestAudioPermission() {
|
||||||
checkAndRequestPermission(Manifest.permission.RECORD_AUDIO, 0);
|
checkAndRequestPermission(
|
||||||
|
Manifest.permission.RECORD_AUDIO, PERMISSIONS_REQUEST_RECORD_AUDIO);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkAndRequestVideoPermission() {
|
||||||
|
checkAndRequestPermission(Manifest.permission.CAMERA, PERMISSIONS_REQUEST_CAMERA);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkAndRequestPermission(String permission, int result) {
|
public void checkAndRequestPermission(String permission, int result) {
|
||||||
|
@ -371,7 +380,7 @@ public class AssistantActivity extends Activity
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRequestPermissionsResult(
|
public void onRequestPermissionsResult(
|
||||||
int requestCode, String[] permissions, int[] grantResults) {
|
int requestCode, String[] permissions, final int[] grantResults) {
|
||||||
for (int i = 0; i < permissions.length; i++) {
|
for (int i = 0; i < permissions.length; i++) {
|
||||||
Log.i(
|
Log.i(
|
||||||
"[Permission] "
|
"[Permission] "
|
||||||
|
@ -382,12 +391,19 @@ public class AssistantActivity extends Activity
|
||||||
: "denied"));
|
: "denied"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requestCode == PERMISSIONS_REQUEST_RECORD_AUDIO) {
|
switch (requestCode) {
|
||||||
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
case PERMISSIONS_REQUEST_CAMERA:
|
||||||
launchEchoCancellerCalibration(true);
|
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
} else {
|
displayQRCodeReader();
|
||||||
isEchoCalibrationFinished();
|
}
|
||||||
}
|
break;
|
||||||
|
case PERMISSIONS_REQUEST_RECORD_AUDIO:
|
||||||
|
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
launchEchoCancellerCalibration(true);
|
||||||
|
} else {
|
||||||
|
isEchoCalibrationFinished();
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -543,13 +559,28 @@ public class AssistantActivity extends Activity
|
||||||
back.setVisibility(View.VISIBLE);
|
back.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void displayRemoteProvisioning() {
|
public void displayRemoteProvisioning(String url) {
|
||||||
fragment = new RemoteProvisioningFragment();
|
fragment = new RemoteProvisioningFragment();
|
||||||
|
Bundle extra = new Bundle();
|
||||||
|
extra.putString("RemoteUrl", url);
|
||||||
|
fragment.setArguments(extra);
|
||||||
changeFragment(fragment);
|
changeFragment(fragment);
|
||||||
currentFragment = AssistantFragmentsEnum.REMOTE_PROVISIONING;
|
currentFragment = AssistantFragmentsEnum.REMOTE_PROVISIONING;
|
||||||
back.setVisibility(View.VISIBLE);
|
back.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void displayQRCodeReader() {
|
||||||
|
if (getPackageManager().checkPermission(Manifest.permission.CAMERA, getPackageName())
|
||||||
|
!= PackageManager.PERMISSION_GRANTED) {
|
||||||
|
checkAndRequestVideoPermission();
|
||||||
|
} else {
|
||||||
|
fragment = new QrCodeFragment();
|
||||||
|
changeFragment(fragment);
|
||||||
|
currentFragment = AssistantFragmentsEnum.QRCODE_READER;
|
||||||
|
back.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void displayCountryChooser() {
|
public void displayCountryChooser() {
|
||||||
fragment = new CountryListFragment();
|
fragment = new CountryListFragment();
|
||||||
changeFragment(fragment);
|
changeFragment(fragment);
|
||||||
|
@ -849,6 +880,14 @@ public class AssistantActivity extends Activity
|
||||||
return countryListAdapter;
|
return countryListAdapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onConfigurationChanged(Configuration newConfig) {
|
||||||
|
super.onConfigurationChanged(newConfig);
|
||||||
|
if (currentFragment == AssistantFragmentsEnum.QRCODE_READER) {
|
||||||
|
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class reads a JSON file containing Country-specific phone number description, and allows
|
* This class reads a JSON file containing Country-specific phone number description, and allows
|
||||||
* to present them into a ListView
|
* to present them into a ListView
|
||||||
|
|
|
@ -28,5 +28,6 @@ public enum AssistantFragmentsEnum {
|
||||||
LOGIN,
|
LOGIN,
|
||||||
REMOTE_PROVISIONING,
|
REMOTE_PROVISIONING,
|
||||||
ECHO_CANCELLER_CALIBRATION,
|
ECHO_CANCELLER_CALIBRATION,
|
||||||
DOWNLOAD_CODEC;
|
DOWNLOAD_CODEC,
|
||||||
|
QRCODE_READER
|
||||||
}
|
}
|
||||||
|
|
99
app/src/main/java/org/linphone/assistant/QrCodeFragment.java
Normal file
99
app/src/main/java/org/linphone/assistant/QrCodeFragment.java
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
package org.linphone.assistant;
|
||||||
|
|
||||||
|
/*
|
||||||
|
QrCodeFragment.java
|
||||||
|
Copyright (C) 2018 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import android.app.Fragment;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.TextureView;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import org.linphone.LinphoneManager;
|
||||||
|
import org.linphone.R;
|
||||||
|
import org.linphone.core.Core;
|
||||||
|
import org.linphone.core.CoreListenerStub;
|
||||||
|
import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration;
|
||||||
|
|
||||||
|
public class QrCodeFragment extends Fragment {
|
||||||
|
private TextureView mQrcodeView;
|
||||||
|
private CoreListenerStub mListener;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(
|
||||||
|
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
View view = inflater.inflate(R.layout.qrcode, container, false);
|
||||||
|
|
||||||
|
mQrcodeView = view.findViewById(R.id.qrcodeCaptureSurface);
|
||||||
|
|
||||||
|
LinphoneManager.getLc().setNativePreviewWindowId(mQrcodeView);
|
||||||
|
|
||||||
|
mListener =
|
||||||
|
new CoreListenerStub() {
|
||||||
|
@Override
|
||||||
|
public void onQrcodeFound(Core lc, String result) {
|
||||||
|
enableQrcodeReader(false);
|
||||||
|
AssistantActivity.instance().displayRemoteProvisioning(result);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void enableQrcodeReader(boolean enable) {
|
||||||
|
LinphoneManager.getLc().enableQrcodeVideoPreview(enable);
|
||||||
|
LinphoneManager.getLc().enableVideoPreview(enable);
|
||||||
|
if (enable) {
|
||||||
|
LinphoneManager.getLc().addListener(mListener);
|
||||||
|
} else {
|
||||||
|
LinphoneManager.getLc().removeListener(mListener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setBackCamera(boolean useBackCamera) {
|
||||||
|
int camId = 0;
|
||||||
|
AndroidCameraConfiguration.AndroidCamera[] cameras =
|
||||||
|
AndroidCameraConfiguration.retrieveCameras();
|
||||||
|
for (AndroidCameraConfiguration.AndroidCamera androidCamera : cameras) {
|
||||||
|
if (androidCamera.frontFacing == !useBackCamera) camId = androidCamera.id;
|
||||||
|
}
|
||||||
|
String[] devices = LinphoneManager.getLc().getVideoDevicesList();
|
||||||
|
String newDevice = devices[camId];
|
||||||
|
LinphoneManager.getLc().setVideoDevice(newDevice);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void launchQrcodeReader() {
|
||||||
|
setBackCamera(true);
|
||||||
|
|
||||||
|
enableQrcodeReader(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
launchQrcodeReader();
|
||||||
|
super.onResume();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
enableQrcodeReader(false);
|
||||||
|
// setBackCamera(false);
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
|
}
|
|
@ -204,14 +204,8 @@ public class RemoteProvisioningActivity extends Activity {
|
||||||
LinphonePreferences.instance().setContext(this); // Needed, else the next call will crash
|
LinphonePreferences.instance().setContext(this); // Needed, else the next call will crash
|
||||||
LinphonePreferences.instance().setRemoteProvisioningUrl(configUri);
|
LinphonePreferences.instance().setRemoteProvisioningUrl(configUri);
|
||||||
|
|
||||||
mHandler.postDelayed(
|
LinphoneManager.getLc().getConfig().sync();
|
||||||
new Runnable() {
|
LinphoneManager.getInstance().restartCore();
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
LinphoneManager.getInstance().restartCore();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void goToLinphoneActivity() {
|
private void goToLinphoneActivity() {
|
||||||
|
|
|
@ -33,19 +33,25 @@ import org.linphone.R;
|
||||||
import org.linphone.settings.LinphonePreferences;
|
import org.linphone.settings.LinphonePreferences;
|
||||||
|
|
||||||
public class RemoteProvisioningFragment extends Fragment implements OnClickListener, TextWatcher {
|
public class RemoteProvisioningFragment extends Fragment implements OnClickListener, TextWatcher {
|
||||||
private EditText remoteProvisioningUrl;
|
private EditText mRemoteProvisioningUrl;
|
||||||
private Button apply;
|
private Button mApply, mQrcode;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(
|
public View onCreateView(
|
||||||
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.assistant_remote_provisioning, container, false);
|
View view = inflater.inflate(R.layout.assistant_remote_provisioning, container, false);
|
||||||
|
|
||||||
remoteProvisioningUrl = view.findViewById(R.id.assistant_remote_provisioning_url);
|
mRemoteProvisioningUrl = view.findViewById(R.id.assistant_remote_provisioning_url);
|
||||||
remoteProvisioningUrl.addTextChangedListener(this);
|
mRemoteProvisioningUrl.addTextChangedListener(this);
|
||||||
apply = view.findViewById(R.id.assistant_apply);
|
mQrcode = view.findViewById(R.id.assistant_qrcode);
|
||||||
apply.setEnabled(false);
|
mQrcode.setOnClickListener(this);
|
||||||
apply.setOnClickListener(this);
|
mApply = view.findViewById(R.id.assistant_apply);
|
||||||
|
mApply.setEnabled(false);
|
||||||
|
mApply.setOnClickListener(this);
|
||||||
|
|
||||||
|
if (getArguments() != null && !getArguments().getString("RemoteUrl").isEmpty()) {
|
||||||
|
mRemoteProvisioningUrl.setText(getArguments().getString("RemoteUrl"));
|
||||||
|
}
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
@ -55,12 +61,14 @@ public class RemoteProvisioningFragment extends Fragment implements OnClickListe
|
||||||
int id = v.getId();
|
int id = v.getId();
|
||||||
|
|
||||||
if (id == R.id.assistant_apply) {
|
if (id == R.id.assistant_apply) {
|
||||||
String url = remoteProvisioningUrl.getText().toString();
|
String url = mRemoteProvisioningUrl.getText().toString();
|
||||||
AssistantActivity.instance().displayRemoteProvisioningInProgressDialog();
|
AssistantActivity.instance().displayRemoteProvisioningInProgressDialog();
|
||||||
LinphonePreferences.instance().setRemoteProvisioningUrl(url);
|
LinphonePreferences.instance().setRemoteProvisioningUrl(url);
|
||||||
LinphoneManager.getLc().getConfig().sync();
|
LinphoneManager.getLc().getConfig().sync();
|
||||||
LinphoneManager.getInstance().restartCore();
|
LinphoneManager.getInstance().restartCore();
|
||||||
AssistantActivity.instance().setCoreListener();
|
AssistantActivity.instance().setCoreListener();
|
||||||
|
} else if (id == R.id.assistant_qrcode) {
|
||||||
|
AssistantActivity.instance().displayQRCodeReader();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +77,7 @@ public class RemoteProvisioningFragment extends Fragment implements OnClickListe
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||||
apply.setEnabled(!remoteProvisioningUrl.getText().toString().isEmpty());
|
mApply.setEnabled(!mRemoteProvisioningUrl.getText().toString().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -72,7 +72,7 @@ public class WelcomeFragment extends Fragment implements OnClickListener {
|
||||||
} else if (id == R.id.create_account) {
|
} else if (id == R.id.create_account) {
|
||||||
AssistantActivity.instance().displayCreateAccount();
|
AssistantActivity.instance().displayCreateAccount();
|
||||||
} else if (id == R.id.remote_provisioning) {
|
} else if (id == R.id.remote_provisioning) {
|
||||||
AssistantActivity.instance().displayRemoteProvisioning();
|
AssistantActivity.instance().displayRemoteProvisioning("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,5 +59,18 @@
|
||||||
android:paddingRight="10dp"
|
android:paddingRight="10dp"
|
||||||
android:layout_marginTop="20dp"/>
|
android:layout_marginTop="20dp"/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/assistant_qrcode"
|
||||||
|
android:text="@string/assistant_launch_qrcode"
|
||||||
|
android:background="@drawable/assistant_button"
|
||||||
|
android:textColor="@drawable/assistant_button_text_color"
|
||||||
|
style="@style/font8"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="40dp"
|
||||||
|
android:paddingLeft="10dp"
|
||||||
|
android:paddingRight="10dp"
|
||||||
|
android:layout_marginTop="20dp"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
15
app/src/main/res/layout/qrcode.xml
Normal file
15
app/src/main/res/layout/qrcode.xml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/qrcode_frame"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:screenOrientation="portrait" >
|
||||||
|
|
||||||
|
<TextureView
|
||||||
|
android:id="@+id/qrcodeCaptureSurface"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:layout_alignParentRight="true" />
|
||||||
|
|
||||||
|
</RelativeLayout>
|
|
@ -92,6 +92,7 @@
|
||||||
<string name="assistant_generic_account">Use SIP account</string>
|
<string name="assistant_generic_account">Use SIP account</string>
|
||||||
<string name="assistant_remote_provisioning_title">Fetch remote configuration</string>
|
<string name="assistant_remote_provisioning_title">Fetch remote configuration</string>
|
||||||
<string name="assistant_fetch_apply">Fetch and apply</string>
|
<string name="assistant_fetch_apply">Fetch and apply</string>
|
||||||
|
<string name="assistant_launch_qrcode">QRCode</string>
|
||||||
<string name="assistant_login">Login</string>
|
<string name="assistant_login">Login</string>
|
||||||
<string name="assistant_ec_calibration">Echo canceler calibration in progress</string>
|
<string name="assistant_ec_calibration">Echo canceler calibration in progress</string>
|
||||||
<string name="assistant_remote_provisioning_login">Enter your login</string>
|
<string name="assistant_remote_provisioning_login">Enter your login</string>
|
||||||
|
|
Loading…
Reference in a new issue