Skip to content

Commit

Permalink
Merge pull request willowtreeapps#104 from willowtreeapps/master
Browse files Browse the repository at this point in the history
reverse master back into dev
  • Loading branch information
Theodore Wilson committed Jul 11, 2017
2 parents cf47317 + 2d26e23 commit 87fc1b9
Show file tree
Hide file tree
Showing 29 changed files with 367 additions and 68 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ dependencies {
testCompile 'junit:junit:4.12'
compile project(':lib')
compile 'com.android.support:recyclerview-v7:25.3.0'
compile 'com.jakewharton.timber:timber:4.5.1'
}
7 changes: 6 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,19 @@
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".SpruceActivity"
android:name=".SplashActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

<activity
android:name=".SpruceActivity"
android:screenOrientation="portrait" />

<activity
android:name=".RecyclerActivity"
android:screenOrientation="portrait"/>
Expand Down
38 changes: 38 additions & 0 deletions app/src/main/java/com/willowtreeapps/spurceexampleapp/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Spruce
*
* Copyright (c) 2017 WillowTree, Inc.
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/

package com.willowtreeapps.spurceexampleapp;

import android.app.Application;
import timber.log.Timber;

public class App extends Application {

@Override
public void onCreate() {
super.onCreate();

if (BuildConfig.DEBUG) {
Timber.plant(new Timber.DebugTree());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Spruce
*
* Copyright (c) 2017 WillowTree, Inc.
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/

package com.willowtreeapps.spurceexampleapp;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;

public class SplashActivity extends AppCompatActivity {

private static int SPLASH_TIMEOUT = 2000;
private ImageView logoImageView;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);

logoImageView = (ImageView) findViewById(R.id.ivLogo);
logoImageView.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.spruce_logo));

Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(SplashActivity.this, SpruceActivity.class));
finish();
}
}, SPLASH_TIMEOUT);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.util.ArrayList;
import java.util.List;


public class SpruceActivity extends AppCompatActivity
implements ViewFragment.OnParentAndChildCreationListener {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import com.willowtreeapps.spruce.sort.LinearSort;
import com.willowtreeapps.spruce.sort.RadialSort;
import com.willowtreeapps.spruce.sort.RandomSort;
import com.willowtreeapps.spruce.sort.SnakeSort;
import com.willowtreeapps.spruce.sort.SortFunction;
import com.willowtreeapps.spurceexampleapp.R;
import com.willowtreeapps.spurceexampleapp.SpruceActivity;
Expand All @@ -69,6 +70,7 @@ public class ControlsFragment extends Fragment implements RadioGroupGridLayout.O
private static final int LINEAR_SORT = 5;
private static final int RADIAL_SORT = 6;
private static final int RANDOM_SORT = 7;
private static final int SNAKE_SORT = 8;

private Animator spruceAnimator;
private SeekBar seekBar;
Expand Down Expand Up @@ -139,6 +141,7 @@ public void onClick(View v) {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch (position) {
case SNAKE_SORT:
case CORNERED_SORT:
case INLINE_SORT:
linearRadioGroup.setVisibility(View.GONE);
Expand Down Expand Up @@ -389,6 +392,13 @@ private void setupSort() {
sortFunction = new RandomSort(seekBar.getProgress());
codeSample.setText(String.format(getResources().getString(R.string.random_sort_code), seekBar.getProgress()));
break;
case SNAKE_SORT:
sortFunction = new SnakeSort(seekBar.getProgress(), linearReversed.isChecked(), corner);
codeSample.setText(String.format(getResources().getString(R.string.snake_sort_code),
seekBar.getProgress(),
String.valueOf(linearReversed.isChecked()),
corner));
break;
default:
sortFunction = new DefaultSort(seekBar.getProgress());
codeSample.setText(String.format(getResources().getString(R.string.default_sort_code), seekBar.getProgress()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.GridLayout;
import android.widget.TextView;

import com.willowtreeapps.spurceexampleapp.R;
import com.willowtreeapps.spurceexampleapp.widgets.CardLayout;
Expand Down Expand Up @@ -62,7 +64,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, @Nullable

for (int i = 0; i < CHILD_VIEW_COUNT; i++) {
CardLayout childView = new CardLayout(getContext());
childView.setAlpha(0F);
parent.addView(childView);
children.add(childView);
}
Expand Down
Binary file added app/src/main/res/drawable-hdpi/spruce_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/spruce_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/spruce_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/spruce_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions app/src/main/res/layout/activity_splash.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Spruce
~
~ Copyright (c) 2017 WillowTree, Inc.
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is
~ furnished to do so, subject to the following conditions:
~ The above copyright notice and this permission notice shall be included in
~ all copies or substantial portions of the Software.
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
~ THE SOFTWARE.
~
-->

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
tools:ignore="ContentDescription|RtlHardcoded,Overdraw">

<ImageView
android:id="@+id/ivLogo"
android:layout_width="@dimen/logo_size_splash"
android:layout_height="@dimen/logo_size_splash"
android:layout_centerInParent="true"
tools:ignore="ContentDescription" />

</RelativeLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="logo_size_splash">96dp</dimen>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/sort_functions_array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@
<item>@string/linear_sort</item>
<item>@string/radial_sort</item>
<item>@string/random_sort</item>
<item>@string/snake_sort</item>
</string-array>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<string name="linear_sort">Linear Sort</string>
<string name="radial_sort">Radial Sort</string>
<string name="random_sort">Random Sort</string>
<string name="snake_sort">Snake Sort</string>
<!-- Linear -->
<string name="bottom_to_top">Bottom to Top</string>
<string name="top_to_bottom">Top to Bottom</string>
Expand Down Expand Up @@ -82,5 +83,6 @@
<string name="linear_sort_code">new LinearSort(%1$d, %2$s, LinearSort.Direction.%3$s);</string>
<string name="radial_sort_code">new RadialSort(%1$d, %2$s, RadialSort.Position.%3$s);</string>
<string name="random_sort_code">new RandomSort(%1$d);</string>
<string name="snake_sort_code">new SnakeSort(%1$d, %2$s, CorneredSort.Corner.%3$s);</string>
<string name="sort_controls">Sort Controls</string>
</resources>
1 change: 1 addition & 0 deletions lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.3.0'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.7.17'
Expand Down
1 change: 1 addition & 0 deletions lib/src/main/java/com/willowtreeapps/spruce/Spruce.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ private AnimatorSet getAnimatorSetForSort(Animator[] animators, SortFunction sor
children.add(viewGroup.getChildAt(i));
}

sortFunction.sortChildren(viewGroup, children);
childrenWithTime = sortFunction.getViewListWithTimeOffsets(viewGroup, children);
animatorSet = new AnimatorSet();
List<Animator> animatorsList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public class ContinuousSort extends RadialSort {

private final long duration;
private final boolean reversed;
private double maxDistance;

/**
* Establishes the delay between object animations and their starting position based on distance,
Expand All @@ -55,17 +54,18 @@ public ContinuousSort(long interObjectDelay, boolean reversed, Position position
public List<SpruceTimedView> getViewListWithTimeOffsets(ViewGroup parent, List<View> children) {
final PointF comparisonPoint = getDistancePoint(parent, children);

Collections.sort(children, new Comparator<View>() {
@Override
public int compare(View left, View right) {
double leftDistance = getDistanceBetweenPoints(Utils.viewToPoint(left), comparisonPoint);
double rightDistance = getDistanceBetweenPoints(Utils.viewToPoint(right), comparisonPoint);
if (leftDistance > rightDistance && leftDistance > maxDistance) {
maxDistance = leftDistance;
double maxDistance = 0;
for (View v1: children) {
for (View v2: children) {
if (v1 != v2) {
double leftDistance = getDistanceBetweenPoints(Utils.viewToPoint(v1), comparisonPoint);
double rightDistance = getDistanceBetweenPoints(Utils.viewToPoint(v2), comparisonPoint);
if (leftDistance > rightDistance && leftDistance > maxDistance) {
maxDistance = leftDistance;
}
}
return Double.compare(leftDistance, rightDistance);
}
});
}

List<SpruceTimedView> timedViews = new ArrayList<>();
for (View view : children) {
Expand All @@ -83,4 +83,18 @@ public int compare(View left, View right) {

return timedViews;
}

@Override
public void sortChildren(ViewGroup parent, List<View> children) {
final PointF comparisonPoint = getDistancePoint(parent, children);
Collections.sort(children, new Comparator<View>() {
@Override
public int compare(View left, View right) {
double leftDistance = getDistanceBetweenPoints(Utils.viewToPoint(left), comparisonPoint);
double rightDistance = getDistanceBetweenPoints(Utils.viewToPoint(right), comparisonPoint);
return Double.compare(leftDistance, rightDistance);
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,15 @@ public ContinuousWeightedSort(long interObjectDelay, boolean reversed, Position
@Override
public List<SpruceTimedView> getViewListWithTimeOffsets(ViewGroup parent, List<View> children) {
final PointF comparisonPoint = getDistancePoint(parent, children);

// non-sort to calculate max horizontal/vertical values
Collections.sort(children, new Comparator<View>() {
@Override
public int compare(View left, View right) {
double leftHorizontalDistance = Utils.horizontalDistance(comparisonPoint, Utils.viewToPoint(left)) * horizontalWeight;
double rightHorizontalDistance = Utils.horizontalDistance(comparisonPoint, Utils.viewToPoint(right)) * horizontalWeight;
double leftVerticalDistance = Utils.verticalDistance(comparisonPoint, Utils.viewToPoint(left)) * verticalWeight;
double rightVerticalDistance = Utils.verticalDistance(comparisonPoint, Utils.viewToPoint(right)) * verticalWeight;

public int compare(View v1, View v2) {
double leftHorizontalDistance = Utils.horizontalDistance(comparisonPoint, Utils.viewToPoint(v1)) * horizontalWeight;
double rightHorizontalDistance = Utils.horizontalDistance(comparisonPoint, Utils.viewToPoint(v2)) * horizontalWeight;
double leftVerticalDistance = Utils.verticalDistance(comparisonPoint, Utils.viewToPoint(v1)) * verticalWeight;
double rightVerticalDistance = Utils.verticalDistance(comparisonPoint, Utils.viewToPoint(v2)) * verticalWeight;
maxHorizontalDistance = calculateMaxDistance(leftHorizontalDistance, rightHorizontalDistance, maxHorizontalDistance);
maxVerticalDistance = calculateMaxDistance(leftVerticalDistance, rightVerticalDistance, maxVerticalDistance);

return 0;
}
});
Expand Down Expand Up @@ -115,6 +111,11 @@ public int compare(View left, View right) {
return timedViews;
}

@Override
public void sortChildren(ViewGroup parent, List<View> children) {
// Do nothing
}

@VisibleForTesting
double calculateMaxDistance(double leftHorizontalDistance, double rightHorizontalDistance, double maximum) {
if (leftHorizontalDistance > rightHorizontalDistance && leftHorizontalDistance > maximum) {
Expand Down
Loading

0 comments on commit 87fc1b9

Please sign in to comment.