ManagerTaskActivity.java
4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package com.huaheng.robot.task;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import com.huaheng.robot.MainActivity;
import com.huaheng.robot.R;
import com.huaheng.robot.https.HttpInterface2;
import com.huaheng.robot.https.Subscribers.ProgressSubscriber;
import com.huaheng.robot.https.Subscribers.SubscriberOnNextListener;
import com.huaheng.robot.util.CommonActivity;
import butterknife.ButterKnife;
public class ManagerTaskActivity extends CommonActivity {
private final int WC= ViewGroup.LayoutParams.WRAP_CONTENT;
private final int FP= ViewGroup.LayoutParams.WRAP_CONTENT;
@Override
protected void initActivityOnCreate(Bundle savedInstanceState) {
super.initActivityOnCreate(savedInstanceState);
setContentView(R.layout.activity_manager_task);
ButterKnife.bind(this);
setTitle(getString(R.string.manager_task));
createTable();
}
public void createTable() {
TableLayout tableLayout = (TableLayout) findViewById(R.id.id_tableLayout);
tableLayout.setStretchAllColumns(true); //设置指定列号的列属性为Stretchable
for (int row = 0; row < 3; row++) { //产生的行数
TableRow tableRow = new TableRow(ManagerTaskActivity.this);
tableRow.setBackgroundColor(Color.rgb(222, 220, 210)); //设置表格背景
for (int col = 0; col < 8; col++) { //产生的列数
TextView tv = new TextView(ManagerTaskActivity.this);
tv.setBackgroundResource(R.drawable.shape); //设置背景
tv.setGravity(Gravity.CENTER);
tv.setText("测试");
tableRow.addView(tv);
}
tableLayout.addView(tableRow, new LinearLayout.LayoutParams(FP, WC));
final int finalRow = row;
tableRow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showCancelTaskDialog(String.valueOf(finalRow));
}
});
}
}
private void showCancelTaskDialog(final String id){
String str = getResources().getString(R.string.cancel_task_message);
String message = String.format(str, id);
final AlertDialog.Builder normalDialog =
new AlertDialog.Builder(ManagerTaskActivity.this);
normalDialog.setTitle(R.string.cancel_task);
normalDialog.setMessage(message);
normalDialog.setPositiveButton(R.string.ok,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
cancelTask(id);
}
});
normalDialog.setNegativeButton(R.string.cancel,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
normalDialog.show();
}
private void cancelTask(String id) {
HttpInterface2.getInsstance().cancelTask(new ProgressSubscriber<String>(this, cancelTaskListener), Integer.parseInt(id));
}
SubscriberOnNextListener cancelTaskListener = new SubscriberOnNextListener<String>() {
@Override
public void onNext(String str) {
}
@Override
public void onError(String str) {
}
};
private void getAllUncompleteTask() {
HttpInterface2.getInsstance().getAllUncompleteTask(new ProgressSubscriber<String>(this, uncompleteTaskListener), 1);
}
SubscriberOnNextListener uncompleteTaskListener = new SubscriberOnNextListener<String>() {
@Override
public void onNext(String str) {
}
@Override
public void onError(String str) {
}
};
}