Skip to content

Commit

Permalink
Merge pull request #2 from shehabic/styleable_ui
Browse files Browse the repository at this point in the history
Styleable ui
  • Loading branch information
shehabic committed Mar 9, 2015
2 parents 299aeaa + d0288ad commit 602d324
Show file tree
Hide file tree
Showing 36 changed files with 129 additions and 74 deletions.
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ Version
=======
v.0.1 beta

Usage (Gradle)
==============

```
repositories {
maven { url 'http://maven.shehabic.com' }
}
Usage (Maven)
=============
```XML
<dependency>
<groupId>com.shehabic.droppy</groupId>
<artifactId>Droppy</artifactId>
<version>0.1</version>
</dependency>
```

```
dependencies {
compile 'com.shehabic.droppy:Droppy:0.1@aar'
}
Usage (Gradle)
==============
```groovy
compile 'com.shehabic.droppy:Droppy:0.1@aar'
```

Generate Programmatically
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ void initMenuItem(String title, int iconResourceId)
if (iconResourceId > 0) {
this.icon = iconResourceId;
}
this.customViewResourceId = R.layout.droppy_menu_item;
}

public DroppyMenuItem(String title)
Expand All @@ -44,8 +43,7 @@ public void setIcon(Drawable iconDrawable)

@Override
public View render(Context context) {
super.render(context);


renderedView = new com.shehabic.droppy.views.DroppyMenuItem(context);

if (this.icon != -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public View render(Context context) {
if (this.renderedView == null) {
this.renderedView = LayoutInflater.from(context).inflate(this.customViewResourceId, null);
}
ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
renderedView.setLayoutParams(lp);

return renderedView;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
package com.shehabic.droppy;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
/**
* Created by shehabic on 2/28/15.
*/
public class DroppyMenuSeparator extends DroppyMenuItemAbstract {

public DroppyMenuSeparator() {
initSeparator(R.layout.droppy_separator);
}

public DroppyMenuSeparator(int customSeparatorResourceId) {
initSeparator(customSeparatorResourceId);
}

protected void initSeparator(int separatorLayoutResourceId) {
customViewResourceId = separatorLayoutResourceId;
type = TYPE_MENU_SEPARATOR;
setId(-1);
setClickable(false);
Expand All @@ -26,7 +16,7 @@ protected void initSeparator(int separatorLayoutResourceId) {
@Override
public View render(Context context) {
if (renderedView == null) {
renderedView = LayoutInflater.from(context).inflate(this.customViewResourceId, null);
renderedView = new com.shehabic.droppy.views.DroppyMenuSeparator(context);
}

return renderedView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public DroppyMenuContainer(Context context, AttributeSet attrs, int defStyleAttr
this.setOrientation(VERTICAL);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DroppyMenuPopup, defStyleAttr, 0);
ViewGroup.LayoutParams lp = getLayoutParams();
int height = (int) a.getDimension(R.styleable.DroppyMenuContainer_android_layout_height, ViewGroup.LayoutParams.WRAP_CONTENT);
int width = (int) a.getDimension(R.styleable.DroppyMenuContainer_android_layout_width, ViewGroup.LayoutParams.WRAP_CONTENT);
int height = a.getLayoutDimension(R.styleable.DroppyMenuContainer_android_layout_height, ViewGroup.LayoutParams.WRAP_CONTENT);
int width = a.getLayoutDimension(R.styleable.DroppyMenuContainer_android_layout_width, ViewGroup.LayoutParams.WRAP_CONTENT);

if (lp == null) {
lp = new ViewGroup.LayoutParams(width, height);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public DroppyMenuItem(Context context, AttributeSet attrs, int defStyleAttr) {
ViewGroup.LayoutParams lp = getLayoutParams();
setMinimumWidth((int) minWidth);
setMinimumHeight((int) minHeight);
int width = (int) a.getDimension(R.styleable.DroppyMenuItem_android_layout_height, ViewGroup.LayoutParams.WRAP_CONTENT);
int height = (int) a.getDimension(R.styleable.DroppyMenuItem_android_layout_width, ViewGroup.LayoutParams.WRAP_CONTENT);
int width = a.getLayoutDimension(R.styleable.DroppyMenuItem_android_layout_width, ViewGroup.LayoutParams.MATCH_PARENT);
int height = a.getLayoutDimension(R.styleable.DroppyMenuItem_android_layout_height, ViewGroup.LayoutParams.WRAP_CONTENT);
if (lp == null) {
lp = new ViewGroup.LayoutParams(width, height);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,18 @@ public DroppyMenuItemIcon(Context context, AttributeSet attrs, int defStyleAttr)
final int defaultMaxHeight = (int) getResources().getDimension(R.dimen.default_menu_item_icon_maxHeight);
final float defaultWeight = 0;
final int defaultLayoutGravity = Gravity.START | Gravity.CENTER_VERTICAL;
final int defaultMarginLeft = (int) getResources().getDimension(R.dimen.default_menu_item_icon_marginLeft);
final int defaultMarginRight= (int) getResources().getDimension(R.dimen.default_menu_item_icon_marginRight);

TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DroppyMenuItemIcon, defStyleAttr, 0);
int maxWidth = (int) a.getDimension(R.styleable.DroppyMenuItemIcon_android_maxWidth, defaultMaxWidth);
int maxHeight = (int) a.getDimension(R.styleable.DroppyMenuItemIcon_android_maxHeight, defaultMaxHeight);
int width = (int) a.getDimension(R.styleable.DroppyMenuItemIcon_android_layout_width, ViewGroup.LayoutParams.WRAP_CONTENT);
int height = (int) a.getDimension(R.styleable.DroppyMenuItemIcon_android_layout_height, ViewGroup.LayoutParams.WRAP_CONTENT);
int width = a.getLayoutDimension(R.styleable.DroppyMenuItemIcon_android_layout_width, ViewGroup.LayoutParams.WRAP_CONTENT);
int height = a.getLayoutDimension(R.styleable.DroppyMenuItemIcon_android_layout_height, ViewGroup.LayoutParams.WRAP_CONTENT);

LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(width, height);
lp.rightMargin = a.getDimensionPixelSize(R.styleable.DroppyMenuItemIcon_android_layout_marginRight, defaultMarginRight);
lp.leftMargin = a.getDimensionPixelSize(R.styleable.DroppyMenuItemIcon_android_layout_marginLeft, defaultMarginLeft);
lp.width = width;
lp.height = height;
lp.weight = a.getFloat(R.styleable.DroppyMenuItemIcon_android_layout_weight, defaultWeight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public DroppyMenuItemTitle(Context context, AttributeSet attrs, int defStyleAttr
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DroppyMenuItemTitle, defStyleAttr, 0);
int minWidth = (int) a.getDimension(R.styleable.DroppyMenuItemTitle_android_minWidth, defaultMinWidth);
int minHeight = (int) a.getDimension(R.styleable.DroppyMenuItemTitle_android_minHeight, defaultMinHeight);
int width = (int) a.getDimension(R.styleable.DroppyMenuItemTitle_android_layout_width, defaultWidth);
int height = a.getInt(R.styleable.DroppyMenuItemTitle_android_layout_height, ViewGroup.LayoutParams.WRAP_CONTENT);
int width = a.getLayoutDimension(R.styleable.DroppyMenuItemTitle_android_layout_width, defaultWidth);
int height = a.getLayoutDimension(R.styleable.DroppyMenuItemTitle_android_layout_height, ViewGroup.LayoutParams.WRAP_CONTENT);
int color = a.getColor(R.styleable.DroppyMenuItemTitle_android_textColor, defaultColor);

setGravity(a.getInt(R.styleable.DroppyMenuItemTitle_android_gravity, defaultGravity));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public DroppyMenuPopup(Context context, AttributeSet attrs, int defStyleAttr) {

TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DroppyMenuPopup, defStyleAttr, 0);
Drawable background = a.getDrawable(R.styleable.DroppyMenuPopup_android_background);
int height = (int) a.getDimension(R.styleable.DroppyMenuPopup_android_layout_height, ViewGroup.LayoutParams.WRAP_CONTENT);
int width = (int) a.getDimension(R.styleable.DroppyMenuPopup_android_layout_width, ViewGroup.LayoutParams.WRAP_CONTENT);
int height = a.getLayoutDimension(R.styleable.DroppyMenuPopup_android_layout_height, ViewGroup.LayoutParams.WRAP_CONTENT);
int width = a.getLayoutDimension(R.styleable.DroppyMenuPopup_android_layout_width, ViewGroup.LayoutParams.WRAP_CONTENT);
ViewGroup.LayoutParams lp = getLayoutParams();
if (lp == null) {
lp = new ViewGroup.LayoutParams(width, height);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.shehabic.droppy.views;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.shehabic.droppy.R;

/**
* Created by shehabic on 3/8/15.
*/
public class DroppyMenuSeparator extends LinearLayout {
public DroppyMenuSeparator(Context context) {
this(context, null);
}

public DroppyMenuSeparator(Context context, AttributeSet attrs) {
this(context, attrs, R.attr.droppyMenuSeparatorStyle);
}

public DroppyMenuSeparator(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);

TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DroppyMenuItem, defStyleAttr, 0);

final Drawable defaultSeparatorBackground = getResources().getDrawable(R.drawable.droppy_separator_background);
final int defaultHeight = getResources().getDimensionPixelSize(R.dimen.default_menu_separator_height);
ViewGroup.LayoutParams lp = getLayoutParams();
int width = a.getLayoutDimension(R.styleable.DroppyMenuItem_android_layout_width, ViewGroup.LayoutParams.MATCH_PARENT);
int height = a.getLayoutDimension(R.styleable.DroppyMenuItem_android_layout_height, defaultHeight);
if (lp == null) {
lp = new ViewGroup.LayoutParams(width, height);
} else {
lp.width = width;
lp.height = height;
}
setOrientation(LinearLayout.HORIZONTAL);

Drawable background = a.getDrawable(R.styleable.DroppyMenuSeparator_android_background);
if (background != null) {
setBackgroundDrawable(background);
} else {
setBackgroundDrawable(defaultSeparatorBackground);
}

this.setLayoutParams(lp);
}
}
5 changes: 5 additions & 0 deletions library/src/main/res/drawable/droppy_separator_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/droppy_separator"/>
</shape>
11 changes: 0 additions & 11 deletions library/src/main/res/layout/droppy_menu.xml

This file was deleted.

12 changes: 0 additions & 12 deletions library/src/main/res/layout/droppy_menu_item.xml

This file was deleted.

3 changes: 0 additions & 3 deletions library/src/main/res/layout/droppy_separator.xml

This file was deleted.

3 changes: 2 additions & 1 deletion library/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="darkgrey" type="color">#FF333333</item>
<item name="droppy_separator" type="color">#FFBBBBBB</item>
<item name="droppy_title_color" type="color">#FF333333</item>
</resources>
14 changes: 14 additions & 0 deletions library/src/main/res/values/droppy__attr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<declare-styleable name="Droppy">
<attr name="droppyPopupStyle" format="reference"/>
<attr name="droppyMenuStyle" format="reference"/>
<attr name="droppyMenuSeparatorStyle" format="reference"/>
<attr name="droppyMenuItemStyle" format="reference"/>
<attr name="droppyMenuItemTitleStyle" format="reference"/>
<attr name="droppyMenuItemIconStyle" format="reference"/>
Expand All @@ -20,6 +21,15 @@
<attr name="android:orientation"/>
</declare-styleable>

<declare-styleable name="DroppyMenuSeparator">
<attr name="android:background"/>
<attr name="android:layout_height"/>
<attr name="android:layout_width"/>
<attr name="android:layout_marginTop"/>
<attr name="android:layout_marginBottom"/>
<attr name="android:orientation"/>
</declare-styleable>

<declare-styleable name="DroppyMenuItem">
<attr name="android:minWidth"/>
<attr name="android:minHeight"/>
Expand All @@ -42,6 +52,8 @@
<attr name="android:layout_gravity"/>
<attr name="android:layout_weight"/>
<attr name="android:layout_height"/>
<attr name="android:layout_marginLeft" />
<attr name="android:layout_marginRight" />
</declare-styleable>

<declare-styleable name="DroppyMenuItemTitle">
Expand All @@ -54,4 +66,6 @@
<attr name="android:gravity"/>
<attr name="android:layout_weight"/>
</declare-styleable>


</resources>
15 changes: 13 additions & 2 deletions library/src/main/res/values/droppy__defaults.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@

<!-- Menu -->

<!-- Menu Separator -->
<dimen name="default_menu_separator_height">0.5dp</dimen>
<dimen name="default_menu_separator_marginTop">3dp</dimen>
<dimen name="default_menu_separator_marginBottom">3dp</dimen>
<drawable name="default_menu_separator_background">@drawable/droppy_separator_background</drawable>
<!-- There's no easy way to define the following -->
<!--<attr name="android:orientation"/>-->

<!-- Menu Item -->
<dimen name="default_menu_item_minWidth">150dp</dimen>
<dimen name="default_menu_item_minHeight">30dp</dimen>
<dimen name="default_menu_item_minHeight">48dp</dimen>
<bool name="default_menu_item_clickable">true</bool>
<dimen name="default_menu_item_paddingTop">2dp</dimen>
<dimen name="default_menu_item_paddingBottom">2dp</dimen>
Expand All @@ -19,13 +27,16 @@
<!-- Mneu Item Icon -->
<dimen name="default_menu_item_icon_maxWidth">32dp</dimen>
<dimen name="default_menu_item_icon_maxHeight">32dp</dimen>
<dimen name="default_menu_item_icon_marginRight">5dp</dimen>
<dimen name="default_menu_item_icon_marginLeft">5dp</dimen>

<!-- There's no easy way to set default values for the following -->
<!--<item name="android:layout_gravity">start|center_vertical</item>-->
<!--<dimen name="default_menu_item_icon_layout_weight">0dp</dimen>-->


<!-- Menu Item Title -->
<color name="default_menu_item_title_textColor">@color/darkgrey</color>
<color name="default_menu_item_title_textColor">@color/droppy_title_color</color>
<dimen name="default_menu_item_title_minWidth">128dp</dimen>
<dimen name="default_menu_item_title_minHeight">30dp</dimen>
<dimen name="default_menu_item_title_layout_width">0dp</dimen>
Expand Down
10 changes: 4 additions & 6 deletions library/src/main/res/values/droppy__styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,9 @@
</style>

<style name="Droppy.DroppyMenuSeparator">
<item name="android:minWidth">120dp</item>
<item name="android:minHeight">0.5dp</item>
<item name="android:background">#BBBBBB</item>
<item name="android:background">@drawable/droppy_separator_background</item>
<item name="android:layout_height">0.5dp</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_marginTop">3dp</item>
<item name="android:layout_marginBottom">3dp</item>
<item name="android:orientation">horizontal</item>
</style>

Expand All @@ -57,10 +53,12 @@
<item name="android:layout_gravity">start|center_vertical</item>
<item name="android:layout_weight">0</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginLeft">5dp</item>
<item name="android:layout_marginRight">5dp</item>
</style>

<style name="Droppy.DroppyMenuItemTitle">
<item name="android:textColor">@color/darkgrey</item>
<item name="android:textColor">@color/droppy_title_color</item>
<item name="android:minWidth">128dp</item>
<item name="android:minHeight">30dp</item>
<item name="android:layout_height">wrap_content</item>
Expand Down
Binary file added samples/src/main/res/drawable-hdpi/droppy1.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 samples/src/main/res/drawable-hdpi/droppy2.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 samples/src/main/res/drawable-hdpi/droppy3.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 samples/src/main/res/drawable-hdpi/droppy4.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 samples/src/main/res/drawable-mdpi/droppy1.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 samples/src/main/res/drawable-mdpi/droppy2.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 samples/src/main/res/drawable-mdpi/droppy3.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 samples/src/main/res/drawable-mdpi/droppy4.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 samples/src/main/res/drawable-xhdpi/droppy1.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 samples/src/main/res/drawable-xhdpi/droppy2.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 samples/src/main/res/drawable-xhdpi/droppy3.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 samples/src/main/res/drawable-xhdpi/droppy4.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 samples/src/main/res/drawable-xxhdpi/droppy1.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 samples/src/main/res/drawable-xxhdpi/droppy2.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 samples/src/main/res/drawable-xxhdpi/droppy3.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 samples/src/main/res/drawable-xxhdpi/droppy4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions samples/src/main/res/menu/droppy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,25 @@
<item
android:id="@+id/dropp1"
android:title="Xml Item 1"
android:icon="@drawable/droppy1"
/>

<item
android:id="@+id/droppy2"
android:title="Xml Item 2"
android:icon="@drawable/droppy2"
/>
</group>
<group android:enabled="true">
<item
android:id="@+id/dropp3"
android:icon="@drawable/ic_launcher"
android:icon="@drawable/droppy3"
android:title="Xml Item 3"
/>

<item
android:id="@+id/droppy4"
android:icon="@drawable/ic_launcher"
android:icon="@drawable/droppy4"
android:title="Xml Item 4"
/>
</group>
Expand Down
Loading

0 comments on commit 602d324

Please sign in to comment.