Question

How can I restrict my GoogleTV app to display in a specific resolution: i.e. 720P, 1080p, etc? For some reason my app is stuck at displaying at a resolution around 960x540 even though my GoogleTV and monitor can handle 1080p.

I'm not sure if it's just my GoogleTV that is displaying only in 960x540 or if other GoogleTVs are also seeing the same thing. In any case, I want to make sure that my app can only be viewed in the resolutions: 960x540 or 1280x720

Était-ce utile?

La solution 2

I figured it out. I had to set the initial scale of the webview, and that allows me to view the WebView in 720p even though the screen resolution is 1080p.

This is the code I used:

boolean _bReloaded = false;
boolean _bLoaded = false;
int _nWebScale = 100;
DisplayMetrics displaymetrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int nScreenHeight = displaymetrics.heightPixels;  
if(nScreenHeight >= 1000){
    _nWebScale = (int) Math.round((nScreenHeight/720.0) * 100.0); 
    _bReloaded = false;
    mWebView.setVisibility(View.INVISIBLE);
}
mWebView.setInitialScale(_nWebScale);

But I wasn't done there.

At this point, the webView is displayed in the proper resolution; however, there is a noticeable resizing of the webview window when the webView loads. This is why in the above code I hide the webview. Another problem is that in my particular case, my HTML wasn't listening to a window resize event and so it didn't readjust its UI after the webview was noticeably seen changing size. To fix this I could change my HTML and have it react to a JavaScript window resize event, or I could do what I ultimately went with - reloading the webview after it loads with the incorrect sized UI. With this solution I didn't have to react to a window resize event:

mWebView.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress) {
            if (progress == 100) {
                if(_nWebScale != 100 && (mWebView.getVisibility() != View.VISIBLE) && !_bReloaded){
                    _bReloaded = true;
                    mWebView.reload();
                } else {
                    _bLoaded = true;
                    displayLoadingSpinner(false);
                    mWebView.setVisibility(View.VISIBLE);
                }
            } else if (mProgressBar.getVisibility() != View.VISIBLE) {
                displayLoadingSpinner(true);
                _bLoaded = false;
            }
        }
});

Another piece of info that isn't directly related to the original question, but may be useful is the following. Within my code, I had to resize and reposition a VideoView based on parameters that were sent from the webview. But because the webview may be in a different resolution than the actual display resolution, I had to adjust the parameters to make them in terms of the screen resolution.

For example:

//this parameter is equal to the width of the webview screen: 720
nHeightFromWebView;
//This is the x position of where the VideoView should be placed.
nXFromWebView; 

float nScale = (float)_nWebScale/100;
int nAdjustedHeight = (int) Math.round(((float)nHeightFromWebView * nScale)); 
//The adjusted height computes to 1080 - the actual resolution of the screen
int nNewX = (int)Math.round((float)nXFromWebView * nScale);

Autres conseils

Each display on a Google TV is different. (With the exception of built in TV's like the LG) There is a step when the Google TV is just turned on where you establish the resolution of the TV.

Most current Google TV (ARM based) are 1080p. Scaling down to 720 is accomplished by your TV.

All that said, 960x540 are android Device Pixels for either 720p or 1080p.

So, to summarize, you can't / shouldn't do what your asking.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top