Symmetry of lettersPicture for animationRotateVerticalHorizontalNextRandomEnter"?""Rotational symmetry: ""Reflective symmetry about a vertical axis: ""Rotational symmetry about a horizontal axis: ""Is this letter symmetrical? Click on buttons to find out."
app/res/layout/activity_main.xml - screen format
app/res/values/rotate.xml - animation for demonstrating OK rotate - rotate, then a light enlarge and reduce
app/res/values/rotatex.xml - animation for demonstrating not OK rotate - rotate, then disappear into distance (throw away!)
app/res/values/vertical.xml - animation for demonstrating OK reflect about a vertical axis - reflect, then a light enlarge and reduce
app/res/values/verticallx.xml - animation for demonstrating not OK reflect about a vertical axis - reflect, then disappear into distance (throw away!)
app/res/values/horizontal.xml - animation for demonstrating OK reflect about a horizontal axis - reflect, then a light enlarge and reduce
app/res/values/horizontalx.xml - animation for demonstrating not OK reflect about a horizontal axis - reflect, then disappear into distance (throw away!)
app/java/com.(the project name)/MainActivity - main code for app
package com.edkins.symmetryofletters;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.Random;
public class MainActivity extends AppCompatActivity {
public static int current = 0;
public static int ok = 1;
static Random myRand = new Random();
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ok = 1; current = 0;
doNew();
}
public void doRotate(View view) {
if (ok==0) {return;}
ImageView pic = (ImageView) findViewById(R.id.pic);
if (rotate[current] == 1) {
Animation anim = AnimationUtils.loadAnimation(this, R.anim.rotate);
anim.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationStart(Animation animation) {ok=0;}
public void onAnimationRepeat(Animation animation) {}
public void onAnimationEnd(Animation animation) {
ok=1;
TextView line = (TextView) findViewById(R.id.rotateContent);
line.setText("Yes");
}
});
pic.startAnimation(anim);
}
else {
Animation anim = AnimationUtils.loadAnimation(this, R.anim.rotatex);
anim.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationStart(Animation animation) {ok=0;}
public void onAnimationRepeat(Animation animation) {}
public void onAnimationEnd(Animation animation) {
ok=1;
TextView line = (TextView) findViewById(R.id.rotateContent);
line.setText("No");
}
});
pic.startAnimation(anim);
}
}
public void doVertical(View view) {
if (ok==0) {return;}
ImageView pic = (ImageView) findViewById(R.id.pic);
if (vertical[current] == 1) {
Animation anim = AnimationUtils.loadAnimation(this, R.anim.vertical);
anim.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationStart(Animation animation) {ok=0;}
public void onAnimationRepeat(Animation animation) {}
public void onAnimationEnd(Animation animation) {
ok=1;
TextView line = (TextView) findViewById(R.id.verticalContent);
line.setText("Yes");}
});
pic.startAnimation(anim);
}
else {
Animation anim = AnimationUtils.loadAnimation(this, R.anim.verticalx);
anim.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationStart(Animation animation) {ok=0;}
public void onAnimationRepeat(Animation animation) {}
public void onAnimationEnd(Animation animation) {
ok=1;
TextView line = (TextView) findViewById(R.id.verticalContent);
line.setText("No");
}
});
pic.startAnimation(anim);
}
}
public void doHorizontal(View view) {
if (ok==0) {return;}
ImageView pic = (ImageView) findViewById(R.id.pic);
if (horizontal[current] == 1) {
Animation anim = AnimationUtils.loadAnimation(this, R.anim.horizontal);
anim.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationStart(Animation animation) {ok=0;}
public void onAnimationRepeat(Animation animation) {}
public void onAnimationEnd(Animation animation) {
ok=1;
TextView line = (TextView) findViewById(R.id.horizontalContent);
line.setText("Yes");
}
});
pic.startAnimation(anim);
}
else {
Animation anim = AnimationUtils.loadAnimation(this, R.anim.horizontalx);
anim.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationStart(Animation animation) {ok=0;}
public void onAnimationRepeat(Animation animation) {}
public void onAnimationEnd(Animation animation) {
ok=1;
TextView line = (TextView) findViewById(R.id.horizontalContent);
line.setText("No");
}
});
pic.startAnimation(anim);
}
}
public void doNew() {
if (ok==0) {return;}
ImageView pic = (ImageView) findViewById(R.id.pic);
pic.setImageResource(start[current]);
TextView line1 = (TextView) findViewById(R.id.rotateContent);
line1.setText("?");
TextView line2 = (TextView) findViewById(R.id.verticalContent);
line2.setText("?");
TextView line3 = (TextView) findViewById(R.id.horizontalContent);
line3.setText("?");
}
public void doNext(View view) {
if (ok==0) {return;}
current++;
if (current>25) {current = 0;}
doNew();
}
public void doRandom(View view) {
if (ok==0) {return;}
int old = current;
while (old==current) {current = myRand.nextInt(26);}
doNew();
}
public static int [] start = {
R.drawable.a, R.drawable.b, R.drawable.c, R.drawable.d, R.drawable.e,
R.drawable.f, R.drawable.g, R.drawable.h, R.drawable.i, R.drawable.j,
R.drawable.k, R.drawable.l, R.drawable.m, R.drawable.n, R.drawable.o,
R.drawable.p, R.drawable.q, R.drawable.r, R.drawable.s, R.drawable.t,
R.drawable.u, R.drawable.v, R.drawable.w, R.drawable.x, R.drawable.y,
R.drawable.z,
};
public static int [] rotate = {
0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1
};
public static int [] vertical = {
1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0
};
public static int [] horizontal = {
0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0
};
}
Index to my other websites