Example usage for android.view ViewGroup setOnClickListener

List of usage examples for android.view ViewGroup setOnClickListener

Introduction

In this page you can find the example usage for android.view ViewGroup setOnClickListener.

Prototype

public void setOnClickListener(@Nullable OnClickListener l) 

Source Link

Document

Register a callback to be invoked when this view is clicked.

Usage

From source file:ca.taglab.PictureFrame.ScreenSlidePageFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // Inflate the layout containing a title and body text.
    final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_screen_slide_page, container,
            false);/*from   w w  w .  j a va 2s  .c o m*/

    Bitmap picture = BitmapFactory.decodeFile(mImgPath);
    rootView.setBackground(new BitmapDrawable(getResources(), picture));

    mConfirmation = (ImageView) rootView.findViewById(R.id.confirm);

    ((TextView) rootView.findViewById(R.id.name)).setText(mName);
    rootView.findViewById(R.id.control).getBackground().setAlpha(200);

    optionsOpen = false;

    mMsgHistory = rootView.findViewById(R.id.msg);
    mMsgHistory.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getActivity(), MessagesActivity.class);
            intent.putExtra("user_name", mName);
            intent.putExtra("user_id", mId);
            intent.putExtra("owner_id", mOwnerId);
            startActivity(intent);
            hideOptions();
        }
    });

    mPhoto = rootView.findViewById(R.id.photo);
    mPhoto.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                String filename = String.valueOf(System.currentTimeMillis()) + ".jpg";
                ContentValues values = new ContentValues();
                values.put(MediaStore.Images.Media.TITLE, filename);
                mCapturedImageURI = getActivity().getContentResolver()
                        .insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);

                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);
                startActivityForResult(intent, CAPTURE_PICTURE);
                hideOptions();
            } catch (Exception e) {
                Log.e(TAG, "Camera intent failed");
            }
        }
    });

    mVideo = rootView.findViewById(R.id.video);
    mVideo.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                String filename = String.valueOf(System.currentTimeMillis()) + ".3gp";
                ContentValues values = new ContentValues();
                values.put(MediaStore.Video.Media.TITLE, filename);
                mCapturedVideoURI = getActivity().getContentResolver()
                        .insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, values);

                Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedVideoURI);
                startActivityForResult(intent, CAPTURE_VIDEO);
                hideOptions();
            } catch (Exception e) {
                Log.e(TAG, "Video intent failed");
            }
        }
    });

    mAudio = rootView.findViewById(R.id.audio);
    mAudio.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                Intent intent = new Intent(getActivity(), AudioRecorderActivity.class);
                startActivityForResult(intent, CAPTURE_AUDIO);
                hideOptions();
            } catch (Exception e) {
                Log.e(TAG, "Audio intent failed");
            }
        }
    });

    mWave = rootView.findViewById(R.id.wave);
    mWave.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                new SendEmailAsyncTask(getActivity(), mEmail, "PictureFrame: I'm thinking of you",
                        "Wave sent via PictureFrame", null).execute();
                //Toast.makeText(getActivity(), "Wave sent to: " + mEmail, Toast.LENGTH_SHORT).show();
                hideOptions();
                messageSent(v);
            } catch (Exception e) {
                Log.e("SendEmailAsyncTask", e.getMessage(), e);
                //Toast.makeText(getActivity(), "Wave to " + mEmail + " failed", Toast.LENGTH_SHORT).show();
            }
        }
    });

    mCancel = rootView.findViewById(R.id.close);

    mPhoto.getBackground().setAlpha(200);
    mVideo.getBackground().setAlpha(200);
    mAudio.getBackground().setAlpha(200);
    mWave.getBackground().setAlpha(200);

    mShortAnimationDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);
    mLongAnimationDuration = getResources().getInteger(android.R.integer.config_longAnimTime);

    rootView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!optionsOpen)
                showOptions();
        }
    });

    mCancel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (optionsOpen)
                hideOptions();
        }
    });

    Cursor unread = getActivity().getContentResolver().query(UserContentProvider.MESSAGE_CONTENT_URI,
            MessageTable.PROJECTION,
            MessageTable.COL_TO_ID + "=? AND " + MessageTable.COL_FROM_ID + "=? AND " + MessageTable.COL_READ
                    + "=?",
            new String[] { Long.toString(mOwnerId), Long.toString(mId), Long.toString(0) }, null);
    if (unread != null && unread.moveToFirst()) {
        rootView.findViewById(R.id.notification).setVisibility(View.VISIBLE);
        rootView.findViewById(R.id.notification).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), MessagesActivity.class);
                intent.putExtra("user_name", mName);
                intent.putExtra("user_id", mId);
                intent.putExtra("owner_id", mOwnerId);
                startActivity(intent);
                v.setVisibility(View.INVISIBLE);
            }
        });
    }
    if (unread != null) {
        unread.close();
    }

    return rootView;
}