Android: Trigger redraw after a colour change - android

I am currently working on a Connect four game.
My game works by the user pressing the 'New game' button. This then draws 42 (7*6) green circles to screen. These circles are used to represent holes on the connect four board i.e. green circles currently do not contain a player's token/counter
At this moment in time I am working on adding the tokens/counters. I have got code working (to a certain point) that enables the user to pick a column. Using log.d() It seems that I am successful changing the colour value of the gaps. My problem is that I do not know how to send this changing in colour to the View i.e. so the gap actually changes from green to red (player's token colour).
How can I send a request to the View so the gap is re-drawn?
N.B. Sorry for the lack of code but it is currently messy and not fully working.
The View is controlled by a ConnectFourView.java (View), the game screen is Board.java (Model) and the code that works out which column has been selected Gaps.java (controller)

Just call invalidate() on your view and it will be redrawn

Related

Android: detecting presses inside grid

I am making a game of Gomoku in Android. I have made a grid out with drawLine(): http://i.stack.imgur.com/Mm4HZ.jpg
I am now trying to make the app detect presses within the small squares. I was thinking perhaps I could generate buttons to be in the center of each square. I have the height/width of a single square saved to varibles so getting the center points to each square shoudln't be difficult. However, how should I dynamically generate buttons where each corresponds to a certain [i][j] in a 10 * 10 matrix where the field data is stored?
You can register an onClickEvent with any view in android. What you want is an invisible view the area of the places were you want click events. I suggest using buttons or something visual so that you can see where the areas are, register the click events for each view, then hide the views so that they are invisible.

have textview change style/attribute on touch roll-off

Ok, I simply can't figure this out for the life of me. I created a custom textview and I basically want it to be a button. I have all my code working except that I can't get it to detect when touched, and then the touch event rolls out of its boundary. Say the textview lights up grey when touched, then if the user drags their finger away to the left or right, I want to have the grey disappear and reset to its normal background color.
I realize I can just use the standard android button, but I don't like how it delays on changing color for the touch event. Maybe someone knows where the stock Button.java class code is, for the android API so I can look at that for hints?
I have tried getting the dimensions of the button with an on global listener and then tracking user touch events to be within those dimensions. And the dimensions and touch location are reported correctly and works sometimes, but it simply doesn't work reliably, maybe due to the user moving too quickly, for example. Even if I set the touch boundary a few pixels inside of the actual boundary.

Android real time ECG-type graphs in a PopupWindow

I have looked at some threads concerning real-time line drawing (for items like ECG traces) and all solutions are based upon the idea that the graph is the main activity. What I need is a popup situation where the line graph is drawn only when it is needed.
Can one attach a 'surface' to a PopupWindow? Right now I use an AlertDialog and invalidate() of a Canvas and that stinks as first it is not real time (the entire set of data is drawn then updated so one gets 'flashes' each update) and second the AlertDialog appears impossible to control the size of (same size both orientations) BUT I do see data displayed in the background behind the Dialog box in a scrolled ListView which is the main activity of the application.
I would even be happy if I could get real time drawing in the AlertDialog without this ugly invalidate() though the inability to specify its size is frustrating!

android- can you make an object drawn in a canvas clickable

I know that the canvas in android is a lower level drawing surface but currently Im drawing all my objects inside a canvas and I would like a better way to handle clicks for each object on the canvas. Ive tried matching an x and y through the view their drawn in and that only works some of the time.
Is there anyway to make the individual bitmaps Im drawing im my canvas clickable. The objects in my app are moving dynamically...think of a game object where on screen elements are moving. Ive tried creating a class that extended Button but everything got drawn in the upper right hand corner of the screen so Im not sure if you can have moving objects onscreen that extend button however at least when I clicked the image on top of the stack of ones drawn it gave the expected response. Right now I register onscreen clicks through the view that the canvas is drawn in and through the running loop that makes on screen action take place I have an array of all items and when a click is registered I loop through all the items and those that are onscreen are checked for their coordinates. if I get a match i fire an intent to perform an action.....like I said this is unreliable at best and Im momentarily at a loss on how to restructure everything to get reliable responses.

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