Skip to content

Commit

Permalink
- Fixing already attached to parent issue
Browse files Browse the repository at this point in the history
- Adding more example for different layouts
- Renaming all view class to avoid confusion when creating the menu programmatically
- Fixing the min. required SDK
  • Loading branch information
shehabic committed Mar 22, 2015
1 parent 05adadb commit c7bf0fe
Show file tree
Hide file tree
Showing 37 changed files with 1,149 additions and 113 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,23 @@ Why not the native PopupMenu?
=============================
Well if you have struggled long enough trying to show an icon beside the text in the normal popup menu or wanted to created a simple popup with custom view yest still contextual to an exisitng view, you would've know that it was almost impossible to do with the normal popup menu unless you use reflection and hack a the internal properties for PopupMenu and yet just add extra icon but not a fully customized view.

Reporting Bug / Opening Issues
==============================
1-Please first make sure the issue you're reporting doesn't already exists to avoid duplicates.
2-Please make sure you specify enough info if possible, including Target and Minimum SDK used, and portion of the code in addition to the stack trace/error message in case of errors.

Forks / Pull Request
====================
As per the license you're free to fork the lib, and modify as you
Pull-request for enhancements and bug-fixes ar always welcomed

Developed By
============

* Mohamed Shehab - <[email protected]>


License
=======

Copyright 2015 Mohamed Shehab

Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ android {
buildToolsVersion "21.1.2"

defaultConfig {
minSdkVersion 14
minSdkVersion 13
targetSdkVersion 21
versionCode 3
versionName "0.2.1"
Expand All @@ -21,7 +21,7 @@ android {
ext {
PUBLISH_GROUP_ID = 'com.shehabic.droppy'
PUBLISH_ARTIFACT_ID = 'Droppy'
PUBLISH_VERSION = '0.2.1'
PUBLISH_VERSION = '0.2.5'
}


Expand Down
3 changes: 0 additions & 3 deletions library/library.iml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/docs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
Expand All @@ -82,9 +81,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/libs" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/poms" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
/**
* Created by shehabic on 3/1/15.
*/
public class DroppyMenuCustomView extends DroppyMenuItemAbstract {
public class DroppyMenuCustomItem extends DroppyMenuItemAbstract {

public DroppyMenuCustomView(int customResourceId){
public DroppyMenuCustomItem(int customResourceId){
isClickable = false;
type = TYPE_CUSTOM;
customViewResourceId = customResourceId;
}

public DroppyMenuCustomView(View customView){
public DroppyMenuCustomItem(View customView){
isClickable = false;
type = TYPE_CUSTOM;
renderedView = customView;
Expand Down
16 changes: 7 additions & 9 deletions library/src/main/java/com/shehabic/droppy/DroppyMenuItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

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

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

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

void initMenuItem(String title, int iconResourceId)
{
Expand Down Expand Up @@ -44,18 +42,18 @@ public void setIcon(Drawable iconDrawable)
@Override
public View render(Context context) {

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

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

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

Expand Down
26 changes: 17 additions & 9 deletions library/src/main/java/com/shehabic/droppy/DroppyMenuPopup.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import android.view.WindowManager;
import android.widget.FrameLayout;

import com.shehabic.droppy.views.DroppyMenuContainer;
import com.shehabic.droppy.views.DroppyMenuContainerView;

import java.lang.reflect.Constructor;
import java.util.ArrayList;
Expand All @@ -27,8 +27,8 @@ public class DroppyMenuPopup {
protected View anchor;
protected List<DroppyMenuItemInterface> menuItems = new ArrayList<DroppyMenuItemInterface>();
protected View mContentView;
protected com.shehabic.droppy.views.DroppyMenuPopup mPopupView;
protected DroppyMenuContainer droppyMenuContainer;
protected com.shehabic.droppy.views.DroppyMenuPopupView mPopupView;
protected DroppyMenuContainerView droppyMenuContainer;
protected DroppyClickCallbackInterface droppyClickCallbackInterface;
protected int popupMenuLayoutResourceId;
protected FrameLayout modalWindow;
Expand Down Expand Up @@ -100,22 +100,30 @@ public void show() {
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
adjustDropDownPosition(lp, -20, 30);
mContentView = new PopupViewContainer(mContext);
detachPopupView();
((ViewGroup) mContentView).addView(mPopupView);
mContentView.setFocusable(true);
mContentView.setClickable(true);
getActivity().getWindow().addContentView(mContentView, lp);
mContentView.requestFocus();
}

protected void detachPopupView()
{
if (mPopupView.getParent() != null) {
try {
((ViewGroup) mPopupView.getParent()).removeView(mPopupView);
} catch (Exception e) {

}
}
}

public void dismiss() {
((ViewGroup) mContentView.getParent()).removeView(mContentView);
((ViewGroup) modalWindow.getParent()).removeView(modalWindow);
}

public void notifyChange() {
render(true);
}

protected void render() {
render(false);
}
Expand All @@ -125,8 +133,8 @@ protected void render(boolean forceRender) {
if (mPopupView != null && ((ViewGroup) mPopupView).getChildCount() > 0) {
((ViewGroup) mPopupView).removeAllViews();
}
mPopupView = new com.shehabic.droppy.views.DroppyMenuPopup(mContext);
droppyMenuContainer = new DroppyMenuContainer(mContext);
mPopupView = new com.shehabic.droppy.views.DroppyMenuPopupView(mContext);
droppyMenuContainer = new DroppyMenuContainerView(mContext);
mPopupView.addView(droppyMenuContainer);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
mPopupView.setLayoutParams(lp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public DroppyMenuSeparator() {
@Override
public View render(Context context) {
if (renderedView == null) {
renderedView = new com.shehabic.droppy.views.DroppyMenuSeparator(context);
renderedView = new com.shehabic.droppy.views.DroppyMenuSeparatorView(context);
}

return renderedView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@
/**
* Created by shehabic on 3/6/15.
*/
public class DroppyMenuContainer extends LinearLayout
public class DroppyMenuContainerView extends LinearLayout
{
public DroppyMenuContainer(Context context) {
public DroppyMenuContainerView(Context context) {
this(context, null);
}

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

public DroppyMenuContainer(Context context, AttributeSet attrs, int defStyleAttr) {
public DroppyMenuContainerView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.setOrientation(VERTICAL);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DroppyMenuPopup, defStyleAttr, 0);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DroppyMenuPopupView, defStyleAttr, 0);
ViewGroup.LayoutParams lp = getLayoutParams();
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);
int height = a.getLayoutDimension(R.styleable.DroppyMenuContainerView_android_layout_height, ViewGroup.LayoutParams.WRAP_CONTENT);
int width = a.getLayoutDimension(R.styleable.DroppyMenuContainerView_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 @@ -13,17 +13,17 @@
/**
* Created by shehabic on 3/7/15.
*/
public class DroppyMenuItemIcon extends ImageView {
public class DroppyMenuItemIconView extends ImageView {

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

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

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

final int defaultMaxWidth = (int) getResources().getDimension(R.dimen.default_menu_item_icon_maxWidth);
Expand All @@ -33,19 +33,19 @@ public DroppyMenuItemIcon(Context context, AttributeSet attrs, int defStyleAttr)
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 = 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);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DroppyMenuItemIconView, defStyleAttr, 0);
int maxWidth = (int) a.getDimension(R.styleable.DroppyMenuItemIconView_android_maxWidth, defaultMaxWidth);
int maxHeight = (int) a.getDimension(R.styleable.DroppyMenuItemIconView_android_maxHeight, defaultMaxHeight);
int width = a.getLayoutDimension(R.styleable.DroppyMenuItemIconView_android_layout_width, ViewGroup.LayoutParams.WRAP_CONTENT);
int height = a.getLayoutDimension(R.styleable.DroppyMenuItemIconView_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.rightMargin = a.getDimensionPixelSize(R.styleable.DroppyMenuItemIconView_android_layout_marginRight, defaultMarginRight);
lp.leftMargin = a.getDimensionPixelSize(R.styleable.DroppyMenuItemIconView_android_layout_marginLeft, defaultMarginLeft);
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);
lp.weight = a.getFloat(R.styleable.DroppyMenuItemIconView_android_layout_weight, defaultWeight);
lp.gravity = a.getInteger(R.styleable.DroppyMenuItemIconView_android_layout_gravity, defaultLayoutGravity);

setMaxHeight(maxWidth);
setMaxHeight(maxHeight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
/**
* Created by shehabic on 3/7/15.
*/
public class DroppyMenuItemTitle extends TextView {
public class DroppyMenuItemTitleView extends TextView {

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

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

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

final int defaultWidth = ViewGroup.LayoutParams.MATCH_PARENT;
Expand All @@ -34,20 +34,20 @@ public DroppyMenuItemTitle(Context context, AttributeSet attrs, int defStyleAttr
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.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);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DroppyMenuItemTitleView, defStyleAttr, 0);
int minWidth = (int) a.getDimension(R.styleable.DroppyMenuItemTitleView_android_minWidth, defaultMinWidth);
int minHeight = (int) a.getDimension(R.styleable.DroppyMenuItemTitleView_android_minHeight, defaultMinHeight);
int width = a.getLayoutDimension(R.styleable.DroppyMenuItemTitleView_android_layout_width, defaultWidth);
int height = a.getLayoutDimension(R.styleable.DroppyMenuItemTitleView_android_layout_height, ViewGroup.LayoutParams.WRAP_CONTENT);
int color = a.getColor(R.styleable.DroppyMenuItemTitleView_android_textColor, defaultColor);

setGravity(a.getInt(R.styleable.DroppyMenuItemTitle_android_gravity, defaultGravity));
setGravity(a.getInt(R.styleable.DroppyMenuItemTitleView_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);
lp.weight = a.getFloat(R.styleable.DroppyMenuItemTitleView_android_layout_weight, defaultWeight);
lp.gravity = a.getInteger(R.styleable.DroppyMenuItemTitleView_android_layout_gravity, defaultLayoutGravity);

setLayoutParams(lp);
setMinHeight(minWidth);
Expand Down
Loading

0 comments on commit c7bf0fe

Please sign in to comment.