private IEnumerator WriteFile(Texture2D tex) { var fileName = "Screenshot" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".png"; var path = Utils.GetWriteFolderPath(tex.name); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path += fileName; var bytes = tex.EncodeToPNG(); #if UNITY_ANDROID //var bytes = tex.GetRawTextureData(); File.WriteAllBytes(path, bytes); yield return(new WaitForEndOfFrame()); while (!File.Exists(path)) { yield return(new WaitForEndOfFrame()); } UtilsAndroid.ScanFile(path, null); #else Debug.Log("WriteFile"); File.WriteAllBytes(path, bytes); yield return(null); #endif }
private void BtnTales_Click(object sender, EventArgs e) { string nameArchiveAbsolutePath = ((Button)sender).Text; string nameArchive = UtilsAndroid.ChangeToRelativePath(nameArchiveAbsolutePath); pathTale = this.ApplicationInfo.DataDir + "/files" + "/VS" + "/" + nameArchive; var intent = new Intent(this, typeof(ActivityTale)); intent.PutExtra("path", JsonConvert.SerializeObject(pathTale)); StartActivity(intent); }
public void loadTaleDownloadData(Object sender) { string nameArchiveAbsolutePath = ((Button)sender).Text; string nameArchiveWithExtension = UtilsAndroid.ChangeToRelativePath(nameArchiveAbsolutePath); int tamNnameArchiveWithExtension = nameArchiveWithExtension.Length; string nameArchive = nameArchiveWithExtension.Substring(0, tamNnameArchiveWithExtension - 5); string documentsPath = this.ApplicationInfo.DataDir + "/files" + "/VS"; if (!Directory.Exists(documentsPath)) { Directory.CreateDirectory(documentsPath); } if (!Directory.Exists(documentsPath + "/" + nameArchive)) { File.Copy(nameArchiveAbsolutePath, System.IO.Path.Combine(documentsPath, nameArchiveWithExtension)); File.Copy(System.IO.Path.Combine(documentsPath, nameArchiveWithExtension), System.IO.Path.Combine(documentsPath, nameArchive + ".zip")); pathTale = documentsPath + "/" + nameArchive; if (!Directory.Exists(pathTale)) { Directory.CreateDirectory(pathTale); } FastZip zip = new FastZip(); zip.ExtractZip(System.IO.Path.Combine(documentsPath, nameArchive + ".zip"), pathTale, null); File.Delete(System.IO.Path.Combine(documentsPath, nameArchiveWithExtension)); File.Delete(pathTale + ".zip"); var intent = new Intent(this, typeof(ActivityTale)); intent.PutExtra("path", JsonConvert.SerializeObject(pathTale)); StartActivity(intent); } else { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.SetTitle("Advertencia"); alert.SetMessage("Este cuento está precargado"); alert.Show(); } }
private void UpdateTaleAndroidGUI() { mediaPlayerTale.Stop(); frmLytFrontPage.SetBackgroundColor(Color.WhiteSmoke); frmLytFrontPage.SetBackgroundResource(0); imgBackgroundPage.SetImageBitmap(null); if (taleManager != null) { lblFrontPage.Text = taleManager.Title; //-- Background String background = taleManager.Background; int tamBackground = background.Length; if (tamBackground > 0) { if (UtilsAndroid.isArchive(background)) { UtilsImageAndroid.SetImage(background, imgBackgroundFrontPage); } if (background.Contains("#")) { frmLytFrontPage.SetBackgroundColor(Color.ParseColor(background)); } } if (taleManager.Music != "") { mediaPlayerTale = MediaPlayer.Create(this, Android.Net.Uri.Parse(taleManager.Music)); mediaPlayerTale.Start(); } } Application.Dispose(); Application.OnTrimMemory(TrimMemory.RunningCritical); }
private void ChangeToAbsolutePathAndroid2(String location) { //cuento if (taleManager.Background != "" && UtilsAndroid.isArchive(taleManager.Background)) { taleManager.Background = location + "/Imagenes/0/" + taleManager.Background; } if (taleManager.Music != "" && UtilsAndroid.isArchive(taleManager.Music)) { taleManager.Music = location + "/Audios/0/" + taleManager.Music; } //páginas foreach (Page page in taleManager.GetPages) { int numPage = page.Index + 1; if (page.Background != "" && UtilsAndroid.isArchive(page.Background)) { page.Background = location + "/Imagenes/" + numPage + "/" + page.Background; } if (page.Music != "" && UtilsAndroid.isArchive(page.Music)) { page.Music = location + "/Audios/" + numPage + "/" + page.Music; } foreach (Pictogram picto in page.Pictograms) { if (picto.ImageName != "" && UtilsAndroid.isArchive(picto.ImageName)) { picto.ImageName = location + "/Imagenes/" + numPage + "/" + picto.ImageName; } if (picto.Sound != "" && UtilsAndroid.isArchive(picto.Sound)) { picto.Sound = location + "/Audios/" + numPage + "/" + picto.Sound; } } } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); pathTale = ""; items = JsonConvert.DeserializeObject <List <string> >(Intent.GetStringExtra("dir")); if (items.Count() >= 0) { if (items.Count() <= 7) { var layout = new LinearLayout(this); layout.Orientation = Orientation.Vertical; layout.SetGravity(GravityFlags.Center); for (int i = 0; i < items.Count; i++) { var layoutH = new LinearLayout(this); layoutH.SetGravity(GravityFlags.Center); layoutH.SetBackgroundColor(Color.ParseColor("#fffff0")); layoutH.SetPadding(5, 5, 5, 5); btnTales = new Button(this); string nameArchiveAbsolutePath = items[i]; nameArchiveClick = UtilsAndroid.ChangeToRelativePath(nameArchiveAbsolutePath); btnTales.Text = nameArchiveClick; btnTales.SetPadding(20, 20, 20, 20); btnTales.SetTextSize(Android.Util.ComplexUnitType.Sp, 18); btnTales.SetTypeface(null, TypefaceStyle.Bold); btnTales.SetTextColor(Color.ParseColor("#000000")); btnTales.Id = i; btnDelete = new Button(this); btnDelete.Text = "Eliminar"; btnDelete.SetPadding(20, 20, 20, 20); btnDelete.SetTextSize(Android.Util.ComplexUnitType.Sp, 18); btnDelete.SetTypeface(null, TypefaceStyle.Bold); btnTales.SetTextColor(Color.ParseColor("#000000")); btnDelete.Id = i; layoutH.AddView(btnTales); layoutH.AddView(btnDelete); layout.AddView(layoutH); btnTales.Click += BtnTales_Click; btnDelete.Click += BtnDelete_Click; } SetContentView(layout); } else { SetContentView(Resource.Layout.preloadTale); //Obtenemos el linear layout donde colocar los botones LinearLayout llBotonera = FindViewById <LinearLayout>(Resource.Id.llBotonera2); //llBotonera.SetBackgroundColor(Color.AntiqueWhite); llBotonera.SetGravity(GravityFlags.Center); //Creamos las propiedades de layout que tendrán los botones. //Son LinearLayout.LayoutParams porque los botones van a estar en un LinearLayout. LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.WrapContent); lp.SetMargins(5, 5, 5, 5); lp.Gravity = GravityFlags.CenterVertical; for (int i = 0; i < items.Count; i++) { var layoutH = new LinearLayout(this); layoutH.SetGravity(GravityFlags.Center); layoutH.SetBackgroundColor(Color.ParseColor("#fffff0")); btnTales = new Button(this); string nameArchiveAbsolutePath = items[i]; nameArchiveClick = UtilsAndroid.ChangeToRelativePath(nameArchiveAbsolutePath); btnTales.Text = nameArchiveClick; btnTales.SetPadding(20, 20, 20, 20); btnTales.SetTextSize(Android.Util.ComplexUnitType.Sp, 18); btnTales.SetTypeface(null, TypefaceStyle.Bold); btnTales.SetTextColor(Color.ParseColor("#000000")); btnTales.Id = i; btnDelete = new Button(this); btnDelete.Text = "Eliminar"; btnDelete.SetPadding(20, 20, 20, 20); btnDelete.SetTextSize(Android.Util.ComplexUnitType.Sp, 18); btnDelete.SetTypeface(null, TypefaceStyle.Bold); btnTales.SetTextColor(Color.ParseColor("#000000")); btnDelete.Id = i; layoutH.AddView(btnTales); layoutH.AddView(btnDelete); //Asignamos propiedades del layout al layout layoutH.LayoutParameters = lp; //Añadimos el layout a la botonera llBotonera.AddView(layoutH); btnTales.Click += BtnTales_Click; btnDelete.Click += BtnDelete_Click; } } } else { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.SetTitle("Advertencia"); alert.SetMessage("No hay cuentos precargados"); alert.Show(); SetContentView(Resource.Layout.Main); var intent = new Intent(this, typeof(MainActivity)); StartActivity(intent); } }