Skip to content
This repository has been archived by the owner on Apr 18, 2022. It is now read-only.

Commit

Permalink
Merge pull request #77 from GoogleCloudPlatform/swast-android-license
Browse files Browse the repository at this point in the history
Add Apache 2 license headers to Android sample code.
  • Loading branch information
tswast committed May 4, 2016
2 parents 633506a + 8d81384 commit 2b6fc4a
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 16 deletions.
2 changes: 1 addition & 1 deletion android/CloudVision/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions android/CloudVision/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="sample.google.com.cloudvision">
package="com.google.sample.cloudvision">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
Expand All @@ -14,7 +14,7 @@
android:theme="@style/AppTheme">
<activity
android:screenOrientation="portrait"
android:name=".MainActivity"
android:name="com.google.sample.cloudvision.MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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();
}
}
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<String> permissionsNeeded = new ArrayList<>();

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="sample.google.com.cloudvision.MainActivity"
tools:context="com.google.sample.cloudvision.MainActivity"
tools:showIn="@layout/activity_main">

<ScrollView
Expand Down
2 changes: 1 addition & 1 deletion android/CloudVision/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0-alpha1'
classpath 'com.android.tools.build:gradle:1.5.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down

0 comments on commit 2b6fc4a

Please sign in to comment.