question

Jon R. Helms avatar image
Jon R. Helms asked

Extend phone & tablet App to Fire TV

I have an app that works on Android tablets and phones that I want to make work on the Fire TV. The primary problem seems to be adapting how the navigation works. My settings screen that comes up when you load the app the first time works fine, it has a TextView, TextBox, and a button. The next screen is a graphic based menu of clickable LinearLayouts, and the FireTV does not let me use the D-pad to get over to them (doesn't surprise me). Ideally I want to keep one code base on all the Android based platforms. What is the best "replacement" for a clickable LinearLayout that would work with the FireTV?
fire tv
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi Jon, We need better clarity on this issue. First, could you confirm that your layout is set as clickable? android:clickable="true" Or in code with yourLinearLayout.setClickable(true); If it's set to clickable and you have registered an OnClickListener but not getting any event reported there, that should be a concern and we will investigate the issue further. Please confirm.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jon R. Helms avatar image
Jon R. Helms answered
It was not set as clickable, just having called setOnClickListener is sufficient for phones & tablets. I did go ahead and add setClickable(true) and I still cannot click or navigate through the LinearLayouts. My first screen is an EditText and a Button, once you click the button it calls a new activity and this activity (and all that follow) use clickable LinearLayouts. I add the LinearLayouts to a parent LinearLayout through code, and here is the code. This is in a function that gets called several times, once per item. LinearLayout layout = new LinearLayout(context); layout.setPadding(5, 5, 5, 5); layout.setGravity(Gravity.BOTTOM); layout.setLayoutParams(new LayoutParams(270, 360)); if(backgroundDrawable != null) layout.setBackgroundDrawable(backgroundDrawable); else if(backgroundUrl != null && backgroundUrl != "") { Drawable bd = GetGraphicFromURL(backgroundUrl); layout.setBackgroundDrawable(bd); } layout.setTag(Tag); layout.setClickable(true); layout.setOnClickListener(onClick); LinearLayout graybox = new LinearLayout(context); graybox.setLayoutParams(new LayoutParams(270, 120)); graybox.setBackgroundColor(Color.BLACK); graybox.getBackground().setAlpha(90); TextView tv = new TextView(context); tv.setText(LabelText); tv.setTextColor(Color.WHITE); tv.setTextSize(22); graybox.addView(tv); layout.addView(graybox); parent.addView(layout);
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jon R. Helms avatar image
Jon R. Helms answered
I put together a basic app that demonstrates the click problem. All three graphics that show should be clickable, and are clickable on phones and tablets, but I don't seem to have any navigation or click on the Fire TV. http://99.63.38.138:83/android.zip
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi Jon, May I know how do you sending the click event into the linear layout in your app. I have connected one mouse through USB with Fire TV and able to get the click events reported with every click on the liner layout set in the view. public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setPadding(5, 5, 5, 5); layout.setGravity(Gravity.BOTTOM); layout.setLayoutParams(new LinearLayout.LayoutParams(270, 360)); layout.setClickable(true); layout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { System.out.println("FireTV.onClick"); } }); LinearLayout graybox = new LinearLayout(this); graybox.setLayoutParams(new LinearLayout.LayoutParams(270, 120)); graybox.setBackgroundColor(Color.BLACK); graybox.getBackground().setAlpha(90); TextView tv = new TextView(this); tv.setText(" Text in TextView"); tv.setTextColor(Color.WHITE); tv.setTextSize(22); graybox.addView(tv); layout.addView(graybox); setContentView(layout); } Are you trying to provide click inputs through Controller? Please let us know your use case. Also, I have said this in your other post, I can not access the zip from above path. Please provide a valid path. Thanks.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Ok. I think you are using Amazon Fire Game Controller inputs in your view. And trying to capture onClick by pressing "A" button. If so, you need to make your layout focasable. Layout view components are not default focasable like buttons. Set this. layout.setFocusable(true); I am able to capture onClick (while "A" button is pressed) in my above code when my linear layout is in focus. Thanks.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jon R. Helms avatar image
Jon R. Helms answered
I'm not using the game controller, so unless that's what the Fire TV defaults to that isn't it. This was a straightforward phone/tablet app. I will try the setFocusable and see if it works.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jon R. Helms avatar image
Jon R. Helms answered
setFocusable did it. I have some UI mods I need to make so that I can see what's selected, but focusable was the problem, thanks a ton!
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Happy to help :)
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.