Skip to content
Browse files

Merge branch 'SoftXperience-master'

  • Loading branch information...
2 parents 19ceb58 + 889f5a8 commit 657440fbee6a0f8634e92a87e29f376a9bc3adf1 @roughike committed
View
35 swipe-selector/src/main/java/com/roughike/swipeselector/SwipeAdapter.java
@@ -281,6 +281,33 @@ protected SwipeItem getSelectedItem() {
return mItems.get(mCurrentPosition);
}
+ public void selectItemAt(int position, boolean animate) {
+ if (position < 0 || position >= mItems.size()) {
+ throw new IndexOutOfBoundsException("This SwipeSelector does " +
+ "not have an item at position " + position + ".");
+ }
+
+ mViewPager.setCurrentItem(position, animate);
+ }
+
+ public void selectItemWithValue(Object value, boolean animate) {
+ boolean itemExists = false;
+
+ for (int i = 0; i < mItems.size(); i++) {
+ if (mItems.get(i).value.equals(value)) {
+ mViewPager.setCurrentItem(i, animate);
+ itemExists = true;
+ break;
+ }
+ }
+
+ if (!itemExists) {
+ throw new IllegalArgumentException("This SwipeSelector " +
+ "does not have an item with the given value "
+ + value.toString() + ".");
+ }
+ }
+
protected Bundle onSaveInstanceState() {
Bundle bundle = new Bundle();
bundle.putInt(STATE_CURRENT_POSITION, mCurrentPosition);
@@ -303,7 +330,13 @@ public Object instantiateItem(ViewGroup container, int position) {
SwipeItem slideItem = mItems.get(position);
title.setText(slideItem.title);
- description.setText(slideItem.description);
+
+ if (slideItem.description == null) {
+ description.setVisibility(View.GONE);
+ } else {
+ description.setVisibility(View.VISIBLE);
+ description.setText(slideItem.description);
+ }
// We shouldn't get here if the typeface didn't exist.
// But just in case, because we're paranoid.
View
66 swipe-selector/src/main/java/com/roughike/swipeselector/SwipeSelector.java
@@ -160,6 +160,72 @@ public SwipeItem getSelectedItem() {
return mAdapter.getSelectedItem();
}
+ /**
+ * Select an item at the specified position and animate the change.
+ *
+ * @param position the position to select.
+ */
+ public void selectItemAt(int position) {
+ selectItemAt(position, true);
+ }
+
+ /**
+ * Select an item at the specified position.
+ *
+ * @param position the position to select.
+ * @param animate should the change be animated or not.
+ */
+ public void selectItemAt(int position, boolean animate) {
+ mAdapter.selectItemAt(position, animate);
+ }
+
+ /**
+ * Select an item that has the specified value. The value was given
+ * to the {@link SwipeItem} when constructing it.
+ *
+ * For example, an item constructed like this:
+ *
+ * {@code
+ * new SwipeItem(1, "Example title", "Example description");
+ * }
+ *
+ * would have the value "1" (without the quote marks). Then you would
+ * select that item by using something like this:
+ *
+ * {@code
+ * swipeSelector.selectItemWithValue(1);
+ * }
+ *
+ * @param value the value of the item to select.
+ */
+ public void selectItemWithValue(Object value) {
+ selectItemWithValue(value, true);
+ }
+
+ /**
+ * Select an item that has the specified value. The value was given
+ * to the {@link SwipeItem} when constructing it.
+ *
+ * For example, an item constructed like this:
+ *
+ * {@code
+ * new SwipeItem(1, "Example title", "Example description");
+ * }
+ *
+ * would have the value "1" (without the quote marks). Then you would
+ * select that item by using something like this:
+ *
+ * {@code
+ * swipeSelector.selectItemWithValue(1, true);
+ * }
+ *
+ * @param value the value of the item to select.
+ * @param animate should the change be animated or not.
+ */
+ public void selectItemWithValue(Object value, boolean animate) {
+ mAdapter.selectItemWithValue(value, animate);
+ }
+
@Override
public Parcelable onSaveInstanceState() {
Bundle bundle = mAdapter.onSaveInstanceState();
View
14 swipe-selector/src/main/res/layout/swipeselector_content_item.xml
@@ -1,16 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
- android:orientation="vertical"
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:gravity="center_horizontal"
- xmlns:android="http://schemas.android.com/apk/res/android">
+ android:gravity="center"
+ android:orientation="vertical">
<TextView
android:id="@+id/swipeselector_content_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:textAppearance="@style/TextAppearance.AppCompat.Body2"/>
+ android:textAppearance="@style/TextAppearance.AppCompat.Body2"
+ tools:text="Title" />
+
<TextView
android:id="@+id/swipeselector_content_description"
@@ -18,6 +21,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="4dp"
- android:textAppearance="@style/TextAppearance.AppCompat.Caption"/>
+ android:textAppearance="@style/TextAppearance.AppCompat.Caption"
+ tools:text="Description" />
</LinearLayout>

0 comments on commit 657440f

Please sign in to comment.
Something went wrong with that request. Please try again.