* [android] fix wrong ripple with pseudo class
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/bdad06d0 Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/bdad06d0 Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/bdad06d0 Branch: refs/heads/master Commit: bdad06d015b6b6b8edd758b5cb8b4fb6ad515b0f Parents: 0bf3d92 Author: misakuo <misa...@apache.org> Authored: Tue Oct 10 17:43:49 2017 +0800 Committer: misakuo <misa...@apache.org> Committed: Tue Oct 10 17:43:49 2017 +0800 ---------------------------------------------------------------------- .../taobao/weex/ui/component/WXComponent.java | 27 ++++++++++++++++---- .../pesudo/OnActivePseudoListener.java | 26 +++++++++++++++++++ .../component/pesudo/OnActivePseudoListner.java | 26 ------------------- .../pesudo/TouchActivePseudoListener.java | 12 ++++----- 4 files changed, 54 insertions(+), 37 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/bdad06d0/android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java index 09e5e8d..e524a0c 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java @@ -74,7 +74,7 @@ import com.taobao.weex.tracing.Stopwatch; import com.taobao.weex.tracing.WXTracing; import com.taobao.weex.ui.IFComponentHolder; import com.taobao.weex.ui.animation.WXAnimationModule; -import com.taobao.weex.ui.component.pesudo.OnActivePseudoListner; +import com.taobao.weex.ui.component.pesudo.OnActivePseudoListener; import com.taobao.weex.ui.component.pesudo.PesudoStatus; import com.taobao.weex.ui.component.pesudo.TouchActivePseudoListener; import com.taobao.weex.ui.flat.FlatComponent; @@ -112,7 +112,7 @@ import static com.taobao.weex.utils.WXUtils.getBoolean; * abstract component * */ -public abstract class WXComponent<T extends View> implements IWXObject, IWXActivityStateListener,OnActivePseudoListner { +public abstract class WXComponent<T extends View> implements IWXObject, IWXActivityStateListener,OnActivePseudoListener { public static final String PROP_FIXED_SIZE = "fixedSize"; public static final String PROP_FS_MATCH_PARENT = "m"; @@ -1278,9 +1278,7 @@ public abstract class WXComponent<T extends View> implements IWXObject, IWXActi public void setBackgroundColor(String color) { if (!TextUtils.isEmpty(color)) { int colorInt = WXResourceUtils.getColor(color); - Object obj = getDomObject().getAttrs().get(Constants.Name.RIPPLE_ENABLED); - boolean isRippleEnabled = getBoolean(obj, false); - if (isRippleEnabled && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + if (isRippleEnabled() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mRippleBackground = prepareBackgroundRipple(); if (mRippleBackground != null) { if (mBackgroundDrawable == null) { @@ -1735,6 +1733,15 @@ public abstract class WXComponent<T extends View> implements IWXObject, IWXActi status, pesudoStyles, styles.getPesudoResetStyles()); + + if (resultStyles != null && isRippleEnabled()) { + resultStyles.remove(Constants.Name.BACKGROUND_COLOR); + if (resultStyles.isEmpty()) { + WXLogUtils.d("PseudoClass", "skip empty pseudo styles"); + return; + } + } + updateStyleByPesudo(resultStyles); } @@ -1896,4 +1903,14 @@ public abstract class WXComponent<T extends View> implements IWXObject, IWXActi } } } + + protected boolean isRippleEnabled() { + try { + Object obj = getDomObject().getAttrs().get(Constants.Name.RIPPLE_ENABLED); + return getBoolean(obj, false); + } catch (Throwable t) { + //ignore + } + return false; + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/bdad06d0/android/sdk/src/main/java/com/taobao/weex/ui/component/pesudo/OnActivePseudoListener.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/pesudo/OnActivePseudoListener.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/pesudo/OnActivePseudoListener.java new file mode 100644 index 0000000..989f9e9 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/pesudo/OnActivePseudoListener.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +package com.taobao.weex.ui.component.pesudo; + +/** + * Created by sospartan on 05/01/2017. + */ +public interface OnActivePseudoListener { + void updateActivePseudo(boolean isSet); +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/bdad06d0/android/sdk/src/main/java/com/taobao/weex/ui/component/pesudo/OnActivePseudoListner.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/pesudo/OnActivePseudoListner.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/pesudo/OnActivePseudoListner.java deleted file mode 100644 index 961e3b8..0000000 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/pesudo/OnActivePseudoListner.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ -package com.taobao.weex.ui.component.pesudo; - -/** - * Created by sospartan on 05/01/2017. - */ -public interface OnActivePseudoListner { - void updateActivePseudo(boolean isSet); -} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/bdad06d0/android/sdk/src/main/java/com/taobao/weex/ui/component/pesudo/TouchActivePseudoListener.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/pesudo/TouchActivePseudoListener.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/pesudo/TouchActivePseudoListener.java index 8caf3f2..7100144 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/pesudo/TouchActivePseudoListener.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/pesudo/TouchActivePseudoListener.java @@ -25,22 +25,22 @@ import android.view.View; * Created by sospartan on 05/01/2017. */ public class TouchActivePseudoListener implements View.OnTouchListener { - private OnActivePseudoListner mOnActivePseudoListner; + private OnActivePseudoListener mOnActivePseudoListener; private boolean mIsConsumeOnTouch; - public TouchActivePseudoListener(OnActivePseudoListner l, boolean consumeInTouch) { - mOnActivePseudoListner = l; + public TouchActivePseudoListener(OnActivePseudoListener l, boolean consumeInTouch) { + mOnActivePseudoListener = l; mIsConsumeOnTouch = consumeInTouch; } @Override public boolean onTouch(View v, MotionEvent event) { int action = event.getAction(); - if (mOnActivePseudoListner != null) { + if (mOnActivePseudoListener != null) { if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_POINTER_DOWN) { - mOnActivePseudoListner.updateActivePseudo(true); + mOnActivePseudoListener.updateActivePseudo(true); } else if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) { - mOnActivePseudoListner.updateActivePseudo(false); + mOnActivePseudoListener.updateActivePseudo(false); } } return mIsConsumeOnTouch;