Giter VIP home page Giter VIP logo

circularseekbar's Introduction

CircularSeekBar

Android CircularSeekBar Custom View/Widget

This is a custom circular SeekBar. It can be used to create SeekBars that are:

-Full Circles

-Semi-Circles

-Ellipses

-Semi-Ellipses

In addition, it is fully customizable via XML attributes, far beyond the default values.

Support and Testing

Tested and working on Android 2.3+.

Tested on the following devices:

-HTC One Google Edition (Android 4.3)

-HTC One X (AT&T, Android 4.1)

-Galaxy Nexus (Android 4.3)

-Emulator with Android versions 2.3-4.2.

CircularSeekBar has also been tested with normal scrolling. It was also been tested successfully with Fragments, as well as scrolling tabs + Fragments.

Known Issues: -The glow effect around the progress part of the circle will not show up on Android 4.0+. This is due to the BlurMaskFilter not working when hardware acceleration is on. Android OS issue.

Screenshot 1

Documentation

In order to use the CircularSeekBar, you need to do three things.

1) Add Source Files to Project

There are two files you need to include: -CircularSeekBar.java -attrs.xml

Place the attrs.xml file inside of your res/values directory.

../yourprojectdir/res/values/attrs.xml

Place CircularSeekBar.java inside of the src folder with the entire directory structure included:

../yourprojectdir/src/com/devadvance/circularseekbar/CircularSeekBar.java

2) Customize Source Files

To use any methods inside if your classes, you must import the correct file. Add this to any classes you want to programmatically use the CircularSeekBar in:

import com.devadvance.circularseekbar.CircularSeekBar;

You also need to add the import for the generated R class to the CircularSeekBar class. You need to change the top of the CircularSeekBar.java file to look like this:

package com.devadvance.circularseekbar;

import com.example.yourappname.R;

where "com.example.yourappname" depends on your project/app. Eclipse may offer to add this import for you.

3) Add CircularSeekBar to Your Layout

Start by adding this to the root of your layout xml file(s):

xmlns:app="http://schemas.android.com/apk/res/com.devadvance.circulartest"

After you add it, the root of your layout xml file(s) should look SIMILAR to this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
	xmlns:tools="http://schemas.android.com/tools"
	xmlns:app="http://schemas.android.com/apk/res/com.devadvance.circulartest"
	android:layout_width="match_parent"
	android:layout_height="match_parent" >

To add the basic CircularSeekBar to your layout, add this to your layout xml file(s) where desired:

<com.devadvance.circularseekbar.CircularSeekBar
android:id="@+id/circularSeekBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

For further configuration, such as color, sizes, and angle, you can specify many attributes associated with the CircularSeekBar, such as:

app:start_angle="270"
app:end_angle="270"
app:circle_x_radius="100"
app:circle_y_radius="100"
app:use_custom_radii="true"
app:progress="25"
app:max="100"
app:pointer_alpha_ontouch="100"
app:pointer_color="#0174DF"
app:pointer_halo_color="#880174DF"

Note: all sizes are measured in DEGREES or DP. No pixels are used.

You can also change the standard Android view attributes, such as:

android:layout_width="300dp"
android:layout_height="300dp"
android:layout_marginTop="100dp"
android:padding="0dp"

To use the CircularSeekBar programmatically, you can treat it like a normal SeekBar inside of your code:

CircularSeekBar seekbar = (CircularSeekBar) findViewById(R.id.circularSeekBar1);
seekbar.getProgress();
seekbar.setProgress(50);

To use the listener to detect progress changes, first add the import for the class at the top of your file:

import com.devadvance.circularseekbar.CircularSeekBar.OnCircularSeekBarChangeListener;

Next, create a listener that implements the OnCircularSeekBarChangeListener:

public class CircleSeekBarListener implements OnCircularSeekBarChangeListener {
	@Override
	public void onProgressChanged(CircularSeekBar circularSeekBar, int progress, boolean fromUser) {
		// TODO Insert your code here
		
	}
}

Then create a new instance of it and set it for your seekbar:

seekbar.setOnSeekBarChangeListener(new CircleSeekBarListener());

All Available Attributes

Available Attributes:

progress - Integer Value.

max - Integer Value.

move_outside_circle - True/False. Default is false. In the case that the user has already touched down on the CircularSeekBar and is adjusting the progress, this determines whether or not movement outside the circle is accepted and adjusted the progress.

start_angle - Decimal Value. Start angle of the circle. Angles are relative to 3 o'clock (positive X axis).

end_angle - Decimal Value. End angle of the circle. Angles are relative to 3 o'clock (positive X axis).

maintain_equal_circle - True/False. Default is true. This controls whether or not an ellipse shape is available. Ellipses are not accurate in terms of representing progress, so be aware of that when you set this to false. Default value is true.

use_custom_radii - True/False. Default is false. If true, then you can specify radii using attributes. No matter what is specified, they will not exceed the bounds of the View itself. If false, then the View size (android:layout_width and android:layout_height) is used.

lock_enabled - True/False. Default is true. If true, then the progress will "stick" to the start/end point. If false, it'll just pass through.

circle_x_radius - Decimal Value. Custom X radius in DP.. Requires use_custom_radii to be true.

circle_y_radius - Decimal Value. Custom Y radius in DP. Requires use_custom_radii to be true.

circle_stroke_width - Decimal Value. Defines the width of the circle ring in DP.

pointer_radius - Decimal Value. Defines the radius of the pointer in DP.

pointer_halo_width - Decimal Value. Defines the width of the pointer halo in DP. Note: This is NOT a radius; it is in addition to the pointer radius.

pointer_halo_border_width - Decimal Value. Defines the width of the pointer halo border in DP. Note: This is NOT a radius; it is in addition to the pointer radius. The border shows up when the user is touching the CircularSeekBar.

circle_color - String value. Hex color value, can be #RRGGBB or #AARRGGBB (where AA is the alpha value).

circle_progress_color - String value. Hex color value, can be #RRGGBB or #AARRGGBB (where AA is the alpha value).

pointer_color - String value. Hex color value, can be #RRGGBB or #AARRGGBB (where AA is the alpha value).

pointer_halo_color - String value. Hex color value, can be #RRGGBB or #AARRGGBB (where AA is the alpha value). If no alpha is included, it defaults to 200 (out of 255).

pointer_alpha_ontouch - Integer value. When the user touches the CircularSeekBar, the opacity/alpha of the pointer halo changes to this value. Defaults to 100 (out of 255).

All Available Methods

The methods available to View are all present, as well as some custom methods that allow customization programmatically:

setProgress and getProgress

setMax and getMax

setCircleColor and getCircleColor

setCircleProgressColor and getCircleProgressColor

setPointerColor and getPointerColor

setPointerHaloColor and getPointerHaloColor

setPointerAlpha and getPointerAlpha

setPointerAlphaOnTouch and getPointerAlphaOnTouch

setLockEnabled and isLockEnabled

Note: Changes made with these methods are persisted by saving state.

License

 Copyright 2013 Matt Joseph

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in 	writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 	either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.

Inspired and Guided By

HoloCircleSeekBar - Copyright 2012 Jesús Manzano

HoloColorPicker - Copyright 2012 Lars Werkman (Designed by Marie Schweiz)

Although I did not used the code from either project directly, they were both used as reference material, and as a result, were extremely helpful.

Other Screenshots

circularseekbar's People

Contributors

beloso avatar berco avatar devadvance avatar heinrichreimer avatar invalidport avatar kubukoz avatar madcoda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

circularseekbar's Issues

elliptic arc but component canvas is square

Hi,

Thanks for the great component. I have a small problem and mayby i dont understand something.

I would like to put two elliptic arc seekBar one below another. Problem is that the component canvas is always square (even if seekbar is not a perfect circle) so there is a big margin between these two component. Is there a way to deal with that?

Animation

How Can I animate the progress programmatically

Sometimes progress value is jumped from 0 to 100.

The current thumb is at value of 0. When changing the seek bar speedy, the value jumps to 100. I suspect the following code block.

else if (lockAtEnd && lockEnabled) {
mProgress = mMax; // Suspected here.
recalculateAll();
invalidate();
if (mOnCircularSeekBarChangeListener != null) {
mOnCircularSeekBarChangeListener.onProgressChanged(this, mProgress, true);
}
}

Guide me with the implementation of any of the methods.

I tried this:

@OverRide
public void onProgressChanged(CircularSeekBar circularSeekBar,
int progress, boolean fromUser) {
Log.v("test", "yup");
Toast.makeText(getApplication(), "ended at", Toast.LENGTH_SHORT).show();
}

@Override
public void onStartTrackingTouch(CircularSeekBar circularSeekBar) {
    // TODO Auto-generated method stub
    Log.v("test", "start");
}

@Override
public void onStopTrackingTouch(CircularSeekBar circularSeekBar) {
    // TODO Auto-generated method stub
    Log.v("test", "stop");
}

LogCat shows the texts successfully in all the three methods. But if any Task is given, to show a Toast or to change a string in TextView...for example here a Toast, it says:

"02-07 06:30:30.272: E/AndroidRuntime(5866): FATAL EXCEPTION: main
02-07 06:30:30.272: E/AndroidRuntime(5866): Process: com.ui.yogeshblogspot, PID: 5866
02-07 06:30:30.272: E/AndroidRuntime(5866): java.lang.NullPointerException
02-07 06:30:30.272: E/AndroidRuntime(5866): at android.widget.Toast.(Toast.java:93)
02-07 06:30:30.272: E/AndroidRuntime(5866): at android.widget.Toast.makeText(Toast.java:241)
02-07 06:30:30.272: E/AndroidRuntime(5866): at com.ui.yogeshblogspot.CustomSeekBarExActivity.onProgressChanged(CustomSeekBarExActivity.java:76)
02-07 06:30:30.272: E/AndroidRuntime(5866): at com.devadvance.circularseekbar.CircularSeekBar.onTouchEvent(CircularSeekBar.java:699)
02-07 06:30:30.272: E/AndroidRuntime(5866): at android.view.View.dispatchTouchEvent(View.java:7690)
02-07 06:30:30.272: E/AndroidRuntime(5866): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
"

Shows a problem here in 'circularseekbar.java' on 'LINE 683'

if (mOnCircularSeekBarChangeListener != null) {
here>>>> mOnCircularSeekBarChangeListener.onProgressChanged(this, mProgress, true);
}

not letting me do anything on events. Please let me know
Thanks.

How to implement??

The instructions you put in the readme aren't working for me.

Specifically, in the CircularSeekBar.java, the line, "package com.devadvance.circularseekbar;" gives me the error "package does not correspond to the file path (my project path)..."

and this " xmlns:app="http://schemas.android.com/apk/res/com.devadvance.circulartest"" in the xml isn't working either.

What am I doing wrong?

Also in CircularSeekBar.java, the word "boolean" is red, says "cannot resolve value"
/**
* Set whether the pointer locks at zero and max or not.
* @param boolean value. True if the pointer should lock at zero and max, false if it should not.
*/

Programmatically setting attributes instead of XML values?

I have 2 circles in the same fragment that need different properties, such as start/end angles, radii, lock, etc, and also need to be dynamically configured at runtime. Is there a way to set the attributes of the circle programmatically instead of in the XML?

ArcSeekBar

How To create arcseekbar with this view? Anyone know .. pls help me.

Disable user to make changes

Is it possible to disable user to make some changes? For example, after user reach certain level I would like to remove option to make other changes. I tried to set clickable to false, but that did not changed nothing. Also I tried using method setEnabled(false), but without success.

Specifying attributes shows XML Parsing Error

I am able to use the Circular Seek Bar (Thanks!) and able to get progress. I am just getting errors in the XML when I add the additional styling information.

For the "circularSeekBar1" - the error is as follows: "error: Error parsing XML: unbound prefix"
Screenshot of error: http://postimg.org/image/cbge0oh4d/

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:orientation="vertical" >


<com.neil.mytestbed.ui.CircularSeekBar
    android:id="@+id/circularSeekBar1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    app:circle_x_radius="100"

    />

<TextView
    android:id="@+id/tv_circularSeekBarProgress"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/circularSeekBar1"
    android:layout_alignParentRight="true"
    android:layout_marginBottom="150dp"
    android:layout_marginRight="34dp"
    android:ems="10"
    android:inputType="textPostalAddress"
    android:text="asdasd" />            
</RelativeLayout>

restrict user to move pointer

@devadvance
Hi,
I want to restrict user to touch or move pointer at specific progress.
For ex,if i reach 15 of progress then user will not move to the pointer in after 15.it will be move before 15.
is it possible?i have tried so much but can't getting output as i expected.
If any solution then please send me on my id [email protected]

Smoothing the Progress update Animation

is there any way by which i could smooth the progress change ?

The scenario i'm trying to implement is that i want to update the progress for 15 seconds while keeping the Maximum value of Progress bar to 100..

Can you please help me in this Regards?

Can we make circular_x_radius to occupy the mobile/tablet width

Hi , I am trying to make this circularseekbar to occupy the entire screen width of a mobile/tablet. Is there any method or way to do achieve this. I am only unable to set app:circle_x_radius="100" which is a numerical value. is there anyway to set app:circle_x_radius="wrap_content"

setProgress() doesn't work

When set progress dynamically in Java Class ,its doesn't change progress and progress color as well.
we need to set grammatically but in Xml its working good...

Error infalting class

Am using android studio
and i have added the auto-res namespace
but i get the error inflating class in the binary xml

solution

Progress step(increment) value

Hello,

Is there any way to set the step value ? I mean if I have values from 0-200 and the step of 25, on stop trackingtouch to get only values multiple of 25 (0, 25, 50, 75...). This is how I temporally implemented on my app :

`circularSeekBar.setOnSeekBarChangeListener(new CircularSeekBar.OnCircularSeekBarChangeListener() {
@OverRide
public void onProgressChanged(CircularSeekBar circularSeekBar, int progress, boolean fromUser) {
selectedAmount = (progress / 25) * 25;
amount.setText(String.valueOf(selectedAmount));
}

        @Override
        public void onStopTrackingTouch(CircularSeekBar seekBar) {
            seekBar.setProgress(selectedAmount);
        }

        @Override
        public void onStartTrackingTouch(CircularSeekBar seekBar) {

        }
    });

`

Selected amount is an int where I keep the current progress of the seekbar and amount is a textview where I show it. With this implementation I get the values smaller or equal ... so if it's a value inside 25-49 I return 25. It's not the best solution, but it works...

Thanks !

How to get the secondary progress?

Hi , your class is of great use and it has helped me to create nicer looking music player. I am only stuck at getting the secondary progress on the seekbar. Also , how can I make it go anti - clockwise.

Trying to achieve SemiCircular progressBar

Hi, am trying to achieve semi/half circular progressbar using circularseekbar, as it is mentioned i changed start_angle to 0 and end_angle to 180. when i build, it shows error saying "No resource identifier found for attribute start_angle and end_angle". I have included my resource package inside circularseekbar class file. what did i miss? please help.

Align to top instead of centering

Is there the option to align the CircularSeekBar to top instead of centering in available space?
In my case I need a SeekBar formed like an arc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.