project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadListActivity.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: 6842
diff changeset
     1
/*
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6842
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: 6842
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: 6842
diff changeset
     4
 *
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6842
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: 6842
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: 6842
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: 6842
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: 6842
diff changeset
     9
 *
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6842
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: 6842
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: 6842
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: 6842
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: 6842
diff changeset
    14
 *
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6842
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: 6842
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: 6842
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: 6842
diff changeset
    18
 */
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6842
diff changeset
    19
6343
9df5a486f41e first part of the new downloader implementation
Xeli
parents:
diff changeset
    20
package org.hedgewars.hedgeroid.Downloader;
9df5a486f41e first part of the new downloader implementation
Xeli
parents:
diff changeset
    21
6350
41b0a9955c47 new download manager \o/
Xeli
parents: 6343
diff changeset
    22
import org.hedgewars.hedgeroid.R;
41b0a9955c47 new download manager \o/
Xeli
parents: 6343
diff changeset
    23
6343
9df5a486f41e first part of the new downloader implementation
Xeli
parents:
diff changeset
    24
import android.os.Bundle;
6350
41b0a9955c47 new download manager \o/
Xeli
parents: 6343
diff changeset
    25
import android.support.v4.app.FragmentActivity;
41b0a9955c47 new download manager \o/
Xeli
parents: 6343
diff changeset
    26
import android.support.v4.app.FragmentManager;
41b0a9955c47 new download manager \o/
Xeli
parents: 6343
diff changeset
    27
import android.support.v4.app.FragmentTransaction;
41b0a9955c47 new download manager \o/
Xeli
parents: 6343
diff changeset
    28
import android.view.Gravity;
6343
9df5a486f41e first part of the new downloader implementation
Xeli
parents:
diff changeset
    29
import android.view.View;
6350
41b0a9955c47 new download manager \o/
Xeli
parents: 6343
diff changeset
    30
import android.view.View.OnClickListener;
41b0a9955c47 new download manager \o/
Xeli
parents: 6343
diff changeset
    31
import android.widget.Button;
41b0a9955c47 new download manager \o/
Xeli
parents: 6343
diff changeset
    32
import android.widget.FrameLayout;
41b0a9955c47 new download manager \o/
Xeli
parents: 6343
diff changeset
    33
import android.widget.ImageView;
41b0a9955c47 new download manager \o/
Xeli
parents: 6343
diff changeset
    34
import android.widget.LinearLayout;
41b0a9955c47 new download manager \o/
Xeli
parents: 6343
diff changeset
    35
41b0a9955c47 new download manager \o/
Xeli
parents: 6343
diff changeset
    36
public class DownloadListActivity extends FragmentActivity implements OnItemMovementListener{
6343
9df5a486f41e first part of the new downloader implementation
Xeli
parents:
diff changeset
    37
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    38
    private FrameLayout layout = null;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    39
    private LinearLayout downloadQueueContainer = null;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    40
    private View infoView = null;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    41
    private ImageView arrow = null;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    42
    private int halfSize = 0;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    43
    private DownloadPackage task = null;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    44
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    45
    public void onCreate(Bundle savedInstanceState){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    46
        super.onCreate(savedInstanceState);
6343
9df5a486f41e first part of the new downloader implementation
Xeli
parents:
diff changeset
    47
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    48
        setContentView(R.layout.download_listactivity);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    49
        //FragmentManager fm = this.getSupportFragmentManager();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    50
        //if(fm.findFragmentById(android.R.id.content) == null){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    51
        //  DownloadListFragment listfrag = new DownloadListFragment();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    52
        //  fm.beginTransaction().add(android.R.id.content, listfrag).commit();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    53
        //}
6350
41b0a9955c47 new download manager \o/
Xeli
parents: 6343
diff changeset
    54
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    55
        layout = (FrameLayout)findViewById(R.id.downloadFrameLayout);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    56
        downloadQueueContainer = (LinearLayout) findViewById(R.id.downloadQueueContainer);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    57
    }
6350
41b0a9955c47 new download manager \o/
Xeli
parents: 6343
diff changeset
    58
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    59
    public void onNewItemSelected(DownloadPackage _task, int x, int minX, int maxX, int size) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    60
        if(layout != null){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    61
            if(!_task.equals(task)){//if it's a new task refresh the whole thing
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    62
                task = _task;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    63
                layout.removeView(infoView);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    64
                infoView = null;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    65
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    66
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    67
            if(infoView == null){//build iv if it hasn't been created yet
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    68
                infoView = this.getLayoutInflater().inflate(R.layout.download_info, layout, false);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    69
                FrameLayout.LayoutParams params = (android.widget.FrameLayout.LayoutParams) infoView.getLayoutParams();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    70
                params.gravity = Gravity.NO_GRAVITY;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    71
                params.height = size;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    72
                arrow = (ImageView)infoView.findViewById(R.id.arrow);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    73
                arrow.setVisibility(View.INVISIBLE);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    74
                halfSize = size/2;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    75
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    76
                Button yes = (Button)infoView.findViewById(R.id.download);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    77
                Button no = (Button)infoView.findViewById(R.id.cancel);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    78
                yes.setOnClickListener(yesClicker);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    79
                no.setOnClickListener(noClicker);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    80
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    81
                layout.addView(infoView, params);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    82
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    83
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    84
    }
6350
41b0a9955c47 new download manager \o/
Xeli
parents: 6343
diff changeset
    85
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    86
    public void onViewMoved(int x, int minX, int maxX) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    87
        if(halfSize == -1){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    88
            if(infoView.getHeight() != 0){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    89
                halfSize = infoView.getHeight()/2;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    90
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    91
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    92
        if(layout != null && infoView != null){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    93
            FrameLayout.LayoutParams params = ((FrameLayout.LayoutParams)infoView.getLayoutParams());
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    94
            if(x - halfSize < minX){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    95
                params.topMargin = 0;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    96
                arrow.setVisibility(View.INVISIBLE);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    97
                params.gravity = Gravity.TOP;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    98
            }else if (x + halfSize >= maxX){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    99
                params.topMargin = 0;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   100
                arrow.setVisibility(View.INVISIBLE);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   101
                params.gravity = Gravity.BOTTOM;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   102
            }else{
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   103
                params.topMargin = x - halfSize;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   104
                params.gravity = Gravity.NO_GRAVITY;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   105
                arrow.setVisibility(View.VISIBLE);
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
            infoView.requestLayout();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   109
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   110
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   111
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   112
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   113
    private OnClickListener yesClicker = new OnClickListener(){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   114
        public void onClick(View v){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   115
            FragmentManager fm = getSupportFragmentManager();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   116
            FragmentTransaction ft= fm.beginTransaction();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   117
            DownloadFragment df = DownloadFragment.getInstance(task);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   118
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   119
            ft.add(R.id.downloadQueueContainer, df).commit();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   120
            //ft.show(new DownloadFragment());
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   121
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   122
            task = null;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   123
            layout.removeView(infoView);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   124
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   125
    };
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   126
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   127
    private OnClickListener noClicker = new OnClickListener(){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   128
        public void onClick(View v){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   129
            task = null;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   130
            layout.removeView(infoView);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   131
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   132
    };
6343
9df5a486f41e first part of the new downloader implementation
Xeli
parents:
diff changeset
   133
}