package com.thingple.tagservice.view;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;

import com.thingple.tag.operator.DeviceApp;
import com.thingple.tag.wrapper.R;
import com.thingple.tagservice.device.DeviceCategory;
import com.thingple.tagservice.device.context.DeviceContext;


public class InventoryActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_inventory);
        doInventory(getApp(), getPower());
    }

    private void resultToParent() {
        Intent intent = new Intent();
        setResult(0, intent);
        finish();
    }

    private void doInventory(final DeviceApp app, final int power) {
        Bundle bundle = getIntent().getExtras();
        String filter = null;
        if (bundle != null) {
            filter = bundle.getString("filter");
            filter = filter == null || filter.trim().equals("") ? null : filter;
        }
        final String filterExp = filter;
        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                DeviceContext deviceContext = getDeviceContext(app);
                if (deviceContext != null) {
                    Log.d("inventory_view", "-->设备正常,开始Inventory");
                    deviceContext.inventoryStart(filterExp, power, DeviceCategory.UHF);
                    resultToParent();
                } else {
                    Log.d("inventory_view", "等待设备启动");
                    handler.postDelayed(this, 1000);
                }
            }
        }, 1000);
    }
}

@@ -888,16 +888,48 @@
 = null;%0A
+        String category = null;%0A
         
@@ -942,32 +942,32 @@
 ndle != null) %7B%0A
-
             filt
@@ -1072,32 +1072,188 @@
  null : filter;%0A
+            category = bundle.getString(%22category%22);%0A            category = category == null %7C%7C category.trim().equals(%22%22) ? DeviceCategory.UHF : category;%0A
         %7D%0A      
@@ -1279,32 +1279,80 @@
 erExp = filter;%0A
+        final String deviceCategory = category;%0A
         final Ha
@@ -1730,17 +1730,17 @@
  power, 
-D
+d
 eviceCat
@@ -1744,20 +1744,16 @@
 Category
-.UHF
 );%0A     

add param inventory:category