Search in sources :

Example 46 with ViewPager

use of androidx.viewpager.widget.ViewPager in project PageIndicatorView by romandanylyk.

the class PageIndicatorView method findViewPager.

private void findViewPager(@Nullable ViewParent viewParent) {
    boolean isValidParent = viewParent != null && viewParent instanceof ViewGroup && ((ViewGroup) viewParent).getChildCount() > 0;
    if (!isValidParent) {
        return;
    }
    int viewPagerId = manager.indicator().getViewPagerId();
    ViewPager viewPager = findViewPager((ViewGroup) viewParent, viewPagerId);
    if (viewPager != null) {
        setViewPager(viewPager);
    } else {
        findViewPager(viewParent.getParent());
    }
}
Also used : ViewGroup(android.view.ViewGroup) ViewPager(androidx.viewpager.widget.ViewPager) SuppressLint(android.annotation.SuppressLint)

Example 47 with ViewPager

use of androidx.viewpager.widget.ViewPager in project Gadgetbridge by Freeyourgadget.

the class NonSwipeableViewPager method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_charts);
    int tabFragmentToOpen = -1;
    initDates();
    IntentFilter filterLocal = new IntentFilter();
    filterLocal.addAction(GBDevice.ACTION_DEVICE_CHANGED);
    LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filterLocal);
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        mGBDevice = extras.getParcelable(GBDevice.EXTRA_DEVICE);
        tabFragmentToOpen = extras.getInt(EXTRA_FRAGMENT_ID);
    } else {
        throw new IllegalArgumentException("Must provide a device when invoking this activity");
    }
    enabledTabsList = fillChartsTabsList(getDevice(), this);
    swipeLayout = findViewById(R.id.activity_swipe_layout);
    swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            fetchActivityData();
        }
    });
    enableSwipeRefresh(true);
    // Set up the ViewPager with the sections adapter.
    NonSwipeableViewPager viewPager = findViewById(R.id.charts_pager);
    viewPager.setAdapter(getPagerAdapter());
    if (tabFragmentToOpen > -1) {
        // open the tab as specified in the intent
        viewPager.setCurrentItem(tabFragmentToOpen);
    }
    viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

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

        @Override
        public void onPageSelected(int position) {
        }

        @Override
        public void onPageScrollStateChanged(int state) {
            enableSwipeRefresh(state == ViewPager.SCROLL_STATE_IDLE);
        }
    });
    dateBar = findViewById(R.id.charts_date_bar);
    mDateControl = findViewById(R.id.charts_text_date);
    mDateControl.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            String detailedDuration = formatDetailedDuration();
            new ShowDurationDialog(detailedDuration, ChartsActivity.this).show();
        }
    });
    Button mPrevButton = findViewById(R.id.charts_previous_day);
    mPrevButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            handleButtonClicked(DATE_PREV_DAY);
        }
    });
    Button mNextButton = findViewById(R.id.charts_next_day);
    mNextButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            handleButtonClicked(DATE_NEXT_DAY);
        }
    });
    Button mPrevWeekButton = findViewById(R.id.charts_previous_week);
    mPrevWeekButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            handleButtonClicked(DATE_PREV_WEEK);
        }
    });
    Button mNextWeekButton = findViewById(R.id.charts_next_week);
    mNextWeekButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            handleButtonClicked(DATE_NEXT_WEEK);
        }
    });
    Button mPrevMonthButton = findViewById(R.id.charts_previous_month);
    mPrevMonthButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            handleButtonClicked(DATE_PREV_MONTH);
        }
    });
    Button mNextMonthButton = findViewById(R.id.charts_next_month);
    mNextMonthButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            handleButtonClicked(DATE_NEXT_MONTH);
        }
    });
}
Also used : IntentFilter(android.content.IntentFilter) Bundle(android.os.Bundle) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) ViewPager(androidx.viewpager.widget.ViewPager) View(android.view.View) TextView(android.widget.TextView) Button(android.widget.Button)

Example 48 with ViewPager

use of androidx.viewpager.widget.ViewPager in project android by nextcloud.

the class FirstRunActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    enableAccountHandling = false;
    super.onCreate(savedInstanceState);
    setContentView(R.layout.first_run_activity);
    boolean isProviderOrOwnInstallationVisible = getResources().getBoolean(R.bool.show_provider_or_own_installation);
    setSlideshowSize(getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE);
    Button loginButton = findViewById(R.id.login);
    loginButton.setBackgroundColor(getResources().getColor(R.color.login_btn_tint));
    loginButton.setTextColor(getResources().getColor(R.color.primary));
    loginButton.setOnClickListener(v -> {
        if (getIntent().getBooleanExtra(EXTRA_ALLOW_CLOSE, false)) {
            Intent authenticatorActivityIntent = new Intent(this, AuthenticatorActivity.class);
            authenticatorActivityIntent.putExtra(AuthenticatorActivity.EXTRA_USE_PROVIDER_AS_WEBLOGIN, false);
            startActivityForResult(authenticatorActivityIntent, FIRST_RUN_RESULT_CODE);
        } else {
            finish();
        }
    });
    Button providerButton = findViewById(R.id.signup);
    providerButton.setBackgroundColor(getResources().getColor(R.color.primary));
    providerButton.setTextColor(getResources().getColor(R.color.login_text_color));
    providerButton.setVisibility(isProviderOrOwnInstallationVisible ? View.VISIBLE : View.GONE);
    providerButton.setOnClickListener(v -> {
        Intent authenticatorActivityIntent = new Intent(this, AuthenticatorActivity.class);
        authenticatorActivityIntent.putExtra(AuthenticatorActivity.EXTRA_USE_PROVIDER_AS_WEBLOGIN, true);
        if (getIntent().getBooleanExtra(EXTRA_ALLOW_CLOSE, false)) {
            startActivityForResult(authenticatorActivityIntent, FIRST_RUN_RESULT_CODE);
        } else {
            authenticatorActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(authenticatorActivityIntent);
        }
    });
    TextView hostOwnServerTextView = findViewById(R.id.host_own_server);
    hostOwnServerTextView.setTextColor(getResources().getColor(R.color.login_text_color));
    hostOwnServerTextView.setVisibility(isProviderOrOwnInstallationVisible ? View.VISIBLE : View.GONE);
    if (!isProviderOrOwnInstallationVisible) {
        hostOwnServerTextView.setOnClickListener(v -> onHostYourOwnServerClick());
    }
    progressIndicator = findViewById(R.id.progressIndicator);
    ViewPager viewPager = findViewById(R.id.contentPanel);
    // Sometimes, accounts are not deleted when you uninstall the application so we'll do it now
    if (onboarding.isFirstRun()) {
        userAccountManager.removeAllAccounts();
    }
    FeaturesViewAdapter featuresViewAdapter = new FeaturesViewAdapter(getSupportFragmentManager(), getFirstRun());
    progressIndicator.setNumberOfSteps(featuresViewAdapter.getCount());
    viewPager.setAdapter(featuresViewAdapter);
    viewPager.addOnPageChangeListener(this);
}
Also used : FeaturesViewAdapter(com.owncloud.android.ui.adapter.FeaturesViewAdapter) Button(android.widget.Button) Intent(android.content.Intent) TextView(android.widget.TextView) ViewPager(androidx.viewpager.widget.ViewPager)

Example 49 with ViewPager

use of androidx.viewpager.widget.ViewPager in project SmartTabLayout by ogaclejapan.

the class DemoTabWithNotificationMarkActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_demo_tab_with_notification_mark);
    final Demo demo = getDemo();
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle(demo.titleResId);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    ViewGroup tab = (ViewGroup) findViewById(R.id.tab);
    tab.addView(LayoutInflater.from(this).inflate(demo.layoutResId, tab, false));
    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
    final SmartTabLayout viewPagerTab = (SmartTabLayout) findViewById(R.id.viewpagertab);
    viewPagerTab.setCustomTabView(this);
    FragmentPagerItems pages = new FragmentPagerItems(this);
    for (int titleResId : demo.tabs()) {
        pages.add(FragmentPagerItem.of(getString(titleResId), DemoFragment.class));
    }
    FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(getSupportFragmentManager(), pages);
    viewPager.setAdapter(adapter);
    viewPagerTab.setViewPager(viewPager);
    viewPagerTab.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            super.onPageSelected(position);
            View tab = viewPagerTab.getTabAt(position);
            View mark = tab.findViewById(R.id.custom_tab_notification_mark);
            mark.setVisibility(View.GONE);
        }
    });
    findViewById(R.id.test).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            int position = Math.abs(random.nextInt()) % demo.tabs().length;
            View tab = viewPagerTab.getTabAt(position);
            View mark = tab.findViewById(R.id.custom_tab_notification_mark);
            mark.setVisibility(View.VISIBLE);
        }
    });
}
Also used : ViewGroup(android.view.ViewGroup) ViewPager(androidx.viewpager.widget.ViewPager) ImageView(android.widget.ImageView) View(android.view.View) FragmentPagerItemAdapter(com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItemAdapter) FragmentPagerItems(com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItems) Toolbar(androidx.appcompat.widget.Toolbar) SmartTabLayout(com.ogaclejapan.smarttablayout.SmartTabLayout)

Example 50 with ViewPager

use of androidx.viewpager.widget.ViewPager in project SmartTabLayout by ogaclejapan.

the class DemoRtlActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_rtl);
    Demo demo = getDemo();
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle(demo.titleResId);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    ViewGroup tab = (ViewGroup) findViewById(R.id.tab);
    tab.addView(LayoutInflater.from(this).inflate(demo.layoutResId, tab, false));
    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
    final SmartTabLayout viewPagerTab = (SmartTabLayout) findViewById(R.id.viewpagertab);
    demo.setup(viewPagerTab);
    FragmentPagerItems pages = new FragmentPagerItems(this);
    for (int titleResId : demo.tabs()) {
        pages.add(FragmentPagerItem.of(getString(titleResId), DemoFragment.class));
    }
    FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(getSupportFragmentManager(), pages);
    viewPager.setAdapter(adapter);
    viewPagerTab.setViewPager(viewPager);
}
Also used : FragmentPagerItems(com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItems) ViewGroup(android.view.ViewGroup) ViewPager(androidx.viewpager.widget.ViewPager) FragmentPagerItemAdapter(com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItemAdapter) Toolbar(androidx.appcompat.widget.Toolbar) SmartTabLayout(com.ogaclejapan.smarttablayout.SmartTabLayout)

Aggregations

ViewPager (androidx.viewpager.widget.ViewPager)68 View (android.view.View)24 Intent (android.content.Intent)12 TabLayout (com.google.android.material.tabs.TabLayout)12 Toolbar (androidx.appcompat.widget.Toolbar)11 ViewGroup (android.view.ViewGroup)9 TextView (android.widget.TextView)9 ColorPreferences (me.ccrama.redditslide.Visuals.ColorPreferences)9 ImageView (android.widget.ImageView)8 PageNavigationView (me.majiajie.pagerbottomtabstrip.PageNavigationView)8 Bundle (android.os.Bundle)6 PagerAdapter (androidx.viewpager.widget.PagerAdapter)6 MyViewPagerAdapter (me.majiajie.pagerbottomtabstriptest.other.MyViewPagerAdapter)6 CircleIndicator (me.relex.circleindicator.CircleIndicator)6 LayoutInflater (android.view.LayoutInflater)5 Button (android.widget.Button)5 SamplePagerAdapter (me.relex.circleindicator.sample.SamplePagerAdapter)5 LinearInterpolator (android.view.animation.LinearInterpolator)4 NonNull (androidx.annotation.NonNull)4 FragmentStatePagerAdapter (androidx.fragment.app.FragmentStatePagerAdapter)4