project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadListFragment.java
author koda
Tue, 21 Jan 2014 22:43:06 +0100
changeset 10017 de822cd3df3a
parent 7584 7831c84cc644
permissions -rw-r--r--
fixwhitespace and dos2unix
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7584
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6485
diff changeset
     1
/*
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6485
diff changeset
     2
 * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6485
diff changeset
     3
 * Copyright (c) 2011-2012 Richard Deurwaarder <xeli@xelification.com>
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6485
diff changeset
     4
 *
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6485
diff changeset
     5
 * This program is free software; you can redistribute it and/or
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6485
diff changeset
     6
 * modify it under the terms of the GNU General Public License
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6485
diff changeset
     7
 * as published by the Free Software Foundation; either version 2
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6485
diff changeset
     8
 * of the License, or (at your option) any later version.
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6485
diff changeset
     9
 *
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6485
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6485
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6485
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6485
diff changeset
    13
 * GNU General Public License for more details.
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6485
diff changeset
    14
 *
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6485
diff changeset
    15
 * You should have received a copy of the GNU General Public License
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6485
diff changeset
    16
 * along with this program; if not, write to the Free Software
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6485
diff changeset
    17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6485
diff changeset
    18
 */
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6485
diff changeset
    19
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    20
package org.hedgewars.hedgeroid.Downloader;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    21
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    22
import java.io.BufferedReader;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    23
import java.io.IOException;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    24
import java.io.InputStreamReader;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    25
import java.net.HttpURLConnection;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    26
import java.net.URL;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    27
import java.util.ArrayList;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    28
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    29
import org.xmlpull.v1.XmlPullParser;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    30
import org.xmlpull.v1.XmlPullParserException;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    31
import org.xmlpull.v1.XmlPullParserFactory;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    32
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    33
import android.graphics.Color;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    34
import android.os.Bundle;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    35
import android.support.v4.app.ListFragment;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    36
import android.util.Log;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    37
import android.view.View;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    38
import android.widget.AbsListView;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    39
import android.widget.AbsListView.OnScrollListener;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    40
import android.widget.AdapterView;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    41
import android.widget.AdapterView.OnItemClickListener;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    42
import android.widget.ArrayAdapter;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    43
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    44
public class DownloadListFragment extends ListFragment implements OnItemClickListener, OnScrollListener, Runnable{
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    45
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    46
    private View targetView = null;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    47
    private ArrayList<OnItemMovementListener> listeners = new ArrayList<OnItemMovementListener>();
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    48
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    49
    public void onActivityCreated(Bundle savedInstanceState){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    50
        super.onActivityCreated(savedInstanceState);
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    51
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    52
        ArrayList<DownloadPackage> tasks = new ArrayList<DownloadPackage>();
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    53
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    54
        ArrayAdapter<DownloadPackage> adapter = new ArrayAdapter<DownloadPackage>(getActivity().getApplicationContext(), android.R.layout.simple_list_item_1, tasks);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    55
        setListAdapter(adapter);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    56
        getListView().setOnItemClickListener(this);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    57
        getListView().setOnScrollListener(this);
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    58
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    59
        if(getActivity() instanceof OnItemMovementListener){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    60
            listeners.add((OnItemMovementListener)getActivity());
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    61
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    62
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    63
        getListView().setCacheColorHint(Color.TRANSPARENT);//To prevent a blackish background while scrolling
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    64
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    65
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    66
        Thread t = new Thread(this, "DownloadListParser");
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    67
        t.start();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    68
    }
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    69
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    70
    public void run(){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    71
        XmlPullParserFactory xmlPullFactory;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    72
        try {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    73
            xmlPullFactory = XmlPullParserFactory.newInstance();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    74
            XmlPullParser xmlPuller = xmlPullFactory.newPullParser();
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    75
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    76
            URL url = new URL("http://www.xelification.com/tmp/downloads.xml");
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    77
            HttpURLConnection conn = (HttpURLConnection)url.openConnection();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    78
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    79
            BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()), 1024);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    80
            xmlPuller.setInput(br);
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    81
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    82
            final ArrayAdapter<DownloadPackage> adapter = (ArrayAdapter<DownloadPackage>) getListAdapter();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    83
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    84
            int eventType = xmlPuller.getEventType();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    85
            while(eventType != XmlPullParser.END_DOCUMENT){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    86
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    87
                if(eventType == XmlPullParser.START_TAG){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    88
                    if(xmlPuller.getName().toLowerCase().equals("task")){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    89
                        final DownloadPackage task = DownloadPackage.getTaskFromXML(getActivity(), xmlPuller);
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    90
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    91
                        getActivity().runOnUiThread(new Runnable(){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    92
                            public void run() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    93
                                adapter.add(task);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    94
                            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    95
                        });
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    96
                    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    97
                }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    98
                eventType = getEventType(xmlPuller);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    99
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   100
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   101
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   102
        } catch (XmlPullParserException e) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   103
            e.printStackTrace();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   104
        } catch (IOException e) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   105
            e.printStackTrace();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   106
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   107
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   108
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   109
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   110
    /**
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   111
     * Skips whitespaces..
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   112
     */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   113
    private static int getEventType(XmlPullParser xmlPuller)throws XmlPullParserException, IOException{
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   114
        int eventType = xmlPuller.next();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   115
        while(eventType == XmlPullParser.TEXT && xmlPuller.isWhitespace()){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   116
            eventType = xmlPuller.next();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   117
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   118
        return eventType;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   119
    }
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   120
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   121
    public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   122
        DownloadPackage task = (DownloadPackage)arg0.getAdapter().getItem(position);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   123
        /*
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   124
        FragmentTransaction ft = getFragmentManager().beginTransaction();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   125
        Fragment prev = getFragmentManager().findFragmentByTag("dialog");
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   126
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   127
        //remove any old dialogs
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   128
        if(prev != null) ft.remove(prev);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   129
        ft.addToBackStack(null);
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   130
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   131
        //create a new dialog based on this task
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   132
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   133
        DialogFragment newFragment = DownloadDialogFragment.newInstance(task);
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   134
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   135
        //show it
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   136
        newFragment.show(ft, "dialog");
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   137
         */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   138
        targetView = arg1;
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   139
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   140
        //determine state
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   141
        int min = arg0.getTop();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   142
        int max = arg0.getBottom();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   143
        int top = targetView.getTop();
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   144
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   145
        previousXCoord = top;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   146
        for(OnItemMovementListener listener : listeners){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   147
            listener.onNewItemSelected(task, top, min, max, targetView.getHeight()*2);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   148
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   149
    }
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   150
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   151
    private int previousXCoord = 0;
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   152
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   153
    /*
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   154
     * (non-Javadoc)
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   155
     * @see android.widget.AbsListView.OnScrollListener#onScroll(android.widget.AbsListView, int, int, int)
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   156
     *
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   157
     * Android renews the Items used in the view, so when a user scroll down the list,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   158
     * as soon as the item has dissapeard from the list it gets reused at the bottom.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   159
     *
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   160
     * For this reason we cannot just keep sending the targetView.getTop() but we must
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   161
     *  remember if the view is supposed to be at the top or bottom of the list. We
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   162
     *  remember this with int state,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   163
     *     - 0 means we've got accurate reading from getTop()
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   164
     *     - -1 means it's somewhere at the top of the list
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   165
     *     - 1 means it's at the bottom somewhere
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   166
     */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   167
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   168
        if(targetView != null){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   169
            int top = targetView.getTop() + (targetView.getHeight()/2);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   170
            int min = view.getTop();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   171
            int max = view.getBottom();
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   172
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   173
            if(Math.abs(previousXCoord - top) > targetView.getHeight()*2 ){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   174
                top = previousXCoord;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   175
            }
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   176
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   177
            for(OnItemMovementListener listener : listeners){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   178
                listener.onViewMoved(top, min, max);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   179
            }
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   180
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   181
            previousXCoord = top;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   182
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   183
    }
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   184
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   185
    public void onScrollStateChanged(AbsListView view, int scrollState) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   186
        switch(scrollState){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   187
        case OnScrollListener.SCROLL_STATE_FLING: Log.d("tag", "fling"); break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   188
        case OnScrollListener.SCROLL_STATE_IDLE:Log.d("tag", "idle"); break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   189
        case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:Log.d("tag", "scroll"); break;
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   190
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   191
        }
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   192
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   193
    }
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   194
}
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   195
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   196
interface OnItemMovementListener{
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   197
    /**
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   198
     * When I new item has been selected this method will be called
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   199
     * @param task The task which goes with this item
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   200
     * @param x The middle of this item
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   201
     * @param minX The top of the parent of this item
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   202
     * @param maxX The bottom of the parent of this item
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   203
     */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   204
    void onNewItemSelected(DownloadPackage task, int x, int minX, int maxX, int size);
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   205
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   206
    /**
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   207
     * When the item has been moved this method is called
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   208
     * @param x The middle of this item
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   209
     * @param minX The top of the parent of this item
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   210
     * @param maxX The bottom of the parent of this item
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   211
     */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   212
    void onViewMoved(int x, int minX, int maxX);
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   213
}
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
   214