Thursday, September 29, 2022
HomeiOS Developmentios - I am having issues displaying a .gif animation in the...

ios – I am having issues displaying a .gif animation in the splash screen for my android app using xamarin.forms?

[ad_1]

The above header refers.

The .gif animation (which is about 2 seconds) hardly displays at all in the splash screen before it gets to the login screen.

This is my SplashLayout.xaml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"    
>

<com.felipecsl.gifimageview.library.GifImageView
    android:id="@+id/myGIFImage"
    android:layout_gravity="center"
    android:scaleType="fitCenter"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
</LinearLayout>

This is my Splash_Activity.cs:

using AbuseAlert.Droid;
using Android.App;
using Android.OS;
using Felipecsl.GifImageViewLibrary;
using System.IO;

namespace Abuse_Alert.Droid
{
    [Activity(Theme = "@style/Theme.Splash", MainLauncher = true, NoHistory = true, 
Label = "AbuseAlert")]

public class SplashActivity : Activity
{        
    GifImageView myGIFImage;

    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        SetContentView(Resource.Layout.SplashLayout);

        System.Threading.ThreadPool.QueueUserWorkItem(o => LoadActivity());
    }

    private void LoadActivity()
    {
        //System.Threading.Thread.Sleep(2000); // Simulate a long pause
                                             // 
        RunOnUiThread(() => StartActivity(typeof(MainActivity)));
    }

    public override void OnWindowFocusChanged(bool hasFocus)
    {
        myGIFImage = FindViewById<GifImageView>(Resource.Id.myGIFImage);

        // From Drawable
        Stream input = Resources.OpenRawResource(Resource.Drawable.AbuseAlert);

        // You should convert the "input" into Byte Array 
        byte[] bytes = ConvertByteArray(input);

        myGIFImage.SetBytes(bytes);
        myGIFImage.StartAnimation();
    }
    private byte[] ConvertByteArray(Stream input)
    {
        byte[] buffer = new byte[16 * 1024];
        using MemoryStream ms = new MemoryStream();
        int read;
        while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
            ms.Write(buffer, 0, read);
        return ms.ToArray();
    }
}
}

This is my MainActivity.cs

using System;
using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.OS;
using AndroidX.Core.App;
using AndroidX.Core.Content;
using MediaManager;
using Android;
using LibVLCSharp.Forms.Shared;
using Android.Content;
using System.Threading.Tasks;
using Xamarin.Forms;
using Android.Gms.Extensions;
using Plugin.Toast;

[assembly: Dependency(typeof(FirebaseAuthenticator))]

namespace AbuseAlert.Droid
{

[Activity(Label = "AbuseAlert", Icon = "@drawable/icon", Theme = "@style/MainTheme", 
MainLauncher = false, ConfigurationChanges = ConfigChanges.ScreenSize | 
 ConfigChanges.Orientation)]

public class MainActivity : 
global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
    public event EventHandler<ActivityResultEventArgs> ActivityResult = delegate { };
    protected override void OnCreate(Bundle savedInstanceState)
    {
        TabLayoutResource = Abuse_Alert.Droid.Resource.Layout.Tabbar;
        ToolbarResource = Abuse_Alert.Droid.Resource.Layout.Toolbar;

        base.OnCreate(savedInstanceState);
        
        CrossMediaManager.Current.Init(this);

        LibVLCSharpFormsRenderer.Init();

        Xamarin.Essentials.Platform.Init(this, savedInstanceState);
        global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
        LoadApplication(new App());

        if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.RecordAudio) != Permission.Granted)
        {
            ActivityCompat.RequestPermissions(this, new String[] { Manifest.Permission.RecordAudio }, 1);
        }

        FormsVideoPlayer.Init();
    }
    public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
    {
        Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);

        base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
    }

    protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
    {
        ActivityResult(this, new ActivityResultEventArgs
        {
            RequestCode = requestCode,
            ResultCode = resultCode,
            Data = data
        });

    }

}

So, what is causing my .gif file (AbuseAlert.gif) which is already in the resources/drawable folder not to render properly?

[ad_2]

Source link

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments