Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Sample #66

Merged
merged 1 commit into from
Mar 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.GridLayout;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
Expand Down Expand Up @@ -88,6 +89,7 @@ public class ViewFragment extends Fragment implements RadioGroupGridLayout.OnCha
private LinearLayout horizontalWeightLayout;
private TextView animationEndText;
private TextView seekBarTitle;
private EditText codeSample;

private List<View> children = new ArrayList<>();
private Animator[] animators;
Expand All @@ -114,6 +116,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, @Nullable
sortDropDown = (Spinner) container.findViewById(R.id.sort_selection);
animationEndText = (TextView) container.findViewById(R.id.animation_end);
seekBarTitle = (TextView) container.findViewById(R.id.seek_bar_title);
codeSample = (EditText) container.findViewById(R.id.code_sample);
final int CHILD_VIEW_COUNT = parent.getColumnCount() * parent.getRowCount();

for (int i = 0; i < CHILD_VIEW_COUNT; i++) {
Expand Down Expand Up @@ -363,36 +366,64 @@ private void setupSort() {
switch (sortDropDown.getSelectedItemPosition()) {
case DEFAULT_SORT:
sortFunction = new DefaultSort(seekBar.getProgress());
codeSample.setText(String.format(getResources().getString(R.string.default_sort_code), seekBar.getProgress()));
break;
case CORNERED_SORT:
sortFunction = new CorneredSort(seekBar.getProgress(), linearReversed.isChecked(), corner);
codeSample.setText(String.format(getResources().getString(R.string.cornered_sort_code),
seekBar.getProgress(),
String.valueOf(linearReversed.isChecked()),
corner));
break;
case CONTINUOUS_SORT:
sortFunction = new ContinuousSort(seekBar.getProgress() * /*timePaddingOffset=*/20,
linearReversed.isChecked(),
positionalRadioGroup.getPosition());
codeSample.setText(String.format(getResources().getString(R.string.continuous_sort_code),
seekBar.getProgress() * /*timePaddingOffset=*/20,
String.valueOf(linearReversed.isChecked()),
positionalRadioGroup.getPosition()));
break;
case CONTINUOUS_WEIGHTED_SORT:
sortFunction = new ContinuousWeightedSort(seekBar.getProgress() * /*timePaddingOffset=*/20,
linearReversed.isChecked(),
positionalRadioGroup.getPosition(),
horizontalWeight,
verticalWeight);
codeSample.setText(String.format(getResources().getString(R.string.continuous_weighted_sort_code),
seekBar.getProgress() * /*timePaddingOffset=*/20,
String.valueOf(linearReversed.isChecked()),
positionalRadioGroup.getPosition(),
String.valueOf(horizontalWeight),
String.valueOf(verticalWeight)));
break;
case INLINE_SORT:
sortFunction = new InlineSort(seekBar.getProgress(), linearReversed.isChecked(), corner);
codeSample.setText(String.format(getResources().getString(R.string.inline_sort_code),
seekBar.getProgress(),
String.valueOf(linearReversed.isChecked()),
corner));
break;
case LINEAR_SORT:
sortFunction = new LinearSort(seekBar.getProgress(), linearReversed.isChecked(), direction);
codeSample.setText(String.format(getResources().getString(R.string.linear_sort_code),
seekBar.getProgress(),
String.valueOf(linearReversed.isChecked()),
direction));
break;
case RADIAL_SORT:
sortFunction = new RadialSort(seekBar.getProgress(), linearReversed.isChecked(), positionalRadioGroup.getPosition());
codeSample.setText(String.format(getResources().getString(R.string.radial_sort_code), seekBar.getProgress(),
String.valueOf(linearReversed.isChecked()),
positionalRadioGroup.getPosition()));
break;
case RANDOM_SORT:
sortFunction = new RandomSort(seekBar.getProgress());
codeSample.setText(String.format(getResources().getString(R.string.random_sort_code), seekBar.getProgress()));
break;
default:
sortFunction = new DefaultSort(seekBar.getProgress());
codeSample.setText(String.format(getResources().getString(R.string.default_sort_code), seekBar.getProgress()));
break;
}

Expand Down
28 changes: 28 additions & 0 deletions app/src/main/res/drawable/code_sample_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?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.
~
-->

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/white"/>
<padding android:bottom="8dp" android:top="8dp" android:right="8dp" android:left="8dp"/>
<stroke android:width="1dp" android:color="@color/lighter_gray"/>
</shape>
17 changes: 17 additions & 0 deletions app/src/main/res/layout/activity_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,23 @@

</LinearLayout>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:text="@string/code_sample"/>

<EditText
android:id="@+id/code_sample"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:inputType="none"
android:textIsSelectable="true"
android:background="@drawable/code_sample_background"/>

</LinearLayout>

</ScrollView>
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,15 @@
<string name="sort_function_selection">Sort Function selection</string>
<string name="select">Select</string>
<string name="cancel">Cancel</string>

<!-- Code generation -->
<string name="code_sample">Code Sample</string>
<string name="default_sort_code">new DefaultSort(%1$d);</string>
<string name="cornered_sort_code">new CorneredSort(%1$d, %2$s, CorneredSort.Corner.%3$s);</string>
<string name="continuous_sort_code">new ContinuousSort(%1$d, %2$s, RadialSort.Position.%3$s);</string>
<string name="continuous_weighted_sort_code">new ContinuousWeightedSort(%1$d, %2$s, RadialSort.Position.%3$s, %4$s, %5$s);</string>
<string name="inline_sort_code">new InlineSort(%1$d, %2$s, CorneredSort.Corner.%3$s);</string>
<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>
</resources>
Loading