yesyoucam 0.1 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 877bbd64af6fe139f3b5fa3ae6b50a6afca10b0a
4
- data.tar.gz: 8a0828d22863b3d30191d6de26b84ed3dc9a76e6
3
+ metadata.gz: 9208f8d396f559090d26d908e11e5ccdd19723da
4
+ data.tar.gz: 9b46dba729b433f48a0f0dcc49338957eef8fea7
5
5
  SHA512:
6
- metadata.gz: 94e969d6aad759423e52d82823e7b394c5dd29fa3c5ef482cb52dd0fa688bc3cca8a7ea1c4d0a662759ac0e0cdb1d4265174ec998316c1f8d3e18215a989486f
7
- data.tar.gz: e4fbe2d3f43968d2d5242a0b0625f59e218ad89869807be3d08582a603f1fe017d5b21830d7c2b912b366289d3a02a60e046b23f94ab9051102a57b0dbcbcd2e
6
+ metadata.gz: 167482ff74f823b2367e142522621e81147e4abf79526174bd8f30f6579bdf1e0c51ea7d49b9f58bfe618c59a199fe47a144c7df28741e001b792cc3c886d2dc
7
+ data.tar.gz: 2de83e738c72c798c8e031ae127c98edba689e4f1f8ab9f66dc1cb5ad184e4aebf62e123956632023e55e6d855acdabcb9a4cd125278ae31da42b259b044fa0c
data/README.md CHANGED
@@ -2,6 +2,91 @@
2
2
  ## A **Ridiculous**ly Simple BluePotion Camera Library to help you achieve your dreams...
3
3
  ![Don't Shia Way](_art/yyc.png)
4
4
 
5
+ ## Usage ("Nothing is impossible")
6
+
7
+ ### Take a Photo
8
+
9
+ ```ruby
10
+ # Fire off a photo taking request
11
+ # Returns true if camera intent is presented to the user.
12
+ # Depends on camera existence (YesYouCam.camera_exists?)
13
+ YesYouCam.capture_photo
14
+ ```
15
+
16
+ ### On Take a Photo Completion - Get Photo
17
+ ```ruby
18
+ # called in BluePotion when the photo has been taken (or any activity is completed actually)
19
+ # If you're not using a PMActivity you should capture the onActivityResult method.
20
+ def activity_result(request_code, result_code, data)
21
+ # Verify this activity was for us!
22
+ if (request_code == YesYouCam::CAPTURE_IMAGE_RC)
23
+ if (result_code == YesYouCam::OK) # OR Android::App::Activity::RESULT_OK
24
+ # Photo success!
25
+ mp "Full sized photo located at #{YesYouCam.photo_path}"
26
+ # now you can do find!(:some_image_view).imageBitmap = YesYouCam.bmp_data
27
+ else
28
+ # Photo failed or was cancelled
29
+ app.toast "No Photo"
30
+ end
31
+ end
32
+ end
33
+ ```
34
+
35
+ ### Want a PNG?
36
+ ```ruby
37
+ # Did you need a PNG instead of a JPG?
38
+ YesYouCam.photo_path # Some JPG path
39
+ YesYouCam.pic_to_png
40
+ YesYouCam.photo_path # Some new PNG path
41
+ ```
42
+
43
+ ### Need the photo discoverable by Photo Libraries and other Apps?
44
+ ```ruby
45
+ # Run this and the current photo (YesYouCam.photo_path) will be
46
+ # added to the user's Photo Gallery, and accessible by all apps.
47
+ YesYouCam.add_to_gallery
48
+ ```
49
+
50
+ ### Let the user select a photo from their library?
51
+ ```ruby
52
+ # Fire off a photo choose request
53
+ YesYouCam.choose_photo
54
+ ```
55
+
56
+ ### Kitchen Sink Example
57
+ ```ruby
58
+ app.alert(title: "Update Photo", message: "How would you like to update your photo?", positive_button: "Take Photo", negative_button: "Choose from Library") do |choice|
59
+ case choice
60
+ when "Take Photo"
61
+ YesYouCam.capture_photo
62
+ when "Choose from Library"
63
+ YesYouCam.choose_photo
64
+ end
65
+ end
66
+
67
+ def activity_result(request_code, result_code, data)
68
+ if request_code == YesYouCam::CAPTURE_IMAGE_RC
69
+ if result_code == YesYouCam::OK
70
+ # Photo success!
71
+ mp "Full sized photo located at #{YesYouCam.photo_path}"
72
+ find!(:some_image_view).imageBitmap = YesYouCam.bmp_data
73
+ else
74
+ # Photo failed or was cancelled
75
+ app.toast "No Photo"
76
+ end
77
+ elsif request_code == YesYouCam::CHOOSE_IMAGE_RC
78
+ # the chosen photo
79
+ selected_uri = data.getData
80
+ # Did you want the path?
81
+ photo_path = YesYouCam.pic_path_from_uri(selected_uri)
82
+ # Did you want the BMP data?
83
+ bmp_data = YesYouCam.bmp_data(photo_path)
84
+ # Nope, the uri is fine...
85
+ find!(:some_image_view).imageURI = selected_uri
86
+ end
87
+ end
88
+ ```
89
+
5
90
  ## Installation
6
91
 
7
92
  Add this line to your application's Gemfile:
@@ -12,13 +97,13 @@ And then execute:
12
97
 
13
98
  $ bundle
14
99
 
15
- Or install it yourself as:
16
-
17
- $ gem install yesyoucam
100
+ Now make sure your `Rakefile` has camera permissions and features needed:
18
101
 
19
- ## Usage
102
+ # This gem will try to add permissions, but it's best that you assure they are set!
103
+ app.permissions += [:write_external_storage]
104
+ # This gem will add this feature, but it's safest for you to also set it!
105
+ app.features = ["android.hardware.camera"]
20
106
 
21
- TODO: Write usage instructions here
22
107
 
23
108
  ## Contributing
24
109
 
@@ -26,4 +111,5 @@ TODO: Write usage instructions here
26
111
  2. Create your feature branch (`git checkout -b my-new-feature`)
27
112
  3. Commit your changes (`git commit -am 'Add some feature'`)
28
113
  4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create new Pull Request
114
+ 5. Order some mexican food and beat a piñata
115
+ 6. Create new Pull Request
@@ -1,4 +1,95 @@
1
- class Yesyoucam
1
+ class YesYouCam
2
+ OK = Android::App::Activity::RESULT_OK
3
+ CAPTURE_IMAGE_RC = 100
4
+ CHOOSE_IMAGE_RC = 101
5
+ DATA = "_data" # MediaStore.Images.Media.DATA
2
6
 
7
+ class << self
8
+
9
+
10
+ @current_photo_path = nil
11
+
12
+
13
+ # Returns true or false on success of firing a photo intent
14
+ def capture_photo
15
+ success = false
16
+ if camera_exists?
17
+ # Performing this check is important because if you call startActivityForResult
18
+ # using an intent that no app can handle, your app will crash.
19
+ # So as long as the result is not nil, it's safe to use the intent.
20
+ take_picture_intent = Potion::Intent.new(Potion::MediaStore::ACTION_IMAGE_CAPTURE)
21
+ if take_picture_intent.resolveActivity(app.package_manager)
22
+ # create place for photo to go
23
+ photo_file = create_image_file
24
+
25
+ if photo_file
26
+ take_picture_intent.putExtra(Potion::MediaStore::EXTRA_OUTPUT, Potion::Uri.fromFile(photo_file))
27
+ find.activity.startActivityForResult(take_picture_intent, YesYouCam::CAPTURE_IMAGE_RC)
28
+ success = true
29
+ end
30
+ end
31
+ end
32
+ success
33
+ end
34
+
35
+ def choose_photo
36
+ choose_pic = Potion::Intent.new(Potion::Intent::ACTION_PICK, Potion::INTERNAL_CONTENT_URI)
37
+ find.activity.startActivityForResult(choose_pic, YesYouCam::CHOOSE_IMAGE_RC)
38
+ end
39
+
40
+ def pic_to_png(quality=100)
41
+ bmp = Potion::BitmapFactory.decodeFile(@current_photo_path)
42
+ # NOTE the instance var for current photo changes with this command
43
+ create_image_file("png")
44
+ image = Potion::File.new(@current_photo_path)
45
+ out_stream = Potion::FileOutputStream.new(image)
46
+ bmp.compress(Android::Graphics::Bitmap::CompressFormat::PNG, quality, out_stream)
47
+ out_stream.flush
48
+ out_stream.close
49
+ end
50
+
51
+ def photo_path
52
+ @current_photo_path
53
+ end
54
+
55
+ def bmp_data(optional_path=nil)
56
+ file_path = optional_path ? optional_path : photo_path
57
+ Android::Graphics::BitmapFactory.decodeFile(file_path)
58
+ end
59
+
60
+ def camera_exists?
61
+ find.app.package_manager.hasSystemFeature("android.hardware.camera")
62
+ end
63
+
64
+ def add_to_gallery
65
+ media_scan_intent = Potion::Intent.new(Potion::Intent::ACTION_MEDIA_SCANNER_SCAN_FILE)
66
+ photo_file = Potion::File.new(photo_path)
67
+ content_uri = Potion::Uri.fromFile(photo_file)
68
+ media_scan_intent.setData(content_uri)
69
+ find.app.context.sendBroadcast(media_scan_intent)
70
+ end
71
+
72
+ def pic_path_from_uri (content_uri)
73
+ cursor = find.app.context.contentResolver.query(content_uri, nil, nil, nil, nil)
74
+ column_index = cursor.getColumnIndexOrThrow(YesYouCam::DATA)
75
+ cursor.moveToFirst
76
+ path = cursor.getString(column_index)
77
+ cursor.close
78
+
79
+ path
80
+ end
81
+
82
+ private
83
+
84
+ def create_image_file(extension="jpg")
85
+ file_name = "#{app.name}_#{Time.now.to_i}"
86
+ storage_dir = Potion::Environment.getExternalStoragePublicDirectory(Potion::Environment::DIRECTORY_PICTURES)
87
+ image_file = Potion::File.createTempFile(file_name, ".#{extension}", storage_dir)
88
+
89
+ @current_photo_path = "#{image_file.getAbsolutePath}"
90
+ image_file
91
+ end
92
+
93
+ end # close eigenclass
3
94
  end
4
95
 
data/lib/yesyoucam.rb CHANGED
@@ -4,7 +4,17 @@ unless defined?(Motion::Project::Config)
4
4
  raise "This file must be required within a RubyMotion project Rakefile."
5
5
  end
6
6
 
7
+ require 'bluepotion'
8
+
7
9
  lib_dir_path = File.dirname(File.expand_path(__FILE__))
8
10
  Motion::Project::App.setup do |app|
9
- app.files.unshift(Dir.glob(File.join(lib_dir_path, "project/**/*.rb")))
10
- end
11
+ # Add camera feature
12
+ app.permissions += ["android.permission.WRITE_EXTERNAL_STORAGE"]
13
+ app.features << "android.hardware.camera"
14
+ # Find insert point
15
+ insert_point = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
16
+
17
+ Dir.glob(File.join(lib_dir_path, "project/**/*.rb")).reverse.each do |file|
18
+ app.files.insert(insert_point, file)
19
+ end
20
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yesyoucam
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gant
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-04 00:00:00.000000000 Z
11
+ date: 2015-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bluepotion
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  description: Quickly and easily implment camera functions in RubyMotion Android
28
42
  email:
29
43
  - GantMan@gmail.com
@@ -38,7 +52,7 @@ homepage: https://github.com/GantMan/yesyoucam
38
52
  licenses:
39
53
  - MIT
40
54
  metadata: {}
41
- post_install_message: JUST DO IT!!!! MAKE YOUR DREAMS COME TRUE!
55
+ post_install_message:
42
56
  rdoc_options: []
43
57
  require_paths:
44
58
  - lib