Programmatically show CrossHair in Shinobi Charts for Android (Xamarin) - android

I'm trying to display the crosshairs on a Shinobi Chart programmatically (via a separate button) on Android and can't figure a way to. I've seen the iOS way which basically involves calling moveToFloatingPosition on the chart.Crosshair.
The closest I've come is calling Focus on Chart.Crosshair, but IsActive and IsShown are false until I long-press on the chart. I'm assuming this is because TrackedSeries is null, so maybe there's a way to set the TrackedSeries programmatically?
shinobiChart.Crosshair.Style.LineColor = Color.Fuchsia.ToAndroid();
shinobiChart.Crosshair.CrosshairMode = Crosshair.Mode.SingleSeries;
lineSeries.CrosshairEnabled = true;
shinobiChart.Crosshair.Focus = lineSeries.DataAdapter.Get(500); // arbitrary DataPoint - it's in the middle of the chart
shinobiChart.RedrawChart();

In the Android version of shinobicharts the API doesn't allow for programmatically displaying the Crosshair - this has to be done via a user gesture (specifically a long press).
What you can do is take advantage of the MotionEvent API in the Android SDK. This allows you to programmatically create user gestures and so you can "perform" a long press on the chart in order to display the Crosshair.
You use the obtain() method to create the MotionEvents - there are a number of overloads of this method so take a look at the docs to see which is the most appropriate to your needs, but the one linked above is the simplest.
Additionally, you can use the conversion methods on the Axis class to go from data values to pixel values, which might help in making sure your MotionEvent is performed directly on the plot area. See Axis.getPixelValueForUserValue(). Note, this method will only return a valid result after the chart has been laid out (but as you're doing this from a button press that shouldn't be a problem).
I appreciate this is a bit fiddly; you'll have to manage the "touch gestures" and make sure you're not permanently "pressing down" on the screen but on the whole it's pretty straight forward. Programmatic control of the Crosshair is definitely something that has been requested before and as such is on our product roadmap though at this stage I'm not able to say when this feature will be available.
Full disclosure - I work for shinobicontrols

Related

Android - How to get raw touch screen data?

How to get an array/bitmap data from android touch screen?
(the shape and area of the touch).
Same question as this one Android: get raw bitmap data from touch events, but this is very old.
The data is processed in the kernel, is there any way I can get it?
It's not possible since your touchscreen only recognizes a few points. For example, try using any kind of a Paint app. You will see that your whole finger won't get noticed if you put it on the screen. Only a few dots will be painted.
Also notice that some phones don't support multi touches. I would recommend you to rethink about your app design. Maybe you could try let the user draw something to achieve a result you want.
Yes that's what I ment. Check cursor location.

How to implement multiple highlight line sliders in line chart

I want to implement single and multiple highlight line sliders in line chart. I am able to get only single highlight line slider with MPAndroidChart (https://github.com/PhilJay/MPAndroidChart) library. But I also need two highlight line sliders to allow the user to select range of values(min and max values) on the chart. Please refer the below image for more information:
Can we achieve the above requirement with any library or we need to draw a custom view?
Any help or guidance will be well appreciated.
In terms of shinobicharts, while the Crosshair could be easily customised to act like one of sliders, in order to have the two sliders you'd probably want to make use of the Annotations feature.
You can create Annotations with custom Views and add them at any X, Y point (in data terms). You can also convert between data values and pixel values via the Axes. It is therefore possible to make the Annotation follow the user's finger as they drag across the screen.
The trickiest part would be placing the circle on the LineSeries at the right Y-value. As I mentioned above you can convert pixel values (e.g. from a user gesture) to data values so you could easily get the X value but the API would leave quite a bit of work up to you in order to get the correct Y value.
This kind of feature is something that is requested quite often and is certainly something we are looking at providing in the future but for now, while possible, it isn't available out-of-the-box.
Disclaimer: I work for shinobicontrols

How do i create a custom clickable graphic for my android app?

I want to create an interactive graphic for my app. It will essentially be a simple picture of a bus line where users can select 2 stops at a time (one for departure times and another for arrivals) I'm not sure how to create this image though, and have it have 20 or so different clickable points. Is there a framework I could use for this? Or is there a way to do this in pure android?
Thanks for the help.
I would suggest writing an onClick listener and using a collection of Rect instances to manage the collision/position of the 'click'. Check out the on click page and the rect page.
One thing to keep in mind are the origin point of your clicks, I'd assume you'll want to use one corner of your image as the point (0,0) and reference everything (clicks and rects) from there.
I would say try to create an ImageView to load your image and set a touch event listener or a click listener to that view. Hard code all places that you want your image to react upon a click.
Check click using an event listener would require you to handle both ACTION_DOWN and ACTION_UP in the MotionEvent object passed in. But it's easier to grab the coordinate of where the user clicks on the page, so you only need one listener but needs to put more work on handling the conversion from the coordinate passed in by MotionEvent to the coordinate on image. This is particular a major issue when your image can be sized larger than the screen size.
Using a click listener would save you from this trouble. As #smitec said, you need to overlay rectangles on your image as "buttons", so you can react to user input based on which buttons they pressed. This way you need to bind listeners to all of them (I suppose) and hard code their positions on your image. But, as mentioned earlier, it saves you from dealing with coordinates later on.

How to produce these views? How Android screens go beyond the simple controls that have Android?

How Android screens go beyond the simple controls that have Android, look at this for example.
How come so that each key responds independently? Is it a single image, several or a drawing?
How to put each circle in the specific country? What if I want a country to be selected?
You can make your own controls by subclassing a view and overriding it's methods. The onDraw method gives you a canvas where you can place just about anything. Check the official android API or this post to get your started.
For the first image, my guess is that it is one image and the position of each click is translated to the corresponding key on the piano. The second image might also be a single image with separate overlays for each country and circle to set the desired color and place the numbers (that's what I would probably do, but it can be done differently).
If you require more flexibility than fixed images, take a look at creating 2D graphics.

Android - Detect Path of Complex Drag

I am recently getting into Android programming and want to make a simple game using 2D canvas drawing. I have checked out the Lunar Lander example and read up on some gestures, but it looks like I can only detect if a gesture occurred. I am looking to do a little more complicated detection on a swipe:
I want to make a simple game where a user can drag their finger through one or more objects on the screen and I want to be able to detect the objects that they went over in their path. They may start going vertically, then horizontally, then vertically again, such that at the end of a contiguous swipe they have selected 4 elements.
1) Are there APIs that expose the functionality of getting the full path of a swipe like this?
2) Since I am drawing on a Canvas, I don't think I will be able to access things like "onMouseOver" for the items in my game. I will have to instead detect if the swipe was within the bounding box of my sprites. Am I thinking about this correctly?
If I have overlooked an obvious post, I apologize. Thank you in advance!
I decided to implement the
public boolean onTouchEvent(MotionEvent event)
handler in my code for my game. Instead of getting the full path, I do a check to see which tile the user is over each time the onTouchEvent fires. I previously thought this event fired only once on the first touch, but it fires as long as you are moving along the surface of the screen, even if you haven't retouched.

Categories

Resources