|
@@ -1,29 +1,37 @@
|
|
|
package com.usai.redant.raimage.UploadList;
|
|
package com.usai.redant.raimage.UploadList;
|
|
|
|
|
|
|
|
-import android.content.BroadcastReceiver;
|
|
|
|
|
import android.content.ComponentName;
|
|
import android.content.ComponentName;
|
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
|
|
|
+import android.content.DialogInterface;
|
|
|
import android.content.Intent;
|
|
import android.content.Intent;
|
|
|
-import android.content.IntentFilter;
|
|
|
|
|
import android.content.ServiceConnection;
|
|
import android.content.ServiceConnection;
|
|
|
|
|
+import android.graphics.Color;
|
|
|
|
|
+import android.graphics.drawable.ColorDrawable;
|
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
|
import android.os.IBinder;
|
|
import android.os.IBinder;
|
|
|
import android.support.annotation.NonNull;
|
|
import android.support.annotation.NonNull;
|
|
|
import android.support.annotation.Nullable;
|
|
import android.support.annotation.Nullable;
|
|
|
-import android.support.v4.content.LocalBroadcastManager;
|
|
|
|
|
import android.support.v7.app.ActionBar;
|
|
import android.support.v7.app.ActionBar;
|
|
|
|
|
+import android.support.v7.app.AlertDialog;
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
import android.util.Log;
|
|
import android.util.Log;
|
|
|
|
|
+import android.util.TypedValue;
|
|
|
import android.view.LayoutInflater;
|
|
import android.view.LayoutInflater;
|
|
|
|
|
+import android.view.Menu;
|
|
|
import android.view.MenuItem;
|
|
import android.view.MenuItem;
|
|
|
import android.view.View;
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
import android.view.ViewGroup;
|
|
|
import android.widget.ArrayAdapter;
|
|
import android.widget.ArrayAdapter;
|
|
|
|
|
+import android.widget.BaseAdapter;
|
|
|
import android.widget.ListView;
|
|
import android.widget.ListView;
|
|
|
import android.widget.ProgressBar;
|
|
import android.widget.ProgressBar;
|
|
|
import android.widget.TextView;
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import com.usai.redant.raimage.R;
|
|
import com.usai.redant.raimage.R;
|
|
|
|
|
+import com.usai.redant.raimage.UploadList.swipemenulistview.SwipeMenu;
|
|
|
|
|
+import com.usai.redant.raimage.UploadList.swipemenulistview.SwipeMenuCreator;
|
|
|
|
|
+import com.usai.redant.raimage.UploadList.swipemenulistview.SwipeMenuItem;
|
|
|
|
|
+import com.usai.redant.raimage.UploadList.swipemenulistview.SwipeMenuListView;
|
|
|
import com.usai.redant.raimage.UploadService;
|
|
import com.usai.redant.raimage.UploadService;
|
|
|
import com.usai.util.RAUploadManager;
|
|
import com.usai.util.RAUploadManager;
|
|
|
|
|
|
|
@@ -32,13 +40,10 @@ import java.util.List;
|
|
|
|
|
|
|
|
public class UploadListActivity extends AppCompatActivity {
|
|
public class UploadListActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
- private ListView uploadList;
|
|
|
|
|
|
|
+ private SwipeMenuListView uploadList;
|
|
|
private uploadAdapter adapter;
|
|
private uploadAdapter adapter;
|
|
|
private ArrayList<Bundle> arr;
|
|
private ArrayList<Bundle> arr;
|
|
|
|
|
|
|
|
- private LocalBroadcastManager broadcastManager;
|
|
|
|
|
- private UploadBroadcastReceiver broadcastReceiver;
|
|
|
|
|
-
|
|
|
|
|
private RAUploadManager uploadManager;
|
|
private RAUploadManager uploadManager;
|
|
|
private UploadService.MyBinder binder;
|
|
private UploadService.MyBinder binder;
|
|
|
private UploadService uploadServiceservice;
|
|
private UploadService uploadServiceservice;
|
|
@@ -142,15 +147,9 @@ public class UploadListActivity extends AppCompatActivity {
|
|
|
mActionBar.setDisplayHomeAsUpEnabled(true);
|
|
mActionBar.setDisplayHomeAsUpEnabled(true);
|
|
|
mActionBar.setTitle("RA Image");
|
|
mActionBar.setTitle("RA Image");
|
|
|
|
|
|
|
|
- // 注册广播接收
|
|
|
|
|
- broadcastManager = LocalBroadcastManager.getInstance(this);
|
|
|
|
|
- IntentFilter intentFilter = new IntentFilter();
|
|
|
|
|
- intentFilter.addAction("");
|
|
|
|
|
- broadcastReceiver = new UploadBroadcastReceiver();
|
|
|
|
|
- broadcastManager.registerReceiver(broadcastReceiver,intentFilter);
|
|
|
|
|
|
|
|
|
|
// 初始化视图
|
|
// 初始化视图
|
|
|
- uploadList = (ListView)findViewById(R.id.upload_list);
|
|
|
|
|
|
|
+ uploadList = (SwipeMenuListView)findViewById(R.id.upload_list);
|
|
|
|
|
|
|
|
serviceConnection = new ServiceConnection() {
|
|
serviceConnection = new ServiceConnection() {
|
|
|
@Override
|
|
@Override
|
|
@@ -167,7 +166,7 @@ public class UploadListActivity extends AppCompatActivity {
|
|
|
runOnUiThread(new Runnable() {
|
|
runOnUiThread(new Runnable() {
|
|
|
@Override
|
|
@Override
|
|
|
public void run() {
|
|
public void run() {
|
|
|
- adapter = new uploadAdapter(UploadListActivity.this,R.layout.upload_list_cell,arr);
|
|
|
|
|
|
|
+ adapter = new uploadAdapter(R.layout.upload_list_cell);
|
|
|
uploadList.setAdapter(adapter);
|
|
uploadList.setAdapter(adapter);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
@@ -182,7 +181,107 @@ public class UploadListActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
bindService();
|
|
bindService();
|
|
|
|
|
|
|
|
|
|
+ SwipeMenuCreator creator = new SwipeMenuCreator() {
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void create(SwipeMenu menu) {
|
|
|
|
|
+ // Create different menus depending on the view type
|
|
|
|
|
+ switch (menu.getViewType()) {
|
|
|
|
|
+ case 0: {
|
|
|
|
|
+ createRemoveMenuItem(menu);
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 1: {
|
|
|
|
|
+ createStartMenuItem(menu);
|
|
|
|
|
+ createRemoveMenuItem(menu);
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 2: {
|
|
|
|
|
+ createStartMenuItem(menu);
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 3: {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ uploadList.setMenuCreator(creator);
|
|
|
|
|
+
|
|
|
|
|
+ uploadList.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
|
|
|
|
|
+ // action
|
|
|
|
|
+ Bundle item = arr.get(position);
|
|
|
|
|
+ int type = taskSwipeType(position);
|
|
|
|
|
+ switch (type) {
|
|
|
|
|
+ case 0: {
|
|
|
|
|
+ if (index == 0) {
|
|
|
|
|
+ // remove
|
|
|
|
|
+ uploadManager.removeTask(item);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 1: {
|
|
|
|
|
+ if (index == 0) {
|
|
|
|
|
+ // start
|
|
|
|
|
+ uploadManager.startTask(item);
|
|
|
|
|
+ } else if (index == 1) {
|
|
|
|
|
+ // remove
|
|
|
|
|
+ uploadManager.removeTask(item);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 2: {
|
|
|
|
|
+ if (index == 0) {
|
|
|
|
|
+ // start
|
|
|
|
|
+ uploadManager.startTask(item);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 3: {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void createRemoveMenuItem(SwipeMenu menu) {
|
|
|
|
|
+ SwipeMenuItem openItem = new SwipeMenuItem(getApplicationContext());
|
|
|
|
|
+ // set item background
|
|
|
|
|
+ openItem.setBackground(new ColorDrawable(Color.rgb(0x9b, 0xbf,0x5a)));
|
|
|
|
|
+ // set item width
|
|
|
|
|
+ openItem.setWidth(dp2px(90));
|
|
|
|
|
+ // set item title
|
|
|
|
|
+ openItem.setTitle("Remove");
|
|
|
|
|
+ // set item title fontsize
|
|
|
|
|
+ openItem.setTitleSize(18);
|
|
|
|
|
+ // set item title font color
|
|
|
|
|
+ openItem.setTitleColor(Color.WHITE);
|
|
|
|
|
+ // add to menu
|
|
|
|
|
+ menu.addMenuItem(openItem);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ private void createStartMenuItem(SwipeMenu menu) {
|
|
|
|
|
+ SwipeMenuItem openItem = new SwipeMenuItem(getApplicationContext());
|
|
|
|
|
+ // set item background
|
|
|
|
|
+ openItem.setBackground(new ColorDrawable(Color.rgb(0xff, 0x99,0x33)));
|
|
|
|
|
+ // set item width
|
|
|
|
|
+ openItem.setWidth(dp2px(90));
|
|
|
|
|
+ // set item title
|
|
|
|
|
+ openItem.setTitle("Restart");
|
|
|
|
|
+ // set item title fontsize
|
|
|
|
|
+ openItem.setTitleSize(18);
|
|
|
|
|
+ // set item title font color
|
|
|
|
|
+ openItem.setTitleColor(Color.WHITE);
|
|
|
|
|
+ // add to menu
|
|
|
|
|
+ menu.addMenuItem(openItem);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -193,6 +292,12 @@ public class UploadListActivity extends AppCompatActivity {
|
|
|
super.onDestroy();
|
|
super.onDestroy();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
|
+ getMenuInflater().inflate(R.menu.upload_list_menu,menu);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
switch (item.getItemId()) {
|
|
switch (item.getItemId()) {
|
|
@@ -200,17 +305,110 @@ public class UploadListActivity extends AppCompatActivity {
|
|
|
finish();
|
|
finish();
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
|
|
+ case R.id.clear_upload_list_btn: {
|
|
|
|
|
+ clearUploadList();
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
}
|
|
}
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private class uploadAdapter extends ArrayAdapter<Bundle> {
|
|
|
|
|
|
|
+ private void clearUploadList() {
|
|
|
|
|
+ if (uploadManager.arr_queue.size() == 0) {
|
|
|
|
|
+ new AlertDialog.Builder(this)
|
|
|
|
|
+ .setTitle("Warning")
|
|
|
|
|
+ .setMessage("Upload list is empty.")
|
|
|
|
|
+ .setPositiveButton("OK",null)
|
|
|
|
|
+ .show();
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ new AlertDialog.Builder(this)
|
|
|
|
|
+ .setTitle("Clear upload list")
|
|
|
|
|
+ .setMessage("Are you sure remove all error/finish task?")
|
|
|
|
|
+ .setPositiveButton("YES", new DialogInterface.OnClickListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
+ // clear
|
|
|
|
|
+ uploadManager.clearTask();
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .setNegativeButton("NO", new DialogInterface.OnClickListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .show();
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private int taskSwipeType(int position) {
|
|
|
|
|
+ Bundle item = arr.get(position);
|
|
|
|
|
+ Bundle taskinfo = item.getBundle("params");
|
|
|
|
|
+ RAUploadManager.TaskStatus istatus = RAUploadManager.TaskStatus.values()[taskinfo.getInt("status",0)];
|
|
|
|
|
+ int type = 3;
|
|
|
|
|
+ switch(istatus)
|
|
|
|
|
+ {
|
|
|
|
|
+ case TaskStatusWait:
|
|
|
|
|
+ case TaskStatusStart:
|
|
|
|
|
+ type = 3;
|
|
|
|
|
+ break;
|
|
|
|
|
+ case TaskStatusStop:
|
|
|
|
|
+ type = 2;
|
|
|
|
|
+ break;
|
|
|
|
|
+ case TaskStatusError:
|
|
|
|
|
+ type = 1;
|
|
|
|
|
+ break;
|
|
|
|
|
+ case TaskStatusFinish:
|
|
|
|
|
+ type = 0;
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ type = 3;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ return type;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private class uploadAdapter extends BaseAdapter {
|
|
|
private int resourceId;
|
|
private int resourceId;
|
|
|
- public uploadAdapter(Context ctx, int resourceID, List<Bundle> objects) {
|
|
|
|
|
- super(ctx,resourceID,objects);
|
|
|
|
|
|
|
+ public uploadAdapter(int resourceID) {
|
|
|
|
|
+
|
|
|
resourceId = resourceID;
|
|
resourceId = resourceID;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int getCount() {
|
|
|
|
|
+ return arr.size();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Bundle getItem(int position) {
|
|
|
|
|
+ return arr.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
|
|
@NonNull
|
|
|
@Override
|
|
@Override
|
|
|
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
|
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
|
@@ -255,7 +453,7 @@ public class UploadListActivity extends AppCompatActivity {
|
|
|
holder = (ViewHolder)cell.getTag();
|
|
holder = (ViewHolder)cell.getTag();
|
|
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
- cell = LayoutInflater.from(getContext()).inflate(resourceId,null);
|
|
|
|
|
|
|
+ cell = LayoutInflater.from(getApplicationContext()).inflate(resourceId,null);
|
|
|
|
|
|
|
|
holder = new ViewHolder();
|
|
holder = new ViewHolder();
|
|
|
holder.name_tv = (TextView)cell.findViewById(R.id.upload_name_tv);
|
|
holder.name_tv = (TextView)cell.findViewById(R.id.upload_name_tv);
|
|
@@ -285,21 +483,6 @@ public class UploadListActivity extends AppCompatActivity {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /** Broadcast */
|
|
|
|
|
- private class UploadBroadcastReceiver extends BroadcastReceiver {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onReceive(Context context, Intent intent) {
|
|
|
|
|
- int index = 0;
|
|
|
|
|
- // item: Model数据
|
|
|
|
|
- Object item = uploadList.getItemAtPosition(index);
|
|
|
|
|
- int startShowIndex = uploadList.getFirstVisiblePosition();
|
|
|
|
|
- int lastShowIndex = uploadList.getLastVisiblePosition();
|
|
|
|
|
- if (index >= startShowIndex && index <= lastShowIndex) {
|
|
|
|
|
- View cell = uploadList.getChildAt(index - startShowIndex);
|
|
|
|
|
- uploadAdapter.ViewHolder holder= (uploadAdapter.ViewHolder)cell.getTag();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
/** Service */
|
|
/** Service */
|
|
|
private void bindService() {
|
|
private void bindService() {
|
|
@@ -307,4 +490,8 @@ public class UploadListActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
|
|
bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private int dp2px(int dp) {
|
|
|
|
|
+ return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,getResources().getDisplayMetrics());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|