package fr.tvbarthel.apps.cameracolorpicker.activities;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import com.melnykov.fab.FloatingActionButton;

import fr.tvbarthel.apps.cameracolorpicker.R;
import fr.tvbarthel.apps.cameracolorpicker.adapters.ColorAdapter;
import fr.tvbarthel.apps.cameracolorpicker.data.ColorItem;
import fr.tvbarthel.apps.cameracolorpicker.data.ColorItems;

/**
 * TODO comment
 */
public class MainActivity extends ActionBarActivity implements View.OnClickListener {

    protected ColorAdapter mColorAdapter;

    /**
     * The user-visible label for the clip {@link fr.tvbarthel.apps.cameracolorpicker.data.ColorItem}.
     */
    protected String mClipColorItemLabel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mClipColorItemLabel = getString(R.string.activity_main_clip_color_item_label);

        mColorAdapter = new ColorAdapter(this);
        final View emptyView = findViewById(R.id.activity_main_empty_view);
        final ListView colorList = (ListView) findViewById(R.id.activity_main_list_view);
        colorList.setAdapter(mColorAdapter);
        colorList.setEmptyView(emptyView);
        colorList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
                final ColorItem colorItem = mColorAdapter.getItem(position);
                final ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                final ClipData clip = ClipData.newPlainText(mClipColorItemLabel, colorItem.getHexString());
                clipboard.setPrimaryClip(clip);
                Toast.makeText(view.getContext(), R.string.activity_main_color_success_copy_message, Toast.LENGTH_SHORT).show();
                return true;
            }
        });

        final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.activity_main_fab);
        fab.attachToListView(colorList);
        fab.setOnClickListener(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        mColorAdapter.clear();
        mColorAdapter.addAll(ColorItems.getSavedColorItems(this));
        mColorAdapter.notifyDataSetChanged();
    }

    @Override
    public void onClick(View v) {
        final int viewId = v.getId();

        switch (viewId) {
            case R.id.activity_main_fab:
                final Intent intent = new Intent(this, ColorPickerActivity.class);
                startActivity(intent);
                break;

            default:
                throw new IllegalArgumentException("View clicked unsupported. Found " + v);
        }
    }
}

@@ -980,16 +980,269 @@
 Label;%0A%0A
+    /**%0A     * A reference to the current %7B@link android.widget.Toast%7D.%0A     * %3Cp/%3E%0A     * Used for hiding the current %7B@link android.widget.Toast%7D before showing a new one or the activity is paused.%0A     * %7B@link %7D%0A     */%0A    protected Toast mToast;%0A%0A
     @Ove
@@ -1239,32 +1239,32 @@
 %0A%0A    @Override%0A
-
     protected vo
@@ -2368,42 +2368,18 @@
     
+show
 Toast
-.makeText(view.getContext(), 
+(
 R.st
@@ -2427,35 +2427,8 @@
 sage
-, Toast.LENGTH_SHORT).show(
 );%0A 
@@ -2885,32 +2885,130 @@
 anged();%0A    %7D%0A%0A
+    @Override%0A    protected void onPause() %7B%0A        super.onPause();%0A        hideToast();%0A    %7D%0A%0A
     @Override%0A  
@@ -3404,16 +3404,16 @@
 %22 + v);%0A
-
         
@@ -3419,11 +3419,500 @@
  %7D%0A    %7D
+%0A%0A    /**%0A     * Hide the current %7B@link android.widget.Toast%7D.%0A     */%0A    protected void hideToast() %7B%0A        if (mToast != null) %7B%0A            mToast.cancel();%0A            mToast = null;%0A        %7D%0A    %7D%0A%0A    /**%0A     * Show a toast text message.%0A     *%0A     * @param resId The resource id of the string resource to use.%0A     */%0A    protected void showToast(int resId) %7B%0A        hideToast();%0A        mToast = Toast.makeText(this, resId, Toast.LENGTH_SHORT);%0A        mToast.show();%0A    %7D
 %0A%7D%0A

Add hideToast and showToast methods for preventing from 'toast spamming'