public DefaultFooter(Activity context) { MainContext = context; animationLoading = new AnimationDrawable(); foreach (var src in loadingAnimSrcs) { animationLoading.AddFrame(ContextCompat.GetDrawable(context, src), 150); animationLoading.OneShot = (false); } }
/// <summary> /// Caches all animations. /// </summary> private void CacheAnimations() { try { foreach (AnimationType animation in Enum.GetValues(typeof(AnimationType))) { if (animation == AnimationType.None || animation == AnimationType.ShirtPullDown) { continue; } var animationDrawable = new AnimationDrawable(); using (var stream = new StreamReader(Assets.Open(string.Format("{0}.xml", animation)))) { var document = XDocument.Load(stream); var root = document.Root; var elements = root.Descendants(); foreach (var element in elements) { var drawable = ReadAttribute(element, "drawable"); var duration = ReadAttribute(element, "duration"); var bitmapStringId = drawable.Substring(drawable.IndexOf('/') + 1); var resID = Resources.GetIdentifier(bitmapStringId, "drawable", PackageName); BitmapFactory.Options options = new BitmapFactory.Options(); options.InJustDecodeBounds = false; options.InPreferredConfig = Bitmap.Config.Rgb565; options.InDither = true; options.InSampleSize = 2; options.InPurgeable = true; using (Bitmap bitmap = BitmapFactory.DecodeResource(Resources, resID, options)) { BitmapDrawable bitmapDrawable = new BitmapDrawable(bitmap); animationDrawable.AddFrame(bitmapDrawable, int.Parse(duration)); } } // cache animation _animationsDrawable.Add(animation.ToString(), animationDrawable); } } } catch (Exception ex) { _statusTextView.Text = ex.ToString(); } }
private void PauseAnimation(IMenuItem target) { Drawable currentFrame; Drawable checkFrame; AnimationDrawable animation; AnimationDrawable newAnimation; newAnimation = new AnimationDrawable(); RunOnUiThread(() => { animation = (AnimationDrawable)target.Icon; animation.Stop(); currentFrame = animation.Current; for (int i = 0; i < animation.NumberOfFrames; i++) { checkFrame = animation.GetFrame(i); if (checkFrame == currentFrame) { for (int k = i; k < animation.NumberOfFrames; k++) { newAnimation.AddFrame(animation.GetFrame(k), 100); } for (int k = 0; k < i; k++) { newAnimation.AddFrame(animation.GetFrame(k), 100); } break; } } target.SetIcon(newAnimation); }); }
private void RenderGif() { AnimationDrawable test = new AnimationDrawable(); test.OneShot = false; for (int i = 1; i < 90; i++) { Drawable d = DrawableConverter.GetDrawableFromAssets("gif/i" + i.ToString() + ".png", this); test.AddFrame(d, 1); } iView.SetImageDrawable(test); }
/// <summary> /// Create an animated bitmap /// </summary> public static Drawable GetAnimatedDrawable(Resources res, string name, int frames, int duration, bool loop) { var animation = new AnimationDrawable(); var bitmapFrames = new List <Bitmap>(frames); for (var i = 0; i < frames; i++) { bitmapFrames.Add(GetAnimationFrameBitmap(name, i)); } // TODO: Load drawable better, like from cache bitmapFrames.ForEach(f => animation.AddFrame(new BitmapDrawable(res, f), duration)); animation.OneShot = !loop; animation.Start(); return(animation); }
/// <summary> /// Gets the rect with animation. /// </summary> /// <returns>Drawable.</returns> public Drawable GetRectWithAnimation() { var builder = DrawableTextView.TextDrwableBuilder.Rect(); var animationDrawable = new AnimationDrawable(); for (var i = 10; i > 0; i--) { var frame = builder.Build(i.ToString(), RandomColor, RandomColor); animationDrawable.AddFrame(frame, 1200); } animationDrawable.OneShot = false; animationDrawable.Start(); return(animationDrawable); }
void SetAnimation() { var frameAnimation = new AnimationDrawable(); foreach (var img in this.images) { frameAnimation.AddFrame(img, 1000); } this.RunOnUiThread(() => { var imageButton = FindViewById <Button> (Resource.Id.AllFilmsButton); imageButton.SetBackgroundDrawable(frameAnimation); frameAnimation.Start(); }); }