|
@@ -0,0 +1,126 @@
|
|
|
|
|
+package com.usai.redant.raimage.UploadList;
|
|
|
|
|
+
|
|
|
|
|
+import android.content.BroadcastReceiver;
|
|
|
|
|
+import android.content.Context;
|
|
|
|
|
+import android.content.Intent;
|
|
|
|
|
+import android.content.IntentFilter;
|
|
|
|
|
+import android.support.annotation.NonNull;
|
|
|
|
|
+import android.support.annotation.Nullable;
|
|
|
|
|
+import android.support.v4.content.LocalBroadcastManager;
|
|
|
|
|
+import android.support.v7.app.ActionBar;
|
|
|
|
|
+import android.support.v7.app.AppCompatActivity;
|
|
|
|
|
+import android.os.Bundle;
|
|
|
|
|
+import android.view.LayoutInflater;
|
|
|
|
|
+import android.view.MenuItem;
|
|
|
|
|
+import android.view.View;
|
|
|
|
|
+import android.view.ViewGroup;
|
|
|
|
|
+import android.widget.ArrayAdapter;
|
|
|
|
|
+import android.widget.ListView;
|
|
|
|
|
+import android.widget.ProgressBar;
|
|
|
|
|
+import android.widget.TextView;
|
|
|
|
|
+
|
|
|
|
|
+import com.usai.redant.raimage.R;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+public class UploadListActivity extends AppCompatActivity {
|
|
|
|
|
+
|
|
|
|
|
+ private ListView uploadList;
|
|
|
|
|
+ private uploadAdapter adapter;
|
|
|
|
|
+
|
|
|
|
|
+ private LocalBroadcastManager broadcastManager;
|
|
|
|
|
+ private UploadBroadcastReceiver broadcastReceiver;
|
|
|
|
|
+ @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("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.setAdapter(adapter);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
|
+ switch (item.getItemId()) {
|
|
|
|
|
+ case android.R.id.home: {
|
|
|
|
|
+ finish();
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private class uploadAdapter extends ArrayAdapter<Bundle> {
|
|
|
|
|
+ private int resourceId;
|
|
|
|
|
+ public uploadAdapter(Context ctx, int resourceID, List<Bundle> objects) {
|
|
|
|
|
+ super(ctx,resourceID,objects);
|
|
|
|
|
+ resourceId = resourceID;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @NonNull
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
|
|
|
|
+
|
|
|
|
|
+ View cell;
|
|
|
|
|
+ ViewHolder holder;
|
|
|
|
|
+ if (convertView != null) {
|
|
|
|
|
+
|
|
|
|
|
+ cell = convertView;
|
|
|
|
|
+ holder = (ViewHolder)cell.getTag();
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ cell = LayoutInflater.from(getContext()).inflate(resourceId,null);
|
|
|
|
|
+
|
|
|
|
|
+ holder = new ViewHolder();
|
|
|
|
|
+ holder.name_tv = (TextView)cell.findViewById(R.id.upload_name_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);
|
|
|
|
|
+
|
|
|
|
|
+ cell.setTag(holder);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return cell;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private class ViewHolder {
|
|
|
|
|
+ public TextView name_tv;
|
|
|
|
|
+ public ProgressBar progressBar;
|
|
|
|
|
+ public TextView state_tv;
|
|
|
|
|
+ public TextView progress_tv;
|
|
|
|
|
+ public TextView err_tv;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ 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();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|