Skip to content

Commit b624907

Browse files
committed
pass css selector to target color changes
1 parent b0ba9b0 commit b624907

File tree

3 files changed

+35
-18
lines changed

3 files changed

+35
-18
lines changed

src/AndroidClient/androidchat/src/main/java/servicestack/net/androidchat/ChatCommandHandler.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
import android.content.Context;
77
import android.content.Intent;
88
import android.graphics.Color;
9+
import android.graphics.drawable.ColorDrawable;
910
import android.os.Vibrator;
1011
import android.widget.Button;
1112
import android.widget.EditText;
1213
import android.widget.ImageView;
1314
import android.widget.ListView;
1415

1516
import net.servicestack.android.AsyncUtils;
17+
import net.servicestack.client.Utils;
1618
import net.servicestack.func.Func;
1719

1820
import java.util.ArrayList;
@@ -123,7 +125,7 @@ private void cancelNotification(NotificationManager notificationManager)
123125
public void changeBackground(String message)
124126
{
125127
String url = message.startsWith("url(")
126-
? message.substring(4, message.length() - 5)
128+
? message.substring(4, message.length() - 1)
127129
: message;
128130

129131
App.get().readBitmap(url, bitmap -> {
@@ -132,18 +134,31 @@ public void changeBackground(String message)
132134
});
133135
}
134136

135-
public void changeBackgroundColor(String message)
136-
{
137+
public void changeBackgroundColor(String message, String cssSelector){
137138
// Inject alpha values
138139
String color = message.replace("#", "#AA");
139140
ListView chatLayout = (ListView)parentActivity.findViewById(R.id.messageHistory);
140141
EditText editText = (EditText)parentActivity.findViewById(R.id.message);
141142
Button sendButton = (Button)parentActivity.findViewById(R.id.sendMessageButton);
142143

144+
int colorVal = Color.parseColor(color);
143145
parentActivity.runOnUiThread(() -> {
144-
chatLayout.setBackgroundColor(Color.parseColor(color));
145-
editText.setBackgroundColor(Color.parseColor(color));
146-
sendButton.setBackgroundColor(Color.parseColor(color));
146+
if (Objects.equals(cssSelector, "#top")){
147+
parentActivity.getSupportActionBar().setBackgroundDrawable(
148+
new ColorDrawable(colorVal)
149+
);
150+
}
151+
152+
if (Objects.equals(cssSelector, "#body") || cssSelector == null){
153+
chatLayout.setBackgroundColor(colorVal);
154+
ImageView chatBackground = (ImageView)parentActivity.findViewById(R.id.chat_background);
155+
chatBackground.setImageDrawable(null);
156+
}
157+
158+
if (Objects.equals(cssSelector, "#bottom")){
159+
editText.setBackgroundColor(colorVal);
160+
sendButton.setBackgroundColor(colorVal);
161+
}
147162
});
148163
}
149164
}

src/AndroidClient/androidchat/src/main/java/servicestack/net/androidchat/CssReceiver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public void backgroundImage(String message){
1717
chatMessageHandler.changeBackground(message);
1818
}
1919

20-
public void Background(String message){
21-
chatMessageHandler.changeBackgroundColor(message);
20+
public void background(String message){
21+
chatMessageHandler.changeBackgroundColor(message, super.getRequest().getCssSelector());
2222
}
2323
}

src/AndroidClient/androidchat/src/main/java/servicestack/net/androidchat/MainActivity.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,13 @@ public class MainActivity extends AppCompatActivity {
5050
private List<ServerEventUser> subscriberList = new ArrayList<>();
5151

5252
private static Map<String, String> commands = Func.toDictionary(
53-
"Announce Hello", "/cmd.announce Hello from Android",
54-
"Play YouTube", "/tv.watch https://youtu.be/u5CVsCnxyXg",
55-
"Set background color", "/css.background$#top #0091ea",
56-
"Reset background color", "/css.background$#top #ffffff",
57-
"Logout", "/logout"
53+
"Announce Hello", "/cmd.announce Hello from Java Android",
54+
"Play YouTube", "/tv.watch https://youtu.be/u5CVsCnxyXg",
55+
"Background Image", "/css.background-image url(http://bit.ly/2lZxbHv)",
56+
"Background Top", "/css.background$#top #0091ea",
57+
"Background", "/css.background #fffde7",
58+
"Background Bottom", "/css.background$#bottom #cccccc",
59+
"Logout", "/logout"
5860
);
5961

6062
public AndroidServerEventsClient getClient(){
@@ -124,11 +126,11 @@ protected void onCreate(Bundle savedInstanceState) {
124126
});
125127

126128
drawerToggle = new ChatActionBarDrawerToggle(
127-
this, //Host Activity
128-
drawerLayout, //DrawerLayout
129-
toolbar, //Instance of toolbar, if you use other ctor, the hamburger icon/arrow animation won't work..
130-
R.string.openDrawer, //Opened Message
131-
R.string.closeDrawer //Closed Message
129+
this, //Host Activity
130+
drawerLayout, //DrawerLayout
131+
toolbar, //Instance of toolbar, if you use other ctor, the hamburger icon/arrow animation won't work..
132+
R.string.openDrawer, //Opened Message
133+
R.string.closeDrawer //Closed Message
132134
);
133135

134136
getSupportActionBar().setHomeButtonEnabled(true);

0 commit comments

Comments
 (0)