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