Skip to content

Commit

Permalink
Example app controls
Browse files Browse the repository at this point in the history
- Add vertical view pager
- Add controls fragment
- Separate parent and children gridlayout from controls
- Clean up continuous weighted weights
  • Loading branch information
bret-fears committed Apr 3, 2017
1 parent 5798999 commit 7fc8804
Show file tree
Hide file tree
Showing 14 changed files with 917 additions and 602 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,54 @@
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

import com.willowtreeapps.spurceexampleapp.fragments.ControlsFragment;
import com.willowtreeapps.spurceexampleapp.fragments.ViewFragment;
import com.willowtreeapps.spurceexampleapp.pager.VerticalViewPager;

public class SpruceActivity extends AppCompatActivity {
import java.util.ArrayList;
import java.util.List;

public class SpruceActivity extends AppCompatActivity
implements ViewFragment.OnParentAndChildCreationListener {

public ViewGroup parent;
public List<View> children = new ArrayList<>();
public Spinner sortDropDown;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_fragment);
setContentView(R.layout.fragment_pager);

FragmentManager fm = getSupportFragmentManager();
Fragment viewFragment = fm.findFragmentById(R.id.view_fragment);

if (viewFragment == null) {
viewFragment = ViewFragment.newInstance();
fm.beginTransaction()
.add(R.id.view_fragment, viewFragment)
.commit();
}
VerticalViewPager verticalPager = (VerticalViewPager) findViewById(R.id.vertical_pager);
VerticalPagerAdapter adapter = new VerticalPagerAdapter(fm);
verticalPager.setAdapter(adapter);

Toolbar toolBar = (Toolbar) findViewById(R.id.tool_bar);
setSupportActionBar(toolBar);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayShowTitleEnabled(false);
}

sortDropDown = (Spinner) findViewById(R.id.sort_selection);
ArrayAdapter<CharSequence> spinnerAdapter = ArrayAdapter.createFromResource(this,
R.array.sort_functions,
R.layout.spinner_item);
spinnerAdapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
sortDropDown.setAdapter(spinnerAdapter);
}

@Override
Expand All @@ -77,4 +95,33 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
return super.onOptionsItemSelected(item);
}

@Override
public void onParentAndChildrenPrepared(ViewGroup parent, List<View> children) {
this.parent = parent;
this.children = children;
}

private class VerticalPagerAdapter extends FragmentStatePagerAdapter {

VerticalPagerAdapter(FragmentManager fm) {
super(fm);
}

@Override
public Fragment getItem(int position) {
switch (position) {
case 1:
return ControlsFragment.newInstance();
default:
return ViewFragment.newInstance();
}
}

@Override
public int getCount() {
return 2;
}

}
}
Loading

0 comments on commit 7fc8804

Please sign in to comment.