From 21aaafc2506bff7067e8b47f2f06b962e5b78f4f Mon Sep 17 00:00:00 2001 From: "kirill.penzykov" Date: Tue, 24 May 2016 10:28:19 +0300 Subject: [PATCH 1/6] done with clickable text --- app/build.gradle | 2 +- .../contextmenu/sample/MainActivity.java | 8 +++--- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 +-- .../lib/ContextMenuDialogFragment.java | 4 +-- .../yalantis/contextmenu/lib/MenuAdapter.java | 6 +++-- .../yalantis/contextmenu/lib/MenuObject.java | 8 ++++-- .../com/yalantis/contextmenu/lib/Utils.java | 27 +++++++++++++------ lib/src/main/res/layout/fragment_menu.xml | 9 ++++--- 9 files changed, 46 insertions(+), 24 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index cdf1964..47011ac 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -19,5 +19,5 @@ android { } dependencies { - compile project(':lib') + compile project(":lib") } diff --git a/app/src/main/java/com/yalantis/contextmenu/sample/MainActivity.java b/app/src/main/java/com/yalantis/contextmenu/sample/MainActivity.java index 027b83c..ca9ec5e 100644 --- a/app/src/main/java/com/yalantis/contextmenu/sample/MainActivity.java +++ b/app/src/main/java/com/yalantis/contextmenu/sample/MainActivity.java @@ -104,9 +104,11 @@ private void initToolbar() { Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar); TextView mToolBarTextView = (TextView) findViewById(R.id.text_view_toolbar_title); setSupportActionBar(mToolbar); - getSupportActionBar().setHomeButtonEnabled(true); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - getSupportActionBar().setDisplayShowTitleEnabled(false); + if(getSupportActionBar()!=null) { + getSupportActionBar().setHomeButtonEnabled(true); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowTitleEnabled(false); + } mToolbar.setNavigationIcon(R.drawable.btn_back); mToolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override diff --git a/build.gradle b/build.gradle index 5ee8e61..521c96b 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:1.5.0' + classpath 'com.android.tools.build:gradle:2.1.0' } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0c71e76..cca8df7 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Apr 10 15:27:10 PDT 2013 +#Mon May 23 17:09:44 EEST 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip diff --git a/lib/src/main/java/com/yalantis/contextmenu/lib/ContextMenuDialogFragment.java b/lib/src/main/java/com/yalantis/contextmenu/lib/ContextMenuDialogFragment.java index dc1ed80..9ae0daa 100644 --- a/lib/src/main/java/com/yalantis/contextmenu/lib/ContextMenuDialogFragment.java +++ b/lib/src/main/java/com/yalantis/contextmenu/lib/ContextMenuDialogFragment.java @@ -156,7 +156,7 @@ public void setItemClickListener(OnMenuItemClickListener itemClickListener) { @Override public void onClick(View v) { if (mItemClickListener != null) { - mItemClickListener.onMenuItemClick(v, mWrapperButtons.indexOfChild(v)); + mItemClickListener.onMenuItemClick(v, ((ViewGroup)v.getParent()).indexOfChild(v)); } close(); } @@ -164,7 +164,7 @@ public void onClick(View v) { @Override public void onLongClick(View v) { if (mItemLongClickListener != null) { - mItemLongClickListener.onMenuItemLongClick(v, mWrapperButtons.indexOfChild(v)); + mItemLongClickListener.onMenuItemLongClick(v, ((ViewGroup)v.getParent()).indexOfChild(v)); } close(); } diff --git a/lib/src/main/java/com/yalantis/contextmenu/lib/MenuAdapter.java b/lib/src/main/java/com/yalantis/contextmenu/lib/MenuAdapter.java index 3740293..646e2c8 100644 --- a/lib/src/main/java/com/yalantis/contextmenu/lib/MenuAdapter.java +++ b/lib/src/main/java/com/yalantis/contextmenu/lib/MenuAdapter.java @@ -2,6 +2,7 @@ import android.content.Context; import android.view.View; +import android.view.ViewGroup; import android.widget.LinearLayout; import com.nineoldandroids.animation.Animator; @@ -69,7 +70,8 @@ public int getItemCount() { private void setViews() { for (int i = 0; i < mMenuObjects.size(); i++) { MenuObject menuObject = mMenuObjects.get(i); - mTextWrapper.addView(Utils.getItemTextView(mContext, menuObject, mMenuItemSize)); + mTextWrapper.addView(Utils.getItemTextView(mContext, menuObject, mMenuItemSize, + clickItem, longClickItem)); mMenuWrapper.addView(Utils.getImageWrapper(mContext, menuObject, mMenuItemSize, clickItem, longClickItem, i != mMenuObjects.size() - 1)); } @@ -198,7 +200,7 @@ public boolean onLongClick(View v) { private void viewClicked(View v) { if (mIsMenuOpen && !mIsAnimationRun) { mClickedView = v; - int childIndex = mMenuWrapper.indexOfChild(v); + int childIndex = ((ViewGroup)v.getParent()).indexOfChild(v); if (childIndex == -1) { return; } diff --git a/lib/src/main/java/com/yalantis/contextmenu/lib/MenuObject.java b/lib/src/main/java/com/yalantis/contextmenu/lib/MenuObject.java index e949bac..609617c 100644 --- a/lib/src/main/java/com/yalantis/contextmenu/lib/MenuObject.java +++ b/lib/src/main/java/com/yalantis/contextmenu/lib/MenuObject.java @@ -5,6 +5,8 @@ import android.graphics.drawable.Drawable; import android.os.Parcel; import android.os.Parcelable; +import android.support.annotation.ColorRes; +import android.support.annotation.StyleRes; import android.widget.ImageView; public class MenuObject implements Parcelable { @@ -82,7 +84,7 @@ public int getTextColor() { * Use {@link #setMenuTextAppearanceStyle(int)} to set all text style params at one place */ @Deprecated - public void setTextColor(int mTextColor) { + public void setTextColor(@ColorRes int mTextColor) { this.mTextColor = mTextColor; } @@ -130,6 +132,7 @@ public void setDrawable(Drawable mDrawable) { mBitmap = null; } + @StyleRes public int getMenuTextAppearanceStyle() { return mMenuTextAppearenseStyle; } @@ -142,11 +145,12 @@ public void setMenuTextAppearanceStyle(int mMenuTextAppearanceStyle) { this.mMenuTextAppearenseStyle = mMenuTextAppearanceStyle; } + @ColorRes public int getDividerColor() { return mDividerColor; } - public void setDividerColor(int mDividerColor) { + public void setDividerColor(@ColorRes int mDividerColor) { this.mDividerColor = mDividerColor; } diff --git a/lib/src/main/java/com/yalantis/contextmenu/lib/Utils.java b/lib/src/main/java/com/yalantis/contextmenu/lib/Utils.java index 238c194..3188684 100644 --- a/lib/src/main/java/com/yalantis/contextmenu/lib/Utils.java +++ b/lib/src/main/java/com/yalantis/contextmenu/lib/Utils.java @@ -5,6 +5,7 @@ import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; +import android.support.v4.content.ContextCompat; import android.view.Gravity; import android.view.View; import android.view.ViewGroup; @@ -24,22 +25,32 @@ public static int getDefaultActionBarSize(Context context) { return actionBarSize; } - public static TextView getItemTextView(Context context, MenuObject menuItem, int menuItemSize) { + public static TextView getItemTextView(Context context, MenuObject menuItem, int menuItemSize, + View.OnClickListener onCLick, View.OnLongClickListener onLongClick) { TextView itemTextView = new TextView(context); RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, menuItemSize); itemTextView.setLayoutParams(textLayoutParams); + itemTextView.setOnClickListener(onCLick); + itemTextView.setOnLongClickListener(onLongClick); // itemTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getResources().getDimension(R.dimen.menu_text_size)); itemTextView.setText(menuItem.getTitle()); itemTextView.setPadding(0, 0, (int) context.getResources().getDimension(R.dimen.text_right_padding), 0); itemTextView.setGravity(Gravity.CENTER_VERTICAL); int textColor = menuItem.getTextColor() == 0 ? - context.getResources().getColor(android.R.color.white) : + android.R.color.white : menuItem.getTextColor(); - itemTextView.setTextColor(textColor); - itemTextView.setTextAppearance(context, menuItem.getMenuTextAppearanceStyle() > 0 - ? menuItem.getMenuTextAppearanceStyle() - : R.style.TextView_DefaultStyle); + + itemTextView.setTextColor(ContextCompat.getColor(context, textColor)); + if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) { + itemTextView.setTextAppearance(context, menuItem.getMenuTextAppearanceStyle() > 0 + ? menuItem.getMenuTextAppearanceStyle() + : R.style.TextView_DefaultStyle); + } else { + itemTextView.setTextAppearance(menuItem.getMenuTextAppearanceStyle() > 0 + ? menuItem.getMenuTextAppearanceStyle() + : R.style.TextView_DefaultStyle); + } return itemTextView; } @@ -78,9 +89,9 @@ public static View getDivider(Context context, MenuObject menuItem) { dividerView.setLayoutParams(viewLayoutParams); dividerView.setClickable(true); int dividerColor = menuItem.getDividerColor() == Integer.MAX_VALUE ? - context.getResources().getColor(R.color.divider_color) : + R.color.divider_color : menuItem.getDividerColor(); - dividerView.setBackgroundColor(dividerColor); + dividerView.setBackgroundColor(ContextCompat.getColor(context, dividerColor)); return dividerView; } diff --git a/lib/src/main/res/layout/fragment_menu.xml b/lib/src/main/res/layout/fragment_menu.xml index 8a0a3f8..a51427a 100644 --- a/lib/src/main/res/layout/fragment_menu.xml +++ b/lib/src/main/res/layout/fragment_menu.xml @@ -7,14 +7,15 @@ + android:layout_height="wrap_content"> + android:layout_alignParentRight="true" + android:layout_alignParentEnd="true"/> + android:layout_marginEnd="@dimen/text_wrapper_right_margin" + android:gravity="end" /> \ No newline at end of file From caadfaecec1fbf07776553bc130bc0441f4039e2 Mon Sep 17 00:00:00 2001 From: "kirill.penzykov" Date: Tue, 24 May 2016 10:35:54 +0300 Subject: [PATCH 2/6] update gradle, small additions --- app/build.gradle | 4 ++-- .../main/java/com/yalantis/contextmenu/lib/MenuObject.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 47011ac..fb2bd98 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.android.application' android { compileSdkVersion 23 - buildToolsVersion "23.0.2" + buildToolsVersion "23.0.3" defaultConfig { applicationId "com.yalantis.contextmenu.sample" @@ -19,5 +19,5 @@ android { } dependencies { - compile project(":lib") + compile project(':lib') } diff --git a/lib/src/main/java/com/yalantis/contextmenu/lib/MenuObject.java b/lib/src/main/java/com/yalantis/contextmenu/lib/MenuObject.java index 609617c..1cafe38 100644 --- a/lib/src/main/java/com/yalantis/contextmenu/lib/MenuObject.java +++ b/lib/src/main/java/com/yalantis/contextmenu/lib/MenuObject.java @@ -141,7 +141,7 @@ public int getMenuTextAppearanceStyle() { * Set style resource id, it will be used for setting text appearance of menu item title. * For better effect your style should extend TextView.DefaultStyle */ - public void setMenuTextAppearanceStyle(int mMenuTextAppearanceStyle) { + public void setMenuTextAppearanceStyle(@StyleRes int mMenuTextAppearanceStyle) { this.mMenuTextAppearenseStyle = mMenuTextAppearanceStyle; } From 6a939ac265e2232d34edf4d3f044bf37560af8b1 Mon Sep 17 00:00:00 2001 From: "kirill.penzykov" Date: Tue, 24 May 2016 12:10:28 +0300 Subject: [PATCH 3/6] update libs --- lib/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/build.gradle b/lib/build.gradle index 694011a..8ba1f69 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -3,7 +3,7 @@ apply from: '../mavenpush.gradle' android { compileSdkVersion 23 - buildToolsVersion "23.0.2" + buildToolsVersion "23.0.3" defaultConfig { minSdkVersion 11 @@ -20,6 +20,6 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:appcompat-v7:23.1.1' + compile 'com.android.support:appcompat-v7:23.4.0' compile 'com.nineoldandroids:library:2.4.0' } From cb19a9f3e13b6c17285e9e54bddca8959d4d6f0e Mon Sep 17 00:00:00 2001 From: "kirill.penzykov" Date: Tue, 24 May 2016 16:14:48 +0300 Subject: [PATCH 4/6] merge request changes --- .../yalantis/contextmenu/sample/MainActivity.java | 6 +++--- .../lib/ContextMenuDialogFragment.java | 4 ++-- .../com/yalantis/contextmenu/lib/MenuAdapter.java | 2 +- .../java/com/yalantis/contextmenu/lib/Utils.java | 15 ++++++++------- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/yalantis/contextmenu/sample/MainActivity.java b/app/src/main/java/com/yalantis/contextmenu/sample/MainActivity.java index ca9ec5e..a9be1cc 100644 --- a/app/src/main/java/com/yalantis/contextmenu/sample/MainActivity.java +++ b/app/src/main/java/com/yalantis/contextmenu/sample/MainActivity.java @@ -26,7 +26,7 @@ import java.util.ArrayList; import java.util.List; -public class MainActivity extends AppCompatActivity implements OnMenuItemClickListener, OnMenuItemLongClickListener{ +public class MainActivity extends AppCompatActivity implements OnMenuItemClickListener, OnMenuItemLongClickListener { private FragmentManager fragmentManager; private ContextMenuDialogFragment mMenuDialogFragment; @@ -104,7 +104,7 @@ private void initToolbar() { Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar); TextView mToolBarTextView = (TextView) findViewById(R.id.text_view_toolbar_title); setSupportActionBar(mToolbar); - if(getSupportActionBar()!=null) { + if (getSupportActionBar() != null) { getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowTitleEnabled(false); @@ -156,7 +156,7 @@ public boolean onOptionsItemSelected(MenuItem item) { public void onBackPressed() { if (mMenuDialogFragment != null && mMenuDialogFragment.isAdded()) { mMenuDialogFragment.dismiss(); - } else{ + } else { finish(); } } diff --git a/lib/src/main/java/com/yalantis/contextmenu/lib/ContextMenuDialogFragment.java b/lib/src/main/java/com/yalantis/contextmenu/lib/ContextMenuDialogFragment.java index 9ae0daa..80bface 100644 --- a/lib/src/main/java/com/yalantis/contextmenu/lib/ContextMenuDialogFragment.java +++ b/lib/src/main/java/com/yalantis/contextmenu/lib/ContextMenuDialogFragment.java @@ -156,7 +156,7 @@ public void setItemClickListener(OnMenuItemClickListener itemClickListener) { @Override public void onClick(View v) { if (mItemClickListener != null) { - mItemClickListener.onMenuItemClick(v, ((ViewGroup)v.getParent()).indexOfChild(v)); + mItemClickListener.onMenuItemClick(v, ((ViewGroup) v.getParent()).indexOfChild(v)); } close(); } @@ -164,7 +164,7 @@ public void onClick(View v) { @Override public void onLongClick(View v) { if (mItemLongClickListener != null) { - mItemLongClickListener.onMenuItemLongClick(v, ((ViewGroup)v.getParent()).indexOfChild(v)); + mItemLongClickListener.onMenuItemLongClick(v, ((ViewGroup) v.getParent()).indexOfChild(v)); } close(); } diff --git a/lib/src/main/java/com/yalantis/contextmenu/lib/MenuAdapter.java b/lib/src/main/java/com/yalantis/contextmenu/lib/MenuAdapter.java index 646e2c8..aecab91 100644 --- a/lib/src/main/java/com/yalantis/contextmenu/lib/MenuAdapter.java +++ b/lib/src/main/java/com/yalantis/contextmenu/lib/MenuAdapter.java @@ -200,7 +200,7 @@ public boolean onLongClick(View v) { private void viewClicked(View v) { if (mIsMenuOpen && !mIsAnimationRun) { mClickedView = v; - int childIndex = ((ViewGroup)v.getParent()).indexOfChild(v); + int childIndex = ((ViewGroup) v.getParent()).indexOfChild(v); if (childIndex == -1) { return; } diff --git a/lib/src/main/java/com/yalantis/contextmenu/lib/Utils.java b/lib/src/main/java/com/yalantis/contextmenu/lib/Utils.java index 3188684..d7f8cb3 100644 --- a/lib/src/main/java/com/yalantis/contextmenu/lib/Utils.java +++ b/lib/src/main/java/com/yalantis/contextmenu/lib/Utils.java @@ -33,7 +33,6 @@ public static TextView getItemTextView(Context context, MenuObject menuItem, int itemTextView.setLayoutParams(textLayoutParams); itemTextView.setOnClickListener(onCLick); itemTextView.setOnLongClickListener(onLongClick); -// itemTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getResources().getDimension(R.dimen.menu_text_size)); itemTextView.setText(menuItem.getTitle()); itemTextView.setPadding(0, 0, (int) context.getResources().getDimension(R.dimen.text_right_padding), 0); itemTextView.setGravity(Gravity.CENTER_VERTICAL); @@ -42,15 +41,17 @@ public static TextView getItemTextView(Context context, MenuObject menuItem, int menuItem.getTextColor(); itemTextView.setTextColor(ContextCompat.getColor(context, textColor)); + + int styleResId = menuItem.getMenuTextAppearanceStyle() > 0 + ? menuItem.getMenuTextAppearanceStyle() + : R.style.TextView_DefaultStyle; + if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) { - itemTextView.setTextAppearance(context, menuItem.getMenuTextAppearanceStyle() > 0 - ? menuItem.getMenuTextAppearanceStyle() - : R.style.TextView_DefaultStyle); + itemTextView.setTextAppearance(context, styleResId); } else { - itemTextView.setTextAppearance(menuItem.getMenuTextAppearanceStyle() > 0 - ? menuItem.getMenuTextAppearanceStyle() - : R.style.TextView_DefaultStyle); + itemTextView.setTextAppearance(styleResId); } + return itemTextView; } From e546129d9f9758afa82215f539e0b88f0bf6f6f4 Mon Sep 17 00:00:00 2001 From: "kirill.penzykov" Date: Wed, 25 May 2016 09:56:36 +0300 Subject: [PATCH 5/6] update gradle --- app/build.gradle | 4 ++-- app/gradle.properties | 3 +++ gradle.properties | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 app/gradle.properties diff --git a/app/build.gradle b/app/build.gradle index fb2bd98..97a75db 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,5 @@ apply plugin: 'com.android.application' - +//apply from: '../mavenpush.gradle' android { compileSdkVersion 23 buildToolsVersion "23.0.3" @@ -19,5 +19,5 @@ android { } dependencies { - compile project(':lib') + compile 'com.yalantis:contextmenu:1.0.7' } diff --git a/app/gradle.properties b/app/gradle.properties new file mode 100644 index 0000000..709085f --- /dev/null +++ b/app/gradle.properties @@ -0,0 +1,3 @@ +POM_NAME=ContextMenu +POM_ARTIFACT_ID=contextmenu +POM_PACKAGING=aar \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 4d157fa..79ea59a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,8 +17,8 @@ # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true -VERSION_NAME=1.0.6 -VERSION_CODE=7 +VERSION_NAME=1.0.7 +VERSION_CODE=8 GROUP=com.yalantis POM_DESCRIPTION=Android Library to display awesome context menu From 4ef794f1534bca1674b4b493f162f25a22d25804 Mon Sep 17 00:00:00 2001 From: "kirill.penzykov" Date: Wed, 25 May 2016 10:00:38 +0300 Subject: [PATCH 6/6] readme --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 313cdf8..841877c 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Check this [project on Behance] (https://www.behance.net/gallery/20411445/Mobile *For a working implementation, have a look at the ```app``` module* #### 1. Clone repository and add sources into your project or use Gradle: -``` compile 'com.yalantis:contextmenu:1.0.6' ``` +``` compile 'com.yalantis:contextmenu:1.0.7' ``` #### 2. Create list of `MenuObject`, which consists of icon or icon and description. You can use any `resource, bitmap, drawable, color` as image: ``` @@ -144,6 +144,11 @@ To stay `Context Menu` below Status Bar set `fitSystemWindows` to true and `clip # Changelog +### Version: 1.0.7 + + * Text in menu now also clickable + * Support libs and gradle updated + ### Version: 1.0.6 * com.android.tools.build:gradle:1.5.0