How to put time delay in COCOS2D Android - android

Similar to Android unlock pattern where in, initially all the circular cells will be in grey color. During when we draw some pattern, those cells touched will become green colored and if that pattern is not a correct one, then the cells touched will become red colored and after some 3 seconds, they become grey colored. I am doing similar thing using COCOS2D. I am getting difficulty in introducing that 3 seconds delay before making the cells back to grey colored. Any suggestions...Thanks.

You can use CCSequence in that first put CCDelayTime and in second put CCCallFuncN(which contain logic of again color your circle to grey)
Below i am providing you iOs code logic
id action1 = [DelayTime ...];
id action2 = [CallFunc ...];
id seq = [Sequence actions:action1, action2, nil];
[someNode runAction:seq];

Related

Transparent white button looks bad in Android Material Design

Consider these 2 screenshots. I defined the elements on the left, top, and bottom-right:
The left/top screenshot has all my elements using a solid white (#FFFFFF) while the bottom/right one adds a bit of transparency (#D0FFFFFF). My issue is that my elements look hideous with transparency. For example the FAB (bottom-right) contains a smaller opaque circle for no reason.
All my elements have elevation 6 (as that is the FAB default elevation). Anything greater-than elevation 2 has this issue clearly visible, and anything below 2 does not cast enough shadow for me to look acceptable.
The Maps-defined element (top-right) seems completely unaffected by this however! What is it doing differently? It's clearly using transparency like me and also casting a shadow corresponding to elevation 2 or more.
Code used is basically this:
fab = FloatingActionButton(this.context!!)
fab.backgroundTintList = ColorStateList.valueOf(Color.parseColor("#d0ffffff"))
fab.compatElevation = 6F
For example the FAB (bottom-right) contains a smaller opaque circle
for no reason.
later on... fab.compatElevation = 6F
 
The circle you are seeing it's FAB's shadow, which is generated by the elevation.
If you want to remove the shadow but keep the elevation, do:
fab.outlineProvider = null
If you want to keep both elevation and shadow, you have to make a custom outlineProvider (probably a banana shaped one).

Android Transparent View Color Calculation Logic

I am wondering what logic Android uses to calculate the final color of a view given two semi-transparent views being stacked.
What I need to do specifically is take two semi-transparent views (let's say with backgrounds #66000000 and #33000000) and figure out what the equivalent singular view COLOR would be.
I have tried ColorUtils.blendARGB but this does not give me the correct value.
Ok this formula seems to work for what I needed:
C1=[R1,G1,B1] is the foreground pixel color.
C2=[R2,G2,B2] is the background pixel color.
p1 is the opacity percentage of the foreground pixel. (0.4) in my case
p2 is the opacity percentage of the background pixel. (0.2)
NewPixelColor = (p1*c1+p2*c2-p1*p2*c2)/(p1+p2-p1*p2)
NewPixelOpacity = p1+p2-p1*p2

Fill shape with text with two different color

I tried to achieve this but I am only able to achieve to fill object (shape).
My requirement is to change text color along with shape filling.
Shape can be filled with percentage like till
10% to 50% = Green
51% to 80% = Yellow
81% to 100% = Red
When Yellow color fills background of ":" in shape, it will change color to "White" which is previously "Yellow". Size of this shape is also dynamic.
What I tried and achieved?
I am able to fill shape with percentage but failed to change color when it reaches to edge of text.
I wrote a custom view. You get this double color effect using Path APIs. But for Android 1+ compatibility, you should use Region API and above Kitkat (19+) you can use just Path API.
Let's go through the concept of how to achieve this effect step by step:
There are three shapes we need to draw - Outline Rounded Stroke + Orange Progress Bar + the text itself
We draw the stroke as it is
But for the Progress bar, we need to remove the text that intersects with it and basically make the text intersection transparent. (DIFFERENCE)
Also for the Progress Bar, we have to show only the part of the rectangle that intersects with the outer rounded stroke path. (INTERSECTION)
And similarly, for the text, on the left side we basically chop off the parts that intersects with the progress bar. And we only show the right side of the text that is orange in color. (DIFFERENCE again)
If you are using API 19+, this is how the critical code snippet looks like:
croppedProgressPath.op(progressPath, textPath, Path.Op.DIFFERENCE);
croppedProgressPath.op(progressStrokePath, Path.Op.INTERSECT);
————————————
croppedTextPath.op(textPath, progressPath, Path.Op.DIFFERENCE);
Lines here and here.
I’ve written a Proof of Concept for this project called Diffre on Github. If you wanna test it out first, all the code is in this repo.

Android using setNumStars to change stars during execution make the ratings act strange

I'm using rb.setNumStars(int) to change the stars form a given default value (say 5) to a new one with app preferences (say 4). The code performs Ok and after refresh the fragment, I can see the change in the stars number to any integer I set (the bar has a StepSize of 1).
The problem is that when I try to set the rating on that bar, the filled stars does not coincide with the rating value, and I have to touch in strange places to get come values, i.e. if I touch the fist star, I get a rating = 1, If I touch the second, I still have a rating = 1 and the filled stars are one and a fragment of the second. If I touch between the second and the third star, I get rating = 2 and I get two and a fragment filled stars.
Imagine this: if F is a full star, P is a partial (but not as in a half star) and E is an empty star, if I touch the second star, and between the 2nd and the 3rd I get:
F P E E Rating = 1 F F P E rating = 2
Edit: The images can be found here: http://1drv.ms/1pyq3gS
If I return the value to 5, the bar behaves as expected, with the filled stars coinciding with the rating.
I can not insert images, to explain this behavior, but I hope it's clear enough.
Does anybody knows why is this happening and how to correct it?
It seems that I was able to answer my own question.
As this is an extension of the progress bar, I´m guessing that when I change the number of stars, a progress bar is stretching to the new width, but keeping it's original values, not reflecting the portion that must fill. By using setMax for the Rating Bar, I think I´m setting the new limits for this bar, so, I changed the number of stars and set the max value to that number, like this:
RatingBar rb = (RatingBar) view.findViewById(rbars[r]);
rb.setNumStars(Integer.valueOf(SP.getString(rchars[r], "3")));
rb.setMax(Integer.valueOf(SP.getString(rchars[r],"3")));
rb.setRating(2);
In this way the rating coincide with the filled stars.

Dynamically changing the border of View

I am just planning to implement a view whose border color keeps on changing dynamically at run time based on a timer. For example initially the view's border will be in green color(timer=20sec) and every sec the green color disappears and once it goes of more than half(timer=10sec) of the view... the border color should change to orange and once it reaches the end(timer=5sec) of timer it should be in red color and phone should vibrate (easy can be done).... If somebody is familiar with zynga poker its the same that i want to implement.
Now one way of implementing it could be have a backend timer and based on that have "n" number of drawables and keep on changing the background of the view every sec. But this requires many images and i dont think this is the optimal way of implementing it.
just wondering if i can write a custom view and implement the surface view and do something around it so that this can be done. Anybody has any idea on how to achieve this? can this be done using any animations around customviews? Any ideas around this are greatly appreciated.
Thanks in advance
Run a timertask, and change the border of the view by setting the background value of the view to a style.
Like,
view.setBackground(R.drawable.border_style_green);
So in the timer task, keep checking the time, and change the border.
Note - border_style_green is a XML file which has the style where you can set the border, the rounded corner to a view, etc.
My suggestion is to make use of the animation framework from android. If your app targets versions below honeycomb use NineOldAndroids.
As already suggested set the border by assigning shapeDrawable to your view
view.setBackground(R.drawable.border_style_green);
you start the animator like this. (this code will animate from currentColor to red in 1000ms)
ObjectAnimator animator = ObjectAnimator.ofFloat(this, "color", currentColor,Color.RED);
animator.setEvaluator(new ArgbEvaluator());
animator.setDuration(1000);
animator.start();
Then in your activity implement:
public void setColor(int color){
currentColor = color;
view.getBackground().setColorFilter(color, PorterDuff.Mode.MULTIPLY);
}
if view is html page : Use Jquery for this implementation. by ajax you can call backend as well. Jquery delay function

Categories

Resources