├── .gitignore ├── .travis.yml ├── LICENSE.txt ├── Notices.MD ├── O365-auth ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── microsoft │ ├── AuthenticationManager.java │ ├── AzureADModule.java │ └── AzureAppCompatActivity.java ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── microsoft │ │ └── o365_android_onenote_rest │ │ ├── BaseActivity.java │ │ ├── BaseFragment.java │ │ ├── SignInActivity.java │ │ ├── SnippetDetailActivity.java │ │ ├── SnippetDetailFragment.java │ │ ├── SnippetListActivity.java │ │ ├── SnippetListAdapter.java │ │ ├── SnippetListFragment.java │ │ ├── application │ │ └── SnippetApp.java │ │ ├── conf │ │ └── ServiceConstants.java │ │ ├── inject │ │ ├── AppModule.java │ │ ├── AzureModule.java │ │ └── ObjectGraphInjector.java │ │ ├── model │ │ └── Scope.java │ │ ├── snippet │ │ ├── AbstractSnippet.java │ │ ├── Callback.java │ │ ├── Input.java │ │ ├── NotebookSnippet.java │ │ ├── PagesSnippet.java │ │ ├── SectionGroupSnippet.java │ │ ├── SectionSnippet.java │ │ ├── SnippetCategory.java │ │ └── SnippetContent.java │ │ └── util │ │ ├── SharedPrefsUtil.java │ │ └── User.java │ └── res │ ├── drawable │ ├── attachment.pdf │ ├── bizcard.png │ ├── bkgrnd_rect.xml │ ├── logo.jpg │ ├── msa.png │ └── o365.png │ ├── layout-sw600dp │ └── activity_snippet_list.xml │ ├── layout │ ├── activity_signin.xml │ ├── activity_snippet_detail.xml │ ├── activity_snippet_list.xml │ ├── fragment_snippet_detail.xml │ ├── list_element.xml │ └── list_segment.xml │ ├── menu │ └── snippet_list_menu.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── raw-en │ ├── create_page_with_business_cards.html │ ├── create_page_with_image.html │ ├── create_page_with_note_tags.html │ ├── create_page_with_pdf.html │ ├── create_page_with_product_info.html │ ├── create_page_with_recipe.html │ ├── create_page_with_url_snapshot.html │ ├── create_page_with_web_snap.html │ ├── create_page_with_web_snap_part1.html │ └── simple_page.html │ └── values │ ├── colors.xml │ ├── notebook_snippets.xml │ ├── pages_snippets.xml │ ├── section_snippets.xml │ ├── sectiongroups_snippets.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── onenoteapi ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── microsoft │ └── onenoteapi │ └── service │ ├── DateTimeDeserializer.java │ ├── DateTimeSerializer.java │ ├── GsonDateTime.java │ ├── NotebooksService.java │ ├── OneNotePartsMap.java │ ├── PagesService.java │ ├── PatchCommand.java │ ├── SectionGroupsService.java │ └── SectionsService.java ├── onenotevos ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── microsoft │ └── onenotevos │ ├── BaseVO.java │ ├── Envelope.java │ ├── Links.java │ ├── Notebook.java │ ├── Page.java │ ├── Section.java │ └── SectionGroup.java ├── readme-images ├── AADPermissions.jpg ├── OneNotePermissions.jpg ├── create_page.png ├── detail.png ├── list.png └── login.png └── settings.gradle /.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 | /gradle 18 | /gradlew 19 | /gradlew.bat 20 | /local.properties 21 | Thumbs.db 22 | bin/ 23 | build/ 24 | gen/ 25 | gradle/ 26 | out/ 27 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Use the new Docker builds 2 | sudo: false 3 | language: android 4 | android: 5 | components: 6 | - platform-tools 7 | - extra 8 | - android-22 9 | - build-tools-22.0.1 10 | 11 | script: 12 | - gradle clean build 13 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Microsoft 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 13 | all 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 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /Notices.MD: -------------------------------------------------------------------------------- 1 | #Third Party Notices for Android REST API Explorer 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 | - Portions of this project are reproduced from work created and [shared by the Android Open Source Project](http://www.google.com/policies/). 6 | - MS Open Tech MSA Auth for Android, which is Copyright (c) Microsoft Open Technologies, Inc. and is available under the MIT license: [http://opensource.org/licenses/MIT](https://github.com/MSOpenTech/msa-auth-for-android/blob/dev/LICENSE). 7 | - [Azure Active Directory Authentication Library for Android](https://github.com/AzureAD/azure-activedirectory-library-for-android), which is Copyright (c) Microsoft Open Technologies, Inc. and is available under the Apache 2.0 license: [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0) ("License"). 8 | - [Dagger](https://github.com/square/dagger), which is Copyright (c) Square, Inc. and is available under the Apache License, Version 2.0 (the "License"). 9 | - [Retrofit](https://github.com/square/retrofit), which is Copyright (c) Square, Inc. and is available under the Apache License, Version 2.0 (the "License"). 10 | - [Okhttp](https://github.com/square/okhttp), which is Copyright (c) Square, Inc. and is available under the Apache License, Version 2.0 (the "License"). 11 | - [Butterknife](https://github.com/JakeWharton/butterknife), which is Copyright (c) Jake Wharton, and is available under the Apache License, Version 2.0 (the "License"). 12 | - [Timber](https://github.com/JakeWharton/timber), which is Copyright (c) Jake Wharton, and is available under the Apache License, Version 2.0 (the "License"). 13 | 14 | -------------------------------------------------------------------------------- /O365-auth/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /O365-auth/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 22 5 | buildToolsVersion "22.0.1" 6 | 7 | defaultConfig { 8 | minSdkVersion 15 9 | targetSdkVersion 22 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | compile 'com.android.support:appcompat-v7:22.1.1' 23 | 24 | // Dependency injection 25 | compile 'com.squareup.dagger:dagger:1.2.2' 26 | provided 'com.squareup.dagger:dagger-compiler:1.2.2' 27 | 28 | // Azure AD 29 | compile 'com.microsoft.aad:adal:1.1.3' 30 | } 31 | -------------------------------------------------------------------------------- /O365-auth/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/brianmel/Library/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 | #} 18 | -------------------------------------------------------------------------------- /O365-auth/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /O365-auth/src/main/java/com/microsoft/AuthenticationManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. 3 | * See full license at the bottom of this file. 4 | */ 5 | package com.microsoft; 6 | 7 | import android.app.Activity; 8 | import android.content.Context; 9 | import android.content.SharedPreferences; 10 | 11 | import com.microsoft.aad.adal.ADALError; 12 | import com.microsoft.aad.adal.AuthenticationCallback; 13 | import com.microsoft.aad.adal.AuthenticationContext; 14 | import com.microsoft.aad.adal.AuthenticationException; 15 | import com.microsoft.aad.adal.AuthenticationResult; 16 | import com.microsoft.aad.adal.PromptBehavior; 17 | 18 | import static com.microsoft.aad.adal.AuthenticationResult.AuthenticationStatus.Succeeded; 19 | 20 | public class AuthenticationManager { 21 | 22 | private static final String USER_ID_VAR_NAME = "userId"; 23 | 24 | private static final int PREFERENCES_MODE = Context.MODE_PRIVATE; 25 | 26 | private final Activity mActivity; 27 | 28 | private final AuthenticationContext mAuthenticationContext; 29 | 30 | private final String 31 | mAuthenticationResourceId, 32 | mSharedPreferencesFilename, 33 | mClientId, 34 | mRedirectUri; 35 | 36 | AuthenticationManager( 37 | Activity activity, 38 | AuthenticationContext authenticationContext, 39 | String authenticationResourceId, 40 | String sharedPreferencesFilename, 41 | String clientId, 42 | String redirectUri) { 43 | mActivity = activity; 44 | mAuthenticationContext = authenticationContext; 45 | mAuthenticationResourceId = authenticationResourceId; 46 | mSharedPreferencesFilename = sharedPreferencesFilename; 47 | mClientId = clientId; 48 | mRedirectUri = redirectUri; 49 | } 50 | 51 | private SharedPreferences getSharedPreferences() { 52 | return mActivity.getSharedPreferences(mSharedPreferencesFilename, PREFERENCES_MODE); 53 | } 54 | 55 | public void connect(AuthenticationCallback authenticationCallback) { 56 | if (isConnected()) { 57 | authenticateSilent(authenticationCallback); 58 | } else { 59 | authenticatePrompt(authenticationCallback); 60 | } 61 | } 62 | 63 | /** 64 | * Disconnects the app from Office 365 by clearing the token cache, setting the client objects 65 | * to null, and removing the user id from shred preferences. 66 | */ 67 | public void disconnect() { 68 | // Clear tokens. 69 | if (mAuthenticationContext.getCache() != null) { 70 | mAuthenticationContext.getCache().removeAll(); 71 | } 72 | 73 | // Forget the user 74 | removeUserId(); 75 | } 76 | 77 | private void authenticatePrompt( 78 | final AuthenticationCallback authenticationCallback) { 79 | mAuthenticationContext 80 | .acquireToken( 81 | mAuthenticationResourceId, 82 | mClientId, 83 | mRedirectUri, 84 | null, 85 | PromptBehavior.Always, 86 | null, 87 | new AuthenticationCallback() { 88 | @Override 89 | public void onSuccess(final AuthenticationResult authenticationResult) { 90 | if (Succeeded == authenticationResult.getStatus()) { 91 | setUserId(authenticationResult.getUserInfo().getUserId()); 92 | authenticationCallback.onSuccess(authenticationResult); 93 | } else { 94 | onError( 95 | new AuthenticationException(ADALError.AUTH_FAILED, 96 | authenticationResult.getErrorCode())); 97 | } 98 | } 99 | 100 | @Override 101 | public void onError(Exception e) { 102 | disconnect(); 103 | authenticationCallback.onError(e); 104 | } 105 | } 106 | ); 107 | } 108 | 109 | private void authenticateSilent( 110 | final AuthenticationCallback authenticationCallback) { 111 | mAuthenticationContext.acquireTokenSilent( 112 | mAuthenticationResourceId, 113 | mClientId, 114 | getUserId(), 115 | new AuthenticationCallback() { 116 | @Override 117 | public void onSuccess(AuthenticationResult authenticationResult) { 118 | authenticationCallback.onSuccess(authenticationResult); 119 | } 120 | 121 | @Override 122 | public void onError(Exception e) { 123 | authenticatePrompt(authenticationCallback); 124 | } 125 | }); 126 | } 127 | 128 | private boolean isConnected() { 129 | return getSharedPreferences().contains(USER_ID_VAR_NAME); 130 | } 131 | 132 | private String getUserId() { 133 | return getSharedPreferences().getString(USER_ID_VAR_NAME, ""); 134 | } 135 | 136 | private void setUserId(String value) { 137 | SharedPreferences.Editor editor = getSharedPreferences().edit(); 138 | editor.putString(USER_ID_VAR_NAME, value); 139 | editor.apply(); 140 | } 141 | 142 | private void removeUserId() { 143 | SharedPreferences.Editor editor = getSharedPreferences().edit(); 144 | editor.remove(USER_ID_VAR_NAME); 145 | editor.apply(); 146 | } 147 | 148 | } 149 | // ********************************************************* 150 | // 151 | // Android-REST-API-Explorer, https://github.com/OneNoteDev/Android-REST-API-Explorer 152 | // 153 | // Copyright (c) Microsoft Corporation 154 | // All rights reserved. 155 | // 156 | // MIT License: 157 | // Permission is hereby granted, free of charge, to any person obtaining 158 | // a copy of this software and associated documentation files (the 159 | // "Software"), to deal in the Software without restriction, including 160 | // without limitation the rights to use, copy, modify, merge, publish, 161 | // distribute, sublicense, and/or sell copies of the Software, and to 162 | // permit persons to whom the Software is furnished to do so, subject to 163 | // the following conditions: 164 | // 165 | // The above copyright notice and this permission notice shall be 166 | // included in all copies or substantial portions of the Software. 167 | // 168 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 169 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 170 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 171 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 172 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 173 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 174 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 175 | // 176 | // ********************************************************* -------------------------------------------------------------------------------- /O365-auth/src/main/java/com/microsoft/AzureADModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. 3 | * See full license at the bottom of this file. 4 | */ 5 | package com.microsoft; 6 | 7 | import android.app.Activity; 8 | 9 | import com.microsoft.aad.adal.AuthenticationContext; 10 | import com.microsoft.aad.adal.AuthenticationSettings; 11 | 12 | import java.security.NoSuchAlgorithmException; 13 | 14 | import javax.crypto.NoSuchPaddingException; 15 | 16 | import dagger.Module; 17 | import dagger.Provides; 18 | 19 | @Module(library = true) 20 | public class AzureADModule { 21 | 22 | private final Builder mBuilder; 23 | 24 | protected AzureADModule(Builder builder) { 25 | mBuilder = builder; 26 | } 27 | 28 | public static class Builder { 29 | 30 | private static final String SHARED_PREFS_DEFAULT_NAME = "AzureAD_Preferences"; 31 | 32 | private Activity mActivity; 33 | 34 | private String 35 | mAuthorityUrl, // the authority used to authenticate 36 | mAuthenticationResourceId, // the resource id used to authenticate 37 | mSharedPreferencesFilename = SHARED_PREFS_DEFAULT_NAME, 38 | mClientId, 39 | mRedirectUri; 40 | 41 | private boolean mValidateAuthority = true; 42 | 43 | public Builder(Activity activity) { 44 | mActivity = activity; 45 | } 46 | 47 | public Builder authorityUrl(String authorityUrl) { 48 | mAuthorityUrl = authorityUrl; 49 | return this; 50 | } 51 | 52 | public Builder authenticationResourceId(String authenticationResourceId) { 53 | mAuthenticationResourceId = authenticationResourceId; 54 | return this; 55 | } 56 | 57 | public Builder validateAuthority(boolean shouldEvaluate) { 58 | mValidateAuthority = shouldEvaluate; 59 | return this; 60 | } 61 | 62 | public Builder skipBroker(boolean shouldSkip) { 63 | AzureADModule.skipBroker(shouldSkip); 64 | return this; 65 | } 66 | 67 | public Builder sharedPreferencesFilename(String filename) { 68 | mSharedPreferencesFilename = filename; 69 | return this; 70 | } 71 | 72 | public Builder clientId(String clientId) { 73 | mClientId = clientId; 74 | return this; 75 | } 76 | 77 | public Builder redirectUri(String redirectUri) { 78 | mRedirectUri = redirectUri; 79 | return this; 80 | } 81 | 82 | public AzureADModule build() { 83 | if (null == mAuthorityUrl) { 84 | throw new IllegalStateException("authorityUrl() is unset"); 85 | } 86 | if (null == mAuthenticationResourceId) { 87 | throw new IllegalStateException("authenticationResourceId() is unset"); 88 | } 89 | if (null == mSharedPreferencesFilename) { 90 | mSharedPreferencesFilename = SHARED_PREFS_DEFAULT_NAME; 91 | } 92 | if (null == mClientId) { 93 | throw new IllegalStateException("clientId() is unset"); 94 | } 95 | if (null == mRedirectUri) { 96 | throw new IllegalStateException("redirectUri() is unset"); 97 | } 98 | return new AzureADModule(this); 99 | } 100 | 101 | } 102 | 103 | public static void skipBroker(boolean shouldSkip) { 104 | AuthenticationSettings.INSTANCE.setSkipBroker(shouldSkip); 105 | } 106 | 107 | @Provides 108 | public AuthenticationContext providesAuthenticationContext() { 109 | try { 110 | return new AuthenticationContext( 111 | mBuilder.mActivity, 112 | mBuilder.mAuthorityUrl, 113 | mBuilder.mValidateAuthority); 114 | } catch (NoSuchAlgorithmException | NoSuchPaddingException e) { 115 | throw new RuntimeException(e); 116 | } 117 | } 118 | 119 | @Provides 120 | public AuthenticationManager providesAuthenticationManager( 121 | AuthenticationContext authenticationContext) { 122 | return new AuthenticationManager( 123 | mBuilder.mActivity, 124 | authenticationContext, 125 | mBuilder.mAuthenticationResourceId, 126 | mBuilder.mSharedPreferencesFilename, 127 | mBuilder.mClientId, 128 | mBuilder.mRedirectUri); 129 | } 130 | 131 | } 132 | // ********************************************************* 133 | // 134 | // Android-REST-API-Explorer, https://github.com/OneNoteDev/Android-REST-API-Explorer 135 | // 136 | // Copyright (c) Microsoft Corporation 137 | // All rights reserved. 138 | // 139 | // MIT License: 140 | // Permission is hereby granted, free of charge, to any person obtaining 141 | // a copy of this software and associated documentation files (the 142 | // "Software"), to deal in the Software without restriction, including 143 | // without limitation the rights to use, copy, modify, merge, publish, 144 | // distribute, sublicense, and/or sell copies of the Software, and to 145 | // permit persons to whom the Software is furnished to do so, subject to 146 | // the following conditions: 147 | // 148 | // The above copyright notice and this permission notice shall be 149 | // included in all copies or substantial portions of the Software. 150 | // 151 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 152 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 153 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 154 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 155 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 156 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 157 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 158 | // 159 | // ********************************************************* -------------------------------------------------------------------------------- /O365-auth/src/main/java/com/microsoft/AzureAppCompatActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. 3 | * See full license at the bottom of this file. 4 | */ 5 | package com.microsoft; 6 | 7 | import android.os.Bundle; 8 | import android.support.v7.app.AppCompatActivity; 9 | 10 | import com.microsoft.aad.adal.AuthenticationContext; 11 | 12 | import javax.inject.Inject; 13 | 14 | import dagger.ObjectGraph; 15 | 16 | public abstract class AzureAppCompatActivity extends AppCompatActivity { 17 | 18 | protected ObjectGraph mObjectGraph; 19 | 20 | @Inject 21 | protected AuthenticationManager mAuthenticationManager; 22 | 23 | @Inject 24 | protected AuthenticationContext mAuthenticationContext; 25 | 26 | @Override 27 | protected void onCreate(Bundle savedInstanceState) { 28 | super.onCreate(savedInstanceState); 29 | 30 | Object[] modules = new Object[getModules().length + 1]; 31 | int ii = 0; 32 | modules[ii++] = getAzureADModule(); 33 | for (Object module : getModules()) { 34 | modules[ii++] = module; 35 | } 36 | 37 | mObjectGraph = getRootGraph(); 38 | if (null == mObjectGraph) { 39 | // create a new one 40 | mObjectGraph = ObjectGraph.create(modules); 41 | } else { 42 | // extend the existing one 43 | mObjectGraph = mObjectGraph.plus(modules); 44 | } 45 | 46 | mObjectGraph.inject(this); 47 | } 48 | 49 | protected abstract AzureADModule getAzureADModule(); 50 | 51 | protected abstract Object[] getModules(); 52 | 53 | protected ObjectGraph getRootGraph() { 54 | return null; 55 | } 56 | 57 | } 58 | // ********************************************************* 59 | // 60 | // Android-REST-API-Explorer, https://github.com/OneNoteDev/Android-REST-API-Explorer 61 | // 62 | // Copyright (c) Microsoft Corporation 63 | // All rights reserved. 64 | // 65 | // MIT License: 66 | // Permission is hereby granted, free of charge, to any person obtaining 67 | // a copy of this software and associated documentation files (the 68 | // "Software"), to deal in the Software without restriction, including 69 | // without limitation the rights to use, copy, modify, merge, publish, 70 | // distribute, sublicense, and/or sell copies of the Software, and to 71 | // permit persons to whom the Software is furnished to do so, subject to 72 | // the following conditions: 73 | // 74 | // The above copyright notice and this permission notice shall be 75 | // included in all copies or substantial portions of the Software. 76 | // 77 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 78 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 79 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 80 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 81 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 82 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 83 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 84 | // 85 | // ********************************************************* -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 22 5 | buildToolsVersion "22.0.1" 6 | 7 | defaultConfig { 8 | applicationId "com.microsoft.o365_android_onenote_rest" 9 | minSdkVersion 15 10 | targetSdkVersion 22 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 | packagingOptions { 21 | exclude 'META-INF/LICENSE.txt' 22 | exclude 'META-INF/NOTICE.txt' 23 | } 24 | } 25 | 26 | dependencies { 27 | // Support libs 28 | compile 'com.android.support:appcompat-v7:22.1.1' 29 | 30 | // Azure AD 31 | compile(project(':O365-auth')) { 32 | exclude group: 'com.android.support' 33 | } 34 | 35 | // MSA Authentication 36 | compile 'com.microsoft.orc:live-auth:0.14.2' 37 | 38 | // Dagger compiler for DI annotation support 39 | provided 'com.squareup.dagger:dagger-compiler:1.2.2' 40 | 41 | // OneNote's rest 42 | compile(project(':onenoteapi')) 43 | 44 | // Butterknife 45 | compile 'com.jakewharton:butterknife:6.1.0' 46 | 47 | // Timber 48 | compile 'com.jakewharton.timber:timber:3.1.0' 49 | 50 | // Apache Commons 51 | compile 'commons-io:commons-io:2.4' 52 | compile 'org.apache.commons:commons-lang3:3.4' 53 | } 54 | -------------------------------------------------------------------------------- /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/brianmel/Library/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 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 23 | 27 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/o365_android_onenote_rest/BaseActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 3 | */ 4 | 5 | package com.microsoft.o365_android_onenote_rest; 6 | 7 | import com.microsoft.AzureADModule; 8 | import com.microsoft.AzureAppCompatActivity; 9 | import com.microsoft.live.LiveAuthClient; 10 | import com.microsoft.o365_android_onenote_rest.application.SnippetApp; 11 | import com.microsoft.o365_android_onenote_rest.conf.ServiceConstants; 12 | import com.microsoft.o365_android_onenote_rest.inject.AzureModule; 13 | import com.microsoft.o365_android_onenote_rest.inject.ObjectGraphInjector; 14 | import com.microsoft.o365_android_onenote_rest.model.Scope; 15 | 16 | import java.util.ArrayList; 17 | 18 | import javax.inject.Inject; 19 | 20 | import dagger.ObjectGraph; 21 | import timber.log.Timber; 22 | 23 | public abstract class BaseActivity 24 | extends AzureAppCompatActivity 25 | implements ObjectGraphInjector { 26 | 27 | @Inject 28 | protected LiveAuthClient mLiveAuthClient; 29 | 30 | public static final Iterable sSCOPES = new ArrayList() {{ 31 | for (Scope.wl scope : Scope.wl.values()) { 32 | Timber.i("Adding scope: " + scope); 33 | add(scope.getScope()); 34 | } 35 | for (Scope.office scope : Scope.office.values()) { 36 | Timber.i("Adding scope: " + scope); 37 | add(scope.getScope()); 38 | } 39 | }}; 40 | 41 | @Override 42 | protected AzureADModule getAzureADModule() { 43 | AzureADModule.Builder builder = new AzureADModule.Builder(this); 44 | builder.validateAuthority(true) 45 | .skipBroker(true) 46 | .authenticationResourceId(ServiceConstants.AUTHENTICATION_RESOURCE_ID) 47 | .authorityUrl(ServiceConstants.AUTHORITY_URL) 48 | .redirectUri(ServiceConstants.REDIRECT_URI) 49 | .clientId(ServiceConstants.CLIENT_ID); 50 | return builder.build(); 51 | } 52 | 53 | @Override 54 | protected Object[] getModules() { 55 | return new Object[]{new AzureModule()}; 56 | } 57 | 58 | @Override 59 | protected ObjectGraph getRootGraph() { 60 | return SnippetApp.getApp().mObjectGraph; 61 | } 62 | 63 | @Override 64 | public void inject(Object target) { 65 | mObjectGraph.inject(target); 66 | } 67 | } 68 | // ********************************************************* 69 | // 70 | // Android-REST-API-Explorer, https://github.com/OneNoteDev/Android-REST-API-Explorer 71 | // 72 | // Copyright (c) Microsoft Corporation 73 | // All rights reserved. 74 | // 75 | // MIT License: 76 | // Permission is hereby granted, free of charge, to any person obtaining 77 | // a copy of this software and associated documentation files (the 78 | // "Software"), to deal in the Software without restriction, including 79 | // without limitation the rights to use, copy, modify, merge, publish, 80 | // distribute, sublicense, and/or sell copies of the Software, and to 81 | // permit persons to whom the Software is furnished to do so, subject to 82 | // the following conditions: 83 | // 84 | // The above copyright notice and this permission notice shall be 85 | // included in all copies or substantial portions of the Software. 86 | // 87 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 88 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 89 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 90 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 91 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 92 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 93 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 94 | // 95 | // ********************************************************* -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/o365_android_onenote_rest/BaseFragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 3 | */ 4 | 5 | package com.microsoft.o365_android_onenote_rest; 6 | 7 | import android.os.Bundle; 8 | import android.support.annotation.Nullable; 9 | import android.support.v4.app.Fragment; 10 | 11 | public abstract class BaseFragment extends Fragment { 12 | 13 | @Override 14 | public void onActivityCreated(@Nullable Bundle savedInstanceState) { 15 | super.onActivityCreated(savedInstanceState); 16 | ((BaseActivity) getActivity()).inject(this); 17 | } 18 | 19 | } 20 | // ********************************************************* 21 | // 22 | // Android-REST-API-Explorer, https://github.com/OneNoteDev/Android-REST-API-Explorer 23 | // 24 | // Copyright (c) Microsoft Corporation 25 | // All rights reserved. 26 | // 27 | // MIT License: 28 | // Permission is hereby granted, free of charge, to any person obtaining 29 | // a copy of this software and associated documentation files (the 30 | // "Software"), to deal in the Software without restriction, including 31 | // without limitation the rights to use, copy, modify, merge, publish, 32 | // distribute, sublicense, and/or sell copies of the Software, and to 33 | // permit persons to whom the Software is furnished to do so, subject to 34 | // the following conditions: 35 | // 36 | // The above copyright notice and this permission notice shall be 37 | // included in all copies or substantial portions of the Software. 38 | // 39 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 40 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 41 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 42 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 43 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 44 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 45 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 46 | // 47 | // ********************************************************* -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/o365_android_onenote_rest/SignInActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 3 | */ 4 | package com.microsoft.o365_android_onenote_rest; 5 | 6 | import android.content.Intent; 7 | import android.os.Bundle; 8 | import android.widget.Toast; 9 | 10 | import com.microsoft.aad.adal.AuthenticationCallback; 11 | import com.microsoft.aad.adal.AuthenticationResult; 12 | import com.microsoft.live.LiveAuthException; 13 | import com.microsoft.live.LiveAuthListener; 14 | import com.microsoft.live.LiveConnectSession; 15 | import com.microsoft.live.LiveStatus; 16 | import com.microsoft.o365_android_onenote_rest.conf.ServiceConstants; 17 | import com.microsoft.o365_android_onenote_rest.util.SharedPrefsUtil; 18 | import com.microsoft.o365_android_onenote_rest.util.User; 19 | 20 | import java.net.URI; 21 | import java.util.UUID; 22 | 23 | import butterknife.ButterKnife; 24 | import butterknife.OnClick; 25 | import timber.log.Timber; 26 | 27 | import static com.microsoft.o365_android_onenote_rest.R.id.msa_signin; 28 | import static com.microsoft.o365_android_onenote_rest.R.id.o365_signin; 29 | 30 | public class SignInActivity 31 | extends BaseActivity 32 | implements AuthenticationCallback, LiveAuthListener { 33 | 34 | @Override 35 | protected void onCreate(Bundle savedInstanceState) { 36 | super.onCreate(savedInstanceState); 37 | setContentView(R.layout.activity_signin); 38 | if (User.isOrg()) { 39 | mAuthenticationManager.connect(this); 40 | } 41 | ButterKnife.inject(this); 42 | } 43 | 44 | @OnClick(o365_signin) 45 | public void onSignInO365Clicked() { 46 | try { 47 | authenticateOrganization(); 48 | } catch (IllegalArgumentException e) { 49 | warnBadClient(); 50 | } 51 | } 52 | 53 | private void warnBadClient() { 54 | Toast.makeText(this, 55 | R.string.warning_clientid_redirecturi_incorrect, 56 | Toast.LENGTH_LONG) 57 | .show(); 58 | } 59 | 60 | private void authenticateOrganization() throws IllegalArgumentException { 61 | validateOrganizationArgs(); 62 | if (!User.isOrg()) { 63 | mLiveAuthClient.logout(new LiveAuthListener() { 64 | @Override 65 | public void onAuthComplete(LiveStatus status, 66 | LiveConnectSession session, 67 | Object userState) { 68 | mAuthenticationManager.connect(SignInActivity.this); 69 | } 70 | 71 | @Override 72 | public void onAuthError(LiveAuthException exception, Object userState) { 73 | mAuthenticationManager.connect(SignInActivity.this); 74 | } 75 | }); 76 | } else { 77 | mAuthenticationManager.connect(this); 78 | } 79 | } 80 | 81 | private void validateOrganizationArgs() throws IllegalArgumentException { 82 | UUID.fromString(ServiceConstants.CLIENT_ID); 83 | URI.create(ServiceConstants.REDIRECT_URI); 84 | } 85 | 86 | @OnClick(msa_signin) 87 | public void onSignInMsaClicked() { 88 | authenticateMsa(); 89 | } 90 | 91 | private void authenticateMsa() { 92 | try { 93 | validateMsaArgs(); 94 | mLiveAuthClient.login(this, sSCOPES, this); 95 | } catch (IllegalArgumentException e) { 96 | warnBadClient(); 97 | } 98 | } 99 | 100 | private void validateMsaArgs() throws IllegalArgumentException { 101 | if (ServiceConstants.MSA_CLIENT_ID.equals("")) { 102 | throw new IllegalArgumentException(); 103 | } 104 | } 105 | 106 | @Override 107 | public void onSuccess(AuthenticationResult authenticationResult) { 108 | finish(); 109 | SharedPrefsUtil.persistAuthToken(authenticationResult); 110 | start(); 111 | } 112 | 113 | private void start() { 114 | Intent appLaunch = new Intent(this, SnippetListActivity.class); 115 | startActivity(appLaunch); 116 | } 117 | 118 | @Override 119 | public void onError(Exception e) { 120 | e.printStackTrace(); 121 | String msg; 122 | if (null == (msg = e.getLocalizedMessage())) { 123 | msg = getString(R.string.signin_err); 124 | } 125 | Toast.makeText(this, msg, Toast.LENGTH_SHORT).show(); 126 | } 127 | 128 | @Override 129 | public void onAuthComplete(LiveStatus status, 130 | LiveConnectSession session, 131 | Object userState) { 132 | Timber.d("MSA: Auth Complete..."); 133 | if (null != status) { 134 | Timber.d(status.toString()); 135 | } 136 | if (null != session) { 137 | Timber.d(session.toString()); 138 | SharedPrefsUtil.persistAuthToken(session); 139 | } 140 | if (null != userState) { 141 | Timber.d(userState.toString()); 142 | } 143 | start(); 144 | } 145 | 146 | @Override 147 | public void onAuthError(LiveAuthException exception, Object userState) { 148 | exception.printStackTrace(); 149 | } 150 | } 151 | // ********************************************************* 152 | // 153 | // Android-REST-API-Explorer, https://github.com/OneNoteDev/Android-REST-API-Explorer 154 | // 155 | // Copyright (c) Microsoft Corporation 156 | // All rights reserved. 157 | // 158 | // MIT License: 159 | // Permission is hereby granted, free of charge, to any person obtaining 160 | // a copy of this software and associated documentation files (the 161 | // "Software"), to deal in the Software without restriction, including 162 | // without limitation the rights to use, copy, modify, merge, publish, 163 | // distribute, sublicense, and/or sell copies of the Software, and to 164 | // permit persons to whom the Software is furnished to do so, subject to 165 | // the following conditions: 166 | // 167 | // The above copyright notice and this permission notice shall be 168 | // included in all copies or substantial portions of the Software. 169 | // 170 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 171 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 172 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 173 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 174 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 175 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 176 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 177 | // 178 | // ********************************************************* -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/o365_android_onenote_rest/SnippetDetailActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 3 | */ 4 | package com.microsoft.o365_android_onenote_rest; 5 | 6 | import android.content.Intent; 7 | import android.os.Bundle; 8 | import android.support.v4.app.NavUtils; 9 | import android.view.MenuItem; 10 | 11 | 12 | public class SnippetDetailActivity extends BaseActivity { 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | setContentView(R.layout.activity_snippet_detail); 18 | if (null != getSupportActionBar()) { 19 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 20 | } 21 | if (savedInstanceState == null) { 22 | Bundle arguments = new Bundle(); 23 | arguments.putInt(SnippetDetailFragment.ARG_ITEM_ID, 24 | getIntent().getIntExtra(SnippetDetailFragment.ARG_ITEM_ID, 0)); 25 | SnippetDetailFragment fragment = new SnippetDetailFragment(); 26 | fragment.setArguments(arguments); 27 | getSupportFragmentManager().beginTransaction() 28 | .add(R.id.snippet_detail_container, fragment) 29 | .commit(); 30 | } 31 | } 32 | 33 | @Override 34 | public boolean onOptionsItemSelected(MenuItem item) { 35 | int id = item.getItemId(); 36 | if (id == android.R.id.home) { 37 | NavUtils.navigateUpTo(this, new Intent(this, SnippetListActivity.class)); 38 | return true; 39 | } 40 | return super.onOptionsItemSelected(item); 41 | } 42 | } 43 | // ********************************************************* 44 | // 45 | // Android-REST-API-Explorer, https://github.com/OneNoteDev/Android-REST-API-Explorer 46 | // 47 | // Copyright (c) Microsoft Corporation 48 | // All rights reserved. 49 | // 50 | // MIT License: 51 | // Permission is hereby granted, free of charge, to any person obtaining 52 | // a copy of this software and associated documentation files (the 53 | // "Software"), to deal in the Software without restriction, including 54 | // without limitation the rights to use, copy, modify, merge, publish, 55 | // distribute, sublicense, and/or sell copies of the Software, and to 56 | // permit persons to whom the Software is furnished to do so, subject to 57 | // the following conditions: 58 | // 59 | // The above copyright notice and this permission notice shall be 60 | // included in all copies or substantial portions of the Software. 61 | // 62 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 63 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 64 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 65 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 66 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 67 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 68 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 69 | // 70 | // ********************************************************* -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/o365_android_onenote_rest/SnippetListActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 3 | */ 4 | package com.microsoft.o365_android_onenote_rest; 5 | 6 | import android.content.Context; 7 | import android.content.Intent; 8 | import android.os.Bundle; 9 | 10 | import com.microsoft.o365_android_onenote_rest.inject.AppModule; 11 | import com.microsoft.o365_android_onenote_rest.util.User; 12 | 13 | 14 | public class SnippetListActivity extends BaseActivity 15 | implements SnippetListFragment.Callbacks { 16 | 17 | private boolean mTwoPane; 18 | 19 | @Override 20 | protected void onCreate(Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | setContentView(R.layout.activity_snippet_list); 23 | 24 | if (findViewById(R.id.snippet_detail_container) != null) { 25 | // The detail container view will be present only in the 26 | // large-screen layouts (res/values-large and 27 | // res/values-sw600dp). If this view is present, then the 28 | // activity should be in two-pane mode. 29 | mTwoPane = true; 30 | 31 | // In two-pane mode, list items should be given the 32 | // 'activated' state when touched. 33 | ((SnippetListFragment) getSupportFragmentManager() 34 | .findFragmentById(R.id.snippet_list)) 35 | .setActivateOnItemClick(true); 36 | } 37 | } 38 | 39 | @Override 40 | public void onItemSelected(int position) { 41 | if (mTwoPane) { 42 | // In two-pane mode, show the detail view in this activity by 43 | // adding or replacing the detail fragment using a 44 | // fragment transaction. 45 | Bundle arguments = new Bundle(); 46 | arguments.putInt(SnippetDetailFragment.ARG_ITEM_ID, position); 47 | SnippetDetailFragment fragment = new SnippetDetailFragment(); 48 | fragment.setArguments(arguments); 49 | getSupportFragmentManager().beginTransaction() 50 | .replace(R.id.snippet_detail_container, fragment) 51 | .commit(); 52 | } else { 53 | // In single-pane mode, simply start the detail activity 54 | // for the selected item ID. 55 | Intent detailIntent = new Intent(this, SnippetDetailActivity.class); 56 | detailIntent.putExtra(SnippetDetailFragment.ARG_ITEM_ID, position); 57 | startActivity(detailIntent); 58 | } 59 | } 60 | 61 | @Override 62 | public void onDisconnectClicked() { 63 | finish(); 64 | 65 | if (User.isOrg()) { 66 | mAuthenticationManager.disconnect(); 67 | } else if (User.isMsa()) { 68 | mLiveAuthClient.logout(null); 69 | } 70 | // drop the application shared preferences to clear any old auth tokens 71 | getSharedPreferences(AppModule.PREFS, Context.MODE_PRIVATE) 72 | .edit() // get the editor 73 | .clear() // clear it 74 | .apply(); // asynchronously apply 75 | Intent login = new Intent(this, SignInActivity.class); 76 | login.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 77 | startActivity(login); 78 | } 79 | } 80 | // ********************************************************* 81 | // 82 | // Android-REST-API-Explorer, https://github.com/OneNoteDev/Android-REST-API-Explorer 83 | // 84 | // Copyright (c) Microsoft Corporation 85 | // All rights reserved. 86 | // 87 | // MIT License: 88 | // Permission is hereby granted, free of charge, to any person obtaining 89 | // a copy of this software and associated documentation files (the 90 | // "Software"), to deal in the Software without restriction, including 91 | // without limitation the rights to use, copy, modify, merge, publish, 92 | // distribute, sublicense, and/or sell copies of the Software, and to 93 | // permit persons to whom the Software is furnished to do so, subject to 94 | // the following conditions: 95 | // 96 | // The above copyright notice and this permission notice shall be 97 | // included in all copies or substantial portions of the Software. 98 | // 99 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 100 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 101 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 102 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 103 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 104 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 105 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 106 | // 107 | // ********************************************************* -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/o365_android_onenote_rest/SnippetListAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 3 | */ 4 | package com.microsoft.o365_android_onenote_rest; 5 | 6 | import android.content.Context; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.BaseAdapter; 11 | import android.widget.TextView; 12 | 13 | import com.microsoft.o365_android_onenote_rest.snippet.AbstractSnippet; 14 | import com.microsoft.o365_android_onenote_rest.snippet.SnippetContent; 15 | 16 | public class SnippetListAdapter extends BaseAdapter { 17 | 18 | public static final String UNAVAILABLE = "unavailable"; 19 | public static final String BETA = "beta"; 20 | private Context mContext; 21 | private LayoutInflater mLayoutInflater; 22 | 23 | @Override 24 | public int getCount() { 25 | return SnippetContent.ITEMS.size(); 26 | } 27 | 28 | @Override 29 | public AbstractSnippet getItem(int position) { 30 | return (AbstractSnippet) SnippetContent.ITEMS.get(position); 31 | } 32 | 33 | @Override 34 | public long getItemId(int position) { 35 | return 0; 36 | } 37 | 38 | @Override 39 | public boolean isEnabled(int position) { 40 | return null != getItem(position).getDescription() 41 | && !hasStatus(getItem(position), UNAVAILABLE); 42 | } 43 | 44 | @Override 45 | public View getView(int position, View convertView, ViewGroup parent) { 46 | if (null == mContext) { 47 | mContext = parent.getContext(); 48 | mLayoutInflater = LayoutInflater.from(mContext); 49 | } 50 | 51 | AbstractSnippet clickedSnippet = getItem(position); 52 | boolean isSegment = (null == clickedSnippet.getDescription()); 53 | 54 | final int id = isSegment ? R.layout.list_segment : R.layout.list_element; 55 | if (null == convertView || isWrongViewType(isSegment, convertView)) { 56 | convertView = mLayoutInflater.inflate(id, parent, false); 57 | } 58 | 59 | TextView name = (TextView) convertView.findViewById(R.id.txt_snippet_name); 60 | name.setText(clickedSnippet.getName()); 61 | 62 | if (!isSegment) { 63 | TextView betaIndicator = (TextView) convertView.findViewById(R.id.beta_indicator); 64 | if (hasStatus(clickedSnippet, UNAVAILABLE)) { 65 | betaIndicator.setText(mContext.getString(R.string.unavailable).toUpperCase()); 66 | } 67 | if (hasStatus(clickedSnippet, BETA)) { 68 | betaIndicator.setText(R.string.beta); 69 | betaIndicator.setVisibility(View.VISIBLE); 70 | } 71 | } 72 | 73 | return convertView; 74 | } 75 | 76 | private boolean hasStatus(AbstractSnippet clickedSnippet, String unavailable) { 77 | return clickedSnippet.getVersion().equalsIgnoreCase(unavailable); 78 | } 79 | 80 | private boolean isWrongViewType(boolean isSegment, View convertView) { 81 | View v = convertView.findViewById(R.id.beta_indicator); 82 | return !isSegment && null == v || (isSegment && null != v); 83 | } 84 | 85 | } 86 | // ********************************************************* 87 | // 88 | // Android-REST-API-Explorer, https://github.com/OneNoteDev/Android-REST-API-Explorer 89 | // 90 | // Copyright (c) Microsoft Corporation 91 | // All rights reserved. 92 | // 93 | // MIT License: 94 | // Permission is hereby granted, free of charge, to any person obtaining 95 | // a copy of this software and associated documentation files (the 96 | // "Software"), to deal in the Software without restriction, including 97 | // without limitation the rights to use, copy, modify, merge, publish, 98 | // distribute, sublicense, and/or sell copies of the Software, and to 99 | // permit persons to whom the Software is furnished to do so, subject to 100 | // the following conditions: 101 | // 102 | // The above copyright notice and this permission notice shall be 103 | // included in all copies or substantial portions of the Software. 104 | // 105 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 106 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 107 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 108 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 109 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 110 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 111 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 112 | // 113 | // ********************************************************* -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/o365_android_onenote_rest/SnippetListFragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 3 | */ 4 | 5 | package com.microsoft.o365_android_onenote_rest; 6 | 7 | import android.app.Activity; 8 | import android.os.Bundle; 9 | import android.support.v4.app.ListFragment; 10 | import android.view.Menu; 11 | import android.view.MenuInflater; 12 | import android.view.MenuItem; 13 | import android.view.View; 14 | import android.widget.ListView; 15 | 16 | public class SnippetListFragment extends ListFragment { 17 | 18 | private static final String STATE_ACTIVATED_POSITION = "activated_position"; 19 | 20 | private Callbacks mCallbacks = sDummyCallbacks; 21 | 22 | private int mActivatedPosition = ListView.INVALID_POSITION; 23 | 24 | public interface Callbacks { 25 | void onItemSelected(int position); 26 | 27 | void onDisconnectClicked(); 28 | } 29 | 30 | private static Callbacks sDummyCallbacks = new Callbacks() { 31 | @Override 32 | public void onItemSelected(int position) { 33 | } 34 | 35 | @Override 36 | public void onDisconnectClicked() { 37 | } 38 | }; 39 | 40 | public SnippetListFragment() { 41 | } 42 | 43 | @Override 44 | public void onCreate(Bundle savedInstanceState) { 45 | super.onCreate(savedInstanceState); 46 | setHasOptionsMenu(true); 47 | setListAdapter(new SnippetListAdapter()); 48 | } 49 | 50 | @Override 51 | public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 52 | inflater.inflate(R.menu.snippet_list_menu, menu); 53 | super.onCreateOptionsMenu(menu, inflater); 54 | } 55 | 56 | @Override 57 | public boolean onOptionsItemSelected(MenuItem item) { 58 | if (R.id.disconnect == item.getItemId()) { 59 | mCallbacks.onDisconnectClicked(); 60 | return true; 61 | } 62 | return super.onOptionsItemSelected(item); 63 | } 64 | 65 | @Override 66 | public void onViewCreated(View view, Bundle savedInstanceState) { 67 | super.onViewCreated(view, savedInstanceState); 68 | 69 | // Restore the previously serialized activated item position. 70 | if (savedInstanceState != null 71 | && savedInstanceState.containsKey(STATE_ACTIVATED_POSITION)) { 72 | setActivatedPosition(savedInstanceState.getInt(STATE_ACTIVATED_POSITION)); 73 | } 74 | } 75 | 76 | @Override 77 | public void onAttach(Activity activity) { 78 | super.onAttach(activity); 79 | 80 | // Activities containing this fragment must implement its callbacks. 81 | if (!(activity instanceof Callbacks)) { 82 | throw new IllegalStateException("Activity must implement fragment's callbacks."); 83 | } 84 | 85 | mCallbacks = (Callbacks) activity; 86 | } 87 | 88 | @Override 89 | public void onDetach() { 90 | super.onDetach(); 91 | 92 | // Reset the active callbacks interface to the dummy implementation. 93 | mCallbacks = sDummyCallbacks; 94 | } 95 | 96 | @Override 97 | public void onListItemClick(ListView listView, View view, int position, long id) { 98 | super.onListItemClick(listView, view, position, id); 99 | mCallbacks.onItemSelected(position); 100 | } 101 | 102 | @Override 103 | public void onSaveInstanceState(Bundle outState) { 104 | super.onSaveInstanceState(outState); 105 | if (mActivatedPosition != ListView.INVALID_POSITION) { 106 | // Serialize and persist the activated item position. 107 | outState.putInt(STATE_ACTIVATED_POSITION, mActivatedPosition); 108 | } 109 | } 110 | 111 | public void setActivateOnItemClick(boolean activateOnItemClick) { 112 | // When setting CHOICE_MODE_SINGLE, ListView will automatically 113 | // give items the 'activated' state when touched. 114 | getListView().setChoiceMode(activateOnItemClick 115 | ? ListView.CHOICE_MODE_SINGLE 116 | : ListView.CHOICE_MODE_NONE); 117 | } 118 | 119 | private void setActivatedPosition(int position) { 120 | if (position == ListView.INVALID_POSITION) { 121 | getListView().setItemChecked(mActivatedPosition, false); 122 | } else { 123 | getListView().setItemChecked(position, true); 124 | } 125 | 126 | mActivatedPosition = position; 127 | } 128 | } 129 | // ********************************************************* 130 | // 131 | // Android-REST-API-Explorer, https://github.com/OneNoteDev/Android-REST-API-Explorer 132 | // 133 | // Copyright (c) Microsoft Corporation 134 | // All rights reserved. 135 | // 136 | // MIT License: 137 | // Permission is hereby granted, free of charge, to any person obtaining 138 | // a copy of this software and associated documentation files (the 139 | // "Software"), to deal in the Software without restriction, including 140 | // without limitation the rights to use, copy, modify, merge, publish, 141 | // distribute, sublicense, and/or sell copies of the Software, and to 142 | // permit persons to whom the Software is furnished to do so, subject to 143 | // the following conditions: 144 | // 145 | // The above copyright notice and this permission notice shall be 146 | // included in all copies or substantial portions of the Software. 147 | // 148 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 149 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 150 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 151 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 152 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 153 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 154 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 155 | // 156 | // ********************************************************* -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/o365_android_onenote_rest/application/SnippetApp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 3 | */ 4 | 5 | package com.microsoft.o365_android_onenote_rest.application; 6 | 7 | import android.app.Application; 8 | 9 | import com.microsoft.o365_android_onenote_rest.BuildConfig; 10 | import com.microsoft.o365_android_onenote_rest.inject.AppModule; 11 | 12 | import javax.inject.Inject; 13 | 14 | import dagger.ObjectGraph; 15 | import retrofit.RequestInterceptor; 16 | import retrofit.RestAdapter; 17 | import retrofit.converter.Converter; 18 | import timber.log.Timber; 19 | 20 | public class SnippetApp extends Application { 21 | /** 22 | * The {@link dagger.ObjectGraph} used by Dagger to fulfill @inject annotations 23 | * 24 | * @see javax.inject.Inject 25 | * @see dagger.Provides 26 | * @see javax.inject.Singleton 27 | */ 28 | public ObjectGraph mObjectGraph; 29 | 30 | private static SnippetApp sSnippetApp; 31 | 32 | @Inject 33 | protected String endpoint; 34 | 35 | @Inject 36 | protected Converter converter; 37 | 38 | @Inject 39 | protected RestAdapter.LogLevel logLevel; 40 | 41 | @Inject 42 | protected RequestInterceptor requestInterceptor; 43 | 44 | @Override 45 | public void onCreate() { 46 | super.onCreate(); 47 | sSnippetApp = this; 48 | mObjectGraph = ObjectGraph.create(new AppModule()); 49 | mObjectGraph.inject(this); 50 | if (BuildConfig.DEBUG) { 51 | Timber.plant(new Timber.DebugTree()); 52 | } 53 | } 54 | 55 | public static SnippetApp getApp() { 56 | return sSnippetApp; 57 | } 58 | 59 | public RestAdapter getRestAdapter() { 60 | return new RestAdapter.Builder() 61 | .setEndpoint(endpoint) 62 | .setLogLevel(logLevel) 63 | .setConverter(converter) 64 | .setRequestInterceptor(requestInterceptor) 65 | .build(); 66 | } 67 | } 68 | // ********************************************************* 69 | // 70 | // Android-REST-API-Explorer, https://github.com/OneNoteDev/Android-REST-API-Explorer 71 | // 72 | // Copyright (c) Microsoft Corporation 73 | // All rights reserved. 74 | // 75 | // MIT License: 76 | // Permission is hereby granted, free of charge, to any person obtaining 77 | // a copy of this software and associated documentation files (the 78 | // "Software"), to deal in the Software without restriction, including 79 | // without limitation the rights to use, copy, modify, merge, publish, 80 | // distribute, sublicense, and/or sell copies of the Software, and to 81 | // permit persons to whom the Software is furnished to do so, subject to 82 | // the following conditions: 83 | // 84 | // The above copyright notice and this permission notice shall be 85 | // included in all copies or substantial portions of the Software. 86 | // 87 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 88 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 89 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 90 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 91 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 92 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 93 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 94 | // 95 | // ********************************************************* -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/o365_android_onenote_rest/conf/ServiceConstants.java: -------------------------------------------------------------------------------- 1 | package com.microsoft.o365_android_onenote_rest.conf; 2 | 3 | public class ServiceConstants { 4 | 5 | // MSA 6 | public static final String MSA_CLIENT_ID = ""; 7 | public static final String ONENOTE_API = "https://www.onenote.com/api"; 8 | // Org 9 | public static final String AUTHENTICATION_RESOURCE_ID = "https://onenote.com"; 10 | public static final String AUTHORITY_URL = "https://login.microsoftonline.com/common"; 11 | public static final String REDIRECT_URI = ""; 12 | public static final String CLIENT_ID = ""; 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/o365_android_onenote_rest/inject/AppModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 3 | */ 4 | 5 | package com.microsoft.o365_android_onenote_rest.inject; 6 | 7 | import android.content.Context; 8 | import android.content.SharedPreferences; 9 | 10 | import com.microsoft.live.LiveAuthClient; 11 | import com.microsoft.o365_android_onenote_rest.application.SnippetApp; 12 | import com.microsoft.o365_android_onenote_rest.conf.ServiceConstants; 13 | import com.microsoft.o365_android_onenote_rest.util.SharedPrefsUtil; 14 | import com.microsoft.onenoteapi.service.GsonDateTime; 15 | 16 | import javax.inject.Singleton; 17 | 18 | import dagger.Module; 19 | import dagger.Provides; 20 | import retrofit.RequestInterceptor; 21 | import retrofit.RestAdapter; 22 | import retrofit.converter.Converter; 23 | import retrofit.converter.GsonConverter; 24 | 25 | @Module(library = true, 26 | injects = { 27 | SnippetApp.class 28 | } 29 | ) 30 | public class AppModule { 31 | 32 | public static final String PREFS = "com.microsoft.o365_android_onenote_rest"; 33 | 34 | @Provides 35 | public String providesRestEndpoint() { 36 | return ServiceConstants.ONENOTE_API; 37 | } 38 | 39 | @Provides 40 | public RestAdapter.LogLevel providesLogLevel() { 41 | return RestAdapter.LogLevel.FULL; 42 | } 43 | 44 | @Provides 45 | public Converter providesConverter() { 46 | return new GsonConverter(GsonDateTime.getOneNoteBuilder() 47 | .create()); 48 | } 49 | 50 | @Provides 51 | public RequestInterceptor providesRequestInterceptor() { 52 | return new RequestInterceptor() { 53 | @Override 54 | public void intercept(RequestFacade request) { 55 | // apply the Authorization header if we had a token... 56 | final SharedPreferences preferences 57 | = SnippetApp.getApp().getSharedPreferences(PREFS, Context.MODE_PRIVATE); 58 | final String token = 59 | preferences.getString(SharedPrefsUtil.PREF_AUTH_TOKEN, null); 60 | if (null != token) { 61 | request.addHeader("Authorization", "Bearer " + token); 62 | } 63 | } 64 | }; 65 | } 66 | 67 | @Provides 68 | @Singleton 69 | public LiveAuthClient providesLiveAuthClient() { 70 | return new LiveAuthClient(SnippetApp.getApp(), ServiceConstants.MSA_CLIENT_ID); 71 | } 72 | } 73 | // ********************************************************* 74 | // 75 | // Android-REST-API-Explorer, https://github.com/OneNoteDev/Android-REST-API-Explorer 76 | // 77 | // Copyright (c) Microsoft Corporation 78 | // All rights reserved. 79 | // 80 | // MIT License: 81 | // Permission is hereby granted, free of charge, to any person obtaining 82 | // a copy of this software and associated documentation files (the 83 | // "Software"), to deal in the Software without restriction, including 84 | // without limitation the rights to use, copy, modify, merge, publish, 85 | // distribute, sublicense, and/or sell copies of the Software, and to 86 | // permit persons to whom the Software is furnished to do so, subject to 87 | // the following conditions: 88 | // 89 | // The above copyright notice and this permission notice shall be 90 | // included in all copies or substantial portions of the Software. 91 | // 92 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 93 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 94 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 95 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 96 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 97 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 98 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 99 | // 100 | // ********************************************************* 101 | -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/o365_android_onenote_rest/inject/AzureModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 3 | */ 4 | package com.microsoft.o365_android_onenote_rest.inject; 5 | 6 | import com.microsoft.AzureADModule; 7 | import com.microsoft.o365_android_onenote_rest.SignInActivity; 8 | import com.microsoft.o365_android_onenote_rest.SnippetDetailActivity; 9 | import com.microsoft.o365_android_onenote_rest.SnippetDetailFragment; 10 | import com.microsoft.o365_android_onenote_rest.SnippetListActivity; 11 | 12 | import dagger.Module; 13 | 14 | @Module(includes = AzureADModule.class, 15 | complete = false, 16 | injects = { 17 | SignInActivity.class, 18 | SnippetListActivity.class, 19 | SnippetDetailActivity.class, 20 | SnippetDetailFragment.class 21 | } 22 | ) 23 | public class AzureModule { 24 | } 25 | // ********************************************************* 26 | // 27 | // Android-REST-API-Explorer, https://github.com/OneNoteDev/Android-REST-API-Explorer 28 | // 29 | // Copyright (c) Microsoft Corporation 30 | // All rights reserved. 31 | // 32 | // MIT License: 33 | // Permission is hereby granted, free of charge, to any person obtaining 34 | // a copy of this software and associated documentation files (the 35 | // "Software"), to deal in the Software without restriction, including 36 | // without limitation the rights to use, copy, modify, merge, publish, 37 | // distribute, sublicense, and/or sell copies of the Software, and to 38 | // permit persons to whom the Software is furnished to do so, subject to 39 | // the following conditions: 40 | // 41 | // The above copyright notice and this permission notice shall be 42 | // included in all copies or substantial portions of the Software. 43 | // 44 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 45 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 46 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 47 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 48 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 49 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 50 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 51 | // 52 | // ********************************************************* -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/o365_android_onenote_rest/inject/ObjectGraphInjector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 3 | */ 4 | 5 | package com.microsoft.o365_android_onenote_rest.inject; 6 | 7 | public interface ObjectGraphInjector { 8 | 9 | void inject(Object target); 10 | 11 | } 12 | // ********************************************************* 13 | // 14 | // Android-REST-API-Explorer, https://github.com/OneNoteDev/Android-REST-API-Explorer 15 | // 16 | // Copyright (c) Microsoft Corporation 17 | // All rights reserved. 18 | // 19 | // MIT License: 20 | // Permission is hereby granted, free of charge, to any person obtaining 21 | // a copy of this software and associated documentation files (the 22 | // "Software"), to deal in the Software without restriction, including 23 | // without limitation the rights to use, copy, modify, merge, publish, 24 | // distribute, sublicense, and/or sell copies of the Software, and to 25 | // permit persons to whom the Software is furnished to do so, subject to 26 | // the following conditions: 27 | // 28 | // The above copyright notice and this permission notice shall be 29 | // included in all copies or substantial portions of the Software. 30 | // 31 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 32 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 33 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 34 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 35 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 36 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 37 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 38 | // 39 | // ********************************************************* -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/o365_android_onenote_rest/model/Scope.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 3 | */ 4 | package com.microsoft.o365_android_onenote_rest.model; 5 | 6 | import com.microsoft.o365_android_onenote_rest.application.SnippetApp; 7 | 8 | import static com.microsoft.o365_android_onenote_rest.R.string.on_base; 9 | import static com.microsoft.o365_android_onenote_rest.R.string.on_create; 10 | import static com.microsoft.o365_android_onenote_rest.R.string.on_update; 11 | import static com.microsoft.o365_android_onenote_rest.R.string.wl_offline_access; 12 | import static com.microsoft.o365_android_onenote_rest.R.string.wl_signin; 13 | 14 | public class Scope { 15 | 16 | public static final String DELIM = "\n---\n"; 17 | 18 | public enum wl { 19 | signin(wl_signin), 20 | offline_access(wl_offline_access); 21 | 22 | public final String mDescription; 23 | 24 | wl(int desc) { 25 | mDescription = getString(desc); 26 | } 27 | 28 | public String getScope() { 29 | return "wl." + name(); 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return getScope() + DELIM + mDescription; 35 | } 36 | } 37 | 38 | public enum office { 39 | onenote_create(on_create), 40 | onenote_update(on_update), 41 | onenote(on_base); 42 | 43 | public final String mDescription; 44 | 45 | office(int desc) { 46 | mDescription = getString(desc); 47 | } 48 | 49 | public String getScope() { 50 | return "office." + name(); 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return getScope() + DELIM + mDescription; 56 | } 57 | } 58 | 59 | private static String getString(int res) { 60 | return SnippetApp.getApp().getString(res); 61 | } 62 | } 63 | // ********************************************************* 64 | // 65 | // Android-REST-API-Explorer, https://github.com/OneNoteDev/Android-REST-API-Explorer 66 | // 67 | // Copyright (c) Microsoft Corporation 68 | // All rights reserved. 69 | // 70 | // MIT License: 71 | // Permission is hereby granted, free of charge, to any person obtaining 72 | // a copy of this software and associated documentation files (the 73 | // "Software"), to deal in the Software without restriction, including 74 | // without limitation the rights to use, copy, modify, merge, publish, 75 | // distribute, sublicense, and/or sell copies of the Software, and to 76 | // permit persons to whom the Software is furnished to do so, subject to 77 | // the following conditions: 78 | // 79 | // The above copyright notice and this permission notice shall be 80 | // included in all copies or substantial portions of the Software. 81 | // 82 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 83 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 84 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 85 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 86 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 87 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 88 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 89 | // 90 | // ********************************************************* 91 | -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/o365_android_onenote_rest/snippet/AbstractSnippet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 3 | */ 4 | 5 | package com.microsoft.o365_android_onenote_rest.snippet; 6 | 7 | import com.microsoft.o365_android_onenote_rest.application.SnippetApp; 8 | import com.microsoft.o365_android_onenote_rest.util.User; 9 | import com.microsoft.onenoteapi.service.NotebooksService; 10 | import com.microsoft.onenoteapi.service.PagesService; 11 | import com.microsoft.onenoteapi.service.SectionGroupsService; 12 | import com.microsoft.onenoteapi.service.SectionsService; 13 | 14 | import static com.microsoft.o365_android_onenote_rest.snippet.SnippetCategory.notebookSnippetCategory; 15 | import static com.microsoft.o365_android_onenote_rest.snippet.SnippetCategory.pagesSnippetCategory; 16 | import static com.microsoft.o365_android_onenote_rest.snippet.SnippetCategory.sectionGroupsSnippetCategory; 17 | import static com.microsoft.o365_android_onenote_rest.snippet.SnippetCategory.sectionsSnippetCategory; 18 | 19 | /** 20 | * The base class for snippets 21 | * 22 | * @param the service which descendants will use to make their calls 23 | * @param the expected object to be returned by the service 24 | */ 25 | public abstract class AbstractSnippet { 26 | 27 | public static final Services sServices = new Services(); 28 | 29 | private String mName, mDesc, mSection, mUrl, mO365Version, mMSAVersion; 30 | public final Service mService; 31 | public final Input mInputArgs; 32 | 33 | private static final int sNameIndex = 0; 34 | private static final int sDescIndex = 1; 35 | private static final int sUrlIndex = 2; 36 | private static final int sO365VersionIndex = 3; 37 | private static final int sMSAVersionIndex = 4; 38 | 39 | 40 | /** 41 | * Snippet constructor 42 | * 43 | * @param category Snippet category (Notebook, sectionGroup, section, page) 44 | * @param descriptionArray The String array for the specified snippet 45 | */ 46 | public AbstractSnippet( 47 | SnippetCategory category, 48 | Integer descriptionArray) { 49 | 50 | //Get snippet configuration information from the 51 | //XML configuration for the snippet 52 | getSnippetArrayContent(category, descriptionArray); 53 | 54 | mService = category.mService; 55 | mInputArgs = Input.None; 56 | } 57 | 58 | /** 59 | * Snippet constructor 60 | * 61 | * @param category Snippet category (Notebook, sectionGroup, section, page) 62 | * @param descriptionArray The String array for the specified snippet 63 | * @param inputArgs any input arguments 64 | */ 65 | public AbstractSnippet( 66 | SnippetCategory category, 67 | Integer descriptionArray, 68 | Input inputArgs) { 69 | 70 | //Get snippet configuration information from the 71 | //XML configuration for the snippet 72 | getSnippetArrayContent(category, descriptionArray); 73 | 74 | mSection = category.mSection; 75 | mService = category.mService; 76 | mInputArgs = inputArgs; 77 | } 78 | 79 | /** 80 | * Gets the items from the specified snippet XML string array and stores the values 81 | * in private class fields 82 | * 83 | * @param category 84 | * @param descriptionArray 85 | */ 86 | private void getSnippetArrayContent(SnippetCategory category, Integer descriptionArray) { 87 | if (null != descriptionArray) { 88 | String[] params = SnippetApp.getApp().getResources().getStringArray(descriptionArray); 89 | 90 | try { 91 | mName = params[sNameIndex]; 92 | mDesc = params[sDescIndex]; 93 | mUrl = params[sUrlIndex]; 94 | mO365Version = params[sO365VersionIndex]; 95 | mMSAVersion = params[sMSAVersionIndex]; 96 | } catch (IndexOutOfBoundsException ex) { 97 | throw new RuntimeException( 98 | "Invalid array in " 99 | + category.mSection 100 | + " snippet XML file" 101 | , ex); 102 | } 103 | } else { 104 | mName = category.mSection; 105 | mDesc = mUrl = null; 106 | mO365Version = null; 107 | mMSAVersion = null; 108 | } 109 | mSection = category.mSection; 110 | } 111 | 112 | protected static class Services { 113 | 114 | public final NotebooksService mNotebooksService; 115 | public final PagesService mPagesService; 116 | public final SectionGroupsService mSectionGroupsService; 117 | public final SectionsService mSectionsService; 118 | 119 | Services() { 120 | mNotebooksService = notebookSnippetCategory.mService; 121 | mPagesService = pagesSnippetCategory.mService; 122 | mSectionGroupsService = sectionGroupsSnippetCategory.mService; 123 | mSectionsService = sectionsSnippetCategory.mService; 124 | } 125 | } 126 | 127 | @SuppressWarnings("unused") 128 | public void setUp(Services services, retrofit.Callback callback) { 129 | // Optional method.... 130 | callback.success(new String[]{}, null); 131 | } 132 | 133 | /** 134 | * Returns the version segment of the endpoint url with input from 135 | * XML snippet description and authentication method (Office 365, MSA) 136 | * 137 | * @return the version of the endpoint to use 138 | */ 139 | public String getVersion() { 140 | return User.isMsa() ? mMSAVersion : mO365Version; 141 | } 142 | 143 | 144 | public String getName() { 145 | return mName; 146 | } 147 | 148 | public String getDescription() { 149 | return mDesc; 150 | } 151 | 152 | public String getUrl() { 153 | return mUrl; 154 | } 155 | 156 | public String getSection() { 157 | return mSection; 158 | } 159 | 160 | /** 161 | * Abstract declaration of method which subclasses must define to actually run the snippet 162 | * 163 | * @param service the service instance to use 164 | * @param callback the recipient of the result 165 | */ 166 | public abstract void request(Service service, Callback callback); 167 | 168 | } 169 | // ********************************************************* 170 | // 171 | // Android-REST-API-Explorer, https://github.com/OneNoteDev/Android-REST-API-Explorer 172 | // 173 | // Copyright (c) Microsoft Corporation 174 | // All rights reserved. 175 | // 176 | // MIT License: 177 | // Permission is hereby granted, free of charge, to any person obtaining 178 | // a copy of this software and associated documentation files (the 179 | // "Software"), to deal in the Software without restriction, including 180 | // without limitation the rights to use, copy, modify, merge, publish, 181 | // distribute, sublicense, and/or sell copies of the Software, and to 182 | // permit persons to whom the Software is furnished to do so, subject to 183 | // the following conditions: 184 | // 185 | // The above copyright notice and this permission notice shall be 186 | // included in all copies or substantial portions of the Software. 187 | // 188 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 189 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 190 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 191 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 192 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 193 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 194 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 195 | // 196 | // ********************************************************* 197 | -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/o365_android_onenote_rest/snippet/Callback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 3 | */ 4 | package com.microsoft.o365_android_onenote_rest.snippet; 5 | 6 | import java.util.Map; 7 | 8 | public interface Callback extends retrofit.Callback { 9 | 10 | Map getParams(); 11 | } 12 | // ********************************************************* 13 | // 14 | // Android-REST-API-Explorer, https://github.com/OneNoteDev/Android-REST-API-Explorer 15 | // 16 | // Copyright (c) Microsoft Corporation 17 | // All rights reserved. 18 | // 19 | // MIT License: 20 | // Permission is hereby granted, free of charge, to any person obtaining 21 | // a copy of this software and associated documentation files (the 22 | // "Software"), to deal in the Software without restriction, including 23 | // without limitation the rights to use, copy, modify, merge, publish, 24 | // distribute, sublicense, and/or sell copies of the Software, and to 25 | // permit persons to whom the Software is furnished to do so, subject to 26 | // the following conditions: 27 | // 28 | // The above copyright notice and this permission notice shall be 29 | // included in all copies or substantial portions of the Software. 30 | // 31 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 32 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 33 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 34 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 35 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 36 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 37 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 38 | // 39 | // ********************************************************* -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/o365_android_onenote_rest/snippet/Input.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 3 | */ 4 | package com.microsoft.o365_android_onenote_rest.snippet; 5 | 6 | public enum Input { 7 | None, Text, Spinner, Both 8 | } 9 | // ********************************************************* 10 | // 11 | // Android-REST-API-Explorer, https://github.com/OneNoteDev/Android-REST-API-Explorer 12 | // 13 | // Copyright (c) Microsoft Corporation 14 | // All rights reserved. 15 | // 16 | // MIT License: 17 | // Permission is hereby granted, free of charge, to any person obtaining 18 | // a copy of this software and associated documentation files (the 19 | // "Software"), to deal in the Software without restriction, including 20 | // without limitation the rights to use, copy, modify, merge, publish, 21 | // distribute, sublicense, and/or sell copies of the Software, and to 22 | // permit persons to whom the Software is furnished to do so, subject to 23 | // the following conditions: 24 | // 25 | // The above copyright notice and this permission notice shall be 26 | // included in all copies or substantial portions of the Software. 27 | // 28 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 29 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 30 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 31 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 32 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 33 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 34 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 35 | // 36 | // ********************************************************* -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/o365_android_onenote_rest/snippet/SectionGroupSnippet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 3 | */ 4 | 5 | package com.microsoft.o365_android_onenote_rest.snippet; 6 | 7 | import com.google.gson.JsonObject; 8 | import com.microsoft.o365_android_onenote_rest.SnippetDetailFragment; 9 | import com.microsoft.onenoteapi.service.SectionGroupsService; 10 | import com.microsoft.onenotevos.Envelope; 11 | import com.microsoft.onenotevos.Notebook; 12 | import com.microsoft.onenotevos.SectionGroup; 13 | 14 | import java.util.HashMap; 15 | import java.util.Map; 16 | 17 | import retrofit.RetrofitError; 18 | import retrofit.client.Response; 19 | import retrofit.mime.TypedString; 20 | 21 | import static com.microsoft.o365_android_onenote_rest.R.array.create_sectiongroup_in_notebook; 22 | import static com.microsoft.o365_android_onenote_rest.R.array.create_sectiongroup_in_sectiongroup; 23 | import static com.microsoft.o365_android_onenote_rest.R.array.list_sectiongroups; 24 | import static com.microsoft.o365_android_onenote_rest.R.array.list_sectiongroups_in_a_notebook; 25 | 26 | public abstract class SectionGroupSnippet 27 | extends AbstractSnippet { 28 | 29 | public SectionGroupSnippet(Integer descriptionArray) { 30 | super(SnippetCategory.sectionGroupsSnippetCategory, descriptionArray); 31 | } 32 | 33 | public SectionGroupSnippet(Integer descriptionArray, Input input) { 34 | super(SnippetCategory.sectionGroupsSnippetCategory, descriptionArray, input); 35 | } 36 | 37 | static SectionGroupSnippet[] getSectionGroupsSnippets() { 38 | return new SectionGroupSnippet[]{ 39 | // Marker element 40 | new SectionGroupSnippet(null) { 41 | @Override 42 | public void request(SectionGroupsService service, Callback callback) { 43 | // Not implemented 44 | } 45 | }, 46 | 47 | /* 48 | * Gets all of the Section groups for all of a user's notebooks 49 | * @see http://dev.onenote.com/docs#/reference/get-sectiongroups/v10menotessectiongroupsfilterorderbyselectexpandtopskipcount 50 | */ 51 | new SectionGroupSnippet>(list_sectiongroups) { 52 | 53 | 54 | @Override 55 | public void request(SectionGroupsService service, 56 | Callback> callback) { 57 | service.getSectionGroups( 58 | getVersion(), 59 | null, 60 | null, 61 | null, 62 | null, 63 | null, 64 | null, 65 | callback); 66 | 67 | } 68 | }, 69 | 70 | /* 71 | * Gets all section groups for a given notebook 72 | * @see http://dev.onenote.com/docs#/reference/get-sectiongroups/v10menotesnotebooksidsectiongroupsfilterorderbyselectexpandtopskipcount 73 | */ 74 | new SectionGroupSnippet>( 75 | list_sectiongroups_in_a_notebook, Input.Spinner) { 76 | 77 | Map notebookMap = new HashMap<>(); 78 | 79 | @Override 80 | public void setUp(Services services, final retrofit.Callback callback) { 81 | fillNotebookSpinner(services, callback, notebookMap); 82 | } 83 | 84 | @Override 85 | public void request(SectionGroupsService service, Callback> callback) { 86 | Notebook notebook = notebookMap.get( 87 | callback.getParams().get( 88 | SnippetDetailFragment.ARG_SPINNER_SELECTION)); 89 | service.getSectionGroupsForNotebook(getVersion(), 90 | notebook.id, 91 | null, 92 | null, 93 | null, 94 | null, 95 | null, 96 | null, 97 | callback); 98 | } 99 | }, 100 | 101 | /* 102 | * Creates a new section group with a name in a notebook specified by id 103 | */ 104 | new SectionGroupSnippet>(create_sectiongroup_in_notebook, Input.Both) { 105 | 106 | Map notebookMap = new HashMap<>(); 107 | 108 | @Override 109 | public void setUp( 110 | Services services, 111 | final retrofit.Callback callback) { 112 | fillNotebookSpinner(services, callback, notebookMap); 113 | } 114 | 115 | //Create the JSON body of a new section request. 116 | //The body sets the section name 117 | TypedString createSectionGroup(String sectionName) { 118 | JsonObject jsonObject = new JsonObject(); 119 | jsonObject.addProperty("name", sectionName); 120 | return new TypedString(jsonObject.toString()) { 121 | @Override 122 | public String mimeType() { 123 | return "application/json"; 124 | } 125 | }; 126 | } 127 | 128 | @Override 129 | public void request(SectionGroupsService service, Callback> callback) { 130 | 131 | Notebook notebook = notebookMap.get(callback 132 | .getParams() 133 | .get(SnippetDetailFragment.ARG_SPINNER_SELECTION)); 134 | 135 | service.postSectionGroupInNotebook( 136 | getVersion(), 137 | "application/json", 138 | notebook.id, 139 | createSectionGroup(callback 140 | .getParams() 141 | .get(SnippetDetailFragment.ARG_TEXT_INPUT)), 142 | callback 143 | ); 144 | } 145 | }, 146 | 147 | /* 148 | * Creates a new section with a title in a notebook specified by id 149 | */ 150 | new SectionGroupSnippet>(create_sectiongroup_in_sectiongroup, Input.Both) { 151 | 152 | Map sectionGroupMap = new HashMap<>(); 153 | 154 | @Override 155 | public void setUp( 156 | Services services, 157 | final retrofit.Callback callback) { 158 | fillSectionGroupSpinner(services, callback, sectionGroupMap); 159 | } 160 | 161 | //Create the JSON body of a new section request. 162 | //The body sets the section name 163 | TypedString createSectionGroupInSectionGroup(String sectionName) { 164 | JsonObject jsonObject = new JsonObject(); 165 | jsonObject.addProperty("name", sectionName); 166 | return new TypedString(jsonObject.toString()) { 167 | @Override 168 | public String mimeType() { 169 | return "application/json"; 170 | } 171 | }; 172 | } 173 | 174 | @Override 175 | public void request(SectionGroupsService service, 176 | Callback> callback) { 177 | 178 | SectionGroup sectionGroup = sectionGroupMap.get(callback 179 | .getParams() 180 | .get(SnippetDetailFragment.ARG_SPINNER_SELECTION)); 181 | 182 | service.postSectionGroupInSectionGroup( 183 | getVersion(), 184 | "application/json", 185 | sectionGroup.id, 186 | createSectionGroupInSectionGroup(callback 187 | .getParams() 188 | .get(SnippetDetailFragment.ARG_TEXT_INPUT)), 189 | callback 190 | ); 191 | } 192 | } 193 | }; 194 | } 195 | 196 | @Override 197 | public abstract void request(SectionGroupsService service, Callback callback); 198 | 199 | protected void fillNotebookSpinner( 200 | Services services, 201 | final retrofit.Callback callback, 202 | final Map notebookMap) { 203 | services.mNotebooksService.getNotebooks(getVersion(), 204 | null, 205 | null, 206 | null, 207 | null, 208 | null, 209 | null, 210 | new Callback>() { 211 | 212 | @Override 213 | public void success(Envelope notebookEnvelope, Response response) { 214 | Notebook[] notebooks = notebookEnvelope.value; 215 | String[] bookNames = new String[notebooks.length]; 216 | for (int i = 0; i < notebooks.length; i++) { 217 | bookNames[i] = notebooks[i].name; 218 | notebookMap.put(notebooks[i].name, notebooks[i]); 219 | } 220 | callback.success(bookNames, response); 221 | } 222 | 223 | @Override 224 | public void failure(RetrofitError error) { 225 | 226 | } 227 | 228 | @Override 229 | public Map getParams() { 230 | return null; 231 | } 232 | }); 233 | } 234 | 235 | protected void fillSectionGroupSpinner( 236 | Services services, 237 | final retrofit.Callback callback, 238 | final Map sectionGroupMap) { 239 | services.mSectionGroupsService.getSectionGroups(getVersion(), 240 | null, 241 | null, 242 | null, 243 | null, 244 | null, 245 | null, 246 | new Callback>() { 247 | 248 | @Override 249 | public void success(Envelope sectionGroupEnvelope, Response response) { 250 | SectionGroup[] sectionGroups = sectionGroupEnvelope.value; 251 | String[] sectionGroupNames = new String[sectionGroups.length]; 252 | for (int i = 0; i < sectionGroups.length; i++) { 253 | sectionGroupNames[i] = sectionGroups[i].name; 254 | sectionGroupMap.put(sectionGroups[i].name, sectionGroups[i]); 255 | } 256 | callback.success(sectionGroupNames, response); 257 | } 258 | 259 | @Override 260 | public void failure(RetrofitError error) { 261 | 262 | } 263 | 264 | @Override 265 | public Map getParams() { 266 | return null; 267 | } 268 | }); 269 | } 270 | 271 | } 272 | // ********************************************************* 273 | // 274 | // Android-REST-API-Explorer, https://github.com/OneNoteDev/Android-REST-API-Explorer 275 | // 276 | // Copyright (c) Microsoft Corporation 277 | // All rights reserved. 278 | // 279 | // MIT License: 280 | // Permission is hereby granted, free of charge, to any person obtaining 281 | // a copy of this software and associated documentation files (the 282 | // "Software"), to deal in the Software without restriction, including 283 | // without limitation the rights to use, copy, modify, merge, publish, 284 | // distribute, sublicense, and/or sell copies of the Software, and to 285 | // permit persons to whom the Software is furnished to do so, subject to 286 | // the following conditions: 287 | // 288 | // The above copyright notice and this permission notice shall be 289 | // included in all copies or substantial portions of the Software. 290 | // 291 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 292 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 293 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 294 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 295 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 296 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 297 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 298 | // 299 | // ********************************************************* -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/o365_android_onenote_rest/snippet/SnippetCategory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 3 | */ 4 | 5 | package com.microsoft.o365_android_onenote_rest.snippet; 6 | 7 | import com.microsoft.o365_android_onenote_rest.application.SnippetApp; 8 | import com.microsoft.onenoteapi.service.NotebooksService; 9 | import com.microsoft.onenoteapi.service.PagesService; 10 | import com.microsoft.onenoteapi.service.SectionGroupsService; 11 | import com.microsoft.onenoteapi.service.SectionsService; 12 | 13 | import static com.microsoft.o365_android_onenote_rest.R.string.section_notebooks; 14 | import static com.microsoft.o365_android_onenote_rest.R.string.section_pages; 15 | import static com.microsoft.o365_android_onenote_rest.R.string.section_sectiongroups; 16 | import static com.microsoft.o365_android_onenote_rest.R.string.section_sections; 17 | 18 | public class SnippetCategory { 19 | static final SnippetCategory notebookSnippetCategory 20 | = new SnippetCategory<>(section_notebooks, create(NotebooksService.class)); 21 | 22 | static final SnippetCategory pagesSnippetCategory 23 | = new SnippetCategory<>(section_pages, create(PagesService.class)); 24 | 25 | static final SnippetCategory sectionGroupsSnippetCategory 26 | = new SnippetCategory<>(section_sectiongroups, create(SectionGroupsService.class)); 27 | 28 | static final SnippetCategory sectionsSnippetCategory 29 | = new SnippetCategory<>(section_sections, create(SectionsService.class)); 30 | 31 | final String mSection; 32 | final T mService; 33 | 34 | SnippetCategory(int sectionId, T service) { 35 | mSection = SnippetApp.getApp().getString(sectionId); 36 | mService = service; 37 | } 38 | 39 | private static T create(Class clazz) { 40 | return SnippetApp.getApp().getRestAdapter().create(clazz); 41 | } 42 | } 43 | // ********************************************************* 44 | // 45 | // Android-REST-API-Explorer, https://github.com/OneNoteDev/Android-REST-API-Explorer 46 | // 47 | // Copyright (c) Microsoft Corporation 48 | // All rights reserved. 49 | // 50 | // MIT License: 51 | // Permission is hereby granted, free of charge, to any person obtaining 52 | // a copy of this software and associated documentation files (the 53 | // "Software"), to deal in the Software without restriction, including 54 | // without limitation the rights to use, copy, modify, merge, publish, 55 | // distribute, sublicense, and/or sell copies of the Software, and to 56 | // permit persons to whom the Software is furnished to do so, subject to 57 | // the following conditions: 58 | // 59 | // The above copyright notice and this permission notice shall be 60 | // included in all copies or substantial portions of the Software. 61 | // 62 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 63 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 64 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 65 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 66 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 67 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 68 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 69 | // 70 | // ********************************************************* -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/o365_android_onenote_rest/snippet/SnippetContent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 3 | */ 4 | 5 | package com.microsoft.o365_android_onenote_rest.snippet; 6 | 7 | import java.util.ArrayList; 8 | import java.util.Collections; 9 | import java.util.List; 10 | 11 | import static com.microsoft.o365_android_onenote_rest.snippet.NotebookSnippet.getNotebookSnippets; 12 | import static com.microsoft.o365_android_onenote_rest.snippet.PagesSnippet.getPagesSnippets; 13 | import static com.microsoft.o365_android_onenote_rest.snippet.SectionGroupSnippet.getSectionGroupsSnippets; 14 | import static com.microsoft.o365_android_onenote_rest.snippet.SectionSnippet.getSectionsServiceSnippets; 15 | 16 | public class SnippetContent { 17 | 18 | public static List> ITEMS = new ArrayList<>(); 19 | 20 | static { 21 | AbstractSnippet[][] baseSnippets = new AbstractSnippet[][]{ 22 | getNotebookSnippets(), 23 | getPagesSnippets(), 24 | getSectionGroupsSnippets(), 25 | getSectionsServiceSnippets() 26 | }; 27 | 28 | for (AbstractSnippet[] snippetArray : baseSnippets) { 29 | Collections.addAll(ITEMS, snippetArray); 30 | } 31 | } 32 | 33 | } 34 | // ********************************************************* 35 | // 36 | // Android-REST-API-Explorer, https://github.com/OneNoteDev/Android-REST-API-Explorer 37 | // 38 | // Copyright (c) Microsoft Corporation 39 | // All rights reserved. 40 | // 41 | // MIT License: 42 | // Permission is hereby granted, free of charge, to any person obtaining 43 | // a copy of this software and associated documentation files (the 44 | // "Software"), to deal in the Software without restriction, including 45 | // without limitation the rights to use, copy, modify, merge, publish, 46 | // distribute, sublicense, and/or sell copies of the Software, and to 47 | // permit persons to whom the Software is furnished to do so, subject to 48 | // the following conditions: 49 | // 50 | // The above copyright notice and this permission notice shall be 51 | // included in all copies or substantial portions of the Software. 52 | // 53 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 54 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 55 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 56 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 57 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 58 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 59 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 60 | // 61 | // ********************************************************* -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/o365_android_onenote_rest/util/SharedPrefsUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 3 | */ 4 | package com.microsoft.o365_android_onenote_rest.util; 5 | 6 | import android.content.Context; 7 | import android.content.SharedPreferences; 8 | 9 | import com.microsoft.aad.adal.AuthenticationResult; 10 | import com.microsoft.live.LiveConnectSession; 11 | import com.microsoft.o365_android_onenote_rest.application.SnippetApp; 12 | import com.microsoft.o365_android_onenote_rest.inject.AppModule; 13 | 14 | public class SharedPrefsUtil { 15 | 16 | public static final String PREF_AUTH_TOKEN = "PREF_AUTH_TOKEN"; 17 | 18 | public static SharedPreferences getSharedPreferences() { 19 | return SnippetApp.getApp().getSharedPreferences(AppModule.PREFS, Context.MODE_PRIVATE); 20 | } 21 | 22 | public static void persistAuthToken(AuthenticationResult result) { 23 | setAccessToken(result.getAccessToken()); 24 | User.isOrg(true); 25 | } 26 | 27 | public static void persistAuthToken(LiveConnectSession session) { 28 | setAccessToken(session.getAccessToken()); 29 | User.isMsa(true); 30 | } 31 | 32 | private static void setAccessToken(String accessToken) { 33 | getSharedPreferences().edit().putString(PREF_AUTH_TOKEN, accessToken).commit(); 34 | } 35 | } 36 | // ********************************************************* 37 | // 38 | // Android-REST-API-Explorer, https://github.com/OneNoteDev/Android-REST-API-Explorer 39 | // 40 | // Copyright (c) Microsoft Corporation 41 | // All rights reserved. 42 | // 43 | // MIT License: 44 | // Permission is hereby granted, free of charge, to any person obtaining 45 | // a copy of this software and associated documentation files (the 46 | // "Software"), to deal in the Software without restriction, including 47 | // without limitation the rights to use, copy, modify, merge, publish, 48 | // distribute, sublicense, and/or sell copies of the Software, and to 49 | // permit persons to whom the Software is furnished to do so, subject to 50 | // the following conditions: 51 | // 52 | // The above copyright notice and this permission notice shall be 53 | // included in all copies or substantial portions of the Software. 54 | // 55 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 56 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 57 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 58 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 59 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 60 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 61 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 62 | // 63 | // ********************************************************* -------------------------------------------------------------------------------- /app/src/main/java/com/microsoft/o365_android_onenote_rest/util/User.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. 3 | */ 4 | package com.microsoft.o365_android_onenote_rest.util; 5 | 6 | public class User { 7 | 8 | private static final String PREF_MSA = "PREF_MSA"; 9 | private static final String PREF_ORG = "PREF_ORG"; 10 | 11 | static void isMsa(boolean msa) { 12 | set(PREF_MSA, msa); 13 | } 14 | 15 | static void isOrg(boolean org) { 16 | set(PREF_ORG, org); 17 | } 18 | 19 | public static boolean isMsa() { 20 | return is(PREF_MSA); 21 | } 22 | 23 | public static boolean isOrg() { 24 | return is(PREF_ORG); 25 | } 26 | 27 | private static boolean is(String which) { 28 | return SharedPrefsUtil.getSharedPreferences().getBoolean(which, false); 29 | } 30 | 31 | private static void set(String which, boolean state) { 32 | SharedPrefsUtil 33 | .getSharedPreferences() 34 | .edit() 35 | .putBoolean(which, state) 36 | .commit(); 37 | } 38 | } 39 | // ********************************************************* 40 | // 41 | // Android-REST-API-Explorer, https://github.com/OneNoteDev/Android-REST-API-Explorer 42 | // 43 | // Copyright (c) Microsoft Corporation 44 | // All rights reserved. 45 | // 46 | // MIT License: 47 | // Permission is hereby granted, free of charge, to any person obtaining 48 | // a copy of this software and associated documentation files (the 49 | // "Software"), to deal in the Software without restriction, including 50 | // without limitation the rights to use, copy, modify, merge, publish, 51 | // distribute, sublicense, and/or sell copies of the Software, and to 52 | // permit persons to whom the Software is furnished to do so, subject to 53 | // the following conditions: 54 | // 55 | // The above copyright notice and this permission notice shall be 56 | // included in all copies or substantial portions of the Software. 57 | // 58 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 59 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 60 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 61 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 62 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 63 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 64 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 65 | // 66 | // ********************************************************* -------------------------------------------------------------------------------- /app/src/main/res/drawable/attachment.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OneNoteDev/Android-REST-API-Explorer/a3436b1f0a4df87df541a592fb3b118915827e00/app/src/main/res/drawable/attachment.pdf -------------------------------------------------------------------------------- /app/src/main/res/drawable/bizcard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OneNoteDev/Android-REST-API-Explorer/a3436b1f0a4df87df541a592fb3b118915827e00/app/src/main/res/drawable/bizcard.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/bkgrnd_rect.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OneNoteDev/Android-REST-API-Explorer/a3436b1f0a4df87df541a592fb3b118915827e00/app/src/main/res/drawable/logo.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/msa.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OneNoteDev/Android-REST-API-Explorer/a3436b1f0a4df87df541a592fb3b118915827e00/app/src/main/res/drawable/msa.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/o365.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OneNoteDev/Android-REST-API-Explorer/a3436b1f0a4df87df541a592fb3b118915827e00/app/src/main/res/drawable/o365.png -------------------------------------------------------------------------------- /app/src/main/res/layout-sw600dp/activity_snippet_list.xml: -------------------------------------------------------------------------------- 1 | 12 | 13 | 18 | 19 | 26 | 27 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_signin.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 16 | 17 | 23 | 24 | 32 | 33 | 38 | 39 | 40 | 41 | 47 | 48 | 54 | 55 | 60 | 61 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_snippet_detail.xml: -------------------------------------------------------------------------------- 1 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_snippet_list.xml: -------------------------------------------------------------------------------- 1 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_snippet_detail.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 13 | 14 | 18 | 19 | 28 | 29 |