Merge remote-tracking branch 'origin/develop' into feature/macgills/modularisation

This commit is contained in:
Sean Mac Gillicuddy 2019-10-16 10:51:01 +01:00
commit 5b484f5f19
4 changed files with 70 additions and 70 deletions

View File

@ -34,8 +34,7 @@ for you. If you prefer to build without Android Studio you must first
set up the Android SDK and then run the command: `./gradlew build ` set up the Android SDK and then run the command: `./gradlew build `
from the root directory of the project. from the root directory of the project.
We utilize different build variants (flavours) to build various We utilize different build variants (flavors) to build various versions of our app. Ensure your build variant is
different versions of our app. Ensure your build variant is
`kiwixDebug` to build the standard app. `kiwixDebug` to build the standard app.
## Libraries Used ## Libraries Used

View File

@ -20,22 +20,22 @@
<body class="content"> <body class="content">
<h2>Contributors</h2> <h2>Contributors</h2>
<a href="mailto:abdulwd97@gmail.com">Abdul Wadood</a><nr> Abdul Wadood<br>
<a href="mailto:adeelzafar619@gmail.com">Adeel Zafar</a><br> Adeel Zafar<br>
<a href="mailto:sood.aditya.08@gmail.com">Aditya Sood</a><br> Aditya Sood<br>
<a href="mailto:ayoubuto@gmail.com">Ayoub Dardory</a><br> Ayoub Dardory<br>
<a href="mailto:cip@gmx.at">Christian Pühringer</a><br> Christian Pühringer<br>
<a href="mailto:elad.keyshawn@gmail.com">Elad Keyshawn</a><br> Elad Keyshawn<br>
<a href="mailto:kelson@kiwix.org">Emmanuel Engelhart</a><br> Emmanuel Engelhart<br>
<a href="mailto:mhutti1@gmail.com">Isaac Hutt</a><br> Isaac Hutt<br>
<a href="mailto:joseph.reeve@googlemail.com">Joseph E. Reeve</a><br> Joseph E. Reeve<br>
<a href="mailto:julianharty@gmail.com">Julian Harty</a><br> Julian Harty<br>
<a href="mailto:rashiq.z@gmail.com">Rashiq Ahmad</a><br> Rashiq Ahmad<br>
<a href="mailto:reg@kiwix.org">Renaud Gaudin</a><br> Renaud Gaudin<br>
<a href="mailto:seantheappdev@gmail.com">Seán Mac Gillicuddy</a><br> Seán Mac Gillicuddy<br>
<a href="mailto:ssiddharth2010@gmail.com">Siddharth Sharma</a><br> Siddharth Sharma<br>
<a href="mailto:sm2030@cam.ac.uk">Souradip Mookerjee</a><br> Souradip Mookerjee<br>
<a href="https://translatewiki.net/wiki/Translating:Kiwix">Translatewiki community</a><br> Translatewiki community<br>
<h2>Licenses</h2> <h2>Licenses</h2>

View File

@ -39,44 +39,44 @@ import org.kiwix.kiwixmobile.core.R;
public class CompatFindActionModeCallback public class CompatFindActionModeCallback
implements ActionMode.Callback, TextWatcher, View.OnClickListener { implements ActionMode.Callback, TextWatcher, View.OnClickListener {
public boolean mIsActive; public boolean isActive;
private View mCustomView; private View customView;
private EditText mEditText; private EditText editText;
private TextView mFindResultsTextView; private TextView findResultsTextView;
private WebView mWebView; private WebView webView;
private InputMethodManager mInput; private InputMethodManager input;
private ActionMode mActionMode; private ActionMode actionMode;
CompatFindActionModeCallback(Context context) { CompatFindActionModeCallback(Context context) {
mCustomView = LayoutInflater.from(context).inflate(R.layout.webview_search, null); customView = LayoutInflater.from(context).inflate(R.layout.webview_search, null);
mEditText = mCustomView.findViewById(R.id.edit); editText = customView.findViewById(R.id.edit);
mEditText.setOnClickListener(this); editText.setOnClickListener(this);
mFindResultsTextView = mCustomView.findViewById(R.id.find_results); findResultsTextView = customView.findViewById(R.id.find_results);
mInput = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); input = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
mIsActive = false; isActive = false;
setText(""); setText("");
} }
public void setActive() { public void setActive() {
mIsActive = true; isActive = true;
} }
public void finish() { public void finish() {
mActionMode.finish(); actionMode.finish();
mWebView.clearMatches(); webView.clearMatches();
} }
// Place text in the text field so it can be searched for. Need to press // Place text in the text field so it can be searched for. Need to press
// the find next or find previous button to find all of the matches. // the find next or find previous button to find all of the matches.
public void setText(String text) { public void setText(String text) {
mEditText.setText(text); editText.setText(text);
Spannable span = mEditText.getText(); Spannable span = editText.getText();
int length = span.length(); int length = span.length();
// Ideally, we would like to set the selection to the whole field, // Ideally, we would like to set the selection to the whole field,
@ -95,22 +95,22 @@ public class CompatFindActionModeCallback
throw new AssertionError( throw new AssertionError(
"WebView supplied to CompatFindActionModeCallback cannot be null"); "WebView supplied to CompatFindActionModeCallback cannot be null");
} }
mWebView = webView; this.webView = webView;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
mFindResultsTextView.setVisibility(View.VISIBLE); findResultsTextView.setVisibility(View.VISIBLE);
mWebView.setFindListener((activeMatchOrdinal, numberOfMatches, isDoneCounting) -> { this.webView.setFindListener((activeMatchOrdinal, numberOfMatches, isDoneCounting) -> {
String result; String result;
if (mEditText.getText().toString().isEmpty()) { if (editText.getText().toString().isEmpty()) {
result = ""; result = "";
} else if (numberOfMatches == 0) { } else if (numberOfMatches == 0) {
result = "0/0"; result = "0/0";
} else { } else {
result = (activeMatchOrdinal + 1) + "/" + numberOfMatches; result = (activeMatchOrdinal + 1) + "/" + numberOfMatches;
} }
mFindResultsTextView.setText(result); findResultsTextView.setText(result);
}); });
} else { } else {
mFindResultsTextView.setVisibility(View.GONE); findResultsTextView.setVisibility(View.GONE);
} }
} }
@ -119,31 +119,31 @@ public class CompatFindActionModeCallback
// If false, find the previous match, up in the document. // If false, find the previous match, up in the document.
private void findNext(boolean next) { private void findNext(boolean next) {
if (mWebView == null) { if (webView == null) {
throw new AssertionError("No WebView for CompatFindActionModeCallback::findNext"); throw new AssertionError("No WebView for CompatFindActionModeCallback::findNext");
} }
mWebView.findNext(next); webView.findNext(next);
} }
// Highlight all the instances of the string from mEditText in mWebView. // Highlight all the instances of the string from mEditText in mWebView.
public void findAll() { public void findAll() {
if (mWebView == null) { if (webView == null) {
throw new AssertionError("No WebView for CompatFindActionModeCallback::findAll"); throw new AssertionError("No WebView for CompatFindActionModeCallback::findAll");
} }
CharSequence find = mEditText.getText(); CharSequence find = editText.getText();
if (find.length() == 0) { if (find.length() == 0) {
mWebView.clearMatches(); webView.clearMatches();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
mWebView.findAllAsync(null); webView.findAllAsync(null);
} else { } else {
mWebView.findAll(null); webView.findAll(null);
} }
} else { } else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
mWebView.findAllAsync(find.toString()); webView.findAllAsync(find.toString());
} else { } else {
mWebView.findAll(find.toString()); webView.findAll(find.toString());
} }
// Enable word highlighting with reflection // Enable word highlighting with reflection
@ -151,7 +151,7 @@ public class CompatFindActionModeCallback
for (Method ms : WebView.class.getDeclaredMethods()) { for (Method ms : WebView.class.getDeclaredMethods()) {
if (ms.getName().equals("setFindIsUp")) { if (ms.getName().equals("setFindIsUp")) {
ms.setAccessible(true); ms.setAccessible(true);
ms.invoke(mWebView, true); ms.invoke(webView, true);
break; break;
} }
} }
@ -163,14 +163,15 @@ public class CompatFindActionModeCallback
// Show on screen keyboard // Show on screen keyboard
public void showSoftInput() { public void showSoftInput() {
mEditText.requestFocus(); //wait for any hidden show/hide processes to finish
mEditText.setFocusable(true); editText.postDelayed(() -> {
mEditText.setFocusableInTouchMode(true);
mEditText.requestFocusFromTouch(); editText.requestFocus();
//show the keyboard
input.showSoftInput(editText, 0);
}, 100);
if (mEditText.requestFocus()) {
mInput.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
}
} }
@Override @Override
@ -180,21 +181,21 @@ public class CompatFindActionModeCallback
@Override @Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) { public boolean onCreateActionMode(ActionMode mode, Menu menu) {
mode.setCustomView(mCustomView); mode.setCustomView(customView);
mode.getMenuInflater().inflate(R.menu.menu_webview, menu); mode.getMenuInflater().inflate(R.menu.menu_webview, menu);
mActionMode = mode; actionMode = mode;
Editable edit = mEditText.getText(); Editable edit = editText.getText();
Selection.setSelection(edit, edit.length()); Selection.setSelection(edit, edit.length());
mEditText.requestFocus(); editText.requestFocus();
return true; return true;
} }
@Override @Override
public void onDestroyActionMode(ActionMode mode) { public void onDestroyActionMode(ActionMode mode) {
mActionMode = null; actionMode = null;
mIsActive = false; isActive = false;
mWebView.clearMatches(); webView.clearMatches();
mInput.hideSoftInputFromWindow(mWebView.getWindowToken(), 0); input.hideSoftInputFromWindow(webView.getWindowToken(), 0);
} }
@Override @Override
@ -204,12 +205,12 @@ public class CompatFindActionModeCallback
@Override @Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) { public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
if (mWebView == null) { if (webView == null) {
throw new AssertionError( throw new AssertionError(
"No WebView for CompatFindActionModeCallback::onActionItemClicked"); "No WebView for CompatFindActionModeCallback::onActionItemClicked");
} }
mInput.hideSoftInputFromWindow(mWebView.getWindowToken(), 0); input.hideSoftInputFromWindow(webView.getWindowToken(), 0);
int itemId = item.getItemId(); int itemId = item.getItemId();
if (itemId == R.id.find_prev) { if (itemId == R.id.find_prev) {

View File

@ -572,7 +572,7 @@ public abstract class CoreMainActivity extends BaseActivity implements WebViewCa
hideTabSwitcher(); hideTabSwitcher();
} else if (isFullscreenOpened) { } else if (isFullscreenOpened) {
closeFullScreen(); closeFullScreen();
} else if (compatCallback.mIsActive) { } else if (compatCallback.isActive) {
compatCallback.finish(); compatCallback.finish();
} else if (drawerLayout.isDrawerOpen(GravityCompat.END)) { } else if (drawerLayout.isDrawerOpen(GravityCompat.END)) {
drawerLayout.closeDrawers(); drawerLayout.closeDrawers();