GithubHelp home page GithubHelp logo

lorensiuswlt / newquickaction3d Goto Github PK

View Code? Open in Web Editor NEW
399.0 52.0 238.0 255 KB

Gallery3D like quickaction

Home Page: http://www.londatiga.net/it/how-to-create-quickaction-dialog-in-android/

License: Apache License 2.0

Java 100.00%

newquickaction3d's Introduction

NewQuickAction3D

NewQuickAction3D is a small android library to create QuickAction dialog with Gallery3D app style.

How to Use

This repo includes a sample Activity (ExampleActivity.java) to show how to use QuickAction.

public class ExampleActivity extends Activity {
	//action id
	private static final int ID_UP     = 1;
	private static final int ID_DOWN   = 2;
	private static final int ID_SEARCH = 3;
	private static final int ID_INFO   = 4;
	private static final int ID_ERASE  = 5;	
	private static final int ID_OK     = 6;
    
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.main);

		ActionItem nextItem 	= new ActionItem(ID_DOWN, "Next", getResources().getDrawable(R.drawable.menu_down_arrow));
		ActionItem prevItem 	= new ActionItem(ID_UP, "Prev", getResources().getDrawable(R.drawable.menu_up_arrow));
    	ActionItem searchItem 	= new ActionItem(ID_SEARCH, "Find", getResources().getDrawable(R.drawable.menu_search));
    	ActionItem infoItem 	= new ActionItem(ID_INFO, "Info", getResources().getDrawable(R.drawable.menu_info));
    	ActionItem eraseItem 	= new ActionItem(ID_ERASE, "Clear", getResources().getDrawable(R.drawable.menu_eraser));
    	ActionItem okItem 		= new ActionItem(ID_OK, "OK", getResources().getDrawable(R.drawable.menu_ok));
    
    	//use setSticky(true) to disable QuickAction dialog being dismissed after an item is clicked
    	prevItem.setSticky(true);
    	nextItem.setSticky(true);
	
		//create QuickAction. Use QuickAction.VERTICAL or QuickAction.HORIZONTAL param to define layout 
    	//orientation
		final QuickAction quickAction = new QuickAction(this, QuickAction.VERTICAL);
	
		//add action items into QuickAction
    	quickAction.addActionItem(nextItem);
		quickAction.addActionItem(prevItem);
    	quickAction.addActionItem(searchItem);
    	quickAction.addActionItem(infoItem);
    	quickAction.addActionItem(eraseItem);
    	quickAction.addActionItem(okItem);
    
    	//Set listener for action item clicked
		quickAction.setOnActionItemClickListener(new QuickAction.OnActionItemClickListener() {			
			@Override
			public void onItemClick(QuickAction source, int pos, int actionId) {
				//here we can filter which action item was clicked with pos or actionId parameter
				ActionItem actionItem = quickAction.getActionItem(pos);
             
				Toast.makeText(getApplicationContext(), actionItem.getTitle() + " selected", Toast.LENGTH_SHORT).show();			    
			}
		});
	
		//set listnener for on dismiss event, this listener will be called only if QuickAction dialog was dismissed
		//by clicking the area outside the dialog.
		quickAction.setOnDismissListener(new QuickAction.OnDismissListener() {			
			@Override
			public void onDismiss() {
				Toast.makeText(getApplicationContext(), "Dismissed", Toast.LENGTH_SHORT).show();
			}
		});
	
		//show on btn1
		Button btn1 = (Button) this.findViewById(R.id.btn1);
		btn1.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				quickAction.show(v);
			}
		});

		Button btn2 = (Button) this.findViewById(R.id.btn2);
		btn2.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				quickAction.show(v);
			}
		});
	
		Button btn3 = (Button) this.findViewById(R.id.btn3);
		btn3.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				quickAction.show(v);
				quickAction.setAnimStyle(QuickAction.ANIM_REFLECT);
			}
		});
	}
}

See http://www.londatiga.net/it/how-to-create-quickaction-dialog-in-android/ for more information.

Example Image Example Image

Developed By

Contributors

Changes

See CHANGELOG for details

License

Copyright 2011 Lorensius W. L. T

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.

newquickaction3d's People

Contributors

lorensiuswlt 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

newquickaction3d's Issues

grid mode

It would be nice to have a 'grid' in addition to the horizontal and vertical modes that are available.

Positioning button and title in the action item

Hi there,
Its a nice working example and worked exactly as you described.
But I want to use this in a little different way.
As per my project's requirement, I need to place the button on the right side and title on the left side. For that I edited the "action_item_horizontal" file because I want to display the action item horizontally. I placed the TextView before ImageView in the RelativeLayout. Doing so and I run the project, I am getting ClassCastException : android.widget.textview...
How can I resolve this?
Waiting for your quick response.
Regards

Inflate actions from XML file

Hi! I used your code in my own project. I'd like to contribute some code for you!
This code is QuickActionInflater, use it as MenuInflater, example:

QuickActionInflater mInflater = new QuickActionInflater(this);
mQuickAction = new QuickAction(this, QuickAction.VERTICAL);
mInflater.inflate(R.menu.options_menu_playback, mQuickAction);

Source code:

/*
 * Copyright (C) 2012 The MusicMod Project
 *
 * 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.
 */

package net.londatiga.android;

import java.io.IOException;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.app.Activity;
import android.content.Context;
import android.content.res.XmlResourceParser;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Xml;
import android.view.InflateException;

/**
 * This class is used to instantiate menu XML files into Menu objects.
 * <p>
 * For performance reasons, menu inflation relies heavily on pre-processing of
 * XML files that is done at build time. Therefore, it is not currently possible
 * to use MenuInflater with an XmlPullParser over a plain XML file at runtime;
 * it only works with an XmlPullParser returned from a compiled resource (R.
 * <em>something</em> file.)
 */
public class QuickActionInflater {
    /** Menu tag name in XML. */
    private static final String XML_MENU = "menu";

    /** Item tag name in XML. */
    private static final String XML_ITEM = "item";

    /** Namespaces to read attributes */
    private static final String ANDROID_NS = "http://schemas.android.com/apk/res/android";

    /** Attribute names */
    private static final String ATTR_ID = "id";
    private static final String ATTR_TITLE = "title";
    private static final String ATTR_ICON = "icon";

    private Context mContext;

    /**
     * Constructs a menu inflater.
     * 
     * @see Activity#getMenuInflater()
     */
    public QuickActionInflater(Context context) {
        mContext = context;
    }

    /**
     * Inflate a menu hierarchy from the specified XML resource. Throws
     * {@link InflateException} if there is an error.
     * 
     * @param menuRes Resource ID for an XML layout resource to load (e.g.,
     *            <code>R.menu.main_activity</code>)
     * @param menu The Menu to inflate into. The items and submenus will be
     *            added to this Menu.
     */
    public void inflate(int menuRes, QuickAction action) {
        XmlResourceParser parser = null;
        try {
            parser = mContext.getResources().getLayout(menuRes);
            AttributeSet attrs = Xml.asAttributeSet(parser);

            parseMenu(parser, attrs, action);
        } catch (XmlPullParserException e) {
            throw new InflateException("Error inflating menu XML", e);
        } catch (IOException e) {
            throw new InflateException("Error inflating menu XML", e);
        } finally {
            if (parser != null) parser.close();
        }
    }

    /**
     * Called internally to fill the given menu. If a sub menu is seen, it will
     * call this recursively.
     */
    private void parseMenu(XmlPullParser parser, AttributeSet attrs, QuickAction action)
            throws XmlPullParserException, IOException {
        QuickActionState quickActionState = new QuickActionState(action);

        int eventType = parser.getEventType();
        String tagName;
        boolean lookingForEndOfUnknownTag = false;
        String unknownTagName = null;

        // This loop will skip to the menu start tag
        do {
            if (eventType == XmlPullParser.START_TAG) {
                tagName = parser.getName();
                if (tagName.equals(XML_MENU)) {
                    // Go to next tag
                    eventType = parser.next();
                    break;
                }

                throw new RuntimeException("Expecting menu, got " + tagName);
            }
            eventType = parser.next();
        } while (eventType != XmlPullParser.END_DOCUMENT);

        boolean reachedEndOfMenu = false;
        while (!reachedEndOfMenu) {
            switch (eventType) {
                case XmlPullParser.START_TAG:
                    if (lookingForEndOfUnknownTag) {
                        break;
                    }
                    tagName = parser.getName();
                    if (tagName.equals(XML_ITEM)) {
                        quickActionState.readItem(attrs);
                    } else {
                        lookingForEndOfUnknownTag = true;
                        unknownTagName = tagName;
                    }
                    break;
                case XmlPullParser.END_TAG:
                    tagName = parser.getName();
                    if (lookingForEndOfUnknownTag && tagName.equals(unknownTagName)) {
                        lookingForEndOfUnknownTag = false;
                        unknownTagName = null;
                    } else if (tagName.equals(XML_ITEM)) {
                        // Add the item if it hasn't been added (if the item was
                        // a submenu, it would have been added already)
                        if (!quickActionState.hasAddedItem()) {
                            quickActionState.addItem();
                        }
                    } else if (tagName.equals(XML_MENU)) {
                        reachedEndOfMenu = true;
                    }
                    break;

                case XmlPullParser.END_DOCUMENT:
                    throw new RuntimeException("Unexpected end of document");
            }

            eventType = parser.next();
        }
    }

    /**
     * State for the current menu.
     * <p>
     * Groups can not be nested unless there is another menu (which will have
     * its state class).
     */
    private class QuickActionState {
        private QuickAction action;

        private boolean itemAdded;
        private int itemId;
        private String itemTitle;
        private Drawable itemIcon;

        public QuickActionState(final QuickAction action) {
            this.action = action;

        }

        /**
         * Called when the parser is pointing to an item tag.
         */
        public void readItem(AttributeSet attrs) {
            // Inherit attributes from the group as default value
            Log.d("QuickActionInflater", "item read! itemId = " + itemId);
            itemId = attrs.getAttributeResourceValue(ANDROID_NS, ATTR_ID, 0);
            itemTitle = mContext.getString(attrs.getAttributeResourceValue(ANDROID_NS, ATTR_TITLE, 0));
            itemIcon = mContext.getResources().getDrawable(attrs.getAttributeResourceValue(ANDROID_NS, ATTR_ICON, android.R.color.transparent));
            itemAdded = false;
        }

        private ActionItem setItem() {
            return new ActionItem(itemId,itemTitle,itemIcon);
        }

        public void addItem() {
            itemAdded = true;
            action.addActionItem(setItem());
        }

        public boolean hasAddedItem() {
            return itemAdded;
        }
    }

}

maven support

Please add the maven support in the same way as SherlockActionBar.
You can only copy pom.xml from SherlockActionBar and modify it for your project
Next step should be upload your library to any public maven repository, but pom.xml make this simple for everyone.

The container moves at each show

Hi, awesome lib but there's an annoying major bug :

Each time the QuickAction is showed, the container (not the arrow) moves to the left for some pixels.
After few openings, the QuickAction is not even under the arrow.

I used it with a button (in an action bar) at the maximum right of the screen.

Best regards,
Alex.

Screenshot : http://hpics.li/b1da65e

problem with listview

hi, there's problem with listview, when i'm clicking on items, the popup will resize to its minimal height.
please see this screenshot : http://i.imgur.com/ouaEP.png

    getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            quickVerticalAction.show(arg1);
        }
    });

mquickAction.addActionItem(faceItem); return nullpointer exeption

            ActionItem faceItem = new ActionItem(FACEBOOK, "FACEBOOK");
    ActionItem twitItem = new ActionItem(TWİTTER, "TWİTTER");
    ActionItem smsItem = new ActionItem(SMS, "SMS");
    ActionItem emailItem = new ActionItem(EMAİL, "EMAİL");

    QuickAction mquickAction = new QuickAction(this,QuickAction.VERTICAL);
    mquickAction.addActionItem(faceItem);

09-25 18:32:44.424: E/ViewRootImpl(24600): sendUserActionEvent() mView == null
09-25 18:32:51.304: E/AndroidRuntime(24600): FATAL EXCEPTION: main
09-25 18:32:51.304: E/AndroidRuntime(24600): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ip_dergi/com.ip_dergi.ItemContent}: java.lang.NullPointerException
09-25 18:32:51.304: E/AndroidRuntime(24600): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2245)
09-25 18:32:51.304: E/AndroidRuntime(24600): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2295)
09-25 18:32:51.304: E/AndroidRuntime(24600): at android.app.ActivityThread.access$700(ActivityThread.java:150)
09-25 18:32:51.304: E/AndroidRuntime(24600): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
09-25 18:32:51.304: E/AndroidRuntime(24600): at android.os.Handler.dispatchMessage(Handler.java:99)
09-25 18:32:51.304: E/AndroidRuntime(24600): at android.os.Looper.loop(Looper.java:137)
09-25 18:32:51.304: E/AndroidRuntime(24600): at android.app.ActivityThread.main(ActivityThread.java:5279)
09-25 18:32:51.304: E/AndroidRuntime(24600): at java.lang.reflect.Method.invokeNative(Native Method)
09-25 18:32:51.304: E/AndroidRuntime(24600): at java.lang.reflect.Method.invoke(Method.java:511)
09-25 18:32:51.304: E/AndroidRuntime(24600): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
09-25 18:32:51.304: E/AndroidRuntime(24600): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
09-25 18:32:51.304: E/AndroidRuntime(24600): at dalvik.system.NativeStart.main(Native Method)
09-25 18:32:51.304: E/AndroidRuntime(24600): Caused by: java.lang.NullPointerException
09-25 18:32:51.304: E/AndroidRuntime(24600): at net.londatiga.android.QuickAction.addActionItem(QuickAction.java:170)
09-25 18:32:51.304: E/AndroidRuntime(24600): at com.ip_dergi.ItemContent.onCreate(ItemContent.java:68)
09-25 18:32:51.304: E/AndroidRuntime(24600): at android.app.Activity.performCreate(Activity.java:5267)
09-25 18:32:51.304: E/AndroidRuntime(24600): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
09-25 18:32:51.304: E/AndroidRuntime(24600): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
09-25 18:32:51.304: E/AndroidRuntime(24600): ... 11 more

Crash after few times showing the quickaction

Afer a few times tappting on the button like a monkey, the app crashes :

LogCat:

09-02 14:31:51.183: ERROR/AndroidRuntime(8552): java.lang.ClassCastException: android.view.ViewGroup$LayoutParams
09-02 14:31:51.183: ERROR/AndroidRuntime(8552): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3129)
09-02 14:31:51.183: ERROR/AndroidRuntime(8552): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
09-02 14:31:51.183: ERROR/AndroidRuntime(8552): at android.view.View.measure(View.java:8313)
09-02 14:31:51.183: ERROR/AndroidRuntime(8552): at android.view.ViewRoot.performTraversals(ViewRoot.java:839)
09-02 14:31:51.183: ERROR/AndroidRuntime(8552): at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
09-02 14:31:51.183: ERROR/AndroidRuntime(8552): at android.os.Handler.dispatchMessage(Handler.java:99)
09-02 14:31:51.183: ERROR/AndroidRuntime(8552): at android.os.Looper.loop(Looper.java:130)
09-02 14:31:51.183: ERROR/AndroidRuntime(8552): at android.app.ActivityThread.main(ActivityThread.java:3683)
09-02 14:31:51.183: ERROR/AndroidRuntime(8552): at java.lang.reflect.Method.invokeNative(Native Method)
09-02 14:31:51.183: ERROR/AndroidRuntime(8552): at java.lang.reflect.Method.invoke(Method.java:507)
09-02 14:31:51.183: ERROR/AndroidRuntime(8552): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-02 14:31:51.183: ERROR/AndroidRuntime(8552): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-02 14:31:51.183: ERROR/AndroidRuntime(8552): at dalvik.system.NativeStart.main(Native Method)

Screenshot : http://hpics.li/c69cd8f

Best regards,
Alexandre

Why complete new repository?

I don't understand why two almost the same project exist as two repository NeqQuickAction and NewQuickAction3D. Don't be better only one project with customizable animation? This situation cause two Issues list, much more forks and mess int the project :-(

Migrate from NewQuickAction to NewQuickAction3D

Hey, I'm currently using NewQuickAction. Is there any simple way to convert NewQuickAction to NewQuickAction3D ?? Will adding the new resources ( if any ) and updating layout file work fine or there are other functionality changes also ? @lorensiuswlt

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.