Java Code Examples for android.support.design.widget.TabLayout#setupWithViewPager()

The following examples show how to use android.support.design.widget.TabLayout#setupWithViewPager() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InterestingActivity.java    From Interessant with Apache License 2.0 7 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    categoryId = getIntent().getExtras().getInt(MainActivity.CATEGORY_ID);
    related = getIntent().getBooleanExtra(RELATED_VIDEO, false);
    relatedHeader = getIntent().getBooleanExtra(RELATED_HEADER_VIDEO, false);
    String title = getIntent().getStringExtra(MainActivity.TITLE);

    if (title == null) {
        ab.setTitle("Interesting");
    } else {
        if (relatedHeader) {
            ab.setTitle(title);
        } else {
            ab.setTitle(title.substring(1));
        }
    }

    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
    setupViewPager(viewPager);

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

}
 
Example 2
Source File: MainActivity.java    From AndroidSkinAnimator with MIT License 6 votes vote down vote up
private void configFragments() {
    List<Fragment> list = new ArrayList<>();
    list.add(new FirstFragment());
    list.add(new MiddleFragment());
    list.add(new LastFragment());
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
    ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
    viewPager.setAdapter(new TabFragmentPagerAdapter(getSupportFragmentManager(), list));
    List<String> listTitle = new ArrayList<>();
    listTitle.add("系统组件");
    listTitle.add("自定义View");
    listTitle.add("第三方库控件");
    mTabFragmentPagerAdapter = new TabFragmentPagerAdapter(getSupportFragmentManager(), list, listTitle);
    viewPager.setAdapter(mTabFragmentPagerAdapter);
    tabLayout.setupWithViewPager(viewPager);
}
 
Example 3
Source File: MainActivity.java    From Android-skin-support with MIT License 6 votes vote down vote up
private void configFragments() {
    List<Fragment> list = new ArrayList<>();
    list.add(new FirstFragment());
    list.add(new SFragment());
    list.add(new TFragment());
    list.add(new LastFragment());
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
    ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
    viewPager.setAdapter(new TabFragmentPagerAdapter(getSupportFragmentManager(), list));
    List<String> listTitle = new ArrayList<>();
    listTitle.add("系统组件");
    listTitle.add("自定义View");
    listTitle.add("List");
    listTitle.add("第三方库控件");
    mTabFragmentPagerAdapter = new TabFragmentPagerAdapter(getSupportFragmentManager(), list, listTitle);
    viewPager.setAdapter(mTabFragmentPagerAdapter);
    tabLayout.setupWithViewPager(viewPager);
}
 
Example 4
Source File: NotificationsActivity.java    From Android-Carbon-Forum with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_notifications);

    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);

    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(mViewPager);
    ImageButton imageButton = (ImageButton) toolbar.findViewById(R.id.notifications_settings_button);
    imageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(NotificationsActivity.this, SettingsActivity.class);
            intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, SettingsActivity.NotificationPreferenceFragment.class.getName());
            intent.putExtra(PreferenceActivity.EXTRA_NO_HEADERS, true);
            startActivity(intent);
        }
    });
}
 
Example 5
Source File: Fragment_order.java    From FoodOrdering with Apache License 2.0 5 votes vote down vote up
private void initView(View view) {
    orderFragment_title = (TabLayout)view.findViewById(R.id.tab_orderFragment_title);
    vp_orderFragment_pager = (ViewPager)view.findViewById(R.id.vp_orderFragment_pager);

    //初始化各fragment
    order_all_fragment = new Fragment_Order_All();
    order_waitComment_fragment = new Fragment_Order_WaitComment();

    //将fragment装进列表中
    list_fragment = new ArrayList<>();
    list_fragment.add(order_all_fragment);
    list_fragment.add(order_waitComment_fragment);

    //将名称加载tab名字列表
    list_title = new ArrayList<>();
    list_title.add("全部订单");
    list_title.add("待评价");

    //设置TabLayout的模式
    orderFragment_title.setTabMode(TabLayout.MODE_FIXED);
    //为TabLayout添加tab名称
    orderFragment_title.addTab(orderFragment_title.newTab().setText(list_title.get(0)));
    orderFragment_title.addTab(orderFragment_title.newTab().setText(list_title.get(1)));

    fAdapter = new Adapter_tab_Order(getChildFragmentManager(),list_fragment,list_title);

    //viewpager加载adapter
    vp_orderFragment_pager.setAdapter(fAdapter);
    //默认选中
    orderFragment_title.getTabAt(0).select();
    //和ViewPager联动起来
    orderFragment_title.setupWithViewPager(vp_orderFragment_pager);
    if (Activity_Main.networkState == 0) {
        Toast.makeText(getActivity(), "网络连接失败,请检查网络连接设置!", Toast.LENGTH_SHORT).show();
    }
}
 
Example 6
Source File: MainActivity.java    From EmojiReactionView with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    setupViewPager((ViewPager) findViewById(R.id.viewpager));

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

    setupTabIcons();
}
 
Example 7
Source File: MainActivity.java    From CellularSignal with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mHandler = new Handler();
    radioInfo = new RadioInfo(this);

    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);

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

    /*FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });*/


}
 
Example 8
Source File: ContactDetailActivity.java    From Rumble with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_contact_detail);

    Bundle args = getIntent().getExtras();
    String contactName = args.getString("ContactName");
    String contactUID  = args.getString("ContactID");

    /* set the toolbar */
    CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
    collapsingToolbar.setTitle(contactName);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setTitle(contactName);

    /* set the background header */
    ImageView header = (ImageView) findViewById(R.id.header_background);
    ColorGenerator generator = ColorGenerator.DEFAULT;
    header.setBackgroundDrawable(
            builder.build(contactName.substring(0, 1),
            generator.getColor(contactUID)));

    /* setting up the view pager and the tablayout */
    TabLayout tabLayout = (TabLayout) findViewById(R.id.contact_tab_layout);
    ViewPager viewPager = (ViewPager) findViewById(R.id.contact_viewpager);
    ContactDetailPagerAdapter pagerAdapter = new ContactDetailPagerAdapter(getSupportFragmentManager(), args);
    viewPager.setAdapter(pagerAdapter);
    tabLayout.setupWithViewPager(viewPager);
    tabLayout.setSelectedTabIndicatorHeight(10);
}
 
Example 9
Source File: GroupDetailActivity.java    From Rumble with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Bundle args = getIntent().getExtras();
    groupName = args.getString("GroupName");
    groupID = args.getString("GroupID");

    group = DatabaseFactory.getGroupDatabase(this).getGroup(groupID);

    setContentView(R.layout.activity_group_detail);
    setTitle(groupName);

    /* setting up the toolbar */
    Toolbar toolbar = (Toolbar) findViewById(R.id.group_toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);

    /* setting up the view pager and the tablayout */
    TabLayout tabLayout = (TabLayout) findViewById(R.id.group_tab_layout);
    ViewPager viewPager = (ViewPager) findViewById(R.id.group_viewpager);
    GroupDetailPagerAdapter pagerAdapter = new GroupDetailPagerAdapter(getSupportFragmentManager(), args);
    viewPager.setAdapter(pagerAdapter);
    tabLayout.setupWithViewPager(viewPager);
    tabLayout.setSelectedTabIndicatorHeight(10);
}
 
Example 10
Source File: MainActivity.java    From SimpleWeibo with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.inject(this);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    final ActionBar ab = getSupportActionBar();
    ab.setHomeAsUpIndicator(R.drawable.ic_menu);
    ab.setDisplayHomeAsUpEnabled(true);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    if (navigationView != null) {
        setupDrawerContent(navigationView);
    }

    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
    if (viewPager != null) {
        setupViewPager(viewPager);
    }

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Here's a Snackbar", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

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

    mWeibo = SimpleWeibo.create(this);
    mWeibo.logIn().subscribe();
}
 
Example 11
Source File: MainActivity.java    From android-design-library with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // Adding Toolbar to Main screen
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    // Setting ViewPager for each Tabs
    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
    setupViewPager(viewPager);
    // Set Tabs inside Toolbar
    TabLayout tabs = (TabLayout) findViewById(R.id.tabs);
    tabs.setupWithViewPager(viewPager);
}
 
Example 12
Source File: DownloadsActivity.java    From KernelAdiutor with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_downloads);

    initToolBar();

    SupportedDownloads.KernelContent content = new SupportedDownloads.KernelContent(getIntent().getStringExtra(JSON_INTENT));
    getSupportActionBar().setTitle(Utils.htmlFrom(content.getName()).toString());

    final ViewPager viewPager = findViewById(R.id.viewpager);

    LinkedHashMap<String, Fragment> items = new LinkedHashMap<>();

    List<SupportedDownloads.KernelContent.Feature> features = content.getFeatures();
    List<SupportedDownloads.KernelContent.Download> downloads = content.getDownloads();

    if (content.getShortDescription() != null && content.getLongDescription() != null) {
        items.put(getString(R.string.about), AboutFragment.newInstance(content));
    }

    if (features.size() > 0) {
        items.put(getString(R.string.features), FeaturesFragment.newInstance(features));
    }

    if (downloads.size() > 0) {
        items.put(getString(R.string.downloads), DownloadKernelFragment.newInstance(downloads));
    }

    viewPager.setOffscreenPageLimit(items.size());
    PagerAdapter pagerAdapter = new PagerAdapter(getSupportFragmentManager(), items);
    viewPager.setAdapter(pagerAdapter);

    TabLayout tabLayout = findViewById(R.id.tablayout);
    tabLayout.setupWithViewPager(viewPager);

    viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
}
 
Example 13
Source File: DemoActivity.java    From ExpandableTextView with Apache License 2.0 4 votes vote down vote up
private void setupTabLayout(TabLayout tabLayout) {
    tabLayout.setTabMode(TabLayout.MODE_FIXED);
    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
    tabLayout.setupWithViewPager(mViewPager);
}
 
Example 14
Source File: NewsActivity.java    From yahnac with Apache License 2.0 4 votes vote down vote up
private void setupTabs() {
    final TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
    tabLayout.setupWithViewPager(headersPager);
    tabLayout.setOnTabSelectedListener(new StoryTabSelectedListener());
}
 
Example 15
Source File: MainActivity.java    From oversec with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    mInstance = this;

    mTabs = new ArrayList<>();
    mTabs.add(TAB_HELP);
    if (Util.isOversec(this)) {
        mTabs.add(TAB_APPS);
    }
    if (Util.isFeatureEnctypeSYM(this)) {
        mTabs.add(TAB_KEYS);
    }
    mTabs.add(TAB_SETTINGS);
    mTabs.add(TAB_PADDER);

    super.onCreate(savedInstanceState);

    if (IabUtil.isGooglePlayInstalled(this)) {
        // Monitor launch times and interval from installation
        RateThisApp.onCreate(this);
        if (OpenKeychainConnector.Companion.getInstance(this).isGooglePlayInstalled()) {
            RateThisApp.showRateDialogIfNeeded(this);
        }
    }
    setContentView(R.layout.activity_main);

    mHelpFragment = new HelpFragment();
    if (Util.isOversec(this)) {
        mAppsFragment = new AppsFragment();
    }

    if (Util.isFeatureEnctypeSYM(this)) {
        mKeysFragment = new KeysFragment();
    }
    mSettingsFragment = new MainSettingsFragment();
    Bundle args = new Bundle();
    args.putBoolean(MainSettingsFragment.EXTRA_MAIN, true);
    mSettingsFragment.setArguments(args);

    mPadderFragment = new PadderFragment();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    mTabLayout = (TabLayout) findViewById(R.id.tabs);


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

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

    checkIntent(getIntent());


}
 
Example 16
Source File: CompanionWatchFaceConfigActivity.java    From FORMWatchFace with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
    setContentView(R.layout.config_activity);

    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    // Set up general chrome
    ImageButton doneButton = (ImageButton) findViewById(R.id.done_button);
    doneButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });

    ScrimInsetsFrameLayout scrimInsetsFrameLayout = (ScrimInsetsFrameLayout)
            findViewById(R.id.scrim_insets_frame_layout);
    scrimInsetsFrameLayout.setOnInsetsCallback(new ScrimInsetsFrameLayout.OnInsetsCallback() {
        @Override
        public void onInsetsChanged(Rect insets) {
            findViewById(R.id.chrome_container).setPadding(0, insets.top, 0, 0);
        }
    });

    // Set up theme list
    mMainClockContainerView = (ViewGroup) ((ViewGroup) findViewById(R.id.clock_container)).getChildAt(0);
    mMainClockView = (FormClockView) mMainClockContainerView.findViewById(R.id.clock);

    mAnimateClockContainerView = (ViewGroup) ((ViewGroup) findViewById(R.id.clock_container)).getChildAt(1);
    mAnimateClockView = (FormClockView) mAnimateClockContainerView.findViewById(R.id.clock);

    mAnimateClockContainerView.setVisibility(View.INVISIBLE);

    setupThemeList();
    String themeId = mSharedPreferences.getString(ConfigHelper.KEY_THEME, Themes.DEFAULT_THEME.id);
    updateUIToSelectedTheme(themeId, false);

    registerSharedPrefsListener();

    // Set up complications config fragment
    mConfigComplicationsFragment = (ConfigComplicationsFragment) getFragmentManager()
            .findFragmentById(R.id.config_complications_container);
    if (mConfigComplicationsFragment == null) {
        mConfigComplicationsFragment = new ConfigComplicationsFragment();
        getFragmentManager()
                .beginTransaction()
                .add(R.id.config_complications_container, mConfigComplicationsFragment)
                .commit();
    }

    // Set up tabs/pager
    final ViewPager pager = (ViewPager) findViewById(R.id.view_pager);
    pager.setPageMargin((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16,
            getResources().getDisplayMetrics()));

    SimplePagerHelper helper = new SimplePagerHelper(this, pager);
    helper.addPage(R.string.title_theme, R.id.config_theme_container);
    helper.addPage(R.string.title_complications, R.id.config_complications_container);

    TabLayout slidingTabLayout = (TabLayout) findViewById(R.id.tabs);
    slidingTabLayout.setupWithViewPager(pager);

    pager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            super.onPageScrolled(position, positionOffset, positionOffsetPixels);
            float translationX = -pager.getWidth();
            if (position == 0) {
                translationX = -positionOffsetPixels;
            }
            mMainClockView.setTranslationX(translationX);
            mAnimateClockView.setTranslationX(translationX);
        }
    });
}
 
Example 17
Source File: HomeActivity.java    From Rumble with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_home);
    mTitle = getTitle();

    /* sliding menu with both right and left drawer */
    slidingMenu = new SlidingMenu(this);
    slidingMenu.setShadowWidthRes(R.dimen.shadow_width);
    slidingMenu.setShadowDrawable(R.drawable.shadow);
    slidingMenu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
    slidingMenu.setFadeDegree(0.35f);
    slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    slidingMenu.setMode(SlidingMenu.LEFT_RIGHT);
    slidingMenu.setMenu(R.layout.slidingmenu_navigation_drawer);
    slidingMenu.setSecondaryMenu(R.layout.slidingmenu_network_drawer);
    slidingMenu.setSecondaryShadowDrawable(R.drawable.shadowright);
    if (savedInstanceState == null) {
        mNavigationDrawerFragment = new FragmentNavigationDrawer();
        mNetworkDrawerFragment    = new FragmentNetworkDrawer();
        this.getSupportFragmentManager().beginTransaction()
                .replace(R.id.navigation_drawer_frame, mNavigationDrawerFragment).commit();
        this.getSupportFragmentManager().beginTransaction()
                .replace(R.id.network_drawer_frame, mNetworkDrawerFragment).commit();
    } else {
        mNavigationDrawerFragment = (FragmentNavigationDrawer) this.getSupportFragmentManager().findFragmentById(R.id.navigation_drawer_frame);
        mNetworkDrawerFragment = (FragmentNetworkDrawer) this.getSupportFragmentManager().findFragmentById(R.id.network_drawer_frame);
    }
    slidingMenu.attachToActivity(this, SlidingMenu.SLIDING_WINDOW);

    /*
     * the tablayout for status and chat message with a viewpager.
     * note that we cannot swipe views with the viewpager as the swipe
     * gesture is catched by slidingmenu to slide the panel
     */
    TabLayout tabLayout = (TabLayout) findViewById(R.id.home_tab_layout);
    viewPager = (ViewPager) findViewById(R.id.home_viewpager);
    pagerAdapter = new HomePagerAdapter(getSupportFragmentManager());
    viewPager.setAdapter(pagerAdapter);
    viewPager.addOnPageChangeListener(onPageChangeListener);
    tabLayout.setupWithViewPager(viewPager);

    // little hack to set the icons instead of text
    notifStatus = renderTabView(this, R.drawable.ic_world,  (ViewGroup)tabLayout.getParent());
    notifChat   = renderTabView(this, R.drawable.ic_forum_white_24dp, (ViewGroup)tabLayout.getParent());
    tabLayout.getTabAt(0).setCustomView(notifStatus);
    tabLayout.getTabAt(1).setCustomView(notifChat);
    tabLayout.setSelectedTabIndicatorHeight(10);

    // for notification
    refreshStatusNotifications();
    refreshChatNotifications();
    EventBus.getDefault().register(this);
}
 
Example 18
Source File: FrameActivity.java    From UMS-Interface with GNU General Public License v3.0 4 votes vote down vote up
@Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
//        setSupportActionBar(toolbar);
        Log.d("UMS_DEBUG","[ INIT]onCreate instance="+this.hashCode() );

        Locale locale = getResources().getConfiguration().locale;
        sLang = locale.getLanguage();
        PermissionUnit.getPermission(new String[]{"android.permission.INTERNET","com.android.launcher.permission.INSTALL_SHORTCUT"},this);
        //app may be cached, LogUnit and ShellUnit may be closed ,restart them.
        sLog.restart();
        ShellUnit.restart();

        initShell();
        if(sMassStorage == null) {
            if(ShellUnit.execRoot("getprop sys.usb.configfs").trim().startsWith("1")) {
                sMassStorage = new MassStorageConfigfs();
            }else{
                sMassStorage = new MassStorageSysfs();
            }
        }
        mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        checkVersion();

        mUmsFragment=new UmsFragment();
        mUmsFragment.init(this);
        mMountFragment= new MountFragment();
        mMountFragment.init(this);
        mInfoFragment= new InfoFragment();
        mInfoFragment.init(this);
        mCreateImageFragment = new CreateImageFragment();
        mCreateImageFragment.init(this);
        mHelpFragment = new HelpFragment();
        mHelpFragment.init(this);
        mQuickStartFragment = new QuickStartFragment();
        mQuickStartFragment.init(this);
        mFragments = new Fragment[] {mQuickStartFragment,mUmsFragment,mMountFragment,mInfoFragment,mCreateImageFragment,mHelpFragment};
        setContentView(R.layout.activity_main);

        //Toolbar _toolbar = new Toolbar(this);
        //setSupportActionBar(_toolbar);
        final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //FrameActivity.this.openOptionsMenu();
                PopupMenu popup = new PopupMenu(FrameActivity.this, fab);
                MenuInflater inflater = popup.getMenuInflater();
                inflater.inflate(R.menu.main, popup.getMenu());
                popup.setOnMenuItemClickListener(FrameActivity.this);
                popup.show();
            }
        });
        String[] _titles = getResources().getStringArray(R.array.tab_titles);
        mViewPager = (ViewPager) findViewById(R.id.main_viewpager);
        UmsPagerAdapter pagerAdapter = new UmsPagerAdapter(getSupportFragmentManager(),mFragments,_titles);
        mViewPager.setAdapter(pagerAdapter);
        TabLayout _tabLayout = (TabLayout) findViewById(R.id.main_tab_layout);
        _tabLayout.setupWithViewPager(mViewPager);
    }
 
Example 19
Source File: CurrencyListTabsActivity.java    From CryptoBuddy with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_currency_list_tabs);
    context = this;
    mToolbar = findViewById(R.id.toolbar_currency_list);
    setSupportActionBar(mToolbar);
    TabLayout tabLayout = findViewById(R.id.currency_list_tabs);
    mViewPager = findViewById(R.id.currency_list_tabs_container);
    libsBuilder = new LibsBuilder()
            //provide a style (optional) (LIGHT, DARK, LIGHT_DARK_TOOLBAR)
            .withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR)
            .withAboutIconShown(true)
            .withLicenseShown(true)
            .withVersionShown(true)
            .withAboutVersionShownName(true)
            .withAboutVersionShownCode(true)
            .withAboutVersionString("Version: " + BuildConfig.VERSION_NAME)
            .withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR)
            .withActivityTitle("CryptoBuddy")
            .withLibraries("easyrest", "materialabout", "androiddevicenames", "customtabs", "togglebuttongroup", "materialfavoritebutton");

    TextDrawable t = new TextDrawable(this);
    t.setText("ART");
    t.setTextAlign(Layout.Alignment.ALIGN_CENTER);
    t.setTextColor(Color.BLACK);
    t.setTextSize(10);
    AccountHeader headerResult = new AccountHeaderBuilder()
            .withActivity(this)
            .withHeaderBackground(t).build();
    drawer = new DrawerBuilder()
            .withActivity(this)
            .withToolbar(mToolbar)
            .withSelectedItem(1)
            .withAccountHeader(headerResult)
            .addDrawerItems(
                new PrimaryDrawerItem().withIdentifier(1).withName(R.string.Home).withIcon(FontAwesome.Icon.faw_home),
                new PrimaryDrawerItem().withIdentifier(2).withName(R.string.News).withIcon(FontAwesome.Icon.faw_newspaper),
                new PrimaryDrawerItem().withIdentifier(3).withName("About").withIcon(FontAwesome.Icon.faw_question_circle),
                new PrimaryDrawerItem().withIdentifier(4).withName("Open Source").withIcon(FontAwesome.Icon.faw_github_square),
                new PrimaryDrawerItem().withIdentifier(5).withName("Rate on Google Play").withIcon(FontAwesome.Icon.faw_thumbs_up)
            )
            .withTranslucentStatusBar(false)
            .build();
    drawer.setOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
        @Override
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
            switch (position) {
                case 1:
                    drawer.closeDrawer();
                    return true;
                case 2:
                    drawer.closeDrawer();
                    drawer.setSelection(1);
                    startActivity(new Intent(context, NewsListActivity.class));
                    return true;
                case 3:
                    drawer.closeDrawer();
                    drawer.setSelection(1);
                    startActivity(new Intent(context, AboutTheDevActivity.class));
                    return true;
                case 4:
                    drawer.closeDrawer();
                    drawer.setSelection(1);
                    libsBuilder.start(context);
                default:
                    return true;
            }
        }
    });

    mSectionsPagerAdapter = new SectionsPagerAdapterCurrencyList(getSupportFragmentManager());
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setOffscreenPageLimit(2);
    mViewPager.addOnPageChangeListener(this);
    tabLayout.setupWithViewPager(mViewPager);
    tabLayout.setSelectedTabIndicatorColor(Color.WHITE);
}
 
Example 20
Source File: MainActivity.java    From android-periodic-table with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main_activity);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

    setSupportActionBar(toolbar);

    getSupportActionBar().setDisplayHomeAsUpEnabled(false);

    ViewPagerAdapter pagerAdapter = new ViewPagerAdapter(this);
    pagerAdapter.addPage(R.string.fragment_title_elements, ElementsFragment.class, null);
    pagerAdapter.addPage(R.string.fragment_title_table, TableFragment.class, null);

    ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setAdapter(pagerAdapter);

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