I am making a new app, and I am using a Canvas. I am scaling the canvas but I set the size to:
public static final int WIDTH = 1920;
public static final int HEIGHT = 1080;
(the screen will be in landscape. That is why width is bigger than height) Meaning if this app was intended for portrait orientation:
public static final int WIDTH = 1080;
public static final int HEIGHT = 1920;
Scaled as the canvas usually is:
public void render(Canvas c) {
super.draw(c);
final float scaleFactorX = getWidth()/(WIDTH*1.f);
final float scaleFactorY = getHeight()/(HEIGHT*1.f);
if (c != null) {
final int savedState = c.save();
c.scale(scaleFactorX, scaleFactorY);
/////render
/////render end
c.restoreToCount(savedState);
}
}
Most phones today are HD or better, and very few have worse resolution. But there are still phones, and I am concerned as to how the scaling will react on other non-HD/better phones as my app will be pushing for a better resolution than the screen supports.
Any ideas how the phone will respond to this? Some phones can auto-adjust the scaling but is that a general function or a function only some phones have?
The SurfaceView is activated in an Activity and set using setContentView:
@Override
public void onCreate(Bundle sis){
super.onCreate(sis);
CustomSurfaceView sf = new CustomSurfaceView(this);
setContentView(sf);
//initialize
sf.init(this, this);
}
EDIT
To clarify:
I am scaling the canvas to a specific size that is the same as HD 1080 resolution. HD 1080 screens will not do any scaling compared to the screen. 2K screens will scale to HD 1080 resolution, meaning it will go with a lower resolution than the screen's max fit.
HD1080 size is 1080x1920 which will be applied to a canvas on a screen that is smaller than that size.
But how will the scaling act on HD 720 screens or in general worse resolution than HD 1080? The app will be pushing a bigger size than the screen supports. How will the phone react to this?
Running the app on a nexus emulator(nexus 4, api 23) results to the canvas being pushed slightly off the screen. Not all phones behave like nexus as the firmware has been edited by the manufacturers, so just because it goes off the screen on the Nexus doesn't mean it will on a Sony or any other brand
Note: HD references to HD 1080 unless otherwise defined.