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

The following examples show how to use android.view.ViewGroup#setOnClickListener() . 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 File: MxVideoPlayer.java    From MxVideoPlayer with 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
Source File: WormDotsIndicator.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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
Source File: SpringDotsIndicator.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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
Source File: ImageFloderAdapter.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
@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
Source File: HashtagView.java    From hashtag-view with 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 6
Source File: PictureFragment.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
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 File: DataPageView.java    From QuickerAndroid with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 根据屏幕方向创建按钮
 */
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 8
Source File: RobotoCalendarView.java    From roboto-calendar-view with Apache License 2.0 5 votes vote down vote up
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 9
Source File: SettingsActivity.java    From input-samples with 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 10
Source File: FunctionChooseAlertView.java    From LocationReportEnabler with GNU General Public License v3.0 5 votes vote down vote up
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 11
Source File: MovieDetailsFragment.java    From udacity-p1-p2-popular-movies with MIT License 5 votes vote down vote up
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 12
Source File: SettingsActivity.java    From android-AutofillFramework with 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 13
Source File: ZhiActivity.java    From MiniPay with 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 14
Source File: FormulaView.java    From AndroidMathKeyboard with 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 15
Source File: UserCenterActivity.java    From Jide-Note with 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 16
Source File: SettingsActivity.java    From input-samples with 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 17
Source File: StandOutWindow.java    From Roundr with 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 18
Source File: ExpandableListItemAdapter.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
@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 File: GSYVideoControlView.java    From GSYVideoPlayer with Apache License 2.0 4 votes vote down vote up
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);
    }
}
 
Example 20
Source File: ExpandableListItemAdapter.java    From ListViewAnimations with Apache License 2.0 4 votes vote down vote up
@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;
}