From 914f9091d26425b41e1bf910897306be0681752c Mon Sep 17 00:00:00 2001 From: Miguel Yanez Barreto Date: Tue, 3 Jan 2017 17:56:22 -0500 Subject: [PATCH 01/32] Add framework to keep track of the current context in Sync mechanism --- .../android/libraries/remixer/Remixer.java | 4 ++++ .../remixer/sync/LocalValueSyncing.java | 10 ++++++++++ .../remixer/sync/SynchronizationMechanism.java | 16 ++++++++++++++++ .../ui/RemixerActivityLifecycleCallbacks.java | 4 ++-- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/Remixer.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/Remixer.java index d242802..de635db 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/Remixer.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/Remixer.java @@ -132,6 +132,10 @@ public void setSynchronizationMechanism(SynchronizationMechanism synchronization } } + public SynchronizationMechanism getSynchronizationMechanism() { + return synchronizationMechanism; + } + /** * This adds a {@link Variable} to be tracked and displayed. * Checks that the variable is compatible with the existing variables with the same key. diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/sync/LocalValueSyncing.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/sync/LocalValueSyncing.java index 7cf4c7d..c547a6c 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/sync/LocalValueSyncing.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/sync/LocalValueSyncing.java @@ -57,4 +57,14 @@ public void onValueChanged(Variable variable) { } } } + + @Override + public void onContextChanged(Object currentContext) { + // Nothing to do here, this class does not care which is the current context. + } + + @Override + public void onContextRemoved(Object currentContext) { + // Nothing to do here, this class does not care which is the current context. + } } diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/sync/SynchronizationMechanism.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/sync/SynchronizationMechanism.java index 9f15591..6c2f64a 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/sync/SynchronizationMechanism.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/sync/SynchronizationMechanism.java @@ -52,4 +52,20 @@ public interface SynchronizationMechanism { * cache/save/sync the new value. */ void onValueChanged(Variable variable); + + /** + * Called when a new activity has been made the current context. + * + *

This may be needed to update context-dependent state. + */ + void onContextChanged(Object currentContext); + + /** + * Called when an activity is stopped and reclaimed, the context is no longer valid. + * + *

This may be needed to update context-dependent state. Notice this may be called for a + * context which is no longer the current context (the one passed in the last call to + * {@link #onContextChanged(Object)}); it is up to the implementation what to do in this case. + */ + void onContextRemoved(Object currentContext); } diff --git a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/RemixerActivityLifecycleCallbacks.java b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/RemixerActivityLifecycleCallbacks.java index c39dbd7..6464962 100644 --- a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/RemixerActivityLifecycleCallbacks.java +++ b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/RemixerActivityLifecycleCallbacks.java @@ -45,7 +45,7 @@ public void onActivityCreated(Activity activity, Bundle bundle) { @Override public void onActivityStarted(Activity activity) { - + Remixer.getInstance().getSynchronizationMechanism().onContextChanged(activity); } @Override @@ -60,7 +60,7 @@ public void onActivityPaused(Activity activity) { @Override public void onActivityStopped(Activity activity) { - + Remixer.getInstance().getSynchronizationMechanism().onContextRemoved(activity); } @Override From a81da56117484baad46facdd0899ecf23e0ab80f Mon Sep 17 00:00:00 2001 From: Miguel Yanez Barreto Date: Tue, 10 Jan 2017 11:28:48 -0500 Subject: [PATCH 02/32] Add a barebones FirebaseRemoteControllerSyncer. --- .../remixer/storage/FirebaseRemoteControllerSyncer.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 remixer_storage/src/main/java/com/google/android/libraries/remixer/storage/FirebaseRemoteControllerSyncer.java diff --git a/remixer_storage/src/main/java/com/google/android/libraries/remixer/storage/FirebaseRemoteControllerSyncer.java b/remixer_storage/src/main/java/com/google/android/libraries/remixer/storage/FirebaseRemoteControllerSyncer.java new file mode 100644 index 0000000..731c208 --- /dev/null +++ b/remixer_storage/src/main/java/com/google/android/libraries/remixer/storage/FirebaseRemoteControllerSyncer.java @@ -0,0 +1,9 @@ +package com.google.android.libraries.remixer.storage; + +/** + * Created by miguely on 2017-01-09. + */ + +public class FirebaseRemoteControllerSyncer extends LocalStorage { + +} From 1c7e1bb62321c50b581f955b8565e27f543e4411 Mon Sep 17 00:00:00 2001 From: Miguel Yanez Barreto Date: Tue, 10 Jan 2017 11:29:24 -0500 Subject: [PATCH 03/32] Add a barebones FirebaseRemoteControllerSyncer. --- .../FirebaseRemoteControllerSyncer.java | 81 ++++++++++++++++++- 1 file changed, 79 insertions(+), 2 deletions(-) diff --git a/remixer_storage/src/main/java/com/google/android/libraries/remixer/storage/FirebaseRemoteControllerSyncer.java b/remixer_storage/src/main/java/com/google/android/libraries/remixer/storage/FirebaseRemoteControllerSyncer.java index 731c208..9d99634 100644 --- a/remixer_storage/src/main/java/com/google/android/libraries/remixer/storage/FirebaseRemoteControllerSyncer.java +++ b/remixer_storage/src/main/java/com/google/android/libraries/remixer/storage/FirebaseRemoteControllerSyncer.java @@ -1,9 +1,86 @@ +/* + * Copyright 2017 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.google.android.libraries.remixer.storage; +import android.content.Context; +import com.google.android.libraries.remixer.Remixer; +import com.google.android.libraries.remixer.Variable; +import com.google.android.libraries.remixer.sync.LocalValueSyncing; +import com.google.android.libraries.remixer.sync.SynchronizationMechanism; +import java.lang.ref.WeakReference; + /** - * Created by miguely on 2017-01-09. + * A {@link SynchronizationMechanism} that syncs up to a firebase Remote Controller. + * + *

This synchronization mechanism assumes that the local host is the source of truth, so it does + * very little in terms of conflict resolution. */ +public class FirebaseRemoteControllerSyncer extends LocalValueSyncing { + + WeakReference context; + + public FirebaseRemoteControllerSyncer(Context context) { + super(context); + } + + /** + * Syncs a variable up to the remote controller. + */ + private void syncVariableToRemoteController (Variable variable) { + // TODO(miguely): write controller sync logic + } + + /** + * Clears all the data in a remote + */ + private void clearVariablesInRemoteController() { + // TODO(miguely): write controller sync logic + } + + @Override + public void onAddingVariable(Variable variable) { + super.onAddingVariable(variable); + syncVariableToRemoteController(variable); + } + + @Override + public void onValueChanged(Variable variable) { + super.onValueChanged(variable); + syncVariableToRemoteController(variable); + } -public class FirebaseRemoteControllerSyncer extends LocalStorage { + @Override + public void onContextChanged(Object currentContext) { + super.onContextChanged(currentContext); + if ((context == null && currentContext != null) || + (context != null && currentContext != context.get())) { + context = new WeakReference(context); + clearVariablesInRemoteController(); + for (Variable var : Remixer.getInstance().getVariablesWithContext(currentContext)) { + syncVariableToRemoteController(var); + } + } + } + @Override + public void onContextRemoved(Object currentContext) { + super.onContextRemoved(currentContext); + if (context != null && context.get() == currentContext) { + clearVariablesInRemoteController(); + } + } } From 985bcb21d45fa7d56cd47fc107d201e83ed184e1 Mon Sep 17 00:00:00 2001 From: Miguel Yanez Barreto Date: Tue, 10 Jan 2017 12:25:46 -0500 Subject: [PATCH 04/32] Fix super() call --- .../remixer/storage/FirebaseRemoteControllerSyncer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remixer_storage/src/main/java/com/google/android/libraries/remixer/storage/FirebaseRemoteControllerSyncer.java b/remixer_storage/src/main/java/com/google/android/libraries/remixer/storage/FirebaseRemoteControllerSyncer.java index 9d99634..4c36d25 100644 --- a/remixer_storage/src/main/java/com/google/android/libraries/remixer/storage/FirebaseRemoteControllerSyncer.java +++ b/remixer_storage/src/main/java/com/google/android/libraries/remixer/storage/FirebaseRemoteControllerSyncer.java @@ -34,7 +34,7 @@ public class FirebaseRemoteControllerSyncer extends LocalValueSyncing { WeakReference context; public FirebaseRemoteControllerSyncer(Context context) { - super(context); + super(); } /** From c8d59c1efd9f13ba4d9725e95d3a78ac51c9f117 Mon Sep 17 00:00:00 2001 From: Miguel Yanez Barreto Date: Wed, 11 Jan 2017 12:06:25 -0500 Subject: [PATCH 05/32] Improve documentations for firebase remote --- .../storage/FirebaseRemoteControllerSyncer.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/remixer_storage/src/main/java/com/google/android/libraries/remixer/storage/FirebaseRemoteControllerSyncer.java b/remixer_storage/src/main/java/com/google/android/libraries/remixer/storage/FirebaseRemoteControllerSyncer.java index 4c36d25..5ac52be 100644 --- a/remixer_storage/src/main/java/com/google/android/libraries/remixer/storage/FirebaseRemoteControllerSyncer.java +++ b/remixer_storage/src/main/java/com/google/android/libraries/remixer/storage/FirebaseRemoteControllerSyncer.java @@ -28,24 +28,33 @@ * *

This synchronization mechanism assumes that the local host is the source of truth, so it does * very little in terms of conflict resolution. + * + *

This implementation currently ignores bringing new values in from the remote controller, that + * will be done in firebase callbacks in a future PR, so it is a different one that introduces said + * dependency. */ public class FirebaseRemoteControllerSyncer extends LocalValueSyncing { WeakReference context; - public FirebaseRemoteControllerSyncer(Context context) { + public FirebaseRemoteControllerSyncer() { super(); } /** * Syncs a variable up to the remote controller. + * + *

Since the local app is the source of truth, this ignores any differences there may be + * between the local data and the remote data and just rewrites any remote data. This should not + * happen in practice though, since variables in remote controllers are tied to a single instance + * of the app (one specific device running the app). */ private void syncVariableToRemoteController (Variable variable) { // TODO(miguely): write controller sync logic } /** - * Clears all the data in a remote + * Clears all the data in a remote. */ private void clearVariablesInRemoteController() { // TODO(miguely): write controller sync logic From 0ddf653db6bf4e63571b10764ff09a716871a9e5 Mon Sep 17 00:00:00 2001 From: Miguel Yanez Barreto Date: Thu, 12 Jan 2017 11:32:13 -0500 Subject: [PATCH 06/32] Decouple the type we use in runtime to represent values from the serialization. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In most cases both are the same, but colors are their special little snowflakes, because they have a very different representation across platforms and the best we can do is give them their own unambiguous representation that doesn’t map directly to Android’s. For context: Android uses 32-bit integers, encoded as AARRGGBB, web uses either four 0-255 integers representing each component or one #RRGGBBAA string (notice the different order of the components), and iOS has a native object that can be initialized with four 0-255 integers, only. This is why we decided to represent it as an object that has four 0-255 integers, a, r, g and b. This already works when serializing to JSON but it doesn’t when serializing to firebase, where it expects a more natural java object representation, for this purpose I wrote a new java class that represents this structure, and refactored our serialization code to use it. --- .../ItemListVariableMethodAnnotation.java | 2 +- .../processor/MethodAnnotation.java | 2 +- .../android/libraries/remixer/DataType.java | 39 +++--- .../serialization/SerializedColor.java | 126 ++++++++++++++++++ .../remixer/serialization/ValueConverter.java | 60 ++++++--- .../converters/BooleanValueConverter.java | 18 ++- .../converters/ColorValueConverter.java | 63 ++------- .../converters/FloatValueConverter.java | 34 ++--- .../converters/StringValueConverter.java | 22 ++- .../remixer/sync/LocalValueSyncing.java | 6 +- .../remixer/serialization/CompareHelper.java | 18 ++- .../serialization/InitializationHelper.java | 23 ---- 12 files changed, 260 insertions(+), 153 deletions(-) create mode 100644 remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/SerializedColor.java delete mode 100644 remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/InitializationHelper.java diff --git a/remixer_annotation/src/main/java/com/google/android/libraries/remixer/annotation/processor/ItemListVariableMethodAnnotation.java b/remixer_annotation/src/main/java/com/google/android/libraries/remixer/annotation/processor/ItemListVariableMethodAnnotation.java index 5558392..e189ce5 100644 --- a/remixer_annotation/src/main/java/com/google/android/libraries/remixer/annotation/processor/ItemListVariableMethodAnnotation.java +++ b/remixer_annotation/src/main/java/com/google/android/libraries/remixer/annotation/processor/ItemListVariableMethodAnnotation.java @@ -192,7 +192,7 @@ public void addSpecificSetupStatements(MethodSpec.Builder methodBuilder) { String listName = key + LIST_SUFFIX; TypeName listType = ParameterizedTypeName.get(ClassName.get(ArrayList.class), - ClassName.get(dataType.getValueClass())); + ClassName.get(dataType.getRuntimeType())); methodBuilder.addStatement(CREATE_NEW_OBJECT, listType, listName, listType); String addValueStatement = String.format(Locale.getDefault(), ADD_ITEM_FORMAT, getJavaPoetEscaping()); diff --git a/remixer_annotation/src/main/java/com/google/android/libraries/remixer/annotation/processor/MethodAnnotation.java b/remixer_annotation/src/main/java/com/google/android/libraries/remixer/annotation/processor/MethodAnnotation.java index b0a7d2c..8fbb204 100644 --- a/remixer_annotation/src/main/java/com/google/android/libraries/remixer/annotation/processor/MethodAnnotation.java +++ b/remixer_annotation/src/main/java/com/google/android/libraries/remixer/annotation/processor/MethodAnnotation.java @@ -267,6 +267,6 @@ protected MethodSpec getCallbackMethodSpec() { * Returns the type to use to parametrize the Variable objects when generating code. */ private final TypeName getVariableType() { - return ClassName.get(dataType.getValueClass()); + return ClassName.get(dataType.getRuntimeType()); } } diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/DataType.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/DataType.java index a27457f..c8890d7 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/DataType.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/DataType.java @@ -1,5 +1,6 @@ package com.google.android.libraries.remixer; +import com.google.android.libraries.remixer.serialization.SerializedColor; import com.google.android.libraries.remixer.serialization.ValueConverter; import com.google.android.libraries.remixer.serialization.converters.BooleanValueConverter; import com.google.android.libraries.remixer.serialization.converters.ColorValueConverter; @@ -12,8 +13,11 @@ /** * The data type for each RemixerItem. The data type is used to determine default layoutIDs and to * help serialization. + * + * @param The type to use during runtime to represent variables of this DataType + * @param The type to use to serialize variables of this type. */ -public class DataType { +public class DataType { /** * The serializable, unique name for this data type. @@ -21,14 +25,14 @@ public class DataType { private final String name; /** - * The class of the values contained by this variable. + * The runtime class of the values contained by this variable. */ - private final Class valueClass; + private final Class runtimeType; /** * The value converter that aids in the serialization process. */ - private final ValueConverter converter; + private final ValueConverter converter; /** * Map of default layout ids for this datatype when used with a specific RemixerItem class. * @@ -39,15 +43,18 @@ public class DataType { new HashMap<>(); /** - * Constructs a datatype with the given {@code name}, that takes values of type {@code valueClass} + * Constructs a datatype with the given {@code name}, that takes values of type {@code runtimeType} * and uses {@code converter} to serialize. * *

Note {@code converter} has a {@link ValueConverter#dataType} field that must be initialized * to the same as {@code name}. */ - public DataType(String name, Class valueClass, ValueConverter converter) { + public DataType( + String name, + Class runtimeType, + ValueConverter converter) { this.name = name; - this.valueClass = valueClass; + this.runtimeType = runtimeType; this.converter = converter; if (!name.equals(converter.getDataType())) { throw new AssertionError(String.format( @@ -69,14 +76,14 @@ public boolean equals(Object obj) { if (!name.equals(dataType.name)) { return false; } - return valueClass.equals(dataType.valueClass); + return runtimeType.equals(dataType.runtimeType); } @Override public int hashCode() { int result = name.hashCode(); - result = 31 * result + valueClass.hashCode(); + result = 31 * result + runtimeType.hashCode(); return result; } @@ -92,11 +99,11 @@ public String getName() { return name; } - public Class getValueClass() { - return valueClass; + public Class getRuntimeType() { + return runtimeType; } - public ValueConverter getConverter() { + public ValueConverter getConverter() { return converter; } @@ -107,15 +114,15 @@ public ValueConverter getConverter() { private static final String KEY_NUMBER = "__DataTypeNumber__"; private static final String KEY_STRING = "__DataTypeString__"; - public static final DataType BOOLEAN = new DataType<>( + public static final DataType BOOLEAN = new DataType<>( KEY_BOOLEAN, Boolean.class, new BooleanValueConverter(KEY_BOOLEAN)); - public static final DataType COLOR = new DataType<>( + public static final DataType COLOR = new DataType<>( KEY_COLOR, Integer.class, new ColorValueConverter(KEY_COLOR)); - public static final DataType NUMBER = new DataType<>( + public static final DataType NUMBER = new DataType<>( KEY_NUMBER, Float.class, new FloatValueConverter(KEY_NUMBER)); - public static final DataType STRING = new DataType<>( + public static final DataType STRING = new DataType<>( KEY_STRING, String.class, new StringValueConverter(KEY_STRING)); } diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/SerializedColor.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/SerializedColor.java new file mode 100644 index 0000000..10bead6 --- /dev/null +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/SerializedColor.java @@ -0,0 +1,126 @@ +/* + * Copyright 2017 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.android.libraries.remixer.serialization; + +/** + * A serialized color represents alpha, red, green and blue as 0-255 integers. + * + *

This is the agreed-upon representation of colors in Remixer. Sadly there is no uniform color + * representation across platforms. + */ + +public class SerializedColor { + + /** + * Alpha component from 0 to 255. + */ + private int a; + + /** + * Red component from 0 to 255. + */ + private int r; + + /** + * Green component from 0 to 255. + */ + private int g; + + /** + * Blue component from 0 to 255. + */ + private int b; + + public SerializedColor() { + a = 0; + r = 0; + g = 0; + b = 0; + } + + /** + * Initialize a SerializedColor from an android native color. + */ + public SerializedColor(int color) { + a = color >>> 24; + r = (color >>> 16) & 0xFF; + g = (color >>> 8) & 0xFF; + b = color & 0xFF; + } + + public int getA() { + return a; + } + + public void setA(int a) { + this.a = a; + } + + public int getR() { + return r; + } + + public void setR(int r) { + this.r = r; + } + + public int getG() { + return g; + } + + public void setG(int g) { + this.g = g; + } + + public int getB() { + return b; + } + + public void setB(int b) { + this.b = b; + } + + /** + * Returns a native android representation of this color, as a AARRGGBB hex integer. + */ + public int toAndroidColor() { + return a << 24 | r << 16 | g << 8 | b; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + SerializedColor that = (SerializedColor) o; + + if (a != that.a) return false; + if (r != that.r) return false; + if (g != that.g) return false; + return b == that.b; + + } + + @Override + public int hashCode() { + int result = a; + result = 31 * result + r; + result = 31 * result + g; + result = 31 * result + b; + return result; + } +} diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/ValueConverter.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/ValueConverter.java index d47cba2..3eaad0f 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/ValueConverter.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/ValueConverter.java @@ -16,6 +16,8 @@ package com.google.android.libraries.remixer.serialization; +import com.google.android.libraries.remixer.ItemListVariable; +import com.google.android.libraries.remixer.RangeVariable; import com.google.android.libraries.remixer.Variable; import com.google.gson.JsonArray; import com.google.gson.JsonElement; @@ -26,9 +28,10 @@ /** * Helper object that abstracts the type-dependent parts of parsing a Variable from Json and * converting it from a java object into its JSON representation. - * @param the data type stored in the variable. + * @param the data type that the remixer core framework uses. + * @param the data type to use during serialization. */ -public abstract class ValueConverter { +public abstract class ValueConverter { /** * The data type this converter is used for. @@ -47,27 +50,30 @@ public String getDataType() { } /** - * Returns an object of type T that holds the value in the current Json Element. + * Returns an object of type SerializableType that holds the value in the current Json Element. */ - public abstract T parseValue(JsonElement element); + public abstract SerializableType parseValue(JsonElement element); /** * Returns a JsonElement that represents the value passed in. */ - public abstract JsonElement valueToJson(T value); + public abstract JsonElement valueToJson(SerializableType value); /** - * Creates a StoredVariable that represents the data in {@code variable} if {@code item} is of - * this type. - * @throws IllegalArgumentException if {@code item} does not match this type. + * Converts values from the runtime type to the serializable type. + */ + public abstract SerializableType fromRuntimeType(RuntimeType value); + + /** + * Converts values from the serializable type to the runtime type. */ - public abstract StoredVariable fromVariable(Variable variable); + public abstract RuntimeType toRuntimeType(SerializableType value); /** * Deserializes a JsonElement that contains a StoredVariable. */ - public StoredVariable deserialize(JsonElement json) { - StoredVariable result = new StoredVariable<>(); + public StoredVariable deserialize(JsonElement json) { + StoredVariable result = new StoredVariable<>(); JsonObject object = json.getAsJsonObject(); result.selectedValue = parseValue(object.get(StoredVariable.SELECTED_VALUE)); result.constraintType = object.get(StoredVariable.CONSTRAINT_TYPE).getAsString(); @@ -83,13 +89,13 @@ public StoredVariable deserialize(JsonElement json) { return result; } - private void deserializeRangeProperties(StoredVariable result, JsonObject object) { + private void deserializeRangeProperties(StoredVariable result, JsonObject object) { result.minValue = parseValue(object.getAsJsonPrimitive(StoredVariable.MIN_VALUE)); result.maxValue = parseValue(object.getAsJsonPrimitive(StoredVariable.MAX_VALUE)); result.increment = parseValue(object.getAsJsonPrimitive(StoredVariable.INCREMENT)); } - private void deserializePossibleValues(StoredVariable result, JsonElement possibleValuesElement) { + private void deserializePossibleValues(StoredVariable result, JsonElement possibleValuesElement) { if (possibleValuesElement != null) { JsonArray array = possibleValuesElement.getAsJsonArray(); result.possibleValues = new ArrayList<>(); @@ -102,7 +108,7 @@ private void deserializePossibleValues(StoredVariable result, JsonElement pos /** * Serializes a StoredVariable into a JsonElement. */ - public JsonElement serialize(StoredVariable src) { + public JsonElement serialize(StoredVariable src) { JsonObject object = new JsonObject(); object.add(StoredVariable.KEY, new JsonPrimitive(src.key)); object.add(StoredVariable.TITLE, new JsonPrimitive(src.title)); @@ -111,7 +117,7 @@ public JsonElement serialize(StoredVariable src) { object.add(StoredVariable.CONSTRAINT_TYPE, new JsonPrimitive(src.constraintType)); if (StoredVariable.ITEM_LIST_VARIABLE_CONSTRAINT.equals(src.constraintType)) { JsonArray possibleValues = new JsonArray(); - for (T item : src.possibleValues) { + for (SerializableType item : src.possibleValues) { possibleValues.add(valueToJson(item)); } object.add(StoredVariable.POSSIBLE_VALUES, possibleValues); @@ -123,4 +129,28 @@ public JsonElement serialize(StoredVariable src) { } return object; } + + /** + * Creates a StoredVariable that represents the data in {@code variable} if {@code item} is of + * this type. + * @throws IllegalArgumentException if {@code item} does not match this type. + */ + @SuppressWarnings("unchecked") + public StoredVariable fromVariable(Variable var) { + if (var.getDataType().getName().equals(dataType)) { + StoredVariable storage = new StoredVariable<>(); + storage.setDataType(dataType); + storage.setSelectedValue(fromRuntimeType((RuntimeType) var.getSelectedValue())); + if (var instanceof ItemListVariable) { + ArrayList possibleValues = new ArrayList<>(); + for (RuntimeType value : ((ItemListVariable) var).getValueList()) { + possibleValues.add(fromRuntimeType(value)); + } + storage.setPossibleValues(possibleValues); + } + return storage; + } + throw new IllegalArgumentException( + "Passed an incompatible object to convert to StoredVariable for type " + dataType); + } } diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/BooleanValueConverter.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/BooleanValueConverter.java index e95f56a..9d0bff1 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/BooleanValueConverter.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/BooleanValueConverter.java @@ -9,7 +9,7 @@ /** * A value converter for boolean values. */ -public class BooleanValueConverter extends ValueConverter { +public class BooleanValueConverter extends ValueConverter { public BooleanValueConverter(String dataType) { super(dataType); @@ -26,14 +26,12 @@ public JsonElement valueToJson(Boolean value) { } @Override - public StoredVariable fromVariable(Variable var) { - if (var.getDataType().getName().equals(dataType)) { - StoredVariable storage = new StoredVariable<>(); - storage.setDataType(dataType); - storage.setSelectedValue((Boolean) var.getSelectedValue()); - return storage; - } - throw new IllegalArgumentException( - "Passed an incompatible object to convert to StoredVariable"); + public Boolean fromRuntimeType(Boolean value) { + return value; + } + + @Override + public Boolean toRuntimeType(Boolean value) { + return value; } } diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/ColorValueConverter.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/ColorValueConverter.java index c55f7dd..448dc57 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/ColorValueConverter.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/ColorValueConverter.java @@ -1,75 +1,36 @@ package com.google.android.libraries.remixer.serialization.converters; -import com.google.android.libraries.remixer.ItemListVariable; -import com.google.android.libraries.remixer.Variable; -import com.google.android.libraries.remixer.serialization.StoredVariable; +import com.google.android.libraries.remixer.serialization.GsonProvider; +import com.google.android.libraries.remixer.serialization.SerializedColor; import com.google.android.libraries.remixer.serialization.ValueConverter; import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; /** * A value converter for color values. */ -public class ColorValueConverter extends ValueConverter { +public class ColorValueConverter extends ValueConverter { public ColorValueConverter(String dataType) { super(dataType); } - private static int argb(int alpha, int red, int green, int blue) { - return (alpha << 24) | (red << 16) | (green << 8) | blue; - } - - private static int alpha(int color) { - return color >>> 24; - } - - private static int red(int color) { - return (color >>> 16) & 0xFF; - } - - private static int green(int color) { - return (color >>> 8) & 0xFF; - } - - private static int blue(int color) { - return color & 0xFF; + @Override + public SerializedColor parseValue(JsonElement element) { + return GsonProvider.getInstance().fromJson(element, SerializedColor.class); } @Override - public Integer parseValue(JsonElement element) { - JsonObject object = element.getAsJsonObject(); - return argb( - object.get("a").getAsInt(), - object.get("r").getAsInt(), - object.get("g").getAsInt(), - object.get("b").getAsInt()); + public JsonElement valueToJson(SerializedColor value) { + return GsonProvider.getInstance().toJsonTree(value); } @Override - public JsonElement valueToJson(Integer value) { - JsonObject object = new JsonObject(); - object.add("a", new JsonPrimitive(alpha(value))); - object.add("r", new JsonPrimitive(red(value))); - object.add("g", new JsonPrimitive(green(value))); - object.add("b", new JsonPrimitive(blue(value))); - return object; + public SerializedColor fromRuntimeType(Integer value) { + return new SerializedColor(value.intValue()); } @Override - @SuppressWarnings("unchecked") - public StoredVariable fromVariable(Variable var) { - if (var.getDataType().getName().equals(dataType)) { - StoredVariable storage = new StoredVariable<>(); - storage.setDataType(dataType); - storage.setSelectedValue((Integer) var.getSelectedValue()); - if (var instanceof ItemListVariable) { - storage.setPossibleValues(((ItemListVariable) var).getValueList()); - } - return storage; - } - throw new IllegalArgumentException( - "Passed an incompatible object to convert to StoredVariable"); + public Integer toRuntimeType(SerializedColor value) { + return value.toAndroidColor(); } } diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/FloatValueConverter.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/FloatValueConverter.java index 6e1f9f8..ed62018 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/FloatValueConverter.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/FloatValueConverter.java @@ -11,7 +11,7 @@ /** * A value converter for integer values. */ -public class FloatValueConverter extends ValueConverter { +public class FloatValueConverter extends ValueConverter { public FloatValueConverter(String dataType) { super(dataType); @@ -30,21 +30,23 @@ public JsonElement valueToJson(Float value) { @Override @SuppressWarnings("unchecked") public StoredVariable fromVariable(Variable var) { - if (var.getDataType().getName().equals(dataType)) { - StoredVariable storage = new StoredVariable<>(); - storage.setDataType(dataType); - storage.setSelectedValue((Float) var.getSelectedValue()); - if (var instanceof RangeVariable) { - RangeVariable range = (RangeVariable) var; - storage.setMinValue(range.getMinValue()); - storage.setMaxValue(range.getMaxValue()); - storage.setIncrement(range.getIncrement()); - } else if (var instanceof ItemListVariable) { - storage.setPossibleValues(((ItemListVariable) var).getValueList()); - } - return storage; + StoredVariable storage = super.fromVariable(var); + if (var instanceof RangeVariable) { + RangeVariable range = (RangeVariable) var; + storage.setMinValue(range.getMinValue()); + storage.setMaxValue(range.getMaxValue()); + storage.setIncrement(range.getIncrement()); } - throw new IllegalArgumentException( - "Passed an incompatible object to convert to StoredVariable"); + return storage; + } + + @Override + public Float fromRuntimeType(Float value) { + return value; + } + + @Override + public Float toRuntimeType(Float value) { + return value; } } diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/StringValueConverter.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/StringValueConverter.java index c65dfe8..30d56d6 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/StringValueConverter.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/StringValueConverter.java @@ -10,7 +10,7 @@ /** * A value converter for string values. */ -public class StringValueConverter extends ValueConverter { +public class StringValueConverter extends ValueConverter { public StringValueConverter(String dataType) { super(dataType); @@ -27,18 +27,12 @@ public JsonElement valueToJson(String value) { } @Override - @SuppressWarnings("unchecked") - public StoredVariable fromVariable(Variable var) { - if (var.getDataType().getName().equals(dataType)) { - StoredVariable storage = new StoredVariable<>(); - storage.setDataType(dataType); - storage.setSelectedValue((String) var.getSelectedValue()); - if (var instanceof ItemListVariable) { - storage.setPossibleValues(((ItemListVariable) var).getValueList()); - } - return storage; - } - throw new IllegalArgumentException( - "Passed an incompatible object to convert to StoredVariable"); + public String fromRuntimeType(String value) { + return value; + } + + @Override + public String toRuntimeType(String value) { + return value; } } diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/sync/LocalValueSyncing.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/sync/LocalValueSyncing.java index c547a6c..697fd2a 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/sync/LocalValueSyncing.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/sync/LocalValueSyncing.java @@ -43,7 +43,8 @@ public void onAddingVariable(Variable variable) { serializableRemixerContents.addItem(variable); StoredVariable storedVariable = serializableRemixerContents.getItem(variable.getKey()); // Check the value for updates. - variable.setValueWithoutNotifyingOthers(storedVariable.getSelectedValue()); + variable.setValueWithoutNotifyingOthers( + variable.getDataType().getConverter().toRuntimeType(storedVariable.getSelectedValue())); } @Override @@ -53,7 +54,8 @@ public void onValueChanged(Variable variable) { List itemList = remixer.getVariablesWithKey(variable.getKey()); for (Variable item : itemList) { if (item != variable) { - ((Variable) item).setValueWithoutNotifyingOthers(variable.getSelectedValue()); + item.setValueWithoutNotifyingOthers( + variable.getDataType().getConverter().toRuntimeType(variable.getSelectedValue())); } } } diff --git a/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/CompareHelper.java b/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/CompareHelper.java index b572d16..2f75c99 100644 --- a/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/CompareHelper.java +++ b/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/CompareHelper.java @@ -19,6 +19,7 @@ import com.google.android.libraries.remixer.ItemListVariable; import com.google.android.libraries.remixer.RangeVariable; import com.google.android.libraries.remixer.Variable; +import java.util.List; import org.junit.Assert; public class CompareHelper { @@ -32,11 +33,20 @@ public static void assertEqualsVariable(StoredVariable storage, Variable< Assert.assertNull(storage.increment); } - public static void assertEqualsItemListVariable( - StoredVariable storage, ItemListVariable variable) { + public static void assertEqualsItemListVariable( + StoredVariable storage, ItemListVariable variable) { assertConsistent(storage, variable); - Assert.assertEquals(variable.getSelectedValue(), storage.selectedValue); - Assert.assertEquals(variable.getValueList(), storage.possibleValues); + List runtimeList = variable.getValueList(); + List serializableList = storage.getPossibleValues(); + Assert.assertNotNull(runtimeList); + Assert.assertNotNull(serializableList); + Assert.assertEquals(runtimeList.size(), serializableList.size()); + ValueConverter converter = variable.getDataType().getConverter(); + for (int i = 0; i < runtimeList.size(); i++) { + Assert.assertEquals(converter.fromRuntimeType(runtimeList.get(i)), serializableList.get(i)); + } + Assert.assertEquals( + variable.getSelectedValue(), converter.toRuntimeType(storage.selectedValue)); Assert.assertNull(storage.minValue); Assert.assertNull(storage.maxValue); Assert.assertNull(storage.increment); diff --git a/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/InitializationHelper.java b/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/InitializationHelper.java deleted file mode 100644 index 55240df..0000000 --- a/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/InitializationHelper.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.google.android.libraries.remixer.serialization; - -import com.google.android.libraries.remixer.DataType; -import com.google.android.libraries.remixer.Remixer; -import java.util.HashSet; - -/** - * Helper class to properly initialize remixer instances. - */ -class InitializationHelper { - - private static HashSet initializedRemixerInstances = new HashSet<>(); - - static void init(Remixer instance) { - if (!initializedRemixerInstances.contains(instance)) { - instance.registerDataType(DataType.BOOLEAN); - instance.registerDataType(DataType.COLOR); - instance.registerDataType(DataType.NUMBER); - instance.registerDataType(DataType.STRING); - initializedRemixerInstances.add(instance); - } - } -} From f94ac0925096e3f948d7e05afa1d1e5ac66849d3 Mon Sep 17 00:00:00 2001 From: Miguel Yanez Barreto Date: Thu, 12 Jan 2017 13:26:53 -0500 Subject: [PATCH 07/32] Rename defaultValue to initialValue and possibleValues to limitedToValues. #xplatconsistency --- README.md | 16 ++-- .../ItemListVariableMethodAnnotation.java | 79 ++++++++++--------- .../RangeVariableMethodAnnotation.java | 14 ++-- .../processor/VariableMethodAnnotation.java | 16 ++-- ...ColorListVariableMethodAnnotationTest.java | 10 +-- ...umberListVariableMethodAnnotationTest.java | 10 +-- .../RangeVariableMethodAnnotationTest.java | 8 +- ...tringListVariableMethodAnnotationTest.java | 10 +-- .../Correct.java | 4 +- .../EmptyList.java | 2 +- .../ExplicitWrongDefault.java | 4 +- ...faultValue.java => FixesInitialValue.java} | 6 +- .../MethodWithWrongParameter.java | 2 +- .../Correct.java | 4 +- .../EmptyList.java | 2 +- .../ExplicitWrongDefault.java | 4 +- ...faultValue.java => FixesInitialValue.java} | 6 +- .../MethodWithWrongParameter.java | 2 +- .../Correct.java | 4 +- .../ExplicitWrongDefault.java | 4 +- ...faultValue.java => FixesInitialValue.java} | 4 +- .../Correct.java | 6 +- .../EmptyList.java | 2 +- .../ExplicitWrongDefault.java | 4 +- ...faultValue.java => FixesInitialValue.java} | 6 +- .../MethodWithWrongParameter.java | 2 +- .../Correct.java | 2 +- .../Correct.java | 4 +- ...faultValue.java => FixesInitialValue.java} | 12 +-- .../Correct.java | 4 +- ...faultValue.java => FixesInitialValue.java} | 12 +-- .../Correct.java | 2 +- ...faultValue.java => FixesInitialValue.java} | 10 +-- .../Correct.java | 18 ++--- ...faultValue.java => FixesInitialValue.java} | 12 +-- .../Correct.java | 2 +- .../remixer/BaseVariableBuilder.java | 6 +- .../remixer/BooleanVariableBuilder.java | 4 +- .../libraries/remixer/ItemListVariable.java | 44 +++++------ .../libraries/remixer/RangeVariable.java | 14 ++-- .../remixer/StringVariableBuilder.java | 2 +- .../android/libraries/remixer/Variable.java | 11 +-- .../annotation/BooleanVariableMethod.java | 4 +- .../annotation/ColorListVariableMethod.java | 6 +- .../annotation/NumberListVariableMethod.java | 6 +- .../annotation/RangeVariableMethod.java | 4 +- .../annotation/StringListVariableMethod.java | 6 +- .../annotation/StringVariableMethod.java | 4 +- .../remixer/serialization/StoredVariable.java | 2 +- .../converters/ColorValueConverter.java | 2 +- .../converters/FloatValueConverter.java | 2 +- .../converters/StringValueConverter.java | 2 +- .../remixer/ItemListVariableTest.java | 14 ++-- .../libraries/remixer/RangeVariableTest.java | 26 +++--- .../ColorVariableSerializationTest.java | 4 +- .../remixer/serialization/CompareHelper.java | 2 +- .../NumberVariableSerializationTest.java | 8 +- ...zableRemixerContentsSerializationTest.java | 16 ++-- .../StringVariableSerializationTest.java | 4 +- .../android/apps/remixer/BoxActivity.java | 2 +- .../android/apps/remixer/MainActivity.java | 4 +- .../remixer/storage/LocalStorageTest.java | 4 +- .../ui/widget/ColorListVariableWidget.java | 2 +- .../ui/widget/ItemListVariableWidget.java | 2 +- .../ui/widget/BooleanVariableWidgetTest.java | 2 +- .../widget/ColorListVariableWidgetTest.java | 4 +- .../ui/widget/ItemListVariableWidgetTest.java | 4 +- .../SeekBarRangeVariableWidgetTest.java | 2 +- .../ui/widget/StringVariableWidgetTest.java | 2 +- 69 files changed, 264 insertions(+), 266 deletions(-) rename remixer_annotation/src/test/resources/inputs/ColorListVariableMethodAnnotationTest/{FixesDefaultValue.java => FixesInitialValue.java} (83%) rename remixer_annotation/src/test/resources/inputs/NumberListVariableMethodAnnotationTest/{FixesDefaultValue.java => FixesInitialValue.java} (83%) rename remixer_annotation/src/test/resources/inputs/RangeVariableMethodAnnotationTest/{FixesDefaultValue.java => FixesInitialValue.java} (89%) rename remixer_annotation/src/test/resources/inputs/StringListVariableMethodAnnotationTest/{FixesDefaultValue.java => FixesInitialValue.java} (82%) rename remixer_annotation/src/test/resources/outputs/ColorListVariableMethodAnnotationTest/{FixesDefaultValue.java => FixesInitialValue.java} (84%) rename remixer_annotation/src/test/resources/outputs/NumberListVariableMethodAnnotationTest/{FixesDefaultValue.java => FixesInitialValue.java} (84%) rename remixer_annotation/src/test/resources/outputs/RangeVariableMethodAnnotationTest/{FixesDefaultValue.java => FixesInitialValue.java} (86%) rename remixer_annotation/src/test/resources/outputs/StringListVariableMethodAnnotationTest/{FixesDefaultValue.java => FixesInitialValue.java} (84%) diff --git a/README.md b/README.md index bdad1c3..efbed77 100644 --- a/README.md +++ b/README.md @@ -130,7 +130,7 @@ They support the following properties: - `key` the key for this variable, you can use it to share the same value across activities, if not set it assumes the method name. - `title` the displayable name of the variable, if not set assumes `key` -- `defaultValue` the initial value, if not set assumes 0 or `minValue` if 0 is out of range. +- `initialValue` the initial value, if not set assumes 0 or `minValue` if 0 is out of range. - `minValue` the minimum value, if not set assumes 0 - `maxValue` the maximum value, if not set assumes 100 - `increment` the increment between two steps of the range, 1 by default. @@ -139,7 +139,7 @@ They support the following properties: A Range variable that goes from 15 to 70 and starts at 20 by default: ```java @RangeVariableMethod( - minValue = 15, maxValue = 70, defaultValue = 20) + minValue = 15, maxValue = 70, initialValue = 20) public void setFontSize(Integer fontSize) { } ``` @@ -151,12 +151,12 @@ They support the following properties: - `key` the key for this variable, you can use it to share the same value across activities, if not set it assumes the method name. - `title` the displayable name of the variable, if not set assumes `key` -- `defaultValue` the initial value, if not set assumes `false` +- `initialValue` the initial value, if not set assumes `false` - `layoutId` a layoutId to display this, must implement RemixerWidget. It assumes a sensible default if unset. -A Boolean variable that has true as a default value: +A Boolean variable that has true as its initial value: ```java -@BooleanVariableMethod(defaultValue = true, key = "someRemixerKey") +@BooleanVariableMethod(initialValue = true, key = "someRemixerKey") public void setUseNewDialog(Boolean useNewDialog) { } ``` @@ -168,7 +168,7 @@ They support the following properties: - `key` the key for this variable, you can use it to share the same value across activities, if not set it assumes the method name. - `title` the displayable name of the variable, if not set assumes `key` -- `defaultValue` the initial value, if not set assumes the first in the `possibleValues` list +- `initialValue` the initial value, if not set assumes the first in the `possibleValues` list - `possibleValues` the list of possible values. - `layoutId` a layoutId to display this, must implement RemixerWidget. It assumes a sensible default if unset. @@ -185,7 +185,7 @@ public void setTitleFont(String fontName) { - `key` the key for this variable, you can use it to share the same value across activities, if not set it assumes the method name. - `title` the displayable name of the variable, if not set assumes `key` -- `defaultValue` the initial value, if not set assumes the empty string. +- `initialValue` the initial value, if not set assumes the empty string. - `layoutId` a layoutId to display this, must implement RemixerWidget. It assumes a sensible default if unset. A String variable that sets freeform example text: @@ -199,7 +199,7 @@ public void setExampleText(String exampleText) { - `key` the key for this variable, you can use it to share the same value across activities, if not set it assumes the method name. - `title` the displayable name of the variable, if not set assumes `key` -- `defaultValue` the initial value, if not set assumes the first in the `possibleValues` list +- `initialValue` the initial value, if not set assumes the first in the `possibleValues` list - `possibleValues` the list of possible values. - `layoutId` a layoutId to display this, must implement RemixerWidget. It assumes a sensible default if unset. diff --git a/remixer_annotation/src/main/java/com/google/android/libraries/remixer/annotation/processor/ItemListVariableMethodAnnotation.java b/remixer_annotation/src/main/java/com/google/android/libraries/remixer/annotation/processor/ItemListVariableMethodAnnotation.java index 5558392..c76b2d5 100644 --- a/remixer_annotation/src/main/java/com/google/android/libraries/remixer/annotation/processor/ItemListVariableMethodAnnotation.java +++ b/remixer_annotation/src/main/java/com/google/android/libraries/remixer/annotation/processor/ItemListVariableMethodAnnotation.java @@ -37,18 +37,18 @@ class ItemListVariableMethodAnnotation extends MethodAnnotation { /** - * Suffix to add to the name of a list holding the possible values for this variable. + * Suffix to add to the name of a list holding the limited to values for this variable. */ private static final String LIST_SUFFIX = "_variable_list"; /** - * Statement format for String.format to add a value to the list of possible values. + * Statement format for String.format to add a value to the list of limited to values. */ private static final String ADD_ITEM_FORMAT = "$L.add(%s)"; /** - * Statement format for String.format to set the default value. + * Statement format for String.format to set the initial value. */ - private static final String SET_DEFAULT_FORMAT = "$L.setDefaultValue(%s)"; + private static final String SET_INITIAL_VALUE_FORMAT = "$L.setInitialValue(%s)"; /** * Javapoet format escaping for float values */ @@ -64,13 +64,13 @@ class ItemListVariableMethodAnnotation extends MethodAnnotation { /** * Statement to create an object through a no-parameter constructor. * - *

This is used to create the list of possible values ({@code ArrayList<T> list = + *

This is used to create the list of limited to values ({@code ArrayList<T> list = * new ArrayList<T>()}. */ private static final String CREATE_NEW_OBJECT = "$T $L = new $T()"; - private final T defaultValue; - private T[] possibleValues; + private final T initialValue; + private T[] limitedToValues; static ItemListVariableMethodAnnotation forStringListVariableMethod( TypeElement sourceClass, @@ -86,8 +86,8 @@ static ItemListVariableMethodAnnotation forStringListVariableMethod( annotation.key(), annotation.title(), annotation.layoutId(), - annotation.possibleValues(), - annotation.defaultValue(), + annotation.limitedToValues(), + annotation.initialValue(), ""); } @@ -96,9 +96,9 @@ static ItemListVariableMethodAnnotation forColorListVariableMethod( ExecutableElement sourceMethod, ColorListVariableMethod annotation) throws RemixerAnnotationException { - Integer[] possibleValues = new Integer[annotation.possibleValues().length]; - for (int i = 0; i < annotation.possibleValues().length; i++) { - possibleValues[i] = annotation.possibleValues()[i]; + Integer[] limitedToValues = new Integer[annotation.limitedToValues().length]; + for (int i = 0; i < annotation.limitedToValues().length; i++) { + limitedToValues[i] = annotation.limitedToValues()[i]; } return new ItemListVariableMethodAnnotation<>( sourceClass, @@ -109,8 +109,8 @@ static ItemListVariableMethodAnnotation forColorListVariableMethod( annotation.key(), annotation.title(), annotation.layoutId(), - possibleValues, - annotation.defaultValue(), + limitedToValues, + annotation.initialValue(), 0); } @@ -119,9 +119,9 @@ static ItemListVariableMethodAnnotation forNumberListVariableMethod( ExecutableElement sourceMethod, NumberListVariableMethod annotation) throws RemixerAnnotationException { - Float[] possibleValues = new Float[annotation.possibleValues().length]; - for (int i = 0; i < annotation.possibleValues().length; i++) { - possibleValues[i] = annotation.possibleValues()[i]; + Float[] limitedToValues = new Float[annotation.limitedToValues().length]; + for (int i = 0; i < annotation.limitedToValues().length; i++) { + limitedToValues[i] = annotation.limitedToValues()[i]; } return new ItemListVariableMethodAnnotation<>( sourceClass, @@ -132,8 +132,8 @@ static ItemListVariableMethodAnnotation forNumberListVariableMethod( annotation.key(), annotation.title(), annotation.layoutId(), - possibleValues, - annotation.defaultValue(), + limitedToValues, + annotation.initialValues(), 0f); } @@ -142,10 +142,10 @@ static ItemListVariableMethodAnnotation forNumberListVariableMethod( * annotations are met. * *

If the default is unset and the zero value (0 for numbers, empty string for Strings) is not - * amongst the possible values then it falls back to the first value in the list. + * amongst the limited to values then it falls back to the first value in the list. * * @throws RemixerAnnotationException if the constraints are not met: - * - The list of possible values is empty. + * - The list of limited to values is empty. * - The default is explicitly set to an unknown value. */ private ItemListVariableMethodAnnotation( @@ -156,34 +156,35 @@ private ItemListVariableMethodAnnotation( String key, String title, int layoutId, - T[] possibleValues, - T defaultValue, + T[] limitedToValues, + T initialValue, T zeroValue) throws RemixerAnnotationException { super(sourceClass, sourceMethod, dataType, builderTypeName, key, title, layoutId); - this.possibleValues = possibleValues; - if (possibleValues.length == 0) { - throw new RemixerAnnotationException(sourceMethod, "List of possible values cannot be empty"); + this.limitedToValues = limitedToValues; + if (limitedToValues.length == 0) { + throw new RemixerAnnotationException( + sourceMethod, "List of limited to values cannot be empty"); } boolean containsDefault = false; - for (T s : possibleValues) { - if (s.equals(defaultValue)) { + for (T s : limitedToValues) { + if (s.equals(initialValue)) { containsDefault = true; break; } } if (!containsDefault) { - if (defaultValue.equals(zeroValue)) { - // If no default value was set (empty) and the list of possible values doesn't contain the + if (initialValue.equals(zeroValue)) { + // If no initial value was set (empty) and the list of limited to values doesn't contain the // zero-value (empty string in case of string, 0 in case of numbers) then assume the first - // value in the list to be the default value. - this.defaultValue = possibleValues[0]; + // value in the list to be the initial value. + this.initialValue = limitedToValues[0]; } else { throw new RemixerAnnotationException(sourceMethod, - "Default value explicitly set to unknown value"); + "Initial value explicitly set to unknown value"); } } else { - this.defaultValue = defaultValue; + this.initialValue = initialValue; } } @@ -196,14 +197,14 @@ public void addSpecificSetupStatements(MethodSpec.Builder methodBuilder) { methodBuilder.addStatement(CREATE_NEW_OBJECT, listType, listName, listType); String addValueStatement = String.format(Locale.getDefault(), ADD_ITEM_FORMAT, getJavaPoetEscaping()); - for (T value : possibleValues) { + for (T value : limitedToValues) { methodBuilder.addStatement(addValueStatement, listName, value); } - methodBuilder.addStatement("$L.setPossibleValues($L)", remixerItemName, listName); + methodBuilder.addStatement("$L.setLimitedToValues($L)", remixerItemName, listName); - String setDefaultValueStatement = - String.format(Locale.getDefault(), SET_DEFAULT_FORMAT, getJavaPoetEscaping()); - methodBuilder.addStatement(setDefaultValueStatement, remixerItemName, defaultValue); + String setInitialValueStatement = + String.format(Locale.getDefault(), SET_INITIAL_VALUE_FORMAT, getJavaPoetEscaping()); + methodBuilder.addStatement(setInitialValueStatement, remixerItemName, initialValue); } private String getJavaPoetEscaping() { diff --git a/remixer_annotation/src/main/java/com/google/android/libraries/remixer/annotation/processor/RangeVariableMethodAnnotation.java b/remixer_annotation/src/main/java/com/google/android/libraries/remixer/annotation/processor/RangeVariableMethodAnnotation.java index e9df0af..bd7bca4 100644 --- a/remixer_annotation/src/main/java/com/google/android/libraries/remixer/annotation/processor/RangeVariableMethodAnnotation.java +++ b/remixer_annotation/src/main/java/com/google/android/libraries/remixer/annotation/processor/RangeVariableMethodAnnotation.java @@ -30,7 +30,7 @@ class RangeVariableMethodAnnotation extends MethodAnnotation { private final float minValue; - private float defaultValue; + private float initialValue; private final float increment; private final float maxValue; @@ -48,17 +48,17 @@ class RangeVariableMethodAnnotation extends MethodAnnotation { minValue = annotation.minValue(); maxValue = annotation.maxValue(); increment = annotation.increment(); - defaultValue = annotation.defaultValue(); + initialValue = annotation.initialValue(); if (minValue > maxValue) { throw new RemixerAnnotationException(sourceMethod, "minValue cannot be greater than maxValue"); } - if (minValue > annotation.defaultValue() || maxValue < annotation.defaultValue()) { - if (annotation.defaultValue() == 0) { - defaultValue = minValue; + if (minValue > annotation.initialValue() || maxValue < annotation.initialValue()) { + if (annotation.initialValue() == 0) { + initialValue = minValue; } else { throw new RemixerAnnotationException(sourceMethod, - "defaultValue was explicitly set out of bounds."); + "initialValue was explicitly set out of bounds."); } } } @@ -67,7 +67,7 @@ class RangeVariableMethodAnnotation extends MethodAnnotation { protected void addSpecificSetupStatements(MethodSpec.Builder methodBuilder) { methodBuilder.addStatement("$L.setMinValue($Lf)", remixerItemName, minValue); methodBuilder.addStatement("$L.setMaxValue($Lf)", remixerItemName, maxValue); - methodBuilder.addStatement("$L.setDefaultValue($Lf)", remixerItemName, defaultValue); + methodBuilder.addStatement("$L.setInitialValue($Lf)", remixerItemName, initialValue); methodBuilder.addStatement("$L.setIncrement($Lf)", remixerItemName, increment); } } diff --git a/remixer_annotation/src/main/java/com/google/android/libraries/remixer/annotation/processor/VariableMethodAnnotation.java b/remixer_annotation/src/main/java/com/google/android/libraries/remixer/annotation/processor/VariableMethodAnnotation.java index 7f8b96a..b08e79c 100644 --- a/remixer_annotation/src/main/java/com/google/android/libraries/remixer/annotation/processor/VariableMethodAnnotation.java +++ b/remixer_annotation/src/main/java/com/google/android/libraries/remixer/annotation/processor/VariableMethodAnnotation.java @@ -39,7 +39,7 @@ */ class VariableMethodAnnotation extends MethodAnnotation { - private final T defaultValue; + private final T initalValue; static VariableMethodAnnotation forBooleanVariableMethod( TypeElement sourceClass, ExecutableElement sourceMethod, BooleanVariableMethod annotation) @@ -52,7 +52,7 @@ static VariableMethodAnnotation forBooleanVariableMethod( annotation.key(), annotation.title(), annotation.layoutId(), - annotation.defaultValue()); + annotation.initialValue()); } static VariableMethodAnnotation forStringVariableMethod( @@ -66,7 +66,7 @@ static VariableMethodAnnotation forStringVariableMethod( annotation.key(), annotation.title(), annotation.layoutId(), - annotation.defaultValue()); + annotation.initialValue()); } private VariableMethodAnnotation( @@ -77,17 +77,17 @@ private VariableMethodAnnotation( String key, String title, int layoutId, - T defaultValue) + T initialValue) throws RemixerAnnotationException { super(sourceClass, sourceMethod, dataType, builderType, key, title, layoutId); - this.defaultValue = defaultValue; + this.initalValue = initialValue; } @Override protected void addSpecificSetupStatements(MethodSpec.Builder methodBuilder) { methodBuilder.addStatement( - defaultValue.getClass().equals(String.class) - ? "$L.setDefaultValue($S)" : "$L.setDefaultValue($L)", - remixerItemName, defaultValue); + initalValue.getClass().equals(String.class) + ? "$L.setInitialValue($S)" : "$L.setInitialValue($L)", + remixerItemName, initalValue); } } diff --git a/remixer_annotation/src/test/java/com/google/android/libraries/remixer/annotation/processor/ColorListVariableMethodAnnotationTest.java b/remixer_annotation/src/test/java/com/google/android/libraries/remixer/annotation/processor/ColorListVariableMethodAnnotationTest.java index 92ddf15..05c7256 100644 --- a/remixer_annotation/src/test/java/com/google/android/libraries/remixer/annotation/processor/ColorListVariableMethodAnnotationTest.java +++ b/remixer_annotation/src/test/java/com/google/android/libraries/remixer/annotation/processor/ColorListVariableMethodAnnotationTest.java @@ -60,7 +60,7 @@ public void failsExplicitWrongDefault() { .that(file) .processedWith(allProcessors) .failsToCompile() - .withErrorContaining("Default value explicitly set to unknown value") + .withErrorContaining("Initial value explicitly set to unknown value") .in(file); } @@ -72,7 +72,7 @@ public void failsEmptyList() { .that(file) .processedWith(allProcessors) .failsToCompile() - .withErrorContaining("List of possible values cannot be empty") + .withErrorContaining("List of limited to values cannot be empty") .in(file); } @@ -90,15 +90,15 @@ public void buildsCorrectColorList() { } @Test - public void buildsAndFixesDefaultValue() { + public void buildsAndFixesInitialValue() { JavaFileObject file = JavaFileObjects - .forResource("inputs/ColorListVariableMethodAnnotationTest/FixesDefaultValue.java"); + .forResource("inputs/ColorListVariableMethodAnnotationTest/FixesInitialValue.java"); Truth.assert_().about(JavaSourceSubjectFactory.javaSource()) .that(file) .processedWith(allProcessors) .compilesWithoutError() .and() .generatesSources(JavaFileObjects - .forResource("outputs/ColorListVariableMethodAnnotationTest/FixesDefaultValue.java")); + .forResource("outputs/ColorListVariableMethodAnnotationTest/FixesInitialValue.java")); } } diff --git a/remixer_annotation/src/test/java/com/google/android/libraries/remixer/annotation/processor/NumberListVariableMethodAnnotationTest.java b/remixer_annotation/src/test/java/com/google/android/libraries/remixer/annotation/processor/NumberListVariableMethodAnnotationTest.java index 79ecdbb..fbc645e 100644 --- a/remixer_annotation/src/test/java/com/google/android/libraries/remixer/annotation/processor/NumberListVariableMethodAnnotationTest.java +++ b/remixer_annotation/src/test/java/com/google/android/libraries/remixer/annotation/processor/NumberListVariableMethodAnnotationTest.java @@ -60,7 +60,7 @@ public void failsExplicitWrongDefault() { .that(file) .processedWith(allProcessors) .failsToCompile() - .withErrorContaining("Default value explicitly set to unknown value") + .withErrorContaining("Initial value explicitly set to unknown value") .in(file); } @@ -72,7 +72,7 @@ public void failsEmptyList() { .that(file) .processedWith(allProcessors) .failsToCompile() - .withErrorContaining("List of possible values cannot be empty") + .withErrorContaining("List of limited to values cannot be empty") .in(file); } @@ -90,15 +90,15 @@ public void buildsCorrectColorList() { } @Test - public void buildsAndFixesDefaultValue() { + public void buildsAndFixesInitialValue() { JavaFileObject file = JavaFileObjects - .forResource("inputs/NumberListVariableMethodAnnotationTest/FixesDefaultValue.java"); + .forResource("inputs/NumberListVariableMethodAnnotationTest/FixesInitialValue.java"); Truth.assert_().about(JavaSourceSubjectFactory.javaSource()) .that(file) .processedWith(allProcessors) .compilesWithoutError() .and() .generatesSources(JavaFileObjects - .forResource("outputs/NumberListVariableMethodAnnotationTest/FixesDefaultValue.java")); + .forResource("outputs/NumberListVariableMethodAnnotationTest/FixesInitialValue.java")); } } diff --git a/remixer_annotation/src/test/java/com/google/android/libraries/remixer/annotation/processor/RangeVariableMethodAnnotationTest.java b/remixer_annotation/src/test/java/com/google/android/libraries/remixer/annotation/processor/RangeVariableMethodAnnotationTest.java index 62e4d12..1fc2eaf 100644 --- a/remixer_annotation/src/test/java/com/google/android/libraries/remixer/annotation/processor/RangeVariableMethodAnnotationTest.java +++ b/remixer_annotation/src/test/java/com/google/android/libraries/remixer/annotation/processor/RangeVariableMethodAnnotationTest.java @@ -70,21 +70,21 @@ public void failsExplicitWrongDefault() { .that(file) .processedWith(allProcessors) .failsToCompile() - .withErrorContaining("defaultValue was explicitly set out of bounds") + .withErrorContaining("initialValue was explicitly set out of bounds") .in(file); } @Test - public void buildsAndFixesDefaultValue() { + public void buildsAndFixesInitialValue() { JavaFileObject file = JavaFileObjects - .forResource("inputs/RangeVariableMethodAnnotationTest/FixesDefaultValue.java"); + .forResource("inputs/RangeVariableMethodAnnotationTest/FixesInitialValue.java"); Truth.assert_().about(JavaSourceSubjectFactory.javaSource()) .that(file) .processedWith(allProcessors) .compilesWithoutError() .and() .generatesSources(JavaFileObjects - .forResource("outputs/RangeVariableMethodAnnotationTest/FixesDefaultValue.java")); + .forResource("outputs/RangeVariableMethodAnnotationTest/FixesInitialValue.java")); } @Test diff --git a/remixer_annotation/src/test/java/com/google/android/libraries/remixer/annotation/processor/StringListVariableMethodAnnotationTest.java b/remixer_annotation/src/test/java/com/google/android/libraries/remixer/annotation/processor/StringListVariableMethodAnnotationTest.java index 40ce6da..645f555 100644 --- a/remixer_annotation/src/test/java/com/google/android/libraries/remixer/annotation/processor/StringListVariableMethodAnnotationTest.java +++ b/remixer_annotation/src/test/java/com/google/android/libraries/remixer/annotation/processor/StringListVariableMethodAnnotationTest.java @@ -58,7 +58,7 @@ public void failsExplicitWrongDefault() { .that(file) .processedWith(allProcessors) .failsToCompile() - .withErrorContaining("Default value explicitly set to unknown value") + .withErrorContaining("Initial value explicitly set to unknown value") .in(file); } @@ -70,20 +70,20 @@ public void failsEmptyList() { .that(file) .processedWith(allProcessors) .failsToCompile() - .withErrorContaining("List of possible values cannot be empty") + .withErrorContaining("List of limited to values cannot be empty") .in(file); } @Test - public void buildsAndFixesDefaultValue() { + public void buildsAndFixesInitialValue() { JavaFileObject file = JavaFileObjects - .forResource("inputs/StringListVariableMethodAnnotationTest/FixesDefaultValue.java"); + .forResource("inputs/StringListVariableMethodAnnotationTest/FixesInitialValue.java"); Truth.assert_().about(JavaSourceSubjectFactory.javaSource()) .that(file) .processedWith(allProcessors) .compilesWithoutError() .and() .generatesSources(JavaFileObjects - .forResource("outputs/StringListVariableMethodAnnotationTest/FixesDefaultValue.java")); + .forResource("outputs/StringListVariableMethodAnnotationTest/FixesInitialValue.java")); } } diff --git a/remixer_annotation/src/test/resources/inputs/ColorListVariableMethodAnnotationTest/Correct.java b/remixer_annotation/src/test/resources/inputs/ColorListVariableMethodAnnotationTest/Correct.java index d2ef0a4..706db67 100644 --- a/remixer_annotation/src/test/resources/inputs/ColorListVariableMethodAnnotationTest/Correct.java +++ b/remixer_annotation/src/test/resources/inputs/ColorListVariableMethodAnnotationTest/Correct.java @@ -21,8 +21,8 @@ public class Correct { /** - * Default value is implicitly 0, this has to move to 1 + * Initial value is implicitly 0, this has to move to 1 */ - @ColorListVariableMethod(possibleValues = {1, 2}, defaultValue = 1) + @ColorListVariableMethod(limitedToValues = {1, 2}, initialValue = 1) public void setColor(Integer i){} } diff --git a/remixer_annotation/src/test/resources/inputs/ColorListVariableMethodAnnotationTest/EmptyList.java b/remixer_annotation/src/test/resources/inputs/ColorListVariableMethodAnnotationTest/EmptyList.java index 880ec80..d650935 100644 --- a/remixer_annotation/src/test/resources/inputs/ColorListVariableMethodAnnotationTest/EmptyList.java +++ b/remixer_annotation/src/test/resources/inputs/ColorListVariableMethodAnnotationTest/EmptyList.java @@ -22,6 +22,6 @@ public class EmptyList { /** * List is empty explicitly! Fail */ - @ColorListVariableMethod(possibleValues = {}) + @ColorListVariableMethod(limitedToValues = {}) public void fail(Integer i){} } diff --git a/remixer_annotation/src/test/resources/inputs/ColorListVariableMethodAnnotationTest/ExplicitWrongDefault.java b/remixer_annotation/src/test/resources/inputs/ColorListVariableMethodAnnotationTest/ExplicitWrongDefault.java index 51f7f63..822c653 100644 --- a/remixer_annotation/src/test/resources/inputs/ColorListVariableMethodAnnotationTest/ExplicitWrongDefault.java +++ b/remixer_annotation/src/test/resources/inputs/ColorListVariableMethodAnnotationTest/ExplicitWrongDefault.java @@ -21,8 +21,8 @@ public class ExplicitWrongDefault { /** - * Default value is explicitly out of range, should fail. + * Initial value is explicitly out of range, should fail. */ - @ColorListVariableMethod(defaultValue = 5, possibleValues = {2, 3}) + @ColorListVariableMethod(initialValue = 5, limitedToValues = {2, 3}) public void wrongDefault(Integer i){} } diff --git a/remixer_annotation/src/test/resources/inputs/ColorListVariableMethodAnnotationTest/FixesDefaultValue.java b/remixer_annotation/src/test/resources/inputs/ColorListVariableMethodAnnotationTest/FixesInitialValue.java similarity index 83% rename from remixer_annotation/src/test/resources/inputs/ColorListVariableMethodAnnotationTest/FixesDefaultValue.java rename to remixer_annotation/src/test/resources/inputs/ColorListVariableMethodAnnotationTest/FixesInitialValue.java index 712e662..fc77921 100644 --- a/remixer_annotation/src/test/resources/inputs/ColorListVariableMethodAnnotationTest/FixesDefaultValue.java +++ b/remixer_annotation/src/test/resources/inputs/ColorListVariableMethodAnnotationTest/FixesInitialValue.java @@ -18,11 +18,11 @@ import com.google.android.libraries.remixer.annotation.ColorListVariableMethod; -public class FixesDefaultValue { +public class FixesInitialValue { /** - * Default value is implicitly 0, this has to move to 1 + * Initial value is implicitly 0, this has to move to 1 */ - @ColorListVariableMethod(possibleValues = {1, 2}) + @ColorListVariableMethod(limitedToValues = {1, 2}) public void fixValue(Integer i){} } diff --git a/remixer_annotation/src/test/resources/inputs/ColorListVariableMethodAnnotationTest/MethodWithWrongParameter.java b/remixer_annotation/src/test/resources/inputs/ColorListVariableMethodAnnotationTest/MethodWithWrongParameter.java index 4df80cb..674f10c 100644 --- a/remixer_annotation/src/test/resources/inputs/ColorListVariableMethodAnnotationTest/MethodWithWrongParameter.java +++ b/remixer_annotation/src/test/resources/inputs/ColorListVariableMethodAnnotationTest/MethodWithWrongParameter.java @@ -22,6 +22,6 @@ public class MethodWithWrongParameter { /** * This method should take a string parameter, fail */ - @ColorListVariableMethod(possibleValues = {1, 2}) + @ColorListVariableMethod(limitedToValues = {1, 2}) public void fail(String i){} } diff --git a/remixer_annotation/src/test/resources/inputs/NumberListVariableMethodAnnotationTest/Correct.java b/remixer_annotation/src/test/resources/inputs/NumberListVariableMethodAnnotationTest/Correct.java index b8214be..b8090d7 100644 --- a/remixer_annotation/src/test/resources/inputs/NumberListVariableMethodAnnotationTest/Correct.java +++ b/remixer_annotation/src/test/resources/inputs/NumberListVariableMethodAnnotationTest/Correct.java @@ -21,8 +21,8 @@ public class Correct { /** - * Default value is implicitly 0, this has to move to 1 + * Initial value is implicitly 0, this has to move to 1 */ - @NumberListVariableMethod(possibleValues = {1, 2}, defaultValue = 1) + @NumberListVariableMethod(limitedToValues = {1, 2}, initialValues = 1) public void setNumber(Float i){} } diff --git a/remixer_annotation/src/test/resources/inputs/NumberListVariableMethodAnnotationTest/EmptyList.java b/remixer_annotation/src/test/resources/inputs/NumberListVariableMethodAnnotationTest/EmptyList.java index bff41f6..68b5340 100644 --- a/remixer_annotation/src/test/resources/inputs/NumberListVariableMethodAnnotationTest/EmptyList.java +++ b/remixer_annotation/src/test/resources/inputs/NumberListVariableMethodAnnotationTest/EmptyList.java @@ -22,6 +22,6 @@ public class EmptyList { /** * List is empty explicitly! Fail */ - @NumberListVariableMethod(possibleValues = {}) + @NumberListVariableMethod(limitedToValues = {}) public void fail(Float i){} } diff --git a/remixer_annotation/src/test/resources/inputs/NumberListVariableMethodAnnotationTest/ExplicitWrongDefault.java b/remixer_annotation/src/test/resources/inputs/NumberListVariableMethodAnnotationTest/ExplicitWrongDefault.java index ac982d2..3f0e189 100644 --- a/remixer_annotation/src/test/resources/inputs/NumberListVariableMethodAnnotationTest/ExplicitWrongDefault.java +++ b/remixer_annotation/src/test/resources/inputs/NumberListVariableMethodAnnotationTest/ExplicitWrongDefault.java @@ -21,8 +21,8 @@ public class ExplicitWrongDefault { /** - * Default value is explicitly out of range, should fail. + * Initial value is explicitly out of range, should fail. */ - @NumberListVariableMethod(defaultValue = 5, possibleValues = {2, 3}) + @NumberListVariableMethod(initialValues = 5, limitedToValues = {2, 3}) public void wrongDefault(Float i){} } diff --git a/remixer_annotation/src/test/resources/inputs/NumberListVariableMethodAnnotationTest/FixesDefaultValue.java b/remixer_annotation/src/test/resources/inputs/NumberListVariableMethodAnnotationTest/FixesInitialValue.java similarity index 83% rename from remixer_annotation/src/test/resources/inputs/NumberListVariableMethodAnnotationTest/FixesDefaultValue.java rename to remixer_annotation/src/test/resources/inputs/NumberListVariableMethodAnnotationTest/FixesInitialValue.java index 21abf7f..f4f54d6 100644 --- a/remixer_annotation/src/test/resources/inputs/NumberListVariableMethodAnnotationTest/FixesDefaultValue.java +++ b/remixer_annotation/src/test/resources/inputs/NumberListVariableMethodAnnotationTest/FixesInitialValue.java @@ -18,11 +18,11 @@ import com.google.android.libraries.remixer.annotation.NumberListVariableMethod; -public class FixesDefaultValue { +public class FixesInitialValue { /** - * Default value is implicitly 0, this has to move to 1 + * Initial value is implicitly 0, this has to move to 1 */ - @NumberListVariableMethod(possibleValues = {1, 2}) + @NumberListVariableMethod(limitedToValues = {1, 2}) public void fixValue(Float i){} } diff --git a/remixer_annotation/src/test/resources/inputs/NumberListVariableMethodAnnotationTest/MethodWithWrongParameter.java b/remixer_annotation/src/test/resources/inputs/NumberListVariableMethodAnnotationTest/MethodWithWrongParameter.java index 3445f37..ac8b8df 100644 --- a/remixer_annotation/src/test/resources/inputs/NumberListVariableMethodAnnotationTest/MethodWithWrongParameter.java +++ b/remixer_annotation/src/test/resources/inputs/NumberListVariableMethodAnnotationTest/MethodWithWrongParameter.java @@ -22,6 +22,6 @@ public class MethodWithWrongParameter { /** * This method should take a string parameter, fail */ - @NumberListVariableMethod(possibleValues = {1, 2}) + @NumberListVariableMethod(limitedToValues = {1, 2}) public void fail(String i){} } diff --git a/remixer_annotation/src/test/resources/inputs/RangeVariableMethodAnnotationTest/Correct.java b/remixer_annotation/src/test/resources/inputs/RangeVariableMethodAnnotationTest/Correct.java index a09f452..cfa0cfb 100644 --- a/remixer_annotation/src/test/resources/inputs/RangeVariableMethodAnnotationTest/Correct.java +++ b/remixer_annotation/src/test/resources/inputs/RangeVariableMethodAnnotationTest/Correct.java @@ -21,8 +21,8 @@ public class Correct { /** - * Default value is implicitly 0, this has to move to 15 with minValue. + * Initial value is implicitly 0, this has to move to 15 with minValue. */ - @RangeVariableMethod(minValue = 15, maxValue = 20, defaultValue = 17) + @RangeVariableMethod(minValue = 15, maxValue = 20, initialValue = 17) public void correct(Float i){} } diff --git a/remixer_annotation/src/test/resources/inputs/RangeVariableMethodAnnotationTest/ExplicitWrongDefault.java b/remixer_annotation/src/test/resources/inputs/RangeVariableMethodAnnotationTest/ExplicitWrongDefault.java index 11fe7af..79867d9 100644 --- a/remixer_annotation/src/test/resources/inputs/RangeVariableMethodAnnotationTest/ExplicitWrongDefault.java +++ b/remixer_annotation/src/test/resources/inputs/RangeVariableMethodAnnotationTest/ExplicitWrongDefault.java @@ -21,8 +21,8 @@ public class ExplicitWrongDefault { /** - * Default value is explicitly out of range, should fail. + * Initial value is explicitly out of range, should fail. */ - @RangeVariableMethod(defaultValue = -15) + @RangeVariableMethod(initialValue = -15) public void fixValue(Float i){} } diff --git a/remixer_annotation/src/test/resources/inputs/RangeVariableMethodAnnotationTest/FixesDefaultValue.java b/remixer_annotation/src/test/resources/inputs/RangeVariableMethodAnnotationTest/FixesInitialValue.java similarity index 89% rename from remixer_annotation/src/test/resources/inputs/RangeVariableMethodAnnotationTest/FixesDefaultValue.java rename to remixer_annotation/src/test/resources/inputs/RangeVariableMethodAnnotationTest/FixesInitialValue.java index b2058f6..eb7d3c5 100644 --- a/remixer_annotation/src/test/resources/inputs/RangeVariableMethodAnnotationTest/FixesDefaultValue.java +++ b/remixer_annotation/src/test/resources/inputs/RangeVariableMethodAnnotationTest/FixesInitialValue.java @@ -18,10 +18,10 @@ import com.google.android.libraries.remixer.annotation.RangeVariableMethod; -public class FixesDefaultValue { +public class FixesInitialValue { /** - * Default value is implicitly 0, this has to move to 15 with minValue. + * Initial value is implicitly 0, this has to move to 15 with minValue. */ @RangeVariableMethod(minValue = 15) public void fixValue(Float i){} diff --git a/remixer_annotation/src/test/resources/inputs/RemixerAnnotationProcessorTest/Correct.java b/remixer_annotation/src/test/resources/inputs/RemixerAnnotationProcessorTest/Correct.java index 160d4f6..a4ef472 100644 --- a/remixer_annotation/src/test/resources/inputs/RemixerAnnotationProcessorTest/Correct.java +++ b/remixer_annotation/src/test/resources/inputs/RemixerAnnotationProcessorTest/Correct.java @@ -31,10 +31,10 @@ public class Correct { @BooleanVariableMethod public void setBoolean(Boolean i) {} - @NumberListVariableMethod(possibleValues = {1, 2, 3}) + @NumberListVariableMethod(limitedToValues = {1, 2, 3}) public void setFloatList(Float i) {} - @ColorListVariableMethod(possibleValues = {1, 2, 3}) + @ColorListVariableMethod(limitedToValues = {1, 2, 3}) public void setColorList(Integer i) {} @RangeVariableMethod @@ -43,6 +43,6 @@ public void setFloat(Float i) {} @StringVariableMethod public void setString(String i) {} - @StringListVariableMethod(possibleValues = {"hello", "world"}) + @StringListVariableMethod(limitedToValues = {"hello", "world"}) public void setStringList(String i) {} } diff --git a/remixer_annotation/src/test/resources/inputs/StringListVariableMethodAnnotationTest/EmptyList.java b/remixer_annotation/src/test/resources/inputs/StringListVariableMethodAnnotationTest/EmptyList.java index e325885..6cbdc21 100644 --- a/remixer_annotation/src/test/resources/inputs/StringListVariableMethodAnnotationTest/EmptyList.java +++ b/remixer_annotation/src/test/resources/inputs/StringListVariableMethodAnnotationTest/EmptyList.java @@ -22,6 +22,6 @@ public class EmptyList { /** * List is empty explicitly! Fail */ - @StringListVariableMethod(possibleValues = {}) + @StringListVariableMethod(limitedToValues = {}) public void fail(String i){} } diff --git a/remixer_annotation/src/test/resources/inputs/StringListVariableMethodAnnotationTest/ExplicitWrongDefault.java b/remixer_annotation/src/test/resources/inputs/StringListVariableMethodAnnotationTest/ExplicitWrongDefault.java index 30a10a4..2911f03 100644 --- a/remixer_annotation/src/test/resources/inputs/StringListVariableMethodAnnotationTest/ExplicitWrongDefault.java +++ b/remixer_annotation/src/test/resources/inputs/StringListVariableMethodAnnotationTest/ExplicitWrongDefault.java @@ -20,8 +20,8 @@ public class ExplicitWrongDefault { /** - * Default value is explicitly out of range, should fail. + * Initial value is explicitly out of range, should fail. */ - @StringListVariableMethod(defaultValue = "adfjuh", possibleValues = {"hello", "world"}) + @StringListVariableMethod(initialValue = "adfjuh", limitedToValues = {"hello", "world"}) public void wrongDefault(String i){} } diff --git a/remixer_annotation/src/test/resources/inputs/StringListVariableMethodAnnotationTest/FixesDefaultValue.java b/remixer_annotation/src/test/resources/inputs/StringListVariableMethodAnnotationTest/FixesInitialValue.java similarity index 82% rename from remixer_annotation/src/test/resources/inputs/StringListVariableMethodAnnotationTest/FixesDefaultValue.java rename to remixer_annotation/src/test/resources/inputs/StringListVariableMethodAnnotationTest/FixesInitialValue.java index d780b8d..50adc6a 100644 --- a/remixer_annotation/src/test/resources/inputs/StringListVariableMethodAnnotationTest/FixesDefaultValue.java +++ b/remixer_annotation/src/test/resources/inputs/StringListVariableMethodAnnotationTest/FixesInitialValue.java @@ -18,10 +18,10 @@ import com.google.android.libraries.remixer.annotation.StringListVariableMethod; -public class FixesDefaultValue { +public class FixesInitialValue { /** - * Default value is implicitly "", this has to move to "hello" + * Initial value is implicitly "", this has to move to "hello" */ - @StringListVariableMethod(possibleValues = {"hello", "world"}) + @StringListVariableMethod(limitedToValues = {"hello", "world"}) public void fixValue(String i){} } diff --git a/remixer_annotation/src/test/resources/inputs/StringListVariableMethodAnnotationTest/MethodWithWrongParameter.java b/remixer_annotation/src/test/resources/inputs/StringListVariableMethodAnnotationTest/MethodWithWrongParameter.java index 3ca5431..35826fc 100644 --- a/remixer_annotation/src/test/resources/inputs/StringListVariableMethodAnnotationTest/MethodWithWrongParameter.java +++ b/remixer_annotation/src/test/resources/inputs/StringListVariableMethodAnnotationTest/MethodWithWrongParameter.java @@ -22,6 +22,6 @@ public class MethodWithWrongParameter { /** * This method should take a string parameter, fail */ - @StringListVariableMethod(possibleValues = {"hello","world"}) + @StringListVariableMethod(limitedToValues = {"hello","world"}) public void fail(Integer i){} } diff --git a/remixer_annotation/src/test/resources/outputs/BooleanVariableMethodAnnotationTest/Correct.java b/remixer_annotation/src/test/resources/outputs/BooleanVariableMethodAnnotationTest/Correct.java index c807bee..3a7c3fd 100644 --- a/remixer_annotation/src/test/resources/outputs/BooleanVariableMethodAnnotationTest/Correct.java +++ b/remixer_annotation/src/test/resources/outputs/BooleanVariableMethodAnnotationTest/Correct.java @@ -39,7 +39,7 @@ public void bindInstance(Correct activity) { correct_remixer_item.setLayoutId(0); correct_remixer_item.setContext(activity); correct_remixer_item.setCallback(correct_callback); - correct_remixer_item.setDefaultValue(false); + correct_remixer_item.setInitialValue(false); remixer.addItem(correct_remixer_item.build()); } diff --git a/remixer_annotation/src/test/resources/outputs/ColorListVariableMethodAnnotationTest/Correct.java b/remixer_annotation/src/test/resources/outputs/ColorListVariableMethodAnnotationTest/Correct.java index 55fdd70..4b6cf0a 100644 --- a/remixer_annotation/src/test/resources/outputs/ColorListVariableMethodAnnotationTest/Correct.java +++ b/remixer_annotation/src/test/resources/outputs/ColorListVariableMethodAnnotationTest/Correct.java @@ -42,8 +42,8 @@ public void bindInstance(Correct activity) { ArrayList setColor_variable_list = new ArrayList(); setColor_variable_list.add(1); setColor_variable_list.add(2); - setColor_remixer_item.setPossibleValues(setColor_variable_list); - setColor_remixer_item.setDefaultValue(1); + setColor_remixer_item.setLimitedToValues(setColor_variable_list); + setColor_remixer_item.setInitialValue(1); remixer.addItem(setColor_remixer_item.build()); } diff --git a/remixer_annotation/src/test/resources/outputs/ColorListVariableMethodAnnotationTest/FixesDefaultValue.java b/remixer_annotation/src/test/resources/outputs/ColorListVariableMethodAnnotationTest/FixesInitialValue.java similarity index 84% rename from remixer_annotation/src/test/resources/outputs/ColorListVariableMethodAnnotationTest/FixesDefaultValue.java rename to remixer_annotation/src/test/resources/outputs/ColorListVariableMethodAnnotationTest/FixesInitialValue.java index e941425..400d4d6 100644 --- a/remixer_annotation/src/test/resources/outputs/ColorListVariableMethodAnnotationTest/FixesDefaultValue.java +++ b/remixer_annotation/src/test/resources/outputs/ColorListVariableMethodAnnotationTest/FixesInitialValue.java @@ -27,9 +27,9 @@ /** * This class was generated by RemixerAnnotationProcessor */ -public class FixesDefaultValue_RemixerBinder implements RemixerBinder.Binder { +public class FixesInitialValue_RemixerBinder implements RemixerBinder.Binder { @Override - public void bindInstance(FixesDefaultValue activity) { + public void bindInstance(FixesInitialValue activity) { Remixer remixer = Remixer.getInstance(); Generated_fixValue fixValue_callback = new Generated_fixValue(activity); ItemListVariable.Builder fixValue_remixer_item = new ItemListVariable.Builder(); @@ -42,15 +42,15 @@ public void bindInstance(FixesDefaultValue activity) { ArrayList fixValue_variable_list = new ArrayList(); fixValue_variable_list.add(1); fixValue_variable_list.add(2); - fixValue_remixer_item.setPossibleValues(fixValue_variable_list); - fixValue_remixer_item.setDefaultValue(1); + fixValue_remixer_item.setLimitedToValues(fixValue_variable_list); + fixValue_remixer_item.setInitialValue(1); remixer.addItem(fixValue_remixer_item.build()); } static class Generated_fixValue implements Callback { - private final FixesDefaultValue activity; + private final FixesInitialValue activity; - Generated_fixValue(FixesDefaultValue activity) { + Generated_fixValue(FixesInitialValue activity) { this.activity = activity; } diff --git a/remixer_annotation/src/test/resources/outputs/NumberListVariableMethodAnnotationTest/Correct.java b/remixer_annotation/src/test/resources/outputs/NumberListVariableMethodAnnotationTest/Correct.java index 78dc346..f553da6 100644 --- a/remixer_annotation/src/test/resources/outputs/NumberListVariableMethodAnnotationTest/Correct.java +++ b/remixer_annotation/src/test/resources/outputs/NumberListVariableMethodAnnotationTest/Correct.java @@ -42,8 +42,8 @@ public void bindInstance(Correct activity) { ArrayList setNumber_variable_list = new ArrayList(); setNumber_variable_list.add(1f); setNumber_variable_list.add(2f); - setNumber_remixer_item.setPossibleValues(setNumber_variable_list); - setNumber_remixer_item.setDefaultValue(1f); + setNumber_remixer_item.setLimitedToValues(setNumber_variable_list); + setNumber_remixer_item.setInitialValue(1f); remixer.addItem(setNumber_remixer_item.build()); } diff --git a/remixer_annotation/src/test/resources/outputs/NumberListVariableMethodAnnotationTest/FixesDefaultValue.java b/remixer_annotation/src/test/resources/outputs/NumberListVariableMethodAnnotationTest/FixesInitialValue.java similarity index 84% rename from remixer_annotation/src/test/resources/outputs/NumberListVariableMethodAnnotationTest/FixesDefaultValue.java rename to remixer_annotation/src/test/resources/outputs/NumberListVariableMethodAnnotationTest/FixesInitialValue.java index 839ca23..762def4 100644 --- a/remixer_annotation/src/test/resources/outputs/NumberListVariableMethodAnnotationTest/FixesDefaultValue.java +++ b/remixer_annotation/src/test/resources/outputs/NumberListVariableMethodAnnotationTest/FixesInitialValue.java @@ -27,9 +27,9 @@ /** * This class was generated by RemixerAnnotationProcessor */ -public class FixesDefaultValue_RemixerBinder implements RemixerBinder.Binder { +public class FixesInitialValue_RemixerBinder implements RemixerBinder.Binder { @Override - public void bindInstance(FixesDefaultValue activity) { + public void bindInstance(FixesInitialValue activity) { Remixer remixer = Remixer.getInstance(); Generated_fixValue fixValue_callback = new Generated_fixValue(activity); ItemListVariable.Builder fixValue_remixer_item = new ItemListVariable.Builder(); @@ -42,15 +42,15 @@ public void bindInstance(FixesDefaultValue activity) { ArrayList fixValue_variable_list = new ArrayList(); fixValue_variable_list.add(1f); fixValue_variable_list.add(2f); - fixValue_remixer_item.setPossibleValues(fixValue_variable_list); - fixValue_remixer_item.setDefaultValue(1f); + fixValue_remixer_item.setLimitedToValues(fixValue_variable_list); + fixValue_remixer_item.setInitialValue(1f); remixer.addItem(fixValue_remixer_item.build()); } static class Generated_fixValue implements Callback { - private final FixesDefaultValue activity; + private final FixesInitialValue activity; - Generated_fixValue(FixesDefaultValue activity) { + Generated_fixValue(FixesInitialValue activity) { this.activity = activity; } diff --git a/remixer_annotation/src/test/resources/outputs/RangeVariableMethodAnnotationTest/Correct.java b/remixer_annotation/src/test/resources/outputs/RangeVariableMethodAnnotationTest/Correct.java index dc5ece8..1dc0ef8 100644 --- a/remixer_annotation/src/test/resources/outputs/RangeVariableMethodAnnotationTest/Correct.java +++ b/remixer_annotation/src/test/resources/outputs/RangeVariableMethodAnnotationTest/Correct.java @@ -40,7 +40,7 @@ public void bindInstance(Correct activity) { correct_remixer_item.setCallback(correct_callback); correct_remixer_item.setMinValue(15f); correct_remixer_item.setMaxValue(20f); - correct_remixer_item.setDefaultValue(17f); + correct_remixer_item.setInitialValue(17f); correct_remixer_item.setIncrement(1f); remixer.addItem(correct_remixer_item.build()); } diff --git a/remixer_annotation/src/test/resources/outputs/RangeVariableMethodAnnotationTest/FixesDefaultValue.java b/remixer_annotation/src/test/resources/outputs/RangeVariableMethodAnnotationTest/FixesInitialValue.java similarity index 86% rename from remixer_annotation/src/test/resources/outputs/RangeVariableMethodAnnotationTest/FixesDefaultValue.java rename to remixer_annotation/src/test/resources/outputs/RangeVariableMethodAnnotationTest/FixesInitialValue.java index 47d637e..deba52b 100644 --- a/remixer_annotation/src/test/resources/outputs/RangeVariableMethodAnnotationTest/FixesDefaultValue.java +++ b/remixer_annotation/src/test/resources/outputs/RangeVariableMethodAnnotationTest/FixesInitialValue.java @@ -26,9 +26,9 @@ /** * This class was generated by RemixerAnnotationProcessor */ -public class FixesDefaultValue_RemixerBinder implements RemixerBinder.Binder { +public class FixesInitialValue_RemixerBinder implements RemixerBinder.Binder { @Override - public void bindInstance(FixesDefaultValue activity) { + public void bindInstance(FixesInitialValue activity) { Remixer remixer = Remixer.getInstance(); Generated_fixValue fixValue_callback = new Generated_fixValue(activity); RangeVariable.Builder fixValue_remixer_item = new RangeVariable.Builder(); @@ -40,15 +40,15 @@ public void bindInstance(FixesDefaultValue activity) { fixValue_remixer_item.setCallback(fixValue_callback); fixValue_remixer_item.setMinValue(15f); fixValue_remixer_item.setMaxValue(100f); - fixValue_remixer_item.setDefaultValue(15f); + fixValue_remixer_item.setInitialValue(15f); fixValue_remixer_item.setIncrement(1f); remixer.addItem(fixValue_remixer_item.build()); } static class Generated_fixValue implements Callback { - private final FixesDefaultValue activity; + private final FixesInitialValue activity; - Generated_fixValue(FixesDefaultValue activity) { + Generated_fixValue(FixesInitialValue activity) { this.activity = activity; } diff --git a/remixer_annotation/src/test/resources/outputs/RemixerAnnotationProcessorTest/Correct.java b/remixer_annotation/src/test/resources/outputs/RemixerAnnotationProcessorTest/Correct.java index 7b38573..883ca51 100644 --- a/remixer_annotation/src/test/resources/outputs/RemixerAnnotationProcessorTest/Correct.java +++ b/remixer_annotation/src/test/resources/outputs/RemixerAnnotationProcessorTest/Correct.java @@ -45,7 +45,7 @@ public void bindInstance(Correct activity) { setBoolean_remixer_item.setLayoutId(0); setBoolean_remixer_item.setContext(activity); setBoolean_remixer_item.setCallback(setBoolean_callback); - setBoolean_remixer_item.setDefaultValue(false); + setBoolean_remixer_item.setInitialValue(false); remixer.addItem(setBoolean_remixer_item.build()); Generated_setFloatList setFloatList_callback = new Generated_setFloatList(activity); ItemListVariable.Builder setFloatList_remixer_item = new ItemListVariable.Builder(); @@ -59,8 +59,8 @@ public void bindInstance(Correct activity) { setFloatList_variable_list.add(1f); setFloatList_variable_list.add(2f); setFloatList_variable_list.add(3f); - setFloatList_remixer_item.setPossibleValues(setFloatList_variable_list); - setFloatList_remixer_item.setDefaultValue(1f); + setFloatList_remixer_item.setLimitedToValues(setFloatList_variable_list); + setFloatList_remixer_item.setInitialValue(1f); remixer.addItem(setFloatList_remixer_item.build()); Generated_setColorList setColorList_callback = new Generated_setColorList(activity); ItemListVariable.Builder setColorList_remixer_item = new ItemListVariable.Builder(); @@ -74,8 +74,8 @@ public void bindInstance(Correct activity) { setColorList_variable_list.add(1); setColorList_variable_list.add(2); setColorList_variable_list.add(3); - setColorList_remixer_item.setPossibleValues(setColorList_variable_list); - setColorList_remixer_item.setDefaultValue(1); + setColorList_remixer_item.setLimitedToValues(setColorList_variable_list); + setColorList_remixer_item.setInitialValue(1); remixer.addItem(setColorList_remixer_item.build()); Generated_setFloat setFloat_callback = new Generated_setFloat(activity); RangeVariable.Builder setFloat_remixer_item = new RangeVariable.Builder(); @@ -87,7 +87,7 @@ public void bindInstance(Correct activity) { setFloat_remixer_item.setCallback(setFloat_callback); setFloat_remixer_item.setMinValue(0f); setFloat_remixer_item.setMaxValue(100f); - setFloat_remixer_item.setDefaultValue(0f); + setFloat_remixer_item.setInitialValue(0f); setFloat_remixer_item.setIncrement(1f); remixer.addItem(setFloat_remixer_item.build()); Generated_setString setString_callback = new Generated_setString(activity); @@ -98,7 +98,7 @@ public void bindInstance(Correct activity) { setString_remixer_item.setLayoutId(0); setString_remixer_item.setContext(activity); setString_remixer_item.setCallback(setString_callback); - setString_remixer_item.setDefaultValue(""); + setString_remixer_item.setInitialValue(""); remixer.addItem(setString_remixer_item.build()); Generated_setStringList setStringList_callback = new Generated_setStringList(activity); ItemListVariable.Builder setStringList_remixer_item = new ItemListVariable.Builder(); @@ -111,8 +111,8 @@ public void bindInstance(Correct activity) { ArrayList setStringList_variable_list = new ArrayList(); setStringList_variable_list.add("hello"); setStringList_variable_list.add("world"); - setStringList_remixer_item.setPossibleValues(setStringList_variable_list); - setStringList_remixer_item.setDefaultValue("hello"); + setStringList_remixer_item.setLimitedToValues(setStringList_variable_list); + setStringList_remixer_item.setInitialValue("hello"); remixer.addItem(setStringList_remixer_item.build()); } diff --git a/remixer_annotation/src/test/resources/outputs/StringListVariableMethodAnnotationTest/FixesDefaultValue.java b/remixer_annotation/src/test/resources/outputs/StringListVariableMethodAnnotationTest/FixesInitialValue.java similarity index 84% rename from remixer_annotation/src/test/resources/outputs/StringListVariableMethodAnnotationTest/FixesDefaultValue.java rename to remixer_annotation/src/test/resources/outputs/StringListVariableMethodAnnotationTest/FixesInitialValue.java index f0c5be2..78a99c8 100644 --- a/remixer_annotation/src/test/resources/outputs/StringListVariableMethodAnnotationTest/FixesDefaultValue.java +++ b/remixer_annotation/src/test/resources/outputs/StringListVariableMethodAnnotationTest/FixesInitialValue.java @@ -27,9 +27,9 @@ /** * This class was generated by RemixerAnnotationProcessor */ -public class FixesDefaultValue_RemixerBinder implements RemixerBinder.Binder { +public class FixesInitialValue_RemixerBinder implements RemixerBinder.Binder { @Override - public void bindInstance(FixesDefaultValue activity) { + public void bindInstance(FixesInitialValue activity) { Remixer remixer = Remixer.getInstance(); Generated_fixValue fixValue_callback = new Generated_fixValue(activity); ItemListVariable.Builder fixValue_remixer_item = new ItemListVariable.Builder(); @@ -42,15 +42,15 @@ public void bindInstance(FixesDefaultValue activity) { ArrayList fixValue_variable_list = new ArrayList(); fixValue_variable_list.add("hello"); fixValue_variable_list.add("world"); - fixValue_remixer_item.setPossibleValues(fixValue_variable_list); - fixValue_remixer_item.setDefaultValue("hello"); + fixValue_remixer_item.setLimitedToValues(fixValue_variable_list); + fixValue_remixer_item.setInitialValue("hello"); remixer.addItem(fixValue_remixer_item.build()); } static class Generated_fixValue implements Callback { - private final FixesDefaultValue activity; + private final FixesInitialValue activity; - Generated_fixValue(FixesDefaultValue activity) { + Generated_fixValue(FixesInitialValue activity) { this.activity = activity; } diff --git a/remixer_annotation/src/test/resources/outputs/StringVariableMethodAnnotationTest/Correct.java b/remixer_annotation/src/test/resources/outputs/StringVariableMethodAnnotationTest/Correct.java index 9de1efd..859f225 100644 --- a/remixer_annotation/src/test/resources/outputs/StringVariableMethodAnnotationTest/Correct.java +++ b/remixer_annotation/src/test/resources/outputs/StringVariableMethodAnnotationTest/Correct.java @@ -38,7 +38,7 @@ public void bindInstance(Correct activity) { correct_remixer_item.setLayoutId(0); correct_remixer_item.setContext(activity); correct_remixer_item.setCallback(correct_callback); - correct_remixer_item.setDefaultValue(""); + correct_remixer_item.setInitialValue(""); remixer.addItem(correct_remixer_item.build()); } diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/BaseVariableBuilder.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/BaseVariableBuilder.java index 5d17c53..a551006 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/BaseVariableBuilder.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/BaseVariableBuilder.java @@ -22,7 +22,7 @@ * @param The type of data stored in the variable. */ public abstract class BaseVariableBuilder { - protected T defaultValue; + protected T initialValue; protected String key; protected String title; protected Object context; @@ -60,8 +60,8 @@ public BaseVariableBuilder setDataType(DataType dataType) { return this; } - public BaseVariableBuilder setDefaultValue(T defaultValue) { - this.defaultValue = defaultValue; + public BaseVariableBuilder setInitialValue(T initialValue) { + this.initialValue = initialValue; return this; } diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/BooleanVariableBuilder.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/BooleanVariableBuilder.java index 0811fe4..d383c70 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/BooleanVariableBuilder.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/BooleanVariableBuilder.java @@ -17,12 +17,12 @@ package com.google.android.libraries.remixer; /** - * Convenience builder for Variable<Boolean> that assumes false to be the default value. + * Convenience builder for Variable<Boolean> that assumes false to be the initial value. */ public class BooleanVariableBuilder extends Variable.Builder { public BooleanVariableBuilder() { - setDefaultValue(false); + setInitialValue(false); setDataType(DataType.BOOLEAN); } diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/ItemListVariable.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/ItemListVariable.java index 7cabc7c..1a28fc3 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/ItemListVariable.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/ItemListVariable.java @@ -27,7 +27,7 @@ */ public class ItemListVariable extends Variable { - private final List valueList; + private final List limitedToValues; /** * Creates a new ItemListVariable, checks its default value and runs the callback if the value is @@ -35,8 +35,8 @@ public class ItemListVariable extends Variable { * * @param title Displayable name for this Variable. * @param key The key used to store this Variable. - * @param defaultValue The default value to use if none has been set. - * @param values List of valid values. + * @param initialValue The default value to use if none has been set. + * @param limitedToValues List of valid values that this variable is limited to take. * @param context the object which created this variable, should be an activity. * @param callback Callback to run once the value is set. Can be null. * @param layoutId A layout id that renders this control on screen. @@ -45,26 +45,26 @@ public class ItemListVariable extends Variable { private ItemListVariable( String title, String key, - T defaultValue, - List values, + T initialValue, + List limitedToValues, Object context, Callback callback, int layoutId, DataType dataType) { - super(title, key, defaultValue, context, callback, layoutId, dataType); - this.valueList = values; + super(title, key, initialValue, context, callback, layoutId, dataType); + this.limitedToValues = limitedToValues; } @Override protected void checkValue(T value) { - if (!valueList.contains(value)) { + if (!limitedToValues.contains(value)) { throw new IllegalArgumentException( String.format("%s is not a valid value for Variable %s", value, getKey())); } } - public List getValueList() { - return valueList; + public List getLimitedToValues() { + return limitedToValues; } /** @@ -82,20 +82,20 @@ public String getSerializableConstraints() { * set, the default layout will be used.

  • If the title is not set, the key will be used as * title * - *

    On the other hand: key, dataType, context, and possibleValues are mandatory. If either is + *

    On the other hand: key, dataType, context, and limitedToValues are mandatory. If either is * missing, an {@link IllegalArgumentException} will be thrown. */ public static class Builder extends BaseVariableBuilder, T> { - private List possibleValues; + private List limitedToValues; - public Builder setPossibleValues(List possibleValues) { - this.possibleValues = possibleValues; + public Builder setLimitedToValues(List limitedToValues) { + this.limitedToValues = limitedToValues; return this; } - public Builder setPossibleValues(T[] possibleValues) { - this.possibleValues = Arrays.asList(possibleValues); + public Builder setLimitedToValues(T[] limitedToValues) { + this.limitedToValues = Arrays.asList(limitedToValues); return this; } @@ -103,21 +103,21 @@ public Builder setPossibleValues(T[] possibleValues) { * Returns a new ItemListVariable created with the configuration stored in this builder * instance. * - * @throws IllegalArgumentException If key or possibleValues are missing or if the configuration + * @throws IllegalArgumentException If key or limitedToValues are missing or if the configuration * is invalid for ItemListVariable. */ @Override public ItemListVariable build() { checkBaseFields(); - if (possibleValues == null || possibleValues.isEmpty()) { + if (limitedToValues == null || limitedToValues.isEmpty()) { throw new IllegalArgumentException( - "possibleValues cannot be unset or empty for ItemListVariable"); + "limitedToValues cannot be unset or empty for ItemListVariable"); } - if (defaultValue == null) { - defaultValue = possibleValues.get(0); + if (initialValue == null) { + initialValue = limitedToValues.get(0); } ItemListVariable variable = new ItemListVariable( - title, key, defaultValue, possibleValues, context, callback, layoutId, dataType); + title, key, initialValue, limitedToValues, context, callback, layoutId, dataType); variable.init(); return variable; } diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/RangeVariable.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/RangeVariable.java index 3393e52..143fcb5 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/RangeVariable.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/RangeVariable.java @@ -42,12 +42,12 @@ public class RangeVariable extends Variable { private final float increment; /** - * Constructor that checks correctness of the range, validates {@code defaultValue} and runs + * Constructor that checks correctness of the range, validates {@code initialValue} and runs * {@code callback}. * * @param title The name of this variable to be displayed in the UI. * @param key The key to store in SharedPreferences. - * @param defaultValue The default value in case there is none in SharedPreferences. + * @param initialValue The initial value for this variable. * @param minValue The minimum value for this variable. * @param maxValue The maximum value for this variable. * @param increment A value that defines each step. Must be a positive integer. So if you have @@ -64,14 +64,14 @@ public class RangeVariable extends Variable { private RangeVariable( String title, String key, - float defaultValue, + float initialValue, float minValue, float maxValue, float increment, Object context, Callback callback, int layoutId) { - super(title, key, defaultValue, context, callback, layoutId, DataType.NUMBER); + super(title, key, initialValue, context, callback, layoutId, DataType.NUMBER); this.minValue = minValue; this.maxValue = maxValue; this.increment = increment; @@ -202,12 +202,12 @@ public RangeVariable build() { if (minValue == null || maxValue == null) { throw new IllegalArgumentException("minValue and maxValue must not be null"); } - if (defaultValue == null) { - defaultValue = minValue; + if (initialValue == null) { + initialValue = minValue; } checkBaseFields(); RangeVariable variable = new RangeVariable( - title, key, defaultValue, minValue, maxValue, increment, context, callback, + title, key, initialValue, minValue, maxValue, increment, context, callback, layoutId); variable.init(); return variable; diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/StringVariableBuilder.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/StringVariableBuilder.java index f64adc7..aa4d2e0 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/StringVariableBuilder.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/StringVariableBuilder.java @@ -23,7 +23,7 @@ public class StringVariableBuilder extends Variable.Builder { public StringVariableBuilder() { - setDefaultValue(""); + setInitialValue(""); setDataType(DataType.STRING); } diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/Variable.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/Variable.java index 7e56413..8f715b0 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/Variable.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/Variable.java @@ -68,19 +68,16 @@ public class Variable { * @param key The key to use to save to SharedPreferences. This needs to be unique across all * Remixes. * @param title The name to display in the UI. - * @param defaultValue The default value for this Variable. + * @param initialValue The initial value for this Variable. * @param context the object which created this variable, should be an activity. * @param callback A callback to execute when the value is updated. Can be {@code null}. * @param layoutId A layout to inflate when displaying this Variable in the UI. * @param dataType The data type this variable contains. */ - // TODO(miguely): Add default value semantics to the defaultValue, currently it behaves mostly - // as an initial value. It should be used in cases when the value is set to an invalid value from - // SharedPreferences or Firebase. protected Variable( String title, String key, - T defaultValue, + T initialValue, Object context, Callback callback, int layoutId, @@ -90,7 +87,7 @@ protected Variable( this.context = new WeakReference<>(context); this.layoutId = layoutId; this.dataType = dataType; - this.selectedValue = defaultValue; + this.selectedValue = initialValue; this.callback = callback; } @@ -228,7 +225,7 @@ public static class Builder extends BaseVariableBuilder, T> { public Variable build() { checkBaseFields(); Variable variable = - new Variable(title, key, defaultValue, context, callback, layoutId, dataType); + new Variable(title, key, initialValue, context, callback, layoutId, dataType); variable.init(); return variable; } diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/BooleanVariableMethod.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/BooleanVariableMethod.java index 1ee2e3d..dab2fce 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/BooleanVariableMethod.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/BooleanVariableMethod.java @@ -44,9 +44,9 @@ String title() default ""; /** - * The default value for this variable, assumes false as default. + * The initial value for this variable, assumes false as if unset. */ - boolean defaultValue() default false; + boolean initialValue() default false; /** * The layout id to inflate when displaying this Variable. If not specified a default will be diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/ColorListVariableMethod.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/ColorListVariableMethod.java index 17a1ed4..ad5bb8a 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/ColorListVariableMethod.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/ColorListVariableMethod.java @@ -49,17 +49,17 @@ String title() default ""; /** - * The default value for this variable, assumes 0 as default. + * The initial value for this variable, assumes 0 as default. * *

    If left unspecified and the empty string is not part of the possible values, then the first * value in the list of possible values is assumed as default. */ - int defaultValue() default 0; + int initialValue() default 0; /** * List of possible values for this ItemListVariable<String>. */ - int[] possibleValues() default {0}; + int[] limitedToValues() default {0}; /** * The layout id to inflate when displaying this Variable. If not specified a default will be diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/NumberListVariableMethod.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/NumberListVariableMethod.java index 91d2c67..f2bf8d3 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/NumberListVariableMethod.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/NumberListVariableMethod.java @@ -49,17 +49,17 @@ String title() default ""; /** - * The default value for this variable, assumes 0 as default. + * The initial value for this variable, assumes 0 as default. * *

    If left unspecified and the empty string is not part of the possible values, then the first * value in the list of possible values is assumed as default. */ - float defaultValue() default 0; + float initialValues() default 0; /** * List of possible values for this ItemListVariable<String>. */ - float[] possibleValues() default {0}; + float[] limitedToValues() default {0}; /** * The layout id to inflate when displaying this Variable. If not specified a default will be diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/RangeVariableMethod.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/RangeVariableMethod.java index 04b0cf5..28d761e 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/RangeVariableMethod.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/RangeVariableMethod.java @@ -48,12 +48,12 @@ String title() default ""; /** - * The default value for this variable. + * The initial value for this variable. * *

    If left unspecified (0) and it is out of bounds, it will default to minValue, for * convenience. */ - float defaultValue() default 0; + float initialValue() default 0; /** * The minimum value for this RangeVariable. It is 0 by default. diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/StringListVariableMethod.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/StringListVariableMethod.java index f724b98..c1db512 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/StringListVariableMethod.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/StringListVariableMethod.java @@ -48,17 +48,17 @@ String title() default ""; /** - * The default value for this variable, assumes "" as default. + * The initial value for this variable, assumes "" as default. * *

    If left unspecified and the empty string is not part of the possible values, then the first * value in the list of possible values is assumed as default. */ - String defaultValue() default ""; + String initialValue() default ""; /** * List of possible values for this ItemListVariable<String>. */ - String[] possibleValues() default {""}; + String[] limitedToValues() default {""}; /** * The layout id to inflate when displaying this Variable. If not specified a default will be diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/StringVariableMethod.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/StringVariableMethod.java index 57f97b7..120c6c0 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/StringVariableMethod.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/StringVariableMethod.java @@ -44,9 +44,9 @@ String title() default ""; /** - * The default value for this variable, assumes false as default. + * The initial value for this variable, assumes false as default. */ - String defaultValue() default ""; + String initialValue() default ""; /** * The layout id to inflate when displaying this Variable. If not specified a default will be diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/StoredVariable.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/StoredVariable.java index d038916..0ff0884 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/StoredVariable.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/StoredVariable.java @@ -58,7 +58,7 @@ public class StoredVariable { static final String CONSTRAINT_TYPE = "constraintType"; static final String DATA_TYPE = "dataType"; static final String SELECTED_VALUE = "selectedValue"; - static final String POSSIBLE_VALUES = "possibleValues"; + static final String POSSIBLE_VALUES = "limitedToValues"; static final String MIN_VALUE = "minValue"; static final String MAX_VALUE = "maxValue"; static final String INCREMENT = "increment"; diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/ColorValueConverter.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/ColorValueConverter.java index c55f7dd..ad45b26 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/ColorValueConverter.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/ColorValueConverter.java @@ -65,7 +65,7 @@ public StoredVariable fromVariable(Variable var) { storage.setDataType(dataType); storage.setSelectedValue((Integer) var.getSelectedValue()); if (var instanceof ItemListVariable) { - storage.setPossibleValues(((ItemListVariable) var).getValueList()); + storage.setPossibleValues(((ItemListVariable) var).getLimitedToValues()); } return storage; } diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/FloatValueConverter.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/FloatValueConverter.java index 6e1f9f8..23f1df9 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/FloatValueConverter.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/FloatValueConverter.java @@ -40,7 +40,7 @@ public StoredVariable fromVariable(Variable var) { storage.setMaxValue(range.getMaxValue()); storage.setIncrement(range.getIncrement()); } else if (var instanceof ItemListVariable) { - storage.setPossibleValues(((ItemListVariable) var).getValueList()); + storage.setPossibleValues(((ItemListVariable) var).getLimitedToValues()); } return storage; } diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/StringValueConverter.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/StringValueConverter.java index c65dfe8..4dd2562 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/StringValueConverter.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/StringValueConverter.java @@ -34,7 +34,7 @@ public StoredVariable fromVariable(Variable var) { storage.setDataType(dataType); storage.setSelectedValue((String) var.getSelectedValue()); if (var instanceof ItemListVariable) { - storage.setPossibleValues(((ItemListVariable) var).getValueList()); + storage.setPossibleValues(((ItemListVariable) var).getLimitedToValues()); } return storage; } diff --git a/remixer_core/src/test/java/com/google/android/libraries/remixer/ItemListVariableTest.java b/remixer_core/src/test/java/com/google/android/libraries/remixer/ItemListVariableTest.java index 091d0e0..ad61b48 100644 --- a/remixer_core/src/test/java/com/google/android/libraries/remixer/ItemListVariableTest.java +++ b/remixer_core/src/test/java/com/google/android/libraries/remixer/ItemListVariableTest.java @@ -38,8 +38,8 @@ public void setUp() { MockitoAnnotations.initMocks(this); correctVariableWithCallback = new ItemListVariable.Builder() - .setPossibleValues(Arrays.asList("A", "B")) - .setDefaultValue("A") + .setLimitedToValues(Arrays.asList("A", "B")) + .setInitialValue("A") .setKey("key") .setContext(this) .setCallback(mockCallback) @@ -48,11 +48,11 @@ public void setUp() { } @Test(expected = IllegalArgumentException.class) - public void initFailsOnDefaultValueNotInList() { + public void initFailsOnInitialValueNotInList() { Variable variable = new ItemListVariable.Builder() - .setPossibleValues(Arrays.asList("Some", "possible", "values")) - .setDefaultValue("Something else") + .setLimitedToValues(Arrays.asList("Some", "possible", "values")) + .setInitialValue("Something else") .setKey("key") .setContext(this) .setDataType(DataType.STRING) @@ -79,8 +79,8 @@ public void setValueCallsCallback() { public void doesNotCrashOnNullCallback() { Variable variable = new ItemListVariable.Builder() - .setPossibleValues(Arrays.asList("A", "B")) - .setDefaultValue("A") + .setLimitedToValues(Arrays.asList("A", "B")) + .setInitialValue("A") .setKey("key") .setContext(this) .setDataType(DataType.STRING) diff --git a/remixer_core/src/test/java/com/google/android/libraries/remixer/RangeVariableTest.java b/remixer_core/src/test/java/com/google/android/libraries/remixer/RangeVariableTest.java index 5930675..93ad5ff 100644 --- a/remixer_core/src/test/java/com/google/android/libraries/remixer/RangeVariableTest.java +++ b/remixer_core/src/test/java/com/google/android/libraries/remixer/RangeVariableTest.java @@ -46,7 +46,7 @@ public void setUp() { .setMinValue(0f) .setMaxValue(20f) .setIncrement(1f) - .setDefaultValue(15f) + .setInitialValue(15f) .setCallback(singleIncrementsCallback) .setKey("key") .setContext(this) @@ -56,7 +56,7 @@ public void setUp() { .setMinValue(0f) .setMaxValue(20f) .setIncrement(5f) - .setDefaultValue(15f) + .setInitialValue(15f) .setCallback(increments5Callback) .setKey("key") .setContext(this) @@ -64,24 +64,24 @@ public void setUp() { } @Test(expected = IllegalArgumentException.class) - public void initDoesNotAcceptDefaultValueGreaterThanMax() { + public void initDoesNotAcceptInitialValueGreaterThanMax() { new RangeVariable.Builder() .setMinValue(0f) .setMaxValue(10f) .setIncrement(5f) - .setDefaultValue(15f) + .setInitialValue(15f) .setKey("key") .setContext(this) .build(); } @Test(expected = IllegalArgumentException.class) - public void initDoesNotAcceptDefaultValueLessThanMin() { + public void initDoesNotAcceptInitialValueLessThanMin() { new RangeVariable.Builder() .setMinValue(10f) .setMaxValue(20f) .setIncrement(5f) - .setDefaultValue(5f) + .setInitialValue(5f) .setKey("key") .setContext(this) .build(); @@ -93,7 +93,7 @@ public void constructorDoesNotAcceptInvalidRanges() { .setMinValue(50f) .setMaxValue(20f) .setIncrement(1f) - .setDefaultValue(15f) + .setInitialValue(15f) .setKey("key") .setContext(this) .build(); @@ -105,7 +105,7 @@ public void constructorDoesNotAcceptNegativeStepping() { .setMinValue(0f) .setMaxValue(20f) .setIncrement(-1f) - .setDefaultValue(15f) + .setInitialValue(15f) .setKey("key") .setContext(this) .build(); @@ -118,20 +118,20 @@ public void constructorDoesNotAcceptInvalidStepping() { .setMinValue(0f) .setMaxValue(52f) .setIncrement(5f) - .setDefaultValue(15f) + .setInitialValue(15f) .setKey("key") .setContext(this) .build(); } @Test(expected = IllegalArgumentException.class) - public void initDoesNotAcceptInvalidSteppingToDefaultValue() { - // Stepping is invalid because defaultValue 22 cannot be reached from 15 in steps of 5 + public void initDoesNotAcceptInvalidSteppingToInitialValue() { + // Stepping is invalid because initialValue 22 cannot be reached from 15 in steps of 5 new RangeVariable.Builder() .setMinValue(0f) .setMaxValue(50f) .setIncrement(5f) - .setDefaultValue(22f) + .setInitialValue(22f) .setKey("key") .setContext(this) .build(); @@ -172,7 +172,7 @@ public void doesNotCrashOnNullCallback() { .setMinValue(0f) .setMaxValue(20f) .setIncrement(1f) - .setDefaultValue(15f) + .setInitialValue(15f) .setKey("key") .setContext(this) .build(); diff --git a/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/ColorVariableSerializationTest.java b/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/ColorVariableSerializationTest.java index 1bb489a..e6cab23 100644 --- a/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/ColorVariableSerializationTest.java +++ b/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/ColorVariableSerializationTest.java @@ -45,8 +45,8 @@ public static void oneTimeSetUp() { @Before public void setUp() { colorListVariable = new ItemListVariable.Builder() - .setPossibleValues(new Integer[]{BLACK, BLUE}) - .setDefaultValue(BLACK) + .setLimitedToValues(new Integer[]{BLACK, BLUE}) + .setInitialValue(BLACK) .setContext(this) .setKey(KEY) .setDataType(DataType.COLOR) diff --git a/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/CompareHelper.java b/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/CompareHelper.java index b572d16..124ca6b 100644 --- a/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/CompareHelper.java +++ b/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/CompareHelper.java @@ -36,7 +36,7 @@ public static void assertEqualsItemListVariable( StoredVariable storage, ItemListVariable variable) { assertConsistent(storage, variable); Assert.assertEquals(variable.getSelectedValue(), storage.selectedValue); - Assert.assertEquals(variable.getValueList(), storage.possibleValues); + Assert.assertEquals(variable.getLimitedToValues(), storage.possibleValues); Assert.assertNull(storage.minValue); Assert.assertNull(storage.maxValue); Assert.assertNull(storage.increment); diff --git a/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/NumberVariableSerializationTest.java b/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/NumberVariableSerializationTest.java index 3bbbefa..ddfb935 100644 --- a/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/NumberVariableSerializationTest.java +++ b/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/NumberVariableSerializationTest.java @@ -47,14 +47,14 @@ public static void oneTimeSetUp() { @Before public void setUp() { floatVariable = new Variable.Builder() - .setDefaultValue(0f) + .setInitialValue(0f) .setKey(KEY) .setContext(this) .setDataType(DataType.NUMBER) .build(); floatListVariable = new ItemListVariable.Builder() - .setPossibleValues(new Float[]{12f, 154f}) - .setDefaultValue(12f) + .setLimitedToValues(new Float[]{12f, 154f}) + .setInitialValue(12f) .setContext(this) .setKey(KEY) .setDataType(DataType.NUMBER) @@ -63,7 +63,7 @@ public void setUp() { .setMinValue(0f) .setMaxValue(100f) .setIncrement(10f) - .setDefaultValue(10f) + .setInitialValue(10f) .setContext(this) .setKey(KEY) .setDataType(DataType.NUMBER) diff --git a/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/SerializableRemixerContentsSerializationTest.java b/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/SerializableRemixerContentsSerializationTest.java index d17fbdb..da3e592 100644 --- a/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/SerializableRemixerContentsSerializationTest.java +++ b/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/SerializableRemixerContentsSerializationTest.java @@ -61,23 +61,23 @@ public void setUp() { .build(); serializableRemixerContents.addItem(booleanVariable); colorListVariable = new ItemListVariable.Builder() - .setPossibleValues(new Integer[]{BLACK, BLUE}) - .setDefaultValue(BLACK) + .setLimitedToValues(new Integer[]{BLACK, BLUE}) + .setInitialValue(BLACK) .setContext(this) .setKey("colorList") .setDataType(DataType.COLOR) .build(); serializableRemixerContents.addItem(colorListVariable); floatVariable = new Variable.Builder() - .setDefaultValue(0f) + .setInitialValue(0f) .setKey("float") .setContext(this) .setDataType(DataType.NUMBER) .build(); serializableRemixerContents.addItem(floatVariable); floatListVariable = new ItemListVariable.Builder() - .setPossibleValues(new Float[]{12f, 24f}) - .setDefaultValue(12f) + .setLimitedToValues(new Float[]{12f, 24f}) + .setInitialValue(12f) .setContext(this) .setKey("floatList") .setDataType(DataType.NUMBER) @@ -87,7 +87,7 @@ public void setUp() { .setMinValue(0f) .setIncrement(10f) .setMaxValue(100f) - .setDefaultValue(10f) + .setInitialValue(10f) .setContext(this) .setKey("range") .build(); @@ -98,8 +98,8 @@ public void setUp() { .build(); serializableRemixerContents.addItem(stringVariable); stringListVariable = new ItemListVariable.Builder() - .setPossibleValues(new String[]{"a", "b", "c"}) - .setDefaultValue("a") + .setLimitedToValues(new String[]{"a", "b", "c"}) + .setInitialValue("a") .setContext(this) .setKey("stringList") .setDataType(DataType.STRING) diff --git a/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/StringVariableSerializationTest.java b/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/StringVariableSerializationTest.java index a884de4..1e352a0 100644 --- a/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/StringVariableSerializationTest.java +++ b/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/StringVariableSerializationTest.java @@ -50,8 +50,8 @@ public void setUp() { .setKey(KEY) .build(); stringListVariable = new ItemListVariable.Builder() - .setPossibleValues(new String[]{"a", "b", "c"}) - .setDefaultValue("a") + .setLimitedToValues(new String[]{"a", "b", "c"}) + .setInitialValue("a") .setContext(this) .setKey(KEY) .setDataType(DataType.STRING) diff --git a/remixer_example/src/main/java/com/google/android/apps/remixer/BoxActivity.java b/remixer_example/src/main/java/com/google/android/apps/remixer/BoxActivity.java index 4757296..e1c01e7 100644 --- a/remixer_example/src/main/java/com/google/android/apps/remixer/BoxActivity.java +++ b/remixer_example/src/main/java/com/google/android/apps/remixer/BoxActivity.java @@ -53,7 +53,7 @@ void showBox(Boolean show) { @ColorListVariableMethod( key = "boxColor", title = "Box color", - possibleValues = {Color.DKGRAY, Color.LTGRAY, Color.MAGENTA, Color.CYAN}, + limitedToValues = {Color.DKGRAY, Color.LTGRAY, Color.MAGENTA, Color.CYAN}, layoutId = R.layout.color_list_variable_widget ) void setBoxColor(Integer color) { diff --git a/remixer_example/src/main/java/com/google/android/apps/remixer/MainActivity.java b/remixer_example/src/main/java/com/google/android/apps/remixer/MainActivity.java index bc02635..0a01460 100644 --- a/remixer_example/src/main/java/com/google/android/apps/remixer/MainActivity.java +++ b/remixer_example/src/main/java/com/google/android/apps/remixer/MainActivity.java @@ -60,12 +60,12 @@ void setTitleTextSize(Float size) { @StringListVariableMethod( title = "Title text", - possibleValues = {"Hello World", "Alohomora", "Foo", "Bar", "May the force be with you"}) + limitedToValues = {"Hello World", "Alohomora", "Foo", "Bar", "May the force be with you"}) void setTitleText(String text) { titleText.setText(text); } - @StringVariableMethod(defaultValue = "Change me!") + @StringVariableMethod(initialValue = "Change me!") void setFreeformText(String text) { freeformText.setText(text); } diff --git a/remixer_storage/src/test/java/com/google/android/libraries/remixer/storage/LocalStorageTest.java b/remixer_storage/src/test/java/com/google/android/libraries/remixer/storage/LocalStorageTest.java index 10cd24b..9a9ce1e 100644 --- a/remixer_storage/src/test/java/com/google/android/libraries/remixer/storage/LocalStorageTest.java +++ b/remixer_storage/src/test/java/com/google/android/libraries/remixer/storage/LocalStorageTest.java @@ -65,7 +65,7 @@ public void setUp() { colorListVariable = new ItemListVariable.Builder() - .setPossibleValues(new Integer[]{Color.BLACK, Color.BLUE}).setDataType(DataType.COLOR) + .setLimitedToValues(new Integer[]{Color.BLACK, Color.BLUE}).setDataType(DataType.COLOR) .setContext(this).setKey("colors").build(); rangeVariable = new RangeVariable.Builder() @@ -117,7 +117,7 @@ public void readsValuesAlreadyStored() { "This is a new value that has to remain when adding stringVariable to the other remixer"; Variable stringWithDifferentValue = new StringVariableBuilder() - .setKey("string").setContext(differentValue).setDefaultValue(differentValue).build(); + .setKey("string").setContext(differentValue).setInitialValue(differentValue).build(); helperInstance.addItem(stringWithDifferentValue); // After this there should be a string variable with key string stored. remixer.setSynchronizationMechanism(new LocalStorage(RuntimeEnvironment.application)); diff --git a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/widget/ColorListVariableWidget.java b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/widget/ColorListVariableWidget.java index 7cd9616..b122567 100644 --- a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/widget/ColorListVariableWidget.java +++ b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/widget/ColorListVariableWidget.java @@ -108,7 +108,7 @@ List getValues() { public void setVariable(ItemListVariable variable) { this.variable = variable; values.clear(); - for (Integer color : variable.getValueList()) { + for (Integer color : variable.getLimitedToValues()) { ColorItem colorItem = new ColorItem(color, color.equals(variable.getSelectedValue())); values.add(colorItem); } diff --git a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/widget/ItemListVariableWidget.java b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/widget/ItemListVariableWidget.java index a42635a..94340eb 100644 --- a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/widget/ItemListVariableWidget.java +++ b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/widget/ItemListVariableWidget.java @@ -62,7 +62,7 @@ protected void onFinishInflate() { @Override public void bindVariable(@NonNull final ItemListVariable variable) { - values = variable.getValueList(); + values = variable.getLimitedToValues(); int position = values.indexOf(variable.getSelectedValue()); nameText.setText(variable.getTitle()); spinner.setAdapter( diff --git a/remixer_ui/src/test/java/com/google/android/libraries/remixer/ui/widget/BooleanVariableWidgetTest.java b/remixer_ui/src/test/java/com/google/android/libraries/remixer/ui/widget/BooleanVariableWidgetTest.java index 1a62242..b74ce2c 100644 --- a/remixer_ui/src/test/java/com/google/android/libraries/remixer/ui/widget/BooleanVariableWidgetTest.java +++ b/remixer_ui/src/test/java/com/google/android/libraries/remixer/ui/widget/BooleanVariableWidgetTest.java @@ -58,7 +58,7 @@ public class BooleanVariableWidgetTest { public void setUp() { MockitoAnnotations.initMocks(this); variable = new BooleanVariableBuilder() - .setDefaultValue(DEFAULT_VALUE) + .setInitialValue(DEFAULT_VALUE) .setTitle(TITLE) .setKey(KEY) .setContext(this) diff --git a/remixer_ui/src/test/java/com/google/android/libraries/remixer/ui/widget/ColorListVariableWidgetTest.java b/remixer_ui/src/test/java/com/google/android/libraries/remixer/ui/widget/ColorListVariableWidgetTest.java index 7940792..0e62861 100644 --- a/remixer_ui/src/test/java/com/google/android/libraries/remixer/ui/widget/ColorListVariableWidgetTest.java +++ b/remixer_ui/src/test/java/com/google/android/libraries/remixer/ui/widget/ColorListVariableWidgetTest.java @@ -64,8 +64,8 @@ public class ColorListVariableWidgetTest { public void setUp() { MockitoAnnotations.initMocks(this); variable = new ItemListVariable.Builder() - .setPossibleValues(ITEM_LIST) - .setDefaultValue(ITEM_LIST[DEFAULT_VALUE_INDEX]) + .setLimitedToValues(ITEM_LIST) + .setInitialValue(ITEM_LIST[DEFAULT_VALUE_INDEX]) .setTitle(TITLE) .setKey(KEY) .setContext(this) diff --git a/remixer_ui/src/test/java/com/google/android/libraries/remixer/ui/widget/ItemListVariableWidgetTest.java b/remixer_ui/src/test/java/com/google/android/libraries/remixer/ui/widget/ItemListVariableWidgetTest.java index ec1d192..032b18f 100644 --- a/remixer_ui/src/test/java/com/google/android/libraries/remixer/ui/widget/ItemListVariableWidgetTest.java +++ b/remixer_ui/src/test/java/com/google/android/libraries/remixer/ui/widget/ItemListVariableWidgetTest.java @@ -64,8 +64,8 @@ public class ItemListVariableWidgetTest { public void setUp() { MockitoAnnotations.initMocks(this); variable = new ItemListVariable.Builder() - .setPossibleValues(ITEM_LIST) - .setDefaultValue(ITEM_LIST[DEFAULT_VALUE_INDEX]) + .setLimitedToValues(ITEM_LIST) + .setInitialValue(ITEM_LIST[DEFAULT_VALUE_INDEX]) .setTitle(TITLE) .setKey(KEY) .setContext(this) diff --git a/remixer_ui/src/test/java/com/google/android/libraries/remixer/ui/widget/SeekBarRangeVariableWidgetTest.java b/remixer_ui/src/test/java/com/google/android/libraries/remixer/ui/widget/SeekBarRangeVariableWidgetTest.java index 61469ce..5d39df5 100644 --- a/remixer_ui/src/test/java/com/google/android/libraries/remixer/ui/widget/SeekBarRangeVariableWidgetTest.java +++ b/remixer_ui/src/test/java/com/google/android/libraries/remixer/ui/widget/SeekBarRangeVariableWidgetTest.java @@ -64,7 +64,7 @@ public void setUp() { .setMinValue(MIN) .setMaxValue(MAX) .setIncrement(INCREMENT) - .setDefaultValue(DEFAULT_VALUE) + .setInitialValue(DEFAULT_VALUE) .setTitle(TITLE) .setKey(KEY) .setContext(this) diff --git a/remixer_ui/src/test/java/com/google/android/libraries/remixer/ui/widget/StringVariableWidgetTest.java b/remixer_ui/src/test/java/com/google/android/libraries/remixer/ui/widget/StringVariableWidgetTest.java index 012e2c0..5cbe486 100644 --- a/remixer_ui/src/test/java/com/google/android/libraries/remixer/ui/widget/StringVariableWidgetTest.java +++ b/remixer_ui/src/test/java/com/google/android/libraries/remixer/ui/widget/StringVariableWidgetTest.java @@ -58,7 +58,7 @@ public class StringVariableWidgetTest { public void setUp() { MockitoAnnotations.initMocks(this); variable = new StringVariableBuilder() - .setDefaultValue(DEFAULT_VALUE) + .setInitialValue(DEFAULT_VALUE) .setTitle(TITLE) .setKey(KEY) .setContext(this) From 7e80c9942d9760f746976aaf5751067236ecab08 Mon Sep 17 00:00:00 2001 From: Miguel Yanez Barreto Date: Thu, 12 Jan 2017 13:38:54 -0500 Subject: [PATCH 08/32] renamed some missing references --- README.md | 13 ++++++------ .../libraries/remixer/ItemListVariable.java | 15 +++++++------ .../libraries/remixer/RangeVariable.java | 2 +- .../android/libraries/remixer/Variable.java | 4 ++-- .../annotation/ColorListVariableMethod.java | 6 +++--- .../annotation/NumberListVariableMethod.java | 2 +- .../annotation/RangeVariableMethod.java | 2 +- .../annotation/StringListVariableMethod.java | 2 +- .../remixer/serialization/StoredVariable.java | 18 ++++++++-------- .../remixer/serialization/ValueConverter.java | 21 ++++++++++--------- .../converters/ColorValueConverter.java | 2 +- .../converters/FloatValueConverter.java | 2 +- .../converters/StringValueConverter.java | 2 +- .../remixer/serialization/CompareHelper.java | 6 +++--- 14 files changed, 50 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index efbed77..8704754 100644 --- a/README.md +++ b/README.md @@ -168,15 +168,15 @@ They support the following properties: - `key` the key for this variable, you can use it to share the same value across activities, if not set it assumes the method name. - `title` the displayable name of the variable, if not set assumes `key` -- `initialValue` the initial value, if not set assumes the first in the `possibleValues` list -- `possibleValues` the list of possible values. +- `initialValue` the initial value, if not set assumes the first in the `limitedToValues` list +- `limitedToValues` the list of values this variable is limited to take. - `layoutId` a layoutId to display this, must implement RemixerWidget. It assumes a sensible default if unset. A String List variable that sets fonts from a list and defaults to the first in the list: ```java @StringListVariableMethod( title = "Title font", - possibleValues = {"Roboto", "Roboto Mono", "Comic Sans MS"}) + limitedToValues = {"Roboto", "Roboto Mono", "Comic Sans MS"}) public void setTitleFont(String fontName) { } ``` @@ -199,15 +199,14 @@ public void setExampleText(String exampleText) { - `key` the key for this variable, you can use it to share the same value across activities, if not set it assumes the method name. - `title` the displayable name of the variable, if not set assumes `key` -- `initialValue` the initial value, if not set assumes the first in the `possibleValues` list -- `possibleValues` the list of possible values. -- `layoutId` a layoutId to display this, must implement RemixerWidget. It assumes a sensible default if unset. +- `initialValue` the initial value, if not set assumes the first in the `limitedToValues` list +- `limitedToValues` the list of values this variable is limited to take.- `layoutId` a layoutId to display this, must implement RemixerWidget. It assumes a sensible default if unset. A variable that lets you pick colors from a list, this example uses a custom layout id to guarantee that it's treated as a Color: ```java @IntegerListVariableMethod( title = "Title Color", - possibleValues = {Color.parseColor("#000000"), Color.parseColor("#DCDCDC")}, + limitedToValues = {Color.parseColor("#000000"), Color.parseColor("#DCDCDC")}, layoutId = R.layout.color_list_variable_widget) public void setTitleColor(Integer color) { } diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/ItemListVariable.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/ItemListVariable.java index 1a28fc3..fbb97a8 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/ItemListVariable.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/ItemListVariable.java @@ -30,12 +30,12 @@ public class ItemListVariable extends Variable { private final List limitedToValues; /** - * Creates a new ItemListVariable, checks its default value and runs the callback if the value is + * Creates a new ItemListVariable, checks its initial value and runs the callback if the value is * valid. * * @param title Displayable name for this Variable. * @param key The key used to store this Variable. - * @param initialValue The default value to use if none has been set. + * @param initialValue The initial value to use if none has been set. * @param limitedToValues List of valid values that this variable is limited to take. * @param context the object which created this variable, should be an activity. * @param callback Callback to run once the value is set. Can be null. @@ -77,10 +77,13 @@ public String getSerializableConstraints() { /** * Convenience builder for ItemListVariable. * - *

    This builder assumes a few things for your convenience:

    • If the default value is not - * set, the first value of the list will be used as the default value.
    • If the layout id is not - * set, the default layout will be used.
    • If the title is not set, the key will be used as - * title
    + *

    This builder assumes a few things for your convenience: + *

      + *
    • If the initial value is not set, the first value of the list will be used as the default + * value. + *
    • If the layout id is not set, the default layout will be used. + *
    • If the title is not set, the key will be used as title + *
    * *

    On the other hand: key, dataType, context, and limitedToValues are mandatory. If either is * missing, an {@link IllegalArgumentException} will be thrown. diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/RangeVariable.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/RangeVariable.java index 143fcb5..8dc81e3 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/RangeVariable.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/RangeVariable.java @@ -157,7 +157,7 @@ public String getSerializableConstraints() { * *

    This builder assumes a few things for your convenience: *

      - *
    • If the default value is not set, minValue will be used as the default value. + *
    • If the initial value is not set, minValue will be used as the initial value. *
    • If the increment is not set, 1 will be used. *
    • If the layout id is not set, the default layout will be used. *
    • If the title is not set, the key will be used as title diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/Variable.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/Variable.java index 8f715b0..643e345 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/Variable.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/Variable.java @@ -92,10 +92,10 @@ protected Variable( } /** - * Makes sure the default value is valid for this variable and runs the callback if so. This must + * Makes sure the initial value is valid for this variable and runs the callback if so. This must * be called as soon as the Variable is created. * - * @throws IllegalArgumentException The currently selected value (or default value) is invalid for + * @throws IllegalArgumentException The currently selected value (or initial value) is invalid for * this Variable. See {@link #checkValue(Object)}. */ public final void init() { diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/ColorListVariableMethod.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/ColorListVariableMethod.java index ad5bb8a..03ce9f4 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/ColorListVariableMethod.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/ColorListVariableMethod.java @@ -25,7 +25,7 @@ * Annotation to apply to a method to turn it into a {@code ItemListVariable<Integer>} for * colors. * - *

      It is set up in a way that you don't need to explicitly set the default value, if it is left + *

      It is set up in a way that you don't need to explicitly set the initial value, if it is left * unspecified and 0 is not part of the possible values, then the first value in the list of * possible values is assumed as default. * @@ -51,8 +51,8 @@ /** * The initial value for this variable, assumes 0 as default. * - *

      If left unspecified and the empty string is not part of the possible values, then the first - * value in the list of possible values is assumed as default. + *

      If left unspecified and the empty string is not part of the limited to values, then the + * first value in the list of possible values is assumed as default. */ int initialValue() default 0; diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/NumberListVariableMethod.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/NumberListVariableMethod.java index f2bf8d3..3872de7 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/NumberListVariableMethod.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/NumberListVariableMethod.java @@ -25,7 +25,7 @@ * Annotation to apply to a method to turn it into a {@code ItemListVariable<Float>} for * numbers. * - *

      It is set up in a way that you don't need to explicitly set the default value, if it is left + *

      It is set up in a way that you don't need to explicitly set the initial value, if it is left * unspecified and 0 is not part of the possible values, then the first value in the list of * possible values is assumed as default. * diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/RangeVariableMethod.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/RangeVariableMethod.java index 28d761e..b251c6d 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/RangeVariableMethod.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/RangeVariableMethod.java @@ -25,7 +25,7 @@ * Annotation to apply to a method to turn it into a RangeVariable. * *

      This is set up in a way that if no values are specified it will be a range from 0 to 100, with - * the default value as 0. Furthermore if you only move the range so that 0 is not included it will + * the initial value as 0. Furthermore if you only move the range so that 0 is not included it will * set the default to be minValue. * *

      Note: It has to be used on a public or default-access method. diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/StringListVariableMethod.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/StringListVariableMethod.java index c1db512..aa01079 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/StringListVariableMethod.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/StringListVariableMethod.java @@ -24,7 +24,7 @@ /** * Annotation to apply to a method to turn it into a {@code ItemListVariable<String>}. * - *

      It is set up in a way that you don't need to explicitly set the default value, if it is left + *

      It is set up in a way that you don't need to explicitly set the initial value, if it is left * unspecified and the empty string is not part of the possible values, then the first value in the * list of possible values is assumed as default. * diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/StoredVariable.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/StoredVariable.java index 0ff0884..aeddb3d 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/StoredVariable.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/StoredVariable.java @@ -58,7 +58,7 @@ public class StoredVariable { static final String CONSTRAINT_TYPE = "constraintType"; static final String DATA_TYPE = "dataType"; static final String SELECTED_VALUE = "selectedValue"; - static final String POSSIBLE_VALUES = "limitedToValues"; + static final String LIMITED_TO_VALUES = "limitedToValues"; static final String MIN_VALUE = "minValue"; static final String MAX_VALUE = "maxValue"; static final String INCREMENT = "increment"; @@ -92,7 +92,7 @@ public class StoredVariable { * The list of possible values, if this is not null then this StoredVariable represents a {@link * com.google.android.libraries.remixer.ItemListVariable}. */ - List possibleValues; + List limitedToValues; // These are only used in case it T is a number and it is a range variable, otherwise they are // ignored. @@ -149,12 +149,12 @@ public void setSelectedValue(T selectedValue) { this.selectedValue = selectedValue; } - public List getPossibleValues() { - return possibleValues; + public List getLimitedToValues() { + return limitedToValues; } - public void setPossibleValues(List possibleValues) { - this.possibleValues = possibleValues; + public void setLimitedToValues(List limitedToValues) { + this.limitedToValues = limitedToValues; } public T getMinValue() { @@ -216,8 +216,8 @@ public boolean isCompatibleWith(StoredVariable variable) { if (!dataType.equals(variable.dataType)) { return false; } - if (possibleValues != null - ? !possibleValues.equals(variable.possibleValues) : variable.possibleValues != null) { + if (limitedToValues != null + ? !limitedToValues.equals(variable.limitedToValues) : variable.limitedToValues != null) { return false; } if (minValue != null ? !minValue.equals(variable.minValue) : variable.minValue != null) { @@ -235,7 +235,7 @@ public int hashCode() { result = 31 * result + (title != null ? title.hashCode() : 0); result = 31 * result + dataType.hashCode(); result = 31 * result + (selectedValue != null ? selectedValue.hashCode() : 0); - result = 31 * result + (possibleValues != null ? possibleValues.hashCode() : 0); + result = 31 * result + (limitedToValues != null ? limitedToValues.hashCode() : 0); result = 31 * result + (minValue != null ? minValue.hashCode() : 0); result = 31 * result + (maxValue != null ? maxValue.hashCode() : 0); result = 31 * result + (increment != null ? increment.hashCode() : 0); diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/ValueConverter.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/ValueConverter.java index d47cba2..dd80b30 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/ValueConverter.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/ValueConverter.java @@ -73,7 +73,7 @@ public StoredVariable deserialize(JsonElement json) { result.constraintType = object.get(StoredVariable.CONSTRAINT_TYPE).getAsString(); if (StoredVariable.ITEM_LIST_VARIABLE_CONSTRAINT.equals(result.constraintType)) { - deserializePossibleValues(result, object.get(StoredVariable.POSSIBLE_VALUES)); + deserializeLimitedToValues(result, object.get(StoredVariable.LIMITED_TO_VALUES)); } else if (StoredVariable.RANGE_VARIABLE_CONSTRAINT.equals(result.constraintType)) { deserializeRangeProperties(result, object); } @@ -89,12 +89,13 @@ private void deserializeRangeProperties(StoredVariable result, JsonObject obj result.increment = parseValue(object.getAsJsonPrimitive(StoredVariable.INCREMENT)); } - private void deserializePossibleValues(StoredVariable result, JsonElement possibleValuesElement) { - if (possibleValuesElement != null) { - JsonArray array = possibleValuesElement.getAsJsonArray(); - result.possibleValues = new ArrayList<>(); + private void deserializeLimitedToValues( + StoredVariable result, JsonElement limitedToValuesElement) { + if (limitedToValuesElement != null) { + JsonArray array = limitedToValuesElement.getAsJsonArray(); + result.limitedToValues = new ArrayList<>(); for (JsonElement arrayElement : array) { - result.possibleValues.add(parseValue(arrayElement)); + result.limitedToValues.add(parseValue(arrayElement)); } } } @@ -110,11 +111,11 @@ public JsonElement serialize(StoredVariable src) { object.add(StoredVariable.SELECTED_VALUE, valueToJson(src.selectedValue)); object.add(StoredVariable.CONSTRAINT_TYPE, new JsonPrimitive(src.constraintType)); if (StoredVariable.ITEM_LIST_VARIABLE_CONSTRAINT.equals(src.constraintType)) { - JsonArray possibleValues = new JsonArray(); - for (T item : src.possibleValues) { - possibleValues.add(valueToJson(item)); + JsonArray limitedToValues = new JsonArray(); + for (T item : src.limitedToValues) { + limitedToValues.add(valueToJson(item)); } - object.add(StoredVariable.POSSIBLE_VALUES, possibleValues); + object.add(StoredVariable.LIMITED_TO_VALUES, limitedToValues); } if (StoredVariable.RANGE_VARIABLE_CONSTRAINT.equals(src.constraintType)) { object.add(StoredVariable.MIN_VALUE, valueToJson(src.minValue)); diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/ColorValueConverter.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/ColorValueConverter.java index ad45b26..0cdf320 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/ColorValueConverter.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/ColorValueConverter.java @@ -65,7 +65,7 @@ public StoredVariable fromVariable(Variable var) { storage.setDataType(dataType); storage.setSelectedValue((Integer) var.getSelectedValue()); if (var instanceof ItemListVariable) { - storage.setPossibleValues(((ItemListVariable) var).getLimitedToValues()); + storage.setLimitedToValues(((ItemListVariable) var).getLimitedToValues()); } return storage; } diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/FloatValueConverter.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/FloatValueConverter.java index 23f1df9..96f739c 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/FloatValueConverter.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/FloatValueConverter.java @@ -40,7 +40,7 @@ public StoredVariable fromVariable(Variable var) { storage.setMaxValue(range.getMaxValue()); storage.setIncrement(range.getIncrement()); } else if (var instanceof ItemListVariable) { - storage.setPossibleValues(((ItemListVariable) var).getLimitedToValues()); + storage.setLimitedToValues(((ItemListVariable) var).getLimitedToValues()); } return storage; } diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/StringValueConverter.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/StringValueConverter.java index 4dd2562..716821b 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/StringValueConverter.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/converters/StringValueConverter.java @@ -34,7 +34,7 @@ public StoredVariable fromVariable(Variable var) { storage.setDataType(dataType); storage.setSelectedValue((String) var.getSelectedValue()); if (var instanceof ItemListVariable) { - storage.setPossibleValues(((ItemListVariable) var).getLimitedToValues()); + storage.setLimitedToValues(((ItemListVariable) var).getLimitedToValues()); } return storage; } diff --git a/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/CompareHelper.java b/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/CompareHelper.java index 124ca6b..0292f72 100644 --- a/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/CompareHelper.java +++ b/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/CompareHelper.java @@ -26,7 +26,7 @@ public class CompareHelper { public static void assertEqualsVariable(StoredVariable storage, Variable variable) { assertConsistent(storage, variable); Assert.assertEquals(variable.getSelectedValue(), storage.selectedValue); - Assert.assertNull(storage.possibleValues); + Assert.assertNull(storage.limitedToValues); Assert.assertNull(storage.minValue); Assert.assertNull(storage.maxValue); Assert.assertNull(storage.increment); @@ -36,7 +36,7 @@ public static void assertEqualsItemListVariable( StoredVariable storage, ItemListVariable variable) { assertConsistent(storage, variable); Assert.assertEquals(variable.getSelectedValue(), storage.selectedValue); - Assert.assertEquals(variable.getLimitedToValues(), storage.possibleValues); + Assert.assertEquals(variable.getLimitedToValues(), storage.limitedToValues); Assert.assertNull(storage.minValue); Assert.assertNull(storage.maxValue); Assert.assertNull(storage.increment); @@ -46,7 +46,7 @@ public static void assertEqualsRangeVariable( StoredVariable storage, RangeVariable variable) { assertConsistent(storage, variable); Assert.assertEquals(variable.getSelectedValue(), storage.selectedValue); - Assert.assertNull(storage.possibleValues); + Assert.assertNull(storage.limitedToValues); Assert.assertEquals(variable.getMinValue(), storage.minValue); Assert.assertEquals(variable.getMaxValue(), storage.maxValue); Assert.assertEquals(variable.getIncrement(), storage.increment); From eaa797333078f778aaa9fdcc94289a239f8d2692 Mon Sep 17 00:00:00 2001 From: Miguel Yanez Barreto Date: Thu, 12 Jan 2017 14:42:12 -0500 Subject: [PATCH 09/32] responded to chugas comments --- README.md | 7 ++++--- .../processor/ItemListVariableMethodAnnotation.java | 7 ++++--- .../NumberListVariableMethodAnnotationTest/Correct.java | 2 +- .../ExplicitWrongDefault.java | 2 +- .../remixer/annotation/NumberListVariableMethod.java | 2 +- .../serialization/NumberVariableSerializationTest.java | 2 +- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 8704754..521b463 100644 --- a/README.md +++ b/README.md @@ -195,16 +195,17 @@ public void setExampleText(String exampleText) { } ``` -##### Integer List Variable +##### Number List Variable - `key` the key for this variable, you can use it to share the same value across activities, if not set it assumes the method name. - `title` the displayable name of the variable, if not set assumes `key` - `initialValue` the initial value, if not set assumes the first in the `limitedToValues` list -- `limitedToValues` the list of values this variable is limited to take.- `layoutId` a layoutId to display this, must implement RemixerWidget. It assumes a sensible default if unset. +- `limitedToValues` the list of values this variable is limited to take. +- `layoutId` a layoutId to display this, must implement RemixerWidget. It assumes a sensible default if unset. A variable that lets you pick colors from a list, this example uses a custom layout id to guarantee that it's treated as a Color: ```java -@IntegerListVariableMethod( +@NumberListVariableMethod( title = "Title Color", limitedToValues = {Color.parseColor("#000000"), Color.parseColor("#DCDCDC")}, layoutId = R.layout.color_list_variable_widget) diff --git a/remixer_annotation/src/main/java/com/google/android/libraries/remixer/annotation/processor/ItemListVariableMethodAnnotation.java b/remixer_annotation/src/main/java/com/google/android/libraries/remixer/annotation/processor/ItemListVariableMethodAnnotation.java index c76b2d5..e456761 100644 --- a/remixer_annotation/src/main/java/com/google/android/libraries/remixer/annotation/processor/ItemListVariableMethodAnnotation.java +++ b/remixer_annotation/src/main/java/com/google/android/libraries/remixer/annotation/processor/ItemListVariableMethodAnnotation.java @@ -37,7 +37,7 @@ class ItemListVariableMethodAnnotation extends MethodAnnotation { /** - * Suffix to add to the name of a list holding the limited to values for this variable. + * Suffix to add to the name of a list holding the set of values this variable can take. */ private static final String LIST_SUFFIX = "_variable_list"; @@ -133,7 +133,7 @@ static ItemListVariableMethodAnnotation forNumberListVariableMethod( annotation.title(), annotation.layoutId(), limitedToValues, - annotation.initialValues(), + annotation.initialValue(), 0f); } @@ -142,7 +142,8 @@ static ItemListVariableMethodAnnotation forNumberListVariableMethod( * annotations are met. * *

      If the default is unset and the zero value (0 for numbers, empty string for Strings) is not - * amongst the limited to values then it falls back to the first value in the list. + * amongst the values this variable is limited to then it falls back to the first value in the + * list. * * @throws RemixerAnnotationException if the constraints are not met: * - The list of limited to values is empty. diff --git a/remixer_annotation/src/test/resources/inputs/NumberListVariableMethodAnnotationTest/Correct.java b/remixer_annotation/src/test/resources/inputs/NumberListVariableMethodAnnotationTest/Correct.java index b8090d7..7312e6e 100644 --- a/remixer_annotation/src/test/resources/inputs/NumberListVariableMethodAnnotationTest/Correct.java +++ b/remixer_annotation/src/test/resources/inputs/NumberListVariableMethodAnnotationTest/Correct.java @@ -23,6 +23,6 @@ public class Correct { /** * Initial value is implicitly 0, this has to move to 1 */ - @NumberListVariableMethod(limitedToValues = {1, 2}, initialValues = 1) + @NumberListVariableMethod(limitedToValues = {1, 2}, initialValue = 1) public void setNumber(Float i){} } diff --git a/remixer_annotation/src/test/resources/inputs/NumberListVariableMethodAnnotationTest/ExplicitWrongDefault.java b/remixer_annotation/src/test/resources/inputs/NumberListVariableMethodAnnotationTest/ExplicitWrongDefault.java index 3f0e189..77757c6 100644 --- a/remixer_annotation/src/test/resources/inputs/NumberListVariableMethodAnnotationTest/ExplicitWrongDefault.java +++ b/remixer_annotation/src/test/resources/inputs/NumberListVariableMethodAnnotationTest/ExplicitWrongDefault.java @@ -23,6 +23,6 @@ public class ExplicitWrongDefault { /** * Initial value is explicitly out of range, should fail. */ - @NumberListVariableMethod(initialValues = 5, limitedToValues = {2, 3}) + @NumberListVariableMethod(initialValue = 5, limitedToValues = {2, 3}) public void wrongDefault(Float i){} } diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/NumberListVariableMethod.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/NumberListVariableMethod.java index 3872de7..d1938b7 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/NumberListVariableMethod.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/annotation/NumberListVariableMethod.java @@ -54,7 +54,7 @@ *

      If left unspecified and the empty string is not part of the possible values, then the first * value in the list of possible values is assumed as default. */ - float initialValues() default 0; + float initialValue() default 0; /** * List of possible values for this ItemListVariable<String>. diff --git a/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/NumberVariableSerializationTest.java b/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/NumberVariableSerializationTest.java index ddfb935..d2b6579 100644 --- a/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/NumberVariableSerializationTest.java +++ b/remixer_core/src/test/java/com/google/android/libraries/remixer/serialization/NumberVariableSerializationTest.java @@ -71,7 +71,7 @@ public void setUp() { } @Test - public void integerListVariableConvertsToStorageTest() { + public void numberListVariableConvertsToStorageTest() { StoredVariable result = StoredVariable.fromVariable(floatListVariable); Assert.assertEquals(DataType.NUMBER.getName(), result.dataType); CompareHelper.assertEqualsItemListVariable(result, floatListVariable); From 3a890e1246899cbe6fd7374103c4e670baf50590 Mon Sep 17 00:00:00 2001 From: Nick Sahler Date: Thu, 12 Jan 2017 16:27:57 -0500 Subject: [PATCH 10/32] Add Shake to Remix #112 --- .../android/apps/remixer/MainActivity.java | 5 +++ .../remixer/ui/view/RemixerFragment.java | 34 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/remixer_example/src/main/java/com/google/android/apps/remixer/MainActivity.java b/remixer_example/src/main/java/com/google/android/apps/remixer/MainActivity.java index bc02635..8774d39 100644 --- a/remixer_example/src/main/java/com/google/android/apps/remixer/MainActivity.java +++ b/remixer_example/src/main/java/com/google/android/apps/remixer/MainActivity.java @@ -15,11 +15,13 @@ */ package com.google.android.apps.remixer; +import android.hardware.SensorManager; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.util.TypedValue; import android.widget.Button; import android.widget.TextView; + import com.google.android.libraries.remixer.annotation.RangeVariableMethod; import com.google.android.libraries.remixer.annotation.RemixerBinder; import com.google.android.libraries.remixer.annotation.StringListVariableMethod; @@ -49,6 +51,9 @@ protected void onCreate(Bundle savedInstanceState) { RemixerFragment remixerFragment = RemixerFragment.newInstance(); remixerFragment.attachToGesture(this, Direction.UP, 3); remixerFragment.attachToButton(this, remixerButton); + + SensorManager sensorManager = (SensorManager)getSystemService(SENSOR_SERVICE); + remixerFragment.attachToShake(this, sensorManager, 20.0); } @RangeVariableMethod( diff --git a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/view/RemixerFragment.java b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/view/RemixerFragment.java index 8824921..077681a 100644 --- a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/view/RemixerFragment.java +++ b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/view/RemixerFragment.java @@ -17,6 +17,10 @@ package com.google.android.libraries.remixer.ui.view; import android.content.Context; +import android.hardware.Sensor; +import android.hardware.SensorEvent; +import android.hardware.SensorEventListener; +import android.hardware.SensorManager; import android.os.Bundle; import android.support.design.widget.BottomSheetDialogFragment; import android.support.v4.app.FragmentActivity; @@ -62,6 +66,7 @@ public static RemixerFragment newInstance() { return new RemixerFragment(); } + private SensorEventListener sensorEventListener; /** * Attach this instance to {@code button}'s OnClick, so that clicking the button shows this * fragment. @@ -78,6 +83,35 @@ public void onClick(View view) { }); } + /** + /** + * Attach this instance to a shake gesture using {@code sensorManager } and show fragment when magnitude exceeds {@code threshold} + */ + public void attachToShake(final FragmentActivity activity, SensorManager sensorManager, final double threshold) { + this.sensorEventListener = new SensorEventListener() { + double lastMagnitude; + /* Temporary delay until `show` bug is fixed */ + long lastSpike = 0; + + @Override + public void onSensorChanged(SensorEvent event) { + double currentMagnitude = Math.sqrt(event.values[0] * event.values[0] + event.values[1] * event.values[1] + event.values[2] * event.values[2]); + + if ((currentMagnitude - lastMagnitude) > threshold && System.currentTimeMillis() - lastSpike > 500) { + show(activity.getSupportFragmentManager(), REMIXER_TAG); + lastSpike = System.currentTimeMillis(); + } + + this.lastMagnitude = currentMagnitude; + } + + @Override + public void onAccuracyChanged(Sensor sensor, int accuracy) { } + }; + + sensorManager.registerListener(sensorEventListener, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); + } + /** * Attach this instance to a swipe gesture with {@code numberOfFingers} numbers in direction * {@code direction} on the {@code activity}, so that performing the gesture will show this From 46b64c253422fcf5e7059d8027b190f35ae4d12f Mon Sep 17 00:00:00 2001 From: Nick Sahler Date: Thu, 12 Jan 2017 16:51:32 -0500 Subject: [PATCH 11/32] Override `show` Forgot that this override is necessary. --- .../remixer/ui/view/RemixerFragment.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/view/RemixerFragment.java b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/view/RemixerFragment.java index 077681a..ecdcd35 100644 --- a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/view/RemixerFragment.java +++ b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/view/RemixerFragment.java @@ -24,11 +24,13 @@ import android.os.Bundle; import android.support.design.widget.BottomSheetDialogFragment; import android.support.v4.app.FragmentActivity; +import android.support.v4.app.FragmentManager; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; + import com.google.android.libraries.remixer.Remixer; import com.google.android.libraries.remixer.ui.R; import com.google.android.libraries.remixer.ui.gesture.Direction; @@ -67,6 +69,7 @@ public static RemixerFragment newInstance() { } private SensorEventListener sensorEventListener; + /** * Attach this instance to {@code button}'s OnClick, so that clicking the button shows this * fragment. @@ -84,6 +87,19 @@ public void onClick(View view) { } /** + * + * @param manager + * @param tag + * @return whether the fragment was shown or not. + */ + + @Override + public void show(FragmentManager manager, String tag) { + if (!isAdded() && !isVisible() && !isRemoving()) { + super.show(manager.beginTransaction(), tag); + } + } + /** * Attach this instance to a shake gesture using {@code sensorManager } and show fragment when magnitude exceeds {@code threshold} */ From d8bf6756e31cee31a95a0441a634d86cf5e0a2cf Mon Sep 17 00:00:00 2001 From: Nick Sahler Date: Thu, 12 Jan 2017 17:18:37 -0500 Subject: [PATCH 12/32] Refactor and cleanup. Create ShakeListener class for refactor. --- .../android/apps/remixer/MainActivity.java | 4 +- .../remixer/ui/gesture/ShakeListener.java | 52 +++++++++++++++++++ .../remixer/ui/view/RemixerFragment.java | 26 ++-------- 3 files changed, 56 insertions(+), 26 deletions(-) create mode 100644 remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/gesture/ShakeListener.java diff --git a/remixer_example/src/main/java/com/google/android/apps/remixer/MainActivity.java b/remixer_example/src/main/java/com/google/android/apps/remixer/MainActivity.java index 8774d39..6fc2b9d 100644 --- a/remixer_example/src/main/java/com/google/android/apps/remixer/MainActivity.java +++ b/remixer_example/src/main/java/com/google/android/apps/remixer/MainActivity.java @@ -51,9 +51,7 @@ protected void onCreate(Bundle savedInstanceState) { RemixerFragment remixerFragment = RemixerFragment.newInstance(); remixerFragment.attachToGesture(this, Direction.UP, 3); remixerFragment.attachToButton(this, remixerButton); - - SensorManager sensorManager = (SensorManager)getSystemService(SENSOR_SERVICE); - remixerFragment.attachToShake(this, sensorManager, 20.0); + remixerFragment.attachToShake(this, 20.0); } @RangeVariableMethod( diff --git a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/gesture/ShakeListener.java b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/gesture/ShakeListener.java new file mode 100644 index 0000000..92c0a27 --- /dev/null +++ b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/gesture/ShakeListener.java @@ -0,0 +1,52 @@ +package com.google.android.libraries.remixer.ui.gesture; + +import android.content.Context; +import android.hardware.Sensor; +import android.hardware.SensorEvent; +import android.hardware.SensorEventListener; +import android.hardware.SensorManager; +import android.support.v4.app.FragmentActivity; + +import com.google.android.libraries.remixer.ui.view.RemixerFragment; + +public class ShakeListener implements SensorEventListener { + private double lastMagnitude; + // TODO(nicksahler): Remove `lastSpike` once `show` bug is fixed + private long lastSpike = 0; + + private double threshold; + private final FragmentActivity activity; + private RemixerFragment remixerFragment; + + private ShakeListener(final FragmentActivity activity, final double threshold, RemixerFragment remixerFragment) { + this.activity = activity; + this.threshold = threshold; + this.remixerFragment = remixerFragment; + } + + + @Override + public void onSensorChanged(SensorEvent event) { + double currentMagnitude = Math.sqrt( + event.values[0] * event.values[0] + + event.values[1] * event.values[1] + + event.values[2] * event.values[2]); + + if ((currentMagnitude - lastMagnitude) > threshold && System.currentTimeMillis() - lastSpike > 500) { + remixerFragment.show(activity.getSupportFragmentManager(), RemixerFragment.REMIXER_TAG); + lastSpike = System.currentTimeMillis(); + } + + this.lastMagnitude = currentMagnitude; + } + + @Override + public void onAccuracyChanged(Sensor sensor, int accuracy) { } + + public static void attach(final FragmentActivity activity, final double threshold, RemixerFragment remixerFragment) { + SensorManager sensorManager = (SensorManager) activity.getSystemService(Context.SENSOR_SERVICE); + + sensorManager.registerListener(new ShakeListener(activity, threshold, remixerFragment), sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); + } + +} diff --git a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/view/RemixerFragment.java b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/view/RemixerFragment.java index ecdcd35..e5c902c 100644 --- a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/view/RemixerFragment.java +++ b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/view/RemixerFragment.java @@ -35,6 +35,7 @@ import com.google.android.libraries.remixer.ui.R; import com.google.android.libraries.remixer.ui.gesture.Direction; import com.google.android.libraries.remixer.ui.gesture.GestureListener; +import com.google.android.libraries.remixer.ui.gesture.ShakeListener; /** * A fragment that shows all Remixes for the current activity. It's very easy to use: @@ -103,29 +104,8 @@ public void show(FragmentManager manager, String tag) { /** * Attach this instance to a shake gesture using {@code sensorManager } and show fragment when magnitude exceeds {@code threshold} */ - public void attachToShake(final FragmentActivity activity, SensorManager sensorManager, final double threshold) { - this.sensorEventListener = new SensorEventListener() { - double lastMagnitude; - /* Temporary delay until `show` bug is fixed */ - long lastSpike = 0; - - @Override - public void onSensorChanged(SensorEvent event) { - double currentMagnitude = Math.sqrt(event.values[0] * event.values[0] + event.values[1] * event.values[1] + event.values[2] * event.values[2]); - - if ((currentMagnitude - lastMagnitude) > threshold && System.currentTimeMillis() - lastSpike > 500) { - show(activity.getSupportFragmentManager(), REMIXER_TAG); - lastSpike = System.currentTimeMillis(); - } - - this.lastMagnitude = currentMagnitude; - } - - @Override - public void onAccuracyChanged(Sensor sensor, int accuracy) { } - }; - - sensorManager.registerListener(sensorEventListener, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); + public void attachToShake(final FragmentActivity activity, final double threshold) { + ShakeListener.attach(activity, threshold, this); } /** From bb0319f9302181506a1882008342eabdec948dc8 Mon Sep 17 00:00:00 2001 From: Nick Sahler Date: Thu, 12 Jan 2017 17:24:06 -0500 Subject: [PATCH 13/32] Give auxiliary method to show fragment rather than overriding --- .../libraries/remixer/ui/gesture/GestureListener.java | 2 +- .../libraries/remixer/ui/gesture/ShakeListener.java | 2 +- .../android/libraries/remixer/ui/view/RemixerFragment.java | 7 +++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/gesture/GestureListener.java b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/gesture/GestureListener.java index 30f6626..e45eb38 100644 --- a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/gesture/GestureListener.java +++ b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/gesture/GestureListener.java @@ -122,7 +122,7 @@ public boolean onTouch(View view, MotionEvent motionEvent) { } } if (correctlySwiped) { - remixerFragment.show(fragmentManager, RemixerFragment.REMIXER_TAG); + remixerFragment.showRemixer(fragmentManager, RemixerFragment.REMIXER_TAG); } // fall-through case MotionEvent.ACTION_CANCEL: diff --git a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/gesture/ShakeListener.java b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/gesture/ShakeListener.java index 92c0a27..da71715 100644 --- a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/gesture/ShakeListener.java +++ b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/gesture/ShakeListener.java @@ -33,7 +33,7 @@ public void onSensorChanged(SensorEvent event) { + event.values[2] * event.values[2]); if ((currentMagnitude - lastMagnitude) > threshold && System.currentTimeMillis() - lastSpike > 500) { - remixerFragment.show(activity.getSupportFragmentManager(), RemixerFragment.REMIXER_TAG); + remixerFragment.showRemixer(activity.getSupportFragmentManager(), RemixerFragment.REMIXER_TAG); lastSpike = System.currentTimeMillis(); } diff --git a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/view/RemixerFragment.java b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/view/RemixerFragment.java index e5c902c..a8347e8 100644 --- a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/view/RemixerFragment.java +++ b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/view/RemixerFragment.java @@ -82,7 +82,7 @@ public void attachToButton(final FragmentActivity activity, Button button) { @Override public void onClick(View view) { - show(activity.getSupportFragmentManager(), REMIXER_TAG); + showRemixer(activity.getSupportFragmentManager(), REMIXER_TAG); } }); } @@ -94,10 +94,9 @@ public void onClick(View view) { * @return whether the fragment was shown or not. */ - @Override - public void show(FragmentManager manager, String tag) { + public void showRemixer(FragmentManager manager, String tag) { if (!isAdded() && !isVisible() && !isRemoving()) { - super.show(manager.beginTransaction(), tag); + show(manager, tag); } } From 16cc542db0369ae597e12e384743a88da423bce4 Mon Sep 17 00:00:00 2001 From: Nick Sahler Date: Thu, 12 Jan 2017 17:36:52 -0500 Subject: [PATCH 14/32] Improve and update documentation --- .../libraries/remixer/ui/gesture/ShakeListener.java | 12 ++++++++++-- .../libraries/remixer/ui/view/RemixerFragment.java | 5 +++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/gesture/ShakeListener.java b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/gesture/ShakeListener.java index da71715..d9ddcbe 100644 --- a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/gesture/ShakeListener.java +++ b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/gesture/ShakeListener.java @@ -8,7 +8,12 @@ import android.support.v4.app.FragmentActivity; import com.google.android.libraries.remixer.ui.view.RemixerFragment; - +/** + * A Gesture Listener that listens for magnitude of 3D acceleration to exceed a given threshold, triggering the display of a + * RemixerFragment. + * + *

      It can be set up by calling {@link #attach(FragmentActivity, double threshold)} + */ public class ShakeListener implements SensorEventListener { private double lastMagnitude; // TODO(nicksahler): Remove `lastSpike` once `show` bug is fixed @@ -43,9 +48,12 @@ public void onSensorChanged(SensorEvent event) { @Override public void onAccuracyChanged(Sensor sensor, int accuracy) { } + /** + * Attaches a ShakeListener to {@code activity} that listens for acceleration change that exceeds {@code threshold} + * and shows {@code remixerFragment} when satisfied. + */ public static void attach(final FragmentActivity activity, final double threshold, RemixerFragment remixerFragment) { SensorManager sensorManager = (SensorManager) activity.getSystemService(Context.SENSOR_SERVICE); - sensorManager.registerListener(new ShakeListener(activity, threshold, remixerFragment), sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); } diff --git a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/view/RemixerFragment.java b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/view/RemixerFragment.java index a8347e8..8f5969c 100644 --- a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/view/RemixerFragment.java +++ b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/view/RemixerFragment.java @@ -99,9 +99,10 @@ public void showRemixer(FragmentManager manager, String tag) { show(manager, tag); } } - + /** - * Attach this instance to a shake gesture using {@code sensorManager } and show fragment when magnitude exceeds {@code threshold} + * Attach this instance to a shake gesture and show fragment when magnitude exceeds {@code threshold} + * */ public void attachToShake(final FragmentActivity activity, final double threshold) { ShakeListener.attach(activity, threshold, this); From 713f3294882447cc222008ecadabbc62ea9cf34c Mon Sep 17 00:00:00 2001 From: Miguel Yanez Barreto Date: Thu, 12 Jan 2017 18:23:58 -0500 Subject: [PATCH 15/32] Remove allowBackup from manifests everywhere Fixes #111 --- remixer/src/main/AndroidManifest.xml | 8 ++++---- remixer_storage/src/main/AndroidManifest.xml | 10 ++++++---- remixer_ui/src/main/AndroidManifest.xml | 4 ++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/remixer/src/main/AndroidManifest.xml b/remixer/src/main/AndroidManifest.xml index 77a54eb..cd5d831 100644 --- a/remixer/src/main/AndroidManifest.xml +++ b/remixer/src/main/AndroidManifest.xml @@ -17,10 +17,10 @@ - + diff --git a/remixer_storage/src/main/AndroidManifest.xml b/remixer_storage/src/main/AndroidManifest.xml index 65c7d62..2e751da 100644 --- a/remixer_storage/src/main/AndroidManifest.xml +++ b/remixer_storage/src/main/AndroidManifest.xml @@ -26,10 +26,12 @@ - + tools:ignore="GradleOverrides,OldTargetApi" + /> + diff --git a/remixer_ui/src/main/AndroidManifest.xml b/remixer_ui/src/main/AndroidManifest.xml index 9a131da..34ccbc0 100644 --- a/remixer_ui/src/main/AndroidManifest.xml +++ b/remixer_ui/src/main/AndroidManifest.xml @@ -27,7 +27,7 @@ android:targetSdkVersion="24" tools:ignore="GradleOverrides,OldTargetApi"/> + android:supportsRtl="true" + /> From 0f7136ccc0e2d586d5740c4563a8657abe6e2394 Mon Sep 17 00:00:00 2001 From: Nick Sahler Date: Tue, 17 Jan 2017 18:33:12 -0500 Subject: [PATCH 16/32] Put discretionary timeout for shake in a constant --- .../android/libraries/remixer/ui/gesture/ShakeListener.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/gesture/ShakeListener.java b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/gesture/ShakeListener.java index d9ddcbe..5d06ef2 100644 --- a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/gesture/ShakeListener.java +++ b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/gesture/ShakeListener.java @@ -18,6 +18,7 @@ public class ShakeListener implements SensorEventListener { private double lastMagnitude; // TODO(nicksahler): Remove `lastSpike` once `show` bug is fixed private long lastSpike = 0; + private final int SHAKE_TIMEOUT = 500; private double threshold; private final FragmentActivity activity; @@ -37,7 +38,7 @@ public void onSensorChanged(SensorEvent event) { + event.values[1] * event.values[1] + event.values[2] * event.values[2]); - if ((currentMagnitude - lastMagnitude) > threshold && System.currentTimeMillis() - lastSpike > 500) { + if ((currentMagnitude - lastMagnitude) > threshold && System.currentTimeMillis() - lastSpike > SHAKE_TIMEOUT) { remixerFragment.showRemixer(activity.getSupportFragmentManager(), RemixerFragment.REMIXER_TAG); lastSpike = System.currentTimeMillis(); } From 76a6071e8bb6854c4ccdbddbd677202ee4057fa4 Mon Sep 17 00:00:00 2001 From: Nick Sahler Date: Tue, 17 Jan 2017 19:23:10 -0500 Subject: [PATCH 17/32] Refactor showRemixer to not depend on timing Refactor attachToShake to support pausing. Saves on resources. --- .../android/apps/remixer/MainActivity.java | 14 +++++- .../remixer/ui/gesture/ShakeListener.java | 44 ++++++++++--------- .../remixer/ui/view/RemixerFragment.java | 31 ++++++++++--- 3 files changed, 61 insertions(+), 28 deletions(-) diff --git a/remixer_example/src/main/java/com/google/android/apps/remixer/MainActivity.java b/remixer_example/src/main/java/com/google/android/apps/remixer/MainActivity.java index 76b23ba..7b5f2ed 100644 --- a/remixer_example/src/main/java/com/google/android/apps/remixer/MainActivity.java +++ b/remixer_example/src/main/java/com/google/android/apps/remixer/MainActivity.java @@ -37,6 +37,7 @@ public class MainActivity extends AppCompatActivity { private TextView titleText; private TextView freeformText; private Button remixerButton; + private RemixerFragment remixerFragment; @Override protected void onCreate(Bundle savedInstanceState) { @@ -48,12 +49,23 @@ protected void onCreate(Bundle savedInstanceState) { remixerButton = (Button) findViewById(R.id.button); RemixerBinder.bind(this); - RemixerFragment remixerFragment = RemixerFragment.newInstance(); + remixerFragment = RemixerFragment.newInstance(); remixerFragment.attachToGesture(this, Direction.UP, 3); remixerFragment.attachToButton(this, remixerButton); + } + + @Override + protected void onResume() { + super.onResume(); remixerFragment.attachToShake(this, 20.0); } + @Override + protected void onPause() { + super.onPause(); + remixerFragment.detachFromShake(this); + } + @RangeVariableMethod( key = "titleTextSize", minValue = 16, maxValue = 72, increment = 4, title = "(Shared) Title font size") diff --git a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/gesture/ShakeListener.java b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/gesture/ShakeListener.java index 5d06ef2..71d34f7 100644 --- a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/gesture/ShakeListener.java +++ b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/gesture/ShakeListener.java @@ -12,38 +12,33 @@ * A Gesture Listener that listens for magnitude of 3D acceleration to exceed a given threshold, triggering the display of a * RemixerFragment. * - *

      It can be set up by calling {@link #attach(FragmentActivity, double threshold)} + *

      It can be set up by calling {@link #attach(FragmentActivity, double threshold, RemixerFragment)} */ public class ShakeListener implements SensorEventListener { private double lastMagnitude; - // TODO(nicksahler): Remove `lastSpike` once `show` bug is fixed - private long lastSpike = 0; - private final int SHAKE_TIMEOUT = 500; private double threshold; private final FragmentActivity activity; private RemixerFragment remixerFragment; - private ShakeListener(final FragmentActivity activity, final double threshold, RemixerFragment remixerFragment) { - this.activity = activity; - this.threshold = threshold; - this.remixerFragment = remixerFragment; + public ShakeListener(final FragmentActivity activity, final double threshold, RemixerFragment remixerFragment) { + this.activity = activity; + this.threshold = threshold; + this.remixerFragment = remixerFragment; } - @Override public void onSensorChanged(SensorEvent event) { - double currentMagnitude = Math.sqrt( - event.values[0] * event.values[0] - + event.values[1] * event.values[1] - + event.values[2] * event.values[2]); + double currentMagnitude = Math.sqrt( + event.values[0] * event.values[0] + + event.values[1] * event.values[1] + + event.values[2] * event.values[2]); - if ((currentMagnitude - lastMagnitude) > threshold && System.currentTimeMillis() - lastSpike > SHAKE_TIMEOUT) { - remixerFragment.showRemixer(activity.getSupportFragmentManager(), RemixerFragment.REMIXER_TAG); - lastSpike = System.currentTimeMillis(); - } + if ((currentMagnitude - lastMagnitude) > threshold ) { + remixerFragment.showRemixer(activity.getSupportFragmentManager(), RemixerFragment.REMIXER_TAG); + } - this.lastMagnitude = currentMagnitude; + this.lastMagnitude = currentMagnitude; } @Override @@ -53,9 +48,16 @@ public void onAccuracyChanged(Sensor sensor, int accuracy) { } * Attaches a ShakeListener to {@code activity} that listens for acceleration change that exceeds {@code threshold} * and shows {@code remixerFragment} when satisfied. */ - public static void attach(final FragmentActivity activity, final double threshold, RemixerFragment remixerFragment) { - SensorManager sensorManager = (SensorManager) activity.getSystemService(Context.SENSOR_SERVICE); - sensorManager.registerListener(new ShakeListener(activity, threshold, remixerFragment), sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); + public void attach() { + SensorManager sensorManager = (SensorManager) activity.getSystemService(Context.SENSOR_SERVICE); + sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); + } + + /** + * Detaches {@code SensorListener} {@code this} from the stored activity + */ + public void detach() { + ((SensorManager) activity.getSystemService(Context.SENSOR_SERVICE)).unregisterListener(this); } } diff --git a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/view/RemixerFragment.java b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/view/RemixerFragment.java index 8f5969c..657dd11 100644 --- a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/view/RemixerFragment.java +++ b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/view/RemixerFragment.java @@ -60,6 +60,7 @@ public class RemixerFragment extends BottomSheetDialogFragment { public static final String REMIXER_TAG = "Remixer"; private Remixer remixer; + private ShakeListener shakeListener; public RemixerFragment() { remixer = Remixer.getInstance(); @@ -69,6 +70,9 @@ public static RemixerFragment newInstance() { return new RemixerFragment(); } + private boolean isAddingFragment = false; + private final Object syncLock = new Object(); + private SensorEventListener sensorEventListener; /** @@ -95,17 +99,31 @@ public void onClick(View view) { */ public void showRemixer(FragmentManager manager, String tag) { - if (!isAdded() && !isVisible() && !isRemoving()) { - show(manager, tag); + synchronized(syncLock) { + if (!isAddingFragment && !isAdded()) { + isAddingFragment = true; + show(manager, tag); + } } } - + + // TODO(nicksahler): Generalize to attaching to any SensorEventListener + /** * Attach this instance to a shake gesture and show fragment when magnitude exceeds {@code threshold} * */ public void attachToShake(final FragmentActivity activity, final double threshold) { - ShakeListener.attach(activity, threshold, this); + shakeListener = new ShakeListener(activity, threshold, this); + shakeListener.attach(); + } + + /** + * Detach from a shake gesture + * + */ + public void detachFromShake(final FragmentActivity activity) { + shakeListener.detach(); } /** @@ -138,8 +156,9 @@ public View onCreateView(LayoutInflater inflater, } @Override - public void onAttach(Context context) { - super.onAttach(context); + public void onResume() { + isAddingFragment = false; + super.onResume(); } @Override From 70ec37deb7e090b5547d1a857a26e369b80e0e59 Mon Sep 17 00:00:00 2001 From: Nick Sahler Date: Tue, 17 Jan 2017 19:44:10 -0500 Subject: [PATCH 18/32] Nullify shakelistener on detach --- .../android/libraries/remixer/ui/view/RemixerFragment.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/view/RemixerFragment.java b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/view/RemixerFragment.java index 657dd11..e6cfebb 100644 --- a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/view/RemixerFragment.java +++ b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/view/RemixerFragment.java @@ -108,10 +108,8 @@ public void showRemixer(FragmentManager manager, String tag) { } // TODO(nicksahler): Generalize to attaching to any SensorEventListener - /** * Attach this instance to a shake gesture and show fragment when magnitude exceeds {@code threshold} - * */ public void attachToShake(final FragmentActivity activity, final double threshold) { shakeListener = new ShakeListener(activity, threshold, this); @@ -120,10 +118,10 @@ public void attachToShake(final FragmentActivity activity, final double threshol /** * Detach from a shake gesture - * */ - public void detachFromShake(final FragmentActivity activity) { + public void detachFromShake() { shakeListener.detach(); + shakeListener = null; } /** From bf716a36829314ed3fdb5d2e183e8034117fc1a9 Mon Sep 17 00:00:00 2001 From: Nick Sahler Date: Wed, 18 Jan 2017 15:31:26 -0500 Subject: [PATCH 19/32] Fix build error. --- .../main/java/com/google/android/apps/remixer/MainActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remixer_example/src/main/java/com/google/android/apps/remixer/MainActivity.java b/remixer_example/src/main/java/com/google/android/apps/remixer/MainActivity.java index 7b5f2ed..182c134 100644 --- a/remixer_example/src/main/java/com/google/android/apps/remixer/MainActivity.java +++ b/remixer_example/src/main/java/com/google/android/apps/remixer/MainActivity.java @@ -63,7 +63,7 @@ protected void onResume() { @Override protected void onPause() { super.onPause(); - remixerFragment.detachFromShake(this); + remixerFragment.detachFromShake(); } @RangeVariableMethod( From f0150758cde0b539350476842e38cd308e727429 Mon Sep 17 00:00:00 2001 From: Miguel Yanez Barreto Date: Wed, 18 Jan 2017 14:54:59 -0800 Subject: [PATCH 20/32] Add dummy configuration for Firebase Services. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows us to compile adding firebase dependencies, but doesn’t expose any actual sensitive data. --- build.gradle | 1 + remixer_example/build.gradle | 3 ++ remixer_example/google-services.json | 42 ++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 remixer_example/google-services.json diff --git a/build.gradle b/build.gradle index f6d0825..7d244bf 100644 --- a/build.gradle +++ b/build.gradle @@ -26,6 +26,7 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:2.2.3' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' + classpath 'com.google.gms:google-services:3.0.0' classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' classpath 'com.vanniktech:gradle-android-junit-jacoco-plugin:0.5.0' } diff --git a/remixer_example/build.gradle b/remixer_example/build.gradle index f10c690..f798e8c 100644 --- a/remixer_example/build.gradle +++ b/remixer_example/build.gradle @@ -52,3 +52,6 @@ dependencies { compile "com.android.support:appcompat-v7:$rootProject.ext.supportLibraryVersion" compile project(':remixer') } + +// Depend on gms google services for Firebase Support, keep at the bottom. +apply plugin: 'com.google.gms.google-services' diff --git a/remixer_example/google-services.json b/remixer_example/google-services.json new file mode 100644 index 0000000..8f48703 --- /dev/null +++ b/remixer_example/google-services.json @@ -0,0 +1,42 @@ +{ + "project_info": { + "project_number": "12345", + "firebase_url": "https://myproject.firebaseio.com", + "project_id": "myproject", + "storage_bucket": "myproject.appspot.com" + }, + "client": [ + { + "client_info": { + "mobilesdk_app_id": "appid", + "android_client_info": { + "package_name": "com.google.android.apps.remixer" + } + }, + "oauth_client": [ + { + "client_id": "clientid", + "client_type": 3 + } + ], + "api_key": [ + { + "current_key": "yourkey" + } + ], + "services": { + "analytics_service": { + "status": 1 + }, + "appinvite_service": { + "status": 1, + "other_platform_oauth_client": [] + }, + "ads_service": { + "status": 2 + } + } + } + ], + "configuration_version": "1" +} From 915929c76e9252596093c63544acbc0431b8477d Mon Sep 17 00:00:00 2001 From: Miguel Yanez Barreto Date: Wed, 18 Jan 2017 14:56:46 -0800 Subject: [PATCH 21/32] Add google-services.json to gitignore. --- remixer_example/.gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 remixer_example/.gitignore diff --git a/remixer_example/.gitignore b/remixer_example/.gitignore new file mode 100644 index 0000000..20a3826 --- /dev/null +++ b/remixer_example/.gitignore @@ -0,0 +1,3 @@ +/build +# Do not put sensitive firebase information in the repo :) +google-services.json From 295d6e449a0dbe4eeb19c114e112deda9afdda11 Mon Sep 17 00:00:00 2001 From: Miguel Yanez Barreto Date: Thu, 19 Jan 2017 14:50:33 -0800 Subject: [PATCH 22/32] Add basic syncing to firebase where the local device is the source of truth. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -Each device gets its own object in firebase so devices are isolated and there is no cross-device syncing. -The root object for each device is “remixer/” -DEVICE_REMOTE_ID is the first 8 digits of a randomly generated UUID (not personally identifiable). -DEVICE_REMOTE_ID is persisted across application restarts until data is cleared. That will allow to reuse the same URL across different runs targeting the same app/device combination. -Deserialization is done manually, because type erasure in Java makes it near impossible to deal with types. This way the remixer type system remains extensible. --- .../android/libraries/remixer/DataType.java | 21 ++- .../SerializableRemixerContents.java | 12 +- .../remixer/serialization/StoredVariable.java | 18 +-- .../apps/remixer/RemixerApplication.java | 14 +- remixer_storage/build.gradle | 2 + remixer_storage/proguard-rules.pro | 24 +-- .../FirebaseRemoteControllerSyncer.java | 151 ++++++++++++++++-- .../storage/FirebaseSerializationHelper.java | 102 ++++++++++++ 8 files changed, 298 insertions(+), 46 deletions(-) create mode 100644 remixer_storage/src/main/java/com/google/android/libraries/remixer/storage/FirebaseSerializationHelper.java diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/DataType.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/DataType.java index c8890d7..b97afe4 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/DataType.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/DataType.java @@ -29,10 +29,16 @@ public class DataType { */ private final Class runtimeType; + /** + * The serializable class of the values contained by this variable. + */ + private final Class serializableType; + /** * The value converter that aids in the serialization process. */ private final ValueConverter converter; + /** * Map of default layout ids for this datatype when used with a specific RemixerItem class. * @@ -52,9 +58,11 @@ public class DataType { public DataType( String name, Class runtimeType, + Class serializableType, ValueConverter converter) { this.name = name; this.runtimeType = runtimeType; + this.serializableType = serializableType; this.converter = converter; if (!name.equals(converter.getDataType())) { throw new AssertionError(String.format( @@ -103,26 +111,29 @@ public Class getRuntimeType() { return runtimeType; } + public Class getSerializableType() { + return serializableType; + } + public ValueConverter getConverter() { return converter; } // ======= Default data types defined here. - private static final String KEY_BOOLEAN = "__DataTypeBoolean__"; private static final String KEY_COLOR = "__DataTypeColor__"; private static final String KEY_NUMBER = "__DataTypeNumber__"; private static final String KEY_STRING = "__DataTypeString__"; public static final DataType BOOLEAN = new DataType<>( - KEY_BOOLEAN, Boolean.class, new BooleanValueConverter(KEY_BOOLEAN)); + KEY_BOOLEAN, Boolean.class, Boolean.class, new BooleanValueConverter(KEY_BOOLEAN)); public static final DataType COLOR = new DataType<>( - KEY_COLOR, Integer.class, new ColorValueConverter(KEY_COLOR)); + KEY_COLOR, Integer.class, SerializedColor.class, new ColorValueConverter(KEY_COLOR)); public static final DataType NUMBER = new DataType<>( - KEY_NUMBER, Float.class, new FloatValueConverter(KEY_NUMBER)); + KEY_NUMBER, Float.class, Float.class, new FloatValueConverter(KEY_NUMBER)); public static final DataType STRING = new DataType<>( - KEY_STRING, String.class, new StringValueConverter(KEY_STRING)); + KEY_STRING, String.class, String.class, new StringValueConverter(KEY_STRING)); } diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/SerializableRemixerContents.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/SerializableRemixerContents.java index 252a3fe..80c2bc4 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/SerializableRemixerContents.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/SerializableRemixerContents.java @@ -112,11 +112,21 @@ public int hashCode() { /** * Sets the value for the StoredVariable with key {@code variable.getKey()}. Must be called only - * after calling {@link #addItem(RemixerItem)} for a variable with this key. + * after calling {@link #addItem(Variable)} or {@link #addItem(StoredVariable)} for a variable + * with this key. */ @SuppressWarnings("unchecked") public void setValue(Variable variable) { StoredVariable storedVariable = StoredVariable.fromVariable(variable); + setValue(storedVariable); + } + + /** + * Sets the value for the StoredVariable with key {@code storedVariable.key}. Must be called only + * after calling {@link #addItem(Variable)} or {@link #addItem(StoredVariable)} for a variable + * with this key. + */ + public void setValue(StoredVariable storedVariable) { StoredVariable existingStoredVariable = keyToDataMap.get(storedVariable.key); if (!existingStoredVariable.isCompatibleWith(storedVariable)) { throw new IncompatibleRemixerItemsWithSameKeyException( diff --git a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/StoredVariable.java b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/StoredVariable.java index aeddb3d..b1be14e 100644 --- a/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/StoredVariable.java +++ b/remixer_core/src/main/java/com/google/android/libraries/remixer/serialization/StoredVariable.java @@ -53,15 +53,15 @@ public class StoredVariable { public final static String RANGE_VARIABLE_CONSTRAINT = "__ConstraintTypeRange__"; // Json dictionary keys to serialize this object - static final String KEY = "key"; - static final String TITLE = "title"; - static final String CONSTRAINT_TYPE = "constraintType"; - static final String DATA_TYPE = "dataType"; - static final String SELECTED_VALUE = "selectedValue"; - static final String LIMITED_TO_VALUES = "limitedToValues"; - static final String MIN_VALUE = "minValue"; - static final String MAX_VALUE = "maxValue"; - static final String INCREMENT = "increment"; + public static final String KEY = "key"; + public static final String TITLE = "title"; + public static final String CONSTRAINT_TYPE = "constraintType"; + public static final String DATA_TYPE = "dataType"; + public static final String SELECTED_VALUE = "selectedValue"; + public static final String LIMITED_TO_VALUES = "limitedToValues"; + public static final String MIN_VALUE = "minValue"; + public static final String MAX_VALUE = "maxValue"; + public static final String INCREMENT = "increment"; /** * The RemixerItem's key. diff --git a/remixer_example/src/main/java/com/google/android/apps/remixer/RemixerApplication.java b/remixer_example/src/main/java/com/google/android/apps/remixer/RemixerApplication.java index e4221aa..3dcf51d 100644 --- a/remixer_example/src/main/java/com/google/android/apps/remixer/RemixerApplication.java +++ b/remixer_example/src/main/java/com/google/android/apps/remixer/RemixerApplication.java @@ -18,6 +18,7 @@ import android.app.Application; import com.google.android.libraries.remixer.Remixer; +import com.google.android.libraries.remixer.storage.FirebaseRemoteControllerSyncer; import com.google.android.libraries.remixer.storage.LocalStorage; import com.google.android.libraries.remixer.ui.RemixerInitialization; @@ -31,10 +32,21 @@ */ public class RemixerApplication extends Application { + // Keep this off so there is no need for proper Firebase credentials for the example app out of + // the box. You can change it to true if you update the google-services.json file. + private static final boolean USE_FIREBASE_REMOTE_CONTROLLER = false; + @Override public void onCreate() { super.onCreate(); RemixerInitialization.initRemixer(this); - Remixer.getInstance().setSynchronizationMechanism(new LocalStorage(getApplicationContext())); + if (USE_FIREBASE_REMOTE_CONTROLLER) { + FirebaseRemoteControllerSyncer syncer = + new FirebaseRemoteControllerSyncer(getApplicationContext()); + Remixer.getInstance().setSynchronizationMechanism(syncer); + syncer.startSyncing(); + } else { + Remixer.getInstance().setSynchronizationMechanism(new LocalStorage(getApplicationContext())); + } } } diff --git a/remixer_storage/build.gradle b/remixer_storage/build.gradle index fdbe01a..34d7f99 100644 --- a/remixer_storage/build.gradle +++ b/remixer_storage/build.gradle @@ -54,6 +54,8 @@ dependencies { compile project(':remixer_core') compile project(':remixer_ui') compile 'com.google.code.gson:gson:2.7' + compile 'com.google.firebase:firebase-core:10.0.1' + compile 'com.google.firebase:firebase-database:10.0.1' androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) diff --git a/remixer_storage/proguard-rules.pro b/remixer_storage/proguard-rules.pro index 89cce70..b57b9bc 100644 --- a/remixer_storage/proguard-rules.pro +++ b/remixer_storage/proguard-rules.pro @@ -1,17 +1,9 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in /Users/miguely/Library/Android/sdk/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html +# Add this global rule +-keepattributes Signature -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} +# This rule will properly ProGuard all the model classes in +# the package com.yourcompany.models. Modify to fit the structure +# of your app. +-keepclassmembers class com.google.android.libraries.remixer.serialization.** { + *; +} diff --git a/remixer_storage/src/main/java/com/google/android/libraries/remixer/storage/FirebaseRemoteControllerSyncer.java b/remixer_storage/src/main/java/com/google/android/libraries/remixer/storage/FirebaseRemoteControllerSyncer.java index 5ac52be..1232656 100644 --- a/remixer_storage/src/main/java/com/google/android/libraries/remixer/storage/FirebaseRemoteControllerSyncer.java +++ b/remixer_storage/src/main/java/com/google/android/libraries/remixer/storage/FirebaseRemoteControllerSyncer.java @@ -17,28 +17,105 @@ package com.google.android.libraries.remixer.storage; import android.content.Context; +import android.content.SharedPreferences; import com.google.android.libraries.remixer.Remixer; import com.google.android.libraries.remixer.Variable; +import com.google.android.libraries.remixer.serialization.StoredVariable; import com.google.android.libraries.remixer.sync.LocalValueSyncing; import com.google.android.libraries.remixer.sync.SynchronizationMechanism; +import com.google.firebase.database.ChildEventListener; +import com.google.firebase.database.DataSnapshot; +import com.google.firebase.database.DatabaseError; +import com.google.firebase.database.DatabaseReference; +import com.google.firebase.database.FirebaseDatabase; import java.lang.ref.WeakReference; +import java.util.List; +import java.util.Locale; +import java.util.UUID; /** * A {@link SynchronizationMechanism} that syncs up to a firebase Remote Controller. * *

      This synchronization mechanism assumes that the local host is the source of truth, so it does * very little in terms of conflict resolution. - * - *

      This implementation currently ignores bringing new values in from the remote controller, that - * will be done in firebase callbacks in a future PR, so it is a different one that introduces said - * dependency. */ -public class FirebaseRemoteControllerSyncer extends LocalValueSyncing { +public class FirebaseRemoteControllerSyncer + extends LocalValueSyncing implements ChildEventListener { - WeakReference context; + /** + * The reference to the root element for this Remixer Instance in the database + */ + private DatabaseReference reference; + /** + * The current context that is active on the app (foreground activity). + */ + private WeakReference context; - public FirebaseRemoteControllerSyncer() { + /** + * Whether syncing is enabled or not. All accesses to this field must be synchronized. + */ + private boolean syncing = false; + + /** + * The autogenerated id for this instance of Remixer. This is the first 8 characters of a random + * UUID that would identify this device. + */ + private String remoteId; + + private static final String PREFERENCES_FILE_NAME = "remixer_firebase"; + private static final String REMOTE_ID = "remote_id"; + private static final String REFERENCE_FORMAT = "remixer/%s"; + + /** + * Initializes a {@code FirebaseRemoteControllerSyncer} instance. + * + *

      Uses {@code context} to get + */ + public FirebaseRemoteControllerSyncer(Context context) { super(); + SharedPreferences preferences = + context.getSharedPreferences(PREFERENCES_FILE_NAME, Context.MODE_PRIVATE); + remoteId = preferences.getString(REMOTE_ID, null); + if (remoteId == null) { + remoteId = UUID.randomUUID().toString().substring(0, 7); + preferences.edit().putString(REMOTE_ID, remoteId).apply(); + } + startSyncing(); + } + + /** + * Starts syncing up to Firebase. + * + *

      Since we don't know what the status of the database is right now, we clear the value and + * then add everything for the current context, then add this instance as a child event listener. + * + *

      That way we get notified of changes to children (individual variables) after the initial + * sync. + */ + public synchronized void startSyncing() { + reference = FirebaseDatabase.getInstance().getReference( + String.format(Locale.getDefault(), REFERENCE_FORMAT, remoteId)); + reference.removeValue(); + clearVariablesInRemoteController(); + syncing = true; + if (context != null && context.get() != null) { + for (Variable variable : Remixer.getInstance().getVariablesWithContext(context.get())) { + syncVariableToRemoteController(StoredVariable.fromVariable(variable)); + } + } + reference.addChildEventListener(this); + } + + /** + * Stops syncing to firebase, removes this instance as listener for changes and clears the + * values in Firebase. + */ + public synchronized void stopSyncing() { + if (syncing) { + syncing = false; + reference.removeEventListener(this); + clearVariablesInRemoteController(); + } } /** @@ -49,27 +126,30 @@ public FirebaseRemoteControllerSyncer() { * happen in practice though, since variables in remote controllers are tied to a single instance * of the app (one specific device running the app). */ - private void syncVariableToRemoteController (Variable variable) { - // TODO(miguely): write controller sync logic + private synchronized void syncVariableToRemoteController (StoredVariable variable) { + if (syncing) { + reference.child(variable.getKey()).setValue(variable); + } } /** * Clears all the data in a remote. */ private void clearVariablesInRemoteController() { - // TODO(miguely): write controller sync logic + reference.removeValue(); } + // Overrides from LocalValueSyncing @Override public void onAddingVariable(Variable variable) { super.onAddingVariable(variable); - syncVariableToRemoteController(variable); + syncVariableToRemoteController(StoredVariable.fromVariable(variable)); } @Override public void onValueChanged(Variable variable) { super.onValueChanged(variable); - syncVariableToRemoteController(variable); + syncVariableToRemoteController(StoredVariable.fromVariable(variable)); } @Override @@ -79,8 +159,11 @@ public void onContextChanged(Object currentContext) { (context != null && currentContext != context.get())) { context = new WeakReference(context); clearVariablesInRemoteController(); - for (Variable var : Remixer.getInstance().getVariablesWithContext(currentContext)) { - syncVariableToRemoteController(var); + List variables = Remixer.getInstance().getVariablesWithContext(currentContext); + if (variables != null) { + for (Variable var : variables) { + syncVariableToRemoteController(StoredVariable.fromVariable(var)); + } } } } @@ -90,6 +173,46 @@ public void onContextRemoved(Object currentContext) { super.onContextRemoved(currentContext); if (context != null && context.get() == currentContext) { clearVariablesInRemoteController(); + context = null; + } + } + + // Implementation of ChildEventListener + @Override + public void onChildAdded(DataSnapshot dataSnapshot, String s) { + // Add it to serializableRemixerContents if it does not exist. If it does exist let the local + // value take precedence and ignore the one coming from firebase. + if (!serializableRemixerContents.keySet().contains(s)) { + serializableRemixerContents.addItem(FirebaseSerializationHelper.deserializeStoredVariable(dataSnapshot)); + } + } + + /** + * + */ + @Override + public void onChildChanged(DataSnapshot dataSnapshot, String s) { + StoredVariable storedVariable = FirebaseSerializationHelper.deserializeStoredVariable(dataSnapshot); + serializableRemixerContents.setValue(storedVariable); + Object valueFromFirebase = Remixer.getDataType(storedVariable.getDataType()) + .getConverter().toRuntimeType(storedVariable.getSelectedValue()); + for (Variable variable : Remixer.getInstance().getVariablesWithKey(storedVariable.getKey())) { + variable.setValueWithoutNotifyingOthers(valueFromFirebase); } } + + @Override + public void onChildRemoved(DataSnapshot dataSnapshot) { + // This shouldn't happen. + } + + @Override + public void onChildMoved(DataSnapshot dataSnapshot, String s) { + // This shouldn't happen. + } + + @Override + public void onCancelled(DatabaseError databaseError) { + + } } diff --git a/remixer_storage/src/main/java/com/google/android/libraries/remixer/storage/FirebaseSerializationHelper.java b/remixer_storage/src/main/java/com/google/android/libraries/remixer/storage/FirebaseSerializationHelper.java new file mode 100644 index 0000000..63462cc --- /dev/null +++ b/remixer_storage/src/main/java/com/google/android/libraries/remixer/storage/FirebaseSerializationHelper.java @@ -0,0 +1,102 @@ +/* + * Copyright 2017 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.android.libraries.remixer.storage; + +import static com.google.android.libraries.remixer.serialization.StoredVariable.CONSTRAINT_TYPE; +import static com.google.android.libraries.remixer.serialization.StoredVariable.DATA_TYPE; +import static com.google.android.libraries.remixer.serialization.StoredVariable.INCREMENT; +import static com.google.android.libraries.remixer.serialization.StoredVariable.KEY; +import static com.google.android.libraries.remixer.serialization.StoredVariable.LIMITED_TO_VALUES; +import static com.google.android.libraries.remixer.serialization.StoredVariable.MAX_VALUE; +import static com.google.android.libraries.remixer.serialization.StoredVariable.MIN_VALUE; +import static com.google.android.libraries.remixer.serialization.StoredVariable.SELECTED_VALUE; +import static com.google.android.libraries.remixer.serialization.StoredVariable.TITLE; + +import com.google.android.libraries.remixer.DataType; +import com.google.android.libraries.remixer.Remixer; +import com.google.android.libraries.remixer.serialization.StoredVariable; +import com.google.firebase.database.DataSnapshot; +import com.google.firebase.database.GenericTypeIndicator; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +/** + * Helper class to deserialize Stored Variables. They cannot be directly deserialized because of + * type erasure in Java. + * + *

      Unless you know the type ahead of compile time, there is no way to pass a correctly formed + * {@link GenericTypeIndicator} for firebase to use when deserializing StoredVariables or even Lists + * for that matter. Since the whole point of remixer variables is to not know their type ahead of + * time, these have to be manually deserialized. + */ +class FirebaseSerializationHelper { + /** + * Deserializes a value of type {@code clazz} from {@code dataSnapshot}'s child keyed by + * {@code key}. + */ + private static T getValue(DataSnapshot dataSnapshot, String key, Class clazz) { + return dataSnapshot.child(key).getValue(clazz); + } + + /** + * Deserializes a list of values of type {@code clazz} from {@code dataSnapshot}'s child keyed by + * {@code key}. + */ + private static List getValueList( + DataSnapshot dataSnapshot, String key, Class serializableType) { + List list = new ArrayList<>(); + for (DataSnapshot child : dataSnapshot.child(key).getChildren()) { + list.add(child.getValue(serializableType)); + } + return list; + } + + /** + * Deserializes an entire {@link StoredVariable} from the given {@code dataSnapshot}. + */ + @SuppressWarnings("unchecked") + public static StoredVariable deserializeStoredVariable(DataSnapshot dataSnapshot) { + StoredVariable variable = new StoredVariable(); + variable.setKey(getValue(dataSnapshot, KEY, String.class)); + variable.setTitle(getValue(dataSnapshot, TITLE, String.class)); + variable.setConstraintType( + getValue(dataSnapshot, CONSTRAINT_TYPE, String.class)); + variable.setDataType(getValue(dataSnapshot, DATA_TYPE, String.class)); + DataType dataType = Remixer.getDataType(variable.getDataType()); + variable.setSelectedValue( + getValue(dataSnapshot, SELECTED_VALUE, dataType.getSerializableType())); + if (dataSnapshot.hasChild(LIMITED_TO_VALUES)) { + variable.setLimitedToValues( + getValueList(dataSnapshot, LIMITED_TO_VALUES, dataType.getSerializableType())); + + } + if (dataSnapshot.hasChild(MIN_VALUE)) { + variable.setMinValue( + getValue(dataSnapshot, MIN_VALUE, dataType.getSerializableType())); + } + if (dataSnapshot.hasChild(MAX_VALUE)) { + variable.setMaxValue( + getValue(dataSnapshot, MAX_VALUE, dataType.getSerializableType())); + } + if (dataSnapshot.hasChild(INCREMENT)) { + variable.setIncrement( + getValue(dataSnapshot, INCREMENT, dataType.getSerializableType())); + } + return variable; + } +} From 627055b6a8be11d06b8d4b1987e943a12cf6eb9a Mon Sep 17 00:00:00 2001 From: Miguel Yanez Barreto Date: Thu, 19 Jan 2017 15:58:54 -0800 Subject: [PATCH 23/32] Add play services to travis config --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 1f2aa3a..73b3eab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,10 @@ android: - platform-tools #latest - build-tools-25.0.0 - android-25 + - extra-android-support - extra-android-m2repository + - extra-google-google_play_services + before_install: - echo yes | android update sdk --filter extra-android-m2repository --no-ui --force > /dev/null From 3a9586789b68a355ee4f7bb5b044d107e59c0eca Mon Sep 17 00:00:00 2001 From: Miguel Yanez Barreto Date: Thu, 19 Jan 2017 16:16:59 -0800 Subject: [PATCH 24/32] Emulate Firebase quickstart travis config file --- .travis.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.travis.yml b/.travis.yml index 73b3eab..05f5e3a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,8 @@ android: - extra-android-support - extra-android-m2repository - extra-google-google_play_services + - extra-google-m2repository + - addon-google_apis-google-25 before_install: @@ -25,6 +27,15 @@ before_install: licenses: - 'android-sdk-license-.+' + - 'google-gdk-license-.+' + +before_cache: + - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock + - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ +cache: + directories: + - $HOME/.gradle/caches/ + - $HOME/.gradle/wrapper/ script: - ./gradlew check jacocoTestReport From 64d13e51c3847050f36242b799b19fe872513153 Mon Sep 17 00:00:00 2001 From: Miguel Yanez Barreto Date: Thu, 19 Jan 2017 17:39:43 -0800 Subject: [PATCH 25/32] =?UTF-8?q?Clean=20up=20after=20mark=E2=80=99s=20com?= =?UTF-8?q?ments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Rename arguments that had no meaningful name - Complete Javadoc - Remove one-liner method. - improve proguard file - Remove useless gitignore. --- remixer_example/.gitignore | 3 -- .../apps/remixer/RemixerApplication.java | 4 +-- remixer_storage/proguard-rules.pro | 4 +-- .../FirebaseRemoteControllerSyncer.java | 29 +++++++++---------- 4 files changed, 16 insertions(+), 24 deletions(-) delete mode 100644 remixer_example/.gitignore diff --git a/remixer_example/.gitignore b/remixer_example/.gitignore deleted file mode 100644 index 20a3826..0000000 --- a/remixer_example/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/build -# Do not put sensitive firebase information in the repo :) -google-services.json diff --git a/remixer_example/src/main/java/com/google/android/apps/remixer/RemixerApplication.java b/remixer_example/src/main/java/com/google/android/apps/remixer/RemixerApplication.java index 3dcf51d..252d9d7 100644 --- a/remixer_example/src/main/java/com/google/android/apps/remixer/RemixerApplication.java +++ b/remixer_example/src/main/java/com/google/android/apps/remixer/RemixerApplication.java @@ -42,11 +42,11 @@ public void onCreate() { RemixerInitialization.initRemixer(this); if (USE_FIREBASE_REMOTE_CONTROLLER) { FirebaseRemoteControllerSyncer syncer = - new FirebaseRemoteControllerSyncer(getApplicationContext()); + new FirebaseRemoteControllerSyncer(this); Remixer.getInstance().setSynchronizationMechanism(syncer); syncer.startSyncing(); } else { - Remixer.getInstance().setSynchronizationMechanism(new LocalStorage(getApplicationContext())); + Remixer.getInstance().setSynchronizationMechanism(new LocalStorage(this)); } } } diff --git a/remixer_storage/proguard-rules.pro b/remixer_storage/proguard-rules.pro index b57b9bc..2b8db94 100644 --- a/remixer_storage/proguard-rules.pro +++ b/remixer_storage/proguard-rules.pro @@ -1,9 +1,7 @@ # Add this global rule -keepattributes Signature -# This rule will properly ProGuard all the model classes in -# the package com.yourcompany.models. Modify to fit the structure -# of your app. +# keep all the serialization-related classes. -keepclassmembers class com.google.android.libraries.remixer.serialization.** { *; } diff --git a/remixer_storage/src/main/java/com/google/android/libraries/remixer/storage/FirebaseRemoteControllerSyncer.java b/remixer_storage/src/main/java/com/google/android/libraries/remixer/storage/FirebaseRemoteControllerSyncer.java index 1232656..cc78f6b 100644 --- a/remixer_storage/src/main/java/com/google/android/libraries/remixer/storage/FirebaseRemoteControllerSyncer.java +++ b/remixer_storage/src/main/java/com/google/android/libraries/remixer/storage/FirebaseRemoteControllerSyncer.java @@ -69,7 +69,8 @@ public class FirebaseRemoteControllerSyncer /** * Initializes a {@code FirebaseRemoteControllerSyncer} instance. * - *

      Uses {@code context} to get + *

      Uses {@code context} to get the Remote ID from shared preferences (or persist a generated + * one if it does not yet exist). */ public FirebaseRemoteControllerSyncer(Context context) { super(); @@ -96,7 +97,6 @@ public synchronized void startSyncing() { reference = FirebaseDatabase.getInstance().getReference( String.format(Locale.getDefault(), REFERENCE_FORMAT, remoteId)); reference.removeValue(); - clearVariablesInRemoteController(); syncing = true; if (context != null && context.get() != null) { for (Variable variable : Remixer.getInstance().getVariablesWithContext(context.get())) { @@ -114,7 +114,7 @@ public synchronized void stopSyncing() { if (syncing) { syncing = false; reference.removeEventListener(this); - clearVariablesInRemoteController(); + reference.removeValue(); } } @@ -132,13 +132,6 @@ private synchronized void syncVariableToRemoteController (StoredVariable variabl } } - /** - * Clears all the data in a remote. - */ - private void clearVariablesInRemoteController() { - reference.removeValue(); - } - // Overrides from LocalValueSyncing @Override public void onAddingVariable(Variable variable) { @@ -158,7 +151,9 @@ public void onContextChanged(Object currentContext) { if ((context == null && currentContext != null) || (context != null && currentContext != context.get())) { context = new WeakReference(context); - clearVariablesInRemoteController(); + if (reference != null) { + reference.removeValue(); + } List variables = Remixer.getInstance().getVariablesWithContext(currentContext); if (variables != null) { for (Variable var : variables) { @@ -172,17 +167,19 @@ public void onContextChanged(Object currentContext) { public void onContextRemoved(Object currentContext) { super.onContextRemoved(currentContext); if (context != null && context.get() == currentContext) { - clearVariablesInRemoteController(); + if (reference != null) { + reference.removeValue(); + } context = null; } } // Implementation of ChildEventListener @Override - public void onChildAdded(DataSnapshot dataSnapshot, String s) { + public void onChildAdded(DataSnapshot dataSnapshot, String childKey) { // Add it to serializableRemixerContents if it does not exist. If it does exist let the local // value take precedence and ignore the one coming from firebase. - if (!serializableRemixerContents.keySet().contains(s)) { + if (!serializableRemixerContents.keySet().contains(childKey)) { serializableRemixerContents.addItem(FirebaseSerializationHelper.deserializeStoredVariable(dataSnapshot)); } } @@ -191,7 +188,7 @@ public void onChildAdded(DataSnapshot dataSnapshot, String s) { * */ @Override - public void onChildChanged(DataSnapshot dataSnapshot, String s) { + public void onChildChanged(DataSnapshot dataSnapshot, String childKey) { StoredVariable storedVariable = FirebaseSerializationHelper.deserializeStoredVariable(dataSnapshot); serializableRemixerContents.setValue(storedVariable); Object valueFromFirebase = Remixer.getDataType(storedVariable.getDataType()) @@ -207,7 +204,7 @@ public void onChildRemoved(DataSnapshot dataSnapshot) { } @Override - public void onChildMoved(DataSnapshot dataSnapshot, String s) { + public void onChildMoved(DataSnapshot dataSnapshot, String childKey) { // This shouldn't happen. } From c302ae45323a89c792dd49dab71bb78709373ea5 Mon Sep 17 00:00:00 2001 From: Miguel Yanez Barreto Date: Fri, 20 Jan 2017 16:59:11 -0800 Subject: [PATCH 26/32] Explain proguard rules. --- remixer_storage/proguard-rules.pro | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/remixer_storage/proguard-rules.pro b/remixer_storage/proguard-rules.pro index 2b8db94..54b8d91 100644 --- a/remixer_storage/proguard-rules.pro +++ b/remixer_storage/proguard-rules.pro @@ -1,4 +1,5 @@ -# Add this global rule +# Necessary to use DatabaseReference.setValue(Object), see +# https://firebase.google.com/docs/database/android/start/ -keepattributes Signature # keep all the serialization-related classes. From de1644d1852610fa602112a946b54f7a218c531d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Andr=C3=A9s=20Y=C3=A1=C3=B1ez=20Barreto?= Date: Mon, 30 Jan 2017 14:51:48 -0500 Subject: [PATCH 27/32] Refactor layout to align things properly, add a close button. (#119) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Refactor layout to align things properly, add a close button. * Fix tests and reply to Mark’s comments: 1. add a project.properties file to remixer_ui/src/main/ so Robolectric knows to look at Support Library’s code for styles. 2. Set a theme across AndroidManifest files and the corresponding tools:replace in the app’s manifest. 3. Inline close code. 4. explicitly state the horizontal orientation on BooleanVariableWidget. 5. Add remixer text styles. 6. Format xml files (sort parameters and so forth). --- remixer_example/src/main/AndroidManifest.xml | 2 +- remixer_ui/src/main/AndroidManifest.xml | 2 +- .../remixer/ui/view/RemixerFragment.java | 15 ++++--- .../ui/widget/BooleanVariableWidget.java | 3 +- remixer_ui/src/main/project.properties | 24 ++++++++++ .../res/drawable-hdpi/ic_close_black_24dp.png | Bin 0 -> 207 bytes .../res/drawable-mdpi/ic_close_black_24dp.png | Bin 0 -> 164 bytes .../drawable-xhdpi/ic_close_black_24dp.png | Bin 0 -> 235 bytes .../drawable-xxhdpi/ic_close_black_24dp.png | Bin 0 -> 309 bytes .../drawable-xxxhdpi/ic_close_black_24dp.png | Bin 0 -> 377 bytes .../res/layout/boolean_variable_widget.xml | 17 +++---- .../res/layout/color_list_variable_widget.xml | 7 +-- .../main/res/layout/fragment_remixer_list.xml | 11 ++--- .../res/layout/item_list_spinner_view.xml | 2 +- .../res/layout/item_list_variable_widget.xml | 9 ++-- .../src/main/res/layout/remixer_header.xml | 42 ++++++++++++++++++ .../layout/seekbar_range_variable_widget.xml | 7 ++- .../res/layout/string_variable_widget.xml | 4 +- remixer_ui/src/main/res/values/styles.xml | 8 +++- 19 files changed, 118 insertions(+), 35 deletions(-) create mode 100644 remixer_ui/src/main/project.properties create mode 100755 remixer_ui/src/main/res/drawable-hdpi/ic_close_black_24dp.png create mode 100755 remixer_ui/src/main/res/drawable-mdpi/ic_close_black_24dp.png create mode 100755 remixer_ui/src/main/res/drawable-xhdpi/ic_close_black_24dp.png create mode 100755 remixer_ui/src/main/res/drawable-xxhdpi/ic_close_black_24dp.png create mode 100755 remixer_ui/src/main/res/drawable-xxxhdpi/ic_close_black_24dp.png create mode 100644 remixer_ui/src/main/res/layout/remixer_header.xml diff --git a/remixer_example/src/main/AndroidManifest.xml b/remixer_example/src/main/AndroidManifest.xml index dc1873d..554efa1 100644 --- a/remixer_example/src/main/AndroidManifest.xml +++ b/remixer_example/src/main/AndroidManifest.xml @@ -36,7 +36,7 @@ android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme" - tools:replace="android:allowBackup"> + tools:replace="android:theme"> diff --git a/remixer_ui/src/main/AndroidManifest.xml b/remixer_ui/src/main/AndroidManifest.xml index 34ccbc0..20bf08e 100644 --- a/remixer_ui/src/main/AndroidManifest.xml +++ b/remixer_ui/src/main/AndroidManifest.xml @@ -29,5 +29,5 @@ + android:theme="@style/RemixerTheme"/> diff --git a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/view/RemixerFragment.java b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/view/RemixerFragment.java index e6cfebb..43b3313 100644 --- a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/view/RemixerFragment.java +++ b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/view/RemixerFragment.java @@ -16,21 +16,18 @@ package com.google.android.libraries.remixer.ui.view; -import android.content.Context; -import android.hardware.Sensor; -import android.hardware.SensorEvent; import android.hardware.SensorEventListener; -import android.hardware.SensorManager; import android.os.Bundle; import android.support.design.widget.BottomSheetDialogFragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentTransaction; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; - +import android.widget.ImageView; import com.google.android.libraries.remixer.Remixer; import com.google.android.libraries.remixer.ui.R; import com.google.android.libraries.remixer.ui.gesture.Direction; @@ -146,7 +143,13 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_remixer_list, container, false); - + ImageView closeButton = (ImageView) view.findViewById(R.id.closeButton); + closeButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + RemixerFragment.this.getFragmentManager().beginTransaction().remove(RemixerFragment.this).commit(); + } + }); RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.remixerList); recyclerView.setAdapter( new RemixerAdapter(remixer.getVariablesWithContext(getActivity()))); diff --git a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/widget/BooleanVariableWidget.java b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/widget/BooleanVariableWidget.java index b2d0e1d..69f8585 100644 --- a/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/widget/BooleanVariableWidget.java +++ b/remixer_ui/src/main/java/com/google/android/libraries/remixer/ui/widget/BooleanVariableWidget.java @@ -22,6 +22,7 @@ import android.util.AttributeSet; import android.view.View; import android.widget.CompoundButton; +import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.Switch; import android.widget.TextView; @@ -32,7 +33,7 @@ * Displays an {@link Variable <Boolean>} as a switch. */ @Keep -public class BooleanVariableWidget extends RelativeLayout +public class BooleanVariableWidget extends LinearLayout implements RemixerWidget> { private TextView nameText; diff --git a/remixer_ui/src/main/project.properties b/remixer_ui/src/main/project.properties new file mode 100644 index 0000000..8bc9832 --- /dev/null +++ b/remixer_ui/src/main/project.properties @@ -0,0 +1,24 @@ +# +# Copyright 2017 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +# This file is necessary for Robolectric to find themes and styles defined in the support libraries. +# If this file is not present, pointing to the "exploded aars" of these libraries, Robolectric will +# throw an exception while trying to inflate the custom views with custom styles. +# http://stackoverflow.com/questions/17627671/custom-layout-inflation-with-fragments-in-robolectric-not-working/18014423#18014423 + +android.library.reference.1=../../build/intermediates/exploded-aar/com.android.support/support-v4/25.0.0 +android.library.reference.2=../../build/intermediates/exploded-aar/com.android.support/appcompat-v7/25.0.0 diff --git a/remixer_ui/src/main/res/drawable-hdpi/ic_close_black_24dp.png b/remixer_ui/src/main/res/drawable-hdpi/ic_close_black_24dp.png new file mode 100755 index 0000000000000000000000000000000000000000..1a9cd75a0d2692fa380f367bdb41c2420df310b0 GIT binary patch literal 207 zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k0wldT1B8LpG*1`DkP61PSG>8J9RwIIzPh7b zJflYMsk(bE^P@Beu4=(eGmA7oyR_x~a$D?{a5p37g|Cs|p&E~Q4@@WZu3cW0RzKfl zOG4W1`7gJ literal 0 HcmV?d00001 diff --git a/remixer_ui/src/main/res/drawable-mdpi/ic_close_black_24dp.png b/remixer_ui/src/main/res/drawable-mdpi/ic_close_black_24dp.png new file mode 100755 index 0000000000000000000000000000000000000000..40a1a84e34f4fb9c31b1dccf1b2bd7f5a50ac00d GIT binary patch literal 164 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM0wlfaz7_+iY)==*kP619lQs%6EAp^x=L~Fl z``+Hk)n=Dm!pL5PtJwWQDwD%^7mKX72vfc*YT)xac;A{}-v*=ps zr9JO5s)Jrvt$1~wJ<6?Hv?}9?*Yy)i*G<&jSt@L~vF4xM{qD^_8RvC6y^4F&G81Sm NgQu&X%Q~loCIAp8KMVi> literal 0 HcmV?d00001 diff --git a/remixer_ui/src/main/res/drawable-xhdpi/ic_close_black_24dp.png b/remixer_ui/src/main/res/drawable-xhdpi/ic_close_black_24dp.png new file mode 100755 index 0000000000000000000000000000000000000000..6bc437298ab7bfbfbf128acdf5849e304b3c6903 GIT binary patch literal 235 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA0wn)(8}b0DO`a}}Ar*{or)}gqq9DL3|6^j{ z=hBm&C)~N@b{5Sp4w$_m*}geiNBekToKL{TWpQP5xqRwZuPjq53pI^Z3A|FbUaRcY z{O^J0fmhZ3y?R?;$@JP$iP2W!Cd>8DEZ3V|*s2`1aV~kzx#D@}&nn~61{Xzi+b(jKntiPo%%5fP`-@uPgu|~7wTA~r iR9eY#70Eo`TEl2=&Qt5V_=GOd^$eb_elF{r5}E*W1LhEy=VysgJ$~x+g}6OvsxLimbaeN-!xQItoH=3nd`|H@dF!kYp_dChV`b9AudQLRn7yg2 zv~UiON9*MGOYAy6D=_*g@;c3(5`S(Hi^X;wk8Ms*3SMP^!WTf z-E_DAd$kLMWY`Z`);MuKF9=d$?_mzLoFj7Xp~|_3ODg!(3;AT&wLoS^O+0tsvcZJ& zD(m_$dNm(!9@n+CTyDa$w$*a^-$!>qK3P{4end8+qbAwoFEAV!JYD@<);T3K0RXh> Be)#|Z literal 0 HcmV?d00001 diff --git a/remixer_ui/src/main/res/drawable-xxxhdpi/ic_close_black_24dp.png b/remixer_ui/src/main/res/drawable-xxxhdpi/ic_close_black_24dp.png new file mode 100755 index 0000000000000000000000000000000000000000..df42feecb812b02df59b016f4d9ba995be1da82a GIT binary patch literal 377 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD0wg^q?%&M7!06!V;uuoF`1aP_Or}5)*N1l- zmd#l`*P1uuRG{<>g~}cLi3NSnFL zkGQYSP&@m;*IK6Q-#O#%t5^JG`{BMqf8+n2Z|={&zE4otx%%IU37m2NTYWzKGCBDA zGRyk&LVN6HtbDhUpKVe#i0?1F$Iko1uY_g0mfJ~qyju(6`+^n!Z*4iz5hh+Bv?p(-%zt$M-+!?Iw6Q#P16<$f#A@_7oVT44$rjF6*2U FngA8*uUr5C literal 0 HcmV?d00001 diff --git a/remixer_ui/src/main/res/layout/boolean_variable_widget.xml b/remixer_ui/src/main/res/layout/boolean_variable_widget.xml index bc70dbb..3b7fa2c 100644 --- a/remixer_ui/src/main/res/layout/boolean_variable_widget.xml +++ b/remixer_ui/src/main/res/layout/boolean_variable_widget.xml @@ -19,22 +19,23 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" - android:padding="@dimen/defaultPadding"> + android:layout_marginBottom="@dimen/secondaryPadding" + android:layout_marginTop="@dimen/secondaryPadding" + android:gravity="center" + android:orientation="horizontal"> + android:layout_centerVertical="true" + android:layout_weight="1"/> diff --git a/remixer_ui/src/main/res/layout/color_list_variable_widget.xml b/remixer_ui/src/main/res/layout/color_list_variable_widget.xml index 5a0e35e..1405f3a 100644 --- a/remixer_ui/src/main/res/layout/color_list_variable_widget.xml +++ b/remixer_ui/src/main/res/layout/color_list_variable_widget.xml @@ -20,12 +20,13 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="vertical" - android:padding="@dimen/defaultPadding" - tools:ignore="UnusedResources"> + android:layout_marginBottom="@dimen/secondaryPadding" + android:layout_marginTop="@dimen/secondaryPadding" + android:orientation="vertical"> diff --git a/remixer_ui/src/main/res/layout/fragment_remixer_list.xml b/remixer_ui/src/main/res/layout/fragment_remixer_list.xml index 63347b7..c2c62b8 100644 --- a/remixer_ui/src/main/res/layout/fragment_remixer_list.xml +++ b/remixer_ui/src/main/res/layout/fragment_remixer_list.xml @@ -23,22 +23,19 @@ android:name="com.google.android.libraries.remixer.view.RemixerFragment" android:layout_width="match_parent" android:layout_height="wrap_content" - android:theme="@style/AppTheme" + android:theme="@style/RemixerTheme" tools:context="com.google.android.libraries.remixer.ui.view.RemixerFragment"> - + layout="@layout/remixer_header"/> diff --git a/remixer_ui/src/main/res/layout/item_list_spinner_view.xml b/remixer_ui/src/main/res/layout/item_list_spinner_view.xml index d900fc6..bc78919 100644 --- a/remixer_ui/src/main/res/layout/item_list_spinner_view.xml +++ b/remixer_ui/src/main/res/layout/item_list_spinner_view.xml @@ -19,5 +19,5 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" - android:padding="@dimen/defaultPadding"> + android:padding="@dimen/secondaryPadding"> diff --git a/remixer_ui/src/main/res/layout/item_list_variable_widget.xml b/remixer_ui/src/main/res/layout/item_list_variable_widget.xml index 2415141..2d3c1a4 100644 --- a/remixer_ui/src/main/res/layout/item_list_variable_widget.xml +++ b/remixer_ui/src/main/res/layout/item_list_variable_widget.xml @@ -19,10 +19,12 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" - android:padding="@dimen/defaultPadding"> + android:layout_marginBottom="@dimen/secondaryPadding" + android:layout_marginTop="@dimen/secondaryPadding"> + android:layout_alignParentLeft="true" + android:layout_alignParentStart="true" + android:layout_below="@id/variableName"/> diff --git a/remixer_ui/src/main/res/layout/remixer_header.xml b/remixer_ui/src/main/res/layout/remixer_header.xml new file mode 100644 index 0000000..f3ad791 --- /dev/null +++ b/remixer_ui/src/main/res/layout/remixer_header.xml @@ -0,0 +1,42 @@ + + + + + + + + + + diff --git a/remixer_ui/src/main/res/layout/seekbar_range_variable_widget.xml b/remixer_ui/src/main/res/layout/seekbar_range_variable_widget.xml index 5a5be3f..0e67cfe 100644 --- a/remixer_ui/src/main/res/layout/seekbar_range_variable_widget.xml +++ b/remixer_ui/src/main/res/layout/seekbar_range_variable_widget.xml @@ -20,10 +20,12 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" - android:padding="@dimen/defaultPadding"> + android:layout_marginBottom="@dimen/secondaryPadding" + android:layout_marginTop="@dimen/secondaryPadding"> + android:paddingBottom="@dimen/secondaryPadding" + android:paddingTop="@dimen/secondaryPadding"/> diff --git a/remixer_ui/src/main/res/layout/string_variable_widget.xml b/remixer_ui/src/main/res/layout/string_variable_widget.xml index d6b964c..a91b1a6 100644 --- a/remixer_ui/src/main/res/layout/string_variable_widget.xml +++ b/remixer_ui/src/main/res/layout/string_variable_widget.xml @@ -19,10 +19,12 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" - android:padding="@dimen/defaultPadding"> + android:layout_marginBottom="@dimen/secondaryPadding" + android:layout_marginTop="@dimen/secondaryPadding"> - + + + + From f8d4e41e90c140d510c52835588c501cab307b09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Andr=C3=A9s=20Y=C3=A1=C3=B1ez=20Barreto?= Date: Mon, 30 Jan 2017 15:50:08 -0500 Subject: [PATCH 28/32] Add explicit circle config + Status badge. (#120) * Add circleCI yaml config file for explicit config. * Add Circle CI build status. --- README.md | 2 +- circle.yml | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 circle.yml diff --git a/README.md b/README.md index 521b463..09a83e0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![Remixer](https://cdn.rawgit.com/material-foundation/material-remixer/master/docs/assets/lockup_remixer_icon_horizontal_dark_small.svg) -[![Build Status](https://travis-ci.org/material-foundation/material-remixer-android.svg?branch=develop)](https://travis-ci.org/material-foundation/material-remixer-android) [![codecov](https://codecov.io/gh/material-foundation/material-remixer-android/branch/develop/graph/badge.svg)](https://codecov.io/gh/material-foundation/material-remixer-android) +[![TravisCI Build Status](https://travis-ci.org/material-foundation/material-remixer-android.svg?branch=develop)](https://travis-ci.org/material-foundation/material-remixer-android) [![CircleCI Build Status](https://circleci.com/gh/material-foundation/material-remixer-android.svg?style=svg)](https://circleci.com/gh/material-foundation/material-remixer-android) [![codecov](https://codecov.io/gh/material-foundation/material-remixer-android/branch/develop/graph/badge.svg)](https://codecov.io/gh/material-foundation/material-remixer-android) Remixer helps teams use and refine design specs by providing an abstraction for these values that is accessible and configurable from both inside and outside the app itself. diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000..e0ee738 --- /dev/null +++ b/circle.yml @@ -0,0 +1,14 @@ + +test: + pre: + - echo y | android update sdk --no-ui --all --filter extra-android-m2repository,extra-android-support + - echo y | android update sdk --no-ui --all --filter build-tools-25.0.0 + + override: + - ./gradlew lint build test check jacocoTestReport -PdisablePreDex; + + post: + - mkdir -p $CIRCLE_TEST_REPORTS/junit/ + - find . -type f -regex ".*/build/test-results/.*xml" -exec cp {} $CIRCLE_TEST_REPORTS/junit/ \; + - find . -type f -regex ".*/build/outputs/androidTest-results/.*xml" -exec cp {} $CIRCLE_TEST_REPORTS/junit/ \; + - bash <(curl -s https://codecov.io/bash) From 39ebda294d9a662d3e5530beed797aeb4b40f587 Mon Sep 17 00:00:00 2001 From: Miguel Yanez Barreto Date: Wed, 8 Feb 2017 16:42:55 -0500 Subject: [PATCH 29/32] Automatic changelog preparation for release. --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a22a2d5..74d9597 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# #develop# + + TODO: Enumerate changes. + + # 0.6.0 ## Breaking changes From 94281ba6bd4a46a63cc9917368683b3ef2899dc3 Mon Sep 17 00:00:00 2001 From: Miguel Yanez Barreto Date: Wed, 8 Feb 2017 16:49:12 -0500 Subject: [PATCH 30/32] Add changelog --- CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74d9597..1a4652e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # #develop# - TODO: Enumerate changes. +- Test improvements for Robolectric, styles are now supported +- First attempt at styling (for tests, not final version). +- Paddings are standardized now. +- Close button added. +- Sync to remote controller implemented. Still not fully ready or supported. Documentation incoming. + # 0.6.0 From 52b25475cd9903c6f31b3297c33648fefa5123be Mon Sep 17 00:00:00 2001 From: Miguel Yanez Barreto Date: Wed, 8 Feb 2017 16:50:05 -0500 Subject: [PATCH 31/32] Update version number on readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 09a83e0..442a945 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ The project is defined as a gradle project with submodules. __Disclaimer:__ Remixer still hasn't reached a stage that we consider is stable enough to commit to the current status of the API, it will be evolving quickly and we may commit breaking changes every once in a while. _That said_, we would love to have you try it out and tell us what you think is missing and what you'd like us to focus on. -You can read our [javadoc for the current release (0.6.0)](https://jitpack.io/com/github/material-foundation/material-remixer-android/remixer/0.6.0/javadoc/index.html) and the [javadoc for HEAD](https://jitpack.io/com/github/material-foundation/material-remixer-android/remixer/develop-SNAPSHOT/javadoc/index.html) generated by jitpack. +You can read our [javadoc for the current release (0.6.5)](https://jitpack.io/com/github/material-foundation/material-remixer-android/remixer/0.6.5/javadoc/index.html) and the [javadoc for HEAD](https://jitpack.io/com/github/material-foundation/material-remixer-android/remixer/develop-SNAPSHOT/javadoc/index.html) generated by jitpack. ### Set up dependencies @@ -61,7 +61,7 @@ And in your modules, apply the `android-apt` plugin and add the remixer dependen apply plugin: 'android-apt' dependencies { - compile 'com.github.material-foundation.material-remixer-android:remixer:0.6.0' + compile 'com.github.material-foundation.material-remixer-android:remixer:0.6.5' } ``` From c359c482f2d35740485cb0a1746b5279a7295577 Mon Sep 17 00:00:00 2001 From: Miguel Yanez Barreto Date: Wed, 8 Feb 2017 16:52:06 -0500 Subject: [PATCH 32/32] update changelog version --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a4652e..85d418c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# #develop# +# 0.6.5 - Test improvements for Robolectric, styles are now supported - First attempt at styling (for tests, not final version).