|
@@ -1,468 +0,0 @@
|
|
|
-package com.usai.redant.apexdrivers.upload;
|
|
|
|
|
-
|
|
|
|
|
-import android.content.BroadcastReceiver;
|
|
|
|
|
-import android.content.ComponentName;
|
|
|
|
|
-import android.content.Context;
|
|
|
|
|
-import android.content.DialogInterface;
|
|
|
|
|
-import android.content.Intent;
|
|
|
|
|
-import android.content.IntentFilter;
|
|
|
|
|
-import android.content.ServiceConnection;
|
|
|
|
|
-import android.os.Bundle;
|
|
|
|
|
-import android.os.IBinder;
|
|
|
|
|
-import android.support.annotation.NonNull;
|
|
|
|
|
-import android.support.annotation.Nullable;
|
|
|
|
|
-import android.support.v7.app.ActionBar;
|
|
|
|
|
-import android.support.v7.app.AlertDialog;
|
|
|
|
|
-import android.util.Log;
|
|
|
|
|
-import android.util.TypedValue;
|
|
|
|
|
-import android.view.Menu;
|
|
|
|
|
-import android.view.MenuItem;
|
|
|
|
|
-import android.view.View;
|
|
|
|
|
-import android.view.ViewGroup;
|
|
|
|
|
-import android.widget.BaseAdapter;
|
|
|
|
|
-import android.widget.ImageButton;
|
|
|
|
|
-import android.widget.ListView;
|
|
|
|
|
-import android.widget.ProgressBar;
|
|
|
|
|
-import android.widget.TextView;
|
|
|
|
|
-
|
|
|
|
|
-import com.usai.redant.apexdrivers.ApexDriversBackgroundService;
|
|
|
|
|
-import com.usai.redant.apexdrivers.R;
|
|
|
|
|
-import com.usai.redant.apexdrivers.base.BasicActivity;
|
|
|
|
|
-import com.usai.redant.rautils.upload.RAUploadManager;
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
-
|
|
|
|
|
-import static com.usai.redant.apexdrivers.ApexDriversBackgroundService.APEX_DRIVER_UPLOAD_COUNT_CHANGE_NOTIFICATION;
|
|
|
|
|
-
|
|
|
|
|
-/**
|
|
|
|
|
- * 请使用TaskActivity
|
|
|
|
|
- * */
|
|
|
|
|
-@Deprecated
|
|
|
|
|
-public class UploadListActivity extends BasicActivity {
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- private ArrayList<Bundle> displaylist = new ArrayList<Bundle>();
|
|
|
|
|
-
|
|
|
|
|
- // private SwipeMenuListView uploadList;
|
|
|
|
|
- private ListView uploadList;
|
|
|
|
|
- private uploadAdapter adapter;
|
|
|
|
|
-// private ArrayList<Bundle> arr;
|
|
|
|
|
-
|
|
|
|
|
- private RAUploadManager uploadManager;
|
|
|
|
|
- private ApexDriversBackgroundService.MyBinder binder;
|
|
|
|
|
- private ApexDriversBackgroundService uploadServiceservice;
|
|
|
|
|
- private boolean serviceConnectionFlag = false; // 绑定服务标识
|
|
|
|
|
- private ServiceConnection serviceConnection;
|
|
|
|
|
- private RAUploadManager.UIUpdateListener uiUpdateListener = new RAUploadManager.UIUpdateListener() {
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void updateCell(long index, final Bundle taskinfo)
|
|
|
|
|
- {
|
|
|
|
|
- if(true)
|
|
|
|
|
- return;
|
|
|
|
|
-
|
|
|
|
|
- if(true) {
|
|
|
|
|
-
|
|
|
|
|
- runOnUiThread(new Runnable() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void run() {
|
|
|
|
|
-
|
|
|
|
|
- adapter.notifyDataSetChanged();
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- final int position = (int)index;
|
|
|
|
|
-
|
|
|
|
|
- runOnUiThread(new Runnable() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void run() {
|
|
|
|
|
-
|
|
|
|
|
- double percent = taskinfo.getDouble("progress",0);
|
|
|
|
|
-
|
|
|
|
|
- long timeStart = System.currentTimeMillis();
|
|
|
|
|
-
|
|
|
|
|
- int startShowIndex = uploadList.getFirstVisiblePosition();
|
|
|
|
|
- int lastShowIndex = uploadList.getLastVisiblePosition();
|
|
|
|
|
-
|
|
|
|
|
- if (position >= startShowIndex && position <= lastShowIndex) {
|
|
|
|
|
- View cell = uploadList.getChildAt((int)position - startShowIndex);
|
|
|
|
|
- uploadAdapter.ViewHolder holder= (uploadAdapter.ViewHolder)cell.getTag();
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- RAUploadManager.TaskStatus istatus = RAUploadManager.TaskStatus.values()[taskinfo.getInt("status",0)];
|
|
|
|
|
- String status="";
|
|
|
|
|
- switch(istatus)
|
|
|
|
|
- {
|
|
|
|
|
- case TaskStatusStart:
|
|
|
|
|
- status="uploading";
|
|
|
|
|
- break;
|
|
|
|
|
- case TaskStatusStop:
|
|
|
|
|
- status="stop";
|
|
|
|
|
- break;
|
|
|
|
|
- case TaskStatusError:
|
|
|
|
|
- status="warning";
|
|
|
|
|
- break;
|
|
|
|
|
- case TaskStatusWait:
|
|
|
|
|
- status="waiting";
|
|
|
|
|
- break;
|
|
|
|
|
- case TaskStatusFinish:
|
|
|
|
|
- status="finish";
|
|
|
|
|
- break;
|
|
|
|
|
-
|
|
|
|
|
- default:
|
|
|
|
|
- status="warning";
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- String err = taskinfo.getString("msg");
|
|
|
|
|
- String name = taskinfo.getString("order","");
|
|
|
|
|
- String action = taskinfo.getString("action","");
|
|
|
|
|
- String time = taskinfo.getString("time");
|
|
|
|
|
- String photoName = taskinfo.getString("name");
|
|
|
|
|
-
|
|
|
|
|
- holder.name_tv.setText(name);
|
|
|
|
|
- holder.progressBar.setProgress((int)(100 *percent));
|
|
|
|
|
- holder.state_tv.setText(status);
|
|
|
|
|
- holder.action_tv.setText(action);
|
|
|
|
|
- holder.time_tv.setText(time);
|
|
|
|
|
- holder.progress_tv.setText(String.format("%.2f%%",100*percent));
|
|
|
|
|
- holder.err_tv.setText(err);
|
|
|
|
|
- holder.photoName_tv.setText(photoName);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void updateList(final ArrayList<Bundle> newlist)
|
|
|
|
|
- {
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- runOnUiThread(new Runnable() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void run() {
|
|
|
|
|
-
|
|
|
|
|
- Log.d("_LIST","running tid="+Thread.currentThread().getId());
|
|
|
|
|
- Log.d("_LIST", "uploadlist UI size: "+ newlist.size());
|
|
|
|
|
- long timeStart = System.currentTimeMillis();
|
|
|
|
|
- displaylist = (ArrayList<Bundle>) newlist.clone();
|
|
|
|
|
- adapter.notifyDataSetChanged();
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- private BroadcastReceiver uploadReceiver = new BroadcastReceiver() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onReceive(Context context, Intent intent) {
|
|
|
|
|
-
|
|
|
|
|
- String action = intent.getAction();
|
|
|
|
|
- if (action.equals(APEX_DRIVER_UPLOAD_COUNT_CHANGE_NOTIFICATION)) {
|
|
|
|
|
-
|
|
|
|
|
- runOnUiThread(new Runnable() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void run() {
|
|
|
|
|
- notifyDataChanged();
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- private void registerBroadcastReceiver() {
|
|
|
|
|
-
|
|
|
|
|
- IntentFilter intentFilter = new IntentFilter();
|
|
|
|
|
- intentFilter.addAction(APEX_DRIVER_UPLOAD_COUNT_CHANGE_NOTIFICATION);
|
|
|
|
|
-
|
|
|
|
|
- registerReceiver(uploadReceiver,intentFilter);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public void notifyDataChanged() {
|
|
|
|
|
-
|
|
|
|
|
- displaylist = (ArrayList<Bundle>) uploadManager.get_arr_queue().clone(); //uploadManager.arr_queue;
|
|
|
|
|
-
|
|
|
|
|
- adapter.notifyDataSetChanged();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
- super.onCreate(savedInstanceState);
|
|
|
|
|
- setContentView(R.layout.activity_upload_list);
|
|
|
|
|
-
|
|
|
|
|
- ActionBar mActionBar = getSupportActionBar();
|
|
|
|
|
- mActionBar.setHomeButtonEnabled(true);
|
|
|
|
|
- mActionBar.setDisplayHomeAsUpEnabled(true);
|
|
|
|
|
- mActionBar.setTitle(getString(R.string.app_name));
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- // 初始化视图
|
|
|
|
|
- uploadList = (ListView)findViewById(R.id.upload_list);
|
|
|
|
|
- adapter = new uploadAdapter(R.layout.upload_cell);
|
|
|
|
|
- uploadList.setAdapter(adapter);
|
|
|
|
|
- serviceConnection = new ServiceConnection() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onServiceConnected(ComponentName name, IBinder iBinder) {
|
|
|
|
|
- serviceConnectionFlag = true;
|
|
|
|
|
-
|
|
|
|
|
- binder = (ApexDriversBackgroundService.MyBinder)iBinder;
|
|
|
|
|
- uploadServiceservice = (ApexDriversBackgroundService)binder.getService();
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- uploadManager = uploadServiceservice.getUploadManager();
|
|
|
|
|
- if (uploadManager == null) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- uploadManager.uiUpdateListener = uiUpdateListener;
|
|
|
|
|
- displaylist = (ArrayList<Bundle>) uploadManager.get_arr_queue().clone(); //uploadManager.arr_queue;
|
|
|
|
|
- adapter.notifyDataSetChanged();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onServiceDisconnected(ComponentName name) {
|
|
|
|
|
- serviceConnectionFlag = false;
|
|
|
|
|
- uploadManager.uiUpdateListener = null;
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- bindService();
|
|
|
|
|
-
|
|
|
|
|
- registerBroadcastReceiver();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- protected void onDestroy() {
|
|
|
|
|
-
|
|
|
|
|
- unbindService(serviceConnection);
|
|
|
|
|
-
|
|
|
|
|
- unregisterReceiver(uploadReceiver);
|
|
|
|
|
-
|
|
|
|
|
- super.onDestroy();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
|
- getMenuInflater().inflate(R.menu.upload_list_menu,menu);
|
|
|
|
|
- return true;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
|
- int i = item.getItemId();
|
|
|
|
|
- if (i == android.R.id.home) {
|
|
|
|
|
- finish();
|
|
|
|
|
-
|
|
|
|
|
- } else if (i == R.id.clear_upload_list_btn) {
|
|
|
|
|
- clearUploadList();
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
- return true;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private void clearUploadList() {
|
|
|
|
|
- if (displaylist.size() == 0) {
|
|
|
|
|
- new AlertDialog.Builder(this)
|
|
|
|
|
- .setTitle(getString(R.string.warning))
|
|
|
|
|
- .setMessage(getString(R.string.upload_empty))
|
|
|
|
|
- .setPositiveButton(getString(R.string.btn_ok),null)
|
|
|
|
|
- .show();
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- new AlertDialog.Builder(this)
|
|
|
|
|
- .setTitle(getString(R.string.clear_title))
|
|
|
|
|
- .setMessage(getString(R.string.clear_ask))
|
|
|
|
|
- .setPositiveButton(getString(R.string.btn_ok), new DialogInterface.OnClickListener() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
- // clear
|
|
|
|
|
- if (serviceConnectionFlag == true && uploadServiceservice != null) {
|
|
|
|
|
- uploadManager.clearTask();
|
|
|
|
|
-// adapter.notifyDataSetChanged();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- .setNegativeButton(getString(R.string.btn_cancel), new DialogInterface.OnClickListener() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- .show();
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- private class uploadAdapter extends BaseAdapter {
|
|
|
|
|
- private int resourceId;
|
|
|
|
|
- public uploadAdapter(int resourceID) {
|
|
|
|
|
-
|
|
|
|
|
- resourceId = resourceID;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public int getCount() {
|
|
|
|
|
- return displaylist.size();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public Bundle getItem(int position) {
|
|
|
|
|
- return displaylist.get(position);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public long getItemId(int position) {
|
|
|
|
|
- return position;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-// @Override
|
|
|
|
|
-// public int getViewTypeCount() {
|
|
|
|
|
-// return 4;
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
-// @Override
|
|
|
|
|
-// public int getItemViewType(int position) {
|
|
|
|
|
-// /**
|
|
|
|
|
-// * 0. <finish> remove </finish>
|
|
|
|
|
-// * 1. <error> start remove </error>
|
|
|
|
|
-// * 2. <stop> start </stop>
|
|
|
|
|
-// * 3. <start\wait> none </start\wait>
|
|
|
|
|
-// * */
|
|
|
|
|
-// return taskSwipeType(position);
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
- @NonNull
|
|
|
|
|
- @Override
|
|
|
|
|
- public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
|
|
|
|
-
|
|
|
|
|
- Log.d("_LIST","running tid="+Thread.currentThread().getId());
|
|
|
|
|
- long timeStart = System.currentTimeMillis();
|
|
|
|
|
-
|
|
|
|
|
- final Bundle item = displaylist.get(position);
|
|
|
|
|
-
|
|
|
|
|
- RAUploadManager.TaskStatus istatus = RAUploadManager.TaskStatus.values()[item.getInt("status",0)];
|
|
|
|
|
- String status="";
|
|
|
|
|
- switch(istatus)
|
|
|
|
|
- {
|
|
|
|
|
- case TaskStatusStart:
|
|
|
|
|
- status="uploading";
|
|
|
|
|
- break;
|
|
|
|
|
- case TaskStatusStop:
|
|
|
|
|
- status="stop";
|
|
|
|
|
- break;
|
|
|
|
|
- case TaskStatusError:
|
|
|
|
|
- status="warning";
|
|
|
|
|
- break;
|
|
|
|
|
- case TaskStatusWait:
|
|
|
|
|
- status="waiting";
|
|
|
|
|
- break;
|
|
|
|
|
- case TaskStatusFinish:
|
|
|
|
|
- status="finish";
|
|
|
|
|
- break;
|
|
|
|
|
-
|
|
|
|
|
- default:
|
|
|
|
|
- status="warning";
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- double percent = item.getDouble("progress",0);
|
|
|
|
|
- String err = item.getString("msg");
|
|
|
|
|
- String name = item.getString("order","");
|
|
|
|
|
- String action = item.getString("action","");
|
|
|
|
|
- String time = item.getString("time");
|
|
|
|
|
- String photoName = item.getString("name");
|
|
|
|
|
-
|
|
|
|
|
- View cell;
|
|
|
|
|
- ViewHolder holder;
|
|
|
|
|
- if (convertView != null) {
|
|
|
|
|
-
|
|
|
|
|
- cell = convertView;
|
|
|
|
|
- holder = (ViewHolder)cell.getTag();
|
|
|
|
|
-
|
|
|
|
|
- } else {
|
|
|
|
|
-
|
|
|
|
|
- cell = View.inflate(getApplicationContext(),resourceId,null);
|
|
|
|
|
- holder = new ViewHolder();
|
|
|
|
|
- holder.name_tv = (TextView)cell.findViewById(R.id.upload_cell_title_tv);
|
|
|
|
|
- holder.photoName_tv = cell.findViewById(R.id.upload_cell_name_tv);
|
|
|
|
|
- holder.action_tv = cell.findViewById(R.id.upload_cell_action_tv);
|
|
|
|
|
- holder.time_tv = cell.findViewById(R.id.upload_cell_time_tv);
|
|
|
|
|
- holder.progressBar = (ProgressBar)cell.findViewById(R.id.upload_progressBar);
|
|
|
|
|
- holder.state_tv = (TextView)cell.findViewById(R.id.upload_state_tv);
|
|
|
|
|
- holder.progress_tv = (TextView)cell.findViewById(R.id.upload_progress_tv);
|
|
|
|
|
- holder.err_tv = (TextView)cell.findViewById(R.id.upload_err_tv);
|
|
|
|
|
- holder.btn_reload=(ImageButton) cell.findViewById(R.id.btn_reload);
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- holder.btn_reload.setImageResource(R.drawable.ic_action_reload);
|
|
|
|
|
- if(istatus!= RAUploadManager.TaskStatus.TaskStatusError)
|
|
|
|
|
- {
|
|
|
|
|
- holder.btn_reload.setVisibility(View.GONE);
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- holder.btn_reload.setVisibility(View.VISIBLE);
|
|
|
|
|
- holder.btn_reload.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onClick(View v) {
|
|
|
|
|
-
|
|
|
|
|
- uploadManager.startTask(item);
|
|
|
|
|
- v.setVisibility(View.GONE);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
- cell.setTag(holder);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- holder.name_tv.setText(name);
|
|
|
|
|
- holder.action_tv.setText(action);
|
|
|
|
|
- holder.time_tv.setText(time);
|
|
|
|
|
- holder.progressBar.setProgress((int) (100 * percent));
|
|
|
|
|
- holder.state_tv.setText(status);
|
|
|
|
|
- holder.progress_tv.setText(String.format("%.2f%%",100*percent));
|
|
|
|
|
- holder.err_tv.setText(err);
|
|
|
|
|
- holder.photoName_tv.setText(photoName);
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- Log.d("_LIST", "getView(): POSITION "+position+" COST " + (System.currentTimeMillis() - timeStart));
|
|
|
|
|
- return cell;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private class ViewHolder {
|
|
|
|
|
- public TextView name_tv;
|
|
|
|
|
- public TextView photoName_tv;
|
|
|
|
|
- public TextView action_tv;
|
|
|
|
|
- public TextView time_tv;
|
|
|
|
|
- public ProgressBar progressBar;
|
|
|
|
|
- public TextView state_tv;
|
|
|
|
|
- public TextView progress_tv;
|
|
|
|
|
- public TextView err_tv;
|
|
|
|
|
- public ImageButton btn_reload;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- /** Service */
|
|
|
|
|
- private void bindService() {
|
|
|
|
|
- Intent intent = new Intent(UploadListActivity.this, ApexDriversBackgroundService.class);
|
|
|
|
|
-
|
|
|
|
|
- bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private int dp2px(int dp) {
|
|
|
|
|
- return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,getResources().getDisplayMetrics());
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|