/* * ****************************************************************************** * Copyright (c) 2013-2014 Gabriele Mariotti. * * 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 it.gmariotti.cardslib.demo.extras.fragment; import android.app.ActionBar; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import com.nhaarman.listviewanimations.appearance.AnimationAdapter; import com.nhaarman.listviewanimations.appearance.simple.AlphaInAnimationAdapter; import com.nhaarman.listviewanimations.appearance.simple.ScaleInAnimationAdapter; import com.nhaarman.listviewanimations.appearance.simple.SwingBottomInAnimationAdapter; import com.nhaarman.listviewanimations.appearance.simple.SwingLeftInAnimationAdapter; import com.nhaarman.listviewanimations.appearance.simple.SwingRightInAnimationAdapter; import java.util.ArrayList; import it.gmariotti.cardslib.demo.extras.R; import it.gmariotti.cardslib.demo.extras.cards.ColorCard; import it.gmariotti.cardslib.library.internal.Card; import it.gmariotti.cardslib.library.internal.CardArrayAdapter; import it.gmariotti.cardslib.library.view.CardListView; /** * This example uses a list of cards animated with ListViewAnimations. * Please refer to https://github.com/nhaarman/ListViewAnimations for full doc * * @author Gabriele Mariotti (gabri.mariotti@gmail.com) */ public class ListViewAnimationsFragment extends BaseFragment implements ActionBar.OnNavigationListener { private CardListView mListView; private CardArrayAdapter mCardArrayAdapter; @Override public int getTitleResourceId() { return R.string.carddemo_extras_title_listviewanimations; } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.demo_extras_fragment_listviewanimations, container, false); } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); initCard(); } @Override public void onResume() { super.onResume(); populateNavigationList(); } @Override public void onPause() { super.onPause(); getActivity().getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); } /** * Populate the downDownValues to select the different animations */ private void populateNavigationList() { getActivity().getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); final String[] dropdownValues = {"Alpha", "Left", "Right", "Bottom", "Bottom right", "Scale"}; ActionBar actionBar = getActivity().getActionBar(); // Specify a SpinnerAdapter to populate the dropdown list. ArrayAdapter<String> adapter = new ArrayAdapter<String>(actionBar.getThemedContext(), android.R.layout.simple_spinner_item, android.R.id.text1, dropdownValues); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Set up the dropdown list navigation in the action bar. actionBar.setListNavigationCallbacks(adapter, this); } /** * This method builds a simple list of cards */ private void initCard() { //Init an array of Cards ArrayList<Card> cards = new ArrayList<Card>(); for (int i = 0; i < 25; i++) { ColorCard card = new ColorCard(this.getActivity()); //Only for test scope, use different titles and colors card.setTitle("A simple colored card " + i); card.setCount(i); switch (i % 5) { case 0: card.setBackgroundResourceId(R.drawable.demoextra_card_selector_color1); break; case 1: card.setBackgroundResourceId(R.drawable.demoextra_card_selector_color2); break; case 2: card.setBackgroundResourceId(R.drawable.demoextra_card_selector_color3); break; case 3: card.setBackgroundResourceId(R.drawable.demoextra_card_selector_color4); break; case 4: card.setBackgroundResourceId(R.drawable.demoextra_card_selector_color5); break; } cards.add(card); } //Set the adapter mCardArrayAdapter = new CardArrayAdapter(getActivity(), cards); mListView = (CardListView) getActivity().findViewById(R.id.carddemo_extra_list_viewanimations); if (mListView != null) { setAlphaAdapter(); } } /** * Alpha animation */ private void setAlphaAdapter() { AnimationAdapter animCardArrayAdapter = new AlphaInAnimationAdapter(mCardArrayAdapter); animCardArrayAdapter.setAbsListView(mListView); if (mListView != null) { mListView.setExternalAdapter(animCardArrayAdapter,mCardArrayAdapter); } } /** * Left animation */ private void setLeftAdapter() { AnimationAdapter animCardArrayAdapter = new SwingLeftInAnimationAdapter(mCardArrayAdapter); animCardArrayAdapter.setAbsListView(mListView); if (mListView != null) { mListView.setExternalAdapter(animCardArrayAdapter,mCardArrayAdapter); } } /** * Right animation */ private void setRightAdapter() { AnimationAdapter animCardArrayAdapter = new SwingRightInAnimationAdapter(mCardArrayAdapter); animCardArrayAdapter.setAbsListView(mListView); if (mListView != null) { mListView.setExternalAdapter(animCardArrayAdapter,mCardArrayAdapter); } } /** * Bottom animation */ private void setBottomAdapter() { AnimationAdapter animCardArrayAdapter = new SwingBottomInAnimationAdapter(mCardArrayAdapter); animCardArrayAdapter.setAbsListView(mListView); mListView.setExternalAdapter(animCardArrayAdapter,mCardArrayAdapter); } /** * Bottom-right animation */ private void setBottomRightAdapter() { AnimationAdapter animCardArrayAdapter = new SwingBottomInAnimationAdapter(new SwingRightInAnimationAdapter(mCardArrayAdapter)); animCardArrayAdapter.setAbsListView(mListView); if (mListView != null) { mListView.setExternalAdapter(animCardArrayAdapter,mCardArrayAdapter); } } /** * Scale animation */ private void setScaleAdapter() { AnimationAdapter animCardArrayAdapter = new ScaleInAnimationAdapter(mCardArrayAdapter); animCardArrayAdapter.setAbsListView(mListView); if (mListView != null) { mListView.setExternalAdapter(animCardArrayAdapter,mCardArrayAdapter); } } @Override public boolean onNavigationItemSelected(int itemPosition, long itemId) { switch (itemPosition) { case 0: setAlphaAdapter(); return true; case 1: setLeftAdapter(); return true; case 2: setRightAdapter(); return true; case 3: setBottomAdapter(); return true; case 4: setBottomRightAdapter(); return true; case 5: setScaleAdapter(); return true; default: return false; } } }