Skip to content

Commit

Permalink
Fix (hopefully) issue where the screen stays on by default for some p…
Browse files Browse the repository at this point in the history
…eople (#597)

Some people are reporting that the screen stays on in the thread view, like the
'keep screen on' menu option is selected (which is isn't), and they have to
toggle the option on and off again every time they start the app.

I can't replicate this problem, and it seems like it shouldn't happen anyway
(the flag is initialised to 'off' and requires the user to select the menu
option to change it), so I'm assuming it's a WebView issue. I've just made the
init code always explicitly set that behaviour to off when the WebView is first
created. Hopefully that's it!

Also removed some old API lint annotations
  • Loading branch information
baka-kaba authored Apr 8, 2018
1 parent 5952b33 commit adf1a05
Showing 1 changed file with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.webkit.WebSettings;
import android.webkit.WebView;

import com.ferg.awfulapp.constants.Constants;
import com.ferg.awfulapp.preferences.AwfulPreferences;
import com.ferg.awfulapp.util.AwfulUtils;

import static com.ferg.awfulapp.constants.Constants.DEBUG;

Expand All @@ -31,15 +28,17 @@
* JavaScript on the page. By default this uses a {@link LoggingWebChromeClient} to add
* some debug logging, and the default {@link android.webkit.WebViewClient}. You should
* call {@link #onPause()} and {@link #onResume()} to handle those lifecycle events.
*
* <p>
* You can run arbitrary JavaScript code with the {@link #runJavascript(String)} method, or invoke
* the thread JavaScript's own loadPageHtml function with {@link #refreshPageContents(boolean)}.
*/

public class AwfulWebView extends WebView {

public static final String TAG = "AwfulWebView";
/** thread.js uses this identifier to communicate with any handler we add */
/**
* thread.js uses this identifier to communicate with any handler we add
*/
private static final String HANDLER_NAME_IN_JAVASCRIPT = "listener";

public AwfulWebView(Context context) {
Expand All @@ -57,7 +56,6 @@ public AwfulWebView(Context context, AttributeSet attrs, int defStyleAttr) {
init();
}

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public AwfulWebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init();
Expand All @@ -71,6 +69,7 @@ private void init() {
AwfulPreferences prefs = AwfulPreferences.getInstance();
WebSettings webSettings = getSettings();
setWebChromeClient(new LoggingWebChromeClient());
setKeepScreenOn(false); // explicitly setting this since some people are complaining the screen stays on until they toggle it on and off

setBackgroundColor(Color.TRANSPARENT);
setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
Expand All @@ -81,17 +80,14 @@ private void init() {
webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);

if (DEBUG) {
//noinspection AndroidLintNewApi
WebView.setWebContentsDebuggingEnabled(true);
}

if (prefs.inlineWebm || prefs.inlineVines) {
//noinspection AndroidLintNewApi
webSettings.setMediaPlaybackRequiresUserGesture(false);
}

if (prefs.inlineTweets) {
//noinspection AndroidLintNewApi
webSettings.setAllowUniversalAccessFromFileURLs(true);
webSettings.setAllowFileAccess(true);
webSettings.setAllowContentAccess(true);
Expand Down Expand Up @@ -145,6 +141,7 @@ public void setContent(@Nullable String content) {

/**
* Helper function to execute some jabbascript in the webview.
*
* @param javascript the code to run
*/
public void runJavascript(@NonNull String javascript) {
Expand All @@ -154,7 +151,7 @@ public void runJavascript(@NonNull String javascript) {

/**
* Calls the javascript function that updates some page content from its source.
*
* <p>
* This calls the #loadPageHtml function in <i>thread.js</i>, which in turn calls #getBodyHtml
* on the handler passed to {@link #setJavascriptHandler(WebViewJsInterface)}, and inserts the
* results into a container on the page.
Expand Down

0 comments on commit adf1a05

Please sign in to comment.