Skip to content

Commit 6a63d2f

Browse files
committed
Updated layout and functionality.
1 parent 258bb0b commit 6a63d2f

File tree

6 files changed

+138
-61
lines changed

6 files changed

+138
-61
lines changed

android/jms/app/src/main/java/com/kaazing/gateway/jms/client/demo/JMSDemoActivity.java

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,16 @@
2626
import javax.jms.Session;
2727
import javax.jms.TextMessage;
2828

29+
import android.app.Activity;
2930
import android.os.Bundle;
3031
import android.support.v4.app.FragmentActivity;
32+
import android.text.Editable;
33+
import android.text.TextWatcher;
3134
import android.text.method.ScrollingMovementMethod;
3235
import android.util.Log;
3336
import android.view.View;
3437
import android.view.View.OnClickListener;
38+
import android.view.inputmethod.InputMethodManager;
3539
import android.widget.Button;
3640
import android.widget.CheckBox;
3741
import android.widget.EditText;
@@ -71,6 +75,11 @@ public class JMSDemoActivity extends FragmentActivity {
7175

7276
private HashMap<String, ArrayDeque<MessageConsumer>> consumers = new HashMap<String, ArrayDeque<MessageConsumer>>();
7377

78+
private void hideKeyboard() {
79+
InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
80+
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
81+
}
82+
7483
/**
7584
* Called when the activity is first created.
7685
* @param savedInstanceState If the activity is being re-initialized after
@@ -100,7 +109,29 @@ public void onCreate(Bundle savedInstanceState) {
100109

101110
Logger logger = Logger.getLogger("com.kaazing.gateway.jms.client");
102111
logger.setLevel(Level.FINE);
103-
112+
113+
locationText.addTextChangedListener(new TextWatcher() {
114+
@Override
115+
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
116+
117+
}
118+
119+
@Override
120+
public void onTextChanged(CharSequence s, int start, int before, int count) {
121+
String url=locationText.getText().toString();
122+
if (url.length()>0){
123+
connectBtn.setEnabled(true);
124+
}
125+
else{
126+
connectBtn.setEnabled(false);
127+
}
128+
}
129+
130+
@Override
131+
public void afterTextChanged(Editable s) {
132+
133+
}
134+
});
104135

105136
if (connectionFactory == null) {
106137
try {
@@ -112,9 +143,10 @@ public void onCreate(Bundle savedInstanceState) {
112143
logMessage("EXCEPTION: " + e.getMessage());
113144
}
114145
}
115-
146+
116147
connectBtn.setOnClickListener(new OnClickListener() {
117148
public void onClick(View v) {
149+
hideKeyboard();
118150
connectBtn.setEnabled(false);
119151
dispatchQueue = new DispatchQueue("DispatchQueue");
120152
dispatchQueue.start();
@@ -131,6 +163,7 @@ public void onClick(View v) {
131163

132164
subscribeBtn.setOnClickListener(new OnClickListener() {
133165
public void onClick(View v) {
166+
hideKeyboard();
134167
final String destinationName = destinationText.getText().toString();
135168
logMessage("SUBSCRIBE - " + destinationName);
136169
dispatchQueue.dispatchAsync(new Runnable() {
@@ -184,6 +217,7 @@ public void run() {
184217

185218
sendBtn.setOnClickListener(new OnClickListener() {
186219
public void onClick(View v) {
220+
hideKeyboard();
187221
final boolean sendBinary = sendBinaryCheckBox.isChecked();
188222
final String text = messageText.getText().toString();
189223
logMessage("SEND: " + text);
@@ -318,7 +352,7 @@ else if (destinationName.startsWith("/queue/")) {
318352
destination = session.createQueue(destinationName);
319353
}
320354
else {
321-
logMessage("Invalid destination name: " + destinationName);
355+
logMessage("Invalid destination name: " + destinationName+". Destination should start from '/topic/' or '/queue/'");
322356
return null;
323357
}
324358
return destination;

android/jms/app/src/main/res/layout/main.xml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919
android:layout_height="wrap_content"
2020
android:text="@string/location_label"
2121
android:textAppearance="?android:attr/textAppearanceMedium"
22-
android:textSize="@dimen/edit_text_size" />
22+
android:textSize="@dimen/edit_text_size"
23+
android:layout_weight="0.04" />
2324

2425
<EditText
2526
android:id="@+id/locationText"
2627
android:layout_width="0dp"
2728
android:layout_height="wrap_content"
2829
android:layout_marginLeft="5dp"
29-
android:layout_weight="1"
30+
android:layout_weight="0.85"
3031
android:ems="10"
3132
android:text="@string/location_default"
3233
android:textSize="@dimen/edit_text_size"
@@ -46,18 +47,19 @@
4647
android:layout_marginRight="5dp"
4748
android:enabled="false"
4849
android:text="@string/disconnectBtn_label"
49-
android:textSize="@dimen/edit_text_size" />
50+
android:textSize="@dimen/edit_text_size"
51+
android:layout_toEndOf="@+id/connectBtn" />
5052

5153
<Button
5254
android:id="@+id/connectBtn"
5355
style="?android:attr/buttonStyleSmall"
5456
android:layout_width="wrap_content"
5557
android:layout_height="wrap_content"
56-
android:layout_alignBaseline="@+id/disconnectBtn"
57-
android:layout_alignBottom="@+id/disconnectBtn"
58-
android:layout_toLeftOf="@+id/disconnectBtn"
5958
android:text="@string/connectBtn_label"
60-
android:textSize="@dimen/edit_text_size" />
59+
android:textSize="@dimen/edit_text_size"
60+
android:layout_below="@+id/linearLayout1"
61+
android:layout_alignEnd="@+id/subscribeBtn"
62+
android:layout_alignStart="@+id/subscribeBtn" />
6163

6264
<LinearLayout
6365
android:id="@+id/linearLayout2"
@@ -129,7 +131,8 @@
129131
android:layout_height="wrap_content"
130132
android:text="@string/message_label"
131133
android:textAppearance="?android:attr/textAppearanceMedium"
132-
android:textSize="@dimen/edit_text_size" />
134+
android:textSize="@dimen/edit_text_size"
135+
android:layout_weight="0.04" />
133136

134137
<EditText
135138
android:id="@+id/messageText"
@@ -155,7 +158,8 @@
155158
android:layout_marginRight="5dp"
156159
android:enabled="false"
157160
android:text="@string/send_label"
158-
android:textSize="@dimen/edit_text_size" />
161+
android:textSize="@dimen/edit_text_size"
162+
android:layout_alignStart="@+id/unsubscribeBtn" />
159163
<CheckBox
160164
android:id="@+id/sendBinaryCheckBox"
161165
android:layout_width="wrap_content"
@@ -189,7 +193,7 @@
189193
<Button
190194
android:id="@+id/clearBtn"
191195
style="?android:attr/buttonStyleSmall"
192-
android:layout_width="wrap_content"
196+
android:layout_width="89dp"
193197
android:layout_height="wrap_content"
194198
android:layout_gravity="right"
195199
android:layout_marginRight="5dp"

android/jms/app/src/main/res/values/strings.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3-
<string name="app_name_short">JMS Demo</string>
4-
<string name="app_name">JMS Messaging Demo</string>
3+
<string name="app_name_short">Kaazing WebSocket JMS Demo</string>
4+
<string name="app_name">Kaazing WebSocket JMS Messaging Demo</string>
55
<string name="location_label">Location</string>
66
<string name="connectBtn_label">Connect</string>
77
<string name="disconnectBtn_label">Disconnect</string>

android/ws/app/src/main/java/com/kaazing/ws/client/demo/EchoActivity.java

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@
1010
import java.nio.ByteBuffer;
1111
import java.util.concurrent.Semaphore;
1212

13+
import android.app.Activity;
1314
import android.os.Bundle;
1415
import android.support.v4.app.FragmentActivity;
16+
import android.text.Editable;
17+
import android.text.TextWatcher;
1518
import android.view.View;
1619
import android.view.View.OnClickListener;
20+
import android.view.inputmethod.InputMethodManager;
1721
import android.widget.Button;
1822
import android.widget.CheckBox;
1923
import android.widget.TextView;
@@ -32,9 +36,9 @@
3236

3337
public class EchoActivity extends FragmentActivity {
3438

35-
private TextView location;
36-
private TextView message;
37-
private TextView log;
39+
private TextView locationText;
40+
private TextView messageText;
41+
private TextView logTextView;
3842
private Button sendBtn;
3943
private Button connectBtn;
4044
private Button disconnectBtn;
@@ -47,43 +51,75 @@ public class EchoActivity extends FragmentActivity {
4751
private boolean closedExplicitly = false;
4852
private LoginDialogFragment loginDialog;
4953

50-
/** Called when the activity is first created. */
54+
private void hideKeyboard() {
55+
InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
56+
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
57+
}
58+
59+
60+
/** Called when the activity is first created. */
5161
@Override
5262
public void onCreate(Bundle savedInstanceState) {
5363
super.onCreate(savedInstanceState);
5464
setContentView(R.layout.main);
55-
location = (TextView)findViewById(R.id.location);
56-
message = (TextView)findViewById( R.id.message);
57-
log = (TextView)findViewById(R.id.log);
65+
locationText = (TextView)findViewById(R.id.locationText);
66+
messageText = (TextView)findViewById( R.id.messageText);
67+
logTextView = (TextView)findViewById(R.id.logView);
5868
sendBtn = (Button)findViewById(R.id.send);
59-
connectBtn = (Button)findViewById(R.id.connect);
60-
disconnectBtn = (Button)findViewById(R.id.disconnect);
61-
clearBtn = (Button)findViewById(R.id.clear);
69+
connectBtn = (Button)findViewById(R.id.connectBtn);
70+
disconnectBtn = (Button)findViewById(R.id.disconnectBtn);
71+
clearBtn = (Button)findViewById(R.id.clearBtn);
6272
sendBinaryCheckBox = (CheckBox)findViewById(R.id.sendBinaryCheckBox);
6373

74+
75+
locationText.addTextChangedListener(new TextWatcher() {
76+
@Override
77+
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
78+
79+
}
80+
81+
@Override
82+
public void onTextChanged(CharSequence s, int start, int before, int count) {
83+
String url= locationText.getText().toString();
84+
if (url.length()>0){
85+
connectBtn.setEnabled(true);
86+
}
87+
else{
88+
connectBtn.setEnabled(false);
89+
}
90+
}
91+
92+
@Override
93+
public void afterTextChanged(Editable s) {
94+
95+
}
96+
});
97+
6498
connectBtn.setOnClickListener(new OnClickListener() {
6599
public void onClick(View v) {
100+
hideKeyboard();
66101
connectBtn.setEnabled(false);
67102
connect();
68103
}
69104
});
70105

71106
sendBtn.setOnClickListener(new OnClickListener() {
72107
public void onClick(View v) {
108+
hideKeyboard();
73109
final boolean sendBinary = sendBinaryCheckBox.isChecked();
74110
dispatchQueue.dispatchAsync(new Runnable() {
75111
public void run() {
76112
try {
77113
WebSocketMessageWriter messageWriter = webSocket.getMessageWriter();
78114
if (sendBinary) {
79-
String messageToSend = message.getText().toString();
115+
String messageToSend = messageText.getText().toString();
80116
ByteBuffer payload = ByteBuffer.wrap(messageToSend.getBytes());
81117
logMessage("SEND BINARY:" + getHexDump(payload));
82118
messageWriter.writeBinary(payload);
83119
}
84120
else {
85-
logMessage("SEND: " + message.getText());
86-
messageWriter.writeText(message.getText());
121+
logMessage("SEND: " + messageText.getText());
122+
messageWriter.writeText(messageText.getText());
87123
}
88124
} catch (Exception e) {
89125
e.printStackTrace();
@@ -102,7 +138,7 @@ public void onClick(View v) {
102138

103139
clearBtn.setOnClickListener(new OnClickListener() {
104140
public void onClick(View v) {
105-
log.setText("");
141+
logTextView.setText("");
106142
}
107143
});
108144

@@ -147,7 +183,7 @@ private void connect() {
147183
public void run() {
148184
try {
149185
WebSocketFactory webSocketFactory = WebSocketFactory.createWebSocketFactory();
150-
webSocket = webSocketFactory.createWebSocket(URI.create(location.getText().toString()));
186+
webSocket = webSocketFactory.createWebSocket(URI.create(locationText.getText().toString()));
151187
webSocket.setChallengeHandler(createChallengehandler());
152188
webSocket.connect();
153189
logMessage("CONNECTED");
@@ -211,7 +247,7 @@ public void run() {
211247
private void logMessage(final String logMessage) {
212248
runOnUiThread(new Runnable() {
213249
public void run() {
214-
log.setText(logMessage + "\n" + log.getText());
250+
logTextView.setText(logMessage + "\n" + logTextView.getText());
215251
}
216252
});
217253
}

0 commit comments

Comments
 (0)