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