My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions

Issue 86 attachment: AndroidImageStringItemUI.java (4.7 KB)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/**
* MicroEmulator
* Copyright (C) 2009 Bartek Teodorczyk <barteo@barteo.net>
*
* It is licensed under the following two licenses as alternatives:
* 1. GNU Lesser General Public License (the "LGPL") version 2.1 or any newer version
* 2. Apache License (the "AL") Version 2.0
*
* You may not use this file except in compliance with at least one of
* the above two licenses.
*
* You may obtain a copy of the LGPL at
* http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
*
* You may obtain a copy of the AL at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the LGPL or the AL for the specific language governing permissions and
* limitations.
*
* @version $Id: AndroidImageStringItemUI.java 1931 2009-02-05 21:00:52Z barteo $
*/

package org.microemu.android.device.ui;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ImageItem;
import javax.microedition.lcdui.StringItem;

import org.microemu.MIDletBridge;
import org.microemu.android.MicroEmulatorActivity;
import org.microemu.android.device.AndroidImmutableImage;
import org.microemu.android.device.AndroidMutableImage;
import org.microemu.device.ui.ImageStringItemUI;

import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.ImageButton;
import android.view.View;

public class AndroidImageStringItemUI extends LinearLayout implements ImageStringItemUI {

private MicroEmulatorActivity activity;

private TextView labelView;

private ImageView imageView;

private TextView textView;

private Command defaultCommand;

public AndroidImageStringItemUI(final MicroEmulatorActivity activity, final Item item) {
super(activity);

this.activity = activity;

setOrientation(LinearLayout.VERTICAL);
setFocusable(false);
setFocusableInTouchMode(false);

labelView = new TextView(activity);
labelView.setFocusable(false);
labelView.setFocusableInTouchMode(false);
labelView.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
labelView.setTextAppearance(labelView.getContext(),
android.R.style.TextAppearance_Large);
labelView.setVisibility(GONE);
addView(labelView);

if (item instanceof StringItem && ((StringItem) item).getAppearanceMode() == Item.BUTTON) {
textView = new Button(activity);
textView.setClickable(true);
textView.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
if (defaultCommand != null) {
MIDletBridge.getMIDletAccess().getDisplayAccess().commandAction(defaultCommand, item);
}
}

});
}
else
textView = new TextView(activity);

textView.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
addView(textView);

if (item instanceof ImageItem && ((ImageItem) item).getAppearanceMode() == Item.BUTTON) {
imageView = new ImageButton(activity);
imageView.setClickable(true);
imageView.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
if (defaultCommand != null) {
MIDletBridge.getMIDletAccess().getDisplayAccess().commandAction(defaultCommand, item);
}
}

});
} else {
imageView = new ImageView(activity);
}
imageView.setVisibility(GONE);
addView(imageView);

setLabel(item.getLabel());
}

public void setDefaultCommand(Command cmd) {
this.defaultCommand = cmd;
}

public void setLabel(final String label) {
activity.post(new Runnable() {
public void run() {
if (label == null) {
labelView.setVisibility(GONE);
} else {
labelView.setVisibility(VISIBLE);
labelView.setText(label);
}
}
});
}

public void setImage(final Image image) {
activity.post(new Runnable() {
public void run() {
if (image == null) {
imageView.setVisibility(GONE);
imageView.setImageBitmap(null);
} else {
imageView.setVisibility(VISIBLE);
if (image.isMutable()) {
imageView.setImageBitmap(((AndroidMutableImage) image).getBitmap());
} else {
imageView.setImageBitmap(((AndroidImmutableImage) image).getBitmap());
}
}
}
});
}

public void setText(final String text) {
activity.post(new Runnable() {
public void run() {
textView.setText(text);
}
});
}

}
Powered by Google Project Hosting