Resolution

edited March 18 in Android Mode

Hello everyone, I did not understand very well and would be grateful if someone could explain. If I create an app for a 5-inch screen and use that program on a 4-inch screen, does the program reset the new resolution automatically or for each screen do I have to make a different app? Thanks in advance.

Tagged:

Answers

  • edited March 17 Answer ✓

    @rhaicmer===

    Android classifies screens according to their size (inches) and density (dpi). As for size screens are a) small b) normal c) large d) large; as for density there are a) low dpi b) medium dpi c) hdpi d) xhdpi e) xxhdpi f) xxxhdpi. Medium and base values are 160dpi for density and 4-5 inches for size. Of course those values are independent, some devices can have quite the same size and not the same density and there are methods to "get" either size or density.

    When you work with AS or Eclipse you can (and often must) provide resources corresponding to these categories or other parameters (orientation);

    working with processing does not allow to do that directly (i mean adding images in the res folder) and in most cases it is not useful if you work for medium density and normal screens: android automatically adapt your images to the screen, though you can also (coding) choose the way to adapt (stretching, cropping....).

    Now, if you want to adapt your images (or textSize) to screens with are "extreme" (xxxhdpi, big tablets) what to do?

    • You have a) to get the values from the device b) put different versions of your images in the data folder c) load them according to the result you get.

    You can also (for configchanges) add vertical and horizontal versions and (always by code) load one or another overriding the onConfigurationChanged() method.

    Yet, i think that if you want that your app target all devices categories the better way is to use AS or Eclipse: for example Android don't use pixels size for textSize but dip (or dp) which is density independent pixel unit. And with P5 you cannot use this kind of unit, very very useful!

    more details here: https://developer.android.com/guide/practices/screens_support.html

  • Akenaton thank you very much. If I understood correctly, if I am working with the average values ​​of dpi and inches the proper android will adapt the code to the screen. About Eclipse, where do I get more information about it?

  • edited March 17 Answer ✓

    @rhaicmer===

    you are right; write code for 160 dpi && medium size ( from 4 to 6)::: not any problems with P5 As for eclipse or As another story begins:: download, install and work: good luck!

  • Useful info so thanks for posting @akenaton

    Out of interest though, is my approach to this 'wrong' in Processing ...

    I just create some scaling variables e.g. ....

      buttonSize = min(width, height)/8 ;
      standardFont = buttonSize/3 ;
      smallFont = buttonSize/4 ;
      verySmallFont = buttonSize/5 ;
      largeFont = buttonSize/2 ;
      superLargeFont = buttonSize ;
    

    then to display a button I just use image(img, x, y, buttonSize, buttonSize) etc and make sure the img file is high enough res (eg 256x256px) so that the scaling is downwards, and not upwards which causes blurring, and I only have to supply one image file at a high enough res. Or I also also rect(x, y, buttonSize, buttonSize) .... for text I call textSize(standardFont) etc

    Is this essentially the same as what is recommended for 'proper' coding as in the API link above? It seems to work OK for me so far, but am I missing something ... it seems too easy somehow compared to the lengthy suggestions in the API documentation??!

    Mark

  • edited March 18

    @hudson_m400===

    in many cases what you do can work; yet you seem to consider only the size param; now let us suppose that you are on a small display with hdpi (240) which is rather current (HTC eg): that means that the pixel size is very little and that your text is too little also. In order to avoid that and getting quite the same way than yours a) you get the density (displayMetrics) for the display b) you adopt the android standard point of view: 160dpi is the medium c) you scale according to the result you got.

    As for images you apply the same strategy: base line is dpi:scale factor = 100%; then you supply alternative resources according to android category: small(75%), large (150%), extra large (200%) and put them in the data folder. If you look at the processing icons you can see that they respect this factor and are created in low dpi....folders. Yet, what you write is true: if you provide xxhdpi images to the app (or xxxhdpi) as they are (in a lot of cases) scaled down they are good; the problem is with memory and cpu: because loading/ scaling down your images is a work which for a lot of devices can make an outOfMemory exception, or slow the app.

    Anyway remains the problem of orientation: you have to provide landscape && portrait alternatives for images.

    (knowing that in most cases low dpi does not matter and xxxhdpi also...)

    below some code for textSize() (note: i leave here the textSize fixed by the user in its preferences though you can remake my code for integrating that)::

                import android.util.DisplayMetrics;
    
    
                float ts;
    
    
                void settings(){
                  fullScreen();
                }
    
                void setup(){
    
                  background(255);
                  fill(0);
    
    
                  DisplayMetrics metrics = new DisplayMetrics();    
                getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);    
                int screenDensity = metrics.densityDpi; 
                println(screenDensity);
    
                ts = screenDensity/160;
                println(ts);
    
                }
    
    
                void draw(){
                  background(255);
                  textSize(24);
                  text("withoutscalingfactor", width/2, 300);
    
                  textSize(24*ts);
                  text("essai", width/2, height/2);
    
                }
    
  • @akenaton Many thanks ... I understand what you mean now. Much appreciated. Mark

Sign In or Register to comment.