Skip to content

Commit

Permalink
Merge pull request #39 from sdsmdg/TrianglifyCorrections
Browse files Browse the repository at this point in the history
Trianglify Corrections
  • Loading branch information
suyashmahar authored May 25, 2017
2 parents 656958b + 20f0d4f commit 0b52edb
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 126 deletions.
21 changes: 14 additions & 7 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,16 @@ trianglifyView.setGridWidth(trianglifyView.getWidth())
| Draw strokes | false | .setDrawStrokes(...) | draw_strokes | Draws triangle's border with neighboring triangle's color |
| Color Palette | YlGn | .setPalette(...) | palette | Set of existing colors to color triangles |
| Random Coloring | false | .setRandomColoring(...) | random_coloring | If random coloring is on triangles will be colored randomly instead of linear interpolation |
| Fill the View Completely | false | .setFillViewCompletely(...) | fillViewCompletely| If fillViewCompletely is true, then it will throw illegalArgumentsException whenever both `BleedX` and `BleedY` are not greater than `cellSize`. Refer to [Section 2.2](#2.2)
| Fill the View Completely | false | .setFillViewCompletely(...) | fillViewCompletely| If fillViewCompletely is true, then it will throw illegalArgumentsException whenever both `BleedX` and `BleedY` are not greater than `cellSize`. Refer to [Section 2.2](#22-details-of-bleed-and-grid-dimensions)

*Current release contains only one GridType accessible with id `0`

**Other methods**
These methods are getters for corresponding properties and are not covered in the table above:
The following methods are getters for corresponding properties and are not covered in the table above:
* isDrawStrokeEnabled
* isRandomColoringEnabled
* isFillTriangle
* isFillViewCompletely
* getVariance
* getTypeGrid
* getPalette
Expand All @@ -91,11 +93,16 @@ These methods are getters for corresponding properties and are not covered in th
* getCellSize
* getBleedX
* getBleedY
* isFillTriangle
* isFillViewCompletely
* getViewState
* setViewState
For more information on states of view read **Smart update of view using smartUpdate** in [Section 2.7 Updating the View](#27-updating-the-view)

The following are additional methods provided for the developer:

**`getViewState`**

This method returns the state of the view. For more information on states of view read **Smart update of view using smartUpdate** in [Section 2.7 Updating the View](#27-updating-the-view).

**`clearView`**

This method clears the triangulation of the view and sets it to `null`.

#### 2.1.2 Palette
| Method | Return Type | Type | Parameters | Description |
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

Trianglify is an Android library that helps creates views with beautiful patterns. Trianglify is based on MVP architecture and licensed under MIT license.

# Usages
# How to Apply

Include following line in the gradle script of your application to include latest release of Trianglify:
```gradle
Expand All @@ -32,7 +32,7 @@ compile 'com.sdsmdg.kd:trianglify:0.9-beta'
| [demo apk](https://drive.google.com/open?id=0Bz_2jvdEtUlrWEpxQ2Y2RnJGc1U)
* Added custom palette demonstration to demo app
* Added method `fillViewCompletely` to check if view is incompletely filled
* Fixes many bugs [#23](https://github.com/sdsmdg/trianglify/issues/23) [#33](https://github.com/sdsmdg/trianglify/issues/33) [#34](https://github.com/sdsmdg/trianglify/issues/34) [#35](https://github.com/sdsmdg/trianglify/issues/35) [#36](https://github.com/sdsmdg/trianglify/issues/36)
* Fixes many bugs - [#23](https://github.com/sdsmdg/trianglify/issues/23), [#33](https://github.com/sdsmdg/trianglify/issues/33), [#34](https://github.com/sdsmdg/trianglify/issues/34), [#35](https://github.com/sdsmdg/trianglify/issues/35) & [#36](https://github.com/sdsmdg/trianglify/issues/36)

For more check complete [change log](/CHANGELOG.md).

Expand Down
108 changes: 51 additions & 57 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
android:layout_width="72dp"
android:text="Variance: "
android:textColor="#212121"
android:padding="4dp"
android:layout_margin="4dp"
android:layout_height="wrap_content" />

<SeekBar
Expand All @@ -47,33 +47,33 @@
android:layout_toRightOf="@id/variance_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="4dp"
android:layout_marginTop="2dp"
/>

<TextView
android:id="@+id/cell_size_textview"
android:layout_below="@id/variance_textview"
android:layout_width="72dp"
android:textColor="#212121"
android:padding="4dp"
android:layout_margin="4dp"
android:text="Cell Size: "
android:layout_height="wrap_content" />

<SeekBar
android:id="@+id/cell_size_seekbar"
android:layout_toRightOf="@id/cell_size_textview"
android:layout_below="@+id/variance_seekbar"
android:layout_below="@+id/variance_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="4dp"
android:layout_marginTop="2dp"
/>

<TextView
android:id="@+id/palette_textview"
android:layout_below="@id/cell_size_textview"
android:layout_width="72dp"
android:textColor="#212121"
android:padding="4dp"
android:layout_margin="4dp"
android:text="Palette: "
android:layout_height="wrap_content" />

Expand All @@ -83,66 +83,60 @@
android:layout_below="@+id/cell_size_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="4dp"
android:layout_marginTop="2dp"
/>

<LinearLayout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="@id/palette_seekbar"
android:layout_below="@id/palette_textview"
android:layout_marginTop="4dp"
>

<LinearLayout
<View
android:id="@+id/layout_middle_point"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_centerInParent="true"
/>

<CheckBox
android:id="@+id/random_coloring_checkbox"
android:layout_toRightOf="@id/layout_middle_point"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Random Coloring"
android:checked="false"
/>

<CheckBox
android:id="@+id/custom_palette_checkbox"
android:layout_toLeftOf="@id/layout_middle_point"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Custom Palette"
/>

<CheckBox
android:id="@+id/draw_stroke_checkbox"
android:layout_below="@id/custom_palette_checkbox"
android:layout_toLeftOf="@id/layout_middle_point"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<CheckBox
android:id="@+id/random_coloring_checkbox"
android:layout_below="@+id/palette_seekbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Random Coloring"
android:checked="false"
android:layout_weight="1"
/>

<CheckBox
android:id="@+id/custom_palette_checkbox"
android:layout_below="@+id/draw_fill_checkbox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Custom Palette"
android:layout_weight="1"
/>
</LinearLayout>

<LinearLayout
android:layout_height="wrap_content"
android:text="Draw Strokes"
/>

<CheckBox
android:id="@+id/draw_fill_checkbox"
android:layout_below="@id/random_coloring_checkbox"
android:layout_toRightOf="@id/layout_middle_point"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<CheckBox
android:id="@+id/draw_stroke_checkbox"
android:layout_below="@+id/random_coloring_checkbox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Draw Strokes"
android:layout_weight="1"
/>

<CheckBox
android:id="@+id/draw_fill_checkbox"
android:layout_below="@+id/draw_stroke_checkbox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Fill Triangles"
android:layout_weight="1"
/>

</LinearLayout>

</LinearLayout>
android:layout_height="wrap_content"
android:text="Fill Triangles"
/>

</RelativeLayout>

</RelativeLayout>

</RelativeLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,25 @@ public class Presenter {
private TrianglifyViewInterface view;
private Triangulation triangulation;
private TriangleGeneratorTask generatorTask;
private TrianglifyView.ViewState viewState;

/**
* Flag for keeping track of changes in attributes of the view. Helpful in increasing
* performance by stopping unnecessary regeneration of triangulation. Look at smartUpdate method for more.
* if triangulation is null then value is NULL_TRIANGULATION
* if triangulation is unchanged then value is UNCHANGED_TRIANGULATION
* if change in fillTriangle or drawStroke then value is PAINT_STYLE_CHANGED
* if change in grid width, grid height, variance, bleedX, bleedY, typeGrid or cell size then value is GRID_PARAMETERS_CHANGED
* if change in palette or random coloring then value is COLOR_SCHEME_CHANGED
*/
public ViewState viewState = ViewState.NULL_TRIANGULATION;

public enum ViewState {
NULL_TRIANGULATION,
UNCHANGED_TRIANGULATION,
PAINT_STYLE_CHANGED,
COLOR_SCHEME_CHANGED,
GRID_PARAMETERS_CHANGED
}

/**
* flag that keeps track of whether just the color of the triangulation is to be changed or not.
Expand All @@ -43,21 +61,17 @@ public Presenter(TrianglifyViewInterface view) {
this.view = view;
}

public boolean getGenerateOnlyColor() {
return generateOnlyColor;
}

public void setGenerateOnlyColor(boolean generateOnlyColor) {
this.generateOnlyColor = generateOnlyColor;
}

public void updateView() {
viewState = view.getViewState();
if (viewState == TrianglifyView.ViewState.PAINT_STYLE_CHANGED || viewState == TrianglifyView.ViewState.UNCHANGED_TRIANGULATION) {
if (viewState == ViewState.PAINT_STYLE_CHANGED || viewState == ViewState.UNCHANGED_TRIANGULATION) {
view.invalidateView(triangulation);
} else if (viewState == TrianglifyView.ViewState.COLOR_SCHEME_CHANGED) {
} else if (viewState == ViewState.COLOR_SCHEME_CHANGED) {
generateNewColoredSoupAndInvalidate();
} else if (viewState == TrianglifyView.ViewState.GRID_PARAMETERS_CHANGED || viewState == TrianglifyView.ViewState.NULL_TRIANGULATION) {
} else if (viewState == ViewState.GRID_PARAMETERS_CHANGED || viewState == ViewState.NULL_TRIANGULATION) {
generateOnlyColor = false;
generateSoupAndInvalidateView();
}
Expand Down Expand Up @@ -152,7 +166,7 @@ private Triangulation generateColoredSoup(Triangulation inputTriangulation) {

public void clearSoup() {
triangulation = null;
view.setViewState(TrianglifyView.ViewState.NULL_TRIANGULATION);
viewState = ViewState.NULL_TRIANGULATION;
}

/**
Expand Down
Loading

0 comments on commit 0b52edb

Please sign in to comment.