use of android.graphics.drawable.AnimationDrawable in project SmartMesh_Android by SmartMeshFoundation.
the class ChatAdapter method setAudioContent.
/**
* Voice broadcast logic
* @param h ViewHolder
* @param position position
* @param type Message type
*/
private void setAudioContent(Holder h, final int position, final int type) {
h.audioTimes.setText(mList.get(position).getSecond() + "''");
final ImageView audioIcon = h.audioIcon;
if (type == LEFT_AUDIO) {
if (mList.get(position).isAudioPlaying()) {
audioIcon.setImageResource(R.drawable.anim_songs_voice_left_icon);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && audioIcon.getDrawable() instanceof AnimationDrawable) {
((AnimationDrawable) audioIcon.getDrawable()).start();
((AnimationDrawable) audioIcon.getDrawable()).setOneShot(false);
}
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && audioIcon.getDrawable() instanceof AnimationDrawable && ((AnimationDrawable) audioIcon.getDrawable()).isRunning()) {
((AnimationDrawable) audioIcon.getDrawable()).stop();
}
audioIcon.setImageResource(R.drawable.icon_audio_left3);
}
} else {
if (mList.get(position).isAudioPlaying()) {
audioIcon.setImageResource(R.drawable.anim_songs_voice_right_icon);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && audioIcon.getDrawable() instanceof AnimationDrawable) {
((AnimationDrawable) audioIcon.getDrawable()).start();
((AnimationDrawable) audioIcon.getDrawable()).setOneShot(false);
}
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && audioIcon.getDrawable() instanceof AnimationDrawable && ((AnimationDrawable) audioIcon.getDrawable()).isRunning()) {
((AnimationDrawable) audioIcon.getDrawable()).stop();
}
audioIcon.setImageResource(R.drawable.icon_audio_right3);
}
}
h.leftLinear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
if (animationDrawable != null) {
animationDrawable.stop();
animationDrawable = null;
}
if (// Is there is the voice of click
mList.get(position).isAudioPlaying()) {
mList.get(position).setAudioPlaying(false);
if (type == LEFT_AUDIO) {
audioIcon.setImageResource(R.drawable.icon_audio_left3);
} else {
audioIcon.setImageResource(R.drawable.icon_audio_right3);
}
mPlayer.stop();
return;
}
boolean is_mode_in_call = MySharedPrefs.readBooleanNormal(mContext, MySharedPrefs.FILE_USER, MySharedPrefs.AUDIO_MODE);
if (is_mode_in_call) {
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
audioManager.setSpeakerphoneOn(false);
} else {
audioManager.setMode(AudioManager.MODE_NORMAL);
audioManager.setSpeakerphoneOn(true);
}
mPlayer.reset();
if (audioManager.getMode() == AudioManager.MODE_IN_COMMUNICATION) {
if (listener != null) {
listener.onShow_mode_in_call_tip();
}
mPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL);
} else {
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
}
mPlayer.setDataSource(TextUtils.isEmpty(mList.get(position).getLocalUrl()) ? mList.get(position).getContent() : mList.get(position).getLocalUrl());
mPlayer.prepare();
mPlayer.start();
for (int i = 0; i < mList.size(); i++) {
if (mList.get(i).getType() == 2 && mList.get(i).isAudioPlaying()) {
mList.get(i).setAudioPlaying(false);
break;
}
}
mList.get(position).setAudioPlaying(true);
notifyDataSetChanged();
if (type == LEFT_AUDIO) {
audioIcon.setImageResource(R.drawable.anim_songs_voice_left_icon);
} else {
audioIcon.setImageResource(R.drawable.anim_songs_voice_right_icon);
}
animationDrawable = (AnimationDrawable) audioIcon.getDrawable();
if (animationDrawable != null) {
animationDrawable.start();
animationDrawable.setOneShot(false);
}
mPlayer.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
if (audioManager != null) {
audioManager.setMode(AudioManager.MODE_NORMAL);
audioManager.setSpeakerphoneOn(true);
}
mPlayer.reset();
if (animationDrawable != null) {
animationDrawable.stop();
animationDrawable = null;
}
mList.get(position).setAudioPlaying(false);
if (type == LEFT_AUDIO) {
audioIcon.setImageResource(R.drawable.icon_audio_left3);
} else {
audioIcon.setImageResource(R.drawable.icon_audio_right3);
}
notifyDataSetChanged();
}
});
} catch (Exception e) {
e.printStackTrace();
MyToast.showToast(mContext, mContext.getString(R.string.chat_audio_failed));
}
}
});
}
use of android.graphics.drawable.AnimationDrawable in project remusic by aa112901.
the class AppCompatImageHelper method applySupportImageTint.
private boolean applySupportImageTint() {
Drawable image = ((ImageView) mView).getDrawable();
AnimationDrawable animationDrawable = null;
if (image instanceof AnimationDrawable) {
Log.e("drawable", "is animationdrawable");
animationDrawable = ((AnimationDrawable) image);
// image = animationDrawable;
}
if (image != null && mImageTintInfo != null && mImageTintInfo.mHasTintList) {
if (animationDrawable != null) {
Log.e("drawable", "is animationdrawable not null");
Drawable tintDrawable = animationDrawable;
Log.e("drawable", "start0");
tintDrawable = DrawableCompat.wrap(tintDrawable);
Log.e("drawable", "start1");
if (mImageTintInfo.mHasTintList) {
DrawableCompat.setTintList(tintDrawable, mImageTintInfo.mTintList);
}
if (mImageTintInfo.mHasTintMode) {
DrawableCompat.setTintMode(tintDrawable, mImageTintInfo.mTintMode);
}
if (tintDrawable.isStateful()) {
tintDrawable.setState(mView.getDrawableState());
}
tintDrawable = DrawableCompat.unwrap(tintDrawable);
setImageDrawable(tintDrawable);
if (image == tintDrawable) {
Log.e("drawable", "invalidateself");
// tintDrawable.invalidateSelf();
}
return true;
} else {
Drawable tintDrawable = image.mutate();
tintDrawable = DrawableCompat.wrap(tintDrawable);
if (mImageTintInfo.mHasTintList) {
DrawableCompat.setTintList(tintDrawable, mImageTintInfo.mTintList);
}
if (mImageTintInfo.mHasTintMode) {
DrawableCompat.setTintMode(tintDrawable, mImageTintInfo.mTintMode);
}
if (tintDrawable.isStateful()) {
tintDrawable.setState(mView.getDrawableState());
}
setImageDrawable(tintDrawable);
if (image == tintDrawable) {
tintDrawable.invalidateSelf();
}
return true;
}
}
return false;
}
use of android.graphics.drawable.AnimationDrawable in project Libraries-for-Android-Developers by eoecn.
the class IcsProgressBar method tileifyIndeterminate.
/**
* Convert a AnimationDrawable for use as a barberpole animation.
* Each frame of the animation is wrapped in a ClipDrawable and
* given a tiling BitmapShader.
*/
private Drawable tileifyIndeterminate(Drawable drawable) {
if (drawable instanceof AnimationDrawable) {
AnimationDrawable background = (AnimationDrawable) drawable;
final int N = background.getNumberOfFrames();
AnimationDrawable newBg = new AnimationDrawable();
newBg.setOneShot(background.isOneShot());
for (int i = 0; i < N; i++) {
Drawable frame = tileify(background.getFrame(i), true);
frame.setLevel(10000);
newBg.addFrame(frame, background.getDuration(i));
}
newBg.setLevel(10000);
drawable = newBg;
}
return drawable;
}
use of android.graphics.drawable.AnimationDrawable in project wechat by motianhuo.
the class MessageAdapter method handleVoiceMessage.
/**
* 语音消息
*
* @param message
* @param holder
* @param position
* @param convertView
*/
private void handleVoiceMessage(final EMMessage message, final ViewHolder holder, final int position, View convertView) {
VoiceMessageBody voiceBody = (VoiceMessageBody) message.getBody();
holder.tv.setText(voiceBody.getLength() + "\"");
holder.iv.setOnClickListener(new VoicePlayClickListener(message, holder.iv, holder.iv_read_status, this, activity, username));
holder.iv.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
activity.startActivityForResult((new Intent(activity, ContextMenu.class)).putExtra("position", position).putExtra("type", EMMessage.Type.VOICE.ordinal()), ChatActivity.REQUEST_CODE_CONTEXT_MENU);
return true;
}
});
if (((ChatActivity) activity).playMsgId != null && ((ChatActivity) activity).playMsgId.equals(message.getMsgId()) && VoicePlayClickListener.isPlaying) {
AnimationDrawable voiceAnimation;
if (message.direct == EMMessage.Direct.RECEIVE) {
holder.iv.setImageResource(R.anim.voice_from_icon);
} else {
holder.iv.setImageResource(R.anim.voice_to_icon);
}
voiceAnimation = (AnimationDrawable) holder.iv.getDrawable();
voiceAnimation.start();
} else {
if (message.direct == EMMessage.Direct.RECEIVE) {
holder.iv.setImageResource(R.drawable.chatfrom_voice_playing);
} else {
holder.iv.setImageResource(R.drawable.chatto_voice_playing);
}
}
if (message.direct == EMMessage.Direct.RECEIVE) {
if (message.isListened()) {
// 隐藏语音未听标志
holder.iv_read_status.setVisibility(View.INVISIBLE);
} else {
holder.iv_read_status.setVisibility(View.VISIBLE);
}
System.err.println("it is receive msg");
if (message.status == EMMessage.Status.INPROGRESS) {
holder.pb.setVisibility(View.VISIBLE);
System.err.println("!!!! back receive");
((FileMessageBody) message.getBody()).setDownloadCallback(new EMCallBack() {
@Override
public void onSuccess() {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
holder.pb.setVisibility(View.INVISIBLE);
notifyDataSetChanged();
}
});
}
@Override
public void onProgress(int progress, String status) {
}
@Override
public void onError(int code, String message) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
holder.pb.setVisibility(View.INVISIBLE);
}
});
}
});
} else {
holder.pb.setVisibility(View.INVISIBLE);
}
return;
}
// until here, deal with send voice msg
switch(message.status) {
case SUCCESS:
holder.pb.setVisibility(View.GONE);
holder.staus_iv.setVisibility(View.GONE);
break;
case FAIL:
holder.pb.setVisibility(View.GONE);
holder.staus_iv.setVisibility(View.VISIBLE);
break;
case INPROGRESS:
holder.pb.setVisibility(View.VISIBLE);
holder.staus_iv.setVisibility(View.GONE);
break;
default:
sendMsgInBackground(message, holder);
}
}
use of android.graphics.drawable.AnimationDrawable in project ActionBarSherlock by JakeWharton.
the class IcsProgressBar method tileifyIndeterminate.
/**
* Convert a AnimationDrawable for use as a barberpole animation.
* Each frame of the animation is wrapped in a ClipDrawable and
* given a tiling BitmapShader.
*/
private Drawable tileifyIndeterminate(Drawable drawable) {
if (drawable instanceof AnimationDrawable) {
AnimationDrawable background = (AnimationDrawable) drawable;
final int N = background.getNumberOfFrames();
AnimationDrawable newBg = new AnimationDrawable();
newBg.setOneShot(background.isOneShot());
for (int i = 0; i < N; i++) {
Drawable frame = tileify(background.getFrame(i), true);
frame.setLevel(10000);
newBg.addFrame(frame, background.getDuration(i));
}
newBg.setLevel(10000);
drawable = newBg;
}
return drawable;
}
Aggregations