Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

87
LINES

< > BotCompany Repo | #1015069 // Android Take Picture, old transpilation

JavaX source code (Android) [tags: use-pretranspiled] - run with: the app

Libraryless. Click here for Pure Java version (87L/1K/4K).

1  
import java.security.NoSuchAlgorithmException;
2  
import java.security.MessageDigest;
3  
import java.lang.reflect.*;
4  
import java.net.*;
5  
import java.io.*;
6  
import javax.swing.*;
7  
import java.util.regex.*;
8  
import java.util.*;
9  
10  
import android.app.Activity;
11  
import android.widget.*;
12  
import android.graphics.*;
13  
import android.hardware.Camera;
14  
import android.view.*;
15  
16  
public class main {
17  
  static Activity androidContext;
18  
  
19  
  public static void main(String[] args) throws Exception {
20  
    System.out.println("Listing cameras...");
21  
    
22  
    androidContext.runOnUiThread(new Runnable() {
23  
public void run() { try {
24  
25  
      int n = Camera.getNumberOfCameras();
26  
      System.out.println("Cameras: " + n);
27  
  
28  
      final Camera cam = Camera.open(0/*n-1*/);
29  
      
30  
      Camera.Parameters p = cam.getParameters();
31  
      p.setPreviewSize(100, 100);
32  
      cam.setParameters(p);
33  
34  
      SurfaceView surfaceView = new SurfaceView(androidContext);
35  
      SurfaceHolder surfaceHolder = surfaceView.getHolder();
36  
      surfaceHolder.addCallback(new CamCallback());
37  
      surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
38  
      
39  
      androidContext.setContentView(surfaceView);
40  
      
41  
      cam.setPreviewDisplay(surfaceHolder);
42  
      cam.startPreview();
43  
      
44  
      System.out.println("Preview started.");
45  
      
46  
      /*surfaceView.post(new Runnable() {
47  
public void run() { try {
48  
49  
        cam.takePicture(null, null, null, new JpegCallback());
50  
      
51  
} catch (Exception __e) { throw __e instanceof RuntimeException ? (RuntimeException) __e : new RuntimeException(__e); }}});
52  
      
53  
      System.out.println("Waiting for callback");*/
54  
    
55  
} catch (Exception __e) { throw __e instanceof RuntimeException ? (RuntimeException) __e : new RuntimeException(__e); }}});
56  
  }
57  
  
58  
  static class CamCallback implements SurfaceHolder.Callback {
59  
    public void surfaceChanged (SurfaceHolder holder, int format, int width, int height) {
60  
      System.out.println("surfaceChanged");
61  
    }
62  
    public void surfaceCreated (SurfaceHolder holder) {
63  
      System.out.println("surfaceCreated");
64  
    }
65  
    public void surfaceDestroyed (SurfaceHolder holder) {
66  
      System.out.println("surfaceDestroyed");
67  
    }
68  
  }
69  
  
70  
  static class ShutterCallback implements Camera.ShutterCallback {
71  
    public void onShutter() {
72  
      System.out.println("Shutter!");
73  
    }
74  
  }
75  
  
76  
  static class JpegCallback implements Camera.PictureCallback {
77  
    public void onPictureTaken (byte[] data, Camera cam) {
78  
      TextView tv = new TextView(androidContext);
79  
      tv.setText("Picture data: " + data.length);
80  
      androidContext.setContentView(tv);
81  
      
82  
      System.out.println("Picture data: " + data.length);
83  
      cam.release();
84  
      System.out.println("Camera released.");
85  
    }
86  
  } 
87  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, nbgitpuheiab, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1015069
Snippet name: Android Take Picture, old transpilation
Eternal ID of this version: #1015069/1
Text MD5: e94c1b1ee898f06b3b8ea14ed204c192
Transpilation MD5: e94c1b1ee898f06b3b8ea14ed204c192
Author: stefan
Category: javax android
Type: JavaX source code (Android)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-05-07 18:23:45
Source code size: 2824 bytes / 87 lines
Pitched / IR pitched: No / No
Views / Downloads: 319 / 412
Referenced in: [show references]