Search in sources :

Example 1 with OnPageChangeListener

use of android.support.v4.view.ViewPager.OnPageChangeListener in project Dxditor by kimi2009.

the class XJManageActivity method onPrepare.

@Override
public void onPrepare() {
    fList = new ArrayList<Class>();
    fList.add(XJGjglFragment.class);
    // fList.add(XjjcLiveActivity.class);
    fList.add(XjWdpmFragment.class);
    fList.add(XJWdqsFragment.class);
    fList.add(XJGjfxFragment.class);
    // ViewPager的adapter
    FragmentPagerAdapter adapter = new TabPageIndicatorAdapter(XJManageActivity.this, getSupportFragmentManager());
    pager.setAdapter(adapter);
    // 实例化TabPageIndicator然后设置ViewPager与之关联
    TabPageIndicator indicator = (TabPageIndicator) findViewById(R.id.indicator);
    indicator.setViewPager(pager);
    // 如果我们要对ViewPager设置监听,用indicator设置就行了
    indicator.setOnPageChangeListener(new OnPageChangeListener() {

        @Override
        public void onPageSelected(int arg0) {
        // Toast.makeText(getApplicationContext(), TITLE[arg0], Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
        }
    });
}
Also used : TabPageIndicator(com.viewpagerindicator.TabPageIndicator) FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) OnPageChangeListener(android.support.v4.view.ViewPager.OnPageChangeListener)

Example 2 with OnPageChangeListener

use of android.support.v4.view.ViewPager.OnPageChangeListener in project Dxditor by kimi2009.

the class ZTManagerActivity method onPrepare.

@Override
public void onPrepare() {
    fList = new ArrayList<Class>();
    fList.add(ZTGjglFragment.class);
    fList.add(ZTZtjcFragment.class);
    fList.add(ZTGdpmFragment.class);
    fList.add(ZTGdqsFragment.class);
    fList.add(ZTGjfxFragment.class);
    // ViewPager的adapter
    FragmentPagerAdapter adapter = new ZTManagerActivity.TabPageIndicatorAdapter(ZTManagerActivity.this, getSupportFragmentManager());
    pager.setAdapter(adapter);
    // 实例化TabPageIndicator然后设置ViewPager与之关联
    TabPageIndicator indicator = (TabPageIndicator) findViewById(R.id.indicator);
    indicator.setViewPager(pager);
    // 如果我们要对ViewPager设置监听,用indicator设置就行了
    indicator.setOnPageChangeListener(new OnPageChangeListener() {

        @Override
        public void onPageSelected(int arg0) {
            Toast.makeText(getApplicationContext(), TITLE[arg0], Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
        }
    });
}
Also used : TabPageIndicator(com.viewpagerindicator.TabPageIndicator) FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) OnPageChangeListener(android.support.v4.view.ViewPager.OnPageChangeListener)

Example 3 with OnPageChangeListener

use of android.support.v4.view.ViewPager.OnPageChangeListener in project quran_android by quran.

the class PagerActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    QuranApplication quranApp = (QuranApplication) getApplication();
    quranApp.refreshLocale(this, false);
    super.onCreate(savedInstanceState);
    // field injection
    getPagerActivityComponent().inject(this);
    bookmarksCache = new SparseBooleanArray();
    boolean shouldAdjustPageNumber = false;
    isDualPages = QuranUtils.isDualPages(this, quranScreenInfo);
    // remove the window background to avoid overdraw. note that, per Romain's blog, this is
    // acceptable (as long as we don't set the background color to null in the theme, since
    // that is used to generate preview windows).
    getWindow().setBackgroundDrawable(null);
    numberOfPages = quranInfo.getNumberOfPages();
    numberOfPagesDual = quranInfo.getNumberOfPagesDual();
    int page = -1;
    isActionBarHidden = true;
    if (savedInstanceState != null) {
        Timber.d("non-null saved instance state!");
        DownloadAudioRequest lastAudioRequest = savedInstanceState.getParcelable(LAST_AUDIO_DL_REQUEST);
        if (lastAudioRequest != null) {
            Timber.d("restoring request from saved instance!");
            lastAudioDownloadRequest = lastAudioRequest;
        }
        page = savedInstanceState.getInt(LAST_READ_PAGE, -1);
        if (page != -1) {
            page = numberOfPages - page;
        }
        showingTranslation = savedInstanceState.getBoolean(LAST_READING_MODE_IS_TRANSLATION, false);
        if (savedInstanceState.containsKey(LAST_ACTIONBAR_STATE)) {
            isActionBarHidden = !savedInstanceState.getBoolean(LAST_ACTIONBAR_STATE);
        }
        boolean lastWasDualPages = savedInstanceState.getBoolean(LAST_WAS_DUAL_PAGES, isDualPages);
        shouldAdjustPageNumber = (lastWasDualPages != isDualPages);
        start = savedInstanceState.getParcelable(LAST_START_POINT);
        end = savedInstanceState.getParcelable(LAST_ENDING_POINT);
        this.lastAudioRequest = savedInstanceState.getParcelable(LAST_AUDIO_REQUEST);
    } else {
        Intent intent = getIntent();
        Bundle extras = intent.getExtras();
        if (extras != null) {
            page = numberOfPages - extras.getInt("page", Constants.PAGES_FIRST);
            showingTranslation = extras.getBoolean(EXTRA_JUMP_TO_TRANSLATION, showingTranslation);
            highlightedSura = extras.getInt(EXTRA_HIGHLIGHT_SURA, -1);
            highlightedAyah = extras.getInt(EXTRA_HIGHLIGHT_AYAH, -1);
        }
    }
    compositeDisposable = new CompositeDisposable();
    // subscribe to changes in bookmarks
    compositeDisposable.add(bookmarkModel.bookmarksObservable().observeOn(AndroidSchedulers.mainThread()).subscribe(ignore -> {
        onBookmarksChanged();
    }));
    final Resources resources = getResources();
    isImmersiveInPortrait = resources.getBoolean(R.bool.immersive_in_portrait);
    isLandscape = resources.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
    ayahToolBarTotalHeight = resources.getDimensionPixelSize(R.dimen.toolbar_total_height);
    setContentView(R.layout.quran_page_activity_slider);
    audioStatusBar = (AudioStatusBar) findViewById(R.id.audio_area);
    audioStatusBar.setIsDualPageMode(quranScreenInfo.isDualPageMode());
    audioStatusBar.setQariList(audioUtils.getQariList(this));
    audioStatusBar.setAudioBarListener(this);
    audioBarParams = (ViewGroup.MarginLayoutParams) audioStatusBar.getLayoutParams();
    toolBarArea = findViewById(R.id.toolbar_area);
    translationsSpinner = (QuranSpinner) findViewById(R.id.spinner);
    // this is the colored view behind the status bar on kitkat and above
    final View statusBarBackground = findViewById(R.id.status_bg);
    statusBarBackground.getLayoutParams().height = getStatusBarHeight();
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if (quranSettings.isArabicNames() || QuranUtils.isRtl()) {
        // remove when we remove LTR from quran_page_activity's root
        ViewCompat.setLayoutDirection(toolbar, ViewCompat.LAYOUT_DIRECTION_RTL);
    }
    setSupportActionBar(toolbar);
    final ActionBar ab = getSupportActionBar();
    if (ab != null) {
        ab.setDisplayShowHomeEnabled(true);
        ab.setDisplayHomeAsUpEnabled(true);
    }
    initAyahActionPanel();
    if (showingTranslation && translationItems != null) {
        updateActionBarSpinner();
    } else {
        updateActionBarTitle(numberOfPages - page);
    }
    lastPopupTime = System.currentTimeMillis();
    pagerAdapter = new QuranPageAdapter(getSupportFragmentManager(), isDualPages, showingTranslation, quranInfo);
    ayahToolBar = (AyahToolBar) findViewById(R.id.ayah_toolbar);
    final NonRestoringViewPager nonRestoringViewPager = findViewById(R.id.quran_pager);
    nonRestoringViewPager.setIsDualPagesInLandscape(QuranUtils.isDualPagesInLandscape(this, quranScreenInfo));
    viewPager = nonRestoringViewPager;
    viewPager.setAdapter(pagerAdapter);
    ayahToolBar.setOnItemSelectedListener(new AyahMenuItemSelectionHandler());
    viewPager.addOnPageChangeListener(new OnPageChangeListener() {

        @Override
        public void onPageScrollStateChanged(int state) {
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            if (ayahToolBar.isShowing() && ayahToolBarPos != null) {
                final int startPage = quranInfo.getPageFromSuraAyah(start.sura, start.ayah);
                int barPos = quranInfo.getPosFromPage(startPage, isDualPages);
                if (position == barPos) {
                    // Swiping to next ViewPager page (i.e. prev quran page)
                    ayahToolBarPos.xScroll = 0 - positionOffsetPixels;
                } else if (position == barPos - 1) {
                    // Swiping to prev ViewPager page (i.e. next quran page)
                    ayahToolBarPos.xScroll = viewPager.getWidth() - positionOffsetPixels;
                } else {
                    // Totally off screen, should hide toolbar
                    ayahToolBar.setVisibility(View.GONE);
                    return;
                }
                ayahToolBar.updatePosition(ayahToolBarPos);
                // If the toolbar is not showing, show it
                if (ayahToolBar.getVisibility() != View.VISIBLE) {
                    ayahToolBar.setVisibility(View.VISIBLE);
                }
            }
        }

        @Override
        public void onPageSelected(int position) {
            Timber.d("onPageSelected(): %d", position);
            final int page = quranInfo.getPageFromPos(position, isDualPages);
            if (quranSettings.shouldDisplayMarkerPopup()) {
                lastPopupTime = QuranDisplayHelper.displayMarkerPopup(PagerActivity.this, quranInfo, page, lastPopupTime);
                if (isDualPages) {
                    lastPopupTime = QuranDisplayHelper.displayMarkerPopup(PagerActivity.this, quranInfo, page - 1, lastPopupTime);
                }
            }
            if (!showingTranslation) {
                updateActionBarTitle(page);
            } else {
                refreshActionBarSpinner();
            }
            if (bookmarksCache.indexOfKey(page) < 0) {
                if (isDualPages) {
                    if (bookmarksCache.indexOfKey(page - 1) < 0) {
                        checkIfPageIsBookmarked(page - 1, page);
                    }
                } else {
                    // we don't have the key
                    checkIfPageIsBookmarked(page);
                }
            }
            // If we're more than 1 page away from ayah selection end ayah mode
            if (isInAyahMode) {
                final int startPage = quranInfo.getPageFromSuraAyah(start.sura, start.ayah);
                int ayahPos = quranInfo.getPosFromPage(startPage, isDualPages);
                if (Math.abs(ayahPos - position) > 1) {
                    endAyahMode();
                }
            }
        }
    });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        setUiVisibilityListener();
        audioStatusBar.setVisibility(View.VISIBLE);
    }
    toggleActionBarVisibility(true);
    if (shouldAdjustPageNumber) {
        // when going from two page per screen to one or vice versa, we adjust the page number,
        // such that the first page is always selected.
        int curPage = numberOfPages - page;
        if (isDualPages) {
            if (curPage % 2 != 0) {
                curPage++;
            }
            curPage = numberOfPagesDual - (curPage / 2);
        } else {
            if (curPage % 2 == 0) {
                curPage--;
            }
            curPage = numberOfPages - curPage;
        }
        page = curPage;
    } else if (isDualPages) {
        page = page / 2;
    }
    viewPager.setCurrentItem(page);
    // just got created, need to reconnect to service
    shouldReconnect = true;
    // enforce orientation lock
    if (quranSettings.isLockOrientation()) {
        int current = getResources().getConfiguration().orientation;
        if (quranSettings.isLandscapeOrientation()) {
            if (current == Configuration.ORIENTATION_PORTRAIT) {
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                return;
            }
        } else if (current == Configuration.ORIENTATION_LANDSCAPE) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            return;
        }
    }
    LocalBroadcastManager.getInstance(this).registerReceiver(audioReceiver, new IntentFilter(AudioService.AudioUpdateIntent.INTENT_NAME));
    downloadReceiver = new DefaultDownloadReceiver(this, QuranDownloadService.DOWNLOAD_TYPE_AUDIO);
    String action = QuranDownloadNotifier.ProgressIntent.INTENT_NAME;
    LocalBroadcastManager.getInstance(this).registerReceiver(downloadReceiver, new IntentFilter(action));
    downloadReceiver.setListener(this);
}
Also used : Bundle(android.os.Bundle) AUDIO_PAGE(com.quran.labs.androidquran.ui.helpers.SlidingPagerAdapter.AUDIO_PAGE) AyahInfoDatabaseProvider(com.quran.labs.androidquran.data.AyahInfoDatabaseProvider) QuranSpinner(com.quran.labs.androidquran.widgets.QuranSpinner) AyahToolBar(com.quran.labs.androidquran.widgets.AyahToolBar) QuranPageAdapter(com.quran.labs.androidquran.ui.helpers.QuranPageAdapter) OnPageChangeListener(android.support.v4.view.ViewPager.OnPageChangeListener) Handler(android.os.Handler) TranslationsDBAdapter(com.quran.labs.androidquran.database.TranslationsDBAdapter) TargetApi(android.annotation.TargetApi) AudioStatusBar(com.quran.labs.androidquran.widgets.AudioStatusBar) TabletFragment(com.quran.labs.androidquran.ui.fragment.TabletFragment) IntentFilter(android.content.IntentFilter) Fragment(android.support.v4.app.Fragment) Set(java.util.Set) PagerActivityComponent(com.quran.labs.androidquran.component.activity.PagerActivityComponent) QuranScreenInfo(com.quran.labs.androidquran.util.QuranScreenInfo) HelpActivity(com.quran.labs.androidquran.HelpActivity) HapticFeedbackConstants(android.view.HapticFeedbackConstants) NonRestoringViewPager(android.support.v4.view.NonRestoringViewPager) Message(android.os.Message) DisposableObserver(io.reactivex.observers.DisposableObserver) TranslationsSpinnerAdapter(com.quran.labs.androidquran.ui.util.TranslationsSpinnerAdapter) QariItem(com.quran.labs.androidquran.common.QariItem) DisposableSingleObserver(io.reactivex.observers.DisposableSingleObserver) TAG_PAGE(com.quran.labs.androidquran.ui.helpers.SlidingPagerAdapter.TAG_PAGE) QuranDownloadService(com.quran.labs.androidquran.service.QuranDownloadService) NonNull(android.support.annotation.NonNull) AudioUtils(com.quran.labs.androidquran.util.AudioUtils) StreamingAudioRequest(com.quran.labs.androidquran.service.util.StreamingAudioRequest) BookmarkModel(com.quran.labs.androidquran.model.bookmark.BookmarkModel) QuranDataProvider(com.quran.labs.androidquran.data.QuranDataProvider) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) QuranFileUtils(com.quran.labs.androidquran.util.QuranFileUtils) Observable(io.reactivex.Observable) SearchActivity(com.quran.labs.androidquran.SearchActivity) ComponentName(android.content.ComponentName) QuranDownloadNotifier(com.quran.labs.androidquran.service.util.QuranDownloadNotifier) TRANSLATION_PAGE(com.quran.labs.androidquran.ui.helpers.SlidingPagerAdapter.TRANSLATION_PAGE) ProgressDialog(android.app.ProgressDialog) TextUtils(android.text.TextUtils) QuranApplication(com.quran.labs.androidquran.QuranApplication) File(java.io.File) FragmentManager(android.support.v4.app.FragmentManager) AlertDialog(android.support.v7.app.AlertDialog) SparseBooleanArray(android.util.SparseBooleanArray) SharedPreferences(android.content.SharedPreferences) Toolbar(android.support.v7.widget.Toolbar) Configuration(android.content.res.Configuration) QuranPreferenceActivity(com.quran.labs.androidquran.QuranPreferenceActivity) DownloadAudioRequest(com.quran.labs.androidquran.service.util.DownloadAudioRequest) SearchView(android.support.v7.widget.SearchView) Constants(com.quran.labs.androidquran.data.Constants) WindowManager(android.view.WindowManager) ShareUtil(com.quran.labs.androidquran.util.ShareUtil) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) AddTagDialog(com.quran.labs.androidquran.ui.fragment.AddTagDialog) HighlightType(com.quran.labs.androidquran.ui.helpers.HighlightType) AyahSelectedListener(com.quran.labs.androidquran.ui.helpers.AyahSelectedListener) ActivityInfo(android.content.pm.ActivityInfo) R(com.quran.labs.androidquran.R) View(android.view.View) Schedulers(io.reactivex.schedulers.Schedulers) ViewCompat(android.support.v4.view.ViewCompat) QuranAppUtils(com.quran.labs.androidquran.util.QuranAppUtils) PreferenceManager(android.preference.PreferenceManager) AyahToolBarPosition(com.quran.labs.androidquran.widgets.AyahToolBar.AyahToolBarPosition) SlidingUpPanelLayout(com.quran.labs.androidquran.widgets.SlidingUpPanelLayout) AudioRequest(com.quran.labs.androidquran.service.util.AudioRequest) AyahActionFragment(com.quran.labs.androidquran.ui.fragment.AyahActionFragment) AudioService(com.quran.labs.androidquran.service.AudioService) MenuItemCompat(android.support.v4.view.MenuItemCompat) LocalTranslation(com.quran.labs.androidquran.common.LocalTranslation) QuranDisplayHelper(com.quran.labs.androidquran.ui.helpers.QuranDisplayHelper) BroadcastReceiver(android.content.BroadcastReceiver) ViewGroup(android.view.ViewGroup) Timber(timber.log.Timber) PAGES(com.quran.labs.androidquran.ui.helpers.SlidingPagerAdapter.PAGES) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) QuranInfo(com.quran.labs.androidquran.data.QuranInfo) DefaultDownloadReceiver(com.quran.labs.androidquran.service.util.DefaultDownloadReceiver) TranslationFragment(com.quran.labs.androidquran.ui.fragment.TranslationFragment) Nullable(android.support.annotation.Nullable) SearchManager(android.app.SearchManager) RecentPagePresenter(com.quran.labs.androidquran.presenter.bookmark.RecentPagePresenter) Context(android.content.Context) ArabicDatabaseUtils(com.quran.labs.androidquran.model.translation.ArabicDatabaseUtils) KeyEvent(android.view.KeyEvent) JumpFragment(com.quran.labs.androidquran.ui.fragment.JumpFragment) ViewPager(android.support.v4.view.ViewPager) ServiceIntentHelper(com.quran.labs.androidquran.service.util.ServiceIntentHelper) Intent(android.content.Intent) QuranUtils(com.quran.labs.androidquran.util.QuranUtils) Single(io.reactivex.Single) MenuItem(android.view.MenuItem) IconPageIndicator(com.quran.labs.androidquran.widgets.IconPageIndicator) HashSet(java.util.HashSet) Inject(javax.inject.Inject) TagBookmarkDialog(com.quran.labs.androidquran.ui.fragment.TagBookmarkDialog) SuraAyah(com.quran.labs.androidquran.data.SuraAyah) QuranSettings(com.quran.labs.androidquran.util.QuranSettings) Build(android.os.Build) WeakReference(java.lang.ref.WeakReference) ActionBar(android.support.v7.app.ActionBar) SlidingPagerAdapter(com.quran.labs.androidquran.ui.helpers.SlidingPagerAdapter) QuranPageWorker(com.quran.labs.androidquran.ui.helpers.QuranPageWorker) QuranPage(com.quran.labs.androidquran.ui.helpers.QuranPage) AyahTracker(com.quran.labs.androidquran.ui.helpers.AyahTracker) JumpDestination(com.quran.labs.androidquran.ui.helpers.JumpDestination) Pair(android.support.v4.util.Pair) PagerActivityModule(com.quran.labs.androidquran.module.activity.PagerActivityModule) Resources(android.content.res.Resources) IntentFilter(android.content.IntentFilter) Bundle(android.os.Bundle) ViewGroup(android.view.ViewGroup) OnPageChangeListener(android.support.v4.view.ViewPager.OnPageChangeListener) Intent(android.content.Intent) SearchView(android.support.v7.widget.SearchView) View(android.view.View) QuranApplication(com.quran.labs.androidquran.QuranApplication) NonRestoringViewPager(android.support.v4.view.NonRestoringViewPager) DefaultDownloadReceiver(com.quran.labs.androidquran.service.util.DefaultDownloadReceiver) SparseBooleanArray(android.util.SparseBooleanArray) QuranPageAdapter(com.quran.labs.androidquran.ui.helpers.QuranPageAdapter) DownloadAudioRequest(com.quran.labs.androidquran.service.util.DownloadAudioRequest) Resources(android.content.res.Resources) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar)

Example 4 with OnPageChangeListener

use of android.support.v4.view.ViewPager.OnPageChangeListener in project LibreraReader by foobnix.

the class MainTabs2 method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (AppState.get().isWhiteTheme) {
        setTheme(R.style.StyledIndicatorsWhite);
    } else {
        setTheme(R.style.StyledIndicatorsBlack);
    }
    super.onCreate(savedInstanceState);
    if (PasswordDialog.isNeedPasswordDialog(this)) {
        return;
    }
    LOG.d(TAG, "onCreate");
    LOG.d("EXTRA_EXIT", EXTRA_EXIT);
    if (getIntent().getBooleanExtra(EXTRA_EXIT, false)) {
        finish();
        return;
    }
    isEink = Dips.isEInk(this);
    TintUtil.setStatusBarColor(this);
    DocumentController.doRotation(this);
    setContentView(R.layout.main_tabs);
    imageMenu = (ImageView) findViewById(R.id.imageMenu1);
    imageMenuParent = findViewById(R.id.imageParent1);
    imageMenuParent.setBackgroundColor(TintUtil.color);
    overlay = findViewById(R.id.overlay);
    toastBrightnessText = (TextView) findViewById(R.id.toastBrightnessText);
    toastBrightnessText.setVisibility(View.GONE);
    TintUtil.setDrawableTint(toastBrightnessText.getCompoundDrawables()[0], Color.WHITE);
    tabFragments = new ArrayList<UIFragment>();
    try {
        for (UITab tab : UITab.getOrdered(AppState.get().tabsOrder)) {
            if (tab.isVisible()) {
                tabFragments.add(tab.getClazz().newInstance());
            }
        }
    } catch (Exception e) {
        LOG.e(e);
        Toast.makeText(MainTabs2.this, R.string.msg_unexpected_error, Toast.LENGTH_LONG).show();
        tabFragments.add(new SearchFragment2());
        tabFragments.add(new BrowseFragment2());
        tabFragments.add(new RecentFragment2());
        tabFragments.add(new BookmarksFragment2());
        tabFragments.add(new OpdsFragment2());
        tabFragments.add(new PrefFragment2());
    }
    getSupportFragmentManager().beginTransaction().replace(R.id.left_drawer, new PrefFragment2()).commit();
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    imageMenu.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (drawerLayout.isDrawerOpen(Gravity.START))
                drawerLayout.closeDrawer(Gravity.START, !AppState.get().isInkMode);
            else
                drawerLayout.openDrawer(Gravity.START, !AppState.get().isInkMode);
        }
    });
    if (UITab.isShowPreferences()) {
        imageMenu.setVisibility(View.GONE);
        drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
    } else {
        imageMenu.setVisibility(View.VISIBLE);
    }
    // ((BrigtnessDraw)
    // findViewById(R.id.brigtnessProgressView)).setActivity(this);
    adapter = new TabsAdapter2(this, tabFragments);
    pager = (ViewPager) findViewById(R.id.pager);
    if (Android6.canWrite(this)) {
        pager.setAdapter(adapter);
    }
    pager.setOffscreenPageLimit(5);
    pager.addOnPageChangeListener(onPageChangeListener);
    drawerLayout.addDrawerListener(new DrawerListener() {

        @Override
        public void onDrawerStateChanged(int arg0) {
        }

        @Override
        public void onDrawerSlide(View arg0, float arg1) {
        }

        @Override
        public void onDrawerOpened(View arg0) {
        // TODO Auto-generated method stub
        }

        @Override
        public void onDrawerClosed(View arg0) {
            tabFragments.get(pager.getCurrentItem()).onSelectFragment();
        }
    });
    indicator = (SlidingTabLayout) findViewById(R.id.slidingTabs);
    indicator.setViewPager(pager);
    indicator.setDividerColors(getResources().getColor(R.color.tint_divider));
    indicator.setSelectedIndicatorColors(Color.WHITE);
    indicator.setBackgroundColor(TintUtil.color);
    if (AppState.get().isInkMode) {
        TintUtil.setTintImageNoAlpha(imageMenu, TintUtil.color);
        indicator.setSelectedIndicatorColors(TintUtil.color);
        indicator.setDividerColors(TintUtil.color);
        indicator.setBackgroundColor(Color.TRANSPARENT);
        imageMenuParent.setBackgroundColor(Color.TRANSPARENT);
    }
    Android6.checkPermissions(this);
    // Analytics.onStart(this);
    List<String> actions = Arrays.asList("android.intent.action.PROCESS_TEXT", "android.intent.action.SEARCH", "android.intent.action.SEND");
    List<String> extras = Arrays.asList(Intent.EXTRA_PROCESS_TEXT_READONLY, Intent.EXTRA_PROCESS_TEXT, SearchManager.QUERY, Intent.EXTRA_TEXT);
    if (getIntent() != null && getIntent().getAction() != null) {
        if (actions.contains(getIntent().getAction())) {
            for (String extra : extras) {
                final String text = getIntent().getStringExtra(extra);
                if (TxtUtils.isNotEmpty(text)) {
                    AppState.get().lastClosedActivity = null;
                    pager.postDelayed(new Runnable() {

                        @Override
                        public void run() {
                            ((SearchFragment2) tabFragments.get(0)).searchAndOrderExteral(text);
                        }
                    }, 250);
                    break;
                }
            }
        }
    }
    boolean showTabs = getIntent().getBooleanExtra(EXTRA_SHOW_TABS, false);
    LOG.d("EXTRA_SHOW_TABS", showTabs, AppState.get().lastMode);
    if (showTabs == false && AppState.get().isOpenLastBook) {
        LOG.d("Open lastBookPath", AppState.get().lastBookPath);
        if (AppState.get().lastBookPath == null || !new File(AppState.get().lastBookPath).isFile()) {
            LOG.d("Open Last book not found");
            return;
        }
        AppState.get().lastClosedActivity = null;
        Safe.run(new Runnable() {

            @Override
            public void run() {
                boolean isEasyMode = HorizontalViewActivity.class.getSimpleName().equals(AppState.get().lastMode);
                Intent intent = new Intent(MainTabs2.this, isEasyMode ? HorizontalViewActivity.class : VerticalViewActivity.class);
                intent.putExtra(PasswordDialog.EXTRA_APP_PASSWORD, getIntent().getStringExtra(PasswordDialog.EXTRA_APP_PASSWORD));
                intent.setData(Uri.fromFile(new File(AppState.get().lastBookPath)));
                startActivity(intent);
            }
        });
    } else if (!AppState.get().isOpenLastBook) {
        LOG.d("Open book lastA", AppState.get().lastClosedActivity);
        if (AppState.get().lastBookPath == null || !new File(AppState.get().lastBookPath).isFile()) {
            LOG.d("Open Last book not found");
            return;
        }
        final String saveMode = AppState.get().lastClosedActivity;
        Safe.run(new Runnable() {

            @Override
            public void run() {
                if (HorizontalViewActivity.class.getSimpleName().equals(saveMode)) {
                    Intent intent = new Intent(MainTabs2.this, HorizontalViewActivity.class);
                    intent.setData(Uri.fromFile(new File(AppState.get().lastBookPath)));
                    startActivity(intent);
                    LOG.d("Start lastA", saveMode);
                } else if (VerticalViewActivity.class.getSimpleName().equals(saveMode)) {
                    Intent intent = new Intent(MainTabs2.this, VerticalViewActivity.class);
                    intent.setData(Uri.fromFile(new File(AppState.get().lastBookPath)));
                    startActivity(intent);
                    LOG.d("Start lastA", saveMode);
                }
            }
        });
    } else {
        RecentUpates.updateAll(this);
    }
    checkGoToPage(getIntent());
    try {
        AndroidWhatsNew.checkForNewBeta(this);
    } catch (Exception e) {
        LOG.e(e);
    }
    if (Android6.canWrite(this)) {
        FontExtractor.extractFonts(this);
    }
    EventBus.getDefault().register(this);
}
Also used : BrowseFragment2(com.foobnix.ui2.fragment.BrowseFragment2) TabsAdapter2(com.foobnix.ui2.adapter.TabsAdapter2) DrawerListener(android.support.v4.widget.DrawerLayout.DrawerListener) OpdsFragment2(com.foobnix.ui2.fragment.OpdsFragment2) HorizontalViewActivity(com.foobnix.pdf.search.activity.HorizontalViewActivity) VerticalViewActivity(org.ebookdroid.ui.viewer.VerticalViewActivity) RecentFragment2(com.foobnix.ui2.fragment.RecentFragment2) UIFragment(com.foobnix.ui2.fragment.UIFragment) PrefFragment2(com.foobnix.ui2.fragment.PrefFragment2) Intent(android.content.Intent) SearchFragment2(com.foobnix.ui2.fragment.SearchFragment2) BookmarksFragment2(com.foobnix.ui2.fragment.BookmarksFragment2) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) UITab(com.foobnix.pdf.info.wrapper.UITab) OnClickListener(android.view.View.OnClickListener) File(java.io.File)

Example 5 with OnPageChangeListener

use of android.support.v4.view.ViewPager.OnPageChangeListener in project Android-Developers-Samples by johnjohndoe.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Set content view (which contains a CheeseListFragment)
    setContentView(R.layout.sample_main);
    // Retrieve the ViewPager from the content view
    ViewPager vp = (ViewPager) findViewById(R.id.viewpager);
    // Set an OnPageChangeListener so we are notified when a new item is selected
    vp.setOnPageChangeListener(mOnPageChangeListener);
    // Finally set the adapter so the ViewPager can display items
    vp.setAdapter(mPagerAdapter);
}
Also used : ViewPager(android.support.v4.view.ViewPager)

Aggregations

OnPageChangeListener (android.support.v4.view.ViewPager.OnPageChangeListener)9 ViewPager (android.support.v4.view.ViewPager)5 Intent (android.content.Intent)3 Fragment (android.support.v4.app.Fragment)3 FragmentPagerAdapter (android.support.v4.app.FragmentPagerAdapter)3 View (android.view.View)3 PagerAdapter (android.support.v4.view.PagerAdapter)2 LinearLayout (android.widget.LinearLayout)2 TabPageIndicator (com.viewpagerindicator.TabPageIndicator)2 File (java.io.File)2 SuppressLint (android.annotation.SuppressLint)1 TargetApi (android.annotation.TargetApi)1 ProgressDialog (android.app.ProgressDialog)1 SearchManager (android.app.SearchManager)1 BroadcastReceiver (android.content.BroadcastReceiver)1 ComponentName (android.content.ComponentName)1 Context (android.content.Context)1 IntentFilter (android.content.IntentFilter)1 SharedPreferences (android.content.SharedPreferences)1 ActivityInfo (android.content.pm.ActivityInfo)1