Updated copyright in source files
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / ExtendedListView.java
1 /* ownCloud Android client application
2 * Copyright (C) 2012 Bartek Przybylski
3 * Copyright (C) 2012-2013 ownCloud Inc.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19
20 package com.owncloud.android.ui;
21
22 import android.content.Context;
23 import android.graphics.Canvas;
24 import android.util.AttributeSet;
25 import android.widget.ListView;
26
27 /**
28 * ListView allowing to specify the position of an item that should be centered in the visible area, if possible.
29 *
30 * The cleanest way I found to overcome the problem due to getHeight() returns 0 until the view is really drawn.
31 *
32 * @author David A. Velasco
33 */
34 public class ExtendedListView extends ListView {
35
36 private int mPositionToSetAndCenter;
37
38 public ExtendedListView(Context context) {
39 super(context);
40 }
41
42 public ExtendedListView(Context context, AttributeSet attrs) {
43 super(context, attrs);
44 }
45
46 public ExtendedListView(Context context, AttributeSet attrs, int defStyle) {
47 super(context, attrs, defStyle);
48 }
49
50 /**
51 * {@inheritDoc}
52 *
53 *
54 */
55 @Override
56 protected void onDraw (Canvas canvas) {
57 super.onDraw(canvas);
58 if (mPositionToSetAndCenter > 0) {
59 this.setSelectionFromTop(mPositionToSetAndCenter, getHeight() / 2);
60 mPositionToSetAndCenter = 0;
61 }
62 }
63
64 /**
65 * Public method to set the position of the item that should be centered in the visible area of the view.
66 *
67 * The position is saved here and checked in onDraw().
68 *
69 * @param position Position (in the list of items) of the item to center in the visible area.
70 */
71 public void setAndCenterSelection(int position) {
72 mPositionToSetAndCenter = position;
73 }
74 }