Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 6.85 KB | None | 0 0
  1. package com.apps.babylearn;
  2.  
  3. import android.graphics.Bitmap;
  4. import android.graphics.BitmapFactory;
  5. import android.media.MediaPlayer;
  6. import android.os.Bundle;
  7. import android.view.Display;
  8. import android.view.View;
  9. import android.view.Window;
  10. import android.view.animation.AccelerateInterpolator;
  11. import android.widget.ImageView;
  12. import android.app.Activity;
  13.  
  14. public class Menu0Numbers extends Activity {
  15.    
  16.    
  17.    private String[] numbers = {
  18.             "1",
  19.             "2",
  20.             "3",
  21.             "4",
  22.             "5",
  23.             "6",
  24.             "7",
  25.             "8",
  26.             "9",
  27.             "10",
  28.     };
  29.    
  30.    private Integer[] images_alt = {
  31.            R.drawable.numbers_1_alt,
  32.            R.drawable.numbers_2_alt,
  33.            R.drawable.numbers_3_alt,
  34.            R.drawable.numbers_4_alt,
  35.            R.drawable.numbers_5_alt,
  36.            R.drawable.numbers_6_alt,
  37.            R.drawable.numbers_7_alt,
  38.            R.drawable.numbers_8_alt,
  39.            R.drawable.numbers_9_alt,
  40.            R.drawable.numbers_10_alt,
  41.            };
  42.      
  43.    private Integer[] audio = {
  44.            R.raw.one,
  45.            R.raw.two,
  46.            R.raw.three,
  47.            R.raw.four,
  48.            R.raw.five,
  49.            R.raw.six,
  50.            R.raw.seven,
  51.            R.raw.eight,
  52.            R.raw.nine,
  53.            R.raw.ten,
  54.            };
  55.    
  56.    // Some initial var setup
  57.    int position = 0;
  58.    MediaPlayer mp = null;
  59.    private ImageView image1;
  60.    private ImageView image2;
  61.    private ImageView image3;
  62.  
  63.    
  64.    private boolean isFirstImage = true;
  65.    
  66.     @Override
  67.     protected void onCreate(Bundle savedInstanceState) {
  68.             requestWindowFeature(Window.FEATURE_NO_TITLE);
  69.             super.onCreate(savedInstanceState);
  70.             setContentView(R.layout.submenu_0_numbers);
  71.            
  72.  
  73.  
  74.            
  75.             // Play initial audio
  76.             SoundMan.plaympSound(audio[position], getBaseContext());
  77.            
  78.             // Set number
  79.             //final ImageView numbers = (ImageView) findViewById(R.id.numbers);
  80.  
  81.            
  82.             image1 = (ImageView) findViewById(R.id.ImageView01);
  83.             image2 = (ImageView) findViewById(R.id.ImageView02);
  84.             image3 = (ImageView) findViewById(R.id.twistButt);
  85.            
  86.             final Display display = getWindowManager().getDefaultDisplay();
  87.             Bitmap numimage = BitmapFactory.decodeResource(getResources(),R.drawable.blank_card);
  88.             numimage = ImageHelper.OverlayText(numimage, numbers[position],display);
  89.             Bitmap altimage = BitmapFactory.decodeResource(getResources(),R.drawable.blank_card);
  90.             Bitmap altimage2 = BitmapFactory.decodeResource(getResources(),R.drawable.menu_0_numbers);
  91.             altimage = ImageHelper.OverlayImage(altimage, altimage2, display);
  92.              
  93.             image1.setImageBitmap(numimage);
  94.             image2.setImageBitmap(altimage);
  95.            
  96.             image2.setVisibility(View.GONE);
  97.  
  98.             final ImageView prev = (ImageView) findViewById(R.id.prev);
  99.              prev.setOnClickListener(new View.OnClickListener() {
  100.                  public void onClick(View v) {
  101.                      if (position == 0){
  102.                          position = 9;
  103.                      } else {
  104.                          position--;     
  105.                      }
  106.                      
  107.                     Bitmap numimage = BitmapFactory.decodeResource(getResources(),R.drawable.blank_card);
  108.                     numimage = ImageHelper.OverlayText(numimage, numbers[position],display);
  109.                     Bitmap altimage = BitmapFactory.decodeResource(getResources(),R.drawable.blank_card);
  110.                     Bitmap altimage2 = BitmapFactory.decodeResource(getResources(),R.drawable.menu_0_numbers);
  111.                     altimage = ImageHelper.OverlayImage(altimage, altimage2, display);
  112.                      
  113.                      image1.setImageBitmap(numimage);
  114.                      image2.setImageBitmap(altimage);
  115.                      SoundMan.plaympSound(audio[position], getBaseContext());
  116.                      }        
  117.                  });
  118.              
  119.             final ImageView next = (ImageView) findViewById(R.id.next);
  120.              next.setOnClickListener(new View.OnClickListener() {
  121.                      public void onClick(View v) {
  122.                          // Perform action on click
  123.                          if (position == 9){
  124.                              position = 0;
  125.                          } else {
  126.                              position++;     
  127.                          }
  128.                         Bitmap numimage = BitmapFactory.decodeResource(getResources(),R.drawable.blank_card);
  129.                         numimage = ImageHelper.OverlayText(numimage, numbers[position],display);
  130.                         Bitmap altimage = BitmapFactory.decodeResource(getResources(),R.drawable.blank_card);
  131.                         Bitmap altimage2 = BitmapFactory.decodeResource(getResources(),R.drawable.menu_0_numbers);
  132.                         altimage = ImageHelper.OverlayImage(altimage, altimage2, display);
  133.                          
  134.                          image1.setImageBitmap(numimage);
  135.                          image2.setImageBitmap(altimage);
  136.                          SoundMan.plaympSound(audio[position], getBaseContext());
  137.                          }        
  138.                      });   
  139.  
  140.              
  141.              // Play Sound Again when image clicked
  142.                 image1.setOnClickListener(new View.OnClickListener() {
  143.                        public void onClick(View view) {
  144.                              SoundMan.plaympSound(audio[position], getBaseContext());
  145.  
  146.                        }
  147.                 });
  148.            
  149.              // Rotate The Image
  150.             image3.setOnClickListener(new View.OnClickListener() {
  151.                    public void onClick(View view) {
  152.                     if (isFirstImage) {      
  153.                      applyRotation(0, 90);
  154.                      isFirstImage = !isFirstImage;
  155.  
  156.                     } else {    
  157.                      applyRotation(0, -90);
  158.                      isFirstImage = !isFirstImage;
  159.                     }
  160.                    }
  161.                 });          
  162.                 }
  163.  
  164.                 private void applyRotation(float start, float end) {
  165.                 // Find the center of image
  166.                 final float centerX = image1.getWidth() / 2.0f;
  167.                 final float centerY = image1.getHeight() / 2.0f;
  168.  
  169.                 // Create a new 3D rotation with the supplied parameter
  170.                 // The animation listener is used to trigger the next animation
  171.                 final Flip3dAnimation rotation =
  172.                        new Flip3dAnimation(start, end, centerX, centerY);
  173.                 rotation.setDuration(500);
  174.                 rotation.setFillAfter(true);
  175.                 rotation.setInterpolator(new AccelerateInterpolator());
  176.                 rotation.setAnimationListener(new DisplayNextView(isFirstImage, image1, image2));
  177.  
  178.                 if (isFirstImage)
  179.                 {
  180.                 image1.startAnimation(rotation);
  181.                 } else {
  182.                 image2.startAnimation(rotation);
  183.                 }
  184.            
  185.                    
  186.     }
  187.    
  188.            
  189. /** Not used now
  190.                 public class SoundManager  {
  191.                      // Media Player Method
  192.                      public void plaympSound(int input){  
  193.                             if (mp!=null){  
  194.                                 mp.reset();  
  195.                                 mp.release();  
  196.                             }  
  197.                                    mp = MediaPlayer.create(getBaseContext(), input);  
  198.                                    mp.start();  
  199.                            }  
  200.                       }
  201. */
  202.  
  203.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement