Tuesday, May 12, 2015

Adding context menus to RecyclerView items


Add an affordance

The "three-dot" overflow pattern was my first choice.





Setup click listeners in ViewHolder


        private ImageView mOverflowIcon;

        public FileViewHolder(View holdMe) {
            super(holdMe);
            holdMe.setOnClickListener(this);
            holdMe.setOnLongClickListener(this);
            mOverflowIcon = (ImageView) holdMe.findViewById(R.id.mfp_context_menu);
            mOverflowIcon.setOnClickListener(this);
        }

Create context menu in OnClickListener

Display the PopupMenu. ("this" is the ViewHolder)

        @Override
        public void onClick(View v) {
            if (v == mOverflowIcon) {
                PopupMenu popup = new PopupMenu(v.getContext(), v);
                popup.inflate(R.menu.mfp_overflow_menu_file);
                popup.setOnMenuItemClickListener(this);
                popup.show();
            }
        }

The menu xml.

        <?xml version="1.0" encoding="utf-8"?>
        <menu xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto">
            <item
                android:id="@+id/delete_file"
                android:title="@string/mfp_delete"
                app:showAsAction="always" />
        </menu>

Add your logic for the menu items

Just the implementation of the OnMenuItemClickListener, and since it's the ViewHolder you have the data as well.

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Toast.makeText(mOverflowIcon.getContext(),"DO SOME STUFF HERE", Toast.LENGTH_LONG).show();
            return true;
        }

NOTE: WindowLeaked

Just a note, if an orientation change occurs while the PopupMenu is still showing you will get a nice informative WindowLeaked exception. This does not crash your app, it is just poor practice. You need to call popupMenu.dismiss() when the activity context is being destroyed, your resulting code for that may vary depending on your implementation.


Monday, April 2, 2012

Where does inspiration come from?

Sitting in my Greek Philosophy class discussing the composition of Reality, pondering the really hard-stuff we hardly think about. I find myself coming back to one of the only absolute truths I believe there is: "You can't get something from nothing." It seems super simple and logical, but it complicates things immensely.

I have been watching House M.D. lately, and almost every episode finds House solving a mystery by a sudden strike of inspiration that seems to come out of no where. I often find myself working on a problem or puzzle and suddenly get a sudden (in the words of Watson) ejaculation of thought, a eureka moment.
Whether the answer suddenly pops into my head, or something leads me to think about a different approach, or a different way of thinking that leads me to an answer. I call this process 'Inspiration'.

So my question is where does 'Inspiration' come from? Since something, even thought, can't come from nothing, it must be derived from something.

Open-ended question.

Thursday, August 18, 2011

FlashForward


So I am in North Carolina staying with my wife's sister. We will be staying with them until Friday, then we will be headed up to Virginia to see my sister's wedding. So it's been a great time to relax and have fun with family. I should post some pictures, not for viewing, but to put them in the cloud instead of using/cluttering up my own disk-space.

*Now the reason for the title, I just watch FlashForward on Netflix.Turns out it ended up being canceled after the first season, which left me with a bunch of questions on how it ended. So in looking at the ending of the series and at the ending of the novel, which the series was based on, it brought up the concept of freewill vs predestination.

This is always a tricky subject and often leaves you more confused than when you started, but the Wikipedia article did a great job of summarizing the moral, physical, and social ramifications of the subject. However, it took me to Newton's third law of motion, in that for every action there is an equal and opposing reaction.

I tried to limit my scope of the freewill controversy to the physical realm by examining the aforementioned third law without the bothersome idea of a conscience agent. If every action has an equal and opposite reaction, this implies the original action must have been a resultant reaction from a previous action. With this thought you can theoretically trace any event to a root cause, with logic dictating there must be an original action to which to attribute all reactions. This implies an external source, presence, or agent outside of the system; which in this case is the physical universe.

I have obviously oversimplified an extremely complicated topic, but I was to trying to tie-in physical laws into the matter of freewill and predestination. That if my previous argument is true, an external source put into motion a predictable and traceable line of action and reactions; this making the original source responsible for a deterministic future. With a determinable line of action and reaction this points to and implies determination of all events. Summarizing, both physical and conscience entities react to previous stimuli, meaning they react to a previous action. With this line of thought it shows a cascading effect, demonstrating that future event are directly connected to previous actions.

Given that the third law of motion is correct, the future of physical events is absolutely deterministic, giving credence to predestination in the physical realm. Now venturing into the conscience agent, one could argue all conscience thought and action are too indeed resultants of previous stimuli. i.e. You eat because you're hungry, you sleep because you're tired, and so on. I would then argue that human behavior is predictable and deterministic given enough knowledge of past events and the insight to interpret those events. I am not arguing against free-will, but that free-will behavior is in itself has a predictable outcome. Again this is an oversimplification, though it has allowed me to cope with the idea that all things are deterministic in that all things are reactions to previous actions. That the future is deterministic, though it is the scope, lack of previous knowledge, and  lack of insight that  prevents us from the total realization of future events.

* Disclaimer: I am no expert, nor do I pretend to be one, these are just my thoughts and I encourage comments and criticism. Also, please excuse any spelling or grammatical mistakes.

Monday, July 25, 2011

First Post

This blog was created to act as a virtual journal. It will predominately be comprised of my personal thoughts and mostly tech related things.