diff --git a/AndroidManifest.xml b/AndroidManifest.xml index f3da1150..e3da86e3 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -2,8 +2,8 @@ + android:versionCode="79" + android:versionName="3.0.17"> diff --git a/src/com/duckduckgo/mobile/android/activity/DuckDuckGo.java b/src/com/duckduckgo/mobile/android/activity/DuckDuckGo.java index a68c76f8..88123be7 100644 --- a/src/com/duckduckgo/mobile/android/activity/DuckDuckGo.java +++ b/src/com/duckduckgo/mobile/android/activity/DuckDuckGo.java @@ -244,7 +244,7 @@ public void onBackStackChanged() { DDGActionBarManager.getInstance().updateActionBar(fragmentManager, tag, backPressed); backPressed = false; } - Log.e(TAG, "Fragment Back Stack current tag: " + DDGControlVar.mDuckDuckGoContainer.currentFragmentTag); + Log.d(TAG, "Fragment Back Stack current tag: " + DDGControlVar.mDuckDuckGoContainer.currentFragmentTag); showAllFragments(); } } diff --git a/src/com/duckduckgo/mobile/android/activity/OnboardingActivity.java b/src/com/duckduckgo/mobile/android/activity/OnboardingActivity.java index 64ad672b..cbd556ab 100644 --- a/src/com/duckduckgo/mobile/android/activity/OnboardingActivity.java +++ b/src/com/duckduckgo/mobile/android/activity/OnboardingActivity.java @@ -5,13 +5,10 @@ import android.graphics.Point; import android.os.Build; import android.support.v4.app.ActivityCompat; -import android.support.v4.app.FragmentPagerAdapter; -import android.support.v4.content.ContextCompat; import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.transition.Fade; -import android.transition.TransitionManager; import android.view.Display; import android.view.View; import android.view.ViewTreeObserver; @@ -20,17 +17,11 @@ import android.widget.LinearLayout; import com.duckduckgo.mobile.android.R; -import com.duckduckgo.mobile.android.adapters.OnboardingAdapter; +import com.duckduckgo.mobile.android.adapters.OnboardingPageAdapter; import com.duckduckgo.mobile.android.dialogs.InstructionDialogFragment; -import com.duckduckgo.mobile.android.fragment.onboarding.EndOnboardingFragment; -import com.duckduckgo.mobile.android.fragment.onboarding.NoAdsFragment; -import com.duckduckgo.mobile.android.fragment.onboarding.NoTrackingFragment; -import com.duckduckgo.mobile.android.fragment.onboarding.PrivacyFragment; -import com.duckduckgo.mobile.android.fragment.onboarding.RightFragment; import com.duckduckgo.mobile.android.util.CompatUtils; import com.duckduckgo.mobile.android.util.OnboardingHelper; import com.duckduckgo.mobile.android.util.OnboardingTransformer; -import com.duckduckgo.mobile.android.util.PreferencesManager; import com.duckduckgo.mobile.android.views.pageindicator.OnboardingPageIndicator; import java.util.Arrays; @@ -44,7 +35,7 @@ public static Intent getStartIntent(Context context) { private FrameLayout activityContainer; private LinearLayout containerLayout; private ViewPager viewPager; - private FragmentPagerAdapter adapter; + private OnboardingPageAdapter adapter; private OnboardingPageIndicator pageIndicator; private Button addToHomeScreenButton; @@ -94,7 +85,7 @@ public void onClick(View v) { } }); - adapter = new OnboardingAdapter(getSupportFragmentManager()); + adapter = new OnboardingPageAdapter(this, getSupportFragmentManager()); viewPager = (ViewPager) findViewById(R.id.view_pager); viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @@ -115,16 +106,10 @@ public void onPageScrollStateChanged(int state) { }); viewPager.setAdapter(adapter); - int[] backgroundColors = new int[] { - ContextCompat.getColor(this, PrivacyFragment.BACKGROUND_COLOR), - ContextCompat.getColor(this, NoAdsFragment.BACKGROUND_COLOR), - ContextCompat.getColor(this, NoTrackingFragment.BACKGROUND_COLOR), - ContextCompat.getColor(this, RightFragment.BACKGROUND_COLOR), - ContextCompat.getColor(this, EndOnboardingFragment.BACKGROUND_COLOR)}; pageIndicator = (OnboardingPageIndicator) findViewById(R.id.page_indicator); pageIndicator.setViewPager(viewPager, adapter.getCount() - 1); - viewPager.setPageTransformer(false, new OnboardingTransformer(backgroundColors, pageIndicator, Arrays.asList(pageIndicator, addToHomeScreenButton))); + viewPager.setPageTransformer(false, new OnboardingTransformer(adapter, pageIndicator, Arrays.asList(pageIndicator, addToHomeScreenButton))); Display display = getWindowManager().getDefaultDisplay(); Point size = new Point(); diff --git a/src/com/duckduckgo/mobile/android/adapters/BannerOnboardingAdapter.java b/src/com/duckduckgo/mobile/android/adapters/BannerOnboardingAdapter.java deleted file mode 100644 index 18d44585..00000000 --- a/src/com/duckduckgo/mobile/android/adapters/BannerOnboardingAdapter.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.duckduckgo.mobile.android.adapters; - -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentPagerAdapter; - -import com.duckduckgo.mobile.android.fragment.onboarding.NoAdsFragment; -import com.duckduckgo.mobile.android.fragment.onboarding.NoTrackingFragment; -import com.duckduckgo.mobile.android.fragment.onboarding.PrivacyFragment; -import com.duckduckgo.mobile.android.fragment.onboarding.RightFragment; - -/** - * Created by fgei on 4/11/17. - */ - -public class BannerOnboardingAdapter extends FragmentPagerAdapter { - - private static final int NUM_PAGES = 4; - - public BannerOnboardingAdapter(FragmentManager fm) { - super(fm); - } - - @Override - public Fragment getItem(int position) { - switch(position) { - case 0: - return PrivacyFragment.newInstance(position, true); - case 1: - return NoAdsFragment.newInstance(position, true); - case 2: - return NoTrackingFragment.newInstance(position, true); - case 3: - return RightFragment.newInstance(position, true); - default: - throw new IllegalArgumentException("Wrong position for Onboarding adapter: "+position); - } - } - - @Override - public int getCount() { - return NUM_PAGES; - } -} diff --git a/src/com/duckduckgo/mobile/android/adapters/OnboardingAdapter.java b/src/com/duckduckgo/mobile/android/adapters/OnboardingAdapter.java deleted file mode 100644 index 02728c81..00000000 --- a/src/com/duckduckgo/mobile/android/adapters/OnboardingAdapter.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.duckduckgo.mobile.android.adapters; - -import android.os.Build; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentPagerAdapter; -import android.support.v4.graphics.ColorUtils; -import android.support.v4.view.ViewPager; -import android.util.Log; -import android.view.View; - -import com.duckduckgo.mobile.android.R; -import com.duckduckgo.mobile.android.fragment.onboarding.EndOnboardingFragment; -import com.duckduckgo.mobile.android.fragment.onboarding.NoAdsFragment; -import com.duckduckgo.mobile.android.fragment.onboarding.NoTrackingFragment; -import com.duckduckgo.mobile.android.fragment.onboarding.PrivacyFragment; -import com.duckduckgo.mobile.android.fragment.onboarding.RightFragment; - -/** - * Created by fgei on 4/4/17. - */ - -public class OnboardingAdapter extends FragmentPagerAdapter { - - private static final int NUM_PAGES = 5; - //private boolean useMiniLayout = false; - public OnboardingAdapter(FragmentManager fm) { - super(fm); - //NUM_PAGES = 5; - //Log.e("NUM_PAGES", "numPages: "+NUM_PAGES); - } - - private OnboardingAdapter(FragmentManager fm, boolean useMiniLayout) { - super(fm); - //this.useMiniLayout = useMiniLayout; - //NUM_PAGES = useMiniLayout ? 4 : 5; - //Log.e("NUM_PAGES", "numPages: "+NUM_PAGES); - } - - @Override - public Fragment getItem(int position) { - switch(position) { - case 0: - return PrivacyFragment.newInstance(position); - case 1: - return NoAdsFragment.newInstance(position); - case 2: - return NoTrackingFragment.newInstance(position); - case 3: - return RightFragment.newInstance(position); - case 4: - return EndOnboardingFragment.newInstance(position); - default: - throw new IllegalArgumentException("Wrong position for Onboarding adapter: "+position); - } - } - - @Override - public int getCount() { - return NUM_PAGES; - } -} diff --git a/src/com/duckduckgo/mobile/android/adapters/OnboardingBannerAdapter.java b/src/com/duckduckgo/mobile/android/adapters/OnboardingBannerAdapter.java new file mode 100644 index 00000000..5e64d11e --- /dev/null +++ b/src/com/duckduckgo/mobile/android/adapters/OnboardingBannerAdapter.java @@ -0,0 +1,71 @@ +package com.duckduckgo.mobile.android.adapters; + +import android.content.Context; +import android.support.v4.view.PagerAdapter; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import com.duckduckgo.mobile.android.R; +import com.duckduckgo.mobile.android.util.OnboardingPageConfiguration; + +/** + * Created by fgei on 4/11/17. + */ + +public class OnboardingBannerAdapter extends PagerAdapter { + + private final OnboardingPageConfiguration[] items; + + public OnboardingBannerAdapter() { + items = new OnboardingPageConfiguration[] { + OnboardingPageConfiguration.getPrivacy(), + OnboardingPageConfiguration.getNoAds(), + OnboardingPageConfiguration.getNoTracking(), + OnboardingPageConfiguration.getRight() + }; + } + + @Override + public Object instantiateItem(ViewGroup container, int position) { + OnboardingPageConfiguration onboardingPageConfiguration = getItem(position); + LayoutInflater inflater = LayoutInflater.from(container.getContext()); + ViewGroup root = (ViewGroup) inflater.inflate(R.layout.viewholder_onboarding, container, false); + populate(root, onboardingPageConfiguration); + container.addView(root); + return root; + } + + @Override + public void destroyItem(ViewGroup container, int position, Object object) { + container.removeView((View) object); + } + + @Override + public boolean isViewFromObject(View view, Object o) { + return view == o; + } + + @Override + public int getCount() { + return items.length; + } + + public OnboardingPageConfiguration getItem(int position) { + return items[position]; + } + + private void populate(View rootView, OnboardingPageConfiguration onboardingPageConfiguration) { + Context context = rootView.getContext(); + TextView titleTextView = (TextView) rootView.findViewById(R.id.title_text_view); + String title = context.getString(onboardingPageConfiguration.title).replaceAll("\\n", " "); + titleTextView.setText(title); + TextView subtitleTextView = (TextView) rootView.findViewById(R.id.subtitle_text_view); + String subtitle = context.getString(onboardingPageConfiguration.subtitle).replaceAll("\\n", " "); + subtitleTextView.setText(subtitle); + ImageView iconImageView = (ImageView) rootView.findViewById(R.id.icon_image_view); + iconImageView.setImageResource(onboardingPageConfiguration.icon); + } +} diff --git a/src/com/duckduckgo/mobile/android/adapters/OnboardingPageAdapter.java b/src/com/duckduckgo/mobile/android/adapters/OnboardingPageAdapter.java new file mode 100644 index 00000000..2f117283 --- /dev/null +++ b/src/com/duckduckgo/mobile/android/adapters/OnboardingPageAdapter.java @@ -0,0 +1,49 @@ +package com.duckduckgo.mobile.android.adapters; + +import android.content.Context; +import android.support.annotation.ColorInt; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentPagerAdapter; +import android.support.v4.content.ContextCompat; + +import com.duckduckgo.mobile.android.fragment.OnboardingPageFragment; +import com.duckduckgo.mobile.android.util.OnboardingPageConfiguration; + +/** + * Created by fgei on 4/4/17. + */ + +public class OnboardingPageAdapter extends FragmentPagerAdapter { + + private final OnboardingPageConfiguration[] items; + private Context context; + + public OnboardingPageAdapter(Context context, FragmentManager fm) { + super(fm); + this.context = context; + items = new OnboardingPageConfiguration[] { + OnboardingPageConfiguration.getPrivacy(), + OnboardingPageConfiguration.getNoAds(), + OnboardingPageConfiguration.getNoTracking(), + OnboardingPageConfiguration.getRight(), + OnboardingPageConfiguration.getFadeOnboarding() + }; + } + + @Override + public Fragment getItem(int position) { + OnboardingPageConfiguration onboardingPageConfiguration = items[position]; + return OnboardingPageFragment.newInstance(onboardingPageConfiguration, position); + } + + @Override + public int getCount() { + return items.length; + } + + @ColorInt + public int getBackgroundColor(int position) { + return ContextCompat.getColor(context, items[position].backgroundColor); + } +} diff --git a/src/com/duckduckgo/mobile/android/adapters/RecyclerMainFeedAdapter.java b/src/com/duckduckgo/mobile/android/adapters/RecyclerMainFeedAdapter.java index 4cb5afb2..2ca83f31 100644 --- a/src/com/duckduckgo/mobile/android/adapters/RecyclerMainFeedAdapter.java +++ b/src/com/duckduckgo/mobile/android/adapters/RecyclerMainFeedAdapter.java @@ -5,12 +5,9 @@ import android.graphics.Bitmap; import android.os.Handler; import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import android.support.v7.view.menu.MenuBuilder; import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.RecyclerView.ViewHolder; -import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.View; @@ -34,7 +31,6 @@ import com.duckduckgo.mobile.android.util.DDGControlVar; import com.duckduckgo.mobile.android.util.DDGUtils; import com.duckduckgo.mobile.android.util.OnboardingHelper; -import com.duckduckgo.mobile.android.util.OnboardingTransformer; import com.duckduckgo.mobile.android.util.PreferencesManager; import com.duckduckgo.mobile.android.views.DDGOverflowMenu; import com.duckduckgo.mobile.android.views.pageindicator.BannerOnboardingPageIndicator; @@ -45,7 +41,7 @@ import java.util.ArrayList; import java.util.List; -public class RecyclerMainFeedAdapter extends RecyclerView.Adapter { +public class RecyclerMainFeedAdapter extends RecyclerView.Adapter { private static final String TAG = "MainFeedAdapter"; private static final int ITEM_TYPE_FEED = 0; @@ -62,7 +58,15 @@ public class RecyclerMainFeedAdapter extends RecyclerView.Adapter { public List data; - public class FeedViewHolder extends RecyclerView.ViewHolder { + public abstract class BaseViewHolder extends RecyclerView.ViewHolder { + public BaseViewHolder(View itemView) { + super(itemView); + } + public abstract void attach(); + public abstract void detach(); + } + + public class FeedViewHolder extends BaseViewHolder { public final TextView textViewTitle; public final FrameLayout frameCategoryContainer; @@ -82,14 +86,23 @@ public FeedViewHolder(View v) { this.imageViewBackground = (AsyncImageView) v.findViewById(R.id.feedItemBackground); this.imageViewFeedIcon = (AsyncImageView) v.findViewById(R.id.feedItemSourceIcon); } + + @Override + public void attach() { + + } + + @Override + public void detach() { + + } } - public class HeaderViewHolder extends RecyclerView.ViewHolder { + public class HeaderViewHolder extends BaseViewHolder { private final int SLIDE_TIME = 10000; public final ViewPager viewPager; - public final FragmentPagerAdapter adapter; public final BannerOnboardingPageIndicator pageIndicator; public final Button instructionbutton; public final ImageButton dismissImageButton; @@ -103,9 +116,7 @@ public HeaderViewHolder(View itemView) { instructionbutton = (Button) itemView.findViewById(R.id.instruction_button); dismissImageButton = (ImageButton) itemView.findViewById(R.id.dismiss_image_button); viewPager = (ViewPager) itemView.findViewById(R.id.view_pager); - adapter = new BannerOnboardingAdapter(fragmentManager); - viewPager.setAdapter(adapter); - viewPager.setPageTransformer(false, new OnboardingTransformer()); + viewPager.setAdapter(new OnboardingBannerAdapter()); viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int i, float v, int i1) { @@ -137,9 +148,18 @@ public void run() { handler.postDelayed(this, SLIDE_TIME); } }; + } + + @Override + public void attach() { startSlidingViewPager(); } + @Override + public void detach() { + stopSlidingViewPager(); + } + private void startSlidingViewPager() { isRunning = true; handler.postDelayed(slideRunnable, SLIDE_TIME); @@ -164,13 +184,13 @@ public RecyclerMainFeedAdapter(Context context, FragmentManager fragmentManager) } @Override - public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { if(viewType == ITEM_TYPE_HEADER) return new HeaderViewHolder(inflater.inflate(R.layout.viewholder_feed_header, parent, false)); return new FeedViewHolder(inflater.inflate(R.layout.item_main_feed, parent, false)); } @Override - public void onBindViewHolder(final ViewHolder holder, int position) { + public void onBindViewHolder(final BaseViewHolder holder, int position) { if(position == 0 && isOnboardingBannerVisible) { //that's the header; final HeaderViewHolder headerHolder = (HeaderViewHolder) holder; @@ -314,7 +334,6 @@ public FeedObject getItem(int position) { int index = position; if(isOnboardingBannerVisible) index -= 1; return data.get(index); - //return data.get(position - 1);//header } @Override @@ -322,14 +341,24 @@ public int getItemCount() { int size = data.size(); if(isOnboardingBannerVisible) return size+ 1; return size; - //return data.size() + 1; //header } @Override public int getItemViewType(int position) { if(position == 0 && isOnboardingBannerVisible) return ITEM_TYPE_HEADER; return ITEM_TYPE_FEED; - //return super.getItemViewType(position); + } + + @Override + public void onViewAttachedToWindow(BaseViewHolder holder) { + super.onViewAttachedToWindow(holder); + holder.attach(); + } + + @Override + public void onViewDetachedFromWindow(BaseViewHolder holder) { + holder.detach(); + super.onViewDetachedFromWindow(holder); } private void dismissOnboardingBanner() { diff --git a/src/com/duckduckgo/mobile/android/fragment/FeedFragment.java b/src/com/duckduckgo/mobile/android/fragment/FeedFragment.java index e59b5e8d..a2263df2 100644 --- a/src/com/duckduckgo/mobile/android/fragment/FeedFragment.java +++ b/src/com/duckduckgo/mobile/android/fragment/FeedFragment.java @@ -66,12 +66,10 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre private Activity activity = null; private RecyclerView recyclerView = null; - //private MainFeedListView feedView = null; private SwipeRefreshLayout swipeRefreshLayout = null; private View fragmentView; private RecyclerMainFeedAdapter recyclerAdapter = null; - //private MainFeedAdapter feedAdapter = null; private MainFeedTask mainFeedTask = null; private RecyclerView.LayoutManager layoutManager; @@ -81,11 +79,6 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre public int source_m_itemHeight; public int source_m_yOffset; - // for keeping filter category at same position - public String category_m_objectId = null; - public int category_m_itemHeight; - public int category_m_yOffset; - private Menu feedMenu = null; private DDGOverflowMenu overflowMenu = null; @@ -117,7 +110,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setRetainInstance(true); - //setHasOptionsMenu(true); activity = getActivity(); init(); } @@ -133,6 +125,7 @@ public void onHiddenChanged(boolean hidden) { @Override public void onResume() { super.onResume(); + recyclerView.setAdapter(recyclerAdapter); // lock button etc. can cause MainFeedTask results to be useless for the Activity // which is restarted (onPostExecute becomes invalid for the new Activity instance) @@ -144,19 +137,13 @@ public void onResume() { @Override public void onPause() { super.onPause(); + recyclerView.setAdapter(null); swipeRefreshLayout.setRefreshing(false); if (mainFeedTask != null) { mainFeedTask.cancel(false); mainFeedTask = null; } } -/* - @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - inflater.inflate(R.menu.main, menu); - menu.findItem(R.id.action_stories).setEnabled(false); - super.onCreateOptionsMenu(menu, inflater); - }*/ @Override public boolean onOptionsItemSelected(MenuItem item) { @@ -171,11 +158,6 @@ public void onRefresh() { } public void init() { - - //SourceClickListener sourceClickListener = new SourceClickListener(); - //CategoryClickListener categoryClickListener = new CategoryClickListener(); - //feedAdapter = new MainFeedAdapter(activity, sourceClickListener, categoryClickListener); - //recyclerAdapter = new RecyclerMainFeedAdapter(activity, sourceClickListener, categoryClickListener); recyclerAdapter = new RecyclerMainFeedAdapter(activity, getFragmentManager()); mainFeedTask = null; @@ -188,81 +170,12 @@ public void init() { layoutManager = new LinearLayoutManager(activity); recyclerView.setLayoutManager(layoutManager); - recyclerView.setAdapter(recyclerAdapter); feedMenu = new MenuBuilder(activity); activity.getMenuInflater().inflate(R.menu.main, feedMenu); } -/* - class SourceClickListener implements View.OnClickListener { - public void onClick(View v) { - // source filtering - - if(DDGControlVar.targetSource != null){ - cancelSourceFilter(); - } - else { - - View itemParent = (View) v.getParent().getParent(); - int pos = feedView.getPositionForView(itemParent); - source_m_objectId = ((FeedObject) feedView.getItemAtPosition(pos)).getId(); - FeedObject feedObject = (FeedObject) feedView.getItemAtPosition(pos); - source_m_itemHeight = itemParent.getHeight(); - - Rect r = new Rect(); - Point offset = new Point(); - feedView.getChildVisibleRect(itemParent, r, offset); - source_m_yOffset = offset.y; - - String sourceType = ((AsyncImageView) v).getType(); - DDGControlVar.targetSource = sourceType; - - DDGControlVar.hasUpdatedFeed = false; - keepFeedUpdated(); - } - - } - }*/ -/* - class CategoryClickListener implements View.OnClickListener { - public void onClick(final View v) { - // category filtering - - if(DDGControlVar.targetCategory != null){ - cancelCategoryFilter(); - } - else { - - final View itemParent = (View) v.getParent(); - int pos = feedView.getPositionForView(itemParent); - category_m_objectId = ((FeedObject) feedView.getItemAtPosition(pos)).getId(); - FeedObject feedObject = (FeedObject) feedView.getItemAtPosition(pos); - category_m_itemHeight = itemParent.getHeight(); - - Rect r = new Rect(); - Point offset = new Point(); - feedView.getChildVisibleRect(itemParent, r, offset); - category_m_yOffset = offset.y; - - DDGControlVar.targetCategory = feedObject.getCategory(); - - for(int i=0; i CREATOR = new Creator() { + @Override + public OnboardingPageConfiguration createFromParcel(Parcel source) { + return new OnboardingPageConfiguration(source); + } + + @Override + public OnboardingPageConfiguration[] newArray(int size) { + return new OnboardingPageConfiguration[size]; + } + }; +} diff --git a/src/com/duckduckgo/mobile/android/util/OnboardingTransformer.java b/src/com/duckduckgo/mobile/android/util/OnboardingTransformer.java index 1b5a911a..94ee64cb 100644 --- a/src/com/duckduckgo/mobile/android/util/OnboardingTransformer.java +++ b/src/com/duckduckgo/mobile/android/util/OnboardingTransformer.java @@ -8,6 +8,7 @@ import android.view.View; import com.duckduckgo.mobile.android.R; +import com.duckduckgo.mobile.android.adapters.OnboardingPageAdapter; import com.duckduckgo.mobile.android.views.pageindicator.OnboardingPageIndicator; import java.util.List; @@ -18,22 +19,12 @@ public class OnboardingTransformer implements ViewPager.PageTransformer { - private boolean doFullTrasformation = true; - private int[] backgroundColors; + private OnboardingPageAdapter onboardingPageAdapter; private OnboardingPageIndicator pageIndicator; private List fadeViews; - public OnboardingTransformer() { - doFullTrasformation = false; - } - - private OnboardingTransformer(int[] backgroundColors, OnboardingPageIndicator pageIndicator) { - this.backgroundColors = backgroundColors; - this.pageIndicator = pageIndicator; - } - - public OnboardingTransformer(int[] backgroundColors, OnboardingPageIndicator pageIndicator, List fadeViews) { - this.backgroundColors = backgroundColors; + public OnboardingTransformer(OnboardingPageAdapter onboardingPageAdapter, OnboardingPageIndicator pageIndicator, List fadeViews) { + this.onboardingPageAdapter = onboardingPageAdapter; this.pageIndicator = pageIndicator; this.fadeViews = fadeViews; } @@ -45,17 +36,16 @@ public void transformPage(View page, float position) { int pageIndex = (Integer) page.getTag(); if(position >= -1.0 && position <= 1.0) { - if(!doFullTrasformation) return; if(position > 0) { - int leftColor = backgroundColors[pageIndex - 1]; - int rightColor = backgroundColors[pageIndex]; + int leftColor = onboardingPageAdapter.getBackgroundColor(pageIndex - 1); + int rightColor = onboardingPageAdapter.getBackgroundColor(pageIndex); int color = blendARGB(rightColor, leftColor, position); page.setBackgroundColor(color); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { image.setScaleX(1 - absolutePosition); image.setScaleY(1 - absolutePosition); - if(pageIndex == (backgroundColors.length - 1)) { + if(pageIndex == (onboardingPageAdapter.getCount() - 1)) { for(View v : fadeViews) { v.setAlpha(absolutePosition); } @@ -65,15 +55,15 @@ public void transformPage(View page, float position) { pageIndicator.setPositionSelected(pageIndex, absolutePosition); } else if(position < 0) { int nextIndex = pageIndex + 1; - int leftColor = backgroundColors[pageIndex]; - int rightColor = backgroundColors[nextIndex]; + int leftColor = onboardingPageAdapter.getBackgroundColor(pageIndex); + int rightColor = onboardingPageAdapter.getBackgroundColor(nextIndex); int color = blendARGB(rightColor, leftColor, 1 - absolutePosition); page.setBackgroundColor(color); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { image.setScaleX(1 - absolutePosition); image.setScaleY(1 - absolutePosition); - if(nextIndex == (backgroundColors.length - 1)) { + if(nextIndex == (onboardingPageAdapter.getCount() - 1)) { for(View v : fadeViews) { v.setAlpha(1 - absolutePosition); } @@ -82,12 +72,10 @@ public void transformPage(View page, float position) { pageIndicator.setPositionSelected(pageIndex, absolutePosition); pageIndicator.setPositionSelected(pageIndex + 1, 1 - absolutePosition); } else { - page.setBackgroundColor(backgroundColors[pageIndex]); + page.setBackgroundColor(onboardingPageAdapter.getBackgroundColor(pageIndex)); } } else { - if(doFullTrasformation) { - page.setBackgroundColor(backgroundColors[pageIndex]); - } + page.setBackgroundColor(onboardingPageAdapter.getBackgroundColor(pageIndex)); } } diff --git a/src/com/duckduckgo/mobile/android/views/webview/DDGWebViewClient.java b/src/com/duckduckgo/mobile/android/views/webview/DDGWebViewClient.java index 7660978b..c4335e36 100644 --- a/src/com/duckduckgo/mobile/android/views/webview/DDGWebViewClient.java +++ b/src/com/duckduckgo/mobile/android/views/webview/DDGWebViewClient.java @@ -12,7 +12,6 @@ import android.net.Uri; import android.net.http.SslError; import android.os.Build; -import android.util.Log; import android.view.View; import android.webkit.SslErrorHandler; import android.webkit.WebSettings; @@ -182,7 +181,6 @@ else if(path != null && !path.equals("/")){ public void onPageFinished (WebView view, String url) { super.onPageFinished(view, url); - Log.e("onpagefinished", "url: " + url); mLoaded = true; DDGControlVar.mCleanSearchBar = false;