2015-11-19 10:21:19 -08:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
|
|
|
import android.animation.Animator;
|
|
|
|
import android.annotation.TargetApi;
|
|
|
|
import android.content.res.Configuration;
|
|
|
|
import android.os.Build;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewAnimationUtils;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.animation.DecelerateInterpolator;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
|
2020-12-04 18:31:58 -05:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
2022-05-19 16:26:03 -04:00
|
|
|
import org.signal.qr.QrScannerView;
|
|
|
|
import org.signal.qr.kitkat.ScanListener;
|
|
|
|
import org.thoughtcrime.securesms.util.LifecycleDisposable;
|
2015-11-19 10:21:19 -08:00
|
|
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
|
|
|
|
2020-06-22 17:01:40 -07:00
|
|
|
public class DeviceAddFragment extends LoggingFragment {
|
2015-11-19 10:21:19 -08:00
|
|
|
|
2022-05-19 16:26:03 -04:00
|
|
|
private final LifecycleDisposable lifecycleDisposable = new LifecycleDisposable();
|
|
|
|
|
|
|
|
private LinearLayout overlay;
|
|
|
|
private ImageView devicesImage;
|
|
|
|
private ScanListener scanListener;
|
2015-11-19 10:21:19 -08:00
|
|
|
|
|
|
|
@Override
|
2019-05-22 13:51:56 -03:00
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup viewGroup, Bundle bundle) {
|
2022-05-19 16:26:03 -04:00
|
|
|
ViewGroup container = ViewUtil.inflate(inflater, viewGroup, R.layout.device_add_fragment);
|
|
|
|
this.overlay = container.findViewById(R.id.overlay);
|
|
|
|
QrScannerView scannerView = container.findViewById(R.id.scanner);
|
|
|
|
this.devicesImage = container.findViewById(R.id.devices);
|
2015-11-19 10:21:19 -08:00
|
|
|
|
|
|
|
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
|
|
|
this.overlay.setOrientation(LinearLayout.HORIZONTAL);
|
|
|
|
} else {
|
|
|
|
this.overlay.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
}
|
|
|
|
|
2021-05-13 10:11:07 -03:00
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
2022-05-19 16:26:03 -04:00
|
|
|
container.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
|
2021-05-13 10:11:07 -03:00
|
|
|
@TargetApi(21)
|
2015-11-19 10:21:19 -08:00
|
|
|
@Override
|
|
|
|
public void onLayoutChange(View v, int left, int top, int right, int bottom,
|
|
|
|
int oldLeft, int oldTop, int oldRight, int oldBottom)
|
|
|
|
{
|
|
|
|
v.removeOnLayoutChangeListener(this);
|
|
|
|
|
|
|
|
Animator reveal = ViewAnimationUtils.createCircularReveal(v, right, bottom, 0, (int) Math.hypot(right, bottom));
|
|
|
|
reveal.setInterpolator(new DecelerateInterpolator(2f));
|
|
|
|
reveal.setDuration(800);
|
|
|
|
reveal.start();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-05-19 16:26:03 -04:00
|
|
|
scannerView.start(getViewLifecycleOwner());
|
2015-11-19 10:21:19 -08:00
|
|
|
|
2022-05-19 16:26:03 -04:00
|
|
|
lifecycleDisposable.bindTo(getViewLifecycleOwner());
|
|
|
|
lifecycleDisposable.add(scannerView.getQrData().subscribe(qrData -> {
|
|
|
|
if (scanListener != null) {
|
|
|
|
scanListener.onQrDataFound(qrData);
|
|
|
|
}
|
|
|
|
}));
|
2015-11-19 10:21:19 -08:00
|
|
|
|
2022-05-19 16:26:03 -04:00
|
|
|
return container;
|
2015-11-19 10:21:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-05-13 10:11:07 -03:00
|
|
|
public void onConfigurationChanged(@NonNull Configuration newConfiguration) {
|
2015-11-19 10:21:19 -08:00
|
|
|
super.onConfigurationChanged(newConfiguration);
|
|
|
|
|
|
|
|
if (newConfiguration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
|
|
|
overlay.setOrientation(LinearLayout.HORIZONTAL);
|
|
|
|
} else {
|
|
|
|
overlay.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public ImageView getDevicesImage() {
|
|
|
|
return devicesImage;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setScanListener(ScanListener scanListener) {
|
|
|
|
this.scanListener = scanListener;
|
|
|
|
}
|
|
|
|
}
|