Skip to content

Commit

Permalink
Recupera la rotacion de pantalla, pero mantiene el numero de veces qu…
Browse files Browse the repository at this point in the history
…e se ha pulsado el boton no tocar.

Esta version recupera la posibilidad de rotar la pantalla, pero ahora, cuando esta rota, el sistema recuerda el numero de veces
que se ha pulsado el boton no tocar.
  • Loading branch information
Wewannado committed Sep 28, 2016
1 parent 0f8db20 commit c3d24d0
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.exemple.profedam.aboutrobots2017;
package com.exemple.rogergcoscojuela.aboutrobots2017;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.exemple.profedam.aboutrobots2017">
package="com.exemple.rogergcoscojuela.aboutrobots2017">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".RobotActivity"
android:screenOrientation="portrait">
<activity android:name="com.exemple.rogergcoscojuela.aboutrobots2017.RobotActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.exemple.profedam.aboutrobots2017;
package com.exemple.rogergcoscojuela.aboutrobots2017;

import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
Expand Down Expand Up @@ -36,6 +36,11 @@ protected void onCreate(Bundle savedInstanceState) {
ImageButton btnSalir = (ImageButton) findViewById(R.id.imageButtonSalir);
btnSalir.setOnClickListener(this);

if (savedInstanceState != null){
this.numeroVeces= savedInstanceState.getInt("numeroVeces");
}
refrescaPantalla();

// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
Expand All @@ -49,28 +54,28 @@ protected void onCreate(Bundle savedInstanceState) {
public void onClick(View v) {

if (v.getId()==R.id.btnNoTocar) {
Button btnNoTocar = (Button) v;
TextView cajaTexto = (TextView) findViewById(R.id.textView);
ImageView imageRob = (ImageView) findViewById(R.id.imageView);
numeroVeces++;
if (numeroVeces == 1) {
btnNoTocar.setText("¡Que no me toques!!!");
cajaTexto.setText("Parece ser que los humanos no son muy inteligentes");
imageRob.setImageResource(R.mipmap.robot_enfadado);
}

if (numeroVeces == 2) {
btnNoTocar.setVisibility(View.INVISIBLE);
cajaTexto.setText("Te lo advertí!");
imageRob.setImageResource(R.mipmap.robot_fumando);
}
refrescaPantalla();
}
if (v.getId() == R.id.imageButtonSalir) {
finish();

}
}
public void refrescaPantalla(){
Button btnNoTocar = (Button) findViewById(R.id.btnNoTocar);
TextView cajaTexto = (TextView) findViewById(R.id.textView);
ImageView imageRob = (ImageView) findViewById(R.id.imageView);
if (numeroVeces == 1) {
btnNoTocar.setText("¡Que no me toques!!!");
cajaTexto.setText("Parece ser que los humanos no son muy inteligentes");
imageRob.setImageResource(R.mipmap.robot_enfadado);
}


if (numeroVeces == 2) {
btnNoTocar.setVisibility(View.INVISIBLE);
cajaTexto.setText("Te lo advertí!");
imageRob.setImageResource(R.mipmap.robot_fumando);
}
}

/**
Expand All @@ -89,6 +94,13 @@ public Action getIndexApiAction() {
.build();
}

@Override
protected void onSaveInstanceState (Bundle outState){
super.onSaveInstanceState(outState);
outState.putInt("numeroVeces", this.numeroVeces);
}


@Override
public void onStart() {
super.onStart();
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_robot.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.exemple.profedam.aboutrobots2017.RobotActivity">
tools:context="com.exemple.rogergcoscojuela.aboutrobots2017.RobotActivity">

<TextView
android:layout_width="wrap_content"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.exemple.profedam.aboutrobots2017;
package com.exemple.rogergcoscojuela.aboutrobots2017;

import org.junit.Test;

Expand Down

0 comments on commit c3d24d0

Please sign in to comment.