First try to implement Qrcode view on assistant
This commit is contained in:
parent
91fc847fd3
commit
14e16907c5
11 changed files with 211 additions and 29 deletions
|
@ -59,5 +59,18 @@
|
|||
android:paddingRight="10dp"
|
||||
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>
|
15
res/layout/qrcode.xml
Normal file
15
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">
|
||||
|
||||
|
||||
<org.linphone.mediastream.video.display.GL2JNIView
|
||||
android:id="@+id/qrcodeCaptureSurface"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentRight="true" />
|
||||
|
||||
</RelativeLayout>
|
|
@ -1,20 +1,20 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/video_frame"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:id="@+id/video_frame"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<org.linphone.mediastream.video.display.GL2JNIView
|
||||
android:visibility="visible"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="match_parent"
|
||||
android:id="@+id/videoSurface" />
|
||||
<org.linphone.mediastream.video.display.GL2JNIView
|
||||
android:visibility="visible"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="match_parent"
|
||||
android:id="@+id/videoSurface" />
|
||||
|
||||
<SurfaceView
|
||||
android:id="@+id/videoCaptureSurface"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentRight="true" />
|
||||
<SurfaceView
|
||||
android:id="@+id/videoCaptureSurface"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentRight="true" />
|
||||
|
||||
</RelativeLayout>
|
|
@ -84,6 +84,7 @@
|
|||
<string name="assistant_generic_account">Use SIP account</string>
|
||||
<string name="assistant_remote_provisioning_title">Fetch remote configuration</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_ec_calibration">Echo canceler calibration in progress</string>
|
||||
<string name="assistant_remote_provisioning_login">Enter your login</string>
|
||||
|
|
|
@ -1302,7 +1302,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onQrcodeFounded(Core lc, String result) {
|
||||
public void onQrcodeFound(Core lc, String result) {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -100,6 +100,8 @@ private static AssistantActivity instance;
|
|||
private boolean remoteProvisioningInProgress;
|
||||
private boolean echoCancellerAlreadyDone;
|
||||
private static final int PERMISSIONS_REQUEST_RECORD_AUDIO = 201;
|
||||
private static final int PERMISSIONS_REQUEST_CAMERA = 202;
|
||||
private static final int PERMISSIONS_ENABLED_CAMERA = 203;
|
||||
private AccountCreator mAccountCreator;
|
||||
private CountryListAdapter countryListAdapter;
|
||||
|
||||
|
@ -190,6 +192,16 @@ private static AssistantActivity instance;
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onQrcodeFound(Core lc, String result) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(AssistantActivity.instance());
|
||||
builder.setMessage("QRCODE found: " + result);
|
||||
builder.setCancelable(false);
|
||||
builder.setNeutralButton(getString(R.string.ok), null);
|
||||
builder.show();
|
||||
}
|
||||
|
||||
};
|
||||
instance = this;
|
||||
}
|
||||
|
@ -308,6 +320,8 @@ private static AssistantActivity instance;
|
|||
} else {
|
||||
displayCreateAccount();
|
||||
}
|
||||
} else if (currentFragment == AssistantFragmentsEnum.QRCODE_READER) {
|
||||
displayRemoteProvisioning();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -323,6 +337,10 @@ private static AssistantActivity instance;
|
|||
checkAndRequestPermission(Manifest.permission.RECORD_AUDIO, 0);
|
||||
}
|
||||
|
||||
public void checkAndRequestVideoPermission() {
|
||||
checkAndRequestPermission(Manifest.permission.CAMERA, 0);
|
||||
}
|
||||
|
||||
public void checkAndRequestPermission(String permission, int result) {
|
||||
int permissionGranted = getPackageManager().checkPermission(permission, getPackageName());
|
||||
Log.i("[Permission] " + permission + " is " + (permissionGranted == PackageManager.PERMISSION_GRANTED ? "granted" : "denied"));
|
||||
|
@ -336,17 +354,30 @@ private static AssistantActivity instance;
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, final int[] grantResults) {
|
||||
for (int i = 0; i < permissions.length; i++) {
|
||||
Log.i("[Permission] " + permissions[i] + " is " + (grantResults[i] == PackageManager.PERMISSION_GRANTED ? "granted" : "denied"));
|
||||
}
|
||||
|
||||
if (requestCode == PERMISSIONS_REQUEST_RECORD_AUDIO) {
|
||||
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
launchEchoCancellerCalibration(true);
|
||||
} else {
|
||||
isEchoCalibrationFinished();
|
||||
}
|
||||
switch (requestCode) {
|
||||
case PERMISSIONS_REQUEST_CAMERA:
|
||||
|
||||
break;
|
||||
case PERMISSIONS_ENABLED_CAMERA:
|
||||
|
||||
break;
|
||||
case PERMISSIONS_REQUEST_RECORD_AUDIO:
|
||||
LinphoneUtils.dispatchOnUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
launchEchoCancellerCalibration(true);
|
||||
} else {
|
||||
isEchoCalibrationFinished();
|
||||
}
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -491,6 +522,13 @@ private static AssistantActivity instance;
|
|||
back.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
public void displayQRCodeReader() {
|
||||
fragment = new QrcodeFragment();
|
||||
changeFragment(fragment);
|
||||
currentFragment = AssistantFragmentsEnum.QRCODE_READER;
|
||||
back.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
public void displayCountryChooser() {
|
||||
fragment = new CountryListFragment();
|
||||
changeFragment(fragment);
|
||||
|
|
|
@ -28,5 +28,6 @@ public enum AssistantFragmentsEnum {
|
|||
LOGIN,
|
||||
REMOTE_PROVISIONING,
|
||||
ECHO_CANCELLER_CALIBRATION,
|
||||
DOWNLOAD_CODEC;
|
||||
DOWNLOAD_CODEC,
|
||||
QRCODE_READER
|
||||
}
|
||||
|
|
110
src/android/org/linphone/assistant/QrcodeFragment.java
Normal file
110
src/android/org/linphone/assistant/QrcodeFragment.java
Normal file
|
@ -0,0 +1,110 @@
|
|||
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.SurfaceView;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import org.linphone.LinphoneManager;
|
||||
import org.linphone.R;
|
||||
import org.linphone.mediastream.video.AndroidVideoWindowImpl;
|
||||
import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration;
|
||||
|
||||
public class QrcodeFragment extends Fragment {
|
||||
private SurfaceView mQrcodeView;
|
||||
private AndroidVideoWindowImpl androidVideoWindowImpl;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.qrcode, container, false);
|
||||
|
||||
mQrcodeView = (SurfaceView) view.findViewById(R.id.qrcodeCaptureSurface);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
private void enableQrcodeReader(boolean enable) {
|
||||
//LinphoneManager.getLc().enableQrcodeVideoPreview(enable);
|
||||
LinphoneManager.getLc().enableVideoPreview(enable);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
androidVideoWindowImpl = new AndroidVideoWindowImpl(null, mQrcodeView, new AndroidVideoWindowImpl.VideoWindowListener() {
|
||||
public void onVideoRenderingSurfaceReady(AndroidVideoWindowImpl vw, SurfaceView surface) {
|
||||
|
||||
}
|
||||
|
||||
public void onVideoRenderingSurfaceDestroyed(AndroidVideoWindowImpl vw) {
|
||||
|
||||
}
|
||||
|
||||
public void onVideoPreviewSurfaceReady(AndroidVideoWindowImpl vw, SurfaceView surface) {
|
||||
mQrcodeView = surface;
|
||||
LinphoneManager.getLc().setNativePreviewWindowId(vw);
|
||||
}
|
||||
|
||||
public void onVideoPreviewSurfaceDestroyed(AndroidVideoWindowImpl vw) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
enableQrcodeReader(true);
|
||||
LinphoneManager.getLc().setQrcodeDecodeRect(500,220,280,280);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
AssistantActivity.instance().checkAndRequestVideoPermission();
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
launchQrcodeReader();
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
LinphoneManager.getLc().setNativePreviewWindowId(null);
|
||||
androidVideoWindowImpl.release();
|
||||
enableQrcodeReader(false);
|
||||
setBackCamera(false);
|
||||
super.onPause();
|
||||
}
|
||||
}
|
|
@ -36,7 +36,7 @@ import android.widget.EditText;
|
|||
|
||||
public class RemoteProvisioningFragment extends Fragment implements OnClickListener, TextWatcher{
|
||||
private EditText remoteProvisioningUrl;
|
||||
private Button apply;
|
||||
private Button apply, qrcode;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
|
@ -45,6 +45,8 @@ public class RemoteProvisioningFragment extends Fragment implements OnClickListe
|
|||
|
||||
remoteProvisioningUrl = (EditText) view.findViewById(R.id.assistant_remote_provisioning_url);
|
||||
remoteProvisioningUrl.addTextChangedListener(this);
|
||||
qrcode = (Button) view.findViewById(R.id.assistant_qrcode);
|
||||
qrcode.setOnClickListener(this);
|
||||
apply = (Button) view.findViewById(R.id.assistant_apply);
|
||||
apply.setEnabled(false);
|
||||
apply.setOnClickListener(this);
|
||||
|
@ -62,6 +64,8 @@ public class RemoteProvisioningFragment extends Fragment implements OnClickListe
|
|||
LinphonePreferences.instance().setRemoteProvisioningUrl(url);
|
||||
LinphoneManager.getInstance().restartCore();
|
||||
AssistantActivity.instance().setCoreListener();
|
||||
} else if (id == R.id.assistant_qrcode) {
|
||||
AssistantActivity.instance().displayQRCodeReader();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit f985c8a7c3b84df3de6bb557c8fe0eabcb56ab05
|
||||
Subproject commit 451f75275ccb37866f4808c79c62c5f360980d17
|
|
@ -1 +1 @@
|
|||
Subproject commit 9c69731add9f4d9fa9642ac6b163d610d48bcae8
|
||||
Subproject commit a46973154acaab7ea7aca926e382acff4445bb17
|
Loading…
Reference in a new issue