0

EDIT : This Question has transformed into another Question

Here is the link to updated Question. Android App Mouse Pointer Input Not working well on Activity UI Elements

This Question :

I am building an Android app which needs to run on Android TV Boxes as well as Tabs and Mobile Phones. I have been able to make the app as per desired need like handling user inputs from USB Mouse and Touch on Mobile Phone but have a problem in detecting USB Mouse inputs on TV Box. The Remote Control inputs are working perfectly fine but again mouse pointer clicks are undetected on app UI. UI of all other apps works perfect using both mouse and remote inputs.

Following is the output on a successful click detect using the mouse. (As Working on Mobile Phone) enter image description here

I am using the following listener to detect the mouse click or any click in the current code.

  btn.setOnTouchListener(new Button.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent arg1) {
            if ((arg1.getAction() == MotionEvent.ACTION_UP)) {
                // Button Click Using Mouse Detected
                // doing Desired Action Here
   
            }
            return true;
        }
    });

I have also added onClickListener() on the same button but has no problem on phone with both options.

Activity XML File :

 <!-- Text view to show click event data -->
 <TextView
    android:id="@+id/xd"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"

    android:layout_marginTop="20sp"
    android:fontFamily="@font/poppinsregular"
    android:textColor="#000000"
    android:textSize="20sp"
    android:text="Test"
    android:visibility="visible" />
   <!--  button 1 -->
  <Button
    android:id="@+id/one"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/sync_btn_design"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:fontFamily="@font/poppinsregular"
    android:text="Tester 1"
    android:textColor="#ffffff"
    android:textSize="20sp"
    android:textStyle="bold" />
  <!--  button 2 -->
  <Button
    android:id="@+id/two"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10sp"
    android:background="@drawable/buttondesign"
    android:focusable="true"
    android:focusableInTouchMode="true"

    android:fontFamily="@font/poppinsregular"
    android:text="Tester 2"
    android:textColor="#ffffff"
    android:textSize="20sp"
    android:textStyle="bold" />

Basically any type of left click is not detected on Android TV Box app UI but works on Mobile Phones or Tabs.

What I Tried?

I used the following code for detecting clicks on my view. So all the mouse or touch events get detected and the output printed in Textview for Debugging on TextView id 'xd' in the given XML Code.

https://developer.android.com/training/gestures/detector#detect-all-supported-gestures

What are the options I can try from here to solve it?

Rahul Shyokand
  • 1,255
  • 10
  • 17
  • Can you give us the layout xml? Also check if the button has the `clickable` and `focusable` attributes set correctly – JensV Aug 17 '20 at 09:58
  • Are all events missing or only ACTION_UP? (e.g. you get ACTION_DOWN) – JensV Aug 17 '20 at 10:06
  • @JensV Yes All Events do not work When I try the app on TV box but Code and UI everything works correctly detecting each event on Tabs or Mobile Phone. I am using this sample for Testing Click Events and it is working only on Mobile. https://developer.android.com/training/gestures/detector#detect-all-supported-gestures – Rahul Shyokand Aug 17 '20 at 10:29
  • @JensV I found that have not used clickable attribute in buttons but it still works on Mobile. I will add it and Test if it makes any difference on TV Box. Thanks – Rahul Shyokand Aug 17 '20 at 10:39

1 Answers1

1
 private int focusedItem=0;
btn.setOnKeyListener(new View.OnKeyListener(){
@Override
public boolean onKey(View v, int keyCode, KeyEvent event){
RecyclerView.LayoutManager lm=recyclerView.getLayoutManager();
if(event.getAction()==KeyEvent.ACTION_DOWN){
if(keyCode==KeyEvent.KEYCODE_DPAD_DOWN){return tryMoveSelection(lm, 1);} else if (keyCode == KeyEvent.KEYCODE_DPAD_UP){return tryMoveSelection(lm, -1);}}
return false;
}
});
anusha anu
  • 19
  • 6
  • Thanks anusha... I have fixed this by using un hiding app bar as hiding app bar was making this problem of not detecting clicks. `getSupportActionBar().hide();` was creating this weird problem. – Rahul Shyokand Sep 10 '20 at 11:04