Exemplo n.º 1
0
 private byte[] LoadBytesFromStream(string assetsPath, Android.Content.Res.AssetManager assets)
 {
     byte[] bytes;
     using (var assetStream = assets.Open(assetsPath)){
         using (var memoryStream = new MemoryStream()){
             assetStream.CopyTo(memoryStream);
             bytes = memoryStream.ToArray();
         }
     }
     return(bytes);
 }
Exemplo n.º 2
0
        public static string ReadHtml(Android.Content.Res.AssetManager assets)
        {
            var body = "";

            using (var stream = assets.Open("content.html"))
            {
                StreamReader sr = new StreamReader(stream);
                body = sr.ReadToEnd();
                sr.Close();
                sr.Dispose();
            }
            return(body);
        }
Exemplo n.º 3
0
        public static string FileToString(string filename)
        {
            string contents = "";
#if __ANDROID__
      Android.Content.Res.AssetManager assets = MainActivity.TheView.Assets;
      using (StreamReader sr = new StreamReader(assets.Open(filename))) {
        contents = sr.ReadToEnd();
      }
#elif __IOS__
            string[] lines = System.IO.File.ReadAllLines(filename);
            contents = string.Join("\n", lines);
#endif
            return contents;
        }
Exemplo n.º 4
0
 private static bool copyAsset(Android.Content.Res.AssetManager assetManager, String fromAssetPath, String toPath)
 {
     try
     {
         using (var input = assetManager.Open(fromAssetPath))
             using (var output = new System.IO.FileStream(toPath, System.IO.FileMode.Create, System.IO.FileAccess.Write))
             {
                 input.CopyTo(output);
             }
         return(true);
     }
     catch (Java.Lang.Exception e)
     {
         e.PrintStackTrace();
         return(false);
     }
 }
Exemplo n.º 5
0
 private string GetResourceString(string ResourceName)
 {
     try
     {
         string content;
         Android.Content.Res.AssetManager assets = this.Assets;
         using (System.IO.StreamReader sr = new System.IO.StreamReader(assets.Open(ResourceName)))
         {
             content = sr.ReadToEnd();
         }
         return(content);
     }
     catch
     {
         throw new Exception("Could not read Resource file!");
     }
 }
Exemplo n.º 6
0
        public static Texture2D GetDefaultFontTexture(GraphicsDevice graphicsDevice)
        {
#if ANDROID
            var activity = FlatRedBallServices.Game.Services.GetService<Android.App.Activity>();

            if(activity == null)
            {
                string message =
                    "As of July 2017, FlatRedBall Android performs a much faster loading of the default font. This requires a change to the Activity1.cs file. You can look at a brand-new Android template to see the required changes.";

                throw new NullReferenceException(message);
            }


            Android.Content.Res.AssetManager androidAssetManager = activity.Assets;
            Texture2D texture;

            try
            {

                using (var stream = androidAssetManager.Open("content/defaultfonttexture.png"))
                {
                    texture = Texture2D.FromStream(graphicsDevice, stream);
                }
            }
            catch
            {
                throw new Exception("The file defaultfonttexture.png in the game's content folder is missing. If you are missing this file, look at the default Android template to see where it should be added (in Assets/content/)");
            }

#else


            var colors = DefaultFontDataColors.GetColorArray();

            Texture2D texture = new Texture2D(graphicsDevice, 256, 128);

			texture.SetData<Microsoft.Xna.Framework.Color>(colors);

#endif

            return texture;
        }
        /// <summary>
        /// Reads the contents of a text file stored in the app's bundle based on the specified <paramref name="path"/>
        /// </summary>
        /// <param name="path">The file and subfolder path relative to the platform's bundle.
        /// The file needs to be located at a path inside "Assets" for Android and "Resources" for iOS</param>
        /// <returns></returns>
        public static string GetBundledTextFileContent(string path)
        {
#if __IOS__
            var    iosPath = Path.Combine(GetApplicationBundlePath(), path);
            string text;
            using (StreamReader sr = new StreamReader(iosPath))
            {
                text = sr.ReadToEnd();
            }
            return(text);
#elif __ANDROID__
            string text;
            Android.Content.Res.AssetManager assets = Android.App.Application.Context.Assets;
            using (StreamReader sr = new StreamReader(assets.Open(path)))
            {
                text = sr.ReadToEnd();
            }
            return(text);
#endif
        }
Exemplo n.º 8
0
        public static void LoadLecturers()
        {
            Android.Content.Res.AssetManager assets = Android.App.Application.Context.Assets;
            using (StreamReader reader = new StreamReader(assets.Open("Lecturers.txt")))
            {
                string   text      = reader.ReadToEnd();
                string[] fileLines = text.Split(new[] { Environment.NewLine }, StringSplitOptions.None);

                fileLines.Where(x => !string.IsNullOrEmpty(x)).ToArray();

                for (int i = 0; i + 1 < fileLines.Length; i += 2)
                {
                    lecturers.Add(new Lecturer
                    {
                        Id = Int32.Parse(fileLines[i].Trim()),
                        //Name = fileLines[i + 1].Trim(),
                    });
                }
            }
        }
Exemplo n.º 9
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            var ContentHeader = FindViewById <TextView>(Resource.Id.ContentHeader);

            ContentHeader.Text = GetText(Resource.String.ContentHeader);

            var ClickMe      = FindViewById <Button>(Resource.Id.ClickMe);
            var btnvalidar   = FindViewById <Button>(Resource.Id.Validar);
            var ClickCounter = FindViewById <TextView>(Resource.Id.ClickCounter);

            ClickMe.Click += (sender, e) =>
            {
                counter++;
                ClickCounter.Text = Resources.GetQuantityString(
                    Resource.Plurals.numberOfClicks, counter, counter);

                var player = Android.Media.MediaPlayer.Create(
                    this, Resource.Raw.sound);

                player.Start();
            };

            btnvalidar.Click += (sender, e) =>
            {
                StartActivity(typeof(Validar));
            };


            Android.Content.Res.AssetManager man = this.Assets;

            using (var Reader =
                       new System.IO.StreamReader(man.Open("Contenido.txt")))
            {
                ContentHeader.Text += $"\n\n{Reader.ReadToEnd()}";
            }
        }
Exemplo n.º 10
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.Main);

            var ContentHeader = FindViewById<TextView>(Resource.Id.ContentHeader);
            ContentHeader.Text = GetText(Resource.String.ContentHeader);

            var ClickMe = FindViewById<Button>(Resource.Id.ClickMe);
            var ClickCounter = FindViewById<TextView>(Resource.Id.ClickCounter);

            ClickMe.Click += (s, e) =>
            {
                Counter++;
                ClickCounter.Text = Resources.GetQuantityString(
                    Resource.Plurals.numberOfClicks, Counter, Counter);

                var Player = Android.Media.MediaPlayer.Create(
                    this, Resource.Raw.sound);
                Player.Start();
            };

            Android.Content.Res.AssetManager Manager = this.Assets;

            using (var Reader =
                new System.IO.StreamReader(Manager.Open("Contenido.txt")))
            {
                ContentHeader.Text += $"\n\n{Reader.ReadToEnd()}";
            }

            var btnIrAValidar = FindViewById<Button>(Resource.Id.btnIrAValidar);

            btnIrAValidar.Click += (s, e) =>
            {
                var intent = new Intent(this, typeof(ValidateActivity));

                StartActivity(intent);
            };
        }
Exemplo n.º 11
0
        public static string ReadHtml(Android.Content.Res.AssetManager assets)
        {
            string content = string.Empty;

            try
            {
                using (var stream = assets.Open("content.html"))
                {
                    StreamReader sr = new StreamReader(stream);
                    content = sr.ReadToEnd();
                    sr.Close();
                    sr.Dispose();
                    return(content);
                }
            }
            catch (Exception ex)
            {
                //todo 异常处理
                return(content);
            }
        }
Exemplo n.º 12
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            var Intent = new Android.Content.Intent(this, typeof(DisenioAndroid));

            var ContentHeader = FindViewById <TextView>(Resource.Id.ContentHeader);

            ContentHeader.Text = GetText(Resource.String.ContentHeader);

            var ClickMe      = FindViewById <Button>(Resource.Id.ClickMe);
            var ClickCounter = FindViewById <TextView>(Resource.Id.ClickCounter);

            ClickMe.Click += (s, e) =>
            {
                Counter++;
                //valor a mostrar y valor que permitira a andorid cual cadena utilizar
                ClickCounter.Text = Resources.GetQuantityString(Resource.
                                                                Plurals.numberOfClicks, Counter, Counter);

                var Player = Android.Media.MediaPlayer.Create(this, Resource.
                                                              Raw.sound);

                Player.Start();
                Android.Content.Res.AssetManager Manager = this.Assets;

                using (var Reader = new System.IO.StreamReader(Manager.Open("Contenido.txt")))
                {
                    ContentHeader.Text += $"\n\n{Reader.ReadToEnd()}";


                    StartActivity(Intent);
                }
            };
        }
Exemplo n.º 13
0
        partial void ReadFileFromAssets(string file, ref List <byte> result)
        {
            file = file.Replace(EngineNS.CEngine.Instance.FileManager.ProjectRoot, "").ToLower();
            Android.Runtime.InputStreamInvoker stream = (Android.Runtime.InputStreamInvoker)AssetManager.Open(file);

            Type type = stream.GetType();
            int  len  = stream.BaseInputStream.Available();

            if (stream != null || len > 0)
            {
                byte[] bytes = new byte[len];
                stream.Read(bytes, 0, len);
                stream.Close();

                result.AddRange(bytes);
            }
        }