app/src/main/java/br/com/javace/javou/ui/activity/MainActivity.java
public class MainActivity extends BaseActivity{

    private ActionMode mAcitonMode;
    private ParticipantFragment mParticipantFragment;

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

        setupInit(savedInstanceState);
    }

    private void setupInit(Bundle savedInstanceState){
        //setupFragment(savedInstanceState);
        Preference preference = new Preference(this);
        if (preference.getString(Constant.FIRST_RUN) == null){
            startActivityForResult(new Intent(this, SynchronizationActivity.class), 0);
            preference.setString(Constant.FIRST_RUN, Constant.TAG);
        }else{
            setupFragment(savedInstanceState);
        }
    }

    private void setupFragment(Bundle savedInstanceState){
        if (savedInstanceState == null) {
            mParticipantFragment = ParticipantFragment.newInstance();
            getFragmentManager().beginTransaction().add(R.id.container, mParticipantFragment, Constant.PARTICIPANT).commit();
        }else{
            if (mParticipantFragment == null) {
                mParticipantFragment = (ParticipantFragment) getFragmentManager().findFragmentByTag(Constant.PARTICIPANT);
            }
        }
    }

    public void showActionMode(String name){
        mAcitonMode = startSupportActionMode(mParticipantFragment.actionModeCallback);
        actionModeSetTitle(name);

        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.action_mode_primary_dark));
        }
    }

    public void actionModeSetTitle(String name){
        mAcitonMode.setTitle(name);
    }

    public void hideActionMode(){
        if (mAcitonMode != null){
            mAcitonMode.finish();
            mAcitonMode = null;
        }

        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.primary_dark));
        }
    }

    @Override
    public void onBackPressed() {
        if (mAcitonMode != null) {
            hideActionMode();
        }else{
            super.onBackPressed();
        }
    }

    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        switch (requestCode){
            case 0:
                mParticipantFragment = ParticipantFragment.newInstance();
                getFragmentManager().beginTransaction().add(R.id.container, mParticipantFragment, Constant.PARTICIPANT).commit();
                break;

            default:
                if (data != null) {
                    if (requestCode == SearchLiveo.REQUEST_CODE_SPEECH_INPUT) {
                        mParticipantFragment.onActivityResult(requestCode, resultCode, data);
                    }
                }
                break;
        }
    }

    @TargetApi(Build.VERSION_CODES.M)
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (mParticipantFragment != null){
            mParticipantFragment.onRequestPermissionsResult(requestCode, permissions, grantResults);
        }
    }
}
app/src/main/java/br/com/javace/javou/interfaces/OnItemLongClickListener.java
public interface OnItemLongClickListener {
    void onItemLongClick(View v, int position);
}
app/src/main/java/br/com/javace/javou/ui/activity/ParticipantFortunateActivity.java
public class ParticipantFortunateActivity extends BaseActivity{

    @BindView(R.id.toolbar) Toolbar mToolbar;
    @BindView(R.id.txt_name) TextView txtName;
    @BindView(R.id.txt_email) TextView txtEmail;
    @BindView(R.id.txt_phone) TextView txtPhone;
    @BindView(R.id.img_photo) ImageView imgPhoto;
    @BindView(R.id.layout_phone) LinearLayout mLayoutPhone;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_participant_fortunate);
        ButterKnife.bind(this);

        mToolbar.setTitle(getString(R.string.participant_fortunate));
        this.setSupportActionBar(mToolbar);

        final ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        }

        Participant participant = getIntent().getExtras().getParcelable(Constant.PARTICIPANT);

        if (participant != null) {
            txtName.setText(participant.getName());
            txtEmail.setText(participant.getEmail());

            mLayoutPhone.setVisibility(View.GONE);
            if (!TextUtils.isEmpty(participant.getPhone())){
                txtPhone.setText(participant.getPhone());
                mLayoutPhone.setVisibility(View.VISIBLE);
            }

            if (participant.getSex()) {
                imgPhoto.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_suricate_girl));
            }
        }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        finish(ActivityAnimation.SLIDE_RIGHT);
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        finish(ActivityAnimation.SLIDE_RIGHT);
    }
}
app/src/main/java/br/com/javace/javou/ui/base/BaseFragment.java
public class BaseFragment extends Fragment {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    }

    public enum ActivityAnimation {
        SLIDE_LEFT, SLIDE_RIGHT
    }

    public void startActivity(Intent intent, final BaseActivity.ActivityAnimation animation) {
        startActivity(intent);
        putAnimation(getActivity(), animation);
    }

    public void startActivityForResult(Intent intent, int requestCode, final BaseActivity.ActivityAnimation animation) {
        startActivityForResult(intent, requestCode);
        putAnimation(getActivity(), animation);
    }


    private static void putAnimation(final Activity source, final BaseActivity.ActivityAnimation animation) {
        try {
            Method method = Activity.class.getMethod("overridePendingTransition", int.class, int.class);

            int[] animations = getAnimation(animation);
            method.invoke(source, animations[0], animations[1]);
        } catch (Exception e) {
            e.getStackTrace();
        }
    }

    private static int[] getAnimation(final BaseActivity.ActivityAnimation animation) {

        int exitAnim;
        int enterAnim;

        switch (animation) {
            case SLIDE_RIGHT:
                enterAnim = R.anim.slide_right_enter;
                exitAnim = R.anim.slide_right_exit;
                break;

            case SLIDE_LEFT:
            default:
                enterAnim = R.anim.slide_left_enter;
                exitAnim = R.anim.slide_left_exit;
                break;
        }

        return new int[]{enterAnim, exitAnim};
    }
}
app/src/main/java/br/com/javace/javou/ui/activity/ResumeActivity.java
public class ResumeActivity extends BaseActivity {

    @BindView(R.id.toolbar) Toolbar mToolbar;
    @BindView(R.id.txt_shape_total_raffled) TextView mTxtShapeTotalReffled;
    @BindView(R.id.txt_shape_total_attendence) TextView mTxtShapeTotalAttendence;
    @BindView(R.id.txt_shape_total_registrations) TextView mTxtShapeTotalRegistrations;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_resume);
        ButterKnife.bind(this);

        mToolbar.setTitle(getString(R.string.resume_event));
        this.setSupportActionBar(mToolbar);

        final ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        generateResume();
    }

    private void generateResume() {
        ParticipantDao dao = new ParticipantDao(this);
        Resume resume = dao.generateResume();
        mTxtShapeTotalRegistrations.setText(String.format(Locale.getDefault(), "%d", resume.getTotalRegistrations()));
        mTxtShapeTotalAttendence.setText(String.format(Locale.getDefault(), "%d", resume.getTotalAttendance()));
        mTxtShapeTotalReffled.setText(String.format(Locale.getDefault(), "%d", resume.getTotalRaffled()));
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        finish(ActivityAnimation.SLIDE_RIGHT);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        finish(ActivityAnimation.SLIDE_RIGHT);
        return super.onOptionsItemSelected(item);
    }
}
app/src/main/java/br/com/javace/javou/dao/ParticipantDao.java
public class ParticipantDao {

    private Context mContext;
    private ClasseDB classeDB;
    private SQLiteDatabase db = null;
    private static ParticipantDao instance;

    public ParticipantDao(Context context) {
        super();
        this.mContext = context;

    }

    public static ParticipantDao getInstance(Context context) {
        if (instance == null) {
            synchronized (ParticipantDao.class) {
                if (instance == null) {
                    instance = new ParticipantDao(context);
                }
            }
        }
        return instance;
    }

    private void openConnection() {

        try {
            this.classeDB = ClasseDB.getInstance(this.mContext);
            db = classeDB.getWritableDatabase();
        } catch (Exception e) {

            Log.e(Constant.TAG, "Erro ao abrir conex?es ParticipantDao");
        }
    }

    private void closeConnection() {
        try {
            if (null != db) {
                db.close();
                db = null;
                classeDB.close();
            }

        } catch (Exception e) {
            Log.e(Constant.TAG, "Erro ao fechar conex?es ParticipantDao");
        }
    }

    public void synchronizeParticipant(List<String[]> participants) {

        if (participants != null) {
            try {
                openConnection();
                for (String[] participant : participants) {
                    try {

                        if (!participant[0].equals("NOME")) {

                            ContentValues campos = new ContentValues();

                            campos.put(Constant.PARTICIPANT_name, participant[0]);
                            campos.put(Constant.PARTICIPANT_email, participant[1].toLowerCase());
                            campos.put(Constant.PARTICIPANT_code, participant[5]);

                            //campos.put(Constant.PARTICIPANT_phone, "");
                            campos.put(Constant.PARTICIPANT_phone, Util.replacePhone(participant[13]));

                            campos.put(Constant.PARTICIPANT_attend, 0);
                            campos.put(Constant.PARTICIPANT_nameEvent, "JAVOU! #09 - Casos de Sucesso");

                            String birthDate = participant[16];
                            campos.put(Constant.PARTICIPANT_birthDate, birthDate);

                            String company = WordUtils.capitalizeFully(participant[17].toLowerCase());
                            campos.put(Constant.PARTICIPANT_company, company);

                            campos.put(Constant.PARTICIPANT_sex, !participant[20].equals("Masculino"));

                            int shirtSize = 5;
                            if (!participant[3].contains("SEM Blusa")) {
                                shirtSize = Util.replaceShirtSize(participant[21]);
                            }
                            campos.put(Constant.PARTICIPANT_shirtSize, shirtSize);

                            try {
                                Long row = db.insertOrThrow(Constant.TABLE_PARTICIPANT, Constant.DATABASE, campos);
                                Log.d("ParticipantDao", row.toString());
                            } catch (Exception e) {
                                e.getMessage();
                                Log.e(Constant.TAG, "insert: " + mContext.getString(R.string.app_name));
                            }
                        }

                    } catch (Exception e) {
                        e.getStackTrace();
                    }
                }

                closeConnection();
            }catch (Exception e){
                e.getStackTrace();
            }
        }
    }

    public boolean insert(Participant participant) {

        if (participant != null) {

            try {
                openConnection();

                ContentValues campos = new ContentValues();

                campos.put(Constant.PARTICIPANT_name, participant.getName());
                campos.put(Constant.PARTICIPANT_phone, participant.getPhone());
                campos.put(Constant.PARTICIPANT_email, participant.getEmail());
                campos.put(Constant.PARTICIPANT_photo, participant.getPhoto());
                campos.put(Constant.PARTICIPANT_shirtSize, participant.getShirtSize());
                campos.put(Constant.PARTICIPANT_attend, participant.isAttend() ? 1 : 0);
                campos.put(Constant.PARTICIPANT_nameEvent, participant.getNameEvent());
                campos.put(Constant.PARTICIPANT_birthDate, participant.getBirthDate());
                campos.put(Constant.PARTICIPANT_sex, participant.isSex() ? 1 : 0);
                campos.put(Constant.PARTICIPANT_company, participant.getCompany());

                try {
                    return ( db.insertOrThrow(Constant.TABLE_PARTICIPANT, Constant.DATABASE, campos) != -1);
                } catch (Exception e) {
                    e.getMessage();
                    Log.e(Constant.TAG, "insert: " + mContext.getString(R.string.app_name));
                }

            } finally {
                closeConnection();
            }
        }

        return false;
    }

    public boolean update(Participant participant) {

        try {
            openConnection();

            ContentValues campos = new ContentValues();

            campos.put(Constant.PARTICIPANT_name, participant.getName());
            campos.put(Constant.PARTICIPANT_phone, participant.getPhone());
            campos.put(Constant.PARTICIPANT_email, participant.getEmail());
            campos.put(Constant.PARTICIPANT_photo, participant.getPhoto());
            campos.put(Constant.PARTICIPANT_shirtSize, participant.getShirtSize());
            campos.put(Constant.PARTICIPANT_attend, participant.isAttend() ? 1 : 0);
            campos.put(Constant.PARTICIPANT_nameEvent, participant.getNameEvent());
            campos.put(Constant.PARTICIPANT_birthDate, participant.getBirthDate());
            campos.put(Constant.PARTICIPANT_sex, participant.isSex() ? 1 : 0);
            campos.put(Constant.PARTICIPANT_company, participant.getCompany());

            String args[] = new String[]{String.valueOf(participant.getId())};
            return (db.update(Constant.TABLE_PARTICIPANT, campos, "id = ?", args) != -1);

        } catch (Exception e) {
            e.getMessage();
            Log.e(Constant.TAG, "Erro ParticipantDao update: ", e);
            Log.e(Constant.TAG, "update: " + mContext.getString(R.string.app_name));
        } finally {
            closeConnection();
        }

        return false;
    }

    public boolean updatePresence(Participant participant) {

        try {
            openConnection();

            ContentValues contentValues = new ContentValues();
            contentValues.put(Constant.PARTICIPANT_attend, participant.isAttend() ? 0 : 1);

            String args[] = new String[]{String.valueOf(participant.getId())};
            return (db.update(Constant.TABLE_PARTICIPANT, contentValues, "id = ?", args) != -1);

        } catch (Exception e) {
            e.getMessage();
            Log.e(Constant.TAG, "Erro ParticipantDao updatePresence: ", e);
            Log.e(Constant.TAG, "updatePresence: " + mContext.getString(R.string.app_name));
        } finally {
            closeConnection();
        }

        return false;
    }

    public boolean delete(int id) {

        try {
            openConnection();

            String args[] = new String[]{String.valueOf(id)};
            return (db.delete(Constant.TABLE_PARTICIPANT, "id = ?", args) != -1);

        } catch (Exception e) {
            e.getMessage();
            Log.e(Constant.TAG, "Erro ParticipantDao delete: ", e);
            Log.e(Constant.TAG, "delete: " + mContext.getString(R.string.app_name));
        } finally {
            closeConnection();
        }

        return false;
    }

    public ArrayList<Participant> getAll() {

        Participant participant;
        ArrayList<Participant> lParticipant = new ArrayList<>();

        Cursor cursor;
        try {

            openConnection();
            cursor = db.query(Constant.TABLE_PARTICIPANT, Constant.PARTICIPANT_COLS, null, null, null,
                    null, Constant.PARTICIPANT_name + " ASC");

            while (cursor.moveToNext()) {
                participant = new Participant();

                participant.setId(cursor.getInt(0));
                participant.setName(cursor.getString(1));
                participant.setPhone(cursor.getString(2));
                participant.setEmail(cursor.getString(3));
                participant.setPhoto(cursor.getString(4));

                //identifying who will be the type of group
                int shirtSize = cursor.getInt(5);
                participant.setGroup(true);
                participant.setShirtSize(shirtSize);

                participant.setAttend(cursor.getInt(6) == 1);
                participant.setNameEvent(cursor.getString(7));

                participant.setBirthDate(cursor.getString(8));
                participant.setSex(cursor.getInt(9) == 1);
                participant.setRaffled(cursor.getInt(10) == 1);
                participant.setCompany(cursor.getString(11));
                participant.setCode(cursor.getInt(12));

                lParticipant.add(participant);
            }
            cursor.close();
            return lParticipant;
        } catch (Exception e) {
            Log.e(Constant.TAG, "Erro ParticipantDao getAll: ", e);
        } finally {
            closeConnection();
        }

        return null;
    }

    public boolean updateAsRaffled(Participant participantFortunate) {

        try {
            openConnection();

            ContentValues contentValues = new ContentValues();
            contentValues.put(Constant.PARTICIPANT_raffled, 1);

            String args[] = new String[]{String.valueOf(participantFortunate.getId())};
            return (db.update(Constant.TABLE_PARTICIPANT, contentValues, "id = ?", args) != -1);

        } catch (Exception e) {
            e.getMessage();
            Log.e(Constant.TAG, "Erro ParticipantDao updateAsRaffled: ", e);
            Log.e(Constant.TAG, "updateAsRaffled: " + mContext.getString(R.string.app_name));
        } finally {
            closeConnection();
        }

        return false;

    }

    public int getTotalRegistrations(){
        openConnection();
        Cursor mCount= db.rawQuery("select count(*) from " + Constant.TABLE_PARTICIPANT, null);
        mCount.moveToFirst();
        int totalRegistrations= mCount.getInt(0);
        mCount.close();
        closeConnection();
        return totalRegistrations;
    }

    public int getTotalAttendance(){
        openConnection();
        Cursor mCount= db.rawQuery("select count(*) from " + Constant.TABLE_PARTICIPANT + " WHERE attend=1", null);
        mCount.moveToFirst();
        int totalAttendance= mCount.getInt(0);
        mCount.close();
        closeConnection();
        return totalAttendance;
    }

    public int getTotalRaffled(){
        openConnection();
        Cursor mCount= db.rawQuery("select count(*) from " + Constant.TABLE_PARTICIPANT + " WHERE attend=1 and raffled=1", null);
        mCount.moveToFirst();
        int totalRaffled= mCount.getInt(0);
        mCount.close();
        closeConnection();
        return totalRaffled;
    }

    public Resume generateResume() {
        Resume resume = new Resume();
        resume.setTotalRegistrations(getTotalRegistrations());
        resume.setTotalAttendance(getTotalAttendance());
        resume.setTotalRaffled(getTotalRaffled());
        return resume;
    }

}
app/src/main/java/br/com/javace/javou/interfaces/OnScrollListener.java
public abstract class OnScrollListener extends RecyclerView.OnScrollListener {

    private int currentPage = 1;
    private int totalItemCount;
    private int visibleItemCount;
    private int firstVisibleItem;

    private int lastVisibleItem = 0;
    private boolean checkScroll = true;

    private boolean loading = false;
    private int currentTotalItems = 0;

    private LinearLayoutManager mLinearLayoutManager;
    private FloatingActionButton mFloatingActionButton;
    public OnScrollListener(LinearLayoutManager linearLayoutManager, FloatingActionButton floatingActionButton) {
        this.mLinearLayoutManager = linearLayoutManager;
        this.mFloatingActionButton = floatingActionButton;
    }

    public OnScrollListener(LinearLayoutManager linearLayoutManager) {
        this.mLinearLayoutManager = linearLayoutManager;
    }

    @Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
        super.onScrolled(recyclerView, dx, dy);

        visibleItemCount = recyclerView.getChildCount();
        totalItemCount = mLinearLayoutManager.getItemCount();
        firstVisibleItem = mLinearLayoutManager.findFirstVisibleItemPosition();

        if (totalItemCount < currentTotalItems) {
            this.currentPage = 1;
            this.currentTotalItems = totalItemCount;

            if (totalItemCount == 0) {
                this.loading = true;
            }
        }

        if (loading && (totalItemCount > currentTotalItems)) {
            loading = false;
            currentTotalItems = totalItemCount;
        }

        if (!loading && (totalItemCount - visibleItemCount)<=(firstVisibleItem + 5)) {
            onLoadMore(currentPage++);
            loading = true;
        }

        if (lastVisibleItem != firstVisibleItem) {
            if (lastVisibleItem < firstVisibleItem) {
                if (checkScroll) {
                    checkScroll = false;
                    showHideFloatButton(true);
                    onScroll(recyclerView, dx, dy, true);
                }
            } else {
                if (!checkScroll) {
                    checkScroll = true;
                    showHideFloatButton(false);
                    onScroll(recyclerView, dx, dy, false);
                }
            }
        }

        lastVisibleItem = firstVisibleItem;
    }

    public void resetEndlessRecyclerView(){
        this.currentTotalItems = 0;
        this.loading = false;
    }

    public abstract void onScroll(RecyclerView recyclerView, int dx, int dy, boolean onScroll);
    public abstract void onLoadMore(int currentPage);

    //Hide or show the FloatingActionButton based on the list scroll
    private void showHideFloatButton(boolean status) {
        if (status) {
            mFloatingActionButton.setAlpha(1f);
            mFloatingActionButton.setTranslationY(0f);
            mFloatingActionButton.animate().alpha(0f)
                    .translationY(mFloatingActionButton.getHeight())
                    .setDuration(175L)
                    .setListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            mFloatingActionButton.setVisibility(FrameLayout.GONE);
                        }
                    }).start();
        } else {
            mFloatingActionButton.setVisibility(View.VISIBLE);
            mFloatingActionButton.setAlpha(0f);
            mFloatingActionButton.setTranslationY(mFloatingActionButton.getHeight());
            mFloatingActionButton.animate()
                    .alpha(1f)
                    .translationY(0f)
                    .setDuration(175L)
                    .setListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            mFloatingActionButton.setVisibility(FrameLayout.VISIBLE);
                        }
                    })
                    .start();
        }
    }
}
app/src/main/java/br/com/javace/javou/interfaces/OnItemClickListener.java
public interface OnItemClickListener {
    void onItemClick(View v, int position);
}
app/src/main/java/br/com/javace/javou/model/participant/Participant.java
public class Participant implements Parcelable {

    private int id;
    private int code;
    private boolean sex;
    private String name;
    private String phone;
    private String email;
    private String photo;
    private int shirtSize;
    private boolean group;
    private boolean attend;
    private String company;
    private String nameEvent;
    private String birthDate;
    private boolean raffled;

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.getId());
        dest.writeInt(this.getCode());
        dest.writeByte(isSex() ? (byte) 1 : (byte) 0);
        dest.writeString(this.getName());
        dest.writeString(this.getPhone());
        dest.writeString(this.getEmail());
        dest.writeString(this.getPhoto());
        dest.writeInt(this.getShirtSize());
        dest.writeByte(isGroup() ? (byte) 1 : (byte) 0);
        dest.writeByte(isAttend() ? (byte) 1 : (byte) 0);
        dest.writeString(this.getCompany());
        dest.writeString(this.getNameEvent());
        dest.writeString(this.getBirthDate());
        dest.writeByte(isRaffled() ? (byte) 1 : (byte) 0);
    }

    public Participant() {
    }

    protected Participant(Parcel in) {
        this.setId(in.readInt());
        this.setCode(in.readInt());
        this.setSex(in.readByte() != 0);
        this.setName(in.readString());
        this.setPhone(in.readString());
        this.setEmail(in.readString());
        this.setPhoto(in.readString());
        this.setShirtSize(in.readInt());
        this.setGroup(in.readByte() != 0);
        this.setAttend(in.readByte() != 0);
        this.setCompany(in.readString());
        this.setNameEvent(in.readString());
        this.setBirthDate(in.readString());
        this.setRaffled(in.readByte() != 0);
    }

    public static final Parcelable.Creator<Participant> CREATOR = new Parcelable.Creator<Participant>() {
        public Participant createFromParcel(Parcel source) {
            return new Participant(source);
        }

        public Participant[] newArray(int size) {
            return new Participant[size];
        }
    };

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public boolean isSex() {
        return sex;
    }

    public void setSex(boolean sex) {
        this.sex = sex;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPhoto() {
        return photo;
    }

    public void setPhoto(String photo) {
        this.photo = photo;
    }

    public int getShirtSize() {
        return shirtSize;
    }

    public void setShirtSize(int shirtSize) {
        this.shirtSize = shirtSize;
    }

    public boolean isGroup() {
        return group;
    }

    public void setGroup(boolean group) {
        this.group = group;
    }

    public boolean isAttend() {
        return attend;
    }

    public void setAttend(boolean attend) {
        this.attend = attend;
    }

    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    public String getNameEvent() {
        return nameEvent;
    }

    public void setNameEvent(String nameEvent) {
        this.nameEvent = nameEvent;
    }

    public String getBirthDate() {
        return birthDate;
    }

    public void setBirthDate(String birthDate) {
        this.birthDate = birthDate;
    }

    public boolean isRaffled() {
        return raffled;
    }

    public void setRaffled(boolean raffled) {
        this.raffled = raffled;
    }

    public boolean getSex() {
        return sex;
    }
}
app/src/main/java/br/com/javace/javou/task/ParticipantSendTask.java
public class ParticipantSendTask extends AsyncTask<Void, Void, Boolean> {

    private ArrayList<Participant> mParticipant;

    protected ParticipantSendTask(ArrayList<Participant> participant){
        this.mParticipant = participant;
    }

    @Override
    protected Boolean doInBackground(Void... params) {

        CSVWriter writer;
        boolean isAttend = false;

        try {
            writer = new CSVWriter(new FileWriter(Constant.PATH_FILE_JAVOU));
            List<String[]> data = new ArrayList<>();

            data.add(Constant.FILE_COLS);

            for (Participant participant : mParticipant) {
                if (participant.isAttend()) {
                    isAttend = true;
                    String sex = (participant.isSex() ? "F" : "M");
                    data.add(new String[]{String.valueOf(participant.getCode()), participant.getName(), participant.getEmail(), participant.getPhone(), sex, participant.getCompany()});
                }
            }

            writer.writeAll(data);
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return isAttend;
    }
}
app/src/main/java/br/com/javace/javou/task/ParticipantDeleteTask.java
public class ParticipantDeleteTask extends AsyncTask<Void, Void, Boolean> {

    private int mId;
    private Context mContext;
    public ParticipantDeleteTask(Context context, int id){
        this.mId = id;
        this.mContext = context;
    }

    @Override
    protected Boolean doInBackground(Void... params) {
        ParticipantDao participantDao = ParticipantDao.getInstance(mContext);
        return participantDao.delete(mId);
    }
}
app/src/main/java/br/com/javace/javou/util/Constant.java
public class Constant {
    public static String TAG = "Javou";
    public static final String NAME_EVENT = "Setic - AppJavou";

    public static final int DATABASE_VERSION = 1;
    public static final String DATABASE = "javou.db";
    private static final String NAME_FILE = "/javou.csv";

    public static String POSITION = "POSITION";
    public static String FIRST_RUN = "FIRST_RUN";
    static String PREFERENCES_APP = "JAVOU";
    public static String ACTION_MODE = "ACTION_MODE";
    public static String PARTICIPANT = "Participant";

    public static String INSERT = "INSERT";

    //Tablet participant
    public static final String TABLE_PARTICIPANT = "participant";
    private static final String PARTICIPANT_id = "id";
    public static final String PARTICIPANT_name = "name";
    public static final String PARTICIPANT_phone = "phone";
    public static final String PARTICIPANT_email = "email";
    public static final String PARTICIPANT_photo = "photo";
    public static final String PARTICIPANT_shirtSize = "shirtSize";
    public static final String PARTICIPANT_attend = "attend";
    public static final String PARTICIPANT_nameEvent = "nameEvent";
    public static final String PARTICIPANT_birthDate = "birthDate";
    public static final String PARTICIPANT_sex = "sex";
    public static final String PARTICIPANT_raffled = "raffled";
    public static final String PARTICIPANT_company = "company";
    public static final String PARTICIPANT_code = "code";

    public static String[] CREATE_TABLE() {
        String CREATE_PARTICIPANT = " CREATE TABLE participant ( "
                + " id INTEGER CONSTRAINT 'PK_PARTICIPANT' PRIMARY KEY AUTOINCREMENT, "
                + " code INT NULL DEFAULT 0, "
                + " name VARCHAR(100) NOT NULL, "
                + " phone VARCHAR(100) NOT NULL, "
                + " email VARCHAR(250) NULL, "
                + " photo TEXT NULL, "
                + " shirtSize INT NULL DEFAULT 0, "
                + " attend INT NULL DEFAULT 0, "
                + " nameEvent VARCHAR(100) NULL, "
                + " birthDate VARCHAR(10) NULL, "
                + " sex CHAR(1) NULL, "
                + " raffled INT NULL DEFAULT 0, "
                + " company VARCHAR(250) NULL ); ";
        return new String[] {CREATE_PARTICIPANT};
    }

    public static final String PATH_FILE_JAVOU = android.os.Environment.getExternalStorageDirectory().getAbsolutePath() + NAME_FILE;

    public static final String PARTICIPANT_COLS[] = {
            PARTICIPANT_id,
            PARTICIPANT_name,
            PARTICIPANT_phone,
            PARTICIPANT_email,
            PARTICIPANT_photo,
            PARTICIPANT_shirtSize,
            PARTICIPANT_attend,
            PARTICIPANT_nameEvent,
            PARTICIPANT_birthDate,
            PARTICIPANT_sex,
            PARTICIPANT_raffled,
            PARTICIPANT_company,
            PARTICIPANT_code
    };

    public static final String FILE_COLS[] = {
            "CODIGO", "NOME", "EMAIL", "CELULAR", "SEXO", "EMPRESA"
    };

}
app/src/main/java/br/com/javace/javou/ui/base/BaseActivity.java
public class BaseActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    }

    public enum ActivityAnimation {
        SLIDE_LEFT, SLIDE_RIGHT
    }

    public void startActivity(Intent intent, final ActivityAnimation animation) {
        startActivity(intent);
        putAnimation(this, animation);
    }

    public void startActivityForResult(Intent intent, int requestCode, final ActivityAnimation animation) {
        startActivityForResult(intent, requestCode);
        putAnimation(this, animation);
    }

    public void finish(final ActivityAnimation animation) {
        finish();
        putAnimation(this, animation);
    }

    private static void putAnimation(final Activity source,
                                     final ActivityAnimation animation) {
        try {
            Method method = Activity.class.getMethod("overridePendingTransition", int.class, int.class);

            int[] animations = getAnimation(animation);
            method.invoke(source, animations[0], animations[1]);
        } catch (Exception e) {
            e.getStackTrace();
        }
    }

    private static int[] getAnimation(final ActivityAnimation animation) {
        int exitAnim;
        int enterAnim;

        switch (animation) {
            case SLIDE_RIGHT:
                enterAnim = R.anim.slide_right_enter;
                exitAnim = R.anim.slide_right_exit;
                break;

            case SLIDE_LEFT:
            default:
                enterAnim = R.anim.slide_left_enter;
                exitAnim = R.anim.slide_left_exit;
                break;
        }

        return new int[]{enterAnim, exitAnim};
    }
}
searchliveo/src/main/java/br/liveo/searchliveo/interfaces/OnSearchListener.java
public interface OnSearchListener {
    void changedSearch(CharSequence text);
}
app/src/main/java/br/com/javace/javou/ui/activity/ParticipantDetailActivity.java
public class ParticipantDetailActivity extends BaseActivity {

    private ProgressDialog mDialog;
    private Participant mParticipant;

    @BindView(R.id.toolbar) Toolbar mToolbar;
    @BindView(R.id.txt_email) TextView mTxtEmail;
    @BindView(R.id.txt_phone) TextView mTxtPhone;
    @BindView(R.id.txt_attend) TextView mTxtAttend;
    @BindView(R.id.img_photo) ImageView mImgPhoto;
    @BindView(R.id.txt_shirt_size) TextView mTxtShirtSize;
    @BindView(R.id.float_edit) FloatingActionButton mFloatEdit;
    @BindView(R.id.collapsing_toolbar) CollapsingToolbarLayout mCollapsingToolbar;

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

        ButterKnife.bind(this);
        this.setSupportActionBar(mToolbar);

        final ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        }

        mFloatEdit.setOnClickListener(onClickEdit);
        mParticipant = getIntent().getExtras().getParcelable(Constant.PARTICIPANT);
        mCollapsingToolbar.setTitle(mParticipant != null ? mParticipant.getName() : getString(R.string.app_name));

        if (mParticipant != null){
            mTxtEmail.setText(mParticipant.getEmail());
            mTxtPhone.setText(mParticipant.getPhone());

            GradientDrawable gradientDrawable = (GradientDrawable) mTxtShirtSize.getBackground();
            gradientDrawable.setColor(ContextCompat.getColor(this, Util.shirtSizeColor[mParticipant.getShirtSize()]));
            mTxtShirtSize.setText(getString(Util.shirtSize[mParticipant.getShirtSize()]));

            if (mParticipant.isAttend()) {
                mTxtAttend.setText(getString(R.string.attended_event));
                mTxtAttend.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_check_green_18dp, 0, 0, 0);
            }

            if (mParticipant.getPhoto() != null && !mParticipant.getPhoto().equals("")) {
                Glide.with(this).load(mParticipant.getPhoto()).centerCrop().into(mImgPhoto);
            }else{
                Glide.with(this).load(R.drawable.ic_suricate).centerCrop().into(mImgPhoto);
            }
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu, menu);
        menu.findItem(R.id.menu_send).setVisible(false);
        menu.findItem(R.id.menu_search).setVisible(false);
        menu.findItem(R.id.menu_raffle).setVisible(false);
        menu.findItem(R.id.menu_discart).setVisible(false);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish(ActivityAnimation.SLIDE_RIGHT);
                break;

            case R.id.menu_delete:
                confirmDelete();
                break;
        }
        return true;
    }

    private View.OnClickListener onClickEdit  = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), NewParticipantActivity.class);
            intent.putExtra(Constant.PARTICIPANT, mParticipant);
            startActivityForResult(intent, 1, BaseActivity.ActivityAnimation.SLIDE_LEFT);
        }
    };


//    private void deleteParticipant(){
//        showDialog();
//        ParseObject gameScore = new ParseObject(Constant.PARTICIPANT);
//        gameScore.setObjectId(mParticipant.getObjectId());
//        gameScore.deleteInBackground(new DeleteCallback() {
//            @Override
//            public void done(ParseException error) {
//                if (error == null) {
//                    Intent intent = new Intent();
//                    intent.putExtra(Constant.PARTICIPANT, true);
//                    setResult(0, intent);
//                    finish();
//                    Toast.makeText(getApplicationContext(), R.string.warning_delete_participante, Toast.LENGTH_SHORT).show();
//                } else {
//                    Toast.makeText(getApplicationContext(), R.string.error_delete_participante, Toast.LENGTH_SHORT).show();
//                }
//
//                hideDialog();
//            }
//        });
//    }

    private void showDialog() {
        mDialog = ProgressDialog.show(this, getString(R.string.wait),
                getString(R.string.warning_delete_wait_participante));
    }

    private void hideDialog(){
        if (mDialog != null){
            mDialog.dismiss();
        }
    }

    private void confirmDelete(){
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(getString(R.string.warning_participant_excluded));
        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                //TODO
                //deleteParticipant();
                dialog.dismiss();
            }
        });
        builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                //TODO
                dialog.dismiss();
            }
        });
        AlertDialog dialog = builder.create();
        dialog.show();
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        finish(ActivityAnimation.SLIDE_RIGHT);
    }
}
app/src/main/java/br/com/javace/javou/model/raffle/Raffle.java
public class Raffle{

    private Random randomGenerator;
    private ArrayList<Participant> participants;

    public Raffle(ArrayList<Participant> participants) {
        this.randomGenerator = new Random();
        this.participants = participants;
    }

    private List<Participant> getParticipantsAttend(){
        List<Participant> attendees = new ArrayList<>();
        for (Participant participant : participants) {
            if(participant.isAttend() && !participant.isRaffled()) //It can be drawn
                attendees.add(participant);
        }
        return attendees;
    }

    private List<Participant> getParticipantsAttendSex(){
        List<Participant> attendees = new ArrayList<>();
        for (Participant participant : participants) {
            if(participant.isAttend() && !participant.isRaffled() && participant.getSex()) //It can be drawn
                attendees.add(participant);
        }
        return attendees;
    }

    public boolean isValid(){
        for (Participant participant : participants) {
            if(participant.isAttend() && !participant.isRaffled())
                return true;
        }
        return false;
    }

    public boolean isValidSex(){
        for (Participant participant : participants) {
            if(participant.isAttend() && !participant.isRaffled() && participant.getSex())
                return true;
        }
        return false;
    }

    public Participant getFortunate() {
        List<Participant> participantsAttend = getParticipantsAttend();

        if(participantsAttend.isEmpty()) {
            return null;
        }

        int index = randomGenerator.nextInt(participantsAttend.size());
        Participant participantFortunate = participantsAttend.get(index);
        participantFortunate.setRaffled(true);
        return participantFortunate;
    }

    public Participant getFortunateSex() {
        List<Participant> participantsAttend = getParticipantsAttendSex();

        if(participantsAttend.isEmpty()) {
            return null;
        }

        int index = randomGenerator.nextInt(participantsAttend.size());
        Participant participantFortunate = participantsAttend.get(index);
        participantFortunate.setRaffled(true);
        return participantFortunate;
    }
}
app/src/main/java/br/com/javace/javou/task/ParticipantPresenceTask.java
public class ParticipantPresenceTask extends AsyncTask<Void, Void, Boolean> {

    private Context mContext;
    private Participant mParticipant;

    public ParticipantPresenceTask(Context context, Participant participant){
        this.mContext = context;
        this.mParticipant = participant;
    }

    @Override
    protected Boolean doInBackground(Void... params) {
        ParticipantDao participantDao = ParticipantDao.getInstance(mContext);
        return participantDao.updatePresence(mParticipant);
    }
}
searchliveo/src/main/java/br/liveo/searchliveo/SearchLiveo.java
public class SearchLiveo extends FrameLayout {

    private Activity mContext;

    private EditText mEdtSearch;

    private ImageView mImgArrowSearch;
    private ImageView mImgVoiceSearch;
    private ImageView mImgCloseSearch;

    private RecyclerView mRecyclerView;
    private RelativeLayout mViewSearch;

    private int mColorPrimaryDark;

    private boolean active = false;
    private boolean isVoice = true;

    private int mColorIcon = -1;
    private int mColorIconArrow = -1;
    private int mColorIconVoice = -1;
    private int mColorIconClose = -1;

    private int mStatusBarHideColor = -1;
    private int mStatusBarShowColor = -1;
    private OnSearchListener mSearchListener;

    private static String SEARCH_TEXT = "SEARCH_TEXT";
    public static int REQUEST_CODE_SPEECH_INPUT = 7777;
    private static String STATE_TO_SAVE = "STATE_TO_SAVE";
    private static String INSTANCE_STATE = "INSTANCE_STATE";

    /**
     * Start context and the listener Search Live library.
     * Use this method when you are using an Activity
     *
     * @param context - Context Activity
     */
    public SearchLiveo with(Context context) {

        if (this.mContext == null) {
            try {
                this.mContext = (Activity) context;
                this.mSearchListener = (OnSearchListener) context;
            } catch (ClassCastException e) {
                throw new ClassCastException(mContext.getString(R.string.warning_listener));
            }
        }else{
            build();
        }

        return this;
    }

    /**
     * Start context and the listener Search Live library.
     * Use this method when you are using an Fragment
     *
     * @param getActivity - Context Fragment
     * @param context - Listener
     */
    public SearchLiveo with(Activity getActivity, OnSearchListener context) {

        if (this.mContext == null) {
            try {
                this.mContext = getActivity;
                this.mSearchListener = context;
            } catch (ClassCastException e) {
                throw new ClassCastException(mContext.getString(R.string.warning_fragment_listener));
            }
        }else{
            build();
        }

        return this;
    }

    public void build(){

        if (this.mSearchListener == null){
            throw new ClassCastException(mContext.getString(R.string.warning_listener));
        }

        try {

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                Resources.Theme theme = this.mContext.getTheme();
                TypedArray typedArray = theme.obtainStyledAttributes(new int[]{android.R.attr.colorPrimaryDark});
                setColorPrimaryDark(typedArray.getResourceId(0, 0));
            }
        }catch (Exception e){
            e.getStackTrace();
        }
    }

    public SearchLiveo(Context context) {
        this(context, null);
    }

    public SearchLiveo(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public SearchLiveo(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        if(!isInEditMode()) {
            init(context);
            initAttribute(context, attrs, defStyleAttr);
        }
    }

    private void init(Context context){
        View view = LayoutInflater.from(context).inflate(R.layout.search_liveo, this, true);

        mEdtSearch = (EditText) view.findViewById(R.id.edt_search);

        mImgArrowSearch = (ImageView) view.findViewById(R.id.img_arrow_search);
        mImgVoiceSearch = (ImageView) view.findViewById(R.id.img_voice_search);

        mImgCloseSearch = (ImageView) view.findViewById(R.id.img_close_search);
        mImgCloseSearch.setVisibility(isVoice() ? View.GONE : View.VISIBLE);

        mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_search_view);

        View toolbarShadow = view.findViewById(R.id.toolbar_shadow);
        toolbarShadow.setVisibility(GONE);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            toolbarShadow.setVisibility(View.VISIBLE);
        }

        mViewSearch = (RelativeLayout) view.findViewById(R.id.view_search);
        mViewSearch.setVisibility(View.INVISIBLE);

        mEdtSearch.setOnKeyListener(onKeyListener);

        mImgArrowSearch.setOnClickListener(onClickSearchArrow);
        mRecyclerView.setOnClickListener(onClickRecyclerView);
        mImgVoiceSearch.setOnClickListener(onClickVoiceSearch);
        mImgCloseSearch.setOnClickListener(onClickCloseSearch);

        mEdtSearch.setOnEditorActionListener(onEditorActionListener);
        mEdtSearch.addTextChangedListener(new OnTextWatcherEdtSearch());
    }

    private void initAttribute(Context context, AttributeSet attributeSet, int defStyleAttr) {
        TypedArray attr = context.obtainStyledAttributes(attributeSet, R.styleable.search_liveo, defStyleAttr, 0);
        if (attr != null) {
            try {

                if (attr.hasValue(R.styleable.search_liveo_search_liveo_hint)) {
                    hint(attr.getString(R.styleable.search_liveo_search_liveo_hint));
                }

                if (attr.hasValue(R.styleable.search_liveo_search_liveo_text_color)) {
                    mEdtSearch.setTextColor(attr.getColor(R.styleable.search_liveo_search_liveo_text_color, -1));
                }

                if (attr.hasValue(R.styleable.search_liveo_search_liveo_hint_color)) {
                    mEdtSearch.setHintTextColor(attr.getColor(R.styleable.search_liveo_search_liveo_hint_color, -1));
                }

                if (attr.hasValue(R.styleable.search_liveo_search_liveo_color_icon)) {
                    setColorIcon(attr.getColor(R.styleable.search_liveo_search_liveo_color_icon, -1));
                }

                if (attr.hasValue(R.styleable.search_liveo_search_liveo_color_arrow)) {
                    setColorIconArrow(attr.getColor(R.styleable.search_liveo_search_liveo_color_arrow, -1));
                }

                if (attr.hasValue(R.styleable.search_liveo_search_liveo_color_voice)) {
                    setColorIconVoice(attr.getColor(R.styleable.search_liveo_search_liveo_color_voice, -1));
                }

                if (attr.hasValue(R.styleable.search_liveo_search_liveo_color_close)) {
                    setColorIconClose(attr.getColor(R.styleable.search_liveo_search_liveo_color_close, -1));
                }

                if (attr.hasValue(R.styleable.search_liveo_search_liveo_background)) {
                    mViewSearch.setBackgroundColor(attr.getColor(R.styleable.search_liveo_search_liveo_background, -1));
                }

                if (attr.hasValue(R.styleable.search_liveo_search_liveo_status_bar_show_color)) {
                    setStatusBarShowColor(attr.getColor(R.styleable.search_liveo_search_liveo_status_bar_show_color, -1));
                }

                if (attr.hasValue(R.styleable.search_liveo_search_liveo_status_bar_hide_color)) {
                    setStatusBarHideColor(attr.getColor(R.styleable.search_liveo_search_liveo_status_bar_hide_color, -1));
                }
            } finally {
                attr.recycle();
            }
        }
    }

    /**
     * Set a new background color. If you do not use this method and standard color is white SearchLiveo.
     * In his layout.xml you can use the "app:searchLiveoBackground="@color/..."" attribute
     *
     * @param resId color attribute - colors.xml file
     */
    public SearchLiveo backgroundResource(int resId){
        mViewSearch.setBackgroundResource(resId);
        return this;
    }

    /**
     * Set a new background color. If you do not use this method and standard color is white SearchLiveo.
     * In his layout.xml you can use the "app:searchLiveoBackground="@color/..."" attribute
     * @param color color attribute - colors.xml file
     */
    public SearchLiveo backgroundColor(int color){
        mViewSearch.setBackgroundColor(ContextCompat.getColor(mContext, color));
        return this;
    }

    /**
     * Set a new text color.
     * In his layout.xml you can use the "app:searchLiveoTextColor="@color/..."" attribute
     * @param color color attribute - colors.xml file
     */
    public SearchLiveo textColor(int color){
        mEdtSearch.setTextColor(ContextCompat.getColor(mContext, color));
        return this;
    };

    /**
     * Set a new hint color.
     * In his layout.xml you can use the "app:searchLiveoHintColor="@color/..."" attribute
     * @param color color attribute - colors.xml file
     */
    public SearchLiveo hintColor(int color){
        mEdtSearch.setHintTextColor(ContextCompat.getColor(mContext, color));
        return this;
    };

    /**
     * Set a new text.
     * @param text "valeu"
     */
    public SearchLiveo text(String text){
        mEdtSearch.setText(text);
        return this;
    };

    /**
     * Set a new hint.
     * In his layout.xml you can use the "app:searchLiveoHint="value"" attribute
     * @param text "valeu"
     */
    public SearchLiveo hint(String text){
        mEdtSearch.setHint(text);
        return this;
    };

    /**
     * Set a new text.
     * @param text string attribute - string.xml file
     */
    public SearchLiveo text(int text){
        mEdtSearch.setText(mContext.getString(text));
        return this;
    };

    /**
     * Set a new hint.
     * In his layout.xml you can use the "app:searchLiveoHint="@string/..."" attribute
     * @param text string attribute - string.xml file
     */
    public SearchLiveo hint(int text){
        mEdtSearch.setHint(mContext.getString(text));
        return this;
    };

    /**
     * Set a new color for all icons (arrow, voice and close).
     * In his layout.xml you can use the "app:searchLiveoColorIcon="@color/..."" attribute
     * @param color color attribute - colors.xml file
     */
    public SearchLiveo colorIcon(int color){
        this.setColorIcon(ContextCompat.getColor(mContext, color));
        return this;
    };

    /**
     * Set a new color for back arrow
     * In his layout.xml you can use the "app:searchLiveoColorArrow="@color/..."" attribute
     * @param color color attribute - colors.xml file
     */
    public SearchLiveo colorIconArrow(int color){
        this.setColorIconArrow(ContextCompat.getColor(mContext, color));
        return this;
    };

    /**
     * Set a new color for voice
     * In his layout.xml you can use the "app:searchLiveoColorVoice="@color/..."" attribute
     * @param color color attribute - colors.xml file
     */
    public SearchLiveo colorIconVoice(int color){
        this.setColorIconVoice(ContextCompat.getColor(mContext, color));
        return this;
    };

    /**
     * Set a new color for close
     * In his layout.xml you can use the "app:searchLiveoColorClose="@color/..."" attribute
     * @param color color attribute - colors.xml file
     */
    public SearchLiveo colorIconClose(int color){
        this.setColorIconClose(ContextCompat.getColor(mContext, color));
        return this;
    };

    /**
     * Set a new color for statusBar when the SearchLiveo is closed
     * In his layout.xml you can use the "app:searchLiveoStatusBarHideColor="@color/..."" attribute
     * @param color color attribute - colors.xml file
     */
    public SearchLiveo statusBarHideColor(int color){
        setStatusBarHideColor(ContextCompat.getColor(mContext, color));
        return this;
    }

    /**
     * Set a new color for statusBar when the SearchLiveo for visible
     * In his layout.xml you can use the "app:searchLiveoStatusBarShowColor="@color/..."" attribute
     * @param color color attribute - colors.xml file
     */
    public SearchLiveo statusBarShowColor(int color){
        setStatusBarShowColor(ContextCompat.getColor(mContext, color));
        return this;
    }

    /**
     * Hide voice icon
     */
    public SearchLiveo hideVoice(){
        setIsVoice(false);
        mImgVoiceSearch.setVisibility(View.GONE);
        return this;
    }

    /**
     * Show voice icon
     */
    public SearchLiveo showVoice(){
        setIsVoice(true);
        mImgVoiceSearch.setVisibility(View.VISIBLE);
        return this;
    }

    private void colorIcon(){
        if (getColorIcon() != -1 && getColorIconArrow() == -1)  {
            mImgArrowSearch.setColorFilter(this.getColorIcon());
        }

        if (getColorIcon() != -1 && getColorIconVoice() == -1)  {
            mImgVoiceSearch.setColorFilter(this.getColorIcon());
        }

        if (getColorIcon() != -1 && getColorIconClose() == -1)  {
            mImgCloseSearch.setColorFilter(this.getColorIcon());
        }
    };

    private void colorIconArrow(){
        if (getColorIconArrow() != -1) {
            mImgArrowSearch.setColorFilter(this.getColorIconArrow());
        }
    };

    private void colorIconVoice(){
        if (this.getColorIconVoice() != -1) {
            mImgVoiceSearch.setColorFilter(this.getColorIconVoice());
        }else{
            mImgVoiceSearch.clearColorFilter();
        }
    };

    private void colorIconClose(){
        if (this.getColorIconClose() != -1) {
            mImgCloseSearch.setColorFilter(this.getColorIconClose());
        }else{
            mImgCloseSearch.clearColorFilter();
        }
    };

    private OnKeyListener onKeyListener = new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                if (keyCode == KeyEvent.KEYCODE_BACK) {
                    hide();
                    return true;
                }
            }
            return false;
        }
    };

    private TextView.OnEditorActionListener onEditorActionListener = new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                hide();
                mContext.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        ((InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE)).
                                hideSoftInputFromWindow(mRecyclerView.getWindowToken(), 0);
                    }
                });
                return true;
            }
            return false;
        }
    };

    private OnClickListener onClickVoiceSearch = new OnClickListener() {
        @Override
        public void onClick(View v) {
            startVoice(mEdtSearch);
        }
    };

    private OnClickListener onClickCloseSearch = new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mEdtSearch.getText().toString().length() != 0) {
                mEdtSearch.setText("");
                mContext.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        ((InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE)).
                                toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
                    }
                });
            }
        }
    };

    private OnClickListener onClickSearchArrow = new OnClickListener() {
        @Override
        public void onClick(View v) {
            hide();
        }
    };

    private OnClickListener onClickRecyclerView = new OnClickListener() {
        @Override
        public void onClick(View v) {
            hide();
        }
    };

    /**
     * If SearchView is active(show), this method returns the value true
     */
    public boolean isActive() {
        return active;
    }

    private void setActive(boolean active) {
        this.active = active;
    }

    public boolean isVoice() {
        return isVoice;
    }

    public void setIsVoice(boolean isVoice) {
        this.isVoice = isVoice;
    }

    public int getStatusBarHideColor() {
        return mStatusBarHideColor;
    }

    public void setStatusBarHideColor(int mStatusBarHideColor) {
        this.mStatusBarHideColor = mStatusBarHideColor;
    }

    public int getStatusBarShowColor() {
        return mStatusBarShowColor;
    }

    public void setStatusBarShowColor(int mStatusBarShowColor) {
        this.mStatusBarShowColor = mStatusBarShowColor;
    }

    private int getColorIcon() {
        return mColorIcon;
    }

    private void setColorIcon(int colorIcon) {
        this.mColorIcon = colorIcon;
        this.colorIcon();
    }

    public int getColorIconArrow() {
        return mColorIconArrow;
    }

    public void setColorIconArrow(int color) {
        this.mColorIconArrow = color;
        this.colorIconArrow();
    }

    public int getColorIconVoice() {
        return mColorIconVoice;
    }

    public void setColorIconVoice(int color) {
        this.mColorIconVoice = color;
        this.colorIconVoice();
    }

    public int getColorIconClose() {
        return mColorIconClose;
    }

    public void setColorIconClose(int color) {
        this.mColorIconClose = color;
        this.colorIconClose();
    }

    private class OnTextWatcherEdtSearch implements TextWatcher {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            try {
                if (mEdtSearch.getText().toString().length() == 0) {
                    mImgCloseSearch.setVisibility(isVoice() ? View.GONE : View.VISIBLE);
                    mImgVoiceSearch.setVisibility(isVoice() ? View.VISIBLE : View.GONE);
                    mImgVoiceSearch.setImageResource(R.drawable.ic_keyboard_voice_color_24dp);
                    colorIconVoice();
                } else {
                    mImgVoiceSearch.setVisibility(View.GONE);
                    mImgCloseSearch.setVisibility(View.VISIBLE);
                    mImgCloseSearch.setImageResource(R.drawable.ic_close_color_24dp);
                    colorIconClose();
                }

                colorIcon();
                colorIconArrow();
                mSearchListener.changedSearch(mEdtSearch.getText().toString());
            } catch (Exception e) {
                e.getStackTrace();
            }
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    }

    /**
     * Hide SearchLiveo
     */
    public void hide() {
        try {
            hideAnimation();
            setActive(false);
        } catch (Exception e) {
            e.getStackTrace();
        }
    }

    /**
     * Show SearchLiveo
     */
    public SearchLiveo show() {
        setActive(true);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

            try {
                showAnimation();
            } catch (ClassCastException e) {
                throw new ClassCastException(mContext.getString(R.string.warning_with));
            }

        } else {

            Animation mFadeIn = AnimationUtils.loadAnimation(mContext.getApplicationContext(), android.R.anim.fade_in);
            mViewSearch.setEnabled(true);
            mViewSearch.setVisibility(View.VISIBLE);
            mViewSearch.setAnimation(mFadeIn);

            mContext.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    ((InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE)).
                            toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
                }
            });
        }

        mEdtSearch.requestFocus();
        return this;
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    private void showAnimation(){
        try {

            if (getStatusBarShowColor() != -1) {
                mContext.getWindow().setStatusBarColor(getStatusBarShowColor());
            }else {
                mContext.getWindow().setStatusBarColor(ContextCompat.getColor(mContext, R.color.search_liveo_primary_dark));
            }

            final Animator animator = ViewAnimationUtils.createCircularReveal(mViewSearch,
                    mViewSearch.getWidth() - (int) dpToPixel(24, this.mContext),
                    (int) dpToPixel(23, this.mContext), 0,
                    (float) Math.hypot(mViewSearch.getWidth(), mViewSearch.getHeight()));
            animator.addListener(new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animation) {
                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    mContext.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            ((InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE)).
                                    toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
                        }
                    });
                }

                @Override
                public void onAnimationCancel(Animator animation) {

                }

                @Override
                public void onAnimationRepeat(Animator animation) {

                }
            });

            animator.setDuration(300);
            animator.start();
        }catch (Exception e){
            e.getStackTrace();
            mContext.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    ((InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE)).
                            toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
                }
            });
        }

        mViewSearch.setVisibility(View.VISIBLE);
    }

    private SearchLiveo hideAnimation() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

            if (getStatusBarHideColor() != -1) {
                mContext.getWindow().setStatusBarColor(getStatusBarHideColor());
            } else {
                mContext.getWindow().setStatusBarColor(getColorPrimaryDark());
            }

            final Animator animatorHide = ViewAnimationUtils.createCircularReveal(mViewSearch,
                    mViewSearch.getWidth() - (int) dpToPixel(24, mContext),
                    (int) dpToPixel(23, mContext),
                    (float) Math.hypot(mViewSearch.getWidth(), mViewSearch.getHeight()), 0);
            animatorHide.addListener(new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animation) {

                    mContext.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            ((InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE)).
                                    hideSoftInputFromWindow(mRecyclerView.getWindowToken(), 0);
                        }
                    });
                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    mViewSearch.setVisibility(View.GONE);
                }

                @Override
                public void onAnimationCancel(Animator animation) {

                }

                @Override
                public void onAnimationRepeat(Animator animation) {

                }
            });
            animatorHide.setDuration(200);
            animatorHide.start();

        } else {

            mContext.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    ((InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE)).
                            hideSoftInputFromWindow(mRecyclerView.getWindowToken(), 0);
                }
            });

            Animation mFadeOut = AnimationUtils.loadAnimation(mContext.getApplicationContext(), android.R.anim.fade_out);
            mViewSearch.setAnimation(mFadeOut);
            mViewSearch.setVisibility(View.INVISIBLE);
        }

        mEdtSearch.setText("");
        mViewSearch.setEnabled(false);
        return this;
    }

    private int getColorPrimaryDark() {
        return mColorPrimaryDark;
    }

    private void setColorPrimaryDark(int mColorPrimaryDark) {
        this.mColorPrimaryDark = ContextCompat.getColor(mContext, mColorPrimaryDark);
    }

    private float dpToPixel(float dp, Context context) {
        Resources resources = context.getResources();
        DisplayMetrics metrics = resources.getDisplayMetrics();
        return dp * (metrics.densityDpi / 160f);
    }

    @Override
    public Parcelable onSaveInstanceState() {
        Bundle bundle = new Bundle();
        bundle.putParcelable(INSTANCE_STATE, super.onSaveInstanceState());
        bundle.putBoolean(STATE_TO_SAVE, this.isActive());

        if (!mEdtSearch.getText().toString().trim().equals("")){
            bundle.putString(SEARCH_TEXT, mEdtSearch.getText().toString());
        }

        return bundle;
    }

    @Override
    public void onRestoreInstanceState(Parcelable state) {

        if (state instanceof Bundle) {
            Bundle bundle = (Bundle) state;
            this.setActive(bundle.getBoolean(STATE_TO_SAVE));

            String text = bundle.getString(SEARCH_TEXT, "");
            if (!text.trim().equals("")){
                mEdtSearch.setText(text);
            }

            if (this.isActive()){
                show();
            }

            state = bundle.getParcelable(INSTANCE_STATE);
        }

        super.onRestoreInstanceState(state);
    }

    private void startVoice(EditText editText) {
        ((InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE)).
                hideSoftInputFromWindow(editText.getWindowToken(), 0);

        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, mContext.getString(R.string.searchview_voice));
        try {
            mContext.startActivityForResult(intent, REQUEST_CODE_SPEECH_INPUT);
        } catch (ActivityNotFoundException a) {
            Toast.makeText(mContext.getApplicationContext(), R.string.not_supported, Toast.LENGTH_SHORT).show();
        }
    }

    public void resultVoice(int requestCode, int resultCode, Intent data){
        if (requestCode == SearchLiveo.REQUEST_CODE_SPEECH_INPUT) {
            if (resultCode == Activity.RESULT_OK && null != data) {
                ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
                mEdtSearch.setText(result.get(0));
            }
        }
    }
}
app/src/main/java/br/com/javace/javou/adapter/ParticipantAdapter.java
public class ParticipantAdapter extends RecyclerView.Adapter<ParticipantAdapter.ViewHolder> {

    private int mBackground;
    private Context mContext;
    private HashSet<Integer> checkedItems;
    private ArrayList<Participant> mParticipants;
    private ArrayList<Participant> mSearchParticipants;

    private static final int ITEM_VIEW_TYPE_ITEM = 1;
    private static final int ITEM_VIEW_TYPE_HEADER = 0;

    private static OnItemClickListener mOnClickListener;
    private static OnItemClickListener mOnItemClickListener;
    private static OnItemLongClickListener mOnItemLongClickListener;

    public ParticipantAdapter(Context context, ArrayList<Participant> participants) {
        this.mContext = context;
        this.mParticipants = participants;
        this.checkedItems = new HashSet<>();
        this.mSearchParticipants = new ArrayList<>();
        this.mSearchParticipants.addAll(this.mParticipants);

        if (context != null) {
            TypedValue mTypedValue = new TypedValue();
            context.getTheme().resolveAttribute(android.R.attr.selectableItemBackground, mTypedValue, true);
            this.mBackground = mTypedValue.resourceId;
        }
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        View mContainer;

        TextView mTitle;
        TextView mName;
        TextView mEmail;
        TextView mShirtSize;

        ViewHolder(View view) {
            super(view);

            mContainer = view;

            mTitle = (TextView) view.findViewById(R.id.txt_title);
            mName = (TextView) view.findViewById(R.id.txt_name);
            mEmail = (TextView) view.findViewById(R.id.txt_email);
            mShirtSize = (TextView) view.findViewById(R.id.txt_shirt_size);

            if (mShirtSize != null) {
                mShirtSize.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        // -1 Refers to the header
                        int position = getAdapterPosition() - 1;
                        if (mOnClickListener != null && position >= 0) {
                            mOnClickListener.onItemClick(v, position);
                        }
                    }
                });
            }

            mContainer.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    // -1 Refers to the header
                    int position = getAdapterPosition() - 1;
                    if (mOnItemClickListener != null && position >= 0) {
                        mOnItemClickListener.onItemClick(v, position);
                    }
                }
            });

            mContainer.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    int position = getAdapterPosition() - 1;
                    if (mOnItemLongClickListener != null && position >= 0) {
                        mOnItemLongClickListener.onItemLongClick(v, position);
                    }
                    return true;
                }
            });
        }
    }

    @Override
    public ParticipantAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view;

        if (viewType == ITEM_VIEW_TYPE_HEADER) {
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.fragment_participant_header, parent, false);
            return new ViewHolder(view);
        }

        view = LayoutInflater.from(parent.getContext()).inflate(R.layout.fragment_participant_item, parent, false);
        view.setBackgroundResource(this.mBackground);
        return new ViewHolder(view);
    }

    private boolean isHeader(int position) {
        return position == 0;
    }

    @Override
    public int getItemViewType(int position) {
        return isHeader(position) ? ITEM_VIEW_TYPE_HEADER : ITEM_VIEW_TYPE_ITEM;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {

        if (mParticipants == null || mParticipants.size() == 0){
            return;
        }

        if (isHeader(position)) {
            holder.mTitle.setText(mParticipants.get(position).getNameEvent());
            return;
        }

        // -1 Refers to the header
        Participant participant = mParticipants.get(position - 1);

        holder.mName.setText(participant.getName());
        holder.mName.setCompoundDrawablesWithIntrinsicBounds(participant.isAttend() ? R.drawable.ic_check_green_18dp : 0, 0, 0, 0);

        holder.mEmail.setText(participant.getEmail());

        if (participant.isGroup()) {
            int shirtSize = participant.getShirtSize();
            holder.mShirtSize.setVisibility(View.VISIBLE);
            GradientDrawable gradientDrawable = (GradientDrawable) holder.mShirtSize.getBackground();
            gradientDrawable.setColor(ContextCompat.getColor(mContext, Util.shirtSizeColor[shirtSize]));
            holder.mShirtSize.setText(this.mContext.getString(Util.shirtSize[shirtSize]));
        }else{
            holder.mShirtSize.setVisibility(View.INVISIBLE);
        }

        if (checkedItems.contains(position)) {
            holder.mContainer.setBackgroundResource(R.drawable.seletor_long_click_item);
        } else {
            holder.mContainer.setBackgroundResource(this.mBackground);
        }
    }

    public void readAttendParticipant(int position, boolean attend){
        mParticipants.get(position).setAttend(attend);
        notifyDataSetChanged();
    }

    public void remove(int position){
        mParticipants.remove(position);
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        // +1 Refers to the header
        return (mParticipants == null ? 0 : mParticipants.size()+1);
    }

    public void setOnClickListener(OnItemClickListener onClickListener) {
        mOnClickListener = onClickListener;
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        mOnItemClickListener = onItemClickListener;
    }

    public void setOnItemLongClickListener(OnItemLongClickListener onItemLongClickListener) {
        mOnItemLongClickListener = onItemLongClickListener;
    }

    public void resetarCheck() {
        this.checkedItems.clear();
        this.notifyDataSetChanged();
    }

    public void setChecked(int position, boolean checked) {
        resetarCheck();

        if (checked) {
            this.checkedItems.add(position);
        } else {
            this.checkedItems.remove(position);
        }

        this.notifyDataSetChanged();
    }

    public void searchParticipantes(CharSequence charText) {

        charText = Util.removeAccent((String) charText).toLowerCase(Locale.getDefault());

        mParticipants.clear();
        if (charText.length() == 0) {
            mParticipants.addAll(mSearchParticipants);
        } else {
            for (Participant participant: mSearchParticipants) {
                String name = Util.removeAccent(participant.getName());
                if (name.toLowerCase(Locale.getDefault()).contains(charText)) {
                    mParticipants.add(participant);
                }
            }
        }

        notifyDataSetChanged();
    }
}
app/src/main/java/br/com/javace/javou/ui/activity/NewParticipantActivity.java
public class NewParticipantActivity extends BaseActivity{

    private int mShirtSize = 0;
    private ProgressDialog mDialog;
    private Participant mParticipant;

    @BindView(R.id.img_sex) ImageView mImgSex;
    @BindView(R.id.toolbar) Toolbar mToolbar;
    @BindView(R.id.sw_sex) SwitchCompat mSwSex;

    @BindView(R.id.edt_code) EditText mEdtCode;
    @BindView(R.id.edt_name) EditText mEdtName;
    @BindView(R.id.edt_email) EditText mEdtEmail;
    @BindView(R.id.edt_phone) EditText mEdtPhone;
    @BindView(R.id.edt_company) EditText mEdtCompany;
    @BindView(R.id.sw_attend) SwitchCompat mSwAttend;

    @BindView(R.id.txt_shirt_size_p) TextView mTxtShirtSizeP;
    @BindView(R.id.txt_shirt_size_m) TextView mTxtShirtSizeM;
    @BindView(R.id.txt_shirt_size_g) TextView mTxtShirtSizeG;
    @BindView(R.id.txt_shirt_size_gg) TextView mTxtShirtSizeGG;
    @BindView(R.id.txt_shirt_size_eg) TextView mTxtShirtSizeEG;

    @BindView(R.id.layout_code) LinearLayout mLayoutCode;
    @BindView(R.id.layout_name) LinearLayout mLayoutName;
    @BindView(R.id.layout_email) LinearLayout mLayoutEmail;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_participant);
        ButterKnife.bind(this);

        mToolbar.setTitle(getString(R.string.new_participant));
        mToolbar.setNavigationIcon(R.drawable.ic_done_white_24dp);
        this.setSupportActionBar(mToolbar);

        setupOnClickListener();
        if (savedInstanceState != null){
            mShirtSize = savedInstanceState.getInt(Constant.PARTICIPANT_shirtSize, 0);
        }

        boolean isInsert = getIntent().getExtras().getBoolean(Constant.INSERT, false);
        if (!isInsert){
            mParticipant = getIntent().getExtras().getParcelable(Constant.PARTICIPANT);
            setupUpdate(mParticipant);
        }

        colorDefaultShirtSize(mShirtSize);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
	}

    private void setupUpdate(Participant participant){
        mEdtCode.setEnabled(false);
        mEdtCode.setText(String.valueOf(participant.getCode()));
        mEdtName.setText(participant.getName());
        mEdtPhone.setText(participant.getPhone());
        mEdtEmail.setText(participant.getEmail());
        mShirtSize = participant.getShirtSize();
        mSwAttend.setChecked(participant.isAttend());
        mSwSex.setChecked(participant.isSex());
        mEdtCompany.setText(participant.getCompany());
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu, menu);
        menu.findItem(R.id.menu_raffle).setVisible(false);
        menu.findItem(R.id.menu_delete).setVisible(false);
        menu.findItem(R.id.menu_search).setVisible(false);
        menu.findItem(R.id.menu_send).setVisible(false);
        menu.findItem(R.id.menu_resume).setVisible(false);
        return true;
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putInt(Constant.PARTICIPANT_shirtSize, mShirtSize);
    }

    private CompoundButton.OnCheckedChangeListener onCheckedAttend = new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mSwAttend.setCompoundDrawablesWithIntrinsicBounds(isChecked ? R.drawable.ic_check_green_18dp : 0, 0, 0, 0);
        }
    };

    private CompoundButton.OnCheckedChangeListener onCheckedSex = new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mSwSex.setText(isChecked ? R.string.female : R.string.male);
            mImgSex.setColorFilter(ContextCompat.getColor(NewParticipantActivity.this, isChecked ? R.color.shirt_size_g : R.color.shirt_size_m));
            mImgSex.setImageDrawable(ContextCompat.getDrawable(NewParticipantActivity.this, isChecked ? R.drawable.ic_favorite_grey600_24dp : R.drawable.ic_android_grey600_24dp));

            if (isChecked){
                YoYo.with(Techniques.Landing).playOn(mImgSex);
            }
        }
    };

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()){
            case android.R.id.home:
                    if (validation()){
                        if (mParticipant == null) {
                            saveParticipant();
                        }else{
                            updateParticipant();
                        }
                    }
                break;

            case R.id.menu_discart:
                finish(ActivityAnimation.SLIDE_RIGHT);
                break;
        }

        return true;
    }

    private void setupOnClickListener(){
        mSwAttend.setOnCheckedChangeListener(onCheckedAttend);
        mSwAttend.setChecked(true);

        mSwSex.setOnCheckedChangeListener(onCheckedSex);
        mSwSex.setChecked(false);

        mTxtShirtSizeP.setOnClickListener(onClickShirtSize);
        mTxtShirtSizeM.setOnClickListener(onClickShirtSize);
        mTxtShirtSizeG.setOnClickListener(onClickShirtSize);
        mTxtShirtSizeGG.setOnClickListener(onClickShirtSize);
        mTxtShirtSizeEG.setOnClickListener(onClickShirtSize);
    }

    private boolean validation(){
		boolean result = true;

        if (mEdtCode.getText().toString().trim().equals("")){
            result = false;
            mEdtCode.requestFocus();
            YoYo.with(Techniques.Shake).playOn(mLayoutCode);
            Toast.makeText(getApplicationContext(), R.string.warning_no_code, Toast.LENGTH_SHORT).show();
        }else if (mEdtName.getText().toString().trim().equals("")){
            result = false;
            mEdtName.requestFocus();
            YoYo.with(Techniques.Shake).playOn(mLayoutName);
            Toast.makeText(getApplicationContext(), R.string.warning_no_name, Toast.LENGTH_SHORT).show();
        }else if (mEdtEmail.getText().toString().trim().equals("")){
            result = false;
            mEdtEmail.requestFocus();
            YoYo.with(Techniques.Shake).playOn(mLayoutEmail);
            Toast.makeText(getApplicationContext(), R.string.warning_no_email, Toast.LENGTH_SHORT).show();
        }

		return result;
	}

    private void saveParticipant(){
        showDialog();

        Participant participant = new Participant();
        participant.setCode(Integer.valueOf(mEdtCode.getText().toString()));
        participant.setName(mEdtName.getText().toString());
        participant.setPhone(mEdtPhone.getText().toString());
        participant.setEmail(mEdtEmail.getText().toString());
        participant.setShirtSize(mShirtSize);
        participant.setAttend(mSwAttend.isChecked());
        participant.setNameEvent(Constant.NAME_EVENT);
        participant.setBirthDate("");
        participant.setRaffled(false);
        participant.setSex(mSwSex.isChecked());
        participant.setCompany(mEdtCompany.getText().toString());

        new ParticipantInsertTask(this, participant){
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                showDialog();
            }

            @Override
            protected void onPostExecute(Boolean result) {
                super.onPostExecute(result);

                if (result){
                    Intent intent = new Intent();
                    intent.putExtra(Constant.PARTICIPANT, true);
                    setResult(0, intent);
                    finish(ActivityAnimation.SLIDE_RIGHT);
                    Toast.makeText(getApplicationContext(), R.string.warning_save_participante, Toast.LENGTH_SHORT).show();
                }else{
                    Toast.makeText(getApplicationContext(), R.string.error_save_participante, Toast.LENGTH_SHORT).show();
                }

                hideDialog();
            }
        }.execute();
    }

    private void updateParticipant(){
        showDialog();

        Participant participant = new Participant();
        participant.setId(mParticipant.getId());
        participant.setCode(Integer.valueOf(mEdtCode.getText().toString()));
        participant.setName(mEdtName.getText().toString());
        participant.setPhone(mEdtPhone.getText().toString());
        participant.setEmail(mEdtEmail.getText().toString());
        participant.setShirtSize(mShirtSize);
        participant.setAttend(mSwAttend.isChecked());
        participant.setNameEvent(mParticipant.getNameEvent());
        participant.setBirthDate(mParticipant.getBirthDate());
        participant.setRaffled(mParticipant.isRaffled());
        participant.setSex(mSwSex.isChecked());
        participant.setCompany(mEdtCompany.getText().toString());

        new ParticipantUpdateTask(this, participant){
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                showDialog();
            }

            @Override
            protected void onPostExecute(Boolean result) {
                super.onPostExecute(result);

                if (result){
                    Intent intent = new Intent();
                    intent.putExtra(Constant.PARTICIPANT, true);
                    setResult(0, intent);
                    finish(ActivityAnimation.SLIDE_RIGHT);
                    Toast.makeText(getApplicationContext(), R.string.warning_save_participante, Toast.LENGTH_SHORT).show();
                }else{
                    Toast.makeText(getApplicationContext(), R.string.error_save_participante, Toast.LENGTH_SHORT).show();
                }

                hideDialog();
            }
        }.execute();
    }

    private View.OnClickListener onClickShirtSize = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            resetColorShirtSize();

            switch (v.getId()){

                case R.id.txt_shirt_size_p:
                    mShirtSize = 0;
                    break;

                case R.id.txt_shirt_size_m:
                    mShirtSize = 1;
                    break;

                case R.id.txt_shirt_size_g:
                    mShirtSize = 2;
                    break;

                case R.id.txt_shirt_size_gg:
                    mShirtSize = 3;
                    break;

                case R.id.txt_shirt_size_eg:
                    mShirtSize = 4;
                    break;

            }

            colorDefaultShirtSize(mShirtSize);
        }
    };

    private void resetColorShirtSize(){
        GradientDrawable gradientDrawable = (GradientDrawable) mTxtShirtSizeP.getBackground();
        gradientDrawable.setColor(ContextCompat.getColor(this, R.color.divider));

        gradientDrawable = (GradientDrawable) mTxtShirtSizeM.getBackground();
        gradientDrawable.setColor(ContextCompat.getColor(this, R.color.divider));

        gradientDrawable = (GradientDrawable) mTxtShirtSizeG.getBackground();
        gradientDrawable.setColor(ContextCompat.getColor(this, R.color.divider));

        gradientDrawable = (GradientDrawable) mTxtShirtSizeGG.getBackground();
        gradientDrawable.setColor(ContextCompat.getColor(this, R.color.divider));

        gradientDrawable = (GradientDrawable) mTxtShirtSizeEG.getBackground();
        gradientDrawable.setColor(ContextCompat.getColor(this, R.color.divider));
    }

    private void colorDefaultShirtSize(int shirtSize){
        resetColorShirtSize();
        GradientDrawable gradientDrawable;

        switch (shirtSize) {
            case 0:
                gradientDrawable = (GradientDrawable) mTxtShirtSizeP.getBackground();
                YoYo.with(Techniques.Landing).withListener(new AnimatorShirtSize(gradientDrawable, shirtSize)).playOn(mTxtShirtSizeP);
                break;

            case 1:
                gradientDrawable = (GradientDrawable) mTxtShirtSizeM.getBackground();
                YoYo.with(Techniques.Landing).withListener(new AnimatorShirtSize(gradientDrawable, shirtSize)).playOn(mTxtShirtSizeM);
                break;

            case 2:
                gradientDrawable = (GradientDrawable) mTxtShirtSizeG.getBackground();
                YoYo.with(Techniques.Landing).withListener(new AnimatorShirtSize(gradientDrawable, shirtSize)).playOn(mTxtShirtSizeG);
                break;

            case 3:
                gradientDrawable = (GradientDrawable) mTxtShirtSizeGG.getBackground();
                YoYo.with(Techniques.Landing).withListener(new AnimatorShirtSize(gradientDrawable, shirtSize)).playOn(mTxtShirtSizeGG);
                break;

            case 4:
                gradientDrawable = (GradientDrawable) mTxtShirtSizeEG.getBackground();
                YoYo.with(Techniques.Landing).withListener(new AnimatorShirtSize(gradientDrawable, shirtSize)).playOn(mTxtShirtSizeEG);
                break;
        }
    }

    private class AnimatorShirtSize implements Animator.AnimatorListener{

        private int mPosition;
        private GradientDrawable mGradientDrawable;

        public AnimatorShirtSize(GradientDrawable gradientDrawable, int position){
            this.mPosition = position;
            this.mGradientDrawable = gradientDrawable;
        }

        @Override
        public void onAnimationStart(Animator animation) {
            if (mGradientDrawable != null) {
                mGradientDrawable.setColor(ContextCompat.getColor(NewParticipantActivity.this, Util.shirtSizeColor[mPosition]));
            }
        }

        @Override
        public void onAnimationEnd(Animator animation) {
        }

        @Override
        public void onAnimationCancel(Animator animation) {

        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }
    }

    private void showDialog() {
        mDialog = ProgressDialog.show(this, getString(R.string.wait),
                getString(R.string.warning_save_wait_participante));
    }

    private void hideDialog(){
        if (mDialog != null){
            mDialog.dismiss();
        }
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        finish(ActivityAnimation.SLIDE_RIGHT);
    }
}
app/src/main/java/br/com/javace/javou/ui/activity/RaffleActivity.java
public class RaffleActivity extends BaseActivity {

    private boolean isFinishOk = false;
    private Participant mParticipantFortunate;
    @BindView(R.id.animated_load) AnimatedCircleLoadingView mAnimatedLoad;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_raffle_main);
        ButterKnife.bind(this);

        mParticipantFortunate =  getIntent().getExtras().getParcelable(Constant.PARTICIPANT);
        mAnimatedLoad.setOnClickListener(onClickAnimLoad);
        startPercentMockThread();
    }

    private View.OnClickListener onClickAnimLoad = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (isFinishOk) {
                isFinishOk = false;
                Toast.makeText(getApplicationContext(), "Terminou", Toast.LENGTH_SHORT).show();
            }
        }
    };

    private void startLoading() {
        mAnimatedLoad.startDeterminate();
    }

    private void startPercentMockThread() {
        startLoading();
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1500);
                    for (int i = 0; i <= 100; i++) {
                        Thread.sleep(10);
                        changePercent(i);
                    }
                    Thread.sleep(3000);
                    ParticipantDao participantDao = new ParticipantDao(getApplicationContext());
                    participantDao.updateAsRaffled(mParticipantFortunate);
                    Intent intent = new Intent(getBaseContext(), ParticipantFortunateActivity.class);
                    intent.putExtra(Constant.PARTICIPANT, mParticipantFortunate);
                    startActivityForResult(intent, 0, BaseActivity.ActivityAnimation.SLIDE_LEFT);
                    finish();

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };

        new Thread(runnable).start();
    }

    private void changePercent(final int percent) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (mAnimatedLoad != null) {
                    mAnimatedLoad.setPercent(percent);

                    if (percent == 100){
                        isFinishOk = true;
                    }
                }
            }
        });
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
    }
}
app/src/main/java/br/com/javace/javou/task/ParticipantTask.java
public class ParticipantTask extends AsyncTask<Void, Void, ArrayList<Participant>> {

    private Context mContext;
    public ParticipantTask(Context context){
        this.mContext = context;
    }

    @Override
    protected ArrayList<Participant> doInBackground(Void... params) {
        ParticipantDao participantDao = ParticipantDao.getInstance(mContext);
        return participantDao.getAll();
    }
}


Question: import android.Manifest;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.ActivityCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.view.ActionMode;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import com.daimajia.androidanimations.library.Techniques;
import com.daimajia.androidanimations.library.YoYo;
import com.nineoldandroids.animation.Animator;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import br.com.javace.javou.R;
import br.com.javace.javou.adapter.ParticipantAdapter;
import br.com.javace.javou.dao.ParticipantDao;
import br.com.javace.javou.interfaces.OnItemClickListener;
import br.com.javace.javou.interfaces.OnItemLongClickListener;
import br.com.javace.javou.interfaces.OnScrollListener;
import br.com.javace.javou.model.participant.Participant;
import br.com.javace.javou.model.raffle.Raffle;
import br.com.javace.javou.task.ParticipantDeleteTask;
import br.com.javace.javou.task.ParticipantPresenceTask;
import br.com.javace.javou.task.ParticipantSendTask;
import br.com.javace.javou.task.ParticipantTask;
import br.com.javace.javou.ui.activity.MainActivity;
import br.com.javace.javou.ui.activity.NewParticipantActivity;
import br.com.javace.javou.ui.activity.ParticipantDetailActivity;
import br.com.javace.javou.ui.activity.ParticipantFortunateActivity;
import br.com.javace.javou.ui.activity.RaffleActivity;
import br.com.javace.javou.ui.activity.ResumeActivity;
import br.com.javace.javou.ui.base.BaseActivity;
import br.com.javace.javou.ui.base.BaseFragment;
import br.com.javace.javou.util.Constant;
import br.liveo.searchliveo.SearchLiveo;
import br.liveo.searchliveo.interfaces.OnSearchListener;
import butterknife.BindView;
import butterknife.ButterKnife;
        if (savedInstanceState == null){
            loadParticipant();
        }else{
            isActionMode = savedInstanceState.getBoolean(Constant.ACTION_MODE);
            mParticipants = savedInstanceState.getParcelableArrayList(Constant.PARTICIPANT);

            if (getParticipants() != null){
                resultAdapter(getParticipants());
            }

            if (isActionMode){
                mPositionActionMode = savedInstanceState.getInt(Constant.POSITION);
                showActionMode(mPositionActionMode);
            }
        }
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putBoolean(Constant.ACTION_MODE, isActionMode);
        outState.putInt(Constant.POSITION, mPositionActionMode);
        outState.putParcelableArrayList(Constant.PARTICIPANT, getParticipants());
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        // TODO Auto-generated method stub
        super.onCreateOptionsMenu(menu, inflater);
        inflater.inflate(R.menu.menu, menu);

        menu.findItem(R.id.menu_discart).setVisible(false);
        menu.findItem(R.id.menu_delete).setVisible(false);
        isSearchView = false;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // TODO Auto-generated method stub
        switch (item.getItemId()) {
            case R.id.menu_search:
                isSearchView = true;
                mSearchLiveo.show();
                break;
            case R.id.menu_raffle:
                raffleParticipant(true);
                break;

            case R.id.menu_woman:
                raffleParticipant(false);
                break;
            case R.id.menu_send:
                if (checkPermission()) {
                    generateSendingFile();
                }
                break;
            case R.id.menu_resume:
                generateResume();
                break;
        }
        return true;
    }

    private void generateResume() {
        Intent intent = new Intent(getActivity(), ResumeActivity.class);
        startActivityForResult(intent, 0, BaseActivity.ActivityAnimation.SLIDE_LEFT);
    }

    private void loadParticipant(){
        mEndlessListener.resetEndlessRecyclerView();
        new ParticipantTask(getActivity()){

            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                mSwipeRefreshLayout.setRefreshing(true);
            }

            @Override
            protected void onPostExecute(ArrayList<Participant> participants) {
                super.onPostExecute(participants);

                if (participants != null && participants.size() > 0){
                    mParticipants = new ArrayList<>();
                    mParticipants = participants;

                    resultAdapter(mParticipants);
                }

                mSwipeRefreshLayout.setRefreshing(false);
            }
        }.execute();

    }

    private SwipeRefreshLayout.OnRefreshListener onRefresh = new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            loadParticipant();
        }
    };

    private void resultAdapter(ArrayList<Participant> participants){
        mParticipantAdapter = new ParticipantAdapter(getActivity(), participants);
        getParticipantAdapter().setOnClickListener(onClickListener);
        getParticipantAdapter().setOnItemClickListener(onItemClickListener);
        getParticipantAdapter().setOnItemLongClickListener(onItemLongClickListener);
        mRecyclerView.setAdapter(getParticipantAdapter());
    }

    private void raffleParticipant(boolean isMan) {
        if (mParticipants != null && mParticipants.size() > 0) {
            Raffle raffle = new Raffle(mParticipants);

            if (raffle.isValid() && isMan) {

                Participant participant = raffle.getFortunate();
                ParticipantDao participantDao = new ParticipantDao(getActivity());
                participantDao.updateAsRaffled(participant);

Answer:                 Intent intent = new Intent(getActivity(), ParticipantFortunateActivity.class);