Skip to content

Commit

Permalink
Adjusting all views and the generation of ui to have eveything styllable
Browse files Browse the repository at this point in the history
  • Loading branch information
shehabic committed Mar 8, 2015
1 parent 33a5b28 commit 4ca01cd
Show file tree
Hide file tree
Showing 17 changed files with 429 additions and 41 deletions.
6 changes: 3 additions & 3 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
versionCode 2
versionName "0.2"
}
buildTypes {
release {
Expand All @@ -21,7 +21,7 @@ android {
ext {
PUBLISH_GROUP_ID = 'com.shehabic.droppy'
PUBLISH_ARTIFACT_ID = 'Droppy'
PUBLISH_VERSION = '0.1'
PUBLISH_VERSION = '0.2'
}


Expand Down
17 changes: 14 additions & 3 deletions library/src/main/java/com/shehabic/droppy/DroppyMenuItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
import android.widget.ImageView;
import android.widget.TextView;

import com.shehabic.droppy.views.DroppyMenuItemIcon;
import com.shehabic.droppy.views.DroppyMenuItemTitle;

/**
* Created by shehabic on 2/28/15.
*/
public class DroppyMenuItem extends DroppyMenuItemAbstract {

private Drawable iconDrawable;
protected com.shehabic.droppy.views.DroppyMenuItem renderedView;

void initMenuItem(String title, int iconResourceId)
{
Expand Down Expand Up @@ -42,14 +46,21 @@ public void setIcon(Drawable iconDrawable)
public View render(Context context) {
super.render(context);

((TextView) this.renderedView.findViewById(R.id.title)).setText(this.title);
renderedView = new com.shehabic.droppy.views.DroppyMenuItem(context);

if (this.icon != -1) {
((ImageView) this.renderedView.findViewById(R.id.icon)).setImageResource(this.icon);
DroppyMenuItemIcon droppyMenuItemIcon = new DroppyMenuItemIcon(context);
droppyMenuItemIcon.setImageResource(this.icon);
} else if (this.iconDrawable != null) {
((ImageView) this.renderedView.findViewById(R.id.icon)).setImageDrawable(iconDrawable);
DroppyMenuItemIcon droppyMenuItemIcon = new DroppyMenuItemIcon(context);
droppyMenuItemIcon.setImageDrawable(iconDrawable);
renderedView.addView(droppyMenuItemIcon);
}

DroppyMenuItemTitle droppyMenuItemTitle = new DroppyMenuItemTitle(context);
droppyMenuItemTitle.setText(this.title);
renderedView.addView(droppyMenuItemTitle);

return renderedView;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.content.Context;
import android.graphics.Point;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
Expand All @@ -14,27 +13,30 @@
import android.view.WindowManager;
import android.widget.FrameLayout;

import com.shehabic.droppy.views.DroppyMenuContainer;

import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;

/**
* Created by shehabic on 2/28/15.
*/
public class DroppyMenu {
public class DroppyMenuPopup {
protected Context mContext;
protected View anchor;
protected List<DroppyMenuItemInterface> menuItems = new ArrayList<DroppyMenuItemInterface>();
protected View mContentView;
protected View mPopupView;
protected com.shehabic.droppy.views.DroppyMenuPopup mPopupView;
protected DroppyMenuContainer droppyMenuContainer;
protected DroppyClickCallbackInterface droppyClickCallbackInterface;
protected int popupMenuLayoutResourceId;
protected FrameLayout modalWindow;
protected int mPopupWidth;
protected int mPopupHeight;
protected int statusBarHeight = -1;

private DroppyMenu(
private DroppyMenuPopup(
Context mContext,
View parentMenuItem,
List<DroppyMenuItemInterface> menuItem,
Expand All @@ -46,9 +48,6 @@ private DroppyMenu(
this.anchor = parentMenuItem;
this.menuItems = menuItem;
this.droppyClickCallbackInterface = droppyClickCallbackInterface;
if (popupMenuLayoutResourceId == -1) {
popupMenuLayoutResourceId = R.layout.droppy_menu;
}
this.popupMenuLayoutResourceId = popupMenuLayoutResourceId;
if (addTriggerOnAnchorClick) {
anchor.setOnClickListener(new View.OnClickListener() {
Expand Down Expand Up @@ -126,7 +125,9 @@ protected void render(boolean forceRender) {
if (mPopupView != null && ((ViewGroup) mPopupView).getChildCount() > 0) {
((ViewGroup) mPopupView).removeAllViews();
}
mPopupView = LayoutInflater.from(mContext).inflate(popupMenuLayoutResourceId, null);
mPopupView = new com.shehabic.droppy.views.DroppyMenuPopup(mContext);
droppyMenuContainer = new DroppyMenuContainer(mContext);
mPopupView.addView(droppyMenuContainer);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
mPopupView.setLayoutParams(lp);
mContentView = mPopupView;
Expand Down Expand Up @@ -161,7 +162,7 @@ public void onClick(View v) {
}
});
}
((ViewGroup) mPopupView.findViewById(R.id.droppyMenu)).addView(menuItemView);
droppyMenuContainer.addView(menuItemView);
}

protected Point getScreenSize() {
Expand Down Expand Up @@ -303,8 +304,8 @@ protected Menu newMenuInstance(Context context) {
return null;
}

public DroppyMenu build() {
return new DroppyMenu(ctx, parentMenuItem, menuItems, callbackInterface, triggerOnAnchorClick, -1);
public DroppyMenuPopup build() {
return new DroppyMenuPopup(ctx, parentMenuItem, menuItems, callbackInterface, triggerOnAnchorClick, -1);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.shehabic.droppy.views;

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

import com.shehabic.droppy.R;

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

public DroppyMenuContainer(Context context, AttributeSet attrs) {
this(context, attrs, R.attr.droppyMenuStyle);
}

public DroppyMenuContainer(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.setOrientation(VERTICAL);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DroppyMenuPopup, defStyleAttr, 0);
ViewGroup.LayoutParams lp = getLayoutParams();
int height = a.getInteger(R.styleable.DroppyMenuContainer_android_layout_height, ViewGroup.LayoutParams.WRAP_CONTENT);
int width = a.getInteger(R.styleable.DroppyMenuContainer_android_layout_width, ViewGroup.LayoutParams.WRAP_CONTENT);

if (lp == null) {
lp = new ViewGroup.LayoutParams(width, height);
} else {
lp.width = width;
lp.height = height;
}
setLayoutParams(lp);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
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.Gravity;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.shehabic.droppy.R;

/**
* Created by shehabic on 3/7/15.
*/
public class DroppyMenuItem extends LinearLayout {

public DroppyMenuItem(Context context) {
this(context, null);
}

public DroppyMenuItem(Context context, AttributeSet attrs) {
this(context, attrs, R.attr.droppyMenuItemStyle);
}

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

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

final Drawable defaultDrawable = getResources().getDrawable(R.drawable.default_menu_item_background);
final float defaultMinWidth = getResources().getDimension(R.dimen.default_menu_item_minWidth);
final float defaultMinHeight = getResources().getDimension(R.dimen.default_menu_item_minHeight);
final boolean defaultIsClickable = getResources().getBoolean(R.bool.default_menu_item_clickable);

float minWidth = a.getDimension(R.styleable.DroppyMenuItem_android_minWidth, defaultMinWidth);
float minHeight = a.getDimension(R.styleable.DroppyMenuItem_android_minHeight, defaultMinHeight);

ViewGroup.LayoutParams lp = getLayoutParams();
setMinimumWidth((int) minWidth);
setMinimumHeight((int) minHeight);
int width = a.getInteger(R.styleable.DroppyMenuItem_android_layout_height, ViewGroup.LayoutParams.WRAP_CONTENT);
int height = a.getInteger(R.styleable.DroppyMenuItem_android_layout_width, ViewGroup.LayoutParams.WRAP_CONTENT);
if (lp == null) {
lp = new ViewGroup.LayoutParams(width, height);
} else {
lp.width = width;
lp.height = height;
}
setClickable(a.getBoolean(R.styleable.DroppyMenuItem_android_clickable, defaultIsClickable));
setOrientation(LinearLayout.HORIZONTAL);
setGravity(a.getInteger(R.styleable.DroppyMenuItem_android_gravity, Gravity.CENTER_VERTICAL));
int paddingTop = a.getInteger(R.styleable.DroppyMenuItem_android_paddingTop, (int) getResources().getDimension(R.dimen.default_menu_item_paddingTop));
int paddingBottom = a.getInteger(R.styleable.DroppyMenuItem_android_paddingBottom, (int) getResources().getDimension(R.dimen.default_menu_item_paddingBottom));
int paddingLeft = a.getInteger(R.styleable.DroppyMenuItem_android_paddingLeft, (int) getResources().getDimension(R.dimen.default_menu_item_paddingLeft));
int paddingRight = a.getInteger(R.styleable.DroppyMenuItem_android_paddingRight, (int) getResources().getDimension(R.dimen.default_menu_item_paddingRight));
setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);

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

this.setLayoutParams(lp);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.shehabic.droppy.views;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.shehabic.droppy.R;

/**
* Created by shehabic on 3/7/15.
*/
public class DroppyMenuItemIcon extends ImageView {

public DroppyMenuItemIcon(Context context) {
this(context, null);
}

public DroppyMenuItemIcon(Context context, AttributeSet attrs) {
this(context, attrs, R.attr.droppyMenuItemIconStyle);
}

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

final int defaultMaxWidth = (int) getResources().getDimension(R.dimen.default_menu_item_icon_maxWidth);
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;

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 = a.getInteger(R.styleable.DroppyMenuItemIcon_android_layout_width, ViewGroup.LayoutParams.WRAP_CONTENT);
int height = a.getInteger(R.styleable.DroppyMenuItemIcon_android_layout_height, ViewGroup.LayoutParams.WRAP_CONTENT);

LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(width, height);
lp.width = width;
lp.height = height;
lp.weight = a.getFloat(R.styleable.DroppyMenuItemIcon_android_layout_weight, defaultWeight);
lp.gravity = a.getInteger(R.styleable.DroppyMenuItemIcon_android_layout_gravity, defaultLayoutGravity);

setMaxHeight(maxWidth);
setMaxHeight(maxHeight);
setLayoutParams(lp);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.shehabic.droppy.views;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.shehabic.droppy.R;

/**
* Created by shehabic on 3/7/15.
*/
public class DroppyMenuItemTitle extends TextView {

public DroppyMenuItemTitle(Context context) {
this(context, null);
}

public DroppyMenuItemTitle(Context context, AttributeSet attrs) {
this(context, attrs, R.attr.droppyMenuItemTitleStyle);
}

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

final int defaultWidth = (int) getResources().getDimension(R.dimen.default_menu_item_title_layout_width);
final int defaultMinWidth = (int) getResources().getDimension(R.dimen.default_menu_item_title_minWidth);
final int defaultMinHeight = (int) getResources().getDimension(R.dimen.default_menu_item_title_minHeight);
final float defaultWeight = 1;
final int defaultColor = getResources().getColor(R.color.default_menu_item_title_textColor);
final int defaultGravity = Gravity.CENTER_VERTICAL;
final int defaultLayoutGravity = Gravity.END | Gravity.CENTER_VERTICAL;

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 = a.getInteger(R.styleable.DroppyMenuItemTitle_android_layout_width, defaultWidth);
int height = a.getInteger(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));

LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(width, height);
lp.width = width;
lp.height = height;
lp.weight = a.getFloat(R.styleable.DroppyMenuItemTitle_android_layout_weight, defaultWeight);
lp.gravity = a.getInteger(R.styleable.DroppyMenuItemTitle_android_layout_gravity, defaultLayoutGravity);

setLayoutParams(lp);
setMinHeight(minWidth);
setMinHeight(minHeight);

setTextColor(color);
}
}
Loading

0 comments on commit 4ca01cd

Please sign in to comment.