Ejemplo n.º 1
0
 public PcaAsyncTask(Context context, List<String> files, int numComponents) {
   super(context);
   mFiles = files;
   mFileManager = FileManager.getSingleton(context);
   mNumComponents = numComponents;
   mShowComponentsMsg = false;
 }
  @Override
  public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    fileManager = FileManager.getSingleton(getContext());

    DeviceConnectionListener listener = null;
    Bundle args = getArguments();
    if (args != null) {
      fromDevice = args.getBoolean(ARG_FROM_DEVICE);
      if (fromDevice) {
        listener = this;
      }
    }
    usbConn = UsbConnection.getSingleton(getContext(), listener);

    mainHandler = new Handler(getContext().getMainLooper());
  }
Ejemplo n.º 3
0
  private void createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    view = inflater.inflate(R.layout.fragment_pca_tab, container, false);

    layoutProgress = view.findViewById(R.id.layoutProgress);
    layoutProgress.setVisibility(View.GONE);

    layoutPCAGraphOptions = view.findViewById(R.id.layoutPCAGraphOptions);
    layoutPCAGraphOptions.setVisibility(View.GONE);

    listFiles = (ListView) view.findViewById(R.id.listArquivos);

    txtComponentes = (TextView) view.findViewById(R.id.txtComponentes);
    txtComponentes.setText("20");

    seekComponentes = (SeekBar) view.findViewById(R.id.seekComponentes);
    seekComponentes.setOnSeekBarChangeListener(
        new SeekBar.OnSeekBarChangeListener() {
          @Override
          public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (progress == 0) {
              seekBar.setProgress(1);
              progress = 1;
            }
            txtComponentes.setText(String.valueOf(progress));
          }

          @Override
          public void onStartTrackingTouch(SeekBar seekBar) {}

          @Override
          public void onStopTrackingTouch(SeekBar seekBar) {
            // TODO
            numComponentes = seekBar.getProgress();
          }
        });
    seekComponentes.setProgress(20);
    numComponentes = 20;

    btnPCA = (Button) view.findViewById(R.id.btnPCA);
    btnPCA.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            // TODO:
            btnPCA.setEnabled(false);

            ArrayList<String> files = new ArrayList<>();

            SparseBooleanArray checkedPositions = listFiles.getCheckedItemPositions();
            for (int i = 0; i < listFiles.getCount(); i++) {
              if (checkedPositions.get(i)) {
                String strFile = (String) listFiles.getItemAtPosition(i);
                if (!TextUtils.isEmpty(strFile)) {
                  files.add(strFile);
                } else {
                  // TODO:
                }
              }
            }

            if (files.isEmpty()) {
              // TODO: show alert, need to select at least one file
              return;
            }

            Bundle args = new Bundle();
            args.putStringArrayList(ARG_FILENAMES, files);
            getLoaderManager().restartLoader(LOADER_PCA, args, PcaTabFragment.this).forceLoad();
          }
        });

    radioGroupMatrizes = (RadioGroup) view.findViewById(R.id.radioGroupMatrizes);
    radioMatrizesL = (RadioButton) view.findViewById(R.id.radioMatrizesL);
    radioMatrizesL.setChecked(true);

    spinX = (Spinner) view.findViewById(R.id.spinX);
    spinY = (Spinner) view.findViewById(R.id.spinY);

    btnPlotPCA = (Button) view.findViewById(R.id.btnPlotPCA);
    btnPlotPCA.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            ChartCollection collection = null;

            switch (radioGroupMatrizes.getCheckedRadioButtonId()) {
              case R.id.radioMatrizesL:
                collection = chartCollections.get("L");
                break;
              case R.id.radioMatrizesT:
                collection = chartCollections.get("T");
                break;
            }

            if (collection != null) {
              int x = spinX.getSelectedItemPosition();
              int y = spinY.getSelectedItemPosition();

              ChartCollection finalCollection =
                  new ChartCollection(String.format("PCA - (%d, %d)", x, y));
              Map<Double, Double> data = new HashMap<>();
              for (ChartData chartData : collection) {
                // TODO:
                Number numX = chartData.getData().get((double) x);
                data.put(numX.doubleValue(), chartData.getData().get((double) y));
              }
              ChartData chartData = new ChartData("PCA", "PCA", new Date().getTime(), data);
              finalCollection.addChartData(chartData);

              listener.onPlotChart(finalCollection);
            }
          }
        });

    fileManager = FileManager.getSingleton(getContext());

    if (fileManager.askForStoragePermission(
        getActivity(), REQUEST_FILE_PERMISSION, Manifest.permission.READ_EXTERNAL_STORAGE)) {
      fillFilesListView();
    }

    mShortAnimationDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);
  }