Example #1
0
  /**
   * @param context
   * @param attrs
   */
  public ImageCycleView(Context context, AttributeSet attrs) {
    super(context, attrs);
    mContext = context;
    mScale = context.getResources().getDisplayMetrics().density;
    LayoutInflater.from(context).inflate(R.layout.ad_cycle_view, this);
    mAdvPager = (ViewPager) findViewById(R.id.adv_pager);
    mAdvPager.setOnPageChangeListener(new GuidePageChangeListener());
    mAdvPager.setOnTouchListener(
        new OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
              case MotionEvent.ACTION_UP:
                // 开始图片滚动
                startImageTimerTask();
                break;
              default:
                // 停止图片滚动
                stopImageTimerTask();
                break;
            }
            return false;
          }
        });
    // 滚动图片右下指示器视图
    mGroup = (ViewGroup) findViewById(R.id.viewGroup);
  }
  private void init() {
    if (null == mAdapter) {
      // print(true, "init() " + coverList.size());
      mAdapter =
          new AlbumFragmentPagerAdapter(
              getActivity().getSupportFragmentManager(), coverList.size(), "", mPager);

      mAdapter.setOnGetItem(
          new OnGetItem() {

            @Override
            public ImageFragment onGetNewItem(int position) {
              // 生成新的 cover 图片实例
              return ImageFragment.newInstance(coverList.get(position).getId(), true);
            }
          });

      mPager.setAdapter(mAdapter);
      mPager.setPageMargin(mPagerMargin);
      mPager.setOffscreenPageLimit(3);
      // set container touch event assign to pager's touch event
      mContainer.setOnTouchListener(mOnTouchListener);

      // set container to refresh when pager's page changed
      mPager.setOnPageChangeListener(mOnPageChangeListener);
      mPager.setOnTouchListener(mOnTouchListener);
      // 设置选中的页面
      mPager.setCurrentItem(selectedPosition);
    } else {
      mAdapter.notifyDataSetChanged();
    }
  }
 /** Function stops sliding images. */
 private void stopSliding() {
   if (timer != null) {
     timer.cancel();
     timer.purge();
   }
   startSlideShow = false;
   startSlideShowButton.setText("Start slide show");
   imageViewPager.setOnTouchListener(null);
 }
Example #4
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.route_widget, container, false);
    ButterKnife.inject(this, rootView);
    fragment = this;
    adapter = new RouteAdapter(act, instructions, fragment);
    adapter.setDestinationName(simpleFeature.getProperty(TEXT));
    TextView destinationName = (TextView) rootView.findViewById(R.id.destination_name);
    destinationName.setText(getString(R.string.routing_to_text) + simpleFeature.getProperty(TEXT));
    if (route != null) {
      distanceToDestination.setDistance(route.getTotalDistance());
    }
    pager.setAdapter(adapter);
    pager.setOnPageChangeListener(this);
    adapter.notifyDataSetChanged();
    currentXCor = mapFragment.getMap().getMapPosition().getX();
    initSpeakerbox();
    initNotificationCreator();
    pager.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            turnAutoPageOff();
            return false;
          }
        });
    initDebugView(rootView);
    initSlideLayout(rootView);
    setMapOnTouchListener();

    res = act.getResources();
    prefs = getDefaultSharedPreferences(act);

    if (LocationServices.FusedLocationApi != null) {
      if (prefs.getBoolean(getString(R.string.settings_mock_gpx_key), false)) {
        final String key = getString(R.string.settings_mock_gpx_filename_key);
        final String defaultFile = getString(R.string.settings_mock_gpx_filename_default_value);
        final String filename = prefs.getString(key, defaultFile);
        final File file = new File(Environment.getExternalStorageDirectory(), filename);
        LocationServices.FusedLocationApi.setMockMode(true);
        LocationServices.FusedLocationApi.setMockTrace(file);
      } else {
        LocationServices.FusedLocationApi.setMockMode(false);
      }
    }

    hideLocateButtonAndAttribution();
    return rootView;
  }
  public void setupViewPager(ViewPager viewPager) {
    ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
    adapter.addFragment(new CornersViewFragmentInside(), "Inside Corners");
    adapter.addFragment(new CornersViewFragmentOutside(), "Outside Corners");

    viewPager.setAdapter(adapter);
    viewPager.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View view, MotionEvent motionEvent) {
            return false;
          }
        });
  }
  public void initLayout() {
    pager = new TabPager(getSupportFragmentManager());

    tabHost = (TabHost) findViewById(android.R.id.tabhost);
    tabHost.setup();

    tabHost.setOnTabChangedListener(pager);
    viewPager.setAdapter(pager);
    viewPager.setOnPageChangeListener(pager);
    viewPager.setOnTouchListener(
        new OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            return true;
          }
        });

    TabHost.TabSpec tabSpec = null;

    @SuppressWarnings("unused")
    View indicator = null;

    int i = 1;

    for (Fragment f : fragments) {
      tabSpec =
          tabHost
              .newTabSpec(f.getClass().getSimpleName())
              .setIndicator(indicator = new Indicator(String.valueOf(i), this).tab)
              .setContent(
                  new TabHost.TabContentFactory() {

                    @Override
                    public View createTabContent(String tag) {
                      View view = new View(WizardActivity.this);
                      view.setMinimumHeight(0);
                      view.setMinimumWidth(0);
                      return view;
                    }
                  });
      tabHost.addTab(tabSpec);
      i++;
    }

    if (getIntent().hasExtra(Codes.Extras.CHANGE_LOCALE)) {
      getIntent().removeExtra(Codes.Extras.CHANGE_LOCALE);
      viewPager.setCurrentItem(1);
    }
  }
  @SuppressWarnings("deprecation")
  public void setViewPageViews(List<View> views) {
    this.views = views;
    // 初始化底部的圆
    addDots(views.size());

    viewPager.setAdapter(new CustomerViewPageAdapter());
    viewPager.setOnPageChangeListener(
        new OnPageChangeListener() {

          @Override
          public void onPageSelected(int index) {
            position = index;
            for (int i = 0; i < dots.size(); i++) {
              if (position == i) {
                dots.get(i).setBackgroundResource(R.drawable.dot_focused);
              } else {
                dots.get(i).setBackgroundResource(R.drawable.dot_normal);
              }
            }
          }

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

          @Override
          public void onPageScrollStateChanged(int arg0) {}
        });
    viewPager.setOnTouchListener(
        new OnTouchListener() {

          public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
              case MotionEvent.ACTION_DOWN:
              case MotionEvent.ACTION_MOVE:
                isContinue = false;
                break;
              case MotionEvent.ACTION_UP:
                isContinue = true;
                break;
              default:
                isContinue = true;
                break;
            }
            return false;
          }
        });
    new Thread(this).start();
  }
 private void buildViewPager() {
   mViewPager = (ViewPager) findViewById(R.id.viewpager);
   TimeLinePagerAdapter adapter = new TimeLinePagerAdapter(getFragmentManager());
   mViewPager.setOverScrollMode(View.OVER_SCROLL_NEVER);
   mViewPager.setOffscreenPageLimit(3);
   mViewPager.setAdapter(adapter);
   mViewPager.setOnPageChangeListener(onPageChangeListener);
   gestureDetector = new GestureDetector(BrowserWeiboMsgActivity.this, new MyOnGestureListener());
   mViewPager.setOnTouchListener(
       new View.OnTouchListener() {
         @Override
         public boolean onTouch(View v, MotionEvent event) {
           return gestureDetector.onTouchEvent(event);
         }
       });
 }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.d("onCreateView " + this);
    View rod = inflater.inflate(R.layout.drama_og_bog_frag, container, false);
    karruselAdapter = new KarruselAdapter(getChildFragmentManager());
    viewPager = (ViewPager) rod.findViewById(R.id.pager);
    viewPager.setAdapter(karruselAdapter);
    viewPager.getLayoutParams().height =
        billedeHø; // Viewpageren skal fylde præcist ét billede i højden
    karruselIndikator = (CirclePageIndicator) rod.findViewById(R.id.indicator);
    karruselIndikator.setViewPager(viewPager);
    final float density = getResources().getDisplayMetrics().density;
    karruselIndikator.setRadius(5 * density);
    karruselIndikator.setPageColor(Color.BLACK);
    karruselIndikator.setFillColor(App.color.blå);
    karruselIndikator.setStrokeColor(0);
    karruselIndikator.setStrokeWidth(0);
    DRData.instans.dramaOgBog.observatører.add(this);
    run();
    viewPager.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN
                || event.getAction() == MotionEvent.ACTION_UP) {
              App.forgrundstråd.removeCallbacks(skiftTilNæsteIKarrusellen);
              App.forgrundstråd.postDelayed(skiftTilNæsteIKarrusellen, 10000);
            }
            return false;
          }
        });
    App.forgrundstråd.postDelayed(skiftTilNæsteIKarrusellen, 10000);

    AQuery aq = new AQuery(rod);
    listView = (PinnedSectionListView) aq.id(R.id.listView).adapter(listeAdapter).getListView();
    listView.setEmptyView(aq.id(R.id.tom).typeface(App.skrift_gibson).getView());
    listView.setOnItemClickListener(this);
    return rod;
  }
Example #10
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_result);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            return false;
          }
        });

    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(mViewPager);

    quoteJson = getIntent().getStringExtra(MainActivity.QUOTE_JSON);
    Gson gson = new Gson();
    JsonParser parser = new JsonParser();
    JsonObject quote = parser.parse(quoteJson).getAsJsonObject();

    symbol = gson.fromJson(quote.get("Symbol"), String.class);
    name = gson.fromJson(quote.get("Name"), String.class);
    setTitle(name);

    // Initialize Facebook SDK for sharing
    FacebookSdk.sdkInitialize(getApplicationContext());
    callbackManager = CallbackManager.Factory.create();
  }
Example #11
0
  private void initAdViewPager() {
    ArrayList<String> photos = banners.get(0).getPhotos();

    if (photos.size() == 0) {
      none_ad.setVisibility(VISIBLE);
      return;
    }

    none_ad.setVisibility(GONE);

    advPics.clear();
    for (int i = 0; i < photos.size(); i++) {
      ImageView img = new ImageView(mContext);
      img.setBackgroundColor(backcolor);
      advPics.add(img);

      try {
        imageFetcher.loadFormCache(photos.get(i), advPics.get(i));
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    //	      对imageviews进行填充
    imageViewsAd = new ImageView[advPics.size()];
    // 小图标
    for (int i = 0; i < advPics.size(); i++) {
      imageView = new ImageView(mContext);
      imageView.setLayoutParams(new LayoutParams(20, 20));
      imageView.setPadding(5, 5, 5, 5);
      imageViewsAd[i] = imageView;
      if (i == 0) {
        imageViewsAd[i].setBackgroundResource(Indicator_select);
      } else {
        imageViewsAd[i].setBackgroundResource(Indicator_unselect);
      }
      ad_indicators.addView(imageViewsAd[i]);
    }

    ad_pager.setAdapter(new AdvAdapter(advPics));
    ad_pager.setOnPageChangeListener(new GuidePageChangeListenerAd());
    ad_pager.setOnTouchListener(
        new OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
              case MotionEvent.ACTION_DOWN:
              case MotionEvent.ACTION_MOVE:
                isContinueAd = false;
                break;
              case MotionEvent.ACTION_UP:
                isContinueAd = true;
                break;
              default:
                isContinueAd = true;
                break;
            }
            return false;
          }
        });
    new Thread(
            new Runnable() {

              @Override
              public void run() {
                while (true) {
                  if (isContinueAd) {
                    viewHandlerAd.sendEmptyMessage(whatAd.get());
                    whatOptionAd();
                  }
                }
              }
            })
        .start();
  }
Example #12
0
  private void initMallViewPager() {
    ArrayList<String> photos = banners.get(1).getPhotos();

    if (photos.size() == 0) {
      none_mall.setVisibility(VISIBLE);
      return;
    }

    none_mall.setVisibility(GONE);

    mallPics.clear();
    for (int i = 0; i < photos.size(); i++) {
      ImageView img = new ImageView(mContext);
      img.setBackgroundColor(backcolor);
      mallPics.add(img);

      try {
        imageFetcher.loadFormCache(photos.get(i), mallPics.get(i));
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    for (int i = 0; i < mallPics.size(); i++) {
      mallPics
          .get(i)
          .setOnClickListener(
              new OnClickListener() {

                @Override
                public void onClick(View v) {
                  final Uri uri = Uri.parse(MALL_WEB);
                  final Intent it = new Intent(Intent.ACTION_VIEW, uri);
                  mContext.startActivity(it);
                }
              });
    }

    imageViewsMall = new ImageView[mallPics.size()];
    // 小图标
    for (int i = 0; i < mallPics.size(); i++) {
      imageView = new ImageView(mContext);
      imageView.setLayoutParams(new LayoutParams(20, 20));
      imageView.setPadding(5, 5, 5, 5);
      imageViewsMall[i] = imageView;
      if (i == 0) {
        imageViewsMall[i].setBackgroundResource(Indicator_select);
      } else {
        imageViewsMall[i].setBackgroundResource(Indicator_unselect);
      }
      mall_indicators.addView(imageViewsMall[i]);
    }

    mall_pager.setAdapter(new AdvAdapter(mallPics));
    mall_pager.setOnPageChangeListener(new GuidePageChangeListenerMall());
    mall_pager.setOnTouchListener(
        new OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
              case MotionEvent.ACTION_DOWN:
              case MotionEvent.ACTION_MOVE:
                isContinueMall = false;
                break;
              case MotionEvent.ACTION_UP:
                isContinueMall = true;
                break;
              default:
                isContinueMall = true;
                break;
            }
            return false;
          }
        });
    new Thread(
            new Runnable() {

              @Override
              public void run() {
                while (true) {
                  if (isContinueMall) {
                    viewHandlerMall.sendEmptyMessage(whatMall.get());
                    whatOptionMall();
                  }
                }
              }
            })
        .start();
  }
  public ScrollingViewPager(Context context, AttributeSet attrs) {
    super(context, attrs);
    mContext = context;
    mContextView =
        (RelativeLayout)
            LayoutInflater.from(context)
                .inflate(R.layout.wgt_horizontal_carousel_viewpager, this, true);
    TypedArray mTypeArray =
        context.obtainStyledAttributes(attrs, R.styleable.HorizontlScrollViewPager);
    mContinuedTime =
        mTypeArray.getInteger(
            R.styleable.HorizontlScrollViewPager_scrollDurationMinute, DEFAULT_TIME);
    mAllowScroll =
        mTypeArray.getBoolean(R.styleable.HorizontlScrollViewPager_allowScroll, DEFAULT_ALLOW);
    mViewPager = (ViewPager) mContextView.findViewById(R.id.pager);
    mIndicator = (CirclePageIndicator) mContextView.findViewById(R.id.circle_indicator);

    mViewPager.addOnPageChangeListener(
        new OnPageChangeListener() {

          @Override
          public void onPageSelected(int arg0) {
            mCurrentPosition = arg0;
          }

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

          @Override
          public void onPageScrollStateChanged(int arg0) {}
        });

    mViewPager.setOnTouchListener(
        new OnTouchListener() {

          private long downTime;
          private float downX;

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
              case MotionEvent.ACTION_DOWN:
                downTime = System.currentTimeMillis();
                downX = v.getScrollX();
                stop();
                break;
              case MotionEvent.ACTION_UP:
                long upTime = System.currentTimeMillis();
                float upX = v.getScrollX();
                if ((upTime - downTime) < 200
                    && Math.abs(upX - downX) < 3
                    && null != onPagerClickListener) {
                  onPagerClickListener.onPagerClick(mCurrentPosition % mDataLists.size());
                }
                reStart();
                break;
              case MotionEvent.ACTION_CANCEL:
                reStart();
                break;
            }
            return false;
          }
        });
    mTypeArray.recycle();
  }
  private void initViewPager() {
    homeViewPager = (ViewPager) headerView.findViewById(R.id.home_viewpager);
    ViewGroup dotContainer = (ViewGroup) headerView.findViewById(R.id.dot_container);

    // 创建广告页
    List<View> adsImageList = new ArrayList<View>();
    NetworkImageView ads1 = new NetworkImageView(getActivity());
    ads1.setScaleType(ImageView.ScaleType.FIT_XY);
    ads1.setBackgroundColor(Color.TRANSPARENT);
    adsImageList.add(ads1);
    NetworkImageView ads2 = new NetworkImageView(getActivity());
    ads2.setScaleType(ImageView.ScaleType.FIT_XY);
    ads2.setBackgroundColor(Color.TRANSPARENT);
    adsImageList.add(ads2);
    NetworkImageView ads3 = new NetworkImageView(getActivity());
    ads3.setScaleType(ImageView.ScaleType.FIT_XY);
    ads3.setBackgroundColor(Color.TRANSPARENT);
    adsImageList.add(ads3);
    // 从服务器加载广告图片并显示
    String adUrl = "http://182.61.8.185/images/3/3.jpg";
    Traffic.showNetworkImage(requestQueue, adUrl, ads1);
    Traffic.showNetworkImage(requestQueue, adUrl, ads2);
    Traffic.showNetworkImage(requestQueue, adUrl, ads3);

    // 对dotImageViews进行填充
    dotImageViews = new ImageView[adsImageList.size()];
    // 导航圆点
    for (int i = 0; i < adsImageList.size(); i++) {
      dotImageView = new ImageView(getActivity());
      dotImageView.setLayoutParams(new LinearLayout.LayoutParams(20, 20));
      dotImageView.setPadding(5, 5, 5, 5);
      dotImageViews[i] = dotImageView;
      if (i == 0) {
        dotImageViews[i].setImageResource(R.drawable.dot_selected);
      } else {
        dotImageViews[i].setImageResource(R.drawable.dot);
      }
      dotContainer.addView(dotImageViews[i]);
    }

    homeViewPager.setAdapter(new AdsAdapter(adsImageList));
    homeViewPager.addOnPageChangeListener(
        new ViewPager.OnPageChangeListener() {
          @Override
          public void onPageScrolled(
              int position, float positionOffset, int positionOffsetPixels) {}

          @Override
          public void onPageSelected(int position) {
            what.getAndSet(position);
            for (int i = 0; i < dotImageViews.length; i++) {
              dotImageViews[position].setImageResource(R.drawable.dot_selected);
              if (position != i) {
                dotImageViews[i].setImageResource(R.drawable.dot);
              }
            }
          }

          @Override
          public void onPageScrollStateChanged(int state) {}
        });
    homeViewPager.setOnTouchListener(
        new View.OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
              case MotionEvent.ACTION_DOWN:
              case MotionEvent.ACTION_MOVE:
                isContinue = false;
              case MotionEvent.ACTION_UP:
                isContinue = true;
                break;
              default:
                isContinue = true;
                break;
            }
            return false;
          }
        });
    new Thread(
            new Runnable() {
              @Override
              public void run() {
                while (true) {
                  if (isContinue) {
                    viewHandler.sendEmptyMessage(what.get());
                    whatOpition();
                  }
                }
              }
            })
        .start();

    homeViewPager.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            // 启动广告活动
          }
        });
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mViewPager = (ViewPager) findViewById(R.id.vp_pager);
    mViewPager.setAdapter(new MyPagerAdapter()); // 给ViewPager设置数据

    mViewPager.setCurrentItem(mImageIds.length * 1000); // 设置item的位置

    tvTitle = (TextView) findViewById(R.id.tv_title);
    tvTitle.setText(mImageDes[0]); // 第一次初始化,设置标题内容

    // 设置页面滑动监听
    mViewPager.setOnPageChangeListener(
        new OnPageChangeListener() {

          // 某一页被选中
          @Override
          public void onPageSelected(int position) {
            int pos = position % mImageIds.length;
            tvTitle.setText(mImageDes[pos]); // 滑动后,修改标题内容

            llContainer.getChildAt(pos).setEnabled(true); // 被选中的圆点设置为红色
            llContainer.getChildAt(mLastPointPos).setEnabled(false); // 上一次被选中的圆点设置为灰色

            mLastPointPos = pos; // 给上一个圆点位置赋值
          }

          // 页面滑动事件
          @Override
          public void onPageScrolled(
              int position, float positionOffset, int positionOffsetPixels) {}

          // 页面滑动状态发生变化
          @Override
          public void onPageScrollStateChanged(int state) {}
        });

    // 初始化小圆点
    llContainer = (LinearLayout) findViewById(R.id.ll_container);

    for (int i = 0; i < mImageIds.length; i++) {
      ImageView view = new ImageView(this);
      // view.setImageResource(R.drawable.shape_circle_default);
      view.setImageResource(R.drawable.shape_circle_selector);

      LinearLayout.LayoutParams params =
          new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
      if (i != 0) {
        params.leftMargin = 5; // 从第二个圆点开始设置左边距
        view.setEnabled(false); // 从第二个圆点开始都设置为不可用
      }

      view.setLayoutParams(params); // 给ImageView设置布局参数

      llContainer.addView(view);
    }

    mHandler.sendEmptyMessageDelayed(0, 3000); // 延时3秒发消息,切换广告条

    // 设置触摸事件
    mViewPager.setOnTouchListener(
        new OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
              case MotionEvent.ACTION_DOWN:
                // 停止广告播放
                mHandler.removeCallbacksAndMessages(null); // 清除handler中的所有消息
                break;
              case MotionEvent.ACTION_UP:
                // 继续播放广告
                mHandler.sendEmptyMessageDelayed(0, 3000); // 继续延时3秒发消息,形成无限循环
                break;

              default:
                break;
            }

            return false; // 要返回false,让ViewPager可以处理默认滑动效果的事件
          }
        });
  }
Example #16
0
  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    findUI();

    setSupportActionBar(toolbar);
    getSupportActionBar().setElevation(0);
    ActionBarDrawerToggle drawerToggle =
        new ActionBarDrawerToggle(
            this,
            drawerLayout,
            toolbar,
            R.string.navigation_drawer_open,
            R.string.navigation_drawer_close);
    drawerLayout.setDrawerListener(drawerToggle);
    drawerToggle.syncState();

    navigationView.setNavigationItemSelectedListener(this);

    // Initialise
    drawerLayout.setViewPager(navigationView, R.id.pager_material);
    scroll.setColorSchemeResources(R.color.colorPrimary);
    scroll.setOnRefreshListener(this);

    pagerMaterial.setAdapter(new MaterialPageAdapter(this));
    pagerMaterial.setPageTransformer(true, new MaterialTransformer());
    pagerCity.setAdapter(new CityPageAdapter(this));

    pagerMaterial.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            pagerCity.onTouchEvent(event);
            return false;
          }
        });
    pagerCity.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            pagerMaterial.onTouchEvent(event);
            return false;
          }
        });

    pagerCity.setOnPageChangeListener(
        new ViewPager.OnPageChangeListener() {
          @Override
          public void onPageScrolled(
              int position, float positionOffset, int positionOffsetPixels) {}

          @Override
          public void onPageSelected(int position) {
            WeatherController.getInstance()
                .setCurrentCity(WeatherController.getInstance().getCities().get(position));
            try {
              ((ForecastFragment) getFragmentManager().findFragmentByTag(FRAGMENT_TAG)).update();
            } catch (ClassCastException ignored) {

            }
          }

          @Override
          public void onPageScrollStateChanged(int state) {}
        });
    Log.d(TAG, "Updating forecast for current city");
    pagerCity.setCurrentItem(WeatherController.getInstance().getIDCurrentCity());
    pagerMaterial.setCurrentItem(WeatherController.getInstance().getIDCurrentCity());

    b_cities.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            startActivityForResult(new Intent(ForecastActivity.this, CitiesActivity.class), 1);
            drawerLayout.closeDrawer(GravityCompat.START);
          }
        });

    if (savedInstanceState == null) onNavigationItemSelected(navigationView.getMenu().getItem(0));
  }