Example usage for android.widget ImageView setOnClickListener

List of usage examples for android.widget ImageView setOnClickListener

Introduction

In this page you can find the example usage for android.widget ImageView 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.idt.ontomedia.geoconsum.fragments.DetailsBaseFragment.java

protected void setURL(Cursor _cursor, int _idTextViewTextURL, int _idTextViewTitleURL, int _idImageViewURL) {
    final String url = _cursor.getString(_cursor.getColumnIndex(DatabaseAdapter.COLUMN_URL));
    TextView textViewText = (TextView) mParentActivity.findViewById(_idTextViewTextURL);
    TextView textviewTitle = (TextView) mParentActivity.findViewById(_idTextViewTitleURL);
    ImageView imageViewUrl = (ImageView) mParentActivity.findViewById(_idImageViewURL);

    if (url.length() != 0) {
        textViewText.setVisibility(View.VISIBLE);
        textviewTitle.setVisibility(View.VISIBLE);
        imageViewUrl.setVisibility(View.VISIBLE);
        imageViewUrl.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

        imageViewUrl.setOnClickListener(new OnClickListener() {

            @Override//from  w  w  w . j ava2  s  .  co m
            public void onClick(View v) {
                String httpURL = url;

                if (!url.startsWith("http")) {
                    httpURL = "http://" + url;
                }
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(httpURL));
                startActivity(intent);
            }
        });
    }
}

From source file:com.meiste.greg.ptw.tab.Standings.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    mSetupNeeded = GAE.isAccountSetupNeeded(getActivity());
    mChanged = false;/*from  w w w  .j a  v  a  2s.  co m*/
    mAccountSetupTime = Util.getAccountSetupTime(getActivity());
    setRetainInstance(true);

    final IntentFilter filter = new IntentFilter(PTW.INTENT_ACTION_STANDINGS);
    getActivity().registerReceiver(mBroadcastReceiver, filter);

    if (mSetupNeeded)
        return Util.getAccountSetupView(getActivity(), inflater, container);
    else if (mFailedConnect) {
        mFailedConnect = false;
        final View v = inflater.inflate(R.layout.no_connection, container, false);

        final Button retry = (Button) v.findViewById(R.id.retry);
        retry.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                mChanged = true;
                notifyChanged();
            }
        });

        return v;
    } else if (!isStandingsPresent() || mConnecting) {
        if (!mConnecting) {
            mConnecting = true;
            GAE.getInstance(getActivity()).getPage(this, "standings");
        }
        return inflater.inflate(R.layout.connecting, container, false);
    }

    final View v = inflater.inflate(R.layout.list, container, false);
    mSwipeRefreshWidget = (SwipeRefreshLayout) v.findViewById(R.id.swipe_refresh_widget);
    mSwipeRefreshWidget.setOnRefreshListener(this);
    mSwipeRefreshWidget.setColorSchemeResources(R.color.refresh1, R.color.refresh2, R.color.refresh3,
            R.color.refresh4);

    final ListView lv = (ListView) v.findViewById(R.id.content);
    final View header = inflater.inflate(R.layout.standings_header, lv, false);
    mAdapter = new PlayerAdapter(getActivity());
    mAfterRace = (TextView) header.findViewById(R.id.after);
    mAfterRace.setText(getRaceAfterText(getActivity()));
    lv.addHeaderView(header, null, false);
    final View footer = inflater.inflate(R.layout.standings_footer, lv, false);
    mFooter = (TextView) footer.findViewById(R.id.standings_footer);
    mFooter.setText(getFooterText(getActivity()));
    lv.addFooterView(footer, null, false);
    lv.setAdapter(mAdapter);

    lv.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(final AdapterView<?> parent, final View v, final int pos, final long id) {
            final Player player = (Player) parent.getItemAtPosition(pos);
            if (mAdapter.isSelf(player)) {
                Util.log("Opening privacy dialog");
                if (mPrivacyDialog == null) {
                    mPrivacyDialog = new PrivacyDialog(getActivity(), Standings.this);
                }
                mPrivacyDialog.show(mAdapter.getPlayerName());
            } else {
                Util.log("Opening friend action dialog");
                if (mFriendActionDialog == null) {
                    mFriendActionDialog = new FriendActionDialog(getActivity(), Standings.this);
                }
                mFriendActionDialog.show(player);
            }
        }
    });

    final ImageView iv = (ImageView) v.findViewById(R.id.add_friend);
    iv.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            if ((NfcAdapter.getDefaultAdapter(getActivity()) != null)
                    && (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
                    && mAdapter.getPlayer().isIdentifiable() && Gcm.isRegistered(getActivity())) {
                Util.log("NFC available. Need to ask user add method.");
                if (mFriendMethodDialog == null) {
                    mFriendMethodDialog = new FriendMethodDialog(getActivity(), Standings.this);
                }
                mFriendMethodDialog.reset();
                mFriendMethodDialog.show();
            } else {
                Util.log("NFC not available. Adding friend via username.");
                showFriendPlayerDialog();
            }
        }
    });

    if (mCheckName) {
        if ((mPrivacyDialog.getNewName() != null)
                && !mPrivacyDialog.getNewName().equals(mAdapter.getPlayerName())) {
            Toast.makeText(getActivity(), R.string.name_taken, Toast.LENGTH_SHORT).show();
        }
        mCheckName = false;
    }

    return v;
}

From source file:com.esri.arcgisruntime.sample.featurelayerupdateattributes.MainActivity.java

/**
 * Displays Callout//from www .j  a  v  a2 s .  co  m
 * @param title the text to show in the Callout
 */
private void showCallout(String title) {

    // create a text view for the callout
    RelativeLayout calloutLayout = new RelativeLayout(getApplicationContext());

    TextView calloutContent = new TextView(getApplicationContext());
    calloutContent.setId(R.id.textview);
    calloutContent.setTextColor(Color.BLACK);
    calloutContent.setTextSize(18);
    calloutContent.setPadding(0, 10, 10, 0);

    calloutContent.setText(title);

    RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    relativeParams.addRule(RelativeLayout.RIGHT_OF, calloutContent.getId());

    // create image view for the callout
    ImageView imageView = new ImageView(getApplicationContext());
    imageView.setImageDrawable(
            ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_info_outline_black_18dp));
    imageView.setLayoutParams(relativeParams);
    imageView.setOnClickListener(new ImageViewOnclickListener());

    calloutLayout.addView(calloutContent);
    calloutLayout.addView(imageView);

    mCallout.setLocation(mMapView.screenToLocation(mClickPoint));
    mCallout.setContent(calloutLayout);
    mCallout.show();
}

From source file:com.example.android.android_me.ui.BodyPartFragment.java

/**
 * Inflates the fragment layout file and sets the correct resource for the image to display
 *//*from ww  w  .j av a  2 s  . c om*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // Inflate the Android-Me fragment layout
    View rootView = inflater.inflate(R.layout.fragment_body_part, container, false);

    //Check bundle
    if (savedInstanceState != null) {
        mImageIds = savedInstanceState.getIntegerArrayList(IMAGE_ID_LIST);
        mListIndex = savedInstanceState.getInt(LIST_INDEX);
    }

    // Get a reference to the ImageView in the fragment layout
    final ImageView imageView = (ImageView) rootView.findViewById(R.id.body_part_image_view);

    // If a list of image ids exists, set the image resource to the correct item in that list
    // Otherwise, create a Log statement that indicates that the list was not found
    if (mImageIds != null) {
        // Set the image resource to the list item at the stored index
        imageView.setImageResource(mImageIds.get(mListIndex));

        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListIndex < mImageIds.size() - 1) {
                    mListIndex++;
                } else {
                    mListIndex = 0;
                }
                imageView.setImageResource(mImageIds.get(mListIndex));
            }
        });

    } else {
        Log.v(TAG, "This fragment has a null list of image id's");
    }

    // Return the rootView
    return rootView;
}

From source file:com.cm.android.displayingbitmaps.ui.ImageGridFragment.java

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

    final View v = inflater.inflate(R.layout.image_grid_fragment, container, false);
    final GridView mGridView = (GridView) v.findViewById(R.id.gridView);
    mGridView.setAdapter(mAdapter);//w  w  w  . ja va2  s. c om
    mGridView.setOnItemClickListener(this);
    mGridView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView absListView, int scrollState) {
            // Pause fetcher to ensure smoother scrolling when flinging
            if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING) {
                // Before Honeycomb pause image loading on scroll to help with performance
                if (!Utils.hasHoneycomb()) {
                    mImageFetcher.setPauseWork(true);
                }
            } else {
                mImageFetcher.setPauseWork(false);
            }
        }

        @Override
        public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount,
                int totalItemCount) {
        }
    });

    // This listener is used to get the final width of the GridView and then calculate the
    // number of columns and the width of each column. The width of each column is variable
    // as the GridView has stretchMode=columnWidth. The column width is used to set the height
    // of each view so we get nice square thumbnails.
    mGridView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @TargetApi(VERSION_CODES.JELLY_BEAN)
        @Override
        public void onGlobalLayout() {
            if (mAdapter.getNumColumns() == 0) {
                final int numColumns = (int) Math
                        .floor(mGridView.getWidth() / (mImageThumbSize + mImageThumbSpacing));
                if (numColumns > 0) {
                    final int columnWidth = (mGridView.getWidth() / numColumns) - mImageThumbSpacing;
                    mAdapter.setNumColumns(numColumns);
                    mAdapter.setItemHeight(columnWidth);
                    if (BuildConfig.DEBUG) {
                        Log.d(TAG, "onCreateView - numColumns set to " + numColumns);
                    }
                    if (Utils.hasJellyBean()) {
                        mGridView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    } else {
                        mGridView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                    }
                }
            }
        }
    });

    //@author anshu
    final ImageView mAddImage = (ImageView) v.findViewById(R.id.add_image);
    mAddImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                takePhoto();
            } catch (IOException ex) {
                // Error occurred while creating the File
                Log.e("takePhoto", ex.toString());
            }
        }
    });

    //Admob
    mAdView = (AdView) v.findViewById(R.id.adView);

    return v;
}

From source file:com.nxt.njitong.ContactlistActivity.java

public void initviews() {
    //super.onActivityCreated(savedInstanceState);
    //T??home???appcrash
    //if(savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false))
    // return;/* w  w w .ja  va 2  s .c o m*/
    context = this;
    findViewById(R.id.back).setVisibility(View.VISIBLE);
    ((TextView) findViewById(R.id.message_title)).setText(getIntent().getStringExtra("type"));
    inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    listView = (ListView) findViewById(R.id.list);
    sidebar = (Sidebar) findViewById(R.id.sidebar);
    sidebar.setListView(listView);
    //???
    blackList = EMContactManager.getInstance().getBlackListUsernames();
    contactList = new ArrayList<User>();
    // ?contactlist
    getContactList();

    //?
    query = (EditText) findViewById(R.id.query);
    String strSearch = getResources().getString(R.string.search);
    query.setHint(strSearch);
    clearSearch = (ImageButton) findViewById(R.id.search_clear);
    query.addTextChangedListener(new TextWatcher() {
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            adapter.getFilter().filter(s);
            if (s.length() > 0) {
                clearSearch.setVisibility(View.VISIBLE);
            } else {
                clearSearch.setVisibility(View.INVISIBLE);

            }
        }

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

        public void afterTextChanged(Editable s) {
        }
    });
    clearSearch.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            query.getText().clear();
        }
    });

    // adapter
    adapter = new ContactAdapter(context, R.layout.row_contact, contactList);
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String username = adapter.getItem(position).getUsername();
            if (Constant.NEW_FRIENDS_USERNAME.equals(username)) {
                // ?
                User user = DemoApplication.getInstance().getContactList().get(Constant.NEW_FRIENDS_USERNAME);
                user.setUnreadMsgCount(0);
                startActivity(new Intent(context, NewFriendsMsgActivity.class));
            } else if (Constant.GROUP_USERNAME.equals(username)) {
                // ??
                startActivity(new Intent(context, GroupsActivity.class));
            } else {
                // demo??
                startActivity(new Intent(context, ChatActivity.class).putExtra("userId",
                        adapter.getItem(position).getUsername()));
            }
        }
    });
    listView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // ??
            if (getWindow()
                    .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
                if (getCurrentFocus() != null)
                    inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
            }
            return false;
        }
    });

    ImageView addContactView = (ImageView) findViewById(R.id.iv_new_contact);
    addContactView.setVisibility(View.GONE);
    // ?
    addContactView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(context, AddContactActivity.class));
        }
    });
    registerForContextMenu(listView);

}

From source file:com.sxt.superqq.fragment.ContactlistFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    // T??home???appcrash
    if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false))
        return;/*from   www.  ja  v  a2  s.c o  m*/
    inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    listView = (ListView) getView().findViewById(R.id.list);
    sidebar = (Sidebar) getView().findViewById(R.id.sidebar);
    sidebar.setListView(listView);
    // ???
    blackList = EMContactManager.getInstance().getBlackListUsernames();
    // contactList = new ArrayList<User>();
    // ?
    query = (EditText) getView().findViewById(R.id.query);
    query.setHint(R.string.search);
    clearSearch = (ImageButton) getView().findViewById(R.id.search_clear);
    query.addTextChangedListener(new TextWatcher() {
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            mAdapter.getFilter().filter(s);
            if (s.length() > 0) {
                clearSearch.setVisibility(View.VISIBLE);
            } else {
                clearSearch.setVisibility(View.INVISIBLE);

            }
        }

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

        public void afterTextChanged(Editable s) {
        }
    });
    clearSearch.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            query.getText().clear();
            hideSoftKeyboard();
        }
    });

    mContactList = new ArrayList<UserBean>();
    // adapter
    mAdapter = new Contact_Adapter(getActivity(), R.layout.row_contact, mContactList);
    listView.setAdapter(mAdapter);
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String username = mAdapter.getItem(position).getUserName();
            if (Constant.NEW_FRIENDS_USERNAME.equals(username)) {
                // ?
                User user = SuperQQApplication.getInstance().getContact_List()
                        .get(Constant.NEW_FRIENDS_USERNAME);
                user.setUnreadMsgCount(0);
                startActivity(new Intent(getActivity(), NewFriendsMsgActivity.class));
            } else if (Constant.GROUP_USERNAME.equals(username)) {
                // ??
                startActivity(new Intent(getActivity(), GroupsActivity.class));
            } else {
                // demo??
                startActivity(new Intent(getActivity(), ChatActivity.class).putExtra("userId",
                        mAdapter.getItem(position).getUserName()));
            }
        }
    });
    listView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // ??
            if (getActivity().getWindow()
                    .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
                if (getActivity().getCurrentFocus() != null)
                    inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
            }
            return false;
        }
    });

    ImageView addContactView = (ImageView) getView().findViewById(R.id.iv_new_contact);
    // ?
    addContactView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(getActivity(), AddContactActivity.class));
        }
    });
    registerForContextMenu(listView);

    regsiterContactReceiver();
}

From source file:com.grass.caishi.cc.frag.FriendsListFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false))
        return;//w ww. ja  va2s. c om
    inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    listView = (ListView) getView().findViewById(R.id.list);
    // listView.setFootRefresh(false);
    // listView.setPullLoadEnable(true);

    swipeRefreshLayout = (SwipeRefreshLayout) getView().findViewById(R.id.swipeLayout);
    // swipeRefreshLayout.setColorSchemeResources(R.color.swipe_color_1,
    // R.color.swipe_color_2, R.color.swipe_color_3, R.color.swipe_color_4);
    // swipeRefreshLayout.setSize(SwipeRefreshLayout.LARGE);
    // swipeRefreshLayout.setProgressBackgroundColor(R.color.swipe_background_color);
    swipeRefreshLayout.setProgressViewEndTarget(true, 100);

    swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
        @Override
        public void onRefresh() {
            ((MainActivity) getActivity()).refreshFriends();
        }
    });

    sidebar = (Sidebar) getView().findViewById(R.id.sidebar);
    sidebar.setListView(listView);
    contactList = new ArrayList<User>();
    // ?contactlist
    getContactList();
    // adapter
    adapter = new ContactAdapter(getActivity(), R.layout.row_contact, contactList);
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String username = adapter.getItem(position).getUsername();
            if (Constant.NEW_FRIENDS_USERNAME.equals(username)) {
                // ?
                User user = MyApplication.getInstance().getContactList(false)
                        .get(Constant.NEW_FRIENDS_USERNAME);
                user.setUnreadMsgCount(0);
                startActivity(new Intent(getActivity(), NewFriendsMsgActivity.class));
            } else if (Constant.GROUP_USERNAME.equals(username)) {
                // ??
                startActivity(new Intent(getActivity(), GroupsActivity.class));
            } else if (Constant.KEFU.equals(username)) {
                // ??
                startActivity(new Intent(getActivity(), ChatActivity.class).putExtra("userId", Constant.KEFU)
                        .putExtra("chatType", 0));
            } else {

                startActivity(new Intent(getActivity(), Userinfo.class).putExtra("userId",
                        adapter.getItem(position).getUsername()));
            }
        }
    });
    listView.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // ??
            if (getActivity().getWindow()
                    .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
                if (getActivity().getCurrentFocus() != null)
                    inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
            }
            return false;
        }
    });

    ImageView addContactView = (ImageView) getView().findViewById(R.id.iv_new_contact);
    // ?
    addContactView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(getActivity(), AddContactActivity.class));
        }
    });
    registerForContextMenu(listView);
    isInitDone = true;
    refresh();

    // // ?
    // query = (EditText) getView().findViewById(R.id.query);
    // // ?button
    // clearSearch = (ImageButton) getView().findViewById(R.id.search_clear);
    // query.addTextChangedListener(new TextWatcher() {
    // public void onTextChanged(CharSequence s, int start, int before, int count) {
    // adapter.getFilter().filter(s);
    // if (s.length() > 0) {
    // clearSearch.setVisibility(View.VISIBLE);
    // } else {
    // clearSearch.setVisibility(View.INVISIBLE);
    // }
    // }
    //
    // public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    // }
    //
    // public void afterTextChanged(Editable s) {
    // }
    // });
    // clearSearch.setOnClickListener(new OnClickListener() {
    // @Override
    // public void onClick(View v) {
    // query.getText().clear();
    // }
    // });

}

From source file:nl.vincentketelaars.mexen.activities.RollDice.java

protected void setupDice(ImageView[] diesIn, ImageView[] vastImagesIn, int[] rollIn, boolean vastIn[]) {
    this.dies = diesIn;
    this.vastImages = vastImagesIn;
    this.roll = rollIn;
    this.vast = vastIn;

    // Get the dice
    for (int i = 0; i < diceImages.length; i++) {
        dice[i] = getResources().getDrawable(diceImages[i]);
    }// w w  w  . j a v  a  2 s  .c om

    // Set drawable
    animationHandler = new Handler(new Handler.Callback() {
        public boolean handleMessage(Message msg) {
            for (int i = 0; i < dies.length; i++) {
                dies[i].setImageDrawable(dice[roll[i]]);
            }
            return true;
        }
    });

    // Listener that increments the number on the dice
    OnClickListener diceListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!changeDiceValueAllowed())
                return;
            for (int i = 0; i < dies.length; i++) {
                if (dies[i].getId() == v.getId() && !vast[i]) {
                    roll[i] = (roll[i] + 1) % diceImages.length;
                }
            }
            animationHandler.sendEmptyMessage(0);
            evaluateChances();
        }
    };

    // Listener that sets vast
    OnLongClickListener vastListener = new OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            int numVast = 0;
            for (boolean v : vast) {
                if (v)
                    numVast++;
            }
            for (int i = 0; i < dies.length; i++) {
                if (dies[i].getId() == view.getId()) {
                    if (vastImages[i].getVisibility() == View.VISIBLE) {
                        setVast(i, false);
                        break;
                    }
                    if (isSpecialVastCase())
                        break;
                    if (vastImages[i].getVisibility() == View.INVISIBLE && numVast < dies.length - 1
                            && roll[i] < getHighestVastNumber()) { // Only vast till highest allowed number
                        setVast(i, true);
                    }
                }
            }
            evaluateChances();
            return true;
        }
    };

    for (ImageView d : dies) {
        d.setOnClickListener(diceListener); // Set the listener for each dice
        d.setOnLongClickListener(vastListener); // Set the long listener for each dice
    }
    evaluateChances();
}

From source file:me.cpwc.nibblegram.ui.Components.EmojiView.java

private void init() {
    setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < Emoji.data.length; i++) {
        GridView gridView = new GridView(getContext());
        if (AndroidUtilities.isTablet()) {
            gridView.setColumnWidth(AndroidUtilities.dp(60));
        } else {/*from  w  w w  .  j a  v a 2 s. c om*/
            gridView.setColumnWidth(AndroidUtilities.dp(45));
        }
        gridView.setNumColumns(-1);
        views.add(gridView);

        EmojiGridAdapter localEmojiGridAdapter = new EmojiGridAdapter(Emoji.data[i]);
        gridView.setAdapter(localEmojiGridAdapter);
        AndroidUtilities.setListViewEdgeEffectColor(gridView, 0xff999999);
        adapters.add(localEmojiGridAdapter);
    }

    setBackgroundColor(0xff222222);
    pager = new ViewPager(getContext());
    pager.setAdapter(new EmojiPagesAdapter());
    PagerSlidingTabStrip tabs = new PagerSlidingTabStrip(getContext());
    tabs.setViewPager(pager);
    tabs.setShouldExpand(true);
    tabs.setIndicatorColor(0xff33b5e5);
    tabs.setIndicatorHeight(AndroidUtilities.dp(2.0f));
    tabs.setUnderlineHeight(AndroidUtilities.dp(2.0f));
    tabs.setUnderlineColor(0x66000000);
    tabs.setTabBackground(0);
    LinearLayout localLinearLayout = new LinearLayout(getContext());
    localLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
    localLinearLayout.addView(tabs,
            new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f));
    ImageView localImageView = new ImageView(getContext());
    localImageView.setImageResource(R.drawable.ic_emoji_backspace);
    localImageView.setScaleType(ImageView.ScaleType.CENTER);
    localImageView.setBackgroundResource(R.drawable.bg_emoji_bs);
    localImageView.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            if (EmojiView.this.listener != null) {
                EmojiView.this.listener.onBackspace();
            }
        }
    });
    localLinearLayout.addView(localImageView,
            new LinearLayout.LayoutParams(AndroidUtilities.dp(61), LayoutParams.MATCH_PARENT));
    recentsWrap = new FrameLayout(getContext());
    recentsWrap.addView(views.get(0));
    TextView localTextView = new TextView(getContext());
    localTextView.setText(LocaleController.getString("NoRecent", R.string.NoRecent));
    localTextView.setTextSize(18.0f);
    localTextView.setTextColor(-7829368);
    localTextView.setGravity(17);
    recentsWrap.addView(localTextView);
    views.get(0).setEmptyView(localTextView);
    addView(localLinearLayout, new LinearLayout.LayoutParams(-1, AndroidUtilities.dp(48.0f)));
    addView(pager);
    loadRecents();
    if (Emoji.data[0] == null || Emoji.data[0].length == 0) {
        pager.setCurrentItem(1);
    }
}