Skip to content

Commit 074a2ca

Browse files
asrivas-devrelGerrit Code Review
authored and
Gerrit Code Review
committed
Merge "Lambda-fy the Drive Quickstart Android App, address minor nits and update the compile options to Java 1.8"
2 parents f504230 + 2f490e9 commit 074a2ca

File tree

11 files changed

+41
-49
lines changed

11 files changed

+41
-49
lines changed

drive/quickstart/.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Android Studio excludes
2+
.idea/
3+
*.iml
4+
5+
# Gradle build excludes
6+
.gradle/
7+
build/
8+
local.properties
9+
10+
# Misc
11+
.DS_Store

drive/quickstart/README.md

+10-8
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ designed to get you up and running with the [Google Drive API for Android](https
1111
* Shows you how to write file content
1212
* Shows you how to set file metadata including title and MIME type
1313

14-
# How can I run it?
15-
16-
1. Create an OAuth 2.0 client as described in the [Getting Started guide](https://developers.google.com/drive/android/get-started).
17-
..* Use 'com.google.android.gms.drive.sample.quickstart' for the package name
18-
..* Request user data access
19-
1. Make sure you have [Google Play Services development](http://developer.android.com/google/play-services/setup.html) set up correctly.
20-
1. Grab the source and create a project in your IDE
21-
1. Run and edit!
14+
# Set Up
15+
1. Install the [Android SDK](https://developer.android.com/sdk/index.html).
16+
1. Download and configure the
17+
[Google Play services SDK](https://developer.android.com/google/play-services/setup.html),
18+
which includes the Google Drive Android API.
19+
1. Create [Google API Console](https://console.developers.google.com/projectselector/apis/dashboard)
20+
project and/or enable the Drive API for an existing project.
21+
1. Register an OAuth 2.0 client for the package 'com.google.android.gms.drive.sample.quickstart'
22+
with your own [debug keys](https://developers.google.com/drive/android/auth).
23+
See full instructions in the [Getting Started guide](https://developers.google.com/drive/android/get-started)
2224

2325
# What does it look like?
2426

drive/quickstart/app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

drive/quickstart/app/build.gradle

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@ android {
1717
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
1818
}
1919
}
20+
compileOptions {
21+
sourceCompatibility JavaVersion.VERSION_1_8
22+
targetCompatibility JavaVersion.VERSION_1_8
23+
}
2024
}
2125

2226
dependencies {
23-
compile fileTree(dir: 'libs', include: ['*.jar'])
27+
compile fileTree(include: ['*.jar'], dir: 'libs')
2428
compile 'com.android.support:appcompat-v7:26.1.0'
25-
2629
compile 'com.google.android.gms:play-services-drive:11.6.0'
2730
compile 'com.google.android.gms:play-services-auth:11.6.0'
2831
}

drive/quickstart/app/src/main/AndroidManifest.xml

-4
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@
1818
package="com.google.android.gms.drive.sample.quickstart"
1919
android:versionCode="1"
2020
android:versionName="1.0" >
21-
2221
<uses-sdk
2322
android:minSdkVersion="8"
2423
android:targetSdkVersion="18" />
25-
2624
<application
2725
android:allowBackup="true"
2826
android:icon="@drawable/ic_launcher"
@@ -33,13 +31,11 @@
3331
android:label="@string/app_name" >
3432
<intent-filter>
3533
<action android:name="android.intent.action.MAIN" />
36-
3734
<category android:name="android.intent.category.LAUNCHER" />
3835
</intent-filter>
3936
</activity>
4037
<meta-data
4138
android:name="com.google.android.gms.version"
4239
android:value="@integer/google_play_services_version" />
4340
</application>
44-
4541
</manifest>

drive/quickstart/app/src/main/java/com/google/android/gms/drive/sample/quickstart/MainActivity.java

+11-25
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* Copyright 2013 Google Inc. All Rights Reserved.
33
*
4-
* <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
55
* except in compliance with the License. You may obtain a copy of the License at
66
*
7-
* <p>http://www.apache.org/licenses/LICENSE-2.0
7+
* http://www.apache.org/licenses/LICENSE-2.0
88
*
9-
* <p>Unless required by applicable law or agreed to in writing, software distributed under the
9+
* Unless required by applicable law or agreed to in writing, software distributed under the
1010
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
1111
* express or implied. See the License for the specific language governing permissions and
1212
* limitations under the License.
@@ -49,7 +49,6 @@ public class MainActivity extends Activity {
4949
private static final int REQUEST_CODE_CAPTURE_IMAGE = 1;
5050
private static final int REQUEST_CODE_CREATOR = 2;
5151

52-
private GoogleSignInClient mGoogleSignInClient;
5352
private DriveClient mDriveClient;
5453
private DriveResourceClient mDriveResourceClient;
5554
private Bitmap mBitmapToSave;
@@ -63,8 +62,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
6362
/** Start sign in activity. */
6463
private void signIn() {
6564
Log.i(TAG, "Start sign in");
66-
mGoogleSignInClient = buildGoogleSignInClient();
67-
startActivityForResult(mGoogleSignInClient.getSignInIntent(), REQUEST_CODE_SIGN_IN);
65+
GoogleSignInClient GoogleSignInClient = buildGoogleSignInClient();
66+
startActivityForResult(GoogleSignInClient.getSignInIntent(), REQUEST_CODE_SIGN_IN);
6867
}
6968

7069
/** Build a Google SignIn client. */
@@ -85,19 +84,9 @@ private void saveFileToDrive() {
8584
mDriveResourceClient
8685
.createContents()
8786
.continueWithTask(
88-
new Continuation<DriveContents, Task<Void>>() {
89-
@Override
90-
public Task<Void> then(@NonNull Task<DriveContents> task) throws Exception {
91-
return createFileIntentSender(task.getResult(), image);
92-
}
93-
})
87+
task -> createFileIntentSender(task.getResult(), image))
9488
.addOnFailureListener(
95-
new OnFailureListener() {
96-
@Override
97-
public void onFailure(@NonNull Exception e) {
98-
Log.w(TAG, "Failed to create new contents.", e);
99-
}
100-
});
89+
e -> Log.w(TAG, "Failed to create new contents.", e));
10190
}
10291

10392
/**
@@ -134,13 +123,10 @@ private Task<Void> createFileIntentSender(DriveContents driveContents, Bitmap im
134123
return mDriveClient
135124
.newCreateFileActivityIntentSender(createFileActivityOptions)
136125
.continueWith(
137-
new Continuation<IntentSender, Void>() {
138-
@Override
139-
public Void then(@NonNull Task<IntentSender> task) throws Exception {
140-
startIntentSenderForResult(task.getResult(), REQUEST_CODE_CREATOR, null, 0, 0, 0);
141-
return null;
142-
}
143-
});
126+
task -> {
127+
startIntentSenderForResult(task.getResult(), REQUEST_CODE_CREATOR, null, 0, 0, 0);
128+
return null;
129+
});
144130
}
145131

146132
@Override

drive/quickstart/app/src/main/res/values/dimens.xml

-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
limitations under the License.
1515
-->
1616
<resources>
17-
1817
<!-- Default screen margins, per the Android Design guidelines. -->
1918
<dimen name="activity_horizontal_margin">16dp</dimen>
2019
<dimen name="activity_vertical_margin">16dp</dimen>
21-
2220
</resources>

drive/quickstart/app/src/main/res/values/strings.xml

-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,5 @@
1515
limitations under the License.
1616
-->
1717
<resources>
18-
1918
<string name="app_name">Google Drive Android API Quickstart</string>
20-
2119
</resources>

drive/quickstart/app/src/main/res/values/styles.xml

-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
limitations under the License.
1515
-->
1616
<resources>
17-
1817
<!--
1918
Base application theme, dependent on API level. This theme is replaced
2019
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
@@ -26,10 +25,8 @@
2625
backward-compatibility can go here.
2726
-->
2827
</style>
29-
3028
<!-- Application theme. -->
3129
<style name="AppTheme" parent="AppBaseTheme">
3230
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
3331
</style>
34-
3532
</resources>

drive/quickstart/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ buildscript {
88
}
99
}
1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:2.3.1'
11+
classpath 'com.android.tools.build:gradle:3.0.1'
1212

1313
// NOTE: Do not place your application dependencies here; they belong
1414
// in the individual module build.gradle files
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Fri Jul 28 11:08:39 CDT 2017
1+
#Sun Mar 18 19:56:05 EDT 2018
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

0 commit comments

Comments
 (0)