Horizontal scroll problem - android

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.

Related

Saving data even the app is close

hello guys I need your help I need to save progress data in my app . I created an App for letter tracing and I want to save the progress of the which letter is done tracing . like the color of image will be change if the letter is done tracing. or it will have star and when the app is close I want the progress is still there and not to start all over again. please help me guys this the screenshots of my app.
When user swipes the finger on the screen you get (x,y) points of the touch events, so you can save the array of the (x,y) points the moment the user lifts his finger of the screen. As there may be a lot of points to save, you can decrease data by saving every second or third point in the array. Doing so will decrease the data you will work with but it also decrease the precision of the user line.

AChartengine: 1. repaint(), 2. limit data points

1:
I use achartengine to draw a line chart. Since i receive constantly data i want the chart scroll automatically to the right. My Problem is now, that the chart only scrolls when i touch the display of my phone(Android 2.3). Chart is running in extra thread and gets repaint() every ~100 ms.
2: How do i limit the collected data points. Is there an option to save the last 100 points and delete the older values? Currently my app saves all data points and gets slower and slower.
Best regards.
You can dynamically set the visible chart area using: renderer.setXAxisMin() and renderer.setXAxisMax(). Call repaint() after calling these methods.
Using the same APIs as the above you can control which data to be displayed. It's up to you to remove data from the series after that.

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.

Get number of homescreens without calling onoffsetschanged (for wallpaper)?

I'm doing a live wallpaper. However, what is initially shown depends on the number of home screens.
While onOffsetsChanged() allows you to calculate the number of home screens, it gets called only if the user scrolls the homescreen.
So is there a way to get the current xStep and xOffSet without calling onOffSetsChanged()?
Edit: I may not need to know that per se. Here's what I'm doing: I'm basically drawing a portion of the bitmap. The portion shown depends on the current homescreen.
Edit 2: so to explain what I'm trying to do---I'm basically trying to mimick the scrolling wallpaper effect but with a video. The point is that the portion shown depends on the current homescreen. Here's the problem: So the user selects the wallpaper. OnSurfaceCreated() is called, followed by onSurfaceChanged(). However, onOffSetsChanged() is never called until the user tries to scroll the homescreens. That's the problem. You don't know what part of the bitmap/video to display until the user scrolls the screen. (So Josh's suggestion doesn't work. The part of the video that's displayed may be wrong---until the user scrolls the screen and we get the correct onOffSetsChanged() values.)
Your edit doesn't really explain why you need to know how many screens there are. You can draw the center portion of your bitmap initially, then when xOffset changes to something like 0, draw the leftmost portion of your bitmap. What's the issue?

Design decisions / advice for a simple game on Android

I need your advice on the best way to implement a scrollable playing field in a simple game. The field consists of multiple rows, with 9 cells in each row. The rows can be dynamically added and removed during the course of the game. Each cell has a digit in it, and optionally several overlayed images, like selection, selector over, crossed out, etc. (see the pic below). The user should be able to click on individual cells of a row to select/deselect/cross the touched cells. At any point in the game there can be from 0 to 3000 cells (0 to about 333 rows). The field should scroll up and down smoothly.
I was thinking about having a ListView with its each row being a row on the field. That way i could add/remove rows dynamically during the game. However, how exactly should i implement a row: have one bitmap representing a row, and then when the user touches it -- get the coordinates of the touch area, and find out what cell was affected, and then act upon that. Is it possible to get the touch coordinates of a row in ListView? If not, should I place 9 dummy image placeholders in each row, and then act on user touching those? What about performance?
Or should I have one huge bitmap / canvas representing the entire field, place it inside a ScrollView and then calculate all the coordinates and update it as the user interacts with it? Is it going to be faster or slower than the ListView?
Any other solutions?
I prefer it to be a "regular" app type game, not a loop-based game, as I don't think I really need to redraw 30 times a second.
I am pretty new to Android. Thank you for your suggestions.
You can easily make that kind of setup run quickly with a "game loop" / SurfaceView combination. That means no ListView, only custom drawing and event handling. Luckily the event handling isn't that difficult, and you'll win later on because you'll have much greater control over the interface than if you had gone with a bunch of customized views and layouts.
I'd avoid that www.droidnova.com tutorial, it uses HashMaps unnecessarily, which will only cost you in performance.
Here's how I'd go about it:
Create an object to hold your cell data. For this example, I'd use an object with an id (to print), and an x and y for where to draw on the screen.
Decide on a board size which will fit on your screen without scrolling, say 10x10. You'll add the scrolling later.
Create a 2-dimensional array of cell objects with lengths boardSize x boardSize. Fill the objects with id and x and y position on the screen.
In your custom onDraw, iterate through each "row" and "column" of your single array and draw the object at its stored x and y value.
So now you've got a grid of objects displaying on your screen. Now you want to restrict the number of rows currently displayed and add some functionality to change which rows are visible. This is done as follows:
During initialization, set up some global ints as mCurrentRow = 0 and mNumVisibleRows = 3. These define your "view window".
Modify your drawing code to only draw rows starting at mCurrentRow and ending at mCurrentRow + mNumVisibleRows. The result of this should be that you only ever see mNumVisibleRows rows, and which group of rows you see depends on what you set mCurrentRow to.
Add some triangles to the right of your grid drawing and have tap touch events in those areas map to increments/decrements of mCurrentRow. Obviously, you should not allow that value to go outside your row count bounds.
If you want to get classy, draw a line between your triangles for a scroll area, and map touch events there to something like newCurrentRow = (touch.y / canvas.height()) * boardSize; That needs some tweaking, but you get the idea.
This approach has the downside of only showing a full set of rows at a time, so scrolling wouldn't be smooth. However, you have complete control over your canvas and what you draw, so with a little more math you could implement a smooth scrolling mechanism which would offset by a fractional row height in the y-direction instead of whole rows.
I dont know if you can create a game like you described with good performance. I would look into basic tile game programming.
But by avoiding the standard view components are have to write all the logic yourself requires quite some work. Things like handling "click" events on different rows needs to be calculated by the tile position relative to the game camera. So theres alot of new stuff in learning to develop game at a lower level.
You also have to take the rendering of your game into your own hands by developing a game loop that constantly updates and draw's your tiles from a background thread to reflect the scroll / state of your game.
You can get more infomation on the basics of a game loop at:
http://www.rbgrn.net/content/54-getting-started-android-game-development
If you want to learn more you should see the following keynotes from android.
http://developer.android.com/videos/index.html#v=U4Bk5rmIpic
http://developer.android.com/videos/index.html#v=7-62tRHLcHk
Those give you a very good insight in developing games for andriod at a low level where you can fine tune for performance.

Categories

Resources