Android Question $100 reward for a fix for this issue

JohnC

Expert
Licensed User
Longtime User
Hi,

I am developing a simple browser application for these new "Android on a Stick" devices that plug directly into an HDTV tv set.

I need to display stuff in the browser in "portrait" mode by *physically* mounting/tilting the HDTV set itself 90 degress, so it is taller then it is wide (its mounted on its side).

The problem is that these android sticks do NOT support portrait mode, so I had to resort to using the animation library to "rotate" a panel that I placed the webview control on, so the webview control will now display in a portrait mode.

However, I ran into a problem in which the webview refuses to display the full height of a tall webpage from top to bottom - it seems to cut-off the lower 1/3 of the webpage (see attached Land-Port.png screen shot). (it does works ok when showing a page in landscap mode as seen in port-land.png below, but I need it to also work in portrait mode)

The below test app supports both landscape and portrait mode, but to properly demonstrate this issue, you need to rotate your android device so it's in landscape mode then run the below app. Select "Rotate" from the pop-up menu to toggle modes until you see the text sideways with the top line on the left side of the screen, then you will see it cut's off the bottom of the webpage (as shown in land-port.png).

I have $100 for a *reliable* solution to this issue!

Notes:
1) So I can see what layer is what, I made the activity background yellow and the panel background red
2) I setup a small boarder around the webview so I can see that the panel is fully surrounding the webview and to make sure that wasnt the reason for cutting off the bottom.
3) When in "Rotate" mode (Port=false), I am creating a portrait positioned panel on the landscape activity, then rotated it in an effort to see if that made a difference, but it didn't.


#Region
Activity Attributes

#FullScreen: True
#IncludeTitle: False​

#End Region

Sub Process_Globals

DimmanagerAsPreferenceManager
DimscreenAsPreferenceScreen​

End Sub

Sub Globals

Dim wv As WebView
Dim iP AsPanel
Dim A1 As AnimationPlus '(you can use the free version 1.x)​

End Sub

Sub Activity_Create(FirstTime AsBoolean)

If FirstTime Then

CreatePreferenceScreen
If manager.GetAll.Size = 0 Then SetDefaults

End If

Activity.Color=Colors.Yellow

Activity.AddMenuItem("Settings","mnuSettings")
Activity.AddMenuItem("Refresh","mnuRefresh")
Activity.AddMenuItem("Rotate","mnuRotate")
Activity.AddMenuItem("Exit","mnuExit")
CreatePanel(manager.GetBoolean("Rotate"))​

End Sub

Sub SetDefaults

manager.SetString("URL", "http://www.max-soft.com/btest.html")
manager.SetBoolean("Rotate", False)​

End Sub

Sub Activity_Resume

wv.LoadUrl(manager.GetString("URL"))​

End Sub

Sub mnuSettings_Click()

StartActivity(screen.CreateIntent)
CreatePanel(manager.GetBoolean("Rotate"))​

End Sub

Sub mnuRotate_Click

If manager.GetBoolean("Rotate")= FalseThen

manager.SetBoolean("Rotate",True)

Else

manager.SetBoolean("Rotate",False)

End If

CreatePanel(manager.GetBoolean("Rotate"))​

End Sub

Sub mnuRefresh_Click()

wv.LoadUrl(manager.GetString("URL"))​

End Sub

Sub mnuExit_Click

If Msgbox2("Are you sure you want to Exit?","Exit","Yes","No","",Null) = DialogResponse.POSITIVE Then

Exit Application
End If​
End Sub

Sub CreatePreferenceScreen

screen.Initialize( "Settings", "")

Dim cat1 AsPreferenceCategory

cat1.Initialize("Browser")
cat1.AddEditText("URL", "URL", "The URL to display", "http://www.max-soft.com/btest.html")
cat1.AddCheckBox("Rotate", "Rotate", "Rotate Screen 90 Degrees", False)

screen.AddPreferenceCategory(cat1)​

End Sub

Sub CreatePanel(Port AsBoolean)

Activity.RemoveAllViews

If Port = TrueThen

iP.Initialize("iP")
Activity.AddView(iP, 0dip, 0dip, Activity.Width , Activity.Height)
iP.Color = Colors.Red

wv.Initialize("wv")
iP.AddView(wv, 5dip, 5dip, iP.Width-10 , iP.Height-10)

Else

iP.Initialize("iP")
Activity.AddView(iP,(Activity.Width /2) - (Activity.Height /2), 0, Activity.Height, Activity.Height)

A1.InitializeRotateCenter("",0,-90,iP)
A1.RepeatCount=0
A1.duration=0
A1.PersistAfter=True
A1.Start(iP)
iP.Color = Colors.Red

iP.SetLayout(0dip, 0dip, Activity.Height, Activity.Width)

wv.Initialize("wv")
iP.AddView(wv, 5dip, 5dip, Activity.Height-10 , Activity.Width-10)

End If

wv.LoadUrl(manager.GetString("URL"))​

End Sub
 

Attachments

  • Port-Land.png
    19.2 KB · Views: 300
Last edited:

thedesolatesoul

Expert
Licensed User
Longtime User
I cant test this since I dont have a device that acts like this, however have you tried to use:
SetScreenOrientation (Orientation As Int)
Changes the current activity orientation. This method cannot be called from a service module.
Orientation - -1 for unspecified, 0 for landscape and 1 for portrait.
While in the package supporting both landscape/portaint (so it lets the app install).
In Activity_Create or Activity_Resume:
B4X:
Dim ph as phone
ph.SetScreenOrientation(1)
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User

As I mentioned, you can "simulate" this issue with *any* device by just leaving your device physically in landscape position and then run my app and select "rotate" until you see the text being displayed sideways (portrait), but your phone is still physically in landscape position.

In reply to your suggestion, like I said the device only supports landscape mode and ignores that setscreenorientation - I know this because I did try that already.
 
Last edited:
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Here you go...
 

Attachments

  • PortBrowser.zip
    5.8 KB · Views: 252
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Tried changing this line
B4X:
iP.AddView(wv, 5dip, 5dip, iP.Width-10 , iP.Height-10)
to
B4X:
iP.AddView(wv, 5dip, 5dip, iP.Width-10dip , iP.Height-10dip)
?
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
I tried setScreenOrientation on my device and it did work (even when locked orientation to landscape). Again, I must stipulate that since I do not own such a device it is impossible to be sure my solution will work the same on your device.

Regarding, using AnimPlus to rotate the webview, I can reproduce your problem. However as soon as I interact with the webview it rotates back! Surprising behaviour. I dont think rotating will be a good solution in this way.

A third solution can be (only for a non-interactive webpage), to CaptureBitmap of the webview and display it however you need it. It will however be memory intensive and display-only.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User

I forgot to mention something...if you look closely at the land-port.png image that shows the probem, you can see the horizontal and vertical scroll bars (medium gray bars) along the top (vertical scroll bar) and the right side (horizontal scroll bar) for the webview control. This to me indicates that I am properly sizing the webview control to take up the entire screen because those scroll bars should only be positioned along the right and bottom of the webview, but it's the contents that are being cut off toward the right half of the screen.

However, I tried your DIP suggestion, but unfortunately it didnt make any difference.
 
Last edited:
Upvote 0

JohnC

Expert
Licensed User
Longtime User

I am glad to hear that you can see the problem and I am confident that if you can do something to fix the issue on your device, it will fix it on my device as well.

Fortunetely, there is no user-touch interaction needed when displaying the webpage (the HDTV's dont have a touch screen), and I did also experiance the same toggle issue when I tried touching the webpage in webview. But I am confident this particular quirk wont matter with my needs.

I also did think about using capture to BMP, but I need the webpage to display video's, other javascript motions, so I cant use a static BMP for this.
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Ok, this is what I found out.

First of all, I'm assuming that when you say "Android on a Stick" is one of those devices like a MK802, if that's the case then you will encounter some issues.

I've used a different animation library (Tween Engine) and I'm able to rotate the webview, and it won't "reset" like it does with your code, HOWEVER, the content doesn't rotate with it, other views (like a ListView for example) works just fine, so, in my opinion there are 2 solutions, 1- Don't use a WebView but a ListView, 2- Create a custom WebView library that is rotated 90 degrees (good luck with that).

I have GoogleTV (soon to be re-branded AndroidTV) and on that device the rotation works like a charm and doesn't have the issues I mentioned above, just to let you know.

Look at the attached sample, I tested it on my HTC EVO, Nexus 7 and GoogleTV (by the way, GoogleTV is not the same as those "TV sticks" it is an actual Google product, in case you don't know), I haven't tested the code on my MK802 because it's just another Android device and it will behave just like any other Android device.

I've added some notes on the attached project so you can easily understand what's going on, the animation is "slow" on purpose, so you can see what's happening.

NOTE: To run the attached sample you must install the Tween Engine library, the APK is also attached in case you don't feel like installing the animation library.
 

Attachments

  • GenericSample.apk
    129.1 KB · Views: 267
  • Rotation_Sample.zip
    10.3 KB · Views: 264
Last edited:
Upvote 0

Beja

Expert
Licensed User
Longtime User
Hi,
Please pardon my (maybe) oversimplification, and accept my two cents.
Why wouldn't you design the layout in portrait only (height > width)?
Or you may design two layouts and then detect the target device, if you
intend to install it to standard Android devices as well.
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
Sorry the above came out of misunderstanding of the problem.
Now my two cents is to change the TV screen orientation from the TV monitor setup
many TV monitors support this.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Ok, this is what I found out.

First of all, I'm assuming that when you say "Android on a Stick" is one of those devices like a MK802, if that's the case then you will encounter some issues.

Yes, exactly - I am using the MK802IIIS. Right now we are using a full-blown PC to connect to the HDTV, but they have fans that fail and are bulky and often need to be placed in a ceiling. Thats why I am looking for a smaller, cheaper, more reliable solution.

I have GoogleTV (soon to be re-branded AndroidTV) and on that device the rotation works like a charm and doesn't have the issues I mentioned above, just to let you know.

Well, correct me if I have this wrong, but I am under the impression that google TV kinda failed and Chromecast is expected to take it's place - is this sorta accurate? If google tv is still actively being developed and growing, then I have some questions:

1) where can I buy them - whats the typical price?
2) do I need to do anything special to side-load B4A apps on it?
3) does it run play store so can I install other market apps?


Well, I took a look at your sample. Since I do need to display a webpage (with all it's capabilities like playing videos), I cant use listview. But, it is strange how the lines start to digitally dissapear as it rotates with webview - very strange. I even tried adding a panel and placing the webview on it and rotating the panel using tween, but same problem.

I didn't know about that tween engine so I was really hoping it would do the trick - darn.
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
1) where can I buy them - whats the typical price?
2) do I need to do anything special to side-load B4A apps on it?
3) does it run play store so can I install other market apps?

1- You can get them at Amazon.com, the prices ranges from $99 and up
2- You can install apps via B4A Bridge or install a file manager and sideload the apps using SMB.
3- GoogleTV is just Android plus a TV addon, the GooglePlay app is installed and you can install apps just like you do on phones or tabs (not all apps are listed, just the ones compatible with GTV).

Well, correct me if I have this wrong, but I am under the impression that google TV kinda failed and Chromecast is expected to take it's place - is this sorta accurate?
ChromeCast is a "teaser", GoogleTV is on the back burner, but, like I said, Google will rebrand it as AndroidTV, maybe running KitKat (some TV sets like Samsung for example already got the GoogleTV upgrade to JB from HoneyComb)
 
Last edited:
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Hi.
care to take a look at this apk : http://goo.gl/66LOYW

Put the phone whatever orientation you want.
press any of the four buttons to choose orientation.

Nelson

Hi Nelson, it seems your app is using the "SetScreenOrientation" call.

The problem is, as I mentioned in my first post, the device that I am using does not support "portrait" mode, so calling SetScreenOrientation doesn't do anything. It appears that the webview control is hard-wired so it only "work" in landscape mode on such devices, so even though I am able to rotate it, it's height (width) can never be more then the landscape screen height.

However, I just found a stick (MK802IV) that supports portrait mode - so my issue is solved!

Thanks everyone for taking the time to see if you could find a solution, but it appears it was probably impossible because google seemed to have hard-coded a few limitations in it's webview control that can not be worked-around.

Thanks again.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…