Saturday, November 5, 2011

Re: [android-developers] Re: Change activity-wide density-configuration so that Resources decode from another res-folder.

You are going down the wrong path.  At this point, what you have are not hdpi or ldpi or whatever bitmaps, because you don't actually want them to match the screen density.  One thing you could do is put them in -nodpi and scale them yourself when loading to whatever size you actually want them to be.

2011/11/5 Alex K. <aragnoid@googlemail.com>
Hi,
ok that makes sense.

My problem is I have a 10.1 inches tablet with a resulution of
1024x600. And it runs on low density of 120dpi.
Since this low density causes bitmaps to be loaded from the drawable-
ldpi folder with very low resolution, the game looks on such a big
screen awful.
That's why I tried to simulate a dpi of 240 for the tablet for the
application. This works partly and the game looked good, like on the
phones.
Do you have any idea for another solution? How can I use hdpi bitmaps
on a ldpi tablet?
Thank you!

On 5 Nov., 00:02, Kostya Vasilyev <kmans...@gmail.com> wrote:
> "The bug" here is trying to modify something that is not intended to be
> modified by application code.
>
> --
> Kostya Vasilyev
> 05.11.2011 2:47 пользователь "Alex K." <aragn...@googlemail.com> написал:
>
>
>
>
>
>
>
> > Hi, I have exactly the same problem. Did you find a solution for this
> > random DisplayMetrics restet to defaults? Or even an alternative
> > solution to get the same effect?
>
> > On 27 Okt., 10:12, arberg <arb...@gmail.com> wrote:
> > > I just noticed that the effect of updateConfig() seems to stick if
> > > applied from onCreateDialog, after a dialog has been displayed (and
> > > the updateConfig-code has been executed). After changing the
> > > DisplayMetrics density from actitvity.onCreateDialog, new activities
> > > also gets the custom density. To pin it out:
>
> > > 1) If I start game, apply custom-density to DisplayMetrics in
> > > activity.onCreate then activity mainview has custom density
> > > 2) if i start a normal preference activity it has normal density, if I
> > > inflate a subview (by clicking a button), it has normal density
> > > 3) if I display a dialog, and apply custom-density to DisplayMetrics
> > > in onCreateDialog, then that dialog gets custom density
> > > 4) and following starts of preference activity gets custom density, as
> > > well as inflated subviews in main activity.
>
> > > It seems like at bug, that the state of the resources displaymetrics
> > > changes, sometimes maintaining custom density, sometimes reverting to
> > > original density.
>
> > > Alex
>
> > > On Oct 26, 11:02 pm, arberg <arb...@gmail.com> wrote:
>
> > > > I would like tochangethe density configuration so that I can force a
> > > > certain size. Specifically I want all 720p screens including xhigh-
> > > > density phones AND large medium-density tablets to use the same
> > > > bitmap, and to have the same text size relative to the screen
> > > > resolution. The result will be that my game looks the same on tablets
> > > > and on phones, without having to rework all my layouts and dimensions
> > > > to large and xlarge screens, and without having to place the same high-
> > > > res bitmaps in both the xhdpi folder and the xlarge (or sw720dp)-
> > > > folder.
>
> > > > I have found one method of doing this. If I obtain aDisplayMetrics
> > > > from the resources, andchangeits values then the resources decoded
> > > > and inflated after the modification are decoded based on the new
> > > > density value. Thus I can run the updateConfig() from early in my
> > > > activity onCreate and then the activity is inflated with my custom
> > > > density-value.
>
> > > >         private void updateConfig() {
> > > >                 Resources resources = getResources();
> > > >                DisplayMetricsdm = resources.getDisplayMetrics();
> > > >                 final int minDimension = Math.min(dm.widthPixels,
> > dm.heightPixels);
> > > >                 float densityDevice = minDimension / 320f
> > *DisplayMetrics.DENSITY_MEDIUM;
> > > >                 // Avoid scaling bitmaps in resources further by
> > setting density to
> > > >                 // match the one of the levels exactly
> > > >                 if (densityDevice >DisplayMetrics.DENSITY_XHIGH) {
> > > >                         densityDevice =DisplayMetrics.DENSITY_XHIGH;
> > > >                 } else if (densityDevice >DisplayMetrics.DENSITY_HIGH)
> > {
> > > >                         densityDevice =DisplayMetrics.DENSITY_HIGH;
> > > >                 } else if (densityDevice
> > >DisplayMetrics.DENSITY_MEDIUM) {
> > > >                         densityDevice =DisplayMetrics.DENSITY_MEDIUM;
> > > >                 } else {
> > > >                         densityDevice =DisplayMetrics.DENSITY_LOW;
> > > >                 }
> > > >                 dm.scaledDensity = dm.density = densityDevice /
> > (float)DisplayMetrics.DENSITY_DEFAULT;
> > > >         dm.densityDpi = (int) densityDevice;
> > > >         dm.xdpi = densityDevice;
> > > >         dm.ydpi = densityDevice;
> > > > // calling  resources.updateConfiguration here has no effect (it just
> > > > sets the the same dm-values again in the dm-object), but maybe its
> > > > more future proof?
> > > >          resources.updateConfiguration(null, dm);
> > > >         }
>
> > > > Updating the density with my updateConfig() method early in
> > > > activity.onCreate affects all the resources I decode in onCreate, but
> > > > when onCreate returns thedisplayMetricsreturns to the default
> > > > values. So if I do a post to UI thread and inflates some more
> > > > resources then I have to run updateConfig() again to apply my custom
> > > > density. Had I done a Localechangeby invoking the
> > > > resources.updateConfiguration, then the Locale-changewould have taken
> > > > effect for the remainder of the activity.
>
> > > > I can see from the implemenation of resources.updateConfiguration (in
> > > > Android-10) than it doesn't do much based on the givenDisplayMetrics,
> > > > it doesn't even flush the bitmap cache, which could cause trouble if I
> > > > had already decoded a bitmap with the original density information.
>
> > > > I would like a way tochangeautoscale by density of the decoded
> > > > resources, for the remainder of my activity execution and preferable
> > > > even for the entire application if possible.
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to android-developers@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscribe@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en



--
Dianne Hackborn
Android framework engineer
hackbod@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment