Ejemplo n.º 1
2
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_second);
    ViewPager pager = (ViewPager) findViewById(R.id.parent);
    pager.setOffscreenPageLimit(1);
    pager.setAdapter(
        new FragmentPagerAdapter(getSupportFragmentManager()) {
          @Override
          public android.support.v4.app.Fragment getItem(int position) {
            return new ExampleFragment(String.valueOf(position));
          }

          @Override
          public int getCount() {
            return 5;
          }
        });
    LifeCycleRetriever.with(this)
        .addListener(
            new LifecycleListener() {
              @Override
              public void onLifeCycleStateChange(@LifeCycle.LifeCycleState int life, int level) {
                Log.e("tag", "ActivityLifeCycle,State:" + haha(life));
              }
            });
  }
Ejemplo n.º 2
1
  private void setupViewPager(ViewPager viewPager) {
    final ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
    adapter.addFrag(((new PlaceholderFragment()).newInstance(0)), "Volume");
    adapter.addFrag(((new PlaceholderFragment()).newInstance(1)), "Surface Area");
    viewPager.addOnPageChangeListener(
        new ViewPager.OnPageChangeListener() {
          @Override
          public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            adapter.getItem(position).setTransitionNameLollipop();
            if (position > 0) adapter.getItem(position - 1).setTransitionNull();
            else adapter.getItem(position + 1).setTransitionNull();
          }

          @Override
          public void onPageSelected(int position) {
            adapter.getItem(position).setTransitionNameLollipop();
            if (position > 0) adapter.getItem(position - 1).setTransitionNull();
            else adapter.getItem(position + 1).setTransitionNull();
          }

          @Override
          public void onPageScrollStateChanged(int state) {}
        });
    viewPager.setAdapter(adapter);
  }
 @Override
 public void handleMessage(Message msg) {
   // 如果没有两条以上数据,则不需要轮播
   if (MESSAGE != msg.what || count < 2) return;
   int index = (viewPager.getCurrentItem() + 1) % count;
   viewPager.setCurrentItem(index, true);
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_viewpager);

    mViewPager = (ViewPager) findViewById(R.id.v_scroll);
    StickHeaderLayout shl_root = (StickHeaderLayout) findViewById(R.id.shl_root);
    mViewPager.setOffscreenPageLimit(4);

    manager = new StickHeaderViewPagerManager(shl_root, mViewPager);

    viewList = new ArrayList<ViewPagerBean>();

    SimpleRecyclerView simpleRecyclerView = new SimpleRecyclerView(this);
    viewList.add(
        new ViewPagerBean(simpleRecyclerView, simpleRecyclerView.getPlaceHoderHeaderLayout()));

    SimpleScrollView simpleScrollView = new SimpleScrollView(this);
    viewList.add(new ViewPagerBean(simpleScrollView, simpleScrollView.getPlaceHoderHeaderLayout()));

    SimpleListView simpleListView = new SimpleListView(this);
    viewList.add(new ViewPagerBean(simpleListView, simpleListView.getPlaceHoderHeaderLayout()));

    SimpleWebView simpleWebView = new SimpleWebView(this);
    viewList.add(new ViewPagerBean(simpleWebView, simpleWebView.getPlaceHoderHeaderLayout()));

    mViewPager.setAdapter(pagerAdapter);

    initTabBar();
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    init(container, savedInstanceState);
    setHasOptionsMenu(true);
    final View view = inflater.inflate(R.layout.fragment_books_pager, container, false);
    final Bundle extras = getArguments();

    if (extras != null) {
      mBookPosition = extras.getInt(Keys.BOOK_POSITION);
    }

    mBookDetailPager = (ViewPager) view.findViewById(R.id.pager_books);
    mBookDetailPager.setOnPageChangeListener(this);
    mSlidingLayout = (SlidingUpPanelLayout) view.findViewById(R.id.sliding_layout);
    mSlidingLayout.setPanelSlideListener(this);

    mAdapter = new BookPageAdapter(getChildFragmentManager(), null);
    mBookDetailPager.setAdapter(mAdapter);

    if (savedInstanceState == null) {
      final ProfileFragment fragment = new ProfileFragment();

      getChildFragmentManager()
          .beginTransaction()
          .replace(R.id.content_user_profile, fragment, FragmentTags.USER_PROFILE)
          .commit();
    } else {
      mBookPosition = savedInstanceState.getInt(Keys.BOOK_POSITION);
    }

    loadBookSearchResults();

    return view;
  }
Ejemplo n.º 6
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Fresco.initialize(this);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_main);
    viewPager = (ViewPager) findViewById(R.id.vp_img);
    viewPager.addOnPageChangeListener(
        new ViewPager.OnPageChangeListener() {
          @Override
          public void onPageScrolled(int i, float v, int i1) {}

          @Override
          public void onPageSelected(int i) {
            Toast.makeText(MainActivity.this, "" + i, Toast.LENGTH_SHORT).show();
          }

          @Override
          public void onPageScrollStateChanged(int i) {}
        });
    viewPager.setAdapter(
        new PagerAdapter() {
          @Override
          public Object instantiateItem(ViewGroup container, int position) {
            SimpleDraweeView mDraweeViewe = new SimpleDraweeView(MainActivity.this);
            // ImageView imgView = (ImageView)
            // View.inflate(getApplicationContext(),R.layout.layout_imgview, null);
            /*GenericDraweeHierarchy hierarchy = mDraweeViewe.getHierarchy();
            hierarchy.setPlaceholderImage(imgIds[position]);*/

            mDraweeViewe.setScaleType(ImageView.ScaleType.CENTER_CROP);
            mDraweeViewe.setAspectRatio(1f);
            Uri imgUri = Uri.parse(imgUrls[position]);
            mDraweeViewe.setImageURI(imgUri);
            container.addView(mDraweeViewe);
            ivList.add(mDraweeViewe);
            return mDraweeViewe;
          }

          @Override
          public int getItemPosition(Object object) {
            return super.getItemPosition(object);
          }

          @Override
          public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView(ivList.get(position));
          }

          @Override
          public int getCount() {
            return imgUrls.length;
          }

          @Override
          public boolean isViewFromObject(View view, Object object) {
            return view == object;
          }
        });
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    savedInstanceState = getIntent().getExtras().getBundle("bundle");
    this.tab = savedInstanceState.getStringArrayList("list");
    this.pos = savedInstanceState.getInt("position");
    setContentView(R.layout.activity_town_details);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar2);
    setSupportActionBar(toolbar);

    ActionBar ab = getSupportActionBar();
    ab.setDisplayHomeAsUpEnabled(true);

    refresh();
    List<TownDetailsFragment> list = new ArrayList<TownDetailsFragment>();
    for (int i = 0; i < this.tab.size(); i++) {
      list.add(TownDetailsFragment.newInstance(this.tab.get(i)));
    }

    MyPagerAdapter pagerAdapter = new MyPagerAdapter(getSupportFragmentManager(), list);
    this.receiverData = new RefreshAllReceiver(pagerAdapter, this.tab);
    this.receiverIcon = new RefreshIconReceiver(pagerAdapter);
    this.filtreData = new IntentFilter("com.intent.action.ALLRECEIVE");
    this.filtreIcon = new IntentFilter("com.intent.action.ICON_UPDATE");

    this.registerReceiver(receiverData, filtreData);
    this.registerReceiver(receiverIcon, filtreIcon);

    refresh();
    ViewPager view = (ViewPager) findViewById(R.id.viewpager);
    view.setAdapter(pagerAdapter);
    view.setCurrentItem(pos);
  }
Ejemplo n.º 8
0
 private void populateTabStrip() {
   final PagerAdapter adapter = mViewPager.getAdapter();
   final View.OnClickListener tabClickListener = new TabClickListener();
   for (int i = 0; i < adapter.getCount(); i++) {
     View tabView = null;
     TextView tabTitleView = null;
     if (mTabViewLayoutId != 0) {
       // If there is a custom tab view layout id set, try and inflate it
       tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
       tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
     }
     if (tabView == null) {
       tabView = createDefaultTabView(getContext());
     }
     if (tabTitleView == null && TextView.class.isInstance(tabView)) {
       tabTitleView = (TextView) tabView;
     }
     if (mDistributeEvenly) {
       LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
       lp.width = 0;
       lp.weight = 1;
     }
     tabTitleView.setText(adapter.getPageTitle(i));
     tabView.setOnClickListener(tabClickListener);
     String desc = mContentDescriptions.get(i, null);
     if (desc != null) {
       tabView.setContentDescription(desc);
     }
     mTabStrip.addView(tabView);
     if (i == mViewPager.getCurrentItem()) {
       tabView.setSelected(true);
     }
   }
 }
Ejemplo n.º 9
0
  private void initViewPager() {
    viewPagerAdapter =
        AdapterLess.$pager(
            getSupportFragmentManager(),
            getResources().getStringArray(R.array.must_titles).length,
            new AdapterLess.FullFragmentPagerCallBack() {
              @Override
              public Fragment getItem(int i) {
                Fragment fragment;
                if (i == 0) {
                  fragment = new MustListFragment();
                } else if (i == 1) {
                  fragment = new MustListFragment();
                } else {
                  fragment = new HomeDigestListFragment();
                }
                return fragment;
              }

              @Override
              public String getPageTitle(int i) {
                return getResources().getStringArray(R.array.must_titles)[i];
              }
            });
    viewPager.setOffscreenPageLimit(3);
    viewPager.setAdapter(viewPagerAdapter);
    tabLayout.setupWithViewPager(viewPager);
  }
Ejemplo n.º 10
0
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_speelveld);
    // Intent intent = getIntent();
    // deelneemGegevens = intent.getStringArrayExtra("strings");
    // spelerLijst[1] = deelneemGegevens[0];

    ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
    adapter = new ImageAdapter(this);
    viewPager.setAdapter(adapter);

    setNaam();

    // Een listener voor het ophalen van de geselceteerde kaart
    viewPager.addOnPageChangeListener(
        new ViewPager.OnPageChangeListener() {

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

          @Override
          public void onPageSelected(int cardNumber) {
            selectedCard = cardNumber;

            huidigeKaart();
          }

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

    getKaartenDatabase();
  }
 public static void removeCurItem(MenuItem item, int idx, ViewPager vp) {
   for (int i = 0; i < vp.getAdapter().getCount(); i++) {
     if (item.getItemId() == idx + i + 1) {
       vp.setCurrentItem(i);
     }
   }
 }
Ejemplo n.º 12
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    doBindService();

    final ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    mViewPager.setOnPageChangeListener(
        new ViewPager.SimpleOnPageChangeListener() {
          @Override
          public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
          }
        });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {

      actionBar.addTab(
          actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
  }
Ejemplo n.º 13
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_learn);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    // 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);

    if (flipper1) {
      mViewPager.setCurrentItem(8, false);
      flipper1 = false;
    } else if (flipper2) {
      mViewPager.setCurrentItem(4, false);
      flipper2 = false;
    } else if (mid) {
      mViewPager.setCurrentItem(8, false);
      mid = false;
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_article_detail);

    getLoaderManager().initLoader(0, null, this);

    mPagerAdapter = new MyPagerAdapter(getFragmentManager());
    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(mPagerAdapter);
    mPager.setPageMargin(
        (int)
            TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics()));
    mPager.setPageMarginDrawable(new ColorDrawable(0x22000000));

    mPager.addOnPageChangeListener(
        new ViewPager.SimpleOnPageChangeListener() {

          @Override
          public void onPageSelected(int position) {
            if (mCursor != null) {
              mCursor.moveToPosition(position);
            }
            mSelectedItemId = mCursor.getLong(ArticleLoader.Query._ID);
          }
        });

    if (savedInstanceState == null) {
      if (getIntent() != null && getIntent().getData() != null) {
        mStartId = ItemsContract.Items.getItemId(getIntent().getData());
        mSelectedItemId = mStartId;
      }
    }
  }
  private void initView() {
    mViewPager = (ViewPager) this.findViewById(R.id.viewpager);
    mPageNum = (TextView) this.findViewById(R.id.page_num);
    mEditText = (EditText) this.findViewById(R.id.edit_text);
    mButton = (Button) this.findViewById(R.id.button);
    mButton.setOnClickListener(this);

    List<Fragment> fragments = new ArrayList<Fragment>();
    Fragment fragment1 = MyOneFragment.newInstance();
    Fragment fragment2 = MyTwoFragment.newInstance();
    Fragment fragment3 = MyThreeFragment.newInstance();
    Fragment fragment4 = MyFourFragment.newInstance();
    Fragment fragment5 = MyFiveFragment.newInstance();

    fragments.add(fragment1);
    fragments.add(fragment2);
    fragments.add(fragment3);
    fragments.add(fragment4);
    fragments.add(fragment5);

    mMyFragmentPagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager(), fragments);
    mViewPager.setAdapter(mMyFragmentPagerAdapter);
    mViewPager.setPageTransformer(true, new FragmentTransformer()); // 设置页面变换监听,对每个页面的变化都有一个变换的监听
    mViewPager.addOnPageChangeListener(new OnMyPageChangeListener()); // 页面变化监听
    mViewPager.setOffscreenPageLimit(2); // 设置缓存页面数。当前页,左右两边(单边)最大缓存页面数。
    //        mViewPager.setOnScrollChangeListener(new
    // OnMyScrollChangeListener());//滚动状态监听,minSdkVersion:23
    //        mViewPager.getCurrentItem();//获取当前显示页索引
    //        mViewPager.getOffscreenPageLimit();//获取缓存页面数
    //        mViewPager.onSaveInstanceState();
    //        mViewPager.setPageTransformer();
    setPageNum(0); // 设置显示首页
  }
Ejemplo n.º 16
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "setting selected id from intent");
    setSelectedItemIDFromIntent();
    ActiveUser activeUser = ((GiveOrTakeApplication) getApplication()).getActiveUser();
    if (activeUser == null || activeUser.getUserID() == null) {
      Intent logoutIntent = new Intent(this, LoginActivity.class);
      logoutIntent.putExtra(LoginFragment.EXTRA_LOGIN_ACTION, LoginFragment.LOGOUT);
      logoutIntent.putExtra(MainActivity.EXTRA_ITEM_ID, getSelectedItemID());
      startActivity(logoutIntent);
      finish();
    }

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the app.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    // When swiping between different sections, select the corresponding
    // tab. We can also use ActionBar.Tab#select() to do this if we have
    // a reference to the Tab.
    mViewPager.setOnPageChangeListener(
        new ViewPager.SimpleOnPageChangeListener() {
          @Override
          public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
          }
        });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
      // Create a tab with text corresponding to the page title defined by
      // the adapter. Also specify this Activity object, which implements
      // the TabListener interface, as the callback (listener) for when
      // this tab is selected.
      actionBar.addTab(
          actionBar
              .newTab()
              .setText(mSectionsPagerAdapter.getPageTitle(i))
              .setIcon(mSectionsPagerAdapter.getPageIcon(i))
              .setTabListener(this));
    }

    actionBar.selectTab(actionBar.getTabAt(DEFAULT_SELECTED_TAB));

    Long itemID = getSelectedItemID();
    if (itemID != null) {
      actionBar.selectTab(actionBar.getTabAt(FREE_ITEMS_TAB));
    }
  }
Ejemplo n.º 17
0
  private void init() {
    mSwipeBackLayout.addSwipeListener(this);
    mSwipeBackLayout.setEdgeTrackingEnabled(SwipeBackLayout.EDGE_LEFT);

    PageAdapter adapter = new PageAdapter(getSupportFragmentManager());
    mViewPager.setAdapter(adapter);

    mViewPager.addOnPageChangeListener(
        new ViewPager.OnPageChangeListener() {
          @Override
          public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            Log.d(TAG, "position->" + position);
            if (position == 0) {
              getSwipeBackLayout().setEdgeSize(Utils.dp2px(200));
            } else {
              getSwipeBackLayout().setEdgeSize(0);
            }
          }

          @Override
          public void onPageSelected(int position) {}

          @Override
          public void onPageScrollStateChanged(int state) {}
        });
    //        mViewPager.setPageTransformer(false, new PageTransformer());
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_enlarge_photo);

    // get the intent
    Intent intent = getIntent();
    Bundle data = intent.getExtras();
    IntentData intentData = data.getParcelable(Constants.IntentsCodes.intentData);

    // set the constant views at this activity
    fillViewWithUserDetails(intentData);

    // get from the intent the data to pass to the pager adapter
    String image1Path = intentData.getphoto1Path();

    String image2Path = intentData.getphoto2Path();

    int votes1 = intentData.getVotes1();
    int votes2 = intentData.getVotes2();
    boolean isAlreadyVoted = intentData.checkIfVotedAlready();

    //		EnlargeDetails details = new EnlargeDetails(image1Path, image2Path,
    //				votes1, votes2, isAlreadyVoted);

    CustomEnlargePagerAdapter adapter =
        new CustomEnlargePagerAdapter(intentData, getWindowManager().getDefaultDisplay());
    ViewPager myPager = (ViewPager) findViewById(R.id.enlargePhoto_viewPager);
    myPager.setAdapter(adapter);

    // start the view pager by the current photo
    int startingImage = intentData.getStartingImage();
    myPager.setCurrentItem(startingImage);
  }
Ejemplo n.º 19
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_touristic_point);

    // Toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitleTextColor(Color.WHITE);
    toolbar.setSubtitleTextColor(Color.WHITE);
    setSupportActionBar(toolbar);

    // Create the adapter that will return a fragment for each of the 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.addOnPageChangeListener(this);

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

    // Recebendo dados da outra activity
    Intent intent = getIntent();
    int id = intent.getExtras().getInt("id");
    touristicPoint = DatabaseDAO.getInstance().getTouristicPointByID(id);
  }
Ejemplo n.º 20
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_mostrar_imagen);

    try {
      Intent intent = getIntent();
      Bundle b = (Bundle) intent.getExtras();
      idRecurso = b.getInt(MainActivity.ID_KEY, 0);

      if (idRecurso == 0) {
        String path = b.getString(MainActivity.URL_KEY);
        uriImagen =
            Uri.parse(
                Environment.getExternalStorageDirectory() + MainActivity.APP_DIRECTORY + path);
      } else {
        buscarUri(idRecurso);
      }

    } catch (Exception e) {
      e.printStackTrace();
      Toast.makeText(this, "Error: " + e.getMessage(), Toast.LENGTH_SHORT).show();
    }

    ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
    ImagePagerAdapter adapter = new ImagePagerAdapter(uriImagen);
    viewPager.setAdapter(adapter);
  }
  /** Adds tabs below the action bar. */
  private void addTabs() {
    viewPager = (ViewPager) findViewById(R.id.pager_main);
    actionBar = getActionBar();
    mAdapter = new TabsPagerAdapter(getSupportFragmentManager());

    viewPager.setAdapter(mAdapter);
    actionBar.setHomeButtonEnabled(false);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // temp fix, to make sure that PATHAlerts isn't refreshing all the time
    viewPager.setOffscreenPageLimit(4);

    // Adding Tabs
    for (String tab_name : tabs) {
      actionBar.addTab(actionBar.newTab().setText(tab_name).setTabListener(this));
    }

    viewPager.setOnPageChangeListener(
        new ViewPager.OnPageChangeListener() {

          @Override
          public void onPageSelected(int position) {
            // on changing the page
            // make respected tab selected
            actionBar.setSelectedNavigationItem(position);
          }

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

          @Override
          public void onPageScrollStateChanged(int arg0) {}
        });
  }
Ejemplo n.º 22
0
  private void initViewPager() {
    seekBar.setMax(viewPager.getAdapter().getCount() - 1);
    seekBar.setOnSeekBarChangeListener(this);
    seekBar.setProgress(viewPager.getCurrentItem());
    viewPager.addOnPageChangeListener(
        new ViewPager.OnPageChangeListener() {
          @Override
          public void onPageScrolled(
              int position, float positionOffset, int positionOffsetPixels) {}

          @Override
          public void onPageSelected(int position) {
            seekBar.setProgress(position);
            updateCurPos(position, seekBar.getMax());
          }

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

    viewPager.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {}
        });

    updateCurPos(seekBar.getProgress(), seekBar.getMax());
  }
Ejemplo n.º 23
0
 /** 图片循环 */
 private void initViewPager() {
   ViewGroup.LayoutParams mViewPagerlayoutParams = mViewPager.getLayoutParams();
   if (mViewPagerlayoutParams != null) {
     mViewPagerlayoutParams.width = Misc.getScreenDisplay(this)[0];
     mViewPagerlayoutParams.height = (int) (mViewPagerlayoutParams.width);
     mViewPager.setLayoutParams(mViewPagerlayoutParams);
   }
   mViewPager.setAdapter(new ProductDetailPicAdapter2(this, product.getImgList()));
   mViewPager.setOnPageChangeListener(this);
   // 设置布局参数
   LinearLayout.LayoutParams params =
       new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
   int marginParam = Misc.dip2px(this, 10) / 2;
   llytPagerPoiner.removeAllViewsInLayout();
   for (int i = 0; i < product.getImgList().size(); i++) {
     // 设置按钮属性
     View item = new ImageView(this);
     item.setBackgroundResource(R.drawable.recommend_gallery);
     item.setTag(String.valueOf(i));
     // item.setOnClickListener(parentActivity);
     params.setMargins(marginParam, 0, marginParam, 0);
     params.weight = 1;
     llytPagerPoiner.addView(item, params);
   }
   llytPagerPoiner.getChildAt(0).setBackgroundResource(R.drawable.recommend_gallery_select);
 }
Ejemplo n.º 24
0
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    viewPager = (ViewPager) getActivity().findViewById(R.id.pager);
    actionBar = getActivity().getActionBar();
    mAdapter = new Course1Adapter(getActivity().getSupportFragmentManager());
    viewPager.setAdapter(mAdapter);
    actionBar.setHomeButtonEnabled(true);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Add the tabs here
    for (String tab_name : tabs) {
      actionBar.addTab(actionBar.newTab().setText(tab_name).setTabListener(this));
    }

    viewPager.setOnPageChangeListener(
        new ViewPager.SimpleOnPageChangeListener() {

          @Override
          public void onPageSelected(int position) {

            // on Page change, that particular page should be selected
            actionBar.setSelectedNavigationItem(position);
          }

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

          @Override
          public void onPageScrollStateChanged(int position) {}
        });
  }
Ejemplo n.º 25
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // initialize the inflater
    mInflater = inflater;

    View rootView = mInflater.inflate(R.layout.app_ops_summary, container, false);
    mContentContainer = container;
    mRootView = rootView;

    mPageNames = getResources().getTextArray(R.array.app_ops_categories);

    mViewPager = (ViewPager) rootView.findViewById(R.id.pager);
    MyPagerAdapter adapter = new MyPagerAdapter(getChildFragmentManager());
    mViewPager.setAdapter(adapter);
    mViewPager.setOnPageChangeListener(adapter);
    PagerTabStrip tabs = (PagerTabStrip) rootView.findViewById(R.id.tabs);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
      tabs.setTabIndicatorColorResource(android.R.color.holo_blue_light);
    } else {
      final TypedValue val = new TypedValue();
      getActivity().getTheme().resolveAttribute(android.R.attr.colorAccent, val, true);
      tabs.setTabIndicatorColor(val.data);
    }

    // We have to do this now because PreferenceFrameLayout looks at it
    // only when the view is added.
    if (container != null
        && "android.preference.PreferenceFrameLayout".equals(container.getClass().getName())) {
      new ObjectWrapper(rootView.getLayoutParams()).set("removeBorders", true);
    }

    return rootView;
  }
Ejemplo n.º 26
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.default_layout);

    ViewPager pager = (ViewPager) findViewById(R.id.pager);
    pager.setAdapter(new MyPagerAdapter(getSupportFragmentManager()));

    final ScrollableTabView tabs = (ScrollableTabView) findViewById(R.id.scrollTabs);
    tabs.setViewPager(pager);
    tabs.setTabAdapter(new CustomTabAdapter(R.layout.my_tab_custom_text));

    findViewById(R.id.button_divider_color)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                Random random = new Random();
                int dividerColor =
                    Color.rgb(random.nextInt(255), random.nextInt(255), random.nextInt(255));
                tabs.setDividerColor(dividerColor);
              }
            });

    findViewById(R.id.button_divider_visibility)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                tabs.setShowDivider(!tabs.isShowingSeparator());
              }
            });
  }
Ejemplo n.º 27
0
  private void initView() {
    mCurrentTabIndex = 0;
    mTabTitles =
        new String[] {
          mActivity.getResources().getString(R.string.ml_chat),
          mActivity.getResources().getString(R.string.ml_contacts),
          mActivity.getResources().getString(R.string.ml_test)
        };

    mContactsFragment = MLContactsFragment.newInstance();
    mConversationFragment = MLConversationsFragment.newInstance();
    mTestFragment = MLTestFragment.newInstance();

    mFragments = new Fragment[] {mConversationFragment, mContactsFragment, mTestFragment};
    MLViewPagerAdapter adapter =
        new MLViewPagerAdapter(getSupportFragmentManager(), mFragments, mTabTitles);
    mViewPager.setAdapter(adapter);
    mViewPager.setCurrentItem(mCurrentTabIndex);
    mViewPager.addOnPageChangeListener(
        new ViewPager.OnPageChangeListener() {
          @Override
          public void onPageScrolled(
              int position, float positionOffset, int positionOffsetPixels) {}

          @Override
          public void onPageSelected(int position) {
            getToolbar().setTitle(mTabTitles[position]);
          }

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

    mTabLayout.setupWithViewPager(mViewPager);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_underline_page_indicator);
    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
    viewPager.setAdapter(
        new FragmentStatePagerAdapter(getSupportFragmentManager()) {
          @Override
          public int getCount() {
            return 5;
          }

          @Override
          public Fragment getItem(int position) {
            Fragment f = new SampleFragment();
            Bundle args = new Bundle();
            args.putInt(SampleFragment.PAGE_NUMBER, position + 1);
            f.setArguments(args);
            return f;
          }

          @Override
          public CharSequence getPageTitle(int position) {
            return "Page" + (position + 1);
          }
        });
    PageIndicator titleIndicator = (PageIndicator) findViewById(R.id.indicator);
    titleIndicator.setViewPager(viewPager);
  }
Ejemplo n.º 29
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    //
    ButterKnife.bind(this);
    getSupportActionBar().hide();
    final ViewPagerAdapter adap = new ViewPagerAdapter(getSupportFragmentManager());
    viewpager.setAdapter(adap);
    viewpager.addOnPageChangeListener(
        new ViewPager.OnPageChangeListener() {
          @Override
          public void onPageScrolled(
              int position, float positionOffset, int positionOffsetPixels) {}

          @Override
          public void onPageSelected(int position) {
            updateTotal(position, PIC_LINKS.length);
          }

          @Override
          public void onPageScrollStateChanged(int state) {}
        });
    updateTotal(0, PIC_LINKS.length);
  }
  /** Set up spinner navigation with swiped pages */
  private void setUpNavigation() {
    // Navigation spinner in toolbar for trainings selection
    LayoutInflater.from(mToolbar.getContext()).inflate(R.layout.navigation_spinner, mToolbar, true);
    mNavigationSpinner = (Spinner) mToolbar.findViewById(R.id.navigation_spinner);
    mNavigationSpinner.setOnItemSelectedListener(this);
    mNavigationSpinner.setSelection(mPosition);

    String[] from = new String[] {Trainings.EXERCISE};
    int[] to = new int[] {R.id.title};
    mNavigationAdapter =
        new NavigationAdapter(
            mToolbar.getContext(), R.layout.navigation_spinner_item, null, from, to, 0);
    mNavigationAdapter.setDropDownViewResource(R.layout.navigation_spinner_dropdown_item);
    mNavigationSpinner.setAdapter(mNavigationAdapter);

    // ViewPager for swipe navigation and animation on training select
    mViewPager.setOnPageChangeListener(this);
    mPagerAdapter = new TrainingPagerAdapter(getChildFragmentManager(), null);
    mViewPager.setAdapter(mPagerAdapter);

    Loader<Cursor> loader = getLoaderManager().getLoader(0);
    if (loader != null && !loader.isReset()) {
      getLoaderManager().restartLoader(0, null, this);
    } else {
      getLoaderManager().initLoader(0, null, this);
    }
  }