Git Product home page Git Product logo

circlemenu's Introduction

CircleMenu

Android Arsenal

CircleMenu 是一个精美别致支持定制的圆形菜单,可以有 0 到 8 个子菜单按钮,按钮背景色,图标都可以修改。CircleMenu 比较适合放在屏幕中间,以得到完好的展现。

小记:

CircleMenu 是在 dribbble 上看到的一个比较有感觉的设计,并不炫酷,但是 UI 很精致,值得推敲的细节比较多。因为没有比较标准的原型图。在还原设计的时候,来来回回修改好多次。到最后也不知道跟原设计有多少差距。不过自己看着还算满意。

该库在实现的时候碰到了许多困难。比如选中子菜单项绘制圆环轨迹路径的时候,使用 PathMeasure 发现 getSegment 方法并不是可以截取任何两个位置之间的 Path(因为要从选中的子菜单按钮的位置开始绘制圆环轨迹路径),思考良久后,使用旋转画布的方法巧妙解决。

又例如,在圆环绘制完成后,圆环会逐渐放大扩散变透明,然后消失的动画。如果这个动画针对的是一个 View 对象,我想使用 ObjectAnimator 可以很快解决。但是现在是在 onDraw 中绘制这一动画效果。最困难的是绘制圆环扩散变透明直至消失这一动画效果。(ps:期间还问过我 QQ 中所有技术群。都说很简单,就是没人说具体,群中绝大部分都是各种灌水,到最后也得不到答案。那时候的感觉很糟糕,感觉再也不相信技术群了,伤心···)最后实现很简单,也是无意中发现 ColorUtils 这个类, ColorUtils 是 Support.v4 中提供的,封装了对 Color 的各种操作。我使用了 ColorUtils.setAlphaComponent(color, alpha) 来操作圆环的颜色的透明度,从而达到一个圆环逐渐消失的效果。

最后谢谢 AigeGcsSloop 两位大神无私奉献。让我能深入学习自定义 View 范畴的知识。让我有能力去完成这个项目。

Preview

Import

Gradle

Step 1. Add the JitPack repository to your build file

allprojects {
	repositories {
		...
		maven { url "https://jitpack.io" }
	}
}

Step 2. Add the dependency

dependencies {
        compile 'com.github.Hitomis:CircleMenu:v1.1.0'
}

Maven

Step 1. Add the JitPack repository to your build file

<repositories>
	<repository>
	    <id>jitpack.io</id>
	    <url>https://jitpack.io</url>
	</repository>
</repositories>

Step 2. Add the dependency

<dependency>
    <groupId>com.github.Hitomis</groupId>
    <artifactId>CircleMenu</artifactId>
    <version>v1.1.0</version>
</dependency>

Usage

布局文件中:

<com.hitomi.cmlibrary.CircleMenu
    android:id="@+id/circle_menu"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

Activity 中:

circleMenu = (CircleMenu) findViewById(R.id.circle_menu);

circleMenu.setMainMenu(Color.parseColor("#CDCDCD"), R.mipmap.icon_menu, R.mipmap.icon_cancel)
        .addSubMenu(Color.parseColor("#258CFF"), R.mipmap.icon_home)
        .addSubMenu(Color.parseColor("#30A400"), R.mipmap.icon_search)
        .addSubMenu(Color.parseColor("#FF4B32"), R.mipmap.icon_notify)
        .addSubMenu(Color.parseColor("#8A39FF"), R.mipmap.icon_setting)
        .addSubMenu(Color.parseColor("#FF6A00"), R.mipmap.icon_gps)
        .setOnMenuSelectedListener(new OnMenuSelectedListener() {

            @Override
            public void onMenuSelected(int index) {}

        }).setOnMenuStatusChangeListener(new OnMenuStatusChangeListener() {

            @Override
            public void onMenuOpened() {}

            @Override
            public void onMenuClosed() {}

        });

Method

方法 说明
setMainMenu 设置主按钮(打开/关闭)的背景色,以及打开/关闭的图标。图标支持 Resource、Bitmap、Drawable 形式
addSubMenu 添加一个子菜单项,包括子菜单的背景色以及图标 。图标支持 Resource、Bitmap、Drawable 形式
openMenu 打开菜单
closeMenu 关闭菜单
isOpened 菜单是否打开,返回 boolean 值
setOnMenuSelectedListener 设置选中子菜单项的监听器,回调方法会传递当前点击子菜单项的下标值,从 0 开始计算
setOnMenuStatusChangeListener 设置 CircleMenu 行为状态监听器,onMenuOpened 为菜单打开后的回调方法,onMenuClosed 为菜单关闭后的回调方法

Thanks

原型设计来源于 dribbble
IOS 版本 Ramotion

Licence

  Copyright 2016 Hitomis, Inc.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

circlemenu's People

Contributors

hitomis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

circlemenu's Issues

主按键图片

当不设置主按键的图片资源时,它的引用为null,为何不创建一个默认的呢?

Add Ids.

How to give each menu option to add ID?

Main activity goes blank

Main activity where I am loading child fragments gets empty, till all the fragments are laoded. Please help.

Kotlin Issue

Not able to perform onMenuSelectedListener on Sub Menu in Android Kotlin...

想问您个问题

我现在的需求是双击屏幕上任意一点 弹出几个按钮 您能给点建议吗

Button outside the circle view

hello Hitomi,
i have 5 Buttons in my Activity, when i click on the any button, its menu should be opened as a circle

i tried to put the implementation of the circle menu inside the onclick of btn_car button but it did't work
` @OverRide
public void onClick(View v) {
switch (v.getId()){
case R.id.btn_car:
//Here the implementation of circle Menu of Car, when btn_car is clicked

       break;`

Can you please help?

openMenuIcon is not showing sometimes...

Hello,
When "setMainMenu(...)" is called after "onSizeChanged(...)", openMenuIcon is not showing sometimes.

So you have to call "resetMainDrawableBounds()" in "setMainMenu(...)".
This gonna be better to prevent openMenuIcon.draw(canvas) not working.

Have nice work!

Here is my fixes.

public CircleMenu2 setMainMenu(int mainMenuColor, int openMenuRes, int closeMenuRes) {
    this.openMenuIcon = this.convertDrawable(openMenuRes);
    this.closeMenuIcon = this.convertDrawable(closeMenuRes);
    this.mainMenuColor = mainMenuColor;
    **resetMainDrawableBounds();**
    return this;
}

public CircleMenu2 setMainMenu(int mainMenuColor, Bitmap openMenuBitmap, Bitmap closeMenuBitmap) {
    this.openMenuIcon = this.convertBitmap(openMenuBitmap);
    this.closeMenuIcon = this.convertBitmap(closeMenuBitmap);
    this.mainMenuColor = mainMenuColor;
    **resetMainDrawableBounds();**
    return this;
}

public CircleMenu2 setMainMenu(int mainMenuColor, Drawable openMenuDrawable, Drawable closeMenuDrawable) {
    this.openMenuIcon = openMenuDrawable;
    this.closeMenuIcon = closeMenuDrawable;
    this.mainMenuColor = mainMenuColor;
    **resetMainDrawableBounds();**
    return this;
}

How to setVisibility ?

I want gone this menu and use this code circleMenu.setVisibility(View.INVISIBLE); but not work!

BUG

activity设置横屏显示,在点选菜单的时候,关闭动画开始的时候,会在4个角的任意一角出现半圆,请悉知!

猜测:关闭动画应该是画布移动0,0导致的

SetClickable SetEnable take no effect

SetClickable SetEnable take no effect.
I would like to prevent multiple clicks when an async call is made, but SetClickable SetEnable take no effect. The menu is always enabled.

To be open as default

Hello, I want to menu be open as default. is that possible?
Thank for this great menu.

OnClickListner on menu icons

Hi Hitomis, I want to add onClickListner on the sub-menus. I added the following code but it is not working.

Intent intent1 = new Intent(this,Activity2.class); this.startActivity(intent1); return true;

Please help me to add the onClickListner.

main icon is default empty

hi,
my problem :
http://uupload.ir/files/u3oq_demo.gif.gif
my code is
`
circleMenu = (CircleMenu) findViewById(R.id.circle_menu);
circleMenu.setMainMenu(Color.parseColor("#FF4081"), R.mipmap.ic_more_vert_white, R.mipmap.eqiq_icon_cancel)
.addSubMenu(Color.parseColor("#FF6A00"), R.mipmap.ic_bookmark_border_white_24dp)
.addSubMenu(Color.parseColor("#8A39FF"), R.mipmap.ic_share)
.addSubMenu(Color.parseColor("#30A400"), R.mipmap.abc_ic_ab_back)
.addSubMenu(Color.parseColor("#FF4B32"), R.mipmap.dll)
.addSubMenu(Color.parseColor("#258CFF"), R.mipmap.ic_action_pause)
.setOnMenuSelectedListener(new OnMenuSelectedListener() {

                @Override
                public void onMenuSelected(int index) {

                }

            }).setOnMenuStatusChangeListener(new OnMenuStatusChangeListener() {

        @Override
        public void onMenuOpened() {}

        @Override
        public void onMenuClosed() {}

    });

`

Long press

hello, I want to ask, is it possible to add long press listener in the circular main menu

Add Text

How can add label text title to each menu
Thank you in advance

icon with text

can we use center as oval button and text.. or the center button invisible and other visible..
and also need add text below the icon.. is there any solution?

hello dear Hitomis

i have this Issues
CircleMenu-master\cmlibrary\build.gradle
No service of type Factory available in projectScopeService
after open file
problem in
apply plugin: 'com.github.dcendents.android-maven'

apply plugin: 'com.android.library'
// JitPack Maven
apply plugin: 'com.github.dcendents.android-maven'
// Group
group='com.github.Hitomi'

android {
compileSdkVersion 24
buildToolsVersion "24.0.2"

defaultConfig {
    minSdkVersion 14
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
}

thank you and have nice day

Close menu

Hi @Hitomis , i use this library. i write this code but when click on back button, not close the menu! when press back button close activity!

@Override public void onBackPressed() { if (profile_circleMenu.isOpened()) { profile_circleMenu.closeMenu(); } super.onBackPressed(); }

how can close menu with backButton?

Thnx ❤️

How to remove padding

Hi, Thanks for this great library.
I want remove padding, i set menu in this position :

        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"

but in this position show padding left and bottom! i want not padding in this menu, how can edit your CircleMenu.java for set padding=0 ?

Thanks ❤️

Button icon disappears on recycler view

When i recycle the view with the button, the icon of the recycled view disappears. Im using the setMainMenu void inside the onBindViewHolder function. Any ideas on how can i fix this?

when starting activity the circle does not turn fully

With this the circle does not turn fully, it turns half way and open the new activity. how would I solve the issue?

circleMenu.setOnMenuSelectedListener(new OnMenuSelectedListener() {

                                             @Override
                                             public void onMenuSelected(int index) {
                                                 switch (index) {
                                                     case 0:
                                                         Toast.makeText(Circle.this, "Home Button Clicked", Toast.LENGTH_SHORT).show();
                                                         break;
                                                     case 1:
                                                         startActivity(new Intent(Circle.this, track.class));
                                                         break;

Rendering problem

java.lang.NullPointerException
at com.hitomi.cmlibrary.CircleMenu.resetMainDrawableBounds(CircleMenu.java:660)
at com.hitomi.cmlibrary.CircleMenu.onSizeChanged(CircleMenu.java:174)
at android.view.View.sizeChange(View.java:17638)
at android.view.View.setFrame(View.java:17600)
at android.view.View.layout(View.java:17517)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1079)
at android.view.View.layout(View.java:17520)
at android.view.ViewGroup.layout(ViewGroup.java:5612)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:17520)
at android.view.ViewGroup.layout(ViewGroup.java:5612)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1079)
at android.view.View.layout(View.java:17520)
at android.view.ViewGroup.layout(ViewGroup.java:5612)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:345)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:429)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:389)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:548)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:533)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:966)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:533)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$70(RenderTask.java:659)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

This is the issue i am getting with the new version of the Hitomis library

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.