├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── dimens.xml │ │ │ │ ├── colors.xml │ │ │ │ ├── styles.xml │ │ │ │ ├── me_messages_snippets.xml │ │ │ │ ├── myorganization_user_snippets.xml │ │ │ │ ├── strings.xml │ │ │ │ ├── me_snippets.xml │ │ │ │ ├── myorganization_groups_snippets.xml │ │ │ │ ├── me_events_snippets.xml │ │ │ │ └── drives_snippets.xml │ │ │ ├── drawable │ │ │ │ ├── border_red.xml │ │ │ │ ├── bkgrnd_rect.xml │ │ │ │ └── ic_launcher.xml │ │ │ ├── menu │ │ │ │ └── snippet_list_menu.xml │ │ │ ├── layout │ │ │ │ ├── activity_snippet_detail.xml │ │ │ │ ├── activity_snippet_list.xml │ │ │ │ ├── list_segment.xml │ │ │ │ ├── list_element.xml │ │ │ │ ├── activity_signin.xml │ │ │ │ └── fragment_snippet_detail.xml │ │ │ └── values-w820dp │ │ │ │ └── dimens.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── microsoft │ │ │ │ └── graph │ │ │ │ └── snippets │ │ │ │ ├── BaseActivity.java │ │ │ │ ├── MSALAuthenticationCallback.java │ │ │ │ ├── BaseFragment.java │ │ │ │ ├── application │ │ │ │ ├── AppModule.java │ │ │ │ └── SnippetApp.java │ │ │ │ ├── util │ │ │ │ ├── IManifestReader.java │ │ │ │ ├── SharedPrefsUtil.java │ │ │ │ └── ManifestReader.java │ │ │ │ ├── ServiceConstants.java │ │ │ │ ├── snippet │ │ │ │ ├── SnippetContent.java │ │ │ │ ├── SnippetCategory.java │ │ │ │ ├── AbstractSnippet.java │ │ │ │ ├── MessageSnippets.java │ │ │ │ ├── UsersSnippets.java │ │ │ │ ├── MeSnippets.java │ │ │ │ └── EventsSnippets.java │ │ │ │ ├── SnippetDetailActivity.java │ │ │ │ ├── SnippetListAdapter.java │ │ │ │ ├── SnippetListActivity.java │ │ │ │ ├── SnippetListFragment.java │ │ │ │ ├── AuthenticationManager.java │ │ │ │ ├── SignInActivity.java │ │ │ │ └── SnippetDetailFragment.java │ │ └── AndroidManifest.xml │ └── androidTest │ │ ├── getTestConfig.sh │ │ ├── getTestConfig.bat │ │ └── java │ │ └── com │ │ └── microsoft │ │ └── graph │ │ └── snippets │ │ ├── TestCredentials.java │ │ ├── SnippetDetailActivityTests.java │ │ ├── SnippetListActivityTests.java │ │ └── SignInActivityTests.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .travis.yml ├── .gitignore ├── gradle.properties ├── NOTICES.md ├── LICENSE ├── gradlew.bat ├── gradlew ├── README-Localized ├── README-zh-cn.md ├── README-zh-tw.md └── README-ja-jp.md └── CONTRIBUTING.md /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoftgraph/android-java-snippets-sample/master/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: android 3 | android: 4 | components: 5 | - tools 6 | - platform-tools 7 | - extra 8 | - android-23 9 | - build-tools-27.0.3 10 | 11 | script: 12 | - ./gradlew clean build -x test 13 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Apr 16 14:31:57 EAT 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 48dp 6 | 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.ap_ 2 | *.apk 3 | *.class 4 | *.dex 5 | *.iml 6 | *.ipr 7 | *.iws 8 | .DS_Store 9 | .classpath 10 | .gradle 11 | .idea 12 | .project 13 | /.idea/libraries 14 | /.idea/workspace.xml 15 | /build 16 | /captures 17 | /local.properties 18 | Thumbs.db 19 | bin/ 20 | build/ 21 | gen/ 22 | out/ 23 | testConfig.json -------------------------------------------------------------------------------- /app/src/main/res/drawable/border_red.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/bkgrnd_rect.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/menu/snippet_list_menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 8 | -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/graph/snippets/BaseActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. 3 | * See LICENSE in the project root for license information. 4 | */ 5 | package com.microsoft.graph.snippets; 6 | 7 | import android.app.Activity; 8 | 9 | public abstract class BaseActivity extends Activity { 10 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_snippet_detail.xml: -------------------------------------------------------------------------------- 1 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #AE4A00 4 | #804325 5 | #1CA41C 6 | #88FFFF00 7 | #88FF0000 8 | #00FFFFFF 9 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/graph/snippets/MSALAuthenticationCallback.java: -------------------------------------------------------------------------------- 1 | package com.microsoft.graph.snippets; 2 | 3 | import com.microsoft.identity.client.AuthenticationResult; 4 | import com.microsoft.identity.client.exception.MsalException; 5 | 6 | interface MSALAuthenticationCallback { 7 | void onSuccess(AuthenticationResult authenticationResult); 8 | void onError(MsalException exception); 9 | void onError(Exception exception); 10 | void onCancel(); 11 | } 12 | -------------------------------------------------------------------------------- /app/src/androidTest/getTestConfig.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | testConfig="{ 4 | \"test_client_id\": \"$TEST_CLIENT_ID\", 5 | \"test_username\": \"$TEST_USERNAME\", 6 | \"test_password\": \"$1\" 7 | }" 8 | echo $testConfig 9 | echo $testConfig > testConfig.json 10 | 11 | adb devices | while read line 12 | do 13 | if [ ! "$line" = "" ] && [ `echo $line | awk '{print $2}'` = "device" ] 14 | then 15 | device=`echo $line | awk '{print $1}'` 16 | echo "$device $@ ..." 17 | adb -s $device push testConfig.json ./data/local 18 | fi 19 | done 20 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_snippet_list.xml: -------------------------------------------------------------------------------- 1 | 11 | -------------------------------------------------------------------------------- /app/src/androidTest/getTestConfig.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | SET testConfig={ 4 | SET testConfig=%testConfig% "test_client_id": "%TEST_CLIENT_ID%", 5 | SET testConfig=%testConfig% "test_username": "%TEST_USERNAME%", 6 | SET testConfig=%testConfig% "test_password": "%1" 7 | SET testConfig=%testConfig% } 8 | echo %testConfig% 9 | echo %testConfig% > testConfig.json 10 | 11 | SET _adb_devices=%ANDROID_HOME%\platform-tools\adb.exe devices 12 | FOR /f "skip=1" %%G IN ('%_adb_devices%') DO %ANDROID_HOME%\platform-tools\adb.exe -s %%G push testConfig.json ./data/local 13 | -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/graph/snippets/BaseFragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. 3 | * See LICENSE in the project root for license information. 4 | */ 5 | package com.microsoft.graph.snippets; 6 | 7 | import android.app.Fragment; 8 | import android.os.Bundle; 9 | import android.support.annotation.Nullable; 10 | 11 | public class BaseFragment extends Fragment { 12 | 13 | @Override 14 | public void onActivityCreated(@Nullable Bundle savedInstanceState) { 15 | super.onActivityCreated(savedInstanceState); 16 | 17 | } 18 | } -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/graph/snippets/application/AppModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. 3 | * See LICENSE in the project root for license information. 4 | */ 5 | package com.microsoft.graph.snippets.application; 6 | import com.microsoft.graph.snippets.ServiceConstants; 7 | 8 | public class AppModule { 9 | 10 | public static final String PREFS = "com.microsoft.o365_android_unified_API_REST_snippets"; 11 | 12 | public String providesRestEndpoint() { 13 | return ServiceConstants.AUTHENTICATION_RESOURCE_ID; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/graph/snippets/util/IManifestReader.java: -------------------------------------------------------------------------------- 1 | package com.microsoft.graph.snippets.util; 2 | 3 | import java.util.HashMap; 4 | 5 | public interface IManifestReader { 6 | String getApplicationMetadataValueString(String key); 7 | int getApplicationMetadataValueInt(String key); 8 | boolean getApplicationMetadataValueBoolean(String key); 9 | int getApplicationMetadataValueColor(String key); 10 | float getApplicationMetadataValueFloat(String key); 11 | String getIntentFilterAction(String activityName); 12 | String[] getIntentFilterCategories(String activityName); 13 | HashMap getIntentFilterData(String activityName); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/johnaustin/AndroidSDK/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 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/res/layout/list_segment.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 13 | 14 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 16 | 17 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/graph/snippets/ServiceConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. 3 | * See LICENSE in the project root for license information. 4 | */ 5 | package com.microsoft.graph.snippets; 6 | 7 | public class ServiceConstants { 8 | public static final String AUTHENTICATION_RESOURCE_ID = "https://graph.microsoft.com"; 9 | public static final String REDIRECT_URI = "http://localhost/androidsnippets"; 10 | // The Microsoft Graph delegated permissions that you set in the application 11 | // registration portal must match these scope values. 12 | // Update this constant with the scope (permission) values for your application: 13 | public static final String[] SCOPES = {"openid", "Mail.ReadWrite","Mail.Send","Files.ReadWrite", 14 | "User.Read.All", "Calendars.ReadWrite","Group.Read.All","Group.ReadWrite.All",}; 15 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /NOTICES.md: -------------------------------------------------------------------------------- 1 | #Third Party Notices for Microsoft Graph SDK Snippets sample for Android 2 | 3 | This project incorporates material from the project(s) listed below (collectively, "Third Party Code"). Microsoft is not the original author of the Third Party Code. The original copyright notices and licenses, under which Microsoft received such Third Party Code, are set out below together with the full text of such licenses. These notices and licenses are provided for informational purposes only. This Third Party Code is licensed to you under the terms set forth in the licenses set forth below. Microsoft reserves all other rights not expressly granted under this agreement, whether by implication, estoppel or otherwise. 4 | 5 | - Android SDK, which is provided by the Android Open Source Project and is used according to terms described in the [Creative Commons 2.5 Attribution License](http://creativecommons.org/licenses/by/2.5). The Android SDK is available [here](http://developer.android.com/sdk/index.html). 6 | -------------------------------------------------------------------------------- /app/src/main/res/layout/list_element.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 15 | 16 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Microsoft. All rights reserved. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/graph/snippets/snippet/SnippetContent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. 3 | * See LICENSE in the project root for license information. 4 | */ 5 | package com.microsoft.graph.snippets.snippet; 6 | 7 | import java.util.ArrayList; 8 | import java.util.Collections; 9 | import java.util.List; 10 | import static com.microsoft.graph.snippets.snippet.DrivesSnippets.getDrivesSnippets; 11 | import static com.microsoft.graph.snippets.snippet.EventsSnippets.getEventsSnippets; 12 | import static com.microsoft.graph.snippets.snippet.GroupsSnippets.getGroupsSnippets; 13 | import static com.microsoft.graph.snippets.snippet.MeSnippets.getMeSnippets; 14 | import static com.microsoft.graph.snippets.snippet.MessageSnippets.getMessageSnippets; 15 | import static com.microsoft.graph.snippets.snippet.UsersSnippets.getUsersSnippets; 16 | 17 | public class SnippetContent { 18 | 19 | 20 | public static final List> ITEMS = new ArrayList<>(); 21 | 22 | static { 23 | AbstractSnippet[][] baseSnippets = new AbstractSnippet[][]{ 24 | getGroupsSnippets(), 25 | getEventsSnippets(), 26 | getMeSnippets(), 27 | getMessageSnippets(), 28 | getUsersSnippets(), 29 | getDrivesSnippets() 30 | }; 31 | 32 | for (AbstractSnippet[] snippetArray : baseSnippets) { 33 | Collections.addAll(ITEMS, snippetArray); 34 | } 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/graph/snippets/util/SharedPrefsUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. 3 | * See LICENSE in the project root for license information. 4 | */ 5 | package com.microsoft.graph.snippets.util; 6 | 7 | import android.content.Context; 8 | import android.content.SharedPreferences; 9 | 10 | import com.microsoft.graph.snippets.application.SnippetApp; 11 | import com.microsoft.graph.snippets.application.AppModule; 12 | import com.microsoft.identity.client.AuthenticationResult; 13 | 14 | public class SharedPrefsUtil { 15 | 16 | public static final String PREF_AUTH_TOKEN = "PREF_AUTH_TOKEN"; 17 | public static final String PREF_USER_TENANT = "PREF_USER_TENANT"; 18 | public static final String PREF_USER_ID = "PREF_USER_ID"; 19 | 20 | public static SharedPreferences getSharedPreferences() { 21 | return SnippetApp.getApp().getSharedPreferences(AppModule.PREFS, Context.MODE_PRIVATE); 22 | } 23 | 24 | public static void persistUserID(AuthenticationResult result) { 25 | setPreference(PREF_USER_ID, result.getAccount().getUsername()); 26 | } 27 | 28 | public static void persistAuthToken(AuthenticationResult result) { 29 | setPreference(PREF_AUTH_TOKEN, result.getAccessToken()); 30 | } 31 | 32 | public static void persistUserTenant(String tenant) { 33 | getSharedPreferences().edit().putString(PREF_USER_TENANT, tenant).commit(); 34 | } 35 | 36 | private static void setPreference(String key, String accessToken) { 37 | getSharedPreferences().edit().putString(key, accessToken).commit(); 38 | } 39 | 40 | } -------------------------------------------------------------------------------- /app/src/androidTest/java/com/microsoft/graph/snippets/TestCredentials.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. 3 | * See LICENSE in the project root for license information. 4 | */ 5 | package com.microsoft.graph.snippets; 6 | 7 | import android.os.Environment; 8 | import com.google.gson.JsonObject; 9 | import com.google.gson.JsonParser; 10 | import java.io.File; 11 | import java.io.FileNotFoundException; 12 | import java.io.FileReader; 13 | 14 | public class TestCredentials { 15 | private static final String TEST_ARTIFACT_LOCATION = "local/testConfig.json"; 16 | private static final String CLIENT_ID_TEST_ARTIFACT = "test_client_id"; 17 | private static final String USERNAME_TEST_ARTIFACT = "test_username"; 18 | private static final String PASSWORD_TEST_ARTIFACT = "test_password"; 19 | 20 | public String clientId; 21 | public String username; 22 | public String password; 23 | 24 | public static TestCredentials getTestCredentials() throws FileNotFoundException { 25 | TestCredentials testCredentials = new TestCredentials(); 26 | File testConfigFile = new File(Environment.getDataDirectory(), TEST_ARTIFACT_LOCATION); 27 | JsonObject testConfig = new JsonParser().parse(new FileReader(testConfigFile)).getAsJsonObject(); 28 | 29 | testCredentials.clientId = testConfig.get(CLIENT_ID_TEST_ARTIFACT).getAsString(); 30 | testCredentials.username = testConfig.get(USERNAME_TEST_ARTIFACT).getAsString(); 31 | testCredentials.password = testConfig.get(PASSWORD_TEST_ARTIFACT).getAsString(); 32 | 33 | return testCredentials; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/graph/snippets/snippet/SnippetCategory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. 3 | * See LICENSE in the project root for license information. 4 | */ 5 | package com.microsoft.graph.snippets.snippet; 6 | 7 | import com.microsoft.graph.snippets.application.SnippetApp; 8 | import static com.microsoft.graph.snippets.R.string.section_drives; 9 | import static com.microsoft.graph.snippets.R.string.section_events; 10 | import static com.microsoft.graph.snippets.R.string.section_groups; 11 | import static com.microsoft.graph.snippets.R.string.section_me; 12 | import static com.microsoft.graph.snippets.R.string.section_messages; 13 | import static com.microsoft.graph.snippets.R.string.section_user; 14 | 15 | public class SnippetCategory { 16 | static final SnippetCategory eventsSnippetCategory 17 | = new SnippetCategory(section_events); 18 | 19 | static final SnippetCategory groupSnippetCategory 20 | = new SnippetCategory(section_groups); 21 | 22 | static final SnippetCategory userSnippetCategory 23 | = new SnippetCategory(section_user); 24 | 25 | static final SnippetCategory mailSnippetCategory 26 | = new SnippetCategory(section_messages); 27 | 28 | static final SnippetCategory meSnippetCategory 29 | = new SnippetCategory(section_me); 30 | 31 | static final SnippetCategory drivesSnippetCategory 32 | = new SnippetCategory(section_drives); 33 | 34 | final String mSection; 35 | 36 | SnippetCategory(int sectionId) { 37 | mSection = SnippetApp.getApp().getString(sectionId); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/src/main/res/values/me_messages_snippets.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | Messages 11 | 12 | 13 | Get user\'s messages 14 | Gets the signed-in user\'s emails. 15 | https://graph.microsoft.io/docs/api-reference/v1.0/api/message_get 16 | false 17 | graphServiceClient()\n .me()\n .messages()\n .buildRequest()\n .get(); 18 | 19 | 20 | Send an email 21 | Sends an email as the signed-in user and saves a copy to their Sent Items folder. 22 | https://graph.microsoft.io/docs/api-reference/v1.0/api/message_send 23 | false 24 | 25 | Message message = new Message();\n\n 26 | Recipient recipient = new Recipient();\n 27 | recipient.emailAddress = new EmailAddress();\n 28 | recipient.emailAddress.address =\n 29 | \"user@contoso.com\";\n 30 | message.toRecipients =\n 31 | Collections.singletonList(recipient);\n\n 32 | 33 | message.subject = \"Email subject\";\n\n 34 | 35 | ItemBody itemBody = new ItemBody();\n 36 | itemBody.contentType = BodyType.text;\n 37 | itemBody.content = \"Email body\";\n 38 | message.body = itemBody;\n\n 39 | 40 | graphServiceClient()\n .me()\n .messages()\n .sendMail(message, true)\n .buildRequest()\n .post(); 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/graph/snippets/SnippetDetailActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. 3 | * See LICENSE in the project root for license information. 4 | */ 5 | package com.microsoft.graph.snippets; 6 | 7 | import android.content.Intent; 8 | import android.os.Bundle; 9 | import android.support.v4.app.NavUtils; 10 | import android.view.MenuItem; 11 | 12 | public class SnippetDetailActivity extends BaseActivity { 13 | private SnippetDetailFragment mSnippetDetailFragment; 14 | 15 | @Override 16 | protected void onCreate(Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | setContentView(R.layout.activity_snippet_detail); 19 | if (null != getActionBar()) { 20 | getActionBar().setDisplayHomeAsUpEnabled(true); 21 | } 22 | if (savedInstanceState == null) { 23 | Bundle arguments = new Bundle(); 24 | arguments.putInt(SnippetDetailFragment.ARG_ITEM_ID, 25 | getIntent().getIntExtra(SnippetDetailFragment.ARG_ITEM_ID, 0)); 26 | mSnippetDetailFragment = new SnippetDetailFragment(); 27 | mSnippetDetailFragment.setArguments(arguments); 28 | getFragmentManager().beginTransaction() 29 | .add(R.id.snippet_detail_container, mSnippetDetailFragment) 30 | .commit(); 31 | } 32 | } 33 | 34 | @Override 35 | public boolean onOptionsItemSelected(MenuItem item) { 36 | int id = item.getItemId(); 37 | if (id == android.R.id.home) { 38 | NavUtils.navigateUpTo(this, new Intent(this, SnippetListActivity.class)); 39 | return true; 40 | } 41 | return super.onOptionsItemSelected(item); 42 | } 43 | 44 | public boolean isExecutingRequest(){ 45 | return mSnippetDetailFragment.isExecutingRequest(); 46 | } 47 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_signin.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 17 | 18 | 22 | 23 | 46 | 47 | 48 | 49 | 58 | 59 | 60 | 61 | 67 | 68 | 75 | 76 | 83 | 84 | 94 | 95 | 102 | 103 | 108 | 109 | 117 | 118 | 119 | 127 | 128 | 129 | 130 | 131 | 138 | 139 | 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/graph/snippets/snippet/UsersSnippets.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. 3 | * See LICENSE in the project root for license information. 4 | */ 5 | package com.microsoft.graph.snippets.snippet; 6 | 7 | import android.content.SharedPreferences; 8 | import com.google.gson.JsonObject; 9 | import com.microsoft.graph.concurrency.ICallback; 10 | import com.microsoft.graph.core.ClientException; 11 | import com.microsoft.graph.models.extensions.PasswordProfile; 12 | import com.microsoft.graph.models.extensions.User; 13 | import com.microsoft.graph.options.Option; 14 | import com.microsoft.graph.options.QueryOption; 15 | import com.microsoft.graph.requests.extensions.IUserCollectionPage; 16 | import com.microsoft.graph.snippets.util.SharedPrefsUtil; 17 | import java.util.LinkedList; 18 | import java.util.List; 19 | import java.util.UUID; 20 | import static com.microsoft.graph.snippets.R.array.get_organization_filtered_users; 21 | import static com.microsoft.graph.snippets.R.array.get_organization_users; 22 | import static com.microsoft.graph.snippets.R.array.insert_organization_user; 23 | import static com.microsoft.graph.snippets.util.SharedPrefsUtil.PREF_USER_TENANT; 24 | 25 | public abstract class UsersSnippets extends AbstractSnippet { 26 | 27 | public UsersSnippets(Integer descriptionArray) { 28 | super(SnippetCategory.userSnippetCategory, descriptionArray); 29 | } 30 | 31 | static UsersSnippets[] getUsersSnippets() { 32 | return new UsersSnippets[]{ 33 | // Marker element 34 | new UsersSnippets(null) { 35 | 36 | @Override 37 | public void request(ICallback callback) { 38 | // Not implemented 39 | } 40 | }, 41 | 42 | /* 43 | * Gets all of the users in your tenant\'s directory. 44 | * HTTP GET https://graph.microsoft.com/{version}/myOrganization/users 45 | * @see https://graph.microsoft.io/docs/api-reference/v1.0/api/user_list 46 | */ 47 | new UsersSnippets(get_organization_users) { 48 | @Override 49 | public void request(final ICallback callback) { 50 | mGraphServiceClient 51 | .users() 52 | .buildRequest() 53 | .get(new ICallback() { 54 | @Override 55 | public void success(IUserCollectionPage iUserCollectionPage) { 56 | callback.success(iUserCollectionPage.getRawObject()); 57 | } 58 | 59 | @Override 60 | public void failure(ClientException ex) { 61 | callback.failure(ex); 62 | } 63 | }); 64 | } 65 | }, 66 | 67 | /* 68 | * Gets all of the users in your tenant's directory who are from the United States, using $filter. 69 | * HTTP GET https://graph.microsoft.com/{version}/myOrganization/users?$filter=country eq \'United States\' 70 | * @see http://graph.microsoft.io/docs/overview/query_parameters 71 | */ 72 | new UsersSnippets(get_organization_filtered_users) { 73 | @Override 74 | public void request(final ICallback callback) { 75 | final List