/*
 * Copyright 2015 Michael Bel
 *
 * 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 org.app.application;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.widget.FrameLayout;
import android.widget.Toast;

import org.app.application.fragments.BottomsFragment;
import org.app.application.fragments.CardFragment;
import org.app.application.fragments.DialogsFragment;
import org.app.application.fragments.FabFragment;
import org.app.application.fragments.ListViewFragment;
import org.app.application.fragments.PatternViewFragment;
import org.app.material.AndroidUtilities;
import org.app.material.widget.ActionBar;
import org.app.material.widget.ActionBarMenu;
import org.app.material.widget.ActionBarMenuItem;
import org.app.material.widget.Browser;
import org.app.material.widget.FragmentSet;
import org.app.material.widget.FragmentsPagerAdapter;

public class LaunchActivity extends FragmentActivity {

    private TabLayout.Tab tab;
    private TabLayout tabLayout;
    private ActionBar actionBar;

    private static final int github = 1;
    private static final int settings = 2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        AndroidUtilities.bind(this);

        FrameLayout layout = (FrameLayout) findViewById(R.id.frameLayout);
        layout.setBackgroundColor(0xFFF0F0F0);

        actionBar = new ActionBar(this)
                .setBackGroundColor(AndroidUtilities.getContextColor(R.attr.colorPrimary))
                .setBackButtonImage(R.drawable.ic_menu)
                .setTitle(R.string.MaterialDemo)
                .setOccupyStatusBar(false)
                .setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
                    @Override
                    public void onItemClick(int id) {
                        if (id == -1) {
                            Toast.makeText(LaunchActivity.this, "Not Implemented", Toast.LENGTH_SHORT).show();
                        } else if (id == github) {
                            Browser.openUrl(LaunchActivity.this, getString(R.string.GithubURL));
                        } else if (id == settings) {
                            Toast.makeText(LaunchActivity.this, "Not Implemented", Toast.LENGTH_SHORT).show();
                            //startActivity(new Intent(LaunchActivity.this, MainActivity.class));
                        }
                    }
                });

        ActionBarMenu menu = actionBar.createMenu();
        menu.addItem(github, R.drawable.ic_github);

        ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_dots_menu);
        item.addSubItem(settings, R.string.Settings, 0);

        layout.addView(actionBar);

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

        FrameLayout.LayoutParams viewPagerParams = (FrameLayout.LayoutParams) viewPager.getLayoutParams();
        viewPagerParams.setMargins(0, AndroidUtilities.isLandscape() ? AndroidUtilities.dp(96) : AndroidUtilities.dp(104), 0, 0);
        viewPager.setLayoutParams(viewPagerParams);

        FragmentsPagerAdapter adapter = new FragmentsPagerAdapter(this, getSupportFragmentManager());
        adapter.addFragments(
            new FragmentSet(new DialogsFragment(), R.string.Dialogs),
            new FragmentSet(new BottomsFragment(), R.string.Bottoms),
            //new FragmentSet(new Recycler(), R.string.Pattern),
            new FragmentSet(new ListViewFragment(), R.string.ListView),
            new FragmentSet(new CardFragment(), R.string.CardView),
            new FragmentSet(new FabFragment(), R.string.Fabs),
            //new FragmentSet(new RecyclerFragment(), R.string.RecyclerView),
            new FragmentSet(new PatternViewFragment(), R.string.Pattern)
        );

        viewPager.setAdapter(adapter);

        tabLayout = (TabLayout) findViewById(R.id.tabs);
        tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
        tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
        tabLayout.setBackgroundColor(AndroidUtilities.getContextColor(this, R.attr.colorPrimary));
        tabLayout.setupWithViewPager(viewPager);

        FrameLayout.LayoutParams tabLayoutParams = (FrameLayout.LayoutParams) tabLayout.getLayoutParams();
        tabLayoutParams.setMargins(0, ActionBar.getCurrentActionBarHeight(), 0, 0);
        tabLayout.setLayoutParams(tabLayoutParams);
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
    }
}
@@ -618,16 +618,47 @@
 ation;%0A%0A
+import android.content.Intent;%0A
 import a
@@ -675,16 +675,16 @@
 Bundle;%0A
-
 import a
@@ -1579,106 +1579,8 @@
  %7B%0A%0A
-    private TabLayout.Tab tab;%0A    private TabLayout tabLayout;%0A    private ActionBar actionBar;%0A%0A
     
@@ -1658,16 +1658,57 @@
 ngs = 2;
+%0A    private static final int adding = 3;
 %0A%0A    @O
@@ -2025,16 +2025,26 @@
         
+ActionBar 
 actionBa
@@ -2575,32 +2575,39 @@
 Activity.this, %22
+Drawer 
 Not Implemented%22
@@ -2869,186 +2869,246 @@
     
-Toast.makeText(LaunchActivity.this, %22Not Implemented%22, Toast.LENGTH_SHORT).show();%0A                            //startActivity(new Intent(LaunchActivity.this, MainActivity.class)
+startActivity(new Intent(LaunchActivity.this, SettingsActivity.class));%0A                        %7D else if (id == adding) %7B%0A                            Toast.makeText(LaunchActivity.this, %22Adding Not Implemented%22, Toast.LENGTH_SHORT).show(
 );%0A 
@@ -4089,73 +4089,8 @@
 s),%0A
-            //new FragmentSet(new Recycler(), R.string.Pattern),%0A
     
@@ -4292,86 +4292,8 @@
 s),%0A
-            //new FragmentSet(new RecyclerFragment(), R.string.RecyclerView),%0A
     
@@ -4413,32 +4413,42 @@
 pter);%0A%0A        
+TabLayout 
 tabLayout = (Tab
@@ -4689,24 +4689,24 @@
 rPrimary));%0A
-
         tabL
@@ -4737,24 +4737,481 @@
 (viewPager);
+%0A        tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() %7B%0A            @Override%0A            public void onTabSelected(TabLayout.Tab tab) %7B%0A                /*if (tab.getPosition() == 4) %7B%0A%0A                %7D*/%0A            %7D%0A%0A            @Override%0A            public void onTabUnselected(TabLayout.Tab tab) %7B%0A%0A            %7D%0A%0A            @Override%0A            public void onTabReselected(TabLayout.Tab tab) %7B%0A%0A            %7D%0A        %7D);
 %0A%0A        Fr

Update main demo activity class