Search in sources :

Example 31 with IO

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

the class PredefinedFormSelector method onItemClick.

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    RForm form = forms.get(position);
    if (form == null)
        return;
    if (previewModeEnabled) {
        new IO(getApplicationContext()).createPreview(form);
        Intent intent = new Intent(this, TeamViewer.class);
        intent.putExtra("teamID", -1);
        intent.putExtra("eventID", -1);
        intent.putExtra("editable", false);
        startActivity(intent);
        return;
    }
    Intent intent = new Intent();
    intent.putExtra("form", form);
    setResult(Constants.PREDEFINED_FORM_SELECTED, intent);
    finish();
}
Also used : RForm(com.cpjd.roblu.models.RForm) IO(com.cpjd.roblu.io.IO) Intent(android.content.Intent)

Example 32 with IO

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

the class RMetricToUI method getGallery.

/**
 * Gets the Gallery UI card from an RGallery reference
 * @param gallery RGallery reference to be set to the UI
 * @return a UI CardView
 */
public CardView getGallery(final boolean demo, final int tabIndex, final int eventID, final RGallery gallery) {
    RelativeLayout layout = new RelativeLayout(activity);
    TextView textView = new TextView(activity);
    textView.setTextColor(rui.getText());
    textView.setText(gallery.getTitle());
    textView.setId(Utils.generateViewId());
    textView.setMaxWidth(width / 3);
    textView.setWidth(width);
    textView.setMaxLines(1);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22);
    Button open = new Button(activity);
    open.setText(R.string.open);
    open.setTextColor(rui.getText());
    open.setId(Utils.generateViewId());
    open.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (demo)
                return;
            /*
                 * Load images from disk into memory
                 */
            IO io = new IO(activity);
            ImageGalleryActivity.IMAGES = new ArrayList<>();
            for (int i = 0; gallery.getPictureIDs() != null && i < gallery.getPictureIDs().size(); i++) {
                ImageGalleryActivity.IMAGES.add(io.loadPicture(eventID, gallery.getPictureIDs().get(i)));
            }
            ImageGalleryActivity.setImageThumbnailLoader(RMetricToUI.this);
            FullScreenImageGalleryActivity.setFullScreenImageLoader(RMetricToUI.this);
            Intent intent = new Intent(activity, ImageGalleryActivity.class);
            Bundle bundle = new Bundle();
            bundle.putString("title", gallery.getTitle());
            bundle.putInt("galleryID", gallery.getID());
            bundle.putInt("eventID", eventID);
            bundle.putInt("rTabIndex", tabIndex);
            bundle.putBoolean("editable", editable);
            intent.putExtras(bundle);
            activity.startActivityForResult(intent, Constants.GENERAL);
        }
    });
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    params.addRule(RelativeLayout.CENTER_VERTICAL);
    open.setLayoutParams(params);
    open.setPadding(open.getPaddingLeft(), open.getPaddingTop(), Utils.DPToPX(activity, 6), open.getPaddingBottom());
    params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.CENTER_VERTICAL);
    textView.setPadding(Utils.DPToPX(activity, 8), textView.getPaddingTop(), textView.getPaddingRight(), textView.getPaddingBottom());
    textView.setLayoutParams(params);
    layout.setTag(gallery.getID());
    layout.addView(textView);
    layout.addView(open);
    return getCard(layout);
}
Also used : ImageGalleryActivity(com.cpjd.roblu.ui.images.ImageGalleryActivity) FullScreenImageGalleryActivity(com.cpjd.roblu.ui.images.FullScreenImageGalleryActivity) IO(com.cpjd.roblu.io.IO) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) CardView(android.support.v7.widget.CardView) TextView(android.widget.TextView) RadioButton(android.widget.RadioButton) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) AppCompatRadioButton(android.support.v7.widget.AppCompatRadioButton) RelativeLayout(android.widget.RelativeLayout) TextView(android.widget.TextView)

Example 33 with IO

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

the class FullScreenImageGalleryActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        onBackPressed();
        return true;
    } else /*
         * User wants to delete an image
         */
    if (item.getItemId() == R.id.delete_image && editable) {
        Intent result = new Intent();
        result.putExtra("position", viewPager.getCurrentItem());
        setResult(Constants.IMAGE_DELETED, result);
        finish();
        return true;
    } else /*
         * User wants to do some drawing!
         */
    if (item.getItemId() == com.cpjd.roblu.R.id.edit && editable) {
        Intent intent = new Intent(this, com.cpjd.roblu.ui.images.Drawing.class);
        intent.putExtra("position", position);
        startActivityForResult(intent, Constants.GENERAL);
        return true;
    } else /*
         * User wants to save the image to the local gallery
         */
    if (item.getItemId() == com.cpjd.roblu.R.id.save_to_device) {
        if (EasyPermissions.hasPermissions(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
            byte[] path = ImageGalleryActivity.IMAGES.get(viewPager.getCurrentItem());
            Bitmap bitmap = BitmapFactory.decodeByteArray(path, 0, path.length);
            MediaStore.Images.Media.insertImage(getContentResolver(), bitmap, String.valueOf(System.currentTimeMillis()), "");
            Utils.showSnackbar(findViewById(R.id.full_screen_activity), getApplicationContext(), "Saved image to device", false, new IO(getApplicationContext()).loadSettings().getRui().getPrimaryColor());
        } else {
            Utils.showSnackbar(findViewById(R.id.full_screen_activity), getApplicationContext(), "Storage permission is disabled. Please enable it.", true, 0);
        }
        return true;
    } else {
        return super.onOptionsItemSelected(item);
    }
}
Also used : Bitmap(android.graphics.Bitmap) IO(com.cpjd.roblu.io.IO) Intent(android.content.Intent)

Example 34 with IO

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

the class ImageGalleryActivity method onActivityResult.

/**
 * Receives the picture that was taken by the user
 * @param requestCode the request code of the child activity
 * @param resultCode the result code of the child activity
 * @param data the picture that was taken
 */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == Constants.GENERAL && resultCode == FragmentActivity.RESULT_OK) {
        // fetch file from storage
        Bitmap bitmap = BitmapFactory.decodeFile(tempPictureFile.getPath());
        // fix rotation
        try {
            ExifInterface ei = new ExifInterface(tempPictureFile.getPath());
            int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
            switch(orientation) {
                case ExifInterface.ORIENTATION_ROTATE_90:
                    bitmap = rotateImage(bitmap, 90);
                    break;
                case ExifInterface.ORIENTATION_ROTATE_180:
                    bitmap = rotateImage(bitmap, 180);
                    break;
                case ExifInterface.ORIENTATION_ROTATE_270:
                    bitmap = rotateImage(bitmap, 270);
                    break;
                default:
                    break;
            }
        } catch (IOException e) {
            Log.d("RBS", "Failed to remove EXIF rotation data from the picture.");
        }
        /*
             * Convert the image into a byte[] and save it to the gallery
             */
        // Convert the bitmap to a byte array
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 30, stream);
        byte[] array = stream.toByteArray();
        int newID = new IO(getApplicationContext()).savePicture(eventID, array);
        // Add the image to the current array
        if (IMAGES == null)
            IMAGES = new ArrayList<>();
        IMAGES.add(array);
        // save the ID to the gallery
        for (int i = 0; i < TeamViewer.team.getTabs().get(rTabIndex).getMetrics().size(); i++) {
            if (TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i).getID() == galleryID) {
                if (((RGallery) TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i)).getPictureIDs() == null) {
                    ((RGallery) TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i)).setPictureIDs(new ArrayList<Integer>());
                }
                ((RGallery) TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i)).getPictureIDs().add(newID);
                break;
            }
        }
        TeamViewer.team.setLastEdit(System.currentTimeMillis());
        new IO(getApplicationContext()).saveTeam(eventID, TeamViewer.team);
        imageGalleryAdapter.notifyDataSetChanged();
    } else /*
         * User edited an image
         */
    if (resultCode == Constants.IMAGE_EDITED) {
        TeamViewer.team.setLastEdit(System.currentTimeMillis());
        /*
             * Update the image in the gallery
             */
        for (int i = 0; i < TeamViewer.team.getTabs().get(rTabIndex).getMetrics().size(); i++) {
            if (TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i).getID() == galleryID) {
                if (((RGallery) TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i)).getPictureIDs() == null) {
                    ((RGallery) TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i)).setPictureIDs(new ArrayList<Integer>());
                }
                ((RGallery) TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i)).getPictureIDs().add(new IO(getApplicationContext()).savePicture(eventID, IMAGES.get(data.getIntExtra("position", 0))));
                break;
            }
        }
        new IO(getApplicationContext()).saveTeam(eventID, TeamViewer.team);
        imageGalleryAdapter.notifyDataSetChanged();
    } else /*
         * User deleted an image
         */
    if (resultCode == Constants.IMAGE_DELETED) {
        // Remove the image from the gallery ID list
        for (int i = 0; i < TeamViewer.team.getTabs().get(rTabIndex).getMetrics().size(); i++) {
            if (TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i).getID() == galleryID) {
                int pictureID = ((RGallery) TeamViewer.team.getTabs().get(rTabIndex).getMetrics().get(i)).getPictureIDs().remove(data.getIntExtra("position", 0));
                // delete from file system
                new IO(getApplicationContext()).deletePicture(eventID, pictureID);
                break;
            }
        }
        IMAGES.remove(data.getIntExtra("position", 0));
        imageGalleryAdapter.notifyDataSetChanged();
        TeamViewer.team.setLastEdit(System.currentTimeMillis());
        new IO(getApplicationContext()).saveTeam(eventID, TeamViewer.team);
    }
}
Also used : Bitmap(android.graphics.Bitmap) RGallery(com.cpjd.roblu.models.metrics.RGallery) IO(com.cpjd.roblu.io.IO) ExifInterface(android.media.ExifInterface) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 35 with IO

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

the class TeamsView method onActivityResult.

/**
 * Receives data from activities originally launched from this class
 * @param requestCode the request code the original activity was launched with
 * @param resultCode the result code return from the launched activity
 * @param data any payload data received from the launched activity
 */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Constants.CUSTOM_SORT_CONFIRMED) {
        // the user selected a custom sort token, retrieve it and sort
        lastCustomSortToken = data.getStringExtra("sortToken");
        lastFilter = SORT_TYPE.CUSTOM_SORT;
        executeLoadTeamsTask(lastFilter, false);
        ignoreOnResumeOnce = true;
    } else if (Constants.MASTER_FORM == requestCode && resultCode == Constants.FORM_CONFIRMED) {
        // the user edited the master form, retrieve it and save it
        Bundle b = data.getExtras();
        if (b != null) {
            settings.setMaster((RForm) b.getSerializable("form"));
        }
        io.saveSettings(settings);
    } else /*
         * This must occur BEFORE the straight up NEW_EVENT_CREATED return.
         * This will be called after the user does a TBA sync
         */
    if (requestCode == Constants.EVENT_SETTINGS_REQUEST && resultCode == Constants.NEW_EVENT_CREATED) {
        executeLoadTeamsTask(lastFilter, true);
    } else if (resultCode == Constants.NEW_EVENT_CREATED) {
        // The user created an event, let's get the ID and select it
        Bundle d = data.getExtras();
        eventDrawerManager.loadEventsToDrawer();
        eventDrawerManager.selectEvent(d != null ? d.getInt("eventID") : 0);
    } else if (resultCode == Constants.MY_MATCHES_EXITED) {
        executeLoadTeamsTask(lastFilter, true);
    } else if (resultCode == Constants.CUSTOM_SORT_CANCELLED) {
        // user exited custom sort, don't make the button in the filter dialog still display custom sort
        lastFilter = settings.getLastFilter();
    } else if (resultCode == Constants.TEAM_EDITED) {
        // the user edited a team, let's toss it in the teams array and reload it also
        if (eventDrawerManager.getEvent() == null)
            return;
        RTeam temp = io.loadTeam(eventDrawerManager.getEvent().getID(), data.getIntExtra("teamID", 0));
        // Reload the teams array
        for (int i = 0; i < teams.size(); i++) {
            if (teams.get(i).getID() == temp.getID()) {
                teams.set(i, temp);
                break;
            }
        }
        // Reload the edited team into the adapter
        adapter.reAdd(temp);
        if (lastQuery != null && !lastQuery.equals(""))
            executeLoadTeamsTask(SORT_TYPE.SEARCH, false);
        else
            executeLoadTeamsTask(lastFilter, false);
        ignoreOnResumeOnce = true;
    } else if (resultCode == Constants.EVENT_SETTINGS_CHANGED) {
        // user edited the event
        int eventID = data.getIntExtra("eventID", 0);
        eventDrawerManager.loadEventsToDrawer();
        eventDrawerManager.selectEvent(eventID);
        if (getSupportActionBar() != null)
            getSupportActionBar().setSubtitle(eventDrawerManager.getEvent().getName());
        executeLoadTeamsTask(lastFilter, true);
    } else if (resultCode == Constants.SETTINGS_CHANGED) {
        // user changed application settings (refresh UI to make sure it matches a possible RUI change)
        // reload settings
        settings = new IO(getApplicationContext()).loadSettings();
        eventDrawerManager.loadEventsToDrawer();
        if (eventDrawerManager.getEvent() != null)
            eventDrawerManager.selectEvent(eventDrawerManager.getEvent().getID());
    // new UIHandler(this, toolbar).update();
    // eventDrawerManager = new EventDrawerManager(this, toolbar, this);
    }
}
Also used : RForm(com.cpjd.roblu.models.RForm) RTeam(com.cpjd.roblu.models.RTeam) Bundle(android.os.Bundle) IO(com.cpjd.roblu.io.IO)

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