Skip to content

Commit 52380e7

Browse files
committed
Merge pull request OfficeDev#210 from TBag/master
Multiple updates.
2 parents 1b6150c + 219c64e commit 52380e7

File tree

132 files changed

+33604
-51
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+33604
-51
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 23
5+
buildToolsVersion "22.0.1"
6+
7+
defaultConfig {
8+
applicationId "com.microsoft.androidoffice365calendar"
9+
minSdkVersion 23
10+
targetSdkVersion 23
11+
versionCode 1
12+
versionName "1.0"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(dir: 'libs', include: ['*.jar'])
24+
testCompile 'junit:junit:4.12'
25+
compile 'com.android.support:appcompat-v7:23.1.1'
26+
compile 'com.android.support:design:23.1.1'
27+
28+
// base OData library:
29+
compile group: 'com.microsoft.services', name: 'odata-engine-core', version: '+'
30+
compile group: 'com.microsoft.services', name: 'odata-engine-android-impl', version: '+', ext:'aar'
31+
32+
// Azure Active Directory Authentication Library
33+
compile group: 'com.microsoft.aad', name: 'adal', version: '1.1.3'
34+
35+
// Graph Library
36+
compile group: 'com.microsoft.services', name: 'graph-services', version: '+'
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in D:\Program Files (x86)\Android\android-sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.microsoft.androidoffice365calendar;
2+
3+
import android.app.Application;
4+
import android.test.ApplicationTestCase;
5+
6+
/**
7+
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
8+
*/
9+
public class ApplicationTest extends ApplicationTestCase<Application> {
10+
public ApplicationTest() {
11+
super(Application.class);
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.microsoft.androidoffice365calendar">
4+
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
7+
8+
<application
9+
android:allowBackup="true"
10+
android:icon="@mipmap/ic_launcher"
11+
android:label="@string/app_name"
12+
android:supportsRtl="true"
13+
android:theme="@style/AppTheme">
14+
<activity
15+
android:name=".MainActivity"
16+
android:label="@string/app_name"
17+
android:theme="@style/AppTheme.NoActionBar">
18+
<intent-filter>
19+
<action android:name="android.intent.action.MAIN" />
20+
21+
<category android:name="android.intent.category.LAUNCHER" />
22+
</intent-filter>
23+
</activity>
24+
</application>
25+
26+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package com.microsoft.androidoffice365calendar;
2+
3+
import android.app.Activity;
4+
import android.util.Log;
5+
6+
import com.google.common.util.concurrent.SettableFuture;
7+
import com.microsoft.aad.adal.AuthenticationCallback;
8+
import com.microsoft.aad.adal.AuthenticationContext;
9+
import com.microsoft.aad.adal.AuthenticationResult;
10+
import com.microsoft.aad.adal.PromptBehavior;
11+
import com.microsoft.services.orc.auth.AuthenticationCredentials;
12+
import com.microsoft.services.orc.core.DependencyResolver;
13+
import com.microsoft.services.orc.http.Credentials;
14+
import com.microsoft.services.orc.http.impl.OAuthCredentials;
15+
import com.microsoft.services.orc.http.impl.OkHttpTransport;
16+
import com.microsoft.services.orc.serialization.impl.GsonSerializer;
17+
18+
public class AuthenticationController {
19+
private final String TAG = "Authentication";
20+
private AuthenticationContext authContext;
21+
private DependencyResolver dependencyResolver;
22+
private Activity contextActivity;
23+
private String resourceId;
24+
25+
public static synchronized AuthenticationController getInstance() {
26+
if (INSTANCE == null) {
27+
INSTANCE = new AuthenticationController();
28+
}
29+
return INSTANCE;
30+
}
31+
private static AuthenticationController INSTANCE;
32+
33+
private AuthenticationController() {
34+
resourceId = Constants.GRAPH_RESOURCE_ID;
35+
}
36+
37+
public void setContextActivity(final Activity contextActivity) {
38+
this.contextActivity = contextActivity;
39+
}
40+
41+
public SettableFuture<Boolean> initialize() {
42+
final SettableFuture<Boolean> result = SettableFuture.create();
43+
44+
if (verifyAuthenticationContext()) {
45+
getAuthenticationContext().acquireToken(
46+
this.contextActivity,
47+
this.resourceId,
48+
Constants.AAD_CLIENT_ID,
49+
Constants.AAD_REDIRECT_URL,
50+
PromptBehavior.Auto,
51+
new AuthenticationCallback<AuthenticationResult>() {
52+
@Override
53+
public void onSuccess(final AuthenticationResult authenticationResult) {
54+
if (authenticationResult != null && authenticationResult.getStatus() == AuthenticationResult.AuthenticationStatus.Succeeded) {
55+
dependencyResolver = new DependencyResolver.Builder(
56+
new OkHttpTransport(), new GsonSerializer(),
57+
new AuthenticationCredentials() {
58+
@Override
59+
public Credentials getCredentials() {
60+
return new OAuthCredentials(authenticationResult.getAccessToken());
61+
}
62+
}).build();
63+
result.set(true);
64+
}
65+
}
66+
67+
@Override
68+
public void onError(Exception t) {
69+
Log.e(TAG, "Acquire token failed. " + t.getMessage());
70+
result.setException(t);
71+
}
72+
});
73+
} else {
74+
result.setException(new Throwable("Auth context verification failed."));
75+
}
76+
return result;
77+
}
78+
79+
public AuthenticationContext getAuthenticationContext() {
80+
if (authContext == null) {
81+
try {
82+
authContext = new AuthenticationContext(this.contextActivity, Constants.AAD_AUTHORITY, false);
83+
} catch (Throwable t) {
84+
Log.e(TAG, "Get AuthenticationContext failed. " + t.toString());
85+
}
86+
}
87+
return authContext;
88+
}
89+
90+
public DependencyResolver getDependencyResolver() {
91+
return getInstance().dependencyResolver;
92+
}
93+
94+
private boolean verifyAuthenticationContext() {
95+
if (this.contextActivity == null) {
96+
return false;
97+
}
98+
return true;
99+
}
100+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.microsoft.androidoffice365calendar;
2+
3+
public interface Constants {
4+
public static final String AAD_CLIENT_ID = "Your app client ID";
5+
public static final String AAD_REDIRECT_URL = "http://AndroidOffice365Calendar";
6+
public static final String AAD_AUTHORITY = "https://login.microsoftonline.com/common";
7+
public static final String GRAPH_RESOURCE_ID = "https://graph.microsoft.com/";
8+
public static final String GRAPH_RESOURCE_URL = "https://graph.microsoft.com/v1.0/";
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.microsoft.androidoffice365calendar;
2+
3+
import android.util.Log;
4+
5+
import com.google.common.util.concurrent.FutureCallback;
6+
import com.google.common.util.concurrent.Futures;
7+
import com.google.common.util.concurrent.SettableFuture;
8+
import com.microsoft.services.graph.Event;
9+
import com.microsoft.services.graph.fetchers.GraphServiceClient;
10+
import com.microsoft.services.orc.core.DependencyResolver;
11+
import com.microsoft.services.orc.core.OrcList;
12+
13+
import java.text.SimpleDateFormat;
14+
import java.util.ArrayList;
15+
import java.util.Calendar;
16+
import java.util.List;
17+
18+
public class GraphController {
19+
private final static String TAG = "GraphController";
20+
21+
public static synchronized GraphController getInstance() {
22+
if (INSTANCE == null) {
23+
INSTANCE = new GraphController();
24+
}
25+
return INSTANCE;
26+
}
27+
private static GraphController INSTANCE;
28+
29+
public SettableFuture<List<String>> initialize() {
30+
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
31+
Calendar calendar = Calendar.getInstance();
32+
int day = calendar.get(Calendar.DAY_OF_MONTH) - 30;
33+
calendar.set(Calendar.DAY_OF_MONTH,day);
34+
String filterDate = formatter.format(calendar.getTime());
35+
final SettableFuture<List<String>> result = SettableFuture.create();
36+
final List<String> events = new ArrayList<String>();
37+
38+
DependencyResolver dependencyResolver = AuthenticationController.getInstance().getDependencyResolver();
39+
GraphServiceClient graphServiceClient = new GraphServiceClient(Constants.GRAPH_RESOURCE_URL,dependencyResolver);
40+
try {
41+
Futures.addCallback(graphServiceClient.getMe().getEvents()
42+
.filter("Start/DateTime ge '" + filterDate + "'")
43+
.select("subject,start,end")
44+
.orderBy("Start/DateTime desc")
45+
.top(10000).read(), new FutureCallback<OrcList<Event>>() {
46+
@Override
47+
public void onSuccess(OrcList<Event> list) {
48+
for (Event event : list){
49+
events.add(event.getSubject());
50+
}
51+
result.set(events);
52+
}
53+
54+
@Override
55+
public void onFailure(Throwable t) {
56+
Log.e(TAG, "Get events failed. " + t.getMessage());
57+
result.setException(t);
58+
}
59+
});
60+
} catch (Exception e) {
61+
Log.e(TAG, "Initialize failed. " + e.getMessage());
62+
result.setException(e);
63+
}
64+
return result;
65+
}
66+
}

0 commit comments

Comments
 (0)