();
25 |
26 | RxAndroidPlugins() {
27 | }
28 |
29 | /**
30 | * Reset any explicit or default-set hooks.
31 | *
32 | * Note: This should only be used for testing purposes.
33 | */
34 | @Beta
35 | public void reset() {
36 | schedulersHook.set(null);
37 | }
38 |
39 | /**
40 | * Retrieves the instance of {@link RxAndroidSchedulersHook} to use based on order of
41 | * precedence as defined in the {@link RxAndroidPlugins} class header.
42 | *
43 | * Override the default by calling {@link #registerSchedulersHook(RxAndroidSchedulersHook)} or by
44 | * setting the property {@code rxandroid.plugin.RxAndroidSchedulersHook.implementation} with the
45 | * full classname to load.
46 | */
47 | public RxAndroidSchedulersHook getSchedulersHook() {
48 | if (schedulersHook.get() == null) {
49 | schedulersHook.compareAndSet(null, RxAndroidSchedulersHook.getDefaultInstance());
50 | // We don't return from here but call get() again in case of thread-race so the winner will
51 | // always get returned.
52 | }
53 | return schedulersHook.get();
54 | }
55 |
56 | /**
57 | * Registers an {@link RxAndroidSchedulersHook} implementation as a global override of any
58 | * injected or default implementations.
59 | *
60 | * @throws IllegalStateException if called more than once or after the default was initialized
61 | * (if usage occurs before trying to register)
62 | */
63 | public void registerSchedulersHook(RxAndroidSchedulersHook impl) {
64 | if (!schedulersHook.compareAndSet(null, impl)) {
65 | throw new IllegalStateException(
66 | "Another strategy was already registered: " + schedulersHook.get());
67 | }
68 | }
69 | }
--------------------------------------------------------------------------------
/src/com/activeandroid/rxschedulers/RxAndroidSchedulersHook.java:
--------------------------------------------------------------------------------
1 | package com.activeandroid.rxschedulers;
2 |
3 | import rx.Scheduler;
4 | import rx.functions.Action0;
5 |
6 | public class RxAndroidSchedulersHook {
7 | private static final RxAndroidSchedulersHook DEFAULT_INSTANCE = new RxAndroidSchedulersHook();
8 |
9 | public static RxAndroidSchedulersHook getDefaultInstance() {
10 | return DEFAULT_INSTANCE;
11 | }
12 |
13 | /**
14 | * Scheduler to return from {@link AndroidSchedulers#mainThread()} or {@code null} if default
15 | * should be used.
16 | *
17 | * This instance should be or behave like a stateless singleton.
18 | */
19 | public Scheduler getMainThreadScheduler() {
20 | return null;
21 | }
22 |
23 | /**
24 | * Invoked before the Action is handed over to the scheduler. Can be used for
25 | * wrapping/decorating/logging. The default is just a passthrough.
26 | *
27 | * @param action action to schedule
28 | * @return wrapped action to schedule
29 | */
30 | public Action0 onSchedule(Action0 action) {
31 | return action;
32 | }
33 | }
--------------------------------------------------------------------------------
/src/com/activeandroid/serializer/BigDecimalSerializer.java:
--------------------------------------------------------------------------------
1 | package com.activeandroid.serializer;
2 |
3 | import java.math.BigDecimal;
4 |
5 | public final class BigDecimalSerializer extends TypeSerializer {
6 | public Class> getDeserializedType() {
7 | return BigDecimal.class;
8 | }
9 |
10 | public Class> getSerializedType() {
11 | return String.class;
12 | }
13 |
14 | public String serialize(Object data) {
15 | if (data == null) {
16 | return null;
17 | }
18 |
19 | return ((BigDecimal) data).toString();
20 | }
21 |
22 | public BigDecimal deserialize(Object data) {
23 | if (data == null) {
24 | return null;
25 | }
26 |
27 | return new BigDecimal((String) data);
28 | }
29 | }
--------------------------------------------------------------------------------
/src/com/activeandroid/serializer/CalendarSerializer.java:
--------------------------------------------------------------------------------
1 | package com.activeandroid.serializer;
2 |
3 | /*
4 | * Copyright (C) 2010 Michael Pardo
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
16 | * limitations under the License.
17 | */
18 |
19 | import java.util.Calendar;
20 |
21 | public final class CalendarSerializer extends TypeSerializer {
22 | public Class> getDeserializedType() {
23 | return Calendar.class;
24 | }
25 |
26 | public Class> getSerializedType() {
27 | return long.class;
28 | }
29 |
30 | public Long serialize(Object data) {
31 | return ((Calendar) data).getTimeInMillis();
32 | }
33 |
34 | public Calendar deserialize(Object data) {
35 | Calendar calendar = Calendar.getInstance();
36 | calendar.setTimeInMillis((Long) data);
37 |
38 | return calendar;
39 | }
40 | }
--------------------------------------------------------------------------------
/src/com/activeandroid/serializer/FileSerializer.java:
--------------------------------------------------------------------------------
1 | package com.activeandroid.serializer;
2 |
3 | import java.io.File;
4 |
5 | /*
6 | * Copyright (C) 2010 Michael Pardo
7 | *
8 | * Licensed under the Apache License, Version 2.0 (the "License");
9 | * you may not use this file except in compliance with the License.
10 | * You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing, software
15 | * distributed under the License is distributed on an "AS IS" BASIS,
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 | * See the License for the specific language governing permissions and
18 | * limitations under the License.
19 | */
20 |
21 |
22 | public final class FileSerializer extends TypeSerializer {
23 | public Class> getDeserializedType() {
24 | return File.class;
25 | }
26 |
27 | public Class> getSerializedType() {
28 | return String.class;
29 | }
30 |
31 | public String serialize(Object data) {
32 | if (data == null) {
33 | return null;
34 | }
35 |
36 | return ((File) data).toString();
37 | }
38 |
39 | public File deserialize(Object data) {
40 | if (data == null) {
41 | return null;
42 | }
43 |
44 | return new File((String) data);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/com/activeandroid/serializer/SqlDateSerializer.java:
--------------------------------------------------------------------------------
1 | package com.activeandroid.serializer;
2 |
3 | /*
4 | * Copyright (C) 2010 Michael Pardo
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
16 | * limitations under the License.
17 | */
18 |
19 | import java.sql.Date;
20 |
21 | public final class SqlDateSerializer extends TypeSerializer {
22 | public Class> getDeserializedType() {
23 | return Date.class;
24 | }
25 |
26 | public Class> getSerializedType() {
27 | return long.class;
28 | }
29 |
30 | public Long serialize(Object data) {
31 | if (data == null) {
32 | return null;
33 | }
34 |
35 | return ((Date) data).getTime();
36 | }
37 |
38 | public Date deserialize(Object data) {
39 | if (data == null) {
40 | return null;
41 | }
42 |
43 | return new Date((Long) data);
44 | }
45 | }
--------------------------------------------------------------------------------
/src/com/activeandroid/serializer/TypeSerializer.java:
--------------------------------------------------------------------------------
1 | package com.activeandroid.serializer;
2 |
3 | /*
4 | * Copyright (C) 2010 Michael Pardo
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
16 | * limitations under the License.
17 | */
18 |
19 | public abstract class TypeSerializer {
20 | public abstract Class> getDeserializedType();
21 |
22 | public abstract Class> getSerializedType();
23 |
24 | public abstract Object serialize(Object data);
25 |
26 | public abstract Object deserialize(Object data);
27 | }
--------------------------------------------------------------------------------
/src/com/activeandroid/serializer/UUIDSerializer.java:
--------------------------------------------------------------------------------
1 | package com.activeandroid.serializer;
2 |
3 | import java.util.UUID;
4 |
5 | public final class UUIDSerializer extends TypeSerializer {
6 | public Class> getDeserializedType() {
7 | return UUID.class;
8 | }
9 |
10 | public Class> getSerializedType() {
11 | return String.class;
12 | }
13 |
14 | public String serialize(Object data) {
15 | if (data == null) {
16 | return null;
17 | }
18 |
19 | return ((UUID) data).toString();
20 | }
21 |
22 | public UUID deserialize(Object data) {
23 | if (data == null) {
24 | return null;
25 | }
26 |
27 | return UUID.fromString((String)data);
28 | }
29 | }
--------------------------------------------------------------------------------
/src/com/activeandroid/serializer/UtilDateSerializer.java:
--------------------------------------------------------------------------------
1 | package com.activeandroid.serializer;
2 |
3 | /*
4 | * Copyright (C) 2010 Michael Pardo
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
16 | * limitations under the License.
17 | */
18 |
19 | import java.util.Date;
20 |
21 | public final class UtilDateSerializer extends TypeSerializer {
22 | public Class> getDeserializedType() {
23 | return Date.class;
24 | }
25 |
26 | public Class> getSerializedType() {
27 | return long.class;
28 | }
29 |
30 | public Long serialize(Object data) {
31 | if (data == null) {
32 | return null;
33 | }
34 |
35 | return ((Date) data).getTime();
36 | }
37 |
38 | public Date deserialize(Object data) {
39 | if (data == null) {
40 | return null;
41 | }
42 |
43 | return new Date((Long) data);
44 | }
45 | }
--------------------------------------------------------------------------------
/src/com/activeandroid/sqlbrite/BackpressureBufferLastOperator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Square, Inc.
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.activeandroid.sqlbrite;
17 |
18 | import rx.Observable.Operator;
19 | import rx.Producer;
20 | import rx.Subscriber;
21 |
22 | /** An operator which keeps the last emitted instance when backpressure has been applied. */
23 | final class BackpressureBufferLastOperator implements Operator {
24 | static final Operator