Demo entry 4016796

Update

   

Submitted by anonymous on Mar 13, 2016 at 05:41
Language: Java. Code size: 7.8 kB.

import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RadioButton;
import android.widget.Spinner;

import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.Calendar;

public class EnterClimb extends AppCompatActivity {
    String LOG_TAG = "DebugTest";
    private ArrayList<Entry> myClimbs = new ArrayList<Entry>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_enter_climb);

        CheckBox tempCheckBox = (CheckBox) findViewById(R.id.boulderingCheckBox);
        Spinner tempSpinner = (Spinner) findViewById(R.id.boulderGrades);
        tempSpinner.setVisibility(View.VISIBLE);
        tempCheckBox.setChecked(true);

        CheckBox currentDayCheckBox = (CheckBox) findViewById(R.id.currentDayRadioButton);
        currentDayCheckBox.setChecked(false);
        Spinner daySpinner = (Spinner) findViewById(R.id.daySpinner);
        Spinner monthSpinner = (Spinner) findViewById(R.id.monthSpinner);
        Spinner yearSpinner = (Spinner) findViewById(R.id.yearSpinner);
        daySpinner.setVisibility(View.VISIBLE);
        monthSpinner.setVisibility(View.VISIBLE);
        yearSpinner.setVisibility(View.VISIBLE);

        Gson gson = new Gson();
        JsonClimbList myClimbList;

        Log.i(LOG_TAG, "Getting Intent");

        Intent intent = getIntent();
        String json = intent.getStringExtra("inputList");
        Log.i(LOG_TAG,"Retrieved: " + json);

        myClimbList = gson.fromJson(json, JsonClimbList.class);
        myClimbs = myClimbList.getMyClimbs();
        Log.i(LOG_TAG,"Leaving onCreate");
    }

    public void boulderingCheckOnClick(View v){
        CheckBox boulderButton = (CheckBox) findViewById(R.id.boulderingCheckBox);
        CheckBox ropeButton = (CheckBox) findViewById(R.id.ropeCheckBox);

        Spinner boulderSpinner = (Spinner) findViewById(R.id.boulderGrades);
        Spinner ropeSpinner = (Spinner) findViewById(R.id.ropeGrades);

        if(boulderButton.isChecked()){
            boulderButton.setChecked(false);
            boulderSpinner.setVisibility(View.INVISIBLE);

            ropeButton.setChecked(true);
            ropeSpinner.setVisibility(View.VISIBLE);
        }
        else{
            boulderButton.setChecked(true);
            boulderSpinner.setVisibility(View.VISIBLE);

            ropeButton.setChecked(false);
            ropeSpinner.setVisibility(View.INVISIBLE);
        }
    }

    public void ropeCheckOnClick(View v){
        CheckBox boulderButton = (CheckBox) findViewById(R.id.boulderingCheckBox);
        CheckBox ropeButton = (CheckBox) findViewById(R.id.ropeCheckBox);

        Spinner boulderSpinner = (Spinner) findViewById(R.id.boulderGrades);
        Spinner ropeSpinner = (Spinner) findViewById(R.id.ropeGrades);

        if(!ropeButton.isChecked()){
            boulderButton.setChecked(false);
            boulderSpinner.setVisibility(View.INVISIBLE);

            ropeButton.setChecked(true);
            ropeSpinner.setVisibility(View.VISIBLE);
        }
        else{
            boulderButton.setChecked(true);
            boulderSpinner.setVisibility(View.VISIBLE);

            ropeButton.setChecked(false);
            ropeSpinner.setVisibility(View.INVISIBLE);
        }
    }

    public void currentDayOnClick(View v){
        CheckBox currentDayBox = (CheckBox) findViewById(R.id.currentDayRadioButton);
        Spinner daySpinner = (Spinner) findViewById(R.id.daySpinner);
        Spinner monthSpinner = (Spinner) findViewById(R.id.monthSpinner);
        Spinner yearSpinner = (Spinner) findViewById(R.id.yearSpinner);

        if(!currentDayBox.isChecked()){
            daySpinner.setVisibility(View.VISIBLE);
            monthSpinner.setVisibility(View.VISIBLE);
            yearSpinner.setVisibility(View.VISIBLE);
        }
        else{
            daySpinner.setVisibility(View.INVISIBLE);
            monthSpinner.setVisibility(View.INVISIBLE);
            yearSpinner.setVisibility(View.INVISIBLE);
        }
    }

    public void onFormEntry(View v){
        CheckBox currentDayBox = (CheckBox) findViewById(R.id.currentDayRadioButton);
        CheckBox boulderButton = (CheckBox) findViewById(R.id.boulderingCheckBox);

        Spinner boulderSpinner = (Spinner) findViewById(R.id.boulderGrades);
        Spinner ropeSpinner = (Spinner) findViewById(R.id.ropeGrades);

        Spinner daySpinner = (Spinner) findViewById(R.id.daySpinner);
        Spinner monthSpinner = (Spinner) findViewById(R.id.monthSpinner);
        Spinner yearSpinner = (Spinner) findViewById(R.id.yearSpinner);

        Entry output;
        boolean bouldering = boulderButton.isChecked();

        Log.i(LOG_TAG,"About to set entry");
        int grade;
        if(bouldering) grade = getBoulderGrade(String.valueOf(boulderSpinner.getSelectedItem()));
        else grade = getTopRopeGrade(String.valueOf(ropeSpinner.getSelectedItem()));

        Log.i(LOG_TAG,"bouldering grade set");

        if(currentDayBox.isChecked()){
            Log.i(LOG_TAG,"Got Calander instance");
            Calendar c = Calendar.getInstance();
            output = new Entry(grade, !bouldering, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
        }
        else{
            Log.i(LOG_TAG,"Inside of else");
            output = new Entry(grade, !bouldering, Integer.parseInt(String.valueOf(yearSpinner.getSelectedItem())), Integer.parseInt(String.valueOf(monthSpinner.getSelectedItem())), Integer.parseInt(String.valueOf(daySpinner.getSelectedItem())));
        }

        Log.i(LOG_TAG,"About to convert to json");
        JsonClimbList temp;
        Gson gson = new Gson();
        myClimbs.add(output);
        temp = new JsonClimbList(myClimbs);
        String json = gson.toJson(temp, JsonClimbList.class);
        Intent resultIntent = new Intent();

        resultIntent.putExtra("outputList", json);

        setResult(Activity.RESULT_OK, resultIntent);
        Log.i(LOG_TAG,"About to finish");
        finish();

    }

    public int getTopRopeGrade(String s){
        if(s.equalsIgnoreCase("5.9")) return 0;
        else
        if(s.equalsIgnoreCase("5.10a")) return 1;
        else
        if(s.equalsIgnoreCase("5.10b")) return 2;
        else
        if(s.equalsIgnoreCase("5.10c")) return 3;
        else
        if(s.equalsIgnoreCase("5.10d")) return 4;
        else
        if(s.equalsIgnoreCase("5.11a")) return 5;
        else
        if(s.equalsIgnoreCase("5.11b")) return 6;
        else
        if(s.equalsIgnoreCase("5.11c")) return 7;
        else
        if(s.equalsIgnoreCase("5.11d")) return 8;
        else
        if(s.equalsIgnoreCase("5.12a")) return 9;
        else
        if(s.equalsIgnoreCase("5.12b")) return 10;
        else
        if(s.equalsIgnoreCase("5.12c")) return 11;
        else
        if(s.equalsIgnoreCase("5.12d")) return 12;
        else return 6;
    }

    public int getBoulderGrade(String s){
        Log.i(LOG_TAG,"About to get bouldering grade");
        return Integer.parseInt(s.substring(1));
    }

    public void Back(View v){
        Intent returnIntent = new Intent();
        setResult(RESULT_CANCELED, returnIntent);
        finish();
    }

    public void Stats(View v){
        Intent intent = new Intent(this, Stats.class);
        startActivity(intent);
    }
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).