Skip to content

Commit

Permalink
Merge pull request Yalantis#40 from Yalantis/feature/clickable_text
Browse files Browse the repository at this point in the history
Feature/clickable text
  • Loading branch information
PenzK committed May 25, 2016
2 parents 7da80d0 + 4ef794f commit 2d2d993
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 34 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
```
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apply plugin: 'com.android.application'

//apply from: '../mavenpush.gradle'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
buildToolsVersion "23.0.3"

defaultConfig {
applicationId "com.yalantis.contextmenu.sample"
Expand All @@ -19,5 +19,5 @@ android {
}

dependencies {
compile project(':lib')
compile 'com.yalantis:contextmenu:1.0.7'
}
3 changes: 3 additions & 0 deletions app/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
POM_NAME=ContextMenu
POM_ARTIFACT_ID=contextmenu
POM_PACKAGING=aar
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -154,7 +156,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
public void onBackPressed() {
if (mMenuDialogFragment != null && mMenuDialogFragment.isAdded()) {
mMenuDialogFragment.dismiss();
} else{
} else {
finish();
}
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.android.tools.build:gradle:2.1.0'
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply from: '../mavenpush.gradle'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
buildToolsVersion "23.0.3"

defaultConfig {
minSdkVersion 11
Expand All @@ -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'
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@ 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();
}

@Override
public void onLongClick(View v) {
if (mItemLongClickListener != null) {
mItemLongClickListener.onMenuItemLongClick(v, mWrapperButtons.indexOfChild(v));
mItemLongClickListener.onMenuItemLongClick(v, ((ViewGroup) v.getParent()).indexOfChild(v));
}
close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 7 additions & 3 deletions lib/src/main/java/com/yalantis/contextmenu/lib/MenuObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -130,6 +132,7 @@ public void setDrawable(Drawable mDrawable) {
mBitmap = null;
}

@StyleRes
public int getMenuTextAppearanceStyle() {
return mMenuTextAppearenseStyle;
}
Expand All @@ -138,15 +141,16 @@ 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;
}

@ColorRes
public int getDividerColor() {
return mDividerColor;
}

public void setDividerColor(int mDividerColor) {
public void setDividerColor(@ColorRes int mDividerColor) {
this.mDividerColor = mDividerColor;
}

Expand Down
28 changes: 20 additions & 8 deletions lib/src/main/java/com/yalantis/contextmenu/lib/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,22 +25,33 @@ 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.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getResources().getDimension(R.dimen.menu_text_size));
itemTextView.setOnClickListener(onCLick);
itemTextView.setOnLongClickListener(onLongClick);
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

itemTextView.setTextColor(ContextCompat.getColor(context, textColor));

int styleResId = menuItem.getMenuTextAppearanceStyle() > 0
? menuItem.getMenuTextAppearanceStyle()
: R.style.TextView_DefaultStyle);
: R.style.TextView_DefaultStyle;

if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) {
itemTextView.setTextAppearance(context, styleResId);
} else {
itemTextView.setTextAppearance(styleResId);
}

return itemTextView;
}

Expand Down Expand Up @@ -78,9 +90,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;
}

Expand Down
9 changes: 6 additions & 3 deletions lib/src/main/res/layout/fragment_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,26 @@
<RelativeLayout
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="wrap_content">

<LinearLayout
android:id="@+id/wrapper_buttons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentRight="true" />
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>

<LinearLayout
android:id="@+id/wrapper_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_toLeftOf="@+id/wrapper_buttons"
android:layout_toStartOf="@+id/wrapper_buttons"
android:layout_marginRight="@dimen/text_wrapper_right_margin"
android:gravity="right" />
android:layout_marginEnd="@dimen/text_wrapper_right_margin"
android:gravity="end" />

</RelativeLayout>
</ScrollView>

0 comments on commit 2d2d993

Please sign in to comment.