├── res ├── drawable │ ├── icon.png │ ├── android_1.jpg │ ├── android_2.jpg │ └── android_3.jpg ├── values │ └── strings.xml └── layout │ └── main.xml ├── .gitignore ├── default.properties ├── README.markdown ├── LICENSE ├── AndroidManifest.xml ├── proguard.cfg └── src └── com └── osesm └── apps └── fakecamera └── MainActivity.java /res/drawable/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bryanl/FakeCamera/HEAD/res/drawable/icon.png -------------------------------------------------------------------------------- /res/drawable/android_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bryanl/FakeCamera/HEAD/res/drawable/android_1.jpg -------------------------------------------------------------------------------- /res/drawable/android_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bryanl/FakeCamera/HEAD/res/drawable/android_2.jpg -------------------------------------------------------------------------------- /res/drawable/android_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bryanl/FakeCamera/HEAD/res/drawable/android_3.jpg -------------------------------------------------------------------------------- /res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | FakeTestCamera 4 | 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # files for the dex VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # generated files 12 | bin/ 13 | gen/ 14 | 15 | # Local configuration file (sdk path, etc) 16 | local.properties 17 | tmp 18 | .idea 19 | *.iml 20 | out/* 21 | -------------------------------------------------------------------------------- /default.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system use, 7 | # "build.properties", and override values to adapt the script to your 8 | # project structure. 9 | 10 | # Project target. 11 | target=android-13 12 | -------------------------------------------------------------------------------- /res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | # FakeCamera 2 | 3 | A nice Fake Camera for smoke testing Android Apps. Use this instead of the built-in emulator camera. 4 | 5 | ## TODO 6 | 7 | * Add some tests 8 | * Find someone to donate a nice app icon 9 | 10 | This code is based on MockCameraApp by Marcus Chen in this thread: 11 | https://groups.google.com/d/msg/robotium-developers/97fgbym_aLU/IginWXgk8LcJ 12 | 13 | ##### Attribution for photos used: 14 | 15 | http://www.flickr.com/photos/62397886@N07/5690861354/ 16 | http://www.flickr.com/photos/asirap/5587611705/ 17 | http://www.flickr.com/photos/mujitra/5480146781/ 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012, Bryan Liles 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 8 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 9 | -------------------------------------------------------------------------------- /AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /proguard.cfg: -------------------------------------------------------------------------------- 1 | -optimizationpasses 5 2 | -dontusemixedcaseclassnames 3 | -dontskipnonpubliclibraryclasses 4 | -dontpreverify 5 | -verbose 6 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* 7 | 8 | -keep public class * extends android.app.Activity 9 | -keep public class * extends android.app.Application 10 | -keep public class * extends android.app.Service 11 | -keep public class * extends android.content.BroadcastReceiver 12 | -keep public class * extends android.content.ContentProvider 13 | -keep public class * extends android.app.backup.BackupAgentHelper 14 | -keep public class * extends android.preference.Preference 15 | -keep public class com.android.vending.licensing.ILicensingService 16 | 17 | -keepclasseswithmembernames class * { 18 | native ; 19 | } 20 | 21 | -keepclasseswithmembers class * { 22 | public (android.content.Context, android.util.AttributeSet); 23 | } 24 | 25 | -keepclasseswithmembers class * { 26 | public (android.content.Context, android.util.AttributeSet, int); 27 | } 28 | 29 | -keepclassmembers class * extends android.app.Activity { 30 | public void *(android.view.View); 31 | } 32 | 33 | -keepclassmembers enum * { 34 | public static **[] values(); 35 | public static ** valueOf(java.lang.String); 36 | } 37 | 38 | -keep class * implements android.os.Parcelable { 39 | public static final android.os.Parcelable$Creator *; 40 | } 41 | -------------------------------------------------------------------------------- /src/com/osesm/apps/fakecamera/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.osesm.apps.fakecamera; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.net.Uri; 6 | import android.os.Bundle; 7 | import android.os.Environment; 8 | import android.provider.MediaStore; 9 | import android.util.Log; 10 | import android.widget.Toast; 11 | 12 | import java.io.*; 13 | 14 | public class MainActivity extends Activity { 15 | 16 | final static int[] photos = {R.drawable.android_1, R.drawable.android_2, R.drawable.android_3}; 17 | static int lastPhotoIndex = -1; 18 | 19 | private final static String TAG = "FakeCamera"; 20 | 21 | @Override 22 | protected void onCreate(Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | prepareToSnapPicture(); 25 | finish(); 26 | } 27 | 28 | private void prepareToSnapPicture() { 29 | checkSdCard(); 30 | Intent intent = getIntent(); 31 | 32 | if (intent.getExtras() != null) { 33 | snapPicture(intent); 34 | setResult(RESULT_OK); 35 | } else { 36 | Log.i(TAG, "Unable to capture photo. Missing Intent Extras."); 37 | setResult(RESULT_CANCELED); 38 | } 39 | } 40 | 41 | private void checkSdCard() { 42 | if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { 43 | Toast.makeText(this, "External SD card not mounted", Toast.LENGTH_LONG).show(); 44 | Log.i(TAG, "External SD card not mounted"); 45 | } 46 | } 47 | 48 | private void snapPicture(Intent intent) { 49 | try { 50 | this.copyFile(getPicturePath(intent)); 51 | Toast.makeText(this, "Click!", Toast.LENGTH_SHORT).show(); 52 | } catch (IOException e) { 53 | Log.i(TAG, "Can't copy photo"); 54 | e.printStackTrace(); 55 | } 56 | } 57 | 58 | private File getPicturePath(Intent intent) { 59 | Uri uri = (Uri) intent.getExtras().get(MediaStore.EXTRA_OUTPUT); 60 | return new File(uri.getPath()); 61 | } 62 | 63 | private void copyFile(File destination) throws IOException { 64 | InputStream in = getResources().openRawResource(getNextPhoto()); 65 | OutputStream out = new FileOutputStream(destination); 66 | byte[] buffer = new byte[1024]; 67 | int length; 68 | 69 | if (in != null) { 70 | Log.i(TAG, "Input photo stream is null"); 71 | 72 | while ((length = in.read(buffer)) > 0) { 73 | out.write(buffer, 0, length); 74 | } 75 | 76 | in.close(); 77 | } 78 | 79 | out.close(); 80 | } 81 | 82 | private int getNextPhoto() { 83 | if (lastPhotoIndex == photos.length - 1) { 84 | lastPhotoIndex = -1; 85 | } 86 | 87 | return photos[++lastPhotoIndex]; 88 | } 89 | } 90 | 91 | 92 | --------------------------------------------------------------------------------