Skip to content

Commit

Permalink
- Logic Fixes.
Browse files Browse the repository at this point in the history
- Adding free size handling.
  • Loading branch information
MuhammedRefaat committed Nov 5, 2019
1 parent 4303309 commit 541924a
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 10 deletions.
1 change: 1 addition & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 30 additions & 1 deletion app/src/main/java/com/imagine/colorpalette/ColorPalette.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;

Expand All @@ -33,6 +34,7 @@ public class ColorPalette extends HorizontalScrollView implements View.OnClickLi
public static final int FASHION_COLORS = 2;
public static final int TURBO_COLORS = 3;
public static final int BLACK_WHITE_COLORS = 4;
private int height = ViewGroup.LayoutParams.MATCH_PARENT;

@IntDef(value = {ORIGINAL_COLORS, SOFT_COLORS, FASHION_COLORS, TURBO_COLORS, BLACK_WHITE_COLORS})
@interface ColorPalettsSelections {
Expand Down Expand Up @@ -90,9 +92,20 @@ private void setContext(Context context) {
* creating and setting att.s for the linear layout
*/
private void setTheContainer() {
// first, check for height change
height = LinearLayout.LayoutParams.MATCH_PARENT;
ViewGroup.LayoutParams parentLayoutParams = this.getLayoutParams();
try {
if (parentLayoutParams.height != ViewGroup.LayoutParams.MATCH_PARENT &&
parentLayoutParams.height != ViewGroup.LayoutParams.WRAP_CONTENT)
height = parentLayoutParams.height;
} catch (Exception ex) {
ex.printStackTrace();
}
// Now, Apply the changes
colorsContainer = new LinearLayout(context);
colorsContainer.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
height));
colorsContainer.setGravity(Gravity.CENTER_VERTICAL);
colorsContainer.setOrientation(LinearLayout.HORIZONTAL);
this.addView(colorsContainer);
Expand Down Expand Up @@ -172,6 +185,22 @@ private void addTheColorLayout(String colorValue, boolean addingFrame) {
colorLayout.setTag(colorValue);
// setting the onCLick Listener for the color selection
colorLayout.setOnClickListener(this);
// check for height changes
if (height != ViewGroup.LayoutParams.MATCH_PARENT) {
try {
// set colorFrame height
LinearLayout.LayoutParams colorFrameLp = (LinearLayout.LayoutParams) colorFrame.getLayoutParams();
colorFrameLp.height = height;
colorFrame.setLayoutParams(colorFrameLp);
// set colorElement height
int colorElementHeight = (int) (height * 0.58333333333);
LinearLayout.LayoutParams colorElementLp = (LinearLayout.LayoutParams) color.getLayoutParams();
colorElementLp.height = colorElementHeight;
color.setLayoutParams(colorElementLp);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

/**
Expand Down
16 changes: 7 additions & 9 deletions app/src/main/res/layout/single_color_layout.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:paddingStart="8dp"
android:paddingLeft="8dp"
android:paddingTop="15dp"
android:paddingEnd="8dp"
android:paddingRight="8dp"
android:paddingBottom="15dp">
android:paddingRight="8dp">

<View
android:id="@+id/color_frame"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_width="@dimen/default_border_size"
android:layout_height="@dimen/default_border_size"
android:layout_centerInParent="true"
android:background="@drawable/color_palette_border"
android:visibility="invisible" />

<View
android:id="@+id/color"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_width="@dimen/default_color_element_size"
android:layout_height="@dimen/default_color_element_size"
android:layout_centerInParent="true"
android:background="@drawable/color_palette_template" />

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color>
<color name="icons">#FFFFFF</color>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="default_border_size">60dp</dimen>
<dimen name="default_color_element_size">35dp</dimen>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
<enum name="blackAndWhite" value="4" />
</attr>
</declare-styleable>

</resources>

0 comments on commit 541924a

Please sign in to comment.