Skip to content

Commit bca324c

Browse files
authored
Merge pull request #86 from Yalantis/develop
Develop
2 parents b3dc07f + 3b1e0b7 commit bca324c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1479
-1514
lines changed

README.md

Lines changed: 100 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44

55
#### You can easily add awesome animated context menu to your app.
66

7-
Check this [project on dribbble] (https://dribbble.com/shots/1785274-Menu-Animation-for-Additional-Functions?list=users&offset=17)
7+
Check this [project on dribbble](https://dribbble.com/shots/1785274-Menu-Animation-for-Additional-Functions?list=users&offset=17)
88

9-
Check this [project on Behance] (https://www.behance.net/gallery/20411445/Mobile-Animations-Interactions)
9+
Check this [project on Behance](https://www.behance.net/gallery/20411445/Mobile-Animations-Interactions)
1010

11-
![ContextMenu](https://d13yacurqjgara.cloudfront.net/users/125056/screenshots/1785274/99miles-profile-light_1-1-4.gif)
11+
<image src="https://cdn.dribbble.com/users/125056/screenshots/1785274/99miles-profile-light_1-1-4.gif"/>
1212

1313
### Usage:
1414

1515
*For a working implementation, have a look at the ```app``` module*
1616

17-
#### 1. Clone repository and add sources into your project or use Gradle:
17+
#### 1. Clone repository and add sources into your project or use Gradle:
1818

1919
Add it in your root build.gradle at the end of repositories:
2020
```
@@ -28,118 +28,144 @@ Add it in your root build.gradle at the end of repositories:
2828
Add the dependency
2929
```
3030
dependencies {
31-
implementation 'com.github.Yalantis:Context-Menu.Android:1.0.8'
31+
implementation 'com.github.Yalantis:Context-Menu.Android:1.1.0'
3232
}
3333
```
3434
#### 2. Create list of `MenuObject`, which consists of icon or icon and description.
35-
You can use any `resource, bitmap, drawable, color` as image:
35+
You can use any `drawable, resource, bitmap, color` as image:
3636
```
37-
item.setResource(...)
38-
item.setBitmap(...)
39-
item.setDrawable(...)
40-
item.setColor(...)
37+
menuObject.drawable = ...
38+
menuObject.setResourceValue(...)
39+
menuObject.setBitmapValue(...)
40+
menuObject.setColorValue(...)
4141
```
42-
You can set image `ScaleType`:
42+
You can set image `ScaleType`:
4343
```
44-
item.setScaleType(ScaleType.FIT_XY)
44+
menuObject.scaleType = ScaleType.FIT_XY
4545
```
46-
You can use any `resource, drawable, color` as background:
46+
You can use any `resource, drawable, color` as background:
4747
```
48-
item.setBgResource(...)
49-
item.setBgDrawable(...)
50-
item.setBgColor(...)
48+
menuObject.setBgResourceValue(...)
49+
menuObject.setBgDrawable(...)
50+
menuObject.setBgColorValue(...)
5151
```
5252
Now You can easily add text appearance style for menu titles:
5353
```
5454
In your project styles create style for text appearance
5555
(For better visual effect extend it from TextView.DefaultStyle):
5656
57-
<style name="TextViewStyle" parent="TextView.DefaultStyle">
58-
<item name="android:textStyle">italic|bold</item>
59-
<item name="android:textColor">#26D0EB</item>
60-
</style>
57+
<style name="TextViewStyle" parent="TextView.DefaultStyle">
58+
<item name="android:textStyle">italic|bold</item>
59+
<item name="android:textColor">#26D0EB</item>
60+
</style>
6161
62-
And set it's id to your MenuObject :
62+
And set it's id to your MenuObject :
6363
64-
MenuObject addFr = new MenuObject("Add to friends");
65-
BitmapDrawable bd = new BitmapDrawable(getResources(),
66-
BitmapFactory.decodeResource(getResources(), R.drawable.icn_3));
67-
addFr.setDrawable(bd);
68-
addFr.setMenuTextAppearanceStyle(R.style.TextViewStyle);
69-
64+
val bitmapDrawable = BitmapDrawable(
65+
resources,
66+
BitmapFactory.decodeResource(resources, R.drawable.icn_3)
67+
)
68+
69+
val menuObject = MenuObject("Add to friends").apply {
70+
drawable = bitmapDrawable
71+
menuTextAppearanceStyle = R.style.TextViewStyle
72+
}
73+
```
74+
You can use any `color` as text color:
7075
```
71-
You can set any `color` as divider color:
76+
menuObject.textColor = ...
7277
```
73-
item.setDividerColor(...)
78+
You can set any `color` as divider color:
79+
```
80+
menuObject.dividerColor = ...
7481
```
7582
Example:
7683
```
77-
MenuObject close = new MenuObject();
78-
close.setResource(R.drawable.icn_close);
84+
val close = MenuObject().apply { setResourceValue(R.drawable.icn_close) }
7985
80-
MenuObject send = new MenuObject("Send message");
81-
send.setResource(R.drawable.icn_1);
86+
val send = MenuObject("Send message").apply { setResourceValue(R.drawable.icn_1) }
87+
88+
val addFriend = MenuObject("Add to friends").apply {
89+
drawable = BitmapDrawable(
90+
resources,
91+
BitmapFactory.decodeResource(resources, R.drawable.icn_3)
92+
)
93+
}
8294
83-
List<MenuObject> menuObjects = new ArrayList<>();
84-
menuObjects.add(close);
85-
menuObjects.add(send);
95+
val menuObjects = mutableListOf<MenuObject>().apply {
96+
add(close)
97+
add(send)
98+
add(addFriend)
99+
}
86100
```
87101

88102
#### 3. Create `newInstance` of `ContextMenuDialogFragment`, which received `MenuParams` object.
89103

90104
```
91-
MenuParams menuParams = new MenuParams();
92-
menuParams.setActionBarSize((int) getResources().getDimension(R.dimen.tool_bar_height));
93-
menuParams.setMenuObjects(getMenuObjects());
94-
menuParams.setClosableOutside(true);
95-
// set other settings to meet your needs
96-
mMenuDialogFragment = ContextMenuDialogFragment.newInstance(menuParams);
105+
val menuParams = MenuParams(
106+
actionBarSize = resources.getDimension(R.dimen.tool_bar_height).toInt(),
107+
menuObjects = getMenuObjects(),
108+
isClosableOutside = false
109+
// set other settings to meet your needs
110+
)
111+
112+
// If you want to change the side you need to add 'gravity' parameter,
113+
// by default it is MenuGravity.END.
114+
115+
// For example:
116+
117+
val menuParams = MenuParams(
118+
actionBarSize = resources.getDimension(R.dimen.tool_bar_height).toInt(),
119+
menuObjects = getMenuObjects(),
120+
isClosableOutside = false,
121+
gravity = MenuGravity.START
122+
)
123+
124+
val contextMenuDialogFragment = ContextMenuDialogFragment.newInstance(menuParams)
97125
```
98126

99127
#### 4. Set menu with button, which will open `ContextMenuDialogFragment`.
100128

101129
```
102-
@Override
103-
public boolean onCreateOptionsMenu(final Menu menu) {
104-
MenuInflater inflater = getMenuInflater();
105-
inflater.inflate(R.menu.menu_main, menu);
106-
return true;
130+
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
131+
menuInflater.inflate(R.menu.menu_main, menu)
132+
return true
107133
}
108134
109-
@Override
110-
public boolean onOptionsItemSelected(MenuItem item) {
111-
switch (item.getItemId()) {
112-
case R.id.context_menu:
113-
mMenuDialogFragment.show(fragmentManager, "ContextMenuDialogFragment");
114-
break;
135+
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
136+
item?.let {
137+
when (it.itemId) {
138+
R.id.context_menu -> {
139+
showContextMenuDialogFragment()
140+
}
141+
}
115142
}
116-
return super.onOptionsItemSelected(item);
143+
144+
return super.onOptionsItemSelected(item)
117145
}
118146
```
119147

120-
#### 5. Implement `OnMenuItemClickListener` interface with `onMenuItemClick` method.
121-
122-
```
123-
public class MainActivity extends ActionBarActivity implements OnMenuItemClickListener
124-
125-
@Override
126-
public void onMenuItemClick(View clickedView, int position) {
127-
//Do something here
148+
#### 5. Add menu item listeners.
149+
```
150+
contextMenuDialogFragment = menuItemClickListener = { view, position ->
151+
// do something here
152+
}
153+
154+
contextMenuDialogFragment = menuItemLongClickListener = { view, position ->
155+
// do something here
128156
}
129-
130-
mMenuDialogFragment.setItemClickListener(this);
131157
```
132158

133159
## Customization:
134160
For better experience menu item size should be equal to `ActionBar` height.
135161

136162
`newInstance` of `ContextMenuDialogFragment` receives `MenuParams` object that has the fields:
137163

138-
`mMenuObjects` - list of MenuObject objects,
164+
`menuObjects` - list of MenuObject objects,
139165

140-
`mAnimationDelay` - delay in millis after fragment opening and before closing, which will make animation smoother on slow devices,
166+
`animationDelay` - delay in millis after fragment opening and before closing, which will make animation smoother on slow devices,
141167

142-
`nAnimationDuration` - duration of every piece of animation in millis,
168+
`animationDuration` - duration of every piece of animation in millis,
143169

144170
`isClosableOutside` - if menu can be closed on touch to non-button area,
145171

@@ -155,10 +181,16 @@ To stay `Context Menu` below Status Bar set `fitSystemWindows` to true and `clip
155181

156182
## Compatibility
157183

158-
* Android Honeycomb 3.0+
184+
* Android KitKat 4.4+
159185

160186
# Changelog
161187

188+
### Version: 1.1.0
189+
190+
* library rewrited on Kotlin
191+
* added `rtl` support
192+
* added `gravity` parameter for `MenuParams`
193+
162194
### Version: 1.0.8
163195

164196
* added transparent menu background support

app/build.gradle

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
apply plugin: 'com.android.application'
2+
apply plugin: 'kotlin-android'
3+
apply plugin: 'kotlin-android-extensions'
24

35
android {
4-
compileSdkVersion 27
5-
buildToolsVersion "27.0.3"
6+
compileSdkVersion 28
67

78
defaultConfig {
89
applicationId "com.yalantis.contextmenu.sample"
9-
minSdkVersion 14
10-
targetSdkVersion 27
10+
minSdkVersion 19
11+
targetSdkVersion 28
1112
versionCode Integer.parseInt(project.VERSION_CODE)
1213
versionName VERSION_NAME
14+
vectorDrawables.useSupportLibrary = true
1315
}
1416

1517
compileOptions {
@@ -20,5 +22,9 @@ android {
2022

2123
dependencies {
2224
implementation project(':lib')
23-
implementation 'com.android.support:appcompat-v7:27.1.1'
24-
}
25+
26+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
27+
28+
implementation 'com.android.support:appcompat-v7:28.0.0'
29+
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
30+
}

app/src/main/AndroidManifest.xml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="com.yalantis.contextmenu" >
3+
xmlns:tools="http://schemas.android.com/tools"
4+
package="com.yalantis.contextmenu">
45

56
<application
67
android:allowBackup="true"
78
android:icon="@drawable/ic_launcher"
89
android:label="@string/app_name"
9-
android:theme="@style/AppTheme" >
10+
android:supportsRtl="true"
11+
android:theme="@style/AppTheme"
12+
tools:ignore="GoogleAppIndexingWarning">
13+
1014
<activity
11-
android:name="com.yalantis.contextmenu.sample.MainActivity"
15+
android:name=".sample.SampleActivity"
1216
android:label="@string/app_name"
1317
android:screenOrientation="portrait">
1418
<intent-filter>
1519
<action android:name="android.intent.action.MAIN" />
16-
1720
<category android:name="android.intent.category.LAUNCHER" />
1821
</intent-filter>
1922
</activity>
23+
2024
</application>
2125

22-
</manifest>
26+
</manifest>

0 commit comments

Comments
 (0)