Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/development'
Browse files Browse the repository at this point in the history
# Conflicts:
#	build.gradle
#	counterfab/src/main/java/com/andremion/counterfab/CounterFab.java
#	gradle/wrapper/gradle-wrapper.properties
  • Loading branch information
andremion committed Feb 3, 2019
2 parents cc44c3c + 18822c5 commit 1a8d56e
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 117 deletions.
14 changes: 7 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
}
}
Expand All @@ -22,17 +22,17 @@ allprojects {
}
project.ext {

compileSdkVersion = 27
compileSdkVersion = 28
minSdkVersion = 16
targetSdkVersion = 27
targetSdkVersion = 28

versionCode = 6
versionName = "1.2.0"
versionCode = 7
versionName = "1.2.1"

supportLibraryVersion = '27.1.1'
materialVersion = '1.0.0'

junitVersion = '4.12'
espressoVersion = '2.2.+'
espressoCoreVersion = '3.1.1'

name = 'CounterFab'
description = 'A FloatingActionButton subclass that shows a counter badge on right top corner'
Expand Down
6 changes: 3 additions & 3 deletions counterfab/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
targetSdkVersion project.ext.targetSdkVersion
versionCode project.ext.versionCode
versionName project.ext.versionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
Expand All @@ -21,11 +21,11 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "com.android.support:design:$supportLibraryVersion"
implementation "com.google.android.material:material:$materialVersion"

testImplementation "junit:junit:$junitVersion"

androidTestImplementation "com.android.support.test.espresso:espresso-core:$espressoVersion"
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoCoreVersion"
}

//apply from: 'https://raw.githubusercontent.com/andremion/JCenter/master/deploy.gradle'
122 changes: 33 additions & 89 deletions counterfab/src/main/java/com/andremion/counterfab/CounterFab.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,41 @@
package com.andremion.counterfab;

import android.animation.ObjectAnimator;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.os.Parcel;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.IntRange;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.util.Property;
import android.view.View;
import android.view.animation.Interpolator;
import android.view.animation.OvershootInterpolator;

import static android.support.design.widget.FloatingActionButton.*;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.stateful.ExtendableSavedState;

import androidx.annotation.IntRange;
import androidx.annotation.Nullable;
import androidx.core.view.ViewCompat;

import static com.google.android.material.R.attr;

/**
* A {@link FloatingActionButton} subclass that shows a counter badge on right top corner.
*/
public class CounterFab extends FloatingActionButton {

private static final String STATE_KEY = CounterFab.class.getName() + ".STATE";
private static final String COUNT_STATE = "COUNT";

private final Property<CounterFab, Float> ANIMATION_PROPERTY =
new Property<CounterFab, Float>(Float.class, "animation") {

Expand Down Expand Up @@ -96,18 +99,16 @@ public Float get(CounterFab object) {
private static final int RIGHT_BOTTOM_POSITION = 3;

public CounterFab(Context context) {
this(context, null, 0);
this(context, null);
}

public CounterFab(Context context, AttributeSet attrs) {
this(context, attrs, 0);
this(context, attrs, attr.floatingActionButtonStyle);
}

public CounterFab(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);

setUseCompatPadding(true);

float density = getResources().getDisplayMetrics().density;
mTextSize = TEXT_SIZE_DP * density;
float textPadding = TEXT_PADDING_DP * density;
Expand All @@ -116,7 +117,7 @@ public CounterFab(Context context, @Nullable AttributeSet attrs, int defStyleAtt
mAnimationFactor = 1;

mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mTextPaint.setStyle(Paint.Style.STROKE);
mTextPaint.setStyle(Style.FILL_AND_STROKE);
mTextPaint.setTextSize(mTextSize);
mTextPaint.setTextAlign(Paint.Align.CENTER);
mTextPaint.setTypeface(Typeface.SANS_SERIF);
Expand Down Expand Up @@ -290,87 +291,30 @@ protected void onDraw(Canvas canvas) {
}
}

private static final class SavedState extends View.BaseSavedState {

private int count;

/**
* Constructor called from {@link CounterFab#onSaveInstanceState()}
*/
private SavedState(@Nullable Parcelable superState) {
super(superState);
}

/**
* Constructor called from {@link #CREATOR}
*/
private SavedState(Parcel in) {
super(in);
readState(in);
}

/**
* Constructor called from {@link #CREATOR}
*/
@TargetApi(VERSION_CODES.N)
private SavedState(Parcel in, ClassLoader loader) {
super(in, loader);
readState(in);
}

private void readState(Parcel in) {
count = in.readInt();
}

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

@Override
public String toString() {
return CounterFab.class.getSimpleName() + '.' + SavedState.class.getSimpleName() + '{'
+ Integer.toHexString(System.identityHashCode(this))
+ " count=" + count + '}';
}

public static final Creator<SavedState> CREATOR = new ClassLoaderCreator<SavedState>() {

@Override
public SavedState createFromParcel(Parcel in, ClassLoader loader) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return new SavedState(in, loader);
} else {
return new SavedState(in);
}
}

@Override
public SavedState createFromParcel(Parcel in) {
return new SavedState(in);
}

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

@Override
public Parcelable onSaveInstanceState() {
Parcelable superState = super.onSaveInstanceState();
SavedState ss = new SavedState(superState);
ss.count = mCount;
return ss;
ExtendableSavedState state = new ExtendableSavedState(superState);

Bundle bundle = new Bundle();
bundle.putInt(COUNT_STATE, mCount);
state.extendableStates.put(STATE_KEY, bundle);

return state;
}

@Override
public void onRestoreInstanceState(Parcelable state) {
SavedState ss = (SavedState) state;
super.onRestoreInstanceState(ss.getSuperState());
setCount(ss.count);
if (!(state instanceof ExtendableSavedState)) {
super.onRestoreInstanceState(state);
return;
}

ExtendableSavedState extendableState = (ExtendableSavedState) state;
super.onRestoreInstanceState(extendableState.getSuperState());

Bundle bundle = extendableState.extendableStates.get(STATE_KEY);
setCount(bundle.getInt(COUNT_STATE));
requestLayout();
}

Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Dec 28 10:00:20 PST 2015
#Wed Jan 30 18:23:22 WET 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
4 changes: 2 additions & 2 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':counterfab')
implementation "com.android.support:design:$supportLibraryVersion"
implementation "com.google.android.material:material:$materialVersion"

testImplementation "junit:junit:$junitVersion"

androidTestImplementation "com.android.support.test.espresso:espresso-core:$espressoVersion"
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoCoreVersion"
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package com.andremion.counterfab.sample;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.View;
import android.widget.RadioGroup;

Expand All @@ -33,10 +33,10 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

mCounterMode = (RadioGroup) findViewById(R.id.counter_mode);
mCounterMode = findViewById(R.id.counter_mode);
mCounterMode.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
Expand All @@ -48,7 +48,7 @@ public void onCheckedChanged(RadioGroup group, int checkedId) {
}
});

mCounterFab = (CounterFab) findViewById(R.id.fab);
mCounterFab = findViewById(R.id.fab);
mCounterFab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Expand Down
10 changes: 5 additions & 5 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@
~ limitations under the License.
-->

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">

<android.support.design.widget.AppBarLayout
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>
</com.google.android.material.appbar.AppBarLayout>

<include layout="@layout/content_main" />

Expand All @@ -48,4 +48,4 @@
app:badgePosition="RightTop"
app:srcCompat="@drawable/ic_add_white_24dp" />

</android.support.design.widget.CoordinatorLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
5 changes: 5 additions & 0 deletions sample/src/main/res/values-v21/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<resources>
<!--We can't use FloatingActionButton#setUseCompatPadding due an issue in Lollipop.-->
<!--Use this margin only for API 21+-->
<dimen name="fab_margin">16dp</dimen>
</resources>
4 changes: 3 additions & 1 deletion sample/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="fab_margin">16dp</dimen>
<!--We can't use FloatingActionButton#setUseCompatPadding due an issue in Lollipop.-->
<!--For pre Lollipop we don't need margin-->
<dimen name="fab_margin">0dp</dimen>
</resources>
6 changes: 3 additions & 3 deletions sample/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
Expand All @@ -13,8 +13,8 @@
<item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.MaterialComponents.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.MaterialComponents.Light" />

</resources>

0 comments on commit 1a8d56e

Please sign in to comment.