Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround to add tsdevice:/? string when QR codes won't work #5538

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion res/layout/device_add_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

<org.thoughtcrime.securesms.components.ShapeScrim
android:layout_weight="1"
android:id="@+id/camera_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

Expand All @@ -39,14 +40,35 @@
android:layout_height="wrap_content"
android:tint="@color/gray27"
android:transitionName="devices"
android:layout_marginBottom="16dp"/>
android:layout_marginBottom="3dp"/>

<TextView android:text="@string/device_add_fragment__scan_the_qr_code_displayed_on_the_device_to_link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:textColorSecondary"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:weightSum="1">

<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:singleLine="true"
android:hint="@string/device_link_fragment__enter_qr"
android:id="@+id/qr_code_edit_text"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/device_link_fragment__enter_button"
android:id="@+id/qr_code_text_button"/>

</LinearLayout>
</LinearLayout>
</LinearLayout>

Expand Down
2 changes: 2 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,8 @@

<!-- device_add_fragment -->
<string name="device_add_fragment__scan_the_qr_code_displayed_on_the_device_to_link">Scan the QR code displayed on the device to link</string>
<string name="device_link_fragment__enter_qr">Not working? Enter QR text...</string>
<string name="device_link_fragment__enter_button">Done</string>

<!-- device_link_fragment -->
<string name="device_link_fragment__link_device">Link device</string>
Expand Down
38 changes: 38 additions & 0 deletions src/org/thoughtcrime/securesms/DeviceAddFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.ViewGroup;
import android.view.animation.DecelerateInterpolator;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;

Expand All @@ -28,6 +31,7 @@
import com.google.zxing.common.HybridBinarizer;
import com.google.zxing.qrcode.QRCodeReader;

import org.thoughtcrime.securesms.components.ShapeScrim;
import org.thoughtcrime.securesms.components.camera.CameraView;
import org.thoughtcrime.securesms.components.camera.CameraView.PreviewCallback;
import org.thoughtcrime.securesms.components.camera.CameraView.PreviewFrame;
Expand All @@ -47,13 +51,19 @@ public class DeviceAddFragment extends Fragment implements PreviewCallback {
private PreviewFrame previewFrame;
private ScanningThread scanningThread;
private ScanListener scanListener;
private EditText qrcodeEditText;
private Button qrcodeTextButton;
private ShapeScrim cameraFrame;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup viewGroup, Bundle bundle) {
this.container = ViewUtil.inflate(inflater, viewGroup, R.layout.device_add_fragment);
this.overlay = ViewUtil.findById(this.container, R.id.overlay);
this.scannerView = ViewUtil.findById(this.container, R.id.scanner);
this.devicesImage = ViewUtil.findById(this.container, R.id.devices);
this.cameraFrame = ViewUtil.findById(this.container, R.id.camera_frame);
this.qrcodeEditText = ViewUtil.findById(this.container, R.id.qr_code_edit_text);
this.qrcodeTextButton = ViewUtil.findById(this.container, R.id.qr_code_text_button);
this.scannerView.onResume();
this.scannerView.setPreviewCallback(this);

Expand All @@ -80,6 +90,32 @@ public void onLayoutChange(View v, int left, int top, int right, int bottom,
});
}

qrcodeTextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String url = qrcodeEditText.getText().toString();
if (TextUtils.isEmpty(url)) {
qrcodeEditText.setError("The QR Code Field should not be empty.");
}
//TODO check for correctly formed input here before spamming the server with garbage

Uri uri = Uri.parse(url);
scanListener.onUrlFound(uri);
}
});

qrcodeEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
scannerView.setVisibility(View.GONE);
cameraFrame.setVisibility(View.GONE);
scannerView.onPause();
scanningThread.stopScanning();
}
}
});

return this.container;
}

Expand All @@ -91,6 +127,8 @@ public void onResume() {
this.previewFrame = null;
this.scanningThread = new ScanningThread();
this.scanningThread.start();
scannerView.setVisibility(View.VISIBLE);
cameraFrame.setVisibility(View.VISIBLE);
}

@Override
Expand Down