Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example app controls #80

Merged
merged 8 commits into from
Apr 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Animator spruceAnimator = new Spruce
Definitely play around with the stock `SortFunction` implementations until you find the one that is perfect for you! Check out the example app if you want to get previews of what each `SortFunction` will look like.

### The Animators
The animations used in Spruce are produced by leveraging the `Animtor` class. You may provide your own custom animations by creating your own `Animator` and provide it to the as part of an `Animator[]` to `SpruceBuilder.animateWith(Animator... animators)`. For more information on using the `Animator` class please check out https://developer.android.com/reference/android/animation/Animator.html
The animations used in Spruce are produced by leveraging the `Animator` class. You may provide your own custom animations by creating your own `Animator` and provide it to the as part of an `Animator[]` to `SpruceBuilder.animateWith(Animator... animators)`. For more information on using the `Animator` class please check out https://developer.android.com/reference/android/animation/Animator.html

### Standard Animation
The `DefaultAnimation` class provides simple `Animator` methods to apply the change `Animator` to the views. Use this class if you want to have a stock linear movement of the changes.
Expand Down
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