Java tutorial
/* * Copyright 2014 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.muvingapp.muving; import android.content.res.Resources; import android.os.Build; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.app.ActionBarActivity; import android.support.v7.widget.Toolbar; import android.util.Config; import android.view.View; import android.widget.ScrollView; import android.widget.TextView; import com.muvingapp.muving.R; import java.lang.ref.WeakReference; import java.util.*; public class MainActivity extends ActionBarActivity { // View pager and adapter (for narrow mode) ViewPager mViewPager = null; OurViewPagerAdapter mViewPagerAdapter = null; SlidingTabLayout mSlidingTabLayout = null; ScrollView mScrollViewWide; private SwipeRefreshLayout mSwipeRefreshLayout; // Login failed butter bar View mButterBar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); /* [ANALYTICS:SCREEN] * TRIGGER: View the My Schedule screen. * LABEL: 'My Schedule' * [/ANALYTICS] */ Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar1); setSupportActionBar(toolbar); mViewPager = (ViewPager) findViewById(R.id.pager); //mScrollViewWide = (ScrollView) findViewById(R.id.main_content_wide); //mWideMode = findViewById(R.id.my_schedule_first_day) != null; //int i; // for (i = 0; i < Config.CONFERENCE_DAYS.length; i++) { // mScheduleAdapters[i] = new MyScheduleAdapter(this, getLUtils()); //} mViewPagerAdapter = new OurViewPagerAdapter(getSupportFragmentManager()); mViewPager.setAdapter(mViewPagerAdapter); mSlidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs); mSlidingTabLayout.setCustomTabView(R.layout.tab_indicator, android.R.id.text1); mSlidingTabLayout.setContentDescription(1, "cercanos"); mSlidingTabLayout.setContentDescription(2, "recientes"); Resources res = getResources(); mSlidingTabLayout.setSelectedIndicatorColors(res.getColor(R.color.tab_selected_strip)); mSlidingTabLayout.setDistributeEvenly(true); mSlidingTabLayout.setViewPager(mViewPager); // mButterBar = findViewById(R.id.butter_bar); if (mSlidingTabLayout != null) { mSlidingTabLayout.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { if (position == 0) { mSlidingTabLayout.announceForAccessibility("cercanos"); } else { mSlidingTabLayout.announceForAccessibility("recientes"); } } } @Override public void onPageScrollStateChanged(int state) { enableDisableSwipeRefresh(state == ViewPager.SCROLL_STATE_IDLE); } }); } //overridePendingTransition(0, 0); //addDataObservers(); } protected void enableDisableSwipeRefresh(boolean enable) { if (mSwipeRefreshLayout != null) { mSwipeRefreshLayout.setEnabled(enable); } } private class OurViewPagerAdapter extends FragmentPagerAdapter { public OurViewPagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int position) { //fragment logic /* LOGD(TAG, "Creating fragment #" + position); MyScheduleFragment frag = new MyScheduleFragment(); Bundle args = new Bundle(); args.putInt(ARG_CONFERENCE_DAY_INDEX, position); frag.setArguments(args); return frag; */ Tab1Frag tab = new Tab1Frag(); //return tab; return tab; } @Override public int getCount() { return 2; } @Override public CharSequence getPageTitle(int position) { return "name"; } } }