From 89474345ca454926d153d63da3e711321069461f Mon Sep 17 00:00:00 2001 From: Rey Pham Date: Fri, 3 Apr 2015 01:15:44 +0700 Subject: [PATCH 1/7] Fix empty Dialog on 5.0 due to pass 0 as theme parameter in super constructor call. Fix bug stop animation in TImePicker class. --- lib/src/main/java/com/rey/material/app/Dialog.java | 1 + lib/src/main/java/com/rey/material/widget/TimePicker.java | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/src/main/java/com/rey/material/app/Dialog.java b/lib/src/main/java/com/rey/material/app/Dialog.java index b8910acf..f6ab940d 100644 --- a/lib/src/main/java/com/rey/material/app/Dialog.java +++ b/lib/src/main/java/com/rey/material/app/Dialog.java @@ -83,6 +83,7 @@ public Dialog(Context context) { this(context, 0); } + public Dialog(Context context, int style) { super(context, style); diff --git a/lib/src/main/java/com/rey/material/widget/TimePicker.java b/lib/src/main/java/com/rey/material/widget/TimePicker.java index e0ce2b01..659e6521 100644 --- a/lib/src/main/java/com/rey/material/widget/TimePicker.java +++ b/lib/src/main/java/com/rey/material/widget/TimePicker.java @@ -110,6 +110,7 @@ private void init(Context context, AttributeSet attrs, int defStyleAttr, int def mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mRect = new Rect(); + setWillNotDraw(false); applyStyle(context, attrs, defStyleAttr, defStyleRes); } @@ -657,7 +658,8 @@ private void update(){ if(mRunning) { if(getHandler() != null) getHandler().postAtTime(mUpdater, SystemClock.uptimeMillis() + ViewUtil.FRAME_DURATION); - stopAnimation(); + else + stopAnimation(); } invalidate(); From 80e256ac9bff559f71029cf1cee1e7d5d8692295 Mon Sep 17 00:00:00 2001 From: Rey Pham Date: Fri, 3 Apr 2015 10:41:47 +0700 Subject: [PATCH 2/7] Add OnPositionChangeListener interface for Slider class. Add OnCheckedChangeListener interface for Switch class. Fix bug input field invisible when set android:visible=gone for EditText class. --- .../com/rey/material/demo/SliderFragment.java | 23 ++++++ app/src/main/res/layout/fragment_slider.xml | 16 ++++ .../com/rey/material/widget/EditText.java | 1 + .../java/com/rey/material/widget/Slider.java | 76 +++++++++++++------ .../java/com/rey/material/widget/Switch.java | 18 ++++- 5 files changed, 107 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/com/rey/material/demo/SliderFragment.java b/app/src/main/java/com/rey/material/demo/SliderFragment.java index 93a0256f..c9abe2ef 100644 --- a/app/src/main/java/com/rey/material/demo/SliderFragment.java +++ b/app/src/main/java/com/rey/material/demo/SliderFragment.java @@ -4,12 +4,15 @@ import android.os.Build; import android.os.Bundle; import android.support.v4.app.Fragment; +import android.transition.Slide; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.CompoundButton; +import android.widget.TextView; import com.rey.material.widget.RadioButton; +import com.rey.material.widget.Slider; public class SliderFragment extends Fragment{ @@ -25,6 +28,26 @@ public static SliderFragment newInstance(){ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_slider, container, false); + Slider sl_continuous = (Slider)v.findViewById(R.id.slider_sl_continuous); + final TextView tv_continuous = (TextView)v.findViewById(R.id.slider_tv_continuous); + tv_continuous.setText(String.format("pos=%.1f value=%d", sl_continuous.getPosition(), sl_continuous.getValue())); + sl_continuous.setOnPositionChangeListener(new Slider.OnPositionChangeListener() { + @Override + public void onPositionChanged(Slider view, float oldPos, float newPos, int oldValue, int newValue) { + tv_continuous.setText(String.format("pos=%.1f value=%d", newPos, newValue)); + } + }); + + Slider sl_discrete = (Slider)v.findViewById(R.id.slider_sl_discrete); + final TextView tv_discrete = (TextView)v.findViewById(R.id.slider_tv_discrete); + tv_discrete.setText(String.format("pos=%.1f value=%d", sl_discrete.getPosition(), sl_discrete.getValue())); + sl_discrete.setOnPositionChangeListener(new Slider.OnPositionChangeListener() { + @Override + public void onPositionChanged(Slider view, float oldPos, float newPos, int oldValue, int newValue) { + tv_discrete.setText(String.format("pos=%.1f value=%d", newPos, newValue)); + } + }); + return v; } diff --git a/app/src/main/res/layout/fragment_slider.xml b/app/src/main/res/layout/fragment_slider.xml index 47555ccf..675b1a40 100644 --- a/app/src/main/res/layout/fragment_slider.xml +++ b/app/src/main/res/layout/fragment_slider.xml @@ -31,6 +31,14 @@ android:padding="16dp" app:sl_value="50"/> + + + + Date: Fri, 3 Apr 2015 13:12:56 +0700 Subject: [PATCH 3/7] Add default style for all Dialog and ProgressView. Fix bug check progressId > 0 instead of progressId !- 0 in ProgressView class. Re-layout YearPicker view to center in DatePickerDialog class. Fix bug dismiss Dialog when activity destroyed. --- .../com/rey/material/demo/ButtonFragment.java | 2 + .../rey/material/demo/DialogsFragment.java | 50 ++++++++-------- .../rey/material/app/DatePickerDialog.java | 57 +++++++++++++------ .../java/com/rey/material/app/Dialog.java | 24 ++++++-- .../com/rey/material/app/SimpleDialog.java | 45 +++++++++++++-- .../rey/material/app/TimePickerDialog.java | 20 +++++-- .../com/rey/material/widget/ProgressView.java | 23 ++++---- 7 files changed, 150 insertions(+), 71 deletions(-) diff --git a/app/src/main/java/com/rey/material/demo/ButtonFragment.java b/app/src/main/java/com/rey/material/demo/ButtonFragment.java index 6de9f773..3ae47d72 100644 --- a/app/src/main/java/com/rey/material/demo/ButtonFragment.java +++ b/app/src/main/java/com/rey/material/demo/ButtonFragment.java @@ -1,6 +1,8 @@ package com.rey.material.demo; import android.annotation.TargetApi; +import android.app.AlertDialog; +import android.content.DialogInterface; import android.os.Build; import android.os.Bundle; import android.support.v4.app.Fragment; diff --git a/app/src/main/java/com/rey/material/demo/DialogsFragment.java b/app/src/main/java/com/rey/material/demo/DialogsFragment.java index 8575c1c7..5c8de021 100644 --- a/app/src/main/java/com/rey/material/demo/DialogsFragment.java +++ b/app/src/main/java/com/rey/material/demo/DialogsFragment.java @@ -77,13 +77,13 @@ public void onClick(View v) { @Override public void onPositiveActionClicked(DialogFragment fragment) { Toast.makeText(fragment.getDialog().getContext(), "Discarded", Toast.LENGTH_SHORT).show(); - fragment.dismiss(); + super.onPositiveActionClicked(fragment); } @Override public void onNegativeActionClicked(DialogFragment fragment) { Toast.makeText(fragment.getDialog().getContext(), "Canceled", Toast.LENGTH_SHORT).show(); - fragment.dismiss(); + super.onNegativeActionClicked(fragment); } }; @@ -96,13 +96,13 @@ public void onNegativeActionClicked(DialogFragment fragment) { @Override public void onPositiveActionClicked(DialogFragment fragment) { Toast.makeText(fragment.getDialog().getContext(), "Deleted", Toast.LENGTH_SHORT).show(); - fragment.dismiss(); + super.onPositiveActionClicked(fragment); } @Override public void onNegativeActionClicked(DialogFragment fragment) { Toast.makeText(fragment.getDialog().getContext(), "Cancelled", Toast.LENGTH_SHORT).show(); - fragment.dismiss(); + super.onNegativeActionClicked(fragment); } }; @@ -115,13 +115,13 @@ public void onNegativeActionClicked(DialogFragment fragment) { @Override public void onPositiveActionClicked(DialogFragment fragment) { Toast.makeText(fragment.getDialog().getContext(), "Agreed", Toast.LENGTH_SHORT).show(); - fragment.dismiss(); + super.onPositiveActionClicked(fragment); } @Override public void onNegativeActionClicked(DialogFragment fragment) { Toast.makeText(fragment.getDialog().getContext(), "Disagreed", Toast.LENGTH_SHORT).show(); - fragment.dismiss(); + super.onNegativeActionClicked(fragment); } }; @@ -143,13 +143,13 @@ protected Dialog onBuild(Context context, int styleId) { @Override public void onPositiveActionClicked(DialogFragment fragment) { Toast.makeText(fragment.getDialog().getContext(), "Connected", Toast.LENGTH_SHORT).show(); - fragment.dismiss(); + super.onPositiveActionClicked(fragment); } @Override public void onNegativeActionClicked(DialogFragment fragment) { Toast.makeText(fragment.getDialog().getContext(), "Cancelled", Toast.LENGTH_SHORT).show(); - fragment.dismiss(); + super.onNegativeActionClicked(fragment); } }; @@ -162,15 +162,14 @@ public void onNegativeActionClicked(DialogFragment fragment) { builder = new SimpleDialog.Builder(R.style.SimpleDialogLight){ @Override public void onPositiveActionClicked(DialogFragment fragment) { - SimpleDialog dialog = (SimpleDialog)fragment.getDialog(); - Toast.makeText(fragment.getDialog().getContext(), "You have selected " + dialog.getSelectedValue() + " as phone ringtone.", Toast.LENGTH_SHORT).show(); - fragment.dismiss(); + Toast.makeText(fragment.getDialog().getContext(), "You have selected " + getSelectedValue() + " as phone ringtone.", Toast.LENGTH_SHORT).show(); + super.onPositiveActionClicked(fragment); } @Override public void onNegativeActionClicked(DialogFragment fragment) { Toast.makeText(fragment.getDialog().getContext(), "Cancelled" , Toast.LENGTH_SHORT).show(); - fragment.dismiss(); + super.onNegativeActionClicked(fragment); } }; @@ -183,8 +182,7 @@ public void onNegativeActionClicked(DialogFragment fragment) { builder = new SimpleDialog.Builder(R.style.SimpleDialog){ @Override public void onPositiveActionClicked(DialogFragment fragment) { - SimpleDialog dialog = (SimpleDialog)fragment.getDialog(); - CharSequence[] values = dialog.getSelectedValues(); + CharSequence[] values = getSelectedValues(); if(values == null) Toast.makeText(fragment.getDialog().getContext(), "You have selected nothing.", Toast.LENGTH_SHORT).show(); else{ @@ -194,13 +192,13 @@ public void onPositiveActionClicked(DialogFragment fragment) { sb.append(values[i]).append(i == values.length - 1? "." : ", "); Toast.makeText(fragment.getDialog().getContext(), sb.toString(), Toast.LENGTH_SHORT).show(); } - fragment.dismiss(); + super.onPositiveActionClicked(fragment); } @Override public void onNegativeActionClicked(DialogFragment fragment) { Toast.makeText(fragment.getDialog().getContext(), "Cancelled" , Toast.LENGTH_SHORT).show(); - fragment.dismiss(); + super.onNegativeActionClicked(fragment); } }; @@ -210,18 +208,18 @@ public void onNegativeActionClicked(DialogFragment fragment) { .negativeAction("CANCEL"); break; case R.id.dialog_bt_time_light: - builder = new TimePickerDialog.Builder(R.style.Material_App_Dialog_TimePicker_Light, 6, 00){ + builder = new TimePickerDialog.Builder(6, 00){ @Override public void onPositiveActionClicked(DialogFragment fragment) { TimePickerDialog dialog = (TimePickerDialog)fragment.getDialog(); Toast.makeText(fragment.getDialog().getContext(), "Time is " + dialog.getFormattedTime(SimpleDateFormat.getTimeInstance()), Toast.LENGTH_SHORT).show(); - fragment.dismiss(); + super.onPositiveActionClicked(fragment); } @Override public void onNegativeActionClicked(DialogFragment fragment) { Toast.makeText(fragment.getDialog().getContext(), "Cancelled" , Toast.LENGTH_SHORT).show(); - fragment.dismiss(); + super.onNegativeActionClicked(fragment); } }; @@ -229,19 +227,19 @@ public void onNegativeActionClicked(DialogFragment fragment) { .negativeAction("CANCEL"); break; case R.id.dialog_bt_date_light: - builder = new DatePickerDialog.Builder(R.style.Material_App_Dialog_DatePicker_Light){ + builder = new DatePickerDialog.Builder(){ @Override public void onPositiveActionClicked(DialogFragment fragment) { DatePickerDialog dialog = (DatePickerDialog)fragment.getDialog(); String date = dialog.getFormattedDate(SimpleDateFormat.getDateInstance()); Toast.makeText(fragment.getDialog().getContext(), "Date is " + date, Toast.LENGTH_SHORT).show(); - fragment.dismiss(); + super.onPositiveActionClicked(fragment); } @Override public void onNegativeActionClicked(DialogFragment fragment) { Toast.makeText(fragment.getDialog().getContext(), "Cancelled" , Toast.LENGTH_SHORT).show(); - fragment.dismiss(); + super.onNegativeActionClicked(fragment); } }; @@ -254,13 +252,13 @@ public void onNegativeActionClicked(DialogFragment fragment) { public void onPositiveActionClicked(DialogFragment fragment) { TimePickerDialog dialog = (TimePickerDialog)fragment.getDialog(); Toast.makeText(fragment.getDialog().getContext(), "Time is " + dialog.getFormattedTime(SimpleDateFormat.getTimeInstance()), Toast.LENGTH_SHORT).show(); - fragment.dismiss(); + super.onPositiveActionClicked(fragment); } @Override public void onNegativeActionClicked(DialogFragment fragment) { Toast.makeText(fragment.getDialog().getContext(), "Cancelled" , Toast.LENGTH_SHORT).show(); - fragment.dismiss(); + super.onNegativeActionClicked(fragment); } }; @@ -274,13 +272,13 @@ public void onPositiveActionClicked(DialogFragment fragment) { DatePickerDialog dialog = (DatePickerDialog)fragment.getDialog(); String date = dialog.getFormattedDate(SimpleDateFormat.getDateInstance()); Toast.makeText(fragment.getDialog().getContext(), "Date is " + date, Toast.LENGTH_SHORT).show(); - fragment.dismiss(); + super.onPositiveActionClicked(fragment); } @Override public void onNegativeActionClicked(DialogFragment fragment) { Toast.makeText(fragment.getDialog().getContext(), "Cancelled" , Toast.LENGTH_SHORT).show(); - fragment.dismiss(); + super.onNegativeActionClicked(fragment); } }; diff --git a/lib/src/main/java/com/rey/material/app/DatePickerDialog.java b/lib/src/main/java/com/rey/material/app/DatePickerDialog.java index 876ebf2b..04e415e4 100644 --- a/lib/src/main/java/com/rey/material/app/DatePickerDialog.java +++ b/lib/src/main/java/com/rey/material/app/DatePickerDialog.java @@ -8,6 +8,7 @@ import android.graphics.Path; import android.graphics.Rect; import android.graphics.RectF; +import android.graphics.drawable.ColorDrawable; import android.os.Parcel; import android.os.Parcelable; import android.view.MotionEvent; @@ -42,7 +43,7 @@ public interface OnDateChangedListener{ private OnDateChangedListener mOnDateChangedListener; public DatePickerDialog(Context context) { - super(context); + super(context, R.style.Material_App_Dialog_DatePicker_Light); } public DatePickerDialog(Context context, int style) { @@ -397,9 +398,10 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { else{ int height = Math.max(heightSize - mHeaderSecondaryHeight - mHeaderPrimaryHeight, mDatePicker.getMeasuredHeight()); int ws = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY); - int hs = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); - mDatePicker.measure(ws, hs); - mYearPicker.measure(ws, hs); + mDatePicker.measure(ws, MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)); + mYearPicker.measure(ws, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); + if(mYearPicker.getMeasuredHeight() != height) + mYearPicker.measure(ws, MeasureSpec.makeMeasureSpec(Math.min(mYearPicker.getMeasuredHeight(), height), MeasureSpec.EXACTLY)); } setMeasuredDimension(widthSize, heightSize); @@ -414,9 +416,10 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { else{ int height = Math.max(heightSize, mDatePicker.getMeasuredHeight()); int ws = MeasureSpec.makeMeasureSpec(widthSize / 2, MeasureSpec.EXACTLY); - int hs = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); - mDatePicker.measure(ws, hs); - mYearPicker.measure(ws, hs); + mDatePicker.measure(ws, MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)); + mYearPicker.measure(ws, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); + if(mYearPicker.getMeasuredHeight() != height) + mYearPicker.measure(ws, MeasureSpec.makeMeasureSpec(Math.min(mYearPicker.getMeasuredHeight(), height), MeasureSpec.EXACTLY)); } setMeasuredDimension(widthSize, heightSize); @@ -479,7 +482,9 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto childLeft += mHeaderRealWidth; mDatePicker.layout(childLeft, childTop, childRight, childBottom); - mYearPicker.layout(childLeft, childTop, childRight, childBottom); + + childTop = (childBottom + childTop - mYearPicker.getMeasuredHeight()) / 2; + mYearPicker.layout(childLeft, childTop, childRight, childTop + mYearPicker.getMeasuredHeight()); } private void measureHeaderText(){ @@ -610,20 +615,20 @@ public boolean onTouchEvent(MotionEvent event) { public static class Builder extends Dialog.Builder implements OnDateChangedListener { - private int mMinDay; - private int mMinMonth; - private int mMinYear; - private int mMaxDay; - private int mMaxMonth; - private int mMaxYear; - private int mDay; - private int mMonth; - private int mYear; + protected int mMinDay; + protected int mMinMonth; + protected int mMinYear; + protected int mMaxDay; + protected int mMaxMonth; + protected int mMaxYear; + protected int mDay; + protected int mMonth; + protected int mYear; private Calendar mCalendar; public Builder(){ - this(0); + this(R.style.Material_App_Dialog_DatePicker_Light); } public Builder(int styleId){ @@ -640,6 +645,10 @@ public Builder(int styleId){ mMaxYear = mYear + 12; } + public Builder(int minDay, int minMonth, int minYear, int maxDay, int maxMonth, int maxYear, int day, int month, int year){ + this(R.style.Material_App_Dialog_DatePicker_Light, minDay, minMonth, minYear, maxDay, maxMonth, maxYear, day, month, year); + } + public Builder(int styleId, int minDay, int minMonth, int minYear, int maxDay, int maxMonth, int maxYear, int day, int month, int year){ super(styleId); mMinDay = minDay; @@ -698,6 +707,18 @@ public Builder date(long time) { return date(day, month, year); } + public int getDay(){ + return mDay; + } + + public int getMonth(){ + return mMonth; + } + + public int getYear(){ + return mYear; + } + @Override public Dialog.Builder contentView(int layoutId) { return this; diff --git a/lib/src/main/java/com/rey/material/app/Dialog.java b/lib/src/main/java/com/rey/material/app/Dialog.java index f6ab940d..4c9af514 100644 --- a/lib/src/main/java/com/rey/material/app/Dialog.java +++ b/lib/src/main/java/com/rey/material/app/Dialog.java @@ -65,7 +65,11 @@ public class Dialog extends android.app.Dialog{ private final Handler mHandler = new Handler(); private final Runnable mDismissAction = new Runnable() { public void run() { - Dialog.super.dismiss(); + //dirty fix for java.lang.IllegalArgumentException: View not attached to window manager + try { + Dialog.super.dismiss(); + } + catch(IllegalArgumentException ex){} } }; @@ -80,7 +84,7 @@ public void run() { public static final int ACTION_NEUTRAL = ViewUtil.generateViewId(); public Dialog(Context context) { - this(context, 0); + this(context, R.style.Material_App_Dialog_Light); } @@ -958,7 +962,9 @@ public static class Builder implements DialogFragment.Builder, Parcelable{ protected Dialog mDialog; - public Builder(){} + public Builder(){ + this(R.style.Material_App_Dialog_Light); + } public Builder(int styleId){ mStyleId = styleId; @@ -995,13 +1001,19 @@ public Builder neutralAction(CharSequence action){ } @Override - public void onPositiveActionClicked(DialogFragment fragment) {} + public void onPositiveActionClicked(DialogFragment fragment) { + fragment.dismiss(); + } @Override - public void onNegativeActionClicked(DialogFragment fragment) {} + public void onNegativeActionClicked(DialogFragment fragment) { + fragment.dismiss(); + } @Override - public void onNeutralActionClicked(DialogFragment fragment) {} + public void onNeutralActionClicked(DialogFragment fragment) { + fragment.dismiss(); + } @Override public Dialog build(Context context) { diff --git a/lib/src/main/java/com/rey/material/app/SimpleDialog.java b/lib/src/main/java/com/rey/material/app/SimpleDialog.java index e380450c..68787928 100644 --- a/lib/src/main/java/com/rey/material/app/SimpleDialog.java +++ b/lib/src/main/java/com/rey/material/app/SimpleDialog.java @@ -54,7 +54,7 @@ public interface OnSelectionChangedListener{ private OnSelectionChangedListener mOnSelectionChangedListener; public SimpleDialog(Context context) { - super(context); + super(context, R.style.Material_App_Dialog_Simple_Light); } public SimpleDialog(Context context, int style) { @@ -453,12 +453,14 @@ public void onCheckedChanged(android.widget.CompoundButton v, boolean isChecked) public static class Builder extends Dialog.Builder implements OnSelectionChangedListener { - private int mMode; - private CharSequence mMessage; - private CharSequence[] mItems; - private int[] mSelectedIndexes; + protected int mMode; + protected CharSequence mMessage; + protected CharSequence[] mItems; + protected int[] mSelectedIndexes; - public Builder(){} + public Builder(){ + super(R.style.Material_App_Dialog_Simple_Light); + } public Builder(int styleId){ super(styleId); @@ -484,6 +486,37 @@ public Builder multiChoiceItems(CharSequence[] items, int... selectedIndexes){ return this; } + public int getSelectedIndex(){ + if(mMode == MODE_ITEMS || mMode == MODE_MULTI_ITEMS) + return mSelectedIndexes[0]; + + return -1; + } + + public CharSequence getSelectedValue(){ + int index = getSelectedIndex(); + return index >= 0 ? mItems[index] : null; + } + + public int[] getSelectedIndexes(){ + if(mMode == MODE_ITEMS || mMode == MODE_MULTI_ITEMS) + return mSelectedIndexes; + + return null; + } + + public CharSequence[] getSelectedValues(){ + int[] indexes = getSelectedIndexes(); + if(indexes == null || indexes.length == 0) + return null; + + CharSequence[] result = new CharSequence[indexes.length]; + for(int i = 0; i < indexes.length; i++) + result[i] = mItems[indexes[i]]; + + return result; + } + @Override protected Dialog onBuild(Context context, int styleId) { SimpleDialog dialog = new SimpleDialog(context, styleId); diff --git a/lib/src/main/java/com/rey/material/app/TimePickerDialog.java b/lib/src/main/java/com/rey/material/app/TimePickerDialog.java index e88904f9..1ab6a019 100644 --- a/lib/src/main/java/com/rey/material/app/TimePickerDialog.java +++ b/lib/src/main/java/com/rey/material/app/TimePickerDialog.java @@ -41,7 +41,7 @@ public interface OnTimeChangedListener{ } public TimePickerDialog(Context context) { - super(context); + super(context, R.style.Material_App_Dialog_TimePicker_Light); } public TimePickerDialog(Context context, int style) { @@ -550,16 +550,20 @@ public boolean onTouchEvent(MotionEvent event) { public static class Builder extends Dialog.Builder implements OnTimeChangedListener { - private int mHour; - private int mMinute; + protected int mHour; + protected int mMinute; public Builder(){ - super(); + super(R.style.Material_App_Dialog_TimePicker_Light); Calendar cal = Calendar.getInstance(); mHour = cal.get(Calendar.HOUR_OF_DAY); mMinute = cal.get(Calendar.MINUTE); } + public Builder(int hourOfDay, int minute){ + this(R.style.Material_App_Dialog_TimePicker_Light, hourOfDay, minute); + } + public Builder(int styleId, int hourOfDay, int minute){ super(styleId); hour(hourOfDay); @@ -576,6 +580,14 @@ public Builder minute(int minute){ return this; } + public int getHour(){ + return mHour; + } + + public int getMinute(){ + return mMinute; + } + @Override public Dialog.Builder contentView(int layoutId) { return this; diff --git a/lib/src/main/java/com/rey/material/widget/ProgressView.java b/lib/src/main/java/com/rey/material/widget/ProgressView.java index 311fe1bf..f8b8a63c 100644 --- a/lib/src/main/java/com/rey/material/widget/ProgressView.java +++ b/lib/src/main/java/com/rey/material/widget/ProgressView.java @@ -63,17 +63,18 @@ private void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, i a.recycle(); - if(mProgressId > 0){ - if(mCircular) - mProgressDrawable = new CircularProgressDrawable.Builder(context, mProgressId).build(); - else - mProgressDrawable = new LinearProgressDrawable.Builder(context, mProgressId).build(); - - if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) - setBackground(mProgressDrawable); - else - setBackgroundDrawable(mProgressDrawable); - } + if(mProgressId == 0) + mProgressId = mCircular ? R.style.Material_Drawable_CircularProgress : R.style.Material_Drawable_LinearProgress; + + if(mCircular) + mProgressDrawable = new CircularProgressDrawable.Builder(context, mProgressId).build(); + else + mProgressDrawable = new LinearProgressDrawable.Builder(context, mProgressId).build(); + + if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) + setBackground(mProgressDrawable); + else + setBackgroundDrawable(mProgressDrawable); } @Override From f25a7d65ad8a08880c28abdf011e8e0da3dea8a8 Mon Sep 17 00:00:00 2001 From: Rey Pham Date: Mon, 6 Apr 2015 17:07:47 +0700 Subject: [PATCH 4/7] Change delayClick attribute to rd_delayClick. Remove ripple attribute, add rd_enable and rd_style attribute. Make ToolbarRippleDrawable support match_view enum of rd_maxRippleRadius --- app/build.gradle | 2 +- app/src/main/res/layout/dialog_recurring.xml | 14 ++-- app/src/main/res/layout/fragment_button.xml | 32 ++++---- app/src/main/res/layout/fragment_dialog.xml | 40 +++++----- app/src/main/res/layout/fragment_snackbar.xml | 16 ++-- app/src/main/res/layout/fragment_spinner.xml | 10 ++- .../main/res/layout/rd_item_dropdown_end.xml | 4 +- .../main/res/layout/rd_item_dropdown_mode.xml | 4 +- app/src/main/res/layout/row_spn.xml | 4 +- app/src/main/res/layout/row_spn_dropdown.xml | 4 +- app/src/main/res/values/styles.xml | 78 +++++++++---------- lib/lib.iml | 3 - .../rey/material/drawable/RippleDrawable.java | 57 +++++++++----- .../drawable/ToolbarRippleDrawable.java | 45 ++++++++--- .../material/widget/FloatingActionButton.java | 27 ++----- .../rey/material/widget/RippleManager.java | 39 +++++++--- lib/src/main/res/values/attrs.xml | 22 +++--- lib/src/main/res/values/styles.xml | 14 ++-- 18 files changed, 231 insertions(+), 184 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index d6b94325..cf22cec9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -34,6 +34,6 @@ dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:21.0.2' compile 'com.android.support:cardview-v7:21.0.2' - compile project(':lib') compile 'com.squareup.picasso:picasso:2.5.0' + compile project(':lib') } diff --git a/app/src/main/res/layout/dialog_recurring.xml b/app/src/main/res/layout/dialog_recurring.xml index 279f1e5b..e5212c08 100644 --- a/app/src/main/res/layout/dialog_recurring.xml +++ b/app/src/main/res/layout/dialog_recurring.xml @@ -24,8 +24,9 @@ app:spn_label="@string/rd_repeat" app:spn_arrowColor="#FFFFFFFF" app:spn_dividerHeight="0dp" - app:ripple="@style/Material.Drawable.Ripple.Wave" - app:delayClick="true" + app:rd_style="@style/Material.Drawable.Ripple.Wave" + app:rd_enable="true" + app:rd_delayClick="true" android:layout_gravity="center_vertical"/> @@ -127,8 +128,9 @@ android:layout_height="wrap_content" android:layout_centerVertical="true" android:padding="8dp" - app:ripple="@style/Material.Drawable.Ripple.Wave.Light" - app:delayClick="true"/> + app:rd_style="@style/Material.Drawable.Ripple.Wave.Light" + app:rd_enable="true" + app:rd_delayClick="true"/> diff --git a/app/src/main/res/layout/fragment_button.xml b/app/src/main/res/layout/fragment_button.xml index a00c17de..003bbb26 100644 --- a/app/src/main/res/layout/fragment_button.xml +++ b/app/src/main/res/layout/fragment_button.xml @@ -37,8 +37,8 @@ android:textColor="#FF000000" android:textAppearance="@style/Base.TextAppearance.AppCompat.Button" android:text="BUTTON" - app:ripple="@style/FlatButtonRippleStyle" - app:delayClick="false"/> + style="@style/FlatButtonRippleStyle" + app:rd_delayClick="false"/> + style="@style/FlatColorButtonRippleStyle" + app:rd_delayClick="true"/> @@ -74,8 +74,8 @@ android:textColor="#FF000000" android:textAppearance="@style/Base.TextAppearance.AppCompat.Button" android:text="BUTTON" - app:ripple="@style/FlatWaveButtonRippleStyle" - app:delayClick="false"/> + style="@style/FlatWaveButtonRippleStyle" + app:rd_delayClick="false"/> + style="@style/FlatWaveColorButtonRippleStyle" + app:rd_delayClick="true"/> @@ -119,8 +119,8 @@ android:textColor="#FF000000" android:textAppearance="@style/Base.TextAppearance.AppCompat.Button" android:text="BUTTON" - app:ripple="@style/RaiseButtonRippleStyle" - app:delayClick="false"/> + style="@style/RaiseButtonRippleStyle" + app:rd_delayClick="false"/> + style="@style/RaiseColorButtonRippleStyle" + app:rd_delayClick="true"/> @@ -156,8 +156,8 @@ android:textColor="#FF000000" android:textAppearance="@style/Base.TextAppearance.AppCompat.Button" android:text="BUTTON" - app:ripple="@style/RaiseWaveButtonRippleStyle" - app:delayClick="false"/> + style="@style/RaiseWaveButtonRippleStyle" + app:rd_delayClick="false"/> + style="@style/RaiseWaveColorButtonRippleStyle" + app:rd_delayClick="true"/> diff --git a/app/src/main/res/layout/fragment_dialog.xml b/app/src/main/res/layout/fragment_dialog.xml index 3b2ef1e0..7ea51955 100644 --- a/app/src/main/res/layout/fragment_dialog.xml +++ b/app/src/main/res/layout/fragment_dialog.xml @@ -38,8 +38,8 @@ android:textAppearance="@style/Base.TextAppearance.AppCompat.Button" android:gravity="center" android:text="TITLE ONLY" - app:ripple="@style/RaiseButtonRippleStyle" - app:delayClick="false"/> + style="@style/RaiseButtonRippleStyle" + app:rd_delayClick="false"/> + style="@style/RaiseButtonRippleStyle" + app:rd_delayClick="false"/> @@ -77,8 +77,8 @@ android:textAppearance="@style/Base.TextAppearance.AppCompat.Button" android:gravity="center" android:text="TITLE & MSG" - app:ripple="@style/RaiseButtonRippleStyle" - app:delayClick="false"/> + style="@style/RaiseButtonRippleStyle" + app:rd_delayClick="false"/> + style="@style/RaiseButtonRippleStyle" + app:rd_delayClick="false"/> @@ -116,8 +116,8 @@ android:textAppearance="@style/Base.TextAppearance.AppCompat.Button" android:gravity="center" android:text="CHOICE" - app:ripple="@style/RaiseButtonRippleStyle" - app:delayClick="false"/> + style="@style/RaiseButtonRippleStyle" + app:rd_delayClick="false"/> + style="@style/RaiseButtonRippleStyle" + app:rd_delayClick="false"/> @@ -163,8 +163,8 @@ android:textAppearance="@style/Base.TextAppearance.AppCompat.Button" android:gravity="center" android:text="TIME (LIGHT)" - app:ripple="@style/RaiseButtonRippleStyle" - app:delayClick="false"/> + style="@style/RaiseButtonRippleStyle" + app:rd_delayClick="false"/> + style="@style/RaiseButtonRippleStyle" + app:rd_delayClick="false"/> @@ -202,8 +202,8 @@ android:textAppearance="@style/Base.TextAppearance.AppCompat.Button" android:gravity="center" android:text="TIME (DARK)" - app:ripple="@style/RaiseButtonRippleStyle" - app:delayClick="false"/> + style="@style/RaiseButtonRippleStyle" + app:rd_delayClick="false"/> + style="@style/RaiseButtonRippleStyle" + app:rd_delayClick="false"/> diff --git a/app/src/main/res/layout/fragment_snackbar.xml b/app/src/main/res/layout/fragment_snackbar.xml index e857cefc..6aee8a61 100644 --- a/app/src/main/res/layout/fragment_snackbar.xml +++ b/app/src/main/res/layout/fragment_snackbar.xml @@ -30,8 +30,8 @@ android:textAppearance="@style/Base.TextAppearance.AppCompat.Button" android:gravity="center" android:text="SINGLE LINE" - app:ripple="@style/RaiseButtonRippleStyle" - app:delayClick="false"/> + style="@style/RaiseButtonRippleStyle" + app:rd_delayClick="false"/> + style="@style/RaiseButtonRippleStyle" + app:rd_delayClick="false"/> diff --git a/app/src/main/res/layout/fragment_spinner.xml b/app/src/main/res/layout/fragment_spinner.xml index 9da39856..758ccbb6 100644 --- a/app/src/main/res/layout/fragment_spinner.xml +++ b/app/src/main/res/layout/fragment_spinner.xml @@ -19,8 +19,9 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:minWidth="128dp" - app:ripple="@style/FlatWaveButtonRippleStyle" - app:delayClick="false" + app:rd_style="@style/Material.Drawable.Ripple.Wave.Light" + app:rd_enable="true" + app:rd_delayClick="false" app:spn_labelEnable="true" app:spn_label="Spinner with arrow" app:spn_arrowSwitchMode="true" @@ -34,8 +35,9 @@ android:layout_height="wrap_content" android:minWidth="128dp" android:layout_marginTop="16dp" - app:ripple="@style/FlatWaveButtonRippleStyle" - app:delayClick="false" + app:rd_style="@style/Material.Drawable.Ripple.Wave.Light" + app:rd_enable="true" + app:rd_delayClick="false" app:spn_labelEnable="true" app:spn_label="Spinner without arrow" app:spn_arrowSize="0dp" diff --git a/app/src/main/res/layout/rd_item_dropdown_end.xml b/app/src/main/res/layout/rd_item_dropdown_end.xml index 8bdd9e48..3d140fc9 100644 --- a/app/src/main/res/layout/rd_item_dropdown_end.xml +++ b/app/src/main/res/layout/rd_item_dropdown_end.xml @@ -8,5 +8,5 @@ android:paddingLeft="8dp" android:paddingRight="8dp" android:gravity="center_vertical" - app:ripple="@style/Material.Drawable.Ripple.Wave.Light" - app:delayClick="false"/> \ No newline at end of file + style="@style/Material.Drawable.Ripple.Wave.Light" + app:rd_delayClick="false"/> \ No newline at end of file diff --git a/app/src/main/res/layout/rd_item_dropdown_mode.xml b/app/src/main/res/layout/rd_item_dropdown_mode.xml index 8bdd9e48..3d140fc9 100644 --- a/app/src/main/res/layout/rd_item_dropdown_mode.xml +++ b/app/src/main/res/layout/rd_item_dropdown_mode.xml @@ -8,5 +8,5 @@ android:paddingLeft="8dp" android:paddingRight="8dp" android:gravity="center_vertical" - app:ripple="@style/Material.Drawable.Ripple.Wave.Light" - app:delayClick="false"/> \ No newline at end of file + style="@style/Material.Drawable.Ripple.Wave.Light" + app:rd_delayClick="false"/> \ No newline at end of file diff --git a/app/src/main/res/layout/row_spn.xml b/app/src/main/res/layout/row_spn.xml index ac8e94f8..54c946b3 100644 --- a/app/src/main/res/layout/row_spn.xml +++ b/app/src/main/res/layout/row_spn.xml @@ -9,6 +9,6 @@ android:textColor="#FF000000" android:paddingLeft="16dp" android:paddingRight="16dp" - app:ripple="@style/MenuItemRippleStyle" - app:delayClick="true"/> + style="@style/MenuItemRippleStyle" + app:rd_delayClick="true"/> diff --git a/app/src/main/res/layout/row_spn_dropdown.xml b/app/src/main/res/layout/row_spn_dropdown.xml index 2be7949c..ae4e8723 100644 --- a/app/src/main/res/layout/row_spn_dropdown.xml +++ b/app/src/main/res/layout/row_spn_dropdown.xml @@ -9,6 +9,6 @@ android:textColor="#FF000000" android:paddingLeft="16dp" android:paddingRight="16dp" - app:ripple="@style/MenuItemRippleStyle" - app:delayClick="true"/> + style="@style/MenuItemRippleStyle" + app:rd_delayClick="true"/> diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index f4d57706..2e7516b1 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -46,7 +46,7 @@ - - - - - - - - - - - - - - -