Some fix for qrcode, but this is crash in zxing lib

This commit is contained in:
Erwan Croze 2018-04-15 17:32:59 +02:00
parent 93b2aec9b5
commit 1e1db71a00
6 changed files with 54 additions and 21 deletions

View file

@ -2,10 +2,11 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/qrcode_frame" android:id="@+id/qrcode_frame"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
android:screenOrientation="portrait" >
<org.linphone.mediastream.video.display.GL2JNIView <SurfaceView
android:id="@+id/qrcodeCaptureSurface" android:id="@+id/qrcodeCaptureSurface"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"

View file

@ -64,6 +64,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;
@ -334,11 +335,11 @@ private static AssistantActivity instance;
} }
public void checkAndRequestAudioPermission() { public void checkAndRequestAudioPermission() {
checkAndRequestPermission(Manifest.permission.RECORD_AUDIO, 0); checkAndRequestPermission(Manifest.permission.RECORD_AUDIO, PERMISSIONS_REQUEST_RECORD_AUDIO);
} }
public void checkAndRequestVideoPermission() { public void checkAndRequestVideoPermission() {
checkAndRequestPermission(Manifest.permission.CAMERA, 0); checkAndRequestPermission(Manifest.permission.CAMERA, PERMISSIONS_REQUEST_CAMERA);
} }
public void checkAndRequestPermission(String permission, int result) { public void checkAndRequestPermission(String permission, int result) {
@ -361,10 +362,9 @@ private static AssistantActivity instance;
switch (requestCode) { switch (requestCode) {
case PERMISSIONS_REQUEST_CAMERA: case PERMISSIONS_REQUEST_CAMERA:
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
break; displayQRCodeReader();
case PERMISSIONS_ENABLED_CAMERA: }
break; break;
case PERMISSIONS_REQUEST_RECORD_AUDIO: case PERMISSIONS_REQUEST_RECORD_AUDIO:
LinphoneUtils.dispatchOnUIThread(new Runnable() { LinphoneUtils.dispatchOnUIThread(new Runnable() {
@ -523,10 +523,15 @@ private static AssistantActivity instance;
} }
public void displayQRCodeReader() { public void displayQRCodeReader() {
fragment = new QrcodeFragment(); if (getPackageManager().checkPermission(Manifest.permission.CAMERA,
changeFragment(fragment); getPackageName()) != PackageManager.PERMISSION_GRANTED) {
currentFragment = AssistantFragmentsEnum.QRCODE_READER; checkAndRequestVideoPermission();
back.setVisibility(View.VISIBLE); } else {
fragment = new QrcodeFragment();
changeFragment(fragment);
currentFragment = AssistantFragmentsEnum.QRCODE_READER;
back.setVisibility(View.VISIBLE);
}
} }
public void displayCountryChooser() { public void displayCountryChooser() {
@ -804,6 +809,15 @@ private static AssistantActivity instance;
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, * This class reads a JSON file containing Country-specific phone number description,
* and allows to present them into a ListView * and allows to present them into a ListView

View file

@ -20,6 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
import android.app.Fragment; import android.app.Fragment;
import android.opengl.GLSurfaceView;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.SurfaceView; import android.view.SurfaceView;
@ -45,7 +46,7 @@ public class QrcodeFragment extends Fragment {
} }
private void enableQrcodeReader(boolean enable) { private void enableQrcodeReader(boolean enable) {
//LinphoneManager.getLc().enableQrcodeVideoPreview(enable); LinphoneManager.getLc().enableQrcodeVideoPreview(enable);
LinphoneManager.getLc().enableVideoPreview(enable); LinphoneManager.getLc().enableVideoPreview(enable);
} }
@ -74,8 +75,7 @@ public class QrcodeFragment extends Fragment {
} }
public void onVideoPreviewSurfaceReady(AndroidVideoWindowImpl vw, SurfaceView surface) { public void onVideoPreviewSurfaceReady(AndroidVideoWindowImpl vw, SurfaceView surface) {
mQrcodeView = surface; LinphoneManager.getLc().setNativePreviewWindowId(androidVideoWindowImpl);
LinphoneManager.getLc().setNativePreviewWindowId(vw);
} }
public void onVideoPreviewSurfaceDestroyed(AndroidVideoWindowImpl vw) { public void onVideoPreviewSurfaceDestroyed(AndroidVideoWindowImpl vw) {
@ -84,27 +84,43 @@ public class QrcodeFragment extends Fragment {
}); });
enableQrcodeReader(true); enableQrcodeReader(true);
LinphoneManager.getLc().setQrcodeDecodeRect(500,220,280,280); //LinphoneManager.getLc().setQrcodeDecodeRect(500,220,280,280);
} }
@Override @Override
public void onStart() { public void onStart() {
AssistantActivity.instance().checkAndRequestVideoPermission();
super.onStart(); super.onStart();
} }
@Override @Override
public void onResume() { public void onResume() {
launchQrcodeReader(); launchQrcodeReader();
if (androidVideoWindowImpl != null) {
synchronized (androidVideoWindowImpl) {
LinphoneManager.getLc().setNativePreviewWindowId(androidVideoWindowImpl);
}
}
super.onResume(); super.onResume();
} }
@Override @Override
public void onPause() { public void onPause() {
LinphoneManager.getLc().setNativePreviewWindowId(null); if (androidVideoWindowImpl != null) {
androidVideoWindowImpl.release(); synchronized (androidVideoWindowImpl) {
LinphoneManager.getLc().setNativePreviewWindowId(null);
}
}
enableQrcodeReader(false); enableQrcodeReader(false);
setBackCamera(false); setBackCamera(false);
super.onPause(); super.onPause();
} }
@Override
public void onDestroy() {
if (androidVideoWindowImpl != null) {
androidVideoWindowImpl.release();
androidVideoWindowImpl = null;
}
super.onDestroy();
}
} }

View file

@ -21,9 +21,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import org.linphone.LinphoneManager; import org.linphone.LinphoneManager;
import org.linphone.LinphonePreferences; import org.linphone.LinphonePreferences;
import org.linphone.Manifest;
import org.linphone.R; import org.linphone.R;
import android.app.Fragment; import android.app.Fragment;
import android.content.pm.PackageManager;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;

@ -1 +1 @@
Subproject commit 451f75275ccb37866f4808c79c62c5f360980d17 Subproject commit 6638137dcb941ad2ae51cf9bd36c6407075dc0d5

@ -1 +1 @@
Subproject commit a46973154acaab7ea7aca926e382acff4445bb17 Subproject commit bf220563fef1d18fb6a0bd3c388951dede6ecf07