Symmetry of letters

A letter appears, You can rotate or reflect it and an animation shows whether it is symmetrical in this way, plus a list of symmetries is built up.

Stringsapp/res/values/strings.xml
Screen formatapp/res/layout/activity_main.xml
Rotate OK definitionapp/res/anim/rotate.xml
Rotate not OK definitionapp/res/anim/rotatex.xml
Vertical reflect OK definitionapp/res/anim/vertical.xml
Vertical reflect OK definitionapp/res/anim/verticalx.xml
Horizontal reflect OK definitionapp/res/anim/horizontal.xml
Horizontal reflect not OK definitionapp/res/anim/horizontalx.xml
Code for appapp/java/com.(the project name)/MainActivity



app/res/drawable - pictures

An image of every letter, plus some buttons




app/res/values/strings.xml - strings

<resources> <string name="app_name">Symmetry of letters</string> <string name="descPic">Picture for animation</string> <string name="rotateText">Rotate</string> <string name="verticalText">Vertical</string> <string name="horizontalText">Horizontal</string> <string name="nextText">Next</string> <string name="randomText">Random</string> <string name="enterText">Enter</string> <string name="query">"?"</string> <string name="rotateMessage">"Rotational symmetry: "</string> <string name="verticalMessage">"Reflective symmetry about a vertical axis: "</string> <string name="horizontalMessage">"Rotational symmetry about a horizontal axis: "</string> <string name="howTo">"Is this letter symmetrical? Click on buttons to find out."</string> </resources>


app/res/layout/activity_main.xml - screen format

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> <TextView android:id="@+id/howToLine" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" android:layout_centerHorizontal="true" android:text="@string/howTo" /> <ImageView android:id="@+id/pic" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" android:layout_width="500dp" android:layout_height="250dp" android:contentDescription="@string/descPic" android:layout_centerHorizontal="true" android:layout_below="@id/howToLine" /> <ImageView android:id="@+id/verticalButton" android:src="@drawable/vertical" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" android:layout_width="100dp" android:layout_height="100dp" android:contentDescription="@string/verticalText" android:onClick="doVertical" android:layout_below="@id/pic" android:layout_centerHorizontal="true" /> <ImageView android:id="@+id/rotateButton" android:src="@drawable/rotate" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" android:layout_width="100dp" android:layout_height="100dp" android:contentDescription="@string/rotateText" android:onClick="doRotate" android:layout_below="@id/pic" android:layout_toLeftOf="@id/verticalButton" android:layout_toStartOf="@id/verticalButton" /> <ImageView android:id="@+id/horizontalButton" android:src="@drawable/horizontal" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" android:layout_width="100dp" android:layout_height="100dp" android:contentDescription="@string/horizontalText" android:onClick="doHorizontal" android:layout_below="@id/pic" android:layout_toRightOf="@id/verticalButton" android:layout_toEndOf="@id/verticalButton" /> <TextView android:id="@+id/rotateLine" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="@dimen/activity_vertical_margin" android:text="@string/rotateMessage" android:layout_below="@id/rotateButton" /> <TextView android:id="@+id/rotateContent" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="@dimen/activity_vertical_margin" android:layout_below="@id/rotateButton" android:layout_toRightOf="@id/rotateLine" android:layout_toEndOf="@id/rotateLine" /> <TextView android:id="@+id/verticalLine" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/verticalMessage" android:layout_below="@id/rotateLine" /> <TextView android:id="@+id/verticalContent" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/rotateLine" android:layout_toRightOf="@id/verticalLine" android:layout_toEndOf="@id/verticalLine" /> <TextView android:id="@+id/horizontalLine" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/horizontalMessage" android:paddingBottom="@dimen/activity_vertical_margin" android:layout_below="@id/verticalLine" /> <TextView android:id="@+id/horizontalContent" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/verticalLine" android:layout_toRightOf="@id/horizontalLine" android:layout_toEndOf="@id/horizontalLine" /> <Button android:id="@+id/nextButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/nextText" android:onClick="doNext" android:layout_below="@id/horizontalLine" /> <Button android:id="@+id/randomButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/randomText" android:onClick="doRandom" android:layout_below="@id/horizontalLine" android:layout_toRightOf="@id/nextButton" android:layout_toEndOf="@id/nextButton" /> </RelativeLayout>


app/res/values/rotate.xml - animation for demonstrating OK rotate - rotate, then a light enlarge and reduce

<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <rotate android:fromDegrees="0" android:toDegrees="180" android:pivotX="50%" android:pivotY="50%" android:duration="1000" /> <scale android:startOffset="1500" android:fromXScale="1.0" android:toXScale="1.1" android:fromYScale="1.0" android:toYScale="1.1" android:pivotX="50%" android:pivotY="50%" android:duration="250" /> <scale android:startOffset="1750" android:fromXScale="1.0" android:toXScale=".9" android:fromYScale="1.0" android:toYScale=".9" android:pivotX="50%" android:pivotY="50%" android:duration="250" /> </set>


app/res/values/rotatex.xml - animation for demonstrating not OK rotate - rotate, then disappear into distance (throw away!)

<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <rotate android:fromDegrees="0" android:toDegrees="180" android:pivotX="50%" android:pivotY="50%" android:duration="1000" /> <scale android:startOffset="2000" android:fromXScale="1.0" android:toXScale="0.0" android:fromYScale="1.0" android:toYScale="0.0" android:pivotX="50%" android:pivotY="50%" android:duration="1000" /> </set>


app/res/values/vertical.xml - animation for demonstrating OK reflect about a vertical axis - reflect, then a light enlarge and reduce

<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:fromXScale="1.0" android:toXScale="-1.0" android:fromYScale="1.0" android:toYScale="1.0" android:pivotX="50%" android:pivotY="50%" android:duration="1000" /> <scale android:startOffset="1500" android:fromXScale="1.0" android:toXScale="1.1" android:fromYScale="1.0" android:toYScale="1.1" android:pivotX="50%" android:pivotY="50%" android:duration="250" /> <scale android:startOffset="1750" android:fromXScale="1.0" android:toXScale=".9" android:fromYScale="1.0" android:toYScale=".9" android:pivotX="50%" android:pivotY="50%" android:duration="250" /> </set>


app/res/values/verticallx.xml - animation for demonstrating not OK reflect about a vertical axis - reflect, then disappear into distance (throw away!)

<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:fromXScale="1.0" android:toXScale="-1.0" android:fromYScale="1.0" android:toYScale="1.0" android:pivotX="50%" android:pivotY="50%" android:duration="1000" /> <scale android:startOffset="2000" android:fromXScale="1.0" android:toXScale="0.0" android:fromYScale="1.0" android:toYScale="0.0" android:pivotX="50%" android:pivotY="50%" android:duration="1000" /> </set>


app/res/values/horizontal.xml - animation for demonstrating OK reflect about a horizontal axis - reflect, then a light enlarge and reduce

<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:fromXScale="1.0" android:toXScale="1.0" android:fromYScale="1.0" android:toYScale="-1.0" android:pivotX="50%" android:pivotY="50%" android:duration="1000" /> <scale android:startOffset="1500" android:fromXScale="1.0" android:toXScale="1.1" android:fromYScale="1.0" android:toYScale="1.1" android:pivotX="50%" android:pivotY="50%" android:duration="250" /> <scale android:startOffset="1750" android:fromXScale="1.0" android:toXScale=".9" android:fromYScale="1.0" android:toYScale=".9" android:pivotX="50%" android:pivotY="50%" android:duration="250" /> </set>


app/res/values/horizontalx.xml - animation for demonstrating not OK reflect about a horizontal axis - reflect, then disappear into distance (throw away!)

<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:fromXScale="1.0" android:toXScale="1.0" android:fromYScale="1.0" android:toYScale="-1.0" android:pivotX="50%" android:pivotY="50%" android:duration="1000" /> <scale android:startOffset="2000" android:fromXScale="1.0" android:toXScale="0.0" android:fromYScale="1.0" android:toYScale="0.0" android:pivotX="50%" android:pivotY="50%" android:duration="1000" /> </set>


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

© Jo Edkins 2016