Example usage for android.view View setOnClickListener

List of usage examples for android.view View setOnClickListener

Introduction

In this page you can find the example usage for android.view View 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:com.csipsimple.ui.favorites.FavAdapter.java

@Override
public void bindView(View view, final Context context, Cursor cursor) {
    ContentValues cv = new ContentValues();
    DatabaseUtils.cursorRowToContentValues(cursor, cv);

    int type = ContactsWrapper.TYPE_CONTACT;
    if (cv.containsKey(ContactsWrapper.FIELD_TYPE)) {
        type = cv.getAsInteger(ContactsWrapper.FIELD_TYPE);
    }// w w  w . jav a 2 s  .co m

    showViewForType(view, type);

    if (type == ContactsWrapper.TYPE_GROUP) {
        // Get views
        TextView tv = (TextView) view.findViewById(R.id.header_text);
        ImageView icon = (ImageView) view.findViewById(R.id.header_icon);
        PresenceStatusSpinner presSpinner = (PresenceStatusSpinner) view
                .findViewById(R.id.header_presence_spinner);

        // Get datas
        SipProfile acc = new SipProfile(cursor);

        final Long profileId = cv.getAsLong(BaseColumns._ID);
        final String groupName = acc.android_group;
        final String displayName = acc.display_name;
        final String wizard = acc.wizard;
        final boolean publishedEnabled = (acc.publish_enabled == 1);
        final String domain = acc.getDefaultDomain();

        // Bind datas to view
        tv.setText(displayName);
        icon.setImageResource(WizardUtils.getWizardIconRes(wizard));
        presSpinner.setProfileId(profileId);

        // Extra menu view if not already set
        ViewGroup menuViewWrapper = (ViewGroup) view.findViewById(R.id.header_cfg_spinner);

        MenuCallback newMcb = new MenuCallback(context, profileId, groupName, domain, publishedEnabled);
        MenuBuilder menuBuilder;
        if (menuViewWrapper.getTag() == null) {

            final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.MATCH_PARENT);

            ActionMenuPresenter mActionMenuPresenter = new ActionMenuPresenter(mContext);
            mActionMenuPresenter.setReserveOverflow(true);
            menuBuilder = new MenuBuilder(context);
            menuBuilder.setCallback(newMcb);
            MenuInflater inflater = new MenuInflater(context);
            inflater.inflate(R.menu.fav_menu, menuBuilder);
            menuBuilder.addMenuPresenter(mActionMenuPresenter);
            ActionMenuView menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(menuViewWrapper);
            UtilityWrapper.getInstance().setBackgroundDrawable(menuView, null);
            menuViewWrapper.addView(menuView, layoutParams);
            menuViewWrapper.setTag(menuBuilder);
        } else {
            menuBuilder = (MenuBuilder) menuViewWrapper.getTag();
            menuBuilder.setCallback(newMcb);
        }
        menuBuilder.findItem(R.id.share_presence).setTitle(
                publishedEnabled ? R.string.deactivate_presence_sharing : R.string.activate_presence_sharing);
        menuBuilder.findItem(R.id.set_sip_data).setVisible(!TextUtils.isEmpty(groupName));

    } else if (type == ContactsWrapper.TYPE_CONTACT) {
        ContactInfo ci = ContactsWrapper.getInstance().getContactInfo(context, cursor);
        ci.userData = cursor.getPosition();
        // Get views
        TextView tv = (TextView) view.findViewById(R.id.contact_name);
        QuickContactBadge badge = (QuickContactBadge) view.findViewById(R.id.quick_contact_photo);
        TextView statusText = (TextView) view.findViewById(R.id.status_text);
        ImageView statusImage = (ImageView) view.findViewById(R.id.status_icon);

        // Bind
        if (ci.contactId != null) {
            tv.setText(ci.displayName);
            badge.assignContactUri(ci.callerInfo.contactContentUri);
            ContactsAsyncHelper.updateImageViewWithContactPhotoAsync(context, badge.getImageView(),
                    ci.callerInfo, R.drawable.ic_contact_picture_holo_dark);

            statusText.setVisibility(ci.hasPresence ? View.VISIBLE : View.GONE);
            statusText.setText(ci.status);
            statusImage.setVisibility(ci.hasPresence ? View.VISIBLE : View.GONE);
            statusImage.setImageResource(ContactsWrapper.getInstance().getPresenceIconResourceId(ci.presence));
        }
        View v;
        v = view.findViewById(R.id.contact_view);
        v.setTag(ci);
        v.setOnClickListener(mPrimaryActionListener);
        v = view.findViewById(R.id.secondary_action_icon);
        v.setTag(ci);
        v.setOnClickListener(mSecondaryActionListener);
    } else if (type == ContactsWrapper.TYPE_CONFIGURE) {
        // We only bind if it's the correct type
        View v = view.findViewById(R.id.configure_view);
        v.setOnClickListener(this);
        ConfigureObj cfg = new ConfigureObj();
        cfg.profileId = cv.getAsLong(BaseColumns._ID);
        v.setTag(cfg);
    }
}

From source file:ar.com.xpasta.Controls.PagerSlidingTabStrip.java

private void addTab(final int position, View tab) {
    tab.setFocusable(true);//from  www . ja  v  a  2s  .  co  m
    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
        }
    });
    tab.setPadding(tabPadding, 0, tabPadding, 0);
    tabsContainer.addView(tab, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
}

From source file:com.astuetz.viewpager.extensions.FixedTabsView.java

/**
 * Initialize and add all tabs to the layout
 *///  w w  w. j a  v a 2s .c  om
private void initTabs() {

    removeAllViews();
    mTabs.clear();

    if (mAdapter == null)
        return;

    for (int i = 0; i < mPager.getAdapter().getCount(); i++) {

        final int index = i;

        View tab = mAdapter.getView(i);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1.0f);
        tab.setLayoutParams(params);
        this.addView(tab);

        mTabs.add(tab);

        if (i != mPager.getAdapter().getCount() - 1) {
            this.addView(getSeparator());
        }

        tab.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mPager.setCurrentItem(index);
            }
        });

    }

    selectTab(mPager.getCurrentItem());
}

From source file:com.mercandalli.android.apps.files.file.FileAddDialog.java

@SuppressWarnings("PMD.AvoidUsingHardCodedIP")
public FileAddDialog(@NonNull final Activity activity, final int id_file_parent,
        @Nullable final IListener listener, @Nullable final IListener dismissListener) {
    super(activity, R.style.DialogFullscreen);
    mActivity = activity;//  www  . ja  v  a2  s .  co  m
    mDismissListener = dismissListener;
    mFileParentId = id_file_parent;
    mListener = listener;

    setContentView(R.layout.dialog_add_file);
    setCancelable(true);

    final View rootView = findViewById(R.id.dialog_add_file_root);
    rootView.startAnimation(AnimationUtils.loadAnimation(mActivity, R.anim.dialog_add_file_open));
    rootView.setOnClickListener(this);

    findViewById(R.id.dialog_add_file_upload_file).setOnClickListener(this);
    findViewById(R.id.dialog_add_file_add_directory).setOnClickListener(this);

    findViewById(R.id.dialog_add_file_text_doc).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            DialogUtils.prompt(mActivity, mActivity.getString(R.string.dialog_file_create_txt),
                    mActivity.getString(R.string.dialog_file_name_interrogation),
                    mActivity.getString(R.string.dialog_file_create),
                    new DialogUtils.OnDialogUtilsStringListener() {
                        @Override
                        public void onDialogUtilsStringCalledBack(String text) {
                            //TODO create a online txt with content
                            Toast.makeText(getContext(), getContext().getString(R.string.not_implemented),
                                    Toast.LENGTH_SHORT).show();
                        }
                    }, mActivity.getString(android.R.string.cancel), null);
            FileAddDialog.this.dismiss();
        }
    });

    findViewById(R.id.dialog_add_file_scan).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            // Ensure that there's a camera activity to handle the intent
            if (takePictureIntent.resolveActivity(mActivity.getPackageManager()) != null) {
                // Create the File where the photo should go
                ApplicationActivity.sPhotoFile = createImageFile();
                // Continue only if the File was successfully created
                if (ApplicationActivity.sPhotoFile != null) {
                    if (listener != null) {
                        ApplicationActivity.sPhotoFileListener = listener;
                    }
                    takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                            Uri.fromFile(ApplicationActivity.sPhotoFile.getFile()));
                    mActivity.startActivityForResult(takePictureIntent, ApplicationActivity.REQUEST_TAKE_PHOTO);
                }
            }
            FileAddDialog.this.dismiss();
        }
    });

    findViewById(R.id.dialog_add_file_add_timer).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            final Calendar currentTime = Calendar.getInstance();

            DialogDatePicker dialogDate = new DialogDatePicker(mActivity,
                    new DatePickerDialog.OnDateSetListener() {
                        @Override
                        public void onDateSet(DatePicker view, final int year, final int monthOfYear,
                                final int dayOfMonth) {

                            Calendar currentTime = Calendar.getInstance();

                            DialogTimePicker dialogTime = new DialogTimePicker(mActivity,
                                    new TimePickerDialog.OnTimeSetListener() {
                                        @Override
                                        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                                            Log.d("TIme Picker", hourOfDay + ":" + minute);

                                            final SimpleDateFormat dateFormatGmt = new SimpleDateFormat(
                                                    "yyyy-MM-dd HH:mm:ss", Locale.US);
                                            dateFormatGmt.setTimeZone(TimeZone.getTimeZone("UTC"));
                                            final SimpleDateFormat dateFormatLocal = new SimpleDateFormat(
                                                    "yyyy-MM-dd HH:mm:ss", Locale.US);

                                            String nowAsISO = dateFormatGmt.format(new Date());

                                            final JSONObject json = new JSONObject();
                                            try {
                                                json.put("type", "timer");
                                                json.put("date_creation", nowAsISO);
                                                json.put("timer_date",
                                                        "" + dateFormatGmt.format(dateFormatLocal.parse(year
                                                                + "-" + (monthOfYear + 1) + "-" + dayOfMonth
                                                                + " " + hourOfDay + ":" + minute + ":00")));

                                                final SimpleDateFormat dateFormatGmtTZ = new SimpleDateFormat(
                                                        "yyyy-MM-dd'T'HH-mm'Z'", Locale.US);
                                                dateFormatGmtTZ.setTimeZone(TimeZone.getTimeZone("UTC"));
                                                nowAsISO = dateFormatGmtTZ.format(new Date());

                                                final List<StringPair> parameters = new ArrayList<>();
                                                parameters.add(new StringPair("content", json.toString()));
                                                parameters.add(new StringPair("name", "TIMER_" + nowAsISO));
                                                parameters.add(
                                                        new StringPair("id_file_parent", "" + id_file_parent));
                                                new TaskPost(mActivity,
                                                        Constants.URL_DOMAIN + Config.ROUTE_FILE,
                                                        new IPostExecuteListener() {
                                                            @Override
                                                            public void onPostExecute(JSONObject json,
                                                                    String body) {
                                                                if (listener != null) {
                                                                    listener.execute();
                                                                }
                                                            }
                                                        }, parameters).execute();
                                            } catch (JSONException | ParseException e) {
                                                Log.e(getClass().getName(), "Failed to convert Json", e);
                                            }

                                        }
                                    }, currentTime.get(Calendar.HOUR_OF_DAY), currentTime.get(Calendar.MINUTE),
                                    true);
                            dialogTime.show();

                        }
                    }, currentTime.get(Calendar.YEAR), currentTime.get(Calendar.MONTH),
                    currentTime.get(Calendar.DAY_OF_MONTH));
            dialogDate.show();

            FileAddDialog.this.dismiss();
        }
    });

    findViewById(R.id.dialog_add_file_article).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            DialogCreateArticle dialogCreateArticle = new DialogCreateArticle(mActivity, listener);
            dialogCreateArticle.show();
            FileAddDialog.this.dismiss();
        }
    });

    FileAddDialog.this.show();
}

From source file:com.chess.genesis.activity.GameListOnlineFrag.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    initBaseContentFrag(container);//w  w w  .j a v a  2 s .  com

    final View view = inflater.inflate(R.layout.fragment_gamelist_online, container, false);

    gamelistadapter_arr = new GameListAdapter[3];
    net = new NetworkClient(act, handle);
    progress = new ProgressMsg(act);

    try {
        // Set "waiting for opponent"
        final JSONArray pool = new JSONArray(Pref.getString(act, R.array.pf_poolinfo));
        final View tpool = view.findViewById(R.id.game_search);

        tpool.setVisibility((pool.length() == 0) ? View.GONE : View.VISIBLE);
        tpool.setOnClickListener(this);
        tpool.setOnTouchListener(this);
    } catch (final JSONException e) {
        throw new RuntimeException(e.getMessage(), e);
    }

    final SwipeTabsPagerAdapter tabAdapter = new SwipeTabsPagerAdapter(act, act.getSupportFragmentManager());
    tabAdapter.setTitles(new String[] { "Their Turn", "Your Turn", "Archive Games" });

    final SwipeTabs swipetabs = (SwipeTabs) view.findViewById(R.id.swipetabs);
    swipetabs.setAdapter(tabAdapter);

    pager = (ViewPager) view.findViewById(R.id.swipe_list);
    tabAdapter.setViewPager(pager);
    pager.setAdapter(new GameListPager());
    pager.setOnPageChangeListener(swipetabs);
    pager.setCurrentItem(YOUR_PAGE);

    return view;
}

From source file:cn.org.eshow.framwork.view.sliding.AbSlidingPlayView.java

/**
 * ???./*from w  w w  .  j a  v  a 2s  .com*/
 *
 * @param views the views
 */
public void addViews(List<View> views) {
    mListViews.addAll(views);
    for (View view : views) {
        view.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (mOnItemClickListener != null) {
                    mOnItemClickListener.onClick(position);
                }
            }
        });

        view.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View view, MotionEvent event) {
                if (mAbOnTouchListener != null) {
                    mAbOnTouchListener.onTouch(event);
                }
                return false;
            }
        });
    }
    mAbViewPagerAdapter.notifyDataSetChanged();
    creatIndex();
}

From source file:com.cardvlaue.sys.redenvelope.PagerSlidingTabStrip.java

private void addTab(final int position, View tab) {
    tab.setFocusable(true);/*from  w  w w. j a  v  a 2  s.  co  m*/
    tab.setOnClickListener(v -> pager.setCurrentItem(position));

    tab.setPadding(tabPadding, 0, tabPadding, 0);
    tabsContainer.addView(tab, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
}

From source file:com.chenl.widgets.flippablestackview.indicator.OrientedPagerSlidingTabLayout.java

private void addTab(final int position, View tab) {
    tab.setFocusable(true);/*from   ww w.j ava  2  s  .  c o  m*/
    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mPager.setCurrentItem(position);
        }
    });
    tab.setPadding(tabPadding, 0, tabPadding, 0);
    LinearLayout.LayoutParams params = shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams;
    params.setMargins(tabMargins, tabMargins, tabMargins, tabMargins);
    tabsContainer.addView(tab, position, params);
}

From source file:com.cyrilmottier.android.cbrreader.fragment.AboutFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_about, container, false);

    LinearLayout libsLayout = (LinearLayout) view.findViewById(R.id.about_libraries);

    for (int i = 0; i < mDescriptions.length; i++) {
        View cardView = inflater.inflate(R.layout.card_deps, libsLayout, false);

        ((TextView) cardView.findViewById(R.id.libraryName)).setText(mDescriptions[i].name);
        ((TextView) cardView.findViewById(R.id.libraryCreator)).setText(mDescriptions[i].owner);
        ((TextView) cardView.findViewById(R.id.libraryDescription)).setText(mDescriptions[i].description);
        ((TextView) cardView.findViewById(R.id.libraryLicense)).setText(mDescriptions[i].license);

        cardView.setTag(mDescriptions[i].link);
        cardView.setOnClickListener(this);
        libsLayout.addView(cardView);/*from w ww .  j av a2 s . c om*/
    }

    return view;
}

From source file:com.cumt.view.PagerSlidingTabStrip.java

private void addTab(final int position, View tab) {
    tab.setFocusable(true);//from   w  w w.j av a 2  s .  com
    tab.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            pager.setCurrentItem(position);
        }
    });

    tab.setPadding(tabPadding, 0, tabPadding, 0);
    tabsContainer.addView(tab, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
}