Revision: 2520
http://sourceforge.net/p/swingme/code/2520
Author: yuranet
Date: 2021-07-08 11:45:28 +0000 (Thu, 08 Jul 2021)
Log Message:
-----------
synth auto scales sizes now
Modified Paths:
--------------
AndroidME/src_MIDP/javax/microedition/lcdui/Image.java
AndroidME/src_SwingME_plaf/net/yura/android/plaf/AndroidIcon.java
AndroidME/src_SwingME_plaf/net/yura/android/plaf/AndroidLookAndFeel.java
Modified: AndroidME/src_MIDP/javax/microedition/lcdui/Image.java
===================================================================
--- AndroidME/src_MIDP/javax/microedition/lcdui/Image.java 2021-07-08 11:37:52 UTC (rev 2519)
+++ AndroidME/src_MIDP/javax/microedition/lcdui/Image.java 2021-07-08 11:45:28 UTC (rev 2520)
@@ -281,7 +281,7 @@
* @see android.graphics.drawable.BitmapDrawable#updateLocalState(Resources)
* @see android.graphics.drawable.Drawable#resolveDensity(Resources, int)
*/
- static int getTargetDensity() {
+ public static int getTargetDensity() {
// on API-29 this returns total rubbish, even on the emulator (display.dpi=480 display.stableDensity=320)
//if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
//return DisplayMetrics.DENSITY_DEVICE_STABLE;
Modified: AndroidME/src_SwingME_plaf/net/yura/android/plaf/AndroidIcon.java
===================================================================
--- AndroidME/src_SwingME_plaf/net/yura/android/plaf/AndroidIcon.java 2021-07-08 11:37:52 UTC (rev 2519)
+++ AndroidME/src_SwingME_plaf/net/yura/android/plaf/AndroidIcon.java 2021-07-08 11:45:28 UTC (rev 2520)
@@ -14,10 +14,8 @@
* You should have received a copy of the GNU Lesser General Public License
* along with 'yura.net Swing ME'. If not, see <http://www.gnu.org/licenses/>.
*/
-
package net.yura.android.plaf;
-
import android.graphics.drawable.Drawable;
import net.yura.mobile.gui.Graphics2D;
import net.yura.mobile.gui.Icon;
Modified: AndroidME/src_SwingME_plaf/net/yura/android/plaf/AndroidLookAndFeel.java
===================================================================
--- AndroidME/src_SwingME_plaf/net/yura/android/plaf/AndroidLookAndFeel.java 2021-07-08 11:37:52 UTC (rev 2519)
+++ AndroidME/src_SwingME_plaf/net/yura/android/plaf/AndroidLookAndFeel.java 2021-07-08 11:45:28 UTC (rev 2520)
@@ -47,20 +47,22 @@
protected Icon getIcon(String path, int x, int y, int w, int h) {
Image.ResourceInputStream resimg = Image.getResourceAsStream(path);
if (resimg!=null) {
- Drawable bmpd = resimg.getDrawable();
- if (bmpd!=null) { // this should NEVER be null, but sometimes it is
+ Drawable bitmapDrawable = resimg.getDrawable();
+ if (bitmapDrawable!=null) { // this should NEVER be null, but sometimes it is
if (w!=0 && h !=0) {
// TODO maybe can be done better to not need a new bitmap
- Bitmap bmp = ((BitmapDrawable)bmpd).getBitmap();
- double density = bmp.getDensity();
- if (density == Bitmap.DENSITY_NONE) {
- density = AndroidMeActivity.DEFAULT_ACTIVITY.getResources().getDisplayMetrics().densityDpi;
+ Bitmap bmp = ((BitmapDrawable)bitmapDrawable).getBitmap();
+ int systemDensity = Image.getTargetDensity();
+ int bitmapDensity = bmp.getDensity();
+ if (bitmapDensity == Bitmap.DENSITY_NONE) {
+ System.err.println("WARN no density for image " + path);
+ bitmapDensity = DisplayMetrics.DENSITY_DEFAULT; // default to make numbers smaller, as less likely to cause a crash
}
- double scale = density / DisplayMetrics.DENSITY_DEFAULT;
- bmp = Bitmap.createBitmap(bmp, (int)(x*scale), (int)(y*scale), (int)(w*scale), (int)(h*scale) );
- bmpd = new BitmapDrawable( AndroidMeApp.getContext().getResources() ,bmp);
+ double scale = (double) bitmapDensity / (double) systemDensity;
+ bmp = Bitmap.createBitmap(bmp, (int) (x * scale), (int) (y * scale), (int) (w * scale), (int) (h * scale));
+ bitmapDrawable = new BitmapDrawable(AndroidMeApp.getContext().getResources(), bmp);
}
- return new AndroidIcon( bmpd );
+ return new AndroidIcon(bitmapDrawable);
}
else {
System.err.println("getDrawable returned null for "+path+" "+resimg);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|