UsActivity.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. package com.ivalentin.margolariak;
  2. import android.annotation.SuppressLint;
  3. import android.app.Activity;
  4. import android.app.Dialog;
  5. import android.graphics.drawable.Drawable;
  6. import android.os.Bundle;
  7. import android.view.Gravity;
  8. import android.view.View;
  9. import android.view.Window;
  10. import android.view.WindowManager;
  11. import android.widget.Button;
  12. import android.widget.ImageView;
  13. import android.widget.LinearLayout;
  14. import android.widget.TextView;
  15. import java.io.File;
  16. /**
  17. * Activity with info about Gasteizko margolariak.
  18. *
  19. * @author Iñigo Valentin
  20. *
  21. * @see Activity
  22. *
  23. */
  24. public class UsActivity extends Activity {
  25. /**
  26. * Runs when the activity is created.
  27. *
  28. * @param savedInstanceState Saved state of the activity.
  29. * @see Activity#onCreate(Bundle)
  30. */
  31. @SuppressLint("InflateParams")
  32. @Override
  33. protected void onCreate(Bundle savedInstanceState) {
  34. //Remove title bar.
  35. this.requestWindowFeature(Window.FEATURE_NO_TITLE);
  36. super.onCreate(savedInstanceState);
  37. //Set layout.
  38. setContentView(R.layout.activity_us);
  39. //Assign layout items
  40. LinearLayout llCuadrilla = (LinearLayout) findViewById(R.id.ll_us_cuadrilla);
  41. LinearLayout llAssociation = (LinearLayout) findViewById(R.id.ll_us_asociacion);
  42. LinearLayout llActivities = (LinearLayout) findViewById(R.id.ll_us_activities);
  43. LinearLayout llTransparency = (LinearLayout) findViewById(R.id.ll_us_transparency);
  44. //Set onClick listeners.
  45. llCuadrilla.setOnClickListener(new View.OnClickListener() {
  46. @Override
  47. public void onClick(View v) {
  48. openDialog(getString(R.string.us_cuadrilla), getString(R.string.us_cuadrilla_content), getResources().getDrawable(R.drawable.us_cuadrilla));
  49. }
  50. });
  51. llAssociation.setOnClickListener(new View.OnClickListener() {
  52. @Override
  53. public void onClick(View v) {
  54. openDialog(getString(R.string.us_association), getString(R.string.us_association_content), getResources().getDrawable(R.drawable.us_asociacion));
  55. }
  56. });
  57. llActivities.setOnClickListener(new View.OnClickListener() {
  58. @Override
  59. public void onClick(View v) {
  60. openDialog(getString(R.string.us_activities), getString(R.string.us_activities_content), getResources().getDrawable(R.drawable.us_activities));
  61. }
  62. });
  63. llTransparency.setOnClickListener(new View.OnClickListener() {
  64. @Override
  65. public void onClick(View v) {
  66. openDialog(getString(R.string.us_transparency), getString(R.string.us_transparency_content), getResources().getDrawable(R.drawable.us_transparency));
  67. }
  68. });
  69. }
  70. /**
  71. * Shows a dialog with expanded info.
  72. *
  73. * @param title The event id.
  74. * @param text The dialog text.
  75. * @param img The dialog image.
  76. */
  77. @SuppressWarnings("ConstantConditions")
  78. private void openDialog(final String title, final String text, final Drawable img){
  79. //Create the dialog
  80. final Dialog dialog = new Dialog(this);
  81. //Set up dialog window
  82. dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
  83. dialog.setContentView(R.layout.dialog_us);
  84. //Set the custom dialog components - text, image and button
  85. TextView tvTitle = (TextView) dialog.findViewById(R.id.tv_dialog_us_title);
  86. TextView tvText = (TextView) dialog.findViewById(R.id.tv_dialog_us_text);
  87. ImageView ivImage = (ImageView) dialog.findViewById(R.id.iv_dialog_us_image);
  88. Button btClose = (Button) dialog.findViewById(R.id.bt_dialog_us_close);
  89. //Set text fields
  90. tvTitle.setText(title);
  91. tvText.setText(text);
  92. //Set image
  93. ivImage.setImageDrawable(img);
  94. //Set close button
  95. btClose.setOnClickListener(new View.OnClickListener() {
  96. @Override
  97. public void onClick(View v) {
  98. dialog.dismiss();
  99. }
  100. });
  101. //Show the dialog
  102. WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
  103. lp.copyFrom(dialog.getWindow().getAttributes());
  104. lp.width = WindowManager.LayoutParams.MATCH_PARENT;
  105. lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
  106. lp.gravity = Gravity.CENTER;
  107. dialog.getWindow().setAttributes(lp);
  108. //Show dialog
  109. dialog.show();
  110. }
  111. /**
  112. * Not called from code, but referenced from activity_sponsor.xml.
  113. * Finishes the activity.
  114. *
  115. * @param v Ignored
  116. *
  117. * @see Activity#finish()
  118. */
  119. public void finish(View v){
  120. finish();
  121. }
  122. }