Chrome theme bug Codename One - codenameone

I got this button to switch themes:
public void onButtonThemeActionEvent(com.codename1.ui.events.ActionEvent ev) {
if(index == 0) {
index++;
UIManager.initNamedTheme("/theme", "Leather");
Display.getInstance().getCurrent().refreshTheme();
}
else if(index == 1) {
index++;
UIManager.initNamedTheme("/theme", "Chrome");
Display.getInstance().getCurrent().refreshTheme();
}
else if(index == 2) {
index++;
UIManager.initNamedTheme("/theme", "FlatOrange");
Display.getInstance().getCurrent().refreshTheme();
}
else if(index == 3) {
index++;
UIManager.initNamedTheme("/theme", "FlatBlue");
Display.getInstance().getCurrent().refreshTheme();
}
else if(index == 4) {
index++;
UIManager.initNamedTheme("/theme", "FlatRed");
Display.getInstance().getCurrent().refreshTheme();
}
else if(index == 5) {
index = 0;
UIManager.initNamedTheme("/theme", "Business");
Display.getInstance().getCurrent().refreshTheme();
}
}
This code will change the themes in a sequence as you can see, the problem happens when changing from Leather to Chrome then as you can see in the image below in the Form title is missing a letter "Tela Principa" it should be "Tela Principal" instead.
OBS: This is an Android Device.
Chrome theme missing a letter in the Form title:
After navigating through any menu and backing to Tela Principal, it is fixed as in the following image:
How to fix this Chrome theme bug?

You need to add a revalidate() after switching themes so the UI will update to new font sizes/padding/margin etc.
If that doesn't work try a forceRevalidate() which you shouldn't normally do but is sometimes necessary.

Related

Arduino with adafruit RGBLCDShield Buttons weird behavior

I have the Arduino uno with rgb lcd shield. there is a very weird behavior with the buttons in one specific function.
The function is called yes/no. It displays a message on the screen (working) the user can select answer yes/no with the buttons up/down/left/right and approve the answer by pressing select button.
The function is as follows:
bool yesno(String message)
{
//Serial.println("asking yesno question " + message);
bool answer = false;
bool answerSelected = false;
setColor('r');
setText(message+'?', "no");
while (!answerSelected)
{
uint8_t buttons = lcd.readButtons();
if (buttons){
if (buttons &(BUTTON_UP || BUTTON_DOWN || BUTTON_RIGHT || BUTTON_LEFT)) {
if (answer) {
answer = false;
setColor('r');
setText(message+'?', "no");
Serial.println(answer);
}
else {
answer = true;
setColor('g');
setText(message+'?', "yes");
Serial.println(answer);
}
}
else if (buttons & BUTTON_SELECT) {
setColor('w');
answerSelected = true;
Serial.println("selected ");
Serial.println(answer);
return answer;
}
}
delay(50);
}
}
for some reason, when pressing left/right/up/down, nothing happens. When pressing select, instead it executes function up/down/left/right
using if (buttons &&(BUTTON_UP || BUTTON_DOWN || BUTTON_RIGHT || BUTTON_LEFT)) instead, the buttons left/right/up/down work as intended but the button select still acts as the other buttons
similar code for a menu works as intended:
void InitializeMenu()
{
// initialize
Serial.println("entering menu");
setColor('w');
while (!exitMenu)
{
if (menuItem != selectedItem)
{
Serial.println("switching menu to: "+menuItems[menuItem]);
setText("Menue", menuItems[menuItem]);
selectedItem = menuItem;
}
uint8_t buttons = lcd.readButtons();
if (buttons & BUTTON_UP) {
menuItem--;
Serial.println("menu up");
Serial.println(menuItem);
Serial.println(menuSize);
if (menuItem < 0)
{
menuItem = menuSize;
Serial.println("start of menu going to end");
}
}
if (buttons & BUTTON_DOWN) {
menuItem++;
Serial.println("menu down");
Serial.println(menuItem);
Serial.println(menuSize);
if (menuItem > menuSize) {
menuItem = 0;
Serial.println("end of menu going to start");
}
}
if (buttons & BUTTON_SELECT) {
Serial.println("enter");
if (menuItem == menuSize) exitMenu = true;
}
delay(50);
}
}
I want to keep the code as short and simple as possible due to very limited space on the arduino uno.
BUTTON_UP || BUTTON_DOWN || BUTTON_RIGHT || BUTTON_LEFT
doesn't do what you expect it to do. || is logical or, and the entire expression evaluates to true. To get a bitmask, change it to bitwise or (|):
BUTTON_UP | BUTTON_DOWN | BUTTON_RIGHT | BUTTON_LEFT

Only first image appears from an array?

I found this example of exactly what I want to do except with .svg files. It appears to work as I have to click the right arrow 6 times to show the first image again. Is there a reason why the other svg images aren't showing?
Here is the code I adapted:
int maxImages = 6; // Total # of images
int imageIndex = 0; // Initial image to be displayed is the first
boolean isPlaying = false;
// Declaring an array of images.
PShape[] images = new PShape[maxImages];
void setup() {
size(1080,1920);
// Loading the images into the array
// Don't forget to put the JPG files in the data folder!
for (int i = 0; i < images.length; i ++ ) {
images[i] = loadShape( "HairStyles" + i + ".svg" );
}
frameRate(5);
}
void draw() {
background(100);
shape(images[imageIndex],500,500);
}
// Only happens when you release key
void keyReleased() {
if (keyCode == RIGHT) {
// Cycle
if (imageIndex >= 5) {
imageIndex = 0;
}
else {
imageIndex += 1;
}
}
else if (keyCode == LEFT) {
// Cycle backwards
if (imageIndex <= 0) {
imageIndex = 5;
}
else {
imageIndex -= 1;
}
}
}
It's pretty much the same as the example, could my problem be something to do with the exported files?

Efficiently navigating arrays and selected strings

I am a noob playing around with actionscript but i feel this question is a basic coding questionMy project is similar to this picture.
I have four quadrant areas (Red, blue, yellow, and green) that I am adding text buttons to each area with a single word in each button. There are 16 words in each section that are added from 4 arrays that have the preset words (redWordArray, greenWordArray, yellowWordArray, blueWordArray). When clicked, the text button glows using a glow filter and the word gets added to another array for data collecting. For instance, a red word when clicked gets added to a red array (redChosenArray). When the word is clicked again, it removes the glow filter and is removed from the chosen array.
I am finding that my performance is slow and I am wondering if I am adding and deleting words correctly and efficiently. These are my functions for adding the glow filters and the selected word to the array. I would love your insights for best coding practices as I am sure it is a mess!
Thank you!
function selectWord(event:MouseEvent):void
{
var tempWord:String = event.currentTarget.mood.text;
var tempArray:Array;
if (event.currentTarget.clicked == false)
{
event.currentTarget.filters = filterArray;
event.currentTarget.clicked = true;
tempArray = addToArray(tempWord)
tempArray.push(tempWord);
trace(redChosen);
trace(blueChosen);
trace(yellowChosen);
trace(greenChosen);
trace("");
}else if(event.currentTarget.clicked == true)
{
event.currentTarget.filters = emptyFilterArray;
event.currentTarget.clicked = false;
removeMoodWord(tempWord);
trace(redChosen);
trace(blueChosen);
trace(yellowChosen);
trace(greenChosen);
trace("");
}
}
function addToArray(moodWord:String):Array
{
var wordFound:Boolean = false;
var allWords:int = 16;
var chosenArray:Array;
while (!wordFound)
{
for (var h:int = 0; h < allWords; h++)
{
if (moodWord == redWords[h])
{
chosenArray = redChosen;
wordFound = true;
}else if (moodWord == yellowWords[h])
{
chosenArray = yellowChosen
wordFound = true;
}else if (moodWord == greenWords[h])
{
chosenArray = greenChosen
wordFound = true;
}else if (moodWord == blueWords[h])
{
chosenArray = blueChosen
wordFound = true;
}
}
}
return chosenArray;
}
function removeMoodWord(moodWord:String):void
{
if (redChosen.indexOf(moodWord) >= 0)
{
redChosen.splice(redChosen.indexOf(moodWord), 1);
}else if (blueChosen.indexOf(moodWord) >= 0)
{
blueChosen.splice(blueChosen.indexOf(moodWord), 1);
}else if (yellowChosen.indexOf(moodWord) >= 0)
{
yellowChosen.splice(yellowChosen.indexOf(moodWord), 1);
}else if (greenChosen.indexOf(moodWord) >= 0)
{
greenChosen.splice(greenChosen.indexOf(moodWord), 1);
}
i fee}

Swipe over table in mobile browser

I and my teammate are writing the game "Battlecity" in dart for mobile browser. The problem is with swipes for tank direction(left to right, right to left, etc) in mobile browser. It works with a great delation(and for some reasond doesn't works in Chrome-Browser).
You can see the problem better, if you start the game on your mobile device(just open link with game: https://javajunikorn.github.io/BattleCity/build/web/html/test.html)
Interesting thing is, that the problem exists only on swipes over gamefield(in our case it's 27*27 html table). If we're swiping out of gamefeeld, than it works great.
Here is code of our Controller:
class Direction{
Point first, last;
Game game;
void startListening(){
window.onTouchStart.listen((ev) {
last = null;
first = ev.touches.first.client;
});
window.onTouchMove.listen((ev){
last = ev.touches.first.client;
});
window.onTouchEnd.listen((ev) {
if(last == null || first.distanceTo(last) < 20)
game.player.shoot();
else {
Point d = first - last;
if(d.x.abs() > d.y.abs()){
//Waagerecht
if( first.x > last.x){
//links
game.player.changeDirection(Directions.left);
}
else{
//rechts
game.player.changeDirection(Directions.right);
}
}
else{
//Senkrecht
if(first.y > last.y){
//Up
game.player.changeDirection(Directions.up);
}
else{
//Down
game.player.changeDirection(Directions.down);
}
}
}
});
window.onKeyPress.listen((k) {
//Shoot
if(k.which == 32) { //spacebar
game.player.shoot();
}
//Up
if(k.which == 119 || k.keyCode == KeyCode.UP){
game.player.changeDirection(Directions.up);
}
//Down
if(k.which == 115 || k.keyCode == KeyCode.DOWN){
game.player.changeDirection(Directions.down);
}
//Left
if(k.which == 97 || k.keyCode == KeyCode.LEFT){
game.player.changeDirection(Directions.left);
}
//Right
if(k.which == 100 || k.keyCode == KeyCode.RIGHT){
game.player.changeDirection(Directions.right);
}
});
}
}

iOS 6 Orientation to display one view in portrait and another view in landscape

I want to show one view in landscape forcibly.
All other views are in portrait.
I tried the code below to show landscape mode while coming from portrait mode. It is not working.
How can I do this?
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ((interfaceOrientation == UIInterfaceOrientationMaskLandscape) ||
(interfaceOrientation == UIInterfaceOrientationMaskLandscapeLeft) ||
(interfaceOrientation == UIInterfaceOrientationMaskLandscapeRight))
{
return YES;
}
return NO;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
-(BOOL)shouldAutorotate{
return NO;
}
-(NSInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}

Resources