Creating own "SeekBar" - java

I want to create my own kind of a SeekBar which means I want to have for example two horizontal-sliders on a plot.
How can I do this? I just managed to bind a class to my view which draws a plot, but how can I put two sliders on it? I was thinking about putting a new layer on the plot and set a move-listener to it but have no idea how to do this. Or should I redraw the slider each time the user moves it?
The SeekBar is just for testing purpose. What I want is a slider on the plot:

Please check this question: Android Seekbar with two thumbs. Android doesn't have a standard UI control but you should be able to find third-party source code.

Related

How to apply the one ripple drawable for multiple buttons dynamically in Java?

I want to apply the same ripple drawable properly on multiple buttons. But it's not happening because, the ripple effect is only getting applied on the last button. I have also used gradient drawable inside the ripple drawable. That works fine on every button. It just the ripple effect is not getting applied on any button except the last button. It is also not working on api level 8. I know that this method doesn't work on apis before api level 21. But I haven't found any tutorial on dynamic button design.
I'm doing everything inside the on-create event. I can't write the codes outside of the on-create event and also can't use any XML for this particular situation I'm in.
Here's the output:
Here's the code:
android.graphics.drawable.GradientDrawable gd_btone = new android.graphics.drawable.GradientDrawable();
gd_btone.setCornerRadius(4);
gd_btone.setStroke(2, Color.parseColor("#ffffff"));
gd_btone.setColor(Color.parseColor("#232323"));
android.graphics.drawable.RippleDrawable ripdr = new android.graphics.drawable.RippleDrawable(new android.content.res.ColorStateList(new int[][]{new int[]{}}, new int[]{ Color.parseColor("#888888")}), gd_btone, null);
button1.setBackground(ripdr);
button2.setBackground(ripdr);
button3.setBackground(ripdr);
button4.setBackground(ripdr);
Also, can anyone help me to make this piece of code back-compatible with api level 8 and how to set margin on this drawable?
I'm not a Android developer so I don't know much about it.
What I see is that the dripple effect is applied to the last button, even when the other buttons are clicked. Because of this, I am thinking that the RippleDrawable class does not support the kind of behavior you are looking for; a single instance can only be bound to one button at a time.
I would suggest simply creating four separate RippleDrawable instances.
Disclaimer: I have not worked with RippleDrawables, but this is purely based on the output you've provided and personal experience with Android development.

Create a view class that is a combination of two views Android

In my app, I have a screen that displays some images next to text. These images are downloaded from the internet, so there will be some latency in displaying them. Right now I have an ImageView and a ProgressBar overlaying each other, and toggling the visibilities when the Bitmap becomes available. Is there any way to combine the two into one class that will handle it all in case I want to use this somewhere else?
One way to go about solving the problem is to make your own custom view which extends ProgressBar and draw the image in the ondraw(Canvasn canvas) using a Rect. That way, your image can be embedded in your view and you can always make it reusable by allowing your self to set the image via a setter/resource xml files which specify the attributes that go along with your custom view. Here's a reusable ProgressButton that I wrote that maybe of use to you, it shows how I did something similar to what I described (it's one which I think works well):
PregressButton
Yes there are a number of ways to combine widgets into a single custom class. Have a read of Custom Components. This should help you decide which approach you want to use for your situation.

Possible implementation of game screen concept for an android game

I want to develop an android app, but I'm still not that great at using xml or the eclipse wysiwyg editor to make scalable and robust interfaces!
Below is a quick concept I drew up on word of what my main game screen will consist of:
I'm currently thinking a vertical linear frame first, with a frame that doesn't change for my important stats etc., then a frame in the middle which is switched by the buttons, but I'm stuck on how to implement this.
For the centre button screen, the map screen, I am hoping to add an image of a map which can be moved around, and somehow attach invisible button objects to points in this picture, maybe with an array of squares or something?
I understand this is a pretty open question and might be difficult to answer, but if you think you can help in anyway please do.
Thanks!
There is a log of possibilities, but you can use a LinearLayout with android:orientation="vertical" and include your stats in top. For the changing screens with buttons you can use a FragmentTabHost and create different Fragment for each of your views.
Check this example with a implementation.
Regarding the map, I think the easiest option is to use Google Maps Android API v2. Here is a example to use the maps v2 and a example of how to add markers to the map.

How android detect button positions and call appropriate handler?

I know this may not be an appropriate question, but I want to know how a touch enabled OS like
android detects a button in an app and calls the appropriate handler? When programming an app we just give the alignment information of a particular button. So, how android keeps the mapping between a button and screen position? I think this is kindof dynamic because if you change the screen orientation or use zoom or something like that the button positions are changed dynamically. So, android must look at the touch position and decide whether a button is there or not and call the appropriate handler. How this all things put together?
I appreciate any reply.

Android button latency?

I've been working on a drum machine app, and the latency between the time you press the button and the time the sound plays is unbearable. I have seen some people use multitouch and gridviews, and make several buttons able to be pressed at the same time, but I honestly have no knowledge of those. How could I set up multitouch or gridviews to reduce the latency?
I would guess the multitouchable buttons are a very custom implementation. You won't ever be able to touch two ordinary buttons simultaneosly, since they are made for single touch and are based on focus gain etc.
Here's my idea behind a multitouchable implementation:
You create a very custom view which will draw all buttons you need. This view should override onTouchEvent and react on multitouch. I never tried that, but this is the only option I can think of.

Categories