Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Android button+canvas fix

141 views
Skip to first unread message

ValtersB

unread,
Mar 19, 2012, 8:11:44 PM3/19/12
to microemulator-developers
Hi,

here are two improvements for the Android port of the latest
Microemulator snapshot as downloaded from here:
http://snapshot.microemu.org/microemulator/download/ (10-Jan-2012
03:05 2.0M)

for whomever might need them

1. Android buttons are now shown as real Android buttons instead of
strings
2. my tests indicate a bug in the latest snapshot - Canvas height is
being clipped down

you can download both of the updated files here (as 7-zip archive):
http://valters-n.co.cc/microemu.fix1.7z

Alternatively:
to fix canvas height just comment out this line:
this.canvas.clipRect(tmp, Region.Op.REPLACE);
in "microemu-android\src\org\microemu\android\device
\AndroidDisplayGraphics.java"


here are the changes required for Android button support as produced
by the diff utility for “microemu-android\src\org\microemu\android
\device\ui\AndroidImageStringItemUI.java”:
44a45
> import android.widget.Button;
46a48
>
50c52
<
---
>
52c54
<
---
>
55,56c57,60
< private TextView textView;
<
---
> private TextView textView=null;
> private Button buttonView=null;
>
>
58c62
<
---
>
61c65
<
---
>
63c67
<
---
>
68c72
< labelView = new TextView(activity);
---
> labelView = new TextView(activity); // was button before
79d82
< textView = new TextView(activity);
81,82c84,86
< textView.setClickable(true);
< textView.setOnClickListener(new View.OnClickListener() {
---
> buttonView = new Button(activity);
> buttonView.setClickable(true);
> buttonView.setOnClickListener(new View.OnClickListener() {
90a95,98
> buttonView.setLayoutParams(new LinearLayout.LayoutParams(
> LinearLayout.LayoutParams.FILL_PARENT,
> LinearLayout.LayoutParams.WRAP_CONTENT));
> addView(buttonView);
92c100,103
< textView.setLayoutParams(new LinearLayout.LayoutParams(
---
> else
> {
> textView = new TextView(activity);
> textView.setLayoutParams(new LinearLayout.LayoutParams(
95c106,108
< addView(textView);
---
> addView(textView);
> }
>
117c130
<
---
>
156c169,170
< textView.setText(text);
---
> if(textView!=null) textView.setText(text);
> if(buttonView!=null) buttonView.setText(text);

Bartek Teodorczyk

unread,
Mar 27, 2012, 5:02:19 AM3/27/12
to microemulato...@googlegroups.com
On Tue, Mar 20, 2012 at 1:11 AM, ValtersB <valters...@gmail.com> wrote:
> Hi,
>
> here are two improvements for the Android port of the latest
> Microemulator snapshot as downloaded from here:
> http://snapshot.microemu.org/microemulator/download/ (10-Jan-2012
> 03:05 2.0M)
>
> for whomever might need them

Hi,

Would be possible if we discuss more details about your issues:

>
> 1. Android buttons are now shown as real Android buttons instead of
> strings

Why would you need the buttons inside the AndroidImageStringItemUI?

> 2. my tests indicate a bug in the latest snapshot - Canvas height is
> being clipped down

What are the conditions you are experiencing this problem? Maybe you
have some simple code I can reproduce this?

BR,
Bartek Teodorczyk

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

ValtersB

unread,
Mar 28, 2012, 10:34:42 AM3/28/12
to microemulator-developers
Hi Bartek,

Of course there are many, many different scenarios, and neither I nor
you can test them all, it was just that for me the two fixes fixed two
problems.

About buttons:
I use such code to add a button to form:
public Form resultScreen;
private final Command CMD_LOGIN = new Command("Login", Command.ITEM,
1);
resultScreen = new Form("Join game");
StringItem item = new StringItem("", "Login", Item.BUTTON);
item.setDefaultCommand(CMD_LOGIN);
item.setItemCommandListener(this);
resultScreen.append(item);

Now the button "Login" will appear as simple text, although it will be
click-able. The code I supplied fixes this and it now appears as real
Android button and everything is OK. I use Android-4 SDK (for maximum
resulting binary compatibility) for compilation, but as far as I
remember the earlier SDKs has the problem too.

Regarding the canvas height:

The code would be too large to supply.
I just use standard canvas like this:
class zCanvas extends Canvas {
int bwidth, bheight; // dimensions of current screen
public void init () {
setFullScreenMode(true);
bwidth=getWidth(); bheight=getHeight();
}
protected void paint(Graphics g) {
g.setColor(245,225,200);
g.fillRect(0, 0, this.bwidth , this.bheight );
}
}
public class g_z extends MIDlet implements CommandListener Runnable
{
zCanvas canvas;
g_z()
{
canvas = new zCanvas ();
canvas.init();
canvas.repaint();
}
}

That code is incomplete of course, but just as an example.
Now upon every repaint it will cut of the bottom part of the screen -
something like it would draw as if in non-fullscreen mode, and yet the
getHeight would return the right size. By commenting out that line
everything is OK.

Valters.

On 27 Marts, 12:02, Bartek Teodorczyk <bar...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages