Skip to content

Commit

Permalink
Merge pull request #357 from bitmold/paste_bridges_ET_fix
Browse files Browse the repository at this point in the history
Fixes #356 Can't Scroll through pasted bridges with soft keyboard open
  • Loading branch information
n8fr8 committed Jul 13, 2020
2 parents 4940449 + 2a389e0 commit 85f6f30
Showing 1 changed file with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* See LICENSE for licensing information */
package org.torproject.android.ui.onboarding;

import android.annotation.SuppressLint;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Intent;
Expand All @@ -10,8 +11,10 @@
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
Expand Down Expand Up @@ -68,6 +71,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
}

mEtPastedBridges = findViewById(R.id.etPastedBridges);
configureMultilineEditTextInScrollView(mEtPastedBridges);
mEtPastedBridges.setText(bridges);
mEtPastedBridges.addTextChangedListener(this);

Expand All @@ -81,9 +85,9 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
finish();

return true;
return true;
}

return super.onOptionsItemSelected(item);
Expand Down Expand Up @@ -155,8 +159,7 @@ protected void onActivityResult(int request, int response, Intent data) {
results = results.substring(urlIdx + 3);

setNewBridges(results);
}
else {
} else {
JSONArray bridgeJson = new JSONArray(results);
StringBuilder bridgeLines = new StringBuilder();

Expand All @@ -167,8 +170,7 @@ protected void onActivityResult(int request, int response, Intent data) {

setNewBridges(bridgeLines.toString());
}
}
catch (Exception e) {
} catch (Exception e) {
Log.e(getClass().getSimpleName(), "unsupported", e);
}
}
Expand Down Expand Up @@ -216,4 +218,23 @@ private void setNewBridges(String bridges, boolean updateEditText) {
intent.setAction(TorServiceConstants.CMD_SIGNAL_HUP);
startService(intent);
}

// configures an EditText we assume to be multiline and nested in a ScrollView to be independently scrollable
@SuppressLint("ClickableViewAccessibility")
private static void configureMultilineEditTextInScrollView(EditText et) {
et.setVerticalScrollBarEnabled(true);
et.setOverScrollMode(View.OVER_SCROLL_ALWAYS);
et.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET);
et.setMovementMethod(ScrollingMovementMethod.getInstance());
et.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.getParent().requestDisallowInterceptTouchEvent(true);
if ((event.getAction() & MotionEvent.ACTION_UP) != 0 && (event.getActionMasked() & MotionEvent.ACTION_UP) != 0) {
v.getParent().requestDisallowInterceptTouchEvent(false);
}
return false;
}
});
}
}

0 comments on commit 85f6f30

Please sign in to comment.