wpc
2018-11-26 aa82e9973b3d962c325d18ed9407b6b33c4fe554
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
package com.lcjian.library.widget.verticalviewpager;
 
import android.database.DataSetObservable;
import android.database.DataSetObserver;
import android.os.Parcelable;
import android.view.View;
import android.view.ViewGroup;
 
public abstract class PagerAdapter {
    private DataSetObservable mObservable = new DataSetObservable();
 
    public static final int POSITION_UNCHANGED = -1;
    public static final int POSITION_NONE = -2;
 
    /**
     * Return the number of views available.
     */
    public abstract int getCount();
 
    /**
     * Called when a change in the shown pages is going to start being made.
     * 
     * @param container
     *            The containing View which is displaying this adapter's page
     *            views.
     */
    public void startUpdate(ViewGroup container) {
        startUpdate((View) container);
    }
 
    /**
     * Create the page for the given position. The adapter is responsible for
     * adding the view to the container given here, although it only must ensure
     * this is done by the time it returns from {@link #finishUpdate(ViewGroup)}
     * .
     * 
     * @param container
     *            The containing View in which the page will be shown.
     * @param position
     *            The page position to be instantiated.
     * @return Returns an Object representing the new page. This does not need
     *         to be a View, but can be some other container of the page.
     */
    public Object instantiateItem(ViewGroup container, int position) {
        return instantiateItem((View) container, position);
    }
 
    /**
     * Remove a page for the given position. The adapter is responsible for
     * removing the view from its container, although it only must ensure this
     * is done by the time it returns from {@link #finishUpdate(ViewGroup)}.
     * 
     * @param container
     *            The containing View from which the page will be removed.
     * @param position
     *            The page position to be removed.
     * @param object
     *            The same object that was returned by
     *            {@link #instantiateItem(View, int)}.
     */
    public void destroyItem(ViewGroup container, int position, Object object) {
        destroyItem((View) container, position, object);
    }
 
    /**
     * Called to inform the adapter of which item is currently considered to be
     * the "primary", that is the one show to the user as the current page.
     * 
     * @param container
     *            The containing View from which the page will be removed.
     * @param position
     *            The page position that is now the primary.
     * @param object
     *            The same object that was returned by
     *            {@link #instantiateItem(View, int)}.
     */
    public void setPrimaryItem(ViewGroup container, int position, Object object) {
        setPrimaryItem((View) container, position, object);
    }
 
    /**
     * Called when the a change in the shown pages has been completed. At this
     * point you must ensure that all of the pages have actually been added or
     * removed from the container as appropriate.
     * 
     * @param container
     *            The containing View which is displaying this adapter's page
     *            views.
     */
    public void finishUpdate(ViewGroup container) {
        finishUpdate((View) container);
    }
 
    /**
     * Called when a change in the shown pages is going to start being made.
     * 
     * @param container
     *            The containing View which is displaying this adapter's page
     *            views.
     * 
     * @deprecated Use {@link #startUpdate(ViewGroup)}
     */
    public void startUpdate(View container) {
    }
 
    /**
     * Create the page for the given position. The adapter is responsible for
     * adding the view to the container given here, although it only must ensure
     * this is done by the time it returns from {@link #finishUpdate(ViewGroup)}
     * .
     * 
     * @param container
     *            The containing View in which the page will be shown.
     * @param position
     *            The page position to be instantiated.
     * @return Returns an Object representing the new page. This does not need
     *         to be a View, but can be some other container of the page.
     * 
     * @deprecated Use {@link #instantiateItem(ViewGroup, int)}
     */
    public Object instantiateItem(View container, int position) {
        throw new UnsupportedOperationException(
                "Required method instantiateItem was not overridden");
    }
 
    /**
     * Remove a page for the given position. The adapter is responsible for
     * removing the view from its container, although it only must ensure this
     * is done by the time it returns from {@link #finishUpdate(View)}.
     * 
     * @param container
     *            The containing View from which the page will be removed.
     * @param position
     *            The page position to be removed.
     * @param object
     *            The same object that was returned by
     *            {@link #instantiateItem(View, int)}.
     * 
     * @deprecated Use {@link #destroyItem(ViewGroup, int, Object)}
     */
    public void destroyItem(View container, int position, Object object) {
        throw new UnsupportedOperationException(
                "Required method destroyItem was not overridden");
    }
 
    /**
     * Called to inform the adapter of which item is currently considered to be
     * the "primary", that is the one show to the user as the current page.
     * 
     * @param container
     *            The containing View from which the page will be removed.
     * @param position
     *            The page position that is now the primary.
     * @param object
     *            The same object that was returned by
     *            {@link #instantiateItem(View, int)}.
     * 
     * @deprecated Use {@link #setPrimaryItem(ViewGroup, int, Object)}
     */
    public void setPrimaryItem(View container, int position, Object object) {
    }
 
    /**
     * Called when the a change in the shown pages has been completed. At this
     * point you must ensure that all of the pages have actually been added or
     * removed from the container as appropriate.
     * 
     * @param container
     *            The containing View which is displaying this adapter's page
     *            views.
     * 
     * @deprecated Use {@link #finishUpdate(ViewGroup)}
     */
    public void finishUpdate(View container) {
    }
 
    /**
     * Determines whether a page View is associated with a specific key object
     * as returned by {@link #instantiateItem(ViewGroup, int)}. This method is
     * required for a PagerAdapter to function properly.
     * 
     * @param view
     *            Page View to check for association with <code>object</code>
     * @param object
     *            Object to check for association with <code>view</code>
     * @return true if <code>view</code> is associated with the key object
     *         <code>object</code>
     */
    public abstract boolean isViewFromObject(View view, Object object);
 
    /**
     * Save any instance state associated with this adapter and its pages that
     * should be restored if the current UI state needs to be reconstructed.
     * 
     * @return Saved state for this adapter
     */
    public Parcelable saveState() {
        return null;
    }
 
    /**
     * Restore any instance state associated with this adapter and its pages
     * that was previously saved by {@link #saveState()}.
     * 
     * @param state
     *            State previously saved by a call to {@link #saveState()}
     * @param loader
     *            A ClassLoader that should be used to instantiate any restored
     *            objects
     */
    public void restoreState(Parcelable state, ClassLoader loader) {
    }
 
    /**
     * Called when the host view is attempting to determine if an item's
     * position has changed. Returns {@link #POSITION_UNCHANGED} if the position
     * of the given item has not changed or {@link #POSITION_NONE} if the item
     * is no longer present in the adapter.
     * 
     * <p>
     * The default implementation assumes that items will never change position
     * and always returns {@link #POSITION_UNCHANGED}.
     * 
     * @param object
     *            Object representing an item, previously returned by a call to
     *            {@link #instantiateItem(View, int)}.
     * @return object's new position index from [0, {@link #getCount()}),
     *         {@link #POSITION_UNCHANGED} if the object's position has not
     *         changed, or {@link #POSITION_NONE} if the item is no longer
     *         present.
     */
    public int getItemPosition(Object object) {
        return POSITION_UNCHANGED;
    }
 
    /**
     * This method should be called by the application if the data backing this
     * adapter has changed and associated views should update.
     */
    public void notifyDataSetChanged() {
        mObservable.notifyChanged();
    }
 
    void registerDataSetObserver(DataSetObserver observer) {
        mObservable.registerObserver(observer);
    }
 
    void unregisterDataSetObserver(DataSetObserver observer) {
        mObservable.unregisterObserver(observer);
    }
 
    /**
     * This method may be called by the ViewPager to obtain a title string to
     * describe the specified page. This method may return null indicating no
     * title for this page. The default implementation returns null.
     * 
     * @param position
     *            The position of the title requested
     * @return A title for the requested page
     */
    public CharSequence getPageTitle(int position) {
        return null;
    }
 
    /**
     * Returns the proportional width of a given page as a percentage of the
     * ViewPager's measured width from (0.f-1.f]
     * 
     * @param position
     *            The position of the page requested
     * @return Proportional width for the given page position
     */
    public float getPageWidth(int position) {
        return 1.f;
    }
 
    public float getPageHeight(int position) {
        return 1.f;
    }
}