ManagerTaskActivity.java 4.12 KB
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) {

        }
    };
}