Giter Club home page Giter Club logo

android-satellite-menu's Introduction

#Satellite Menu

'Path' has a very attractive menu sitting on the left bottom corner of the screen. Satellite Menu is the open version of this menu.

For the ones who didnt see path, the menu consists of a main button on the left bottom of the screen. When the user clicks on this button, a number of buttons are popped out of this button. I have resembled this structure to a planet and satellites and thats why I gave the name of this project.

The menu uses built-in animations of Android platform.

Works in API Level 7 (2.1) and above.

Licenced with LGPL.

##Usage

Add the component definition to your view xml as in the following example:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:sat="http://schemas.android.com/apk/res/android.view.ext"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <android.view.ext.SatelliteMenu
        android:id="@+id/menu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|left" 
        android:layout_margin="8dp"
        sat:satelliteDistance="170dp"
        sat:mainImage="@drawable/ic_launcher"
        sat:totalSpacingDegree="90"
        sat:closeOnClick="true"
        sat:expandDuration="500"/>

</FrameLayout>

The attributes are:

  • satelliteDistance The distance of items from the center button
  • totalSpacingDegree The degree between the first and the last item.
  • closeOnClick Defines if the menu shall collapse after clicking on a menu item.
  • expandDuration The duration of expand and collapse operations in milliseconds.

After defining the view in XML, some menu items can be added from code:

SatelliteMenu menu = (SatelliteMenu) findViewById(R.id.menu);
List<SatelliteMenuItem> items = new ArrayList<SatelliteMenuItem>();
items.add(new SatelliteMenuItem(4, R.drawable.ic_1));
items.add(new SatelliteMenuItem(4, R.drawable.ic_3));
items.add(new SatelliteMenuItem(4, R.drawable.ic_4));
items.add(new SatelliteMenuItem(3, R.drawable.ic_5));
items.add(new SatelliteMenuItem(2, R.drawable.ic_6));
items.add(new SatelliteMenuItem(1, R.drawable.ic_2));

Each menu item takes the ID of the item and the drawable resource for the item.

In order to listen clicks on items:

menu.setOnItemClickedListener(new SateliteClickedListener() {
  public void eventOccured(int id) {
    Log.i("sat", "Clicked on " + id);
  }
});

The click event gives the ID of the item which was defined when adding it.

android-satellite-menu's People

Contributors

siyamed 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  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

android-satellite-menu's Issues

BadParcelableException

Hi siyamed,
Iam using satellite menu library for my project.Iam getting badparcelableexception during onResume() and onRestart() in Satellitemenu.java at line no:513
crashlog

redraw satellite items

I want to redraw the items so it can display which item is selected
I changed the addItems function from the library to reset the menuitems every time, so it won't be adding more and more items .

This is my code

initarc(menu_x,"x");
menu_x.setOnItemClickedListener(new SateliteClickedListener() {
public void eventOccured(int argx) {
initarc(menu_x,"x");
}
});

initarc is the function to add items and determine which item is selected so it will display a different icon

the problem is when i click an item, the main satellite is unclickable anymore
(no action when clicked)
but then if I press home and resume the app, then the items are displayed.

something is wrong when adding items from the itemclicklistener, because if i call initarc twice without the listener everything works fine.

Really need some help here!
Thanks.

how to setup?

thanks very much for sharing this library, but I can not set up in my project, the issue is like :Multiple annotations found at this line:
- error: No resource identifier found for attribute 'satelliteDistance' in package
'android.view.ext'
- error: No resource identifier found for attribute 'mainImage' in package 'android.view.ext'
- error: No resource identifier found for attribute 'closeOnClick' in package
'android.view.ext'
- error: No resource identifier found for attribute 'expandDuration' in package
'android.view.ext'
- error: No resource identifier found for attribute 'totalSpacingDegree' in package
'android.view.ext'

Can't open a new view

Hello

i've been using your widget, but when i'm trying to open a new view from the icon pressed the app crashes, i was wandering if anyone already open a new view???

360度のメニューが表示されるように改良しました

SatelliteMenu.java

public void addItems(List items) {

    menuItems.addAll(items);
    this.removeView(imgMain);
    TextView tmpView = new TextView(getContext());
    tmpView.setLayoutParams(new FrameLayout.LayoutParams(0, 0));

// float[] degrees = getDegrees(menuItems.size());
float[] degrees = getDegrees(menuItems.size()+1); // <----- Bug
int index = 0;
for (SatelliteMenuItem menuItem : menuItems) {
int finalX = SatelliteAnimationCreator.getTranslateX(
// degrees[index], satelliteDistance);
degrees[index], satelliteDistance/2); // 円形の場合は、アイテムをメニュー幅の半分にする
int finalY = SatelliteAnimationCreator.getTranslateY(
// degrees[index], satelliteDistance);
degrees[index], satelliteDistance/2); // 円形の場合は、アイテムをメニュー幅の半分にする

        ImageView itemView = (ImageView) LayoutInflater.from(getContext())
                .inflate(R.layout.sat_item_cr, this, false);
        ImageView cloneView = (ImageView) LayoutInflater.from(getContext())
                .inflate(R.layout.sat_item_cr, this, false);
        cloneView.setTag(menuItem.getId());
        itemView.setTag(menuItem.getId());
        cloneView.setVisibility(View.GONE);
        itemView.setVisibility(View.GONE);

        cloneView.setOnClickListener(internalItemClickListener);

// cloneView.setTag(Integer.valueOf(menuItem.getId()));
FrameLayout.LayoutParams layoutParams = getLayoutParams(cloneView);
// layoutParams.bottomMargin = Math.abs(finalY); // 絶対値
// layoutParams.leftMargin = Math.abs(finalX); // 絶対値
layoutParams.bottomMargin = -(finalY);
layoutParams.leftMargin = finalX;
cloneView.setLayoutParams(layoutParams);

        if (menuItem.getImgResourceId() > 0) {
            itemView.setImageResource(menuItem.getImgResourceId());
            cloneView.setImageResource(menuItem.getImgResourceId());
        } else if (menuItem.getImgDrawable() != null) {
            itemView.setImageDrawable(menuItem.getImgDrawable());
            cloneView.setImageDrawable(menuItem.getImgDrawable());
        }

        Animation itemOut = SatelliteAnimationCreator.createItemOutAnimation(getContext(), index, expandDuration, finalX, finalY);
        Animation itemIn = SatelliteAnimationCreator.createItemInAnimation(getContext(), index, expandDuration, finalX, finalY);
        Animation itemClick = SatelliteAnimationCreator.createItemClickAnimation(getContext());

        menuItem.setView(itemView);
        menuItem.setCloneView(cloneView);
        menuItem.setInAnimation(itemIn);
        menuItem.setOutAnimation(itemOut);
        menuItem.setClickAnimation(itemClick);
        menuItem.setFinalX(finalX);
        menuItem.setFinalY(finalY);

        itemIn.setAnimationListener(new SatelliteAnimationListener(itemView, true, viewToItemMap));
        itemOut.setAnimationListener(new SatelliteAnimationListener(itemView, false, viewToItemMap));
        itemClick.setAnimationListener(new SatelliteItemClickAnimationListener(this, menuItem.getId()));

        this.addView(itemView);
        this.addView(cloneView);
        viewToItemMap.put(itemView, menuItem);
        viewToItemMap.put(cloneView, menuItem);
        index++;
    }

    this.addView(imgMain);
}

always on Top

Hi!
You can leave this menu always visible?
I'm using in a layout that contains a ExpandableListView that is populated dynamically via code.
Depending on the number of items that have ExpandableListView, the menu disappears.
I'm using fullscreen layout without ActionBar.

Help?

Rotation causes a funy behaviour

Hi!

In the demo App itself, if you expand the menu, then rotate, the menu is all the sudden closed. This in itself could be an OK behavior, the real issue comes when pressing to expand the menu again the icons do a funny dance and close themselves.

I imagine, what is going on is that the menu is keeping the expanded state internally while the reality of the views correlates to a new fresh activity, and don't reflect the internal views. I have been looking around for a way of maybe resetting the controller during onPause and recreating it during onResume, but it doesn't make a difference.

Other than that good job, the menu does look really good... and thank you for sharing!

fix this issue

When we use setCloseItemsOnClick(false), onItemClickListener of the satellite menu does not work.

Strange behavior on Xperia S

Hello,

I am using your animation for an application, and it works perfectly.

The only bug I have is on Sony Xperia S (with Android 4.0.4), at the end of the animation.
Indeed, buttons don't stay in the place where they should stay : they are all located in a same vertical line (http://file.rspreprod.fr/Screenshot_XperiaS.png)

Do you have an idea on how to fix it ?

Thanks by advance,

Gabriel

Adding library to project

Can you plz tell me how do i add this library to my project in Android Studio and how do i use it further.

xml attributes do not work

XML attributes such as sat:satelliteDistance, sat:mainImage etc. do not work even in the sample project provided here. Even though there are no error shown.

Problem with dynamically adding/removing menu items

Hi,

First of all thank you for creating this amazing library and share it with us.

I'm using this menu in my main screen. Depends of what server is sending me i need to dynamically add some items or remove some others. However, I couldn't successful. Is there a way to do this? If you prepare a sample code i'll be so thankful.

how to open a activity?

Hello thank you for sharing. I want to click on the icon button to open an Activity, how to modify or rewrite the method?

the itemclickEvent should be after the itemIn animation

your code is that when ClickAnimation starts ,the clickEvent is triggered. I change it into AnimationEnd(),but the UE is still uncomfortable.
I think probably the most comfortable way is : ItemClickAnimation---ItemInAnimation---ItemClickEvent

Center menu

Hi.

Applying:

android:layout_gravity="bottom|center_horizontal"
sat:totalSpacingDegree="180"

Doesn't center the menu, so how to center it?

I tried with:

android:layout_gravity="bottom|center_horizontal"

in satellite-menu/res/layout/sat_main.xml but this centers the ImageView, but not the menu

sat_main traslation on rotate right

Hi!, i was trying your library but when i use a different image for sat_main, when the user taps the image rotates as we expect but its moving some pixels left and down

Move to a sensible Java package

android.view is for official Android code. AFAIK, your menu is not part of official Android. I would therefore suggest that you move your View to a package name that is yours, not somebody else's.

Bottom right icon flickers

When I open the SatelitteMenu the second icon from the right bottom corner flickers and causes a weird effect, this does not happens if I close and open the menu several times after, but will happen again if I leave my activity and recreate the SatelitteMenu.

Is there any known fix?

SetOnClickListener on only the button?

It seems like it should be easy, but adding a click listener to the menu only works when you click around it (the amount of space it takes up when opened)... Is there a way to do something, eg a Toast, only when the user clicks the menu button itself? 现在看来似乎应该很容易,但增加点击监听器菜单只能当你周围单击(空间量它打开时占用)...有没有办法做一些事情,用户点击,只有当菜单按钮本身?

Issue with right bottom corner

Hi Siyamed,
Nice code implemented. Could you please tell me how to align the menu at the right bottom corner of the screen?
I tried changing the android:layout_gravity="bottom|right" but that didn't help. Also how to move the images on a fling?

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.