├── .gitignore
├── CHANGES.md
├── LICENSE
├── README.md
├── build.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── build.gradle
├── dev-config
│ └── findbugs
│ │ └── findbug-filter.xml
├── doclets
│ └── BBDoclet-1.0.jar
└── src
│ ├── androidTest
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── baasbox
│ │ │ └── android
│ │ │ └── test
│ │ │ ├── BaasBoxTimeoutTest.java
│ │ │ ├── ChangePasswordTest.java
│ │ │ ├── DocumentsTest.java
│ │ │ ├── FilesTest.java
│ │ │ ├── FilesTest2.java
│ │ │ ├── JsonTest.java
│ │ │ ├── LinkTest.java
│ │ │ ├── LoginTest.java
│ │ │ ├── ParcelablesTest.java
│ │ │ ├── QueryTest.java
│ │ │ ├── RestTest.java
│ │ │ ├── SessionTests.java
│ │ │ ├── TestBase64Users.java
│ │ │ ├── TestSignup.java
│ │ │ ├── TestSocialSignup.java
│ │ │ ├── UserTest.java
│ │ │ └── common
│ │ │ ├── BaasTestBase.java
│ │ │ ├── Box.java
│ │ │ └── TestBase.java
│ └── res
│ │ └── drawable
│ │ └── team.jpg
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── com
│ └── baasbox
│ └── android
│ ├── AsyncStream.java
│ ├── BaasACL.java
│ ├── BaasAdmin.java
│ ├── BaasApiException.java
│ ├── BaasAsset.java
│ ├── BaasAssetId.java
│ ├── BaasBox.java
│ ├── BaasCancellationException.java
│ ├── BaasClientException.java
│ ├── BaasCloudMessagingService.java
│ ├── BaasCredentialManager.java
│ ├── BaasDocument.java
│ ├── BaasException.java
│ ├── BaasFile.java
│ ├── BaasHandler.java
│ ├── BaasIOException.java
│ ├── BaasInvalidSessionException.java
│ ├── BaasLink.java
│ ├── BaasObject.java
│ ├── BaasQuery.java
│ ├── BaasResult.java
│ ├── BaasRuntimeException.java
│ ├── BaasServerException.java
│ ├── BaasStream.java
│ ├── BaasUser.java
│ ├── ByteOutput.java
│ ├── Cache.java
│ ├── ConcurrentHashSet.java
│ ├── DataStreamHandler.java
│ ├── DefaultSignupStrategy.java
│ ├── DyanmicByteArrayOutputStream.java
│ ├── ExceptionHandler.java
│ ├── FixedByteArrayOutputStream.java
│ ├── Grant.java
│ ├── HttpUrlConnectionClient.java
│ ├── JsonWrapper.java
│ ├── NetworkTask.java
│ ├── Plugin.java
│ ├── RequestFactory.java
│ ├── RequestOptions.java
│ ├── RequestToken.java
│ ├── Rest.java
│ ├── RestImpl.java
│ ├── Role.java
│ ├── SaveMode.java
│ ├── StreamBody.java
│ ├── StreamRequest.java
│ ├── impl
│ ├── Base64.java
│ ├── Constants.java
│ ├── DiskLruCache.java
│ ├── Dispatcher.java
│ ├── GCMWrapper.java
│ ├── GoogleCloudMessagingWrapper.java
│ ├── ImmediateDispatcher.java
│ ├── Logger.java
│ ├── StrictLineReader.java
│ ├── Task.java
│ ├── Util.java
│ └── package-info.java
│ ├── json
│ ├── JsonArray.java
│ ├── JsonException.java
│ ├── JsonObject.java
│ ├── JsonReader.java
│ ├── JsonScope.java
│ ├── JsonStructure.java
│ ├── JsonToken.java
│ ├── JsonWriter.java
│ ├── StringPool.java
│ └── package-info.java
│ ├── net
│ ├── HttpRequest.java
│ ├── HttpResponse.java
│ ├── OkClient.java
│ └── RestClient.java
│ ├── package-info.java
│ └── plugins
│ └── glide
│ ├── BaasAssetModelLoader.java
│ ├── BaasFileModelLoader.java
│ ├── BaasImageFetcher.java
│ └── GlidePlugin.java
├── proguard-project.txt
├── project.properties
├── samples
├── aloa
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── baasbox
│ │ │ └── android
│ │ │ └── samples
│ │ │ └── aloa
│ │ │ └── ApplicationTest.java
│ │ └── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ └── com
│ │ │ └── baasbox
│ │ │ └── android
│ │ │ └── samples
│ │ │ └── aloa
│ │ │ ├── Aloa.java
│ │ │ ├── Configuration.java
│ │ │ ├── Data.java
│ │ │ ├── activities
│ │ │ ├── CreateChannelFragment.java
│ │ │ ├── LoginActivity.java
│ │ │ ├── MainActivity.java
│ │ │ ├── OnTargetSelectedListener.java
│ │ │ ├── SendMessageActivity.java
│ │ │ ├── SendTargetFragment.java
│ │ │ ├── UserStatusFragment.java
│ │ │ └── loaders
│ │ │ │ ├── BaasUsersLoader.java
│ │ │ │ └── ChannelsLoader.java
│ │ │ ├── receive
│ │ │ ├── NewMessageNotification.java
│ │ │ └── PushReceiver.java
│ │ │ └── utils
│ │ │ ├── BaasLoader.java
│ │ │ ├── BaseActivity.java
│ │ │ ├── BaseBaasLoader.java
│ │ │ └── BaseFragment.java
│ │ └── res
│ │ ├── drawable-hdpi-v11
│ │ └── ic_stat_new_message.png
│ │ ├── drawable-hdpi-v9
│ │ └── ic_stat_new_message.png
│ │ ├── drawable-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_stat_new_message.png
│ │ ├── drawable-mdpi-v11
│ │ └── ic_stat_new_message.png
│ │ ├── drawable-mdpi-v9
│ │ └── ic_stat_new_message.png
│ │ ├── drawable-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_stat_new_message.png
│ │ ├── drawable-nodpi
│ │ └── example_picture.png
│ │ ├── drawable-xhdpi-v11
│ │ └── ic_stat_new_message.png
│ │ ├── drawable-xhdpi-v9
│ │ └── ic_stat_new_message.png
│ │ ├── drawable-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_stat_new_message.png
│ │ ├── drawable-xxhdpi-v11
│ │ └── ic_stat_new_message.png
│ │ ├── drawable-xxhdpi-v9
│ │ └── ic_stat_new_message.png
│ │ ├── drawable-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_stat_new_message.png
│ │ ├── layout
│ │ ├── activity_login.xml
│ │ ├── activity_main.xml
│ │ ├── activity_send_message.xml
│ │ ├── fragment_sendtarget_grid.xml
│ │ ├── fragment_sendtarget_list.xml
│ │ └── fragment_user_status.xml
│ │ ├── menu
│ │ └── main.xml
│ │ ├── values-large
│ │ └── refs.xml
│ │ ├── values-sw600dp
│ │ └── refs.xml
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── dimens.xml
│ │ ├── ids.xml
│ │ ├── refs.xml
│ │ ├── strings.xml
│ │ ├── strings_activity_login.xml
│ │ └── styles.xml
├── phrasebook
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ │ └── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ └── com
│ │ │ └── baasbox
│ │ │ └── android
│ │ │ └── samples
│ │ │ └── phrasebook
│ │ │ ├── Configuration.java
│ │ │ ├── Phrasebook.java
│ │ │ ├── ServerContract.java
│ │ │ ├── common
│ │ │ ├── BaseActivity.java
│ │ │ └── BaseFragment.java
│ │ │ ├── loaders
│ │ │ └── BaasDocumentsLoader.java
│ │ │ ├── ui
│ │ │ ├── HomeActivity.java
│ │ │ └── PhraseOfTheDay.java
│ │ │ └── utils
│ │ │ └── ThreadLocalRandom.java
│ │ └── res
│ │ ├── drawable-hdpi
│ │ ├── ic_empty_star.png
│ │ ├── ic_full_star.png
│ │ ├── ic_half_star.png
│ │ ├── ic_launcher.png
│ │ └── ic_send.png
│ │ ├── drawable-mdpi
│ │ ├── ic_empty_star.png
│ │ ├── ic_full_star.png
│ │ ├── ic_half_star.png
│ │ ├── ic_launcher.png
│ │ └── ic_send.png
│ │ ├── drawable-xhdpi
│ │ ├── ic_empty_star.png
│ │ ├── ic_full_star.png
│ │ ├── ic_half_star.png
│ │ ├── ic_launcher.png
│ │ └── ic_send.png
│ │ ├── drawable-xxhdpi
│ │ ├── ic_empty_star.png
│ │ ├── ic_full_star.png
│ │ ├── ic_half_star.png
│ │ ├── ic_launcher.png
│ │ └── ic_send.png
│ │ ├── drawable
│ │ └── colorized_rating_bar.xml
│ │ ├── layout
│ │ ├── activity_home.xml
│ │ ├── fragment_phrase_of_the_day.xml
│ │ └── include_submit_comment.xml
│ │ └── values
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
└── social
│ └── build.gradle
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.apk
3 | *.ap_
4 |
5 | # files for the dex VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # generated files
12 | bin/
13 | gen/
14 |
15 | # Local configuration file (sdk path, etc)
16 | local.properties
17 |
18 | # Eclipse project files
19 | .classpath
20 | .project
21 |
22 | # Idea project files
23 | *.iml
24 | .idea/**
25 |
26 |
27 | # Gradle generated artifacts
28 | build/**
29 | .gradle/**
30 |
31 | server/**
32 |
33 | # local gradle
34 | dev-config.gradle
35 | dev-config/**
36 | gradle.properties
37 |
38 | samples/googleauthenticate/**
--------------------------------------------------------------------------------
/CHANGES.md:
--------------------------------------------------------------------------------
1 | # CHANGELOG
2 |
3 | ## 0.9.2
4 |
5 |
6 | ### Features
7 | * Added support for initial acl on documents
8 | * Added getters and test methods to acl
9 |
10 | ### Bugs
11 | * Fixed #34 wrong change password url
12 | * Fixed #33 files throw null pointer exception when streaming
13 |
14 |
15 | ## 0.9.1
16 |
17 | ### Changes
18 | * Removed deprecated methods
19 | * Deprecated rest and restSync in favor of a rest interface accessible through
20 | BaasBox.rest()
21 |
22 | ### Features
23 | * Added support to all keys of the push api
24 |
25 | ### Bugs
26 | * Fixed #32
27 |
28 |
29 | ## 0.8.3
30 |
31 | ### Changes
32 | * Project layout conforms to Android Studio/gradle standards
33 | * Project now includes a samples directory that contains
34 | api usage samples.
35 |
36 | ### Features
37 | * Query api and Acl Api changes
38 | * First link api implementation
39 | * Ability to access files url to use with other libraries
40 | * Alpha OkHttp client implementation available as alternative rest client
41 | * RestClient implementation has a new init method called when the client is initalized
42 | * Added skip parameter to query api
43 | * Ability to initialize documents from json objects
44 |
45 | ### Fixes
46 | * Fixed BaasUser bug during fetch of current user (#25)
47 | * Added missing methods overloads
48 | * Fixed error with social signup
49 | * Fixed BaasDocument parcelable cast error
50 | * Fixed file streaming error on large file size
51 |
52 | ## 0.8.0
53 |
54 | ### Features
55 | * Simplified google cloud messaging integration
56 | * Ability to concatenate query builders
57 | * Renamed BaasFile image streaming methods to the more explicit streamImage*
58 | * Replaced Priority paramter with a more generic flags bitmask See RequestOptions constants.
59 |
60 | ### Fixes
61 | * Fixed silently ignoring wrong syntax in hostname
62 | * Fixed missing where params in request
63 | * Fixed file streaming bugs
64 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Android-SDK
2 | ===========
3 |
4 | BaasBox Android SDK.
5 |
6 | The binary of the library can be downloaded from [BaasBox](http://www.baasbox.com/download/) download page.
7 |
8 | *Documentation:* [[user guide]](http://www.baasbox.com/documentation/) [[javadoc reference]](http://baasbox.github.io/Android-SDK/docs/)
9 |
10 | Check out our [blog](http://www.baasbox.com/blog/), for updates and tutorials.
11 |
12 | ## Building
13 |
14 | To build the library jar
15 |
16 | ```
17 | ./gradlew library:coreLibJar
18 | ```
19 |
20 | will produce a jar in `library/build/libs` that can be added as a dependency to any android project.
21 |
22 | **NOTE** to be able to build the project you'll need to place a file `local.properties` inside the root of the project containing.
23 |
24 | ```
25 | sdk.dir=
26 | ```
27 | this file is autogenerated when importing the project in android studio.
28 |
29 | Make sure to have the latest build tools and sdk installed and updated. Currently the library is built with compileSdkVersion 21 and tools 21.1.2.
30 |
31 | [](https://bitdeli.com/free "Bitdeli Badge")
32 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 | buildscript {
18 | repositories {
19 | jcenter()
20 | }
21 | dependencies {
22 | classpath 'com.android.tools.build:gradle:1.5.0'
23 | }
24 | }
25 |
26 | task wrapper(type: Wrapper) {
27 | gradleVersion = '2.8'
28 | }
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Dec 09 10:00:04 CET 2014
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | build/**
2 | docs/**
--------------------------------------------------------------------------------
/library/dev-config/findbugs/findbug-filter.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
12 |
--------------------------------------------------------------------------------
/library/doclets/BBDoclet-1.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/library/doclets/BBDoclet-1.0.jar
--------------------------------------------------------------------------------
/library/src/androidTest/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
15 |
16 |
20 |
21 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/baasbox/android/test/BaasBoxTimeoutTest.java:
--------------------------------------------------------------------------------
1 | package com.baasbox.android.test;
2 |
3 | /**
4 | * Created by Andrea Tortorella on 2/27/15.
5 | */
6 | public class BaasBoxTimeoutTest {
7 | }
8 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/baasbox/android/test/ChangePasswordTest.java:
--------------------------------------------------------------------------------
1 | package com.baasbox.android.test;
2 |
3 | import com.baasbox.android.BaasResult;
4 | import com.baasbox.android.BaasUser;
5 | import com.baasbox.android.test.common.BaasTestBase;
6 |
7 | /**
8 | * Created by Andrea Tortorella on 2/23/15.
9 | */
10 | public class ChangePasswordTest extends BaasTestBase{
11 |
12 | public static final String USERNAME = "auser";
13 | public static final String PASSWORD = "password";
14 | public static final String NEW_PASSWORD="newpassword";
15 |
16 |
17 | @Override
18 | protected void beforeClass() throws Exception {
19 | super.beforeClass();
20 | resetDb();
21 | createUser(USERNAME,PASSWORD);
22 | }
23 |
24 |
25 | public void testCanChangePassword(){
26 | BaasResult logged = BaasUser.withUserName(USERNAME).setPassword(PASSWORD).login(null).await();
27 | assertNotNull(logged);
28 | assertEquals(USERNAME,logged.value().getName());
29 | BaasUser current = BaasUser.current();
30 | assertNotNull(current);
31 | BaasResult await = current.changePassword(NEW_PASSWORD, null).await();
32 |
33 |
34 | }
35 |
36 | private void createUser(String user,String pass){
37 | BaasUser u =
38 | BaasUser.withUserName(user)
39 | .setPassword(pass);
40 |
41 | BaasResult res =u.signup(null).await();
42 | assertTrue(res.isSuccess());
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/baasbox/android/test/JsonTest.java:
--------------------------------------------------------------------------------
1 | package com.baasbox.android.test;
2 |
3 | import android.content.BroadcastReceiver;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.content.IntentFilter;
7 | import android.os.Bundle;
8 | import com.baasbox.android.json.JsonArray;
9 | import com.baasbox.android.json.JsonObject;
10 | import com.baasbox.android.test.common.BaasTestBase;
11 |
12 | /**
13 | * Created by Andrea Tortorella on 22/04/14.
14 | */
15 | public class JsonTest extends BaasTestBase{
16 |
17 | public void testParcelability(){
18 | JsonObject o =new JsonObject()
19 | .put("v", new JsonArray().add("work").add(2))
20 | .put("k", "k");
21 |
22 | Bundle b = new Bundle();
23 | b.putParcelable("KEY",o);
24 | JsonObject j =b.getParcelable("KEY");
25 | assertEquals(j,o);
26 | }
27 |
28 | public void testIntentParcelability(){
29 | JsonObject o =new JsonObject().put("k", new JsonArray());
30 | Bundle b =new Bundle();
31 | Bundle hb = new Bundle();
32 | hb.putParcelable("H",o);
33 | b.putBundle("B",hb);
34 | Intent i =new Intent("ACTION");
35 | i.putExtras(b);
36 |
37 | getContext().registerReceiver(new BroadcastReceiver() {
38 | @Override
39 | public void onReceive(Context context, Intent intent) {
40 | JsonObject o = intent.getExtras().getBundle("B").getParcelable("K");
41 |
42 | }
43 | }, new IntentFilter("ACTION"));
44 | getContext().sendBroadcast(i);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/baasbox/android/test/ParcelablesTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.baasbox.android.test;
19 |
20 | import android.os.Bundle;
21 | import android.os.Parcel;
22 | import com.baasbox.android.BaasDocument;
23 | import com.baasbox.android.json.JsonArray;
24 | import com.baasbox.android.json.JsonObject;
25 | import com.baasbox.android.test.common.TestBase;
26 |
27 | /**
28 | * Created by Andrea Tortorella on 25/07/14.
29 | */
30 | public class ParcelablesTest extends TestBase {
31 |
32 | public void testCanParcelJson(){
33 | JsonObject o = new JsonObject();
34 | o.put("Key1", "val1");
35 | o.put("Key2", new JsonObject().put("a", "a").put("b", new JsonArray().add(new JsonObject().put("x", "x"))));
36 |
37 | Bundle b = new Bundle();
38 | b.putParcelable("SAVE",o);
39 | Parcel p = Parcel.obtain();
40 | b.writeToParcel(p,0);
41 | p.setDataPosition(0);
42 | Bundle readBack = p.readBundle();
43 | readBack.setClassLoader(BaasDocument.class.getClassLoader());
44 | JsonObject backObj = readBack.getParcelable("SAVE");
45 | assertEquals(o.toString(),backObj.toString());
46 | }
47 |
48 | public void testCanParcelDocuments(){
49 | BaasDocument doc = new BaasDocument("fake");
50 | doc.put("Key", "Val1");
51 | doc.put("Key2", "Val2");
52 | doc.put("Key3", new JsonArray().add("ciao"));
53 |
54 | Bundle b = new Bundle();
55 | b.putParcelable("SAVE",doc);
56 |
57 | Parcel p = Parcel.obtain();
58 | b.writeToParcel(p,0);
59 | p.setDataPosition(0);
60 | Bundle readBack = p.readBundle();
61 | readBack.setClassLoader(BaasDocument.class.getClassLoader());
62 | BaasDocument newDoc = readBack.getParcelable("SAVE");
63 |
64 | assertEquals(newDoc.getString("Key"),doc.getString("Key"));
65 | assertEquals(newDoc.getString("Key2"),doc.getString("Key2"));
66 | assertEquals(newDoc.getArray("Key3").getString(0),doc.getArray("Key3").getString(0));
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/baasbox/android/test/RestTest.java:
--------------------------------------------------------------------------------
1 | package com.baasbox.android.test;
2 |
3 | import com.baasbox.android.BaasBox;
4 | import com.baasbox.android.BaasHandler;
5 | import com.baasbox.android.BaasResult;
6 | import com.baasbox.android.BaasUser;
7 | import com.baasbox.android.RequestToken;
8 | import com.baasbox.android.Rest;
9 | import com.baasbox.android.json.JsonObject;
10 | import com.baasbox.android.test.common.BaasTestBase;
11 |
12 | /**
13 | * Created by Andrea Tortorella on 1/12/15.
14 | */
15 | public class RestTest extends BaasTestBase {
16 |
17 | public static final String USER1 = "user1";
18 | public static final String COLLECTION = "test";
19 |
20 | @Override
21 | protected void beforeClass() throws Exception {
22 | super.beforeClass();
23 | resetDb();
24 | BaasUser.withUserName(USER1).setPassword("pass").signupSync();
25 | }
26 |
27 | @Override
28 | protected void beforeTest() throws Exception {
29 | super.beforeTest();
30 | asAdmin(new Runnable() {
31 | @Override
32 | public void run() {
33 | BaasResult res = BaasBox.rest().sync(Rest.Method.POST, "admin/collection/" + COLLECTION, null, true);
34 | assertTrue(res.isSuccess());
35 | }
36 | });
37 | }
38 |
39 | public void testRestDocumentPost(){
40 | BaasResult user = BaasUser.withUserName(USER1).setPassword("pass").loginSync();
41 | RequestToken token=BaasBox.rest().async(Rest.Method.POST,"document/"+COLLECTION,new JsonObject().put("my","data"),true,new BaasHandler() {
42 | @Override
43 | public void handle(BaasResult result) {
44 |
45 | }
46 | });
47 | BaasResult await = token.await();
48 | assertTrue(await.isSuccess());
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/baasbox/android/test/SessionTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014. BaasBox
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and limitations under the License.
14 | */
15 |
16 | package com.baasbox.android.test;
17 |
18 | import com.baasbox.android.*;
19 | import com.baasbox.android.test.common.BaasTestBase;
20 |
21 | import java.util.concurrent.TimeUnit;
22 |
23 | /**
24 | * Created by eto on 06/03/14.
25 | */
26 | public class SessionTests extends BaasTestBase {
27 |
28 | private static final boolean SKIP = true;
29 |
30 | @Override
31 | protected void beforeClass() throws Exception {
32 | super.beforeClass();
33 | resetDb();
34 | }
35 |
36 | public void testExpiration(){
37 | if (!SKIP) {
38 | BaasResult user = BaasUser.withUserName("paolo")
39 | .setPassword("paolo")
40 | .signupSync();
41 | if (user.isFailed()) {
42 | fail("Unable to signup");
43 | }
44 | BaasUser.current().getScope(BaasUser.Scope.PRIVATE).put("KEY", true);
45 | BaasResult resup = BaasUser.current().saveSync();
46 | if (resup.isFailed()) {
47 | fail("Unable to modify self");
48 | }
49 | try {
50 | TimeUnit.SECONDS.sleep(80);
51 | } catch (InterruptedException e) {
52 |
53 | }
54 |
55 | BaasResult resUs = BaasUser.current().refreshSync();
56 | try {
57 | resUs.get();
58 | if (BaasBox.getDefault().config.sessionTokenExpires) {
59 | fail();
60 | } else {
61 | assertTrue(true);
62 | }
63 | } catch (BaasInvalidSessionException e) {
64 | if (BaasBox.getDefault().config.sessionTokenExpires) {
65 | assertTrue(true);
66 | } else {
67 | fail("Should not refresh the token");
68 | }
69 | } catch (BaasException e) {
70 | fail(e.getMessage());
71 | }
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/baasbox/android/test/TestBase64Users.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014. BaasBox
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions andlimitations under the License.
14 | */
15 |
16 | package com.baasbox.android.test;
17 |
18 | import android.util.Log;
19 | import com.baasbox.android.BaasBox;
20 | import com.baasbox.android.BaasException;
21 | import com.baasbox.android.BaasResult;
22 | import com.baasbox.android.BaasUser;
23 | import com.baasbox.android.test.common.BaasTestBase;
24 |
25 | import java.util.List;
26 | import java.util.UUID;
27 |
28 | /**
29 | * Created by Andrea Tortorella on 17/03/14.
30 | */
31 | public class TestBase64Users extends BaasTestBase{
32 |
33 | @Override
34 | protected void beforeClass() throws Exception {
35 | super.beforeClass();
36 | BaasBox.quitClient();
37 | box = null;
38 | initBaasbox(BaasBox.Config.AuthType.BASIC_AUTHENTICATION);
39 | }
40 |
41 | public void testBase64Auth(){
42 | UUID uuid = UUID.randomUUID();
43 | String f = uuid.toString();
44 | BaasResult signup = BaasUser.withUserName(f)
45 | .setPassword(f)
46 | .signupSync();
47 | if (signup.isFailed()) {
48 | Log.e("WHAT","ERROR",signup.error());
49 | }
50 | BaasResult> res = BaasUser.current().followersSync();
51 | assertTrue(res.isSuccess());
52 | try {
53 | res.get();
54 | } catch (BaasException e) {
55 | throw new RuntimeException(e);
56 | }
57 | }
58 |
59 |
60 | @Override
61 | protected void afterClass() throws Exception {
62 | super.afterClass();
63 | super.initBaasbox(BaasBox.Config.AuthType.SESSION_TOKEN);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/baasbox/android/test/TestSignup.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014. BaasBox
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and limitations under the License.
14 | */
15 |
16 | package com.baasbox.android.test;
17 |
18 | import com.baasbox.android.*;
19 | import com.baasbox.android.test.common.BaasTestBase;
20 |
21 | /**
22 | * Created by Andrea Tortorella on 05/02/14.
23 | */
24 | public class TestSignup extends BaasTestBase {
25 | private static final String USER_NAME="username";
26 | private static final String USER_PASSWORD ="userpass";
27 |
28 | @Override
29 | protected void beforeTest() throws Exception {
30 | super.beforeTest();
31 | resetDb();
32 | }
33 |
34 | public void testPreconditions(){
35 | assertNotNull("baasbox not initialized",box);
36 | }
37 |
38 | public void testSignupNewUser(){
39 | RequestToken token= BaasUser.withUserName(USER_NAME)
40 | .setPassword(USER_PASSWORD)
41 | .signup(new BaasHandler() {
42 | @Override
43 | public void handle(BaasResult result) {
44 |
45 | }
46 | });
47 | BaasResult await = token.await();
48 | try {
49 | BaasUser user = await.get();
50 | assertNotNull(BaasUser.current());
51 | assertEquals(user, BaasUser.current());
52 | } catch (BaasException e) {
53 | fail(e.toString());
54 | }
55 | }
56 |
57 | public void testSignupExistingShouldFail(){
58 | BaasResult precedingUser = BaasUser.withUserName(USER_NAME)
59 | .setPassword(USER_PASSWORD)
60 | .signupSync();
61 | if (precedingUser.isSuccess()){
62 | BaasResult await = BaasUser.withUserName(USER_NAME)
63 | .setPassword(USER_PASSWORD)
64 | .signup(BaasHandler.NOOP)
65 | .await();
66 |
67 | assertFalse(await.isSuccess());
68 | } else {
69 | fail("unable to create first user");
70 | }
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/baasbox/android/test/TestSocialSignup.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.baasbox.android.test;
19 |
20 | import android.util.Log;
21 |
22 | import com.baasbox.android.BaasException;
23 | import com.baasbox.android.BaasHandler;
24 | import com.baasbox.android.BaasResult;
25 | import com.baasbox.android.BaasUser;
26 | import com.baasbox.android.RequestToken;
27 | import com.baasbox.android.test.common.BaasTestBase;
28 |
29 | /**
30 | * Created by Andrea Tortorella on 06/08/14.
31 | */
32 | public class TestSocialSignup extends BaasTestBase {
33 |
34 | @Override
35 | protected void beforeTest() throws Exception {
36 | super.beforeTest();
37 | // resetDb();
38 | }
39 |
40 | public void testPreconditions(){
41 | assertNotNull("baasbox not initialized",box);
42 | }
43 |
44 | public void testSignupWithFakeCredentials(){
45 | RequestToken token = BaasUser.signupWithProvider(
46 | BaasUser.Social.GOOGLE,
47 | "fake-token",
48 | "fake-token",
49 | new BaasHandler() {
50 | @Override
51 | public void handle(BaasResult result) {
52 |
53 | }
54 | });
55 | BaasResult await = token.await();
56 | assertFalse("cannot connect with fake credentials",await.isSuccess());
57 | BaasException error = await.error();
58 | Log.d("TEST",error.getMessage());
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/baasbox/android/test/UserTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014. BaasBox
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and limitations under the License.
14 | */
15 |
16 | package com.baasbox.android.test;
17 |
18 | import com.baasbox.android.BaasHandler;
19 | import com.baasbox.android.BaasResult;
20 | import com.baasbox.android.BaasUser;
21 | import com.baasbox.android.test.common.BaasTestBase;
22 |
23 | import java.lang.Override;
24 | import java.util.List;
25 |
26 | /**
27 | * Created by eto on 17/02/14.
28 | */
29 | public class UserTest extends BaasTestBase {
30 | public static final String KEY = "key";
31 | private static final String USERNAME = "username";
32 | private static final String PASSWORD = "password";
33 |
34 | private static final String UNKNOWN = "unknown";
35 |
36 | private static final String FRIEND = "friend";
37 |
38 | @Override
39 | protected void beforeClass() throws Exception {
40 | super.beforeClass();
41 | resetDb();
42 | createUser(UNKNOWN,PASSWORD,"friend1","reg1");
43 | createUser(FRIEND,PASSWORD,"friend2","reg2");
44 | createUser(USERNAME,PASSWORD,"mefriend","mereg");
45 | }
46 |
47 |
48 | public void testCanListUsers(){
49 | BaasResult> res = BaasUser.fetchAll(null).await();
50 | assertTrue(res.isSuccess());
51 | assertEquals(3,res.value().size());
52 | List users = res.value();
53 | for (BaasUser u:users){
54 | if (!u.isCurrent()){
55 | assertNull(u.getScope(BaasUser.Scope.PRIVATE));
56 | assertNull(u.getScope(BaasUser.Scope.FRIEND));
57 | assertNotNull(u.getScope(BaasUser.Scope.REGISTERED));
58 | assertNotNull(u.getScope(BaasUser.Scope.PUBLIC));
59 | }
60 | }
61 | }
62 |
63 | public void testCanFollowUser(){
64 | BaasResult res = BaasUser.withUserName(FRIEND).follow(null).await();
65 | assertTrue(res.isSuccess());
66 |
67 | assertNotNull(res.value().getScope(BaasUser.Scope.FRIEND));
68 | assertEquals("friend2",res.value().getScope(BaasUser.Scope.FRIEND).getString(KEY));
69 | BaasResult> following = BaasUser.current().following(null).await();
70 | assertTrue(following.isSuccess());
71 | assertEquals(1,following.value().size());
72 |
73 | assertEquals(FRIEND,following.value().get(0).getName());
74 |
75 | BaasResult> followers = BaasUser.withUserName(FRIEND).followers(null).await();
76 |
77 |
78 | BaasResult unf = BaasUser.withUserName(FRIEND).unfollow(null).await();
79 | assertTrue(unf.isSuccess());
80 |
81 | }
82 |
83 | private void createUser(String user,String pass,String friendsData,String regData){
84 | BaasUser u =
85 | BaasUser.withUserName(user)
86 | .setPassword(pass);
87 | u.getScope(BaasUser.Scope.FRIEND).put(KEY, friendsData);
88 | u.getScope(BaasUser.Scope.REGISTERED).put(KEY, regData);
89 | u.getScope(BaasUser.Scope.PRIVATE).put(KEY, "invisible");
90 | u.getScope(BaasUser.Scope.PUBLIC).put(KEY, "public");
91 | BaasResult res =u.signup(null).await();
92 | assertTrue(res.isSuccess());
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/baasbox/android/test/common/BaasTestBase.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014. BaasBox
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and limitations under the License.
14 | */
15 |
16 | package com.baasbox.android.test.common;
17 |
18 | import android.os.Handler;
19 | import android.os.Looper;
20 | import com.baasbox.android.BaasBox;
21 | import com.baasbox.android.BaasResult;
22 | import com.baasbox.android.BaasUser;
23 | import com.baasbox.android.Rest;
24 | import com.baasbox.android.impl.Logger;
25 | import com.baasbox.android.json.JsonObject;
26 | import com.baasbox.android.net.HttpRequest;
27 | import com.baasbox.android.net.OkClient;
28 | import com.baasbox.android.test.R;
29 |
30 | /**
31 | * Created by Andrea Tortorella on 01/02/14.
32 | */
33 | public class BaasTestBase extends TestBase {
34 | protected BaasBox box;
35 | private Handler mHandler;
36 | private final String IP_ADDRESS = "192.168.56.1";
37 | private final String EMU_ADDRESS = "10.0.2.2";
38 |
39 | @Override
40 | protected void beforeClass() throws Exception {
41 | super.beforeClass();
42 | mHandler = new Handler(Looper.myLooper());
43 | box = initBaasbox(BaasBox.Config.AuthType.SESSION_TOKEN);
44 | Logger.debug("Baasbox initialized");
45 | }
46 |
47 | protected BaasBox initBaasbox(BaasBox.Config.AuthType auth) {
48 | BaasBox.Builder builder = BaasBox.builder(getContext());
49 | return builder.setApiDomain(EMU_ADDRESS)
50 | .setAuthentication(auth)
51 | .setRestClient(new OkClient())
52 | .setSessionTokenExpires(false)
53 | .init();
54 | }
55 |
56 | protected void runNext(Runnable action) {
57 | mHandler.post(action);
58 | }
59 |
60 | protected final void resetDb() {
61 | asAdmin(new Runnable() {
62 | @Override
63 | public void run() {
64 | BaasResult o = BaasBox.rest().sync(Rest.Method.DELETE, "admin/db/0", null, true);
65 | if (o.isFailed()) fail(o.toString());
66 | }
67 | });
68 | }
69 |
70 | protected final void asAdmin(Runnable action) {
71 | asUser("admin", "admin", action);
72 | }
73 |
74 | protected final void asUser(String username, String password, Runnable action) {
75 | BaasResult user =
76 | BaasUser.withUserName(username)
77 | .setPassword(password)
78 | .loginSync();
79 | if (user.isFailed()) fail(user.error().toString());
80 | action.run();
81 | BaasResult logout = user.value().logoutSync();
82 | if (logout.isFailed()) fail(logout.error().toString());
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/baasbox/android/test/common/Box.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014. BaasBox
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and limitations under the License.
14 | */
15 |
16 | package com.baasbox.android.test.common;
17 |
18 | import com.baasbox.android.BaasHandler;
19 | import com.baasbox.android.BaasResult;
20 |
21 | /**
22 | * Created by Andrea Tortorella on 28/01/14.
23 | */
24 | public class Box implements BaasHandler {
25 | public volatile BaasResult value;
26 |
27 | @Override
28 | public void handle(BaasResult result) {
29 | value=result;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/baasbox/android/test/common/TestBase.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014. BaasBox
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and limitations under the License.
14 | */
15 |
16 | package com.baasbox.android.test.common;
17 |
18 | import android.content.Context;
19 | import android.test.AndroidTestCase;
20 |
21 | import java.lang.reflect.InvocationTargetException;
22 | import java.lang.reflect.Method;
23 |
24 | /**
25 | * Created by Andrea Tortorella on 01/02/14.
26 | */
27 | public class TestBase extends AndroidTestCase {
28 |
29 | private static final Method TEST_CONTEXT_METHOD;
30 |
31 | static {
32 | Method m;
33 | try {
34 | m = AndroidTestCase.class.getMethod("getTestContext");
35 | } catch (NoSuchMethodException e) {
36 | m = null;
37 | }
38 | TEST_CONTEXT_METHOD = m;
39 | }
40 |
41 | private int totalTests;
42 | private boolean first = true;
43 |
44 | public Context getTest(){
45 | try {
46 | Object invoke = TEST_CONTEXT_METHOD.invoke(this);
47 | return (Context)invoke;
48 | } catch (NullPointerException e){
49 | return null;
50 | }catch (IllegalAccessException e) {
51 | return null;
52 | } catch (InvocationTargetException e) {
53 | return null;
54 | }
55 | }
56 | public TestBase(){
57 | Method[] methods = getClass().getDeclaredMethods();
58 | int tests = 0;
59 | for(Method m:methods){
60 | boolean test = m.getName().startsWith("test");
61 | if(test) tests++;
62 | }
63 |
64 | totalTests=tests;
65 | }
66 |
67 | protected void assertIsOneOf(T check,T ... values){
68 | for(T v:values){
69 | if(v.equals(check)) return;
70 | }
71 | fail();
72 | }
73 |
74 |
75 | @Override
76 | protected final void setUp() throws Exception {
77 | super.setUp();
78 | if(first){
79 | first=false;
80 | beforeClass();
81 | }
82 | beforeTest();
83 | }
84 |
85 | protected void beforeTest() throws Exception{}
86 |
87 | protected void beforeClass() throws Exception{}
88 |
89 | protected void afterTest() throws Exception{}
90 |
91 | protected void afterClass() throws Exception{}
92 |
93 |
94 | @Override
95 | protected final void tearDown() throws Exception {
96 | super.tearDown();
97 | afterTest();
98 | totalTests--;
99 | if (totalTests==0){
100 | afterClass();
101 | }
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/library/src/androidTest/res/drawable/team.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/library/src/androidTest/res/drawable/team.jpg
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/BaasAssetId.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.baasbox.android;
19 |
20 | import android.net.Uri;
21 |
22 | import java.util.WeakHashMap;
23 |
24 | /**
25 | * Created by Andrea Tortorella on 08/09/14.
26 | */
27 | public class BaasAssetId {
28 |
29 | private static final WeakHashMap CACHE = new WeakHashMap(30);
30 |
31 | public static BaasAssetId create(String id){
32 | synchronized (CACHE) {
33 | BaasAssetId baasAssetId = CACHE.get(id);
34 | if (baasAssetId== null){
35 | baasAssetId = new BaasAssetId(id);
36 | CACHE.put(id,baasAssetId);
37 | }
38 | return baasAssetId;
39 | }
40 | }
41 |
42 | public final String id;
43 |
44 | private BaasAssetId(String id){
45 | this.id = id;
46 | }
47 |
48 | public Uri getUri() {
49 | BaasBox box = BaasBox.getDefaultChecked();
50 | return box.requestFactory.getAuthenticatedUri(box.requestFactory.getEndpoint("asset/{}",id));
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/BaasCancellationException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014. BaasBox
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and limitations under the License.
14 | */
15 |
16 | package com.baasbox.android;
17 |
18 | /**
19 | * A subclass of {@link com.baasbox.android.BaasException} that is
20 | * thrown when the user tries to access the result of a cancelled request.
21 | */
22 | public class BaasCancellationException extends BaasException {
23 | }
24 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/BaasClientException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014. BaasBox
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and limitations under the License.
14 | */
15 |
16 | package com.baasbox.android;
17 |
18 | import com.baasbox.android.json.JsonObject;
19 |
20 | import java.util.HashMap;
21 | import java.util.Map;
22 |
23 | /**
24 | * A subclass of {@link BaasApiException} indicating an error due a wrong
25 | * request. When a BaasClientException is thrown the SDK made an error during
26 | * the request; misspelling the URI or putting a wrong parameter value.
27 | *
28 | * More info about the error could be found in the class parameters values.
29 | *
30 | * @author Davide Caroselli
31 | */
32 | public class BaasClientException extends BaasApiException {
33 | // ------------------------------ FIELDS ------------------------------
34 |
35 | private static final long serialVersionUID = 7494588625332374406L;
36 |
37 | // --------------------------- CONSTRUCTORS ---------------------------
38 | public BaasClientException(int httpStatus, JsonObject json) {
39 | super(httpStatus, json);
40 | }
41 |
42 | public BaasClientException(int code, int httpStatus, String resource, String method,
43 | Map requestHeader, String apiVersion,
44 | String detailMessage) {
45 | super(code, httpStatus, resource, method, requestHeader, apiVersion,
46 | detailMessage);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/BaasException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014. BaasBox
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and limitations under the License.
14 | */
15 |
16 | package com.baasbox.android;
17 |
18 | /**
19 | * Base class of all the exceptions
20 | * thrown by the BaasBox android sdk.
21 | *
22 | * @author Davide Caroselli
23 | * @since 0.7.3
24 | */
25 | public class BaasException extends Exception {
26 | // ------------------------------ FIELDS ------------------------------
27 |
28 | private static final long serialVersionUID = 1981606473384352072L;
29 |
30 | // --------------------------- CONSTRUCTORS ---------------------------
31 | public BaasException() {
32 | }
33 |
34 | public BaasException(String detailMessage) {
35 | super(detailMessage);
36 | }
37 |
38 | public BaasException(Throwable throwable) {
39 | super(throwable);
40 | }
41 |
42 | public BaasException(String detailMessage, Throwable throwable) {
43 | super(detailMessage, throwable);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/BaasHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014. BaasBox
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and limitations under the License.
14 | */
15 |
16 | package com.baasbox.android;
17 |
18 | /**
19 | * Interface definition for a callback to be invoked when BaasBox responds to an asynchronous
20 | * request.
21 | *
22 | * @param the expected response type
23 | * @author Andrea Tortorella
24 | * @since 0.7.3
25 | */
26 | public interface BaasHandler {
27 | // ------------------------------ FIELDS ------------------------------
28 |
29 | /**
30 | * A no op handler, that simply discards the received response
31 | */
32 | BaasHandler NOOP = new BaasHandler() {
33 | @Override
34 | public void handle(BaasResult result) {
35 | // do nothing
36 | }
37 | };
38 |
39 | // -------------------------- OTHER METHODS --------------------------
40 |
41 | /**
42 | * Method invoked with the result of an async request.
43 | *
44 | * @param result the result or an error wrapped in a {@link com.baasbox.android.BaasResult}
45 | */
46 | void handle(BaasResult result);
47 | }
48 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/BaasIOException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014. BaasBox
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and limitations under the License.
14 | */
15 |
16 | package com.baasbox.android;
17 |
18 | /**
19 | * A subclass of {@link com.baasbox.android.BaasException}
20 | * that represents an I/O exception.
21 | *
22 | * @author Davide Caroselli
23 | * @since 0.7.3
24 | */
25 | public class BaasIOException extends BaasException {
26 | // ------------------------------ FIELDS ------------------------------
27 |
28 | private static final long serialVersionUID = 4277921777119622999L;
29 |
30 | // --------------------------- CONSTRUCTORS ---------------------------
31 | public BaasIOException(String detailMessage) {
32 | super(detailMessage);
33 | }
34 |
35 | public BaasIOException(Throwable throwable) {
36 | super(throwable);
37 | }
38 |
39 | public BaasIOException(String detailMessage, Throwable throwable) {
40 | super(detailMessage, throwable);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/BaasInvalidSessionException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014. BaasBox
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and limitations under the License.
14 | */
15 |
16 | package com.baasbox.android;
17 |
18 | import com.baasbox.android.json.JsonObject;
19 |
20 | import java.util.HashMap;
21 | import java.util.Map;
22 |
23 | /**
24 | * This is a particular subclass of {@link BaasClientException} indicating an
25 | * invalid state of the user session. This exception is thrown when the SDK
26 | * could not successfully authenticate the user; this could happen when the
27 | * session token is expired (if used) and the stored credentials are not valid
28 | * anymore.
29 | *
30 | * A BaasInvalidSessionException could be thrown any time by any API call,
31 | * when catching this exception the App should prompt the user the Login Panel,
32 | * alerting the session is not valid anymore and to please re-login the user.
33 | *
34 | * @author Davide Caroselli
35 | */
36 | public class BaasInvalidSessionException extends BaasClientException {
37 | // ------------------------------ FIELDS ------------------------------
38 |
39 | public static final int INVALID_SESSION_TOKEN_CODE = 40101;
40 |
41 | private static final long serialVersionUID = -6923343849646015698L;
42 |
43 | // --------------------------- CONSTRUCTORS ---------------------------
44 | public BaasInvalidSessionException(JsonObject object) {
45 | super(401, object);
46 | }
47 |
48 | public BaasInvalidSessionException(String resource, String method,
49 | Map requestHeader, String apiVersion,
50 | String detailMessage) {
51 | super(INVALID_SESSION_TOKEN_CODE, 401, resource, method, requestHeader,
52 | apiVersion, detailMessage);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/BaasRuntimeException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014. BaasBox
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and limitations under the License.
14 | */
15 |
16 | package com.baasbox.android;
17 |
18 | /**
19 | * Created by Andrea Tortorella on 09/02/14.
20 | */
21 | public class BaasRuntimeException extends RuntimeException {
22 | // --------------------------- CONSTRUCTORS ---------------------------
23 | public BaasRuntimeException() {
24 | }
25 |
26 | public BaasRuntimeException(String detailMessage) {
27 | super(detailMessage);
28 | }
29 |
30 | public BaasRuntimeException(Throwable throwable) {
31 | super(throwable);
32 | }
33 |
34 | public BaasRuntimeException(String detailMessage, Throwable throwable) {
35 | super(detailMessage, throwable);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/BaasServerException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014. BaasBox
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and limitations under the License.
14 | */
15 |
16 | package com.baasbox.android;
17 |
18 | import com.baasbox.android.json.JsonObject;
19 |
20 | import java.util.HashMap;
21 | import java.util.Map;
22 |
23 | /**
24 | * A subclass of {@link BaasApiException} indicating an error due a problem
25 | * within the server. When a BaasServerException is thrown, the BaasBox
26 | * server thrown an unexpected exception.
27 | *
28 | * More info about the error could be found in the class parameters values.
29 | *
30 | * @author Davide Caroselli
31 | */
32 | public class BaasServerException extends BaasApiException {
33 | // ------------------------------ FIELDS ------------------------------
34 |
35 | private static final long serialVersionUID = 3343497779336452255L;
36 |
37 | // --------------------------- CONSTRUCTORS ---------------------------
38 | public BaasServerException(int status, JsonObject jsonResponse) {
39 | super(status, jsonResponse);
40 | }
41 |
42 | public BaasServerException(int code, int httpStatus, String resource, String method,
43 | Map requestHeader, String apiVersion,
44 | String detailMessage) {
45 | super(code, httpStatus, resource, method, requestHeader, apiVersion,
46 | detailMessage);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/BaasStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014. BaasBox
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and limitations under the License.
14 | */
15 |
16 | package com.baasbox.android;
17 |
18 | import com.baasbox.android.impl.DiskLruCache;
19 | import com.baasbox.android.net.HttpResponse;
20 |
21 |
22 | import java.io.BufferedInputStream;
23 | import java.io.FilterInputStream;
24 | import java.io.IOException;
25 | import java.io.InputStream;
26 |
27 | /**
28 | * An input streams over the content of a response
29 | * that gives access to the content type, the content length
30 | * and the id of the associated BaasBox file.
31 | *
32 | * @author Andrea Tortorella
33 | * @since 0.7.3
34 | */
35 | public final class BaasStream extends FilterInputStream {
36 | // ------------------------------ FIELDS ------------------------------
37 |
38 | /**
39 | * The content type of the stream
40 | */
41 | public final String contentType;
42 |
43 | /**
44 | * The content length of the stream
45 | */
46 | public final long contentLength;
47 |
48 | /**
49 | * The id of the file.
50 | */
51 | public final String id;
52 | private final HttpResponse.Body entity;
53 | private final DiskLruCache.Snapshot snapshot;
54 |
55 | // --------------------------- CONSTRUCTORS ---------------------------
56 | BaasStream(String id, DiskLruCache.Snapshot s) {
57 | super(s.getInputStream(0));
58 | this.id = id;
59 | this.contentLength = s.getLength(0);
60 | this.contentType = null;
61 | this.entity = null;
62 | this.snapshot = null;
63 | }
64 |
65 | BaasStream(String id, HttpResponse.Body entity) throws IOException {
66 | super(getInput(entity));
67 | this.entity = entity;
68 | this.snapshot = null;
69 | this.id = id;
70 | String contentTypeHeader = entity.contentType();
71 | String contentType = "application/octet-stream";
72 | if (contentTypeHeader != null) {
73 | contentType = contentTypeHeader;
74 | }
75 | this.contentType = contentType;
76 | contentLength = entity.contentLength();
77 | }
78 |
79 | static BufferedInputStream getInput(HttpResponse.Body entity) throws IOException {
80 | InputStream in = entity.getContent();
81 | if (in instanceof BufferedInputStream) {
82 | return (BufferedInputStream) in;
83 | }
84 | return new BufferedInputStream(in);
85 | }
86 |
87 | // ------------------------ INTERFACE METHODS ------------------------
88 |
89 |
90 | // --------------------- Interface AutoCloseable ---------------------
91 |
92 | @Override
93 | public void close() throws IOException {
94 | super.close();
95 | if (entity != null) {
96 |
97 | entity.close();
98 | }
99 | if (snapshot != null) snapshot.close();
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/ByteOutput.java:
--------------------------------------------------------------------------------
1 | package com.baasbox.android;
2 |
3 | import java.io.IOException;
4 |
5 | /**
6 | * Created by Andrea Tortorella on 2/23/15.
7 | */
8 | interface ByteOutput {
9 | byte[] data();
10 | int size();
11 |
12 | void write(byte[] what,int offset,int count) throws IOException;
13 |
14 | void close() throws IOException;
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/ConcurrentHashSet.java:
--------------------------------------------------------------------------------
1 | package com.baasbox.android;
2 |
3 | import java.util.AbstractSet;
4 | import java.util.Iterator;
5 | import java.util.concurrent.ConcurrentHashMap;
6 |
7 | /**
8 | * Created by aktor on 25/11/15.
9 | */
10 | class ConcurrentHashSet extends AbstractSet {
11 |
12 | private final ConcurrentHashMap mMap;
13 |
14 | ConcurrentHashSet(){
15 | mMap = new ConcurrentHashMap<>();
16 | }
17 |
18 | @Override
19 | public Iterator iterator() {
20 | return mMap.keySet().iterator();
21 | }
22 |
23 |
24 | @Override
25 | public int size() {
26 | return mMap.size();
27 | }
28 |
29 | @Override
30 | public boolean contains(Object object) {
31 | return mMap.get(object) != null;
32 | }
33 |
34 | @Override
35 | public boolean add(T object) {
36 | return mMap.put(object,object)==null;
37 | }
38 |
39 | @Override
40 | public boolean remove(Object object) {
41 | return mMap.remove(object,object);
42 | }
43 |
44 | @Override
45 | public void clear() {
46 | mMap.clear();
47 | }
48 |
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/DataStreamHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014. BaasBox
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and limitations under the License.
14 | */
15 |
16 | package com.baasbox.android;
17 |
18 | /**
19 | * Interface definition for a callback to be invoked when new data is available
20 | * in an asynchronous streaming request.
21 | * This interface is used to handle the asynchronous streaming of files.
22 | *
23 | * The callback is invoked on a background thread ant it may be invoked many times while the data is streamed
24 | * from the server.
25 | * While the content is downloaded the data byte array will never be null and will contain
26 | * new data received from the server.
27 | *
28 | * When the streaming of the file ends, the callback will be invoked one more time with
29 | * a null data
byte array, that is an indication that the content has been completely
30 | * retrieved from the server.
31 | *
32 | *
33 | * The return value of the last call to {@link #onData(byte[], int)} is what will be presented
34 | * to the handler, wrapped in a {@link com.baasbox.android.BaasResult}, if during any invocation an exception is thrown
35 | * it will be wrapped as a {@link com.baasbox.android.BaasResult#failure(BaasException)}.
36 | *
37 | *
38 | * This is an example of streaming a response to a String:
39 | *
40 | *
41 | *
42 | * public class StreamToString implements DataStreamHandler<String>{
43 | * private ByteArrayOutputStream out = new ByteArrayOutputStream();
44 | *
45 | * @Override
46 | * public String onData(byte[] data,int read,long contentLength,String id,String contentType) throws Exception{
47 | * if(data!=null){
48 | * out.write(data,0,read);
49 | * return null;
50 | * } else{
51 | * return out.toString("UTF-8");
52 | * }
53 | * }
54 | * }
55 | *
56 | *
57 | *
58 | *
59 | * @param the type of response that this stream handler will deliver
60 | * @author Andrea Tortorella
61 | * @since 0.7.3
62 | */
63 | public interface DataStreamHandler {
64 | // -------------------------- OTHER METHODS --------------------------
65 |
66 | /**
67 | * Method invoked right before data starts to stream.
68 | * @param id the identifier to which this stream is bound to
69 | * @param contentLength the length of the body
70 | * @param contentType the contentType of the response
71 | * @throws Exception
72 | */
73 | void startData(String id,long contentLength,String contentType) throws Exception;
74 |
75 | /**
76 | * Method invoked when new data is available.
77 | *
78 | * @param data a byte[] array filled with new available data or null if there is no more available.
79 | * @param read the number of actual bytes that can be read from data
80 | * @throws Exception any exception thrown will be wrapped in a {@link com.baasbox.android.BaasException}
81 | */
82 | void onData(byte[] data, int read) throws Exception;
83 |
84 | /**
85 | * Method invoked when the whole data has been streamed
86 | *
87 | * @param id the identifier to which this stream is bound to
88 | * @param contentLength the length of the body
89 | * @param contentType the contentType of the response
90 | * @return an object
91 | * @throws Exception
92 | */
93 | R endData(String id,long contentLength,String contentType) throws Exception;
94 |
95 | void finishStream(String id);
96 | }
97 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/DefaultSignupStrategy.java:
--------------------------------------------------------------------------------
1 | package com.baasbox.android;
2 |
3 | import com.baasbox.android.json.JsonObject;
4 |
5 | /**
6 | * Created by aktor on 14/12/15.
7 | */
8 | public class DefaultSignupStrategy implements BaasUser.SignupStrategy {
9 | public static final BaasUser.SignupStrategy INSTANCE = new DefaultSignupStrategy();
10 |
11 | protected DefaultSignupStrategy(){}
12 |
13 | @Override
14 | public void validate(BaasUser user) throws BaasRuntimeException {
15 | if (user.getPassword() == null){
16 | throw new BaasRuntimeException("missing password");
17 | }
18 | }
19 |
20 | @Override
21 | public String endpoint() {
22 | return "user";
23 | }
24 |
25 | @Override
26 | public JsonObject requestBody(BaasUser userSignUp) {
27 | return userSignUp.toJsonRequest(true);
28 | }
29 |
30 | @Override
31 | public String getToken(JsonObject response) {
32 | return response.getString("X-BB-SESSION");
33 | }
34 |
35 | @Override
36 | public void updateUser(BaasUser user, JsonObject content) {
37 | user.update(content);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/DyanmicByteArrayOutputStream.java:
--------------------------------------------------------------------------------
1 | package com.baasbox.android;
2 |
3 |
4 | /**
5 | * Created by Andrea Tortorella on 2/23/15.
6 | */
7 | class DyanmicByteArrayOutputStream extends java.io.ByteArrayOutputStream implements ByteOutput {
8 |
9 |
10 | DyanmicByteArrayOutputStream(){
11 | super();
12 |
13 | }
14 |
15 | @Override
16 | public byte[] data(){
17 | if (buf.length==size()){
18 | return buf;
19 | } else {
20 | return toByteArray();
21 | }
22 | }
23 |
24 |
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/ExceptionHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014. BaasBox
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and limitations under the License.
14 | */
15 |
16 | package com.baasbox.android;
17 |
18 | import com.baasbox.android.impl.Logger;
19 |
20 | /**
21 | * This is invoked when an unexpected error happens during the execution
22 | * of an asynchronous operation.
23 | *
24 | * @author Andrea Tortorella
25 | * @since 0.7.3
26 | */
27 | public interface ExceptionHandler {
28 | // ------------------------------ FIELDS ------------------------------
29 |
30 | ExceptionHandler DEFAULT = new ExceptionHandler() {
31 | @Override
32 | public boolean onError(Throwable t){
33 | throw new RuntimeException(t);
34 | }
35 | };
36 |
37 | ExceptionHandler LOGGING_HANDLER = new ExceptionHandler() {
38 | @Override
39 | public boolean onError(Throwable t){
40 | Logger.error(t, "Error during execution of task on dispatcher: continue with next request");
41 | return true;
42 | }
43 | };
44 |
45 | // -------------------------- OTHER METHODS --------------------------
46 |
47 | boolean onError(Throwable t);
48 | }
49 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/FixedByteArrayOutputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.baasbox.android;
19 |
20 | import java.io.IOException;
21 | import java.io.OutputStream;
22 | import java.io.UnsupportedEncodingException;
23 | import java.util.Arrays;
24 |
25 | /**
26 | * Created by Andrea Tortorella on 19/05/14.
27 | */
28 | class FixedByteArrayOutputStream extends OutputStream implements ByteOutput{
29 | private byte[] mData;
30 | private int mCount;
31 |
32 | FixedByteArrayOutputStream(long size){
33 | this((int)size);
34 | }
35 |
36 | FixedByteArrayOutputStream(int size){
37 | if (size<0) throw new IllegalArgumentException("Size cannot be negative");
38 | mData = new byte[size];
39 | }
40 |
41 | @Override
42 | public void write(byte[] buffer) throws IOException {
43 | this.write(buffer,0,buffer.length);
44 | }
45 |
46 | @Override
47 | public void write(byte[] buffer, int offset, int count) throws IOException {
48 | if ((offset<0)||(offset>buffer.length)||(count<0)||((offset+count)>buffer.length)||
49 | ((offset+count)<0)){
50 | throw new IndexOutOfBoundsException();
51 | } else if (count == 0){
52 | return;
53 | } else {
54 | int c = mCount+count;
55 | System.arraycopy(buffer,offset,mData,mCount,count);
56 | mCount=c;
57 | }
58 | }
59 |
60 | @Override
61 | public synchronized void write(int oneByte) throws IOException {
62 | if (mCount==mData.length){
63 | throw new IndexOutOfBoundsException("Array index out of bounds");
64 | }
65 | mData[mCount++]=(byte)oneByte;
66 | }
67 |
68 | public synchronized void writeTo(OutputStream out) throws IOException{
69 | out.write(mData,0,mCount);
70 | }
71 |
72 | public synchronized void reset(){
73 | mCount = 0;
74 | }
75 |
76 | public synchronized byte[] data(){
77 | return mData;
78 | }
79 |
80 | public synchronized byte[] copy(){
81 | return Arrays.copyOf(mData,mCount);
82 | }
83 |
84 | public synchronized int size(){
85 | return mCount;
86 | }
87 |
88 | @Override
89 | public synchronized String toString() {
90 | return new String(mData,0,mCount);
91 | }
92 |
93 | public synchronized String toString(String charset) throws UnsupportedEncodingException{
94 | return new String(mData,0,mCount,charset);
95 | }
96 |
97 | @Override
98 | public void close() throws IOException {
99 | // ignore
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/Grant.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014. BaasBox
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and limitations under the License.
14 | */
15 |
16 | package com.baasbox.android;
17 |
18 | /**
19 | * An enumeration representing the possible access grants to
20 | * {@link com.baasbox.android.BaasObject}.
21 | *
22 | * @author Andrea Tortorella
23 | * @since 0.7.3
24 | */
25 | public enum Grant {
26 | /**
27 | * Read permission
28 | */
29 | READ("read"),
30 |
31 | /**
32 | * Update permission
33 | */
34 | UPDATE("update"),
35 |
36 | /**
37 | * Delete permission
38 | */
39 | DELETE("delete"),
40 |
41 | /**
42 | * Permission to take any operation
43 | * on the object.
44 | */
45 | ALL("all");
46 |
47 | // ------------------------------ FIELDS ------------------------------
48 |
49 | final String action;
50 |
51 | // --------------------------- CONSTRUCTORS ---------------------------
52 | Grant(String action) {
53 | this.action = action;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/JsonWrapper.java:
--------------------------------------------------------------------------------
1 | package com.baasbox.android;
2 |
3 | import android.os.Parcel;
4 |
5 | import com.baasbox.android.json.JsonObject;
6 |
7 | /**
8 | * Created by eto on 17/02/14.
9 | */
10 | final class JsonWrapper extends JsonObject{
11 | private volatile boolean mDirty;
12 |
13 | JsonWrapper(){
14 | super(new JsonObject());
15 | mDirty = true;
16 | }
17 |
18 | JsonWrapper(JsonObject o){
19 | super(o == null ? new JsonObject():o);
20 | mDirty = true;
21 | }
22 |
23 | JsonWrapper(Parcel p){
24 | super(p);
25 | mDirty = (p.readByte() == 1);
26 | }
27 |
28 | @Override
29 | protected void onModify() {
30 | super.onModify();
31 | mDirty =true;
32 | }
33 |
34 | boolean isDirty(){
35 | return mDirty;
36 | }
37 |
38 | void setDirty(boolean dirty){
39 | mDirty=dirty;
40 | }
41 |
42 | @Override
43 | public void writeToParcel(Parcel dest, int flags) {
44 | super.writeToParcel(dest, flags);
45 | dest.writeByte((byte)(mDirty?1:0));
46 | }
47 |
48 | public static final Creator CREATOR = new Creator() {
49 | @Override
50 | public JsonWrapper createFromParcel(Parcel source) {
51 | return new JsonWrapper(source);
52 | }
53 |
54 | @Override
55 | public JsonWrapper[] newArray(int size) {
56 | return new JsonWrapper[size];
57 | }
58 | };
59 | }
60 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/Plugin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.baasbox.android;
19 |
20 | import android.content.Context;
21 |
22 | import com.baasbox.android.BaasBox;
23 |
24 | /**
25 | * Created by Andrea Tortorella on 09/09/14.
26 | */
27 | public abstract class Plugin {
28 | protected abstract void setup(Context context,BaasBox box,T options);
29 |
30 | public static abstract class Options{
31 | public static class Empty extends Options{ private Empty(){}}
32 | public static final Options NoOptions = new Empty();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/RequestOptions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.baasbox.android;
19 |
20 | import com.baasbox.android.impl.Constants;
21 |
22 | /**
23 | * Options that can be used to modify how a request will be executed.
24 | *
25 | * Created by Andrea Tortorella on 14/04/14.
26 | */
27 | public final class RequestOptions {
28 | /**
29 | * Marks an asyncrhonous request as normal priority
30 | */
31 | public static final int PRIORITY_NORMAL = Constants.PRIORITY_NORMAL;
32 |
33 | /**
34 | * Marks an asynchronous request as low priority
35 | */
36 | public static final int PRIORITY_LOW=Constants.PRIORITY_HIGH;
37 |
38 |
39 | /**
40 | * Marks an asynchronous request as high priority
41 | */
42 | public static final int PRIORITY_HIGH=Constants.PRIORITY_HIGH;
43 |
44 | /**
45 | * The set of defaults flags for a request.
46 | */
47 | public static final int DEFAULT = PRIORITY_NORMAL;
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/Rest.java:
--------------------------------------------------------------------------------
1 | package com.baasbox.android;
2 |
3 | import com.baasbox.android.json.JsonObject;
4 | import com.baasbox.android.json.JsonStructure;
5 | import com.baasbox.android.net.HttpRequest;
6 |
7 | /**
8 | * Created by Andrea Tortorella on 1/12/15.
9 | */
10 | public interface Rest {
11 | public static enum Method{
12 | GET(HttpRequest.GET),
13 | POST(HttpRequest.POST),
14 | PUT(HttpRequest.PUT),
15 | DELETE(HttpRequest.DELETE),
16 | PATCH(HttpRequest.PATCH)
17 | ;
18 |
19 | final int method;
20 | Method(int method){
21 | this.method= method;
22 | }
23 | }
24 |
25 | public RequestToken async(Method method,String endpoint,JsonStructure body,boolean authenticate,int flags,BaasHandler handler);
26 | public RequestToken async(Method method, String endpoint, JsonStructure body, boolean authenticate, BaasHandler handler);
27 | public RequestToken async(Method method, String endpoint, boolean authenticate, BaasHandler handler);
28 |
29 | public RequestToken async(Method method, String endpoint, JsonStructure body, BaasHandler handler);
30 | public RequestToken async(Method method, String endpoint, BaasHandler handler);
31 |
32 | public BaasResult sync(Method method, String endpoint, JsonStructure body, boolean authenticate);
33 | public BaasResult sync(Method method, String endpoint, JsonStructure body);
34 | public BaasResult sync(Method method, String endpoint);
35 |
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/Role.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014. BaasBox
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and limitations under the License.
14 | */
15 |
16 | package com.baasbox.android;
17 |
18 | /**
19 | * Constants and utilites for
20 | * managing and usin roles.
21 | * Created by Andrea Tortorella on 18/01/14.
22 | */
23 | public final class Role {
24 | // ------------------------------ FIELDS ------------------------------
25 |
26 | /**
27 | * Role of anonymous users
28 | */
29 | public static final String ANONYMOUS = "anonymous";
30 |
31 | /**
32 | * Role of registered users
33 | */
34 | public static final String REGISTERED = "registered";
35 |
36 | /**
37 | * Role of administrators
38 | */
39 | public static final String ADMIN = "administrator";
40 |
41 | /**
42 | * Role of backoffice users
43 | */
44 | public static final String BACKOFFICE = "backoffice";
45 |
46 | // --------------------------- CONSTRUCTORS ---------------------------
47 | private Role() {
48 | }
49 |
50 | // -------------------------- STATIC METHODS --------------------------
51 |
52 | /**
53 | * Returns the role to whom belong all users
54 | * that are friends of user
55 | *
56 | * @param user the username
57 | * @return the role of friends of user
58 | */
59 | public static String friendsOf(String user) {
60 | if (user == null) throw new IllegalArgumentException("user cannot be null");
61 | return "friends_of_" + user;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/SaveMode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014. BaasBox
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and limitations under the License.
14 | */
15 |
16 | package com.baasbox.android;
17 |
18 | /**
19 | * Mode used during update operations.
20 | * Created by Andrea Tortorella on 16/01/14.
21 | */
22 | public enum SaveMode {
23 | /**
24 | * Ignore the version during updates,
25 | * documents on the server are overwritten by the local
26 | * one that is sent.
27 | */
28 | IGNORE_VERSION,
29 |
30 | /**
31 | * Check the version during updates,
32 | * If the version on the server is newer
33 | * than the local one, the document is not updated
34 | * and an error is returned instead
35 | */
36 | CHECK_VERSION,
37 | }
38 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/StreamBody.java:
--------------------------------------------------------------------------------
1 | package com.baasbox.android;
2 |
3 | import java.io.IOException;
4 |
5 | /**
6 | * Created by Andrea Tortorella on 05/02/14.
7 | */
8 | abstract class StreamBody implements DataStreamHandler {
9 | // ------------------------------ FIELDS ------------------------------
10 |
11 | //private FixedByteArrayOutputStream bos;
12 | private ByteOutput bos;
13 |
14 | // ------------------------ INTERFACE METHODS ------------------------
15 |
16 |
17 | // --------------------- Interface DataStreamHandler ---------------------
18 |
19 | @Override
20 | public final void startData(String id, long contentLength, String contentType) throws Exception {
21 | if (contentLength==-1){
22 | bos = new DyanmicByteArrayOutputStream();
23 | } else {
24 | bos = new FixedByteArrayOutputStream(contentLength);
25 | }
26 | }
27 |
28 | @Override
29 | public final R endData(String id, long contentLength, String contentType) throws Exception {
30 | byte[] content = bos.data();
31 |
32 | return convert(content,id,contentType,contentLength);
33 | }
34 |
35 | @Override
36 | public final void onData(byte[] data, int read) throws Exception {
37 | bos.write(data,0,read);
38 | }
39 |
40 | @Override
41 | public final void finishStream(String stremId) {
42 | try {
43 | if(bos != null){
44 | bos.close();
45 | }
46 | } catch (IOException e) {
47 | // swallow
48 | }
49 | }
50 |
51 | // -------------------------- OTHER METHODS --------------------------
52 |
53 | protected abstract R convert(byte[] body, String id,String contentType,long contentLength);
54 |
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/StreamRequest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014. BaasBox
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and limitations under the License.
14 | */
15 |
16 | package com.baasbox.android;
17 |
18 | import com.baasbox.android.net.HttpRequest;
19 | import com.baasbox.android.net.HttpResponse;
20 |
21 | import java.io.IOException;
22 |
23 | /**
24 | * Created by Andrea Tortorella on 17/01/14.
25 | */
26 | class StreamRequest extends NetworkTask {
27 | // ------------------------------ FIELDS ------------------------------
28 |
29 | private final String id;
30 | private final HttpRequest request;
31 |
32 | // --------------------------- CONSTRUCTORS ---------------------------
33 | protected StreamRequest(BaasBox box, String resource, String id, String sizeSpec, int sizeId) {
34 | super(box, RequestOptions.DEFAULT, null);
35 | this.id = id;
36 | String endpoint = box.requestFactory.getEndpoint("{}/{}", resource, id);
37 | RequestFactory.Param param = null;
38 | if (sizeSpec != null) {
39 | param = new RequestFactory.Param("resize", sizeSpec);
40 | } else if (sizeId >= 0) {
41 | param = new RequestFactory.Param("sizeId", Integer.toString(sizeId));
42 | }
43 | if (param != null) {
44 | request = box.requestFactory.get(endpoint, param);
45 | } else {
46 | request = box.requestFactory.get(endpoint);
47 | }
48 | }
49 |
50 | // -------------------------- OTHER METHODS --------------------------
51 |
52 | @Override
53 | protected BaasStream getFromCache(BaasBox box) throws BaasException {
54 | return box.mCache.getStream(id);
55 | }
56 |
57 | @Override
58 | protected BaasStream onOk(int status, HttpResponse response, BaasBox box) throws BaasException {
59 | boolean close = true;
60 | HttpResponse.Body entity = null;
61 | try {
62 | entity = response.getEntity();
63 |
64 | BaasStream stream = new BaasStream(id, entity);
65 | close = false;
66 | return stream;
67 | } catch (IOException e) {
68 | throw new BaasException(e);
69 | } finally {
70 | if (close) {
71 | try {
72 | if (entity != null) {
73 | entity.close();
74 | }
75 | } catch (IOException e) {
76 | // ignored
77 | }
78 | }
79 | }
80 | }
81 |
82 | @Override
83 | protected HttpRequest request(BaasBox box) {
84 | return request;
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/impl/Constants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.baasbox.android.impl;
19 |
20 | /**
21 | * Created by Andrea Tortorella on 12/05/14.
22 | */
23 | public final class Constants {
24 | public static final int[] PRIORITY_MAP ={0,-1,1,0};
25 | public static final int PRIORITY_NORMAL = 0;
26 | public static final int PRIORITY_LOW = 1;
27 | public static final int PRIORITY_HIGH = 2;
28 | public static final int PRIORITY_MASK = PRIORITY_LOW|PRIORITY_HIGH;
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/impl/ImmediateDispatcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014. BaasBox
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and limitations under the License.
14 | */
15 |
16 | package com.baasbox.android.impl;
17 |
18 | import com.baasbox.android.BaasException;
19 | import com.baasbox.android.BaasResult;
20 |
21 | /**
22 | * Created by eto on 20/01/14.
23 | */
24 | public final class ImmediateDispatcher {
25 | // -------------------------- OTHER METHODS --------------------------
26 |
27 | public BaasResult execute(Task request) {
28 | try {
29 | R r = request.asyncCall();
30 | return BaasResult.success(r);
31 | } catch (BaasException e) {
32 | return BaasResult.failure(e);
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/impl/Logger.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014. BaasBox
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and limitations under the License.
14 | */
15 |
16 | package com.baasbox.android.impl;
17 |
18 | import android.util.Log;
19 |
20 | import java.util.Locale;
21 |
22 | /**
23 | * Created by Andrea Tortorella on 18/01/14.
24 | */
25 | public final class Logger {
26 | // ------------------------------ FIELDS ------------------------------
27 |
28 | private static final boolean ENABLED = true;
29 | private static final String TAG = "BAASBOX";
30 |
31 | // --------------------------- CONSTRUCTORS ---------------------------
32 | private Logger(){
33 | }
34 |
35 | // -------------------------- STATIC METHODS --------------------------
36 |
37 | public static void warn(String format, Object... args) {
38 | if (ENABLED && Log.isLoggable(TAG, Log.WARN)) {
39 | Log.w(TAG, String.format(Locale.US, format, args));
40 | }
41 | }
42 |
43 | public static void warn(Throwable e,String format, Object... args) {
44 | if (ENABLED && Log.isLoggable(TAG, Log.WARN)) {
45 | Log.w(TAG, String.format(Locale.US, format, args),e);
46 | }
47 | }
48 |
49 | public static void trace(String format, Object... args) {
50 | if (ENABLED && Log.isLoggable(TAG, Log.VERBOSE)) {
51 | Log.v(TAG, String.format(Locale.US, format, args));
52 | }
53 | }
54 |
55 | public static void info(String format, Object... args) {
56 | if (ENABLED && Log.isLoggable(TAG, Log.INFO)) {
57 | Log.i(TAG, String.format(Locale.US, format, args));
58 | }
59 | }
60 |
61 | public static void info(Throwable e,String format, Object... args) {
62 | if (ENABLED && Log.isLoggable(TAG, Log.INFO)) {
63 | Log.i(TAG, String.format(Locale.US, format, args),e);
64 | }
65 | }
66 |
67 | public static void error(String format, Object... args) {
68 | if (ENABLED && Log.isLoggable(TAG, Log.ERROR)) {
69 | Log.e(TAG, String.format(Locale.US, format, args));
70 | }
71 | }
72 |
73 | public static void error(Throwable t, String format, Object... args) {
74 | if (ENABLED && Log.isLoggable(TAG, Log.ERROR)) {
75 | Log.e(TAG, String.format(Locale.US, format, args), t);
76 | }
77 | }
78 |
79 | public static void debug(String format, Object... args) {
80 | if (ENABLED && Log.isLoggable(TAG, Log.DEBUG)) {
81 | Log.d(TAG, String.format(Locale.US, format, args));
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/impl/Util.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.baasbox.android.impl;
18 |
19 | import android.os.Parcel;
20 | import android.os.Parcelable;
21 |
22 | import java.io.*;
23 | import java.nio.charset.Charset;
24 |
25 | /**
26 | * Junk drawer of utility methods.
27 | */
28 | public final class Util {
29 | // ------------------------------ FIELDS ------------------------------
30 |
31 | static final Charset US_ASCII = Charset.forName("US-ASCII");
32 | static final Charset UTF_8 = Charset.forName("UTF-8");
33 |
34 | // --------------------------- CONSTRUCTORS ---------------------------
35 | private Util() {
36 | }
37 |
38 | // -------------------------- STATIC METHODS --------------------------
39 |
40 | static String readFully(Reader reader) throws IOException {
41 | try {
42 | StringWriter writer = new StringWriter();
43 | char[] buffer = new char[1024];
44 | int count;
45 | while ((count = reader.read(buffer)) != -1) {
46 | writer.write(buffer, 0, count);
47 | }
48 | return writer.toString();
49 | } finally {
50 | reader.close();
51 | }
52 | }
53 |
54 | /**
55 | * Deletes the contents of {@code dir}. Throws an IOException if any file
56 | * could not be deleted, or if {@code dir} is not a readable directory.
57 | */
58 | static void deleteContents(File dir) throws IOException {
59 | File[] files = dir.listFiles();
60 | if (files == null) {
61 | throw new IOException("not a readable directory: " + dir);
62 | }
63 | for (File file : files) {
64 | if (file.isDirectory()) {
65 | deleteContents(file);
66 | }
67 | if (!file.delete()) {
68 | throw new IOException("failed to delete file: " + file);
69 | }
70 | }
71 | }
72 |
73 | static void closeQuietly(/*Auto*/Closeable closeable) {
74 | if (closeable != null) {
75 | try {
76 | closeable.close();
77 | } catch (RuntimeException rethrown) {
78 | throw rethrown;
79 | } catch (Exception ignored) {
80 | // ignored
81 | }
82 | }
83 | }
84 |
85 |
86 | public static void writeOptString(Parcel p, String s) {
87 | if (s == null) {
88 | p.writeByte((byte) 0);
89 | } else {
90 | p.writeByte((byte) 1);
91 | p.writeString(s);
92 | }
93 | }
94 |
95 | public static void writeBoolean(Parcel p,boolean b) {
96 | p.writeByte(b?(byte)1:(byte)0);
97 | }
98 |
99 | public static void writeOptBytes(Parcel dest, byte[] bytes) {
100 | if (bytes==null){
101 | dest.writeByte((byte)0);
102 | } else {
103 | dest.writeByte((byte)1);
104 | dest.writeInt(bytes.length);
105 | dest.writeByteArray(bytes);
106 | }
107 | }
108 |
109 | public static final String readOptString(Parcel p) {
110 | boolean read = p.readByte() == 1;
111 | if (read) {
112 | return p.readString();
113 | }
114 | return null;
115 | }
116 |
117 | public static byte[] readOptBytes(Parcel source){
118 | if (source.readByte()==1){
119 | int size = source.readInt();
120 | byte[] ret = new byte[size];
121 | source.readByteArray(ret);
122 | return ret;
123 | }
124 | return null;
125 | }
126 |
127 | public static boolean readBoolean(Parcel source) {
128 | return source.readByte()==1;
129 | }
130 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/impl/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @hide
3 | */
4 | package com.baasbox.android.impl;
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/json/JsonException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014. BaasBox
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and limitations under the License.
14 | */
15 |
16 | package com.baasbox.android.json;
17 |
18 | /**
19 | * Created by Andrea Tortorella on 01/01/14.
20 | */
21 | public class JsonException extends RuntimeException {
22 | // ------------------------------ FIELDS ------------------------------
23 |
24 | private static final long serialVersionUID = -3383190900059424412L;
25 |
26 | // --------------------------- CONSTRUCTORS ---------------------------
27 | public JsonException() {
28 | }
29 |
30 | public JsonException(String detailMessage) {
31 | super(detailMessage);
32 | }
33 |
34 | public JsonException(Throwable throwable) {
35 | super(throwable);
36 | }
37 |
38 | public JsonException(String detailMessage, Throwable throwable) {
39 | super(detailMessage, throwable);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/json/JsonScope.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.baasbox.android.json;
18 |
19 | /**
20 | * Lexical scoping elements within a JSON reader or writer.
21 | */
22 | enum JsonScope {
23 | /**
24 | * An array with no elements requires no separators or newlines before
25 | * it is closed.
26 | */
27 | EMPTY_ARRAY,
28 |
29 | /**
30 | * A array with at least one value requires a comma and newline before
31 | * the next element.
32 | */
33 | NONEMPTY_ARRAY,
34 |
35 | /**
36 | * An object with no name/value pairs requires no separators or newlines
37 | * before it is closed.
38 | */
39 | EMPTY_OBJECT,
40 |
41 | /**
42 | * An object whose most recent element is a key. The next element must
43 | * be a value.
44 | */
45 | DANGLING_NAME,
46 |
47 | /**
48 | * An object with at least one name/value pair requires a comma and
49 | * newline before the next element.
50 | */
51 | NONEMPTY_OBJECT,
52 |
53 | /**
54 | * No object or array has been started.
55 | */
56 | EMPTY_DOCUMENT,
57 |
58 | /**
59 | * A document with at an array or object.
60 | */
61 | NONEMPTY_DOCUMENT,
62 |
63 | /**
64 | * A document that's been closed and cannot be accessed.
65 | */
66 | CLOSED,
67 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/json/JsonToken.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.baasbox.android.json;
18 |
19 | /**
20 | * A structure, name or value type in a JSON-encoded string.
21 | */
22 | enum JsonToken {
23 | /**
24 | * The opening of a JSON array. Written using {@link JsonWriter#beginObject}
25 | * and read using {@link JsonReader#beginObject}.
26 | */
27 | BEGIN_ARRAY,
28 |
29 | /**
30 | * The closing of a JSON array. Written using {@link JsonWriter#endArray}
31 | * and read using {@link JsonReader#endArray}.
32 | */
33 | END_ARRAY,
34 |
35 | /**
36 | * The opening of a JSON object. Written using {@link JsonWriter#beginObject}
37 | * and read using {@link JsonReader#beginObject}.
38 | */
39 | BEGIN_OBJECT,
40 |
41 | /**
42 | * The closing of a JSON object. Written using {@link JsonWriter#endObject}
43 | * and read using {@link JsonReader#endObject}.
44 | */
45 | END_OBJECT,
46 |
47 | /**
48 | * A JSON property name. Within objects, tokens alternate between names and
49 | * their values. Written using {@link JsonWriter#name} and read using {@link
50 | * JsonReader#nextName}
51 | */
52 | NAME,
53 |
54 | /**
55 | * A JSON string.
56 | */
57 | STRING,
58 |
59 | /**
60 | * A JSON number represented in this API by a Java {@code double}, {@code
61 | * long}, or {@code int}.
62 | */
63 | NUMBER,
64 |
65 | /**
66 | * A JSON {@code true} or {@code false}.
67 | */
68 | BOOLEAN,
69 |
70 | /**
71 | * A JSON {@code null}.
72 | */
73 | NULL,
74 |
75 | /**
76 | * The end of the JSON stream. This sentinel value is returned by {@link
77 | * JsonReader#peek()} to signal that the JSON-encoded value has no more
78 | * tokens.
79 | */
80 | END_DOCUMENT
81 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/json/StringPool.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.baasbox.android.json;
17 |
18 | /**
19 | * A pool of string instances. Unlike the {@link String#intern() VM's
20 | * interned strings}, this pool provides no guarantee of reference equality.
21 | * It is intended only to save allocations. This class is not thread safe.
22 | */
23 | final class StringPool {
24 | // ------------------------------ FIELDS ------------------------------
25 |
26 | private final String[] pool = new String[512];
27 |
28 | // -------------------------- OTHER METHODS --------------------------
29 |
30 | /**
31 | * Returns a string equal to {@code new String(array, start, length)}.
32 | */
33 | public String get(char[] array, int start, int length) {
34 | // Compute an arbitrary hash of the content
35 | int hashCode = 0;
36 | for (int i = start; i < start + length; i++) {
37 | hashCode = (hashCode * 31) + array[i];
38 | }
39 |
40 | // Pick a bucket using Doug Lea's supplemental secondaryHash function (from HashMap)
41 | hashCode ^= (hashCode >>> 20) ^ (hashCode >>> 12);
42 | hashCode ^= (hashCode >>> 7) ^ (hashCode >>> 4);
43 | int index = hashCode & (pool.length - 1);
44 |
45 | String pooled = pool[index];
46 | if (pooled != null && contentEquals(pooled, array, start, length)) {
47 | return pooled;
48 | }
49 |
50 | String result = new String(array, start, length);
51 | pool[index] = result;
52 | return result;
53 | }
54 |
55 | private static boolean contentEquals(String s, char[] chars, int start, int length) {
56 | if (s.length() != length) {
57 | return false;
58 | }
59 | for (int i = 0; i < length; i++) {
60 | if (chars[start + i] != s.charAt(i)) {
61 | return false;
62 | }
63 | }
64 | return true;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/json/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Provides classes to use JSON as tree like structures.
3 | *
4 | */
5 | package com.baasbox.android.json;
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/net/HttpRequest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014. BaasBox
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and limitations under the License.
14 | */
15 |
16 | package com.baasbox.android.net;
17 |
18 | import java.io.InputStream;
19 | import java.util.Map;
20 |
21 | /**
22 | * Reifies an http request.
23 | * Created by eto on 23/12/13.
24 | */
25 | public class HttpRequest {
26 | // ------------------------------ FIELDS ------------------------------
27 |
28 | public static final int GET = 1;
29 | public static final int POST = 2;
30 | public static final int PUT = 3;
31 | public static final int DELETE = 4;
32 | public static final int PATCH = 5;
33 |
34 | public final int method;
35 | public final String url;
36 | public final Map headers;
37 | public InputStream body;
38 |
39 | // --------------------------- CONSTRUCTORS ---------------------------
40 | public HttpRequest(int method, String url, Map headers, InputStream body) {
41 | this.method = method;
42 | this.url = url;
43 | this.headers = headers;
44 | this.body = body;
45 | }
46 |
47 | // ------------------------ CANONICAL METHODS ------------------------
48 |
49 | @Override
50 | public String toString() {
51 | StringBuilder sb = new StringBuilder("{url ->" + url + " method: " + methodToString(method) + ", headers ->{");
52 | for (Map.Entry header : headers.entrySet()) {
53 | sb.append(header.getKey() + ":" + header.getValue());
54 | }
55 | sb.append("}}");
56 |
57 | return sb.toString();
58 | }
59 |
60 | private static String methodToString(int method) {
61 | String methodName;
62 | switch (method) {
63 | case GET:
64 | methodName = "GET";
65 | break;
66 | case POST:
67 | methodName = "POST";
68 | break;
69 | case PUT:
70 | methodName = "PUT";
71 | break;
72 | case DELETE:
73 | methodName = "DELETE";
74 | break;
75 | case PATCH:
76 | methodName = "PATCH";
77 | break;
78 | default:
79 | throw new IllegalArgumentException("Invalid http method identifier");
80 | }
81 | return methodName;
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/net/RestClient.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014. BaasBox
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and limitations under the License.
14 | */
15 |
16 | package com.baasbox.android.net;
17 |
18 | import android.content.Context;
19 |
20 | import com.baasbox.android.BaasBox;
21 | import com.baasbox.android.BaasException;
22 |
23 | /**
24 | * This interface represent an http client for Baasbox.
25 | * Created by Andrea Tortorella on 23/12/13.
26 | */
27 | public interface RestClient {
28 | // -------------------------- OTHER METHODS --------------------------
29 |
30 | /**
31 | * Execute the http request returning on success an HttpResponse
32 | * from the service.
33 | * May fail, with any exception, but that must be wrapped in a BaasException.
34 | *
35 | * @param request the request
36 | * @return an http response
37 | * @throws com.baasbox.android.BaasException
38 | */
39 | HttpResponse execute(HttpRequest request) throws BaasException;
40 |
41 | /**
42 | * Initializes the client given a configuration and a context
43 | * @param context
44 | * @param config
45 | */
46 | void init(Context context, BaasBox.Config config);
47 | }
48 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Provides classes necessary to use the BaasBox API,
3 | * and the main entry point to configure the client.
4 | *
5 | * A BaasBox connected app needs to initialize the
6 | * client through the {@link com.baasbox.android.BaasBox} class
7 | * providing an optional configuration.
8 | *
9 | * Once this initialization has been done, the server functionality
10 | * may be accessed through wrapper classes for each kind of resource
11 | * exposed via the rest api.
12 | *
13 | * Each rest endpoint is accessible through asynchronous methods,
14 | * that give a callback interface using {@link com.baasbox.android.BaasHandler}
15 | * general interface,
16 | * Asyncrhonous calls may be canceled or suspended for later resumption, through
17 | * the handle {@link com.baasbox.android.RequestToken} returned by asynchronous
18 | * calls.
19 | *
20 | * The api also provides synchronous alternatives using the
21 | * sync version of the methods, mostly for cases when the
22 | * request is initiated by another thread other than the main one.
23 | *
24 | * Different resources are wrapped by specific classes:
25 | *
26 | * - {@link com.baasbox.android.BaasUser} a user of the BaasBox server
27 | * - {@link com.baasbox.android.BaasDocument} a json document stored in a collectiont on the server
28 | * - {@link com.baasbox.android.BaasFile} a blob stored on the server
29 | *
30 | *
31 | * Since remote calls done through http, may fail results are always wrapped in an
32 | * option result type {@link com.baasbox.android.BaasResult}
33 | *
34 | */
35 | package com.baasbox.android;
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/plugins/glide/BaasAssetModelLoader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.baasbox.android.plugins.glide;
19 |
20 | import android.content.Context;
21 |
22 | import com.baasbox.android.BaasAssetId;
23 | import com.bumptech.glide.load.data.DataFetcher;
24 | import com.bumptech.glide.load.model.GenericLoaderFactory;
25 | import com.bumptech.glide.load.model.ModelLoader;
26 | import com.bumptech.glide.load.model.ModelLoaderFactory;
27 |
28 | import java.io.InputStream;
29 |
30 | /**
31 | * Created by Andrea Tortorella on 08/09/14.
32 | */
33 | class BaasAssetModelLoader implements ModelLoader {
34 | @Override
35 | public DataFetcher getResourceFetcher(BaasAssetId baasAssetId, int i, int i2) {
36 | return null;
37 | }
38 |
39 | static class Factory implements ModelLoaderFactory {
40 |
41 | @Override
42 | public ModelLoader build(Context context, GenericLoaderFactory genericLoaderFactory) {
43 | return new BaasAssetModelLoader();
44 | }
45 |
46 | @Override
47 | public void teardown() {
48 |
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/plugins/glide/BaasFileModelLoader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.baasbox.android.plugins.glide;
19 |
20 | import android.content.Context;
21 |
22 | import com.baasbox.android.BaasFile;
23 | import com.bumptech.glide.load.data.DataFetcher;
24 | import com.bumptech.glide.load.model.GenericLoaderFactory;
25 | import com.bumptech.glide.load.model.ModelLoader;
26 | import com.bumptech.glide.load.model.ModelLoaderFactory;
27 |
28 | import java.io.InputStream;
29 |
30 | /**
31 | * Created by Andrea Tortorella on 08/09/14.
32 | */
33 | class BaasFileModelLoader implements ModelLoader{
34 |
35 |
36 |
37 | @Override
38 | public DataFetcher getResourceFetcher(BaasFile baasFile, int width, int height) {
39 | return new BaasImageFetcher(baasFile,width,height);
40 | }
41 |
42 | static class Factory implements ModelLoaderFactory{
43 |
44 | @Override
45 | public ModelLoader build(Context context, GenericLoaderFactory genericLoaderFactory) {
46 | return new BaasFileModelLoader();
47 | }
48 |
49 | @Override
50 | public void teardown() {
51 | //do nothing
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/plugins/glide/BaasImageFetcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.baasbox.android.plugins.glide;
19 |
20 | import com.baasbox.android.BaasAsset;
21 | import com.baasbox.android.BaasAssetId;
22 | import com.baasbox.android.BaasFile;
23 | import com.baasbox.android.BaasHandler;
24 | import com.baasbox.android.BaasResult;
25 | import com.baasbox.android.BaasStream;
26 | import com.baasbox.android.RequestToken;
27 | import com.bumptech.glide.Priority;
28 | import com.bumptech.glide.load.data.DataFetcher;
29 |
30 | import java.io.ByteArrayInputStream;
31 | import java.io.InputStream;
32 |
33 | /**
34 | *
35 | * Created by Andrea Tortorella on 08/09/14.
36 | */
37 | class BaasImageFetcher implements DataFetcher{
38 |
39 | private BaasFile file;
40 | private BaasAssetId assetId;
41 | private int width;
42 | private int height;
43 |
44 | public BaasImageFetcher(BaasAssetId assetId,int width,int height){
45 | this.assetId =assetId;
46 | this.width=width;
47 | this.height=height;
48 | }
49 |
50 | public BaasImageFetcher(BaasFile baasFile, int width, int height) {
51 | this.file=baasFile;
52 | this.width=width;
53 | this.height=height;
54 | }
55 |
56 | private String parseSpecFrom(int width,int height){
57 | return null;
58 | }
59 |
60 | @Override
61 | public InputStream loadData(Priority priority) throws Exception {
62 | if (file!=null){
63 | return file.streamImageSync(null).get();
64 | } else if (assetId!=null){
65 | return BaasAsset.streamImageAssetSync(assetId.id,parseSpecFrom(width,height)).get();
66 | }
67 | return null;
68 | }
69 |
70 | @Override
71 | public void cleanup() {
72 | // do nothing
73 | }
74 |
75 | @Override
76 | public String getId() {
77 | if (file != null) {
78 | return "bb::file::"+ file.getId() + "::" + parseSpecFrom(width, height);
79 | } else if (assetId!=null){
80 | return "bb::asset::"+assetId.id+"::"+parseSpecFrom(width,height);
81 | } else {
82 | return null;
83 | }
84 | }
85 |
86 | @Override
87 | public void cancel() {
88 | // handle cancellation
89 | }
90 |
91 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/baasbox/android/plugins/glide/GlidePlugin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.baasbox.android.plugins.glide;
19 |
20 | import android.content.Context;
21 |
22 | import com.baasbox.android.BaasAssetId;
23 | import com.baasbox.android.BaasBox;
24 | import com.baasbox.android.BaasFile;
25 | import com.baasbox.android.Plugin;
26 | import com.bumptech.glide.Glide;
27 |
28 | import java.io.InputStream;
29 |
30 | /**
31 | * Created by Andrea Tortorella on 09/09/14.
32 | */
33 | public final class GlidePlugin extends Plugin{
34 | public static final GlidePlugin PLUGIN = new GlidePlugin();
35 |
36 | private GlidePlugin(){}
37 |
38 | /**
39 | * @hide
40 | * @param context
41 | * @param box
42 | * @param empty
43 | */
44 | @Override
45 | protected void setup(Context context, BaasBox box,Options.Empty empty) {
46 | Glide glide = Glide.get(context);
47 | glide.register(BaasFile.class, InputStream.class, new BaasFileModelLoader.Factory());
48 | glide.register(BaasAssetId.class, InputStream.class, new BaasAssetModelLoader.Factory());
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-19
15 | android.library=true
16 |
--------------------------------------------------------------------------------
/samples/aloa/.gitignore:
--------------------------------------------------------------------------------
1 | build/**
2 |
--------------------------------------------------------------------------------
/samples/aloa/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 | apply plugin: 'com.android.application'
18 |
19 | repositories {
20 | jcenter()
21 | }
22 |
23 | android {
24 | compileSdkVersion 23
25 | buildToolsVersion "23.0.2"
26 |
27 | defaultConfig {
28 |
29 | applicationId "com.baasbox.android.samples.aloa"
30 | minSdkVersion 14
31 | targetSdkVersion 23
32 | versionCode 1
33 | versionName "1.0"
34 |
35 | }
36 | buildTypes {
37 | release {
38 | buildConfigField "String", "SENDERID", "\"${project.hasProperty("aloa.projectid")?project.property("aloa.projectid"):""}\""
39 | minifyEnabled false
40 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
41 | }
42 | debug{
43 | buildConfigField "String", "SENDERID", "\"${project.hasProperty("aloa.projectid")?project.property("aloa.projectid"):""}\""
44 |
45 | }
46 | }
47 | }
48 |
49 | dependencies {
50 | compile fileTree(dir: 'libs', include: ['*.jar'])
51 | compile project(':library')
52 | compile 'com.android.support:appcompat-v7:23.1.1'
53 | compile 'com.google.android.gms:play-services:8.3.0'
54 | compile 'com.android.support:support-v4:23.1.1'
55 | compile 'com.github.dmytrodanylyk.circular-progress-button:library:1.1.0'
56 | }
57 |
--------------------------------------------------------------------------------
/samples/aloa/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 /home/eto/Env/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 |
--------------------------------------------------------------------------------
/samples/aloa/src/androidTest/java/com/baasbox/android/samples/aloa/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.baasbox.android.samples.aloa;
19 |
20 | import android.app.Application;
21 | import android.test.ApplicationTestCase;
22 |
23 | /**
24 | * Testing Fundamentals
25 | */
26 | public class ApplicationTest extends ApplicationTestCase {
27 | public ApplicationTest() {
28 | super(Application.class);
29 | }
30 | }
--------------------------------------------------------------------------------
/samples/aloa/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
31 |
32 |
33 |
39 |
41 |
42 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
55 |
56 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/samples/aloa/src/main/java/com/baasbox/android/samples/aloa/Aloa.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.baasbox.android.samples.aloa;
19 |
20 | import android.app.Application;
21 |
22 | import com.baasbox.android.BaasBox;
23 |
24 | /**
25 | * Created by Andrea Tortorella on 11/08/14.
26 | */
27 | public class Aloa extends Application {
28 | private BaasBox baasBox;
29 | private static Aloa self;
30 |
31 | @Override
32 | public void onCreate() {
33 | super.onCreate();
34 | baasBox = BaasBox.builder(this)
35 | .setAppCode(Configuration.APPCODE)
36 | .setApiDomain(Configuration.API_DOMAIN)
37 | .setPort(Configuration.PORT)
38 | .setPushSenderId(Configuration.GCM_SENDER_ID)
39 | .init();
40 | self = this;
41 | }
42 |
43 | public static final Aloa app(){
44 | return self;
45 | }
46 |
47 | public static final BaasBox box(){
48 | return self.baasBox;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/samples/aloa/src/main/java/com/baasbox/android/samples/aloa/Configuration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.baasbox.android.samples.aloa;
19 |
20 | /**
21 | * Created by Andrea Tortorella on 11/08/14.
22 | */
23 | public final class Configuration {
24 |
25 | private Configuration(){}
26 |
27 | public static final String GCM_SENDER_ID = BuildConfig.SENDERID; // replace with your own sender id
28 |
29 | public static final String APPCODE = "1234567890";
30 |
31 | public static final String API_DOMAIN = "192.168.56.1";
32 |
33 | public static final int PORT = 9000;
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/samples/aloa/src/main/java/com/baasbox/android/samples/aloa/Data.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.baasbox.android.samples.aloa;
19 |
20 | /**
21 | * Created by Andrea Tortorella on 11/08/14.
22 | */
23 | public class Data {
24 |
25 | public static final String FLOWERS = "flower";
26 | }
27 |
--------------------------------------------------------------------------------
/samples/aloa/src/main/java/com/baasbox/android/samples/aloa/activities/CreateChannelFragment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.baasbox.android.samples.aloa.activities;
19 |
20 | import android.app.Activity;
21 | import android.app.AlertDialog;
22 | import android.app.Dialog;
23 | import android.content.DialogInterface;
24 | import android.os.Bundle;
25 | import android.support.v4.app.DialogFragment;
26 | import android.support.v4.app.FragmentManager;
27 | import android.text.TextUtils;
28 | import android.widget.EditText;
29 |
30 | import com.baasbox.android.samples.aloa.R;
31 |
32 | /**
33 | * Created by Andrea Tortorella on 12/08/14.
34 | */
35 | public class CreateChannelFragment extends DialogFragment {
36 |
37 | private OnTargetSelectedListener listener;
38 |
39 | public static CreateChannelFragment show(FragmentManager manager){
40 | CreateChannelFragment ccf = new CreateChannelFragment();
41 | ccf.show(manager,"CREATE_CHANNEL_DIALOG");
42 | return ccf;
43 | }
44 |
45 | @Override
46 | public void onAttach(Activity activity) {
47 | super.onAttach(activity);
48 | listener = (OnTargetSelectedListener)activity;
49 | }
50 |
51 | @Override
52 | public Dialog onCreateDialog(Bundle savedInstanceState) {
53 | AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
54 | final EditText input = new EditText(getActivity());
55 | builder.setTitle(getString(R.string.create_channel));
56 | builder.setMessage(getString(R.string.create_channel_message));
57 | builder.setView(input);
58 | final DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() {
59 | @Override
60 | public void onClick(DialogInterface dialog, int which) {
61 | if (which==DialogInterface.BUTTON_POSITIVE){
62 | String ch = input.getText().toString();
63 | if (listener!=null&& !TextUtils.isEmpty(ch)){
64 | listener.onTargetSelected(ch,true);
65 | }
66 | }
67 | }
68 | };
69 | builder.setPositiveButton(android.R.string.ok,clickListener);
70 | builder.setNegativeButton(android.R.string.cancel,clickListener);
71 | return builder.create();
72 | }
73 |
74 | @Override
75 | public void onDetach() {
76 | super.onDetach();
77 | listener=null;
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/samples/aloa/src/main/java/com/baasbox/android/samples/aloa/activities/OnTargetSelectedListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.baasbox.android.samples.aloa.activities;
19 |
20 | /**
21 | * This interface must be implemented by activities that contain this
22 | * fragment to allow an interaction in this fragment to be communicated
23 | * to the activity and potentially other fragments contained in that
24 | * activity.
25 | *
26 | * See the Android Training lesson Communicating with Other Fragments for more information.
29 | */
30 | public interface OnTargetSelectedListener {
31 | public void onTargetSelected(String id, boolean isChannel);
32 | }
33 |
--------------------------------------------------------------------------------
/samples/aloa/src/main/java/com/baasbox/android/samples/aloa/activities/loaders/BaasUsersLoader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.baasbox.android.samples.aloa.activities.loaders;
19 |
20 | import android.content.Context;
21 |
22 | import com.baasbox.android.BaasHandler;
23 | import com.baasbox.android.BaasQuery;
24 | import com.baasbox.android.BaasUser;
25 | import com.baasbox.android.RequestOptions;
26 | import com.baasbox.android.RequestToken;
27 | import com.baasbox.android.samples.aloa.utils.BaseBaasLoader;
28 |
29 | import java.util.List;
30 |
31 | /**
32 | * Created by Andrea Tortorella on 11/08/14.
33 | */
34 | public class BaasUsersLoader extends BaseBaasLoader> {
35 | private final BaasQuery.Criteria criteria;
36 | private final int flags;
37 |
38 | public BaasUsersLoader(Context context,BaasQuery.Criteria criteria,int flags) {
39 | super(context);
40 | this.criteria = criteria;
41 | this.flags=flags;
42 | }
43 |
44 | public BaasUsersLoader(Context context,BaasQuery.Criteria criteria) {
45 | this(context, criteria, RequestOptions.DEFAULT);
46 | }
47 |
48 | public BaasUsersLoader(Context context) {
49 | this(context, null, RequestOptions.DEFAULT);
50 | }
51 |
52 | @Override
53 | protected RequestToken load(BaasHandler> handler) {
54 | return BaasUser.fetchAll(criteria,flags,handler);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/samples/aloa/src/main/java/com/baasbox/android/samples/aloa/activities/loaders/ChannelsLoader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.baasbox.android.samples.aloa.activities.loaders;
19 |
20 | import android.content.Context;
21 |
22 | import com.baasbox.android.BaasHandler;
23 | import com.baasbox.android.BaasResult;
24 | import com.baasbox.android.RequestOptions;
25 | import com.baasbox.android.RequestToken;
26 | import com.baasbox.android.json.JsonArray;
27 | import com.baasbox.android.json.JsonObject;
28 | import com.baasbox.android.net.HttpRequest;
29 | import com.baasbox.android.samples.aloa.Aloa;
30 | import com.baasbox.android.samples.aloa.utils.BaasLoader;
31 |
32 | import java.util.ArrayList;
33 | import java.util.List;
34 |
35 | /**
36 | * Created by Andrea Tortorella on 11/08/14.
37 | */
38 | public class ChannelsLoader extends BaasLoader> {
39 | public ChannelsLoader(Context context) {
40 | super(context);
41 | }
42 |
43 | @Override
44 | protected BaasResult> remapResult(BaasResult result) {
45 | if (result.isFailed()){
46 | return BaasResult.failure(result.error());
47 | } else {
48 | JsonObject value = result.value();
49 | JsonArray channels = value.getObject("data").getArray("channels");
50 | List chs = new ArrayList();
51 | for (Object ch:channels){
52 | chs.add(ch.toString());
53 | }
54 | return BaasResult.success(chs);
55 | }
56 | }
57 |
58 |
59 | @Override
60 | protected RequestToken load(BaasHandler handler) {
61 | return Aloa.box().rest(HttpRequest.GET,"scripts/channels",(JsonObject)null,true,handler);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/samples/aloa/src/main/java/com/baasbox/android/samples/aloa/receive/PushReceiver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.baasbox.android.samples.aloa.receive;
19 |
20 | import android.content.BroadcastReceiver;
21 | import android.content.Context;
22 | import android.content.Intent;
23 | import android.os.Bundle;
24 | import android.os.PowerManager;
25 |
26 | import com.google.android.gms.gcm.GoogleCloudMessaging;
27 |
28 | /**
29 | * Created by Andrea Tortorella on 12/08/14.
30 | */
31 | public class PushReceiver extends BroadcastReceiver{
32 | public static final String WAKELOCK_TAG = "WAKE_FOR_GCM";
33 |
34 | private PowerManager.WakeLock acquireLock(Context context){
35 | PowerManager manager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
36 | PowerManager.WakeLock wakeLock = manager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKELOCK_TAG);
37 | wakeLock.acquire();
38 | return wakeLock;
39 | }
40 |
41 | @Override
42 | public void onReceive(Context context, Intent intent) {
43 | PowerManager.WakeLock wl = acquireLock(context);
44 | try {
45 |
46 | GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
47 | String message = gcm.getMessageType(intent);
48 | if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(message)) {
49 | Bundle extras = intent.getExtras();
50 | String messageText = extras.getString("message", "no message");
51 | NewMessageNotification.notify(context, messageText, 1);
52 | }
53 | } finally {
54 | wl.release();
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/samples/aloa/src/main/java/com/baasbox/android/samples/aloa/utils/BaasLoader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.baasbox.android.samples.aloa.utils;
19 |
20 | import android.content.Context;
21 | import android.support.v4.content.Loader;
22 |
23 | import com.baasbox.android.BaasHandler;
24 | import com.baasbox.android.BaasResult;
25 | import com.baasbox.android.RequestToken;
26 |
27 | /**
28 | * Created by Andrea Tortorella on 11/08/14.
29 | */
30 | public abstract class BaasLoader extends Loader> {
31 |
32 | private RequestToken mCurrentLoad;
33 | private BaasResult mResult;
34 |
35 | private final BaasHandler mHandler = new BaasHandler() {
36 | @Override
37 | public void handle(BaasResult result) {
38 | complete(result);
39 | }
40 | };
41 |
42 | public BaasLoader(Context context) {
43 | super(context);
44 | }
45 |
46 | private void complete(BaasResult result) {
47 | mCurrentLoad = null;
48 | mResult = result;
49 | if (isStarted()){
50 | deliverResult(remapResult(result));
51 | }
52 | }
53 |
54 | protected abstract BaasResult remapResult(BaasResult result);
55 |
56 |
57 | @Override
58 | protected void onForceLoad() {
59 | super.onForceLoad();
60 | if (mCurrentLoad!=null){
61 | mCurrentLoad.abort();
62 | }
63 | mCurrentLoad = load(mHandler);
64 | }
65 |
66 | protected abstract RequestToken load(BaasHandler handler);
67 |
68 | @Override
69 | protected void onReset() {
70 | super.onReset();
71 | if (mCurrentLoad!=null){
72 | mCurrentLoad.abort();
73 | }
74 | mResult = null;
75 | mCurrentLoad = null;
76 | }
77 |
78 | @Override
79 | protected void onStartLoading() {
80 | super.onStartLoading();
81 | if (mResult != null){
82 | deliverResult(remapResult(mResult));
83 | } else if (takeContentChanged()||mResult == null){
84 | forceLoad();
85 | }
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/samples/aloa/src/main/java/com/baasbox/android/samples/aloa/utils/BaseActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.baasbox.android.samples.aloa.utils;
19 |
20 | import android.support.v7.app.ActionBarActivity;
21 |
22 | /**
23 | * Created by Andrea Tortorella on 11/08/14.
24 | */
25 | public class BaseActivity extends ActionBarActivity {
26 | }
27 |
--------------------------------------------------------------------------------
/samples/aloa/src/main/java/com/baasbox/android/samples/aloa/utils/BaseBaasLoader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.baasbox.android.samples.aloa.utils;
19 |
20 | import android.content.Context;
21 |
22 | import com.baasbox.android.BaasHandler;
23 | import com.baasbox.android.BaasResult;
24 | import com.baasbox.android.RequestToken;
25 |
26 | /**
27 | * Created by Andrea Tortorella on 11/08/14.
28 | */
29 | public abstract class BaseBaasLoader extends BaasLoader{
30 |
31 | public BaseBaasLoader(Context context) {
32 | super(context);
33 | }
34 |
35 | @Override
36 | protected final BaasResult remapResult(BaasResult result) {
37 | return result;
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/samples/aloa/src/main/java/com/baasbox/android/samples/aloa/utils/BaseFragment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.baasbox.android.samples.aloa.utils;
19 |
20 | import android.support.v4.app.Fragment;
21 |
22 | /**
23 | * Created by Andrea Tortorella on 11/08/14.
24 | */
25 | public class BaseFragment extends Fragment {
26 | }
27 |
--------------------------------------------------------------------------------
/samples/aloa/src/main/res/drawable-hdpi-v11/ic_stat_new_message.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/aloa/src/main/res/drawable-hdpi-v11/ic_stat_new_message.png
--------------------------------------------------------------------------------
/samples/aloa/src/main/res/drawable-hdpi-v9/ic_stat_new_message.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/aloa/src/main/res/drawable-hdpi-v9/ic_stat_new_message.png
--------------------------------------------------------------------------------
/samples/aloa/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/aloa/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/samples/aloa/src/main/res/drawable-hdpi/ic_stat_new_message.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/aloa/src/main/res/drawable-hdpi/ic_stat_new_message.png
--------------------------------------------------------------------------------
/samples/aloa/src/main/res/drawable-mdpi-v11/ic_stat_new_message.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/aloa/src/main/res/drawable-mdpi-v11/ic_stat_new_message.png
--------------------------------------------------------------------------------
/samples/aloa/src/main/res/drawable-mdpi-v9/ic_stat_new_message.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/aloa/src/main/res/drawable-mdpi-v9/ic_stat_new_message.png
--------------------------------------------------------------------------------
/samples/aloa/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/aloa/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/samples/aloa/src/main/res/drawable-mdpi/ic_stat_new_message.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/aloa/src/main/res/drawable-mdpi/ic_stat_new_message.png
--------------------------------------------------------------------------------
/samples/aloa/src/main/res/drawable-nodpi/example_picture.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/aloa/src/main/res/drawable-nodpi/example_picture.png
--------------------------------------------------------------------------------
/samples/aloa/src/main/res/drawable-xhdpi-v11/ic_stat_new_message.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/aloa/src/main/res/drawable-xhdpi-v11/ic_stat_new_message.png
--------------------------------------------------------------------------------
/samples/aloa/src/main/res/drawable-xhdpi-v9/ic_stat_new_message.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/aloa/src/main/res/drawable-xhdpi-v9/ic_stat_new_message.png
--------------------------------------------------------------------------------
/samples/aloa/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/aloa/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/samples/aloa/src/main/res/drawable-xhdpi/ic_stat_new_message.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/aloa/src/main/res/drawable-xhdpi/ic_stat_new_message.png
--------------------------------------------------------------------------------
/samples/aloa/src/main/res/drawable-xxhdpi-v11/ic_stat_new_message.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/aloa/src/main/res/drawable-xxhdpi-v11/ic_stat_new_message.png
--------------------------------------------------------------------------------
/samples/aloa/src/main/res/drawable-xxhdpi-v9/ic_stat_new_message.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/aloa/src/main/res/drawable-xxhdpi-v9/ic_stat_new_message.png
--------------------------------------------------------------------------------
/samples/aloa/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/aloa/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/samples/aloa/src/main/res/drawable-xxhdpi/ic_stat_new_message.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/aloa/src/main/res/drawable-xxhdpi/ic_stat_new_message.png
--------------------------------------------------------------------------------
/samples/aloa/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
28 |
34 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/samples/aloa/src/main/res/layout/fragment_sendtarget_grid.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
19 |
24 |
25 |
30 |
31 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/samples/aloa/src/main/res/layout/fragment_sendtarget_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
19 |
24 |
25 |
29 |
30 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/samples/aloa/src/main/res/layout/fragment_user_status.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
19 |
20 |
24 |
28 |
35 |
--------------------------------------------------------------------------------
/samples/aloa/src/main/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
36 |
--------------------------------------------------------------------------------
/samples/aloa/src/main/res/values-large/refs.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 |
20 |
27 | - @layout/fragment_sendtarget_grid
28 |
29 |
--------------------------------------------------------------------------------
/samples/aloa/src/main/res/values-sw600dp/refs.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 |
20 |
27 | - @layout/fragment_sendtarget_grid
28 |
29 |
--------------------------------------------------------------------------------
/samples/aloa/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 |
22 | 64dp
23 |
24 |
--------------------------------------------------------------------------------
/samples/aloa/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 |
20 | 16dp
21 | 16dp
22 |
23 |
--------------------------------------------------------------------------------
/samples/aloa/src/main/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/samples/aloa/src/main/res/values/refs.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 |
20 |
27 | - @layout/fragment_sendtarget_list
28 |
29 |
--------------------------------------------------------------------------------
/samples/aloa/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
19 |
20 | Aloa
21 | Hello world!
22 | Settings
23 | Status
24 | Users
25 | Channels
26 | Create Channel
27 | Create a new channel
28 | New message: %1$s
29 | You said %1$s and lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam non enim magna. Morbi dictum, velit vel semper venenatis, magna odio volutpat velit, at ullamcorper nulla lacus sed turpis. Pellentesque vitae metus elit, nec tincidunt tellus. Integer sed nisl sem, ullamcorper ornare lacus. Duis ac mauris sed massa congue volutpat. Donec sed erat sit amet turpis viverra rhoncus sit amet nec magna. Donec lacinia ligula at libero volutpat volutpat nec nec tortor.
30 |
31 |
32 |
--------------------------------------------------------------------------------
/samples/aloa/src/main/res/values/strings_activity_login.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 | Sign in
20 |
21 |
22 | Email
23 | Password
24 | Sign in
25 |
26 | Register
27 | @string/action_sign_in
28 |
29 | This email address is invalid
30 | This password is too short
31 | This password is incorrect
32 | This field is required
33 | Your favourite flower
34 | Or create an account:
35 |
36 |
--------------------------------------------------------------------------------
/samples/aloa/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 |
20 |
21 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/samples/phrasebook/.gitignore:
--------------------------------------------------------------------------------
1 | build/**
2 |
--------------------------------------------------------------------------------
/samples/phrasebook/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 | apply plugin: 'com.android.application'
18 |
19 | repositories {
20 | jcenter()
21 | }
22 |
23 | android {
24 | compileSdkVersion 23
25 | buildToolsVersion "23.0.2"
26 |
27 | defaultConfig {
28 |
29 | applicationId "com.baasbox.android.samples.phrasebook"
30 | minSdkVersion 14
31 | targetSdkVersion 23
32 | versionCode 1
33 | versionName "1.0"
34 |
35 | }
36 | buildTypes {
37 | release {
38 | // buildConfigField "String", "SENDERID", "\"${project.hasProperty("aloa.projectid")?project.property("aloa.projectid"):""}\""
39 | minifyEnabled false
40 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
41 | }
42 | debug{
43 | // buildConfigField "String", "SENDERID", "\"${project.hasProperty("aloa.projectid")?project.property("aloa.projectid"):""}\""
44 |
45 | }
46 | }
47 | }
48 |
49 |
50 | dependencies {
51 | compile fileTree(dir: 'libs', include: ['*.jar'])
52 | compile project(':library')
53 | compile 'com.google.android.gms:play-services:8.3.0'
54 | compile 'com.android.support:support-v4:23.1.1'
55 | compile 'com.github.dmytrodanylyk.circular-progress-button:library:1.1.0'
56 | compile 'com.github.bumptech.glide:glide:3.3.+'
57 | }
58 |
--------------------------------------------------------------------------------
/samples/phrasebook/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 /home/eto/Env/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 |
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
20 |
21 |
22 |
23 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/java/com/baasbox/android/samples/phrasebook/Configuration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.baasbox.android.samples.phrasebook;
19 |
20 | /**
21 | * Created by Andrea Tortorella on 11/08/14.
22 | */
23 | public final class Configuration {
24 |
25 | private Configuration(){}
26 |
27 | public static final String APPCODE = "1234567890";
28 |
29 | public static final String API_DOMAIN = "192.168.56.1";
30 |
31 | public static final int PORT = 9000;
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/java/com/baasbox/android/samples/phrasebook/Phrasebook.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.baasbox.android.samples.phrasebook;
19 |
20 | import android.app.Application;
21 | import android.widget.ImageView;
22 |
23 | import com.baasbox.android.BaasAssetId;
24 | import com.baasbox.android.BaasBox;
25 | import com.baasbox.android.BaasFile;
26 | import com.baasbox.android.plugins.glide.GlidePlugin;
27 | import com.bumptech.glide.Glide;
28 |
29 | /**
30 | * Created by Andrea Tortorella on 08/09/14.
31 | */
32 | public class Phrasebook extends Application {
33 | private static Phrasebook self;
34 |
35 | private BaasBox baasBox;
36 |
37 | @Override
38 | public void onCreate() {
39 | super.onCreate();
40 | baasBox = BaasBox.builder(this)
41 | .setApiDomain(Configuration.API_DOMAIN)
42 | .setPort(Configuration.PORT)
43 | .setAppCode(Configuration.APPCODE)
44 | .addPlugin(GlidePlugin.PLUGIN)
45 | .init();
46 | self = this;
47 | Glide.with(this).load(BaasAssetId.create("asset")).into(new ImageView(this));
48 | }
49 |
50 | public static Phrasebook app(){
51 | return self;
52 | }
53 |
54 | public BaasBox box(){
55 | return baasBox;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/java/com/baasbox/android/samples/phrasebook/ServerContract.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.baasbox.android.samples.phrasebook;
19 |
20 | import com.baasbox.android.BaasQuery;
21 |
22 | import java.util.Random;
23 |
24 | /**
25 | * Created by Andrea Tortorella on 09/09/14.
26 | */
27 | public final class ServerContract {
28 | private ServerContract(){throw new AssertionError("not instantiable");}
29 |
30 | public static final class Phrases {
31 | private Phrases(){throw new AssertionError("not instantiable");}
32 |
33 | public static final String COLLECTION = "phrases";
34 |
35 | public static final String PHRASE = "phrase";
36 |
37 | public static BaasQuery.Criteria random(int count){
38 |
39 | return BaasQuery.builder().skip(count).pagination(0, 1).criteria();
40 | }
41 |
42 | }
43 |
44 | public static final class Comments {
45 | private Comments(){throw new AssertionError("not instantiable");}
46 |
47 | public static final String COLLECTION = "comments";
48 |
49 | public static final String TEXT = "text";
50 | public static final String RATING = "rating";
51 | }
52 |
53 |
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/java/com/baasbox/android/samples/phrasebook/common/BaseActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.baasbox.android.samples.phrasebook.common;
19 |
20 | import android.app.Activity;
21 |
22 | /**
23 | * Created by Andrea Tortorella on 08/09/14.
24 | */
25 | public class BaseActivity extends Activity {
26 | }
27 |
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/java/com/baasbox/android/samples/phrasebook/common/BaseFragment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.baasbox.android.samples.phrasebook.common;
19 |
20 |
21 | import android.app.Fragment;
22 |
23 | /**
24 | * Created by Andrea Tortorella on 08/09/14.
25 | */
26 | public class BaseFragment extends Fragment {
27 | }
28 |
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/java/com/baasbox/android/samples/phrasebook/ui/HomeActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.baasbox.android.samples.phrasebook.ui;
19 |
20 | import android.os.Bundle;
21 |
22 | import com.baasbox.android.samples.phrasebook.R;
23 | import com.baasbox.android.samples.phrasebook.common.BaseActivity;
24 |
25 | /**
26 | * Created by Andrea Tortorella on 08/09/14.
27 | */
28 | public class HomeActivity extends BaseActivity {
29 | public static final String PHRASE_OF_THE_DAY_TAG = "phrase_of_the_day_tag";
30 |
31 | @Override
32 | protected void onCreate(Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 | setContentView(R.layout.activity_home);
35 | if (savedInstanceState == null) {
36 | getFragmentManager().beginTransaction()
37 | .add(R.id.frame_container, new PhraseOfTheDay(), PHRASE_OF_THE_DAY_TAG)
38 | .commit();
39 | }
40 |
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/java/com/baasbox/android/samples/phrasebook/ui/PhraseOfTheDay.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.baasbox.android.samples.phrasebook.ui;
19 |
20 | import android.app.LoaderManager;
21 | import android.content.Loader;
22 | import android.os.Bundle;
23 | import android.support.annotation.Nullable;
24 | import android.view.LayoutInflater;
25 | import android.view.View;
26 | import android.view.ViewGroup;
27 | import android.widget.Button;
28 | import android.widget.EditText;
29 | import android.widget.ImageView;
30 | import android.widget.RatingBar;
31 | import android.widget.TextView;
32 |
33 | import com.baasbox.android.BaasDocument;
34 | import com.baasbox.android.BaasFile;
35 | import com.baasbox.android.BaasQuery;
36 | import com.baasbox.android.BaasResult;
37 | import com.baasbox.android.samples.phrasebook.R;
38 | import com.baasbox.android.samples.phrasebook.common.BaseFragment;
39 | import com.baasbox.android.samples.phrasebook.loaders.BaasDocumentsLoader;
40 | import com.bumptech.glide.Glide;
41 |
42 | import java.util.List;
43 |
44 | /**
45 | * Created by Andrea Tortorella on 08/09/14.
46 | */
47 | public class PhraseOfTheDay extends BaseFragment {
48 |
49 | private TextView phraseOfTheDay;
50 | private EditText comment;
51 | private RatingBar rating;
52 | private View submitComment;
53 |
54 | @Override
55 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
56 | View view = inflater.inflate(R.layout.fragment_phrase_of_the_day,container,false);
57 | phraseOfTheDay =(TextView)view.findViewById(R.id.tv_phrase_of_the_day);
58 | comment = (EditText) view.findViewById(R.id.in_comment);
59 | rating = (RatingBar) view.findViewById(R.id.rating_comment);
60 | submitComment = view.findViewById(R.id.btn_submit_comment);
61 | return view;
62 | }
63 |
64 | @Override
65 | public void onActivityCreated(Bundle savedInstanceState) {
66 | super.onActivityCreated(savedInstanceState);
67 | getLoaderManager().initLoader(0,null,new LoaderManager.LoaderCallbacks>>() {
68 | @Override
69 | public Loader>> onCreateLoader(int id, Bundle args) {
70 | return new BaasDocumentsLoader(getActivity(),"collection", BaasQuery.builder().where("x = x").and("y = 2").criteria());
71 | }
72 |
73 | @Override
74 | public void onLoadFinished(Loader>> loader, BaasResult> data) {
75 |
76 | }
77 |
78 | @Override
79 | public void onLoaderReset(Loader>> loader) {
80 |
81 | }
82 | });
83 | }
84 |
85 | private void loadImage(BaasFile file){
86 | Glide.with(this).load(file).into(new ImageView(getActivity()));
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/java/com/baasbox/android/samples/phrasebook/utils/ThreadLocalRandom.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | package com.baasbox.android.samples.phrasebook.utils;
19 |
20 | import java.util.Random;
21 |
22 | /**
23 | * Created by Andrea Tortorella on 09/09/14.
24 | */
25 | public class ThreadLocalRandom extends Random {
26 |
27 | private static final long MULTIPLIER = 0x5DEECE66DL;
28 | private static final long ADDEND = 0xBL;
29 | private static final long MASK = (1L << 48) -1;
30 |
31 | private long rnd;
32 |
33 | boolean initialized;
34 |
35 | private long pad0,pad1,pad2,pad3,pad4,pad5,pad6,pad7;
36 |
37 | private static final ThreadLocal LOCAL_RANDOM =
38 | new ThreadLocal() {
39 | @Override
40 | protected ThreadLocalRandom initialValue() {
41 | return new ThreadLocalRandom();
42 | }
43 | };
44 |
45 | ThreadLocalRandom(){
46 | super();
47 | initialized = true;
48 | }
49 |
50 | public static ThreadLocalRandom current(){
51 | return LOCAL_RANDOM.get();
52 | }
53 |
54 | public void setSeed(long seed) {
55 | if (initialized){
56 | throw new UnsupportedOperationException();
57 | }
58 | rnd = (seed ^ MULTIPLIER) & MASK;
59 | }
60 |
61 | protected int next(int bits) {
62 | rnd = (rnd * MULTIPLIER + ADDEND)& MASK;
63 | return (int) (rnd >>> (48-bits));
64 | }
65 |
66 | public int nextInt(int least,int bound) {
67 | if (least >= bound){
68 | throw new IllegalArgumentException();
69 | }
70 | return nextInt(bound-least)+least;
71 | }
72 |
73 | public long nextLong(long n) {
74 | if (n <= 0) {
75 | throw new IllegalArgumentException("n must be positive");
76 | }
77 | long offset = 0;
78 | while (n >= Integer.MAX_VALUE) {
79 | int bits = next(2);
80 | long half = n >>> 1;
81 | long nextn = ((bits & 2) == 0) ? half : n-half;
82 | if ((bits & 1) == 0) {
83 | offset += n -nextn;
84 | }
85 | n = nextn;
86 | }
87 | return offset + nextInt((int)n);
88 | }
89 |
90 | public long nextLong(long least,long bound){
91 | if (least >= bound){
92 | throw new IllegalArgumentException();
93 | }
94 | return nextLong((bound-least)) + least;
95 | }
96 |
97 | public double nextDouble(double n) {
98 | if (n <= 0) {
99 | throw new IllegalArgumentException("n must be positive");
100 | }
101 | return nextDouble()*n;
102 | }
103 |
104 | public double nextDouble(double least,double bound) {
105 | if (least>=bound){
106 | throw new IllegalArgumentException();
107 | }
108 | return nextDouble()*(bound-least)+least;
109 | }
110 |
111 | private static final long serialVersionUID = -5851777807851030925L;
112 | }
113 |
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/res/drawable-hdpi/ic_empty_star.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/phrasebook/src/main/res/drawable-hdpi/ic_empty_star.png
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/res/drawable-hdpi/ic_full_star.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/phrasebook/src/main/res/drawable-hdpi/ic_full_star.png
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/res/drawable-hdpi/ic_half_star.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/phrasebook/src/main/res/drawable-hdpi/ic_half_star.png
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/phrasebook/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/res/drawable-hdpi/ic_send.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/phrasebook/src/main/res/drawable-hdpi/ic_send.png
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/res/drawable-mdpi/ic_empty_star.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/phrasebook/src/main/res/drawable-mdpi/ic_empty_star.png
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/res/drawable-mdpi/ic_full_star.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/phrasebook/src/main/res/drawable-mdpi/ic_full_star.png
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/res/drawable-mdpi/ic_half_star.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/phrasebook/src/main/res/drawable-mdpi/ic_half_star.png
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/phrasebook/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/res/drawable-mdpi/ic_send.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/phrasebook/src/main/res/drawable-mdpi/ic_send.png
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/res/drawable-xhdpi/ic_empty_star.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/phrasebook/src/main/res/drawable-xhdpi/ic_empty_star.png
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/res/drawable-xhdpi/ic_full_star.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/phrasebook/src/main/res/drawable-xhdpi/ic_full_star.png
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/res/drawable-xhdpi/ic_half_star.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/phrasebook/src/main/res/drawable-xhdpi/ic_half_star.png
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/phrasebook/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/res/drawable-xhdpi/ic_send.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/phrasebook/src/main/res/drawable-xhdpi/ic_send.png
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/res/drawable-xxhdpi/ic_empty_star.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/phrasebook/src/main/res/drawable-xxhdpi/ic_empty_star.png
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/res/drawable-xxhdpi/ic_full_star.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/phrasebook/src/main/res/drawable-xxhdpi/ic_full_star.png
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/res/drawable-xxhdpi/ic_half_star.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/phrasebook/src/main/res/drawable-xxhdpi/ic_half_star.png
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/phrasebook/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/res/drawable-xxhdpi/ic_send.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/baasbox/Android-SDK/6bb2203246b885b2ad63a7bfaf37c83caf15e0d8/samples/phrasebook/src/main/res/drawable-xxhdpi/ic_send.png
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/res/drawable/colorized_rating_bar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
19 |
20 |
21 |
23 |
25 |
27 |
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/res/layout/activity_home.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
19 |
20 |
26 |
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/res/layout/fragment_phrase_of_the_day.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
19 |
20 |
28 |
37 |
42 |
44 |
45 |
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/res/layout/include_submit_comment.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
19 |
23 |
26 |
27 |
34 |
45 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
19 |
20 | 16dp
21 | 16dp
22 | 48dp
23 |
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
19 |
20 | Phrasebook
21 |
--------------------------------------------------------------------------------
/samples/phrasebook/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
19 |
20 |
23 |
24 |
27 |
--------------------------------------------------------------------------------
/samples/social/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 | apply plugin: 'com.android.application'
18 |
19 | repositories {
20 | jcenter()
21 | }
22 |
23 | android {
24 | compileSdkVersion 23
25 | buildToolsVersion "23.0.2"
26 |
27 | defaultConfig {
28 |
29 | applicationId "com.baasbox.android.samples.phrasebook"
30 | minSdkVersion 14
31 | targetSdkVersion 23
32 | versionCode 1
33 | versionName "1.0"
34 |
35 | }
36 | buildTypes {
37 | release {
38 | minifyEnabled false
39 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
40 | }
41 | debug{
42 |
43 | }
44 | }
45 | }
46 |
47 |
48 | dependencies {
49 | compile fileTree(dir: 'libs', include: ['*.jar'])
50 | compile project(':library')
51 | }
52 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014.
3 | *
4 | * BaasBox - info@baasbox.com
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and limitations under the License.
16 | */
17 |
18 | include ':library', ':samples:aloa', ':samples:phrasebook', ':samples/social'
--------------------------------------------------------------------------------