repo_name
stringlengths
7
104
file_path
stringlengths
13
198
context
stringlengths
67
7.15k
import_statement
stringlengths
16
4.43k
code
stringlengths
40
6.98k
prompt
stringlengths
227
8.27k
next_line
stringlengths
8
795
vimeo/stag-java
integration-test-java/src/test/java/com/vimeo/sample_java_model/ExternalModel1Test.java
// Path: integration-test-java/src/test/java/verification/Utils.java // public final class Utils { // // private Utils() { // } // // private static <T> TypeAdapter<T> getTypeAdapter(@NotNull Class<T> clazz) { // Gson gson = new Gson(); // Stag.Factory factory = new Stag.Factory(); // TypeToken<T> innerModelType = TypeToken.get(clazz); // return factory.create(gson, innerModelType); // } // // /** // * Verifies that a TypeAdapter was generated for the specified class. // * // * @param clazz the class to check. // * @param <T> the type of the class, used internally. // */ // public static <T> void verifyTypeAdapterGeneration(@NotNull Class<T> clazz) { // TypeAdapter<T> typeAdapter = getTypeAdapter(clazz); // assertNotNull("Type adapter should have been generated by Stag", typeAdapter); // } // // /** // * Verifies that a TypeAdapter was NOT generated for the specified class. // * // * @param clazz the class to check. // * @param <T> the type of the class, used internally. // */ // public static <T> void verifyNoTypeAdapterGeneration(@NotNull Class<T> clazz) { // TypeAdapter<T> typeAdapter = getTypeAdapter(clazz); // assertNull("Type adapter should not have been generated by Stag", typeAdapter); // } // // /** // * Verifies that the type adapter for a class is correct. It does this by manufacturing an // * instance of the class, writing it to JSON, and then reading that object back out of JSON // * and comparing the two instances. // * // * @param clazz the {@link Class} to use to get the {@link TypeAdapter}. // */ // public static <T> void verifyTypeAdapterCorrectness(@NotNull Class<T> clazz) { // final PodamFactory factory = new PodamFactoryImpl(); // factory.setClassStrategy(new HungarianNotationClassInfoStrategy()); // // final T object = factory.manufacturePojo(clazz); // final TypeAdapter<T> typeAdapter = getTypeAdapter(clazz); // // T newObject = null; // if (typeAdapter != null) { // final String json = typeAdapter.toJson(object); // try { // newObject = typeAdapter.fromJson(json); // } catch (IOException ignored) {} // } // // assertEquals(object, newObject); // } // // }
import org.junit.Test; import verification.Utils;
package com.vimeo.sample_java_model; /** * Created by restainoa on 2/2/17. */ public class ExternalModel1Test { @Test public void typeAdapterWasGenerated() throws Exception {
// Path: integration-test-java/src/test/java/verification/Utils.java // public final class Utils { // // private Utils() { // } // // private static <T> TypeAdapter<T> getTypeAdapter(@NotNull Class<T> clazz) { // Gson gson = new Gson(); // Stag.Factory factory = new Stag.Factory(); // TypeToken<T> innerModelType = TypeToken.get(clazz); // return factory.create(gson, innerModelType); // } // // /** // * Verifies that a TypeAdapter was generated for the specified class. // * // * @param clazz the class to check. // * @param <T> the type of the class, used internally. // */ // public static <T> void verifyTypeAdapterGeneration(@NotNull Class<T> clazz) { // TypeAdapter<T> typeAdapter = getTypeAdapter(clazz); // assertNotNull("Type adapter should have been generated by Stag", typeAdapter); // } // // /** // * Verifies that a TypeAdapter was NOT generated for the specified class. // * // * @param clazz the class to check. // * @param <T> the type of the class, used internally. // */ // public static <T> void verifyNoTypeAdapterGeneration(@NotNull Class<T> clazz) { // TypeAdapter<T> typeAdapter = getTypeAdapter(clazz); // assertNull("Type adapter should not have been generated by Stag", typeAdapter); // } // // /** // * Verifies that the type adapter for a class is correct. It does this by manufacturing an // * instance of the class, writing it to JSON, and then reading that object back out of JSON // * and comparing the two instances. // * // * @param clazz the {@link Class} to use to get the {@link TypeAdapter}. // */ // public static <T> void verifyTypeAdapterCorrectness(@NotNull Class<T> clazz) { // final PodamFactory factory = new PodamFactoryImpl(); // factory.setClassStrategy(new HungarianNotationClassInfoStrategy()); // // final T object = factory.manufacturePojo(clazz); // final TypeAdapter<T> typeAdapter = getTypeAdapter(clazz); // // T newObject = null; // if (typeAdapter != null) { // final String json = typeAdapter.toJson(object); // try { // newObject = typeAdapter.fromJson(json); // } catch (IOException ignored) {} // } // // assertEquals(object, newObject); // } // // } // Path: integration-test-java/src/test/java/com/vimeo/sample_java_model/ExternalModel1Test.java import org.junit.Test; import verification.Utils; package com.vimeo.sample_java_model; /** * Created by restainoa on 2/2/17. */ public class ExternalModel1Test { @Test public void typeAdapterWasGenerated() throws Exception {
Utils.verifyTypeAdapterGeneration(ExternalModel1.class);
vimeo/stag-java
integration-test-java-cross-module/src/test/java/com/vimeo/sample/model/ExternalModelExample2Test.java
// Path: integration-test-java/src/test/java/verification/Utils.java // public final class Utils { // // private Utils() { // } // // private static <T> TypeAdapter<T> getTypeAdapter(@NotNull Class<T> clazz) { // Gson gson = new Gson(); // Stag.Factory factory = new Stag.Factory(); // TypeToken<T> innerModelType = TypeToken.get(clazz); // return factory.create(gson, innerModelType); // } // // /** // * Verifies that a TypeAdapter was generated for the specified class. // * // * @param clazz the class to check. // * @param <T> the type of the class, used internally. // */ // public static <T> void verifyTypeAdapterGeneration(@NotNull Class<T> clazz) { // TypeAdapter<T> typeAdapter = getTypeAdapter(clazz); // assertNotNull("Type adapter should have been generated by Stag", typeAdapter); // } // // /** // * Verifies that a TypeAdapter was NOT generated for the specified class. // * // * @param clazz the class to check. // * @param <T> the type of the class, used internally. // */ // public static <T> void verifyNoTypeAdapterGeneration(@NotNull Class<T> clazz) { // TypeAdapter<T> typeAdapter = getTypeAdapter(clazz); // assertNull("Type adapter should not have been generated by Stag", typeAdapter); // } // // /** // * Verifies that the type adapter for a class is correct. It does this by manufacturing an // * instance of the class, writing it to JSON, and then reading that object back out of JSON // * and comparing the two instances. // * // * @param clazz the {@link Class} to use to get the {@link TypeAdapter}. // */ // public static <T> void verifyTypeAdapterCorrectness(@NotNull Class<T> clazz) { // final PodamFactory factory = new PodamFactoryImpl(); // factory.setClassStrategy(new HungarianNotationClassInfoStrategy()); // // final T object = factory.manufacturePojo(clazz); // final TypeAdapter<T> typeAdapter = getTypeAdapter(clazz); // // T newObject = null; // if (typeAdapter != null) { // final String json = typeAdapter.toJson(object); // try { // newObject = typeAdapter.fromJson(json); // } catch (IOException ignored) {} // } // // assertEquals(object, newObject); // } // // }
import verification.Utils; import org.junit.Test;
package com.vimeo.sample.model; /** * Created by restainoa on 2/2/17. */ public class ExternalModelExample2Test { @Test public void typeAdapterWasGenerated() throws Exception {
// Path: integration-test-java/src/test/java/verification/Utils.java // public final class Utils { // // private Utils() { // } // // private static <T> TypeAdapter<T> getTypeAdapter(@NotNull Class<T> clazz) { // Gson gson = new Gson(); // Stag.Factory factory = new Stag.Factory(); // TypeToken<T> innerModelType = TypeToken.get(clazz); // return factory.create(gson, innerModelType); // } // // /** // * Verifies that a TypeAdapter was generated for the specified class. // * // * @param clazz the class to check. // * @param <T> the type of the class, used internally. // */ // public static <T> void verifyTypeAdapterGeneration(@NotNull Class<T> clazz) { // TypeAdapter<T> typeAdapter = getTypeAdapter(clazz); // assertNotNull("Type adapter should have been generated by Stag", typeAdapter); // } // // /** // * Verifies that a TypeAdapter was NOT generated for the specified class. // * // * @param clazz the class to check. // * @param <T> the type of the class, used internally. // */ // public static <T> void verifyNoTypeAdapterGeneration(@NotNull Class<T> clazz) { // TypeAdapter<T> typeAdapter = getTypeAdapter(clazz); // assertNull("Type adapter should not have been generated by Stag", typeAdapter); // } // // /** // * Verifies that the type adapter for a class is correct. It does this by manufacturing an // * instance of the class, writing it to JSON, and then reading that object back out of JSON // * and comparing the two instances. // * // * @param clazz the {@link Class} to use to get the {@link TypeAdapter}. // */ // public static <T> void verifyTypeAdapterCorrectness(@NotNull Class<T> clazz) { // final PodamFactory factory = new PodamFactoryImpl(); // factory.setClassStrategy(new HungarianNotationClassInfoStrategy()); // // final T object = factory.manufacturePojo(clazz); // final TypeAdapter<T> typeAdapter = getTypeAdapter(clazz); // // T newObject = null; // if (typeAdapter != null) { // final String json = typeAdapter.toJson(object); // try { // newObject = typeAdapter.fromJson(json); // } catch (IOException ignored) {} // } // // assertEquals(object, newObject); // } // // } // Path: integration-test-java-cross-module/src/test/java/com/vimeo/sample/model/ExternalModelExample2Test.java import verification.Utils; import org.junit.Test; package com.vimeo.sample.model; /** * Created by restainoa on 2/2/17. */ public class ExternalModelExample2Test { @Test public void typeAdapterWasGenerated() throws Exception {
Utils.verifyTypeAdapterGeneration(ExternalModelExample2.class);
vimeo/stag-java
integration-test-java-cross-module/src/test/java/com/vimeo/sample/model/GenericClassTest.java
// Path: integration-test-java/src/test/java/verification/Utils.java // public final class Utils { // // private Utils() { // } // // private static <T> TypeAdapter<T> getTypeAdapter(@NotNull Class<T> clazz) { // Gson gson = new Gson(); // Stag.Factory factory = new Stag.Factory(); // TypeToken<T> innerModelType = TypeToken.get(clazz); // return factory.create(gson, innerModelType); // } // // /** // * Verifies that a TypeAdapter was generated for the specified class. // * // * @param clazz the class to check. // * @param <T> the type of the class, used internally. // */ // public static <T> void verifyTypeAdapterGeneration(@NotNull Class<T> clazz) { // TypeAdapter<T> typeAdapter = getTypeAdapter(clazz); // assertNotNull("Type adapter should have been generated by Stag", typeAdapter); // } // // /** // * Verifies that a TypeAdapter was NOT generated for the specified class. // * // * @param clazz the class to check. // * @param <T> the type of the class, used internally. // */ // public static <T> void verifyNoTypeAdapterGeneration(@NotNull Class<T> clazz) { // TypeAdapter<T> typeAdapter = getTypeAdapter(clazz); // assertNull("Type adapter should not have been generated by Stag", typeAdapter); // } // // /** // * Verifies that the type adapter for a class is correct. It does this by manufacturing an // * instance of the class, writing it to JSON, and then reading that object back out of JSON // * and comparing the two instances. // * // * @param clazz the {@link Class} to use to get the {@link TypeAdapter}. // */ // public static <T> void verifyTypeAdapterCorrectness(@NotNull Class<T> clazz) { // final PodamFactory factory = new PodamFactoryImpl(); // factory.setClassStrategy(new HungarianNotationClassInfoStrategy()); // // final T object = factory.manufacturePojo(clazz); // final TypeAdapter<T> typeAdapter = getTypeAdapter(clazz); // // T newObject = null; // if (typeAdapter != null) { // final String json = typeAdapter.toJson(object); // try { // newObject = typeAdapter.fromJson(json); // } catch (IOException ignored) {} // } // // assertEquals(object, newObject); // } // // }
import verification.Utils; import org.junit.Test;
package com.vimeo.sample.model; /** * Created by restainoa on 2/2/17. */ public class GenericClassTest { @Test public void typeAdapterWasGenerated() throws Exception {
// Path: integration-test-java/src/test/java/verification/Utils.java // public final class Utils { // // private Utils() { // } // // private static <T> TypeAdapter<T> getTypeAdapter(@NotNull Class<T> clazz) { // Gson gson = new Gson(); // Stag.Factory factory = new Stag.Factory(); // TypeToken<T> innerModelType = TypeToken.get(clazz); // return factory.create(gson, innerModelType); // } // // /** // * Verifies that a TypeAdapter was generated for the specified class. // * // * @param clazz the class to check. // * @param <T> the type of the class, used internally. // */ // public static <T> void verifyTypeAdapterGeneration(@NotNull Class<T> clazz) { // TypeAdapter<T> typeAdapter = getTypeAdapter(clazz); // assertNotNull("Type adapter should have been generated by Stag", typeAdapter); // } // // /** // * Verifies that a TypeAdapter was NOT generated for the specified class. // * // * @param clazz the class to check. // * @param <T> the type of the class, used internally. // */ // public static <T> void verifyNoTypeAdapterGeneration(@NotNull Class<T> clazz) { // TypeAdapter<T> typeAdapter = getTypeAdapter(clazz); // assertNull("Type adapter should not have been generated by Stag", typeAdapter); // } // // /** // * Verifies that the type adapter for a class is correct. It does this by manufacturing an // * instance of the class, writing it to JSON, and then reading that object back out of JSON // * and comparing the two instances. // * // * @param clazz the {@link Class} to use to get the {@link TypeAdapter}. // */ // public static <T> void verifyTypeAdapterCorrectness(@NotNull Class<T> clazz) { // final PodamFactory factory = new PodamFactoryImpl(); // factory.setClassStrategy(new HungarianNotationClassInfoStrategy()); // // final T object = factory.manufacturePojo(clazz); // final TypeAdapter<T> typeAdapter = getTypeAdapter(clazz); // // T newObject = null; // if (typeAdapter != null) { // final String json = typeAdapter.toJson(object); // try { // newObject = typeAdapter.fromJson(json); // } catch (IOException ignored) {} // } // // assertEquals(object, newObject); // } // // } // Path: integration-test-java-cross-module/src/test/java/com/vimeo/sample/model/GenericClassTest.java import verification.Utils; import org.junit.Test; package com.vimeo.sample.model; /** * Created by restainoa on 2/2/17. */ public class GenericClassTest { @Test public void typeAdapterWasGenerated() throws Exception {
Utils.verifyTypeAdapterGeneration(GenericClass.class);
vimeo/stag-java
integration-test-java-cross-module/src/test/java/com/vimeo/sample/model/NestedModelTest.java
// Path: integration-test-java/src/test/java/verification/Utils.java // public final class Utils { // // private Utils() { // } // // private static <T> TypeAdapter<T> getTypeAdapter(@NotNull Class<T> clazz) { // Gson gson = new Gson(); // Stag.Factory factory = new Stag.Factory(); // TypeToken<T> innerModelType = TypeToken.get(clazz); // return factory.create(gson, innerModelType); // } // // /** // * Verifies that a TypeAdapter was generated for the specified class. // * // * @param clazz the class to check. // * @param <T> the type of the class, used internally. // */ // public static <T> void verifyTypeAdapterGeneration(@NotNull Class<T> clazz) { // TypeAdapter<T> typeAdapter = getTypeAdapter(clazz); // assertNotNull("Type adapter should have been generated by Stag", typeAdapter); // } // // /** // * Verifies that a TypeAdapter was NOT generated for the specified class. // * // * @param clazz the class to check. // * @param <T> the type of the class, used internally. // */ // public static <T> void verifyNoTypeAdapterGeneration(@NotNull Class<T> clazz) { // TypeAdapter<T> typeAdapter = getTypeAdapter(clazz); // assertNull("Type adapter should not have been generated by Stag", typeAdapter); // } // // /** // * Verifies that the type adapter for a class is correct. It does this by manufacturing an // * instance of the class, writing it to JSON, and then reading that object back out of JSON // * and comparing the two instances. // * // * @param clazz the {@link Class} to use to get the {@link TypeAdapter}. // */ // public static <T> void verifyTypeAdapterCorrectness(@NotNull Class<T> clazz) { // final PodamFactory factory = new PodamFactoryImpl(); // factory.setClassStrategy(new HungarianNotationClassInfoStrategy()); // // final T object = factory.manufacturePojo(clazz); // final TypeAdapter<T> typeAdapter = getTypeAdapter(clazz); // // T newObject = null; // if (typeAdapter != null) { // final String json = typeAdapter.toJson(object); // try { // newObject = typeAdapter.fromJson(json); // } catch (IOException ignored) {} // } // // assertEquals(object, newObject); // } // // }
import verification.Utils; import org.junit.Test;
package com.vimeo.sample.model; /** * Created by restainoa on 2/2/17. */ public class NestedModelTest { @Test public void typeAdapterWasGenerated_NestedModel() throws Exception {
// Path: integration-test-java/src/test/java/verification/Utils.java // public final class Utils { // // private Utils() { // } // // private static <T> TypeAdapter<T> getTypeAdapter(@NotNull Class<T> clazz) { // Gson gson = new Gson(); // Stag.Factory factory = new Stag.Factory(); // TypeToken<T> innerModelType = TypeToken.get(clazz); // return factory.create(gson, innerModelType); // } // // /** // * Verifies that a TypeAdapter was generated for the specified class. // * // * @param clazz the class to check. // * @param <T> the type of the class, used internally. // */ // public static <T> void verifyTypeAdapterGeneration(@NotNull Class<T> clazz) { // TypeAdapter<T> typeAdapter = getTypeAdapter(clazz); // assertNotNull("Type adapter should have been generated by Stag", typeAdapter); // } // // /** // * Verifies that a TypeAdapter was NOT generated for the specified class. // * // * @param clazz the class to check. // * @param <T> the type of the class, used internally. // */ // public static <T> void verifyNoTypeAdapterGeneration(@NotNull Class<T> clazz) { // TypeAdapter<T> typeAdapter = getTypeAdapter(clazz); // assertNull("Type adapter should not have been generated by Stag", typeAdapter); // } // // /** // * Verifies that the type adapter for a class is correct. It does this by manufacturing an // * instance of the class, writing it to JSON, and then reading that object back out of JSON // * and comparing the two instances. // * // * @param clazz the {@link Class} to use to get the {@link TypeAdapter}. // */ // public static <T> void verifyTypeAdapterCorrectness(@NotNull Class<T> clazz) { // final PodamFactory factory = new PodamFactoryImpl(); // factory.setClassStrategy(new HungarianNotationClassInfoStrategy()); // // final T object = factory.manufacturePojo(clazz); // final TypeAdapter<T> typeAdapter = getTypeAdapter(clazz); // // T newObject = null; // if (typeAdapter != null) { // final String json = typeAdapter.toJson(object); // try { // newObject = typeAdapter.fromJson(json); // } catch (IOException ignored) {} // } // // assertEquals(object, newObject); // } // // } // Path: integration-test-java-cross-module/src/test/java/com/vimeo/sample/model/NestedModelTest.java import verification.Utils; import org.junit.Test; package com.vimeo.sample.model; /** * Created by restainoa on 2/2/17. */ public class NestedModelTest { @Test public void typeAdapterWasGenerated_NestedModel() throws Exception {
Utils.verifyTypeAdapterGeneration(NestedModel.class);
vimeo/stag-java
integration-test-java-cross-module/src/test/java/com/vimeo/sample/model/IdenticalFieldTypesTest.java
// Path: integration-test-java/src/test/java/verification/Utils.java // public final class Utils { // // private Utils() { // } // // private static <T> TypeAdapter<T> getTypeAdapter(@NotNull Class<T> clazz) { // Gson gson = new Gson(); // Stag.Factory factory = new Stag.Factory(); // TypeToken<T> innerModelType = TypeToken.get(clazz); // return factory.create(gson, innerModelType); // } // // /** // * Verifies that a TypeAdapter was generated for the specified class. // * // * @param clazz the class to check. // * @param <T> the type of the class, used internally. // */ // public static <T> void verifyTypeAdapterGeneration(@NotNull Class<T> clazz) { // TypeAdapter<T> typeAdapter = getTypeAdapter(clazz); // assertNotNull("Type adapter should have been generated by Stag", typeAdapter); // } // // /** // * Verifies that a TypeAdapter was NOT generated for the specified class. // * // * @param clazz the class to check. // * @param <T> the type of the class, used internally. // */ // public static <T> void verifyNoTypeAdapterGeneration(@NotNull Class<T> clazz) { // TypeAdapter<T> typeAdapter = getTypeAdapter(clazz); // assertNull("Type adapter should not have been generated by Stag", typeAdapter); // } // // /** // * Verifies that the type adapter for a class is correct. It does this by manufacturing an // * instance of the class, writing it to JSON, and then reading that object back out of JSON // * and comparing the two instances. // * // * @param clazz the {@link Class} to use to get the {@link TypeAdapter}. // */ // public static <T> void verifyTypeAdapterCorrectness(@NotNull Class<T> clazz) { // final PodamFactory factory = new PodamFactoryImpl(); // factory.setClassStrategy(new HungarianNotationClassInfoStrategy()); // // final T object = factory.manufacturePojo(clazz); // final TypeAdapter<T> typeAdapter = getTypeAdapter(clazz); // // T newObject = null; // if (typeAdapter != null) { // final String json = typeAdapter.toJson(object); // try { // newObject = typeAdapter.fromJson(json); // } catch (IOException ignored) {} // } // // assertEquals(object, newObject); // } // // }
import verification.Utils; import org.junit.Test;
package com.vimeo.sample.model; /** * Created by restainoa on 2/2/17. */ public class IdenticalFieldTypesTest { @Test public void typeAdapterWasGenerated() throws Exception {
// Path: integration-test-java/src/test/java/verification/Utils.java // public final class Utils { // // private Utils() { // } // // private static <T> TypeAdapter<T> getTypeAdapter(@NotNull Class<T> clazz) { // Gson gson = new Gson(); // Stag.Factory factory = new Stag.Factory(); // TypeToken<T> innerModelType = TypeToken.get(clazz); // return factory.create(gson, innerModelType); // } // // /** // * Verifies that a TypeAdapter was generated for the specified class. // * // * @param clazz the class to check. // * @param <T> the type of the class, used internally. // */ // public static <T> void verifyTypeAdapterGeneration(@NotNull Class<T> clazz) { // TypeAdapter<T> typeAdapter = getTypeAdapter(clazz); // assertNotNull("Type adapter should have been generated by Stag", typeAdapter); // } // // /** // * Verifies that a TypeAdapter was NOT generated for the specified class. // * // * @param clazz the class to check. // * @param <T> the type of the class, used internally. // */ // public static <T> void verifyNoTypeAdapterGeneration(@NotNull Class<T> clazz) { // TypeAdapter<T> typeAdapter = getTypeAdapter(clazz); // assertNull("Type adapter should not have been generated by Stag", typeAdapter); // } // // /** // * Verifies that the type adapter for a class is correct. It does this by manufacturing an // * instance of the class, writing it to JSON, and then reading that object back out of JSON // * and comparing the two instances. // * // * @param clazz the {@link Class} to use to get the {@link TypeAdapter}. // */ // public static <T> void verifyTypeAdapterCorrectness(@NotNull Class<T> clazz) { // final PodamFactory factory = new PodamFactoryImpl(); // factory.setClassStrategy(new HungarianNotationClassInfoStrategy()); // // final T object = factory.manufacturePojo(clazz); // final TypeAdapter<T> typeAdapter = getTypeAdapter(clazz); // // T newObject = null; // if (typeAdapter != null) { // final String json = typeAdapter.toJson(object); // try { // newObject = typeAdapter.fromJson(json); // } catch (IOException ignored) {} // } // // assertEquals(object, newObject); // } // // } // Path: integration-test-java-cross-module/src/test/java/com/vimeo/sample/model/IdenticalFieldTypesTest.java import verification.Utils; import org.junit.Test; package com.vimeo.sample.model; /** * Created by restainoa on 2/2/17. */ public class IdenticalFieldTypesTest { @Test public void typeAdapterWasGenerated() throws Exception {
Utils.verifyTypeAdapterGeneration(IdenticalFieldTypes.class);
dima767/inspektr
inspektr-audit/src/main/java/com/github/inspektr/audit/support/Slf4jLoggingAuditTrailManager.java
// Path: inspektr-audit/src/main/java/com/github/inspektr/audit/AuditActionContext.java // public final class AuditActionContext implements Serializable { // // /** // * Unique Id for serialization. // */ // private static final long serialVersionUID = -3530737409883959089L; // // /** This is <i>WHO</i>*/ // private final String principal; // // /** This is <i>WHAT</i>*/ // private final String resourceOperatedUpon; // // /** This is <i>ACTION</i>*/ // private final String actionPerformed; // // /** This is <i>Application from which operation has been performed</i>*/ // private final String applicationCode; // // /** This is <i>WHEN</i>*/ // private final Date whenActionWasPerformed; // // /** Client IP Address */ // private final String clientIpAddress; // // /** Server IP Address */ // private final String serverIpAddress; // // public AuditActionContext(final String principal, final String resourceOperatedUpon, final String actionPerformed, final String applicationCode, // final Date whenActionWasPerformed, final String clientIpAddress, final String serverIpAddress, AuditPointRuntimeInfo runtimeInfo) { // assertNotNull(principal, "'principal' cannot be null.\n" + getDiagnosticInfo(runtimeInfo)); // assertNotNull(resourceOperatedUpon, "'resourceOperatedUpon' cannot be null.\n" + getDiagnosticInfo(runtimeInfo)); // assertNotNull(actionPerformed, "'actionPerformed' cannot be null.\n" + getDiagnosticInfo(runtimeInfo)); // assertNotNull(applicationCode, "'applicationCode' cannot be null.\n" + getDiagnosticInfo(runtimeInfo)); // assertNotNull(whenActionWasPerformed, "'whenActionPerformed' cannot be null.\n" + getDiagnosticInfo(runtimeInfo)); // assertNotNull(clientIpAddress, "'clientIpAddress' cannot be null.\n" + getDiagnosticInfo(runtimeInfo)); // assertNotNull(serverIpAddress, "'serverIpAddress' cannot be null.\n" + getDiagnosticInfo(runtimeInfo)); // this.principal = principal; // this.resourceOperatedUpon = resourceOperatedUpon; // this.actionPerformed = actionPerformed; // this.applicationCode = applicationCode; // this.whenActionWasPerformed = new Date(whenActionWasPerformed.getTime()); // this.clientIpAddress = clientIpAddress; // this.serverIpAddress = serverIpAddress; // } // // protected void assertNotNull(final Object o, final String message) { // if (o == null) { // throw new IllegalArgumentException(message); // } // } // // public String getPrincipal() { // return principal; // } // // public String getResourceOperatedUpon() { // return resourceOperatedUpon; // } // // public String getActionPerformed() { // return actionPerformed; // } // // public String getApplicationCode() { // return applicationCode; // } // // public Date getWhenActionWasPerformed() { // return new Date(whenActionWasPerformed.getTime()); // } // // public String getClientIpAddress() { // return this.clientIpAddress; // } // // public String getServerIpAddress() { // return this.serverIpAddress; // } // // private String getDiagnosticInfo(AuditPointRuntimeInfo runtimeInfo) { // return "Check the correctness of @Audit annotation at the following audit point: " + runtimeInfo.asString(); // } // } // // Path: inspektr-audit/src/main/java/com/github/inspektr/audit/AuditTrailManager.java // public interface AuditTrailManager { // // /** // * Make an audit trail record. Implementations could use any type of back end medium to serialize audit trail // * data i.e. RDBMS, log file, IO stream, SMTP, JMS queue or what ever else imaginable. // * <p> // * This concept is somewhat similar to log4j Appender. // * // * @param auditActionContext // */ // void record(AuditActionContext auditActionContext); // }
import org.slf4j.LoggerFactory; import com.github.inspektr.audit.AuditActionContext; import com.github.inspektr.audit.AuditTrailManager; import org.slf4j.Logger;
/** * Licensed to Inspektr under one or more contributor license * agreements. See the NOTICE file distributed with this work * for additional information regarding copyright ownership. * Inspektr licenses this file to you 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.github.inspektr.audit.support; /** * <code>AuditTrailManager</code> that dumps auditable information to a configured logger. * * @author Dmitriy Kopylenko * @version $Revision$ $Date$ * @since 1.0 * @see AuditTrailManager */ public final class Slf4jLoggingAuditTrailManager extends AbstractStringAuditTrailManager { private final Logger log = LoggerFactory.getLogger(this.getClass());
// Path: inspektr-audit/src/main/java/com/github/inspektr/audit/AuditActionContext.java // public final class AuditActionContext implements Serializable { // // /** // * Unique Id for serialization. // */ // private static final long serialVersionUID = -3530737409883959089L; // // /** This is <i>WHO</i>*/ // private final String principal; // // /** This is <i>WHAT</i>*/ // private final String resourceOperatedUpon; // // /** This is <i>ACTION</i>*/ // private final String actionPerformed; // // /** This is <i>Application from which operation has been performed</i>*/ // private final String applicationCode; // // /** This is <i>WHEN</i>*/ // private final Date whenActionWasPerformed; // // /** Client IP Address */ // private final String clientIpAddress; // // /** Server IP Address */ // private final String serverIpAddress; // // public AuditActionContext(final String principal, final String resourceOperatedUpon, final String actionPerformed, final String applicationCode, // final Date whenActionWasPerformed, final String clientIpAddress, final String serverIpAddress, AuditPointRuntimeInfo runtimeInfo) { // assertNotNull(principal, "'principal' cannot be null.\n" + getDiagnosticInfo(runtimeInfo)); // assertNotNull(resourceOperatedUpon, "'resourceOperatedUpon' cannot be null.\n" + getDiagnosticInfo(runtimeInfo)); // assertNotNull(actionPerformed, "'actionPerformed' cannot be null.\n" + getDiagnosticInfo(runtimeInfo)); // assertNotNull(applicationCode, "'applicationCode' cannot be null.\n" + getDiagnosticInfo(runtimeInfo)); // assertNotNull(whenActionWasPerformed, "'whenActionPerformed' cannot be null.\n" + getDiagnosticInfo(runtimeInfo)); // assertNotNull(clientIpAddress, "'clientIpAddress' cannot be null.\n" + getDiagnosticInfo(runtimeInfo)); // assertNotNull(serverIpAddress, "'serverIpAddress' cannot be null.\n" + getDiagnosticInfo(runtimeInfo)); // this.principal = principal; // this.resourceOperatedUpon = resourceOperatedUpon; // this.actionPerformed = actionPerformed; // this.applicationCode = applicationCode; // this.whenActionWasPerformed = new Date(whenActionWasPerformed.getTime()); // this.clientIpAddress = clientIpAddress; // this.serverIpAddress = serverIpAddress; // } // // protected void assertNotNull(final Object o, final String message) { // if (o == null) { // throw new IllegalArgumentException(message); // } // } // // public String getPrincipal() { // return principal; // } // // public String getResourceOperatedUpon() { // return resourceOperatedUpon; // } // // public String getActionPerformed() { // return actionPerformed; // } // // public String getApplicationCode() { // return applicationCode; // } // // public Date getWhenActionWasPerformed() { // return new Date(whenActionWasPerformed.getTime()); // } // // public String getClientIpAddress() { // return this.clientIpAddress; // } // // public String getServerIpAddress() { // return this.serverIpAddress; // } // // private String getDiagnosticInfo(AuditPointRuntimeInfo runtimeInfo) { // return "Check the correctness of @Audit annotation at the following audit point: " + runtimeInfo.asString(); // } // } // // Path: inspektr-audit/src/main/java/com/github/inspektr/audit/AuditTrailManager.java // public interface AuditTrailManager { // // /** // * Make an audit trail record. Implementations could use any type of back end medium to serialize audit trail // * data i.e. RDBMS, log file, IO stream, SMTP, JMS queue or what ever else imaginable. // * <p> // * This concept is somewhat similar to log4j Appender. // * // * @param auditActionContext // */ // void record(AuditActionContext auditActionContext); // } // Path: inspektr-audit/src/main/java/com/github/inspektr/audit/support/Slf4jLoggingAuditTrailManager.java import org.slf4j.LoggerFactory; import com.github.inspektr.audit.AuditActionContext; import com.github.inspektr.audit.AuditTrailManager; import org.slf4j.Logger; /** * Licensed to Inspektr under one or more contributor license * agreements. See the NOTICE file distributed with this work * for additional information regarding copyright ownership. * Inspektr licenses this file to you 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.github.inspektr.audit.support; /** * <code>AuditTrailManager</code> that dumps auditable information to a configured logger. * * @author Dmitriy Kopylenko * @version $Revision$ $Date$ * @since 1.0 * @see AuditTrailManager */ public final class Slf4jLoggingAuditTrailManager extends AbstractStringAuditTrailManager { private final Logger log = LoggerFactory.getLogger(this.getClass());
public void record(final AuditActionContext auditActionContext) {
dima767/inspektr
inspektr-support-spring/src/main/java/com/github/inspektr/error/web/ErrorLogHandlerExceptionResolver.java
// Path: inspektr-error/src/main/java/com/github/inspektr/error/ErrorLogManager.java // public interface ErrorLogManager { // // /** // * Records the specified error. // * // * @param errorDescription The error description. // */ // void recordError(String errorDescription); // // /** // * Records the specified throwable. // * // * @param throwable The throwable describing the error. // */ // void recordError(Throwable throwable); // // /** // * Returns the list of {@link ErrorReporter} associated with this manager. // * // * @return list of <code>ErrorReporters</code>. // */ // List<ErrorReporter> getErrorReporters(); // // }
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.validation.constraints.Min; import javax.validation.constraints.NotNull; import com.github.inspektr.error.ErrorLogManager; import org.springframework.core.Ordered; import org.springframework.web.servlet.HandlerExceptionResolver; import org.springframework.web.servlet.ModelAndView;
/** * Licensed to Inspektr under one or more contributor license * agreements. See the NOTICE file distributed with this work * for additional information regarding copyright ownership. * Inspektr licenses this file to you 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.github.inspektr.error.web; /** * A <code>HandlerExceptionResolver</code> implementation that reports uncaught * exceptions during handler mapping or execution to a configured * {@link com.github.inspektr.error.ErrorLogManager}. * <p> * <code>HanderExceptionResolvers</code> should be ordered. If the application has * other resolvers in addition to the <code>ErrorLogHandlerExceptionResolver</code>, * it should make sure that the <code>ErrorLogHandlerExceptionResolver</code> has * the lowest order value (i.e. highest priority) so as to make sure that this * resolver is always invoked. * * @author Alice Leung * @version $Revision: 1.3 $ $Date: 2007/07/11 20:48:46 $ * @since 1.0 */ public final class ErrorLogHandlerExceptionResolver implements HandlerExceptionResolver, Ordered { @NotNull
// Path: inspektr-error/src/main/java/com/github/inspektr/error/ErrorLogManager.java // public interface ErrorLogManager { // // /** // * Records the specified error. // * // * @param errorDescription The error description. // */ // void recordError(String errorDescription); // // /** // * Records the specified throwable. // * // * @param throwable The throwable describing the error. // */ // void recordError(Throwable throwable); // // /** // * Returns the list of {@link ErrorReporter} associated with this manager. // * // * @return list of <code>ErrorReporters</code>. // */ // List<ErrorReporter> getErrorReporters(); // // } // Path: inspektr-support-spring/src/main/java/com/github/inspektr/error/web/ErrorLogHandlerExceptionResolver.java import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.validation.constraints.Min; import javax.validation.constraints.NotNull; import com.github.inspektr.error.ErrorLogManager; import org.springframework.core.Ordered; import org.springframework.web.servlet.HandlerExceptionResolver; import org.springframework.web.servlet.ModelAndView; /** * Licensed to Inspektr under one or more contributor license * agreements. See the NOTICE file distributed with this work * for additional information regarding copyright ownership. * Inspektr licenses this file to you 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.github.inspektr.error.web; /** * A <code>HandlerExceptionResolver</code> implementation that reports uncaught * exceptions during handler mapping or execution to a configured * {@link com.github.inspektr.error.ErrorLogManager}. * <p> * <code>HanderExceptionResolvers</code> should be ordered. If the application has * other resolvers in addition to the <code>ErrorLogHandlerExceptionResolver</code>, * it should make sure that the <code>ErrorLogHandlerExceptionResolver</code> has * the lowest order value (i.e. highest priority) so as to make sure that this * resolver is always invoked. * * @author Alice Leung * @version $Revision: 1.3 $ $Date: 2007/07/11 20:48:46 $ * @since 1.0 */ public final class ErrorLogHandlerExceptionResolver implements HandlerExceptionResolver, Ordered { @NotNull
private ErrorLogManager errorLogManager;
dima767/inspektr
inspektr-common/src/main/java/com/github/inspektr/common/spi/DefaultClientInfoResolver.java
// Path: inspektr-common/src/main/java/com/github/inspektr/common/web/ClientInfo.java // public final class ClientInfo { // // public static ClientInfo EMPTY_CLIENT_INFO = new ClientInfo(); // // /** IP Address of the server (local). */ // private final String serverIpAddress; // // /** IP Address of the client (Remote) */ // private final String clientIpAddress; // // private ClientInfo() { // this((String) null, (String) null); // } // // public ClientInfo(final HttpServletRequest request) { // this(request.getLocalAddr(), request.getRemoteAddr()); // } // // public ClientInfo(final HttpServletRequest request, final String alternateLocation) { // this(request.getLocalAddr(), request.getHeader(alternateLocation) != null ? request.getHeader(alternateLocation) : request.getRemoteAddr()); // } // // public ClientInfo(final String serverIpAddress, final String clientIpAddress) { // this.serverIpAddress = serverIpAddress == null ? "unknown" : serverIpAddress; // this.clientIpAddress = clientIpAddress == null ? "unknown" : clientIpAddress; // } // // public String getServerIpAddress() { // return this.serverIpAddress; // } // // public String getClientIpAddress() { // return this.clientIpAddress; // } // } // // Path: inspektr-common/src/main/java/com/github/inspektr/common/web/ClientInfoHolder.java // public final class ClientInfoHolder { // // private static final ThreadLocal<ClientInfo> clientInfoHolder = new ThreadLocal<ClientInfo>(); // // public static void setClientInfo(final ClientInfo clientInfo) { // clientInfoHolder.set(clientInfo); // } // // public static ClientInfo getClientInfo() { // return clientInfoHolder.get(); // } // // public static void clear() { // clientInfoHolder.remove(); // } // }
import org.aspectj.lang.JoinPoint; import com.github.inspektr.common.web.ClientInfo; import com.github.inspektr.common.web.ClientInfoHolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory;
/** * Licensed to Inspektr under one or more contributor license * agreements. See the NOTICE file distributed with this work * for additional information regarding copyright ownership. * Inspektr licenses this file to you 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.github.inspektr.common.spi; /** * Default implementation that gets it from the ThreadLocal. * * @author Scott Battaglia * @version $Revision$ $Date$ * @since 1.0 * */ public final class DefaultClientInfoResolver implements ClientInfoResolver { private final Logger log = LoggerFactory.getLogger(getClass());
// Path: inspektr-common/src/main/java/com/github/inspektr/common/web/ClientInfo.java // public final class ClientInfo { // // public static ClientInfo EMPTY_CLIENT_INFO = new ClientInfo(); // // /** IP Address of the server (local). */ // private final String serverIpAddress; // // /** IP Address of the client (Remote) */ // private final String clientIpAddress; // // private ClientInfo() { // this((String) null, (String) null); // } // // public ClientInfo(final HttpServletRequest request) { // this(request.getLocalAddr(), request.getRemoteAddr()); // } // // public ClientInfo(final HttpServletRequest request, final String alternateLocation) { // this(request.getLocalAddr(), request.getHeader(alternateLocation) != null ? request.getHeader(alternateLocation) : request.getRemoteAddr()); // } // // public ClientInfo(final String serverIpAddress, final String clientIpAddress) { // this.serverIpAddress = serverIpAddress == null ? "unknown" : serverIpAddress; // this.clientIpAddress = clientIpAddress == null ? "unknown" : clientIpAddress; // } // // public String getServerIpAddress() { // return this.serverIpAddress; // } // // public String getClientIpAddress() { // return this.clientIpAddress; // } // } // // Path: inspektr-common/src/main/java/com/github/inspektr/common/web/ClientInfoHolder.java // public final class ClientInfoHolder { // // private static final ThreadLocal<ClientInfo> clientInfoHolder = new ThreadLocal<ClientInfo>(); // // public static void setClientInfo(final ClientInfo clientInfo) { // clientInfoHolder.set(clientInfo); // } // // public static ClientInfo getClientInfo() { // return clientInfoHolder.get(); // } // // public static void clear() { // clientInfoHolder.remove(); // } // } // Path: inspektr-common/src/main/java/com/github/inspektr/common/spi/DefaultClientInfoResolver.java import org.aspectj.lang.JoinPoint; import com.github.inspektr.common.web.ClientInfo; import com.github.inspektr.common.web.ClientInfoHolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Licensed to Inspektr under one or more contributor license * agreements. See the NOTICE file distributed with this work * for additional information regarding copyright ownership. * Inspektr licenses this file to you 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.github.inspektr.common.spi; /** * Default implementation that gets it from the ThreadLocal. * * @author Scott Battaglia * @version $Revision$ $Date$ * @since 1.0 * */ public final class DefaultClientInfoResolver implements ClientInfoResolver { private final Logger log = LoggerFactory.getLogger(getClass());
public ClientInfo resolveFrom(final JoinPoint joinPoint, final Object retVal) {
dima767/inspektr
inspektr-common/src/main/java/com/github/inspektr/common/spi/DefaultClientInfoResolver.java
// Path: inspektr-common/src/main/java/com/github/inspektr/common/web/ClientInfo.java // public final class ClientInfo { // // public static ClientInfo EMPTY_CLIENT_INFO = new ClientInfo(); // // /** IP Address of the server (local). */ // private final String serverIpAddress; // // /** IP Address of the client (Remote) */ // private final String clientIpAddress; // // private ClientInfo() { // this((String) null, (String) null); // } // // public ClientInfo(final HttpServletRequest request) { // this(request.getLocalAddr(), request.getRemoteAddr()); // } // // public ClientInfo(final HttpServletRequest request, final String alternateLocation) { // this(request.getLocalAddr(), request.getHeader(alternateLocation) != null ? request.getHeader(alternateLocation) : request.getRemoteAddr()); // } // // public ClientInfo(final String serverIpAddress, final String clientIpAddress) { // this.serverIpAddress = serverIpAddress == null ? "unknown" : serverIpAddress; // this.clientIpAddress = clientIpAddress == null ? "unknown" : clientIpAddress; // } // // public String getServerIpAddress() { // return this.serverIpAddress; // } // // public String getClientIpAddress() { // return this.clientIpAddress; // } // } // // Path: inspektr-common/src/main/java/com/github/inspektr/common/web/ClientInfoHolder.java // public final class ClientInfoHolder { // // private static final ThreadLocal<ClientInfo> clientInfoHolder = new ThreadLocal<ClientInfo>(); // // public static void setClientInfo(final ClientInfo clientInfo) { // clientInfoHolder.set(clientInfo); // } // // public static ClientInfo getClientInfo() { // return clientInfoHolder.get(); // } // // public static void clear() { // clientInfoHolder.remove(); // } // }
import org.aspectj.lang.JoinPoint; import com.github.inspektr.common.web.ClientInfo; import com.github.inspektr.common.web.ClientInfoHolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory;
/** * Licensed to Inspektr under one or more contributor license * agreements. See the NOTICE file distributed with this work * for additional information regarding copyright ownership. * Inspektr licenses this file to you 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.github.inspektr.common.spi; /** * Default implementation that gets it from the ThreadLocal. * * @author Scott Battaglia * @version $Revision$ $Date$ * @since 1.0 * */ public final class DefaultClientInfoResolver implements ClientInfoResolver { private final Logger log = LoggerFactory.getLogger(getClass()); public ClientInfo resolveFrom(final JoinPoint joinPoint, final Object retVal) {
// Path: inspektr-common/src/main/java/com/github/inspektr/common/web/ClientInfo.java // public final class ClientInfo { // // public static ClientInfo EMPTY_CLIENT_INFO = new ClientInfo(); // // /** IP Address of the server (local). */ // private final String serverIpAddress; // // /** IP Address of the client (Remote) */ // private final String clientIpAddress; // // private ClientInfo() { // this((String) null, (String) null); // } // // public ClientInfo(final HttpServletRequest request) { // this(request.getLocalAddr(), request.getRemoteAddr()); // } // // public ClientInfo(final HttpServletRequest request, final String alternateLocation) { // this(request.getLocalAddr(), request.getHeader(alternateLocation) != null ? request.getHeader(alternateLocation) : request.getRemoteAddr()); // } // // public ClientInfo(final String serverIpAddress, final String clientIpAddress) { // this.serverIpAddress = serverIpAddress == null ? "unknown" : serverIpAddress; // this.clientIpAddress = clientIpAddress == null ? "unknown" : clientIpAddress; // } // // public String getServerIpAddress() { // return this.serverIpAddress; // } // // public String getClientIpAddress() { // return this.clientIpAddress; // } // } // // Path: inspektr-common/src/main/java/com/github/inspektr/common/web/ClientInfoHolder.java // public final class ClientInfoHolder { // // private static final ThreadLocal<ClientInfo> clientInfoHolder = new ThreadLocal<ClientInfo>(); // // public static void setClientInfo(final ClientInfo clientInfo) { // clientInfoHolder.set(clientInfo); // } // // public static ClientInfo getClientInfo() { // return clientInfoHolder.get(); // } // // public static void clear() { // clientInfoHolder.remove(); // } // } // Path: inspektr-common/src/main/java/com/github/inspektr/common/spi/DefaultClientInfoResolver.java import org.aspectj.lang.JoinPoint; import com.github.inspektr.common.web.ClientInfo; import com.github.inspektr.common.web.ClientInfoHolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Licensed to Inspektr under one or more contributor license * agreements. See the NOTICE file distributed with this work * for additional information regarding copyright ownership. * Inspektr licenses this file to you 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.github.inspektr.common.spi; /** * Default implementation that gets it from the ThreadLocal. * * @author Scott Battaglia * @version $Revision$ $Date$ * @since 1.0 * */ public final class DefaultClientInfoResolver implements ClientInfoResolver { private final Logger log = LoggerFactory.getLogger(getClass()); public ClientInfo resolveFrom(final JoinPoint joinPoint, final Object retVal) {
final ClientInfo clientInfo = ClientInfoHolder.getClientInfo();
dima767/inspektr
inspektr-support-spring/src/main/java/com/github/inspektr/error/web/ErrorLoggingFilter.java
// Path: inspektr-error/src/main/java/com/github/inspektr/error/ErrorLogManager.java // public interface ErrorLogManager { // // /** // * Records the specified error. // * // * @param errorDescription The error description. // */ // void recordError(String errorDescription); // // /** // * Records the specified throwable. // * // * @param throwable The throwable describing the error. // */ // void recordError(Throwable throwable); // // /** // * Returns the list of {@link ErrorReporter} associated with this manager. // * // * @return list of <code>ErrorReporters</code>. // */ // List<ErrorReporter> getErrorReporters(); // // }
import java.io.IOException; import javax.servlet.FilterChain; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.validation.constraints.NotNull; import com.github.inspektr.error.ErrorLogManager; import org.springframework.web.filter.OncePerRequestFilter;
/** * Licensed to Inspektr under one or more contributor license * agreements. See the NOTICE file distributed with this work * for additional information regarding copyright ownership. * Inspektr licenses this file to you 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.github.inspektr.error.web; /** * Spring manageable bean implementing the <code>javax.servlet.Filter</code> * interface. This filter should be configured as the top of the web application's * filter chain and will record any uncaught exceptions from the chain using * the configured {@link com.github.inspektr.error.ErrorLogManager}. * To take advantage of Spring dependency injection, * this bean can be specified as the target of a <code>DelegatingFilterProxy</code>. * * @author lleung * @version $Revision: 1.2 $ $Date: 2007/07/11 20:48:46 $ * @since 1.0 */ public class ErrorLoggingFilter extends OncePerRequestFilter { @NotNull
// Path: inspektr-error/src/main/java/com/github/inspektr/error/ErrorLogManager.java // public interface ErrorLogManager { // // /** // * Records the specified error. // * // * @param errorDescription The error description. // */ // void recordError(String errorDescription); // // /** // * Records the specified throwable. // * // * @param throwable The throwable describing the error. // */ // void recordError(Throwable throwable); // // /** // * Returns the list of {@link ErrorReporter} associated with this manager. // * // * @return list of <code>ErrorReporters</code>. // */ // List<ErrorReporter> getErrorReporters(); // // } // Path: inspektr-support-spring/src/main/java/com/github/inspektr/error/web/ErrorLoggingFilter.java import java.io.IOException; import javax.servlet.FilterChain; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.validation.constraints.NotNull; import com.github.inspektr.error.ErrorLogManager; import org.springframework.web.filter.OncePerRequestFilter; /** * Licensed to Inspektr under one or more contributor license * agreements. See the NOTICE file distributed with this work * for additional information regarding copyright ownership. * Inspektr licenses this file to you 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.github.inspektr.error.web; /** * Spring manageable bean implementing the <code>javax.servlet.Filter</code> * interface. This filter should be configured as the top of the web application's * filter chain and will record any uncaught exceptions from the chain using * the configured {@link com.github.inspektr.error.ErrorLogManager}. * To take advantage of Spring dependency injection, * this bean can be specified as the target of a <code>DelegatingFilterProxy</code>. * * @author lleung * @version $Revision: 1.2 $ $Date: 2007/07/11 20:48:46 $ * @since 1.0 */ public class ErrorLoggingFilter extends OncePerRequestFilter { @NotNull
private ErrorLogManager errorLogManager;
dima767/inspektr
inspektr-error/src/main/java/com/github/inspektr/error/support/DefaultErrorLogManager.java
// Path: inspektr-common/src/main/java/com/github/inspektr/common/spi/PrincipalResolver.java // public interface PrincipalResolver { // // /** // * Default String that can be used when the user is anonymous. // */ // final String ANONYMOUS_USER = "audit:anonymous"; // // /** // * Default String that can be used when the user cannot be determined. // */ // final String UNKNOWN_USER = "audit:unknown"; // // /** // * Resolve the principal performing an audit-able action. // * <p> // * Note, this method should NEVER throw an exception *unless* the expectation is that a failed resolution causes // * the entire transaction to fail. Otherwise use {@link com.github.inspektr.common.spi.PrincipalResolver#UNKNOWN_USER}. // * // * @param auditTarget the join point where we're auditing. // * @param returnValue the returned value // * @return The principal as a String. CANNOT be NULL. // */ // String resolveFrom(JoinPoint auditTarget, Object returnValue); // // /** // * Resolve the principal performing an audit-able action that has incurred // * an exception. // * <p> // * Note, this method should NEVER throw an exception *unless* the expectation is that a failed resolution causes // * the entire transaction to fail. Otherwise use {@link com.github.inspektr.common.spi.PrincipalResolver#UNKNOWN_USER}. // * // * @param auditTarget the join point where we're auditing. // * @param exception The exception incurred when the join point proceeds. // * @return The principal as a String. CANNOT be NULL. // */ // String resolveFrom(JoinPoint auditTarget, Exception exception); // // /** // * Called when there is no other way to resolve the principal (i.e. an error was captured, auditing was not // * called, etc.) // * <p> // * Note, this method should NEVER throw an exception *unless* the expectation is that a failed resolution causes // * the entire transaction to fail. Otherwise use {@link com.github.inspektr.common.spi.PrincipalResolver#UNKNOWN_USER}. // * // * @return the principal. CANNOT be NULL. // */ // String resolve(); // } // // Path: inspektr-error/src/main/java/com/github/inspektr/error/ErrorLogManager.java // public interface ErrorLogManager { // // /** // * Records the specified error. // * // * @param errorDescription The error description. // */ // void recordError(String errorDescription); // // /** // * Records the specified throwable. // * // * @param throwable The throwable describing the error. // */ // void recordError(Throwable throwable); // // /** // * Returns the list of {@link ErrorReporter} associated with this manager. // * // * @return list of <code>ErrorReporters</code>. // */ // List<ErrorReporter> getErrorReporters(); // // } // // Path: inspektr-error/src/main/java/com/github/inspektr/error/ErrorReporter.java // public interface ErrorReporter { // // /** // * Reports the specified error. // * // * @param applicationCode The application identifier. // * @param principal Optional application-specific context information on the // * principal incurring the error. // * @param errorDescription Details on the error. // */ // void reportError(String applicationCode, String principal, String errorDescription); // // /** // * Reports the specified <code>Throwable</code>. // * // * @param applicationCode The application identifier. // * @param principal Optional application-specific context information on the // * principal incurring the error. // * @param throwable The <code>Throwable</code> to be reported. // */ // void reportError(String applicationCode, String principal, Throwable throwable); // // }
import com.github.inspektr.error.ErrorLogManager; import com.github.inspektr.error.ErrorReporter; import java.util.List; import com.github.inspektr.common.spi.PrincipalResolver;
/** * Licensed to Inspektr under one or more contributor license * agreements. See the NOTICE file distributed with this work * for additional information regarding copyright ownership. * Inspektr licenses this file to you 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.github.inspektr.error.support; /** * An <code>ErrorLogManager</code> implementation. * * @author lleung * @version $Revision: 1.2 $ $Date: 2007/07/11 20:48:47 $ * @since 1.0 */ public class DefaultErrorLogManager implements ErrorLogManager { /** * The application identifier to use when recording errors. */ private String applicationCode; /** * The resolver for a description of the principal associated with the error. */
// Path: inspektr-common/src/main/java/com/github/inspektr/common/spi/PrincipalResolver.java // public interface PrincipalResolver { // // /** // * Default String that can be used when the user is anonymous. // */ // final String ANONYMOUS_USER = "audit:anonymous"; // // /** // * Default String that can be used when the user cannot be determined. // */ // final String UNKNOWN_USER = "audit:unknown"; // // /** // * Resolve the principal performing an audit-able action. // * <p> // * Note, this method should NEVER throw an exception *unless* the expectation is that a failed resolution causes // * the entire transaction to fail. Otherwise use {@link com.github.inspektr.common.spi.PrincipalResolver#UNKNOWN_USER}. // * // * @param auditTarget the join point where we're auditing. // * @param returnValue the returned value // * @return The principal as a String. CANNOT be NULL. // */ // String resolveFrom(JoinPoint auditTarget, Object returnValue); // // /** // * Resolve the principal performing an audit-able action that has incurred // * an exception. // * <p> // * Note, this method should NEVER throw an exception *unless* the expectation is that a failed resolution causes // * the entire transaction to fail. Otherwise use {@link com.github.inspektr.common.spi.PrincipalResolver#UNKNOWN_USER}. // * // * @param auditTarget the join point where we're auditing. // * @param exception The exception incurred when the join point proceeds. // * @return The principal as a String. CANNOT be NULL. // */ // String resolveFrom(JoinPoint auditTarget, Exception exception); // // /** // * Called when there is no other way to resolve the principal (i.e. an error was captured, auditing was not // * called, etc.) // * <p> // * Note, this method should NEVER throw an exception *unless* the expectation is that a failed resolution causes // * the entire transaction to fail. Otherwise use {@link com.github.inspektr.common.spi.PrincipalResolver#UNKNOWN_USER}. // * // * @return the principal. CANNOT be NULL. // */ // String resolve(); // } // // Path: inspektr-error/src/main/java/com/github/inspektr/error/ErrorLogManager.java // public interface ErrorLogManager { // // /** // * Records the specified error. // * // * @param errorDescription The error description. // */ // void recordError(String errorDescription); // // /** // * Records the specified throwable. // * // * @param throwable The throwable describing the error. // */ // void recordError(Throwable throwable); // // /** // * Returns the list of {@link ErrorReporter} associated with this manager. // * // * @return list of <code>ErrorReporters</code>. // */ // List<ErrorReporter> getErrorReporters(); // // } // // Path: inspektr-error/src/main/java/com/github/inspektr/error/ErrorReporter.java // public interface ErrorReporter { // // /** // * Reports the specified error. // * // * @param applicationCode The application identifier. // * @param principal Optional application-specific context information on the // * principal incurring the error. // * @param errorDescription Details on the error. // */ // void reportError(String applicationCode, String principal, String errorDescription); // // /** // * Reports the specified <code>Throwable</code>. // * // * @param applicationCode The application identifier. // * @param principal Optional application-specific context information on the // * principal incurring the error. // * @param throwable The <code>Throwable</code> to be reported. // */ // void reportError(String applicationCode, String principal, Throwable throwable); // // } // Path: inspektr-error/src/main/java/com/github/inspektr/error/support/DefaultErrorLogManager.java import com.github.inspektr.error.ErrorLogManager; import com.github.inspektr.error.ErrorReporter; import java.util.List; import com.github.inspektr.common.spi.PrincipalResolver; /** * Licensed to Inspektr under one or more contributor license * agreements. See the NOTICE file distributed with this work * for additional information regarding copyright ownership. * Inspektr licenses this file to you 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.github.inspektr.error.support; /** * An <code>ErrorLogManager</code> implementation. * * @author lleung * @version $Revision: 1.2 $ $Date: 2007/07/11 20:48:47 $ * @since 1.0 */ public class DefaultErrorLogManager implements ErrorLogManager { /** * The application identifier to use when recording errors. */ private String applicationCode; /** * The resolver for a description of the principal associated with the error. */
private PrincipalResolver currentContextPrincipalResolver;
dima767/inspektr
inspektr-error/src/main/java/com/github/inspektr/error/support/DefaultErrorLogManager.java
// Path: inspektr-common/src/main/java/com/github/inspektr/common/spi/PrincipalResolver.java // public interface PrincipalResolver { // // /** // * Default String that can be used when the user is anonymous. // */ // final String ANONYMOUS_USER = "audit:anonymous"; // // /** // * Default String that can be used when the user cannot be determined. // */ // final String UNKNOWN_USER = "audit:unknown"; // // /** // * Resolve the principal performing an audit-able action. // * <p> // * Note, this method should NEVER throw an exception *unless* the expectation is that a failed resolution causes // * the entire transaction to fail. Otherwise use {@link com.github.inspektr.common.spi.PrincipalResolver#UNKNOWN_USER}. // * // * @param auditTarget the join point where we're auditing. // * @param returnValue the returned value // * @return The principal as a String. CANNOT be NULL. // */ // String resolveFrom(JoinPoint auditTarget, Object returnValue); // // /** // * Resolve the principal performing an audit-able action that has incurred // * an exception. // * <p> // * Note, this method should NEVER throw an exception *unless* the expectation is that a failed resolution causes // * the entire transaction to fail. Otherwise use {@link com.github.inspektr.common.spi.PrincipalResolver#UNKNOWN_USER}. // * // * @param auditTarget the join point where we're auditing. // * @param exception The exception incurred when the join point proceeds. // * @return The principal as a String. CANNOT be NULL. // */ // String resolveFrom(JoinPoint auditTarget, Exception exception); // // /** // * Called when there is no other way to resolve the principal (i.e. an error was captured, auditing was not // * called, etc.) // * <p> // * Note, this method should NEVER throw an exception *unless* the expectation is that a failed resolution causes // * the entire transaction to fail. Otherwise use {@link com.github.inspektr.common.spi.PrincipalResolver#UNKNOWN_USER}. // * // * @return the principal. CANNOT be NULL. // */ // String resolve(); // } // // Path: inspektr-error/src/main/java/com/github/inspektr/error/ErrorLogManager.java // public interface ErrorLogManager { // // /** // * Records the specified error. // * // * @param errorDescription The error description. // */ // void recordError(String errorDescription); // // /** // * Records the specified throwable. // * // * @param throwable The throwable describing the error. // */ // void recordError(Throwable throwable); // // /** // * Returns the list of {@link ErrorReporter} associated with this manager. // * // * @return list of <code>ErrorReporters</code>. // */ // List<ErrorReporter> getErrorReporters(); // // } // // Path: inspektr-error/src/main/java/com/github/inspektr/error/ErrorReporter.java // public interface ErrorReporter { // // /** // * Reports the specified error. // * // * @param applicationCode The application identifier. // * @param principal Optional application-specific context information on the // * principal incurring the error. // * @param errorDescription Details on the error. // */ // void reportError(String applicationCode, String principal, String errorDescription); // // /** // * Reports the specified <code>Throwable</code>. // * // * @param applicationCode The application identifier. // * @param principal Optional application-specific context information on the // * principal incurring the error. // * @param throwable The <code>Throwable</code> to be reported. // */ // void reportError(String applicationCode, String principal, Throwable throwable); // // }
import com.github.inspektr.error.ErrorLogManager; import com.github.inspektr.error.ErrorReporter; import java.util.List; import com.github.inspektr.common.spi.PrincipalResolver;
/** * Licensed to Inspektr under one or more contributor license * agreements. See the NOTICE file distributed with this work * for additional information regarding copyright ownership. * Inspektr licenses this file to you 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.github.inspektr.error.support; /** * An <code>ErrorLogManager</code> implementation. * * @author lleung * @version $Revision: 1.2 $ $Date: 2007/07/11 20:48:47 $ * @since 1.0 */ public class DefaultErrorLogManager implements ErrorLogManager { /** * The application identifier to use when recording errors. */ private String applicationCode; /** * The resolver for a description of the principal associated with the error. */ private PrincipalResolver currentContextPrincipalResolver; /** * The ErrorReporters to use to report the errors. */
// Path: inspektr-common/src/main/java/com/github/inspektr/common/spi/PrincipalResolver.java // public interface PrincipalResolver { // // /** // * Default String that can be used when the user is anonymous. // */ // final String ANONYMOUS_USER = "audit:anonymous"; // // /** // * Default String that can be used when the user cannot be determined. // */ // final String UNKNOWN_USER = "audit:unknown"; // // /** // * Resolve the principal performing an audit-able action. // * <p> // * Note, this method should NEVER throw an exception *unless* the expectation is that a failed resolution causes // * the entire transaction to fail. Otherwise use {@link com.github.inspektr.common.spi.PrincipalResolver#UNKNOWN_USER}. // * // * @param auditTarget the join point where we're auditing. // * @param returnValue the returned value // * @return The principal as a String. CANNOT be NULL. // */ // String resolveFrom(JoinPoint auditTarget, Object returnValue); // // /** // * Resolve the principal performing an audit-able action that has incurred // * an exception. // * <p> // * Note, this method should NEVER throw an exception *unless* the expectation is that a failed resolution causes // * the entire transaction to fail. Otherwise use {@link com.github.inspektr.common.spi.PrincipalResolver#UNKNOWN_USER}. // * // * @param auditTarget the join point where we're auditing. // * @param exception The exception incurred when the join point proceeds. // * @return The principal as a String. CANNOT be NULL. // */ // String resolveFrom(JoinPoint auditTarget, Exception exception); // // /** // * Called when there is no other way to resolve the principal (i.e. an error was captured, auditing was not // * called, etc.) // * <p> // * Note, this method should NEVER throw an exception *unless* the expectation is that a failed resolution causes // * the entire transaction to fail. Otherwise use {@link com.github.inspektr.common.spi.PrincipalResolver#UNKNOWN_USER}. // * // * @return the principal. CANNOT be NULL. // */ // String resolve(); // } // // Path: inspektr-error/src/main/java/com/github/inspektr/error/ErrorLogManager.java // public interface ErrorLogManager { // // /** // * Records the specified error. // * // * @param errorDescription The error description. // */ // void recordError(String errorDescription); // // /** // * Records the specified throwable. // * // * @param throwable The throwable describing the error. // */ // void recordError(Throwable throwable); // // /** // * Returns the list of {@link ErrorReporter} associated with this manager. // * // * @return list of <code>ErrorReporters</code>. // */ // List<ErrorReporter> getErrorReporters(); // // } // // Path: inspektr-error/src/main/java/com/github/inspektr/error/ErrorReporter.java // public interface ErrorReporter { // // /** // * Reports the specified error. // * // * @param applicationCode The application identifier. // * @param principal Optional application-specific context information on the // * principal incurring the error. // * @param errorDescription Details on the error. // */ // void reportError(String applicationCode, String principal, String errorDescription); // // /** // * Reports the specified <code>Throwable</code>. // * // * @param applicationCode The application identifier. // * @param principal Optional application-specific context information on the // * principal incurring the error. // * @param throwable The <code>Throwable</code> to be reported. // */ // void reportError(String applicationCode, String principal, Throwable throwable); // // } // Path: inspektr-error/src/main/java/com/github/inspektr/error/support/DefaultErrorLogManager.java import com.github.inspektr.error.ErrorLogManager; import com.github.inspektr.error.ErrorReporter; import java.util.List; import com.github.inspektr.common.spi.PrincipalResolver; /** * Licensed to Inspektr under one or more contributor license * agreements. See the NOTICE file distributed with this work * for additional information regarding copyright ownership. * Inspektr licenses this file to you 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.github.inspektr.error.support; /** * An <code>ErrorLogManager</code> implementation. * * @author lleung * @version $Revision: 1.2 $ $Date: 2007/07/11 20:48:47 $ * @since 1.0 */ public class DefaultErrorLogManager implements ErrorLogManager { /** * The application identifier to use when recording errors. */ private String applicationCode; /** * The resolver for a description of the principal associated with the error. */ private PrincipalResolver currentContextPrincipalResolver; /** * The ErrorReporters to use to report the errors. */
private List<ErrorReporter> errorReporters;
berict/Tapad
app/src/main/java/com/bedrock/padder/activity/VideoAdActivity.java
// Path: app/src/main/java/com/bedrock/padder/helper/WindowHelper.java // @Nullable // public static String getStringFromId(String id, Context context) { // try { // Class res = R.string.class; // Field field = res.getField(id); // return context.getResources().getString(field.getInt(null)); // } catch (Exception e) { // Log.e("getStringFromId", "Failure to get string from id [" + id + "]"); // return null; // } // //from : https://daniel-codes.blogspot.com/2009/12/dynamically-retrieving-resources-in.html // }
import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.Toast; import com.bedrock.padder.R; import com.google.android.gms.ads.AdRequest; import com.google.android.gms.ads.MobileAds; import com.google.android.gms.ads.reward.RewardItem; import com.google.android.gms.ads.reward.RewardedVideoAd; import com.google.android.gms.ads.reward.RewardedVideoAdListener; import static com.bedrock.padder.helper.WindowHelper.getStringFromId;
private void loadRewardedVideoAd() { if (!mRewardedVideoAd.isLoaded()) { //mRewardedVideoAd.loadAd(getStringFromId(R.string.admob_unit_id_video, this), // new AdRequest.Builder().build()); mRewardedVideoAd.loadAd("ca-app-pub-3940256099942544/5224354917", new AdRequest.Builder().build()); } } @Override public void onRewardedVideoAdLoaded() { mRewardedVideoAd.show(); } @Override public void onRewardedVideoAdOpened() { } @Override public void onRewardedVideoStarted() { } @Override public void onRewardedVideoAdClosed() { finish(); } @Override public void onRewarded(RewardItem reward) {
// Path: app/src/main/java/com/bedrock/padder/helper/WindowHelper.java // @Nullable // public static String getStringFromId(String id, Context context) { // try { // Class res = R.string.class; // Field field = res.getField(id); // return context.getResources().getString(field.getInt(null)); // } catch (Exception e) { // Log.e("getStringFromId", "Failure to get string from id [" + id + "]"); // return null; // } // //from : https://daniel-codes.blogspot.com/2009/12/dynamically-retrieving-resources-in.html // } // Path: app/src/main/java/com/bedrock/padder/activity/VideoAdActivity.java import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.Toast; import com.bedrock.padder.R; import com.google.android.gms.ads.AdRequest; import com.google.android.gms.ads.MobileAds; import com.google.android.gms.ads.reward.RewardItem; import com.google.android.gms.ads.reward.RewardedVideoAd; import com.google.android.gms.ads.reward.RewardedVideoAdListener; import static com.bedrock.padder.helper.WindowHelper.getStringFromId; private void loadRewardedVideoAd() { if (!mRewardedVideoAd.isLoaded()) { //mRewardedVideoAd.loadAd(getStringFromId(R.string.admob_unit_id_video, this), // new AdRequest.Builder().build()); mRewardedVideoAd.loadAd("ca-app-pub-3940256099942544/5224354917", new AdRequest.Builder().build()); } } @Override public void onRewardedVideoAdLoaded() { mRewardedVideoAd.show(); } @Override public void onRewardedVideoAdOpened() { } @Override public void onRewardedVideoStarted() { } @Override public void onRewardedVideoAdClosed() { finish(); } @Override public void onRewarded(RewardItem reward) {
Toast.makeText(this, getStringFromId(R.string.ads_video_thanks, this), Toast.LENGTH_LONG).show();
berict/Tapad
app/src/main/java/com/bedrock/padder/model/sound/GesturePad.java
// Path: app/src/main/java/com/bedrock/padder/helper/OnSwipeTouchListener.java // public class OnSwipeTouchListener implements View.OnTouchListener { // // private GestureDetector gestureDetector; // // public OnSwipeTouchListener(Context c) { // gestureDetector = new GestureDetector(c, new GestureListener()); // } // // public boolean onTouch(final View view, final MotionEvent motionEvent) { // return gestureDetector.onTouchEvent(motionEvent); // } // // private final class GestureListener extends GestureDetector.SimpleOnGestureListener { // // private static final int SWIPE_THRESHOLD = 100; // private static final int SWIPE_VELOCITY_THRESHOLD = 100; // // @Override // public boolean onDown(MotionEvent e) { // onTouch(); // return true; // } // // @Override // public boolean onSingleTapUp(MotionEvent e) { // onClick(); // return super.onSingleTapUp(e); // } // // @Override // public boolean onSingleTapConfirmed(MotionEvent e) { // onSingleClickConfirmed(); // return super.onSingleTapConfirmed(e); // } // // @Override // public boolean onDoubleTap(MotionEvent e) { // onDoubleClick(); // return super.onDoubleTap(e); // } // // @Override // public void onLongPress(MotionEvent e) { // onLongClick(); // super.onLongPress(e); // } // // // Determines the fling velocity and then fires the appropriate swipe event accordingly // @Override // public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { // boolean result = false; // try { // float diffY = e2.getY() - e1.getY(); // float diffX = e2.getX() - e1.getX(); // if (Math.abs(diffX) > Math.abs(diffY)) { // if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) { // if (diffX > 0) { // onSwipeRight(); // } else { // onSwipeLeft(); // } // } // } else { // if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) { // if (diffY > 0) { // onSwipeDown(); // } else { // onSwipeUp(); // } // } // } // } catch (Exception exception) { // exception.printStackTrace(); // } // return result; // } // } // // public void onTouch() { // } // // public void onSwipeRight() { // } // // public void onSwipeLeft() { // } // // public void onSwipeUp() { // } // // public void onSwipeDown() { // } // // public void onClick() { // } // // public void onDoubleClick() { // } // // public void onLongClick() { // } // // public void onSingleClickConfirmed() { // } // } // // Path: app/src/main/java/com/bedrock/padder/activity/MainActivity.java // public static boolean isStopLoopOnSingle = false; // // Path: app/src/main/java/com/bedrock/padder/model/tutorial/TimingListener.java // public static boolean broadcast(Timing timing) { // int index = timings.indexOf(timing); // if (index >= 0) { // Timing listening = timings.get(index); // // timing configuration // int delay = (int) (timing.listenTime - listening.listenTime // - (TUTORIAL_ANIMATION_DURATION + 100)); // // if (listening.listener != null) { // listening.listener.onBroadcast(timing, delay); // } // timings.remove(index); // Log.w("broadcast", "Listener removed for " + timing.toString()); // return true; // } else { // Log.w("broadcast", "No listener found for " + timing.toString()); // return false; // } // }
import android.app.Activity; import android.util.Log; import android.view.View; import com.bedrock.padder.helper.OnSwipeTouchListener; import static com.bedrock.padder.activity.MainActivity.isStopLoopOnSingle; import static com.bedrock.padder.model.tutorial.TimingListener.broadcast;
Sound up, Sound right, Sound down, Sound left, int deck, View view, int color, int colorDef, Activity activity) { super(normal, deck, view, color, colorDef, activity, false); this.up = up; this.right = right; this.down = down; this.left = left; initListener(); } public GesturePad(Sound sounds[], int deck, View view, int color, int colorDef, Activity activity) { super(sounds[0], deck, view, color, colorDef, activity, false); this.up = sounds[1]; this.right = sounds[2]; this.down = sounds[3]; this.left = sounds[4]; initListener(); } private void initListener() { normal.setSoundListener(new Sound.SoundListener() { @Override public void onSoundStart(Sound sound, int playingThreadCount) { threadCount++; if (threadCount == 1 && !padColorOnPlay) { setPadColor(colorDef); }
// Path: app/src/main/java/com/bedrock/padder/helper/OnSwipeTouchListener.java // public class OnSwipeTouchListener implements View.OnTouchListener { // // private GestureDetector gestureDetector; // // public OnSwipeTouchListener(Context c) { // gestureDetector = new GestureDetector(c, new GestureListener()); // } // // public boolean onTouch(final View view, final MotionEvent motionEvent) { // return gestureDetector.onTouchEvent(motionEvent); // } // // private final class GestureListener extends GestureDetector.SimpleOnGestureListener { // // private static final int SWIPE_THRESHOLD = 100; // private static final int SWIPE_VELOCITY_THRESHOLD = 100; // // @Override // public boolean onDown(MotionEvent e) { // onTouch(); // return true; // } // // @Override // public boolean onSingleTapUp(MotionEvent e) { // onClick(); // return super.onSingleTapUp(e); // } // // @Override // public boolean onSingleTapConfirmed(MotionEvent e) { // onSingleClickConfirmed(); // return super.onSingleTapConfirmed(e); // } // // @Override // public boolean onDoubleTap(MotionEvent e) { // onDoubleClick(); // return super.onDoubleTap(e); // } // // @Override // public void onLongPress(MotionEvent e) { // onLongClick(); // super.onLongPress(e); // } // // // Determines the fling velocity and then fires the appropriate swipe event accordingly // @Override // public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { // boolean result = false; // try { // float diffY = e2.getY() - e1.getY(); // float diffX = e2.getX() - e1.getX(); // if (Math.abs(diffX) > Math.abs(diffY)) { // if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) { // if (diffX > 0) { // onSwipeRight(); // } else { // onSwipeLeft(); // } // } // } else { // if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) { // if (diffY > 0) { // onSwipeDown(); // } else { // onSwipeUp(); // } // } // } // } catch (Exception exception) { // exception.printStackTrace(); // } // return result; // } // } // // public void onTouch() { // } // // public void onSwipeRight() { // } // // public void onSwipeLeft() { // } // // public void onSwipeUp() { // } // // public void onSwipeDown() { // } // // public void onClick() { // } // // public void onDoubleClick() { // } // // public void onLongClick() { // } // // public void onSingleClickConfirmed() { // } // } // // Path: app/src/main/java/com/bedrock/padder/activity/MainActivity.java // public static boolean isStopLoopOnSingle = false; // // Path: app/src/main/java/com/bedrock/padder/model/tutorial/TimingListener.java // public static boolean broadcast(Timing timing) { // int index = timings.indexOf(timing); // if (index >= 0) { // Timing listening = timings.get(index); // // timing configuration // int delay = (int) (timing.listenTime - listening.listenTime // - (TUTORIAL_ANIMATION_DURATION + 100)); // // if (listening.listener != null) { // listening.listener.onBroadcast(timing, delay); // } // timings.remove(index); // Log.w("broadcast", "Listener removed for " + timing.toString()); // return true; // } else { // Log.w("broadcast", "No listener found for " + timing.toString()); // return false; // } // } // Path: app/src/main/java/com/bedrock/padder/model/sound/GesturePad.java import android.app.Activity; import android.util.Log; import android.view.View; import com.bedrock.padder.helper.OnSwipeTouchListener; import static com.bedrock.padder.activity.MainActivity.isStopLoopOnSingle; import static com.bedrock.padder.model.tutorial.TimingListener.broadcast; Sound up, Sound right, Sound down, Sound left, int deck, View view, int color, int colorDef, Activity activity) { super(normal, deck, view, color, colorDef, activity, false); this.up = up; this.right = right; this.down = down; this.left = left; initListener(); } public GesturePad(Sound sounds[], int deck, View view, int color, int colorDef, Activity activity) { super(sounds[0], deck, view, color, colorDef, activity, false); this.up = sounds[1]; this.right = sounds[2]; this.down = sounds[3]; this.left = sounds[4]; initListener(); } private void initListener() { normal.setSoundListener(new Sound.SoundListener() { @Override public void onSoundStart(Sound sound, int playingThreadCount) { threadCount++; if (threadCount == 1 && !padColorOnPlay) { setPadColor(colorDef); }
broadcast(deck, column * 10 + row);
berict/Tapad
app/src/main/java/com/bedrock/padder/model/sound/GesturePad.java
// Path: app/src/main/java/com/bedrock/padder/helper/OnSwipeTouchListener.java // public class OnSwipeTouchListener implements View.OnTouchListener { // // private GestureDetector gestureDetector; // // public OnSwipeTouchListener(Context c) { // gestureDetector = new GestureDetector(c, new GestureListener()); // } // // public boolean onTouch(final View view, final MotionEvent motionEvent) { // return gestureDetector.onTouchEvent(motionEvent); // } // // private final class GestureListener extends GestureDetector.SimpleOnGestureListener { // // private static final int SWIPE_THRESHOLD = 100; // private static final int SWIPE_VELOCITY_THRESHOLD = 100; // // @Override // public boolean onDown(MotionEvent e) { // onTouch(); // return true; // } // // @Override // public boolean onSingleTapUp(MotionEvent e) { // onClick(); // return super.onSingleTapUp(e); // } // // @Override // public boolean onSingleTapConfirmed(MotionEvent e) { // onSingleClickConfirmed(); // return super.onSingleTapConfirmed(e); // } // // @Override // public boolean onDoubleTap(MotionEvent e) { // onDoubleClick(); // return super.onDoubleTap(e); // } // // @Override // public void onLongPress(MotionEvent e) { // onLongClick(); // super.onLongPress(e); // } // // // Determines the fling velocity and then fires the appropriate swipe event accordingly // @Override // public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { // boolean result = false; // try { // float diffY = e2.getY() - e1.getY(); // float diffX = e2.getX() - e1.getX(); // if (Math.abs(diffX) > Math.abs(diffY)) { // if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) { // if (diffX > 0) { // onSwipeRight(); // } else { // onSwipeLeft(); // } // } // } else { // if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) { // if (diffY > 0) { // onSwipeDown(); // } else { // onSwipeUp(); // } // } // } // } catch (Exception exception) { // exception.printStackTrace(); // } // return result; // } // } // // public void onTouch() { // } // // public void onSwipeRight() { // } // // public void onSwipeLeft() { // } // // public void onSwipeUp() { // } // // public void onSwipeDown() { // } // // public void onClick() { // } // // public void onDoubleClick() { // } // // public void onLongClick() { // } // // public void onSingleClickConfirmed() { // } // } // // Path: app/src/main/java/com/bedrock/padder/activity/MainActivity.java // public static boolean isStopLoopOnSingle = false; // // Path: app/src/main/java/com/bedrock/padder/model/tutorial/TimingListener.java // public static boolean broadcast(Timing timing) { // int index = timings.indexOf(timing); // if (index >= 0) { // Timing listening = timings.get(index); // // timing configuration // int delay = (int) (timing.listenTime - listening.listenTime // - (TUTORIAL_ANIMATION_DURATION + 100)); // // if (listening.listener != null) { // listening.listener.onBroadcast(timing, delay); // } // timings.remove(index); // Log.w("broadcast", "Listener removed for " + timing.toString()); // return true; // } else { // Log.w("broadcast", "No listener found for " + timing.toString()); // return false; // } // }
import android.app.Activity; import android.util.Log; import android.view.View; import com.bedrock.padder.helper.OnSwipeTouchListener; import static com.bedrock.padder.activity.MainActivity.isStopLoopOnSingle; import static com.bedrock.padder.model.tutorial.TimingListener.broadcast;
} else { return normal; } } public Sound getDown() { if (down.getDuration() > 0) { return down; } else { return normal; } } public Sound getLeft() { if (left.getDuration() > 0) { return left; } else { return normal; } } @Override public Sound getNormal() { return super.getNormal(); } @Override void setPad() { if (normal != null && view != null && color != 0 && colorDef != 0 && activity != null) { // initialized check, normal should be not null
// Path: app/src/main/java/com/bedrock/padder/helper/OnSwipeTouchListener.java // public class OnSwipeTouchListener implements View.OnTouchListener { // // private GestureDetector gestureDetector; // // public OnSwipeTouchListener(Context c) { // gestureDetector = new GestureDetector(c, new GestureListener()); // } // // public boolean onTouch(final View view, final MotionEvent motionEvent) { // return gestureDetector.onTouchEvent(motionEvent); // } // // private final class GestureListener extends GestureDetector.SimpleOnGestureListener { // // private static final int SWIPE_THRESHOLD = 100; // private static final int SWIPE_VELOCITY_THRESHOLD = 100; // // @Override // public boolean onDown(MotionEvent e) { // onTouch(); // return true; // } // // @Override // public boolean onSingleTapUp(MotionEvent e) { // onClick(); // return super.onSingleTapUp(e); // } // // @Override // public boolean onSingleTapConfirmed(MotionEvent e) { // onSingleClickConfirmed(); // return super.onSingleTapConfirmed(e); // } // // @Override // public boolean onDoubleTap(MotionEvent e) { // onDoubleClick(); // return super.onDoubleTap(e); // } // // @Override // public void onLongPress(MotionEvent e) { // onLongClick(); // super.onLongPress(e); // } // // // Determines the fling velocity and then fires the appropriate swipe event accordingly // @Override // public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { // boolean result = false; // try { // float diffY = e2.getY() - e1.getY(); // float diffX = e2.getX() - e1.getX(); // if (Math.abs(diffX) > Math.abs(diffY)) { // if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) { // if (diffX > 0) { // onSwipeRight(); // } else { // onSwipeLeft(); // } // } // } else { // if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) { // if (diffY > 0) { // onSwipeDown(); // } else { // onSwipeUp(); // } // } // } // } catch (Exception exception) { // exception.printStackTrace(); // } // return result; // } // } // // public void onTouch() { // } // // public void onSwipeRight() { // } // // public void onSwipeLeft() { // } // // public void onSwipeUp() { // } // // public void onSwipeDown() { // } // // public void onClick() { // } // // public void onDoubleClick() { // } // // public void onLongClick() { // } // // public void onSingleClickConfirmed() { // } // } // // Path: app/src/main/java/com/bedrock/padder/activity/MainActivity.java // public static boolean isStopLoopOnSingle = false; // // Path: app/src/main/java/com/bedrock/padder/model/tutorial/TimingListener.java // public static boolean broadcast(Timing timing) { // int index = timings.indexOf(timing); // if (index >= 0) { // Timing listening = timings.get(index); // // timing configuration // int delay = (int) (timing.listenTime - listening.listenTime // - (TUTORIAL_ANIMATION_DURATION + 100)); // // if (listening.listener != null) { // listening.listener.onBroadcast(timing, delay); // } // timings.remove(index); // Log.w("broadcast", "Listener removed for " + timing.toString()); // return true; // } else { // Log.w("broadcast", "No listener found for " + timing.toString()); // return false; // } // } // Path: app/src/main/java/com/bedrock/padder/model/sound/GesturePad.java import android.app.Activity; import android.util.Log; import android.view.View; import com.bedrock.padder.helper.OnSwipeTouchListener; import static com.bedrock.padder.activity.MainActivity.isStopLoopOnSingle; import static com.bedrock.padder.model.tutorial.TimingListener.broadcast; } else { return normal; } } public Sound getDown() { if (down.getDuration() > 0) { return down; } else { return normal; } } public Sound getLeft() { if (left.getDuration() > 0) { return left; } else { return normal; } } @Override public Sound getNormal() { return super.getNormal(); } @Override void setPad() { if (normal != null && view != null && color != 0 && colorDef != 0 && activity != null) { // initialized check, normal should be not null
view.setOnTouchListener(new OnSwipeTouchListener(activity) {
berict/Tapad
app/src/main/java/com/bedrock/padder/model/sound/GesturePad.java
// Path: app/src/main/java/com/bedrock/padder/helper/OnSwipeTouchListener.java // public class OnSwipeTouchListener implements View.OnTouchListener { // // private GestureDetector gestureDetector; // // public OnSwipeTouchListener(Context c) { // gestureDetector = new GestureDetector(c, new GestureListener()); // } // // public boolean onTouch(final View view, final MotionEvent motionEvent) { // return gestureDetector.onTouchEvent(motionEvent); // } // // private final class GestureListener extends GestureDetector.SimpleOnGestureListener { // // private static final int SWIPE_THRESHOLD = 100; // private static final int SWIPE_VELOCITY_THRESHOLD = 100; // // @Override // public boolean onDown(MotionEvent e) { // onTouch(); // return true; // } // // @Override // public boolean onSingleTapUp(MotionEvent e) { // onClick(); // return super.onSingleTapUp(e); // } // // @Override // public boolean onSingleTapConfirmed(MotionEvent e) { // onSingleClickConfirmed(); // return super.onSingleTapConfirmed(e); // } // // @Override // public boolean onDoubleTap(MotionEvent e) { // onDoubleClick(); // return super.onDoubleTap(e); // } // // @Override // public void onLongPress(MotionEvent e) { // onLongClick(); // super.onLongPress(e); // } // // // Determines the fling velocity and then fires the appropriate swipe event accordingly // @Override // public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { // boolean result = false; // try { // float diffY = e2.getY() - e1.getY(); // float diffX = e2.getX() - e1.getX(); // if (Math.abs(diffX) > Math.abs(diffY)) { // if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) { // if (diffX > 0) { // onSwipeRight(); // } else { // onSwipeLeft(); // } // } // } else { // if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) { // if (diffY > 0) { // onSwipeDown(); // } else { // onSwipeUp(); // } // } // } // } catch (Exception exception) { // exception.printStackTrace(); // } // return result; // } // } // // public void onTouch() { // } // // public void onSwipeRight() { // } // // public void onSwipeLeft() { // } // // public void onSwipeUp() { // } // // public void onSwipeDown() { // } // // public void onClick() { // } // // public void onDoubleClick() { // } // // public void onLongClick() { // } // // public void onSingleClickConfirmed() { // } // } // // Path: app/src/main/java/com/bedrock/padder/activity/MainActivity.java // public static boolean isStopLoopOnSingle = false; // // Path: app/src/main/java/com/bedrock/padder/model/tutorial/TimingListener.java // public static boolean broadcast(Timing timing) { // int index = timings.indexOf(timing); // if (index >= 0) { // Timing listening = timings.get(index); // // timing configuration // int delay = (int) (timing.listenTime - listening.listenTime // - (TUTORIAL_ANIMATION_DURATION + 100)); // // if (listening.listener != null) { // listening.listener.onBroadcast(timing, delay); // } // timings.remove(index); // Log.w("broadcast", "Listener removed for " + timing.toString()); // return true; // } else { // Log.w("broadcast", "No listener found for " + timing.toString()); // return false; // } // }
import android.app.Activity; import android.util.Log; import android.view.View; import com.bedrock.padder.helper.OnSwipeTouchListener; import static com.bedrock.padder.activity.MainActivity.isStopLoopOnSingle; import static com.bedrock.padder.model.tutorial.TimingListener.broadcast;
return normal; } } public Sound getLeft() { if (left.getDuration() > 0) { return left; } else { return normal; } } @Override public Sound getNormal() { return super.getNormal(); } @Override void setPad() { if (normal != null && view != null && color != 0 && colorDef != 0 && activity != null) { // initialized check, normal should be not null view.setOnTouchListener(new OnSwipeTouchListener(activity) { @Override public void onTouch() { setPadColor(); Log.d("Pad [Gesture]", "onTouch"); } @Override public void onClick() {
// Path: app/src/main/java/com/bedrock/padder/helper/OnSwipeTouchListener.java // public class OnSwipeTouchListener implements View.OnTouchListener { // // private GestureDetector gestureDetector; // // public OnSwipeTouchListener(Context c) { // gestureDetector = new GestureDetector(c, new GestureListener()); // } // // public boolean onTouch(final View view, final MotionEvent motionEvent) { // return gestureDetector.onTouchEvent(motionEvent); // } // // private final class GestureListener extends GestureDetector.SimpleOnGestureListener { // // private static final int SWIPE_THRESHOLD = 100; // private static final int SWIPE_VELOCITY_THRESHOLD = 100; // // @Override // public boolean onDown(MotionEvent e) { // onTouch(); // return true; // } // // @Override // public boolean onSingleTapUp(MotionEvent e) { // onClick(); // return super.onSingleTapUp(e); // } // // @Override // public boolean onSingleTapConfirmed(MotionEvent e) { // onSingleClickConfirmed(); // return super.onSingleTapConfirmed(e); // } // // @Override // public boolean onDoubleTap(MotionEvent e) { // onDoubleClick(); // return super.onDoubleTap(e); // } // // @Override // public void onLongPress(MotionEvent e) { // onLongClick(); // super.onLongPress(e); // } // // // Determines the fling velocity and then fires the appropriate swipe event accordingly // @Override // public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { // boolean result = false; // try { // float diffY = e2.getY() - e1.getY(); // float diffX = e2.getX() - e1.getX(); // if (Math.abs(diffX) > Math.abs(diffY)) { // if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) { // if (diffX > 0) { // onSwipeRight(); // } else { // onSwipeLeft(); // } // } // } else { // if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) { // if (diffY > 0) { // onSwipeDown(); // } else { // onSwipeUp(); // } // } // } // } catch (Exception exception) { // exception.printStackTrace(); // } // return result; // } // } // // public void onTouch() { // } // // public void onSwipeRight() { // } // // public void onSwipeLeft() { // } // // public void onSwipeUp() { // } // // public void onSwipeDown() { // } // // public void onClick() { // } // // public void onDoubleClick() { // } // // public void onLongClick() { // } // // public void onSingleClickConfirmed() { // } // } // // Path: app/src/main/java/com/bedrock/padder/activity/MainActivity.java // public static boolean isStopLoopOnSingle = false; // // Path: app/src/main/java/com/bedrock/padder/model/tutorial/TimingListener.java // public static boolean broadcast(Timing timing) { // int index = timings.indexOf(timing); // if (index >= 0) { // Timing listening = timings.get(index); // // timing configuration // int delay = (int) (timing.listenTime - listening.listenTime // - (TUTORIAL_ANIMATION_DURATION + 100)); // // if (listening.listener != null) { // listening.listener.onBroadcast(timing, delay); // } // timings.remove(index); // Log.w("broadcast", "Listener removed for " + timing.toString()); // return true; // } else { // Log.w("broadcast", "No listener found for " + timing.toString()); // return false; // } // } // Path: app/src/main/java/com/bedrock/padder/model/sound/GesturePad.java import android.app.Activity; import android.util.Log; import android.view.View; import com.bedrock.padder.helper.OnSwipeTouchListener; import static com.bedrock.padder.activity.MainActivity.isStopLoopOnSingle; import static com.bedrock.padder.model.tutorial.TimingListener.broadcast; return normal; } } public Sound getLeft() { if (left.getDuration() > 0) { return left; } else { return normal; } } @Override public Sound getNormal() { return super.getNormal(); } @Override void setPad() { if (normal != null && view != null && color != 0 && colorDef != 0 && activity != null) { // initialized check, normal should be not null view.setOnTouchListener(new OnSwipeTouchListener(activity) { @Override public void onTouch() { setPadColor(); Log.d("Pad [Gesture]", "onTouch"); } @Override public void onClick() {
if (getNormal().isLooping && isStopLoopOnSingle) {
berict/Tapad
app/src/main/java/com/bedrock/padder/model/tutorial/TutorialView.java
// Path: app/src/main/java/com/bedrock/padder/model/tutorial/TimingListener.java // public static void listen(Timing timing) { // if (timings.indexOf(timing) >= 0) { // timings.remove(timing); // Log.e("broadcast", "duplicate: listener removed for " + timing.toString()); // } // timings.add(timing); // Log.i("broadcast", "listener added for " + timing.toString()); // } // // Path: app/src/main/java/com/bedrock/padder/model/tutorial/Tutorial.java // public static Animation ANIMATION_FADE = new AlphaAnimation(1, 0); // // Path: app/src/main/java/com/bedrock/padder/model/tutorial/Tutorial.java // public static int TUTORIAL_ANIMATION_DURATION = 400; // 400 ~ 500 seems legit
import android.os.Handler; import android.util.Log; import android.view.View; import android.view.animation.Animation; import static com.bedrock.padder.model.tutorial.TimingListener.listen; import static com.bedrock.padder.model.tutorial.Tutorial.ANIMATION_FADE; import static com.bedrock.padder.model.tutorial.Tutorial.TUTORIAL_ANIMATION_DURATION;
package com.bedrock.padder.model.tutorial; public class TutorialView { private View view; private Timing timing; private Animation animation = null; private Animation.AnimationListener listener = new Animation.AnimationListener() { boolean isOnAnimationEndCalled = false; boolean isAnimationCalled = false; @Override public void onAnimationStart(final Animation anim) { if (view != null) { view.setVisibility(View.VISIBLE); Log.d("TutorialView", "animation.onAnimationStart " + view.getTag()); } new Handler().postDelayed(new Runnable() { @Override public void run() { onAnimationEnd(anim); } }, anim.getDuration()); } @Override public void onAnimationEnd(Animation anim) { if (!isOnAnimationEndCalled) { Log.d("TutorialView", "animation.onAnimationEnd " + view.getTag()); if (view != null) {
// Path: app/src/main/java/com/bedrock/padder/model/tutorial/TimingListener.java // public static void listen(Timing timing) { // if (timings.indexOf(timing) >= 0) { // timings.remove(timing); // Log.e("broadcast", "duplicate: listener removed for " + timing.toString()); // } // timings.add(timing); // Log.i("broadcast", "listener added for " + timing.toString()); // } // // Path: app/src/main/java/com/bedrock/padder/model/tutorial/Tutorial.java // public static Animation ANIMATION_FADE = new AlphaAnimation(1, 0); // // Path: app/src/main/java/com/bedrock/padder/model/tutorial/Tutorial.java // public static int TUTORIAL_ANIMATION_DURATION = 400; // 400 ~ 500 seems legit // Path: app/src/main/java/com/bedrock/padder/model/tutorial/TutorialView.java import android.os.Handler; import android.util.Log; import android.view.View; import android.view.animation.Animation; import static com.bedrock.padder.model.tutorial.TimingListener.listen; import static com.bedrock.padder.model.tutorial.Tutorial.ANIMATION_FADE; import static com.bedrock.padder.model.tutorial.Tutorial.TUTORIAL_ANIMATION_DURATION; package com.bedrock.padder.model.tutorial; public class TutorialView { private View view; private Timing timing; private Animation animation = null; private Animation.AnimationListener listener = new Animation.AnimationListener() { boolean isOnAnimationEndCalled = false; boolean isAnimationCalled = false; @Override public void onAnimationStart(final Animation anim) { if (view != null) { view.setVisibility(View.VISIBLE); Log.d("TutorialView", "animation.onAnimationStart " + view.getTag()); } new Handler().postDelayed(new Runnable() { @Override public void run() { onAnimationEnd(anim); } }, anim.getDuration()); } @Override public void onAnimationEnd(Animation anim) { if (!isOnAnimationEndCalled) { Log.d("TutorialView", "animation.onAnimationEnd " + view.getTag()); if (view != null) {
Animation hide = ANIMATION_FADE;
berict/Tapad
app/src/main/java/com/bedrock/padder/model/tutorial/TutorialView.java
// Path: app/src/main/java/com/bedrock/padder/model/tutorial/TimingListener.java // public static void listen(Timing timing) { // if (timings.indexOf(timing) >= 0) { // timings.remove(timing); // Log.e("broadcast", "duplicate: listener removed for " + timing.toString()); // } // timings.add(timing); // Log.i("broadcast", "listener added for " + timing.toString()); // } // // Path: app/src/main/java/com/bedrock/padder/model/tutorial/Tutorial.java // public static Animation ANIMATION_FADE = new AlphaAnimation(1, 0); // // Path: app/src/main/java/com/bedrock/padder/model/tutorial/Tutorial.java // public static int TUTORIAL_ANIMATION_DURATION = 400; // 400 ~ 500 seems legit
import android.os.Handler; import android.util.Log; import android.view.View; import android.view.animation.Animation; import static com.bedrock.padder.model.tutorial.TimingListener.listen; import static com.bedrock.padder.model.tutorial.Tutorial.ANIMATION_FADE; import static com.bedrock.padder.model.tutorial.Tutorial.TUTORIAL_ANIMATION_DURATION;
public void onAnimationEnd(Animation anim) { if (!isOnAnimationEndCalled) { view.setVisibility(View.INVISIBLE); Log.d("TutorialView", "hide.onAnimationEnd " + view.getTag()); } isOnAnimationEndCalled = true; } @Override public void onAnimationRepeat(Animation anim) { } }); hide.setDuration(50); if (view != null) { Log.d("TutorialView", "view.startAnimation " + view.getTag()); Log.d("TutorialView", "view.getVisibility " + view.getVisibility()); } view.startAnimation(hide); new Handler().postDelayed(new Runnable() { @Override public void run() { if (!isAnimationCalled) { Log.w("run", "View " + view.getTag() + ".getVisibility " + view.getVisibility()); view.setVisibility(View.INVISIBLE); } } }, 50 + 10);
// Path: app/src/main/java/com/bedrock/padder/model/tutorial/TimingListener.java // public static void listen(Timing timing) { // if (timings.indexOf(timing) >= 0) { // timings.remove(timing); // Log.e("broadcast", "duplicate: listener removed for " + timing.toString()); // } // timings.add(timing); // Log.i("broadcast", "listener added for " + timing.toString()); // } // // Path: app/src/main/java/com/bedrock/padder/model/tutorial/Tutorial.java // public static Animation ANIMATION_FADE = new AlphaAnimation(1, 0); // // Path: app/src/main/java/com/bedrock/padder/model/tutorial/Tutorial.java // public static int TUTORIAL_ANIMATION_DURATION = 400; // 400 ~ 500 seems legit // Path: app/src/main/java/com/bedrock/padder/model/tutorial/TutorialView.java import android.os.Handler; import android.util.Log; import android.view.View; import android.view.animation.Animation; import static com.bedrock.padder.model.tutorial.TimingListener.listen; import static com.bedrock.padder.model.tutorial.Tutorial.ANIMATION_FADE; import static com.bedrock.padder.model.tutorial.Tutorial.TUTORIAL_ANIMATION_DURATION; public void onAnimationEnd(Animation anim) { if (!isOnAnimationEndCalled) { view.setVisibility(View.INVISIBLE); Log.d("TutorialView", "hide.onAnimationEnd " + view.getTag()); } isOnAnimationEndCalled = true; } @Override public void onAnimationRepeat(Animation anim) { } }); hide.setDuration(50); if (view != null) { Log.d("TutorialView", "view.startAnimation " + view.getTag()); Log.d("TutorialView", "view.getVisibility " + view.getVisibility()); } view.startAnimation(hide); new Handler().postDelayed(new Runnable() { @Override public void run() { if (!isAnimationCalled) { Log.w("run", "View " + view.getTag() + ".getVisibility " + view.getVisibility()); view.setVisibility(View.INVISIBLE); } } }, 50 + 10);
if (animation.getDuration() != TUTORIAL_ANIMATION_DURATION) {
berict/Tapad
app/src/main/java/com/bedrock/padder/model/tutorial/TutorialView.java
// Path: app/src/main/java/com/bedrock/padder/model/tutorial/TimingListener.java // public static void listen(Timing timing) { // if (timings.indexOf(timing) >= 0) { // timings.remove(timing); // Log.e("broadcast", "duplicate: listener removed for " + timing.toString()); // } // timings.add(timing); // Log.i("broadcast", "listener added for " + timing.toString()); // } // // Path: app/src/main/java/com/bedrock/padder/model/tutorial/Tutorial.java // public static Animation ANIMATION_FADE = new AlphaAnimation(1, 0); // // Path: app/src/main/java/com/bedrock/padder/model/tutorial/Tutorial.java // public static int TUTORIAL_ANIMATION_DURATION = 400; // 400 ~ 500 seems legit
import android.os.Handler; import android.util.Log; import android.view.View; import android.view.animation.Animation; import static com.bedrock.padder.model.tutorial.TimingListener.listen; import static com.bedrock.padder.model.tutorial.Tutorial.ANIMATION_FADE; import static com.bedrock.padder.model.tutorial.Tutorial.TUTORIAL_ANIMATION_DURATION;
} @Override public void onAnimationRepeat(Animation anim) { } }; TutorialView(View view, Timing timing) { this.view = view; this.timing = timing; } void setAnimation(Animation animation) { this.animation = animation; animation.setAnimationListener(listener); } public void setDuration(int duration) { animation.setDuration(duration); } public void start() { if (view == null) { Log.e("TutorialView", "View is null"); return; } if (animation == null) { Log.e("TutorialView", "Animation is not initialized"); return; }
// Path: app/src/main/java/com/bedrock/padder/model/tutorial/TimingListener.java // public static void listen(Timing timing) { // if (timings.indexOf(timing) >= 0) { // timings.remove(timing); // Log.e("broadcast", "duplicate: listener removed for " + timing.toString()); // } // timings.add(timing); // Log.i("broadcast", "listener added for " + timing.toString()); // } // // Path: app/src/main/java/com/bedrock/padder/model/tutorial/Tutorial.java // public static Animation ANIMATION_FADE = new AlphaAnimation(1, 0); // // Path: app/src/main/java/com/bedrock/padder/model/tutorial/Tutorial.java // public static int TUTORIAL_ANIMATION_DURATION = 400; // 400 ~ 500 seems legit // Path: app/src/main/java/com/bedrock/padder/model/tutorial/TutorialView.java import android.os.Handler; import android.util.Log; import android.view.View; import android.view.animation.Animation; import static com.bedrock.padder.model.tutorial.TimingListener.listen; import static com.bedrock.padder.model.tutorial.Tutorial.ANIMATION_FADE; import static com.bedrock.padder.model.tutorial.Tutorial.TUTORIAL_ANIMATION_DURATION; } @Override public void onAnimationRepeat(Animation anim) { } }; TutorialView(View view, Timing timing) { this.view = view; this.timing = timing; } void setAnimation(Animation animation) { this.animation = animation; animation.setAnimationListener(listener); } public void setDuration(int duration) { animation.setDuration(duration); } public void start() { if (view == null) { Log.e("TutorialView", "View is null"); return; } if (animation == null) { Log.e("TutorialView", "Animation is not initialized"); return; }
listen(timing);
berict/Tapad
app/src/main/java/com/bedrock/padder/model/about/Item.java
// Path: app/src/main/java/com/bedrock/padder/helper/WindowHelper.java // public static String getStringFromIdWithFallback(String id, Context context) { // try { // Class res = R.string.class; // Field field = res.getField(id); // return context.getResources().getString(field.getInt(null)); // } catch (Exception e) { // Log.e("getStringFromId", "Failure to get string from id [" + id + "]"); // return id; // } // //from : https://daniel-codes.blogspot.com/2009/12/dynamically-retrieving-resources-in.html // }
import android.content.Context; import static com.bedrock.padder.helper.WindowHelper.getStringFromIdWithFallback;
private Boolean isRunnableWithAnim; public Item(String text, String hint) { this.text = text; this.hint = hint; this.isHintVisible = true; this.imageId = text; this.isRunnableWithAnim = false; } public Item(String text, String hint, Boolean isHintVisible) { this.text = text; this.hint = hint; this.isHintVisible = isHintVisible; this.imageId = text; this.isRunnableWithAnim = false; } public Item(String text, String hint, Boolean isHintVisible, String imageId) { this.text = text; this.hint = hint; this.isHintVisible = isHintVisible; this.imageId = imageId; } public String getText() { return text; } public String getText(Context context) {
// Path: app/src/main/java/com/bedrock/padder/helper/WindowHelper.java // public static String getStringFromIdWithFallback(String id, Context context) { // try { // Class res = R.string.class; // Field field = res.getField(id); // return context.getResources().getString(field.getInt(null)); // } catch (Exception e) { // Log.e("getStringFromId", "Failure to get string from id [" + id + "]"); // return id; // } // //from : https://daniel-codes.blogspot.com/2009/12/dynamically-retrieving-resources-in.html // } // Path: app/src/main/java/com/bedrock/padder/model/about/Item.java import android.content.Context; import static com.bedrock.padder.helper.WindowHelper.getStringFromIdWithFallback; private Boolean isRunnableWithAnim; public Item(String text, String hint) { this.text = text; this.hint = hint; this.isHintVisible = true; this.imageId = text; this.isRunnableWithAnim = false; } public Item(String text, String hint, Boolean isHintVisible) { this.text = text; this.hint = hint; this.isHintVisible = isHintVisible; this.imageId = text; this.isRunnableWithAnim = false; } public Item(String text, String hint, Boolean isHintVisible, String imageId) { this.text = text; this.hint = hint; this.isHintVisible = isHintVisible; this.imageId = imageId; } public String getText() { return text; } public String getText(Context context) {
return getStringFromIdWithFallback(getText(), context);
berict/Tapad
app/src/main/java/com/bedrock/padder/api/SchemaVersion.java
// Path: app/src/main/java/com/bedrock/padder/model/preset/Version.java // public class Version { // // private Integer version; // // public Version(Integer version) { // this.version = version; // } // // public Integer getVersion() { // return version; // } // }
import com.bedrock.padder.model.preset.Version; import retrofit2.http.GET; import rx.Observable;
package com.bedrock.padder.api; public interface SchemaVersion { @GET("tapad/version")
// Path: app/src/main/java/com/bedrock/padder/model/preset/Version.java // public class Version { // // private Integer version; // // public Version(Integer version) { // this.version = version; // } // // public Integer getVersion() { // return version; // } // } // Path: app/src/main/java/com/bedrock/padder/api/SchemaVersion.java import com.bedrock.padder.model.preset.Version; import retrofit2.http.GET; import rx.Observable; package com.bedrock.padder.api; public interface SchemaVersion { @GET("tapad/version")
Observable<Version> getObservableVersion();
berict/Tapad
app/src/main/java/com/bedrock/padder/model/tutorial/TutorialXmlParser.java
// Path: app/src/main/java/com/bedrock/padder/helper/FileHelper.java // public static String PROJECT_LOCATION_PRESETS = Environment.getExternalStorageDirectory().getPath() + "/Tapad/presets";
import android.app.Activity; import android.util.Log; import android.util.Xml; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import static com.bedrock.padder.helper.FileHelper.PROJECT_LOCATION_PRESETS;
package com.bedrock.padder.model.tutorial; /* Example from * https://developer.android.com/training/basics/network-ops/xml.html */ public class TutorialXmlParser { String tag; Activity activity = null; public TutorialXmlParser(String tag, Activity activity) { this.activity = activity; this.tag = tag; } // We don't use namespaces private static final String ns = null; public Tutorial parse() { try {
// Path: app/src/main/java/com/bedrock/padder/helper/FileHelper.java // public static String PROJECT_LOCATION_PRESETS = Environment.getExternalStorageDirectory().getPath() + "/Tapad/presets"; // Path: app/src/main/java/com/bedrock/padder/model/tutorial/TutorialXmlParser.java import android.app.Activity; import android.util.Log; import android.util.Xml; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import static com.bedrock.padder.helper.FileHelper.PROJECT_LOCATION_PRESETS; package com.bedrock.padder.model.tutorial; /* Example from * https://developer.android.com/training/basics/network-ops/xml.html */ public class TutorialXmlParser { String tag; Activity activity = null; public TutorialXmlParser(String tag, Activity activity) { this.activity = activity; this.tag = tag; } // We don't use namespaces private static final String ns = null; public Tutorial parse() { try {
return parse(new FileInputStream(PROJECT_LOCATION_PRESETS + "/" + tag + "/timing/timing.tpt"));
berict/Tapad
app/src/main/java/com/bedrock/padder/model/tutorial/TimingListener.java
// Path: app/src/main/java/com/bedrock/padder/model/tutorial/Tutorial.java // public static int TUTORIAL_ANIMATION_DURATION = 400; // 400 ~ 500 seems legit
import android.util.Log; import java.util.ArrayList; import static com.bedrock.padder.model.tutorial.Tutorial.TUTORIAL_ANIMATION_DURATION;
package com.bedrock.padder.model.tutorial; public class TimingListener { public static ArrayList<Timing> timings = new ArrayList<>(); // attach on TutorialView public static void listen(Timing timing) { if (timings.indexOf(timing) >= 0) { timings.remove(timing); Log.e("broadcast", "duplicate: listener removed for " + timing.toString()); } timings.add(timing); Log.i("broadcast", "listener added for " + timing.toString()); } // attach on Pad public static boolean broadcast(Timing timing) { int index = timings.indexOf(timing); if (index >= 0) { Timing listening = timings.get(index); // timing configuration int delay = (int) (timing.listenTime - listening.listenTime
// Path: app/src/main/java/com/bedrock/padder/model/tutorial/Tutorial.java // public static int TUTORIAL_ANIMATION_DURATION = 400; // 400 ~ 500 seems legit // Path: app/src/main/java/com/bedrock/padder/model/tutorial/TimingListener.java import android.util.Log; import java.util.ArrayList; import static com.bedrock.padder.model.tutorial.Tutorial.TUTORIAL_ANIMATION_DURATION; package com.bedrock.padder.model.tutorial; public class TimingListener { public static ArrayList<Timing> timings = new ArrayList<>(); // attach on TutorialView public static void listen(Timing timing) { if (timings.indexOf(timing) >= 0) { timings.remove(timing); Log.e("broadcast", "duplicate: listener removed for " + timing.toString()); } timings.add(timing); Log.i("broadcast", "listener added for " + timing.toString()); } // attach on Pad public static boolean broadcast(Timing timing) { int index = timings.indexOf(timing); if (index >= 0) { Timing listening = timings.get(index); // timing configuration int delay = (int) (timing.listenTime - listening.listenTime
- (TUTORIAL_ANIMATION_DURATION + 100));
berict/Tapad
app/src/main/java/com/bedrock/padder/model/tutorial/Tutorial.java
// Path: app/src/main/java/com/bedrock/padder/helper/WindowHelper.java // public static int getId(String id) { // try { // Class res = R.id.class; // Field field = res.getField(id); // return field.getInt(null); // } catch (Exception e) { // Log.e("getId", "Failure to get id.", e); // return -1; // } // //from : https://daniel-codes.blogspot.com/2009/12/dynamically-retrieving-resources-in.html // } // // Path: app/src/main/java/com/bedrock/padder/model/tutorial/TimingListener.java // public static ArrayList<Timing> timings = new ArrayList<>();
import android.app.Activity; import android.os.AsyncTask; import android.os.Handler; import android.os.Looper; import android.support.v4.view.animation.LinearOutSlowInInterpolator; import android.util.Log; import android.view.View; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.view.animation.ScaleAnimation; import com.google.gson.GsonBuilder; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import static com.bedrock.padder.helper.WindowHelper.getId; import static com.bedrock.padder.model.tutorial.TimingListener.timings;
boolean hasSamePad = sync.hasSamePad(syncs.get(currentSyncIndex)); for (Sync.Item item : sync.items) { if (hasSamePad && delay < 400) { // Set duration as 50ms less than next interval if (delay > 50) { show(item.deck, item.pad, item.gesture, delay - 50); } else { Log.e("Sync", "TUTORIAL SKIPPED: bad tutorial composition (same pad under 50ms)"); } } else { show(item.deck, item.pad, item.gesture); } } if (delay == 0) { handler.post(this); } else { handler.postDelayed(this, delay); } } else { for (Sync.Item item : sync.items) { show(item.deck, item.pad, item.gesture); } handler.postDelayed(new Runnable() { @Override public void run() { Log.i("TUTORIAL", "ended"); listener.onFinish(getTutorial());
// Path: app/src/main/java/com/bedrock/padder/helper/WindowHelper.java // public static int getId(String id) { // try { // Class res = R.id.class; // Field field = res.getField(id); // return field.getInt(null); // } catch (Exception e) { // Log.e("getId", "Failure to get id.", e); // return -1; // } // //from : https://daniel-codes.blogspot.com/2009/12/dynamically-retrieving-resources-in.html // } // // Path: app/src/main/java/com/bedrock/padder/model/tutorial/TimingListener.java // public static ArrayList<Timing> timings = new ArrayList<>(); // Path: app/src/main/java/com/bedrock/padder/model/tutorial/Tutorial.java import android.app.Activity; import android.os.AsyncTask; import android.os.Handler; import android.os.Looper; import android.support.v4.view.animation.LinearOutSlowInInterpolator; import android.util.Log; import android.view.View; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.view.animation.ScaleAnimation; import com.google.gson.GsonBuilder; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import static com.bedrock.padder.helper.WindowHelper.getId; import static com.bedrock.padder.model.tutorial.TimingListener.timings; boolean hasSamePad = sync.hasSamePad(syncs.get(currentSyncIndex)); for (Sync.Item item : sync.items) { if (hasSamePad && delay < 400) { // Set duration as 50ms less than next interval if (delay > 50) { show(item.deck, item.pad, item.gesture, delay - 50); } else { Log.e("Sync", "TUTORIAL SKIPPED: bad tutorial composition (same pad under 50ms)"); } } else { show(item.deck, item.pad, item.gesture); } } if (delay == 0) { handler.post(this); } else { handler.postDelayed(this, delay); } } else { for (Sync.Item item : sync.items) { show(item.deck, item.pad, item.gesture); } handler.postDelayed(new Runnable() { @Override public void run() { Log.i("TUTORIAL", "ended"); listener.onFinish(getTutorial());
timings.clear();
berict/Tapad
app/src/main/java/com/bedrock/padder/model/tutorial/Tutorial.java
// Path: app/src/main/java/com/bedrock/padder/helper/WindowHelper.java // public static int getId(String id) { // try { // Class res = R.id.class; // Field field = res.getField(id); // return field.getInt(null); // } catch (Exception e) { // Log.e("getId", "Failure to get id.", e); // return -1; // } // //from : https://daniel-codes.blogspot.com/2009/12/dynamically-retrieving-resources-in.html // } // // Path: app/src/main/java/com/bedrock/padder/model/tutorial/TimingListener.java // public static ArrayList<Timing> timings = new ArrayList<>();
import android.app.Activity; import android.os.AsyncTask; import android.os.Handler; import android.os.Looper; import android.support.v4.view.animation.LinearOutSlowInInterpolator; import android.util.Log; import android.view.View; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.view.animation.ScaleAnimation; import com.google.gson.GsonBuilder; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import static com.bedrock.padder.helper.WindowHelper.getId; import static com.bedrock.padder.model.tutorial.TimingListener.timings;
} else { view = new TutorialView(pads[pad], new Timing(deck, pad)); view.setAnimation(animations[0]); } } else { view = new TutorialView(decks[deck - 1], new Timing(deck)); view.setAnimation(animations[0]); } view.setDuration(duration); view.start(); } Log.d("TUTORIAL", "show [" + deck + ", " + pad + ", " + gesture + "]"); } private void init(Tutorial tutorial) { if (tutorial != null) { this.bpm = tutorial.bpm; this.syncs = tutorial.syncs; Log.i(this.getClass().getSimpleName(), "tutorial.syncs.size = " + tutorial.syncs.size()); Log.i(this.getClass().getSimpleName(), "syncs.size = " + syncs.size()); init(); } else { Log.e(this.getClass().getSimpleName(), ".init: tutorial is null"); } } private void init() { handler = new Handler(Looper.getMainLooper()); for (int i = 0; i < decks.length; i++) {
// Path: app/src/main/java/com/bedrock/padder/helper/WindowHelper.java // public static int getId(String id) { // try { // Class res = R.id.class; // Field field = res.getField(id); // return field.getInt(null); // } catch (Exception e) { // Log.e("getId", "Failure to get id.", e); // return -1; // } // //from : https://daniel-codes.blogspot.com/2009/12/dynamically-retrieving-resources-in.html // } // // Path: app/src/main/java/com/bedrock/padder/model/tutorial/TimingListener.java // public static ArrayList<Timing> timings = new ArrayList<>(); // Path: app/src/main/java/com/bedrock/padder/model/tutorial/Tutorial.java import android.app.Activity; import android.os.AsyncTask; import android.os.Handler; import android.os.Looper; import android.support.v4.view.animation.LinearOutSlowInInterpolator; import android.util.Log; import android.view.View; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.view.animation.ScaleAnimation; import com.google.gson.GsonBuilder; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import static com.bedrock.padder.helper.WindowHelper.getId; import static com.bedrock.padder.model.tutorial.TimingListener.timings; } else { view = new TutorialView(pads[pad], new Timing(deck, pad)); view.setAnimation(animations[0]); } } else { view = new TutorialView(decks[deck - 1], new Timing(deck)); view.setAnimation(animations[0]); } view.setDuration(duration); view.start(); } Log.d("TUTORIAL", "show [" + deck + ", " + pad + ", " + gesture + "]"); } private void init(Tutorial tutorial) { if (tutorial != null) { this.bpm = tutorial.bpm; this.syncs = tutorial.syncs; Log.i(this.getClass().getSimpleName(), "tutorial.syncs.size = " + tutorial.syncs.size()); Log.i(this.getClass().getSimpleName(), "syncs.size = " + syncs.size()); init(); } else { Log.e(this.getClass().getSimpleName(), ".init: tutorial is null"); } } private void init() { handler = new Handler(Looper.getMainLooper()); for (int i = 0; i < decks.length; i++) {
decks[i] = activity.findViewById(getId("tgl" + String.valueOf(i + 1) + "_tutorial"));
berict/Tapad
app/src/main/java/com/bedrock/padder/model/about/Bio.java
// Path: app/src/main/java/com/bedrock/padder/model/preset/Preset.java // public class Preset { // // private String tag; // // private About about; // // private Boolean isGesture; // // private Integer soundCount; // // private Integer bpm; // // public Preset(String tag, About about, Boolean isGesture, Integer soundCount, Integer bpm) { // this.tag = tag; // this.about = about; // this.isGesture = isGesture; // this.soundCount = soundCount; // this.bpm = bpm; // } // // public String getTag() { // return tag; // } // // public Boolean isGesture() { // return isGesture; // } // // public Integer getSoundCount() { // return soundCount; // } // // public Integer getBpm() { // return bpm; // } // // public void setTag(String tag) { // this.tag = tag; // } // // public About getAbout() { // return about; // } // // public String getSound(int deckIndex, int padIndex, int gestureIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + getPadStringFromIndex(padIndex); // if (gestureIndex > 0) { // fileName += "_" + gestureIndex; // } // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // public String getSound(int deckIndex, int padIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + getPadStringFromIndex(padIndex); // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // public String getSound(int deckIndex, String padIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + padIndex; // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // private String getPadStringFromIndex(int padIndex) { // switch (padIndex) { // case 0: // return "00"; // case 1: // return "11"; // case 2: // return "12"; // case 3: // return "13"; // case 4: // return "14"; // case 5: // return "21"; // case 6: // return "22"; // case 7: // return "23"; // case 8: // return "24"; // case 9: // return "31"; // case 10: // return "32"; // case 11: // return "33"; // case 12: // return "34"; // case 13: // return "41"; // case 14: // return "42"; // case 15: // return "43"; // case 16: // return "44"; // default: // return null; // } // } // // public Boolean getInAppTutorialAvailable() { // return new File(PROJECT_LOCATION_PRESETS + "/" + getTag() + "/timing/timing.tpt").exists(); // } // // public void loadPreset(Activity activity) { // isPresetChanged = true; // new Preferences(activity).setLastPlayed(tag); // } // // public void load(int color, int colorDef, Activity activity) { // SoundHelper sound = new SoundHelper(); // sound.load(this, color, colorDef, activity); // } // // @Override // public String toString() { // Gson gson = new GsonBuilder() // .setPrettyPrinting() // .create(); // return gson.toJson(this); // } // } // // Path: app/src/main/java/com/bedrock/padder/helper/FileHelper.java // public static String PROJECT_LOCATION_PRESETS = Environment.getExternalStorageDirectory().getPath() + "/Tapad/presets"; // // Path: app/src/main/java/com/bedrock/padder/helper/WindowHelper.java // public static String getStringFromIdWithFallback(String id, Context context) { // try { // Class res = R.string.class; // Field field = res.getField(id); // return context.getResources().getString(field.getInt(null)); // } catch (Exception e) { // Log.e("getStringFromId", "Failure to get string from id [" + id + "]"); // return id; // } // //from : https://daniel-codes.blogspot.com/2009/12/dynamically-retrieving-resources-in.html // }
import android.content.Context; import com.bedrock.padder.model.preset.Preset; import static com.bedrock.padder.helper.FileHelper.PROJECT_LOCATION_PRESETS; import static com.bedrock.padder.helper.WindowHelper.getStringFromIdWithFallback;
package com.bedrock.padder.model.about; public class Bio { private String title; private String name; private String text; private String source; public Bio(String title, String name, String text, String source) { this.title = title; this.name = name; this.text = text; this.source = source; } public String getTitle() { return title; } public String getTitle(Context context) {
// Path: app/src/main/java/com/bedrock/padder/model/preset/Preset.java // public class Preset { // // private String tag; // // private About about; // // private Boolean isGesture; // // private Integer soundCount; // // private Integer bpm; // // public Preset(String tag, About about, Boolean isGesture, Integer soundCount, Integer bpm) { // this.tag = tag; // this.about = about; // this.isGesture = isGesture; // this.soundCount = soundCount; // this.bpm = bpm; // } // // public String getTag() { // return tag; // } // // public Boolean isGesture() { // return isGesture; // } // // public Integer getSoundCount() { // return soundCount; // } // // public Integer getBpm() { // return bpm; // } // // public void setTag(String tag) { // this.tag = tag; // } // // public About getAbout() { // return about; // } // // public String getSound(int deckIndex, int padIndex, int gestureIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + getPadStringFromIndex(padIndex); // if (gestureIndex > 0) { // fileName += "_" + gestureIndex; // } // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // public String getSound(int deckIndex, int padIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + getPadStringFromIndex(padIndex); // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // public String getSound(int deckIndex, String padIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + padIndex; // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // private String getPadStringFromIndex(int padIndex) { // switch (padIndex) { // case 0: // return "00"; // case 1: // return "11"; // case 2: // return "12"; // case 3: // return "13"; // case 4: // return "14"; // case 5: // return "21"; // case 6: // return "22"; // case 7: // return "23"; // case 8: // return "24"; // case 9: // return "31"; // case 10: // return "32"; // case 11: // return "33"; // case 12: // return "34"; // case 13: // return "41"; // case 14: // return "42"; // case 15: // return "43"; // case 16: // return "44"; // default: // return null; // } // } // // public Boolean getInAppTutorialAvailable() { // return new File(PROJECT_LOCATION_PRESETS + "/" + getTag() + "/timing/timing.tpt").exists(); // } // // public void loadPreset(Activity activity) { // isPresetChanged = true; // new Preferences(activity).setLastPlayed(tag); // } // // public void load(int color, int colorDef, Activity activity) { // SoundHelper sound = new SoundHelper(); // sound.load(this, color, colorDef, activity); // } // // @Override // public String toString() { // Gson gson = new GsonBuilder() // .setPrettyPrinting() // .create(); // return gson.toJson(this); // } // } // // Path: app/src/main/java/com/bedrock/padder/helper/FileHelper.java // public static String PROJECT_LOCATION_PRESETS = Environment.getExternalStorageDirectory().getPath() + "/Tapad/presets"; // // Path: app/src/main/java/com/bedrock/padder/helper/WindowHelper.java // public static String getStringFromIdWithFallback(String id, Context context) { // try { // Class res = R.string.class; // Field field = res.getField(id); // return context.getResources().getString(field.getInt(null)); // } catch (Exception e) { // Log.e("getStringFromId", "Failure to get string from id [" + id + "]"); // return id; // } // //from : https://daniel-codes.blogspot.com/2009/12/dynamically-retrieving-resources-in.html // } // Path: app/src/main/java/com/bedrock/padder/model/about/Bio.java import android.content.Context; import com.bedrock.padder.model.preset.Preset; import static com.bedrock.padder.helper.FileHelper.PROJECT_LOCATION_PRESETS; import static com.bedrock.padder.helper.WindowHelper.getStringFromIdWithFallback; package com.bedrock.padder.model.about; public class Bio { private String title; private String name; private String text; private String source; public Bio(String title, String name, String text, String source) { this.title = title; this.name = name; this.text = text; this.source = source; } public String getTitle() { return title; } public String getTitle(Context context) {
return getStringFromIdWithFallback(getTitle(), context);
berict/Tapad
app/src/main/java/com/bedrock/padder/model/about/Bio.java
// Path: app/src/main/java/com/bedrock/padder/model/preset/Preset.java // public class Preset { // // private String tag; // // private About about; // // private Boolean isGesture; // // private Integer soundCount; // // private Integer bpm; // // public Preset(String tag, About about, Boolean isGesture, Integer soundCount, Integer bpm) { // this.tag = tag; // this.about = about; // this.isGesture = isGesture; // this.soundCount = soundCount; // this.bpm = bpm; // } // // public String getTag() { // return tag; // } // // public Boolean isGesture() { // return isGesture; // } // // public Integer getSoundCount() { // return soundCount; // } // // public Integer getBpm() { // return bpm; // } // // public void setTag(String tag) { // this.tag = tag; // } // // public About getAbout() { // return about; // } // // public String getSound(int deckIndex, int padIndex, int gestureIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + getPadStringFromIndex(padIndex); // if (gestureIndex > 0) { // fileName += "_" + gestureIndex; // } // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // public String getSound(int deckIndex, int padIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + getPadStringFromIndex(padIndex); // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // public String getSound(int deckIndex, String padIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + padIndex; // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // private String getPadStringFromIndex(int padIndex) { // switch (padIndex) { // case 0: // return "00"; // case 1: // return "11"; // case 2: // return "12"; // case 3: // return "13"; // case 4: // return "14"; // case 5: // return "21"; // case 6: // return "22"; // case 7: // return "23"; // case 8: // return "24"; // case 9: // return "31"; // case 10: // return "32"; // case 11: // return "33"; // case 12: // return "34"; // case 13: // return "41"; // case 14: // return "42"; // case 15: // return "43"; // case 16: // return "44"; // default: // return null; // } // } // // public Boolean getInAppTutorialAvailable() { // return new File(PROJECT_LOCATION_PRESETS + "/" + getTag() + "/timing/timing.tpt").exists(); // } // // public void loadPreset(Activity activity) { // isPresetChanged = true; // new Preferences(activity).setLastPlayed(tag); // } // // public void load(int color, int colorDef, Activity activity) { // SoundHelper sound = new SoundHelper(); // sound.load(this, color, colorDef, activity); // } // // @Override // public String toString() { // Gson gson = new GsonBuilder() // .setPrettyPrinting() // .create(); // return gson.toJson(this); // } // } // // Path: app/src/main/java/com/bedrock/padder/helper/FileHelper.java // public static String PROJECT_LOCATION_PRESETS = Environment.getExternalStorageDirectory().getPath() + "/Tapad/presets"; // // Path: app/src/main/java/com/bedrock/padder/helper/WindowHelper.java // public static String getStringFromIdWithFallback(String id, Context context) { // try { // Class res = R.string.class; // Field field = res.getField(id); // return context.getResources().getString(field.getInt(null)); // } catch (Exception e) { // Log.e("getStringFromId", "Failure to get string from id [" + id + "]"); // return id; // } // //from : https://daniel-codes.blogspot.com/2009/12/dynamically-retrieving-resources-in.html // }
import android.content.Context; import com.bedrock.padder.model.preset.Preset; import static com.bedrock.padder.helper.FileHelper.PROJECT_LOCATION_PRESETS; import static com.bedrock.padder.helper.WindowHelper.getStringFromIdWithFallback;
package com.bedrock.padder.model.about; public class Bio { private String title; private String name; private String text; private String source; public Bio(String title, String name, String text, String source) { this.title = title; this.name = name; this.text = text; this.source = source; } public String getTitle() { return title; } public String getTitle(Context context) { return getStringFromIdWithFallback(getTitle(), context); }
// Path: app/src/main/java/com/bedrock/padder/model/preset/Preset.java // public class Preset { // // private String tag; // // private About about; // // private Boolean isGesture; // // private Integer soundCount; // // private Integer bpm; // // public Preset(String tag, About about, Boolean isGesture, Integer soundCount, Integer bpm) { // this.tag = tag; // this.about = about; // this.isGesture = isGesture; // this.soundCount = soundCount; // this.bpm = bpm; // } // // public String getTag() { // return tag; // } // // public Boolean isGesture() { // return isGesture; // } // // public Integer getSoundCount() { // return soundCount; // } // // public Integer getBpm() { // return bpm; // } // // public void setTag(String tag) { // this.tag = tag; // } // // public About getAbout() { // return about; // } // // public String getSound(int deckIndex, int padIndex, int gestureIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + getPadStringFromIndex(padIndex); // if (gestureIndex > 0) { // fileName += "_" + gestureIndex; // } // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // public String getSound(int deckIndex, int padIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + getPadStringFromIndex(padIndex); // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // public String getSound(int deckIndex, String padIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + padIndex; // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // private String getPadStringFromIndex(int padIndex) { // switch (padIndex) { // case 0: // return "00"; // case 1: // return "11"; // case 2: // return "12"; // case 3: // return "13"; // case 4: // return "14"; // case 5: // return "21"; // case 6: // return "22"; // case 7: // return "23"; // case 8: // return "24"; // case 9: // return "31"; // case 10: // return "32"; // case 11: // return "33"; // case 12: // return "34"; // case 13: // return "41"; // case 14: // return "42"; // case 15: // return "43"; // case 16: // return "44"; // default: // return null; // } // } // // public Boolean getInAppTutorialAvailable() { // return new File(PROJECT_LOCATION_PRESETS + "/" + getTag() + "/timing/timing.tpt").exists(); // } // // public void loadPreset(Activity activity) { // isPresetChanged = true; // new Preferences(activity).setLastPlayed(tag); // } // // public void load(int color, int colorDef, Activity activity) { // SoundHelper sound = new SoundHelper(); // sound.load(this, color, colorDef, activity); // } // // @Override // public String toString() { // Gson gson = new GsonBuilder() // .setPrettyPrinting() // .create(); // return gson.toJson(this); // } // } // // Path: app/src/main/java/com/bedrock/padder/helper/FileHelper.java // public static String PROJECT_LOCATION_PRESETS = Environment.getExternalStorageDirectory().getPath() + "/Tapad/presets"; // // Path: app/src/main/java/com/bedrock/padder/helper/WindowHelper.java // public static String getStringFromIdWithFallback(String id, Context context) { // try { // Class res = R.string.class; // Field field = res.getField(id); // return context.getResources().getString(field.getInt(null)); // } catch (Exception e) { // Log.e("getStringFromId", "Failure to get string from id [" + id + "]"); // return id; // } // //from : https://daniel-codes.blogspot.com/2009/12/dynamically-retrieving-resources-in.html // } // Path: app/src/main/java/com/bedrock/padder/model/about/Bio.java import android.content.Context; import com.bedrock.padder.model.preset.Preset; import static com.bedrock.padder.helper.FileHelper.PROJECT_LOCATION_PRESETS; import static com.bedrock.padder.helper.WindowHelper.getStringFromIdWithFallback; package com.bedrock.padder.model.about; public class Bio { private String title; private String name; private String text; private String source; public Bio(String title, String name, String text, String source) { this.title = title; this.name = name; this.text = text; this.source = source; } public String getTitle() { return title; } public String getTitle(Context context) { return getStringFromIdWithFallback(getTitle(), context); }
public String getImage(Preset preset) {
berict/Tapad
app/src/main/java/com/bedrock/padder/model/about/Bio.java
// Path: app/src/main/java/com/bedrock/padder/model/preset/Preset.java // public class Preset { // // private String tag; // // private About about; // // private Boolean isGesture; // // private Integer soundCount; // // private Integer bpm; // // public Preset(String tag, About about, Boolean isGesture, Integer soundCount, Integer bpm) { // this.tag = tag; // this.about = about; // this.isGesture = isGesture; // this.soundCount = soundCount; // this.bpm = bpm; // } // // public String getTag() { // return tag; // } // // public Boolean isGesture() { // return isGesture; // } // // public Integer getSoundCount() { // return soundCount; // } // // public Integer getBpm() { // return bpm; // } // // public void setTag(String tag) { // this.tag = tag; // } // // public About getAbout() { // return about; // } // // public String getSound(int deckIndex, int padIndex, int gestureIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + getPadStringFromIndex(padIndex); // if (gestureIndex > 0) { // fileName += "_" + gestureIndex; // } // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // public String getSound(int deckIndex, int padIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + getPadStringFromIndex(padIndex); // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // public String getSound(int deckIndex, String padIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + padIndex; // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // private String getPadStringFromIndex(int padIndex) { // switch (padIndex) { // case 0: // return "00"; // case 1: // return "11"; // case 2: // return "12"; // case 3: // return "13"; // case 4: // return "14"; // case 5: // return "21"; // case 6: // return "22"; // case 7: // return "23"; // case 8: // return "24"; // case 9: // return "31"; // case 10: // return "32"; // case 11: // return "33"; // case 12: // return "34"; // case 13: // return "41"; // case 14: // return "42"; // case 15: // return "43"; // case 16: // return "44"; // default: // return null; // } // } // // public Boolean getInAppTutorialAvailable() { // return new File(PROJECT_LOCATION_PRESETS + "/" + getTag() + "/timing/timing.tpt").exists(); // } // // public void loadPreset(Activity activity) { // isPresetChanged = true; // new Preferences(activity).setLastPlayed(tag); // } // // public void load(int color, int colorDef, Activity activity) { // SoundHelper sound = new SoundHelper(); // sound.load(this, color, colorDef, activity); // } // // @Override // public String toString() { // Gson gson = new GsonBuilder() // .setPrettyPrinting() // .create(); // return gson.toJson(this); // } // } // // Path: app/src/main/java/com/bedrock/padder/helper/FileHelper.java // public static String PROJECT_LOCATION_PRESETS = Environment.getExternalStorageDirectory().getPath() + "/Tapad/presets"; // // Path: app/src/main/java/com/bedrock/padder/helper/WindowHelper.java // public static String getStringFromIdWithFallback(String id, Context context) { // try { // Class res = R.string.class; // Field field = res.getField(id); // return context.getResources().getString(field.getInt(null)); // } catch (Exception e) { // Log.e("getStringFromId", "Failure to get string from id [" + id + "]"); // return id; // } // //from : https://daniel-codes.blogspot.com/2009/12/dynamically-retrieving-resources-in.html // }
import android.content.Context; import com.bedrock.padder.model.preset.Preset; import static com.bedrock.padder.helper.FileHelper.PROJECT_LOCATION_PRESETS; import static com.bedrock.padder.helper.WindowHelper.getStringFromIdWithFallback;
package com.bedrock.padder.model.about; public class Bio { private String title; private String name; private String text; private String source; public Bio(String title, String name, String text, String source) { this.title = title; this.name = name; this.text = text; this.source = source; } public String getTitle() { return title; } public String getTitle(Context context) { return getStringFromIdWithFallback(getTitle(), context); } public String getImage(Preset preset) { String tag = preset.getTag(); if (tag == null || tag.equals("about_bio_tapad")) { return tag; } else {
// Path: app/src/main/java/com/bedrock/padder/model/preset/Preset.java // public class Preset { // // private String tag; // // private About about; // // private Boolean isGesture; // // private Integer soundCount; // // private Integer bpm; // // public Preset(String tag, About about, Boolean isGesture, Integer soundCount, Integer bpm) { // this.tag = tag; // this.about = about; // this.isGesture = isGesture; // this.soundCount = soundCount; // this.bpm = bpm; // } // // public String getTag() { // return tag; // } // // public Boolean isGesture() { // return isGesture; // } // // public Integer getSoundCount() { // return soundCount; // } // // public Integer getBpm() { // return bpm; // } // // public void setTag(String tag) { // this.tag = tag; // } // // public About getAbout() { // return about; // } // // public String getSound(int deckIndex, int padIndex, int gestureIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + getPadStringFromIndex(padIndex); // if (gestureIndex > 0) { // fileName += "_" + gestureIndex; // } // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // public String getSound(int deckIndex, int padIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + getPadStringFromIndex(padIndex); // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // public String getSound(int deckIndex, String padIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + padIndex; // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // private String getPadStringFromIndex(int padIndex) { // switch (padIndex) { // case 0: // return "00"; // case 1: // return "11"; // case 2: // return "12"; // case 3: // return "13"; // case 4: // return "14"; // case 5: // return "21"; // case 6: // return "22"; // case 7: // return "23"; // case 8: // return "24"; // case 9: // return "31"; // case 10: // return "32"; // case 11: // return "33"; // case 12: // return "34"; // case 13: // return "41"; // case 14: // return "42"; // case 15: // return "43"; // case 16: // return "44"; // default: // return null; // } // } // // public Boolean getInAppTutorialAvailable() { // return new File(PROJECT_LOCATION_PRESETS + "/" + getTag() + "/timing/timing.tpt").exists(); // } // // public void loadPreset(Activity activity) { // isPresetChanged = true; // new Preferences(activity).setLastPlayed(tag); // } // // public void load(int color, int colorDef, Activity activity) { // SoundHelper sound = new SoundHelper(); // sound.load(this, color, colorDef, activity); // } // // @Override // public String toString() { // Gson gson = new GsonBuilder() // .setPrettyPrinting() // .create(); // return gson.toJson(this); // } // } // // Path: app/src/main/java/com/bedrock/padder/helper/FileHelper.java // public static String PROJECT_LOCATION_PRESETS = Environment.getExternalStorageDirectory().getPath() + "/Tapad/presets"; // // Path: app/src/main/java/com/bedrock/padder/helper/WindowHelper.java // public static String getStringFromIdWithFallback(String id, Context context) { // try { // Class res = R.string.class; // Field field = res.getField(id); // return context.getResources().getString(field.getInt(null)); // } catch (Exception e) { // Log.e("getStringFromId", "Failure to get string from id [" + id + "]"); // return id; // } // //from : https://daniel-codes.blogspot.com/2009/12/dynamically-retrieving-resources-in.html // } // Path: app/src/main/java/com/bedrock/padder/model/about/Bio.java import android.content.Context; import com.bedrock.padder.model.preset.Preset; import static com.bedrock.padder.helper.FileHelper.PROJECT_LOCATION_PRESETS; import static com.bedrock.padder.helper.WindowHelper.getStringFromIdWithFallback; package com.bedrock.padder.model.about; public class Bio { private String title; private String name; private String text; private String source; public Bio(String title, String name, String text, String source) { this.title = title; this.name = name; this.text = text; this.source = source; } public String getTitle() { return title; } public String getTitle(Context context) { return getStringFromIdWithFallback(getTitle(), context); } public String getImage(Preset preset) { String tag = preset.getTag(); if (tag == null || tag.equals("about_bio_tapad")) { return tag; } else {
return PROJECT_LOCATION_PRESETS + "/" + tag + "/about/artist_image";
berict/Tapad
app/src/main/java/com/bedrock/padder/model/about/Detail.java
// Path: app/src/main/java/com/bedrock/padder/helper/WindowHelper.java // @Nullable // public static String getStringFromId(String id, Context context) { // try { // Class res = R.string.class; // Field field = res.getField(id); // return context.getResources().getString(field.getInt(null)); // } catch (Exception e) { // Log.e("getStringFromId", "Failure to get string from id [" + id + "]"); // return null; // } // //from : https://daniel-codes.blogspot.com/2009/12/dynamically-retrieving-resources-in.html // } // // Path: app/src/main/java/com/bedrock/padder/helper/WindowHelper.java // public static String getStringFromIdWithFallback(String id, Context context) { // try { // Class res = R.string.class; // Field field = res.getField(id); // return context.getResources().getString(field.getInt(null)); // } catch (Exception e) { // Log.e("getStringFromId", "Failure to get string from id [" + id + "]"); // return id; // } // //from : https://daniel-codes.blogspot.com/2009/12/dynamically-retrieving-resources-in.html // }
import android.content.Context; import static com.bedrock.padder.helper.WindowHelper.getStringFromId; import static com.bedrock.padder.helper.WindowHelper.getStringFromIdWithFallback;
package com.bedrock.padder.model.about; public class Detail { private String title; private Item[] items; public Detail (String title, Item[] items) { this.title = title; this.items = items; } public String getTitle() { return title; } public String getTitle(Context context) {
// Path: app/src/main/java/com/bedrock/padder/helper/WindowHelper.java // @Nullable // public static String getStringFromId(String id, Context context) { // try { // Class res = R.string.class; // Field field = res.getField(id); // return context.getResources().getString(field.getInt(null)); // } catch (Exception e) { // Log.e("getStringFromId", "Failure to get string from id [" + id + "]"); // return null; // } // //from : https://daniel-codes.blogspot.com/2009/12/dynamically-retrieving-resources-in.html // } // // Path: app/src/main/java/com/bedrock/padder/helper/WindowHelper.java // public static String getStringFromIdWithFallback(String id, Context context) { // try { // Class res = R.string.class; // Field field = res.getField(id); // return context.getResources().getString(field.getInt(null)); // } catch (Exception e) { // Log.e("getStringFromId", "Failure to get string from id [" + id + "]"); // return id; // } // //from : https://daniel-codes.blogspot.com/2009/12/dynamically-retrieving-resources-in.html // } // Path: app/src/main/java/com/bedrock/padder/model/about/Detail.java import android.content.Context; import static com.bedrock.padder.helper.WindowHelper.getStringFromId; import static com.bedrock.padder.helper.WindowHelper.getStringFromIdWithFallback; package com.bedrock.padder.model.about; public class Detail { private String title; private Item[] items; public Detail (String title, Item[] items) { this.title = title; this.items = items; } public String getTitle() { return title; } public String getTitle(Context context) {
return getStringFromIdWithFallback(getTitle(), context);
berict/Tapad
app/src/main/java/com/bedrock/padder/model/about/Detail.java
// Path: app/src/main/java/com/bedrock/padder/helper/WindowHelper.java // @Nullable // public static String getStringFromId(String id, Context context) { // try { // Class res = R.string.class; // Field field = res.getField(id); // return context.getResources().getString(field.getInt(null)); // } catch (Exception e) { // Log.e("getStringFromId", "Failure to get string from id [" + id + "]"); // return null; // } // //from : https://daniel-codes.blogspot.com/2009/12/dynamically-retrieving-resources-in.html // } // // Path: app/src/main/java/com/bedrock/padder/helper/WindowHelper.java // public static String getStringFromIdWithFallback(String id, Context context) { // try { // Class res = R.string.class; // Field field = res.getField(id); // return context.getResources().getString(field.getInt(null)); // } catch (Exception e) { // Log.e("getStringFromId", "Failure to get string from id [" + id + "]"); // return id; // } // //from : https://daniel-codes.blogspot.com/2009/12/dynamically-retrieving-resources-in.html // }
import android.content.Context; import static com.bedrock.padder.helper.WindowHelper.getStringFromId; import static com.bedrock.padder.helper.WindowHelper.getStringFromIdWithFallback;
package com.bedrock.padder.model.about; public class Detail { private String title; private Item[] items; public Detail (String title, Item[] items) { this.title = title; this.items = items; } public String getTitle() { return title; } public String getTitle(Context context) { return getStringFromIdWithFallback(getTitle(), context); } public String getTitle(String prefix, Context context) {
// Path: app/src/main/java/com/bedrock/padder/helper/WindowHelper.java // @Nullable // public static String getStringFromId(String id, Context context) { // try { // Class res = R.string.class; // Field field = res.getField(id); // return context.getResources().getString(field.getInt(null)); // } catch (Exception e) { // Log.e("getStringFromId", "Failure to get string from id [" + id + "]"); // return null; // } // //from : https://daniel-codes.blogspot.com/2009/12/dynamically-retrieving-resources-in.html // } // // Path: app/src/main/java/com/bedrock/padder/helper/WindowHelper.java // public static String getStringFromIdWithFallback(String id, Context context) { // try { // Class res = R.string.class; // Field field = res.getField(id); // return context.getResources().getString(field.getInt(null)); // } catch (Exception e) { // Log.e("getStringFromId", "Failure to get string from id [" + id + "]"); // return id; // } // //from : https://daniel-codes.blogspot.com/2009/12/dynamically-retrieving-resources-in.html // } // Path: app/src/main/java/com/bedrock/padder/model/about/Detail.java import android.content.Context; import static com.bedrock.padder.helper.WindowHelper.getStringFromId; import static com.bedrock.padder.helper.WindowHelper.getStringFromIdWithFallback; package com.bedrock.padder.model.about; public class Detail { private String title; private Item[] items; public Detail (String title, Item[] items) { this.title = title; this.items = items; } public String getTitle() { return title; } public String getTitle(Context context) { return getStringFromIdWithFallback(getTitle(), context); } public String getTitle(String prefix, Context context) {
String res = getStringFromId(prefix, context);
berict/Tapad
app/src/main/java/com/bedrock/padder/helper/WindowHelper.java
// Path: app/src/main/java/com/bedrock/padder/model/preferences/Preferences.java // public static final String APPLICATION_ID = "com.bedrock.padder";
import android.app.Activity; import android.app.ActivityManager; import android.content.Context; import android.content.SharedPreferences; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; import android.graphics.Rect; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Handler; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; import android.util.DisplayMetrics; import android.util.Log; import android.view.Display; import android.view.MotionEvent; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.view.inputmethod.InputMethodManager; import android.widget.LinearLayout; import android.widget.RelativeLayout; import com.bedrock.padder.R; import java.io.IOException; import java.io.RandomAccessFile; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.regex.Matcher; import java.util.regex.Pattern; import static android.content.Context.MODE_PRIVATE; import static com.bedrock.padder.model.preferences.Preferences.APPLICATION_ID;
package com.bedrock.padder.helper; public class WindowHelper { public void setNavigationBar(int colorId, Activity activity) { if (Build.VERSION.SDK_INT >= 16) { if (colorId == R.color.transparent) { activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { Window w = activity.getWindow(); w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); } Log.i("WindowHelper", "Transparent navigation bar color applied."); } else { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { activity.getWindow().setNavigationBarColor(activity.getResources().getColor(colorId)); Log.i("WindowHelper", "Navigation bar color applied."); } } } else { Log.i("WindowHelper", "API doesn't match requirement. (API >= 16)"); } } public int getNavigationBar(final int id, final Activity activity) { /* Must be a parent view */
// Path: app/src/main/java/com/bedrock/padder/model/preferences/Preferences.java // public static final String APPLICATION_ID = "com.bedrock.padder"; // Path: app/src/main/java/com/bedrock/padder/helper/WindowHelper.java import android.app.Activity; import android.app.ActivityManager; import android.content.Context; import android.content.SharedPreferences; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; import android.graphics.Rect; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Handler; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; import android.util.DisplayMetrics; import android.util.Log; import android.view.Display; import android.view.MotionEvent; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.view.inputmethod.InputMethodManager; import android.widget.LinearLayout; import android.widget.RelativeLayout; import com.bedrock.padder.R; import java.io.IOException; import java.io.RandomAccessFile; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.regex.Matcher; import java.util.regex.Pattern; import static android.content.Context.MODE_PRIVATE; import static com.bedrock.padder.model.preferences.Preferences.APPLICATION_ID; package com.bedrock.padder.helper; public class WindowHelper { public void setNavigationBar(int colorId, Activity activity) { if (Build.VERSION.SDK_INT >= 16) { if (colorId == R.color.transparent) { activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { Window w = activity.getWindow(); w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); } Log.i("WindowHelper", "Transparent navigation bar color applied."); } else { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { activity.getWindow().setNavigationBarColor(activity.getResources().getColor(colorId)); Log.i("WindowHelper", "Navigation bar color applied."); } } } else { Log.i("WindowHelper", "API doesn't match requirement. (API >= 16)"); } } public int getNavigationBar(final int id, final Activity activity) { /* Must be a parent view */
final SharedPreferences prefs = activity.getSharedPreferences(APPLICATION_ID, MODE_PRIVATE);
berict/Tapad
app/src/main/java/com/bedrock/padder/model/about/About.java
// Path: app/src/main/java/com/bedrock/padder/model/preset/Preset.java // public class Preset { // // private String tag; // // private About about; // // private Boolean isGesture; // // private Integer soundCount; // // private Integer bpm; // // public Preset(String tag, About about, Boolean isGesture, Integer soundCount, Integer bpm) { // this.tag = tag; // this.about = about; // this.isGesture = isGesture; // this.soundCount = soundCount; // this.bpm = bpm; // } // // public String getTag() { // return tag; // } // // public Boolean isGesture() { // return isGesture; // } // // public Integer getSoundCount() { // return soundCount; // } // // public Integer getBpm() { // return bpm; // } // // public void setTag(String tag) { // this.tag = tag; // } // // public About getAbout() { // return about; // } // // public String getSound(int deckIndex, int padIndex, int gestureIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + getPadStringFromIndex(padIndex); // if (gestureIndex > 0) { // fileName += "_" + gestureIndex; // } // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // public String getSound(int deckIndex, int padIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + getPadStringFromIndex(padIndex); // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // public String getSound(int deckIndex, String padIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + padIndex; // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // private String getPadStringFromIndex(int padIndex) { // switch (padIndex) { // case 0: // return "00"; // case 1: // return "11"; // case 2: // return "12"; // case 3: // return "13"; // case 4: // return "14"; // case 5: // return "21"; // case 6: // return "22"; // case 7: // return "23"; // case 8: // return "24"; // case 9: // return "31"; // case 10: // return "32"; // case 11: // return "33"; // case 12: // return "34"; // case 13: // return "41"; // case 14: // return "42"; // case 15: // return "43"; // case 16: // return "44"; // default: // return null; // } // } // // public Boolean getInAppTutorialAvailable() { // return new File(PROJECT_LOCATION_PRESETS + "/" + getTag() + "/timing/timing.tpt").exists(); // } // // public void loadPreset(Activity activity) { // isPresetChanged = true; // new Preferences(activity).setLastPlayed(tag); // } // // public void load(int color, int colorDef, Activity activity) { // SoundHelper sound = new SoundHelper(); // sound.load(this, color, colorDef, activity); // } // // @Override // public String toString() { // Gson gson = new GsonBuilder() // .setPrettyPrinting() // .create(); // return gson.toJson(this); // } // } // // Path: app/src/main/java/com/bedrock/padder/helper/FileHelper.java // public static String PROJECT_LOCATION_PRESETS = Environment.getExternalStorageDirectory().getPath() + "/Tapad/presets"; // // Path: app/src/main/java/com/bedrock/padder/helper/WindowHelper.java // public static String getStringFromIdWithFallback(String id, Context context) { // try { // Class res = R.string.class; // Field field = res.getField(id); // return context.getResources().getString(field.getInt(null)); // } catch (Exception e) { // Log.e("getStringFromId", "Failure to get string from id [" + id + "]"); // return id; // } // //from : https://daniel-codes.blogspot.com/2009/12/dynamically-retrieving-resources-in.html // }
import android.content.Context; import android.graphics.Color; import com.bedrock.padder.model.preset.Preset; import static com.bedrock.padder.helper.FileHelper.PROJECT_LOCATION_PRESETS; import static com.bedrock.padder.helper.WindowHelper.getStringFromIdWithFallback;
this.color = color; this.bio = bio; this.details = details; } public About(String songName, String songArtist, String color, Bio bio, Detail[] details) { this.songName = songName; this.songArtist = songArtist; this.color = color; this.bio = bio; this.details = details; } public String getTitle() { return songName + " - " + songArtist; } public String getTitle(Context context) { return getSongName(context) + " - " + getSongArtist(context); } public String getSongName() { return songName; } public String getSongName(Context context) {
// Path: app/src/main/java/com/bedrock/padder/model/preset/Preset.java // public class Preset { // // private String tag; // // private About about; // // private Boolean isGesture; // // private Integer soundCount; // // private Integer bpm; // // public Preset(String tag, About about, Boolean isGesture, Integer soundCount, Integer bpm) { // this.tag = tag; // this.about = about; // this.isGesture = isGesture; // this.soundCount = soundCount; // this.bpm = bpm; // } // // public String getTag() { // return tag; // } // // public Boolean isGesture() { // return isGesture; // } // // public Integer getSoundCount() { // return soundCount; // } // // public Integer getBpm() { // return bpm; // } // // public void setTag(String tag) { // this.tag = tag; // } // // public About getAbout() { // return about; // } // // public String getSound(int deckIndex, int padIndex, int gestureIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + getPadStringFromIndex(padIndex); // if (gestureIndex > 0) { // fileName += "_" + gestureIndex; // } // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // public String getSound(int deckIndex, int padIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + getPadStringFromIndex(padIndex); // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // public String getSound(int deckIndex, String padIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + padIndex; // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // private String getPadStringFromIndex(int padIndex) { // switch (padIndex) { // case 0: // return "00"; // case 1: // return "11"; // case 2: // return "12"; // case 3: // return "13"; // case 4: // return "14"; // case 5: // return "21"; // case 6: // return "22"; // case 7: // return "23"; // case 8: // return "24"; // case 9: // return "31"; // case 10: // return "32"; // case 11: // return "33"; // case 12: // return "34"; // case 13: // return "41"; // case 14: // return "42"; // case 15: // return "43"; // case 16: // return "44"; // default: // return null; // } // } // // public Boolean getInAppTutorialAvailable() { // return new File(PROJECT_LOCATION_PRESETS + "/" + getTag() + "/timing/timing.tpt").exists(); // } // // public void loadPreset(Activity activity) { // isPresetChanged = true; // new Preferences(activity).setLastPlayed(tag); // } // // public void load(int color, int colorDef, Activity activity) { // SoundHelper sound = new SoundHelper(); // sound.load(this, color, colorDef, activity); // } // // @Override // public String toString() { // Gson gson = new GsonBuilder() // .setPrettyPrinting() // .create(); // return gson.toJson(this); // } // } // // Path: app/src/main/java/com/bedrock/padder/helper/FileHelper.java // public static String PROJECT_LOCATION_PRESETS = Environment.getExternalStorageDirectory().getPath() + "/Tapad/presets"; // // Path: app/src/main/java/com/bedrock/padder/helper/WindowHelper.java // public static String getStringFromIdWithFallback(String id, Context context) { // try { // Class res = R.string.class; // Field field = res.getField(id); // return context.getResources().getString(field.getInt(null)); // } catch (Exception e) { // Log.e("getStringFromId", "Failure to get string from id [" + id + "]"); // return id; // } // //from : https://daniel-codes.blogspot.com/2009/12/dynamically-retrieving-resources-in.html // } // Path: app/src/main/java/com/bedrock/padder/model/about/About.java import android.content.Context; import android.graphics.Color; import com.bedrock.padder.model.preset.Preset; import static com.bedrock.padder.helper.FileHelper.PROJECT_LOCATION_PRESETS; import static com.bedrock.padder.helper.WindowHelper.getStringFromIdWithFallback; this.color = color; this.bio = bio; this.details = details; } public About(String songName, String songArtist, String color, Bio bio, Detail[] details) { this.songName = songName; this.songArtist = songArtist; this.color = color; this.bio = bio; this.details = details; } public String getTitle() { return songName + " - " + songArtist; } public String getTitle(Context context) { return getSongName(context) + " - " + getSongArtist(context); } public String getSongName() { return songName; } public String getSongName(Context context) {
return getStringFromIdWithFallback(getSongName(), context);
berict/Tapad
app/src/main/java/com/bedrock/padder/model/about/About.java
// Path: app/src/main/java/com/bedrock/padder/model/preset/Preset.java // public class Preset { // // private String tag; // // private About about; // // private Boolean isGesture; // // private Integer soundCount; // // private Integer bpm; // // public Preset(String tag, About about, Boolean isGesture, Integer soundCount, Integer bpm) { // this.tag = tag; // this.about = about; // this.isGesture = isGesture; // this.soundCount = soundCount; // this.bpm = bpm; // } // // public String getTag() { // return tag; // } // // public Boolean isGesture() { // return isGesture; // } // // public Integer getSoundCount() { // return soundCount; // } // // public Integer getBpm() { // return bpm; // } // // public void setTag(String tag) { // this.tag = tag; // } // // public About getAbout() { // return about; // } // // public String getSound(int deckIndex, int padIndex, int gestureIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + getPadStringFromIndex(padIndex); // if (gestureIndex > 0) { // fileName += "_" + gestureIndex; // } // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // public String getSound(int deckIndex, int padIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + getPadStringFromIndex(padIndex); // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // public String getSound(int deckIndex, String padIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + padIndex; // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // private String getPadStringFromIndex(int padIndex) { // switch (padIndex) { // case 0: // return "00"; // case 1: // return "11"; // case 2: // return "12"; // case 3: // return "13"; // case 4: // return "14"; // case 5: // return "21"; // case 6: // return "22"; // case 7: // return "23"; // case 8: // return "24"; // case 9: // return "31"; // case 10: // return "32"; // case 11: // return "33"; // case 12: // return "34"; // case 13: // return "41"; // case 14: // return "42"; // case 15: // return "43"; // case 16: // return "44"; // default: // return null; // } // } // // public Boolean getInAppTutorialAvailable() { // return new File(PROJECT_LOCATION_PRESETS + "/" + getTag() + "/timing/timing.tpt").exists(); // } // // public void loadPreset(Activity activity) { // isPresetChanged = true; // new Preferences(activity).setLastPlayed(tag); // } // // public void load(int color, int colorDef, Activity activity) { // SoundHelper sound = new SoundHelper(); // sound.load(this, color, colorDef, activity); // } // // @Override // public String toString() { // Gson gson = new GsonBuilder() // .setPrettyPrinting() // .create(); // return gson.toJson(this); // } // } // // Path: app/src/main/java/com/bedrock/padder/helper/FileHelper.java // public static String PROJECT_LOCATION_PRESETS = Environment.getExternalStorageDirectory().getPath() + "/Tapad/presets"; // // Path: app/src/main/java/com/bedrock/padder/helper/WindowHelper.java // public static String getStringFromIdWithFallback(String id, Context context) { // try { // Class res = R.string.class; // Field field = res.getField(id); // return context.getResources().getString(field.getInt(null)); // } catch (Exception e) { // Log.e("getStringFromId", "Failure to get string from id [" + id + "]"); // return id; // } // //from : https://daniel-codes.blogspot.com/2009/12/dynamically-retrieving-resources-in.html // }
import android.content.Context; import android.graphics.Color; import com.bedrock.padder.model.preset.Preset; import static com.bedrock.padder.helper.FileHelper.PROJECT_LOCATION_PRESETS; import static com.bedrock.padder.helper.WindowHelper.getStringFromIdWithFallback;
this.songArtist = songArtist; this.color = color; this.bio = bio; this.details = details; } public String getTitle() { return songName + " - " + songArtist; } public String getTitle(Context context) { return getSongName(context) + " - " + getSongArtist(context); } public String getSongName() { return songName; } public String getSongName(Context context) { return getStringFromIdWithFallback(getSongName(), context); } public String getSongArtist() { return songArtist; } public String getSongArtist(Context context) { return getStringFromIdWithFallback(getSongArtist(), context); }
// Path: app/src/main/java/com/bedrock/padder/model/preset/Preset.java // public class Preset { // // private String tag; // // private About about; // // private Boolean isGesture; // // private Integer soundCount; // // private Integer bpm; // // public Preset(String tag, About about, Boolean isGesture, Integer soundCount, Integer bpm) { // this.tag = tag; // this.about = about; // this.isGesture = isGesture; // this.soundCount = soundCount; // this.bpm = bpm; // } // // public String getTag() { // return tag; // } // // public Boolean isGesture() { // return isGesture; // } // // public Integer getSoundCount() { // return soundCount; // } // // public Integer getBpm() { // return bpm; // } // // public void setTag(String tag) { // this.tag = tag; // } // // public About getAbout() { // return about; // } // // public String getSound(int deckIndex, int padIndex, int gestureIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + getPadStringFromIndex(padIndex); // if (gestureIndex > 0) { // fileName += "_" + gestureIndex; // } // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // public String getSound(int deckIndex, int padIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + getPadStringFromIndex(padIndex); // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // public String getSound(int deckIndex, String padIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + padIndex; // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // private String getPadStringFromIndex(int padIndex) { // switch (padIndex) { // case 0: // return "00"; // case 1: // return "11"; // case 2: // return "12"; // case 3: // return "13"; // case 4: // return "14"; // case 5: // return "21"; // case 6: // return "22"; // case 7: // return "23"; // case 8: // return "24"; // case 9: // return "31"; // case 10: // return "32"; // case 11: // return "33"; // case 12: // return "34"; // case 13: // return "41"; // case 14: // return "42"; // case 15: // return "43"; // case 16: // return "44"; // default: // return null; // } // } // // public Boolean getInAppTutorialAvailable() { // return new File(PROJECT_LOCATION_PRESETS + "/" + getTag() + "/timing/timing.tpt").exists(); // } // // public void loadPreset(Activity activity) { // isPresetChanged = true; // new Preferences(activity).setLastPlayed(tag); // } // // public void load(int color, int colorDef, Activity activity) { // SoundHelper sound = new SoundHelper(); // sound.load(this, color, colorDef, activity); // } // // @Override // public String toString() { // Gson gson = new GsonBuilder() // .setPrettyPrinting() // .create(); // return gson.toJson(this); // } // } // // Path: app/src/main/java/com/bedrock/padder/helper/FileHelper.java // public static String PROJECT_LOCATION_PRESETS = Environment.getExternalStorageDirectory().getPath() + "/Tapad/presets"; // // Path: app/src/main/java/com/bedrock/padder/helper/WindowHelper.java // public static String getStringFromIdWithFallback(String id, Context context) { // try { // Class res = R.string.class; // Field field = res.getField(id); // return context.getResources().getString(field.getInt(null)); // } catch (Exception e) { // Log.e("getStringFromId", "Failure to get string from id [" + id + "]"); // return id; // } // //from : https://daniel-codes.blogspot.com/2009/12/dynamically-retrieving-resources-in.html // } // Path: app/src/main/java/com/bedrock/padder/model/about/About.java import android.content.Context; import android.graphics.Color; import com.bedrock.padder.model.preset.Preset; import static com.bedrock.padder.helper.FileHelper.PROJECT_LOCATION_PRESETS; import static com.bedrock.padder.helper.WindowHelper.getStringFromIdWithFallback; this.songArtist = songArtist; this.color = color; this.bio = bio; this.details = details; } public String getTitle() { return songName + " - " + songArtist; } public String getTitle(Context context) { return getSongName(context) + " - " + getSongArtist(context); } public String getSongName() { return songName; } public String getSongName(Context context) { return getStringFromIdWithFallback(getSongName(), context); } public String getSongArtist() { return songArtist; } public String getSongArtist(Context context) { return getStringFromIdWithFallback(getSongArtist(), context); }
public String getImage(Preset preset) {
berict/Tapad
app/src/main/java/com/bedrock/padder/model/about/About.java
// Path: app/src/main/java/com/bedrock/padder/model/preset/Preset.java // public class Preset { // // private String tag; // // private About about; // // private Boolean isGesture; // // private Integer soundCount; // // private Integer bpm; // // public Preset(String tag, About about, Boolean isGesture, Integer soundCount, Integer bpm) { // this.tag = tag; // this.about = about; // this.isGesture = isGesture; // this.soundCount = soundCount; // this.bpm = bpm; // } // // public String getTag() { // return tag; // } // // public Boolean isGesture() { // return isGesture; // } // // public Integer getSoundCount() { // return soundCount; // } // // public Integer getBpm() { // return bpm; // } // // public void setTag(String tag) { // this.tag = tag; // } // // public About getAbout() { // return about; // } // // public String getSound(int deckIndex, int padIndex, int gestureIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + getPadStringFromIndex(padIndex); // if (gestureIndex > 0) { // fileName += "_" + gestureIndex; // } // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // public String getSound(int deckIndex, int padIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + getPadStringFromIndex(padIndex); // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // public String getSound(int deckIndex, String padIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + padIndex; // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // private String getPadStringFromIndex(int padIndex) { // switch (padIndex) { // case 0: // return "00"; // case 1: // return "11"; // case 2: // return "12"; // case 3: // return "13"; // case 4: // return "14"; // case 5: // return "21"; // case 6: // return "22"; // case 7: // return "23"; // case 8: // return "24"; // case 9: // return "31"; // case 10: // return "32"; // case 11: // return "33"; // case 12: // return "34"; // case 13: // return "41"; // case 14: // return "42"; // case 15: // return "43"; // case 16: // return "44"; // default: // return null; // } // } // // public Boolean getInAppTutorialAvailable() { // return new File(PROJECT_LOCATION_PRESETS + "/" + getTag() + "/timing/timing.tpt").exists(); // } // // public void loadPreset(Activity activity) { // isPresetChanged = true; // new Preferences(activity).setLastPlayed(tag); // } // // public void load(int color, int colorDef, Activity activity) { // SoundHelper sound = new SoundHelper(); // sound.load(this, color, colorDef, activity); // } // // @Override // public String toString() { // Gson gson = new GsonBuilder() // .setPrettyPrinting() // .create(); // return gson.toJson(this); // } // } // // Path: app/src/main/java/com/bedrock/padder/helper/FileHelper.java // public static String PROJECT_LOCATION_PRESETS = Environment.getExternalStorageDirectory().getPath() + "/Tapad/presets"; // // Path: app/src/main/java/com/bedrock/padder/helper/WindowHelper.java // public static String getStringFromIdWithFallback(String id, Context context) { // try { // Class res = R.string.class; // Field field = res.getField(id); // return context.getResources().getString(field.getInt(null)); // } catch (Exception e) { // Log.e("getStringFromId", "Failure to get string from id [" + id + "]"); // return id; // } // //from : https://daniel-codes.blogspot.com/2009/12/dynamically-retrieving-resources-in.html // }
import android.content.Context; import android.graphics.Color; import com.bedrock.padder.model.preset.Preset; import static com.bedrock.padder.helper.FileHelper.PROJECT_LOCATION_PRESETS; import static com.bedrock.padder.helper.WindowHelper.getStringFromIdWithFallback;
} public String getTitle() { return songName + " - " + songArtist; } public String getTitle(Context context) { return getSongName(context) + " - " + getSongArtist(context); } public String getSongName() { return songName; } public String getSongName(Context context) { return getStringFromIdWithFallback(getSongName(), context); } public String getSongArtist() { return songArtist; } public String getSongArtist(Context context) { return getStringFromIdWithFallback(getSongArtist(), context); } public String getImage(Preset preset) { String tag = preset.getTag(); if (presetArtist != null) { // normal preset
// Path: app/src/main/java/com/bedrock/padder/model/preset/Preset.java // public class Preset { // // private String tag; // // private About about; // // private Boolean isGesture; // // private Integer soundCount; // // private Integer bpm; // // public Preset(String tag, About about, Boolean isGesture, Integer soundCount, Integer bpm) { // this.tag = tag; // this.about = about; // this.isGesture = isGesture; // this.soundCount = soundCount; // this.bpm = bpm; // } // // public String getTag() { // return tag; // } // // public Boolean isGesture() { // return isGesture; // } // // public Integer getSoundCount() { // return soundCount; // } // // public Integer getBpm() { // return bpm; // } // // public void setTag(String tag) { // this.tag = tag; // } // // public About getAbout() { // return about; // } // // public String getSound(int deckIndex, int padIndex, int gestureIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + getPadStringFromIndex(padIndex); // if (gestureIndex > 0) { // fileName += "_" + gestureIndex; // } // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // public String getSound(int deckIndex, int padIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + getPadStringFromIndex(padIndex); // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // public String getSound(int deckIndex, String padIndex) { // String fileName = PROJECT_LOCATION_PRESETS + "/" // + tag // + "/sounds/sound" // + "_" + (deckIndex + 1) // + "_" + padIndex; // File sound = new File(fileName); // if (sound.exists()) { // return fileName; // } else { // return null; // } // } // // private String getPadStringFromIndex(int padIndex) { // switch (padIndex) { // case 0: // return "00"; // case 1: // return "11"; // case 2: // return "12"; // case 3: // return "13"; // case 4: // return "14"; // case 5: // return "21"; // case 6: // return "22"; // case 7: // return "23"; // case 8: // return "24"; // case 9: // return "31"; // case 10: // return "32"; // case 11: // return "33"; // case 12: // return "34"; // case 13: // return "41"; // case 14: // return "42"; // case 15: // return "43"; // case 16: // return "44"; // default: // return null; // } // } // // public Boolean getInAppTutorialAvailable() { // return new File(PROJECT_LOCATION_PRESETS + "/" + getTag() + "/timing/timing.tpt").exists(); // } // // public void loadPreset(Activity activity) { // isPresetChanged = true; // new Preferences(activity).setLastPlayed(tag); // } // // public void load(int color, int colorDef, Activity activity) { // SoundHelper sound = new SoundHelper(); // sound.load(this, color, colorDef, activity); // } // // @Override // public String toString() { // Gson gson = new GsonBuilder() // .setPrettyPrinting() // .create(); // return gson.toJson(this); // } // } // // Path: app/src/main/java/com/bedrock/padder/helper/FileHelper.java // public static String PROJECT_LOCATION_PRESETS = Environment.getExternalStorageDirectory().getPath() + "/Tapad/presets"; // // Path: app/src/main/java/com/bedrock/padder/helper/WindowHelper.java // public static String getStringFromIdWithFallback(String id, Context context) { // try { // Class res = R.string.class; // Field field = res.getField(id); // return context.getResources().getString(field.getInt(null)); // } catch (Exception e) { // Log.e("getStringFromId", "Failure to get string from id [" + id + "]"); // return id; // } // //from : https://daniel-codes.blogspot.com/2009/12/dynamically-retrieving-resources-in.html // } // Path: app/src/main/java/com/bedrock/padder/model/about/About.java import android.content.Context; import android.graphics.Color; import com.bedrock.padder.model.preset.Preset; import static com.bedrock.padder.helper.FileHelper.PROJECT_LOCATION_PRESETS; import static com.bedrock.padder.helper.WindowHelper.getStringFromIdWithFallback; } public String getTitle() { return songName + " - " + songArtist; } public String getTitle(Context context) { return getSongName(context) + " - " + getSongArtist(context); } public String getSongName() { return songName; } public String getSongName(Context context) { return getStringFromIdWithFallback(getSongName(), context); } public String getSongArtist() { return songArtist; } public String getSongArtist(Context context) { return getStringFromIdWithFallback(getSongArtist(), context); } public String getImage(Preset preset) { String tag = preset.getTag(); if (presetArtist != null) { // normal preset
return PROJECT_LOCATION_PRESETS + "/" + tag + "/about/album_art";
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/ScopingTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java // public interface HasServices // extends ScopeKey { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithOnlyParentServices.java // public abstract class TestKeyWithOnlyParentServices extends TestKey implements HasParentServices { // private final List<String> parentScopes; // // public TestKeyWithOnlyParentServices(String name, List<String> parentScopes) { // super(name); // this.parentScopes = parentScopes; // } // // @Nonnull // @Override // public List<String> getParentScopes() { // return parentScopes; // } // }
import android.app.Activity; import android.os.Parcel; import com.zhuinden.simplestack.helpers.HasServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices; import com.zhuinden.statebundle.StateBundle; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static org.assertj.core.api.Assertions.assertThat;
stateBundle.putInt("blah", 5); return stateBundle; } @Override public void fromBundle(@Nullable StateBundle bundle) { if(bundle != null) { blah = bundle.getInt("blah"); } } @Override public void onServiceRegistered() { didServiceRegister = true; } @Override public void onServiceUnregistered() { didServiceUnregister = true; } } StateChanger stateChanger = new StateChanger() { @Override public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) { completionCallback.stateChangeComplete(); } }; private static class TestKeyWithScope
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java // public interface HasServices // extends ScopeKey { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithOnlyParentServices.java // public abstract class TestKeyWithOnlyParentServices extends TestKey implements HasParentServices { // private final List<String> parentScopes; // // public TestKeyWithOnlyParentServices(String name, List<String> parentScopes) { // super(name); // this.parentScopes = parentScopes; // } // // @Nonnull // @Override // public List<String> getParentScopes() { // return parentScopes; // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/ScopingTest.java import android.app.Activity; import android.os.Parcel; import com.zhuinden.simplestack.helpers.HasServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices; import com.zhuinden.statebundle.StateBundle; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static org.assertj.core.api.Assertions.assertThat; stateBundle.putInt("blah", 5); return stateBundle; } @Override public void fromBundle(@Nullable StateBundle bundle) { if(bundle != null) { blah = bundle.getInt("blah"); } } @Override public void onServiceRegistered() { didServiceRegister = true; } @Override public void onServiceUnregistered() { didServiceUnregister = true; } } StateChanger stateChanger = new StateChanger() { @Override public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) { completionCallback.stateChangeComplete(); } }; private static class TestKeyWithScope
extends TestKey
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/ScopingTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java // public interface HasServices // extends ScopeKey { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithOnlyParentServices.java // public abstract class TestKeyWithOnlyParentServices extends TestKey implements HasParentServices { // private final List<String> parentScopes; // // public TestKeyWithOnlyParentServices(String name, List<String> parentScopes) { // super(name); // this.parentScopes = parentScopes; // } // // @Nonnull // @Override // public List<String> getParentScopes() { // return parentScopes; // } // }
import android.app.Activity; import android.os.Parcel; import com.zhuinden.simplestack.helpers.HasServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices; import com.zhuinden.statebundle.StateBundle; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static org.assertj.core.api.Assertions.assertThat;
return stateBundle; } @Override public void fromBundle(@Nullable StateBundle bundle) { if(bundle != null) { blah = bundle.getInt("blah"); } } @Override public void onServiceRegistered() { didServiceRegister = true; } @Override public void onServiceUnregistered() { didServiceUnregister = true; } } StateChanger stateChanger = new StateChanger() { @Override public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) { completionCallback.stateChangeComplete(); } }; private static class TestKeyWithScope extends TestKey
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java // public interface HasServices // extends ScopeKey { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithOnlyParentServices.java // public abstract class TestKeyWithOnlyParentServices extends TestKey implements HasParentServices { // private final List<String> parentScopes; // // public TestKeyWithOnlyParentServices(String name, List<String> parentScopes) { // super(name); // this.parentScopes = parentScopes; // } // // @Nonnull // @Override // public List<String> getParentScopes() { // return parentScopes; // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/ScopingTest.java import android.app.Activity; import android.os.Parcel; import com.zhuinden.simplestack.helpers.HasServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices; import com.zhuinden.statebundle.StateBundle; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static org.assertj.core.api.Assertions.assertThat; return stateBundle; } @Override public void fromBundle(@Nullable StateBundle bundle) { if(bundle != null) { blah = bundle.getInt("blah"); } } @Override public void onServiceRegistered() { didServiceRegister = true; } @Override public void onServiceUnregistered() { didServiceUnregister = true; } } StateChanger stateChanger = new StateChanger() { @Override public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) { completionCallback.stateChangeComplete(); } }; private static class TestKeyWithScope extends TestKey
implements ScopeKey, HasServices {
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/ScopingTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java // public interface HasServices // extends ScopeKey { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithOnlyParentServices.java // public abstract class TestKeyWithOnlyParentServices extends TestKey implements HasParentServices { // private final List<String> parentScopes; // // public TestKeyWithOnlyParentServices(String name, List<String> parentScopes) { // super(name); // this.parentScopes = parentScopes; // } // // @Nonnull // @Override // public List<String> getParentScopes() { // return parentScopes; // } // }
import android.app.Activity; import android.os.Parcel; import com.zhuinden.simplestack.helpers.HasServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices; import com.zhuinden.statebundle.StateBundle; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static org.assertj.core.api.Assertions.assertThat;
return new TestKeyWithScope(in); } @Override public TestKeyWithScope[] newArray(int size) { return new TestKeyWithScope[size]; } }; } private TestKey testKey1 = new TestKey("hello"); private TestKeyWithScope testKey2 = new TestKeyWithScope("world"); private TestKey testKey3 = new TestKey("!"); @Test public void scopedServicesShouldNotBeNull() { Backstack backstack = new Backstack(); try { backstack.setScopedServices(null); Assert.fail(); } catch(IllegalArgumentException e) { // OK! } } @Test public void scopedServicesCanBeSetBeforeInitialStateChange() { Backstack backstack = new Backstack(); backstack.setup(History.of(testKey1));
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java // public interface HasServices // extends ScopeKey { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithOnlyParentServices.java // public abstract class TestKeyWithOnlyParentServices extends TestKey implements HasParentServices { // private final List<String> parentScopes; // // public TestKeyWithOnlyParentServices(String name, List<String> parentScopes) { // super(name); // this.parentScopes = parentScopes; // } // // @Nonnull // @Override // public List<String> getParentScopes() { // return parentScopes; // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/ScopingTest.java import android.app.Activity; import android.os.Parcel; import com.zhuinden.simplestack.helpers.HasServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices; import com.zhuinden.statebundle.StateBundle; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static org.assertj.core.api.Assertions.assertThat; return new TestKeyWithScope(in); } @Override public TestKeyWithScope[] newArray(int size) { return new TestKeyWithScope[size]; } }; } private TestKey testKey1 = new TestKey("hello"); private TestKeyWithScope testKey2 = new TestKeyWithScope("world"); private TestKey testKey3 = new TestKey("!"); @Test public void scopedServicesShouldNotBeNull() { Backstack backstack = new Backstack(); try { backstack.setScopedServices(null); Assert.fail(); } catch(IllegalArgumentException e) { // OK! } } @Test public void scopedServicesCanBeSetBeforeInitialStateChange() { Backstack backstack = new Backstack(); backstack.setup(History.of(testKey1));
backstack.setScopedServices(new ServiceProvider());
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/ScopingTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java // public interface HasServices // extends ScopeKey { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithOnlyParentServices.java // public abstract class TestKeyWithOnlyParentServices extends TestKey implements HasParentServices { // private final List<String> parentScopes; // // public TestKeyWithOnlyParentServices(String name, List<String> parentScopes) { // super(name); // this.parentScopes = parentScopes; // } // // @Nonnull // @Override // public List<String> getParentScopes() { // return parentScopes; // } // }
import android.app.Activity; import android.os.Parcel; import com.zhuinden.simplestack.helpers.HasServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices; import com.zhuinden.statebundle.StateBundle; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static org.assertj.core.api.Assertions.assertThat;
} @Test public void navigationIsPossibleAndEnqueuedDuringActivationDispatch() { final TestKey destination = new TestKey("destination"); Backstack backstack = new Backstack(); backstack.setScopedServices(new ServiceProvider()); class MyService implements ScopedServices.Activated { private final Backstack backstack; public MyService(Backstack backstack) { this.backstack = backstack; } @Override public void onServiceActive() { backstack.setHistory(History.of(destination), StateChange.REPLACE); } @Override public void onServiceInactive() { } } final MyService service = new MyService(backstack);
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java // public interface HasServices // extends ScopeKey { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithOnlyParentServices.java // public abstract class TestKeyWithOnlyParentServices extends TestKey implements HasParentServices { // private final List<String> parentScopes; // // public TestKeyWithOnlyParentServices(String name, List<String> parentScopes) { // super(name); // this.parentScopes = parentScopes; // } // // @Nonnull // @Override // public List<String> getParentScopes() { // return parentScopes; // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/ScopingTest.java import android.app.Activity; import android.os.Parcel; import com.zhuinden.simplestack.helpers.HasServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices; import com.zhuinden.statebundle.StateBundle; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static org.assertj.core.api.Assertions.assertThat; } @Test public void navigationIsPossibleAndEnqueuedDuringActivationDispatch() { final TestKey destination = new TestKey("destination"); Backstack backstack = new Backstack(); backstack.setScopedServices(new ServiceProvider()); class MyService implements ScopedServices.Activated { private final Backstack backstack; public MyService(Backstack backstack) { this.backstack = backstack; } @Override public void onServiceActive() { backstack.setHistory(History.of(destination), StateChange.REPLACE); } @Override public void onServiceInactive() { } } final MyService service = new MyService(backstack);
TestKeyWithOnlyParentServices beep = new TestKeyWithOnlyParentServices("beep",
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/ReentranceTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // }
import javax.annotation.Nonnull; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Fail.fail; import static org.mockito.MockitoAnnotations.initMocks; import android.os.Parcelable; import com.zhuinden.simplestack.helpers.TestKey; import org.junit.Before; import org.junit.Test; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.concurrent.atomic.AtomicInteger;
flow = new Backstack(); flow.setup(History.single(new Catalog())); flow.setStateChanger(new StateChanger() { @Override public void handleStateChange(@Nonnull StateChange traversal, @Nonnull StateChanger.Callback callback) { lastCallback = callback; flow.removeStateChanger(); flow.goTo(new Loading()); } }); verifyHistory(flow.getHistory(), new Catalog()); flow.setStateChanger(new StateChanger() { @Override public void handleStateChange(@Nonnull StateChange traversal, @Nonnull StateChanger.Callback callback) { secondDispatcherCount.incrementAndGet(); callback.stateChangeComplete(); } }); assertThat(secondDispatcherCount.get()).isZero(); lastCallback.stateChangeComplete(); assertThat(secondDispatcherCount.get()).isEqualTo(1); verifyHistory(flow.getHistory(), new Loading(), new Catalog()); } static class Catalog
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/ReentranceTest.java import javax.annotation.Nonnull; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Fail.fail; import static org.mockito.MockitoAnnotations.initMocks; import android.os.Parcelable; import com.zhuinden.simplestack.helpers.TestKey; import org.junit.Before; import org.junit.Test; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; flow = new Backstack(); flow.setup(History.single(new Catalog())); flow.setStateChanger(new StateChanger() { @Override public void handleStateChange(@Nonnull StateChange traversal, @Nonnull StateChanger.Callback callback) { lastCallback = callback; flow.removeStateChanger(); flow.goTo(new Loading()); } }); verifyHistory(flow.getHistory(), new Catalog()); flow.setStateChanger(new StateChanger() { @Override public void handleStateChange(@Nonnull StateChange traversal, @Nonnull StateChanger.Callback callback) { secondDispatcherCount.incrementAndGet(); callback.stateChangeComplete(); } }); assertThat(secondDispatcherCount.get()).isZero(); lastCallback.stateChangeComplete(); assertThat(secondDispatcherCount.get()).isEqualTo(1); verifyHistory(flow.getHistory(), new Loading(), new Catalog()); } static class Catalog
extends TestKey {
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java
// Path: simple-stack/src/main/java/com/zhuinden/simplestack/ScopedServices.java // public interface ScopedServices { // /** // * When a service implements {@link Activated}, then it will receive a callback when the scope the service belongs to becomes the active (top-most) scope. // */ // public static interface Activated { // /** // * Called when the explicit parent chain the service is bound to becomes the top-most scope. // */ // void onServiceActive(); // // /** // * Called when the explicit parent chain the service is bound to is no longer the top-most scope. // */ // void onServiceInactive(); // } // // /** // * When a service implements {@link Registered}, then it will receive a callback when the service has been registered to at least one scope. // */ // public static interface Registered { // /** // * Called when the service has been registered to any scopes, and this is the first scope it was registered to. // */ // void onServiceRegistered(); // // /** // * Called when the service is no longer registered in any scopes. // */ // void onServiceUnregistered(); // } // // /** // * When a service implements {@link HandlesBack}, then it will receive a callback when back is being dispatched across the active scope chain. // */ // public static interface HandlesBack { // /** // * Called when back is being dispatched. // * // * @return whether the service handled back. // */ // boolean onBackEvent(); // } // // /** // * Used to configure the services that belong to given scopes. // * // * @param serviceBinder the binder that allows binding services to scopes. // */ // void bindServices(@Nonnull ServiceBinder serviceBinder); // } // // Path: simple-stack/src/main/java/com/zhuinden/simplestack/ServiceBinder.java // public class ServiceBinder { // private final ScopeManager scopeManager; // // private final Object key; // private final String scopeTag; // private final ScopeNode scope; // // ServiceBinder(ScopeManager scopeManager, Object key, String scopeTag, ScopeNode scope) { // this.scopeManager = scopeManager; // // this.key = key; // this.scopeTag = scopeTag; // this.scope = scope; // } // // /** // * Returns the key that this service binder was created for. // * // * @param <T> the type of the key // * @return the key // */ // @Nonnull // public <T> T getKey() { // //noinspection unchecked // return (T) key; // } // // /** // * Returns the scope tag this service binder belongs to. // * // * @return the scope tag // */ // @Nonnull // public final String getScopeTag() { // return scopeTag; // } // // /** // * Adds the service to the scope. // * // * @param serviceTag the tag of the service // * @param service the service // */ // public void addService(@Nonnull String serviceTag, @Nonnull Object service) { // scope.addService(serviceTag, service); // } // // /** // * Returns whether the service with given service tag is in the local scope. // * // * @param serviceTag the service tag // * @return if the service is in the scope // */ // public boolean hasService(@Nonnull String serviceTag) { // return scope.hasService(serviceTag); // } // // /** // * Retrieves the service from the local scope if it exists. // * // * @param serviceTag the service tag // * @param <T> the type of the service // * @return the service // * @throws IllegalArgumentException if the service is not in the scope // */ // @Nonnull // public <T> T getService(@Nonnull String serviceTag) { // return scope.getService(serviceTag); // } // // /** // * Adds an alias to the service within the local scope. Callbacks are not called for aliases, but they can be found as services. // * // * @param alias the alias // * @param service the service // */ // public void addAlias(@Nonnull String alias, @Nonnull Object service) { // scope.addAlias(alias, service); // } // // /** // * Returns whether the service can be found within the currently existing active scopes. // * // * @param serviceTag the service tag // * @return if the service exists in active scopes // */ // public boolean canFindService(@Nonnull String serviceTag) { // return scopeManager.canFindService(serviceTag); // } // // /** // * Retrieves the service from the active scopes if it exists. // * // * @param serviceTag the service tag // * @param <T> the type of the service // * @return the service // * @throws IllegalArgumentException if the service is not found in any active scopes // */ // @Nonnull // public <T> T lookupService(@Nonnull String serviceTag) { // return scopeManager.lookupService(serviceTag); // } // // /** // * Returns whether the service can be found if looked up from the provided scope. // * // * @param scopeTag the scope tag // * @param serviceTag the service tag // * @return whether the service can be looked up from the provided scope // */ // public boolean canFindFromScope(String scopeTag, String serviceTag) { // return scopeManager.canFindFromScope(scopeTag, serviceTag, ScopeLookupMode.ALL); // } // // /** // * Retrieves the service from the current scope or any of its parents, if the service exists. // * // * @param serviceTag the service tag // * @param <T> the type of the service // * @return the service // * @throws IllegalArgumentException if the service is not found in the scope or any of its parents // */ // @Nonnull // public <T> T lookupFromScope(String scopeTag, String serviceTag) { // return scopeManager.lookupFromScope(scopeTag, serviceTag, ScopeLookupMode.ALL); // } // // /** // * Returns the {@link Backstack} that manages the scopes. // * // * @return the backstack // */ // @Nonnull // public Backstack getBackstack() { // return scopeManager.getBackstack(); // } // }
import com.zhuinden.simplestack.ScopedServices; import com.zhuinden.simplestack.ServiceBinder; import javax.annotation.Nonnull;
package com.zhuinden.simplestack.helpers; public class ServiceProvider implements ScopedServices { @Override
// Path: simple-stack/src/main/java/com/zhuinden/simplestack/ScopedServices.java // public interface ScopedServices { // /** // * When a service implements {@link Activated}, then it will receive a callback when the scope the service belongs to becomes the active (top-most) scope. // */ // public static interface Activated { // /** // * Called when the explicit parent chain the service is bound to becomes the top-most scope. // */ // void onServiceActive(); // // /** // * Called when the explicit parent chain the service is bound to is no longer the top-most scope. // */ // void onServiceInactive(); // } // // /** // * When a service implements {@link Registered}, then it will receive a callback when the service has been registered to at least one scope. // */ // public static interface Registered { // /** // * Called when the service has been registered to any scopes, and this is the first scope it was registered to. // */ // void onServiceRegistered(); // // /** // * Called when the service is no longer registered in any scopes. // */ // void onServiceUnregistered(); // } // // /** // * When a service implements {@link HandlesBack}, then it will receive a callback when back is being dispatched across the active scope chain. // */ // public static interface HandlesBack { // /** // * Called when back is being dispatched. // * // * @return whether the service handled back. // */ // boolean onBackEvent(); // } // // /** // * Used to configure the services that belong to given scopes. // * // * @param serviceBinder the binder that allows binding services to scopes. // */ // void bindServices(@Nonnull ServiceBinder serviceBinder); // } // // Path: simple-stack/src/main/java/com/zhuinden/simplestack/ServiceBinder.java // public class ServiceBinder { // private final ScopeManager scopeManager; // // private final Object key; // private final String scopeTag; // private final ScopeNode scope; // // ServiceBinder(ScopeManager scopeManager, Object key, String scopeTag, ScopeNode scope) { // this.scopeManager = scopeManager; // // this.key = key; // this.scopeTag = scopeTag; // this.scope = scope; // } // // /** // * Returns the key that this service binder was created for. // * // * @param <T> the type of the key // * @return the key // */ // @Nonnull // public <T> T getKey() { // //noinspection unchecked // return (T) key; // } // // /** // * Returns the scope tag this service binder belongs to. // * // * @return the scope tag // */ // @Nonnull // public final String getScopeTag() { // return scopeTag; // } // // /** // * Adds the service to the scope. // * // * @param serviceTag the tag of the service // * @param service the service // */ // public void addService(@Nonnull String serviceTag, @Nonnull Object service) { // scope.addService(serviceTag, service); // } // // /** // * Returns whether the service with given service tag is in the local scope. // * // * @param serviceTag the service tag // * @return if the service is in the scope // */ // public boolean hasService(@Nonnull String serviceTag) { // return scope.hasService(serviceTag); // } // // /** // * Retrieves the service from the local scope if it exists. // * // * @param serviceTag the service tag // * @param <T> the type of the service // * @return the service // * @throws IllegalArgumentException if the service is not in the scope // */ // @Nonnull // public <T> T getService(@Nonnull String serviceTag) { // return scope.getService(serviceTag); // } // // /** // * Adds an alias to the service within the local scope. Callbacks are not called for aliases, but they can be found as services. // * // * @param alias the alias // * @param service the service // */ // public void addAlias(@Nonnull String alias, @Nonnull Object service) { // scope.addAlias(alias, service); // } // // /** // * Returns whether the service can be found within the currently existing active scopes. // * // * @param serviceTag the service tag // * @return if the service exists in active scopes // */ // public boolean canFindService(@Nonnull String serviceTag) { // return scopeManager.canFindService(serviceTag); // } // // /** // * Retrieves the service from the active scopes if it exists. // * // * @param serviceTag the service tag // * @param <T> the type of the service // * @return the service // * @throws IllegalArgumentException if the service is not found in any active scopes // */ // @Nonnull // public <T> T lookupService(@Nonnull String serviceTag) { // return scopeManager.lookupService(serviceTag); // } // // /** // * Returns whether the service can be found if looked up from the provided scope. // * // * @param scopeTag the scope tag // * @param serviceTag the service tag // * @return whether the service can be looked up from the provided scope // */ // public boolean canFindFromScope(String scopeTag, String serviceTag) { // return scopeManager.canFindFromScope(scopeTag, serviceTag, ScopeLookupMode.ALL); // } // // /** // * Retrieves the service from the current scope or any of its parents, if the service exists. // * // * @param serviceTag the service tag // * @param <T> the type of the service // * @return the service // * @throws IllegalArgumentException if the service is not found in the scope or any of its parents // */ // @Nonnull // public <T> T lookupFromScope(String scopeTag, String serviceTag) { // return scopeManager.lookupFromScope(scopeTag, serviceTag, ScopeLookupMode.ALL); // } // // /** // * Returns the {@link Backstack} that manages the scopes. // * // * @return the backstack // */ // @Nonnull // public Backstack getBackstack() { // return scopeManager.getBackstack(); // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java import com.zhuinden.simplestack.ScopedServices; import com.zhuinden.simplestack.ServiceBinder; import javax.annotation.Nonnull; package com.zhuinden.simplestack.helpers; public class ServiceProvider implements ScopedServices { @Override
public void bindServices(@Nonnull ServiceBinder serviceBinder) {
Zhuinden/simple-stack
samples/scoping-samples/simple-stack-example-scoping-java/src/main/java/com/zhuinden/simplestackexamplescoping/features/words/NewWordKey.java
// Path: samples/scoping-samples/simple-stack-example-scoping-java/src/main/java/com/zhuinden/simplestackexamplescoping/core/navigation/BaseKey.java // public abstract class BaseKey // extends DefaultFragmentKey // implements DefaultServiceProvider.HasServices { // @Nonnull // @Override // public String getFragmentTag() { // return toString(); // } // // @Nonnull // @Override // public String getScopeTag() { // return toString(); // } // // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // } // }
import com.google.auto.value.AutoValue; import com.zhuinden.simplestackexamplescoping.core.navigation.BaseKey; import javax.annotation.Nonnull; import androidx.fragment.app.Fragment;
package com.zhuinden.simplestackexamplescoping.features.words; @AutoValue public abstract class NewWordKey
// Path: samples/scoping-samples/simple-stack-example-scoping-java/src/main/java/com/zhuinden/simplestackexamplescoping/core/navigation/BaseKey.java // public abstract class BaseKey // extends DefaultFragmentKey // implements DefaultServiceProvider.HasServices { // @Nonnull // @Override // public String getFragmentTag() { // return toString(); // } // // @Nonnull // @Override // public String getScopeTag() { // return toString(); // } // // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // } // } // Path: samples/scoping-samples/simple-stack-example-scoping-java/src/main/java/com/zhuinden/simplestackexamplescoping/features/words/NewWordKey.java import com.google.auto.value.AutoValue; import com.zhuinden.simplestackexamplescoping.core.navigation.BaseKey; import javax.annotation.Nonnull; import androidx.fragment.app.Fragment; package com.zhuinden.simplestackexamplescoping.features.words; @AutoValue public abstract class NewWordKey
extends BaseKey {
Zhuinden/simple-stack
simple-stack/src/main/java/com/zhuinden/simplestack/navigator/changehandlers/AnimatorViewChangeHandler.java
// Path: simple-stack/src/main/java/com/zhuinden/simplestack/navigator/ViewChangeHandler.java // public interface ViewChangeHandler { // /** // * It must be called to signal that the view change is complete. // */ // interface ViewChangeCallback { // void onCompleted(); // } // // /** // * Perform the view change. The previous view must be removed from the container, and the new view must be added to the container. // * When complete, the completion callback must be called. // * // * @param container the container for the views // * @param previousView the previous view // * @param newView the new view // * @param direction the direction (from the StateChange) // * @param viewChangeCallback the callback that must be called when the view change is complete. // */ // void performViewChange(@Nonnull final ViewGroup container, @Nonnull final View previousView, @Nonnull final View newView, final int direction, @Nonnull final ViewChangeCallback viewChangeCallback); // }
import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.annotation.TargetApi; import android.view.View; import android.view.ViewGroup; import android.view.animation.Interpolator; import com.zhuinden.simplestack.navigator.ViewChangeHandler; import javax.annotation.Nonnull; import javax.annotation.Nullable;
/* * Copyright 2017 Gabor Varadi * * 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.zhuinden.simplestack.navigator.changehandlers; /** * Convenience base class to support view animations using Animator. */ @TargetApi(11) public abstract class AnimatorViewChangeHandler
// Path: simple-stack/src/main/java/com/zhuinden/simplestack/navigator/ViewChangeHandler.java // public interface ViewChangeHandler { // /** // * It must be called to signal that the view change is complete. // */ // interface ViewChangeCallback { // void onCompleted(); // } // // /** // * Perform the view change. The previous view must be removed from the container, and the new view must be added to the container. // * When complete, the completion callback must be called. // * // * @param container the container for the views // * @param previousView the previous view // * @param newView the new view // * @param direction the direction (from the StateChange) // * @param viewChangeCallback the callback that must be called when the view change is complete. // */ // void performViewChange(@Nonnull final ViewGroup container, @Nonnull final View previousView, @Nonnull final View newView, final int direction, @Nonnull final ViewChangeCallback viewChangeCallback); // } // Path: simple-stack/src/main/java/com/zhuinden/simplestack/navigator/changehandlers/AnimatorViewChangeHandler.java import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.annotation.TargetApi; import android.view.View; import android.view.ViewGroup; import android.view.animation.Interpolator; import com.zhuinden.simplestack.navigator.ViewChangeHandler; import javax.annotation.Nonnull; import javax.annotation.Nullable; /* * Copyright 2017 Gabor Varadi * * 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.zhuinden.simplestack.navigator.changehandlers; /** * Convenience base class to support view animations using Animator. */ @TargetApi(11) public abstract class AnimatorViewChangeHandler
implements ViewChangeHandler {
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/ScopingAliasTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/Action.java // public interface Action { // public void doSomething(); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithExplicitParent.java // public abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices { // public TestKeyWithExplicitParent(String name) { // super(name); // } // // protected TestKeyWithExplicitParent(Parcel in) { // super(in); // } // // @Override // public final void bindServices(ServiceBinder serviceBinder) { // if(name.equals(serviceBinder.getScopeTag())) { // bindOwnServices(serviceBinder); // } else { // bindParentServices(serviceBinder); // } // } // // protected abstract void bindParentServices(ServiceBinder serviceBinder); // // protected abstract void bindOwnServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/AssertionHelper.java // public static void assertThrows(Action action) { // try { // action.doSomething(); // Assert.fail("Did not throw exception."); // } catch(Exception e) { // // OK! // } // }
import com.zhuinden.simplestack.helpers.Action; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import com.zhuinden.statebundle.StateBundle; import org.junit.Test; import java.util.List; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static com.zhuinden.simplestack.helpers.AssertionHelper.assertThrows; import static org.assertj.core.api.Assertions.assertThat;
package com.zhuinden.simplestack; public class ScopingAliasTest { @Test public void aliasesWork() { Backstack backstack = new Backstack();
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/Action.java // public interface Action { // public void doSomething(); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithExplicitParent.java // public abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices { // public TestKeyWithExplicitParent(String name) { // super(name); // } // // protected TestKeyWithExplicitParent(Parcel in) { // super(in); // } // // @Override // public final void bindServices(ServiceBinder serviceBinder) { // if(name.equals(serviceBinder.getScopeTag())) { // bindOwnServices(serviceBinder); // } else { // bindParentServices(serviceBinder); // } // } // // protected abstract void bindParentServices(ServiceBinder serviceBinder); // // protected abstract void bindOwnServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/AssertionHelper.java // public static void assertThrows(Action action) { // try { // action.doSomething(); // Assert.fail("Did not throw exception."); // } catch(Exception e) { // // OK! // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/ScopingAliasTest.java import com.zhuinden.simplestack.helpers.Action; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import com.zhuinden.statebundle.StateBundle; import org.junit.Test; import java.util.List; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static com.zhuinden.simplestack.helpers.AssertionHelper.assertThrows; import static org.assertj.core.api.Assertions.assertThat; package com.zhuinden.simplestack; public class ScopingAliasTest { @Test public void aliasesWork() { Backstack backstack = new Backstack();
backstack.setScopedServices(new ServiceProvider());
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/ScopingAliasTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/Action.java // public interface Action { // public void doSomething(); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithExplicitParent.java // public abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices { // public TestKeyWithExplicitParent(String name) { // super(name); // } // // protected TestKeyWithExplicitParent(Parcel in) { // super(in); // } // // @Override // public final void bindServices(ServiceBinder serviceBinder) { // if(name.equals(serviceBinder.getScopeTag())) { // bindOwnServices(serviceBinder); // } else { // bindParentServices(serviceBinder); // } // } // // protected abstract void bindParentServices(ServiceBinder serviceBinder); // // protected abstract void bindOwnServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/AssertionHelper.java // public static void assertThrows(Action action) { // try { // action.doSomething(); // Assert.fail("Did not throw exception."); // } catch(Exception e) { // // OK! // } // }
import com.zhuinden.simplestack.helpers.Action; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import com.zhuinden.statebundle.StateBundle; import org.junit.Test; import java.util.List; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static com.zhuinden.simplestack.helpers.AssertionHelper.assertThrows; import static org.assertj.core.api.Assertions.assertThat;
package com.zhuinden.simplestack; public class ScopingAliasTest { @Test public void aliasesWork() { Backstack backstack = new Backstack(); backstack.setScopedServices(new ServiceProvider()); final Object service = new Object();
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/Action.java // public interface Action { // public void doSomething(); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithExplicitParent.java // public abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices { // public TestKeyWithExplicitParent(String name) { // super(name); // } // // protected TestKeyWithExplicitParent(Parcel in) { // super(in); // } // // @Override // public final void bindServices(ServiceBinder serviceBinder) { // if(name.equals(serviceBinder.getScopeTag())) { // bindOwnServices(serviceBinder); // } else { // bindParentServices(serviceBinder); // } // } // // protected abstract void bindParentServices(ServiceBinder serviceBinder); // // protected abstract void bindOwnServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/AssertionHelper.java // public static void assertThrows(Action action) { // try { // action.doSomething(); // Assert.fail("Did not throw exception."); // } catch(Exception e) { // // OK! // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/ScopingAliasTest.java import com.zhuinden.simplestack.helpers.Action; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import com.zhuinden.statebundle.StateBundle; import org.junit.Test; import java.util.List; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static com.zhuinden.simplestack.helpers.AssertionHelper.assertThrows; import static org.assertj.core.api.Assertions.assertThat; package com.zhuinden.simplestack; public class ScopingAliasTest { @Test public void aliasesWork() { Backstack backstack = new Backstack(); backstack.setScopedServices(new ServiceProvider()); final Object service = new Object();
TestKeyWithScope boop = new TestKeyWithScope("boop") {
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/ScopingAliasTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/Action.java // public interface Action { // public void doSomething(); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithExplicitParent.java // public abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices { // public TestKeyWithExplicitParent(String name) { // super(name); // } // // protected TestKeyWithExplicitParent(Parcel in) { // super(in); // } // // @Override // public final void bindServices(ServiceBinder serviceBinder) { // if(name.equals(serviceBinder.getScopeTag())) { // bindOwnServices(serviceBinder); // } else { // bindParentServices(serviceBinder); // } // } // // protected abstract void bindParentServices(ServiceBinder serviceBinder); // // protected abstract void bindOwnServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/AssertionHelper.java // public static void assertThrows(Action action) { // try { // action.doSomething(); // Assert.fail("Did not throw exception."); // } catch(Exception e) { // // OK! // } // }
import com.zhuinden.simplestack.helpers.Action; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import com.zhuinden.statebundle.StateBundle; import org.junit.Test; import java.util.List; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static com.zhuinden.simplestack.helpers.AssertionHelper.assertThrows; import static org.assertj.core.api.Assertions.assertThat;
final Object serviceShared1P2 = new MyService("serviceShared1P2"); final Object serviceShared1P3 = new MyService("serviceShared1P3"); final Object serviceShared2P1 = new MyService("serviceShared2P1"); final Object serviceShared2P2 = new MyService("serviceShared2P2"); final Object serviceShared2P3 = new MyService("serviceShared2P3"); final Object serviceShared3P1 = new MyService("serviceShared3P1"); final Object serviceShared3P2 = new MyService("serviceShared3P2"); final Object serviceShared3P3 = new MyService("serviceShared3P3"); final Object serviceP1 = new MyService("serviceP1"); final Object serviceP2 = new MyService("serviceP2"); final Object serviceP3 = new MyService("serviceP3"); TestKeyWithScope beep = new TestKeyWithScope("scope1") { @Override public void bindServices(ServiceBinder serviceBinder) { assertThat(serviceBinder.getScopeTag()).isEqualTo(getScopeTag()); serviceBinder.addService("service1", service1); serviceBinder.addService("serviceShared12", serviceShared12); serviceBinder.addService("serviceShared13", serviceShared13); serviceBinder.addService("serviceShared123", serviceShared123); serviceBinder.addService("serviceShared1P1", serviceShared1P1); serviceBinder.addService("serviceShared1P2", serviceShared1P2); serviceBinder.addService("serviceShared1P3", serviceShared1P3); serviceBinder.addService("serviceShared0123P1P2P3", serviceShared0123P1P2P3); } };
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/Action.java // public interface Action { // public void doSomething(); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithExplicitParent.java // public abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices { // public TestKeyWithExplicitParent(String name) { // super(name); // } // // protected TestKeyWithExplicitParent(Parcel in) { // super(in); // } // // @Override // public final void bindServices(ServiceBinder serviceBinder) { // if(name.equals(serviceBinder.getScopeTag())) { // bindOwnServices(serviceBinder); // } else { // bindParentServices(serviceBinder); // } // } // // protected abstract void bindParentServices(ServiceBinder serviceBinder); // // protected abstract void bindOwnServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/AssertionHelper.java // public static void assertThrows(Action action) { // try { // action.doSomething(); // Assert.fail("Did not throw exception."); // } catch(Exception e) { // // OK! // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/ScopingAliasTest.java import com.zhuinden.simplestack.helpers.Action; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import com.zhuinden.statebundle.StateBundle; import org.junit.Test; import java.util.List; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static com.zhuinden.simplestack.helpers.AssertionHelper.assertThrows; import static org.assertj.core.api.Assertions.assertThat; final Object serviceShared1P2 = new MyService("serviceShared1P2"); final Object serviceShared1P3 = new MyService("serviceShared1P3"); final Object serviceShared2P1 = new MyService("serviceShared2P1"); final Object serviceShared2P2 = new MyService("serviceShared2P2"); final Object serviceShared2P3 = new MyService("serviceShared2P3"); final Object serviceShared3P1 = new MyService("serviceShared3P1"); final Object serviceShared3P2 = new MyService("serviceShared3P2"); final Object serviceShared3P3 = new MyService("serviceShared3P3"); final Object serviceP1 = new MyService("serviceP1"); final Object serviceP2 = new MyService("serviceP2"); final Object serviceP3 = new MyService("serviceP3"); TestKeyWithScope beep = new TestKeyWithScope("scope1") { @Override public void bindServices(ServiceBinder serviceBinder) { assertThat(serviceBinder.getScopeTag()).isEqualTo(getScopeTag()); serviceBinder.addService("service1", service1); serviceBinder.addService("serviceShared12", serviceShared12); serviceBinder.addService("serviceShared13", serviceShared13); serviceBinder.addService("serviceShared123", serviceShared123); serviceBinder.addService("serviceShared1P1", serviceShared1P1); serviceBinder.addService("serviceShared1P2", serviceShared1P2); serviceBinder.addService("serviceShared1P3", serviceShared1P3); serviceBinder.addService("serviceShared0123P1P2P3", serviceShared0123P1P2P3); } };
TestKeyWithExplicitParent boop = new TestKeyWithExplicitParent("scope2") {
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/ScopingAliasTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/Action.java // public interface Action { // public void doSomething(); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithExplicitParent.java // public abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices { // public TestKeyWithExplicitParent(String name) { // super(name); // } // // protected TestKeyWithExplicitParent(Parcel in) { // super(in); // } // // @Override // public final void bindServices(ServiceBinder serviceBinder) { // if(name.equals(serviceBinder.getScopeTag())) { // bindOwnServices(serviceBinder); // } else { // bindParentServices(serviceBinder); // } // } // // protected abstract void bindParentServices(ServiceBinder serviceBinder); // // protected abstract void bindOwnServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/AssertionHelper.java // public static void assertThrows(Action action) { // try { // action.doSomething(); // Assert.fail("Did not throw exception."); // } catch(Exception e) { // // OK! // } // }
import com.zhuinden.simplestack.helpers.Action; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import com.zhuinden.statebundle.StateBundle; import org.junit.Test; import java.util.List; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static com.zhuinden.simplestack.helpers.AssertionHelper.assertThrows; import static org.assertj.core.api.Assertions.assertThat;
// then assertThat(backstack.hasService(GlobalServices.SCOPE_TAG, "service0")).isTrue(); assertThat(backstack.hasService(GlobalServices.SCOPE_TAG, "alias0")).isTrue(); assertThat(backstack.canFindFromScope(GlobalServices.SCOPE_TAG, "alias0")).isTrue(); assertThat(backstack.canFindFromScope(GlobalServices.SCOPE_TAG, "alias0", ScopeLookupMode.ALL)).isTrue(); assertThat(backstack.canFindFromScope(GlobalServices.SCOPE_TAG, "alias0", ScopeLookupMode.EXPLICIT)).isTrue(); assertThat(backstack.canFindService("alias0")).isTrue(); assertThat(backstack.lookupFromScope(GlobalServices.SCOPE_TAG, "alias0")).isSameAs(service0); assertThat(backstack.lookupFromScope(GlobalServices.SCOPE_TAG, "alias0", ScopeLookupMode.ALL)).isSameAs(service0); assertThat(backstack.lookupFromScope(GlobalServices.SCOPE_TAG, "alias0", ScopeLookupMode.EXPLICIT)).isSameAs(service0); assertThat(backstack.lookupService("alias0")).isSameAs(service0); // ALSO backstack.goBack(); backstack.goBack(); // then assertThat(backstack.hasService("parent1", "serviceP1")).isFalse(); assertThat(backstack.hasService("parent1", "aliasP1")).isFalse(); assertThat(backstack.canFindFromScope("parent1", "aliasP1")).isFalse(); assertThat(backstack.canFindFromScope("parent1", "aliasP1", ScopeLookupMode.ALL)).isFalse(); assertThat(backstack.canFindFromScope("parent1", "aliasP1", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindService("aliasP1")).isFalse();
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/Action.java // public interface Action { // public void doSomething(); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithExplicitParent.java // public abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices { // public TestKeyWithExplicitParent(String name) { // super(name); // } // // protected TestKeyWithExplicitParent(Parcel in) { // super(in); // } // // @Override // public final void bindServices(ServiceBinder serviceBinder) { // if(name.equals(serviceBinder.getScopeTag())) { // bindOwnServices(serviceBinder); // } else { // bindParentServices(serviceBinder); // } // } // // protected abstract void bindParentServices(ServiceBinder serviceBinder); // // protected abstract void bindOwnServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/AssertionHelper.java // public static void assertThrows(Action action) { // try { // action.doSomething(); // Assert.fail("Did not throw exception."); // } catch(Exception e) { // // OK! // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/ScopingAliasTest.java import com.zhuinden.simplestack.helpers.Action; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import com.zhuinden.statebundle.StateBundle; import org.junit.Test; import java.util.List; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static com.zhuinden.simplestack.helpers.AssertionHelper.assertThrows; import static org.assertj.core.api.Assertions.assertThat; // then assertThat(backstack.hasService(GlobalServices.SCOPE_TAG, "service0")).isTrue(); assertThat(backstack.hasService(GlobalServices.SCOPE_TAG, "alias0")).isTrue(); assertThat(backstack.canFindFromScope(GlobalServices.SCOPE_TAG, "alias0")).isTrue(); assertThat(backstack.canFindFromScope(GlobalServices.SCOPE_TAG, "alias0", ScopeLookupMode.ALL)).isTrue(); assertThat(backstack.canFindFromScope(GlobalServices.SCOPE_TAG, "alias0", ScopeLookupMode.EXPLICIT)).isTrue(); assertThat(backstack.canFindService("alias0")).isTrue(); assertThat(backstack.lookupFromScope(GlobalServices.SCOPE_TAG, "alias0")).isSameAs(service0); assertThat(backstack.lookupFromScope(GlobalServices.SCOPE_TAG, "alias0", ScopeLookupMode.ALL)).isSameAs(service0); assertThat(backstack.lookupFromScope(GlobalServices.SCOPE_TAG, "alias0", ScopeLookupMode.EXPLICIT)).isSameAs(service0); assertThat(backstack.lookupService("alias0")).isSameAs(service0); // ALSO backstack.goBack(); backstack.goBack(); // then assertThat(backstack.hasService("parent1", "serviceP1")).isFalse(); assertThat(backstack.hasService("parent1", "aliasP1")).isFalse(); assertThat(backstack.canFindFromScope("parent1", "aliasP1")).isFalse(); assertThat(backstack.canFindFromScope("parent1", "aliasP1", ScopeLookupMode.ALL)).isFalse(); assertThat(backstack.canFindFromScope("parent1", "aliasP1", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindService("aliasP1")).isFalse();
assertThrows(new Action() {
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/ScopingAliasTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/Action.java // public interface Action { // public void doSomething(); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithExplicitParent.java // public abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices { // public TestKeyWithExplicitParent(String name) { // super(name); // } // // protected TestKeyWithExplicitParent(Parcel in) { // super(in); // } // // @Override // public final void bindServices(ServiceBinder serviceBinder) { // if(name.equals(serviceBinder.getScopeTag())) { // bindOwnServices(serviceBinder); // } else { // bindParentServices(serviceBinder); // } // } // // protected abstract void bindParentServices(ServiceBinder serviceBinder); // // protected abstract void bindOwnServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/AssertionHelper.java // public static void assertThrows(Action action) { // try { // action.doSomething(); // Assert.fail("Did not throw exception."); // } catch(Exception e) { // // OK! // } // }
import com.zhuinden.simplestack.helpers.Action; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import com.zhuinden.statebundle.StateBundle; import org.junit.Test; import java.util.List; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static com.zhuinden.simplestack.helpers.AssertionHelper.assertThrows; import static org.assertj.core.api.Assertions.assertThat;
// then assertThat(backstack.hasService(GlobalServices.SCOPE_TAG, "service0")).isTrue(); assertThat(backstack.hasService(GlobalServices.SCOPE_TAG, "alias0")).isTrue(); assertThat(backstack.canFindFromScope(GlobalServices.SCOPE_TAG, "alias0")).isTrue(); assertThat(backstack.canFindFromScope(GlobalServices.SCOPE_TAG, "alias0", ScopeLookupMode.ALL)).isTrue(); assertThat(backstack.canFindFromScope(GlobalServices.SCOPE_TAG, "alias0", ScopeLookupMode.EXPLICIT)).isTrue(); assertThat(backstack.canFindService("alias0")).isTrue(); assertThat(backstack.lookupFromScope(GlobalServices.SCOPE_TAG, "alias0")).isSameAs(service0); assertThat(backstack.lookupFromScope(GlobalServices.SCOPE_TAG, "alias0", ScopeLookupMode.ALL)).isSameAs(service0); assertThat(backstack.lookupFromScope(GlobalServices.SCOPE_TAG, "alias0", ScopeLookupMode.EXPLICIT)).isSameAs(service0); assertThat(backstack.lookupService("alias0")).isSameAs(service0); // ALSO backstack.goBack(); backstack.goBack(); // then assertThat(backstack.hasService("parent1", "serviceP1")).isFalse(); assertThat(backstack.hasService("parent1", "aliasP1")).isFalse(); assertThat(backstack.canFindFromScope("parent1", "aliasP1")).isFalse(); assertThat(backstack.canFindFromScope("parent1", "aliasP1", ScopeLookupMode.ALL)).isFalse(); assertThat(backstack.canFindFromScope("parent1", "aliasP1", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindService("aliasP1")).isFalse();
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/Action.java // public interface Action { // public void doSomething(); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithExplicitParent.java // public abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices { // public TestKeyWithExplicitParent(String name) { // super(name); // } // // protected TestKeyWithExplicitParent(Parcel in) { // super(in); // } // // @Override // public final void bindServices(ServiceBinder serviceBinder) { // if(name.equals(serviceBinder.getScopeTag())) { // bindOwnServices(serviceBinder); // } else { // bindParentServices(serviceBinder); // } // } // // protected abstract void bindParentServices(ServiceBinder serviceBinder); // // protected abstract void bindOwnServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/AssertionHelper.java // public static void assertThrows(Action action) { // try { // action.doSomething(); // Assert.fail("Did not throw exception."); // } catch(Exception e) { // // OK! // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/ScopingAliasTest.java import com.zhuinden.simplestack.helpers.Action; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import com.zhuinden.statebundle.StateBundle; import org.junit.Test; import java.util.List; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static com.zhuinden.simplestack.helpers.AssertionHelper.assertThrows; import static org.assertj.core.api.Assertions.assertThat; // then assertThat(backstack.hasService(GlobalServices.SCOPE_TAG, "service0")).isTrue(); assertThat(backstack.hasService(GlobalServices.SCOPE_TAG, "alias0")).isTrue(); assertThat(backstack.canFindFromScope(GlobalServices.SCOPE_TAG, "alias0")).isTrue(); assertThat(backstack.canFindFromScope(GlobalServices.SCOPE_TAG, "alias0", ScopeLookupMode.ALL)).isTrue(); assertThat(backstack.canFindFromScope(GlobalServices.SCOPE_TAG, "alias0", ScopeLookupMode.EXPLICIT)).isTrue(); assertThat(backstack.canFindService("alias0")).isTrue(); assertThat(backstack.lookupFromScope(GlobalServices.SCOPE_TAG, "alias0")).isSameAs(service0); assertThat(backstack.lookupFromScope(GlobalServices.SCOPE_TAG, "alias0", ScopeLookupMode.ALL)).isSameAs(service0); assertThat(backstack.lookupFromScope(GlobalServices.SCOPE_TAG, "alias0", ScopeLookupMode.EXPLICIT)).isSameAs(service0); assertThat(backstack.lookupService("alias0")).isSameAs(service0); // ALSO backstack.goBack(); backstack.goBack(); // then assertThat(backstack.hasService("parent1", "serviceP1")).isFalse(); assertThat(backstack.hasService("parent1", "aliasP1")).isFalse(); assertThat(backstack.canFindFromScope("parent1", "aliasP1")).isFalse(); assertThat(backstack.canFindFromScope("parent1", "aliasP1", ScopeLookupMode.ALL)).isFalse(); assertThat(backstack.canFindFromScope("parent1", "aliasP1", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindService("aliasP1")).isFalse();
assertThrows(new Action() {
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithExplicitParent.java
// Path: simple-stack/src/main/java/com/zhuinden/simplestack/ServiceBinder.java // public class ServiceBinder { // private final ScopeManager scopeManager; // // private final Object key; // private final String scopeTag; // private final ScopeNode scope; // // ServiceBinder(ScopeManager scopeManager, Object key, String scopeTag, ScopeNode scope) { // this.scopeManager = scopeManager; // // this.key = key; // this.scopeTag = scopeTag; // this.scope = scope; // } // // /** // * Returns the key that this service binder was created for. // * // * @param <T> the type of the key // * @return the key // */ // @Nonnull // public <T> T getKey() { // //noinspection unchecked // return (T) key; // } // // /** // * Returns the scope tag this service binder belongs to. // * // * @return the scope tag // */ // @Nonnull // public final String getScopeTag() { // return scopeTag; // } // // /** // * Adds the service to the scope. // * // * @param serviceTag the tag of the service // * @param service the service // */ // public void addService(@Nonnull String serviceTag, @Nonnull Object service) { // scope.addService(serviceTag, service); // } // // /** // * Returns whether the service with given service tag is in the local scope. // * // * @param serviceTag the service tag // * @return if the service is in the scope // */ // public boolean hasService(@Nonnull String serviceTag) { // return scope.hasService(serviceTag); // } // // /** // * Retrieves the service from the local scope if it exists. // * // * @param serviceTag the service tag // * @param <T> the type of the service // * @return the service // * @throws IllegalArgumentException if the service is not in the scope // */ // @Nonnull // public <T> T getService(@Nonnull String serviceTag) { // return scope.getService(serviceTag); // } // // /** // * Adds an alias to the service within the local scope. Callbacks are not called for aliases, but they can be found as services. // * // * @param alias the alias // * @param service the service // */ // public void addAlias(@Nonnull String alias, @Nonnull Object service) { // scope.addAlias(alias, service); // } // // /** // * Returns whether the service can be found within the currently existing active scopes. // * // * @param serviceTag the service tag // * @return if the service exists in active scopes // */ // public boolean canFindService(@Nonnull String serviceTag) { // return scopeManager.canFindService(serviceTag); // } // // /** // * Retrieves the service from the active scopes if it exists. // * // * @param serviceTag the service tag // * @param <T> the type of the service // * @return the service // * @throws IllegalArgumentException if the service is not found in any active scopes // */ // @Nonnull // public <T> T lookupService(@Nonnull String serviceTag) { // return scopeManager.lookupService(serviceTag); // } // // /** // * Returns whether the service can be found if looked up from the provided scope. // * // * @param scopeTag the scope tag // * @param serviceTag the service tag // * @return whether the service can be looked up from the provided scope // */ // public boolean canFindFromScope(String scopeTag, String serviceTag) { // return scopeManager.canFindFromScope(scopeTag, serviceTag, ScopeLookupMode.ALL); // } // // /** // * Retrieves the service from the current scope or any of its parents, if the service exists. // * // * @param serviceTag the service tag // * @param <T> the type of the service // * @return the service // * @throws IllegalArgumentException if the service is not found in the scope or any of its parents // */ // @Nonnull // public <T> T lookupFromScope(String scopeTag, String serviceTag) { // return scopeManager.lookupFromScope(scopeTag, serviceTag, ScopeLookupMode.ALL); // } // // /** // * Returns the {@link Backstack} that manages the scopes. // * // * @return the backstack // */ // @Nonnull // public Backstack getBackstack() { // return scopeManager.getBackstack(); // } // }
import android.os.Parcel; import com.zhuinden.simplestack.ServiceBinder;
package com.zhuinden.simplestack.helpers; public abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices { public TestKeyWithExplicitParent(String name) { super(name); } protected TestKeyWithExplicitParent(Parcel in) { super(in); } @Override
// Path: simple-stack/src/main/java/com/zhuinden/simplestack/ServiceBinder.java // public class ServiceBinder { // private final ScopeManager scopeManager; // // private final Object key; // private final String scopeTag; // private final ScopeNode scope; // // ServiceBinder(ScopeManager scopeManager, Object key, String scopeTag, ScopeNode scope) { // this.scopeManager = scopeManager; // // this.key = key; // this.scopeTag = scopeTag; // this.scope = scope; // } // // /** // * Returns the key that this service binder was created for. // * // * @param <T> the type of the key // * @return the key // */ // @Nonnull // public <T> T getKey() { // //noinspection unchecked // return (T) key; // } // // /** // * Returns the scope tag this service binder belongs to. // * // * @return the scope tag // */ // @Nonnull // public final String getScopeTag() { // return scopeTag; // } // // /** // * Adds the service to the scope. // * // * @param serviceTag the tag of the service // * @param service the service // */ // public void addService(@Nonnull String serviceTag, @Nonnull Object service) { // scope.addService(serviceTag, service); // } // // /** // * Returns whether the service with given service tag is in the local scope. // * // * @param serviceTag the service tag // * @return if the service is in the scope // */ // public boolean hasService(@Nonnull String serviceTag) { // return scope.hasService(serviceTag); // } // // /** // * Retrieves the service from the local scope if it exists. // * // * @param serviceTag the service tag // * @param <T> the type of the service // * @return the service // * @throws IllegalArgumentException if the service is not in the scope // */ // @Nonnull // public <T> T getService(@Nonnull String serviceTag) { // return scope.getService(serviceTag); // } // // /** // * Adds an alias to the service within the local scope. Callbacks are not called for aliases, but they can be found as services. // * // * @param alias the alias // * @param service the service // */ // public void addAlias(@Nonnull String alias, @Nonnull Object service) { // scope.addAlias(alias, service); // } // // /** // * Returns whether the service can be found within the currently existing active scopes. // * // * @param serviceTag the service tag // * @return if the service exists in active scopes // */ // public boolean canFindService(@Nonnull String serviceTag) { // return scopeManager.canFindService(serviceTag); // } // // /** // * Retrieves the service from the active scopes if it exists. // * // * @param serviceTag the service tag // * @param <T> the type of the service // * @return the service // * @throws IllegalArgumentException if the service is not found in any active scopes // */ // @Nonnull // public <T> T lookupService(@Nonnull String serviceTag) { // return scopeManager.lookupService(serviceTag); // } // // /** // * Returns whether the service can be found if looked up from the provided scope. // * // * @param scopeTag the scope tag // * @param serviceTag the service tag // * @return whether the service can be looked up from the provided scope // */ // public boolean canFindFromScope(String scopeTag, String serviceTag) { // return scopeManager.canFindFromScope(scopeTag, serviceTag, ScopeLookupMode.ALL); // } // // /** // * Retrieves the service from the current scope or any of its parents, if the service exists. // * // * @param serviceTag the service tag // * @param <T> the type of the service // * @return the service // * @throws IllegalArgumentException if the service is not found in the scope or any of its parents // */ // @Nonnull // public <T> T lookupFromScope(String scopeTag, String serviceTag) { // return scopeManager.lookupFromScope(scopeTag, serviceTag, ScopeLookupMode.ALL); // } // // /** // * Returns the {@link Backstack} that manages the scopes. // * // * @return the backstack // */ // @Nonnull // public Backstack getBackstack() { // return scopeManager.getBackstack(); // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithExplicitParent.java import android.os.Parcel; import com.zhuinden.simplestack.ServiceBinder; package com.zhuinden.simplestack.helpers; public abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices { public TestKeyWithExplicitParent(String name) { super(name); } protected TestKeyWithExplicitParent(Parcel in) { super(in); } @Override
public final void bindServices(ServiceBinder serviceBinder) {
Zhuinden/simple-stack
samples/basic-samples/simple-stack-example-basic-java-view/src/main/java/com/zhuinden/navigationexampleview/core/navigation/BaseKey.java
// Path: simple-stack/src/main/java/com/zhuinden/simplestack/navigator/DefaultViewKey.java // public interface DefaultViewKey { // int layout(); // // @Nonnull // ViewChangeHandler viewChangeHandler(); // } // // Path: simple-stack/src/main/java/com/zhuinden/simplestack/navigator/ViewChangeHandler.java // public interface ViewChangeHandler { // /** // * It must be called to signal that the view change is complete. // */ // interface ViewChangeCallback { // void onCompleted(); // } // // /** // * Perform the view change. The previous view must be removed from the container, and the new view must be added to the container. // * When complete, the completion callback must be called. // * // * @param container the container for the views // * @param previousView the previous view // * @param newView the new view // * @param direction the direction (from the StateChange) // * @param viewChangeCallback the callback that must be called when the view change is complete. // */ // void performViewChange(@Nonnull final ViewGroup container, @Nonnull final View previousView, @Nonnull final View newView, final int direction, @Nonnull final ViewChangeCallback viewChangeCallback); // } // // Path: simple-stack/src/main/java/com/zhuinden/simplestack/navigator/changehandlers/FadeViewChangeHandler.java // @TargetApi(11) // public final class FadeViewChangeHandler // extends AnimatorViewChangeHandler { // @Override // protected Animator createAnimator(@Nonnull View previousView, @Nonnull View newView, int direction) { // AnimatorSet set = new AnimatorSet(); // set.play(ObjectAnimator.ofFloat(previousView, "alpha", 1, 0)); // set.play(ObjectAnimator.ofFloat(newView, "alpha", 0, 1)); // return set; // } // // @Override // protected void resetPreviousViewValues(View previousView) { // previousView.setAlpha(1f); // } // }
import android.os.Parcelable; import androidx.annotation.NonNull; import com.zhuinden.simplestack.navigator.DefaultViewKey; import com.zhuinden.simplestack.navigator.ViewChangeHandler; import com.zhuinden.simplestack.navigator.changehandlers.FadeViewChangeHandler;
package com.zhuinden.navigationexampleview.core.navigation; /** * Created by Owner on 2017. 06. 29.. */ public abstract class BaseKey implements DefaultViewKey, Parcelable { @NonNull @Override
// Path: simple-stack/src/main/java/com/zhuinden/simplestack/navigator/DefaultViewKey.java // public interface DefaultViewKey { // int layout(); // // @Nonnull // ViewChangeHandler viewChangeHandler(); // } // // Path: simple-stack/src/main/java/com/zhuinden/simplestack/navigator/ViewChangeHandler.java // public interface ViewChangeHandler { // /** // * It must be called to signal that the view change is complete. // */ // interface ViewChangeCallback { // void onCompleted(); // } // // /** // * Perform the view change. The previous view must be removed from the container, and the new view must be added to the container. // * When complete, the completion callback must be called. // * // * @param container the container for the views // * @param previousView the previous view // * @param newView the new view // * @param direction the direction (from the StateChange) // * @param viewChangeCallback the callback that must be called when the view change is complete. // */ // void performViewChange(@Nonnull final ViewGroup container, @Nonnull final View previousView, @Nonnull final View newView, final int direction, @Nonnull final ViewChangeCallback viewChangeCallback); // } // // Path: simple-stack/src/main/java/com/zhuinden/simplestack/navigator/changehandlers/FadeViewChangeHandler.java // @TargetApi(11) // public final class FadeViewChangeHandler // extends AnimatorViewChangeHandler { // @Override // protected Animator createAnimator(@Nonnull View previousView, @Nonnull View newView, int direction) { // AnimatorSet set = new AnimatorSet(); // set.play(ObjectAnimator.ofFloat(previousView, "alpha", 1, 0)); // set.play(ObjectAnimator.ofFloat(newView, "alpha", 0, 1)); // return set; // } // // @Override // protected void resetPreviousViewValues(View previousView) { // previousView.setAlpha(1f); // } // } // Path: samples/basic-samples/simple-stack-example-basic-java-view/src/main/java/com/zhuinden/navigationexampleview/core/navigation/BaseKey.java import android.os.Parcelable; import androidx.annotation.NonNull; import com.zhuinden.simplestack.navigator.DefaultViewKey; import com.zhuinden.simplestack.navigator.ViewChangeHandler; import com.zhuinden.simplestack.navigator.changehandlers.FadeViewChangeHandler; package com.zhuinden.navigationexampleview.core.navigation; /** * Created by Owner on 2017. 06. 29.. */ public abstract class BaseKey implements DefaultViewKey, Parcelable { @NonNull @Override
public ViewChangeHandler viewChangeHandler() {
Zhuinden/simple-stack
samples/basic-samples/simple-stack-example-basic-java-view/src/main/java/com/zhuinden/navigationexampleview/core/navigation/BaseKey.java
// Path: simple-stack/src/main/java/com/zhuinden/simplestack/navigator/DefaultViewKey.java // public interface DefaultViewKey { // int layout(); // // @Nonnull // ViewChangeHandler viewChangeHandler(); // } // // Path: simple-stack/src/main/java/com/zhuinden/simplestack/navigator/ViewChangeHandler.java // public interface ViewChangeHandler { // /** // * It must be called to signal that the view change is complete. // */ // interface ViewChangeCallback { // void onCompleted(); // } // // /** // * Perform the view change. The previous view must be removed from the container, and the new view must be added to the container. // * When complete, the completion callback must be called. // * // * @param container the container for the views // * @param previousView the previous view // * @param newView the new view // * @param direction the direction (from the StateChange) // * @param viewChangeCallback the callback that must be called when the view change is complete. // */ // void performViewChange(@Nonnull final ViewGroup container, @Nonnull final View previousView, @Nonnull final View newView, final int direction, @Nonnull final ViewChangeCallback viewChangeCallback); // } // // Path: simple-stack/src/main/java/com/zhuinden/simplestack/navigator/changehandlers/FadeViewChangeHandler.java // @TargetApi(11) // public final class FadeViewChangeHandler // extends AnimatorViewChangeHandler { // @Override // protected Animator createAnimator(@Nonnull View previousView, @Nonnull View newView, int direction) { // AnimatorSet set = new AnimatorSet(); // set.play(ObjectAnimator.ofFloat(previousView, "alpha", 1, 0)); // set.play(ObjectAnimator.ofFloat(newView, "alpha", 0, 1)); // return set; // } // // @Override // protected void resetPreviousViewValues(View previousView) { // previousView.setAlpha(1f); // } // }
import android.os.Parcelable; import androidx.annotation.NonNull; import com.zhuinden.simplestack.navigator.DefaultViewKey; import com.zhuinden.simplestack.navigator.ViewChangeHandler; import com.zhuinden.simplestack.navigator.changehandlers.FadeViewChangeHandler;
package com.zhuinden.navigationexampleview.core.navigation; /** * Created by Owner on 2017. 06. 29.. */ public abstract class BaseKey implements DefaultViewKey, Parcelable { @NonNull @Override public ViewChangeHandler viewChangeHandler() {
// Path: simple-stack/src/main/java/com/zhuinden/simplestack/navigator/DefaultViewKey.java // public interface DefaultViewKey { // int layout(); // // @Nonnull // ViewChangeHandler viewChangeHandler(); // } // // Path: simple-stack/src/main/java/com/zhuinden/simplestack/navigator/ViewChangeHandler.java // public interface ViewChangeHandler { // /** // * It must be called to signal that the view change is complete. // */ // interface ViewChangeCallback { // void onCompleted(); // } // // /** // * Perform the view change. The previous view must be removed from the container, and the new view must be added to the container. // * When complete, the completion callback must be called. // * // * @param container the container for the views // * @param previousView the previous view // * @param newView the new view // * @param direction the direction (from the StateChange) // * @param viewChangeCallback the callback that must be called when the view change is complete. // */ // void performViewChange(@Nonnull final ViewGroup container, @Nonnull final View previousView, @Nonnull final View newView, final int direction, @Nonnull final ViewChangeCallback viewChangeCallback); // } // // Path: simple-stack/src/main/java/com/zhuinden/simplestack/navigator/changehandlers/FadeViewChangeHandler.java // @TargetApi(11) // public final class FadeViewChangeHandler // extends AnimatorViewChangeHandler { // @Override // protected Animator createAnimator(@Nonnull View previousView, @Nonnull View newView, int direction) { // AnimatorSet set = new AnimatorSet(); // set.play(ObjectAnimator.ofFloat(previousView, "alpha", 1, 0)); // set.play(ObjectAnimator.ofFloat(newView, "alpha", 0, 1)); // return set; // } // // @Override // protected void resetPreviousViewValues(View previousView) { // previousView.setAlpha(1f); // } // } // Path: samples/basic-samples/simple-stack-example-basic-java-view/src/main/java/com/zhuinden/navigationexampleview/core/navigation/BaseKey.java import android.os.Parcelable; import androidx.annotation.NonNull; import com.zhuinden.simplestack.navigator.DefaultViewKey; import com.zhuinden.simplestack.navigator.ViewChangeHandler; import com.zhuinden.simplestack.navigator.changehandlers.FadeViewChangeHandler; package com.zhuinden.navigationexampleview.core.navigation; /** * Created by Owner on 2017. 06. 29.. */ public abstract class BaseKey implements DefaultViewKey, Parcelable { @NonNull @Override public ViewChangeHandler viewChangeHandler() {
return new FadeViewChangeHandler();
Zhuinden/simple-stack
samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/features/kitten/grid/KittenGridKey.java
// Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/navigation/BaseFragment.java // public class BaseFragment // extends KeyedFragment { // public BaseFragment() { // } // // public BaseFragment(@LayoutRes int layoutRes) { // super(layoutRes); // } // // @Override // public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // startPostponedEnterTransition(); // } // } // // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/navigation/BaseKey.java // public abstract class BaseKey extends DefaultFragmentKey { // @NotNull // @Override // public String getFragmentTag() { // return toString(); // } // }
import com.example.fragmenttransitions.core.navigation.BaseFragment; import com.example.fragmenttransitions.core.navigation.BaseKey; import com.google.auto.value.AutoValue; import org.jetbrains.annotations.NotNull;
package com.example.fragmenttransitions.features.kitten.grid; /** * Created by Zhuinden on 2020. 12. 18.. */ @AutoValue public abstract class KittenGridKey
// Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/navigation/BaseFragment.java // public class BaseFragment // extends KeyedFragment { // public BaseFragment() { // } // // public BaseFragment(@LayoutRes int layoutRes) { // super(layoutRes); // } // // @Override // public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // startPostponedEnterTransition(); // } // } // // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/navigation/BaseKey.java // public abstract class BaseKey extends DefaultFragmentKey { // @NotNull // @Override // public String getFragmentTag() { // return toString(); // } // } // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/features/kitten/grid/KittenGridKey.java import com.example.fragmenttransitions.core.navigation.BaseFragment; import com.example.fragmenttransitions.core.navigation.BaseKey; import com.google.auto.value.AutoValue; import org.jetbrains.annotations.NotNull; package com.example.fragmenttransitions.features.kitten.grid; /** * Created by Zhuinden on 2020. 12. 18.. */ @AutoValue public abstract class KittenGridKey
extends BaseKey {
Zhuinden/simple-stack
samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/features/kitten/grid/KittenGridKey.java
// Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/navigation/BaseFragment.java // public class BaseFragment // extends KeyedFragment { // public BaseFragment() { // } // // public BaseFragment(@LayoutRes int layoutRes) { // super(layoutRes); // } // // @Override // public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // startPostponedEnterTransition(); // } // } // // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/navigation/BaseKey.java // public abstract class BaseKey extends DefaultFragmentKey { // @NotNull // @Override // public String getFragmentTag() { // return toString(); // } // }
import com.example.fragmenttransitions.core.navigation.BaseFragment; import com.example.fragmenttransitions.core.navigation.BaseKey; import com.google.auto.value.AutoValue; import org.jetbrains.annotations.NotNull;
package com.example.fragmenttransitions.features.kitten.grid; /** * Created by Zhuinden on 2020. 12. 18.. */ @AutoValue public abstract class KittenGridKey extends BaseKey { @NotNull @Override
// Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/navigation/BaseFragment.java // public class BaseFragment // extends KeyedFragment { // public BaseFragment() { // } // // public BaseFragment(@LayoutRes int layoutRes) { // super(layoutRes); // } // // @Override // public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // startPostponedEnterTransition(); // } // } // // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/navigation/BaseKey.java // public abstract class BaseKey extends DefaultFragmentKey { // @NotNull // @Override // public String getFragmentTag() { // return toString(); // } // } // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/features/kitten/grid/KittenGridKey.java import com.example.fragmenttransitions.core.navigation.BaseFragment; import com.example.fragmenttransitions.core.navigation.BaseKey; import com.google.auto.value.AutoValue; import org.jetbrains.annotations.NotNull; package com.example.fragmenttransitions.features.kitten.grid; /** * Created by Zhuinden on 2020. 12. 18.. */ @AutoValue public abstract class KittenGridKey extends BaseKey { @NotNull @Override
public BaseFragment instantiateFragment() {
Zhuinden/simple-stack
samples/scoping-samples/simple-stack-example-scoping-java/src/main/java/com/zhuinden/simplestackexamplescoping/core/navigation/BaseKey.java
// Path: simple-stack/src/main/java/com/zhuinden/simplestack/ServiceBinder.java // public class ServiceBinder { // private final ScopeManager scopeManager; // // private final Object key; // private final String scopeTag; // private final ScopeNode scope; // // ServiceBinder(ScopeManager scopeManager, Object key, String scopeTag, ScopeNode scope) { // this.scopeManager = scopeManager; // // this.key = key; // this.scopeTag = scopeTag; // this.scope = scope; // } // // /** // * Returns the key that this service binder was created for. // * // * @param <T> the type of the key // * @return the key // */ // @Nonnull // public <T> T getKey() { // //noinspection unchecked // return (T) key; // } // // /** // * Returns the scope tag this service binder belongs to. // * // * @return the scope tag // */ // @Nonnull // public final String getScopeTag() { // return scopeTag; // } // // /** // * Adds the service to the scope. // * // * @param serviceTag the tag of the service // * @param service the service // */ // public void addService(@Nonnull String serviceTag, @Nonnull Object service) { // scope.addService(serviceTag, service); // } // // /** // * Returns whether the service with given service tag is in the local scope. // * // * @param serviceTag the service tag // * @return if the service is in the scope // */ // public boolean hasService(@Nonnull String serviceTag) { // return scope.hasService(serviceTag); // } // // /** // * Retrieves the service from the local scope if it exists. // * // * @param serviceTag the service tag // * @param <T> the type of the service // * @return the service // * @throws IllegalArgumentException if the service is not in the scope // */ // @Nonnull // public <T> T getService(@Nonnull String serviceTag) { // return scope.getService(serviceTag); // } // // /** // * Adds an alias to the service within the local scope. Callbacks are not called for aliases, but they can be found as services. // * // * @param alias the alias // * @param service the service // */ // public void addAlias(@Nonnull String alias, @Nonnull Object service) { // scope.addAlias(alias, service); // } // // /** // * Returns whether the service can be found within the currently existing active scopes. // * // * @param serviceTag the service tag // * @return if the service exists in active scopes // */ // public boolean canFindService(@Nonnull String serviceTag) { // return scopeManager.canFindService(serviceTag); // } // // /** // * Retrieves the service from the active scopes if it exists. // * // * @param serviceTag the service tag // * @param <T> the type of the service // * @return the service // * @throws IllegalArgumentException if the service is not found in any active scopes // */ // @Nonnull // public <T> T lookupService(@Nonnull String serviceTag) { // return scopeManager.lookupService(serviceTag); // } // // /** // * Returns whether the service can be found if looked up from the provided scope. // * // * @param scopeTag the scope tag // * @param serviceTag the service tag // * @return whether the service can be looked up from the provided scope // */ // public boolean canFindFromScope(String scopeTag, String serviceTag) { // return scopeManager.canFindFromScope(scopeTag, serviceTag, ScopeLookupMode.ALL); // } // // /** // * Retrieves the service from the current scope or any of its parents, if the service exists. // * // * @param serviceTag the service tag // * @param <T> the type of the service // * @return the service // * @throws IllegalArgumentException if the service is not found in the scope or any of its parents // */ // @Nonnull // public <T> T lookupFromScope(String scopeTag, String serviceTag) { // return scopeManager.lookupFromScope(scopeTag, serviceTag, ScopeLookupMode.ALL); // } // // /** // * Returns the {@link Backstack} that manages the scopes. // * // * @return the backstack // */ // @Nonnull // public Backstack getBackstack() { // return scopeManager.getBackstack(); // } // }
import com.zhuinden.simplestack.ServiceBinder; import com.zhuinden.simplestackextensions.fragments.DefaultFragmentKey; import com.zhuinden.simplestackextensions.services.DefaultServiceProvider; import javax.annotation.Nonnull;
package com.zhuinden.simplestackexamplescoping.core.navigation; public abstract class BaseKey extends DefaultFragmentKey implements DefaultServiceProvider.HasServices { @Nonnull @Override public String getFragmentTag() { return toString(); } @Nonnull @Override public String getScopeTag() { return toString(); } @Override
// Path: simple-stack/src/main/java/com/zhuinden/simplestack/ServiceBinder.java // public class ServiceBinder { // private final ScopeManager scopeManager; // // private final Object key; // private final String scopeTag; // private final ScopeNode scope; // // ServiceBinder(ScopeManager scopeManager, Object key, String scopeTag, ScopeNode scope) { // this.scopeManager = scopeManager; // // this.key = key; // this.scopeTag = scopeTag; // this.scope = scope; // } // // /** // * Returns the key that this service binder was created for. // * // * @param <T> the type of the key // * @return the key // */ // @Nonnull // public <T> T getKey() { // //noinspection unchecked // return (T) key; // } // // /** // * Returns the scope tag this service binder belongs to. // * // * @return the scope tag // */ // @Nonnull // public final String getScopeTag() { // return scopeTag; // } // // /** // * Adds the service to the scope. // * // * @param serviceTag the tag of the service // * @param service the service // */ // public void addService(@Nonnull String serviceTag, @Nonnull Object service) { // scope.addService(serviceTag, service); // } // // /** // * Returns whether the service with given service tag is in the local scope. // * // * @param serviceTag the service tag // * @return if the service is in the scope // */ // public boolean hasService(@Nonnull String serviceTag) { // return scope.hasService(serviceTag); // } // // /** // * Retrieves the service from the local scope if it exists. // * // * @param serviceTag the service tag // * @param <T> the type of the service // * @return the service // * @throws IllegalArgumentException if the service is not in the scope // */ // @Nonnull // public <T> T getService(@Nonnull String serviceTag) { // return scope.getService(serviceTag); // } // // /** // * Adds an alias to the service within the local scope. Callbacks are not called for aliases, but they can be found as services. // * // * @param alias the alias // * @param service the service // */ // public void addAlias(@Nonnull String alias, @Nonnull Object service) { // scope.addAlias(alias, service); // } // // /** // * Returns whether the service can be found within the currently existing active scopes. // * // * @param serviceTag the service tag // * @return if the service exists in active scopes // */ // public boolean canFindService(@Nonnull String serviceTag) { // return scopeManager.canFindService(serviceTag); // } // // /** // * Retrieves the service from the active scopes if it exists. // * // * @param serviceTag the service tag // * @param <T> the type of the service // * @return the service // * @throws IllegalArgumentException if the service is not found in any active scopes // */ // @Nonnull // public <T> T lookupService(@Nonnull String serviceTag) { // return scopeManager.lookupService(serviceTag); // } // // /** // * Returns whether the service can be found if looked up from the provided scope. // * // * @param scopeTag the scope tag // * @param serviceTag the service tag // * @return whether the service can be looked up from the provided scope // */ // public boolean canFindFromScope(String scopeTag, String serviceTag) { // return scopeManager.canFindFromScope(scopeTag, serviceTag, ScopeLookupMode.ALL); // } // // /** // * Retrieves the service from the current scope or any of its parents, if the service exists. // * // * @param serviceTag the service tag // * @param <T> the type of the service // * @return the service // * @throws IllegalArgumentException if the service is not found in the scope or any of its parents // */ // @Nonnull // public <T> T lookupFromScope(String scopeTag, String serviceTag) { // return scopeManager.lookupFromScope(scopeTag, serviceTag, ScopeLookupMode.ALL); // } // // /** // * Returns the {@link Backstack} that manages the scopes. // * // * @return the backstack // */ // @Nonnull // public Backstack getBackstack() { // return scopeManager.getBackstack(); // } // } // Path: samples/scoping-samples/simple-stack-example-scoping-java/src/main/java/com/zhuinden/simplestackexamplescoping/core/navigation/BaseKey.java import com.zhuinden.simplestack.ServiceBinder; import com.zhuinden.simplestackextensions.fragments.DefaultFragmentKey; import com.zhuinden.simplestackextensions.services.DefaultServiceProvider; import javax.annotation.Nonnull; package com.zhuinden.simplestackexamplescoping.core.navigation; public abstract class BaseKey extends DefaultFragmentKey implements DefaultServiceProvider.HasServices { @Nonnull @Override public String getFragmentTag() { return toString(); } @Nonnull @Override public String getScopeTag() { return toString(); } @Override
public void bindServices(@Nonnull ServiceBinder serviceBinder) {
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/BackstackDelegateTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // }
import android.app.Activity; import android.app.Application; import android.content.Context; import android.os.Bundle; import android.os.Parcelable; import android.view.View; import com.zhuinden.simplestack.helpers.TestKey; import com.zhuinden.statebundle.StateBundle; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import javax.annotation.Nonnull; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail;
fail(); } catch(IllegalArgumentException e) { // OK! } } @Test public void setSamePersistenceTagTwiceShouldBeOk() { BackstackDelegate backstackDelegate = new BackstackDelegate(); backstackDelegate.setPersistenceTag(new String("hello")); backstackDelegate.setPersistenceTag(new String("hello")); // no exceptions thrown } @Test public void setTwoDifferentPersistenceTagsShouldThrow() { BackstackDelegate backstackDelegate = new BackstackDelegate(); backstackDelegate.setPersistenceTag(new String("hello")); try { backstackDelegate.setPersistenceTag(new String("world")); fail(); } catch(IllegalStateException e) { // OK! } } @Test public void setPersistenceTagAfterOnCreateShouldThrow() { BackstackDelegate backstackDelegate = new BackstackDelegate(); backstackDelegate.onCreate(null, null, new ArrayList<Object>() {{
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/BackstackDelegateTest.java import android.app.Activity; import android.app.Application; import android.content.Context; import android.os.Bundle; import android.os.Parcelable; import android.view.View; import com.zhuinden.simplestack.helpers.TestKey; import com.zhuinden.statebundle.StateBundle; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import javax.annotation.Nonnull; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; fail(); } catch(IllegalArgumentException e) { // OK! } } @Test public void setSamePersistenceTagTwiceShouldBeOk() { BackstackDelegate backstackDelegate = new BackstackDelegate(); backstackDelegate.setPersistenceTag(new String("hello")); backstackDelegate.setPersistenceTag(new String("hello")); // no exceptions thrown } @Test public void setTwoDifferentPersistenceTagsShouldThrow() { BackstackDelegate backstackDelegate = new BackstackDelegate(); backstackDelegate.setPersistenceTag(new String("hello")); try { backstackDelegate.setPersistenceTag(new String("world")); fail(); } catch(IllegalStateException e) { // OK! } } @Test public void setPersistenceTagAfterOnCreateShouldThrow() { BackstackDelegate backstackDelegate = new BackstackDelegate(); backstackDelegate.onCreate(null, null, new ArrayList<Object>() {{
add(new TestKey("hello"));
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/ScopingRegisteredCallbackTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasParentServices.java // public interface HasParentServices // extends ScopeKey.Child { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // }
import android.os.Parcel; import com.zhuinden.simplestack.helpers.HasParentServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import org.junit.Test; import java.util.ArrayList; import java.util.List; import java.util.Objects; import javax.annotation.Nonnull; import static org.assertj.core.api.Assertions.assertThat;
return true; } if(o == null || getClass() != o.getClass()) { return false; } Pair<?, ?> pair = (Pair<?, ?>) o; return Objects.equals(first, pair.first) && Objects.equals(second, pair.second); } @Override public int hashCode() { return Objects.hash(first, second); } @Override public String toString() { return "Pair{" + "first=" + first + ", second=" + second + '}'; } } @Test public void registeredWorks() { final List<Pair<Object, ? extends ServiceEvent>> events = new ArrayList<>(); Backstack backstack = new Backstack();
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasParentServices.java // public interface HasParentServices // extends ScopeKey.Child { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/ScopingRegisteredCallbackTest.java import android.os.Parcel; import com.zhuinden.simplestack.helpers.HasParentServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import org.junit.Test; import java.util.ArrayList; import java.util.List; import java.util.Objects; import javax.annotation.Nonnull; import static org.assertj.core.api.Assertions.assertThat; return true; } if(o == null || getClass() != o.getClass()) { return false; } Pair<?, ?> pair = (Pair<?, ?>) o; return Objects.equals(first, pair.first) && Objects.equals(second, pair.second); } @Override public int hashCode() { return Objects.hash(first, second); } @Override public String toString() { return "Pair{" + "first=" + first + ", second=" + second + '}'; } } @Test public void registeredWorks() { final List<Pair<Object, ? extends ServiceEvent>> events = new ArrayList<>(); Backstack backstack = new Backstack();
backstack.setScopedServices(new ServiceProvider());
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/ScopingRegisteredCallbackTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasParentServices.java // public interface HasParentServices // extends ScopeKey.Child { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // }
import android.os.Parcel; import com.zhuinden.simplestack.helpers.HasParentServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import org.junit.Test; import java.util.ArrayList; import java.util.List; import java.util.Objects; import javax.annotation.Nonnull; import static org.assertj.core.api.Assertions.assertThat;
final Object serviceShared0123P1P2P3 = new MyService("serviceShared0123P1P2P3"); backstack.setGlobalServices(GlobalServices.builder() .addService("service0", service0) .addService("serviceShared0123P1P2P3", serviceShared0123P1P2P3) .build()); final Object service1 = new MyService("service1"); final Object service2 = new MyService("service2"); final Object service3 = new MyService("service3"); final Object serviceShared12 = new MyService("serviceShared12"); final Object serviceShared13 = new MyService("serviceShared13"); final Object serviceShared23 = new MyService("serviceShared23"); final Object serviceShared123 = new MyService("serviceShared123"); final Object serviceShared1P1 = new MyService("serviceShared1P1"); final Object serviceShared1P2 = new MyService("serviceShared1P2"); final Object serviceShared1P3 = new MyService("serviceShared1P3"); final Object serviceShared2P1 = new MyService("serviceShared2P1"); final Object serviceShared2P2 = new MyService("serviceShared2P2"); final Object serviceShared2P3 = new MyService("serviceShared2P3"); final Object serviceShared3P1 = new MyService("serviceShared3P1"); final Object serviceShared3P2 = new MyService("serviceShared3P2"); final Object serviceShared3P3 = new MyService("serviceShared3P3"); final Object serviceP1 = new MyService("serviceP1"); final Object serviceP2 = new MyService("serviceP2"); final Object serviceP3 = new MyService("serviceP3");
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasParentServices.java // public interface HasParentServices // extends ScopeKey.Child { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/ScopingRegisteredCallbackTest.java import android.os.Parcel; import com.zhuinden.simplestack.helpers.HasParentServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import org.junit.Test; import java.util.ArrayList; import java.util.List; import java.util.Objects; import javax.annotation.Nonnull; import static org.assertj.core.api.Assertions.assertThat; final Object serviceShared0123P1P2P3 = new MyService("serviceShared0123P1P2P3"); backstack.setGlobalServices(GlobalServices.builder() .addService("service0", service0) .addService("serviceShared0123P1P2P3", serviceShared0123P1P2P3) .build()); final Object service1 = new MyService("service1"); final Object service2 = new MyService("service2"); final Object service3 = new MyService("service3"); final Object serviceShared12 = new MyService("serviceShared12"); final Object serviceShared13 = new MyService("serviceShared13"); final Object serviceShared23 = new MyService("serviceShared23"); final Object serviceShared123 = new MyService("serviceShared123"); final Object serviceShared1P1 = new MyService("serviceShared1P1"); final Object serviceShared1P2 = new MyService("serviceShared1P2"); final Object serviceShared1P3 = new MyService("serviceShared1P3"); final Object serviceShared2P1 = new MyService("serviceShared2P1"); final Object serviceShared2P2 = new MyService("serviceShared2P2"); final Object serviceShared2P3 = new MyService("serviceShared2P3"); final Object serviceShared3P1 = new MyService("serviceShared3P1"); final Object serviceShared3P2 = new MyService("serviceShared3P2"); final Object serviceShared3P3 = new MyService("serviceShared3P3"); final Object serviceP1 = new MyService("serviceP1"); final Object serviceP2 = new MyService("serviceP2"); final Object serviceP3 = new MyService("serviceP3");
TestKeyWithScope beep = new TestKeyWithScope("scope1") {
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/ScopingRegisteredCallbackTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasParentServices.java // public interface HasParentServices // extends ScopeKey.Child { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // }
import android.os.Parcel; import com.zhuinden.simplestack.helpers.HasParentServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import org.junit.Test; import java.util.ArrayList; import java.util.List; import java.util.Objects; import javax.annotation.Nonnull; import static org.assertj.core.api.Assertions.assertThat;
final Object serviceShared1P2 = new MyService("serviceShared1P2"); final Object serviceShared1P3 = new MyService("serviceShared1P3"); final Object serviceShared2P1 = new MyService("serviceShared2P1"); final Object serviceShared2P2 = new MyService("serviceShared2P2"); final Object serviceShared2P3 = new MyService("serviceShared2P3"); final Object serviceShared3P1 = new MyService("serviceShared3P1"); final Object serviceShared3P2 = new MyService("serviceShared3P2"); final Object serviceShared3P3 = new MyService("serviceShared3P3"); final Object serviceP1 = new MyService("serviceP1"); final Object serviceP2 = new MyService("serviceP2"); final Object serviceP3 = new MyService("serviceP3"); TestKeyWithScope beep = new TestKeyWithScope("scope1") { @Override public void bindServices(ServiceBinder serviceBinder) { assertThat(serviceBinder.getScopeTag()).isEqualTo(getScopeTag()); serviceBinder.addService("service1", service1); serviceBinder.addService("serviceShared12", serviceShared12); serviceBinder.addService("serviceShared13", serviceShared13); serviceBinder.addService("serviceShared123", serviceShared123); serviceBinder.addService("serviceShared1P1", serviceShared1P1); serviceBinder.addService("serviceShared1P2", serviceShared1P2); serviceBinder.addService("serviceShared1P3", serviceShared1P3); serviceBinder.addService("serviceShared0123P1P2P3", serviceShared0123P1P2P3); } };
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasParentServices.java // public interface HasParentServices // extends ScopeKey.Child { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/ScopingRegisteredCallbackTest.java import android.os.Parcel; import com.zhuinden.simplestack.helpers.HasParentServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import org.junit.Test; import java.util.ArrayList; import java.util.List; import java.util.Objects; import javax.annotation.Nonnull; import static org.assertj.core.api.Assertions.assertThat; final Object serviceShared1P2 = new MyService("serviceShared1P2"); final Object serviceShared1P3 = new MyService("serviceShared1P3"); final Object serviceShared2P1 = new MyService("serviceShared2P1"); final Object serviceShared2P2 = new MyService("serviceShared2P2"); final Object serviceShared2P3 = new MyService("serviceShared2P3"); final Object serviceShared3P1 = new MyService("serviceShared3P1"); final Object serviceShared3P2 = new MyService("serviceShared3P2"); final Object serviceShared3P3 = new MyService("serviceShared3P3"); final Object serviceP1 = new MyService("serviceP1"); final Object serviceP2 = new MyService("serviceP2"); final Object serviceP3 = new MyService("serviceP3"); TestKeyWithScope beep = new TestKeyWithScope("scope1") { @Override public void bindServices(ServiceBinder serviceBinder) { assertThat(serviceBinder.getScopeTag()).isEqualTo(getScopeTag()); serviceBinder.addService("service1", service1); serviceBinder.addService("serviceShared12", serviceShared12); serviceBinder.addService("serviceShared13", serviceShared13); serviceBinder.addService("serviceShared123", serviceShared123); serviceBinder.addService("serviceShared1P1", serviceShared1P1); serviceBinder.addService("serviceShared1P2", serviceShared1P2); serviceBinder.addService("serviceShared1P3", serviceShared1P3); serviceBinder.addService("serviceShared0123P1P2P3", serviceShared0123P1P2P3); } };
abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices {
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/HistoryBuilderTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // }
import com.zhuinden.simplestack.helpers.TestKey; import org.junit.Assert; import org.junit.Test; import java.util.Arrays; import java.util.List; import static org.assertj.core.api.Assertions.assertThat;
/* * Copyright 2017 Gabor Varadi * * 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.zhuinden.simplestack; /** * Created by Owner on 2017. 01. 20.. */ public class HistoryBuilderTest { @Test public void historyBuilderThrowsForNullBackstack() { try { History.Builder historyBuilder = History.builderFrom((Backstack) null); Assert.fail(); } catch(IllegalArgumentException e) { // OK! } } @Test public void historyBuilderThrowsForAddingNull() { History.Builder historyBuilder = History.newBuilder(); try { historyBuilder.add(null); Assert.fail(); } catch(IllegalArgumentException e) { // OK! } } @Test public void historyBuilderThrowsFromNull() { try { History.builderFrom(Arrays.asList(null, null)); Assert.fail(); } catch(IllegalArgumentException e) { // OK! } } @Test public void removeUntilThrowsIfKeyNotFound() { try {
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/HistoryBuilderTest.java import com.zhuinden.simplestack.helpers.TestKey; import org.junit.Assert; import org.junit.Test; import java.util.Arrays; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; /* * Copyright 2017 Gabor Varadi * * 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.zhuinden.simplestack; /** * Created by Owner on 2017. 01. 20.. */ public class HistoryBuilderTest { @Test public void historyBuilderThrowsForNullBackstack() { try { History.Builder historyBuilder = History.builderFrom((Backstack) null); Assert.fail(); } catch(IllegalArgumentException e) { // OK! } } @Test public void historyBuilderThrowsForAddingNull() { History.Builder historyBuilder = History.newBuilder(); try { historyBuilder.add(null); Assert.fail(); } catch(IllegalArgumentException e) { // OK! } } @Test public void historyBuilderThrowsFromNull() { try { History.builderFrom(Arrays.asList(null, null)); Assert.fail(); } catch(IllegalArgumentException e) { // OK! } } @Test public void removeUntilThrowsIfKeyNotFound() { try {
History.Builder builder = History.newBuilder().add(new TestKey("hello"));
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/BackstackTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithExplicitParent.java // public abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices { // public TestKeyWithExplicitParent(String name) { // super(name); // } // // protected TestKeyWithExplicitParent(Parcel in) { // super(in); // } // // @Override // public final void bindServices(ServiceBinder serviceBinder) { // if(name.equals(serviceBinder.getScopeTag())) { // bindOwnServices(serviceBinder); // } else { // bindParentServices(serviceBinder); // } // } // // protected abstract void bindParentServices(ServiceBinder serviceBinder); // // protected abstract void bindOwnServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithOnlyParentServices.java // public abstract class TestKeyWithOnlyParentServices extends TestKey implements HasParentServices { // private final List<String> parentScopes; // // public TestKeyWithOnlyParentServices(String name, List<String> parentScopes) { // super(name); // this.parentScopes = parentScopes; // } // // @Nonnull // @Override // public List<String> getParentScopes() { // return parentScopes; // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // }
import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static org.assertj.core.api.Assertions.assertThat; import android.content.Context; import android.os.Parcelable; import android.view.View; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent; import com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import com.zhuinden.statebundle.StateBundle; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito;
/* * Copyright 2017 Gabor Varadi * * 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.zhuinden.simplestack; /** * Created by Owner on 2017. 03. 25.. */ public class BackstackTest { StateChanger stateChanger = new StateChanger() { @Override public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) { completionCallback.stateChangeComplete(); } }; @Test public void afterClearAndRestorationTheInitialKeysShouldBeRestoredAndNotOverwrittenByRestoredState() {
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithExplicitParent.java // public abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices { // public TestKeyWithExplicitParent(String name) { // super(name); // } // // protected TestKeyWithExplicitParent(Parcel in) { // super(in); // } // // @Override // public final void bindServices(ServiceBinder serviceBinder) { // if(name.equals(serviceBinder.getScopeTag())) { // bindOwnServices(serviceBinder); // } else { // bindParentServices(serviceBinder); // } // } // // protected abstract void bindParentServices(ServiceBinder serviceBinder); // // protected abstract void bindOwnServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithOnlyParentServices.java // public abstract class TestKeyWithOnlyParentServices extends TestKey implements HasParentServices { // private final List<String> parentScopes; // // public TestKeyWithOnlyParentServices(String name, List<String> parentScopes) { // super(name); // this.parentScopes = parentScopes; // } // // @Nonnull // @Override // public List<String> getParentScopes() { // return parentScopes; // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/BackstackTest.java import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static org.assertj.core.api.Assertions.assertThat; import android.content.Context; import android.os.Parcelable; import android.view.View; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent; import com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import com.zhuinden.statebundle.StateBundle; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; /* * Copyright 2017 Gabor Varadi * * 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.zhuinden.simplestack; /** * Created by Owner on 2017. 03. 25.. */ public class BackstackTest { StateChanger stateChanger = new StateChanger() { @Override public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) { completionCallback.stateChangeComplete(); } }; @Test public void afterClearAndRestorationTheInitialKeysShouldBeRestoredAndNotOverwrittenByRestoredState() {
TestKey initial = new TestKey("initial");
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/BackstackTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithExplicitParent.java // public abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices { // public TestKeyWithExplicitParent(String name) { // super(name); // } // // protected TestKeyWithExplicitParent(Parcel in) { // super(in); // } // // @Override // public final void bindServices(ServiceBinder serviceBinder) { // if(name.equals(serviceBinder.getScopeTag())) { // bindOwnServices(serviceBinder); // } else { // bindParentServices(serviceBinder); // } // } // // protected abstract void bindParentServices(ServiceBinder serviceBinder); // // protected abstract void bindOwnServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithOnlyParentServices.java // public abstract class TestKeyWithOnlyParentServices extends TestKey implements HasParentServices { // private final List<String> parentScopes; // // public TestKeyWithOnlyParentServices(String name, List<String> parentScopes) { // super(name); // this.parentScopes = parentScopes; // } // // @Nonnull // @Override // public List<String> getParentScopes() { // return parentScopes; // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // }
import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static org.assertj.core.api.Assertions.assertThat; import android.content.Context; import android.os.Parcelable; import android.view.View; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent; import com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import com.zhuinden.statebundle.StateBundle; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito;
} }; backstack.setStateChanger(stateChanger); backstack.removeStateChanger(); backstack.setHistory(History.of(key2), StateChange.REPLACE); backstack.removeAllStateChangeCompletionListeners(); backstack.setStateChanger(stateChanger); backstack.setHistory(History.of(key3), StateChange.REPLACE); assertThat(service1.isActivatedCalled).isTrue(); assertThat(service1.isDeactivatedCalled).isTrue(); assertThat(service1.isRegisteredCalled).isTrue(); assertThat(service1.isUnregisteredCalled).isTrue(); assertThat(service2.isRegisteredCalled).isTrue(); assertThat(service2.isUnregisteredCalled).isTrue(); assertThat(service2.isActivatedCalled).isTrue(); assertThat(service2.isDeactivatedCalled).isTrue(); } @Test public void exitScopeThrowsWhenBackstackIsEmpty() { Backstack backstack = new Backstack();
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithExplicitParent.java // public abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices { // public TestKeyWithExplicitParent(String name) { // super(name); // } // // protected TestKeyWithExplicitParent(Parcel in) { // super(in); // } // // @Override // public final void bindServices(ServiceBinder serviceBinder) { // if(name.equals(serviceBinder.getScopeTag())) { // bindOwnServices(serviceBinder); // } else { // bindParentServices(serviceBinder); // } // } // // protected abstract void bindParentServices(ServiceBinder serviceBinder); // // protected abstract void bindOwnServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithOnlyParentServices.java // public abstract class TestKeyWithOnlyParentServices extends TestKey implements HasParentServices { // private final List<String> parentScopes; // // public TestKeyWithOnlyParentServices(String name, List<String> parentScopes) { // super(name); // this.parentScopes = parentScopes; // } // // @Nonnull // @Override // public List<String> getParentScopes() { // return parentScopes; // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/BackstackTest.java import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static org.assertj.core.api.Assertions.assertThat; import android.content.Context; import android.os.Parcelable; import android.view.View; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent; import com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import com.zhuinden.statebundle.StateBundle; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; } }; backstack.setStateChanger(stateChanger); backstack.removeStateChanger(); backstack.setHistory(History.of(key2), StateChange.REPLACE); backstack.removeAllStateChangeCompletionListeners(); backstack.setStateChanger(stateChanger); backstack.setHistory(History.of(key3), StateChange.REPLACE); assertThat(service1.isActivatedCalled).isTrue(); assertThat(service1.isDeactivatedCalled).isTrue(); assertThat(service1.isRegisteredCalled).isTrue(); assertThat(service1.isUnregisteredCalled).isTrue(); assertThat(service2.isRegisteredCalled).isTrue(); assertThat(service2.isUnregisteredCalled).isTrue(); assertThat(service2.isActivatedCalled).isTrue(); assertThat(service2.isDeactivatedCalled).isTrue(); } @Test public void exitScopeThrowsWhenBackstackIsEmpty() { Backstack backstack = new Backstack();
backstack.setScopedServices(new ServiceProvider());
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/BackstackTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithExplicitParent.java // public abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices { // public TestKeyWithExplicitParent(String name) { // super(name); // } // // protected TestKeyWithExplicitParent(Parcel in) { // super(in); // } // // @Override // public final void bindServices(ServiceBinder serviceBinder) { // if(name.equals(serviceBinder.getScopeTag())) { // bindOwnServices(serviceBinder); // } else { // bindParentServices(serviceBinder); // } // } // // protected abstract void bindParentServices(ServiceBinder serviceBinder); // // protected abstract void bindOwnServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithOnlyParentServices.java // public abstract class TestKeyWithOnlyParentServices extends TestKey implements HasParentServices { // private final List<String> parentScopes; // // public TestKeyWithOnlyParentServices(String name, List<String> parentScopes) { // super(name); // this.parentScopes = parentScopes; // } // // @Nonnull // @Override // public List<String> getParentScopes() { // return parentScopes; // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // }
import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static org.assertj.core.api.Assertions.assertThat; import android.content.Context; import android.os.Parcelable; import android.view.View; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent; import com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import com.zhuinden.statebundle.StateBundle; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito;
backstack.setStateChanger(stateChanger); backstack.removeStateChanger(); backstack.setHistory(History.of(key2), StateChange.REPLACE); backstack.removeAllStateChangeCompletionListeners(); backstack.setStateChanger(stateChanger); backstack.setHistory(History.of(key3), StateChange.REPLACE); assertThat(service1.isActivatedCalled).isTrue(); assertThat(service1.isDeactivatedCalled).isTrue(); assertThat(service1.isRegisteredCalled).isTrue(); assertThat(service1.isUnregisteredCalled).isTrue(); assertThat(service2.isRegisteredCalled).isTrue(); assertThat(service2.isUnregisteredCalled).isTrue(); assertThat(service2.isActivatedCalled).isTrue(); assertThat(service2.isDeactivatedCalled).isTrue(); } @Test public void exitScopeThrowsWhenBackstackIsEmpty() { Backstack backstack = new Backstack(); backstack.setScopedServices(new ServiceProvider());
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithExplicitParent.java // public abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices { // public TestKeyWithExplicitParent(String name) { // super(name); // } // // protected TestKeyWithExplicitParent(Parcel in) { // super(in); // } // // @Override // public final void bindServices(ServiceBinder serviceBinder) { // if(name.equals(serviceBinder.getScopeTag())) { // bindOwnServices(serviceBinder); // } else { // bindParentServices(serviceBinder); // } // } // // protected abstract void bindParentServices(ServiceBinder serviceBinder); // // protected abstract void bindOwnServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithOnlyParentServices.java // public abstract class TestKeyWithOnlyParentServices extends TestKey implements HasParentServices { // private final List<String> parentScopes; // // public TestKeyWithOnlyParentServices(String name, List<String> parentScopes) { // super(name); // this.parentScopes = parentScopes; // } // // @Nonnull // @Override // public List<String> getParentScopes() { // return parentScopes; // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/BackstackTest.java import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static org.assertj.core.api.Assertions.assertThat; import android.content.Context; import android.os.Parcelable; import android.view.View; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent; import com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import com.zhuinden.statebundle.StateBundle; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; backstack.setStateChanger(stateChanger); backstack.removeStateChanger(); backstack.setHistory(History.of(key2), StateChange.REPLACE); backstack.removeAllStateChangeCompletionListeners(); backstack.setStateChanger(stateChanger); backstack.setHistory(History.of(key3), StateChange.REPLACE); assertThat(service1.isActivatedCalled).isTrue(); assertThat(service1.isDeactivatedCalled).isTrue(); assertThat(service1.isRegisteredCalled).isTrue(); assertThat(service1.isUnregisteredCalled).isTrue(); assertThat(service2.isRegisteredCalled).isTrue(); assertThat(service2.isUnregisteredCalled).isTrue(); assertThat(service2.isActivatedCalled).isTrue(); assertThat(service2.isDeactivatedCalled).isTrue(); } @Test public void exitScopeThrowsWhenBackstackIsEmpty() { Backstack backstack = new Backstack(); backstack.setScopedServices(new ServiceProvider());
Object key = new TestKeyWithScope("blah") {
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/BackstackTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithExplicitParent.java // public abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices { // public TestKeyWithExplicitParent(String name) { // super(name); // } // // protected TestKeyWithExplicitParent(Parcel in) { // super(in); // } // // @Override // public final void bindServices(ServiceBinder serviceBinder) { // if(name.equals(serviceBinder.getScopeTag())) { // bindOwnServices(serviceBinder); // } else { // bindParentServices(serviceBinder); // } // } // // protected abstract void bindParentServices(ServiceBinder serviceBinder); // // protected abstract void bindOwnServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithOnlyParentServices.java // public abstract class TestKeyWithOnlyParentServices extends TestKey implements HasParentServices { // private final List<String> parentScopes; // // public TestKeyWithOnlyParentServices(String name, List<String> parentScopes) { // super(name); // this.parentScopes = parentScopes; // } // // @Nonnull // @Override // public List<String> getParentScopes() { // return parentScopes; // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // }
import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static org.assertj.core.api.Assertions.assertThat; import android.content.Context; import android.os.Parcelable; import android.view.View; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent; import com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import com.zhuinden.statebundle.StateBundle; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito;
Object lastKey = new TestKey("lastKey"); Object key = new TestKeyWithScope("blah") { @Override public void bindServices(ServiceBinder serviceBinder) { } }; backstack.setup(History.of(firstKey, key, lastKey)); backstack.setStateChanger(new StateChanger() { @Override public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) { completionCallback.stateChangeComplete(); } }); backstack.exitScope("blah"); assertThat(backstack.getHistory()).containsExactly(firstKey); } @Test public void exitScopeExitsExplicitScopeCorrectly() { Backstack backstack = new Backstack(); backstack.setScopedServices(new ServiceProvider()); Object firstKey = new TestKey("firstKey"); Object lastKey = new TestKey("lastKey");
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithExplicitParent.java // public abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices { // public TestKeyWithExplicitParent(String name) { // super(name); // } // // protected TestKeyWithExplicitParent(Parcel in) { // super(in); // } // // @Override // public final void bindServices(ServiceBinder serviceBinder) { // if(name.equals(serviceBinder.getScopeTag())) { // bindOwnServices(serviceBinder); // } else { // bindParentServices(serviceBinder); // } // } // // protected abstract void bindParentServices(ServiceBinder serviceBinder); // // protected abstract void bindOwnServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithOnlyParentServices.java // public abstract class TestKeyWithOnlyParentServices extends TestKey implements HasParentServices { // private final List<String> parentScopes; // // public TestKeyWithOnlyParentServices(String name, List<String> parentScopes) { // super(name); // this.parentScopes = parentScopes; // } // // @Nonnull // @Override // public List<String> getParentScopes() { // return parentScopes; // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/BackstackTest.java import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static org.assertj.core.api.Assertions.assertThat; import android.content.Context; import android.os.Parcelable; import android.view.View; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent; import com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import com.zhuinden.statebundle.StateBundle; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; Object lastKey = new TestKey("lastKey"); Object key = new TestKeyWithScope("blah") { @Override public void bindServices(ServiceBinder serviceBinder) { } }; backstack.setup(History.of(firstKey, key, lastKey)); backstack.setStateChanger(new StateChanger() { @Override public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) { completionCallback.stateChangeComplete(); } }); backstack.exitScope("blah"); assertThat(backstack.getHistory()).containsExactly(firstKey); } @Test public void exitScopeExitsExplicitScopeCorrectly() { Backstack backstack = new Backstack(); backstack.setScopedServices(new ServiceProvider()); Object firstKey = new TestKey("firstKey"); Object lastKey = new TestKey("lastKey");
Object key = new TestKeyWithOnlyParentServices("key", History.of("blah")) {
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/BackstackTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithExplicitParent.java // public abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices { // public TestKeyWithExplicitParent(String name) { // super(name); // } // // protected TestKeyWithExplicitParent(Parcel in) { // super(in); // } // // @Override // public final void bindServices(ServiceBinder serviceBinder) { // if(name.equals(serviceBinder.getScopeTag())) { // bindOwnServices(serviceBinder); // } else { // bindParentServices(serviceBinder); // } // } // // protected abstract void bindParentServices(ServiceBinder serviceBinder); // // protected abstract void bindOwnServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithOnlyParentServices.java // public abstract class TestKeyWithOnlyParentServices extends TestKey implements HasParentServices { // private final List<String> parentScopes; // // public TestKeyWithOnlyParentServices(String name, List<String> parentScopes) { // super(name); // this.parentScopes = parentScopes; // } // // @Nonnull // @Override // public List<String> getParentScopes() { // return parentScopes; // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // }
import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static org.assertj.core.api.Assertions.assertThat; import android.content.Context; import android.os.Parcelable; import android.view.View; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent; import com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import com.zhuinden.statebundle.StateBundle; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito;
Object key = new TestKeyWithOnlyParentServices("key", History.of("blah")) { @Override public void bindServices(ServiceBinder serviceBinder) { } }; backstack.setup(History.of(firstKey, key, lastKey)); backstack.setStateChanger(new StateChanger() { @Override public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) { completionCallback.stateChangeComplete(); } }); backstack.exitScope("blah"); assertThat(backstack.getHistory()).containsExactly(firstKey); } @Test public void exitScopeExitsExplicitScopesCorrectly() { Backstack backstack = new Backstack(); backstack.setScopedServices(new ServiceProvider()); Object firstKey = new TestKey("firstKey"); Object secondKey = new TestKey("secondKey"); Object lastKey = new TestKey("lastKey");
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithExplicitParent.java // public abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices { // public TestKeyWithExplicitParent(String name) { // super(name); // } // // protected TestKeyWithExplicitParent(Parcel in) { // super(in); // } // // @Override // public final void bindServices(ServiceBinder serviceBinder) { // if(name.equals(serviceBinder.getScopeTag())) { // bindOwnServices(serviceBinder); // } else { // bindParentServices(serviceBinder); // } // } // // protected abstract void bindParentServices(ServiceBinder serviceBinder); // // protected abstract void bindOwnServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithOnlyParentServices.java // public abstract class TestKeyWithOnlyParentServices extends TestKey implements HasParentServices { // private final List<String> parentScopes; // // public TestKeyWithOnlyParentServices(String name, List<String> parentScopes) { // super(name); // this.parentScopes = parentScopes; // } // // @Nonnull // @Override // public List<String> getParentScopes() { // return parentScopes; // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/BackstackTest.java import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static org.assertj.core.api.Assertions.assertThat; import android.content.Context; import android.os.Parcelable; import android.view.View; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent; import com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import com.zhuinden.statebundle.StateBundle; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; Object key = new TestKeyWithOnlyParentServices("key", History.of("blah")) { @Override public void bindServices(ServiceBinder serviceBinder) { } }; backstack.setup(History.of(firstKey, key, lastKey)); backstack.setStateChanger(new StateChanger() { @Override public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) { completionCallback.stateChangeComplete(); } }); backstack.exitScope("blah"); assertThat(backstack.getHistory()).containsExactly(firstKey); } @Test public void exitScopeExitsExplicitScopesCorrectly() { Backstack backstack = new Backstack(); backstack.setScopedServices(new ServiceProvider()); Object firstKey = new TestKey("firstKey"); Object secondKey = new TestKey("secondKey"); Object lastKey = new TestKey("lastKey");
Object key1 = new TestKeyWithExplicitParent("key1") {
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/HistoryTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // }
import com.zhuinden.simplestack.helpers.TestKey; import org.junit.Test; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import javax.annotation.Nonnull; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail;
/* * Copyright 2018 Gabor Varadi * * 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.zhuinden.simplestack; /** * Created by zhuinden on 2018. 03. 03.. */ public class HistoryTest { @Test public void from() throws Exception {
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/HistoryTest.java import com.zhuinden.simplestack.helpers.TestKey; import org.junit.Test; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import javax.annotation.Nonnull; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; /* * Copyright 2018 Gabor Varadi * * 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.zhuinden.simplestack; /** * Created by zhuinden on 2018. 03. 03.. */ public class HistoryTest { @Test public void from() throws Exception {
TestKey testKey1 = new TestKey("Hello");
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java
// Path: simple-stack/src/main/java/com/zhuinden/simplestack/ScopeKey.java // public interface ScopeKey { // /** // * Defines the tag of the scope this key defines the existence of. // * // * @return the tag of the scope // */ // @Nonnull // String getScopeTag(); // // /** // * Inheriting from {@link Child} enables defining an explicit parent hierarchy, thus ensuring that // * even if the scopes are not defined by the tags of any existing keys in the {@link Backstack}'s current {@link History}, // * the scopes will still be created, bound and shall exist. // * // * During {@link Backstack#lookupService(String)}, the explicit parents are traversed first, and implicit parents second. Implicit scope inheritance means that the previous keys' scopes will be traversed as well. // * // * If a {@link Child} is the top-most scope, then its explicit scopes are activated as well, so their services have {@link ScopedServices.Activated#onServiceActive()} called if they implement {@link com.zhuinden.simplestack.ScopedServices.Activated}. // */ // public interface Child { // /** // * Defines the hierarchy of the parent scope that ought to exist as explicit parents of this key. // * // * The order of the items matters: the top-most scope is the first, the bottom-most parent is the last. // * // * @return the list of scope tags that ought to serve as the key's hierarchy of explicit parents // */ // @Nonnull // List<String> getParentScopes(); // } // } // // Path: simple-stack/src/main/java/com/zhuinden/simplestack/ServiceBinder.java // public class ServiceBinder { // private final ScopeManager scopeManager; // // private final Object key; // private final String scopeTag; // private final ScopeNode scope; // // ServiceBinder(ScopeManager scopeManager, Object key, String scopeTag, ScopeNode scope) { // this.scopeManager = scopeManager; // // this.key = key; // this.scopeTag = scopeTag; // this.scope = scope; // } // // /** // * Returns the key that this service binder was created for. // * // * @param <T> the type of the key // * @return the key // */ // @Nonnull // public <T> T getKey() { // //noinspection unchecked // return (T) key; // } // // /** // * Returns the scope tag this service binder belongs to. // * // * @return the scope tag // */ // @Nonnull // public final String getScopeTag() { // return scopeTag; // } // // /** // * Adds the service to the scope. // * // * @param serviceTag the tag of the service // * @param service the service // */ // public void addService(@Nonnull String serviceTag, @Nonnull Object service) { // scope.addService(serviceTag, service); // } // // /** // * Returns whether the service with given service tag is in the local scope. // * // * @param serviceTag the service tag // * @return if the service is in the scope // */ // public boolean hasService(@Nonnull String serviceTag) { // return scope.hasService(serviceTag); // } // // /** // * Retrieves the service from the local scope if it exists. // * // * @param serviceTag the service tag // * @param <T> the type of the service // * @return the service // * @throws IllegalArgumentException if the service is not in the scope // */ // @Nonnull // public <T> T getService(@Nonnull String serviceTag) { // return scope.getService(serviceTag); // } // // /** // * Adds an alias to the service within the local scope. Callbacks are not called for aliases, but they can be found as services. // * // * @param alias the alias // * @param service the service // */ // public void addAlias(@Nonnull String alias, @Nonnull Object service) { // scope.addAlias(alias, service); // } // // /** // * Returns whether the service can be found within the currently existing active scopes. // * // * @param serviceTag the service tag // * @return if the service exists in active scopes // */ // public boolean canFindService(@Nonnull String serviceTag) { // return scopeManager.canFindService(serviceTag); // } // // /** // * Retrieves the service from the active scopes if it exists. // * // * @param serviceTag the service tag // * @param <T> the type of the service // * @return the service // * @throws IllegalArgumentException if the service is not found in any active scopes // */ // @Nonnull // public <T> T lookupService(@Nonnull String serviceTag) { // return scopeManager.lookupService(serviceTag); // } // // /** // * Returns whether the service can be found if looked up from the provided scope. // * // * @param scopeTag the scope tag // * @param serviceTag the service tag // * @return whether the service can be looked up from the provided scope // */ // public boolean canFindFromScope(String scopeTag, String serviceTag) { // return scopeManager.canFindFromScope(scopeTag, serviceTag, ScopeLookupMode.ALL); // } // // /** // * Retrieves the service from the current scope or any of its parents, if the service exists. // * // * @param serviceTag the service tag // * @param <T> the type of the service // * @return the service // * @throws IllegalArgumentException if the service is not found in the scope or any of its parents // */ // @Nonnull // public <T> T lookupFromScope(String scopeTag, String serviceTag) { // return scopeManager.lookupFromScope(scopeTag, serviceTag, ScopeLookupMode.ALL); // } // // /** // * Returns the {@link Backstack} that manages the scopes. // * // * @return the backstack // */ // @Nonnull // public Backstack getBackstack() { // return scopeManager.getBackstack(); // } // }
import com.zhuinden.simplestack.ScopeKey; import com.zhuinden.simplestack.ServiceBinder;
package com.zhuinden.simplestack.helpers; public interface HasServices extends ScopeKey {
// Path: simple-stack/src/main/java/com/zhuinden/simplestack/ScopeKey.java // public interface ScopeKey { // /** // * Defines the tag of the scope this key defines the existence of. // * // * @return the tag of the scope // */ // @Nonnull // String getScopeTag(); // // /** // * Inheriting from {@link Child} enables defining an explicit parent hierarchy, thus ensuring that // * even if the scopes are not defined by the tags of any existing keys in the {@link Backstack}'s current {@link History}, // * the scopes will still be created, bound and shall exist. // * // * During {@link Backstack#lookupService(String)}, the explicit parents are traversed first, and implicit parents second. Implicit scope inheritance means that the previous keys' scopes will be traversed as well. // * // * If a {@link Child} is the top-most scope, then its explicit scopes are activated as well, so their services have {@link ScopedServices.Activated#onServiceActive()} called if they implement {@link com.zhuinden.simplestack.ScopedServices.Activated}. // */ // public interface Child { // /** // * Defines the hierarchy of the parent scope that ought to exist as explicit parents of this key. // * // * The order of the items matters: the top-most scope is the first, the bottom-most parent is the last. // * // * @return the list of scope tags that ought to serve as the key's hierarchy of explicit parents // */ // @Nonnull // List<String> getParentScopes(); // } // } // // Path: simple-stack/src/main/java/com/zhuinden/simplestack/ServiceBinder.java // public class ServiceBinder { // private final ScopeManager scopeManager; // // private final Object key; // private final String scopeTag; // private final ScopeNode scope; // // ServiceBinder(ScopeManager scopeManager, Object key, String scopeTag, ScopeNode scope) { // this.scopeManager = scopeManager; // // this.key = key; // this.scopeTag = scopeTag; // this.scope = scope; // } // // /** // * Returns the key that this service binder was created for. // * // * @param <T> the type of the key // * @return the key // */ // @Nonnull // public <T> T getKey() { // //noinspection unchecked // return (T) key; // } // // /** // * Returns the scope tag this service binder belongs to. // * // * @return the scope tag // */ // @Nonnull // public final String getScopeTag() { // return scopeTag; // } // // /** // * Adds the service to the scope. // * // * @param serviceTag the tag of the service // * @param service the service // */ // public void addService(@Nonnull String serviceTag, @Nonnull Object service) { // scope.addService(serviceTag, service); // } // // /** // * Returns whether the service with given service tag is in the local scope. // * // * @param serviceTag the service tag // * @return if the service is in the scope // */ // public boolean hasService(@Nonnull String serviceTag) { // return scope.hasService(serviceTag); // } // // /** // * Retrieves the service from the local scope if it exists. // * // * @param serviceTag the service tag // * @param <T> the type of the service // * @return the service // * @throws IllegalArgumentException if the service is not in the scope // */ // @Nonnull // public <T> T getService(@Nonnull String serviceTag) { // return scope.getService(serviceTag); // } // // /** // * Adds an alias to the service within the local scope. Callbacks are not called for aliases, but they can be found as services. // * // * @param alias the alias // * @param service the service // */ // public void addAlias(@Nonnull String alias, @Nonnull Object service) { // scope.addAlias(alias, service); // } // // /** // * Returns whether the service can be found within the currently existing active scopes. // * // * @param serviceTag the service tag // * @return if the service exists in active scopes // */ // public boolean canFindService(@Nonnull String serviceTag) { // return scopeManager.canFindService(serviceTag); // } // // /** // * Retrieves the service from the active scopes if it exists. // * // * @param serviceTag the service tag // * @param <T> the type of the service // * @return the service // * @throws IllegalArgumentException if the service is not found in any active scopes // */ // @Nonnull // public <T> T lookupService(@Nonnull String serviceTag) { // return scopeManager.lookupService(serviceTag); // } // // /** // * Returns whether the service can be found if looked up from the provided scope. // * // * @param scopeTag the scope tag // * @param serviceTag the service tag // * @return whether the service can be looked up from the provided scope // */ // public boolean canFindFromScope(String scopeTag, String serviceTag) { // return scopeManager.canFindFromScope(scopeTag, serviceTag, ScopeLookupMode.ALL); // } // // /** // * Retrieves the service from the current scope or any of its parents, if the service exists. // * // * @param serviceTag the service tag // * @param <T> the type of the service // * @return the service // * @throws IllegalArgumentException if the service is not found in the scope or any of its parents // */ // @Nonnull // public <T> T lookupFromScope(String scopeTag, String serviceTag) { // return scopeManager.lookupFromScope(scopeTag, serviceTag, ScopeLookupMode.ALL); // } // // /** // * Returns the {@link Backstack} that manages the scopes. // * // * @return the backstack // */ // @Nonnull // public Backstack getBackstack() { // return scopeManager.getBackstack(); // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java import com.zhuinden.simplestack.ScopeKey; import com.zhuinden.simplestack.ServiceBinder; package com.zhuinden.simplestack.helpers; public interface HasServices extends ScopeKey {
void bindServices(ServiceBinder serviceBinder);
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/ScopeLookupModeTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/Action.java // public interface Action { // public void doSomething(); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasParentServices.java // public interface HasParentServices // extends ScopeKey.Child { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java // public interface HasServices // extends ScopeKey { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/AssertionHelper.java // public static void assertThrows(Action action) { // try { // action.doSomething(); // Assert.fail("Did not throw exception."); // } catch(Exception e) { // // OK! // } // }
import static org.assertj.core.api.Assertions.assertThat; import android.os.Parcel; import com.zhuinden.simplestack.helpers.Action; import com.zhuinden.simplestack.helpers.HasParentServices; import com.zhuinden.simplestack.helpers.HasServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import org.junit.Test; import java.util.List; import javax.annotation.Nonnull; import static com.zhuinden.simplestack.helpers.AssertionHelper.assertThrows;
/* * Copyright 2019 Gabor Varadi * * 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.zhuinden.simplestack; public class ScopeLookupModeTest { @Test public void lookupModesWork() { final Backstack backstack = new Backstack();
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/Action.java // public interface Action { // public void doSomething(); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasParentServices.java // public interface HasParentServices // extends ScopeKey.Child { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java // public interface HasServices // extends ScopeKey { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/AssertionHelper.java // public static void assertThrows(Action action) { // try { // action.doSomething(); // Assert.fail("Did not throw exception."); // } catch(Exception e) { // // OK! // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/ScopeLookupModeTest.java import static org.assertj.core.api.Assertions.assertThat; import android.os.Parcel; import com.zhuinden.simplestack.helpers.Action; import com.zhuinden.simplestack.helpers.HasParentServices; import com.zhuinden.simplestack.helpers.HasServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import org.junit.Test; import java.util.List; import javax.annotation.Nonnull; import static com.zhuinden.simplestack.helpers.AssertionHelper.assertThrows; /* * Copyright 2019 Gabor Varadi * * 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.zhuinden.simplestack; public class ScopeLookupModeTest { @Test public void lookupModesWork() { final Backstack backstack = new Backstack();
backstack.setScopedServices(new ServiceProvider());
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/ScopeLookupModeTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/Action.java // public interface Action { // public void doSomething(); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasParentServices.java // public interface HasParentServices // extends ScopeKey.Child { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java // public interface HasServices // extends ScopeKey { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/AssertionHelper.java // public static void assertThrows(Action action) { // try { // action.doSomething(); // Assert.fail("Did not throw exception."); // } catch(Exception e) { // // OK! // } // }
import static org.assertj.core.api.Assertions.assertThat; import android.os.Parcel; import com.zhuinden.simplestack.helpers.Action; import com.zhuinden.simplestack.helpers.HasParentServices; import com.zhuinden.simplestack.helpers.HasServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import org.junit.Test; import java.util.List; import javax.annotation.Nonnull; import static com.zhuinden.simplestack.helpers.AssertionHelper.assertThrows;
/* * Copyright 2019 Gabor Varadi * * 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.zhuinden.simplestack; public class ScopeLookupModeTest { @Test public void lookupModesWork() { final Backstack backstack = new Backstack(); backstack.setScopedServices(new ServiceProvider()); final Object parentService1 = new Object(); final Object parentService2 = new Object(); final Object service1 = new Object(); final Object service2 = new Object(); class Key1
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/Action.java // public interface Action { // public void doSomething(); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasParentServices.java // public interface HasParentServices // extends ScopeKey.Child { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java // public interface HasServices // extends ScopeKey { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/AssertionHelper.java // public static void assertThrows(Action action) { // try { // action.doSomething(); // Assert.fail("Did not throw exception."); // } catch(Exception e) { // // OK! // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/ScopeLookupModeTest.java import static org.assertj.core.api.Assertions.assertThat; import android.os.Parcel; import com.zhuinden.simplestack.helpers.Action; import com.zhuinden.simplestack.helpers.HasParentServices; import com.zhuinden.simplestack.helpers.HasServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import org.junit.Test; import java.util.List; import javax.annotation.Nonnull; import static com.zhuinden.simplestack.helpers.AssertionHelper.assertThrows; /* * Copyright 2019 Gabor Varadi * * 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.zhuinden.simplestack; public class ScopeLookupModeTest { @Test public void lookupModesWork() { final Backstack backstack = new Backstack(); backstack.setScopedServices(new ServiceProvider()); final Object parentService1 = new Object(); final Object parentService2 = new Object(); final Object service1 = new Object(); final Object service2 = new Object(); class Key1
extends TestKey
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/ScopeLookupModeTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/Action.java // public interface Action { // public void doSomething(); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasParentServices.java // public interface HasParentServices // extends ScopeKey.Child { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java // public interface HasServices // extends ScopeKey { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/AssertionHelper.java // public static void assertThrows(Action action) { // try { // action.doSomething(); // Assert.fail("Did not throw exception."); // } catch(Exception e) { // // OK! // } // }
import static org.assertj.core.api.Assertions.assertThat; import android.os.Parcel; import com.zhuinden.simplestack.helpers.Action; import com.zhuinden.simplestack.helpers.HasParentServices; import com.zhuinden.simplestack.helpers.HasServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import org.junit.Test; import java.util.List; import javax.annotation.Nonnull; import static com.zhuinden.simplestack.helpers.AssertionHelper.assertThrows;
/* * Copyright 2019 Gabor Varadi * * 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.zhuinden.simplestack; public class ScopeLookupModeTest { @Test public void lookupModesWork() { final Backstack backstack = new Backstack(); backstack.setScopedServices(new ServiceProvider()); final Object parentService1 = new Object(); final Object parentService2 = new Object(); final Object service1 = new Object(); final Object service2 = new Object(); class Key1 extends TestKey
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/Action.java // public interface Action { // public void doSomething(); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasParentServices.java // public interface HasParentServices // extends ScopeKey.Child { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java // public interface HasServices // extends ScopeKey { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/AssertionHelper.java // public static void assertThrows(Action action) { // try { // action.doSomething(); // Assert.fail("Did not throw exception."); // } catch(Exception e) { // // OK! // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/ScopeLookupModeTest.java import static org.assertj.core.api.Assertions.assertThat; import android.os.Parcel; import com.zhuinden.simplestack.helpers.Action; import com.zhuinden.simplestack.helpers.HasParentServices; import com.zhuinden.simplestack.helpers.HasServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import org.junit.Test; import java.util.List; import javax.annotation.Nonnull; import static com.zhuinden.simplestack.helpers.AssertionHelper.assertThrows; /* * Copyright 2019 Gabor Varadi * * 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.zhuinden.simplestack; public class ScopeLookupModeTest { @Test public void lookupModesWork() { final Backstack backstack = new Backstack(); backstack.setScopedServices(new ServiceProvider()); final Object parentService1 = new Object(); final Object parentService2 = new Object(); final Object service1 = new Object(); final Object service2 = new Object(); class Key1 extends TestKey
implements HasServices, HasParentServices {
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/ScopeLookupModeTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/Action.java // public interface Action { // public void doSomething(); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasParentServices.java // public interface HasParentServices // extends ScopeKey.Child { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java // public interface HasServices // extends ScopeKey { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/AssertionHelper.java // public static void assertThrows(Action action) { // try { // action.doSomething(); // Assert.fail("Did not throw exception."); // } catch(Exception e) { // // OK! // } // }
import static org.assertj.core.api.Assertions.assertThat; import android.os.Parcel; import com.zhuinden.simplestack.helpers.Action; import com.zhuinden.simplestack.helpers.HasParentServices; import com.zhuinden.simplestack.helpers.HasServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import org.junit.Test; import java.util.List; import javax.annotation.Nonnull; import static com.zhuinden.simplestack.helpers.AssertionHelper.assertThrows;
/* * Copyright 2019 Gabor Varadi * * 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.zhuinden.simplestack; public class ScopeLookupModeTest { @Test public void lookupModesWork() { final Backstack backstack = new Backstack(); backstack.setScopedServices(new ServiceProvider()); final Object parentService1 = new Object(); final Object parentService2 = new Object(); final Object service1 = new Object(); final Object service2 = new Object(); class Key1 extends TestKey
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/Action.java // public interface Action { // public void doSomething(); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasParentServices.java // public interface HasParentServices // extends ScopeKey.Child { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java // public interface HasServices // extends ScopeKey { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/AssertionHelper.java // public static void assertThrows(Action action) { // try { // action.doSomething(); // Assert.fail("Did not throw exception."); // } catch(Exception e) { // // OK! // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/ScopeLookupModeTest.java import static org.assertj.core.api.Assertions.assertThat; import android.os.Parcel; import com.zhuinden.simplestack.helpers.Action; import com.zhuinden.simplestack.helpers.HasParentServices; import com.zhuinden.simplestack.helpers.HasServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import org.junit.Test; import java.util.List; import javax.annotation.Nonnull; import static com.zhuinden.simplestack.helpers.AssertionHelper.assertThrows; /* * Copyright 2019 Gabor Varadi * * 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.zhuinden.simplestack; public class ScopeLookupModeTest { @Test public void lookupModesWork() { final Backstack backstack = new Backstack(); backstack.setScopedServices(new ServiceProvider()); final Object parentService1 = new Object(); final Object parentService2 = new Object(); final Object service1 = new Object(); final Object service2 = new Object(); class Key1 extends TestKey
implements HasServices, HasParentServices {
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/ScopeLookupModeTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/Action.java // public interface Action { // public void doSomething(); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasParentServices.java // public interface HasParentServices // extends ScopeKey.Child { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java // public interface HasServices // extends ScopeKey { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/AssertionHelper.java // public static void assertThrows(Action action) { // try { // action.doSomething(); // Assert.fail("Did not throw exception."); // } catch(Exception e) { // // OK! // } // }
import static org.assertj.core.api.Assertions.assertThat; import android.os.Parcel; import com.zhuinden.simplestack.helpers.Action; import com.zhuinden.simplestack.helpers.HasParentServices; import com.zhuinden.simplestack.helpers.HasServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import org.junit.Test; import java.util.List; import javax.annotation.Nonnull; import static com.zhuinden.simplestack.helpers.AssertionHelper.assertThrows;
assertThat(backstack.canFindFromScope("boop", "parentService1", ScopeLookupMode.ALL)).isTrue(); assertThat(backstack.canFindFromScope("boop", "parentService2", ScopeLookupMode.ALL)).isTrue(); assertThat(backstack.canFindFromScope("parent2", "service1", ScopeLookupMode.ALL)).isTrue(); assertThat(backstack.canFindFromScope("parent2", "service2", ScopeLookupMode.ALL)).isFalse(); assertThat(backstack.canFindFromScope("parent2", "parentService1", ScopeLookupMode.ALL)).isTrue(); assertThat(backstack.canFindFromScope("parent2", "parentService2", ScopeLookupMode.ALL)).isTrue(); // EXPLICIT specified assertThat(backstack.canFindFromScope("beep", "service1", ScopeLookupMode.EXPLICIT)).isTrue(); assertThat(backstack.canFindFromScope("beep", "service2", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("beep", "parentService1", ScopeLookupMode.EXPLICIT)).isTrue(); assertThat(backstack.canFindFromScope("beep", "parentService2", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("parent1", "service1", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("parent1", "service2", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("parent1", "parentService1", ScopeLookupMode.EXPLICIT)).isTrue(); assertThat(backstack.canFindFromScope("parent1", "parentService2", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("boop", "service1", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("boop", "service2", ScopeLookupMode.EXPLICIT)).isTrue(); assertThat(backstack.canFindFromScope("boop", "parentService1", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("boop", "parentService2", ScopeLookupMode.EXPLICIT)).isTrue(); assertThat(backstack.canFindFromScope("parent2", "service1", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("parent2", "service2", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("parent2", "parentService1", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("parent2", "parentService2", ScopeLookupMode.EXPLICIT)).isTrue(); // default (ALL)
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/Action.java // public interface Action { // public void doSomething(); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasParentServices.java // public interface HasParentServices // extends ScopeKey.Child { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java // public interface HasServices // extends ScopeKey { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/AssertionHelper.java // public static void assertThrows(Action action) { // try { // action.doSomething(); // Assert.fail("Did not throw exception."); // } catch(Exception e) { // // OK! // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/ScopeLookupModeTest.java import static org.assertj.core.api.Assertions.assertThat; import android.os.Parcel; import com.zhuinden.simplestack.helpers.Action; import com.zhuinden.simplestack.helpers.HasParentServices; import com.zhuinden.simplestack.helpers.HasServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import org.junit.Test; import java.util.List; import javax.annotation.Nonnull; import static com.zhuinden.simplestack.helpers.AssertionHelper.assertThrows; assertThat(backstack.canFindFromScope("boop", "parentService1", ScopeLookupMode.ALL)).isTrue(); assertThat(backstack.canFindFromScope("boop", "parentService2", ScopeLookupMode.ALL)).isTrue(); assertThat(backstack.canFindFromScope("parent2", "service1", ScopeLookupMode.ALL)).isTrue(); assertThat(backstack.canFindFromScope("parent2", "service2", ScopeLookupMode.ALL)).isFalse(); assertThat(backstack.canFindFromScope("parent2", "parentService1", ScopeLookupMode.ALL)).isTrue(); assertThat(backstack.canFindFromScope("parent2", "parentService2", ScopeLookupMode.ALL)).isTrue(); // EXPLICIT specified assertThat(backstack.canFindFromScope("beep", "service1", ScopeLookupMode.EXPLICIT)).isTrue(); assertThat(backstack.canFindFromScope("beep", "service2", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("beep", "parentService1", ScopeLookupMode.EXPLICIT)).isTrue(); assertThat(backstack.canFindFromScope("beep", "parentService2", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("parent1", "service1", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("parent1", "service2", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("parent1", "parentService1", ScopeLookupMode.EXPLICIT)).isTrue(); assertThat(backstack.canFindFromScope("parent1", "parentService2", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("boop", "service1", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("boop", "service2", ScopeLookupMode.EXPLICIT)).isTrue(); assertThat(backstack.canFindFromScope("boop", "parentService1", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("boop", "parentService2", ScopeLookupMode.EXPLICIT)).isTrue(); assertThat(backstack.canFindFromScope("parent2", "service1", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("parent2", "service2", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("parent2", "parentService1", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("parent2", "parentService2", ScopeLookupMode.EXPLICIT)).isTrue(); // default (ALL)
assertThrows(new Action() {
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/ScopeLookupModeTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/Action.java // public interface Action { // public void doSomething(); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasParentServices.java // public interface HasParentServices // extends ScopeKey.Child { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java // public interface HasServices // extends ScopeKey { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/AssertionHelper.java // public static void assertThrows(Action action) { // try { // action.doSomething(); // Assert.fail("Did not throw exception."); // } catch(Exception e) { // // OK! // } // }
import static org.assertj.core.api.Assertions.assertThat; import android.os.Parcel; import com.zhuinden.simplestack.helpers.Action; import com.zhuinden.simplestack.helpers.HasParentServices; import com.zhuinden.simplestack.helpers.HasServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import org.junit.Test; import java.util.List; import javax.annotation.Nonnull; import static com.zhuinden.simplestack.helpers.AssertionHelper.assertThrows;
assertThat(backstack.canFindFromScope("boop", "parentService1", ScopeLookupMode.ALL)).isTrue(); assertThat(backstack.canFindFromScope("boop", "parentService2", ScopeLookupMode.ALL)).isTrue(); assertThat(backstack.canFindFromScope("parent2", "service1", ScopeLookupMode.ALL)).isTrue(); assertThat(backstack.canFindFromScope("parent2", "service2", ScopeLookupMode.ALL)).isFalse(); assertThat(backstack.canFindFromScope("parent2", "parentService1", ScopeLookupMode.ALL)).isTrue(); assertThat(backstack.canFindFromScope("parent2", "parentService2", ScopeLookupMode.ALL)).isTrue(); // EXPLICIT specified assertThat(backstack.canFindFromScope("beep", "service1", ScopeLookupMode.EXPLICIT)).isTrue(); assertThat(backstack.canFindFromScope("beep", "service2", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("beep", "parentService1", ScopeLookupMode.EXPLICIT)).isTrue(); assertThat(backstack.canFindFromScope("beep", "parentService2", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("parent1", "service1", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("parent1", "service2", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("parent1", "parentService1", ScopeLookupMode.EXPLICIT)).isTrue(); assertThat(backstack.canFindFromScope("parent1", "parentService2", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("boop", "service1", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("boop", "service2", ScopeLookupMode.EXPLICIT)).isTrue(); assertThat(backstack.canFindFromScope("boop", "parentService1", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("boop", "parentService2", ScopeLookupMode.EXPLICIT)).isTrue(); assertThat(backstack.canFindFromScope("parent2", "service1", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("parent2", "service2", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("parent2", "parentService1", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("parent2", "parentService2", ScopeLookupMode.EXPLICIT)).isTrue(); // default (ALL)
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/Action.java // public interface Action { // public void doSomething(); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasParentServices.java // public interface HasParentServices // extends ScopeKey.Child { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java // public interface HasServices // extends ScopeKey { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/AssertionHelper.java // public static void assertThrows(Action action) { // try { // action.doSomething(); // Assert.fail("Did not throw exception."); // } catch(Exception e) { // // OK! // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/ScopeLookupModeTest.java import static org.assertj.core.api.Assertions.assertThat; import android.os.Parcel; import com.zhuinden.simplestack.helpers.Action; import com.zhuinden.simplestack.helpers.HasParentServices; import com.zhuinden.simplestack.helpers.HasServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import org.junit.Test; import java.util.List; import javax.annotation.Nonnull; import static com.zhuinden.simplestack.helpers.AssertionHelper.assertThrows; assertThat(backstack.canFindFromScope("boop", "parentService1", ScopeLookupMode.ALL)).isTrue(); assertThat(backstack.canFindFromScope("boop", "parentService2", ScopeLookupMode.ALL)).isTrue(); assertThat(backstack.canFindFromScope("parent2", "service1", ScopeLookupMode.ALL)).isTrue(); assertThat(backstack.canFindFromScope("parent2", "service2", ScopeLookupMode.ALL)).isFalse(); assertThat(backstack.canFindFromScope("parent2", "parentService1", ScopeLookupMode.ALL)).isTrue(); assertThat(backstack.canFindFromScope("parent2", "parentService2", ScopeLookupMode.ALL)).isTrue(); // EXPLICIT specified assertThat(backstack.canFindFromScope("beep", "service1", ScopeLookupMode.EXPLICIT)).isTrue(); assertThat(backstack.canFindFromScope("beep", "service2", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("beep", "parentService1", ScopeLookupMode.EXPLICIT)).isTrue(); assertThat(backstack.canFindFromScope("beep", "parentService2", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("parent1", "service1", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("parent1", "service2", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("parent1", "parentService1", ScopeLookupMode.EXPLICIT)).isTrue(); assertThat(backstack.canFindFromScope("parent1", "parentService2", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("boop", "service1", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("boop", "service2", ScopeLookupMode.EXPLICIT)).isTrue(); assertThat(backstack.canFindFromScope("boop", "parentService1", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("boop", "parentService2", ScopeLookupMode.EXPLICIT)).isTrue(); assertThat(backstack.canFindFromScope("parent2", "service1", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("parent2", "service2", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("parent2", "parentService1", ScopeLookupMode.EXPLICIT)).isFalse(); assertThat(backstack.canFindFromScope("parent2", "parentService2", ScopeLookupMode.EXPLICIT)).isTrue(); // default (ALL)
assertThrows(new Action() {
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/ScopingGlobalScopeTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasParentServices.java // public interface HasParentServices // extends ScopeKey.Child { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java // public interface HasServices // extends ScopeKey { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // }
import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static org.assertj.core.api.Assertions.assertThat; import android.os.Parcel; import com.zhuinden.simplestack.helpers.HasParentServices; import com.zhuinden.simplestack.helpers.HasServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import com.zhuinden.statebundle.StateBundle; import org.junit.Assert; import org.junit.Test; import java.util.ArrayList; import java.util.List; import java.util.Objects;
/* * Copyright 2019 Gabor Varadi * * 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.zhuinden.simplestack; public class ScopingGlobalScopeTest { @Test public void globalScopeExists() { Object service = new Object(); Backstack backstack = new Backstack(); backstack.setGlobalServices(GlobalServices.builder() .addService("service", service) .build());
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasParentServices.java // public interface HasParentServices // extends ScopeKey.Child { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java // public interface HasServices // extends ScopeKey { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/ScopingGlobalScopeTest.java import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static org.assertj.core.api.Assertions.assertThat; import android.os.Parcel; import com.zhuinden.simplestack.helpers.HasParentServices; import com.zhuinden.simplestack.helpers.HasServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import com.zhuinden.statebundle.StateBundle; import org.junit.Assert; import org.junit.Test; import java.util.ArrayList; import java.util.List; import java.util.Objects; /* * Copyright 2019 Gabor Varadi * * 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.zhuinden.simplestack; public class ScopingGlobalScopeTest { @Test public void globalScopeExists() { Object service = new Object(); Backstack backstack = new Backstack(); backstack.setGlobalServices(GlobalServices.builder() .addService("service", service) .build());
backstack.setup(History.of(new TestKey("hello!")));
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/ScopingGlobalScopeTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasParentServices.java // public interface HasParentServices // extends ScopeKey.Child { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java // public interface HasServices // extends ScopeKey { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // }
import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static org.assertj.core.api.Assertions.assertThat; import android.os.Parcel; import com.zhuinden.simplestack.helpers.HasParentServices; import com.zhuinden.simplestack.helpers.HasServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import com.zhuinden.statebundle.StateBundle; import org.junit.Assert; import org.junit.Test; import java.util.ArrayList; import java.util.List; import java.util.Objects;
/* * Copyright 2019 Gabor Varadi * * 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.zhuinden.simplestack; public class ScopingGlobalScopeTest { @Test public void globalScopeExists() { Object service = new Object(); Backstack backstack = new Backstack(); backstack.setGlobalServices(GlobalServices.builder() .addService("service", service) .build()); backstack.setup(History.of(new TestKey("hello!"))); backstack.setStateChanger(new StateChanger() { @Override public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) { completionCallback.stateChangeComplete(); } }); assertThat(backstack.canFindService("service")).isTrue(); assertThat(backstack.lookupService("service")).isSameAs(service); } @Test public void globalScopeLookupWorks() { final Backstack backstack = new Backstack();
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasParentServices.java // public interface HasParentServices // extends ScopeKey.Child { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java // public interface HasServices // extends ScopeKey { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/ScopingGlobalScopeTest.java import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static org.assertj.core.api.Assertions.assertThat; import android.os.Parcel; import com.zhuinden.simplestack.helpers.HasParentServices; import com.zhuinden.simplestack.helpers.HasServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import com.zhuinden.statebundle.StateBundle; import org.junit.Assert; import org.junit.Test; import java.util.ArrayList; import java.util.List; import java.util.Objects; /* * Copyright 2019 Gabor Varadi * * 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.zhuinden.simplestack; public class ScopingGlobalScopeTest { @Test public void globalScopeExists() { Object service = new Object(); Backstack backstack = new Backstack(); backstack.setGlobalServices(GlobalServices.builder() .addService("service", service) .build()); backstack.setup(History.of(new TestKey("hello!"))); backstack.setStateChanger(new StateChanger() { @Override public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) { completionCallback.stateChangeComplete(); } }); assertThat(backstack.canFindService("service")).isTrue(); assertThat(backstack.lookupService("service")).isSameAs(service); } @Test public void globalScopeLookupWorks() { final Backstack backstack = new Backstack();
backstack.setScopedServices(new ServiceProvider());
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/ScopingGlobalScopeTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasParentServices.java // public interface HasParentServices // extends ScopeKey.Child { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java // public interface HasServices // extends ScopeKey { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // }
import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static org.assertj.core.api.Assertions.assertThat; import android.os.Parcel; import com.zhuinden.simplestack.helpers.HasParentServices; import com.zhuinden.simplestack.helpers.HasServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import com.zhuinden.statebundle.StateBundle; import org.junit.Assert; import org.junit.Test; import java.util.ArrayList; import java.util.List; import java.util.Objects;
backstack.setStateChanger(new StateChanger() { @Override public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) { completionCallback.stateChangeComplete(); } }); assertThat(backstack.canFindService("service")).isTrue(); assertThat(backstack.lookupService("service")).isSameAs(service); } @Test public void globalScopeLookupWorks() { final Backstack backstack = new Backstack(); backstack.setScopedServices(new ServiceProvider()); final Object globalService = new Object(); backstack.setGlobalServices(GlobalServices.builder() .addService("parentService2", globalService) .build()); final Object parentService1 = new Object(); final Object parentService2 = new Object(); final Object service1 = new Object(); final Object service2 = new Object(); class Key1 extends TestKey
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasParentServices.java // public interface HasParentServices // extends ScopeKey.Child { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java // public interface HasServices // extends ScopeKey { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/ScopingGlobalScopeTest.java import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static org.assertj.core.api.Assertions.assertThat; import android.os.Parcel; import com.zhuinden.simplestack.helpers.HasParentServices; import com.zhuinden.simplestack.helpers.HasServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import com.zhuinden.statebundle.StateBundle; import org.junit.Assert; import org.junit.Test; import java.util.ArrayList; import java.util.List; import java.util.Objects; backstack.setStateChanger(new StateChanger() { @Override public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) { completionCallback.stateChangeComplete(); } }); assertThat(backstack.canFindService("service")).isTrue(); assertThat(backstack.lookupService("service")).isSameAs(service); } @Test public void globalScopeLookupWorks() { final Backstack backstack = new Backstack(); backstack.setScopedServices(new ServiceProvider()); final Object globalService = new Object(); backstack.setGlobalServices(GlobalServices.builder() .addService("parentService2", globalService) .build()); final Object parentService1 = new Object(); final Object parentService2 = new Object(); final Object service1 = new Object(); final Object service2 = new Object(); class Key1 extends TestKey
implements HasServices, HasParentServices {
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/ScopingGlobalScopeTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasParentServices.java // public interface HasParentServices // extends ScopeKey.Child { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java // public interface HasServices // extends ScopeKey { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // }
import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static org.assertj.core.api.Assertions.assertThat; import android.os.Parcel; import com.zhuinden.simplestack.helpers.HasParentServices; import com.zhuinden.simplestack.helpers.HasServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import com.zhuinden.statebundle.StateBundle; import org.junit.Assert; import org.junit.Test; import java.util.ArrayList; import java.util.List; import java.util.Objects;
backstack.setStateChanger(new StateChanger() { @Override public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) { completionCallback.stateChangeComplete(); } }); assertThat(backstack.canFindService("service")).isTrue(); assertThat(backstack.lookupService("service")).isSameAs(service); } @Test public void globalScopeLookupWorks() { final Backstack backstack = new Backstack(); backstack.setScopedServices(new ServiceProvider()); final Object globalService = new Object(); backstack.setGlobalServices(GlobalServices.builder() .addService("parentService2", globalService) .build()); final Object parentService1 = new Object(); final Object parentService2 = new Object(); final Object service1 = new Object(); final Object service2 = new Object(); class Key1 extends TestKey
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasParentServices.java // public interface HasParentServices // extends ScopeKey.Child { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java // public interface HasServices // extends ScopeKey { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/ScopingGlobalScopeTest.java import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static org.assertj.core.api.Assertions.assertThat; import android.os.Parcel; import com.zhuinden.simplestack.helpers.HasParentServices; import com.zhuinden.simplestack.helpers.HasServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import com.zhuinden.statebundle.StateBundle; import org.junit.Assert; import org.junit.Test; import java.util.ArrayList; import java.util.List; import java.util.Objects; backstack.setStateChanger(new StateChanger() { @Override public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) { completionCallback.stateChangeComplete(); } }); assertThat(backstack.canFindService("service")).isTrue(); assertThat(backstack.lookupService("service")).isSameAs(service); } @Test public void globalScopeLookupWorks() { final Backstack backstack = new Backstack(); backstack.setScopedServices(new ServiceProvider()); final Object globalService = new Object(); backstack.setGlobalServices(GlobalServices.builder() .addService("parentService2", globalService) .build()); final Object parentService1 = new Object(); final Object parentService2 = new Object(); final Object service1 = new Object(); final Object service2 = new Object(); class Key1 extends TestKey
implements HasServices, HasParentServices {
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/ScopingGlobalScopeTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasParentServices.java // public interface HasParentServices // extends ScopeKey.Child { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java // public interface HasServices // extends ScopeKey { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // }
import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static org.assertj.core.api.Assertions.assertThat; import android.os.Parcel; import com.zhuinden.simplestack.helpers.HasParentServices; import com.zhuinden.simplestack.helpers.HasServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import com.zhuinden.statebundle.StateBundle; import org.junit.Assert; import org.junit.Test; import java.util.ArrayList; import java.util.List; import java.util.Objects;
@Override public void onServiceRegistered() { events.add(Pair.of((Object) this, ServiceEvent.CREATE)); } @Override public void onServiceUnregistered() { events.add(Pair.of((Object) this, ServiceEvent.DESTROY)); } } final Object service0 = new MyService(0); backstack.setGlobalServices(GlobalServices.builder() .addService("SERVICE0", service0) .build()); final Object service1 = new MyService(1); final Object service2 = new MyService(2); final Object service3 = new MyService(3); final Object service4 = new MyService(4); final Object service5 = new MyService(5); final Object service6 = new MyService(6); final Object service7 = new MyService(7); final Object service8 = new MyService(8); final Object service9 = new MyService(9);
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasParentServices.java // public interface HasParentServices // extends ScopeKey.Child { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java // public interface HasServices // extends ScopeKey { // void bindServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/ScopingGlobalScopeTest.java import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static org.assertj.core.api.Assertions.assertThat; import android.os.Parcel; import com.zhuinden.simplestack.helpers.HasParentServices; import com.zhuinden.simplestack.helpers.HasServices; import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKey; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import com.zhuinden.statebundle.StateBundle; import org.junit.Assert; import org.junit.Test; import java.util.ArrayList; import java.util.List; import java.util.Objects; @Override public void onServiceRegistered() { events.add(Pair.of((Object) this, ServiceEvent.CREATE)); } @Override public void onServiceUnregistered() { events.add(Pair.of((Object) this, ServiceEvent.DESTROY)); } } final Object service0 = new MyService(0); backstack.setGlobalServices(GlobalServices.builder() .addService("SERVICE0", service0) .build()); final Object service1 = new MyService(1); final Object service2 = new MyService(2); final Object service3 = new MyService(3); final Object service4 = new MyService(4); final Object service5 = new MyService(5); final Object service6 = new MyService(6); final Object service7 = new MyService(7); final Object service8 = new MyService(8); final Object service9 = new MyService(9);
TestKeyWithScope beep = new TestKeyWithScope("beep") {
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/FlowTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // }
import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.MockitoAnnotations.initMocks; import android.os.Parcel; import android.os.Parcelable; import com.zhuinden.simplestack.helpers.TestKey; import org.junit.Before; import org.junit.Test; import java.util.Arrays; import java.util.Iterator; import javax.annotation.Nonnull;
package com.zhuinden.simplestack; /* * Copyright 2013 Square Inc. * Copyright 2017 Gabor Varadi * * 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. */ public class FlowTest { static class Uno { public Uno() { } } static class Dos { public Dos() { } } static class Tres { public Tres() { } }
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/FlowTest.java import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.MockitoAnnotations.initMocks; import android.os.Parcel; import android.os.Parcelable; import com.zhuinden.simplestack.helpers.TestKey; import org.junit.Before; import org.junit.Test; import java.util.Arrays; import java.util.Iterator; import javax.annotation.Nonnull; package com.zhuinden.simplestack; /* * Copyright 2013 Square Inc. * Copyright 2017 Gabor Varadi * * 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. */ public class FlowTest { static class Uno { public Uno() { } } static class Dos { public Dos() { } } static class Tres { public Tres() { } }
final TestKey able = new TestKey("Able");
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/BackstackCoreTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // }
import static org.assertj.core.api.Assertions.assertThat; import android.os.Parcelable; import com.zhuinden.simplestack.helpers.TestKey; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nonnull;
} } @Test public void initialKeysShouldNotBeEmptyList() { try { Backstack backstack = new Backstack(); backstack.setup(new ArrayList<Parcelable>()); Assert.fail(); } catch(IllegalArgumentException e) { // good! } } @Test public void initialKeysShouldNotBeNullList() { try { List<Parcelable> list = null; Backstack backstack = new Backstack(); backstack.setup(list); Assert.fail(); } catch(NullPointerException e) { // good! } } @Test public void stateChangerShouldNotBeNull() { try { // TODO this test is testing internal behavior
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/BackstackCoreTest.java import static org.assertj.core.api.Assertions.assertThat; import android.os.Parcelable; import com.zhuinden.simplestack.helpers.TestKey; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nonnull; } } @Test public void initialKeysShouldNotBeEmptyList() { try { Backstack backstack = new Backstack(); backstack.setup(new ArrayList<Parcelable>()); Assert.fail(); } catch(IllegalArgumentException e) { // good! } } @Test public void initialKeysShouldNotBeNullList() { try { List<Parcelable> list = null; Backstack backstack = new Backstack(); backstack.setup(list); Assert.fail(); } catch(NullPointerException e) { // good! } } @Test public void stateChangerShouldNotBeNull() { try { // TODO this test is testing internal behavior
NavigationCore navigationCore = new NavigationCore(new TestKey("Hi"));
Zhuinden/simple-stack
samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/features/kitten/details/KittenDetailsKey.java
// Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/navigation/BaseFragment.java // public class BaseFragment // extends KeyedFragment { // public BaseFragment() { // } // // public BaseFragment(@LayoutRes int layoutRes) { // super(layoutRes); // } // // @Override // public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // startPostponedEnterTransition(); // } // } // // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/navigation/BaseKey.java // public abstract class BaseKey extends DefaultFragmentKey { // @NotNull // @Override // public String getFragmentTag() { // return toString(); // } // } // // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/sharedelements/HasSharedElement.java // public interface HasSharedElement { // SharedElement sharedElement(); // } // // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/sharedelements/SharedElement.java // @AutoValue // public abstract class SharedElement implements Parcelable { // public abstract String sourceTransitionName(); // // public abstract String targetTransitionName(); // // public static SharedElement create(String sourceTransitionName, String targetTransitionName) { // return new AutoValue_SharedElement(sourceTransitionName, targetTransitionName); // } // }
import androidx.annotation.IntRange; import com.example.fragmenttransitions.core.navigation.BaseFragment; import com.example.fragmenttransitions.core.navigation.BaseKey; import com.example.fragmenttransitions.core.sharedelements.HasSharedElement; import com.example.fragmenttransitions.core.sharedelements.SharedElement; import com.google.auto.value.AutoValue; import org.jetbrains.annotations.NotNull;
package com.example.fragmenttransitions.features.kitten.details; /** * Created by Zhuinden on 2020. 12. 18.. */ @AutoValue public abstract class KittenDetailsKey
// Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/navigation/BaseFragment.java // public class BaseFragment // extends KeyedFragment { // public BaseFragment() { // } // // public BaseFragment(@LayoutRes int layoutRes) { // super(layoutRes); // } // // @Override // public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // startPostponedEnterTransition(); // } // } // // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/navigation/BaseKey.java // public abstract class BaseKey extends DefaultFragmentKey { // @NotNull // @Override // public String getFragmentTag() { // return toString(); // } // } // // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/sharedelements/HasSharedElement.java // public interface HasSharedElement { // SharedElement sharedElement(); // } // // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/sharedelements/SharedElement.java // @AutoValue // public abstract class SharedElement implements Parcelable { // public abstract String sourceTransitionName(); // // public abstract String targetTransitionName(); // // public static SharedElement create(String sourceTransitionName, String targetTransitionName) { // return new AutoValue_SharedElement(sourceTransitionName, targetTransitionName); // } // } // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/features/kitten/details/KittenDetailsKey.java import androidx.annotation.IntRange; import com.example.fragmenttransitions.core.navigation.BaseFragment; import com.example.fragmenttransitions.core.navigation.BaseKey; import com.example.fragmenttransitions.core.sharedelements.HasSharedElement; import com.example.fragmenttransitions.core.sharedelements.SharedElement; import com.google.auto.value.AutoValue; import org.jetbrains.annotations.NotNull; package com.example.fragmenttransitions.features.kitten.details; /** * Created by Zhuinden on 2020. 12. 18.. */ @AutoValue public abstract class KittenDetailsKey
extends BaseKey
Zhuinden/simple-stack
samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/features/kitten/details/KittenDetailsKey.java
// Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/navigation/BaseFragment.java // public class BaseFragment // extends KeyedFragment { // public BaseFragment() { // } // // public BaseFragment(@LayoutRes int layoutRes) { // super(layoutRes); // } // // @Override // public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // startPostponedEnterTransition(); // } // } // // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/navigation/BaseKey.java // public abstract class BaseKey extends DefaultFragmentKey { // @NotNull // @Override // public String getFragmentTag() { // return toString(); // } // } // // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/sharedelements/HasSharedElement.java // public interface HasSharedElement { // SharedElement sharedElement(); // } // // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/sharedelements/SharedElement.java // @AutoValue // public abstract class SharedElement implements Parcelable { // public abstract String sourceTransitionName(); // // public abstract String targetTransitionName(); // // public static SharedElement create(String sourceTransitionName, String targetTransitionName) { // return new AutoValue_SharedElement(sourceTransitionName, targetTransitionName); // } // }
import androidx.annotation.IntRange; import com.example.fragmenttransitions.core.navigation.BaseFragment; import com.example.fragmenttransitions.core.navigation.BaseKey; import com.example.fragmenttransitions.core.sharedelements.HasSharedElement; import com.example.fragmenttransitions.core.sharedelements.SharedElement; import com.google.auto.value.AutoValue; import org.jetbrains.annotations.NotNull;
package com.example.fragmenttransitions.features.kitten.details; /** * Created by Zhuinden on 2020. 12. 18.. */ @AutoValue public abstract class KittenDetailsKey extends BaseKey
// Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/navigation/BaseFragment.java // public class BaseFragment // extends KeyedFragment { // public BaseFragment() { // } // // public BaseFragment(@LayoutRes int layoutRes) { // super(layoutRes); // } // // @Override // public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // startPostponedEnterTransition(); // } // } // // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/navigation/BaseKey.java // public abstract class BaseKey extends DefaultFragmentKey { // @NotNull // @Override // public String getFragmentTag() { // return toString(); // } // } // // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/sharedelements/HasSharedElement.java // public interface HasSharedElement { // SharedElement sharedElement(); // } // // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/sharedelements/SharedElement.java // @AutoValue // public abstract class SharedElement implements Parcelable { // public abstract String sourceTransitionName(); // // public abstract String targetTransitionName(); // // public static SharedElement create(String sourceTransitionName, String targetTransitionName) { // return new AutoValue_SharedElement(sourceTransitionName, targetTransitionName); // } // } // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/features/kitten/details/KittenDetailsKey.java import androidx.annotation.IntRange; import com.example.fragmenttransitions.core.navigation.BaseFragment; import com.example.fragmenttransitions.core.navigation.BaseKey; import com.example.fragmenttransitions.core.sharedelements.HasSharedElement; import com.example.fragmenttransitions.core.sharedelements.SharedElement; import com.google.auto.value.AutoValue; import org.jetbrains.annotations.NotNull; package com.example.fragmenttransitions.features.kitten.details; /** * Created by Zhuinden on 2020. 12. 18.. */ @AutoValue public abstract class KittenDetailsKey extends BaseKey
implements HasSharedElement {
Zhuinden/simple-stack
samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/features/kitten/details/KittenDetailsKey.java
// Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/navigation/BaseFragment.java // public class BaseFragment // extends KeyedFragment { // public BaseFragment() { // } // // public BaseFragment(@LayoutRes int layoutRes) { // super(layoutRes); // } // // @Override // public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // startPostponedEnterTransition(); // } // } // // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/navigation/BaseKey.java // public abstract class BaseKey extends DefaultFragmentKey { // @NotNull // @Override // public String getFragmentTag() { // return toString(); // } // } // // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/sharedelements/HasSharedElement.java // public interface HasSharedElement { // SharedElement sharedElement(); // } // // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/sharedelements/SharedElement.java // @AutoValue // public abstract class SharedElement implements Parcelable { // public abstract String sourceTransitionName(); // // public abstract String targetTransitionName(); // // public static SharedElement create(String sourceTransitionName, String targetTransitionName) { // return new AutoValue_SharedElement(sourceTransitionName, targetTransitionName); // } // }
import androidx.annotation.IntRange; import com.example.fragmenttransitions.core.navigation.BaseFragment; import com.example.fragmenttransitions.core.navigation.BaseKey; import com.example.fragmenttransitions.core.sharedelements.HasSharedElement; import com.example.fragmenttransitions.core.sharedelements.SharedElement; import com.google.auto.value.AutoValue; import org.jetbrains.annotations.NotNull;
package com.example.fragmenttransitions.features.kitten.details; /** * Created by Zhuinden on 2020. 12. 18.. */ @AutoValue public abstract class KittenDetailsKey extends BaseKey implements HasSharedElement {
// Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/navigation/BaseFragment.java // public class BaseFragment // extends KeyedFragment { // public BaseFragment() { // } // // public BaseFragment(@LayoutRes int layoutRes) { // super(layoutRes); // } // // @Override // public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // startPostponedEnterTransition(); // } // } // // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/navigation/BaseKey.java // public abstract class BaseKey extends DefaultFragmentKey { // @NotNull // @Override // public String getFragmentTag() { // return toString(); // } // } // // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/sharedelements/HasSharedElement.java // public interface HasSharedElement { // SharedElement sharedElement(); // } // // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/sharedelements/SharedElement.java // @AutoValue // public abstract class SharedElement implements Parcelable { // public abstract String sourceTransitionName(); // // public abstract String targetTransitionName(); // // public static SharedElement create(String sourceTransitionName, String targetTransitionName) { // return new AutoValue_SharedElement(sourceTransitionName, targetTransitionName); // } // } // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/features/kitten/details/KittenDetailsKey.java import androidx.annotation.IntRange; import com.example.fragmenttransitions.core.navigation.BaseFragment; import com.example.fragmenttransitions.core.navigation.BaseKey; import com.example.fragmenttransitions.core.sharedelements.HasSharedElement; import com.example.fragmenttransitions.core.sharedelements.SharedElement; import com.google.auto.value.AutoValue; import org.jetbrains.annotations.NotNull; package com.example.fragmenttransitions.features.kitten.details; /** * Created by Zhuinden on 2020. 12. 18.. */ @AutoValue public abstract class KittenDetailsKey extends BaseKey implements HasSharedElement {
public abstract SharedElement sharedElement();
Zhuinden/simple-stack
samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/features/kitten/details/KittenDetailsKey.java
// Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/navigation/BaseFragment.java // public class BaseFragment // extends KeyedFragment { // public BaseFragment() { // } // // public BaseFragment(@LayoutRes int layoutRes) { // super(layoutRes); // } // // @Override // public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // startPostponedEnterTransition(); // } // } // // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/navigation/BaseKey.java // public abstract class BaseKey extends DefaultFragmentKey { // @NotNull // @Override // public String getFragmentTag() { // return toString(); // } // } // // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/sharedelements/HasSharedElement.java // public interface HasSharedElement { // SharedElement sharedElement(); // } // // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/sharedelements/SharedElement.java // @AutoValue // public abstract class SharedElement implements Parcelable { // public abstract String sourceTransitionName(); // // public abstract String targetTransitionName(); // // public static SharedElement create(String sourceTransitionName, String targetTransitionName) { // return new AutoValue_SharedElement(sourceTransitionName, targetTransitionName); // } // }
import androidx.annotation.IntRange; import com.example.fragmenttransitions.core.navigation.BaseFragment; import com.example.fragmenttransitions.core.navigation.BaseKey; import com.example.fragmenttransitions.core.sharedelements.HasSharedElement; import com.example.fragmenttransitions.core.sharedelements.SharedElement; import com.google.auto.value.AutoValue; import org.jetbrains.annotations.NotNull;
package com.example.fragmenttransitions.features.kitten.details; /** * Created by Zhuinden on 2020. 12. 18.. */ @AutoValue public abstract class KittenDetailsKey extends BaseKey implements HasSharedElement { public abstract SharedElement sharedElement(); public abstract int kittenNumber(); public static KittenDetailsKey create(SharedElement sharedElement, @IntRange(from = 1, to = 6) int kittenNumber) { return new AutoValue_KittenDetailsKey(sharedElement, kittenNumber); } @NotNull @Override
// Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/navigation/BaseFragment.java // public class BaseFragment // extends KeyedFragment { // public BaseFragment() { // } // // public BaseFragment(@LayoutRes int layoutRes) { // super(layoutRes); // } // // @Override // public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // startPostponedEnterTransition(); // } // } // // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/navigation/BaseKey.java // public abstract class BaseKey extends DefaultFragmentKey { // @NotNull // @Override // public String getFragmentTag() { // return toString(); // } // } // // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/sharedelements/HasSharedElement.java // public interface HasSharedElement { // SharedElement sharedElement(); // } // // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/core/sharedelements/SharedElement.java // @AutoValue // public abstract class SharedElement implements Parcelable { // public abstract String sourceTransitionName(); // // public abstract String targetTransitionName(); // // public static SharedElement create(String sourceTransitionName, String targetTransitionName) { // return new AutoValue_SharedElement(sourceTransitionName, targetTransitionName); // } // } // Path: samples/shared-element-samples/simple-stack-example-sharedelement-fragment/src/main/java/com/example/fragmenttransitions/features/kitten/details/KittenDetailsKey.java import androidx.annotation.IntRange; import com.example.fragmenttransitions.core.navigation.BaseFragment; import com.example.fragmenttransitions.core.navigation.BaseKey; import com.example.fragmenttransitions.core.sharedelements.HasSharedElement; import com.example.fragmenttransitions.core.sharedelements.SharedElement; import com.google.auto.value.AutoValue; import org.jetbrains.annotations.NotNull; package com.example.fragmenttransitions.features.kitten.details; /** * Created by Zhuinden on 2020. 12. 18.. */ @AutoValue public abstract class KittenDetailsKey extends BaseKey implements HasSharedElement { public abstract SharedElement sharedElement(); public abstract int kittenNumber(); public static KittenDetailsKey create(SharedElement sharedElement, @IntRange(from = 1, to = 6) int kittenNumber) { return new AutoValue_KittenDetailsKey(sharedElement, kittenNumber); } @NotNull @Override
public BaseFragment instantiateFragment() {
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/ScopingExplicitParentsTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // }
import android.app.Activity; import com.zhuinden.simplestack.helpers.TestKey; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; import java.util.ArrayList; import java.util.Collections; import java.util.List; import javax.annotation.Nonnull; import static org.assertj.core.api.Assertions.assertThat;
/* * Copyright 2018 Gabor Varadi * * 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.zhuinden.simplestack; public class ScopingExplicitParentsTest { private static class DefaultScopedServices implements ScopedServices { @Override public void bindServices(@Nonnull ServiceBinder serviceBinder) { // boop } } @Test public void explicitParentScopesListThrowsIfNull() { class ChildKey
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java // public class TestKey // implements Parcelable { // public final String name; // // public TestKey(String name) { // this.name = name; // } // // protected TestKey(Parcel in) { // name = in.readString(); // } // // public static final Creator<TestKey> CREATOR = new Creator<TestKey>() { // @Override // public TestKey createFromParcel(Parcel in) { // return new TestKey(in); // } // // @Override // public TestKey[] newArray(int size) { // return new TestKey[size]; // } // }; // // @Override // public boolean equals(Object o) { // if(this == o) { // return true; // } // if(o == null || getClass() != o.getClass()) { // return false; // } // TestKey key = (TestKey) o; // return name.equals(key.name); // } // // @Override // public int hashCode() { // return name.hashCode(); // } // // @Override // public String toString() { // return String.format("%s{%h}", name, this); // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(name); // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/ScopingExplicitParentsTest.java import android.app.Activity; import com.zhuinden.simplestack.helpers.TestKey; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; import java.util.ArrayList; import java.util.Collections; import java.util.List; import javax.annotation.Nonnull; import static org.assertj.core.api.Assertions.assertThat; /* * Copyright 2018 Gabor Varadi * * 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.zhuinden.simplestack; public class ScopingExplicitParentsTest { private static class DefaultScopedServices implements ScopedServices { @Override public void bindServices(@Nonnull ServiceBinder serviceBinder) { // boop } } @Test public void explicitParentScopesListThrowsIfNull() { class ChildKey
extends TestKey
Zhuinden/simple-stack
tutorials/tutorial-sample/src/main/java/com/zhuinden/simplestacktutorials/steps/step_5/FragmentStateChanger.java
// Path: simple-stack/src/main/java/com/zhuinden/simplestack/StateChange.java // public class StateChange { // @Retention(SOURCE) // // @IntDef({FORWARD, BACKWARD, REPLACE}) // removed android.support.annotation // @interface StateChangeDirection { // } // // public static final int REPLACE = 0; // public static final int BACKWARD = -1; // public static final int FORWARD = 1; // // StateChange(Backstack backstack, List<Object> previousKeys, List<Object> newKeys, @StateChangeDirection int direction) { // this.backstack = backstack; // this.previousKeys = previousKeys; // this.newKeys = newKeys; // this.direction = direction; // } // // Backstack backstack; // List<Object> previousKeys; // List<Object> newKeys; // int direction; // // /** // * The backstack this state change was executed by. // * // * @return the backstack // */ // @Nonnull // public Backstack getBackstack() { // return backstack; // } // // /** // * Convenience method to help short-circuit if the top new key is the same as the previous one. // * // * @return if the top new key is equal to the top previous key // */ // public final boolean isTopNewKeyEqualToPrevious() { // return topNewKey().equals(topPreviousKey()); // } // // // create a copy list where each item is casted to <T> // private <T> History<T> createParametricCopyList(List<Object> list) { // List<T> copyList = new LinkedList<>(); // for(Object key : list) { // // noinspection unchecked // copyList.add((T)key); // } // return History.from(copyList); // } // // /** // * The previous state from before the new keys were set. // * If empty, then this is an initialize {@link StateChange}. // * // * @param <T> the type of the key // * // * @return the previous state. // */ // @Nonnull // public <T> History<T> getPreviousKeys() { // return createParametricCopyList(previousKeys); // } // // /** // * The new state after the state change is complete. // * // * @param <T> the type of the key // * // * @return the new state. // */ // @Nonnull // public <T> History<T> getNewKeys() { // return createParametricCopyList(newKeys); // } // // /** // * The direction of the state change. // * // * @return the direction: FORWARD, BACKWARD or REPLACE. // */ // @StateChangeDirection // public int getDirection() { // return direction; // } // // /** // * Provides the top of the previous state. // * // * @return the last element in previous state, or null if empty. // */ // @Nullable // public <T> T topPreviousKey() { // if(previousKeys.size() > 0) { // // noinspection unchecked // return (T) previousKeys.get(previousKeys.size() - 1); // } else { // return null; // } // } // // /** // * Provides the top of the new state. // * // * @return the last element in new state. // */ // @Nonnull // public <T> T topNewKey() { // // noinspection unchecked // return (T) newKeys.get(newKeys.size() - 1); // } // // /** // * Creates a {@link KeyContextWrapper} using the provided key. // * // * @param base the context used as base for the new context wrapper. // * @param key the key this context is associated with. // * @return the context to use used with LayoutInflater.from(). // */ // @Nonnull // public Context createContext(@Nonnull Context base, @Nonnull Object key) { // return new KeyContextWrapper(base, key); // } // }
import com.zhuinden.simplestack.StateChange; import com.zhuinden.simplestacktutorials.R; import java.util.List; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentTransaction;
package com.zhuinden.simplestacktutorials.steps.step_5; public class FragmentStateChanger { private FragmentManager fragmentManager; private int containerId; public FragmentStateChanger(FragmentManager fragmentManager, int containerId) { this.fragmentManager = fragmentManager; this.containerId = containerId; }
// Path: simple-stack/src/main/java/com/zhuinden/simplestack/StateChange.java // public class StateChange { // @Retention(SOURCE) // // @IntDef({FORWARD, BACKWARD, REPLACE}) // removed android.support.annotation // @interface StateChangeDirection { // } // // public static final int REPLACE = 0; // public static final int BACKWARD = -1; // public static final int FORWARD = 1; // // StateChange(Backstack backstack, List<Object> previousKeys, List<Object> newKeys, @StateChangeDirection int direction) { // this.backstack = backstack; // this.previousKeys = previousKeys; // this.newKeys = newKeys; // this.direction = direction; // } // // Backstack backstack; // List<Object> previousKeys; // List<Object> newKeys; // int direction; // // /** // * The backstack this state change was executed by. // * // * @return the backstack // */ // @Nonnull // public Backstack getBackstack() { // return backstack; // } // // /** // * Convenience method to help short-circuit if the top new key is the same as the previous one. // * // * @return if the top new key is equal to the top previous key // */ // public final boolean isTopNewKeyEqualToPrevious() { // return topNewKey().equals(topPreviousKey()); // } // // // create a copy list where each item is casted to <T> // private <T> History<T> createParametricCopyList(List<Object> list) { // List<T> copyList = new LinkedList<>(); // for(Object key : list) { // // noinspection unchecked // copyList.add((T)key); // } // return History.from(copyList); // } // // /** // * The previous state from before the new keys were set. // * If empty, then this is an initialize {@link StateChange}. // * // * @param <T> the type of the key // * // * @return the previous state. // */ // @Nonnull // public <T> History<T> getPreviousKeys() { // return createParametricCopyList(previousKeys); // } // // /** // * The new state after the state change is complete. // * // * @param <T> the type of the key // * // * @return the new state. // */ // @Nonnull // public <T> History<T> getNewKeys() { // return createParametricCopyList(newKeys); // } // // /** // * The direction of the state change. // * // * @return the direction: FORWARD, BACKWARD or REPLACE. // */ // @StateChangeDirection // public int getDirection() { // return direction; // } // // /** // * Provides the top of the previous state. // * // * @return the last element in previous state, or null if empty. // */ // @Nullable // public <T> T topPreviousKey() { // if(previousKeys.size() > 0) { // // noinspection unchecked // return (T) previousKeys.get(previousKeys.size() - 1); // } else { // return null; // } // } // // /** // * Provides the top of the new state. // * // * @return the last element in new state. // */ // @Nonnull // public <T> T topNewKey() { // // noinspection unchecked // return (T) newKeys.get(newKeys.size() - 1); // } // // /** // * Creates a {@link KeyContextWrapper} using the provided key. // * // * @param base the context used as base for the new context wrapper. // * @param key the key this context is associated with. // * @return the context to use used with LayoutInflater.from(). // */ // @Nonnull // public Context createContext(@Nonnull Context base, @Nonnull Object key) { // return new KeyContextWrapper(base, key); // } // } // Path: tutorials/tutorial-sample/src/main/java/com/zhuinden/simplestacktutorials/steps/step_5/FragmentStateChanger.java import com.zhuinden.simplestack.StateChange; import com.zhuinden.simplestacktutorials.R; import java.util.List; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentTransaction; package com.zhuinden.simplestacktutorials.steps.step_5; public class FragmentStateChanger { private FragmentManager fragmentManager; private int containerId; public FragmentStateChanger(FragmentManager fragmentManager, int containerId) { this.fragmentManager = fragmentManager; this.containerId = containerId; }
public void handleStateChange(StateChange stateChange) {
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasParentServices.java
// Path: simple-stack/src/main/java/com/zhuinden/simplestack/ScopeKey.java // public interface ScopeKey { // /** // * Defines the tag of the scope this key defines the existence of. // * // * @return the tag of the scope // */ // @Nonnull // String getScopeTag(); // // /** // * Inheriting from {@link Child} enables defining an explicit parent hierarchy, thus ensuring that // * even if the scopes are not defined by the tags of any existing keys in the {@link Backstack}'s current {@link History}, // * the scopes will still be created, bound and shall exist. // * // * During {@link Backstack#lookupService(String)}, the explicit parents are traversed first, and implicit parents second. Implicit scope inheritance means that the previous keys' scopes will be traversed as well. // * // * If a {@link Child} is the top-most scope, then its explicit scopes are activated as well, so their services have {@link ScopedServices.Activated#onServiceActive()} called if they implement {@link com.zhuinden.simplestack.ScopedServices.Activated}. // */ // public interface Child { // /** // * Defines the hierarchy of the parent scope that ought to exist as explicit parents of this key. // * // * The order of the items matters: the top-most scope is the first, the bottom-most parent is the last. // * // * @return the list of scope tags that ought to serve as the key's hierarchy of explicit parents // */ // @Nonnull // List<String> getParentScopes(); // } // } // // Path: simple-stack/src/main/java/com/zhuinden/simplestack/ServiceBinder.java // public class ServiceBinder { // private final ScopeManager scopeManager; // // private final Object key; // private final String scopeTag; // private final ScopeNode scope; // // ServiceBinder(ScopeManager scopeManager, Object key, String scopeTag, ScopeNode scope) { // this.scopeManager = scopeManager; // // this.key = key; // this.scopeTag = scopeTag; // this.scope = scope; // } // // /** // * Returns the key that this service binder was created for. // * // * @param <T> the type of the key // * @return the key // */ // @Nonnull // public <T> T getKey() { // //noinspection unchecked // return (T) key; // } // // /** // * Returns the scope tag this service binder belongs to. // * // * @return the scope tag // */ // @Nonnull // public final String getScopeTag() { // return scopeTag; // } // // /** // * Adds the service to the scope. // * // * @param serviceTag the tag of the service // * @param service the service // */ // public void addService(@Nonnull String serviceTag, @Nonnull Object service) { // scope.addService(serviceTag, service); // } // // /** // * Returns whether the service with given service tag is in the local scope. // * // * @param serviceTag the service tag // * @return if the service is in the scope // */ // public boolean hasService(@Nonnull String serviceTag) { // return scope.hasService(serviceTag); // } // // /** // * Retrieves the service from the local scope if it exists. // * // * @param serviceTag the service tag // * @param <T> the type of the service // * @return the service // * @throws IllegalArgumentException if the service is not in the scope // */ // @Nonnull // public <T> T getService(@Nonnull String serviceTag) { // return scope.getService(serviceTag); // } // // /** // * Adds an alias to the service within the local scope. Callbacks are not called for aliases, but they can be found as services. // * // * @param alias the alias // * @param service the service // */ // public void addAlias(@Nonnull String alias, @Nonnull Object service) { // scope.addAlias(alias, service); // } // // /** // * Returns whether the service can be found within the currently existing active scopes. // * // * @param serviceTag the service tag // * @return if the service exists in active scopes // */ // public boolean canFindService(@Nonnull String serviceTag) { // return scopeManager.canFindService(serviceTag); // } // // /** // * Retrieves the service from the active scopes if it exists. // * // * @param serviceTag the service tag // * @param <T> the type of the service // * @return the service // * @throws IllegalArgumentException if the service is not found in any active scopes // */ // @Nonnull // public <T> T lookupService(@Nonnull String serviceTag) { // return scopeManager.lookupService(serviceTag); // } // // /** // * Returns whether the service can be found if looked up from the provided scope. // * // * @param scopeTag the scope tag // * @param serviceTag the service tag // * @return whether the service can be looked up from the provided scope // */ // public boolean canFindFromScope(String scopeTag, String serviceTag) { // return scopeManager.canFindFromScope(scopeTag, serviceTag, ScopeLookupMode.ALL); // } // // /** // * Retrieves the service from the current scope or any of its parents, if the service exists. // * // * @param serviceTag the service tag // * @param <T> the type of the service // * @return the service // * @throws IllegalArgumentException if the service is not found in the scope or any of its parents // */ // @Nonnull // public <T> T lookupFromScope(String scopeTag, String serviceTag) { // return scopeManager.lookupFromScope(scopeTag, serviceTag, ScopeLookupMode.ALL); // } // // /** // * Returns the {@link Backstack} that manages the scopes. // * // * @return the backstack // */ // @Nonnull // public Backstack getBackstack() { // return scopeManager.getBackstack(); // } // }
import com.zhuinden.simplestack.ScopeKey; import com.zhuinden.simplestack.ServiceBinder;
package com.zhuinden.simplestack.helpers; public interface HasParentServices extends ScopeKey.Child {
// Path: simple-stack/src/main/java/com/zhuinden/simplestack/ScopeKey.java // public interface ScopeKey { // /** // * Defines the tag of the scope this key defines the existence of. // * // * @return the tag of the scope // */ // @Nonnull // String getScopeTag(); // // /** // * Inheriting from {@link Child} enables defining an explicit parent hierarchy, thus ensuring that // * even if the scopes are not defined by the tags of any existing keys in the {@link Backstack}'s current {@link History}, // * the scopes will still be created, bound and shall exist. // * // * During {@link Backstack#lookupService(String)}, the explicit parents are traversed first, and implicit parents second. Implicit scope inheritance means that the previous keys' scopes will be traversed as well. // * // * If a {@link Child} is the top-most scope, then its explicit scopes are activated as well, so their services have {@link ScopedServices.Activated#onServiceActive()} called if they implement {@link com.zhuinden.simplestack.ScopedServices.Activated}. // */ // public interface Child { // /** // * Defines the hierarchy of the parent scope that ought to exist as explicit parents of this key. // * // * The order of the items matters: the top-most scope is the first, the bottom-most parent is the last. // * // * @return the list of scope tags that ought to serve as the key's hierarchy of explicit parents // */ // @Nonnull // List<String> getParentScopes(); // } // } // // Path: simple-stack/src/main/java/com/zhuinden/simplestack/ServiceBinder.java // public class ServiceBinder { // private final ScopeManager scopeManager; // // private final Object key; // private final String scopeTag; // private final ScopeNode scope; // // ServiceBinder(ScopeManager scopeManager, Object key, String scopeTag, ScopeNode scope) { // this.scopeManager = scopeManager; // // this.key = key; // this.scopeTag = scopeTag; // this.scope = scope; // } // // /** // * Returns the key that this service binder was created for. // * // * @param <T> the type of the key // * @return the key // */ // @Nonnull // public <T> T getKey() { // //noinspection unchecked // return (T) key; // } // // /** // * Returns the scope tag this service binder belongs to. // * // * @return the scope tag // */ // @Nonnull // public final String getScopeTag() { // return scopeTag; // } // // /** // * Adds the service to the scope. // * // * @param serviceTag the tag of the service // * @param service the service // */ // public void addService(@Nonnull String serviceTag, @Nonnull Object service) { // scope.addService(serviceTag, service); // } // // /** // * Returns whether the service with given service tag is in the local scope. // * // * @param serviceTag the service tag // * @return if the service is in the scope // */ // public boolean hasService(@Nonnull String serviceTag) { // return scope.hasService(serviceTag); // } // // /** // * Retrieves the service from the local scope if it exists. // * // * @param serviceTag the service tag // * @param <T> the type of the service // * @return the service // * @throws IllegalArgumentException if the service is not in the scope // */ // @Nonnull // public <T> T getService(@Nonnull String serviceTag) { // return scope.getService(serviceTag); // } // // /** // * Adds an alias to the service within the local scope. Callbacks are not called for aliases, but they can be found as services. // * // * @param alias the alias // * @param service the service // */ // public void addAlias(@Nonnull String alias, @Nonnull Object service) { // scope.addAlias(alias, service); // } // // /** // * Returns whether the service can be found within the currently existing active scopes. // * // * @param serviceTag the service tag // * @return if the service exists in active scopes // */ // public boolean canFindService(@Nonnull String serviceTag) { // return scopeManager.canFindService(serviceTag); // } // // /** // * Retrieves the service from the active scopes if it exists. // * // * @param serviceTag the service tag // * @param <T> the type of the service // * @return the service // * @throws IllegalArgumentException if the service is not found in any active scopes // */ // @Nonnull // public <T> T lookupService(@Nonnull String serviceTag) { // return scopeManager.lookupService(serviceTag); // } // // /** // * Returns whether the service can be found if looked up from the provided scope. // * // * @param scopeTag the scope tag // * @param serviceTag the service tag // * @return whether the service can be looked up from the provided scope // */ // public boolean canFindFromScope(String scopeTag, String serviceTag) { // return scopeManager.canFindFromScope(scopeTag, serviceTag, ScopeLookupMode.ALL); // } // // /** // * Retrieves the service from the current scope or any of its parents, if the service exists. // * // * @param serviceTag the service tag // * @param <T> the type of the service // * @return the service // * @throws IllegalArgumentException if the service is not found in the scope or any of its parents // */ // @Nonnull // public <T> T lookupFromScope(String scopeTag, String serviceTag) { // return scopeManager.lookupFromScope(scopeTag, serviceTag, ScopeLookupMode.ALL); // } // // /** // * Returns the {@link Backstack} that manages the scopes. // * // * @return the backstack // */ // @Nonnull // public Backstack getBackstack() { // return scopeManager.getBackstack(); // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasParentServices.java import com.zhuinden.simplestack.ScopeKey; import com.zhuinden.simplestack.ServiceBinder; package com.zhuinden.simplestack.helpers; public interface HasParentServices extends ScopeKey.Child {
void bindServices(ServiceBinder serviceBinder);
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/ScopingBackEventDispatchTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithExplicitParent.java // public abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices { // public TestKeyWithExplicitParent(String name) { // super(name); // } // // protected TestKeyWithExplicitParent(Parcel in) { // super(in); // } // // @Override // public final void bindServices(ServiceBinder serviceBinder) { // if(name.equals(serviceBinder.getScopeTag())) { // bindOwnServices(serviceBinder); // } else { // bindParentServices(serviceBinder); // } // } // // protected abstract void bindParentServices(ServiceBinder serviceBinder); // // protected abstract void bindOwnServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithOnlyParentServices.java // public abstract class TestKeyWithOnlyParentServices extends TestKey implements HasParentServices { // private final List<String> parentScopes; // // public TestKeyWithOnlyParentServices(String name, List<String> parentScopes) { // super(name); // this.parentScopes = parentScopes; // } // // @Nonnull // @Override // public List<String> getParentScopes() { // return parentScopes; // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // }
import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent; import com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import org.junit.Test; import java.util.List; import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nonnull; import static org.assertj.core.api.Assertions.assertThat;
package com.zhuinden.simplestack; public class ScopingBackEventDispatchTest { private class HandlesBackOnce implements ScopedServices.HandlesBack { private boolean handledBackOnce = false; @Override public boolean onBackEvent() { if(!handledBackOnce) { this.handledBackOnce = true; return true; } return false; } } @Test public void onBackStackGoBackDispatchesBackToActiveScope() { final HandlesBackOnce service1 = new HandlesBackOnce(); final HandlesBackOnce service2 = new HandlesBackOnce();
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithExplicitParent.java // public abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices { // public TestKeyWithExplicitParent(String name) { // super(name); // } // // protected TestKeyWithExplicitParent(Parcel in) { // super(in); // } // // @Override // public final void bindServices(ServiceBinder serviceBinder) { // if(name.equals(serviceBinder.getScopeTag())) { // bindOwnServices(serviceBinder); // } else { // bindParentServices(serviceBinder); // } // } // // protected abstract void bindParentServices(ServiceBinder serviceBinder); // // protected abstract void bindOwnServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithOnlyParentServices.java // public abstract class TestKeyWithOnlyParentServices extends TestKey implements HasParentServices { // private final List<String> parentScopes; // // public TestKeyWithOnlyParentServices(String name, List<String> parentScopes) { // super(name); // this.parentScopes = parentScopes; // } // // @Nonnull // @Override // public List<String> getParentScopes() { // return parentScopes; // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/ScopingBackEventDispatchTest.java import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent; import com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import org.junit.Test; import java.util.List; import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nonnull; import static org.assertj.core.api.Assertions.assertThat; package com.zhuinden.simplestack; public class ScopingBackEventDispatchTest { private class HandlesBackOnce implements ScopedServices.HandlesBack { private boolean handledBackOnce = false; @Override public boolean onBackEvent() { if(!handledBackOnce) { this.handledBackOnce = true; return true; } return false; } } @Test public void onBackStackGoBackDispatchesBackToActiveScope() { final HandlesBackOnce service1 = new HandlesBackOnce(); final HandlesBackOnce service2 = new HandlesBackOnce();
Object key1 = new TestKeyWithScope("key1") {
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/ScopingBackEventDispatchTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithExplicitParent.java // public abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices { // public TestKeyWithExplicitParent(String name) { // super(name); // } // // protected TestKeyWithExplicitParent(Parcel in) { // super(in); // } // // @Override // public final void bindServices(ServiceBinder serviceBinder) { // if(name.equals(serviceBinder.getScopeTag())) { // bindOwnServices(serviceBinder); // } else { // bindParentServices(serviceBinder); // } // } // // protected abstract void bindParentServices(ServiceBinder serviceBinder); // // protected abstract void bindOwnServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithOnlyParentServices.java // public abstract class TestKeyWithOnlyParentServices extends TestKey implements HasParentServices { // private final List<String> parentScopes; // // public TestKeyWithOnlyParentServices(String name, List<String> parentScopes) { // super(name); // this.parentScopes = parentScopes; // } // // @Nonnull // @Override // public List<String> getParentScopes() { // return parentScopes; // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // }
import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent; import com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import org.junit.Test; import java.util.List; import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nonnull; import static org.assertj.core.api.Assertions.assertThat;
package com.zhuinden.simplestack; public class ScopingBackEventDispatchTest { private class HandlesBackOnce implements ScopedServices.HandlesBack { private boolean handledBackOnce = false; @Override public boolean onBackEvent() { if(!handledBackOnce) { this.handledBackOnce = true; return true; } return false; } } @Test public void onBackStackGoBackDispatchesBackToActiveScope() { final HandlesBackOnce service1 = new HandlesBackOnce(); final HandlesBackOnce service2 = new HandlesBackOnce(); Object key1 = new TestKeyWithScope("key1") { @Override public void bindServices(ServiceBinder serviceBinder) { serviceBinder.addService("service1", service1); } }; Object key2 = new TestKeyWithScope("key2") { @Override public void bindServices(ServiceBinder serviceBinder) { serviceBinder.addService("service2", service2); } }; Backstack backstack = new Backstack();
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithExplicitParent.java // public abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices { // public TestKeyWithExplicitParent(String name) { // super(name); // } // // protected TestKeyWithExplicitParent(Parcel in) { // super(in); // } // // @Override // public final void bindServices(ServiceBinder serviceBinder) { // if(name.equals(serviceBinder.getScopeTag())) { // bindOwnServices(serviceBinder); // } else { // bindParentServices(serviceBinder); // } // } // // protected abstract void bindParentServices(ServiceBinder serviceBinder); // // protected abstract void bindOwnServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithOnlyParentServices.java // public abstract class TestKeyWithOnlyParentServices extends TestKey implements HasParentServices { // private final List<String> parentScopes; // // public TestKeyWithOnlyParentServices(String name, List<String> parentScopes) { // super(name); // this.parentScopes = parentScopes; // } // // @Nonnull // @Override // public List<String> getParentScopes() { // return parentScopes; // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/ScopingBackEventDispatchTest.java import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent; import com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import org.junit.Test; import java.util.List; import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nonnull; import static org.assertj.core.api.Assertions.assertThat; package com.zhuinden.simplestack; public class ScopingBackEventDispatchTest { private class HandlesBackOnce implements ScopedServices.HandlesBack { private boolean handledBackOnce = false; @Override public boolean onBackEvent() { if(!handledBackOnce) { this.handledBackOnce = true; return true; } return false; } } @Test public void onBackStackGoBackDispatchesBackToActiveScope() { final HandlesBackOnce service1 = new HandlesBackOnce(); final HandlesBackOnce service2 = new HandlesBackOnce(); Object key1 = new TestKeyWithScope("key1") { @Override public void bindServices(ServiceBinder serviceBinder) { serviceBinder.addService("service1", service1); } }; Object key2 = new TestKeyWithScope("key2") { @Override public void bindServices(ServiceBinder serviceBinder) { serviceBinder.addService("service2", service2); } }; Backstack backstack = new Backstack();
backstack.setScopedServices(new ServiceProvider());
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/ScopingBackEventDispatchTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithExplicitParent.java // public abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices { // public TestKeyWithExplicitParent(String name) { // super(name); // } // // protected TestKeyWithExplicitParent(Parcel in) { // super(in); // } // // @Override // public final void bindServices(ServiceBinder serviceBinder) { // if(name.equals(serviceBinder.getScopeTag())) { // bindOwnServices(serviceBinder); // } else { // bindParentServices(serviceBinder); // } // } // // protected abstract void bindParentServices(ServiceBinder serviceBinder); // // protected abstract void bindOwnServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithOnlyParentServices.java // public abstract class TestKeyWithOnlyParentServices extends TestKey implements HasParentServices { // private final List<String> parentScopes; // // public TestKeyWithOnlyParentServices(String name, List<String> parentScopes) { // super(name); // this.parentScopes = parentScopes; // } // // @Nonnull // @Override // public List<String> getParentScopes() { // return parentScopes; // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // }
import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent; import com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import org.junit.Test; import java.util.List; import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nonnull; import static org.assertj.core.api.Assertions.assertThat;
backstack.setStateChanger(stateChanger); assertThat(backstack.getHistory()).containsExactly(key); backstack.detachStateChanger(); boolean handled = backstack.goBack(); assertThat(handled).isTrue(); assertThat(service.handledBackOnce).isTrue(); handled = backstack.goBack(); // returns `false` even if no state changer assertThat(handled).isFalse(); } @Test public void onBackDispatchHandlesBackHandlesInActiveParentScope() { final HandlesBackOnce previousService = new HandlesBackOnce(); Object previousKey = new TestKeyWithScope("previousKey") { @Override public void bindServices(ServiceBinder serviceBinder) { serviceBinder.addService("service1", previousService); } }; final HandlesBackOnce parentService1 = new HandlesBackOnce(); final HandlesBackOnce parentService2 = new HandlesBackOnce(); final HandlesBackOnce service1 = new HandlesBackOnce(); final HandlesBackOnce service2 = new HandlesBackOnce();
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithExplicitParent.java // public abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices { // public TestKeyWithExplicitParent(String name) { // super(name); // } // // protected TestKeyWithExplicitParent(Parcel in) { // super(in); // } // // @Override // public final void bindServices(ServiceBinder serviceBinder) { // if(name.equals(serviceBinder.getScopeTag())) { // bindOwnServices(serviceBinder); // } else { // bindParentServices(serviceBinder); // } // } // // protected abstract void bindParentServices(ServiceBinder serviceBinder); // // protected abstract void bindOwnServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithOnlyParentServices.java // public abstract class TestKeyWithOnlyParentServices extends TestKey implements HasParentServices { // private final List<String> parentScopes; // // public TestKeyWithOnlyParentServices(String name, List<String> parentScopes) { // super(name); // this.parentScopes = parentScopes; // } // // @Nonnull // @Override // public List<String> getParentScopes() { // return parentScopes; // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/ScopingBackEventDispatchTest.java import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent; import com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import org.junit.Test; import java.util.List; import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nonnull; import static org.assertj.core.api.Assertions.assertThat; backstack.setStateChanger(stateChanger); assertThat(backstack.getHistory()).containsExactly(key); backstack.detachStateChanger(); boolean handled = backstack.goBack(); assertThat(handled).isTrue(); assertThat(service.handledBackOnce).isTrue(); handled = backstack.goBack(); // returns `false` even if no state changer assertThat(handled).isFalse(); } @Test public void onBackDispatchHandlesBackHandlesInActiveParentScope() { final HandlesBackOnce previousService = new HandlesBackOnce(); Object previousKey = new TestKeyWithScope("previousKey") { @Override public void bindServices(ServiceBinder serviceBinder) { serviceBinder.addService("service1", previousService); } }; final HandlesBackOnce parentService1 = new HandlesBackOnce(); final HandlesBackOnce parentService2 = new HandlesBackOnce(); final HandlesBackOnce service1 = new HandlesBackOnce(); final HandlesBackOnce service2 = new HandlesBackOnce();
Object key = new TestKeyWithExplicitParent("key") {
Zhuinden/simple-stack
simple-stack/src/test/java/com/zhuinden/simplestack/ScopingBackEventDispatchTest.java
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithExplicitParent.java // public abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices { // public TestKeyWithExplicitParent(String name) { // super(name); // } // // protected TestKeyWithExplicitParent(Parcel in) { // super(in); // } // // @Override // public final void bindServices(ServiceBinder serviceBinder) { // if(name.equals(serviceBinder.getScopeTag())) { // bindOwnServices(serviceBinder); // } else { // bindParentServices(serviceBinder); // } // } // // protected abstract void bindParentServices(ServiceBinder serviceBinder); // // protected abstract void bindOwnServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithOnlyParentServices.java // public abstract class TestKeyWithOnlyParentServices extends TestKey implements HasParentServices { // private final List<String> parentScopes; // // public TestKeyWithOnlyParentServices(String name, List<String> parentScopes) { // super(name); // this.parentScopes = parentScopes; // } // // @Nonnull // @Override // public List<String> getParentScopes() { // return parentScopes; // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // }
import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent; import com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import org.junit.Test; import java.util.List; import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nonnull; import static org.assertj.core.api.Assertions.assertThat;
assertThat(service1.handledBackOnce).isTrue(); assertThat(service2.handledBackOnce).isTrue(); handled = backstack.goBack(); assertThat(handled).isTrue(); assertThat(parentService1.handledBackOnce).isTrue(); assertThat(parentService2.handledBackOnce).isTrue(); assertThat(service1.handledBackOnce).isTrue(); assertThat(service2.handledBackOnce).isTrue(); assertThat(previousService.handledBackOnce).isFalse(); assertThat(backstack.getHistory()).containsExactly(previousKey, key); handled = backstack.goBack(); assertThat(handled).isTrue(); assertThat(backstack.getHistory()).containsExactly(previousKey); handled = backstack.goBack(); assertThat(handled).isTrue(); assertThat(previousService.handledBackOnce).isTrue(); handled = backstack.goBack(); assertThat(handled).isFalse(); } @Test public void onBackDispatchHandlesBackHandlesInActiveParentScopeEvenIfTopIsNotScopeKey() { final HandlesBackOnce parentService = new HandlesBackOnce();
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java // public class ServiceProvider // implements ScopedServices { // @Override // public void bindServices(@Nonnull ServiceBinder serviceBinder) { // Object key = serviceBinder.getKey(); // if(key instanceof HasServices) { // ((HasServices) key).bindServices(serviceBinder); // return; // } // if(key instanceof HasParentServices) { // ((HasParentServices) key).bindServices(serviceBinder); // //noinspection UnnecessaryReturnStatement // return; // } // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithExplicitParent.java // public abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices { // public TestKeyWithExplicitParent(String name) { // super(name); // } // // protected TestKeyWithExplicitParent(Parcel in) { // super(in); // } // // @Override // public final void bindServices(ServiceBinder serviceBinder) { // if(name.equals(serviceBinder.getScopeTag())) { // bindOwnServices(serviceBinder); // } else { // bindParentServices(serviceBinder); // } // } // // protected abstract void bindParentServices(ServiceBinder serviceBinder); // // protected abstract void bindOwnServices(ServiceBinder serviceBinder); // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithOnlyParentServices.java // public abstract class TestKeyWithOnlyParentServices extends TestKey implements HasParentServices { // private final List<String> parentScopes; // // public TestKeyWithOnlyParentServices(String name, List<String> parentScopes) { // super(name); // this.parentScopes = parentScopes; // } // // @Nonnull // @Override // public List<String> getParentScopes() { // return parentScopes; // } // } // // Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithScope.java // public abstract class TestKeyWithScope // extends TestKey // implements HasServices { // public TestKeyWithScope(String name) { // super(name); // } // // protected TestKeyWithScope(Parcel in) { // super(in); // } // // @Nonnull // @Override // public String getScopeTag() { // return name; // } // } // Path: simple-stack/src/test/java/com/zhuinden/simplestack/ScopingBackEventDispatchTest.java import com.zhuinden.simplestack.helpers.ServiceProvider; import com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent; import com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices; import com.zhuinden.simplestack.helpers.TestKeyWithScope; import org.junit.Test; import java.util.List; import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nonnull; import static org.assertj.core.api.Assertions.assertThat; assertThat(service1.handledBackOnce).isTrue(); assertThat(service2.handledBackOnce).isTrue(); handled = backstack.goBack(); assertThat(handled).isTrue(); assertThat(parentService1.handledBackOnce).isTrue(); assertThat(parentService2.handledBackOnce).isTrue(); assertThat(service1.handledBackOnce).isTrue(); assertThat(service2.handledBackOnce).isTrue(); assertThat(previousService.handledBackOnce).isFalse(); assertThat(backstack.getHistory()).containsExactly(previousKey, key); handled = backstack.goBack(); assertThat(handled).isTrue(); assertThat(backstack.getHistory()).containsExactly(previousKey); handled = backstack.goBack(); assertThat(handled).isTrue(); assertThat(previousService.handledBackOnce).isTrue(); handled = backstack.goBack(); assertThat(handled).isFalse(); } @Test public void onBackDispatchHandlesBackHandlesInActiveParentScopeEvenIfTopIsNotScopeKey() { final HandlesBackOnce parentService = new HandlesBackOnce();
Object key = new TestKeyWithOnlyParentServices("key", History.of("parentScope")) {
Zhuinden/simple-stack
samples/basic-samples/simple-stack-example-basic-java-view/src/main/java/com/zhuinden/navigationexampleview/screens/OtherKey.java
// Path: samples/basic-samples/simple-stack-example-basic-java-view/src/main/java/com/zhuinden/navigationexampleview/core/navigation/BaseKey.java // public abstract class BaseKey implements DefaultViewKey, Parcelable { // @NonNull // @Override // public ViewChangeHandler viewChangeHandler() { // return new FadeViewChangeHandler(); // } // } // // Path: simple-stack/src/main/java/com/zhuinden/simplestack/navigator/ViewChangeHandler.java // public interface ViewChangeHandler { // /** // * It must be called to signal that the view change is complete. // */ // interface ViewChangeCallback { // void onCompleted(); // } // // /** // * Perform the view change. The previous view must be removed from the container, and the new view must be added to the container. // * When complete, the completion callback must be called. // * // * @param container the container for the views // * @param previousView the previous view // * @param newView the new view // * @param direction the direction (from the StateChange) // * @param viewChangeCallback the callback that must be called when the view change is complete. // */ // void performViewChange(@Nonnull final ViewGroup container, @Nonnull final View previousView, @Nonnull final View newView, final int direction, @Nonnull final ViewChangeCallback viewChangeCallback); // } // // Path: simple-stack/src/main/java/com/zhuinden/simplestack/navigator/changehandlers/SegueViewChangeHandler.java // @TargetApi(11) // public final class SegueViewChangeHandler // extends AnimatorViewChangeHandler { // @Override // protected Animator createAnimator(@Nonnull View from, @Nonnull View to, int direction) { // int fromTranslation = (-1) * direction * from.getWidth(); // int toTranslation = direction * to.getWidth(); // // AnimatorSet set = new AnimatorSet(); // set.play(ObjectAnimator.ofFloat(from, "translationX", fromTranslation)); // set.play(ObjectAnimator.ofFloat(to, "translationX", toTranslation, 0)); // return set; // } // // @Override // protected void resetPreviousViewValues(View previousView) { // previousView.setTranslationX(0f); // } // }
import androidx.annotation.NonNull; import com.google.auto.value.AutoValue; import com.zhuinden.navigationexampleview.R; import com.zhuinden.navigationexampleview.core.navigation.BaseKey; import com.zhuinden.simplestack.navigator.ViewChangeHandler; import com.zhuinden.simplestack.navigator.changehandlers.SegueViewChangeHandler;
package com.zhuinden.navigationexampleview.screens; /** * Created by Owner on 2017. 06. 29.. */ @AutoValue public abstract class OtherKey extends BaseKey { public static OtherKey create() { return new AutoValue_OtherKey(); } @Override public int layout() { return R.layout.other_view; } @NonNull @Override
// Path: samples/basic-samples/simple-stack-example-basic-java-view/src/main/java/com/zhuinden/navigationexampleview/core/navigation/BaseKey.java // public abstract class BaseKey implements DefaultViewKey, Parcelable { // @NonNull // @Override // public ViewChangeHandler viewChangeHandler() { // return new FadeViewChangeHandler(); // } // } // // Path: simple-stack/src/main/java/com/zhuinden/simplestack/navigator/ViewChangeHandler.java // public interface ViewChangeHandler { // /** // * It must be called to signal that the view change is complete. // */ // interface ViewChangeCallback { // void onCompleted(); // } // // /** // * Perform the view change. The previous view must be removed from the container, and the new view must be added to the container. // * When complete, the completion callback must be called. // * // * @param container the container for the views // * @param previousView the previous view // * @param newView the new view // * @param direction the direction (from the StateChange) // * @param viewChangeCallback the callback that must be called when the view change is complete. // */ // void performViewChange(@Nonnull final ViewGroup container, @Nonnull final View previousView, @Nonnull final View newView, final int direction, @Nonnull final ViewChangeCallback viewChangeCallback); // } // // Path: simple-stack/src/main/java/com/zhuinden/simplestack/navigator/changehandlers/SegueViewChangeHandler.java // @TargetApi(11) // public final class SegueViewChangeHandler // extends AnimatorViewChangeHandler { // @Override // protected Animator createAnimator(@Nonnull View from, @Nonnull View to, int direction) { // int fromTranslation = (-1) * direction * from.getWidth(); // int toTranslation = direction * to.getWidth(); // // AnimatorSet set = new AnimatorSet(); // set.play(ObjectAnimator.ofFloat(from, "translationX", fromTranslation)); // set.play(ObjectAnimator.ofFloat(to, "translationX", toTranslation, 0)); // return set; // } // // @Override // protected void resetPreviousViewValues(View previousView) { // previousView.setTranslationX(0f); // } // } // Path: samples/basic-samples/simple-stack-example-basic-java-view/src/main/java/com/zhuinden/navigationexampleview/screens/OtherKey.java import androidx.annotation.NonNull; import com.google.auto.value.AutoValue; import com.zhuinden.navigationexampleview.R; import com.zhuinden.navigationexampleview.core.navigation.BaseKey; import com.zhuinden.simplestack.navigator.ViewChangeHandler; import com.zhuinden.simplestack.navigator.changehandlers.SegueViewChangeHandler; package com.zhuinden.navigationexampleview.screens; /** * Created by Owner on 2017. 06. 29.. */ @AutoValue public abstract class OtherKey extends BaseKey { public static OtherKey create() { return new AutoValue_OtherKey(); } @Override public int layout() { return R.layout.other_view; } @NonNull @Override
public ViewChangeHandler viewChangeHandler() {
Zhuinden/simple-stack
samples/basic-samples/simple-stack-example-basic-java-view/src/main/java/com/zhuinden/navigationexampleview/screens/OtherKey.java
// Path: samples/basic-samples/simple-stack-example-basic-java-view/src/main/java/com/zhuinden/navigationexampleview/core/navigation/BaseKey.java // public abstract class BaseKey implements DefaultViewKey, Parcelable { // @NonNull // @Override // public ViewChangeHandler viewChangeHandler() { // return new FadeViewChangeHandler(); // } // } // // Path: simple-stack/src/main/java/com/zhuinden/simplestack/navigator/ViewChangeHandler.java // public interface ViewChangeHandler { // /** // * It must be called to signal that the view change is complete. // */ // interface ViewChangeCallback { // void onCompleted(); // } // // /** // * Perform the view change. The previous view must be removed from the container, and the new view must be added to the container. // * When complete, the completion callback must be called. // * // * @param container the container for the views // * @param previousView the previous view // * @param newView the new view // * @param direction the direction (from the StateChange) // * @param viewChangeCallback the callback that must be called when the view change is complete. // */ // void performViewChange(@Nonnull final ViewGroup container, @Nonnull final View previousView, @Nonnull final View newView, final int direction, @Nonnull final ViewChangeCallback viewChangeCallback); // } // // Path: simple-stack/src/main/java/com/zhuinden/simplestack/navigator/changehandlers/SegueViewChangeHandler.java // @TargetApi(11) // public final class SegueViewChangeHandler // extends AnimatorViewChangeHandler { // @Override // protected Animator createAnimator(@Nonnull View from, @Nonnull View to, int direction) { // int fromTranslation = (-1) * direction * from.getWidth(); // int toTranslation = direction * to.getWidth(); // // AnimatorSet set = new AnimatorSet(); // set.play(ObjectAnimator.ofFloat(from, "translationX", fromTranslation)); // set.play(ObjectAnimator.ofFloat(to, "translationX", toTranslation, 0)); // return set; // } // // @Override // protected void resetPreviousViewValues(View previousView) { // previousView.setTranslationX(0f); // } // }
import androidx.annotation.NonNull; import com.google.auto.value.AutoValue; import com.zhuinden.navigationexampleview.R; import com.zhuinden.navigationexampleview.core.navigation.BaseKey; import com.zhuinden.simplestack.navigator.ViewChangeHandler; import com.zhuinden.simplestack.navigator.changehandlers.SegueViewChangeHandler;
package com.zhuinden.navigationexampleview.screens; /** * Created by Owner on 2017. 06. 29.. */ @AutoValue public abstract class OtherKey extends BaseKey { public static OtherKey create() { return new AutoValue_OtherKey(); } @Override public int layout() { return R.layout.other_view; } @NonNull @Override public ViewChangeHandler viewChangeHandler() {
// Path: samples/basic-samples/simple-stack-example-basic-java-view/src/main/java/com/zhuinden/navigationexampleview/core/navigation/BaseKey.java // public abstract class BaseKey implements DefaultViewKey, Parcelable { // @NonNull // @Override // public ViewChangeHandler viewChangeHandler() { // return new FadeViewChangeHandler(); // } // } // // Path: simple-stack/src/main/java/com/zhuinden/simplestack/navigator/ViewChangeHandler.java // public interface ViewChangeHandler { // /** // * It must be called to signal that the view change is complete. // */ // interface ViewChangeCallback { // void onCompleted(); // } // // /** // * Perform the view change. The previous view must be removed from the container, and the new view must be added to the container. // * When complete, the completion callback must be called. // * // * @param container the container for the views // * @param previousView the previous view // * @param newView the new view // * @param direction the direction (from the StateChange) // * @param viewChangeCallback the callback that must be called when the view change is complete. // */ // void performViewChange(@Nonnull final ViewGroup container, @Nonnull final View previousView, @Nonnull final View newView, final int direction, @Nonnull final ViewChangeCallback viewChangeCallback); // } // // Path: simple-stack/src/main/java/com/zhuinden/simplestack/navigator/changehandlers/SegueViewChangeHandler.java // @TargetApi(11) // public final class SegueViewChangeHandler // extends AnimatorViewChangeHandler { // @Override // protected Animator createAnimator(@Nonnull View from, @Nonnull View to, int direction) { // int fromTranslation = (-1) * direction * from.getWidth(); // int toTranslation = direction * to.getWidth(); // // AnimatorSet set = new AnimatorSet(); // set.play(ObjectAnimator.ofFloat(from, "translationX", fromTranslation)); // set.play(ObjectAnimator.ofFloat(to, "translationX", toTranslation, 0)); // return set; // } // // @Override // protected void resetPreviousViewValues(View previousView) { // previousView.setTranslationX(0f); // } // } // Path: samples/basic-samples/simple-stack-example-basic-java-view/src/main/java/com/zhuinden/navigationexampleview/screens/OtherKey.java import androidx.annotation.NonNull; import com.google.auto.value.AutoValue; import com.zhuinden.navigationexampleview.R; import com.zhuinden.navigationexampleview.core.navigation.BaseKey; import com.zhuinden.simplestack.navigator.ViewChangeHandler; import com.zhuinden.simplestack.navigator.changehandlers.SegueViewChangeHandler; package com.zhuinden.navigationexampleview.screens; /** * Created by Owner on 2017. 06. 29.. */ @AutoValue public abstract class OtherKey extends BaseKey { public static OtherKey create() { return new AutoValue_OtherKey(); } @Override public int layout() { return R.layout.other_view; } @NonNull @Override public ViewChangeHandler viewChangeHandler() {
return new SegueViewChangeHandler();
oduwa/AndroidMirroring
Android mirroring app/app/src/main/java/com/vnc/oeo/mediaprojectiontest1/HomeActivity.java
// Path: Android mirroring app/app/src/main/Networking/TCPClient.java // public class TCPClient { // // public interface SocketImageCallback { // void didReceiveMessage(byte[] frameMessage); // } // // static boolean shouldFetch = true; // // // public static void start(SocketImageCallback socketImageCallback) { // try { // int serverPort = 6880; // ServerSocket listenSocket = new ServerSocket(serverPort); // // System.out.println("server start listening... ... ..."); // // while (true) { // Socket clientSocket = listenSocket.accept(); // if(shouldFetch == true){ // Connection c = new Connection(clientSocket, socketImageCallback); // } // } // } catch (IOException e) { // System.out.println("Listen :" + e.getMessage()); // } // } // } // // Path: Android mirroring app/app/src/main/Networking/TCPServer.java // public class TCPServer { // // public static void start(byte[] d) {// arguments supply message and hostname of destination // Socket s = null; // try { // //htc 10.10.19.196 // int serverPort = 6880; // String ip = "10.10.19.196"; //"10.0.2.2";//"192.168.5.5";//"10.10.19.228"; //"localhost"; // //String data = "Hello, How are you?"; // // byte[] data; // // byte[] ints = new byte[1184 * 768]; // // // // for (int i = 0; i < 1184 * 768; i++) { // // ints[i] = (byte) Color.RED; //0x00FF0000; // // } // // data = ints; // // s = new Socket(ip, serverPort); // DataInputStream input = new DataInputStream(s.getInputStream()); // DataOutputStream output = new DataOutputStream(s.getOutputStream()); // // //Step 1 send length // System.out.println("Length" + d.length); // output.writeInt(d.length); // //Step 2 send length // System.out.println("Writing......."); // //output.writeBytes(data); // UTF is a string encoding // output.write(d); // System.out.println("Written"); // // /* // //Step 1 read length // int nb = input.readInt(); // byte[] digit = new byte[nb]; // // //Step 2 read byte // for (int i = 0; i < nb; i++) { // digit[i] = input.readByte(); // } // // String st = new String(digit); // System.out.println("Received: " + st); // */ // } catch (UnknownHostException e) { // System.out.println("Sock:" + e.getMessage()); // } catch (EOFException e) { // System.out.println("EOF:" + e.getMessage()); // } catch (IOException e) { // System.out.println("IO:" + e.getMessage()); // } finally { // if (s != null) { // try { // s.close(); // } catch (IOException e) {/*close failed*/ // // } // } // } // } // } // // Path: Android mirroring app/app/src/main/VNCServerJNIWrapper/VNCAndroidServer.java // public class VNCAndroidServer { // // public native String getStringFromJNI(); // // public native void newScreenAvailable(ByteBuffer buffer); // public native void newFrameAvailable(byte[] frameData, int len); // public static native void sendTextMessage(String msg, int len); // public static native void newScreenAvailable2(byte[] frameData, int len); // public static native void setNewScreen(byte[] frameData, int len); // // public static native void startSharedMemServer(); // public static native void startSharedMemClient(); // // // public static void start(){ // Thread t = new Thread(new Runnable() { // @Override // public void run() { // VNCAndroidServer.newScreenAvailable2(null, 0); // } // }); // t.start(); // } // // static { // System.loadLibrary("JNIDummy"); // } // // } // // Path: Android mirroring app/app/src/main/Bindings/Server.java // public class Server { // // public static native long getInstance(); // // static { // System.loadLibrary("j"); // } // // } // // Path: Android mirroring app/app/src/main/java/com/vnc/oeo/mediaprojectiontest1/VNCUtility.java // public static int getIntFromColor(int Red, int Green, int Blue){ // Red = (Red << 16) & 0x00FF0000; //Shift red 16-bits and mask out other stuff // Green = (Green << 8) & 0x0000FF00; //Shift Green 8-bits and mask out other stuff // Blue = Blue & 0x000000FF; //Mask out anything not blue. // // return 0xFF000000 | Red | Green | Blue; //0xFF000000 for 100% Alpha. Bitwise OR everything together. // }
import android.app.Activity; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; import android.os.Build; import android.os.Bundle; import android.util.Base64; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.ImageView; import com.vnc.oeo.mediaprojectiontest1.R; import java.io.ByteArrayOutputStream; import main.Networking.TCPClient; import main.Networking.TCPServer; import main.VNCServerJNIWrapper.VNCAndroidServer; import main.Bindings.Server; import static main.java.com.vnc.oeo.mediaprojectiontest1.VNCUtility.getIntFromColor;
package main.java.com.vnc.oeo.mediaprojectiontest1; public class HomeActivity extends Activity { private static final String TAG = ServerActivity.class.getName(); private Activity mActivity; private ImageView mImageView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home); // Store Context mActivity = this; //VNCAndroidServer.start(); // Server
// Path: Android mirroring app/app/src/main/Networking/TCPClient.java // public class TCPClient { // // public interface SocketImageCallback { // void didReceiveMessage(byte[] frameMessage); // } // // static boolean shouldFetch = true; // // // public static void start(SocketImageCallback socketImageCallback) { // try { // int serverPort = 6880; // ServerSocket listenSocket = new ServerSocket(serverPort); // // System.out.println("server start listening... ... ..."); // // while (true) { // Socket clientSocket = listenSocket.accept(); // if(shouldFetch == true){ // Connection c = new Connection(clientSocket, socketImageCallback); // } // } // } catch (IOException e) { // System.out.println("Listen :" + e.getMessage()); // } // } // } // // Path: Android mirroring app/app/src/main/Networking/TCPServer.java // public class TCPServer { // // public static void start(byte[] d) {// arguments supply message and hostname of destination // Socket s = null; // try { // //htc 10.10.19.196 // int serverPort = 6880; // String ip = "10.10.19.196"; //"10.0.2.2";//"192.168.5.5";//"10.10.19.228"; //"localhost"; // //String data = "Hello, How are you?"; // // byte[] data; // // byte[] ints = new byte[1184 * 768]; // // // // for (int i = 0; i < 1184 * 768; i++) { // // ints[i] = (byte) Color.RED; //0x00FF0000; // // } // // data = ints; // // s = new Socket(ip, serverPort); // DataInputStream input = new DataInputStream(s.getInputStream()); // DataOutputStream output = new DataOutputStream(s.getOutputStream()); // // //Step 1 send length // System.out.println("Length" + d.length); // output.writeInt(d.length); // //Step 2 send length // System.out.println("Writing......."); // //output.writeBytes(data); // UTF is a string encoding // output.write(d); // System.out.println("Written"); // // /* // //Step 1 read length // int nb = input.readInt(); // byte[] digit = new byte[nb]; // // //Step 2 read byte // for (int i = 0; i < nb; i++) { // digit[i] = input.readByte(); // } // // String st = new String(digit); // System.out.println("Received: " + st); // */ // } catch (UnknownHostException e) { // System.out.println("Sock:" + e.getMessage()); // } catch (EOFException e) { // System.out.println("EOF:" + e.getMessage()); // } catch (IOException e) { // System.out.println("IO:" + e.getMessage()); // } finally { // if (s != null) { // try { // s.close(); // } catch (IOException e) {/*close failed*/ // // } // } // } // } // } // // Path: Android mirroring app/app/src/main/VNCServerJNIWrapper/VNCAndroidServer.java // public class VNCAndroidServer { // // public native String getStringFromJNI(); // // public native void newScreenAvailable(ByteBuffer buffer); // public native void newFrameAvailable(byte[] frameData, int len); // public static native void sendTextMessage(String msg, int len); // public static native void newScreenAvailable2(byte[] frameData, int len); // public static native void setNewScreen(byte[] frameData, int len); // // public static native void startSharedMemServer(); // public static native void startSharedMemClient(); // // // public static void start(){ // Thread t = new Thread(new Runnable() { // @Override // public void run() { // VNCAndroidServer.newScreenAvailable2(null, 0); // } // }); // t.start(); // } // // static { // System.loadLibrary("JNIDummy"); // } // // } // // Path: Android mirroring app/app/src/main/Bindings/Server.java // public class Server { // // public static native long getInstance(); // // static { // System.loadLibrary("j"); // } // // } // // Path: Android mirroring app/app/src/main/java/com/vnc/oeo/mediaprojectiontest1/VNCUtility.java // public static int getIntFromColor(int Red, int Green, int Blue){ // Red = (Red << 16) & 0x00FF0000; //Shift red 16-bits and mask out other stuff // Green = (Green << 8) & 0x0000FF00; //Shift Green 8-bits and mask out other stuff // Blue = Blue & 0x000000FF; //Mask out anything not blue. // // return 0xFF000000 | Red | Green | Blue; //0xFF000000 for 100% Alpha. Bitwise OR everything together. // } // Path: Android mirroring app/app/src/main/java/com/vnc/oeo/mediaprojectiontest1/HomeActivity.java import android.app.Activity; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; import android.os.Build; import android.os.Bundle; import android.util.Base64; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.ImageView; import com.vnc.oeo.mediaprojectiontest1.R; import java.io.ByteArrayOutputStream; import main.Networking.TCPClient; import main.Networking.TCPServer; import main.VNCServerJNIWrapper.VNCAndroidServer; import main.Bindings.Server; import static main.java.com.vnc.oeo.mediaprojectiontest1.VNCUtility.getIntFromColor; package main.java.com.vnc.oeo.mediaprojectiontest1; public class HomeActivity extends Activity { private static final String TAG = ServerActivity.class.getName(); private Activity mActivity; private ImageView mImageView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home); // Store Context mActivity = this; //VNCAndroidServer.start(); // Server
final VNCAndroidServer server = new VNCAndroidServer();
michel-kraemer/gradle-download-task
src/test/java/de/undercouch/gradle/tasks/download/TestBase.java
// Path: src/main/java/de/undercouch/gradle/tasks/download/internal/WorkerExecutorHelper.java // public abstract class WorkerExecutorHelper { // /** // * Creates a new instance of the {@link WorkerExecutorHelper} depending // * on the Gradle version // * @param objectFactory creates Gradle model objects // * @return the helper // */ // public static WorkerExecutorHelper newInstance(ObjectFactory objectFactory) { // if (GradleVersion.current().getBaseVersion().compareTo(GradleVersion.version("5.6")) >= 0) { // return objectFactory.newInstance(DefaultWorkerExecutorHelper.class); // } // return new LegacyWorkerExecutorHelper(); // } // // /** // * Execute a job asynchronously // * @param job the job to execute // */ // public abstract void submit(Job job); // // /** // * Wait for all jobs of the current build operation to complete // */ // public abstract void await(); // // /** // * Returns {@code true} if {@link #await()} MUST be called at the end of // * the task. This mostly applies to Gradle versions that don't have a // * Worker API and therefore cannot let the task continue to run in parallel // * to others. // * @return {@code true} if {@link #await()} must be called // */ // public abstract boolean needsAwait(); // }
import de.undercouch.gradle.tasks.download.internal.WorkerExecutorHelper; import org.gradle.api.Action; import org.gradle.api.Project; import org.gradle.api.Task; import org.gradle.internal.operations.BuildOperationCategory; import org.gradle.internal.operations.BuildOperationDescriptor; import org.gradle.internal.operations.BuildOperationState; import org.gradle.internal.operations.CurrentBuildOperationRef; import org.gradle.testfixtures.ProjectBuilder; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.io.TempDir; import javax.annotation.Nullable; import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.HashMap; import java.util.List; import java.util.Map;
.build(), 0); op.setRunning(true); CurrentBuildOperationRef.instance().set(op); return (Download)project.task(taskParams, "downloadFile"); } protected Project makeProject() { return makeProject(null); } protected Project makeProject(@Nullable Action<Project> projectConfiguration) { Project project = ProjectBuilder.builder().withProjectDir(projectDir).build(); if (projectConfiguration != null) { projectConfiguration.execute(project); } Map<String, Object> applyParams = new HashMap<>(); applyParams.put("plugin", "de.undercouch.download"); project.apply(applyParams); return project; } protected void execute(Task t) { List<Action<? super Task>> actions = t.getActions(); for (Action<? super Task> a : actions) { a.execute(t); }
// Path: src/main/java/de/undercouch/gradle/tasks/download/internal/WorkerExecutorHelper.java // public abstract class WorkerExecutorHelper { // /** // * Creates a new instance of the {@link WorkerExecutorHelper} depending // * on the Gradle version // * @param objectFactory creates Gradle model objects // * @return the helper // */ // public static WorkerExecutorHelper newInstance(ObjectFactory objectFactory) { // if (GradleVersion.current().getBaseVersion().compareTo(GradleVersion.version("5.6")) >= 0) { // return objectFactory.newInstance(DefaultWorkerExecutorHelper.class); // } // return new LegacyWorkerExecutorHelper(); // } // // /** // * Execute a job asynchronously // * @param job the job to execute // */ // public abstract void submit(Job job); // // /** // * Wait for all jobs of the current build operation to complete // */ // public abstract void await(); // // /** // * Returns {@code true} if {@link #await()} MUST be called at the end of // * the task. This mostly applies to Gradle versions that don't have a // * Worker API and therefore cannot let the task continue to run in parallel // * to others. // * @return {@code true} if {@link #await()} must be called // */ // public abstract boolean needsAwait(); // } // Path: src/test/java/de/undercouch/gradle/tasks/download/TestBase.java import de.undercouch.gradle.tasks.download.internal.WorkerExecutorHelper; import org.gradle.api.Action; import org.gradle.api.Project; import org.gradle.api.Task; import org.gradle.internal.operations.BuildOperationCategory; import org.gradle.internal.operations.BuildOperationDescriptor; import org.gradle.internal.operations.BuildOperationState; import org.gradle.internal.operations.CurrentBuildOperationRef; import org.gradle.testfixtures.ProjectBuilder; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.io.TempDir; import javax.annotation.Nullable; import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.HashMap; import java.util.List; import java.util.Map; .build(), 0); op.setRunning(true); CurrentBuildOperationRef.instance().set(op); return (Download)project.task(taskParams, "downloadFile"); } protected Project makeProject() { return makeProject(null); } protected Project makeProject(@Nullable Action<Project> projectConfiguration) { Project project = ProjectBuilder.builder().withProjectDir(projectDir).build(); if (projectConfiguration != null) { projectConfiguration.execute(project); } Map<String, Object> applyParams = new HashMap<>(); applyParams.put("plugin", "de.undercouch.download"); project.apply(applyParams); return project; } protected void execute(Task t) { List<Action<? super Task>> actions = t.getActions(); for (Action<? super Task> a : actions) { a.execute(t); }
WorkerExecutorHelper.newInstance(t.getProject().getObjects()).await();
nitindhar7/kampr
src/com/nitindhar/kampr/async/SnapTask.java
// Path: src/com/nitindhar/kampr/util/ImageUtils.java // public class ImageUtils { // // public static Bitmap getBitmapFromByteArray(byte[] imageData) { // return BitmapFactory.decodeByteArray(imageData, 0, imageData.length); // } // // public static byte[] getByteArrayFromBitmap(Bitmap imageData) { // ByteArrayOutputStream stream = new ByteArrayOutputStream(); // imageData.compress(Bitmap.CompressFormat.JPEG, 100, stream); // return stream.toByteArray(); // } // // public static Bitmap fetchUserIcon(Context context, String url, int defaultDrawableId) { // try { // InputStream is = (InputStream) new URL(url).getContent(); // return getBitmapFromStream(is, context, defaultDrawableId); // } catch (MalformedURLException e) { // throw new RuntimeException("Error: malformed URI", e); // } catch (IOException e) { // throw new RuntimeException("Error: could not read from stream", e); // } // } // // public static Bitmap getBitmapFromStream(InputStream is, Context context, int drawableId) { // Bitmap bmp = BitmapFactory.decodeStream(is); // if(bmp == null) { // return BitmapFactory.decodeResource(context.getResources(), drawableId); // } // else { // return bmp; // } // } // // public static Bitmap fetchImageBitmap(String uri) { // Bitmap imageData = null; // try { // InputStream is = (InputStream) new URL(uri).getContent(); // imageData = BitmapFactory.decodeStream(is); // } catch (MalformedURLException e) { // throw new RuntimeException("Error processing url", e); // } catch (IOException e) { // throw new RuntimeException("Error fetching data from stream", e); // } // return imageData; // } // // }
import android.graphics.Bitmap; import android.os.AsyncTask; import android.widget.ImageView; import com.nitindhar.forrst.model.Post; import com.nitindhar.kampr.util.ImageUtils;
package com.nitindhar.kampr.async; public class SnapTask extends AsyncTask<Post, Integer, Bitmap> { private final ImageView postOriginal; public SnapTask(ImageView postOriginal) { this.postOriginal = postOriginal; } @Override protected Bitmap doInBackground(Post... posts) {
// Path: src/com/nitindhar/kampr/util/ImageUtils.java // public class ImageUtils { // // public static Bitmap getBitmapFromByteArray(byte[] imageData) { // return BitmapFactory.decodeByteArray(imageData, 0, imageData.length); // } // // public static byte[] getByteArrayFromBitmap(Bitmap imageData) { // ByteArrayOutputStream stream = new ByteArrayOutputStream(); // imageData.compress(Bitmap.CompressFormat.JPEG, 100, stream); // return stream.toByteArray(); // } // // public static Bitmap fetchUserIcon(Context context, String url, int defaultDrawableId) { // try { // InputStream is = (InputStream) new URL(url).getContent(); // return getBitmapFromStream(is, context, defaultDrawableId); // } catch (MalformedURLException e) { // throw new RuntimeException("Error: malformed URI", e); // } catch (IOException e) { // throw new RuntimeException("Error: could not read from stream", e); // } // } // // public static Bitmap getBitmapFromStream(InputStream is, Context context, int drawableId) { // Bitmap bmp = BitmapFactory.decodeStream(is); // if(bmp == null) { // return BitmapFactory.decodeResource(context.getResources(), drawableId); // } // else { // return bmp; // } // } // // public static Bitmap fetchImageBitmap(String uri) { // Bitmap imageData = null; // try { // InputStream is = (InputStream) new URL(uri).getContent(); // imageData = BitmapFactory.decodeStream(is); // } catch (MalformedURLException e) { // throw new RuntimeException("Error processing url", e); // } catch (IOException e) { // throw new RuntimeException("Error fetching data from stream", e); // } // return imageData; // } // // } // Path: src/com/nitindhar/kampr/async/SnapTask.java import android.graphics.Bitmap; import android.os.AsyncTask; import android.widget.ImageView; import com.nitindhar.forrst.model.Post; import com.nitindhar.kampr.util.ImageUtils; package com.nitindhar.kampr.async; public class SnapTask extends AsyncTask<Post, Integer, Bitmap> { private final ImageView postOriginal; public SnapTask(ImageView postOriginal) { this.postOriginal = postOriginal; } @Override protected Bitmap doInBackground(Post... posts) {
Bitmap snapBitmap = ImageUtils.fetchImageBitmap(posts[0].getSnap().getOriginalUrl());
nitindhar7/kampr
src/com/nitindhar/kampr/data/SessionDao.java
// Path: src/com/nitindhar/kampr/models/Session.java // public class Session { // // private final String username; // private final String password; // private final String token; // private final Integer userId; // // public Session(String username, String password, String token, // Integer userId) { // Preconditions.checkArgument(!StringUtils.isBlank(username)); // Preconditions.checkArgument(!StringUtils.isBlank(password)); // Preconditions.checkArgument(!StringUtils.isBlank(token)); // // this.username = username; // this.password = password; // this.token = token; // this.userId = userId; // } // // public String getUsername() { // return username; // } // // public String getPassword() { // return password; // } // // public String getToken() { // return token; // } // // public Integer getUserId() { // return userId; // } // // }
import com.nitindhar.kampr.models.Session;
package com.nitindhar.kampr.data; public interface SessionDao { public boolean sessionExists();
// Path: src/com/nitindhar/kampr/models/Session.java // public class Session { // // private final String username; // private final String password; // private final String token; // private final Integer userId; // // public Session(String username, String password, String token, // Integer userId) { // Preconditions.checkArgument(!StringUtils.isBlank(username)); // Preconditions.checkArgument(!StringUtils.isBlank(password)); // Preconditions.checkArgument(!StringUtils.isBlank(token)); // // this.username = username; // this.password = password; // this.token = token; // this.userId = userId; // } // // public String getUsername() { // return username; // } // // public String getPassword() { // return password; // } // // public String getToken() { // return token; // } // // public Integer getUserId() { // return userId; // } // // } // Path: src/com/nitindhar/kampr/data/SessionDao.java import com.nitindhar.kampr.models.Session; package com.nitindhar.kampr.data; public interface SessionDao { public boolean sessionExists();
public boolean storeSession(Session session) throws Exception;
nitindhar7/kampr
src/com/nitindhar/kampr/data/SessionSharedPreferencesDao.java
// Path: src/com/nitindhar/kampr/models/Session.java // public class Session { // // private final String username; // private final String password; // private final String token; // private final Integer userId; // // public Session(String username, String password, String token, // Integer userId) { // Preconditions.checkArgument(!StringUtils.isBlank(username)); // Preconditions.checkArgument(!StringUtils.isBlank(password)); // Preconditions.checkArgument(!StringUtils.isBlank(token)); // // this.username = username; // this.password = password; // this.token = token; // this.userId = userId; // } // // public String getUsername() { // return username; // } // // public String getPassword() { // return password; // } // // public String getToken() { // return token; // } // // public Integer getUserId() { // return userId; // } // // }
import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import android.content.SharedPreferences; import com.nitindhar.kampr.models.Session;
package com.nitindhar.kampr.data; public class SessionSharedPreferencesDao implements SessionDao { private static final SessionDao INSTANCE = new SessionSharedPreferencesDao(); private static final String SESSION_KEY_USERNAME = "login_username"; private static final String SESSION_KEY_PASSWORD = "login_password"; private static final String SESSION_KEY_TOKEN = "login_token"; private static final String SESSION_KEY_USER_ID = "login_user_id"; private static final String SESSION_KEY_EULA_ACCEPTED = "agreed_to_eula"; private static final String SESSION_KEY_POST_TYPE = "post_type"; private static final String SESSION_PASSWORD_HASH_ALGO = "MD5"; private static SharedPreferences preferences; public static SessionDao instance() { return INSTANCE; } public static void setSharedPreferences(SharedPreferences preferences) { SessionSharedPreferencesDao.preferences = preferences; } @Override public boolean sessionExists() { if (preferences.getString(SESSION_KEY_TOKEN, null) != null) { return true; } else { return false; } } @Override
// Path: src/com/nitindhar/kampr/models/Session.java // public class Session { // // private final String username; // private final String password; // private final String token; // private final Integer userId; // // public Session(String username, String password, String token, // Integer userId) { // Preconditions.checkArgument(!StringUtils.isBlank(username)); // Preconditions.checkArgument(!StringUtils.isBlank(password)); // Preconditions.checkArgument(!StringUtils.isBlank(token)); // // this.username = username; // this.password = password; // this.token = token; // this.userId = userId; // } // // public String getUsername() { // return username; // } // // public String getPassword() { // return password; // } // // public String getToken() { // return token; // } // // public Integer getUserId() { // return userId; // } // // } // Path: src/com/nitindhar/kampr/data/SessionSharedPreferencesDao.java import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import android.content.SharedPreferences; import com.nitindhar.kampr.models.Session; package com.nitindhar.kampr.data; public class SessionSharedPreferencesDao implements SessionDao { private static final SessionDao INSTANCE = new SessionSharedPreferencesDao(); private static final String SESSION_KEY_USERNAME = "login_username"; private static final String SESSION_KEY_PASSWORD = "login_password"; private static final String SESSION_KEY_TOKEN = "login_token"; private static final String SESSION_KEY_USER_ID = "login_user_id"; private static final String SESSION_KEY_EULA_ACCEPTED = "agreed_to_eula"; private static final String SESSION_KEY_POST_TYPE = "post_type"; private static final String SESSION_PASSWORD_HASH_ALGO = "MD5"; private static SharedPreferences preferences; public static SessionDao instance() { return INSTANCE; } public static void setSharedPreferences(SharedPreferences preferences) { SessionSharedPreferencesDao.preferences = preferences; } @Override public boolean sessionExists() { if (preferences.getString(SESSION_KEY_TOKEN, null) != null) { return true; } else { return false; } } @Override
public boolean storeSession(Session session)
nitindhar7/kampr
src/com/nitindhar/kampr/async/UserPostsTask.java
// Path: src/com/nitindhar/kampr/adapters/UserPostsAdapter.java // public class UserPostsAdapter<T> extends AbstractListAdapter<T> { // // public UserPostsAdapter(Context context, List<T> posts) { // super(context, posts); // } // // @Override // public View getView(int position, View convertView, ViewGroup parent) { // convertView = getConvertView(convertView, R.layout.user_post_item); // // final PostDecorator pd = (PostDecorator) objects.get(position); // // TextView postDate = (TextView) getViewHandle(convertView, // R.id.user_post_item_date); // postDate.setText(TimeUtils.getPostDate(pd.getPost().getCreatedAt())); // // TextView postLikes = (TextView) getViewHandle(convertView, // R.id.post_likes_count); // postLikes.setText(Integer.toString(pd.getPost().getLikeCount())); // // TextView postViews = (TextView) getViewHandle(convertView, // R.id.post_views_count); // postViews.setText(Integer.toString(pd.getPost().getViewCount())); // // TextView postComments = (TextView) getViewHandle(convertView, // R.id.post_comments_count); // postComments.setText(Integer.toString(pd.getPost().getCommentCount())); // // TextView postTitle = (TextView) getViewHandle(convertView, // R.id.user_post_item_content); // postTitle.setText(pd.getPost().getTitle()); // // TextView postDescription = (TextView) getViewHandle(convertView, // R.id.user_post_item_description); // postDescription.setText(pd.getPost().getDescription().trim()); // // OnClickListener onCountsClickListener = new OnClickListener() { // // @Override // public void onClick(View v) { // View commentsFlyout = inflater.inflate(R.layout.comments_flyout, null); // ListView comments = (ListView) commentsFlyout.findViewById(android.R.id.list); // comments.setVerticalScrollBarEnabled(false); // comments.setVerticalFadingEdgeEnabled(false); // comments.setDivider(context.getResources().getDrawable(R.color.kampr_light_green)); // comments.setDividerHeight(1); // // CommentsTask commentsTask = new CommentsTask(context, comments); // commentsTask.execute(pd.getPost().getId()); // // AlertDialog.Builder builder = new AlertDialog.Builder(context); // AlertDialog alert = builder.create(); // alert.setView(commentsFlyout); // alert.show(); // } // }; // // RelativeLayout postItemCounts = (RelativeLayout) getViewHandle(convertView, // R.id.user_post_item_counts); // if(pd.getPost().getCommentCount() > 0) { // postItemCounts.setOnClickListener(onCountsClickListener); // } // // convertView.setId(pd.getPost().getId()); // // return convertView; // } // // public PostDecorator getViewObject(int position) { // return (PostDecorator) objects.get(position); // } // // } // // Path: src/com/nitindhar/kampr/models/PostDecorator.java // @SuppressWarnings("serial") // public class PostDecorator implements Serializable { // // private Post post; // private Future<Bitmap> userIconFuture; // private List<Future<Bitmap>> postSnapFutures; // // public Bitmap getUserIcon() { // Bitmap userIcon = null; // try { // userIcon = userIconFuture.get(); // } catch (Exception e) {} // return userIcon; // } // // public Future<Bitmap> getUserIconFuture() { // return userIconFuture; // } // // public List<Bitmap> getPostSnaps() { // List<Bitmap> snaps = new ArrayList<Bitmap>(); // for(Future<Bitmap> future : postSnapFutures) { // try { // snaps.add(future.get()); // } catch (Exception e) {} // } // return snaps; // } // // public List<Future<Bitmap>> getPostSnapFutures() { // return postSnapFutures; // } // // public void setUserIconFuture(Future<Bitmap> userIconFuture) { // this.userIconFuture = userIconFuture; // } // // public void setPostSnapFutures(List<Future<Bitmap>> postSnapFutures) { // this.postSnapFutures = postSnapFutures; // } // // public Post getPost() { // return post; // } // // public void setPost(Post post) { // this.post = post; // } // // } // // Path: src/com/nitindhar/kampr/util/ForrstUtil.java // public class ForrstUtil { // // private static final ForrstAPI forrst = new ForrstAPIClient(HttpProvider.JAVA_NET); // // public static ForrstAPI client() { // return forrst; // } // // }
import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import android.content.Context; import android.os.AsyncTask; import android.view.MenuItem; import android.widget.ListView; import com.nitindhar.forrst.model.Post; import com.nitindhar.kampr.adapters.UserPostsAdapter; import com.nitindhar.kampr.models.PostDecorator; import com.nitindhar.kampr.util.ForrstUtil;
package com.nitindhar.kampr.async; public class UserPostsTask extends AsyncTask<Integer, Integer, List<PostDecorator>> { private static final ExecutorService executor = Executors .newFixedThreadPool(10); private final Context context; private final ListView userPosts; private final List<PostDecorator> listOfPosts;
// Path: src/com/nitindhar/kampr/adapters/UserPostsAdapter.java // public class UserPostsAdapter<T> extends AbstractListAdapter<T> { // // public UserPostsAdapter(Context context, List<T> posts) { // super(context, posts); // } // // @Override // public View getView(int position, View convertView, ViewGroup parent) { // convertView = getConvertView(convertView, R.layout.user_post_item); // // final PostDecorator pd = (PostDecorator) objects.get(position); // // TextView postDate = (TextView) getViewHandle(convertView, // R.id.user_post_item_date); // postDate.setText(TimeUtils.getPostDate(pd.getPost().getCreatedAt())); // // TextView postLikes = (TextView) getViewHandle(convertView, // R.id.post_likes_count); // postLikes.setText(Integer.toString(pd.getPost().getLikeCount())); // // TextView postViews = (TextView) getViewHandle(convertView, // R.id.post_views_count); // postViews.setText(Integer.toString(pd.getPost().getViewCount())); // // TextView postComments = (TextView) getViewHandle(convertView, // R.id.post_comments_count); // postComments.setText(Integer.toString(pd.getPost().getCommentCount())); // // TextView postTitle = (TextView) getViewHandle(convertView, // R.id.user_post_item_content); // postTitle.setText(pd.getPost().getTitle()); // // TextView postDescription = (TextView) getViewHandle(convertView, // R.id.user_post_item_description); // postDescription.setText(pd.getPost().getDescription().trim()); // // OnClickListener onCountsClickListener = new OnClickListener() { // // @Override // public void onClick(View v) { // View commentsFlyout = inflater.inflate(R.layout.comments_flyout, null); // ListView comments = (ListView) commentsFlyout.findViewById(android.R.id.list); // comments.setVerticalScrollBarEnabled(false); // comments.setVerticalFadingEdgeEnabled(false); // comments.setDivider(context.getResources().getDrawable(R.color.kampr_light_green)); // comments.setDividerHeight(1); // // CommentsTask commentsTask = new CommentsTask(context, comments); // commentsTask.execute(pd.getPost().getId()); // // AlertDialog.Builder builder = new AlertDialog.Builder(context); // AlertDialog alert = builder.create(); // alert.setView(commentsFlyout); // alert.show(); // } // }; // // RelativeLayout postItemCounts = (RelativeLayout) getViewHandle(convertView, // R.id.user_post_item_counts); // if(pd.getPost().getCommentCount() > 0) { // postItemCounts.setOnClickListener(onCountsClickListener); // } // // convertView.setId(pd.getPost().getId()); // // return convertView; // } // // public PostDecorator getViewObject(int position) { // return (PostDecorator) objects.get(position); // } // // } // // Path: src/com/nitindhar/kampr/models/PostDecorator.java // @SuppressWarnings("serial") // public class PostDecorator implements Serializable { // // private Post post; // private Future<Bitmap> userIconFuture; // private List<Future<Bitmap>> postSnapFutures; // // public Bitmap getUserIcon() { // Bitmap userIcon = null; // try { // userIcon = userIconFuture.get(); // } catch (Exception e) {} // return userIcon; // } // // public Future<Bitmap> getUserIconFuture() { // return userIconFuture; // } // // public List<Bitmap> getPostSnaps() { // List<Bitmap> snaps = new ArrayList<Bitmap>(); // for(Future<Bitmap> future : postSnapFutures) { // try { // snaps.add(future.get()); // } catch (Exception e) {} // } // return snaps; // } // // public List<Future<Bitmap>> getPostSnapFutures() { // return postSnapFutures; // } // // public void setUserIconFuture(Future<Bitmap> userIconFuture) { // this.userIconFuture = userIconFuture; // } // // public void setPostSnapFutures(List<Future<Bitmap>> postSnapFutures) { // this.postSnapFutures = postSnapFutures; // } // // public Post getPost() { // return post; // } // // public void setPost(Post post) { // this.post = post; // } // // } // // Path: src/com/nitindhar/kampr/util/ForrstUtil.java // public class ForrstUtil { // // private static final ForrstAPI forrst = new ForrstAPIClient(HttpProvider.JAVA_NET); // // public static ForrstAPI client() { // return forrst; // } // // } // Path: src/com/nitindhar/kampr/async/UserPostsTask.java import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import android.content.Context; import android.os.AsyncTask; import android.view.MenuItem; import android.widget.ListView; import com.nitindhar.forrst.model.Post; import com.nitindhar.kampr.adapters.UserPostsAdapter; import com.nitindhar.kampr.models.PostDecorator; import com.nitindhar.kampr.util.ForrstUtil; package com.nitindhar.kampr.async; public class UserPostsTask extends AsyncTask<Integer, Integer, List<PostDecorator>> { private static final ExecutorService executor = Executors .newFixedThreadPool(10); private final Context context; private final ListView userPosts; private final List<PostDecorator> listOfPosts;
private UserPostsAdapter<PostDecorator> userPostsAdapter;
nitindhar7/kampr
src/com/nitindhar/kampr/async/LoginTask.java
// Path: src/com/nitindhar/kampr/data/SessionDao.java // public interface SessionDao { // // public boolean sessionExists(); // // public boolean storeSession(Session session) throws Exception; // // public boolean removeSession(); // // public boolean sessionWasEulaAccepted(); // // public boolean sessionEulaAccepted(); // // public String getSessionToken(); // // public boolean storeSessionPostType(String postType); // // public String getSessionPostType(); // // } // // Path: src/com/nitindhar/kampr/data/SessionSharedPreferencesDao.java // public class SessionSharedPreferencesDao implements SessionDao { // // private static final SessionDao INSTANCE = new SessionSharedPreferencesDao(); // private static final String SESSION_KEY_USERNAME = "login_username"; // private static final String SESSION_KEY_PASSWORD = "login_password"; // private static final String SESSION_KEY_TOKEN = "login_token"; // private static final String SESSION_KEY_USER_ID = "login_user_id"; // private static final String SESSION_KEY_EULA_ACCEPTED = "agreed_to_eula"; // private static final String SESSION_KEY_POST_TYPE = "post_type"; // private static final String SESSION_PASSWORD_HASH_ALGO = "MD5"; // // private static SharedPreferences preferences; // // public static SessionDao instance() { // return INSTANCE; // } // // public static void setSharedPreferences(SharedPreferences preferences) { // SessionSharedPreferencesDao.preferences = preferences; // } // // @Override // public boolean sessionExists() { // if (preferences.getString(SESSION_KEY_TOKEN, null) != null) { // return true; // } else { // return false; // } // } // // @Override // public boolean storeSession(Session session) // throws NoSuchAlgorithmException { // SharedPreferences.Editor editor = preferences.edit(); // MessageDigest md = MessageDigest // .getInstance(SESSION_PASSWORD_HASH_ALGO); // byte[] passwordHash = md.digest(session.getPassword().getBytes()); // // editor.putString(SESSION_KEY_USERNAME, session.getUsername()); // editor.putString(SESSION_KEY_PASSWORD, passwordHash.toString()); // editor.putString(SESSION_KEY_TOKEN, session.getToken()); // editor.putString(SESSION_KEY_USER_ID, // Integer.toString(session.getUserId())); // return editor.commit(); // } // // @Override // public boolean sessionWasEulaAccepted() { // return preferences.getBoolean(SESSION_KEY_EULA_ACCEPTED, false); // } // // @Override // public boolean sessionEulaAccepted() { // SharedPreferences.Editor editor = preferences.edit(); // editor.putBoolean(SESSION_KEY_EULA_ACCEPTED, true); // return editor.commit(); // } // // @Override // public boolean removeSession() { // SharedPreferences.Editor editor = preferences.edit(); // editor.remove(SESSION_KEY_USERNAME); // editor.remove(SESSION_KEY_PASSWORD); // editor.remove(SESSION_KEY_TOKEN); // editor.remove(SESSION_KEY_USER_ID); // editor.remove(SESSION_KEY_POST_TYPE); // return editor.commit(); // } // // @Override // public String getSessionToken() { // return preferences.getString(SESSION_KEY_TOKEN, null); // } // // @Override // public boolean storeSessionPostType(String postType) { // SharedPreferences.Editor editor = preferences.edit(); // editor.putString(SESSION_KEY_POST_TYPE, postType); // return editor.commit(); // } // // @Override // public String getSessionPostType() { // return preferences.getString(SESSION_KEY_POST_TYPE, null); // } // // } // // Path: src/com/nitindhar/kampr/models/Session.java // public class Session { // // private final String username; // private final String password; // private final String token; // private final Integer userId; // // public Session(String username, String password, String token, // Integer userId) { // Preconditions.checkArgument(!StringUtils.isBlank(username)); // Preconditions.checkArgument(!StringUtils.isBlank(password)); // Preconditions.checkArgument(!StringUtils.isBlank(token)); // // this.username = username; // this.password = password; // this.token = token; // this.userId = userId; // } // // public String getUsername() { // return username; // } // // public String getPassword() { // return password; // } // // public String getToken() { // return token; // } // // public Integer getUserId() { // return userId; // } // // } // // Path: src/com/nitindhar/kampr/util/ForrstUtil.java // public class ForrstUtil { // // private static final ForrstAPI forrst = new ForrstAPIClient(HttpProvider.JAVA_NET); // // public static ForrstAPI client() { // return forrst; // } // // }
import java.util.concurrent.Callable; import com.google.common.base.Optional; import com.nitindhar.forrst.model.Auth; import com.nitindhar.kampr.data.SessionDao; import com.nitindhar.kampr.data.SessionSharedPreferencesDao; import com.nitindhar.kampr.models.Session; import com.nitindhar.kampr.util.ForrstUtil;
package com.nitindhar.kampr.async; public class LoginTask implements Callable<Boolean> { private static SessionDao sessionDao = SessionSharedPreferencesDao.instance(); private final String username; private final String password; public LoginTask(String username, String password) { this.username = username; this.password = password; } @Override public Boolean call() { boolean validCredentials = false; try {
// Path: src/com/nitindhar/kampr/data/SessionDao.java // public interface SessionDao { // // public boolean sessionExists(); // // public boolean storeSession(Session session) throws Exception; // // public boolean removeSession(); // // public boolean sessionWasEulaAccepted(); // // public boolean sessionEulaAccepted(); // // public String getSessionToken(); // // public boolean storeSessionPostType(String postType); // // public String getSessionPostType(); // // } // // Path: src/com/nitindhar/kampr/data/SessionSharedPreferencesDao.java // public class SessionSharedPreferencesDao implements SessionDao { // // private static final SessionDao INSTANCE = new SessionSharedPreferencesDao(); // private static final String SESSION_KEY_USERNAME = "login_username"; // private static final String SESSION_KEY_PASSWORD = "login_password"; // private static final String SESSION_KEY_TOKEN = "login_token"; // private static final String SESSION_KEY_USER_ID = "login_user_id"; // private static final String SESSION_KEY_EULA_ACCEPTED = "agreed_to_eula"; // private static final String SESSION_KEY_POST_TYPE = "post_type"; // private static final String SESSION_PASSWORD_HASH_ALGO = "MD5"; // // private static SharedPreferences preferences; // // public static SessionDao instance() { // return INSTANCE; // } // // public static void setSharedPreferences(SharedPreferences preferences) { // SessionSharedPreferencesDao.preferences = preferences; // } // // @Override // public boolean sessionExists() { // if (preferences.getString(SESSION_KEY_TOKEN, null) != null) { // return true; // } else { // return false; // } // } // // @Override // public boolean storeSession(Session session) // throws NoSuchAlgorithmException { // SharedPreferences.Editor editor = preferences.edit(); // MessageDigest md = MessageDigest // .getInstance(SESSION_PASSWORD_HASH_ALGO); // byte[] passwordHash = md.digest(session.getPassword().getBytes()); // // editor.putString(SESSION_KEY_USERNAME, session.getUsername()); // editor.putString(SESSION_KEY_PASSWORD, passwordHash.toString()); // editor.putString(SESSION_KEY_TOKEN, session.getToken()); // editor.putString(SESSION_KEY_USER_ID, // Integer.toString(session.getUserId())); // return editor.commit(); // } // // @Override // public boolean sessionWasEulaAccepted() { // return preferences.getBoolean(SESSION_KEY_EULA_ACCEPTED, false); // } // // @Override // public boolean sessionEulaAccepted() { // SharedPreferences.Editor editor = preferences.edit(); // editor.putBoolean(SESSION_KEY_EULA_ACCEPTED, true); // return editor.commit(); // } // // @Override // public boolean removeSession() { // SharedPreferences.Editor editor = preferences.edit(); // editor.remove(SESSION_KEY_USERNAME); // editor.remove(SESSION_KEY_PASSWORD); // editor.remove(SESSION_KEY_TOKEN); // editor.remove(SESSION_KEY_USER_ID); // editor.remove(SESSION_KEY_POST_TYPE); // return editor.commit(); // } // // @Override // public String getSessionToken() { // return preferences.getString(SESSION_KEY_TOKEN, null); // } // // @Override // public boolean storeSessionPostType(String postType) { // SharedPreferences.Editor editor = preferences.edit(); // editor.putString(SESSION_KEY_POST_TYPE, postType); // return editor.commit(); // } // // @Override // public String getSessionPostType() { // return preferences.getString(SESSION_KEY_POST_TYPE, null); // } // // } // // Path: src/com/nitindhar/kampr/models/Session.java // public class Session { // // private final String username; // private final String password; // private final String token; // private final Integer userId; // // public Session(String username, String password, String token, // Integer userId) { // Preconditions.checkArgument(!StringUtils.isBlank(username)); // Preconditions.checkArgument(!StringUtils.isBlank(password)); // Preconditions.checkArgument(!StringUtils.isBlank(token)); // // this.username = username; // this.password = password; // this.token = token; // this.userId = userId; // } // // public String getUsername() { // return username; // } // // public String getPassword() { // return password; // } // // public String getToken() { // return token; // } // // public Integer getUserId() { // return userId; // } // // } // // Path: src/com/nitindhar/kampr/util/ForrstUtil.java // public class ForrstUtil { // // private static final ForrstAPI forrst = new ForrstAPIClient(HttpProvider.JAVA_NET); // // public static ForrstAPI client() { // return forrst; // } // // } // Path: src/com/nitindhar/kampr/async/LoginTask.java import java.util.concurrent.Callable; import com.google.common.base.Optional; import com.nitindhar.forrst.model.Auth; import com.nitindhar.kampr.data.SessionDao; import com.nitindhar.kampr.data.SessionSharedPreferencesDao; import com.nitindhar.kampr.models.Session; import com.nitindhar.kampr.util.ForrstUtil; package com.nitindhar.kampr.async; public class LoginTask implements Callable<Boolean> { private static SessionDao sessionDao = SessionSharedPreferencesDao.instance(); private final String username; private final String password; public LoginTask(String username, String password) { this.username = username; this.password = password; } @Override public Boolean call() { boolean validCredentials = false; try {
Optional<Auth> auth = ForrstUtil.client().usersAuth(username, password);
nitindhar7/kampr
src/com/nitindhar/kampr/async/LoginTask.java
// Path: src/com/nitindhar/kampr/data/SessionDao.java // public interface SessionDao { // // public boolean sessionExists(); // // public boolean storeSession(Session session) throws Exception; // // public boolean removeSession(); // // public boolean sessionWasEulaAccepted(); // // public boolean sessionEulaAccepted(); // // public String getSessionToken(); // // public boolean storeSessionPostType(String postType); // // public String getSessionPostType(); // // } // // Path: src/com/nitindhar/kampr/data/SessionSharedPreferencesDao.java // public class SessionSharedPreferencesDao implements SessionDao { // // private static final SessionDao INSTANCE = new SessionSharedPreferencesDao(); // private static final String SESSION_KEY_USERNAME = "login_username"; // private static final String SESSION_KEY_PASSWORD = "login_password"; // private static final String SESSION_KEY_TOKEN = "login_token"; // private static final String SESSION_KEY_USER_ID = "login_user_id"; // private static final String SESSION_KEY_EULA_ACCEPTED = "agreed_to_eula"; // private static final String SESSION_KEY_POST_TYPE = "post_type"; // private static final String SESSION_PASSWORD_HASH_ALGO = "MD5"; // // private static SharedPreferences preferences; // // public static SessionDao instance() { // return INSTANCE; // } // // public static void setSharedPreferences(SharedPreferences preferences) { // SessionSharedPreferencesDao.preferences = preferences; // } // // @Override // public boolean sessionExists() { // if (preferences.getString(SESSION_KEY_TOKEN, null) != null) { // return true; // } else { // return false; // } // } // // @Override // public boolean storeSession(Session session) // throws NoSuchAlgorithmException { // SharedPreferences.Editor editor = preferences.edit(); // MessageDigest md = MessageDigest // .getInstance(SESSION_PASSWORD_HASH_ALGO); // byte[] passwordHash = md.digest(session.getPassword().getBytes()); // // editor.putString(SESSION_KEY_USERNAME, session.getUsername()); // editor.putString(SESSION_KEY_PASSWORD, passwordHash.toString()); // editor.putString(SESSION_KEY_TOKEN, session.getToken()); // editor.putString(SESSION_KEY_USER_ID, // Integer.toString(session.getUserId())); // return editor.commit(); // } // // @Override // public boolean sessionWasEulaAccepted() { // return preferences.getBoolean(SESSION_KEY_EULA_ACCEPTED, false); // } // // @Override // public boolean sessionEulaAccepted() { // SharedPreferences.Editor editor = preferences.edit(); // editor.putBoolean(SESSION_KEY_EULA_ACCEPTED, true); // return editor.commit(); // } // // @Override // public boolean removeSession() { // SharedPreferences.Editor editor = preferences.edit(); // editor.remove(SESSION_KEY_USERNAME); // editor.remove(SESSION_KEY_PASSWORD); // editor.remove(SESSION_KEY_TOKEN); // editor.remove(SESSION_KEY_USER_ID); // editor.remove(SESSION_KEY_POST_TYPE); // return editor.commit(); // } // // @Override // public String getSessionToken() { // return preferences.getString(SESSION_KEY_TOKEN, null); // } // // @Override // public boolean storeSessionPostType(String postType) { // SharedPreferences.Editor editor = preferences.edit(); // editor.putString(SESSION_KEY_POST_TYPE, postType); // return editor.commit(); // } // // @Override // public String getSessionPostType() { // return preferences.getString(SESSION_KEY_POST_TYPE, null); // } // // } // // Path: src/com/nitindhar/kampr/models/Session.java // public class Session { // // private final String username; // private final String password; // private final String token; // private final Integer userId; // // public Session(String username, String password, String token, // Integer userId) { // Preconditions.checkArgument(!StringUtils.isBlank(username)); // Preconditions.checkArgument(!StringUtils.isBlank(password)); // Preconditions.checkArgument(!StringUtils.isBlank(token)); // // this.username = username; // this.password = password; // this.token = token; // this.userId = userId; // } // // public String getUsername() { // return username; // } // // public String getPassword() { // return password; // } // // public String getToken() { // return token; // } // // public Integer getUserId() { // return userId; // } // // } // // Path: src/com/nitindhar/kampr/util/ForrstUtil.java // public class ForrstUtil { // // private static final ForrstAPI forrst = new ForrstAPIClient(HttpProvider.JAVA_NET); // // public static ForrstAPI client() { // return forrst; // } // // }
import java.util.concurrent.Callable; import com.google.common.base.Optional; import com.nitindhar.forrst.model.Auth; import com.nitindhar.kampr.data.SessionDao; import com.nitindhar.kampr.data.SessionSharedPreferencesDao; import com.nitindhar.kampr.models.Session; import com.nitindhar.kampr.util.ForrstUtil;
package com.nitindhar.kampr.async; public class LoginTask implements Callable<Boolean> { private static SessionDao sessionDao = SessionSharedPreferencesDao.instance(); private final String username; private final String password; public LoginTask(String username, String password) { this.username = username; this.password = password; } @Override public Boolean call() { boolean validCredentials = false; try { Optional<Auth> auth = ForrstUtil.client().usersAuth(username, password); if (auth.isPresent()) {
// Path: src/com/nitindhar/kampr/data/SessionDao.java // public interface SessionDao { // // public boolean sessionExists(); // // public boolean storeSession(Session session) throws Exception; // // public boolean removeSession(); // // public boolean sessionWasEulaAccepted(); // // public boolean sessionEulaAccepted(); // // public String getSessionToken(); // // public boolean storeSessionPostType(String postType); // // public String getSessionPostType(); // // } // // Path: src/com/nitindhar/kampr/data/SessionSharedPreferencesDao.java // public class SessionSharedPreferencesDao implements SessionDao { // // private static final SessionDao INSTANCE = new SessionSharedPreferencesDao(); // private static final String SESSION_KEY_USERNAME = "login_username"; // private static final String SESSION_KEY_PASSWORD = "login_password"; // private static final String SESSION_KEY_TOKEN = "login_token"; // private static final String SESSION_KEY_USER_ID = "login_user_id"; // private static final String SESSION_KEY_EULA_ACCEPTED = "agreed_to_eula"; // private static final String SESSION_KEY_POST_TYPE = "post_type"; // private static final String SESSION_PASSWORD_HASH_ALGO = "MD5"; // // private static SharedPreferences preferences; // // public static SessionDao instance() { // return INSTANCE; // } // // public static void setSharedPreferences(SharedPreferences preferences) { // SessionSharedPreferencesDao.preferences = preferences; // } // // @Override // public boolean sessionExists() { // if (preferences.getString(SESSION_KEY_TOKEN, null) != null) { // return true; // } else { // return false; // } // } // // @Override // public boolean storeSession(Session session) // throws NoSuchAlgorithmException { // SharedPreferences.Editor editor = preferences.edit(); // MessageDigest md = MessageDigest // .getInstance(SESSION_PASSWORD_HASH_ALGO); // byte[] passwordHash = md.digest(session.getPassword().getBytes()); // // editor.putString(SESSION_KEY_USERNAME, session.getUsername()); // editor.putString(SESSION_KEY_PASSWORD, passwordHash.toString()); // editor.putString(SESSION_KEY_TOKEN, session.getToken()); // editor.putString(SESSION_KEY_USER_ID, // Integer.toString(session.getUserId())); // return editor.commit(); // } // // @Override // public boolean sessionWasEulaAccepted() { // return preferences.getBoolean(SESSION_KEY_EULA_ACCEPTED, false); // } // // @Override // public boolean sessionEulaAccepted() { // SharedPreferences.Editor editor = preferences.edit(); // editor.putBoolean(SESSION_KEY_EULA_ACCEPTED, true); // return editor.commit(); // } // // @Override // public boolean removeSession() { // SharedPreferences.Editor editor = preferences.edit(); // editor.remove(SESSION_KEY_USERNAME); // editor.remove(SESSION_KEY_PASSWORD); // editor.remove(SESSION_KEY_TOKEN); // editor.remove(SESSION_KEY_USER_ID); // editor.remove(SESSION_KEY_POST_TYPE); // return editor.commit(); // } // // @Override // public String getSessionToken() { // return preferences.getString(SESSION_KEY_TOKEN, null); // } // // @Override // public boolean storeSessionPostType(String postType) { // SharedPreferences.Editor editor = preferences.edit(); // editor.putString(SESSION_KEY_POST_TYPE, postType); // return editor.commit(); // } // // @Override // public String getSessionPostType() { // return preferences.getString(SESSION_KEY_POST_TYPE, null); // } // // } // // Path: src/com/nitindhar/kampr/models/Session.java // public class Session { // // private final String username; // private final String password; // private final String token; // private final Integer userId; // // public Session(String username, String password, String token, // Integer userId) { // Preconditions.checkArgument(!StringUtils.isBlank(username)); // Preconditions.checkArgument(!StringUtils.isBlank(password)); // Preconditions.checkArgument(!StringUtils.isBlank(token)); // // this.username = username; // this.password = password; // this.token = token; // this.userId = userId; // } // // public String getUsername() { // return username; // } // // public String getPassword() { // return password; // } // // public String getToken() { // return token; // } // // public Integer getUserId() { // return userId; // } // // } // // Path: src/com/nitindhar/kampr/util/ForrstUtil.java // public class ForrstUtil { // // private static final ForrstAPI forrst = new ForrstAPIClient(HttpProvider.JAVA_NET); // // public static ForrstAPI client() { // return forrst; // } // // } // Path: src/com/nitindhar/kampr/async/LoginTask.java import java.util.concurrent.Callable; import com.google.common.base.Optional; import com.nitindhar.forrst.model.Auth; import com.nitindhar.kampr.data.SessionDao; import com.nitindhar.kampr.data.SessionSharedPreferencesDao; import com.nitindhar.kampr.models.Session; import com.nitindhar.kampr.util.ForrstUtil; package com.nitindhar.kampr.async; public class LoginTask implements Callable<Boolean> { private static SessionDao sessionDao = SessionSharedPreferencesDao.instance(); private final String username; private final String password; public LoginTask(String username, String password) { this.username = username; this.password = password; } @Override public Boolean call() { boolean validCredentials = false; try { Optional<Auth> auth = ForrstUtil.client().usersAuth(username, password); if (auth.isPresent()) {
Session session = new Session(username, password, auth.get()
nitindhar7/kampr
src/com/nitindhar/kampr/async/PostSnapFetchTask.java
// Path: src/com/nitindhar/kampr/util/ImageUtils.java // public class ImageUtils { // // public static Bitmap getBitmapFromByteArray(byte[] imageData) { // return BitmapFactory.decodeByteArray(imageData, 0, imageData.length); // } // // public static byte[] getByteArrayFromBitmap(Bitmap imageData) { // ByteArrayOutputStream stream = new ByteArrayOutputStream(); // imageData.compress(Bitmap.CompressFormat.JPEG, 100, stream); // return stream.toByteArray(); // } // // public static Bitmap fetchUserIcon(Context context, String url, int defaultDrawableId) { // try { // InputStream is = (InputStream) new URL(url).getContent(); // return getBitmapFromStream(is, context, defaultDrawableId); // } catch (MalformedURLException e) { // throw new RuntimeException("Error: malformed URI", e); // } catch (IOException e) { // throw new RuntimeException("Error: could not read from stream", e); // } // } // // public static Bitmap getBitmapFromStream(InputStream is, Context context, int drawableId) { // Bitmap bmp = BitmapFactory.decodeStream(is); // if(bmp == null) { // return BitmapFactory.decodeResource(context.getResources(), drawableId); // } // else { // return bmp; // } // } // // public static Bitmap fetchImageBitmap(String uri) { // Bitmap imageData = null; // try { // InputStream is = (InputStream) new URL(uri).getContent(); // imageData = BitmapFactory.decodeStream(is); // } catch (MalformedURLException e) { // throw new RuntimeException("Error processing url", e); // } catch (IOException e) { // throw new RuntimeException("Error fetching data from stream", e); // } // return imageData; // } // // }
import java.util.concurrent.Callable; import android.graphics.Bitmap; import com.nitindhar.kampr.util.ImageUtils;
package com.nitindhar.kampr.async; public class PostSnapFetchTask implements Callable<Bitmap> { private final String url; public PostSnapFetchTask(String url) { this.url = url; } @Override public Bitmap call() throws Exception {
// Path: src/com/nitindhar/kampr/util/ImageUtils.java // public class ImageUtils { // // public static Bitmap getBitmapFromByteArray(byte[] imageData) { // return BitmapFactory.decodeByteArray(imageData, 0, imageData.length); // } // // public static byte[] getByteArrayFromBitmap(Bitmap imageData) { // ByteArrayOutputStream stream = new ByteArrayOutputStream(); // imageData.compress(Bitmap.CompressFormat.JPEG, 100, stream); // return stream.toByteArray(); // } // // public static Bitmap fetchUserIcon(Context context, String url, int defaultDrawableId) { // try { // InputStream is = (InputStream) new URL(url).getContent(); // return getBitmapFromStream(is, context, defaultDrawableId); // } catch (MalformedURLException e) { // throw new RuntimeException("Error: malformed URI", e); // } catch (IOException e) { // throw new RuntimeException("Error: could not read from stream", e); // } // } // // public static Bitmap getBitmapFromStream(InputStream is, Context context, int drawableId) { // Bitmap bmp = BitmapFactory.decodeStream(is); // if(bmp == null) { // return BitmapFactory.decodeResource(context.getResources(), drawableId); // } // else { // return bmp; // } // } // // public static Bitmap fetchImageBitmap(String uri) { // Bitmap imageData = null; // try { // InputStream is = (InputStream) new URL(uri).getContent(); // imageData = BitmapFactory.decodeStream(is); // } catch (MalformedURLException e) { // throw new RuntimeException("Error processing url", e); // } catch (IOException e) { // throw new RuntimeException("Error fetching data from stream", e); // } // return imageData; // } // // } // Path: src/com/nitindhar/kampr/async/PostSnapFetchTask.java import java.util.concurrent.Callable; import android.graphics.Bitmap; import com.nitindhar.kampr.util.ImageUtils; package com.nitindhar.kampr.async; public class PostSnapFetchTask implements Callable<Bitmap> { private final String url; public PostSnapFetchTask(String url) { this.url = url; } @Override public Bitmap call() throws Exception {
return ImageUtils.fetchImageBitmap(url);