Skip to content

Hi. Thank you for your button. I added one more. #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
# built application files
Application files
*.apk
*.ap_

# files for the dex VM
# Files for the Dalvik VM
*.dex

# Java class files
*.class

# generated files
# Generated files
bin/
gen/

# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Eclipse project files
.classpath
.project

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Intellij project files
*.iml
*.ipr
*.iws
.idea/
.gradle/

build
.idea/
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
classpath 'com.android.tools.build:gradle:1.2.2'
classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.+'
}
}

ext {
compileSdkVersion = 19
buildToolsVersion = "19.1.0"
compileSdkVersion = 22
buildToolsVersion = "22.0.1"
}

def isReleaseBuild() {
Expand Down
17 changes: 9 additions & 8 deletions example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,37 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
apply plugin: 'android'
apply plugin: 'com.android.application'

repositories {
mavenCentral()
}

android {
compileSdkVersion 19
buildToolsVersion "19.1"
compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig {
minSdkVersion 11
targetSdkVersion 19
targetSdkVersion 22
versionCode 1
versionName "1.0"
}

buildTypes {
release {
runProguard true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
compile 'com.android.support:appcompat-v7:19.1.0'
compile 'com.github.markushi:circlebutton:1.1'
compile 'com.android.support:appcompat-v7:22.0.0'
//compile 'com.github.markushi:circlebutton:1.1'
compile project(':library')
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import android.view.ViewGroup;
import android.widget.Toast;

import at.markushi.ui.CheckableCircleButton;

public class MainActivity extends ActionBarActivity {

@Override
Expand All @@ -20,7 +22,7 @@ protected void onCreate(Bundle savedInstanceState) {
}
}

public static class PlaceholderFragment extends Fragment implements View.OnClickListener {
public static class PlaceholderFragment extends Fragment implements View.OnClickListener, CheckableCircleButton.OnCheckedChangeListener {

public PlaceholderFragment() {
}
Expand All @@ -31,7 +33,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa

rootView.findViewById(R.id.button0).setOnClickListener(this);
rootView.findViewById(R.id.button1).setOnClickListener(this);
rootView.findViewById(R.id.button2).setOnClickListener(this);
CheckableCircleButton ccb = (CheckableCircleButton) rootView.findViewById(R.id.button2);
ccb.setOnCheckedChangeListener(this);

return rootView;
}
Expand All @@ -40,6 +43,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
public void onClick(View view) {
Toast.makeText(getActivity(), "Button clicked", Toast.LENGTH_SHORT).show();
}
}

@Override
public void onCheckedChanged(CheckableCircleButton button, boolean isChecked) {
String state = isChecked ? "checked": "unchecked";
Toast.makeText(getActivity(), "Button in " + state +" state", Toast.LENGTH_SHORT).show();
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 8 additions & 5 deletions example/src/main/res/layout/fragment_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,18 @@
android:src="@drawable/ic_action_tick"
app:cb_color="#FFBB33" />

<at.markushi.ui.CircleButton
<at.markushi.ui.CheckableCircleButton
android:id="@+id/button2"
android:layout_width="64dip"
android:layout_height="64dip"
android:layout_width="96dip"
android:layout_height="96dip"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="8dip"
android:src="@drawable/ic_action_tick"
app:cb_color="#FF4444" />
android:src="@drawable/ic_play_arrow_white_36dp"
app:cb_pressedRingWidth="8dp"
app:cb_checkedSrc="@drawable/ic_pause_white_36dp"
app:cb_color="#B48CF4"
app:cb_checkedColor="#AF5555"/>

</LinearLayout>
</FrameLayout>
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Wed Apr 10 15:27:10 PDT 2013
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
8 changes: 4 additions & 4 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
classpath 'com.android.tools.build:gradle:1.2.2'
}
}

apply plugin: 'android-sdk-manager'
apply plugin: 'android-library'
apply plugin: 'com.android.library'

repositories {
mavenCentral()
}

android {
compileSdkVersion 19
buildToolsVersion "19.1"
compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig {
versionName = VERSION_NAME
Expand Down
170 changes: 170 additions & 0 deletions library/src/main/java/at/markushi/ui/CheckableCircleButton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
package at.markushi.ui;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.widget.Checkable;

import at.markushi.circlebutton.R;

public class CheckableCircleButton extends CircleButton implements Checkable {
private boolean mChecked = false;

private int mDefaultColor = Color.RED;
private int mCheckedColor = Color.BLUE;

private Drawable mDefaultDrawable;
private Drawable mCheckedDrawable;

private OnCheckedChangeListener mListener;
private boolean mBroadcasting;

public CheckableCircleButton(Context context) {
super(context);
}

public CheckableCircleButton(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}

public CheckableCircleButton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context, attrs);
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public CheckableCircleButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs);
}

@Override
public void setPressed(boolean pressed) {
super.setPressed(pressed);
toggle();
}

@Override
public void setChecked(boolean b) {
if (mChecked != b) {
mChecked = b;
setVisualState(mChecked);
// Avoid infinite recursions if setChecked() is called from a listener
if (mBroadcasting) {
return;
}
mBroadcasting = true;
if (mListener != null) {
mListener.onCheckedChanged(this, mChecked);
}
mBroadcasting = false;
}
}

@Override
public boolean isChecked() {
return mChecked;
}

@Override
public void toggle() {
setChecked(!mChecked);
}

private void init(Context context, AttributeSet attrs) {
if (attrs != null) {
final TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.CircleButton);
mDefaultColor = ta.getColor(R.styleable.CircleButton_cb_color, mDefaultColor);
ta.recycle();

final TypedArray ta_ccb = context.obtainStyledAttributes(attrs, R.styleable.CheckableCircleButton);
mCheckedColor = ta_ccb.getColor(R.styleable.CircleButton_cb_color, mCheckedColor);
mCheckedDrawable = ta_ccb.getDrawable(R.styleable.CheckableCircleButton_cb_checkedSrc);
ta_ccb.recycle();
}
mDefaultDrawable = getDrawable();
}

private void setVisualState(boolean isChecked) {
setColor(isChecked ? mCheckedColor: mDefaultColor);
setImageDrawable(isChecked ? mCheckedDrawable: mDefaultDrawable);
}

public void setCheckedState(boolean isChecked) {
if (mChecked != isChecked) {
mChecked = isChecked;
setVisualState(mChecked);
}
}

public void setOnCheckedChangeListener(OnCheckedChangeListener listener) {
mListener = listener;
}

public interface OnCheckedChangeListener {
void onCheckedChanged(CheckableCircleButton button, boolean isChecked);
}


static class SavedState extends BaseSavedState {
boolean checked;

SavedState(Parcelable superState) {
super(superState);
}

private SavedState(Parcel in) {
super(in);
checked = (Boolean)in.readValue(null);
}

@Override
public void writeToParcel(Parcel out, int flags) {
super.writeToParcel(out, flags);
out.writeValue(checked);
}

@Override
public String toString() {
return "CheckableCircleButton.SavedState{"
+ Integer.toHexString(System.identityHashCode(this))
+ " checked=" + checked + "}";
}

public static final Parcelable.Creator<SavedState> CREATOR
= new Parcelable.Creator<SavedState>() {
public SavedState createFromParcel(Parcel in) {
return new SavedState(in);
}

public SavedState[] newArray(int size) {
return new SavedState[size];
}
};
}

@Override
public Parcelable onSaveInstanceState() {
Parcelable superState = super.onSaveInstanceState();
SavedState ss = new SavedState(superState);
ss.checked = mChecked;
return ss;
}

@Override
public void onRestoreInstanceState(Parcelable state) {
SavedState ss = (SavedState) state;

super.onRestoreInstanceState(ss.getSuperState());
mChecked = ss.checked;
setVisualState(ss.checked);
requestLayout();
}
}
Loading