Smooth update only part of number in textview - android

Do anyone have some idea about next problem:
In my app, I have textview with double value like 12242,25
I am updating that value every 100ms with step like 0,6
Currently I'm just changing the whole text with new value, but then I get that blinking because of changing all of numbers.
I would like to update only those decimals that are for real changing.
So on previous example, 12242, would stay (no text update), and i would update only last 2 decimals, from ,25 to ,85...and so on
Do anyone have some idea how to solve this?

If you mean everything keeps moving around, using a monospace font will keep your digits in the same place, so long as you format the string so the decimal point has a consistent number of digits before or after it (depending on whether the text is aligned with the left or right or it's centred)
If you mean it's actually blinking on and off, that shouldn't happen - it should just draw the current text, and the next frame after the text is changed it should just draw the new text. If that is a thing that's happening though, you might want to look into separate text views, one for each digit like a digital display. That way you're only changing the views for specific digits, but you'll need extra logic to work out which ones you're changing!

Related

How to ensure space between labels MPAndroidChart

I am creating a line chart using MPAndroidChart, all is working great, but I've noticed that at the labels often become bunched up. I know there is a way to prevent this (I've seen other apps that don't have this issue,) but I don't know what setting to enable.
There are a couple of ways you could make the labels fit better.
Decrease the text size of the X axis labels with mChart.getXAxis().setTextSize(float)
Set a label count limit for the X axis using mChart.getXAxis().setLabelCount(int). This should work fine, as you are already not showing one label per data point.
Change the date format of your label.
Some, all or none of these might help you, depending on your requirements. Good luck!

App Inventor Slider : Setting it for whole values?

How do I set the slider to increment by a whole number, not by a decimal value of .N? I can get the value to translate to a label, but I don't want it in decimal value.
This was my original reference: https://www.youtube.com/watch?v=P80FkfGvHWw
Edit:
My value needs to be at 5 maximum... but I do not want to receive the decimal values at all. I eliminated most of the possible fractional values, but there are still some options.
Between 1-5, is there a mathematical way that can automatically round fractions to a whole number?
Thank you! (Please ignore the comment, that was for something else)
see the documentation
round
Returns the given number rounded to the closest integer. If the
fractional part is < .5 it will be rounded down. It it is > .5 it will
be rounded up. If it is exactly equal to .5, numbers with an even
whole part will be rounded down, and numbers with an odd whole part
will be rounded up. (This method is called round to even.)
Probably also a good idea is to use Do it, see also the Top 5 Tips how to learn App Inventor. You also can simplify your blocks a bit instead of using 3 times set global wholeInt ...

Pou connect game algorithm

Recently I played a simple game on android called Pou, and one of it's inside games was a connect the dots on the field game. Here is a screenshot to better explain the situation.
At the beginning of the game you are given n-pairs of dots and you have to connect the same colored ones. While doing this you need to fill the matrix field.
Generating such a field is not a problem, but how can I be sure that it is solvable?
My question would be how can I generate a field that has a solution?
Is this a graph problem? Or some kind of a connectivity problem?
Of course I can always produce a brute force solution, but I am looking for something better
Actually you can generate the matrix in such a way that you can be sure it is solvable.
The main idea is as follow. Let say that you need i pairs of dots and the matrix is n by n
Set i randomly chosen cells (start points) as heads and to each assign a different color.
At each iteration for each color move its head randomly (left, right, up, down) into an uncolored cell and color it with i-th color. (if there is no legal such moves do not consider this color any more -- that will be the end point)
When you are finished and there is no uncolored cells you created a legal coloring of the board.
If there are some uncolored cells -- it may be quite challenging but for sure doable to modify / extend the coloring you obtained to fill those regions with some color -- the easiest way would be to exclude those regions from the matrix altogether :-)
Some other very loose thoughts:
each region that consists of more than 2 uncolored cells can be made legal (or at least some part of it) by assigning two additional dots to it;
you can split your initial n by n matrix into smaller rectangular parts and assign to each part some number of dots (proportional to the area) and use the above method -- for sure there will be less uncolored cells when you merge those parts back (on the other hand the puzzle will be bit easier).
UPDATE
once still in phase of coloring, if the next move produces a single, isolated cell: chose a different move and if no such move exists stop the coloring process for this color.
if you want to have a predefined number of dots (or the number close to it), check not only for single isolated cell, but for whole isolated regions. [btw. mind the possibility of coloring a candidate for isolation region by extending its start point]
for relative small n you can try using above method(s) until you hit full-coloring (so generate, check if legal, if not: generate again)
UPDATE II
If you have time you can try generating colors once at a time, with some probability of stopping, that depends on the length / area of the coloring. So basically just choose a random uncolored position and execute the above method. It should be easier to implement.

Android - need a number flip animation

I'm developing an Android application to read "electric meters". The user enters the counter - the application calculates the consumption and sends it to a server.
The representation of the counter should look like a old electricity meters
old electricity meter
I've already integrated the counter-numbers as images. I will have an animation that if the user enters a number (keyboard) then the relevant section begins to rotate to the correct number position.
For example: The user enters the number 5 for the first digit, then rotate the digit from 0-5. The animated numbers flip to the correct position. How can I do this? Any idea?
thank u!!!
There is a custom view which I've created for a custom application. Initially, i also tried searching for this type of view but couldn't found any. So created one of my own.
You can see the code here: https://github.com/Vinayrraj/Android-FlipDigitView
Also this video might help you: http://youtu.be/d6-M2nN2Gzg
You can take a look to Ticker, an Android text view with scrolling text change animation:
Ticker is a simple Android UI component for displaying scrolling text.
Think about how an odometer scrolls when going from one number to the
next, that is similar to what Ticker does. The Ticker handles smooth
animations between strings and also string resizing (e.g. animate from
"9999" to "10000").
I'd have one spinning animation - but make it fast and blurred so you can't see what number it's on - play that for 1 second, then replace with the correct position - it's a trick, but will save you doing lots of different animations.
If I got your need, I would use two different approach:
1) one big animation with numbers from 0 to 9; when you have an inoput number, you should launch the animation and stop at the right frame (just a math calculation matter);
2) one animation for each number; you could think about a number flipping as if its rotating on itself vertically; then, when the user put his number X, you have to flip between X different animations until the good one and stop.

Horizontal scroll problem

I am relatively new to Android. I am working on an application wherein
i want to display digital signals. But the problem is once I occupy
the available screen width how to i add a scrolling feature to
continue viewing the signal. Also i am drawing the signal using using
drawLine(), so what co-ordinates should i set for drawing the lines
when scrolling is enabled? Can somebody please give a simple example
where a line extends more than the available screen width and you can
scroll through to see the remaining line.
Thanx in advance.
I've written a few of these before in other languages, so I can ive you the principles, rather than an example. I'm assuming you have some sort of buttons to the left and right that allows the user to scroll through the data, and that your signal data is stored in an array. You will be able to determine how much data you can fit into one screen width based on whatever scaling factor you are using. Say your screen can display ten values at a time, then you simple store the starting point in your signal array and use that as the left most point to display on your screen. Then all you have to do is show the next ten values in your array. When the user selects the button to move left or right through the data simply increment or decrement the starting point. If you are streaming in your signal, then the stream can increment the starting point whenever you receive a new piece of data. A redraw after each start value change will give the impression of scrolling. Watch out for start and end conditions (i.e. you don't want to scroll until you have at least a full screen of data). All you are doing is creating a window onto the data you have.
Hope this helps.

Categories

Resources