Java Code Examples for android.view.ViewGroup#setOnClickListener()

The following examples show how to use android.view.ViewGroup#setOnClickListener() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: MxVideoPlayer   File: MxVideoPlayer.java    License: Apache License 2.0 6 votes vote down vote up
public void initView(Context context) {
    View.inflate(context, getLayoutId(), this);
    mPlayControllerButton = (ImageView) findViewById(R.id.mx_start);
    mFullscreenButton = (ImageView) findViewById(R.id.mx_fullscreen);
    mProgressBar = (SeekBar) findViewById(R.id.mx_progress);
    mCurrentTimeTextView = (TextView) findViewById(R.id.mx_current_time);
    mTotalTimeTextView = (TextView) findViewById(R.id.mx_total_time);
    mBottomContainer = (ViewGroup) findViewById(R.id.mx_layout_bottom);
    mTextureViewContainer = (ViewGroup) findViewById(R.id.mx_surface_container);
    mTopContainer = (ViewGroup) findViewById(R.id.mx_layout_top);
    mCacheImageView = (MxImageView) findViewById(R.id.mx_cache);

    mPlayControllerButton.setOnClickListener(this);
    if (mFullscreenButton != null) {
        mFullscreenButton.setOnClickListener(this);
    }
    mProgressBar.setOnSeekBarChangeListener(this);
    mBottomContainer.setOnClickListener(this);
    mTextureViewContainer.setOnClickListener(this);

    mTextureViewContainer.setOnTouchListener(this);
    mScreenWidth = getContext().getResources().getDisplayMetrics().widthPixels;
    mScreenHeight = getContext().getResources().getDisplayMetrics().heightPixels;
    mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
    mHandler = new Handler();
}
 
Example 2
private void addStrokeDots(int count) {
    for (int i = 0; i < count; i++) {
        ViewGroup dot = buildDot(true);
        final int finalI = i;
        dot.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (dotsClickable && viewPager != null && viewPager.getAdapter() != null && finalI < viewPager.getAdapter().getItemCount()) {
                    viewPager.setCurrentItem(finalI, true);
                }
            }
        });

        strokeDots.add((ImageView) dot.findViewById(R.id.worm_dot));
        strokeDotsLinearLayout.addView(dot);
    }
}
 
Example 3
private void addStrokeDots(int count) {
    for (int i = 0; i < count; i++) {
        ViewGroup dot = buildDot(true);
        final int finalI = i;
        dot.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (dotsClickable && viewPager != null && viewPager.getAdapter() != null && finalI < viewPager.getAdapter().getItemCount()) {
                    viewPager.setCurrentItem(finalI, true);
                }
            }
        });

        strokeDots.add((ImageView) dot.findViewById(R.id.spring_dot));
        strokeDotsLinearLayout.addView(dot);
    }
}
 
Example 4
@Override
protected void onBindViewHolder(RecyclerView.ViewHolder holder, Cursor cursor) {
    ListViewHolder listViewHolder = (ListViewHolder) holder;
    final ImageFolderBean imageFolderBean = ImageFolderBean.valueOf(cursor);
    ViewGroup viewGroup = listViewHolder.mItemView;
    viewGroup.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mOnItemClickListener != null) {
                mOnItemClickListener.onClick(imageFolderBean);
            }
        }
    });
    listViewHolder.mNameView.setText(imageFolderBean.floderName);
    listViewHolder.mCountView.setText("" + imageFolderBean.count);
    VenvyImageInfo venvyImageInfo =
            new VenvyImageInfo.Builder()
                    .setResizeWidth(70)
                    .setResizeHeight(70)
                    .setUrl(imageFolderBean.firstImagePath)
                    .isLocalMedia(true).build();
    listViewHolder.mImageView.loadImage(venvyImageInfo);
}
 
Example 5
/**
 * 根据屏幕方向创建按钮
 */
public void createActionButton() {
    if (!actionBtnArray.isEmpty()) actionBtnArray.clear();
    for (int rowIndex = 0; rowIndex < currentPageRow; rowIndex++)
        for (int colIndex = 0; colIndex < currentPageCol; colIndex++) {
            View view = LayoutInflater.from(getContext()).inflate(R.layout.layout_action_button, null);
            ViewGroup actionBtn = view.findViewById(R.id.actionBtn);
            actionBtn.setTag(getButtonIndex(rowIndex, colIndex));
            actionBtn.setOnClickListener(this);
            GridLayout.LayoutParams gridLayoutParam = new GridLayout.LayoutParams(
                    GridLayout.spec(rowIndex, 1f),
                    GridLayout.spec(colIndex, 1f)
            );
            gridLayoutParam.setMargins(1, 1, 1, 1);
            gridLayoutParam.height = 0;
            gridLayoutParam.width = 0;
            addView(view, gridLayoutParam);
            UiButtonItem item = new UiButtonItem();
            item.button = actionBtn;
            item.imageView = view.findViewById(R.id.actionBtnBg);
            item.textView = view.findViewById(R.id.actionBtnText);
            actionBtnArray.put(getButtonIndex(rowIndex, colIndex), item);
        }
}
 
Example 6
public View onCreateView(LayoutInflater inflater, ViewGroup container,
		Bundle savedInstanceState) {
	if (container == null) {
		// Currently in a layout without a container, so no
		// reason to create our view.
		return null;
	}
	View theView = inflater.inflate(R.layout.picture, null);
	mImage = (ImageView) theView.findViewById(R.id.image);
	mNotes = (ViewGroup) theView.findViewById(R.id.notes);
	mDescription = (TextView) theView.findViewById(R.id.description);
	mDay = (TextView) theView.findViewById(R.id.day);
	mTitle = (TextView) theView.findViewById(R.id.title);
	mHeader = (ViewGroup) theView.findViewById(R.id.header);
	mNotes.setAlpha(0);

	refreshPictureInfo();
	mImage.setOnClickListener(notesClickListener);
	mHeader.setOnClickListener(notesClickListener);

	return theView;
}
 
Example 7
Source Project: hashtag-view   File: HashtagView.java    License: MIT License 6 votes vote down vote up
private View inflateItemView(final ItemData item) {
    ViewGroup itemLayout = (ViewGroup) LayoutInflater.from(getContext()).inflate(R.layout.layout_item, this, false);
    itemLayout.setBackgroundResource(backgroundDrawable);
    itemLayout.setPadding(itemPaddingLeft, itemPaddingTop, itemPaddingRight, itemPaddingBottom);
    itemLayout.setMinimumWidth(minItemWidth);
    try {
        if (foregroundDrawable != 0)
            ((FrameLayout) itemLayout).setForeground(ContextCompat.getDrawable(getContext(), foregroundDrawable));
    } catch (Exception e) {
        e.printStackTrace();
    }

    itemLayout.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (isInSelectMode) {
                handleSelection(item);
            } else {
                handleClick(item);
            }
        }
    });
    return itemLayout;
}
 
Example 8
Source Project: input-samples   File: SettingsActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void setupSettingsSwitch(int containerId, int labelId, int switchId, boolean checked,
        CompoundButton.OnCheckedChangeListener checkedChangeListener) {
    ViewGroup container = findViewById(containerId);
    String switchLabel = ((TextView) container.findViewById(labelId)).getText().toString();
    final Switch switchView = container.findViewById(switchId);
    switchView.setContentDescription(switchLabel);
    switchView.setChecked(checked);
    container.setOnClickListener((view) -> switchView.performClick());
    switchView.setOnCheckedChangeListener(checkedChangeListener);
}
 
Example 9
Source Project: input-samples   File: SettingsActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void setupSettingsButton(int containerId, int labelId, int imageViewId,
        final View.OnClickListener onClickListener) {
    ViewGroup container = findViewById(containerId);
    TextView buttonLabel = container.findViewById(labelId);
    String buttonLabelText = buttonLabel.getText().toString();
    ImageView imageView = container.findViewById(imageViewId);
    imageView.setContentDescription(buttonLabelText);
    container.setOnClickListener(onClickListener);
}
 
Example 10
Source Project: Jide-Note   File: UserCenterActivity.java    License: MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_user_center);
    initToolbar();

    tencentSDKHelper = TencentSDKHelper.getInstance(this.getApplicationContext());

    userInfoLayout = (ViewGroup) findViewById(R.id.user_info_layout);
    userNoteCountLayout = (ViewGroup) findViewById(R.id.user_note_count_layout);
    userLogOutLayout = (ViewGroup) findViewById(R.id.user_logout_layout);
    userInfoLayout.setOnClickListener(this);
    userNoteCountLayout.setOnClickListener(this);
    userLogOutLayout.setOnClickListener(this);
}
 
Example 11
Source Project: AndroidMathKeyboard   File: FormulaView.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 设置可点击控件
 *
 * @param view
 * @param isFirst 初始化时,是否被选中
 * @param isRoot  是否是布局根节点
 */
public void setCanClickView(ViewGroup view, boolean isFirst, boolean isRoot) {
    clickViews.put(getResources().getResourceEntryName(view.getId()), view);
    view.setOnClickListener(clickListener);

    if (isFirst) {
        view.setBackgroundColor(Color.parseColor("#CC33B5E5"));
        notifyClicked(getResources().getResourceEntryName(view.getId()));
    }

    if (isRoot) {
        rootView = view;
    }
}
 
Example 12
Source Project: MiniPay   File: ZhiActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void initView() {
    mTitleTv = (TextView) findViewById(R.id.zhi_title);
    mSummeryTv = (TextView) findViewById(R.id.zhi_summery);
    mQaView = (ViewGroup) findViewById(R.id.qa_layout);
    mZhiBg = (ViewGroup) findViewById(R.id.zhi_bg);
    mQaImage = (ImageView) findViewById(R.id.qa_image_view);
    mTip = (TextView) findViewById(R.id.tip);
    mZhiBg.setOnClickListener(this);
}
 
Example 13
private void setupSettingsButton(int containerId, int labelId, int imageViewId,
        final View.OnClickListener onClickListener) {
    ViewGroup container = findViewById(containerId);
    TextView buttonLabel = container.findViewById(labelId);
    String buttonLabelText = buttonLabel.getText().toString();
    ImageView imageView = container.findViewById(imageViewId);
    imageView.setContentDescription(buttonLabelText);
    container.setOnClickListener(onClickListener);
}
 
Example 14
private void addReviews(List<Review> reviews) {
    mReviewsView.removeAllViews();
    LayoutInflater inflater = getActivity().getLayoutInflater();
    for (Review review : reviews) {
        ViewGroup reviewContainer = (ViewGroup) inflater.inflate(R.layout.review, mReviewsView,
                false);
        TextView reviewAuthor = (TextView) reviewContainer.findViewById(R.id.review_author);
        TextView reviewContent = (TextView) reviewContainer.findViewById(R.id.review_content);
        reviewAuthor.setText(review.getAuthor());
        reviewContent.setText(review.getContent().replace("\n\n", " ").replace("\n", " "));
        reviewContainer.setOnClickListener(this);
        reviewContainer.setTag(review);
        mReviewsView.addView(reviewContainer);
    }
}
 
Example 15
ChoiceItemViewHolder (ViewGroup view, int choiceType) {
    mCheckBox = (CheckBox) view.findViewById(R.id.item_cb);
    mTv = (TextView) view.findViewById(R.id.item_text);
    this.mChoiceType = choiceType;
    setText();
    view.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mCheckBox.isEnabled()) {
                mCheckBox.setChecked(!mCheckBox.isChecked());
            }
        }
    });
}
 
Example 16
private void setUpDaysInCalendar() {

        Calendar auxCalendar = Calendar.getInstance(Locale.getDefault());
        auxCalendar.setTime(currentCalendar.getTime());
        auxCalendar.set(Calendar.DAY_OF_MONTH, 1);
        int firstDayOfMonth = auxCalendar.get(Calendar.DAY_OF_WEEK);
        TextView dayOfTheMonthText;
        ViewGroup dayOfTheMonthContainer;
        ViewGroup dayOfTheMonthLayout;

        // Calculate dayOfTheMonthIndex
        int dayOfTheMonthIndex = getWeekIndex(firstDayOfMonth, auxCalendar);

        for (int i = 1; i <= auxCalendar.getActualMaximum(Calendar.DAY_OF_MONTH); i++, dayOfTheMonthIndex++) {
            dayOfTheMonthContainer = rootView.findViewWithTag(DAY_OF_THE_MONTH_LAYOUT + dayOfTheMonthIndex);
            dayOfTheMonthText = rootView.findViewWithTag(DAY_OF_THE_MONTH_TEXT + dayOfTheMonthIndex);
            if (dayOfTheMonthText == null) {
                break;
            }
            dayOfTheMonthContainer.setOnClickListener(onDayOfMonthClickListener);
            dayOfTheMonthContainer.setOnLongClickListener(onDayOfMonthLongClickListener);
            dayOfTheMonthText.setVisibility(View.VISIBLE);
            dayOfTheMonthText.setText(String.valueOf(i));
        }

        for (int i = 36; i < 43; i++) {
            dayOfTheMonthText = rootView.findViewWithTag(DAY_OF_THE_MONTH_TEXT + i);
            dayOfTheMonthLayout = rootView.findViewWithTag(DAY_OF_THE_MONTH_LAYOUT + i);
            if (dayOfTheMonthText.getVisibility() == INVISIBLE) {
                dayOfTheMonthLayout.setVisibility(GONE);
            } else {
                dayOfTheMonthLayout.setVisibility(VISIBLE);
            }
        }
    }
 
Example 17
@Override
@NonNull
public View getView(final int position, @Nullable final View convertView, @NonNull final ViewGroup parent) {
    ViewGroup view = (ViewGroup) convertView;
    ViewHolder viewHolder;

    if (view == null) {
        view = createView(parent);

        viewHolder = new ViewHolder();
        viewHolder.titleParent = (ViewGroup) view.findViewById(mTitleParentResId);
        viewHolder.contentParent = (ViewGroup) view.findViewById(mContentParentResId);

        view.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) view.getTag();
    }

    View titleView = getTitleView(position, viewHolder.titleView, viewHolder.titleParent);
    if (!titleView.equals(viewHolder.titleView)) {
        viewHolder.titleParent.removeAllViews();
        viewHolder.titleParent.addView(titleView);

        if (mActionViewResId == 0) {
            view.setOnClickListener(new TitleViewOnClickListener(viewHolder.contentParent));
        } else {
            view.findViewById(mActionViewResId).setOnClickListener(new TitleViewOnClickListener(viewHolder.contentParent));
        }
    }
    viewHolder.titleView = titleView;

    View contentView = getContentView(position, viewHolder.contentView, viewHolder.contentParent);
    if (!contentView.equals(viewHolder.contentView)) {
        viewHolder.contentParent.removeAllViews();
        viewHolder.contentParent.addView(contentView);
    }
    viewHolder.contentView = contentView;

    viewHolder.contentParent.setVisibility(mExpandedIds.contains(getItemId(position)) ? View.VISIBLE : View.GONE);
    viewHolder.contentParent.setTag(getItemId(position));

    LayoutParams layoutParams = viewHolder.contentParent.getLayoutParams();
    layoutParams.height = LayoutParams.WRAP_CONTENT;
    viewHolder.contentParent.setLayoutParams(layoutParams);

    return view;
}
 
Example 18
@Override
public View getView(final int position, final View convertView, final ViewGroup parent) {
    ViewGroup view = (ViewGroup) convertView;
    ViewHolder viewHolder;

    if (view == null) {
        view = createView(parent);

        viewHolder = new ViewHolder();
        viewHolder.titleParent = (ViewGroup) view.findViewById(mTitleParentResId);
        viewHolder.contentParent = (ViewGroup) view.findViewById(mContentParentResId);

        view.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) view.getTag();
    }

    View titleView = getTitleView(position, viewHolder.titleView, viewHolder.titleParent);
    if (titleView != viewHolder.titleView) {
        viewHolder.titleParent.removeAllViews();
        viewHolder.titleParent.addView(titleView);

        if (mActionViewResId == 0) {
            view.setOnClickListener(new TitleViewOnClickListener(viewHolder.contentParent));
        } else {
            view.findViewById(mActionViewResId).setOnClickListener(new TitleViewOnClickListener(viewHolder.contentParent));
        }
    }
    viewHolder.titleView = titleView;

    View contentView = getContentView(position, viewHolder.contentView, viewHolder.contentParent);
    if (contentView != viewHolder.contentView) {
        viewHolder.contentParent.removeAllViews();
        viewHolder.contentParent.addView(contentView);
    }
    viewHolder.contentView = contentView;

    viewHolder.contentParent.setVisibility(mExpandedIds.contains(getItemId(position)) ? View.VISIBLE : View.GONE);
    viewHolder.contentParent.setTag(getItemId(position));

    LayoutParams layoutParams = viewHolder.contentParent.getLayoutParams();
    layoutParams.height = LayoutParams.WRAP_CONTENT;
    viewHolder.contentParent.setLayoutParams(layoutParams);

    return view;
}
 
Example 19
Source Project: Roundr   File: StandOutWindow.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * You probably want to leave this method alone and implement
 * {@link #getDropDownItems(int)} instead. Only implement this method if you
 * want more control over the drop down menu.
 * 
 * <p>
 * Implement this method to set a custom drop down menu when the user clicks
 * on the icon of the window corresponding to the id. The icon is only shown
 * when {@link StandOutFlags#FLAG_DECORATION_SYSTEM} is set.
 * 
 * @param id
 *            The id of the window.
 * @return The drop down menu to be anchored to the icon, or null to have no
 *         dropdown menu.
 */
public PopupWindow getDropDown(final int id) {
	final List<DropDownListItem> items;

	List<DropDownListItem> dropDownListItems = getDropDownItems(id);
	if (dropDownListItems != null) {
		items = dropDownListItems;
	} else {
		items = new ArrayList<StandOutWindow.DropDownListItem>();
	}

	// add default drop down items
	items.add(new DropDownListItem(android.R.drawable.ic_menu_close_clear_cancel, "Quit " + getAppName(), new Runnable() {

		@Override
		public void run() {
			closeAll();
		}
	}));

	// turn item list into views in PopupWindow
	LinearLayout list = new LinearLayout(this);
	list.setOrientation(LinearLayout.VERTICAL);

	ScrollView scroller = new ScrollView(this);
	scroller.addView(list);

	final PopupWindow dropDown = new PopupWindow(scroller, StandOutLayoutParams.WRAP_CONTENT, StandOutLayoutParams.WRAP_CONTENT, true);

	for (final DropDownListItem item : items) {
		ViewGroup listItem = (ViewGroup) mLayoutInflater.inflate(R.layout.drop_down_list_item, null);
		list.addView(listItem);

		ImageView icon = (ImageView) listItem.findViewById(R.id.icon);
		icon.setImageResource(item.icon);

		TextView description = (TextView) listItem.findViewById(R.id.description);
		description.setText(item.description);

		listItem.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				item.action.run();
				dropDown.dismiss();
			}
		});
	}

	Drawable background = getResources().getDrawable(android.R.drawable.editbox_dropdown_dark_frame);
	dropDown.setBackgroundDrawable(background);
	return dropDown;
}
 
Example 20
protected void init(Context context) {
    super.init(context);

    mStartButton = findViewById(R.id.start);
    mTitleTextView = (TextView) findViewById(R.id.title);
    mBackButton = (ImageView) findViewById(R.id.back);
    mFullscreenButton = (ImageView) findViewById(R.id.fullscreen);
    mProgressBar = (SeekBar) findViewById(R.id.progress);
    mCurrentTimeTextView = (TextView) findViewById(R.id.current);
    mTotalTimeTextView = (TextView) findViewById(R.id.total);
    mBottomContainer = (ViewGroup) findViewById(R.id.layout_bottom);
    mTopContainer = (ViewGroup) findViewById(R.id.layout_top);
    mBottomProgressBar = (ProgressBar) findViewById(R.id.bottom_progressbar);
    mThumbImageViewLayout = (RelativeLayout) findViewById(R.id.thumb);
    mLockScreen = (ImageView) findViewById(R.id.lock_screen);

    mLoadingProgressBar = findViewById(R.id.loading);


    if (isInEditMode())
        return;

    if (mStartButton != null) {
        mStartButton.setOnClickListener(this);
    }

    if (mFullscreenButton != null) {
        mFullscreenButton.setOnClickListener(this);
        mFullscreenButton.setOnTouchListener(this);
    }

    if (mProgressBar != null) {
        mProgressBar.setOnSeekBarChangeListener(this);
    }

    if (mBottomContainer != null) {
        mBottomContainer.setOnClickListener(this);
    }

    if (mTextureViewContainer != null) {
        mTextureViewContainer.setOnClickListener(this);
        mTextureViewContainer.setOnTouchListener(this);
    }

    if (mProgressBar != null) {
        mProgressBar.setOnTouchListener(this);
    }

    if (mThumbImageViewLayout != null) {
        mThumbImageViewLayout.setVisibility(GONE);
        mThumbImageViewLayout.setOnClickListener(this);
    }
    if (mThumbImageView != null && !mIfCurrentIsFullscreen && mThumbImageViewLayout != null) {
        mThumbImageViewLayout.removeAllViews();
        resolveThumbImage(mThumbImageView);
    }

    if (mBackButton != null)
        mBackButton.setOnClickListener(this);

    if (mLockScreen != null) {
        mLockScreen.setVisibility(GONE);
        mLockScreen.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mCurrentState == CURRENT_STATE_AUTO_COMPLETE ||
                        mCurrentState == CURRENT_STATE_ERROR) {
                    return;
                }
                lockTouchLogic();
                if (mLockClickListener != null) {
                    mLockClickListener.onClick(v, mLockCurScreen);
                }
            }
        });
    }

    if (getActivityContext() != null) {
        mSeekEndOffset = CommonUtil.dip2px(getActivityContext(), 50);
    }
}