diff --git a/android/CloudVision/app/build.gradle b/android/CloudVision/app/build.gradle index 221560a..603283e 100644 --- a/android/CloudVision/app/build.gradle +++ b/android/CloudVision/app/build.gradle @@ -5,7 +5,7 @@ android { buildToolsVersion "23.0.2" defaultConfig { - applicationId "sample.google.com.cloudvision" + applicationId "com.google.sample.cloudvision" minSdkVersion 22 targetSdkVersion 23 versionCode 1 diff --git a/android/CloudVision/app/src/main/AndroidManifest.xml b/android/CloudVision/app/src/main/AndroidManifest.xml index 3ebfffa..f5b2f92 100644 --- a/android/CloudVision/app/src/main/AndroidManifest.xml +++ b/android/CloudVision/app/src/main/AndroidManifest.xml @@ -1,6 +1,6 @@ + package="com.google.sample.cloudvision"> @@ -14,7 +14,7 @@ android:theme="@style/AppTheme"> diff --git a/android/CloudVision/app/src/main/java/sample/google/com/cloudvision/MainActivity.java b/android/CloudVision/app/src/main/java/com/google/sample/cloudvision/MainActivity.java similarity index 88% rename from android/CloudVision/app/src/main/java/sample/google/com/cloudvision/MainActivity.java rename to android/CloudVision/app/src/main/java/com/google/sample/cloudvision/MainActivity.java index 134b601..fa30f1f 100644 --- a/android/CloudVision/app/src/main/java/sample/google/com/cloudvision/MainActivity.java +++ b/android/CloudVision/app/src/main/java/com/google/sample/cloudvision/MainActivity.java @@ -1,4 +1,20 @@ -package sample.google.com.cloudvision; +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.sample.cloudvision; import android.Manifest; import android.content.DialogInterface; @@ -94,7 +110,11 @@ public void startGalleryChooser() { } public void startCamera() { - if (PermissionUtils.requestPermission(this, CAMERA_PERMISSIONS_REQUEST, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA)) { + if (PermissionUtils.requestPermission( + this, + CAMERA_PERMISSIONS_REQUEST, + Manifest.permission.READ_EXTERNAL_STORAGE, + Manifest.permission.CAMERA)) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(getCameraFile())); startActivityForResult(intent, CAMERA_IMAGE_REQUEST); @@ -112,16 +132,19 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == GALLERY_IMAGE_REQUEST && resultCode == RESULT_OK && data != null) { uploadImage(data.getData()); - } - else if(requestCode == CAMERA_IMAGE_REQUEST && resultCode == RESULT_OK) { + } else if (requestCode == CAMERA_IMAGE_REQUEST && resultCode == RESULT_OK) { uploadImage(Uri.fromFile(getCameraFile())); } } @Override - public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { + public void onRequestPermissionsResult( + int requestCode, String[] permissions, int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); - if (PermissionUtils.permissionGranted(requestCode, CAMERA_PERMISSIONS_REQUEST, grantResults)) { + if (PermissionUtils.permissionGranted( + requestCode, + CAMERA_PERMISSIONS_REQUEST, + grantResults)) { startCamera(); } } @@ -130,7 +153,10 @@ public void uploadImage(Uri uri) { if (uri != null) { try { // scale the image to 800px to save on bandwidth - Bitmap bitmap = scaleBitmapDown(MediaStore.Images.Media.getBitmap(getContentResolver(), uri), 1200); + Bitmap bitmap = + scaleBitmapDown( + MediaStore.Images.Media.getBitmap(getContentResolver(), uri), + 1200); callCloudVision(bitmap); mMainImage.setImageBitmap(bitmap); diff --git a/android/CloudVision/app/src/main/java/sample/google/com/cloudvision/PermissionUtils.java b/android/CloudVision/app/src/main/java/com/google/sample/cloudvision/PermissionUtils.java similarity index 58% rename from android/CloudVision/app/src/main/java/sample/google/com/cloudvision/PermissionUtils.java rename to android/CloudVision/app/src/main/java/com/google/sample/cloudvision/PermissionUtils.java index e579aa3..0a7e8c2 100644 --- a/android/CloudVision/app/src/main/java/sample/google/com/cloudvision/PermissionUtils.java +++ b/android/CloudVision/app/src/main/java/com/google/sample/cloudvision/PermissionUtils.java @@ -1,4 +1,20 @@ -package sample.google.com.cloudvision; +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.sample.cloudvision; import android.app.Activity; import android.content.pm.PackageManager; @@ -8,7 +24,8 @@ import java.util.ArrayList; public class PermissionUtils { - public static boolean requestPermission(Activity activity, int requestCode, String... permissions) { + public static boolean requestPermission( + Activity activity, int requestCode, String... permissions) { boolean granted = true; ArrayList permissionsNeeded = new ArrayList<>(); @@ -32,7 +49,8 @@ public static boolean requestPermission(Activity activity, int requestCode, Stri } - public static boolean permissionGranted(int requestCode, int permissionCode, int[] grantResults) { + public static boolean permissionGranted( + int requestCode, int permissionCode, int[] grantResults) { if (requestCode == permissionCode) { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { return true; diff --git a/android/CloudVision/app/src/main/res/layout/activity_main.xml b/android/CloudVision/app/src/main/res/layout/activity_main.xml index 82feef9..5c5174d 100644 --- a/android/CloudVision/app/src/main/res/layout/activity_main.xml +++ b/android/CloudVision/app/src/main/res/layout/activity_main.xml @@ -5,7 +5,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" - tools:context="sample.google.com.cloudvision.MainActivity"> + tools:context="com.google.sample.cloudvision.MainActivity">