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