[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [orbot/master] Fixed behaviour on device turn.
commit 1749167ac07d7a0ffdbd6378b55482bbc3143e05
Author: Benjamin Erhart <berhart@xxxxxxxxxxxxxxxxxxx>
Date: Wed Apr 22 13:35:35 2020 +0200
Fixed behaviour on device turn.
---
.../android/ui/onboarding/MoatActivity.java | 55 +++++++++++----
app/src/main/res/layout/activity_moat.xml | 78 +++++++++++++---------
2 files changed, 86 insertions(+), 47 deletions(-)
diff --git a/app/src/main/java/org/torproject/android/ui/onboarding/MoatActivity.java b/app/src/main/java/org/torproject/android/ui/onboarding/MoatActivity.java
index 12ed6e3e..f4e3a107 100644
--- a/app/src/main/java/org/torproject/android/ui/onboarding/MoatActivity.java
+++ b/app/src/main/java/org/torproject/android/ui/onboarding/MoatActivity.java
@@ -24,6 +24,7 @@ import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
+import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
@@ -66,6 +67,7 @@ public class MoatActivity extends AppCompatActivity implements View.OnClickListe
private Button mBtRequest;
private String mChallenge;
+ private byte[] mCaptcha;
private RequestQueue mQueue;
@@ -120,11 +122,29 @@ public class MoatActivity extends AppCompatActivity implements View.OnClickListe
mEtSolution = findViewById(R.id.solutionEt);
mBtRequest = findViewById(R.id.requestBt);
- mIvCaptcha.setVisibility(View.GONE);
mEtSolution.setOnEditorActionListener(this);
- mBtRequest.setEnabled(false);
mBtRequest.setOnClickListener(this);
+ if (savedInstanceState != null) {
+ mOriginalBridges = savedInstanceState.getString("originalBridges");
+ mOriginalBridgeStatus = savedInstanceState.getBoolean("originalBridgeStatus");
+ mChallenge = savedInstanceState.getString("challenge");
+ mCaptcha = savedInstanceState.getByteArray("captcha");
+
+ if (mCaptcha != null) {
+ mProgressBar.setVisibility(View.GONE);
+ mIvCaptcha.setImageBitmap(BitmapFactory.decodeByteArray(mCaptcha, 0, mCaptcha.length));
+ mRequestInProgress = false;
+ }
+ }
+ else {
+ mIvCaptcha.setVisibility(View.GONE);
+ mBtRequest.setEnabled(false);
+
+ mOriginalBridges = Prefs.getBridgesList();
+ mOriginalBridgeStatus = Prefs.bridgesEnabled();
+ }
+
LocalBroadcastManager.getInstance(this).registerReceiver(mBroadcastReceiver,
new IntentFilter(TorServiceConstants.ACTION_STATUS));
}
@@ -149,9 +169,6 @@ public class MoatActivity extends AppCompatActivity implements View.OnClickListe
protected void onResume() {
super.onResume();
- mOriginalBridges = Prefs.getBridgesList();
- mOriginalBridgeStatus = Prefs.bridgesEnabled();
-
sendIntentToService(TorServiceConstants.ACTION_STATUS);
}
@@ -201,13 +218,13 @@ public class MoatActivity extends AppCompatActivity implements View.OnClickListe
}
@Override
- protected void onPause() {
- super.onPause();
+ public void onSaveInstanceState(@NonNull Bundle outState) {
+ super.onSaveInstanceState(outState);
- if (!mSuccess) {
- Prefs.setBridgesList(mOriginalBridges);
- Prefs.putBridgesEnabled(mOriginalBridgeStatus);
- }
+ outState.putString("originalBridges", mOriginalBridges);
+ outState.putBoolean("originalBridgeStatus", mOriginalBridgeStatus);
+ outState.putString("challenge", mChallenge);
+ outState.putByteArray("captcha", mCaptcha);
}
@Override
@@ -215,6 +232,11 @@ public class MoatActivity extends AppCompatActivity implements View.OnClickListe
super.onDestroy();
LocalBroadcastManager.getInstance(this).unregisterReceiver(mBroadcastReceiver);
+
+ if (!mSuccess) {
+ Prefs.setBridgesList(mOriginalBridges);
+ Prefs.putBridgesEnabled(mOriginalBridgeStatus);
+ }
}
private void fetchCaptcha() {
@@ -231,8 +253,8 @@ public class MoatActivity extends AppCompatActivity implements View.OnClickListe
JSONObject data = response.getJSONArray("data").getJSONObject(0);
mChallenge = data.getString("challenge");
- byte[] image = Base64.decode(data.getString("image"), Base64.DEFAULT);
- mIvCaptcha.setImageBitmap(BitmapFactory.decodeByteArray(image, 0, image.length));
+ mCaptcha = Base64.decode(data.getString("image"), Base64.DEFAULT);
+ mIvCaptcha.setImageBitmap(BitmapFactory.decodeByteArray(mCaptcha, 0, mCaptcha.length));
mIvCaptcha.setVisibility(View.VISIBLE);
mEtSolution.setText(null);
mBtRequest.setEnabled(true);
@@ -253,6 +275,9 @@ public class MoatActivity extends AppCompatActivity implements View.OnClickListe
mIvCaptcha.setVisibility(View.GONE);
mBtRequest.setEnabled(false);
+ mChallenge = null;
+ mCaptcha = null;
+
mQueue.add(request);
}
}
@@ -370,7 +395,9 @@ public class MoatActivity extends AppCompatActivity implements View.OnClickListe
sendIntentToService(TorServiceConstants.CMD_SIGNAL_HUP);
- fetchCaptcha();
+ if (mCaptcha == null) {
+ fetchCaptcha();
+ }
break;
}
diff --git a/app/src/main/res/layout/activity_moat.xml b/app/src/main/res/layout/activity_moat.xml
index b0a2b42f..c6a88209 100644
--- a/app/src/main/res/layout/activity_moat.xml
+++ b/app/src/main/res/layout/activity_moat.xml
@@ -22,45 +22,57 @@
</com.google.android.material.appbar.AppBarLayout>
- <TextView
+ <ScrollView
android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_margin="12dp"
- android:text="@string/solve_captcha_instruction" />
-
- <RelativeLayout
- android:layout_width="match_parent"
- android:layout_height="240dp"
- android:layout_margin="12dp">
+ android:layout_height="match_parent">
- <ImageView
- android:id="@+id/captchaIv"
+ <LinearLayout
android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:contentDescription="@string/captcha"
- tools:srcCompat="@tools:sample/backgrounds/scenic" />
+ android:layout_height="wrap_content"
+ android:orientation="vertical" >
- <ProgressBar
- android:id="@+id/progressBar"
- android:layout_width="match_parent"
- android:layout_height="match_parent" />
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_margin="12dp"
+ android:text="@string/solve_captcha_instruction" />
- </RelativeLayout>
+ <RelativeLayout
+ android:layout_width="match_parent"
+ android:layout_height="160dp"
+ android:layout_margin="12dp">
- <EditText
- android:id="@+id/solutionEt"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:autofillHints=""
- android:ems="10"
- android:hint="@string/enter_characters_from_image"
- android:imeOptions="actionSend"
- android:inputType="textShortMessage|text" />
+ <ImageView
+ android:id="@+id/captchaIv"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:contentDescription="@string/captcha"
+ tools:srcCompat="@tools:sample/backgrounds/scenic" />
- <Button
- android:id="@+id/requestBt"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="@string/request_bridges" />
+ <ProgressBar
+ android:id="@+id/progressBar"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" />
+
+ </RelativeLayout>
+
+ <EditText
+ android:id="@+id/solutionEt"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:autofillHints=""
+ android:ems="10"
+ android:hint="@string/enter_characters_from_image"
+ android:imeOptions="actionSend"
+ android:inputType="textShortMessage|text" />
+
+ <Button
+ android:id="@+id/requestBt"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/request_bridges" />
+
+ </LinearLayout>
+ </ScrollView>
</LinearLayout>
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits