Java Code Examples for android.view.View#setSelected()

The following examples show how to use android.view.View#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: BottomBar.java    From MeiBaseModule with Apache License 2.0 6 votes vote down vote up
@Override
protected void onRestoreInstanceState(Parcelable state) {
    SavedState ss = (SavedState) state;
    super.onRestoreInstanceState(ss.getSuperState());
    if (mCurrentPosition != ss.position) {
        View beforeView = mTabLayout.getChildAt(mCurrentPosition);
        if (beforeView != null) {
            beforeView.setSelected(false);
        }
        View currentView = mTabLayout.getChildAt(ss.position);
        if (currentView != null) {
            currentView.setSelected(true);
        }
    }
    mCurrentPosition = ss.position;
}
 
Example 2
Source File: IconPageIndicator.java    From android-project-wo2b with Apache License 2.0 6 votes vote down vote up
@Override
public void setCurrentItem(int item) {
    if (mViewPager == null) {
        throw new IllegalStateException("ViewPager has not been bound.");
    }
    mSelectedIndex = item;
    mViewPager.setCurrentItem(item);

    int tabCount = mIconsLayout.getChildCount();
    for (int i = 0; i < tabCount; i++) {
        View child = mIconsLayout.getChildAt(i);
        boolean isSelected = (i == item);
        child.setSelected(isSelected);
        if (isSelected) {
            animateToIcon(item);
        }
    }
}
 
Example 3
Source File: MulContactAdapter.java    From Android with MIT License 6 votes vote down vote up
@Override
public void onClick(View v) {
    int posi = (int) v.getTag();
    ContactEntity index = friendEntities.get(posi);
    String pubkey = index.getPub_key();
    if (!members.contains(pubkey)) {
        View secview = v.findViewById(R.id.select);
        if (selectEntities.contains(index)) {
            selectEntities.remove(index);
            secview.setSelected(false);
        } else {
            selectEntities.add(index);
            secview.setSelected(true);
        }
    }

    if(onSeleFriendListence != null){
        onSeleFriendListence.seleFriend(selectEntities);
    }

}
 
Example 4
Source File: IconPageIndicator.java    From BigApp_WordPress_Android with Apache License 2.0 6 votes vote down vote up
@Override
public void setCurrentItem(int item) {
    if (mViewPager == null) {
        throw new IllegalStateException("ViewPager has not been bound.");
    }
    mSelectedIndex = item;
    mViewPager.setCurrentItem(item);

    int tabCount = mIconsLayout.getChildCount();
    for (int i = 0; i < tabCount; i++) {
        View child = mIconsLayout.getChildAt(i);
        boolean isSelected = (i == item);
        child.setSelected(isSelected);
        if (isSelected) {
            animateToIcon(item);
        }
    }
}
 
Example 5
Source File: CharactersFragment.java    From Gojuon with MIT License 6 votes vote down vote up
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
    try {
        String katakana = mCharactersAdapter.getItem(i)[Characters.INDEX_KATAKANA];

        // Pronounce the character
        Gojuon.pronounce(getActivity(), katakana);

        // Mark as selected.
        if (mSharedPreferences.getBoolean(Gojuon.KEY_HIGHLIGHT_SELECTED, true) && !katakana.isEmpty()) {
            view.setSelected(true);
        }
    } catch (RuntimeException e) {
        e.printStackTrace();
    }
}
 
Example 6
Source File: KChartTabView.java    From kAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    if (mSelectedIndex >= 0 && mSelectedIndex < mLlContainer.getChildCount()) {
        mLlContainer.getChildAt(mSelectedIndex).setSelected(false);
    }
    mSelectedIndex = mLlContainer.indexOfChild(v);
    v.setSelected(true);
    mTabSelectListener.onTabSelected(mSelectedIndex);
}
 
Example 7
Source File: WallpaperPickerActivity.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
@Thunk void selectTile(View v) {
    if (mSelectedTile != null) {
        mSelectedTile.setSelected(false);
        mSelectedTile = null;
    }
    mSelectedTile = v;
    v.setSelected(true);
    mSelectedIndex = mWallpapersView.indexOfChild(v);
    // TODO: Remove this once the accessibility framework and
    // services have better support for selection state.
    v.announceForAccessibility(
            getContext().getString(R.string.announce_selection, v.getContentDescription()));
}
 
Example 8
Source File: KChartTabView.java    From KChartView with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    if (mSelectedIndex >= 0 && mSelectedIndex < mLlContainer.getChildCount()) {
        mLlContainer.getChildAt(mSelectedIndex).setSelected(false);
    }
    mSelectedIndex = mLlContainer.indexOfChild(v);
    v.setSelected(true);
    mTabSelectListener.onTabSelected(mSelectedIndex);
}
 
Example 9
Source File: HListView.java    From letv with Apache License 2.0 5 votes vote down vote up
private void handleNewSelectionChange(View selectedView, int direction, int newSelectedPosition, boolean newFocusAssigned) {
    if (newSelectedPosition == -1) {
        throw new IllegalArgumentException("newSelectedPosition needs to be valid");
    }
    int leftViewIndex;
    int rightViewIndex;
    View leftView;
    View rightView;
    boolean leftSelected = false;
    int selectedIndex = this.mSelectedPosition - this.mFirstPosition;
    int nextSelectedIndex = newSelectedPosition - this.mFirstPosition;
    if (direction == 33) {
        leftViewIndex = nextSelectedIndex;
        rightViewIndex = selectedIndex;
        leftView = getChildAt(leftViewIndex);
        rightView = selectedView;
        leftSelected = true;
    } else {
        leftViewIndex = selectedIndex;
        rightViewIndex = nextSelectedIndex;
        leftView = selectedView;
        rightView = getChildAt(rightViewIndex);
    }
    int numChildren = getChildCount();
    if (leftView != null) {
        boolean z = !newFocusAssigned && leftSelected;
        leftView.setSelected(z);
        measureAndAdjustRight(leftView, leftViewIndex, numChildren);
    }
    if (rightView != null) {
        z = (newFocusAssigned || leftSelected) ? false : true;
        rightView.setSelected(z);
        measureAndAdjustRight(rightView, rightViewIndex, numChildren);
    }
}
 
Example 10
Source File: PagerSlidingTabStrip.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
public void redrawTabs(int currentPosition) {
    try {
        for (int i = 0; i < tabsContainer.getChildCount(); ++i) {
            View tmp = tabsContainer.getChildAt(i);
            if (i == currentPosition) {
                tmp.setSelected(true);
            } else {
                tmp.setSelected(false);
            }
        }
    } catch (Exception e) {
        //no-op
    }
}
 
Example 11
Source File: LegacyGlobalActions.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public View create(Context context, View convertView, ViewGroup parent,
        LayoutInflater inflater) {
    View v = inflater.inflate(R.layout.global_actions_silent_mode, parent, false);

    int selectedIndex = ringerModeToIndex(mAudioManager.getRingerMode());
    for (int i = 0; i < 3; i++) {
        View itemView = v.findViewById(ITEM_IDS[i]);
        itemView.setSelected(selectedIndex == i);
        // Set up click handler
        itemView.setTag(i);
        itemView.setOnClickListener(this);
    }
    return v;
}
 
Example 12
Source File: SimplePagedTabsHelper.java    From BetterWeather with Apache License 2.0 5 votes vote down vote up
public void addTab(CharSequence label, int contentViewId) {
    View tabView = LayoutInflater.from(mContext).inflate(R.layout.tab, mTabContainer, false);
    ((TextView) tabView.findViewById(R.id.tab)).setText(label);
    tabView.setOnClickListener(mTabClickListener);
    int position = mTabContentIds.size();
    tabView.setSelected(mPager.getCurrentItem() == position);
    mTabPositions.put(tabView, position);
    mTabContainer.addView(tabView);
    mTabContentIds.add(contentViewId);
}
 
Example 13
Source File: TabLayout.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
/**
 * Called when a selected tab is added. Unselects all other tabs in the TabLayout.
 *
 * @param position Position of the selected tab.
 */
private void setSelectedTabView(int position) {
  final int tabCount = slidingTabIndicator.getChildCount();
  if (position < tabCount) {
    for (int i = 0; i < tabCount; i++) {
      final View child = slidingTabIndicator.getChildAt(i);
      child.setSelected(i == position);
      child.setActivated(i == position);
    }
  }
}
 
Example 14
Source File: ReaderSettingDialog.java    From FriendBook with GNU General Public License v3.0 5 votes vote down vote up
private void setPageMode(int pageMode) {
    View selectedView = null;
    switch (pageMode) {
        case PageView.PAGE_MODE_COVER:
            readTvFlipOverCover.setSelected(true);
            selectedView = readTvFlipOverCover;
            break;
        case PageView.PAGE_MODE_SIMULATION:
            readTvFlipOverSimulation.setSelected(true);
            selectedView = readTvFlipOverSimulation;
            break;
        case PageView.PAGE_MODE_SLIDE:
            readTvFlipOverSlide.setSelected(true);
            selectedView = readTvFlipOverSlide;
            break;
        case PageView.PAGE_MODE_NONE:
            readTvFlipOverNone.setSelected(true);
            selectedView = readTvFlipOverNone;
            break;
    }
    for (View view : flipOverViews) {
        if (view != selectedView && view.isSelected()) {
            view.setSelected(false);
        }
    }
    if (pageMode != mPageView.getPageMode()) {
        mPageView.setPageAnimMode(pageMode);
        ReaderSettingManager
                .getInstance()
                .setPageMode(pageMode);
    }

}
 
Example 15
Source File: IndicatorView.java    From AndroidSweetSheet with Apache License 2.0 5 votes vote down vote up
private void setSelect(int i) {
    View view = mIndicators.get(i);
    view.setSelected(true);
    if(mPreSelectPosition != -1){
        mIndicators.get(mPreSelectPosition).
        setSelected(false);
    }
    mPreSelectPosition=i;
}
 
Example 16
Source File: ReadInterfacePop.java    From HaoReader with GNU General Public License v3.0 5 votes vote down vote up
private void updatePageMode(int pageMode) {
    for (int i = 0; i < pageAnimModeView.getChildCount(); i++) {
        View child = pageAnimModeView.getChildAt(i);
        if (child instanceof AppCompatButton) {
            int pos = Integer.parseInt((String) child.getTag());
            child.setSelected(pageMode == pos);
        }
    }
}
 
Example 17
Source File: FileDialog.java    From mOrgAnd with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Quando clica no item da lista, deve-se: 1) Se for diretorio, abre seus
 * arquivos filhos; 2) Se puder escolher diretorio, define-o como sendo o
 * path escolhido. 3) Se for arquivo, define-o como path escolhido. 4) Ativa
 * botao de selecao.
 */
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {

    File file = new File(path.get(position));

    setSelectVisible(v);

    if (file.isDirectory()) {
        selectButton.setEnabled(false);
        if (file.canRead()) {
            lastPositions.put(currentPath, position);
            getDir(path.get(position));
            if (canSelectDir) {
                selectedFile = file;
                v.setSelected(true);
                selectButton.setEnabled(true);
            }
        } else {
            new AlertDialog.Builder(this).setIcon(R.drawable.ic_launcher)
                    .setTitle("[" + file.getName() + "] " + getText(R.string.cant_read_folder))
                    .setPositiveButton("OK", new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                        }
                    }).show();
        }
    } else {
        selectedFile = file;
        v.setSelected(true);
        selectButton.setEnabled(true);
    }
}
 
Example 18
Source File: ViewPageAdapter.java    From recurrence with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void tabSelected(View view) {
    view.setSelected(true);
}
 
Example 19
Source File: MainActivity.java    From SelectorDrawable with Apache License 2.0 4 votes vote down vote up
public void onClick(View view) {
    view.setSelected(!view.isSelected());
}
 
Example 20
Source File: SlidingTabLayout.java    From AndroidStarterKit with MIT License 4 votes vote down vote up
private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;
        View tabTitleView = null;

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = tabView.findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = tabView;
        }

        if (mDistributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            lp.width = 0;
            lp.weight = 1;
        }

        if (TextView.class.isInstance(tabTitleView)) {
            ((TextView) tabTitleView).setText(adapter.getPageTitle(i));
        } else if (ImageView.class.isInstance(tabTitleView) && adapter instanceof TabIconProvider){
            TabIconProvider mTabIconProvider = (TabIconProvider) adapter;
            tabTitleView.setBackgroundResource(mTabIconProvider.getPageIconResId(i));
        }

        tabView.setOnClickListener(tabClickListener);

        String desc = mContentDescriptions.get(i, null);
        if (desc != null) {
            tabView.setContentDescription(desc);
        }

        mTabStrip.addView(tabView);
        if (i == mViewPager.getCurrentItem()) {
            tabView.setSelected(true);
        }
    }
}