Java Code Examples for android.widget.ImageView#setSelected()

The following examples show how to use android.widget.ImageView#setSelected() . 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: AdViewpagerUtil.java    From AdViewPager with Apache License 2.0 6 votes vote down vote up
public void initDots(int length)
{
    if(dotlayout == null)
        return;
    dotlayout.removeAllViews();
    LinearLayout.LayoutParams mParams = new LinearLayout.LayoutParams(dip2px(context, dotsize), dip2px(context, dotsize));
    mParams.setMargins(dip2px(context, dotoffset), 0, dip2px(context, dotoffset), 0);//设置小圆点左右之间的间隔

    dotViews = new ImageView[length];

    for(int i = 0; i < length; i++)
    {
        ImageView imageView = new ImageView(context);
        imageView.setLayoutParams(mParams);
        imageView.setImageResource(R.drawable.dot_selector);
        if(i== 0)
        {
            imageView.setSelected(true);//默认启动时,选中第一个小圆点
        }
        else {
            imageView.setSelected(false);
        }
        dotViews[i] = imageView;//得到每个小圆点的引用,用于滑动页面时,(onPageSelected方法中)更改它们的状态。
        dotlayout.addView(imageView);//添加到布局里面显示
    }
}
 
Example 2
Source File: CallActivity.java    From linphone-android with GNU General Public License v3.0 6 votes vote down vote up
private void displayPausedConference() {
    LinearLayout pausedConferenceView =
            (LinearLayout)
                    LayoutInflater.from(this)
                            .inflate(R.layout.call_conference_paused_cell, null, false);

    ImageView conferenceResume = pausedConferenceView.findViewById(R.id.conference_resume);
    conferenceResume.setSelected(true);
    conferenceResume.setOnClickListener(
            new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    LinphoneManager.getCallManager().resumeConference();
                    updateCallsList();
                }
            });

    mCallsList.addView(pausedConferenceView);
}
 
Example 3
Source File: AdViewpagerUtil.java    From youqu_master with Apache License 2.0 6 votes vote down vote up
/**
 * 初始化标识点
 *
 * @param length
 */
public void initDots(int length) {
    if (dotlayout == null)
        return;
    dotlayout.removeAllViews();
    LinearLayout.LayoutParams mParams = new LinearLayout.LayoutParams(dip2px(context, dotsize), dip2px(context, dotsize));
    mParams.setMargins(dip2px(context, dotoffset), 0, dip2px(context, dotoffset), 0);//设置小圆点左右之间的间隔

    dotViews = new ImageView[length];

    for (int i = 0; i < length; i++) {
        ImageView imageView = new ImageView(context);
        imageView.setLayoutParams(mParams);
        imageView.setImageResource(R.drawable.dot_selector);
        if (i == 0) {
            imageView.setSelected(true);//默认启动时,选中第一个小圆点
        } else {
            imageView.setSelected(false);
        }
        dotViews[i] = imageView;//得到每个小圆点的引用,用于滑动页面时,(onPageSelected方法中)更改它们的状态。
        dotlayout.addView(imageView);//添加到布局里面显示
    }
}
 
Example 4
Source File: WeatherActivity.java    From DongWeather with Apache License 2.0 6 votes vote down vote up
/**
 * 导航栏shape初始化,动态生成匹配数量的shape
 */
public void initGuideView() {
    LinearLayout layout = (LinearLayout)findViewById(R.id.vp_guide_layout);
    LinearLayout.LayoutParams mParams = new LinearLayout.LayoutParams(20, 20);
    mParams.setMargins(0, 0, 0, 0);//设置小圆点左右之间的间隔

    guideShapeViewArrayList.clear();
    layout.removeAllViews();
    for(int i = 0; i < selectedCountisList.size(); i++)
    {
        ImageView imageView = new ImageView(this);
        imageView.setLayoutParams(mParams);
        imageView.setImageResource(R.drawable.guide_shape_select);
        if(i == currentPosition)
        {
            imageView.setSelected(true);//默认启动时,选中第一个小圆点
        }
        else {
            imageView.setSelected(false);
        }
        guideShapeViewArrayList.add(i, imageView);//得到每个小圆点的引用,用于滑动页面时,(onPageSelected方法中)更改它们的状态。
        layout.addView(imageView);//添加到布局里面显示
    }
}
 
Example 5
Source File: HomeActivity.java    From Socket.io-FLSocketIM-Android with MIT License 6 votes vote down vote up
private void tabItemClick(int position) {

        String [] titles = {"FoxChat", "联系人", "我"};
        setTitle(titles[position]);
        viewPager.setCurrentItem(position, false);
        for(ImageView imageView : imageViews) {

            imageView.setSelected(false);
        }
        for (TextView textView : textViews) {
            textView.setSelected(false);
        }

        ImageView seletedImage = imageViews.get(position);
        seletedImage.setSelected(true);

        TextView seletedTextView = textViews.get(position);
        seletedTextView.setSelected(true);
    }
 
Example 6
Source File: AdViewpagerUtil.java    From AndroidPickPhotoDialog with Apache License 2.0 6 votes vote down vote up
public void initDots(int length)
{
    if(dotlayout == null)
        return;
    dotlayout.removeAllViews();
    LinearLayout.LayoutParams mParams = new LinearLayout.LayoutParams(dip2px(context, dotsize), dip2px(context, dotsize));
    mParams.setMargins(dip2px(context, dotoffset), 0, dip2px(context, dotoffset), 0);//设置小圆点左右之间的间隔

    dotViews = new ImageView[length];

    for(int i = 0; i < length; i++)
    {
        ImageView imageView = new ImageView(context);
        imageView.setLayoutParams(mParams);
        imageView.setImageResource(R.drawable.dot_selector);
        if(i== 0)
        {
            imageView.setSelected(true);//默认启动时,选中第一个小圆点
        }
        else {
            imageView.setSelected(false);
        }
        dotViews[i] = imageView;//得到每个小圆点的引用,用于滑动页面时,(onPageSelected方法中)更改它们的状态。
        dotlayout.addView(imageView);//添加到布局里面显示
    }
}
 
Example 7
Source File: WeekdaysPicker.java    From Weekdays-Selector with MIT License 6 votes vote down vote up
private void setDaySelected(ImageView dayView, boolean b) {
    dayView.setSelected(b);
    String dayText = getDayText(dayView);
    int tag = (int) dayView.getTag();
    if (b) {
        dayView.setImageDrawable(getDrawableBorderSelected(dayText, selectedDayBackgroundColor, selectedBuilder));
        selectedDays.add(tag);
    } else {
        if (tag == SATURDAY || tag == SUNDAY) {
            dayView.setImageDrawable(getDrawableBorderUnselected(dayText, unSelectedWeekendColor, unselectedWeekendBuilder));
        } else {
            dayView.setImageDrawable(getDrawableBorderUnselected(dayText, unSelectedDayBackgroundColor, unselectedBuilder));
        }
        selectedDays.remove(tag);
    }
}
 
Example 8
Source File: Banner.java    From ZhihuDaily with Apache License 2.0 6 votes vote down vote up
private void initIndicator() {
    indicator.removeAllViews();
    for (int i = 0; i < mDataList.size() && mDataList.size() > 1; i++) {
        ImageView point = new ImageView(getContext());
        LayoutParams params = new LayoutParams(20, 20);
        params.leftMargin = 5;
        params.rightMargin = 5;
        point.setImageResource(R.drawable.point_selector);
        if (i == 0) {
            point.setSelected(true);
        } else {
            point.setSelected(false);
        }
        point.setLayoutParams(params);
        indicator.addView(point);
    }
}
 
Example 9
Source File: PagerSlidingTabStrip.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void addIconTab(final int position, Drawable drawable) {
    ImageView tab = new ImageView(getContext()) {
        @Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            if (pager.getAdapter() instanceof IconTabProvider) {
                ((IconTabProvider) pager.getAdapter()).customOnDraw(canvas, position);
            }
        }
    };
    tab.setFocusable(true);
    tab.setImageDrawable(drawable);
    tab.setScaleType(ImageView.ScaleType.CENTER);
    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (pager.getAdapter() instanceof IconTabProvider) {
                if (!((IconTabProvider) pager.getAdapter()).canScrollToTab(position)) {
                    return;
                }
            }
            pager.setCurrentItem(position);
        }
    });
    tabsContainer.addView(tab);
    tab.setSelected(position == currentPosition);
}
 
Example 10
Source File: RegularVerticalPresenter.java    From TvRecyclerView with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView() {
    ImageView view = new ImageView(getContext());
    view.setSelected(true);
    view.setFocusable(true);
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(413, 238);
    view.setLayoutParams(params);
    return view;
}
 
Example 11
Source File: PairingActivity.java    From microbit with Apache License 2.0 5 votes vote down vote up
/**
 * Sets a clicked cell on/off.
 *
 * @param image An image of a clicked cell.
 * @param pos   Position of a clicked cell.
 * @return True, if cell is on and false otherwise.
 */
private boolean toggleLED(ImageView image, int pos) {
    boolean isOn;
    //Toast.makeText(this, "Pos :" +  pos, Toast.LENGTH_SHORT).show();
    int state = (Integer) image.getTag(R.id.ledState);
    if(state != 1) {
        DEVICE_CODE_ARRAY[pos] = 1;
        image.setBackground(getApplication().getResources().getDrawable(R.drawable.red_white_led_btn));
        image.setTag(R.id.ledState, 1);
        isOn = true;

    } else {
        DEVICE_CODE_ARRAY[pos] = 0;
        image.setBackground(getApplication().getResources().getDrawable(R.drawable.white_red_led_btn));
        image.setTag(R.id.ledState, 0);
        isOn = false;
        // Update the code to consider the still ON LED below the toggled one
        if(pos < 20) {
            DEVICE_CODE_ARRAY[pos + 5] = 1;
        }
    }

    image.setSelected(false);
    int position = (Integer) image.getTag(R.id.position);
    image.setContentDescription("" + position + getLEDStatus(pos));
    return isOn;
}
 
Example 12
Source File: DialogCreator.java    From MissZzzReader with Apache License 2.0 5 votes vote down vote up
private static void selectedStyle(ImageView curSelected, ReadStyle readStyle, OnReadStyleChangeListener listener) {
    ivLastSelectd.setSelected(false);
    ivLastSelectd = curSelected;
    curSelected.setSelected(true);
    if (listener != null) {
        listener.onChange(readStyle);
    }
}
 
Example 13
Source File: PagerSlidingTabStrip.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void addIconTab(final int position, Drawable drawable, CharSequence contentDescription) {
    ImageView tab = new ImageView(getContext()) {
        @Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            if (pager.getAdapter() instanceof IconTabProvider) {
                ((IconTabProvider) pager.getAdapter()).customOnDraw(canvas, position);
            }
        }

        @Override
        public void setSelected(boolean selected) {
            super.setSelected(selected);
            Drawable background = getBackground();
            if (Build.VERSION.SDK_INT >= 21 && background != null) {
                int color = Theme.getColor(selected ? Theme.key_chat_emojiPanelIconSelected : Theme.key_chat_emojiBottomPanelIcon);
                Theme.setSelectorDrawableColor(background, Color.argb(30, Color.red(color), Color.green(color), Color.blue(color)), true);
            }
        }
    };
    tab.setFocusable(true);
    if (Build.VERSION.SDK_INT >= 21) {
        RippleDrawable rippleDrawable = (RippleDrawable) Theme.createSelectorDrawable(Theme.getColor(Theme.key_chat_emojiBottomPanelIcon));
        Theme.setRippleDrawableForceSoftware(rippleDrawable);
        tab.setBackground(rippleDrawable);
    }
    tab.setImageDrawable(drawable);
    tab.setScaleType(ImageView.ScaleType.CENTER);
    tab.setOnClickListener(v -> {
        if (pager.getAdapter() instanceof IconTabProvider) {
            if (!((IconTabProvider) pager.getAdapter()).canScrollToTab(position)) {
                return;
            }
        }
        pager.setCurrentItem(position, false);
    });
    tabsContainer.addView(tab);
    tab.setSelected(position == currentPosition);
    tab.setContentDescription(contentDescription);
}
 
Example 14
Source File: PagerSlidingTabStrip.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void addIconTab(final int position, Drawable drawable) {
    ImageView tab = new ImageView(getContext()) {
        @Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            if (pager.getAdapter() instanceof IconTabProvider) {
                ((IconTabProvider) pager.getAdapter()).customOnDraw(canvas, position);
            }
        }
    };
    tab.setFocusable(true);
    tab.setImageDrawable(drawable);
    tab.setScaleType(ImageView.ScaleType.CENTER);
    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (pager.getAdapter() instanceof IconTabProvider) {
                if (!((IconTabProvider) pager.getAdapter()).canScrollToTab(position)) {
                    return;
                }
            }
            pager.setCurrentItem(position);
        }
    });
    tabsContainer.addView(tab);
    tab.setSelected(position == currentPosition);
}
 
Example 15
Source File: MainActivity.java    From HaoReader with GNU General Public License v3.0 5 votes vote down vote up
private void setTabSelected(TabLayout.Tab tab, boolean selected) {
    View custom = tab.getCustomView();
    if (custom != null) {
        ImageView icon = custom.findViewById(R.id.icon);
        TextView text = custom.findViewById(R.id.text);
        icon.setSelected(selected);
        text.setSelected(selected);
    }
}
 
Example 16
Source File: PagerSlidingTabStrip.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void addIconTab(final int position, Drawable drawable, CharSequence contentDescription) {
    ImageView tab = new ImageView(getContext()) {
        @Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            if (pager.getAdapter() instanceof IconTabProvider) {
                ((IconTabProvider) pager.getAdapter()).customOnDraw(canvas, position);
            }
        }

        @Override
        public void setSelected(boolean selected) {
            super.setSelected(selected);
            Drawable background = getBackground();
            if (Build.VERSION.SDK_INT >= 21 && background != null) {
                int color = Theme.getColor(selected ? Theme.key_chat_emojiPanelIconSelected : Theme.key_chat_emojiBottomPanelIcon);
                Theme.setSelectorDrawableColor(background, Color.argb(30, Color.red(color), Color.green(color), Color.blue(color)), true);
            }
        }
    };
    tab.setFocusable(true);
    if (Build.VERSION.SDK_INT >= 21) {
        RippleDrawable rippleDrawable = (RippleDrawable) Theme.createSelectorDrawable(Theme.getColor(Theme.key_chat_emojiBottomPanelIcon));
        Theme.setRippleDrawableForceSoftware(rippleDrawable);
        tab.setBackground(rippleDrawable);
    }
    tab.setImageDrawable(drawable);
    tab.setScaleType(ImageView.ScaleType.CENTER);
    tab.setOnClickListener(v -> {
        if (pager.getAdapter() instanceof IconTabProvider) {
            if (!((IconTabProvider) pager.getAdapter()).canScrollToTab(position)) {
                return;
            }
        }
        pager.setCurrentItem(position, false);
    });
    tabsContainer.addView(tab);
    tab.setSelected(position == currentPosition);
    tab.setContentDescription(contentDescription);
}
 
Example 17
Source File: ScrollSlidingTabStrip.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public void addIconTab(Drawable drawable) {
    final int position = tabCount++;
    ImageView tab = new ImageView(getContext());
    tab.setFocusable(true);
    tab.setImageDrawable(drawable);
    tab.setScaleType(ImageView.ScaleType.CENTER);
    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            delegate.onPageSelected(position);
        }
    });
    tabsContainer.addView(tab);
    tab.setSelected(position == currentPosition);
}
 
Example 18
Source File: StarShowActivity.java    From ShadowLayout with MIT License 5 votes vote down vote up
public boolean select(ImageView imageView) {
    if (imageView.isSelected()) {
        imageView.setSelected(false);
        return false;
    } else {
        imageView.setSelected(true);
        return true;
    }
}
 
Example 19
Source File: ChoosePayMethodActivity.java    From FlowGeek with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    ImageView mChooserView = (ImageView) view.getTag();
    mChooserView.setSelected(!mChooserView.isSelected());
}
 
Example 20
Source File: PlayDetailActivity.java    From BeMusic with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_play_detail);

    mToolbar = (Toolbar)findViewById(R.id.play_detail_tool_bar);

    mTitleTv = (TextView)findViewById(R.id.play_detail_title);
    mArtistTv = (TextView)findViewById(R.id.play_detail_artist);
    mAlbumTv = (TextView)findViewById(R.id.play_detail_album);
    mPositionTv = (TextView)findViewById(R.id.play_detail_position);
    mDurationTv = (TextView)findViewById(R.id.play_detail_duration);

    mPanel = findViewById(R.id.play_detail_panel);

    mThumbIv = (ImageView)findViewById(R.id.play_detail_thumb);
    mSeekBar = (SeekBar)findViewById(R.id.play_detail_seek_bar);
    mPlayPauseIv = (ImageView)findViewById(R.id.play_detail_play_pause);
    mPreviousIv = (ImageView)findViewById(R.id.play_detail_previous);
    mNextIv = (ImageView)findViewById(R.id.play_detail_next);
    mRuleIv = (ImageView)findViewById(R.id.play_detail_rule_change);
    mPlayListIv = (ImageView)findViewById(R.id.play_detail_play_list);

    final int width = getResources().getDisplayMetrics().widthPixels;
    final int height = getResources().getDisplayMetrics().heightPixels;
    final int size = Math.min(width, height);
    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)mThumbIv.getLayoutParams();
    if (params == null) {
        params = new RelativeLayout.LayoutParams(size, size);
    } else {
        params.width = size;
        params.height = size;
    }
    mThumbIv.setLayoutParams(params);

    setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setTitle(null);

    mPlayPauseIv.setOnClickListener(mClickListener);
    mPreviousIv.setOnClickListener(mClickListener);
    mNextIv.setOnClickListener(mClickListener);
    mRuleIv.setOnClickListener(mClickListener);
    mPlayListIv.setOnClickListener(mClickListener);
    mSeekBar.setOnSeekBarChangeListener(mSeekListener);

    Song song = PlayManager.getInstance(this).getCurrentSong();
    mPlayPauseIv.setSelected(PlayManager.getInstance(this).isPlaying());
    onPlayRuleChanged(PlayManager.getInstance(this).getRule());
    showSong(song);

}