ankidroid / Anki-Android

AnkiDroid: Anki flashcards on Android. Your secret trick to achieve superhuman information retention.
GNU General Public License v3.0
8.7k stars 2.24k forks source link

Can't focus/type text into HTML input box #1623

Closed hssm closed 8 years ago

hssm commented 9 years ago

Originally reported on Google Code with ID 720

What steps will reproduce the problem?
1a. Load Minmal.anki and Minmal.media
1b. Or create some model like: 

{{Front}}
<br><input id="myVar"; style="width:66%"/>
<button onClick="document.getElementById('myFrame').src=myVar.value+'.html'">OK</button>
<br><iframe id="myFrame"; height="480px"; width="66%"; frameborder="0"; scrolling="yes";></iframe>

2. On study, try changing textinput to 'a' or 'b' (without '')
3. Try pressing OK button

What is the expected output? What do you see instead?
➙ In Anki 1.2.8 and Ankiweb one can change the textinput whereas sometimes Ankidroid
doesn't focus the textinput and doesn't give a blinking cursor.
➙ In Anki 1.2.8 and Ankiweb one can press the OK button and at least in Anki 1.2.8
the iframe loads the specified a.html or b.html successfully whereas Ankidroid crashes.

What version of AnkiDroid are you using? On what version of Android?
0.7 Beta 20
1.2.8

Please provide any additional information below.
On former Ankidroid versions this actually did work sometimes. Unfortunately not always.
As this is very useful for minimal information study, I'll gladly give more feedback
to improve Ankidroid!

Reported by Ingmar.Zech on 2011-08-13 12:23:16


hssm commented 9 years ago
Android 2.1

Reported by Ingmar.Zech on 2011-08-13 12:55:51

hssm commented 9 years ago
I'm able to consistently reproduce the crash by tapping the "OK" button on the card.
Log here: http://www-personal.umich.edu/~mikemorr/20110813log-720.txt

Reported by mikemorr.com on 2011-08-13 14:39:36

hssm commented 9 years ago
Thanks for looking into it!

Interestingly, Ankidroid can handle 

<iframe id="myFrame"; src="'a.html'"; height="480px"; width="66%"; frameborder="0";
scrolling="yes";></iframe> 

just fine (loads a.html on startup), while Anki 1.2.8 cannot. 

So I guess it's <input> causing this error.

08-13 10:31:30.741 I/AnkiDroid( 1609): Focusable = true, Focusable in touch mode =
false
...
08-13 10:31:35.327 I/UsageStats( 1216): Unexpected resume of com.android.launcher while
already resumed in com.ichi2.anki
08-13 10:31:35.374 W/InputManagerService( 1216): Got RemoteException sending setActive(false)
notification to pid 1609 uid 10027

Reported by Ingmar.Zech on 2011-08-15 11:47:08

hssm commented 9 years ago
With 0.7beta23 (fixing Issue 725), I no longer get a crash when tapping the "OK" button.

However, I am still unable to enter text into the textbox. Tapping inside the box makes
a blinking cursor appear, but even when I force the onscreen keyboard to appear (by
a long press on the Menu button), I can't type text into the box.

Reported by mikemorr.com on 2011-08-16 03:30:28

hssm commented 9 years ago
Hopefully the crash issue is fixed, so I'm renaming this issue (from "Crash on using
textinput or iframe") to describe the other problem (can't type into input box). 

Attached is a simple deck with only <input /> on each side of the card. I'm unable
to focus the text input box, make a cursor appear in it, or type into it.

Reported by mikemorr.com on 2011-08-16 05:08:06


hssm commented 9 years ago

Reported by nicolas.raoul on 2011-08-16 05:18:14

hssm commented 9 years ago
I'm on 0.7 now. Sometimes I can type into the input field. Most of the time, it doesn't
work (or even surcharges my input keyboard). I made it work (but only once) just by
changing from landscape to portrait mode. Would be great to see this working the whole
time.

Reported by Ingmar.Zech on 2011-08-24 18:18:07


hssm commented 9 years ago
This really seems to be Android's Issue 7189:   WebView with input/textarea never get
virtual keyboard focus.

Found 2 different solutions so far (ranked by quality of success-stories):

1) Overriding onCheckIsTextEditor():

class MyWebView extends WebView {

    public MyWebView(Context context) {
        super(context);
    }

    @Override
    public boolean onCheckIsTextEditor() {
        return true; 
    }
}

2a) Adding TouchListener:

webview.requestFocus(View.FOCUS_DOWN);
        webview.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                    case MotionEvent.ACTION_UP:
                        if (!v.hasFocus()) {
                            v.requestFocus();
                        }
                        break;
                }
                return false;
            }
        });

2b) Adding android:focusable to WebView layout:

<WebView android:id="@+id/uiContent"
    android:layout_weight="1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:focusable="true"/>

(Sources: https://code.google.com/p/android/issues/detail?id=7189, http://stackoverflow.com/questions/4293965/android-webview-focus-problem)

Reported by Ingmar.Zech on 2011-08-29 11:01:11

hssm commented 9 years ago
Unfortunately, this code part causes an npe for some devices (https://code.google.com/p/ankidroid/issues/detail?id=805):

    @Override
    public boolean onCheckIsTextEditor() {
        return true; 
    }

I removed it when searching for the 805 error and it obviously solved the case.
I'd propose to add an option for html input boxes (with a hint that it does not work
on all devices) and disable it by default.

What do you think?

Reported by NorbertNagold on 2011-10-06 08:15:40

hssm commented 9 years ago
Sounds good :-)

Reported by nicolas.raoul on 2011-10-06 08:25:49

hssm commented 9 years ago
To allow for issue 805: This fix here is now disabled by default, you can enable it
in preferences/other. If the crash occurs (because you own one of the devices in question),
it will be automatically disabled again.

Anyway, it would be better to find a solution which works for everyone; so I keep this
issue open

Reported by NorbertNagold on 2011-10-07 07:12:00

hssm commented 9 years ago
Is this still an issue in 2.x?

Reported by perceptualchaos2 on 2015-06-01 06:02:24

hssm commented 9 years ago
I still can’t get text into an <input> tag with API 8/Android 2.2.
Which is a shame, because otherwise my code to use an input tag for the type answer
feature is ready.

Reported by ospalh on 2015-06-03 13:47:05

eginhard commented 8 years ago

@ospalh This should finally be obsolete, right?

ospalh commented 8 years ago

Well, it’s still not working. You can’t reliably get focus into an input box on old Android systems, when you have one in your card templates. But it’s not really an AnkiDroid, but an Android or Webview problem. So i guess we can close this as “won’t fix”.

And the type-in feature is only slightly related to this, and working all right with the extra input field.