/
MainActivity.cs
121 lines (117 loc) · 6.45 KB
/
MainActivity.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using Android.App;
using Android.OS;
using Android.Support.V7.App;
using Android.Runtime;
using Android.Widget;
namespace Fragments
{
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
public class MainActivity : AppCompatActivity, IEstadoSeleccionado, ICiudadSeleccionada
{
bool contiene = false;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);
if (savedInstanceState != null)
contiene = savedInstanceState.ContainsKey("horizontal-first");
FrameLayout contenedor = FindViewById<FrameLayout>(Resource.Id.contenedorFragment);
if (contenedor != null)
{
Android.Support.V4.App.Fragment estados = SupportFragmentManager.FindFragmentById(Resource.Id.estados);
if (savedInstanceState == null || estados == null || contiene)
{
estados = new EstadosFragment();
SupportFragmentManager.BeginTransaction().Add(Resource.Id.contenedorFragment, estados).Commit();
}
}
SupportFragmentManager.BackStackChanged += delegate {
OnBackStackChanged();
};
OnBackStackChanged();
}
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);
}
public void OnEstadoSeleccionado(string[] ciudades)
{
FrameLayout contenedor = FindViewById<FrameLayout>(Resource.Id.contenedorFragment);
if (contenedor != null)
{
Bundle args = new Bundle();
args.PutStringArray("ciudades", ciudades);
CiudadesFragment ciudadesFragment = new CiudadesFragment();
ciudadesFragment.Arguments = args;
//SupportFragmentManager.BeginTransaction().Replace(Resource.Id.contenedorFragment, ciudadesFragment).SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentOpen).AddToBackStack(null).Commit();
//SupportFragmentManager.BeginTransaction().SetTransition(Android.Support.V4.App.FragmentTransaction.TransitExitMask).Replace(Resource.Id.contenedorFragment, ciudadesFragment).AddToBackStack(null).Commit();
SupportFragmentManager.BeginTransaction().SetCustomAnimations(
Resource.Animator.voltear_a_la_derecha_in,
Resource.Animator.voltear_a_la_derecha_out,
Resource.Animator.voltear_a_la_izquierda_in,
Resource.Animator.voltear_a_la_izquierda_out
).Replace(Resource.Id.contenedorFragment, ciudadesFragment).AddToBackStack(null).Commit();
}
else
{
var ciudadesFragment = SupportFragmentManager.FindFragmentById(Resource.Id.ciudades) as CiudadesFragment;
ciudadesFragment.updateCiudades(ciudades);
}
}
public void OnCiudadSeleccionada(string[] ciudades)
{
FrameLayout contenedor = FindViewById<FrameLayout>(Resource.Id.contenedorFragment);
InformacionFragment informacion = new InformacionFragment();
if (contenedor != null)
{
Bundle args = new Bundle();
args.PutStringArray("ciudades", ciudades);
informacion = new InformacionFragment();
informacion.Arguments = args;
//SupportFragmentManager.BeginTransaction().Replace(Resource.Id.contenedorFragment, informacion).SetTransition(Android.Support.V4.App.FragmentTransaction.TransitFragmentOpen).AddToBackStack(null).Commit();
//SupportFragmentManager.BeginTransaction().SetTransition(Android.Support.V4.App.FragmentTransaction.TransitUnset).Replace(Resource.Id.contenedorFragment, contentDetallesCiudad).AddToBackStack(null).Commit();
SupportFragmentManager.BeginTransaction().SetCustomAnimations(
Resource.Animator.voltear_a_la_derecha_in,
Resource.Animator.voltear_a_la_derecha_out,
Resource.Animator.voltear_a_la_izquierda_in,
Resource.Animator.voltear_a_la_izquierda_out
).Replace(Resource.Id.contenedorFragment, informacion).AddToBackStack(null).Commit();
}
else
{
var informacionFragment = SupportFragmentManager.FindFragmentById(Resource.Id.Informacion) as InformacionFragment;
informacionFragment.View.SetBackgroundResource(Resource.Drawable.propiedades);
if (ciudades[0] == "Aguascalientes")
informacionFragment.View.SetBackgroundResource(Resource.Drawable.Aguascalientes);
if (ciudades[0] == "Calvillo")
informacionFragment.View.SetBackgroundResource(Resource.Drawable.Calvillo);
//android:background="#ddffffff"
//LinearLayout l = (LinearLayout)FindViewById(Resource.Id.Informacion);
//l.SetBackgroundResource(Resource.Drawable.propiedades);
informacionFragment.updateInformacion(ciudades);
}
}
protected override void OnSaveInstanceState(Bundle outState)
{
base.OnSaveInstanceState(outState);
FrameLayout contenedor = FindViewById<FrameLayout>(Resource.Id.contenedorFragment);
if (contenedor == null && !contiene)//Se inició en horizontal
outState.PutBoolean("horizontal-first", true);
else
outState.PutBoolean("horizontal-first", false);
}
private void OnBackStackChanged()
{
bool hasBack = SupportFragmentManager.BackStackEntryCount > 0;
SupportActionBar.SetDisplayHomeAsUpEnabled(hasBack);
}
public override bool OnSupportNavigateUp()
{
SupportFragmentManager.PopBackStack();
return true;
}
}
}