diff options
author | Daniel Lublin <daniel@lublin.se> | 2020-04-16 23:39:09 +0300 |
---|---|---|
committer | Daniel Lublin <daniel@lublin.se> | 2020-04-17 23:14:00 +0300 |
commit | 2bc205b6be3f942c20bb70a464eff6a52977f38b (patch) | |
tree | b5843580dc237b6d4db2186b8991119a4efd1b29 | |
parent | b50ff7a17ae3f6cdf3e54a08596fd3abc2cc51b6 (diff) |
Remove broken talking animation and drawable flipper
This fixes #12
6 files changed, 9 insertions, 254 deletions
diff --git a/app/src/main/java/se/lublin/mumla/channel/ChannelListAdapter.java b/app/src/main/java/se/lublin/mumla/channel/ChannelListAdapter.java index 3368c91..84123c9 100644 --- a/app/src/main/java/se/lublin/mumla/channel/ChannelListAdapter.java +++ b/app/src/main/java/se/lublin/mumla/channel/ChannelListAdapter.java @@ -51,9 +51,7 @@ import se.lublin.humla.model.TalkState; import se.lublin.mumla.R; import se.lublin.mumla.db.MumlaDatabase; import se.lublin.mumla.drawable.CircleDrawable; -import se.lublin.mumla.drawable.FlipDrawable; import se.lublin.mumla.service.MumlaService; -import se.lublin.mumla.util.TalkingIndicatorView; /** * Created by andrew on 31/07/13. @@ -63,11 +61,6 @@ public class ChannelListAdapter extends RecyclerView.Adapter implements UserMenu public static final long CHANNEL_ID_MASK = (0x1L << 32); public static final long USER_ID_MASK = (0x1L << 33); - /** - * Time (in ms) to run the flip animation for. - */ - private static final long FLIP_DURATION = 350; - private Context mContext; private IHumlaService mService; private MumlaDatabase mDatabase; @@ -232,10 +225,6 @@ public class ChannelListAdapter extends RecyclerView.Adapter implements UserMenu uvh.mUserName.setTypeface(null, typefaceStyle); uvh.mUserTalkHighlight.setImageDrawable(getTalkStateDrawable(user)); - uvh.mTalkingIndicator.setAlpha( - (user.getTalkState() == TalkState.TALKING || - user.getTalkState() == TalkState.WHISPERING || - user.getTalkState() == TalkState.SHOUTING) ? 1 : 0); // Pad the view depending on channel's nested level. DisplayMetrics metrics = mContext.getResources().getDisplayMetrics(); @@ -319,43 +308,13 @@ public class ChannelListAdapter extends RecyclerView.Adapter implements UserMenu UserViewHolder uvh = (UserViewHolder) view.findViewHolderForItemId(itemId); if (uvh != null) { Drawable newState = getTalkStateDrawable(user); - Drawable oldState = uvh.mUserTalkHighlight.getDrawable().getCurrent(); - - if (!newState.getConstantState().equals(oldState.getConstantState())) { - // "Flip" in new talking state. - FlipDrawable drawable = new FlipDrawable(oldState, newState); - uvh.mUserTalkHighlight.setImageDrawable(drawable); - drawable.start(FLIP_DURATION); + if (!uvh.mUserTalkHighlight.getDrawable().getCurrent().getConstantState() + .equals(newState.getConstantState())) { + uvh.mUserTalkHighlight.setImageDrawable(newState); } } } - /** - * Updates the user's talking indicator. - * @param user The user to update. - * @param view The view containing this adapter. - */ - public void animateUserTalkStateUpdate(IUser user, RecyclerView view) { - long itemId = user.getSession() | USER_ID_MASK; - final UserViewHolder uvh = (UserViewHolder) view.findViewHolderForItemId(itemId); - if (uvh != null) { - boolean talking = user.getTalkState() == TalkState.TALKING || - user.getTalkState() == TalkState.WHISPERING || - user.getTalkState() == TalkState.SHOUTING; - float strokeWidth = uvh.mTalkingIndicator.getStrokeWidth(); - float width = uvh.mUserTalkHighlight.getWidth(); - // Scale down the user's avatar to show the talking indicator. - float scale = talking ? (1 - (strokeWidth * 2)/width) : 1; - uvh.mTalkingIndicator.animate() - .alpha(talking ? 1 : 0) - .setDuration(200); - uvh.mUserTalkHighlight.animate() - .scaleX(scale) - .scaleY(scale) - .setDuration(200); - } - } - private Drawable getTalkStateDrawable(IUser user) { Resources resources = mContext.getResources(); if (user.isSelfDeafened()) { @@ -368,6 +327,11 @@ public class ChannelListAdapter extends RecyclerView.Adapter implements UserMenu return resources.getDrawable(R.drawable.outline_circle_server_muted); } else if (user.isSuppressed()) { return resources.getDrawable(R.drawable.outline_circle_suppressed); + } else if (user.getTalkState() == TalkState.TALKING + || user.getTalkState() == TalkState.SHOUTING + || user.getTalkState() == TalkState.WHISPERING) { + // TODO whisper and shouting? + return resources.getDrawable(R.drawable.outline_circle_talking_on); } else { // Passive drawables if (user.getTexture() != null) { @@ -500,7 +464,6 @@ public class ChannelListAdapter extends RecyclerView.Adapter implements UserMenu // public ImageView mUserAvatar; public ImageView mUserTalkHighlight; public ImageView mMoreButton; - public TalkingIndicatorView mTalkingIndicator; public UserViewHolder(View itemView) { super(itemView); @@ -508,7 +471,6 @@ public class ChannelListAdapter extends RecyclerView.Adapter implements UserMenu mUserTalkHighlight = (ImageView) itemView.findViewById(R.id.user_row_talk_highlight); mUserName = (TextView) itemView.findViewById(R.id.user_row_name); mMoreButton = (ImageView) itemView.findViewById(R.id.user_row_more); - mTalkingIndicator = (TalkingIndicatorView) itemView.findViewById(R.id.user_row_talk_indicator); } } diff --git a/app/src/main/java/se/lublin/mumla/channel/ChannelListFragment.java b/app/src/main/java/se/lublin/mumla/channel/ChannelListFragment.java index e92cfd7..4287bf3 100644 --- a/app/src/main/java/se/lublin/mumla/channel/ChannelListFragment.java +++ b/app/src/main/java/se/lublin/mumla/channel/ChannelListFragment.java @@ -117,7 +117,7 @@ public class ChannelListFragment extends HumlaServiceFragment implements OnChann @Override public void onUserTalkStateUpdated(IUser user) { - mChannelListAdapter.animateUserTalkStateUpdate(user, mChannelView); + mChannelListAdapter.animateUserStateUpdate(user, mChannelView); } }; diff --git a/app/src/main/java/se/lublin/mumla/drawable/FlipDrawable.java b/app/src/main/java/se/lublin/mumla/drawable/FlipDrawable.java deleted file mode 100644 index b421fd4..0000000 --- a/app/src/main/java/se/lublin/mumla/drawable/FlipDrawable.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (C) 2014 Andrew Comminos - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package se.lublin.mumla.drawable; - -import android.animation.ValueAnimator; -import android.annotation.TargetApi; -import android.graphics.Camera; -import android.graphics.Canvas; -import android.graphics.drawable.Drawable; -import android.graphics.drawable.LayerDrawable; - -/** - * A transition drawable that shows a "flip" between two different images. - * Created by andrew on 19/10/14. - */ -@TargetApi(11) -public class FlipDrawable extends LayerDrawable implements ValueAnimator.AnimatorUpdateListener { - private Drawable mFrom; - private Drawable mTo; - private Camera mCamera; - private float mRotate; - - public FlipDrawable(Drawable from, Drawable to) { - super(new Drawable[] { from, to }); - mFrom = from; - mTo = to; - mCamera = new Camera(); - mRotate = 0; - } - - @Override - public void draw(Canvas canvas) { - float centerX = getIntrinsicWidth()/2; - float centerY = getIntrinsicHeight()/2; - boolean flipped = mRotate > 90; - mCamera.save(); - mCamera.translate(centerX, centerY, 0); - if (!flipped) { - mCamera.rotateY(mRotate); - } else { - mCamera.rotateY(180 - mRotate); - } - mCamera.translate(-centerX, -centerY, 0); - mCamera.applyToCanvas(canvas); - mCamera.restore(); - if (flipped) { - mTo.draw(canvas); - } else { - mFrom.draw(canvas); - } - - } - - @Override - public Drawable getCurrent() { - return mRotate > 90 ? mTo : mFrom; - } - - /** - * Starts the flip animation. - * @param duration The duration in ms for the flip to occur. - */ - public void start(long duration) { - ValueAnimator animator = ValueAnimator.ofFloat(0, 180); - animator.setDuration(duration); - animator.addUpdateListener(this); - animator.start(); - } - - @Override - public void onAnimationUpdate(ValueAnimator animation) { - mRotate = (Float) animation.getAnimatedValue(); - invalidateSelf(); - } -} diff --git a/app/src/main/java/se/lublin/mumla/util/TalkingIndicatorView.java b/app/src/main/java/se/lublin/mumla/util/TalkingIndicatorView.java deleted file mode 100644 index 627ffd2..0000000 --- a/app/src/main/java/se/lublin/mumla/util/TalkingIndicatorView.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) 2015 Andrew Comminos <andrew@comminos.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package se.lublin.mumla.util; - -import android.animation.ValueAnimator; -import android.annotation.TargetApi; -import android.content.Context; -import android.content.res.TypedArray; -import android.graphics.Canvas; -import android.graphics.Paint; -import android.graphics.RectF; -import android.os.Build; -import android.util.AttributeSet; -import android.view.View; -import android.view.animation.LinearInterpolator; - -import se.lublin.mumla.R; - -/** - * Created by andrew on 30/11/15. - */ -@TargetApi(Build.VERSION_CODES.HONEYCOMB) -public class TalkingIndicatorView extends View implements ValueAnimator.AnimatorUpdateListener { - private static final float OVERSHOOT_TENSION = 3.5f; - - /** The offset of the arc from the origin, mod 360. */ - private float mArcOffset; - /** The length of the arc, in radians. */ - private float mArcLength; - private float mArcWidth; - private Paint mArcPaint; - private RectF mBounds; - - public TalkingIndicatorView(Context context, AttributeSet attrs) { - super(context, attrs); - TypedArray style = context.obtainStyledAttributes(attrs, new int[] { - R.attr.arcColor, - R.attr.arcWidth, - R.attr.arcLength, - R.attr.cyclePeriod - }); - - mArcOffset = 0; - mArcLength = style.getDimensionPixelSize(2, 20); - mArcWidth = style.getDimensionPixelSize(1, 4); - - mArcPaint = new Paint(); - mArcPaint.setAntiAlias(true); - mArcPaint.setColor(style.getColor(0, 0xFFFF0000)); - mArcPaint.setStrokeWidth(mArcWidth); - mArcPaint.setStyle(Paint.Style.STROKE); - - ValueAnimator cycleAnimator = new ValueAnimator(); - cycleAnimator.setRepeatCount(ValueAnimator.INFINITE); - cycleAnimator.setDuration(style.getInteger(3, 1000)); - cycleAnimator.setFloatValues(0, 360); - cycleAnimator.setInterpolator(new LinearInterpolator()); - cycleAnimator.addUpdateListener(this); - cycleAnimator.start(); - - style.recycle(); - } - - @Override - protected void onDraw(Canvas canvas) { - super.onDraw(canvas); - - canvas.drawArc(mBounds, mArcOffset, mArcLength, false, mArcPaint); - } - - @Override - protected void onSizeChanged(int w, int h, int oldw, int oldh) { - super.onSizeChanged(w, h, oldw, oldh); - mBounds = new RectF(0, 0, w, h); - mBounds.inset(mArcWidth / 2, mArcWidth / 2); - } - - @Override - public void onAnimationUpdate(ValueAnimator animation) { - mArcOffset = (float) animation.getAnimatedValue(); - invalidate(); - } - - public float getStrokeWidth() { - return mArcWidth; - } -} diff --git a/app/src/main/res/layout/channel_user_row.xml b/app/src/main/res/layout/channel_user_row.xml index ca568f7..3e3dfae 100644 --- a/app/src/main/res/layout/channel_user_row.xml +++ b/app/src/main/res/layout/channel_user_row.xml @@ -37,15 +37,6 @@ <!--android:layout_margin="2dp"--> <!--android:scaleType="centerCrop"/>--> - <se.lublin.mumla.util.TalkingIndicatorView - android:id="@+id/user_row_talk_indicator" - android:layout_width="match_parent" - android:layout_height="match_parent" - custom:arcColor="@color/ripple_talk_state_on" - custom:arcWidth="2dp" - custom:cyclePeriod="1200" - custom:arcLength="70dp"/> - <ImageView android:id="@+id/user_row_talk_highlight" android:layout_width="match_parent" diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index dda253e..4e6c78d 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -18,10 +18,4 @@ <resources> <attr name="cardStyle" format="reference" /> - <declare-styleable name="TalkingIndicatorView"> - <attr name="arcColor" format="color" /> - <attr name="arcWidth" format="dimension" /> - <attr name="arcLength" format="dimension" /> - <attr name="cyclePeriod" format="integer" /> - </declare-styleable> </resources>
\ No newline at end of file |