private void prepareNextPage() { try { preparingWindow = forward ? slidingWindows.getNextWindow() : slidingWindows.getPreviousWindow(); //// System.out.println("preparingWindow" + preparingWindow); if (preparingWindow.isLoading()) { // Log.d("SLIDING", "register on load listener..."); handler.post( new Runnable() { public void run() { preparingWindow.registerOnLoadListener( new com.goal98.flipdroid.model.Window.OnLoadListener() { public void onWindowLoaded(com.goal98.flipdroid.model.Window window) { if (forward) next = preparingWindow.get(); else { previous = preparingWindow.get(); } prepareFail = false; } public void onWindowSkipped( com.goal98.flipdroid.model.Window pageViewWindow) { prepareNextPage(); } }); } }); return; } else if (preparingWindow.isSkip()) { // Log.d("SLIDING", "slide to next page..."); prepareNextPage(); return; } else { if (forward) next = preparingWindow.get(); else previous = preparingWindow.get(); handler.post( new Runnable() { public void run() { renderNextPageIfNotRendered(); if (forward) next.removeLoadingIfNecessary(); else previous.removeLoadingIfNecessary(); } }); prepareFail = false; } } catch (LastWindowException e) { prepareFail = true; e.printStackTrace(); next = pageViewFactory.createLastPage(); } }
private void slideToNextPage() { System.out.println("debug slide to next"); try { if (preparingWindow == null && !prepareFail) preparingWindow = forward ? slidingWindows.getNextWindow() : slidingWindows.getPreviousWindow(); else { if (previousDirection != forward) { if (previousDirection) { if (currentPageIndex == 0) { finishActivity(); return; } preparingWindow = slidingWindows.getPreviousWindow(); preparingWindow = slidingWindows.getPreviousWindow(); } else { preparingWindow = slidingWindows.getNextWindow(); preparingWindow = slidingWindows.getNextWindow(); } } if (next.isLastPage()) { handler.post( new Runnable() { public void run() { showAnimation(); } }); return; } boolean preparingWindowReady = preparingWindow.isLoaded(); if (!preparingWindowReady) { preparingWindow.registerOnLoadListener(PageActivity.this); handler.post( new Runnable() { public void run() { current.showLoading(); } }); return; } } final com.goal98.flipdroid.model.Window nextWindow = preparingWindow; preparingWindow = null; if (nextWindow.isLoading()) { // Log.d("SLIDING", "register on load listener..."); handler.post( new Runnable() { public void run() { nextWindow.registerOnLoadListener(PageActivity.this); current.showLoading(); } }); return; } else if (nextWindow.isSkip()) { // Log.d("SLIDING", "slide to next page..."); current.setLoadingNext(false); slideToNextPage(); return; } else { if (next.isLastPage()) { //// System.out.println("lastpage"); } else { if (forward) next = nextWindow.get(); else previous = nextWindow.get(); } handler.post( new Runnable() { public void run() { if (forward) next.removeLoadingIfNecessary(); else { if (previous == null) return; previous.removeLoadingIfNecessary(); } showAnimation(); } }); } } catch (Exception e) { e.printStackTrace(); next = pageViewFactory.createLastPage(); handler.post( new Runnable() { public void run() { showAnimation(); } }); } }
public void reload() { currentPageIndex = -1; PagingStrategy pagingStrategy = null; if (accountType.equals(Constants.TYPE_SINA_WEIBO) || accountType.equals(Constants.TYPE_MY_SINA_WEIBO)) { //// System.out.println("accountType" + accountType); if (isWeiboMode()) pagingStrategy = new WeiboPagingStrategy(this); else pagingStrategy = new FixedPagingStrategy(this, 2); pagingStrategy.setNoMoreArticleListener( new NoMoreArticleListener() { public void onNoMoreArticle() throws NoMoreStatusException { // Log.d("cache system", "no more articles, refreshing repo"); repo.refresh(repo.getRefreshingToken()); } }); repo = new ContentRepo(pagingStrategy, refreshingSemaphore); sinaToken = SinaAccountUtil.getToken(PageActivity.this); ArticleFilter filter; if (isWeiboMode()) filter = new NullArticleFilter(); else filter = new ContainsLinkFilter(new NullArticleFilter()); source = new SinaArticleSource( true, sinaToken.getToken(), sinaToken.getTokenSecret(), sourceId, filter); } else if (accountType.equals(Constants.TYPE_RSS) || accountType.equals(Constants.TYPE_BAIDUSEARCH)) { pagingStrategy = new FixedPagingStrategy(this, 2); pagingStrategy.setNoMoreArticleListener( new NoMoreArticleListener() { public void onNoMoreArticle() throws NoMoreStatusException { throw new NoMoreStatusException(); } }); repo = new ContentRepo(pagingStrategy, refreshingSemaphore); cachedArticleSource = new CachedArticleSource( new FeaturedArticleSource(this, contentUrl, sourceName, sourceImageURL), this, this, SourceCache.getInstance(this)); cachedArticleSource.loadSourceFromCache(); source = cachedArticleSource; } else if (accountType.equals(Constants.TYPE_GOOGLE_READER)) { String sid = preferences.getString(GoogleAccountActivity.GOOGLE_ACCOUNT_SID, ""); String auth = preferences.getString(GoogleAccountActivity.GOOGLE_ACCOUNT_AUTH, ""); pagingStrategy = new FixedPagingStrategy(this, 2); pagingStrategy.setNoMoreArticleListener( new NoMoreArticleListener() { public void onNoMoreArticle() throws NoMoreStatusException { throw new NoMoreStatusException(); } }); repo = new ContentRepo(pagingStrategy, refreshingSemaphore); source = new GoogleReaderArticleSource(sid, auth); } else if (accountType.equals(Constants.TYPE_TAOBAO)) { pagingStrategy = new FixedPagingStrategy(this, 2); pagingStrategy.setNoMoreArticleListener( new NoMoreArticleListener() { public void onNoMoreArticle() throws NoMoreStatusException { throw new NoMoreStatusException(); } }); repo = new ContentRepo(pagingStrategy, refreshingSemaphore); source = new TaobaoArticleSource(sourceName, this.getApplicationContext()); } repo.setArticleSource(source); headerText.setText(sourceName); if (sourceImageURL != null && sourceImageURL.length() != 0) { headerImageView.setImageUrl(sourceImageURL); headerImageView.loadImage(); } else { int maxTitle = 7; if (sourceName != null && sourceName.length() >= maxTitle) headerImageView.setVisibility(View.GONE); else headerImageView.setVisibility(View.INVISIBLE); } slidingWindows = new PageViewSlidingWindows(10, repo, pageViewFactory, 3); current = pageViewFactory.createFirstPage(); shadow = new LinearLayout(PageActivity.this); shadow.setBackgroundColor(Color.parseColor("#10999999")); shadow2 = new LinearLayout(PageActivity.this); shadow2.setBackgroundColor(Color.parseColor("#FFDDDDDD")); shadowParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT); pageViewLayoutParamsFront = new FrameLayout.LayoutParams( FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.FILL_PARENT); pageViewLayoutParamsBack = pageViewLayoutParamsFront; flipPage(true); }