summaryrefslogtreecommitdiff
path: root/library/main/src/com/android/setupwizardlib/items/AbstractItemHierarchy.java
diff options
context:
space:
mode:
Diffstat (limited to 'library/main/src/com/android/setupwizardlib/items/AbstractItemHierarchy.java')
-rw-r--r--library/main/src/com/android/setupwizardlib/items/AbstractItemHierarchy.java195
1 files changed, 90 insertions, 105 deletions
diff --git a/library/main/src/com/android/setupwizardlib/items/AbstractItemHierarchy.java b/library/main/src/com/android/setupwizardlib/items/AbstractItemHierarchy.java
index 805e7af..e33cc2f 100644
--- a/library/main/src/com/android/setupwizardlib/items/AbstractItemHierarchy.java
+++ b/library/main/src/com/android/setupwizardlib/items/AbstractItemHierarchy.java
@@ -20,138 +20,123 @@ import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.Log;
-
import com.android.setupwizardlib.R;
-
import java.util.ArrayList;
-/**
- * An abstract item hierarchy; provides default implementation for ID and observers.
- */
+/** An abstract item hierarchy; provides default implementation for ID and observers. */
public abstract class AbstractItemHierarchy implements ItemHierarchy {
- /* static section */
+ /* static section */
- private static final String TAG = "AbstractItemHierarchy";
+ private static final String TAG = "AbstractItemHierarchy";
- /* non-static section */
+ /* non-static section */
- private ArrayList<Observer> mObservers = new ArrayList<>();
- private int mId = 0;
+ private final ArrayList<Observer> observers = new ArrayList<>();
+ private int id = 0;
- public AbstractItemHierarchy() {
- }
+ public AbstractItemHierarchy() {}
- public AbstractItemHierarchy(Context context, AttributeSet attrs) {
- TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SuwAbstractItem);
- mId = a.getResourceId(R.styleable.SuwAbstractItem_android_id, 0);
- a.recycle();
- }
+ public AbstractItemHierarchy(Context context, AttributeSet attrs) {
+ TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SuwAbstractItem);
+ id = a.getResourceId(R.styleable.SuwAbstractItem_android_id, 0);
+ a.recycle();
+ }
- public void setId(int id) {
- mId = id;
- }
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public int getViewId() {
+ return getId();
+ }
- public int getId() {
- return mId;
+ @Override
+ public void registerObserver(Observer observer) {
+ observers.add(observer);
+ }
+
+ @Override
+ public void unregisterObserver(Observer observer) {
+ observers.remove(observer);
+ }
+
+ /** @see Observer#onChanged(ItemHierarchy) */
+ public void notifyChanged() {
+ for (Observer observer : observers) {
+ observer.onChanged(this);
}
+ }
- public int getViewId() {
- return getId();
+ /** @see Observer#onItemRangeChanged(ItemHierarchy, int, int) */
+ public void notifyItemRangeChanged(int position, int itemCount) {
+ if (position < 0) {
+ Log.w(TAG, "notifyItemRangeChanged: Invalid position=" + position);
+ return;
+ }
+ if (itemCount < 0) {
+ Log.w(TAG, "notifyItemRangeChanged: Invalid itemCount=" + itemCount);
+ return;
}
- @Override
- public void registerObserver(Observer observer) {
- mObservers.add(observer);
+ for (Observer observer : observers) {
+ observer.onItemRangeChanged(this, position, itemCount);
}
+ }
- @Override
- public void unregisterObserver(Observer observer) {
- mObservers.remove(observer);
+ /** @see Observer#onItemRangeInserted(ItemHierarchy, int, int) */
+ public void notifyItemRangeInserted(int position, int itemCount) {
+ if (position < 0) {
+ Log.w(TAG, "notifyItemRangeInserted: Invalid position=" + position);
+ return;
+ }
+ if (itemCount < 0) {
+ Log.w(TAG, "notifyItemRangeInserted: Invalid itemCount=" + itemCount);
+ return;
}
- /**
- * @see Observer#onChanged(ItemHierarchy)
- */
- public void notifyChanged() {
- for (Observer observer : mObservers) {
- observer.onChanged(this);
- }
+ for (Observer observer : observers) {
+ observer.onItemRangeInserted(this, position, itemCount);
}
+ }
- /**
- * @see Observer#onItemRangeChanged(ItemHierarchy, int, int)
- */
- public void notifyItemRangeChanged(int position, int itemCount) {
- if (position < 0) {
- Log.w(TAG, "notifyItemRangeChanged: Invalid position=" + position);
- return;
- }
- if (itemCount < 0) {
- Log.w(TAG, "notifyItemRangeChanged: Invalid itemCount=" + itemCount);
- return;
- }
-
- for (Observer observer : mObservers) {
- observer.onItemRangeChanged(this, position, itemCount);
- }
+ /** @see Observer#onItemRangeMoved(ItemHierarchy, int, int, int) */
+ public void notifyItemRangeMoved(int fromPosition, int toPosition, int itemCount) {
+ if (fromPosition < 0) {
+ Log.w(TAG, "notifyItemRangeMoved: Invalid fromPosition=" + fromPosition);
+ return;
+ }
+ if (toPosition < 0) {
+ Log.w(TAG, "notifyItemRangeMoved: Invalid toPosition=" + toPosition);
+ return;
+ }
+ if (itemCount < 0) {
+ Log.w(TAG, "notifyItemRangeMoved: Invalid itemCount=" + itemCount);
+ return;
}
- /**
- * @see Observer#onItemRangeInserted(ItemHierarchy, int, int)
- */
- public void notifyItemRangeInserted(int position, int itemCount) {
- if (position < 0) {
- Log.w(TAG, "notifyItemRangeInserted: Invalid position=" + position);
- return;
- }
- if (itemCount < 0) {
- Log.w(TAG, "notifyItemRangeInserted: Invalid itemCount=" + itemCount);
- return;
- }
-
- for (Observer observer : mObservers) {
- observer.onItemRangeInserted(this, position, itemCount);
- }
+ for (Observer observer : observers) {
+ observer.onItemRangeMoved(this, fromPosition, toPosition, itemCount);
}
+ }
- /**
- * @see Observer#onItemRangeMoved(ItemHierarchy, int, int, int)
- */
- public void notifyItemRangeMoved(int fromPosition, int toPosition, int itemCount) {
- if (fromPosition < 0) {
- Log.w(TAG, "notifyItemRangeMoved: Invalid fromPosition=" + fromPosition);
- return;
- }
- if (toPosition < 0) {
- Log.w(TAG, "notifyItemRangeMoved: Invalid toPosition=" + toPosition);
- return;
- }
- if (itemCount < 0) {
- Log.w(TAG, "notifyItemRangeMoved: Invalid itemCount=" + itemCount);
- return;
- }
-
- for (Observer observer : mObservers) {
- observer.onItemRangeMoved(this, fromPosition, toPosition, itemCount);
- }
+ /** @see Observer#onItemRangeRemoved(ItemHierarchy, int, int) */
+ public void notifyItemRangeRemoved(int position, int itemCount) {
+ if (position < 0) {
+ Log.w(TAG, "notifyItemRangeInserted: Invalid position=" + position);
+ return;
+ }
+ if (itemCount < 0) {
+ Log.w(TAG, "notifyItemRangeInserted: Invalid itemCount=" + itemCount);
+ return;
}
- /**
- * @see Observer#onItemRangeRemoved(ItemHierarchy, int, int)
- */
- public void notifyItemRangeRemoved(int position, int itemCount) {
- if (position < 0) {
- Log.w(TAG, "notifyItemRangeInserted: Invalid position=" + position);
- return;
- }
- if (itemCount < 0) {
- Log.w(TAG, "notifyItemRangeInserted: Invalid itemCount=" + itemCount);
- return;
- }
-
- for (Observer observer : mObservers) {
- observer.onItemRangeRemoved(this, position, itemCount);
- }
+ for (Observer observer : observers) {
+ observer.onItemRangeRemoved(this, position, itemCount);
}
+ }
}