1
1
/*
2
2
* Copyright (c) 2011 Google Inc.
3
- *
3
+ *
4
4
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5
5
* in compliance with the License. You may obtain a copy of the License at
6
- *
6
+ *
7
7
* http://www.apache.org/licenses/LICENSE-2.0
8
- *
8
+ *
9
9
* Unless required by applicable law or agreed to in writing, software distributed under the License
10
10
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
11
* or implied. See the License for the specific language governing permissions and limitations under
20
20
import com .google .api .client .http .HttpResponse ;
21
21
import com .google .api .client .http .HttpResponseException ;
22
22
import com .google .api .client .http .HttpTransport ;
23
+ import com .google .api .client .http .json .JsonHttpRequest ;
24
+ import com .google .api .client .http .json .JsonHttpRequestInitializer ;
23
25
import com .google .api .client .json .jackson .JacksonFactory ;
24
26
import com .google .api .services .samples .shared .android .ClientCredentials ;
25
27
import com .google .api .services .tasks .Tasks ;
28
+ import com .google .api .services .tasks .TasksRequest ;
26
29
import com .google .api .services .tasks .model .Task ;
27
30
28
31
import android .accounts .Account ;
54
57
* To enable logging of HTTP requests/responses, change {@link #LOGGING_LEVEL} to
55
58
* {@link Level#CONFIG} or {@link Level#ALL} and run this command:
56
59
* </p>
57
- *
60
+ *
58
61
* <pre>adb shell setprop log.tag.HttpTransport DEBUG * </pre>
59
- *
62
+ *
60
63
* @author Johan Euphrosine (based on Yaniv Inbar Buzz sample)
61
64
*/
62
65
public class TasksSample extends ListActivity {
@@ -86,9 +89,16 @@ public class TasksSample extends ListActivity {
86
89
@ Override
87
90
public void onCreate (Bundle savedInstanceState ) {
88
91
super .onCreate (savedInstanceState );
89
- service = new Tasks (transport , accessProtectedResource , new JacksonFactory ());
90
- service .setKey (ClientCredentials .KEY );
91
- service .setApplicationName ("Google-TasksSample/1.0" );
92
+ service =
93
+ Tasks .builder (transport , new JacksonFactory ()).setApplicationName ("Google-TasksSample/1.0" )
94
+ .setHttpRequestInitializer (accessProtectedResource )
95
+ .setJsonHttpRequestInitializer (new JsonHttpRequestInitializer () {
96
+
97
+ public void initialize (JsonHttpRequest request ) throws IOException {
98
+ TasksRequest tasksRequest = (TasksRequest ) request ;
99
+ tasksRequest .setKey (ClientCredentials .KEY );
100
+ }
101
+ }).build ();
92
102
accountManager = new GoogleAccountManager (this );
93
103
Logger .getLogger ("com.google.api.client" ).setLevel (LOGGING_LEVEL );
94
104
gotAccount (false );
@@ -136,8 +146,8 @@ void gotAccount(final Account account) {
136
146
SharedPreferences .Editor editor = settings .edit ();
137
147
editor .putString ("accountName" , account .name );
138
148
editor .commit ();
139
- accountManager .manager .getAuthToken (
140
- account , AUTH_TOKEN_TYPE , true , new AccountManagerCallback <Bundle >() {
149
+ accountManager .manager .getAuthToken (account , AUTH_TOKEN_TYPE , true ,
150
+ new AccountManagerCallback <Bundle >() {
141
151
142
152
public void run (AccountManagerFuture <Bundle > future ) {
143
153
try {
@@ -147,8 +157,8 @@ public void run(AccountManagerFuture<Bundle> future) {
147
157
intent .setFlags (intent .getFlags () & ~Intent .FLAG_ACTIVITY_NEW_TASK );
148
158
startActivityForResult (intent , REQUEST_AUTHENTICATE );
149
159
} else if (bundle .containsKey (AccountManager .KEY_AUTHTOKEN )) {
150
- accessProtectedResource .setAccessToken (
151
- bundle .getString (AccountManager .KEY_AUTHTOKEN ));
160
+ accessProtectedResource .setAccessToken (bundle
161
+ .getString (AccountManager .KEY_AUTHTOKEN ));
152
162
onAuthToken ();
153
163
}
154
164
} catch (Exception e ) {
@@ -210,7 +220,7 @@ void handleException(Exception e) {
210
220
void onAuthToken () {
211
221
try {
212
222
List <String > taskTitles = new ArrayList <String >();
213
- List <Task > tasks = service .tasks .list ("@default" ).execute ().getItems ();
223
+ List <Task > tasks = service .tasks () .list ("@default" ).execute ().getItems ();
214
224
if (tasks != null ) {
215
225
for (Task task : tasks ) {
216
226
taskTitles .add (task .getTitle ());
0 commit comments