Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
appinventor-sources
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
appinventor-sources
Commits
9ebfb0d7
Commit
9ebfb0d7
authored
Nov 26, 2018
by
Susan Rati Lane
Committed by
Evan W. Patton
Nov 26, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Restore button ripple effect for material theme phones
Fixes #1318
parent
3ed2f95a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
24 deletions
+55
-24
appinventor/components/src/com/google/appinventor/components/runtime/ButtonBase.java
...com/google/appinventor/components/runtime/ButtonBase.java
+55
-24
No files found.
appinventor/components/src/com/google/appinventor/components/runtime/ButtonBase.java
View file @
9ebfb0d7
...
...
@@ -6,6 +6,8 @@
package
com.google.appinventor.components.runtime
;
import
android.graphics.drawable.RippleDrawable
;
import
android.os.Build
;
import
com.google.appinventor.components.annotations.DesignerProperty
;
import
com.google.appinventor.components.annotations.PropertyCategory
;
import
com.google.appinventor.components.annotations.SimpleEvent
;
...
...
@@ -161,13 +163,12 @@ public abstract class ButtonBase extends AndroidViewComponent
* release when not-pressed.
*/
@Override
public
boolean
onTouch
(
View
view
,
MotionEvent
me
)
{
public
boolean
onTouch
(
View
view
,
MotionEvent
me
)
{
//NOTE: We ALWAYS return false because we want to indicate that this listener has not
//been consumed. Using this approach, other listeners (e.g. OnClick) can process as normal.
if
(
me
.
getAction
()
==
MotionEvent
.
ACTION_DOWN
)
{
//button pressed, provide visual feedback AND return false
if
(
ShowFeedback
(
))
{
if
(
ShowFeedback
()
&&
(
AppInventorCompatActivity
.
isClassicMode
()
||
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
LOLLIPOP
))
{
view
.
getBackground
().
setAlpha
(
70
);
// translucent
view
.
invalidate
();
}
...
...
@@ -175,7 +176,7 @@ public abstract class ButtonBase extends AndroidViewComponent
}
else
if
(
me
.
getAction
()
==
MotionEvent
.
ACTION_UP
||
me
.
getAction
()
==
MotionEvent
.
ACTION_CANCEL
)
{
//button released, set button back to normal AND return false
if
(
ShowFeedback
(
))
{
if
(
ShowFeedback
()
&&
(
AppInventorCompatActivity
.
isClassicMode
()
||
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
LOLLIPOP
))
{
view
.
getBackground
().
setAlpha
(
255
);
// opaque
view
.
invalidate
();
}
...
...
@@ -388,6 +389,12 @@ public abstract class ButtonBase extends AndroidViewComponent
// If there is no background image and color is default,
// restore original 3D bevel appearance.
ViewUtil
.
setBackgroundDrawable
(
view
,
defaultButtonDrawable
);
}
else
if
(
backgroundColor
==
Component
.
COLOR_NONE
)
{
// Clear the background image.
ViewUtil
.
setBackgroundDrawable
(
view
,
null
);
//Now we set again the default drawable
ViewUtil
.
setBackgroundDrawable
(
view
,
defaultButtonDrawable
);
view
.
getBackground
().
setColorFilter
(
backgroundColor
,
PorterDuff
.
Mode
.
CLEAR
);
}
else
{
// Clear the background image.
ViewUtil
.
setBackgroundDrawable
(
view
,
null
);
...
...
@@ -409,12 +416,20 @@ public abstract class ButtonBase extends AndroidViewComponent
}
}
private
ColorStateList
createRippleState
()
{
int
[][]
states
=
new
int
[][]
{
new
int
[]
{
android
.
R
.
attr
.
state_enabled
}
};
int
enabled_color
=
defaultColorStateList
.
getColorForState
(
view
.
getDrawableState
(),
android
.
R
.
attr
.
state_enabled
);
int
[]
colors
=
new
int
[]
{
Color
.
argb
(
70
,
Color
.
red
(
enabled_color
),
Color
.
green
(
enabled_color
),
Color
.
blue
(
enabled_color
))
};
return
new
ColorStateList
(
states
,
colors
);
}
// Throw IllegalArgumentException if shape has illegal value.
private
void
setShape
()
{
ShapeDrawable
drawable
=
new
ShapeDrawable
();
// Set color of drawable.
drawable
.
getPaint
().
setColor
((
backgroundColor
==
Component
.
COLOR_DEFAULT
)
?
SHAPED_DEFAULT_BACKGROUND_COLOR
:
backgroundColor
);
// Set shape of drawable.
switch
(
shape
)
{
case
Component
.
BUTTON_SHAPE_ROUNDED
:
...
...
@@ -429,8 +444,24 @@ public abstract class ButtonBase extends AndroidViewComponent
default
:
throw
new
IllegalArgumentException
();
}
// Set drawable to the background of the button.
view
.
setBackgroundDrawable
(
drawable
);
if
(!
AppInventorCompatActivity
.
isClassicMode
()
&&
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
ViewUtil
.
setBackgroundDrawable
(
view
,
new
RippleDrawable
(
createRippleState
(),
drawable
,
drawable
));
}
else
{
ViewUtil
.
setBackgroundDrawable
(
view
,
drawable
);
}
if
(
backgroundColor
==
Component
.
COLOR_NONE
)
{
view
.
getBackground
().
setColorFilter
(
backgroundColor
,
PorterDuff
.
Mode
.
CLEAR
);
}
else
if
(
backgroundColor
==
Component
.
COLOR_DEFAULT
)
{
view
.
getBackground
().
setColorFilter
(
SHAPED_DEFAULT_BACKGROUND_COLOR
,
PorterDuff
.
Mode
.
SRC_ATOP
);
}
else
{
view
.
getBackground
().
setColorFilter
(
backgroundColor
,
PorterDuff
.
Mode
.
SRC_ATOP
);
}
view
.
invalidate
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment