Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.apps.babylearn;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import android.media.MediaPlayer;
- import android.os.Bundle;
- import android.view.Display;
- import android.view.View;
- import android.view.Window;
- import android.view.animation.AccelerateInterpolator;
- import android.widget.ImageView;
- import android.app.Activity;
- public class Menu0Numbers extends Activity {
- private String[] numbers = {
- "1",
- "2",
- "3",
- "4",
- "5",
- "6",
- "7",
- "8",
- "9",
- "10",
- };
- private Integer[] images_alt = {
- R.drawable.numbers_1_alt,
- R.drawable.numbers_2_alt,
- R.drawable.numbers_3_alt,
- R.drawable.numbers_4_alt,
- R.drawable.numbers_5_alt,
- R.drawable.numbers_6_alt,
- R.drawable.numbers_7_alt,
- R.drawable.numbers_8_alt,
- R.drawable.numbers_9_alt,
- R.drawable.numbers_10_alt,
- };
- private Integer[] audio = {
- R.raw.one,
- R.raw.two,
- R.raw.three,
- R.raw.four,
- R.raw.five,
- R.raw.six,
- R.raw.seven,
- R.raw.eight,
- R.raw.nine,
- R.raw.ten,
- };
- // Some initial var setup
- int position = 0;
- MediaPlayer mp = null;
- private ImageView image1;
- private ImageView image2;
- private ImageView image3;
- private boolean isFirstImage = true;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- super.onCreate(savedInstanceState);
- setContentView(R.layout.submenu_0_numbers);
- // Play initial audio
- SoundMan.plaympSound(audio[position], getBaseContext());
- // Set number
- //final ImageView numbers = (ImageView) findViewById(R.id.numbers);
- image1 = (ImageView) findViewById(R.id.ImageView01);
- image2 = (ImageView) findViewById(R.id.ImageView02);
- image3 = (ImageView) findViewById(R.id.twistButt);
- final Display display = getWindowManager().getDefaultDisplay();
- Bitmap numimage = BitmapFactory.decodeResource(getResources(),R.drawable.blank_card);
- numimage = ImageHelper.OverlayText(numimage, numbers[position],display);
- Bitmap altimage = BitmapFactory.decodeResource(getResources(),R.drawable.blank_card);
- Bitmap altimage2 = BitmapFactory.decodeResource(getResources(),R.drawable.menu_0_numbers);
- altimage = ImageHelper.OverlayImage(altimage, altimage2, display);
- image1.setImageBitmap(numimage);
- image2.setImageBitmap(altimage);
- image2.setVisibility(View.GONE);
- final ImageView prev = (ImageView) findViewById(R.id.prev);
- prev.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- if (position == 0){
- position = 9;
- } else {
- position--;
- }
- Bitmap numimage = BitmapFactory.decodeResource(getResources(),R.drawable.blank_card);
- numimage = ImageHelper.OverlayText(numimage, numbers[position],display);
- Bitmap altimage = BitmapFactory.decodeResource(getResources(),R.drawable.blank_card);
- Bitmap altimage2 = BitmapFactory.decodeResource(getResources(),R.drawable.menu_0_numbers);
- altimage = ImageHelper.OverlayImage(altimage, altimage2, display);
- image1.setImageBitmap(numimage);
- image2.setImageBitmap(altimage);
- SoundMan.plaympSound(audio[position], getBaseContext());
- }
- });
- final ImageView next = (ImageView) findViewById(R.id.next);
- next.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- // Perform action on click
- if (position == 9){
- position = 0;
- } else {
- position++;
- }
- Bitmap numimage = BitmapFactory.decodeResource(getResources(),R.drawable.blank_card);
- numimage = ImageHelper.OverlayText(numimage, numbers[position],display);
- Bitmap altimage = BitmapFactory.decodeResource(getResources(),R.drawable.blank_card);
- Bitmap altimage2 = BitmapFactory.decodeResource(getResources(),R.drawable.menu_0_numbers);
- altimage = ImageHelper.OverlayImage(altimage, altimage2, display);
- image1.setImageBitmap(numimage);
- image2.setImageBitmap(altimage);
- SoundMan.plaympSound(audio[position], getBaseContext());
- }
- });
- // Play Sound Again when image clicked
- image1.setOnClickListener(new View.OnClickListener() {
- public void onClick(View view) {
- SoundMan.plaympSound(audio[position], getBaseContext());
- }
- });
- // Rotate The Image
- image3.setOnClickListener(new View.OnClickListener() {
- public void onClick(View view) {
- if (isFirstImage) {
- applyRotation(0, 90);
- isFirstImage = !isFirstImage;
- } else {
- applyRotation(0, -90);
- isFirstImage = !isFirstImage;
- }
- }
- });
- }
- private void applyRotation(float start, float end) {
- // Find the center of image
- final float centerX = image1.getWidth() / 2.0f;
- final float centerY = image1.getHeight() / 2.0f;
- // Create a new 3D rotation with the supplied parameter
- // The animation listener is used to trigger the next animation
- final Flip3dAnimation rotation =
- new Flip3dAnimation(start, end, centerX, centerY);
- rotation.setDuration(500);
- rotation.setFillAfter(true);
- rotation.setInterpolator(new AccelerateInterpolator());
- rotation.setAnimationListener(new DisplayNextView(isFirstImage, image1, image2));
- if (isFirstImage)
- {
- image1.startAnimation(rotation);
- } else {
- image2.startAnimation(rotation);
- }
- }
- /** Not used now
- public class SoundManager {
- // Media Player Method
- public void plaympSound(int input){
- if (mp!=null){
- mp.reset();
- mp.release();
- }
- mp = MediaPlayer.create(getBaseContext(), input);
- mp.start();
- }
- }
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement