Advertisement
babusaatbhoni

Cameramodule

Apr 4th, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.13 KB | None | 0 0
  1. package com.primus.taukycameraappsmodule1;
  2.  
  3.  
  4. import android.hardware.SensorManager;
  5. import android.os.Bundle;
  6. import android.app.Activity;
  7. import android.content.Context;
  8. import android.content.pm.ActivityInfo;
  9. import android.content.res.Configuration;
  10. import android.view.Display;
  11. import android.view.View;
  12. import android.view.View.OnClickListener;
  13. import android.view.WindowManager;
  14. import android.view.animation.Animation;
  15. import android.view.animation.Animation.AnimationListener;
  16. import android.view.animation.AnimationUtils;
  17. import android.widget.Button;
  18. import android.widget.FrameLayout;
  19. import android.widget.ImageButton;
  20. import android.widget.RelativeLayout;
  21. import android.widget.Toast;
  22.  
  23. public class Cameramodule extends Activity  {
  24.    
  25.     Camerapriview preview;
  26.     FrameLayout cameraframe;
  27.     Button b,camswitch;
  28.     ImageButton camera_settings,Take_picture;
  29.    
  30.     public static int second_select=0;
  31.      Animation animation;
  32.    
  33.     int orienation;
  34.    
  35.     SensorManager sensorManager;
  36.    
  37.     ImageButton flash,camera_switching;
  38.    
  39.     RelativeLayout second_overlay;
  40.     int flag=1;
  41.    
  42.     public static int cam_switch_flag=1;
  43.    
  44.     Button one,two,five,eight,ten,infinity;
  45.  
  46.     @Override
  47.     protected void onCreate(Bundle savedInstanceState) {
  48.         super.onCreate(savedInstanceState);
  49.         setContentView(R.layout.activity_cameramodule);
  50.        
  51.    
  52.        
  53.        
  54.         one=(Button) findViewById(R.id.one);
  55.         two=(Button) findViewById(R.id.two);
  56.         five=(Button) findViewById(R.id.five);
  57.         eight=(Button) findViewById(R.id.eight);
  58.         ten=(Button) findViewById(R.id.ten);
  59.         infinity=(Button) findViewById(R.id.infinity);
  60.        
  61.         one.setOnClickListener(new OnClickListener() {
  62.            
  63.             @Override
  64.             public void onClick(View v) {
  65.                 // TODO Auto-generated method stub
  66.                 second_select=1;
  67.                 second_overlay.setVisibility(View.GONE);
  68.                
  69.                
  70.             }
  71.         });
  72.        
  73.         two.setOnClickListener(new OnClickListener() {
  74.            
  75.             @Override
  76.             public void onClick(View v) {
  77.                 // TODO Auto-generated method stub
  78.                 second_select=2;
  79.                 second_overlay.setVisibility(View.GONE);
  80.                
  81.             }
  82.         });
  83.        
  84.         five.setOnClickListener(new OnClickListener() {
  85.            
  86.             @Override
  87.             public void onClick(View v) {
  88.                 // TODO Auto-generated method stub
  89.                 second_select=5;
  90.                 second_overlay.setVisibility(View.GONE);
  91.                
  92.             }
  93.         });
  94.        
  95.         eight.setOnClickListener(new OnClickListener() {
  96.            
  97.             @Override
  98.             public void onClick(View v) {
  99.                 // TODO Auto-generated method stub
  100.                 second_select=8;
  101.                 second_overlay.setVisibility(View.GONE);
  102.                
  103.             }
  104.         });
  105.        
  106.         ten.setOnClickListener(new OnClickListener() {
  107.            
  108.             @Override
  109.             public void onClick(View v) {
  110.                 // TODO Auto-generated method stub
  111.                 second_select=10;
  112.                 second_overlay.setVisibility(View.GONE);
  113.                
  114.             }
  115.         });
  116.        
  117.         infinity.setOnClickListener(new OnClickListener() {
  118.            
  119.             @Override
  120.             public void onClick(View v) {
  121.                 // TODO Auto-generated method stub
  122.                 second_overlay.setVisibility(View.GONE);
  123.                
  124.                 second_select=0;//zero means infinity;
  125.                
  126.             }
  127.         });
  128.        
  129.         preview=new Camerapriview(this,Cameramodule.this);
  130.        
  131.         second_overlay=(RelativeLayout) findViewById(R.id.second_overlay);
  132.         second_overlay.setVisibility(View.GONE);
  133.        
  134.         //sensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
  135.        
  136.        
  137.         cameraframe=(FrameLayout) findViewById(R.id.mframe);
  138.         camera_settings=(ImageButton) findViewById(R.id.camera_settings);
  139.         Take_picture=(ImageButton) findViewById(R.id.taje_picture);
  140.        
  141.         camera_switching=(ImageButton) findViewById(R.id.camera_switch);
  142.        
  143.        
  144.         orienation=getResources().getConfiguration().orientation;
  145.        
  146.        
  147.        
  148.         cameraframe.addView(preview);
  149.        
  150.         WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
  151.        
  152.        
  153.         Display display = getWindowManager().getDefaultDisplay();
  154.         int width = display.getWidth();  // deprecated
  155.         int height = display.getHeight();
  156.        
  157.        
  158.        
  159.        
  160.        
  161.         //create dialog box..
  162.    
  163.        
  164.        
  165.        
  166.        
  167.         /*
  168.          *
  169.          * Camera record setting options
  170.          */
  171.        
  172.        
  173.         Take_picture.setOnClickListener(new OnClickListener() {
  174.            
  175.             @Override
  176.             public void onClick(View arg0) {
  177.                 // TODO Auto-generated method stub
  178.                 preview.camera.takePicture(null, new Rwacallbackhandler(getApplicationContext()), new Photohandler(getApplicationContext()));
  179.                
  180.                
  181.                
  182.             }
  183.         });
  184.        
  185.        
  186.         /*
  187.          * Switch the front and back camera...
  188.          */
  189.         camera_switching.setOnClickListener(new OnClickListener() {
  190.            
  191.             @Override
  192.             public void onClick(View v) {
  193.                 // TODO Auto-generated method stub
  194.                
  195.                  preview.callswitch(Cameramodule.this);
  196.                  
  197.                  if(cam_switch_flag==1)
  198.                  {
  199.                  cam_switch_flag=2;
  200.                  }
  201.                  else if (cam_switch_flag==2) {
  202.                      cam_switch_flag=1;
  203.                    
  204.                 }
  205.                  
  206.                  
  207.                
  208.             }
  209.         });
  210.        
  211.         //create flash option
  212.        
  213.         camera_settings.setOnClickListener(new OnClickListener() {
  214.            
  215.             @Override
  216.             public void onClick(View arg0) {
  217.                 // TODO Auto-generated method stub
  218.                
  219.                 if(flag==1)
  220.                 {
  221.                 second_overlay.setVisibility(View.VISIBLE);
  222.                 startAnimationPopOut();
  223.                
  224.                 flag=2;
  225.                 }
  226.                 else if(flag==2)
  227.                 {
  228.                     second_overlay.setVisibility(View.GONE);
  229.                     //startAnimationPopOut();
  230.                     flag=1;
  231.                    
  232.                 }
  233.                
  234.             }
  235.         });
  236.        
  237.        
  238.     }
  239.    
  240.    
  241.     @Override
  242.     public void onConfigurationChanged(Configuration newConfig) {
  243.         super.onConfigurationChanged(newConfig);
  244.         setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  245.        
  246.         Toast.makeText(getApplicationContext(), "Changes", 1000).show();
  247.     }
  248.    
  249.    
  250.    
  251.    
  252.  
  253.  
  254.  
  255.     private void startAnimationPopOut() {        
  256.        
  257.  
  258.          animation = AnimationUtils.loadAnimation(this,R.anim.layout_animation);
  259.  
  260.         animation.setAnimationListener(new AnimationListener() {                  
  261.             @Override
  262.             public void onAnimationStart(Animation animation) {
  263.  
  264.             }
  265.  
  266.             @Override
  267.             public void onAnimationRepeat(Animation animation) {
  268.  
  269.             }
  270.  
  271.             @Override
  272.             public void onAnimationEnd(Animation animation) {
  273.  
  274.             }
  275.         });
  276.  
  277.        second_overlay.clearAnimation();
  278.        second_overlay.startAnimation(animation);
  279.        
  280.     }
  281.    
  282.    
  283. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement