Search in sources :

Example 1 with ViewPager

use of com.samourai.wallet.widgets.ViewPager in project samourai-wallet-android by Samourai-Wallet.

the class RestoreSeedWalletActivity method setPagerIndicators.

/**
 * Creates pager indicator dynamically using number of fragments present in the adapter
 */
private void setPagerIndicators() {
    indicators = new ImageView[adapter.getCount()];
    // Creating circle dot ImageView based on adapter size
    for (int i = 0; i < adapter.getCount(); i++) {
        indicators[i] = new ImageView(this);
        indicators[i].setImageDrawable(getResources().getDrawable(R.drawable.pager_indicator_dot));
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        params.setMargins(8, 0, 8, 0);
        pagerIndicatorContainer.addView(indicators[i], params);
    }
    // Setting first ImageView as active indicator
    indicators[0].setImageDrawable(getResources().getDrawable(R.drawable.pager_indicator_dot));
    indicators[0].getDrawable().setColorFilter(getResources().getColor(R.color.accent), PorterDuff.Mode.ADD);
    // Viewpager listener is responsible for changing indicator color
    wallet_create_viewpager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            for (int i = 0; i < adapter.getCount(); i++) {
                indicators[i].setImageDrawable(getResources().getDrawable(R.drawable.pager_indicator_dot));
            }
            // here we using PorterDuff mode to overlay color over ImageView to set Active indicator
            // we don't have to create multiple asset for showing active and inactive states of indicators
            indicators[position].getDrawable().setColorFilter(getResources().getColor(R.color.accent), PorterDuff.Mode.ADD);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
}
Also used : ImageView(android.widget.ImageView) ViewPager(com.samourai.wallet.widgets.ViewPager) LinearLayout(android.widget.LinearLayout)

Example 2 with ViewPager

use of com.samourai.wallet.widgets.ViewPager in project samourai-wallet-android by Samourai-Wallet.

the class CreateWalletActivity method setPagerIndicators.

/**
 * Creates pager indicator dynamically using number of fragments present in the adapter
 */
private void setPagerIndicators() {
    indicators = new ImageView[adapter.getCount()];
    // Creating circle dot ImageView based on adapter size
    for (int i = 0; i < adapter.getCount(); i++) {
        indicators[i] = new ImageView(this);
        indicators[i].setImageDrawable(getResources().getDrawable(R.drawable.pager_indicator_dot));
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        params.setMargins(8, 0, 8, 0);
        pagerIndicatorContainer.addView(indicators[i], params);
    }
    // Setting first ImageView as active indicator
    indicators[0].setImageDrawable(getResources().getDrawable(R.drawable.pager_indicator_dot));
    indicators[0].getDrawable().setColorFilter(getResources().getColor(R.color.accent), PorterDuff.Mode.ADD);
    // Viewpager listener is responsible for changing indicator color
    wallet_create_viewpager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            for (int i = 0; i < adapter.getCount(); i++) {
                indicators[i].setImageDrawable(getResources().getDrawable(R.drawable.pager_indicator_dot));
            }
            // here we using PorterDuff mode to overlay color over ImageView to set Active indicator
            // we don't have to create multiple asset for showing active and inactive states of indicators
            indicators[position].getDrawable().setColorFilter(getResources().getColor(R.color.accent), PorterDuff.Mode.ADD);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
}
Also used : ImageView(android.widget.ImageView) ViewPager(com.samourai.wallet.widgets.ViewPager) LinearLayout(android.widget.LinearLayout)

Aggregations

ImageView (android.widget.ImageView)2 LinearLayout (android.widget.LinearLayout)2 ViewPager (com.samourai.wallet.widgets.ViewPager)2