Search in sources :

Example 1 with IO

use of com.cpjd.roblu.io.IO in project Roblu by wdavies973.

the class MetricEditor method buildConfigLayout.

/**
 * Adds the config text fields below the metric preview
 */
private void buildConfigLayout() {
    // clear old config items (don't clear toolbar, preview metric, or metric type selector)
    for (int i = 3; i < this.layout.getChildCount(); i++) {
        this.layout.removeViewAt(i);
    }
    RelativeLayout layout = new RelativeLayout(this);
    layout.addView(getConfigField("Title", layout, 0));
    if (metric instanceof RCheckbox || metric instanceof RChooser) {
        layout.addView(getConfigField("Comma separated list", layout, 1));
    } else if (metric instanceof RCounter) {
        final TextInputLayout til = getConfigField("Increment", layout, 1);
        til.setId(Utils.generateViewId());
        layout.addView(til);
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        params.addRule(RelativeLayout.BELOW, til.getId());
        CheckBox checkBox = new CheckBox(getApplicationContext());
        checkBox.setId(Utils.generateViewId());
        checkBox.setLayoutParams(params);
        checkBox.setHighlightColor(rui.getAccent());
        checkBox.setTextColor(rui.getText());
        checkBox.setText("Verbose input");
        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                ((RCounter) metric).setVerboseInput(isChecked);
                addMetricPreviewToToolbar();
            }
        });
        ColorStateList colorStateList = new ColorStateList(new int[][] { // unchecked
        new int[] { -android.R.attr.state_checked }, // checked
        new int[] { android.R.attr.state_checked } }, new int[] { rui.getButtons(), rui.getAccent() });
        CompoundButtonCompat.setButtonTintList(checkBox, colorStateList);
        layout.addView(checkBox);
    } else if (metric instanceof RSlider) {
        layout.addView(getConfigField("Minimum", layout, 1));
        layout.addView(getConfigField("Maximum", layout, 2));
    } else if (metric instanceof RCalculation) {
        final TextInputLayout til = getConfigField("Calculation", layout, 1);
        layout.addView(til);
        // Also add a button for inputting metric names
        Button b = new Button(getApplicationContext());
        b.setText("Add metric");
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        params.addRule(RelativeLayout.BELOW, til.getId());
        b.setLayoutParams(params);
        layout.addView(b);
        b.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                final Dialog d = new Dialog(MetricEditor.this);
                d.setTitle("Pick metric:");
                d.setContentView(R.layout.metric_chooser);
                final Spinner spinner = d.findViewById(R.id.type);
                String[] values;
                final ArrayList<RMetric> metrics;
                if (tab == 0)
                    metrics = form.getPit();
                else
                    metrics = form.getMatch();
                // Remove all but counters, stopwatches, and sliders
                for (int i = 0; i < metrics.size(); i++) {
                    if (!(metrics.get(i) instanceof RCounter) && !(metrics.get(i) instanceof RStopwatch && !(metrics.get(i) instanceof RSlider)) && !(metrics.get(i) instanceof RCalculation)) {
                        metrics.remove(i);
                        i--;
                    }
                }
                values = new String[metrics.size()];
                for (int i = 0; i < metrics.size(); i++) {
                    values[i] = metrics.get(i).getTitle();
                }
                ArrayAdapter<String> adp = new ArrayAdapter<>(getApplicationContext(), android.R.layout.simple_list_item_1, values);
                adp.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                spinner.setAdapter(adp);
                Button button = d.findViewById(R.id.button7);
                button.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        try {
                            RMetric m = new ArrayList<>(metrics).get(spinner.getSelectedItemPosition());
                            til.getEditText().setText(til.getEditText().getText().toString() + " " + m.getTitle());
                        } catch (Exception e) {
                            Log.d("RBS", "Failed to select metric");
                        } finally {
                            d.dismiss();
                        }
                    }
                });
                if (d.getWindow() != null)
                    d.getWindow().getAttributes().windowAnimations = new IO(getApplicationContext()).loadSettings().getRui().getAnimation();
                d.show();
            }
        });
    }
    this.layout.addView(getCardView(layout));
}
Also used : Spinner(android.widget.Spinner) ArrayList(java.util.ArrayList) ColorStateList(android.content.res.ColorStateList) RMetric(com.cpjd.roblu.models.metrics.RMetric) RCalculation(com.cpjd.roblu.models.metrics.RCalculation) RCheckbox(com.cpjd.roblu.models.metrics.RCheckbox) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) Dialog(android.app.Dialog) RSlider(com.cpjd.roblu.models.metrics.RSlider) TextInputLayout(android.support.design.widget.TextInputLayout) RChooser(com.cpjd.roblu.models.metrics.RChooser) IO(com.cpjd.roblu.io.IO) View(android.view.View) AdapterView(android.widget.AdapterView) CardView(android.support.v7.widget.CardView) TextView(android.widget.TextView) RStopwatch(com.cpjd.roblu.models.metrics.RStopwatch) CheckBox(android.widget.CheckBox) RelativeLayout(android.widget.RelativeLayout) RCounter(com.cpjd.roblu.models.metrics.RCounter) CompoundButton(android.widget.CompoundButton) ArrayAdapter(android.widget.ArrayAdapter)

Example 2 with IO

use of com.cpjd.roblu.io.IO in project Roblu by wdavies973.

the class PredefinedFormSelector method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        setResult(Constants.CANCELLED);
        finish();
        return true;
    }
    if (item.getItemId() == R.id.preview) {
        previewModeEnabled = !previewModeEnabled;
        if (previewModeEnabled)
            Utils.showSnackbar(findViewById(R.id.activity_predefined_layout), getApplicationContext(), "Preview mode enabled", false, new IO(getApplicationContext()).loadSettings().getRui().getPrimaryColor());
        else
            Utils.showSnackbar(findViewById(R.id.activity_predefined_layout), getApplicationContext(), "Preview mode disabled", false, new IO(getApplicationContext()).loadSettings().getRui().getPrimaryColor());
    }
    return false;
}
Also used : IO(com.cpjd.roblu.io.IO)

Example 3 with IO

use of com.cpjd.roblu.io.IO in project Roblu by wdavies973.

the class Drawing method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_drawing);
    rui = new IO(getApplicationContext()).loadSettings().getRui();
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    if (getSupportActionBar() != null)
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    DisplayMetrics displayMetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    position = getIntent().getIntExtra("position", 0);
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPreferredConfig = Bitmap.Config.ARGB_8888;
    View content = getWindow().findViewById(Window.ID_ANDROID_CONTENT);
    int temp = 0;
    if (content != null)
        temp = content.getHeight();
    if (getIntent().getBooleanExtra("fieldDiagram", false)) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        this.canvas = this.findViewById(R.id.canvas);
        // Load image
        if (getIntent().getByteArrayExtra("fieldDrawings") != null) {
            Bitmap b = BitmapFactory.decodeByteArray(getIntent().getByteArrayExtra("fieldDrawings"), 0, getIntent().getByteArrayExtra("fieldDrawings").length);
            Bitmap bitmap = Bitmap.createScaledBitmap(b, displayMetrics.widthPixels, displayMetrics.heightPixels - toolbar.getHeight() - temp, false);
            if (bitmap != null)
                this.canvas.drawBitmap(bitmap);
        }
        LinearLayout layout = findViewById(R.id.drawing_layout);
        layout.setBackgroundResource(getIntent().getIntExtra("fieldDiagramID", R.drawable.field2018));
        this.canvas.setBaseColor(rui.getBackground());
        this.canvas.setPaintStrokeWidth(7F);
        canvas.setPaintStrokeColor(Color.YELLOW);
    } else {
        // Load image
        Bitmap b = BitmapFactory.decodeByteArray(ImageGalleryActivity.IMAGES.get(position), 0, ImageGalleryActivity.IMAGES.get(position).length);
        Bitmap bitmap = Bitmap.createScaledBitmap(b, displayMetrics.widthPixels, displayMetrics.heightPixels - toolbar.getHeight() - temp, false);
        this.canvas = this.findViewById(R.id.canvas);
        this.canvas.setBaseColor(rui.getBackground());
        if (bitmap != null)
            this.canvas.drawBitmap(bitmap);
        this.canvas.setPaintStrokeWidth(7F);
    }
}
Also used : Bitmap(android.graphics.Bitmap) IO(com.cpjd.roblu.io.IO) BitmapFactory(android.graphics.BitmapFactory) DisplayMetrics(android.util.DisplayMetrics) View(android.view.View) CanvasView(com.android.graphics.CanvasView) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout) Toolbar(android.support.v7.widget.Toolbar)

Example 4 with IO

use of com.cpjd.roblu.io.IO in project Roblu by wdavies973.

the class ImageGalleryActivity method onClick.

/**
 * The user clicked the plus button and wants to add a new image
 * @param v the floating action button that was clicked
 */
@Override
public void onClick(View v) {
    if (!editable)
        return;
    if (EasyPermissions.hasPermissions(this, android.Manifest.permission.CAMERA)) {
        tempPictureFile = new IO(getApplicationContext()).getTempPictureFile();
        Uri fileUri = FileProvider.getUriForFile(getApplicationContext(), "com.cpjd.roblu", tempPictureFile);
        Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        camera.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
        startActivityForResult(camera, Constants.GENERAL);
    } else {
        Utils.showSnackbar(layout, getApplicationContext(), "Camera permission is disabled. Please enable it.", true, 0);
    }
}
Also used : IO(com.cpjd.roblu.io.IO) Intent(android.content.Intent) Uri(android.net.Uri)

Example 5 with IO

use of com.cpjd.roblu.io.IO in project Roblu by wdavies973.

the class SetupActivity method onClick.

@Override
public void onClick(View v) {
    switch(v.getId()) {
        case R.id.ytube:
            startActivity(new Intent(this, Tutorial.class));
            break;
        case R.id.welcome_next_page:
            pager.goToNextPage();
            break;
        case R.id.bluetooth_next_page:
            pager.goToNextPage();
            break;
        case R.id.permissions_next_page:
            if (android.os.Build.VERSION.SDK_INT < 23) {
                // Below API Level 23 doesn't require asking for permissions
                pager.goToNextPage();
                break;
            }
            String[] perms = { Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE };
            ActivityCompat.requestPermissions(this, perms, 0);
            break;
        case R.id.number_next:
            EditText et = findViewById(R.id.number_input);
            EditText et2 = findViewById(R.id.team_code_input);
            try {
                RSettings settings = new IO(getApplicationContext()).loadSettings();
                settings.setTeamNumber(Integer.parseInt(et.getText().toString()));
                settings.setCode(et2.getText().toString());
                new IO(getApplicationContext()).saveSettings(settings);
            } catch (Exception e) {
                try {
                    RSettings settings = new IO(getApplicationContext()).loadSettings();
                    settings.setTeamNumber(0);
                    new IO(getApplicationContext()).saveSettings(settings);
                } catch (Exception e2) {
                    Log.d("RBS", "Failed to save team number.");
                }
                Log.d("RBS", "Failed to save team number.");
            }
            pager.goToNextPage();
            break;
        case R.id.finished_next:
            setupFinished();
            break;
    }
}
Also used : EditText(android.widget.EditText) Tutorial(com.cpjd.roblu.ui.tutorials.Tutorial) IO(com.cpjd.roblu.io.IO) Intent(android.content.Intent) RSettings(com.cpjd.roblu.models.RSettings)

Aggregations

IO (com.cpjd.roblu.io.IO)59 TextView (android.widget.TextView)18 Intent (android.content.Intent)15 View (android.view.View)14 ArrayList (java.util.ArrayList)13 REvent (com.cpjd.roblu.models.REvent)11 Toolbar (android.support.v7.widget.Toolbar)10 RForm (com.cpjd.roblu.models.RForm)10 RTeam (com.cpjd.roblu.models.RTeam)10 RUI (com.cpjd.roblu.models.RUI)10 RCheckout (com.cpjd.roblu.models.RCheckout)8 RTab (com.cpjd.roblu.models.RTab)8 RMetric (com.cpjd.roblu.models.metrics.RMetric)8 UIHandler (com.cpjd.roblu.ui.UIHandler)8 RecyclerView (android.support.v7.widget.RecyclerView)7 Dialog (android.app.Dialog)6 Bundle (android.os.Bundle)6 Button (android.widget.Button)6 RSettings (com.cpjd.roblu.models.RSettings)6 AlertDialog (android.app.AlertDialog)5