From 31b1e7beb9486a53fb0243e345ad5a8eda378144 Mon Sep 17 00:00:00 2001 From: Rey Pham Date: Fri, 11 Dec 2015 10:17:06 +0700 Subject: [PATCH 01/16] Add ImageView class. CheckedImageView: support checked state. --- .../rey/material/widget/CheckedImageView.java | 118 +++------------- .../com/rey/material/widget/ImageView.java | 127 ++++++++++++++++++ .../rey/material/widget/TabIndicatorView.java | 2 +- 3 files changed, 145 insertions(+), 102 deletions(-) create mode 100644 material/src/main/java/com/rey/material/widget/ImageView.java diff --git a/material/src/main/java/com/rey/material/widget/CheckedImageView.java b/material/src/main/java/com/rey/material/widget/CheckedImageView.java index 2ec3c5db..1e277209 100644 --- a/material/src/main/java/com/rey/material/widget/CheckedImageView.java +++ b/material/src/main/java/com/rey/material/widget/CheckedImageView.java @@ -1,136 +1,41 @@ package com.rey.material.widget; -import android.annotation.TargetApi; import android.content.Context; -import android.graphics.drawable.Drawable; -import android.os.Build; -import android.support.annotation.NonNull; import android.util.AttributeSet; -import android.view.MotionEvent; import android.widget.Checkable; -import com.rey.material.app.ThemeManager; -import com.rey.material.drawable.RippleDrawable; -import com.rey.material.util.ViewUtil; - /** * Created by Rey on 9/16/2015. */ -public class CheckedImageView extends android.widget.ImageView implements Checkable, ThemeManager.OnThemeChangedListener { - - private RippleManager mRippleManager; - protected int mStyleId; - protected int mCurrentStyle = ThemeManager.THEME_UNDEFINED; +public class CheckedImageView extends ImageView implements Checkable { private boolean mChecked = false; + private static final int[] STATE_CHECKED = new int[]{ + android.R.attr.state_checked + }; + public CheckedImageView(Context context) { super(context); - - init(context, null, 0, 0); } public CheckedImageView(Context context, AttributeSet attrs) { super(context, attrs); - - init(context, attrs, 0, 0); } public CheckedImageView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); - - init(context, attrs, defStyleAttr, 0); } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) public CheckedImageView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); - - init(context, attrs, defStyleAttr, defStyleRes); - } - - protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){ - applyStyle(context, attrs, defStyleAttr, defStyleRes); - if(!isInEditMode()) - mStyleId = ThemeManager.getStyleId(context, attrs, defStyleAttr, defStyleRes); - } - - public void applyStyle(int resId){ - ViewUtil.applyStyle(this, resId); - applyStyle(getContext(), null, 0, resId); - } - - protected void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){ - getRippleManager().onCreate(this, context, attrs, defStyleAttr, defStyleRes); - } - - @Override - public void onThemeChanged(ThemeManager.OnThemeChangedEvent event) { - int style = ThemeManager.getInstance().getCurrentStyle(mStyleId); - if(mCurrentStyle != style){ - mCurrentStyle = style; - applyStyle(mCurrentStyle); - } - } - - @Override - protected void onAttachedToWindow() { - super.onAttachedToWindow(); - if(mStyleId != 0) { - ThemeManager.getInstance().registerOnThemeChangedListener(this); - onThemeChanged(null); - } - } - - @Override - protected void onDetachedFromWindow() { - super.onDetachedFromWindow(); - RippleManager.cancelRipple(this); - if(mStyleId != 0) - ThemeManager.getInstance().unregisterOnThemeChangedListener(this); - } - - @Override - public void setBackgroundDrawable(Drawable drawable) { - Drawable background = getBackground(); - if(background instanceof RippleDrawable && !(drawable instanceof RippleDrawable)) - ((RippleDrawable) background).setBackgroundDrawable(drawable); - else - super.setBackgroundDrawable(drawable); - } - - protected RippleManager getRippleManager(){ - if(mRippleManager == null){ - synchronized (RippleManager.class){ - if(mRippleManager == null) - mRippleManager = new RippleManager(); - } - } - - return mRippleManager; - } - - @Override - public void setOnClickListener(OnClickListener l) { - RippleManager rippleManager = getRippleManager(); - if (l == rippleManager) - super.setOnClickListener(l); - else { - rippleManager.setOnClickListener(l); - setOnClickListener(rippleManager); - } - } - - @Override - public boolean onTouchEvent(@NonNull MotionEvent event) { - boolean result = super.onTouchEvent(event); - return getRippleManager().onTouchEvent(this, event) || result; } @Override public void setChecked(boolean b) { if(mChecked != b){ mChecked = b; + refreshDrawableState(); } } @@ -143,4 +48,15 @@ public boolean isChecked() { public void toggle() { setChecked(!isChecked()); } + + @Override + public int[] onCreateDrawableState(int extraSpace) { + final int[] drawableState = super.onCreateDrawableState(extraSpace + 1); + + int[] additionalStates = mChecked ? STATE_CHECKED : null; + if (additionalStates != null) + mergeDrawableStates(drawableState, additionalStates); + + return drawableState; + } } diff --git a/material/src/main/java/com/rey/material/widget/ImageView.java b/material/src/main/java/com/rey/material/widget/ImageView.java new file mode 100644 index 00000000..4d42558b --- /dev/null +++ b/material/src/main/java/com/rey/material/widget/ImageView.java @@ -0,0 +1,127 @@ +package com.rey.material.widget; + +import android.annotation.TargetApi; +import android.content.Context; +import android.graphics.drawable.Drawable; +import android.os.Build; +import android.support.annotation.NonNull; +import android.util.AttributeSet; +import android.view.MotionEvent; + +import com.rey.material.app.ThemeManager; +import com.rey.material.drawable.RippleDrawable; +import com.rey.material.util.ViewUtil; + +/** + * Created by Rey on 9/16/2015. + */ +public class ImageView extends android.widget.ImageView implements ThemeManager.OnThemeChangedListener { + + private RippleManager mRippleManager; + protected int mStyleId; + protected int mCurrentStyle = ThemeManager.THEME_UNDEFINED; + + public ImageView(Context context) { + super(context); + + init(context, null, 0, 0); + } + + public ImageView(Context context, AttributeSet attrs) { + super(context, attrs); + + init(context, attrs, 0, 0); + } + + public ImageView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + + init(context, attrs, defStyleAttr, 0); + } + + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public ImageView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + + init(context, attrs, defStyleAttr, defStyleRes); + } + + protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){ + applyStyle(context, attrs, defStyleAttr, defStyleRes); + if(!isInEditMode()) + mStyleId = ThemeManager.getStyleId(context, attrs, defStyleAttr, defStyleRes); + } + + public void applyStyle(int resId){ + ViewUtil.applyStyle(this, resId); + applyStyle(getContext(), null, 0, resId); + } + + protected void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){ + getRippleManager().onCreate(this, context, attrs, defStyleAttr, defStyleRes); + } + + @Override + public void onThemeChanged(ThemeManager.OnThemeChangedEvent event) { + int style = ThemeManager.getInstance().getCurrentStyle(mStyleId); + if(mCurrentStyle != style){ + mCurrentStyle = style; + applyStyle(mCurrentStyle); + } + } + + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + if(mStyleId != 0) { + ThemeManager.getInstance().registerOnThemeChangedListener(this); + onThemeChanged(null); + } + } + + @Override + protected void onDetachedFromWindow() { + super.onDetachedFromWindow(); + RippleManager.cancelRipple(this); + if(mStyleId != 0) + ThemeManager.getInstance().unregisterOnThemeChangedListener(this); + } + + @Override + public void setBackgroundDrawable(Drawable drawable) { + Drawable background = getBackground(); + if(background instanceof RippleDrawable && !(drawable instanceof RippleDrawable)) + ((RippleDrawable) background).setBackgroundDrawable(drawable); + else + super.setBackgroundDrawable(drawable); + } + + protected RippleManager getRippleManager(){ + if(mRippleManager == null){ + synchronized (RippleManager.class){ + if(mRippleManager == null) + mRippleManager = new RippleManager(); + } + } + + return mRippleManager; + } + + @Override + public void setOnClickListener(OnClickListener l) { + RippleManager rippleManager = getRippleManager(); + if (l == rippleManager) + super.setOnClickListener(l); + else { + rippleManager.setOnClickListener(l); + setOnClickListener(rippleManager); + } + } + + @Override + public boolean onTouchEvent(@NonNull MotionEvent event) { + boolean result = super.onTouchEvent(event); + return getRippleManager().onTouchEvent(this, event) || result; + } + +} diff --git a/material/src/main/java/com/rey/material/widget/TabIndicatorView.java b/material/src/main/java/com/rey/material/widget/TabIndicatorView.java index 9a3981ae..56d74fa5 100644 --- a/material/src/main/java/com/rey/material/widget/TabIndicatorView.java +++ b/material/src/main/java/com/rey/material/widget/TabIndicatorView.java @@ -588,7 +588,7 @@ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { v = new CheckedTextView(parent.getContext()); break; case TYPE_ICON: - v = new ImageButton(parent.getContext()); + v = new CheckedImageView(parent.getContext()); break; } From 650d586d31f3bd9ce525dc95742f0ae0eb2cf26f Mon Sep 17 00:00:00 2001 From: Rey Pham Date: Fri, 11 Dec 2015 10:29:07 +0700 Subject: [PATCH 02/16] Fix bug #294. --- .../java/com/rey/material/app/BottomSheetDialog.java | 7 ++++++- material/src/main/java/com/rey/material/app/Dialog.java | 9 +++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/material/src/main/java/com/rey/material/app/BottomSheetDialog.java b/material/src/main/java/com/rey/material/app/BottomSheetDialog.java index 1d9eb4b7..e88dc00e 100644 --- a/material/src/main/java/com/rey/material/app/BottomSheetDialog.java +++ b/material/src/main/java/com/rey/material/app/BottomSheetDialog.java @@ -55,6 +55,8 @@ public void run() { private boolean mRunShowAnimation = false; private Animation mAnimation; + private boolean mDismissPending = false; + public BottomSheetDialog(Context context) { this(context, R.style.Material_App_BottomSheetDialog); } @@ -344,7 +346,7 @@ public void dismissImmediately(){ @Override public void dismiss() { - if(!isShowing()) + if(!isShowing() || mDismissPending) return; if(mContentView != null){ @@ -354,6 +356,7 @@ public void dismiss() { mAnimation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { + mDismissPending = true; } @Override @@ -362,9 +365,11 @@ public void onAnimationRepeat(Animation animation) { @Override public void onAnimationEnd(Animation animation) { + mDismissPending = false; mAnimation = null; mHandler.post(mDismissAction); } + }); mContentView.startAnimation(mAnimation); } diff --git a/material/src/main/java/com/rey/material/app/Dialog.java b/material/src/main/java/com/rey/material/app/Dialog.java index 5bc681d2..de428211 100644 --- a/material/src/main/java/com/rey/material/app/Dialog.java +++ b/material/src/main/java/com/rey/material/app/Dialog.java @@ -81,6 +81,7 @@ public void run() { private boolean mCancelable = true; private boolean mCanceledOnTouchOutside = true; + private boolean mDismissPending = false; /** * The viewId of title view. @@ -1045,23 +1046,27 @@ public void dismissImmediately(){ @Override public void dismiss() { - if(!isShowing()) + if(!isShowing() || mDismissPending) return; if(mOutAnimationId != 0){ Animation anim = AnimationUtils.loadAnimation(mContainer.getContext(), mOutAnimationId); anim.setAnimationListener(new Animation.AnimationListener() { @Override - public void onAnimationStart(Animation animation) {} + public void onAnimationStart(Animation animation) { + mDismissPending = true; + } @Override public void onAnimationRepeat(Animation animation) {} @Override public void onAnimationEnd(Animation animation) { + mDismissPending = false; mCardView.setVisibility(View.GONE); mHandler.post(mDismissAction); } + }); mCardView.startAnimation(anim); } From 32a6bb3d0e60253a35387e6f6c690ec47fac4d58 Mon Sep 17 00:00:00 2001 From: Rey Pham Date: Sat, 12 Dec 2015 10:56:49 +0700 Subject: [PATCH 03/16] Fix bug #271 (incorrect baseline calculating). --- .../java/com/rey/material/widget/Spinner.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/material/src/main/java/com/rey/material/widget/Spinner.java b/material/src/main/java/com/rey/material/widget/Spinner.java index c829b068..a30d79dd 100644 --- a/material/src/main/java/com/rey/material/widget/Spinner.java +++ b/material/src/main/java/com/rey/material/widget/Spinner.java @@ -14,6 +14,7 @@ import android.support.annotation.NonNull; import android.text.TextUtils; import android.util.AttributeSet; +import android.util.Log; import android.util.SparseArray; import android.util.TypedValue; import android.view.Gravity; @@ -583,7 +584,24 @@ public int getBaseline() { if (child != null) { final int childBaseline = child.getBaseline(); - return childBaseline >= 0 ? child.getTop() + childBaseline : -1; + if(childBaseline < 0) + return -1; + + int paddingTop = getPaddingTop(); + if(mLabelView != null) + paddingTop += mLabelView.getMeasuredHeight(); + + int remainHeight = getMeasuredHeight() - paddingTop - getPaddingBottom() - getDividerDrawableHeight(); + + int verticalGravity = mGravity & Gravity.VERTICAL_GRAVITY_MASK; + switch (verticalGravity) { + case Gravity.TOP: + return paddingTop + childBaseline; + case Gravity.BOTTOM: + return paddingTop + remainHeight - child.getMeasuredHeight() + childBaseline; + default: + return (remainHeight - child.getMeasuredHeight()) / 2 + paddingTop + childBaseline; + } } return -1; @@ -813,7 +831,7 @@ else if(horizontalGravity == Gravity.END) } v.layout(x, y, x + v.getMeasuredWidth(), y + v.getMeasuredHeight()); - } + } } @Override From 9a0d011674acd7c9b4eaec58b5601a6718aa484e Mon Sep 17 00:00:00 2001 From: Rey Pham Date: Sat, 12 Dec 2015 11:39:19 +0700 Subject: [PATCH 04/16] Add support for Maven's SNAPSHOT repository. --- .idea/vcs.xml | 1 + app/app.iml | 6 --- dist/bintray.gradle | 28 ----------- dist/distInfo.gradle | 29 +++++++++++ dist/maven.gradle | 114 ++++++++++++++++++++++++++++++++++++++++++ material/build.gradle | 2 + material/material.iml | 5 +- 7 files changed, 147 insertions(+), 38 deletions(-) create mode 100644 dist/distInfo.gradle create mode 100644 dist/maven.gradle diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7f..fce7f719 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,5 +2,6 @@ + \ No newline at end of file diff --git a/app/app.iml b/app/app.iml index 50b71d60..d3a03676 100644 --- a/app/app.iml +++ b/app/app.iml @@ -66,22 +66,16 @@ - - - - - - diff --git a/dist/bintray.gradle b/dist/bintray.gradle index 6c309d10..715105be 100644 --- a/dist/bintray.gradle +++ b/dist/bintray.gradle @@ -1,34 +1,6 @@ apply plugin: 'com.github.dcendents.android-maven' apply plugin: 'com.jfrog.bintray' -ext { - bintrayUser = BINTRAY_USERNAME - bintrayApiKey = BINTRAY_APIKEY - bintrayGpgPassword = GPG_PASSWORD - - bintrayRepo = 'maven' - bintrayName = 'material' - - publishedGroupId = 'com.github.rey5137' - libraryName = 'Material Library' - artifact = 'material' - - libraryDescription = 'An Android library to bring Material Design UI to pre-Lolipop Android.' - - siteUrl = 'https://github.com/rey5137/material' - gitUrl = 'https://github.com/rey5137/material.git' - - libraryVersion = '1.2.2' - - developerId = 'rey5137' - developerName = 'Rey Pham' - developerEmail = 'pea5137@gmail.com' - - licenseName = 'The Apache Software License, Version 2.0' - licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt' - allLicenses = ["Apache-2.0"] -} - group = publishedGroupId // Maven Group ID for the artifact install { diff --git a/dist/distInfo.gradle b/dist/distInfo.gradle new file mode 100644 index 00000000..6e919e39 --- /dev/null +++ b/dist/distInfo.gradle @@ -0,0 +1,29 @@ +ext { + bintrayUser = BINTRAY_USERNAME + bintrayApiKey = BINTRAY_APIKEY + bintrayGpgPassword = GPG_PASSWORD + + bintrayRepo = 'maven' + bintrayName = 'material' + + publishedGroupId = 'com.github.rey5137' + libraryName = 'Material Library' + artifact = 'material' + libraryPackaging = 'aar' + + libraryDescription = 'An Android library to bring Material Design UI to pre-Lolipop Android.' + + siteUrl = 'https://github.com/rey5137/material' + gitUrl = 'https://github.com/rey5137/material.git' + + libraryVersion = '1.2.2.1-SNAPSHOT' + + developerId = 'rey5137' + developerName = 'Rey Pham' + developerEmail = 'pea5137@gmail.com' + + licenseName = 'The Apache Software License, Version 2.0' + licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt' + licenseDist = 'repo' + allLicenses = ["Apache-2.0"] +} \ No newline at end of file diff --git a/dist/maven.gradle b/dist/maven.gradle new file mode 100644 index 00000000..97c34b6c --- /dev/null +++ b/dist/maven.gradle @@ -0,0 +1,114 @@ +/* + * Copyright 2013 Chris Banes + * + * 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. + */ + +apply plugin: 'maven' +apply plugin: 'signing' + +def isReleaseBuild() { + return libraryVersion.contains("SNAPSHOT") == false +} + +def getReleaseRepositoryUrl() { + return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL + : "https://oss.sonatype.org/service/local/staging/deploy/maven2/" +} + +def getSnapshotRepositoryUrl() { + return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL + : "https://oss.sonatype.org/content/repositories/snapshots/" +} + +def getRepositoryUsername() { + return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : "" +} + +def getRepositoryPassword() { + return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : "" +} + +afterEvaluate { project -> + uploadArchives { + repositories { + mavenDeployer { + beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } + + pom.groupId = publishedGroupId + pom.artifactId = artifact + pom.version = libraryVersion + + repository(url: getReleaseRepositoryUrl()) { + authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) + } + snapshotRepository(url: getSnapshotRepositoryUrl()) { + authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) + } + + pom.project { + name libraryName + packaging libraryPackaging + description libraryDescription + url siteUrl + + scm { + url siteUrl + connection gitUrl + developerConnection gitUrl + } + + licenses { + license { + name licenseName + url licenseUrl + distribution licenseDist + } + } + + developers { + developer { + id developerId + name developerName + } + } + } + } + } + } + + signing { + required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") } + sign configurations.archives + } + + task androidJavadocs(type: Javadoc) { + source = android.sourceSets.main.java.srcDirs + classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) + } + + task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) { + classifier = 'javadoc' + from androidJavadocs.destinationDir + } + + task androidSourcesJar(type: Jar) { + classifier = 'sources' + from android.sourceSets.main.java.sourceFiles + } + + artifacts { + archives androidSourcesJar + archives androidJavadocsJar + } +} \ No newline at end of file diff --git a/material/build.gradle b/material/build.gradle index 17bc46e4..848013b6 100644 --- a/material/build.gradle +++ b/material/build.gradle @@ -30,4 +30,6 @@ dependencies { compile "com.android.support:recyclerview-v7:${libSupportVersion}" } +apply from: '../dist/distInfo.gradle' apply from: '../dist/bintray.gradle' +apply from: '../dist/maven.gradle' diff --git a/material/material.iml b/material/material.iml index 3e644054..c66a6e8d 100644 --- a/material/material.iml +++ b/material/material.iml @@ -1,5 +1,5 @@ - + @@ -65,7 +65,6 @@ - @@ -79,9 +78,7 @@ - - From 6a8090dec7fb8a65c584dbad568dc76746755e0a Mon Sep 17 00:00:00 2001 From: Rey Pham Date: Mon, 21 Dec 2015 23:42:19 +0700 Subject: [PATCH 05/16] Spinner: fix NPE bug. --- dist/distInfo.gradle | 2 +- material/src/main/java/com/rey/material/widget/Spinner.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/distInfo.gradle b/dist/distInfo.gradle index 6e919e39..6ecb8a22 100644 --- a/dist/distInfo.gradle +++ b/dist/distInfo.gradle @@ -16,7 +16,7 @@ ext { siteUrl = 'https://github.com/rey5137/material' gitUrl = 'https://github.com/rey5137/material.git' - libraryVersion = '1.2.2.1-SNAPSHOT' + libraryVersion = '1.2.2.2-SNAPSHOT' developerId = 'rey5137' developerName = 'Rey Pham' diff --git a/material/src/main/java/com/rey/material/widget/Spinner.java b/material/src/main/java/com/rey/material/widget/Spinner.java index a30d79dd..815d2b74 100644 --- a/material/src/main/java/com/rey/material/widget/Spinner.java +++ b/material/src/main/java/com/rey/material/widget/Spinner.java @@ -951,7 +951,7 @@ private int measureContentWidth(SpinnerAdapter adapter, Drawable background) { itemType = positionType; itemView = null; } - itemView = adapter.getView(i, itemView, null); + itemView = adapter.getView(i, itemView, this); if (itemView.getLayoutParams() == null) itemView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); From cdb3e71381f6f942673f8954f98380425f7a3377 Mon Sep 17 00:00:00 2001 From: rey5137 Date: Thu, 7 Jan 2016 14:38:41 +0700 Subject: [PATCH 06/16] ToolbarManager: add show/hide navigation feature. --- .../com/rey/material/app/ToolbarManager.java | 223 +++++++++++++++++- 1 file changed, 214 insertions(+), 9 deletions(-) diff --git a/material/src/main/java/com/rey/material/app/ToolbarManager.java b/material/src/main/java/com/rey/material/app/ToolbarManager.java index 572678a8..67f6ec6f 100644 --- a/material/src/main/java/com/rey/material/app/ToolbarManager.java +++ b/material/src/main/java/com/rey/material/app/ToolbarManager.java @@ -2,19 +2,24 @@ import android.os.Build; import android.support.annotation.Nullable; +import android.support.v4.animation.AnimatorCompatHelper; +import android.support.v4.animation.AnimatorUpdateListenerCompat; +import android.support.v4.animation.ValueAnimatorCompat; import android.support.v4.app.FragmentManager; import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.AppCompatDelegate; import android.support.v7.widget.ActionMenuView; import android.support.v7.widget.Toolbar; -import android.view.Gravity; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewTreeObserver; import android.view.animation.Animation; import android.view.animation.AnimationUtils; +import android.view.animation.DecelerateInterpolator; +import android.view.animation.Interpolator; +import android.view.animation.TranslateAnimation; import com.rey.material.drawable.NavigationDrawerDrawable; import com.rey.material.drawable.ToolbarRippleDrawable; @@ -22,6 +27,7 @@ import java.lang.ref.WeakReference; import java.util.ArrayList; +import java.util.List; /** * A Manager class to help handling Toolbar used as ActionBar in ActionBarActivity. @@ -228,6 +234,15 @@ public boolean isNavigationBackState(){ return mNavigationManager != null && mNavigationManager.isBackState(); } + public boolean isNavigationVisisble(){ + return mNavigationManager != null && mNavigationManager.isNavigationVisible(); + } + + public void setNavigationVisisble(boolean visible, boolean animation){ + if(mNavigationManager != null) + mNavigationManager.setNavigationVisible(visible, animation); + } + private ToolbarRippleDrawable getBackground(){ if(mBuilder == null) mBuilder = new ToolbarRippleDrawable.Builder(mToolbar.getContext(), mRippleStyle); @@ -362,19 +377,21 @@ public static abstract class NavigationManager{ protected NavigationDrawerDrawable mNavigationIcon; protected Toolbar mToolbar; - /** - * @param styleId the style res of navigation icon. - */ + protected long mAnimationDuration; + protected boolean mNavigationVisible = true; + protected boolean mAnimating = false; + public NavigationManager(NavigationDrawerDrawable navigationIcon, Toolbar toolbar){ mToolbar = toolbar; mNavigationIcon = navigationIcon; - mToolbar.setNavigationIcon(mNavigationIcon); - mToolbar.setNavigationOnClickListener(new View.OnClickListener(){ + mToolbar.setNavigationIcon(mNavigationVisible ? mNavigationIcon : null); + mToolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onNavigationClick(); } }); + mAnimationDuration = toolbar.getResources().getInteger(android.R.integer.config_shortAnimTime); } /** @@ -399,7 +416,7 @@ public void notifyStateInvalidated(){ * Notify the current state of navigation icon is changed. It should update the state with animation. */ public void notifyStateChanged(){ - mNavigationIcon.switchIconState(isBackState() ? NavigationDrawerDrawable.STATE_ARROW : NavigationDrawerDrawable.STATE_DRAWER, true); + mNavigationIcon.switchIconState(isBackState() ? NavigationDrawerDrawable.STATE_ARROW : NavigationDrawerDrawable.STATE_DRAWER, mNavigationVisible); } /** @@ -411,6 +428,194 @@ public void notifyStateProgressChanged(boolean isBackState, float progress){ mNavigationIcon.setIconState(isBackState ? NavigationDrawerDrawable.STATE_ARROW : NavigationDrawerDrawable.STATE_DRAWER, progress); } + public boolean isNavigationVisible(){ + return mNavigationVisible; + } + + public void setNavigationVisible(boolean visible, boolean animation){ + if(mAnimating) + return; + + if(mNavigationVisible != visible){ + mNavigationVisible = visible; + + if(!animation) + mToolbar.setNavigationIcon(mNavigationVisible ? mNavigationIcon : null); + else{ + if(mNavigationVisible) + animateNavigationIn(); + else + animateNavigationOut(); + } + + } + } + + protected Interpolator getInterpolator(boolean in){ + return new DecelerateInterpolator(); + } + + private void animateNavigationOut(){ + mAnimating = true; + mToolbar.setNavigationIcon(null); + doOnPreDraw(mToolbar, new Runnable() { + @Override + public void run() { + final ViewData viewData = new ViewData(mToolbar); + mToolbar.setNavigationIcon(mNavigationIcon); + + doOnPreDraw(mToolbar, new Runnable() { + @Override + public void run() { + boolean first = true; + for (int i = 0, count = mToolbar.getChildCount(); i < count; i++) { + View child = mToolbar.getChildAt(i); + if (!(child instanceof ActionMenuView)) { + int nextLeft = viewData.getLeft(child); + if (nextLeft < 0) + nextLeft = -child.getLeft() - child.getWidth(); + + if (first) { + animateView(child, child.getLeft(), nextLeft, new Runnable() { + @Override + public void run() { + mToolbar.setNavigationIcon(null); + mAnimating = false; + } + }); + first = false; + } else + animateView(child, child.getLeft(), nextLeft, null); + } + } + + if (first) { + mToolbar.setNavigationIcon(null); + mAnimating = false; + } + } + }); + } + }); + } + + private void animateView(final View view, final int prevLeft, final int nextLeft, final Runnable doOnEndRunnable){ + final Interpolator interpolator = getInterpolator(false); + + ValueAnimatorCompat animator = AnimatorCompatHelper.emptyValueAnimator(); + animator.setDuration(mAnimationDuration); + animator.addUpdateListener(new AnimatorUpdateListenerCompat() { + @Override + public void onAnimationUpdate(ValueAnimatorCompat animation) { + float factor = interpolator.getInterpolation(animation.getAnimatedFraction()); + float left = prevLeft + (nextLeft - prevLeft) * factor; + view.offsetLeftAndRight((int) (left - view.getLeft())); + + if (animation.getAnimatedFraction() == 1f) { + if (doOnEndRunnable != null) + doOnEndRunnable.run(); + } + } + }); + + animator.start(); + } + + private void animateNavigationIn(){ + mAnimating = true; + + doOnPreDraw(mToolbar, new Runnable() { + @Override + public void run() { + final ViewData viewData = new ViewData(mToolbar); + mToolbar.setNavigationIcon(mNavigationIcon); + + doOnPreDraw(mToolbar, new Runnable() { + @Override + public void run() { + boolean first = true; + + for(int i = 0, count = mToolbar.getChildCount(); i < count; i++){ + View child = mToolbar.getChildAt(i); + if(!(child instanceof ActionMenuView)){ + int prevLeft = viewData.getLeft(child); + if(prevLeft < 0) + prevLeft = -child.getLeft() - child.getWidth(); + + TranslateAnimation anim = new TranslateAnimation( + TranslateAnimation.ABSOLUTE, prevLeft - child.getLeft(), TranslateAnimation.ABSOLUTE, 0, + TranslateAnimation.ABSOLUTE, 0, TranslateAnimation.ABSOLUTE, 0); + + if(first){ + anim.setAnimationListener(new Animation.AnimationListener() { + @Override + public void onAnimationStart(Animation animation) {} + + @Override + public void onAnimationEnd(Animation animation) { + mAnimating = false; + } + + @Override + public void onAnimationRepeat(Animation animation) {} + }); + first = false; + } + + anim.setInterpolator(getInterpolator(true)); + anim.setDuration(mAnimationDuration); + child.startAnimation(anim); + } + } + + if(first) + mAnimating = false; + } + }); + } + }); + } + + private void doOnPreDraw(final View v, final Runnable runnable){ + v.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { + @Override + public boolean onPreDraw() { + runnable.run(); + v.getViewTreeObserver().removeOnPreDrawListener(this); + return false; + } + }); + } + + static class ViewData{ + + List views; + List lefts; + + public ViewData(Toolbar toolbar){ + int count = toolbar.getChildCount(); + views = new ArrayList<>(count); + lefts = new ArrayList<>(count); + + for(int i = 0; i < count; i++){ + View child = toolbar.getChildAt(i); + if(!(child instanceof ActionMenuView)) { + views.add(child); + lefts.add(child.getLeft()); + } + } + } + + public int getLeft(View view){ + for(int i = 0, size = views.size(); i < size; i++) + if(views.get(i) == view) + return lefts.get(i); + + return -1; + } + + } + } /** @@ -466,7 +671,7 @@ public void onBackStackChanged() { @Override public boolean isBackState() { - return mFragmentManager.getBackStackEntryCount() > 1 || (mDrawerLayout != null && mDrawerLayout.isDrawerOpen(Gravity.START)); + return mFragmentManager.getBackStackEntryCount() > 1 || (mDrawerLayout != null && mDrawerLayout.isDrawerOpen(GravityCompat.START)); } @Override @@ -538,7 +743,7 @@ public void onThemeChanged(@Nullable ThemeManager.OnThemeChangedEvent event) { NavigationDrawerDrawable drawable = new NavigationDrawerDrawable.Builder(mToolbar.getContext(), mCurrentStyle).build(); drawable.switchIconState(mNavigationIcon.getIconState(), false); mNavigationIcon = drawable; - mToolbar.setNavigationIcon(mNavigationIcon); + mToolbar.setNavigationIcon(mNavigationVisible ? mNavigationIcon : null); } } From 112daec95922988f30098e2c4f5e5981bbc91219 Mon Sep 17 00:00:00 2001 From: rey5137 Date: Fri, 8 Jan 2016 15:26:08 +0700 Subject: [PATCH 07/16] ToolbarManager: handle case animations are canceled. --- dist/distInfo.gradle | 2 +- .../com/rey/material/app/ToolbarManager.java | 173 ++++++++++++------ .../drawable/LineMorphingDrawable.java | 7 +- .../drawable/NavigationDrawerDrawable.java | 9 +- 4 files changed, 127 insertions(+), 64 deletions(-) diff --git a/dist/distInfo.gradle b/dist/distInfo.gradle index 6ecb8a22..dd90dbba 100644 --- a/dist/distInfo.gradle +++ b/dist/distInfo.gradle @@ -16,7 +16,7 @@ ext { siteUrl = 'https://github.com/rey5137/material' gitUrl = 'https://github.com/rey5137/material.git' - libraryVersion = '1.2.2.2-SNAPSHOT' + libraryVersion = '1.2.2.4-SNAPSHOT' developerId = 'rey5137' developerName = 'Rey Pham' diff --git a/material/src/main/java/com/rey/material/app/ToolbarManager.java b/material/src/main/java/com/rey/material/app/ToolbarManager.java index 67f6ec6f..68faf36d 100644 --- a/material/src/main/java/com/rey/material/app/ToolbarManager.java +++ b/material/src/main/java/com/rey/material/app/ToolbarManager.java @@ -1,8 +1,10 @@ package com.rey.material.app; import android.os.Build; +import android.os.SystemClock; import android.support.annotation.Nullable; import android.support.v4.animation.AnimatorCompatHelper; +import android.support.v4.animation.AnimatorListenerCompat; import android.support.v4.animation.AnimatorUpdateListenerCompat; import android.support.v4.animation.ValueAnimatorCompat; import android.support.v4.app.FragmentManager; @@ -377,9 +379,11 @@ public static abstract class NavigationManager{ protected NavigationDrawerDrawable mNavigationIcon; protected Toolbar mToolbar; - protected long mAnimationDuration; protected boolean mNavigationVisible = true; - protected boolean mAnimating = false; + + protected long mAnimationDuration; + private long mAnimTime; + private List mAnimations = new ArrayList<>(); public NavigationManager(NavigationDrawerDrawable navigationIcon, Toolbar toolbar){ mToolbar = toolbar; @@ -433,19 +437,21 @@ public boolean isNavigationVisible(){ } public void setNavigationVisible(boolean visible, boolean animation){ - if(mAnimating) - return; - if(mNavigationVisible != visible){ mNavigationVisible = visible; + long time = SystemClock.uptimeMillis(); - if(!animation) + if(!animation) { mToolbar.setNavigationIcon(mNavigationVisible ? mNavigationIcon : null); + mAnimTime = time; + if(!mNavigationVisible) + mNavigationIcon.cancel(); + } else{ if(mNavigationVisible) - animateNavigationIn(); + animateNavigationIn(time); else - animateNavigationOut(); + animateNavigationOut(time); } } @@ -455,18 +461,29 @@ protected Interpolator getInterpolator(boolean in){ return new DecelerateInterpolator(); } - private void animateNavigationOut(){ - mAnimating = true; + private void cancelAllAnimations(){ + for(Object obj : mAnimations){ + if(obj instanceof Animation) + ((Animation)obj).cancel(); + else if(obj instanceof ValueAnimatorCompat) + ((ValueAnimatorCompat)obj).cancel(); + } + + mAnimations.clear(); + } + + private void animateNavigationOut(long time){ + mAnimTime = time; + cancelAllAnimations(); mToolbar.setNavigationIcon(null); - doOnPreDraw(mToolbar, new Runnable() { + doOnPreDraw(mToolbar, new AnimRunnable(time) { @Override - public void run() { + void doWork() { final ViewData viewData = new ViewData(mToolbar); mToolbar.setNavigationIcon(mNavigationIcon); - - doOnPreDraw(mToolbar, new Runnable() { + doOnPreDraw(mToolbar, new AnimRunnable(mTime) { @Override - public void run() { + void doWork() { boolean first = true; for (int i = 0, count = mToolbar.getChildCount(); i < count; i++) { View child = mToolbar.getChildAt(i); @@ -476,31 +493,30 @@ public void run() { nextLeft = -child.getLeft() - child.getWidth(); if (first) { - animateView(child, child.getLeft(), nextLeft, new Runnable() { + animateViewOut(child, nextLeft, new Runnable() { @Override public void run() { mToolbar.setNavigationIcon(null); - mAnimating = false; + mNavigationIcon.cancel(); } }); first = false; } else - animateView(child, child.getLeft(), nextLeft, null); + animateViewOut(child, nextLeft, null); } } - if (first) { + if (first) mToolbar.setNavigationIcon(null); - mAnimating = false; - } } }); } }); } - private void animateView(final View view, final int prevLeft, final int nextLeft, final Runnable doOnEndRunnable){ + private void animateViewOut(final View view, final int nextLeft, final Runnable doOnEndRunnable){ final Interpolator interpolator = getInterpolator(false); + final int prevLeft = view.getLeft(); ValueAnimatorCompat animator = AnimatorCompatHelper.emptyValueAnimator(); animator.setDuration(mAnimationDuration); @@ -518,64 +534,82 @@ public void onAnimationUpdate(ValueAnimatorCompat animation) { } }); + animator.addListener(new AnimatorListenerCompat() { + @Override + public void onAnimationStart(ValueAnimatorCompat animation) { + } + + @Override + public void onAnimationEnd(ValueAnimatorCompat animation) { + mAnimations.remove(animation); + } + + @Override + public void onAnimationCancel(ValueAnimatorCompat animation) { + } + + @Override + public void onAnimationRepeat(ValueAnimatorCompat animation) { + } + }); + animator.start(); + mAnimations.add(animator); } - private void animateNavigationIn(){ - mAnimating = true; - - doOnPreDraw(mToolbar, new Runnable() { + private void animateNavigationIn(long time){ + mAnimTime = time; + cancelAllAnimations(); + mToolbar.setNavigationIcon(null); + doOnPreDraw(mToolbar, new AnimRunnable(time) { @Override - public void run() { + void doWork() { final ViewData viewData = new ViewData(mToolbar); mToolbar.setNavigationIcon(mNavigationIcon); - - doOnPreDraw(mToolbar, new Runnable() { + doOnPreDraw(mToolbar, new AnimRunnable(mTime) { @Override - public void run() { - boolean first = true; - - for(int i = 0, count = mToolbar.getChildCount(); i < count; i++){ + void doWork() { + for (int i = 0, count = mToolbar.getChildCount(); i < count; i++) { View child = mToolbar.getChildAt(i); - if(!(child instanceof ActionMenuView)){ + if (!(child instanceof ActionMenuView)) { int prevLeft = viewData.getLeft(child); - if(prevLeft < 0) + if (prevLeft < 0) prevLeft = -child.getLeft() - child.getWidth(); - TranslateAnimation anim = new TranslateAnimation( - TranslateAnimation.ABSOLUTE, prevLeft - child.getLeft(), TranslateAnimation.ABSOLUTE, 0, - TranslateAnimation.ABSOLUTE, 0, TranslateAnimation.ABSOLUTE, 0); - - if(first){ - anim.setAnimationListener(new Animation.AnimationListener() { - @Override - public void onAnimationStart(Animation animation) {} - - @Override - public void onAnimationEnd(Animation animation) { - mAnimating = false; - } - - @Override - public void onAnimationRepeat(Animation animation) {} - }); - first = false; - } - - anim.setInterpolator(getInterpolator(true)); - anim.setDuration(mAnimationDuration); - child.startAnimation(anim); + animateViewIn(child, prevLeft); } } - - if(first) - mAnimating = false; } }); } }); } + private void animateViewIn(View view, int prevLeft){ + TranslateAnimation anim = new TranslateAnimation( + TranslateAnimation.ABSOLUTE, prevLeft - view.getLeft(), TranslateAnimation.ABSOLUTE, 0, + TranslateAnimation.ABSOLUTE, 0, TranslateAnimation.ABSOLUTE, 0); + + anim.setAnimationListener(new Animation.AnimationListener() { + @Override + public void onAnimationStart(Animation animation) { + } + + @Override + public void onAnimationEnd(Animation animation) { + mAnimations.remove(animation); + } + + @Override + public void onAnimationRepeat(Animation animation) { + } + }); + anim.setInterpolator(getInterpolator(true)); + anim.setDuration(mAnimationDuration); + view.startAnimation(anim); + mAnimations.add(anim); + } + private void doOnPreDraw(final View v, final Runnable runnable){ v.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override @@ -616,6 +650,23 @@ public int getLeft(View view){ } + abstract class AnimRunnable implements Runnable{ + + long mTime; + + public AnimRunnable(long time){ + mTime = time; + } + + @Override + public void run() { + if(mTime == mAnimTime) + doWork(); + } + + abstract void doWork(); + } + } /** diff --git a/material/src/main/java/com/rey/material/drawable/LineMorphingDrawable.java b/material/src/main/java/com/rey/material/drawable/LineMorphingDrawable.java index cccfb192..d71d9011 100644 --- a/material/src/main/java/com/rey/material/drawable/LineMorphingDrawable.java +++ b/material/src/main/java/com/rey/material/drawable/LineMorphingDrawable.java @@ -318,7 +318,12 @@ private void resetAnimation(){ mStartTime = SystemClock.uptimeMillis(); mAnimProgress = 0f; } - + + public void cancel(){ + stop(); + setLineState(mCurState, 1f); + } + @Override public void start() { resetAnimation(); diff --git a/material/src/main/java/com/rey/material/drawable/NavigationDrawerDrawable.java b/material/src/main/java/com/rey/material/drawable/NavigationDrawerDrawable.java index 4e5206e9..c578149f 100644 --- a/material/src/main/java/com/rey/material/drawable/NavigationDrawerDrawable.java +++ b/material/src/main/java/com/rey/material/drawable/NavigationDrawerDrawable.java @@ -41,7 +41,14 @@ public boolean setIconState(int state, float progress){ public float getIconAnimProgress(){ return mLineDrawable.getAnimProgress(); } - + + public void cancel(){ + if(mRippleDrawable != null) + mRippleDrawable.cancel(); + if(mLineDrawable != null) + mLineDrawable.cancel(); + } + @Override public void draw(Canvas canvas) { mRippleDrawable.draw(canvas); From 9e076318b560d6ab339ecde955766416e5615aad Mon Sep 17 00:00:00 2001 From: rey5137 Date: Thu, 25 Feb 2016 10:53:44 +0700 Subject: [PATCH 08/16] Extend Button from AppCompatButton to support backgroundTint attribute. --- dist/distInfo.gradle | 2 +- .../com/rey/material/drawable/RippleDrawable.java | 6 ++++-- .../main/java/com/rey/material/widget/Button.java | 12 ++---------- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/dist/distInfo.gradle b/dist/distInfo.gradle index 6ecb8a22..dd90dbba 100644 --- a/dist/distInfo.gradle +++ b/dist/distInfo.gradle @@ -16,7 +16,7 @@ ext { siteUrl = 'https://github.com/rey5137/material' gitUrl = 'https://github.com/rey5137/material.git' - libraryVersion = '1.2.2.2-SNAPSHOT' + libraryVersion = '1.2.2.4-SNAPSHOT' developerId = 'rey5137' developerName = 'Rey Pham' diff --git a/material/src/main/java/com/rey/material/drawable/RippleDrawable.java b/material/src/main/java/com/rey/material/drawable/RippleDrawable.java index 0d1a736e..df144455 100644 --- a/material/src/main/java/com/rey/material/drawable/RippleDrawable.java +++ b/material/src/main/java/com/rey/material/drawable/RippleDrawable.java @@ -147,12 +147,14 @@ public void setMask(int type, int topLeftCornerRadius, int topRightCornerRadius, @Override public void setAlpha(int alpha) { mAlpha = alpha; + if(mBackgroundDrawable != null) + mBackgroundDrawable.setAlpha(alpha); } @Override public void setColorFilter(ColorFilter filter) { - mFillPaint.setColorFilter(filter); - mShaderPaint.setColorFilter(filter); + if(mBackgroundDrawable != null) + mBackgroundDrawable.setColorFilter(filter); } @Override diff --git a/material/src/main/java/com/rey/material/widget/Button.java b/material/src/main/java/com/rey/material/widget/Button.java index e85a2e78..7a1e8da8 100644 --- a/material/src/main/java/com/rey/material/widget/Button.java +++ b/material/src/main/java/com/rey/material/widget/Button.java @@ -1,10 +1,9 @@ package com.rey.material.widget; -import android.annotation.TargetApi; import android.content.Context; import android.graphics.drawable.Drawable; -import android.os.Build; import android.support.annotation.NonNull; +import android.support.v7.widget.AppCompatButton; import android.util.AttributeSet; import android.view.MotionEvent; @@ -12,7 +11,7 @@ import com.rey.material.drawable.RippleDrawable; import com.rey.material.util.ViewUtil; -public class Button extends android.widget.Button implements ThemeManager.OnThemeChangedListener{ +public class Button extends AppCompatButton implements ThemeManager.OnThemeChangedListener{ private RippleManager mRippleManager; @@ -37,13 +36,6 @@ public Button(Context context, AttributeSet attrs, int defStyleAttr) { init(context, attrs, defStyleAttr, 0); } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public Button(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - - init(context, attrs, defStyleAttr, defStyleRes); - } - protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){ ViewUtil.applyFont(this, attrs, defStyleAttr, defStyleRes); applyStyle(context, attrs, defStyleAttr, defStyleRes); From e054a51ab45b05941107a1f541b65f065a551fc9 Mon Sep 17 00:00:00 2001 From: rey5137 Date: Thu, 3 Mar 2016 00:27:24 +0700 Subject: [PATCH 09/16] FloatingActionButton: use MarginLayoutParam. --- dist/distInfo.gradle | 2 +- .../rey/material/widget/FloatingActionButton.java | 13 ++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/dist/distInfo.gradle b/dist/distInfo.gradle index dd90dbba..48261ea9 100644 --- a/dist/distInfo.gradle +++ b/dist/distInfo.gradle @@ -16,7 +16,7 @@ ext { siteUrl = 'https://github.com/rey5137/material' gitUrl = 'https://github.com/rey5137/material.git' - libraryVersion = '1.2.2.4-SNAPSHOT' + libraryVersion = '1.2.2.5-SNAPSHOT' developerId = 'rey5137' developerName = 'Rey Pham' diff --git a/material/src/main/java/com/rey/material/widget/FloatingActionButton.java b/material/src/main/java/com/rey/material/widget/FloatingActionButton.java index 2cf4cfaa..289dfb1b 100644 --- a/material/src/main/java/com/rey/material/widget/FloatingActionButton.java +++ b/material/src/main/java/com/rey/material/widget/FloatingActionButton.java @@ -22,7 +22,6 @@ import android.view.animation.DecelerateInterpolator; import android.view.animation.Interpolator; import android.widget.FrameLayout; -import android.widget.RelativeLayout; import com.rey.material.R; import com.rey.material.app.ThemeManager; @@ -413,19 +412,15 @@ private void updateParams(int x, int y, int gravity, ViewGroup.LayoutParams para } private void setLeftMargin(ViewGroup.LayoutParams params, int value){ - if(params instanceof FrameLayout.LayoutParams) - ((FrameLayout.LayoutParams)params).leftMargin = value; - else if(params instanceof RelativeLayout.LayoutParams) - ((RelativeLayout.LayoutParams)params).leftMargin = value; + if(params instanceof ViewGroup.MarginLayoutParams) + ((ViewGroup.MarginLayoutParams)params).leftMargin = value; else Log.v(FloatingActionButton.class.getSimpleName(), "cannot recognize LayoutParams: " + params); } private void setTopMargin(ViewGroup.LayoutParams params, int value){ - if(params instanceof FrameLayout.LayoutParams) - ((FrameLayout.LayoutParams)params).topMargin = value; - else if(params instanceof RelativeLayout.LayoutParams) - ((RelativeLayout.LayoutParams)params).topMargin = value; + if(params instanceof ViewGroup.MarginLayoutParams) + ((ViewGroup.MarginLayoutParams)params).topMargin = value; else Log.v(FloatingActionButton.class.getSimpleName(), "cannot recognize LayoutParams: " + params); } From 11e773a6c4211ab4964df4fc46d41c494e862825 Mon Sep 17 00:00:00 2001 From: rey5137 Date: Sat, 26 Mar 2016 22:54:12 +0700 Subject: [PATCH 10/16] Add OnCheckedChangeListener interface to CheckedTextView. --- dist/distInfo.gradle | 2 +- .../rey/material/widget/CheckedTextView.java | 30 +++++++++++++++++++ .../java/com/rey/material/widget/Switch.java | 2 +- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/dist/distInfo.gradle b/dist/distInfo.gradle index 48261ea9..e0b7ca70 100644 --- a/dist/distInfo.gradle +++ b/dist/distInfo.gradle @@ -16,7 +16,7 @@ ext { siteUrl = 'https://github.com/rey5137/material' gitUrl = 'https://github.com/rey5137/material.git' - libraryVersion = '1.2.2.5-SNAPSHOT' + libraryVersion = '1.2.2.6-SNAPSHOT' developerId = 'rey5137' developerName = 'Rey Pham' diff --git a/material/src/main/java/com/rey/material/widget/CheckedTextView.java b/material/src/main/java/com/rey/material/widget/CheckedTextView.java index ae5349f9..7ac3c82d 100644 --- a/material/src/main/java/com/rey/material/widget/CheckedTextView.java +++ b/material/src/main/java/com/rey/material/widget/CheckedTextView.java @@ -18,6 +18,20 @@ public class CheckedTextView extends android.widget.CheckedTextView implements T protected int mStyleId; protected int mCurrentStyle = ThemeManager.THEME_UNDEFINED; + /** + * Interface definition for a callback to be invoked when the checked state is changed. + */ + public interface OnCheckedChangeListener{ + /** + * Called when the checked state is changed. + * @param view The CheckedTextView view. + * @param checked The checked state. + */ + void onCheckedChanged(CheckedTextView view, boolean checked); + } + + private OnCheckedChangeListener mOnCheckedChangeListener; + public CheckedTextView(Context context) { super(context); @@ -59,6 +73,22 @@ protected void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, getRippleManager().onCreate(this, context, attrs, defStyleAttr, defStyleRes); } + /** + * Set a listener will be called when the checked state is changed. + * @param listener The {@link OnCheckedChangeListener} will be called. + */ + public void setOnCheckedChangeListener(OnCheckedChangeListener listener){ + mOnCheckedChangeListener = listener; + } + + @Override + public void setChecked(boolean checked) { + boolean change = isChecked() != checked; + super.setChecked(checked); + if(change && mOnCheckedChangeListener != null) + mOnCheckedChangeListener.onCheckedChanged(this, checked); + } + @Override public void setTextAppearance(int resId) { ViewUtil.applyTextAppearance(this, resId); diff --git a/material/src/main/java/com/rey/material/widget/Switch.java b/material/src/main/java/com/rey/material/widget/Switch.java index 94eeee31..7bacfea0 100644 --- a/material/src/main/java/com/rey/material/widget/Switch.java +++ b/material/src/main/java/com/rey/material/widget/Switch.java @@ -87,7 +87,7 @@ public interface OnCheckedChangeListener{ * @param view The Switch view. * @param checked The checked state. */ - public void onCheckedChanged(Switch view, boolean checked); + void onCheckedChanged(Switch view, boolean checked); } private OnCheckedChangeListener mOnCheckedChangeListener; From 3b7d40eb268d9ae99109a6a309db1aeb67810d09 Mon Sep 17 00:00:00 2001 From: rey5137 Date: Tue, 5 Apr 2016 10:58:07 +0700 Subject: [PATCH 11/16] - Extends from AppCompat view instead of Android view. --- app/build.gradle | 25 +++++++++++-------- .../com/rey/material/app/ContactEditText.java | 4 --- .../com/rey/material/demo/MainActivity.java | 23 ++++++++++------- app/src/main/res/menu/menu_main.xml | 12 ++++----- dist/distInfo.gradle | 10 ++++---- material/build.gradle | 2 +- .../com/rey/material/widget/CheckBox.java | 4 --- .../rey/material/widget/CheckedImageView.java | 4 --- .../rey/material/widget/CheckedTextView.java | 12 ++------- .../widget/CircleCheckedTextView.java | 10 ++------ .../rey/material/widget/CompoundButton.java | 7 ------ .../com/rey/material/widget/DatePicker.java | 6 ----- .../com/rey/material/widget/EditText.java | 13 +++++----- .../material/widget/FloatingActionButton.java | 7 ------ .../com/rey/material/widget/FrameLayout.java | 9 ------- .../com/rey/material/widget/ImageButton.java | 12 ++------- .../com/rey/material/widget/ImageView.java | 12 ++------- .../com/rey/material/widget/LinearLayout.java | 7 ------ .../com/rey/material/widget/ListView.java | 6 ----- .../com/rey/material/widget/ProgressView.java | 9 ------- .../com/rey/material/widget/RadioButton.java | 4 --- .../rey/material/widget/RelativeLayout.java | 9 ------- .../java/com/rey/material/widget/Slider.java | 9 ------- .../com/rey/material/widget/SnackBar.java | 4 --- .../java/com/rey/material/widget/Spinner.java | 4 --- .../java/com/rey/material/widget/Switch.java | 9 ------- .../rey/material/widget/TabPageIndicator.java | 7 ------ .../com/rey/material/widget/TextView.java | 12 ++------- .../com/rey/material/widget/TimePicker.java | 9 ------- .../com/rey/material/widget/YearPicker.java | 4 --- 30 files changed, 56 insertions(+), 209 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 6e7f9c1c..914e2f9e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,26 +12,29 @@ android { versionName "0.0.5" } - signingConfigs { - release { - storeFile file(MATERIAL_KEYSTORE_FILE) - storePassword MATERIAL_KEYSTORE_PASSWORD - keyAlias MATERIAL_KEYSTORE_ALIAS - keyPassword MATERIAL_KEYSTORE_PASSWORD - } - } - buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - signingConfig signingConfigs.release } } + + if(hasProperty('MATERIAL_KEYSTORE_FILE')) { + android.signingConfigs { + release { + storeFile file(MATERIAL_KEYSTORE_FILE) + storePassword MATERIAL_KEYSTORE_PASSWORD + keyAlias MATERIAL_KEYSTORE_ALIAS + keyPassword MATERIAL_KEYSTORE_PASSWORD + } + } + + android.buildTypes.release.signingConfig signingConfigs.release + } } ext{ - libSupportVersion = '23.1.1' + libSupportVersion = '23.2.1' } dependencies { diff --git a/app/src/main/java/com/rey/material/app/ContactEditText.java b/app/src/main/java/com/rey/material/app/ContactEditText.java index ef7bd764..405f8b94 100644 --- a/app/src/main/java/com/rey/material/app/ContactEditText.java +++ b/app/src/main/java/com/rey/material/app/ContactEditText.java @@ -90,10 +90,6 @@ public ContactEditText(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } - public ContactEditText(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - } - @Override protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){ mRecipientMap = new HashMap<>(); diff --git a/app/src/main/java/com/rey/material/demo/MainActivity.java b/app/src/main/java/com/rey/material/demo/MainActivity.java index 718c7def..2d9947c9 100644 --- a/app/src/main/java/com/rey/material/demo/MainActivity.java +++ b/app/src/main/java/com/rey/material/demo/MainActivity.java @@ -5,7 +5,6 @@ import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; -import android.support.v4.view.GravityCompat; import android.support.v4.view.ViewPager; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.AppCompatActivity; @@ -19,7 +18,6 @@ import android.widget.FrameLayout; import android.widget.ListView; import android.widget.TextView; -import android.widget.Toast; import com.rey.material.app.ThemeManager; import com.rey.material.app.ToolbarManager; @@ -67,10 +65,12 @@ protected void onCreate(Bundle savedInstanceState) { mToolbarManager.setNavigationManager(new ToolbarManager.ThemableNavigationManager(R.array.navigation_drawer, getSupportFragmentManager(), mToolbar, dl_navigator) { @Override public void onNavigationClick() { - if (mToolbarManager.getCurrentGroup() != R.id.tb_group_main) - mToolbarManager.setCurrentGroup(R.id.tb_group_main); - else - dl_navigator.openDrawer(GravityCompat.START); +// if (mToolbarManager.getCurrentGroup() != R.id.tb_group_main) +// mToolbarManager.setCurrentGroup(R.id.tb_group_main); +// else +// dl_navigator.openDrawer(GravityCompat.START); + + mToolbarManager.setNavigationVisisble(false, true); } @Override @@ -140,9 +140,14 @@ public boolean onOptionsItemSelected(MenuItem item) { mToolbarManager.setCurrentGroup(R.id.tb_group_main); break; case R.id.tb_theme: - int theme = (ThemeManager.getInstance().getCurrentTheme() + 1) % ThemeManager.getInstance().getThemeCount(); - ThemeManager.getInstance().setCurrentTheme(theme); - Toast.makeText(this, "Current theme: " + theme, Toast.LENGTH_SHORT).show(); + if(mToolbarManager.isNavigationVisisble()) + mToolbarManager.setNavigationVisisble(false, true); + else + mToolbarManager.setNavigationVisisble(true, true); + +// int theme = (ThemeManager.getInstance().getCurrentTheme() + 1) % ThemeManager.getInstance().getThemeCount(); +// ThemeManager.getInstance().setCurrentTheme(theme); +// Toast.makeText(this, "Current theme: " + theme, Toast.LENGTH_SHORT).show(); break; } return true; diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml index 6a2e2181..8629ae69 100644 --- a/app/src/main/res/menu/menu_main.xml +++ b/app/src/main/res/menu/menu_main.xml @@ -12,12 +12,6 @@ android:icon="@drawable/ic_autorenew_white_24dp" android:title="Switch group"/> - - + + diff --git a/dist/distInfo.gradle b/dist/distInfo.gradle index e0b7ca70..b8605c31 100644 --- a/dist/distInfo.gradle +++ b/dist/distInfo.gradle @@ -1,7 +1,7 @@ ext { - bintrayUser = BINTRAY_USERNAME - bintrayApiKey = BINTRAY_APIKEY - bintrayGpgPassword = GPG_PASSWORD + bintrayUser = hasProperty('BINTRAY_USERNAME') ? BINTRAY_USERNAME : "" + bintrayApiKey = hasProperty('BINTRAY_APIKEY') ? BINTRAY_APIKEY : "" + bintrayGpgPassword = hasProperty('GPG_PASSWORD') ? GPG_PASSWORD : "" bintrayRepo = 'maven' bintrayName = 'material' @@ -16,7 +16,7 @@ ext { siteUrl = 'https://github.com/rey5137/material' gitUrl = 'https://github.com/rey5137/material.git' - libraryVersion = '1.2.2.6-SNAPSHOT' + libraryVersion = '1.2.2.7-SNAPSHOT' developerId = 'rey5137' developerName = 'Rey Pham' @@ -26,4 +26,4 @@ ext { licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt' licenseDist = 'repo' allLicenses = ["Apache-2.0"] -} \ No newline at end of file +} diff --git a/material/build.gradle b/material/build.gradle index 848013b6..1d9e06eb 100644 --- a/material/build.gradle +++ b/material/build.gradle @@ -19,7 +19,7 @@ android { } ext{ - libSupportVersion = '23.1.1' + libSupportVersion = '23.2.1' } dependencies { diff --git a/material/src/main/java/com/rey/material/widget/CheckBox.java b/material/src/main/java/com/rey/material/widget/CheckBox.java index a3679b22..e448d976 100644 --- a/material/src/main/java/com/rey/material/widget/CheckBox.java +++ b/material/src/main/java/com/rey/material/widget/CheckBox.java @@ -19,10 +19,6 @@ public CheckBox(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } - public CheckBox(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - } - @Override protected void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){ super.applyStyle(context, attrs, defStyleAttr, defStyleRes); diff --git a/material/src/main/java/com/rey/material/widget/CheckedImageView.java b/material/src/main/java/com/rey/material/widget/CheckedImageView.java index 1e277209..2e8095ab 100644 --- a/material/src/main/java/com/rey/material/widget/CheckedImageView.java +++ b/material/src/main/java/com/rey/material/widget/CheckedImageView.java @@ -27,10 +27,6 @@ public CheckedImageView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } - public CheckedImageView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - } - @Override public void setChecked(boolean b) { if(mChecked != b){ diff --git a/material/src/main/java/com/rey/material/widget/CheckedTextView.java b/material/src/main/java/com/rey/material/widget/CheckedTextView.java index 7ac3c82d..1bf60fce 100644 --- a/material/src/main/java/com/rey/material/widget/CheckedTextView.java +++ b/material/src/main/java/com/rey/material/widget/CheckedTextView.java @@ -1,10 +1,9 @@ package com.rey.material.widget; -import android.annotation.TargetApi; import android.content.Context; import android.graphics.drawable.Drawable; -import android.os.Build; import android.support.annotation.NonNull; +import android.support.v7.widget.AppCompatCheckedTextView; import android.util.AttributeSet; import android.view.MotionEvent; @@ -12,7 +11,7 @@ import com.rey.material.drawable.RippleDrawable; import com.rey.material.util.ViewUtil; -public class CheckedTextView extends android.widget.CheckedTextView implements ThemeManager.OnThemeChangedListener { +public class CheckedTextView extends AppCompatCheckedTextView implements ThemeManager.OnThemeChangedListener { private RippleManager mRippleManager; protected int mStyleId; @@ -50,13 +49,6 @@ public CheckedTextView(Context context, AttributeSet attrs, int defStyleAttr) { init(context, attrs, defStyleAttr, 0); } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public CheckedTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - - init(context, attrs, defStyleAttr, defStyleRes); - } - protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){ ViewUtil.applyFont(this, attrs, defStyleAttr, defStyleRes); applyStyle(context, attrs, defStyleAttr, defStyleRes); diff --git a/material/src/main/java/com/rey/material/widget/CircleCheckedTextView.java b/material/src/main/java/com/rey/material/widget/CircleCheckedTextView.java index d1561b12..47ed1cb4 100644 --- a/material/src/main/java/com/rey/material/widget/CircleCheckedTextView.java +++ b/material/src/main/java/com/rey/material/widget/CircleCheckedTextView.java @@ -3,6 +3,7 @@ import android.annotation.TargetApi; import android.content.Context; import android.os.Build; +import android.support.v7.widget.AppCompatCheckedTextView; import android.util.AttributeSet; import android.view.Gravity; import android.view.animation.Interpolator; @@ -13,7 +14,7 @@ /** * Created by Rey on 2/5/2015. */ -public class CircleCheckedTextView extends android.widget.CheckedTextView { +public class CircleCheckedTextView extends AppCompatCheckedTextView { private CircleDrawable mBackground; @@ -41,13 +42,6 @@ public CircleCheckedTextView(Context context, AttributeSet attrs, int defStyleAt init(context, attrs, defStyleAttr, 0); } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public CircleCheckedTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - - init(context, attrs, defStyleAttr, defStyleRes); - } - protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){ setGravity(Gravity.CENTER); setPadding(0, 0, 0, 0); diff --git a/material/src/main/java/com/rey/material/widget/CompoundButton.java b/material/src/main/java/com/rey/material/widget/CompoundButton.java index c8a497a5..ebb5a7db 100644 --- a/material/src/main/java/com/rey/material/widget/CompoundButton.java +++ b/material/src/main/java/com/rey/material/widget/CompoundButton.java @@ -41,13 +41,6 @@ public CompoundButton(Context context, AttributeSet attrs, int defStyleAttr) { init(context, attrs, defStyleAttr, 0); } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public CompoundButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - - init(context, attrs, defStyleAttr, defStyleRes); - } - protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) applyPadding(context, attrs, defStyleAttr, defStyleRes); diff --git a/material/src/main/java/com/rey/material/widget/DatePicker.java b/material/src/main/java/com/rey/material/widget/DatePicker.java index 1d37aef3..efdf63fc 100644 --- a/material/src/main/java/com/rey/material/widget/DatePicker.java +++ b/material/src/main/java/com/rey/material/widget/DatePicker.java @@ -122,12 +122,6 @@ public DatePicker(Context context, AttributeSet attrs, int defStyleAttr) { init(context, attrs, defStyleAttr, 0); } - public DatePicker(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - - init(context, attrs, defStyleAttr, defStyleRes); - } - @Override protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){ mTypeface = Typeface.DEFAULT; diff --git a/material/src/main/java/com/rey/material/widget/EditText.java b/material/src/main/java/com/rey/material/widget/EditText.java index 0f332fcb..8872bafc 100644 --- a/material/src/main/java/com/rey/material/widget/EditText.java +++ b/material/src/main/java/com/rey/material/widget/EditText.java @@ -12,6 +12,9 @@ import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.view.GravityCompat; +import android.support.v7.widget.AppCompatAutoCompleteTextView; +import android.support.v7.widget.AppCompatEditText; +import android.support.v7.widget.AppCompatMultiAutoCompleteTextView; import android.text.Editable; import android.text.InputFilter; import android.text.Layout; @@ -124,10 +127,6 @@ public EditText(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } - public EditText(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - } - @SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override @@ -3689,7 +3688,7 @@ protected int[] onCreateDrawableState(int extraSpace) { } - private class InternalEditText extends android.widget.EditText{ + private class InternalEditText extends AppCompatEditText{ public InternalEditText(Context context) { super(context); @@ -3816,7 +3815,7 @@ void superOnSelectionChanged(int selStart, int selEnd) { } } - private class InternalAutoCompleteTextView extends AutoCompleteTextView{ + private class InternalAutoCompleteTextView extends AppCompatAutoCompleteTextView { public InternalAutoCompleteTextView(Context context) { super(context); @@ -3988,7 +3987,7 @@ void superOnSelectionChanged(int selStart, int selEnd) { } } - private class InternalMultiAutoCompleteTextView extends MultiAutoCompleteTextView{ + private class InternalMultiAutoCompleteTextView extends AppCompatMultiAutoCompleteTextView{ public InternalMultiAutoCompleteTextView(Context context) { super(context); diff --git a/material/src/main/java/com/rey/material/widget/FloatingActionButton.java b/material/src/main/java/com/rey/material/widget/FloatingActionButton.java index 289dfb1b..ed9e7342 100644 --- a/material/src/main/java/com/rey/material/widget/FloatingActionButton.java +++ b/material/src/main/java/com/rey/material/widget/FloatingActionButton.java @@ -67,13 +67,6 @@ public FloatingActionButton(Context context, AttributeSet attrs, int defStyleAtt init(context, attrs, defStyleAttr, 0); } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public FloatingActionButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - - init(context, attrs, defStyleAttr, defStyleRes); - } - protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { setClickable(true); mSwitchIconAnimator = new SwitchIconAnimator(); diff --git a/material/src/main/java/com/rey/material/widget/FrameLayout.java b/material/src/main/java/com/rey/material/widget/FrameLayout.java index 37df212b..cd7b0f49 100644 --- a/material/src/main/java/com/rey/material/widget/FrameLayout.java +++ b/material/src/main/java/com/rey/material/widget/FrameLayout.java @@ -1,9 +1,7 @@ package com.rey.material.widget; -import android.annotation.TargetApi; import android.content.Context; import android.graphics.drawable.Drawable; -import android.os.Build; import android.support.annotation.NonNull; import android.util.AttributeSet; import android.view.MotionEvent; @@ -37,13 +35,6 @@ public FrameLayout(Context context, AttributeSet attrs, int defStyleAttr) { init(context, attrs, defStyleAttr, 0); } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public FrameLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - - init(context, attrs, defStyleAttr, defStyleRes); - } - protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){ applyStyle(context, attrs, defStyleAttr, defStyleRes); if(!isInEditMode()) diff --git a/material/src/main/java/com/rey/material/widget/ImageButton.java b/material/src/main/java/com/rey/material/widget/ImageButton.java index a53ea048..f286ae96 100644 --- a/material/src/main/java/com/rey/material/widget/ImageButton.java +++ b/material/src/main/java/com/rey/material/widget/ImageButton.java @@ -1,10 +1,9 @@ package com.rey.material.widget; -import android.annotation.TargetApi; import android.content.Context; import android.graphics.drawable.Drawable; -import android.os.Build; import android.support.annotation.NonNull; +import android.support.v7.widget.AppCompatImageButton; import android.util.AttributeSet; import android.view.MotionEvent; @@ -12,7 +11,7 @@ import com.rey.material.drawable.RippleDrawable; import com.rey.material.util.ViewUtil; -public class ImageButton extends android.widget.ImageButton implements ThemeManager.OnThemeChangedListener{ +public class ImageButton extends AppCompatImageButton implements ThemeManager.OnThemeChangedListener{ private RippleManager mRippleManager; protected int mStyleId; @@ -36,13 +35,6 @@ public ImageButton(Context context, AttributeSet attrs, int defStyleAttr) { init(context, attrs, defStyleAttr, 0); } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public ImageButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - - init(context, attrs, defStyleAttr, defStyleRes); - } - protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){ applyStyle(context, attrs, defStyleAttr, defStyleRes); if(!isInEditMode()) diff --git a/material/src/main/java/com/rey/material/widget/ImageView.java b/material/src/main/java/com/rey/material/widget/ImageView.java index 4d42558b..38b36430 100644 --- a/material/src/main/java/com/rey/material/widget/ImageView.java +++ b/material/src/main/java/com/rey/material/widget/ImageView.java @@ -1,10 +1,9 @@ package com.rey.material.widget; -import android.annotation.TargetApi; import android.content.Context; import android.graphics.drawable.Drawable; -import android.os.Build; import android.support.annotation.NonNull; +import android.support.v7.widget.AppCompatImageView; import android.util.AttributeSet; import android.view.MotionEvent; @@ -15,7 +14,7 @@ /** * Created by Rey on 9/16/2015. */ -public class ImageView extends android.widget.ImageView implements ThemeManager.OnThemeChangedListener { +public class ImageView extends AppCompatImageView implements ThemeManager.OnThemeChangedListener { private RippleManager mRippleManager; protected int mStyleId; @@ -39,13 +38,6 @@ public ImageView(Context context, AttributeSet attrs, int defStyleAttr) { init(context, attrs, defStyleAttr, 0); } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public ImageView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - - init(context, attrs, defStyleAttr, defStyleRes); - } - protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){ applyStyle(context, attrs, defStyleAttr, defStyleRes); if(!isInEditMode()) diff --git a/material/src/main/java/com/rey/material/widget/LinearLayout.java b/material/src/main/java/com/rey/material/widget/LinearLayout.java index f207c792..e01e7806 100644 --- a/material/src/main/java/com/rey/material/widget/LinearLayout.java +++ b/material/src/main/java/com/rey/material/widget/LinearLayout.java @@ -38,13 +38,6 @@ public LinearLayout(Context context, AttributeSet attrs, int defStyleAttr) { init(context, attrs, defStyleAttr, 0); } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public LinearLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - - init(context, attrs, defStyleAttr, defStyleRes); - } - protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){ applyStyle(context, attrs, defStyleAttr, defStyleRes); if(!isInEditMode()) diff --git a/material/src/main/java/com/rey/material/widget/ListView.java b/material/src/main/java/com/rey/material/widget/ListView.java index e11196c8..b70ddba4 100644 --- a/material/src/main/java/com/rey/material/widget/ListView.java +++ b/material/src/main/java/com/rey/material/widget/ListView.java @@ -33,12 +33,6 @@ public ListView(Context context, AttributeSet attrs, int defStyleAttr) { init(context, attrs, defStyleAttr, 0); } - public ListView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr); - - init(context, attrs, defStyleAttr, defStyleRes); - } - protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){ super.setRecyclerListener(new RecyclerListener() { diff --git a/material/src/main/java/com/rey/material/widget/ProgressView.java b/material/src/main/java/com/rey/material/widget/ProgressView.java index 79720d3d..10bdf2ff 100644 --- a/material/src/main/java/com/rey/material/widget/ProgressView.java +++ b/material/src/main/java/com/rey/material/widget/ProgressView.java @@ -1,11 +1,9 @@ package com.rey.material.widget; -import android.annotation.TargetApi; import android.content.Context; import android.content.res.TypedArray; import android.graphics.drawable.Animatable; import android.graphics.drawable.Drawable; -import android.os.Build; import android.support.annotation.NonNull; import android.util.AttributeSet; import android.view.View; @@ -51,13 +49,6 @@ public ProgressView(Context context, AttributeSet attrs, int defStyleAttr){ init(context, attrs, defStyleAttr, 0); } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public ProgressView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - - init(context, attrs, defStyleAttr, defStyleRes); - } - protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){ applyStyle(context, attrs, defStyleAttr, defStyleRes); if(!isInEditMode()) diff --git a/material/src/main/java/com/rey/material/widget/RadioButton.java b/material/src/main/java/com/rey/material/widget/RadioButton.java index d40c88e5..92f7d32c 100644 --- a/material/src/main/java/com/rey/material/widget/RadioButton.java +++ b/material/src/main/java/com/rey/material/widget/RadioButton.java @@ -19,10 +19,6 @@ public RadioButton(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } - public RadioButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - } - @Override protected void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){ super.applyStyle(context, attrs, defStyleAttr, defStyleRes); diff --git a/material/src/main/java/com/rey/material/widget/RelativeLayout.java b/material/src/main/java/com/rey/material/widget/RelativeLayout.java index fb70aec8..f1528859 100644 --- a/material/src/main/java/com/rey/material/widget/RelativeLayout.java +++ b/material/src/main/java/com/rey/material/widget/RelativeLayout.java @@ -1,9 +1,7 @@ package com.rey.material.widget; -import android.annotation.TargetApi; import android.content.Context; import android.graphics.drawable.Drawable; -import android.os.Build; import android.support.annotation.NonNull; import android.util.AttributeSet; import android.view.MotionEvent; @@ -37,13 +35,6 @@ public RelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) { init(context, attrs, defStyleAttr, 0); } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public RelativeLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - - init(context, attrs, defStyleAttr, defStyleRes); - } - protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){ applyStyle(context, attrs, defStyleAttr, defStyleRes); if(!isInEditMode()) diff --git a/material/src/main/java/com/rey/material/widget/Slider.java b/material/src/main/java/com/rey/material/widget/Slider.java index 93588597..cbc58010 100644 --- a/material/src/main/java/com/rey/material/widget/Slider.java +++ b/material/src/main/java/com/rey/material/widget/Slider.java @@ -1,6 +1,5 @@ package com.rey.material.widget; -import android.annotation.TargetApi; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; @@ -11,7 +10,6 @@ import android.graphics.RectF; import android.graphics.Typeface; import android.graphics.drawable.Drawable; -import android.os.Build; import android.os.Parcel; import android.os.Parcelable; import android.os.SystemClock; @@ -133,13 +131,6 @@ public Slider(Context context, AttributeSet attrs, int defStyleAttr) { init(context, attrs, defStyleAttr, 0); } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public Slider(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - - init(context, attrs, defStyleAttr, defStyleRes); - } - protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){ mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); diff --git a/material/src/main/java/com/rey/material/widget/SnackBar.java b/material/src/main/java/com/rey/material/widget/SnackBar.java index 63292136..1c199850 100644 --- a/material/src/main/java/com/rey/material/widget/SnackBar.java +++ b/material/src/main/java/com/rey/material/widget/SnackBar.java @@ -127,10 +127,6 @@ public SnackBar(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } - public SnackBar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - } - @Override protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){ mWidth = MATCH_PARENT; diff --git a/material/src/main/java/com/rey/material/widget/Spinner.java b/material/src/main/java/com/rey/material/widget/Spinner.java index 815d2b74..46688b88 100644 --- a/material/src/main/java/com/rey/material/widget/Spinner.java +++ b/material/src/main/java/com/rey/material/widget/Spinner.java @@ -118,10 +118,6 @@ public Spinner(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } - public Spinner(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - } - @Override protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { mLabelEnable = false; diff --git a/material/src/main/java/com/rey/material/widget/Switch.java b/material/src/main/java/com/rey/material/widget/Switch.java index 7bacfea0..80d1add7 100644 --- a/material/src/main/java/com/rey/material/widget/Switch.java +++ b/material/src/main/java/com/rey/material/widget/Switch.java @@ -1,6 +1,5 @@ package com.rey.material.widget; -import android.annotation.TargetApi; import android.content.Context; import android.content.res.ColorStateList; import android.content.res.TypedArray; @@ -11,7 +10,6 @@ import android.graphics.RectF; import android.graphics.Shader; import android.graphics.drawable.Drawable; -import android.os.Build; import android.os.Parcel; import android.os.Parcelable; import android.os.SystemClock; @@ -110,13 +108,6 @@ public Switch(Context context, AttributeSet attrs, int defStyleAttr) { init(context, attrs, defStyleAttr, 0); } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public Switch(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - - init(context, attrs, defStyleAttr, defStyleRes); - } - protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){ mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); diff --git a/material/src/main/java/com/rey/material/widget/TabPageIndicator.java b/material/src/main/java/com/rey/material/widget/TabPageIndicator.java index 9b8a4761..9a448fe3 100644 --- a/material/src/main/java/com/rey/material/widget/TabPageIndicator.java +++ b/material/src/main/java/com/rey/material/widget/TabPageIndicator.java @@ -92,13 +92,6 @@ public TabPageIndicator(Context context, AttributeSet attrs, int defStyleAttr) { init(context, attrs, defStyleAttr, 0); } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public TabPageIndicator(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - - init(context, attrs, defStyleAttr, defStyleRes); - } - protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){ setHorizontalScrollBarEnabled(false); diff --git a/material/src/main/java/com/rey/material/widget/TextView.java b/material/src/main/java/com/rey/material/widget/TextView.java index b973a58e..d372113f 100644 --- a/material/src/main/java/com/rey/material/widget/TextView.java +++ b/material/src/main/java/com/rey/material/widget/TextView.java @@ -1,10 +1,9 @@ package com.rey.material.widget; -import android.annotation.TargetApi; import android.content.Context; import android.graphics.drawable.Drawable; -import android.os.Build; import android.support.annotation.NonNull; +import android.support.v7.widget.AppCompatTextView; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; @@ -13,7 +12,7 @@ import com.rey.material.drawable.RippleDrawable; import com.rey.material.util.ViewUtil; -public class TextView extends android.widget.TextView implements ThemeManager.OnThemeChangedListener{ +public class TextView extends AppCompatTextView implements ThemeManager.OnThemeChangedListener{ private RippleManager mRippleManager; protected int mStyleId; @@ -43,13 +42,6 @@ public TextView(Context context, AttributeSet attrs, int defStyleAttr) { init(context, attrs, defStyleAttr, 0); } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public TextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - - init(context, attrs, defStyleAttr, defStyleRes); - } - protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){ ViewUtil.applyFont(this, attrs, defStyleAttr, defStyleRes); applyStyle(context, attrs, defStyleAttr, defStyleRes); diff --git a/material/src/main/java/com/rey/material/widget/TimePicker.java b/material/src/main/java/com/rey/material/widget/TimePicker.java index fb861c1c..f4b80e04 100644 --- a/material/src/main/java/com/rey/material/widget/TimePicker.java +++ b/material/src/main/java/com/rey/material/widget/TimePicker.java @@ -1,6 +1,5 @@ package com.rey.material.widget; -import android.annotation.TargetApi; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; @@ -8,7 +7,6 @@ import android.graphics.PointF; import android.graphics.Rect; import android.graphics.Typeface; -import android.os.Build; import android.os.Parcel; import android.os.Parcelable; import android.os.SystemClock; @@ -120,13 +118,6 @@ public TimePicker(Context context, AttributeSet attrs, int defStyleAttr) { init(context, attrs, defStyleAttr, 0); } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public TimePicker(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - - init(context, attrs, defStyleAttr, defStyleRes); - } - protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){ mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mRect = new Rect(); diff --git a/material/src/main/java/com/rey/material/widget/YearPicker.java b/material/src/main/java/com/rey/material/widget/YearPicker.java index c783b4e8..164410ef 100644 --- a/material/src/main/java/com/rey/material/widget/YearPicker.java +++ b/material/src/main/java/com/rey/material/widget/YearPicker.java @@ -86,10 +86,6 @@ public YearPicker(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } - public YearPicker(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - } - @Override protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){ mTextSize = -1; From 6e7019ee2ef438da69f47120a8c969d80e01e6eb Mon Sep 17 00:00:00 2001 From: rey5137 Date: Fri, 15 Apr 2016 00:10:40 +0700 Subject: [PATCH 12/16] Spinner: measure view properly. --- dist/distInfo.gradle | 2 +- .../java/com/rey/material/widget/Spinner.java | 57 ++++++++++--------- 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/dist/distInfo.gradle b/dist/distInfo.gradle index b8605c31..773bea20 100644 --- a/dist/distInfo.gradle +++ b/dist/distInfo.gradle @@ -16,7 +16,7 @@ ext { siteUrl = 'https://github.com/rey5137/material' gitUrl = 'https://github.com/rey5137/material.git' - libraryVersion = '1.2.2.7-SNAPSHOT' + libraryVersion = '1.2.2.8-SNAPSHOT' developerId = 'rey5137' developerName = 'Rey Pham' diff --git a/material/src/main/java/com/rey/material/widget/Spinner.java b/material/src/main/java/com/rey/material/widget/Spinner.java index 46688b88..197df228 100644 --- a/material/src/main/java/com/rey/material/widget/Spinner.java +++ b/material/src/main/java/com/rey/material/widget/Spinner.java @@ -643,7 +643,31 @@ private int getArrowDrawableWidth(){ private int getDividerDrawableHeight(){ return mDividerHeight > 0 ? mDividerHeight + mDividerPadding : 0; } - + + private int getSpec(int availableSize, int size){ + int spec; + switch (size){ + case ViewGroup.LayoutParams.WRAP_CONTENT: + if(availableSize > 0) + spec = MeasureSpec.makeMeasureSpec(availableSize, MeasureSpec.AT_MOST); + else + spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); + break; + case ViewGroup.LayoutParams.MATCH_PARENT: + if(availableSize > 0) + spec = MeasureSpec.makeMeasureSpec(availableSize, MeasureSpec.EXACTLY); + else + spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); + break; + default: + spec = MeasureSpec.makeMeasureSpec(size, MeasureSpec.EXACTLY); + break; + } + + return spec; + } + + @SuppressWarnings("Range") @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int widthMode = MeasureSpec.getMode(widthMeasureSpec); @@ -657,7 +681,10 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int labelWidth = 0; int labelHeight = 0; if(mLabelView != null && mLabelView.getLayoutParams() != null){ - mLabelView.measure(MeasureSpec.makeMeasureSpec(widthSize - paddingHorizontal, widthMode), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); + int size = widthMode == MeasureSpec.UNSPECIFIED ? 0 : (widthSize - paddingHorizontal); + int ws = MeasureSpec.makeMeasureSpec(size, widthMode); + int hs = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); + mLabelView.measure(ws, hs); labelWidth = mLabelView.getMeasuredWidth(); labelHeight = mLabelView.getMeasuredHeight(); } @@ -667,31 +694,9 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { View v = getSelectedView(); if(v != null){ - int ws; - int hs; ViewGroup.LayoutParams params = v.getLayoutParams(); - switch (params.width){ - case ViewGroup.LayoutParams.WRAP_CONTENT: - ws = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); - break; - case ViewGroup.LayoutParams.MATCH_PARENT: - ws = MeasureSpec.makeMeasureSpec(widthSize - paddingHorizontal, widthMode); - break; - default: - ws = MeasureSpec.makeMeasureSpec(params.width, MeasureSpec.EXACTLY); - break; - } - switch (params.height){ - case ViewGroup.LayoutParams.WRAP_CONTENT: - hs = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); - break; - case ViewGroup.LayoutParams.MATCH_PARENT: - hs = MeasureSpec.makeMeasureSpec(heightSize - paddingVertical - labelHeight, heightMode); - break; - default: - hs = MeasureSpec.makeMeasureSpec(params.height, MeasureSpec.EXACTLY); - break; - } + int ws = getSpec(widthSize - paddingHorizontal, params.width); + int hs = getSpec(heightSize - paddingVertical - mLabelView.getMeasuredHeight(), params.height); v.measure(ws, hs); width = v.getMeasuredWidth(); From 24a7967e846bc5a1cbdccc7908aa0aa4b4677175 Mon Sep 17 00:00:00 2001 From: rey5137 Date: Mon, 30 May 2016 23:06:08 +0700 Subject: [PATCH 13/16] Add sl_thumbTouchRadius attribute. --- .../src/main/java/com/rey/material/widget/Slider.java | 9 ++++++--- material/src/main/res/values/attrs.xml | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/material/src/main/java/com/rey/material/widget/Slider.java b/material/src/main/java/com/rey/material/widget/Slider.java index cbc58010..187bcf98 100644 --- a/material/src/main/java/com/rey/material/widget/Slider.java +++ b/material/src/main/java/com/rey/material/widget/Slider.java @@ -60,6 +60,7 @@ public class Slider extends View implements ThemeManager.OnThemeChangedListener{ private int mThumbBorderSize = -1; private int mThumbRadius = -1; private int mThumbFocusRadius = -1; + private int mThumbTouchRadius = -1; private float mThumbPosition = -1; private Typeface mTypeface = Typeface.DEFAULT; private int mTextSize = -1; @@ -100,14 +101,14 @@ public interface OnPositionChangeListener{ * @param oldValue The old value. * @param newValue The new value. */ - public void onPositionChanged(Slider view, boolean fromUser, float oldPos, float newPos, int oldValue, int newValue); + void onPositionChanged(Slider view, boolean fromUser, float oldPos, float newPos, int oldValue, int newValue); } private OnPositionChangeListener mOnPositionChangeListener; public interface ValueDescriptionProvider{ - public String getDescription(int value); + String getDescription(int value); } @@ -198,6 +199,8 @@ else if(attr == R.styleable.Slider_sl_thumbRadius) mThumbRadius = a.getDimensionPixelSize(attr, 0); else if(attr == R.styleable.Slider_sl_thumbFocusRadius) mThumbFocusRadius = a.getDimensionPixelSize(attr, 0); + else if(attr == R.styleable.Slider_sl_thumbTouchRadius) + mThumbTouchRadius = a.getDimensionPixelSize(attr, 0); else if(attr == R.styleable.Slider_sl_travelAnimDuration) { mTravelAnimationDuration = a.getInteger(attr, 0); mTransformAnimationDuration = mTravelAnimationDuration; @@ -692,7 +695,7 @@ public boolean onTouchEvent(@NonNull MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: - mIsDragging = isThumbHit(x, y, mThumbRadius) && !mThumbMoveAnimator.isRunning(); + mIsDragging = isThumbHit(x, y, mThumbTouchRadius > 0 ? mThumbTouchRadius : mThumbRadius) && !mThumbMoveAnimator.isRunning(); mMemoPoint.set(x, y); if(mIsDragging) { mThumbRadiusAnimator.startAnimation(mDiscreteMode ? 0 : mThumbFocusRadius); diff --git a/material/src/main/res/values/attrs.xml b/material/src/main/res/values/attrs.xml index a750f8c7..5f52f1e9 100644 --- a/material/src/main/res/values/attrs.xml +++ b/material/src/main/res/values/attrs.xml @@ -307,6 +307,7 @@ + From 4d360a3f03ee14b1741c884146f75383338b4e00 Mon Sep 17 00:00:00 2001 From: rey5137 Date: Mon, 30 May 2016 23:06:38 +0700 Subject: [PATCH 14/16] Update gradle. --- .idea/gradle.xml | 7 +++++++ .idea/vcs.xml | 12 ++++++++++++ build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 ++-- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 701563c5..4d302ff4 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -13,6 +13,13 @@ + diff --git a/.idea/vcs.xml b/.idea/vcs.xml index fce7f719..31d8df57 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -3,5 +3,17 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 408ae8ff..5736609b 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:1.5.0' + classpath 'com.android.tools.build:gradle:2.1.0' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4' // NOTE: Do not place your application dependencies here; they belong diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 3921c7df..d4e59346 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Nov 30 10:42:23 ICT 2015 +#Mon May 30 22:30:34 ICT 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip From 121bee7809a0ac0e2194e3c04e581625207b1a09 Mon Sep 17 00:00:00 2001 From: rey5137 Date: Tue, 31 May 2016 11:20:27 +0700 Subject: [PATCH 15/16] Add rd_delayRipple attribute. --- .../rey/material/drawable/RippleDrawable.java | 42 +++++++++++++++---- material/src/main/res/values/attrs.xml | 1 + 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/material/src/main/java/com/rey/material/drawable/RippleDrawable.java b/material/src/main/java/com/rey/material/drawable/RippleDrawable.java index df144455..b884758d 100644 --- a/material/src/main/java/com/rey/material/drawable/RippleDrawable.java +++ b/material/src/main/java/com/rey/material/drawable/RippleDrawable.java @@ -19,6 +19,7 @@ import android.graphics.drawable.Drawable; import android.os.SystemClock; import android.util.AttributeSet; +import android.util.Log; import android.util.TypedValue; import android.view.MotionEvent; import android.view.View; @@ -65,7 +66,10 @@ public class RippleDrawable extends Drawable implements Animatable, OnTouchListe private Interpolator mOutInterpolator; private long mStartTime; - + + private long mTouchTime; + private int mDelayRippleTime; + private int mState = STATE_OUT; public static final int DELAY_CLICK_NONE = 0; @@ -85,13 +89,14 @@ public class RippleDrawable extends Drawable implements Animatable, OnTouchListe private static final float[] GRADIENT_STOPS = new float[]{0f, 0.99f, 1f}; private static final float GRADIENT_RADIUS = 16; - private RippleDrawable(Drawable backgroundDrawable, int backgroundAnimDuration, int backgroundColor, int rippleType, int delayClickType, int maxRippleRadius, int rippleAnimDuration, int rippleColor, Interpolator inInterpolator, Interpolator outInterpolator, int type, int topLeftCornerRadius, int topRightCornerRadius, int bottomRightCornerRadius, int bottomLeftCornerRadius, int left, int top, int right, int bottom){ + private RippleDrawable(Drawable backgroundDrawable, int backgroundAnimDuration, int backgroundColor, int rippleType, int delayClickType, int delayRippleTime, int maxRippleRadius, int rippleAnimDuration, int rippleColor, Interpolator inInterpolator, Interpolator outInterpolator, int type, int topLeftCornerRadius, int topRightCornerRadius, int bottomRightCornerRadius, int bottomLeftCornerRadius, int left, int top, int right, int bottom){ setBackgroundDrawable(backgroundDrawable); mBackgroundAnimDuration = backgroundAnimDuration; mBackgroundColor = backgroundColor; mRippleType = rippleType; setDelayClickType(delayClickType); + mDelayRippleTime = delayRippleTime; mMaxRippleRadius = maxRippleRadius; mRippleAnimDuration = rippleAnimDuration; mRippleColor = rippleColor; @@ -311,11 +316,17 @@ public boolean onTouch(View v, MotionEvent event) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_MOVE: if(mState == STATE_OUT || mState == STATE_RELEASE){ - if(mRippleType == TYPE_WAVE || mRippleType == TYPE_TOUCH_MATCH_VIEW) - mMaxRippleRadius = getMaxRippleRadius(event.getX(), event.getY()); - + long time = SystemClock.uptimeMillis(); + if(mTouchTime == 0) + mTouchTime = time; + setRippleEffect(event.getX(), event.getY(), 0); - setRippleState(STATE_PRESS); + + if(mTouchTime <= time - mDelayRippleTime) { + if (mRippleType == TYPE_WAVE || mRippleType == TYPE_TOUCH_MATCH_VIEW) + mMaxRippleRadius = getMaxRippleRadius(event.getX(), event.getY()); + setRippleState(STATE_PRESS); + } } else if(mRippleType == TYPE_TOUCH){ if(setRippleEffect(event.getX(), event.getY(), mRippleRadius)) @@ -323,7 +334,13 @@ else if(mRippleType == TYPE_TOUCH){ } break; case MotionEvent.ACTION_UP: - case MotionEvent.ACTION_CANCEL: + if(mTouchTime > 0 && mState == STATE_OUT) { + if (mRippleType == TYPE_WAVE || mRippleType == TYPE_TOUCH_MATCH_VIEW) + mMaxRippleRadius = getMaxRippleRadius(event.getX(), event.getY()); + setRippleState(STATE_PRESS); + } + case MotionEvent.ACTION_CANCEL: + mTouchTime = 0; if(mState != STATE_OUT){ if(mState == STATE_HOVER){ if(mRippleType == TYPE_WAVE || mRippleType == TYPE_TOUCH_MATCH_VIEW) @@ -430,7 +447,7 @@ private void updateTouch(){ private void updateWave(){ float progress = Math.min(1f, (float)(SystemClock.uptimeMillis() - mStartTime) / mRippleAnimDuration); - + if(mState != STATE_RELEASE){ setRippleEffect(mRipplePoint.x, mRipplePoint.y, mMaxRippleRadius * mInInterpolator.getInterpolation(progress)); @@ -504,6 +521,7 @@ public static class Builder{ private int mRippleAnimDuration = 400; private int mRippleColor; private int mDelayClickType; + private int mDelayRippleTime; private Interpolator mInInterpolator; private Interpolator mOutInterpolator; @@ -532,6 +550,7 @@ public Builder(Context context, AttributeSet attrs, int defStyleAttr, int defSty backgroundAnimDuration(a.getInteger(R.styleable.RippleDrawable_rd_backgroundAnimDuration, context.getResources().getInteger(android.R.integer.config_mediumAnimTime))); rippleType(a.getInteger(R.styleable.RippleDrawable_rd_rippleType, RippleDrawable.TYPE_TOUCH)); delayClickType(a.getInteger(R.styleable.RippleDrawable_rd_delayClick, RippleDrawable.DELAY_CLICK_NONE)); + delayRippleTime(a.getInteger(R.styleable.RippleDrawable_rd_delayRipple, 0)); type = ThemeUtil.getType(a, R.styleable.RippleDrawable_rd_maxRippleRadius); if(type >= TypedValue.TYPE_FIRST_INT && type <= TypedValue.TYPE_LAST_INT) maxRippleRadius(a.getInteger(R.styleable.RippleDrawable_rd_maxRippleRadius, -1)); @@ -565,7 +584,7 @@ public RippleDrawable build(){ if(mOutInterpolator == null) mOutInterpolator = new DecelerateInterpolator(); - return new RippleDrawable(mBackgroundDrawable, mBackgroundAnimDuration, mBackgroundColor, mRippleType, mDelayClickType, mMaxRippleRadius, mRippleAnimDuration, mRippleColor, mInInterpolator, mOutInterpolator, mMaskType, mMaskTopLeftCornerRadius, mMaskTopRightCornerRadius, mMaskBottomRightCornerRadius, mMaskBottomLeftCornerRadius, mMaskLeft, mMaskTop, mMaskRight, mMaskBottom); + return new RippleDrawable(mBackgroundDrawable, mBackgroundAnimDuration, mBackgroundColor, mRippleType, mDelayClickType, mDelayRippleTime, mMaxRippleRadius, mRippleAnimDuration, mRippleColor, mInInterpolator, mOutInterpolator, mMaskType, mMaskTopLeftCornerRadius, mMaskTopRightCornerRadius, mMaskBottomRightCornerRadius, mMaskBottomLeftCornerRadius, mMaskLeft, mMaskTop, mMaskRight, mMaskBottom); } public Builder backgroundDrawable(Drawable drawable){ @@ -593,6 +612,11 @@ public Builder delayClickType(int type){ return this; } + public Builder delayRippleTime(int time){ + mDelayRippleTime = time; + return this; + } + public Builder maxRippleRadius(int radius){ mMaxRippleRadius = radius; return this; diff --git a/material/src/main/res/values/attrs.xml b/material/src/main/res/values/attrs.xml index 5f52f1e9..daa0ec2b 100644 --- a/material/src/main/res/values/attrs.xml +++ b/material/src/main/res/values/attrs.xml @@ -225,6 +225,7 @@ + From acdf5698d575e587b07ef53e32af6e53d1e351eb Mon Sep 17 00:00:00 2001 From: rey5137 Date: Wed, 1 Jun 2016 00:39:03 +0700 Subject: [PATCH 16/16] Release 1.2.3 --- app/build.gradle | 4 ++-- dist/bintray.gradle | 1 + dist/distInfo.gradle | 13 +++++++++---- dist/maven.gradle | 27 +++++---------------------- material/build.gradle | 13 ++++++------- 5 files changed, 23 insertions(+), 35 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 914e2f9e..2a659c99 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.android.application' android { compileSdkVersion 23 - buildToolsVersion "21.1.2" + buildToolsVersion "23.0.3" defaultConfig { applicationId "com.rey.material.demo" @@ -34,7 +34,7 @@ android { } ext{ - libSupportVersion = '23.2.1' + libSupportVersion = '23.4.0' } dependencies { diff --git a/dist/bintray.gradle b/dist/bintray.gradle index 715105be..c333caed 100644 --- a/dist/bintray.gradle +++ b/dist/bintray.gradle @@ -1,5 +1,6 @@ apply plugin: 'com.github.dcendents.android-maven' apply plugin: 'com.jfrog.bintray' +apply from: "$rootProject.projectDir/dist/distInfo.gradle" group = publishedGroupId // Maven Group ID for the artifact diff --git a/dist/distInfo.gradle b/dist/distInfo.gradle index 773bea20..391d387a 100644 --- a/dist/distInfo.gradle +++ b/dist/distInfo.gradle @@ -1,7 +1,12 @@ ext { - bintrayUser = hasProperty('BINTRAY_USERNAME') ? BINTRAY_USERNAME : "" - bintrayApiKey = hasProperty('BINTRAY_APIKEY') ? BINTRAY_APIKEY : "" - bintrayGpgPassword = hasProperty('GPG_PASSWORD') ? GPG_PASSWORD : "" + bintrayUser = project.hasProperty('BINTRAY_USERNAME') ? BINTRAY_USERNAME : "" + bintrayApiKey = project.hasProperty('BINTRAY_APIKEY') ? BINTRAY_APIKEY : "" + bintrayGpgPassword = project.hasProperty('GPG_PASSWORD') ? GPG_PASSWORD : "" + + mavenUser = project.hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : "" + mavenPassword = project.hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : "" + mavenReleaseRepo = project.hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL : "https://oss.sonatype.org/service/local/staging/deploy/maven2/" + mavenSnapshotRepo = project.hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL : "https://oss.sonatype.org/content/repositories/snapshots/" bintrayRepo = 'maven' bintrayName = 'material' @@ -16,7 +21,7 @@ ext { siteUrl = 'https://github.com/rey5137/material' gitUrl = 'https://github.com/rey5137/material.git' - libraryVersion = '1.2.2.8-SNAPSHOT' + libraryVersion = '1.2.3' developerId = 'rey5137' developerName = 'Rey Pham' diff --git a/dist/maven.gradle b/dist/maven.gradle index 97c34b6c..9930a156 100644 --- a/dist/maven.gradle +++ b/dist/maven.gradle @@ -16,29 +16,12 @@ apply plugin: 'maven' apply plugin: 'signing' +apply from: "$rootProject.projectDir/dist/distInfo.gradle" def isReleaseBuild() { return libraryVersion.contains("SNAPSHOT") == false } -def getReleaseRepositoryUrl() { - return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL - : "https://oss.sonatype.org/service/local/staging/deploy/maven2/" -} - -def getSnapshotRepositoryUrl() { - return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL - : "https://oss.sonatype.org/content/repositories/snapshots/" -} - -def getRepositoryUsername() { - return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : "" -} - -def getRepositoryPassword() { - return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : "" -} - afterEvaluate { project -> uploadArchives { repositories { @@ -49,11 +32,11 @@ afterEvaluate { project -> pom.artifactId = artifact pom.version = libraryVersion - repository(url: getReleaseRepositoryUrl()) { - authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) + repository(url: mavenReleaseRepo) { + authentication(userName: mavenUser, password: mavenPassword) } - snapshotRepository(url: getSnapshotRepositoryUrl()) { - authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) + snapshotRepository(url: mavenSnapshotRepo) { + authentication(userName: mavenUser, password: mavenPassword) } pom.project { diff --git a/material/build.gradle b/material/build.gradle index 1d9e06eb..1eea2ea3 100644 --- a/material/build.gradle +++ b/material/build.gradle @@ -2,13 +2,13 @@ apply plugin: 'com.android.library' android { compileSdkVersion 23 - buildToolsVersion "23.0.2" + buildToolsVersion "23.0.3" defaultConfig { minSdkVersion 9 targetSdkVersion 23 versionCode 21 - versionName "1.2.2" + versionName "1.2.3" } buildTypes { release { @@ -18,8 +18,11 @@ android { } } +apply from: "$rootProject.projectDir/dist/bintray.gradle" +apply from: "$rootProject.projectDir/dist/maven.gradle" + ext{ - libSupportVersion = '23.2.1' + libSupportVersion = '23.4.0' } dependencies { @@ -29,7 +32,3 @@ dependencies { compile "com.android.support:cardview-v7:${libSupportVersion}" compile "com.android.support:recyclerview-v7:${libSupportVersion}" } - -apply from: '../dist/distInfo.gradle' -apply from: '../dist/bintray.gradle' -apply from: '../dist/maven.gradle'