Example usage for android.widget Spinner setAdapter

List of usage examples for android.widget Spinner setAdapter

Introduction

In this page you can find the example usage for android.widget Spinner setAdapter.

Prototype

@Override
public void setAdapter(SpinnerAdapter adapter) 

Source Link

Document

Sets the SpinnerAdapter used to provide the data which backs this Spinner.

Usage

From source file:org.glucosio.android.fragment.OverviewFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    GlucosioApplication app = (GlucosioApplication) getActivity().getApplicationContext();
    presenter = new OverviewPresenter(this, app.getDBHandler());
    if (!presenter.isdbEmpty()) {
        presenter.loadDatabase(isNewGraphEnabled());
    }/* w  w w. j  a  va2  s. com*/

    mFragmentView = inflater.inflate(R.layout.fragment_overview, container, false);

    chart = (LineChart) mFragmentView.findViewById(R.id.chart);
    disableTouchTheft(chart);
    Legend legend = chart.getLegend();

    lastReadingTextView = (TextView) mFragmentView.findViewById(R.id.item_history_reading);
    lastDateTextView = (TextView) mFragmentView.findViewById(R.id.fragment_overview_last_date);
    tipTextView = (TextView) mFragmentView.findViewById(R.id.random_tip_textview);
    graphSpinnerRange = (Spinner) mFragmentView.findViewById(R.id.chart_spinner_range);
    Spinner graphSpinnerMetric = (Spinner) mFragmentView.findViewById(R.id.chart_spinner_metrics);
    ImageButton graphExport = (ImageButton) mFragmentView.findViewById(R.id.fragment_overview_graph_export);
    HB1ACTextView = (TextView) mFragmentView.findViewById(R.id.fragment_overview_hb1ac);
    HB1ACDateTextView = (TextView) mFragmentView.findViewById(R.id.fragment_overview_hb1ac_date);
    HB1ACMoreButton = (ImageButton) mFragmentView.findViewById(R.id.fragment_overview_a1c_more);
    graphCheckboxGlucose = (CheckBox) mFragmentView.findViewById(R.id.fragment_overview_graph_glucose);
    graphCheckboxKetones = (CheckBox) mFragmentView.findViewById(R.id.fragment_overview_graph_ketones);
    graphCheckboxCholesterol = (CheckBox) mFragmentView.findViewById(R.id.fragment_overview_graph_cholesterol);
    graphCheckboxA1c = (CheckBox) mFragmentView.findViewById(R.id.fragment_overview_graph_a1c);
    graphCheckboxWeight = (CheckBox) mFragmentView.findViewById(R.id.fragment_overview_graph_weight);
    graphCheckboxPressure = (CheckBox) mFragmentView.findViewById(R.id.fragment_overview_graph_pressure);

    graphCheckboxGlucose.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            setData();
            graphCheckboxWeight.setChecked(false);
            graphCheckboxCholesterol.setChecked(false);
            graphCheckboxKetones.setChecked(false);
            graphCheckboxPressure.setChecked(false);
            graphCheckboxWeight.setChecked(false);
            graphCheckboxA1c.setChecked(false);
            graphCheckboxGlucose.setChecked(b);
        }
    });

    graphCheckboxA1c.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            setData();
            graphCheckboxGlucose.setChecked(false);
            graphCheckboxWeight.setChecked(false);
            graphCheckboxCholesterol.setChecked(false);
            graphCheckboxKetones.setChecked(false);
            graphCheckboxPressure.setChecked(false);
            graphCheckboxWeight.setChecked(false);
            graphSpinnerRange.setEnabled(!b);
            graphCheckboxA1c.setChecked(b);
        }
    });

    graphCheckboxKetones.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            setData();
            graphCheckboxGlucose.setChecked(false);
            graphCheckboxWeight.setChecked(false);
            graphCheckboxCholesterol.setChecked(false);
            graphCheckboxPressure.setChecked(false);
            graphCheckboxWeight.setChecked(false);
            graphCheckboxA1c.setChecked(false);
            graphSpinnerRange.setEnabled(!b);
            graphCheckboxKetones.setChecked(b);
        }
    });

    graphCheckboxWeight.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            setData();
            graphCheckboxGlucose.setChecked(false);
            graphCheckboxWeight.setChecked(false);
            graphCheckboxCholesterol.setChecked(false);
            graphCheckboxKetones.setChecked(false);
            graphCheckboxPressure.setChecked(false);
            graphCheckboxA1c.setChecked(false);
            graphSpinnerRange.setEnabled(!b);
            graphCheckboxWeight.setChecked(b);
        }
    });

    graphCheckboxPressure.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            setData();
            graphCheckboxGlucose.setChecked(false);
            graphCheckboxWeight.setChecked(false);
            graphCheckboxCholesterol.setChecked(false);
            graphCheckboxKetones.setChecked(false);
            graphCheckboxWeight.setChecked(false);
            graphCheckboxA1c.setChecked(false);
            graphSpinnerRange.setEnabled(!b);
            graphCheckboxPressure.setChecked(b);
        }
    });

    graphCheckboxCholesterol.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            setData();
            graphCheckboxGlucose.setChecked(false);
            graphCheckboxWeight.setChecked(false);
            graphCheckboxKetones.setChecked(false);
            graphCheckboxPressure.setChecked(false);
            graphCheckboxWeight.setChecked(false);
            graphCheckboxA1c.setChecked(false);
            graphSpinnerRange.setEnabled(!b);
            graphCheckboxCholesterol.setChecked(b);
        }
    });

    HB1ACMoreButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showA1cDialog();
        }
    });
    // Set array and adapter for graphSpinnerRange
    String[] selectorRangeArray = getActivity().getResources()
            .getStringArray(R.array.fragment_overview_selector_range);
    String[] selectorMetricArray = getActivity().getResources()
            .getStringArray(R.array.fragment_overview_selector_metric);
    ArrayAdapter<String> dataRangeAdapter = new ArrayAdapter<>(getActivity(),
            android.R.layout.simple_spinner_item, selectorRangeArray);
    ArrayAdapter<String> dataMetricAdapter = new ArrayAdapter<>(getActivity(),
            android.R.layout.simple_spinner_item, selectorMetricArray);
    dataRangeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    dataMetricAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    graphSpinnerRange.setAdapter(dataRangeAdapter);
    graphSpinnerMetric.setAdapter(dataMetricAdapter);

    graphSpinnerRange.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (!presenter.isdbEmpty()) {
                setData();
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    graphSpinnerRange.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (!presenter.isdbEmpty()) {
                setData();
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    XAxis xAxis = chart.getXAxis();
    xAxis.setDrawGridLines(false);
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setTextColor(getResources().getColor(R.color.glucosio_text_light));
    xAxis.setAvoidFirstLastClipping(true);

    int minGlucoseValue = presenter.getGlucoseMinValue();
    int maxGlucoseValue = presenter.getGlucoseMaxValue();

    LimitLine ll1;
    LimitLine ll2;

    if (("mg/dL").equals(presenter.getUnitMeasuerement())) {
        ll1 = new LimitLine(minGlucoseValue);
        ll2 = new LimitLine(maxGlucoseValue);
    } else {
        ll1 = new LimitLine((float) GlucosioConverter.glucoseToMmolL(maxGlucoseValue),
                getString(R.string.reading_high));
        ll2 = new LimitLine((float) GlucosioConverter.glucoseToMmolL(minGlucoseValue),
                getString(R.string.reading_low));
    }

    ll1.setLineWidth(0.8f);
    ll1.setLineColor(getResources().getColor(R.color.glucosio_reading_low));

    ll2.setLineWidth(0.8f);
    ll2.setLineColor(getResources().getColor(R.color.glucosio_reading_high));

    YAxis leftAxis = chart.getAxisLeft();
    leftAxis.setTextColor(getResources().getColor(R.color.glucosio_text_light));
    leftAxis.setStartAtZero(false);
    leftAxis.disableGridDashedLine();
    leftAxis.setDrawGridLines(false);
    leftAxis.addLimitLine(ll1);
    leftAxis.addLimitLine(ll2);
    leftAxis.setDrawLimitLinesBehindData(true);

    chart.getAxisRight().setEnabled(false);
    chart.setBackgroundColor(Color.parseColor("#FFFFFF"));
    chart.setDescription("");
    chart.setGridBackgroundColor(Color.parseColor("#FFFFFF"));
    if (!presenter.isdbEmpty()) {
        setData();
    }
    legend.setEnabled(false);

    graphExport.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (ContextCompat.checkSelfPermission(getActivity(),
                    Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                // If we don't have permission, ask the user

                ActivityCompat.requestPermissions(getActivity(),
                        new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                        PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);

                Snackbar.make(mFragmentView, getString(R.string.fragment_overview_permission_storage),
                        Snackbar.LENGTH_SHORT).show();
            } else {
                // else save the image to gallery
                exportGraphToGallery();
            }
        }
    });

    loadLastReading();
    loadHB1AC();
    loadRandomTip();

    return mFragmentView;
}

From source file:knayi.delevadriver.JobDetailActivity.java

@Override
public void onClick(View v) {

    Calendar calendar = Calendar.getInstance();
    final long timestamp = System.currentTimeMillis();
    final String token = sPref.getString(Config.TOKEN, null);

    switch (v.getId()) {

    case R.id.job_reject:

        if (job_reject.getText().toString().equals("Reject")) {

            MaterialDialog dialog = new MaterialDialog.Builder(this).titleColor(R.color.white)
                    .customView(R.layout.reject_layout, true).positiveText("REJECT")
                    .positiveColor(R.color.white).positiveColorRes(R.color.white).negativeText("CANCEL")
                    .negativeColorRes(R.color.white).backgroundColorRes(R.color.primary)
                    .typeface("ciclefina.ttf", "ciclegordita.ttf")
                    .callback(new MaterialDialog.ButtonCallback() {
                        @Override
                        public void onPositive(final MaterialDialog dialog) {
                            super.onPositive(dialog);

                            EditText et_message = (EditText) dialog.findViewById(R.id.reject_message);

                            if (!et_message.getText().toString().equals("")) {
                                AvaliableJobsAPI.getInstance().getService().rejectJob(jobitem.get_id(), token,
                                        et_message.getText().toString(), "true", new Callback<String>() {
                                            @Override
                                            public void success(String s, Response response) {
                                                Toast.makeText(JobDetailActivity.this,
                                                        "Job is successfully rejected", Toast.LENGTH_SHORT)
                                                        .show();
                                                dialog.dismiss();

                                                //remove job id that is saved to use in locatin update
                                                sPref.edit().putString(Config.TOKEN_JOBID, null).commit();
                                                sPref.edit().putString(Config.TOKEN_DELAY, null).commit();

                                                //check report service is alive
                                                //if alive stop service
                                                if (sPref.getBoolean(Config.TOKEN_SERVICE_ALIVE, false)) {
                                                    Intent intentservice = new Intent(JobDetailActivity.this,
                                                            BackgroundLocationService.class);
                                                    stopService(intentservice);
                                                }

                                                Intent intent = new Intent(JobDetailActivity.this,
                                                        DrawerMainActivity.class);
                                                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                                                        | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                                                startActivity(intent);
                                                finish();
                                            }

                                            @Override
                                            public void failure(RetrofitError error) {

                                                if (error.getBody() == null) {
                                                    Toast.makeText(JobDetailActivity.this,
                                                            "Cannot connect to server!", Toast.LENGTH_SHORT)
                                                            .show();
                                                } else {

                                                    String errmsg = error.getBody().toString();
                                                    String errcode = "";

                                                    try {
                                                        JSONObject errobj = new JSONObject(errmsg);

                                                        errcode = errobj.getJSONObject("err")
                                                                .getString("message");

                                                        Toast.makeText(JobDetailActivity.this, errcode,
                                                                Toast.LENGTH_SHORT).show();

                                                    } catch (JSONException e) {
                                                        e.printStackTrace();
                                                    }

                                                }

                                                dialog.dismiss();
                                            }
                                        });
                            } else {
                                Toast.makeText(JobDetailActivity.this, "Please enter your message",
                                        Toast.LENGTH_SHORT).show();
                            }/*from ww w  .  ja  v  a2  s  .  com*/

                            progress.setVisibility(View.INVISIBLE);
                            progress_background.setVisibility(View.INVISIBLE);

                        }

                        @Override
                        public void onNegative(MaterialDialog dialog) {
                            super.onNegative(dialog);

                            dialog.dismiss();
                            progress.setVisibility(View.INVISIBLE);
                            progress_background.setVisibility(View.INVISIBLE);

                        }
                    }

                    ).build();

            dialog.show();

            EditText et_message = (EditText) dialog.findViewById(R.id.reject_message);
            et_message.setTypeface(MyTypeFace.get(JobDetailActivity.this, MyTypeFace.NORMAL));

        }
        /*else{
                
            final Dialog msgDialog = new Dialog(JobDetailActivity.this);
                
            msgDialog.setTitle("Why do u reject?");
            msgDialog.setCancelable(true);
            msgDialog.setContentView(R.layout.custom_dialog_reason);
            final EditText message = (EditText) msgDialog.findViewById(R.id.messagebox);
            Button submit = (Button) msgDialog.findViewById(R.id.submitbutton);
                
            msgDialog.show();
                
            submit.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                
                    progress.setVisibility(View.VISIBLE);
                
                    progress_background.setVisibility(View.VISIBLE);
                
                    if(message.getText().toString().equals("") && message.getText().toString().equals(null)){
                        Toast.makeText(getApplicationContext(), "Please input message to submit", Toast.LENGTH_SHORT).show();
                    }else{
                        msgDialog.dismiss();
                
                        progress.setVisibility(View.VISIBLE);
                        progress_background.setVisibility(View.VISIBLE);
                        if(token == null){
                            new SweetAlertDialog(JobDetailActivity.this, SweetAlertDialog.WARNING_TYPE)
                                    .setTitleText("")
                                    .setContentText("Please Login again!")
                                    .show();
                            finish();
                            startActivity(new Intent(JobDetailActivity.this, LoginActivity.class));
                
                
                
                        }
                        else{
                            AvaliableJobsAPI.getInstance().getService().rejectJob(jobitem.get_id(), token, location, String.valueOf(timestamp), message.getText().toString(), new Callback<String>() {
                                @Override
                                public void success(String s, Response response) {
                                    progress.setVisibility(View.INVISIBLE);
                                    progress_background.setVisibility(View.INVISIBLE);
                                    startActivity(new Intent(JobDetailActivity.this, TabMainActivity.class));
                                    finish();
                
                                }
                
                                @Override
                                public void failure(RetrofitError error) {
                                    progress.setVisibility(View.INVISIBLE);
                                    progress_background.setVisibility(View.INVISIBLE);
                                    Toast.makeText(getApplicationContext(), "Something Went Wrong!", Toast.LENGTH_SHORT).show();
                                }
                            });
                
                        }
                    }
                
                }
            });
                
        }*/

        break;

    case R.id.job_bid:

        progress.setVisibility(View.VISIBLE);
        progress_background.setVisibility(View.VISIBLE);

        if (token == null) {

            MaterialDialog dialog = new MaterialDialog.Builder(this)
                    .customView(R.layout.custom_message_dialog, false).positiveText("OK")
                    .positiveColor(R.color.white).positiveColorRes(R.color.white)
                    .backgroundColorRes(R.color.primary).typeface("ciclefina.ttf", "ciclegordita.ttf").build();
            dialog.show();

            TextView txt_title = (TextView) dialog.findViewById(R.id.dialog_title);
            TextView txt_message = (TextView) dialog.findViewById(R.id.dialog_message);
            txt_title.setTypeface(MyTypeFace.get(JobDetailActivity.this, MyTypeFace.NORMAL));
            txt_message.setTypeface(MyTypeFace.get(JobDetailActivity.this, MyTypeFace.NORMAL));

            txt_title.setText("Please Login again!");
            txt_message.setText("Server doesn't know this account!");

            Intent intent = new Intent(JobDetailActivity.this, LoginActivity.class);
            startActivity(intent);
            finish();
        }

        if (job_bid.getText().toString().equals("Bid")) {

            final long ts1 = System.currentTimeMillis();

            Location mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);

            if (mLastLocation != null) {
                location = mLastLocation.getLongitude() + "," + mLastLocation.getLatitude();
            }

            acceptJob(token, String.valueOf(ts1), "");

            /*MaterialDialog dialog = new MaterialDialog.Builder(this)
                    .title("Estimate time of arrival to pick up point")
                    .customView(R.layout.estimatetime_layout, true)
                    .positiveText("BID")
                    .positiveColor(R.color.primary)
                    .positiveColorRes(R.color.primary)
                    .negativeText("CANCEL")
                    .negativeColorRes(R.color.primary)
                    .cancelable(false)
                    .callback(new MaterialDialog.ButtonCallback() {
                                  @Override
                                  public void onPositive(MaterialDialog dialog) {
                                      super.onPositive(dialog);
                    
                                      EditText et_estimatetime = (EditText) dialog.findViewById(R.id.estimatetime_et);
                    
                    
                                      if(!et_estimatetime.getText().toString().equals("")) {
                                          acceptJob(token, String.valueOf(ts1), et_estimatetime.getText().toString());
                                      }else{
                                          Toast.makeText(JobDetailActivity.this, "Please Input Fields!", Toast.LENGTH_SHORT).show();
                                          progress.setVisibility(View.INVISIBLE);
                                          progress_background.setVisibility(View.INVISIBLE);
                                      }
                    
                    
                                  }
                    
                                  @Override
                                  public void onNegative(MaterialDialog dialog) {
                                      super.onNegative(dialog);
                    
                                      dialog.dismiss();
                                      progress.setVisibility(View.INVISIBLE);
                                      progress_background.setVisibility(View.INVISIBLE);
                    
                                  }
                              }
                    
                    )
                    .build();
                    
                    
            dialog.show();
                    
            final EditText et_estimatetime = (EditText) dialog.findViewById(R.id.estimatetime_et);
                    
            et_estimatetime.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Calendar mcurrentTime = Calendar.getInstance();
                    int hour = mcurrentTime.get(Calendar.HOUR_OF_DAY);
                    int minute = mcurrentTime.get(Calendar.MINUTE);
                    TimePickerDialog mTimePicker;
                    mTimePicker = new TimePickerDialog(JobDetailActivity.this, new TimePickerDialog.OnTimeSetListener() {
                        @Override
                        public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
                            et_estimatetime.setText( selectedHour + ":" + selectedMinute);
                        }
                    }, hour, minute, true);//Yes 24 hour time
                    mTimePicker.setTitle("Select Time");
                    mTimePicker.show();
                }
            });*/

        }

        else if (job_bid.getText().toString().equals("Agree")) {

            AvaliableJobsAPI.getInstance().getService().agreeJob(jobitem.get_id(), token, "true",
                    new Callback<String>() {
                        @Override
                        public void success(String s, Response response) {
                            Toast.makeText(JobDetailActivity.this, "Success", Toast.LENGTH_SHORT).show();

                            getDataFromServer(job_id);
                        }

                        @Override
                        public void failure(RetrofitError error) {

                            if (error.getBody() == null) {
                                Toast.makeText(JobDetailActivity.this, "Cannot connect to server!",
                                        Toast.LENGTH_SHORT).show();
                            } else {

                                String errmsg = error.getBody().toString();
                                String errcode = "";

                                try {
                                    JSONObject errobj = new JSONObject(errmsg);

                                    errcode = errobj.getJSONObject("err").getString("message");

                                    Toast.makeText(JobDetailActivity.this, errcode, Toast.LENGTH_SHORT).show();

                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }

                            }

                        }
                    });

        }

        else if (job_bid.getText().toString().equals("Finished")) {

            MaterialDialog dialog = new MaterialDialog.Builder(this).titleColor(R.color.white)
                    .customView(R.layout.custom_request_message_dialog, true).positiveText("SEND")
                    .positiveColor(R.color.white).positiveColorRes(R.color.white).negativeText("CANCEL")
                    .negativeColorRes(R.color.white).backgroundColorRes(R.color.primary)
                    .typeface("ciclefina.ttf", "ciclegordita.ttf")
                    .callback(new MaterialDialog.ButtonCallback() {
                        @Override
                        public void onPositive(MaterialDialog dialog) {
                            super.onPositive(dialog);

                            EditText request_secret_code = (EditText) dialog
                                    .findViewById(R.id.request_secret_code);
                            /*EditText request_msg = (EditText) dialog.findViewById(R.id.request_msg);*/

                            if (request_secret_code != null) {

                                if (request_secret_code.getText().toString() != null
                                        && request_secret_code.getText().toString() != "") {

                                    Location mLastLocation = LocationServices.FusedLocationApi
                                            .getLastLocation(mGoogleApiClient);
                                    Long tsLong = System.currentTimeMillis();
                                    String ts = tsLong.toString();

                                    String location = "96,16";

                                    if (mLastLocation != null) {
                                        location = mLastLocation.getLongitude() + ","
                                                + mLastLocation.getLatitude();
                                    }

                                    final long timestamp = System.currentTimeMillis();
                                    JSONObject obj = new JSONObject();
                                    try {
                                        obj.put("location", location);
                                        obj.put("timestamp", String.valueOf(timestamp));
                                        obj.put("secret_code", request_secret_code.getText().toString());
                                        obj.put("message", "");//request_msg.getText().toString());
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }

                                    String json = obj.toString();

                                    try {
                                        TypedInput in = new TypedByteArray("application/json",
                                                json.getBytes("UTF-8"));

                                        progress.setVisibility(View.VISIBLE);
                                        progress_background.setVisibility(View.VISIBLE);

                                        AvaliableJobsAPI.getInstance().getService().jobDone(jobitem.get_id(),
                                                token, in, new Callback<String>() {
                                                    @Override
                                                    public void success(String s, Response response) {

                                                        Toast.makeText(JobDetailActivity.this,
                                                                "Message is sent successfully",
                                                                Toast.LENGTH_SHORT).show();

                                                        sPref.edit().putString(Config.TOKEN_DELAY, null)
                                                                .commit();

                                                        if (sPref.getBoolean(Config.TOKEN_SERVICE_ALIVE,
                                                                false)) {
                                                            Intent intentservice = new Intent(
                                                                    JobDetailActivity.this,
                                                                    BackgroundLocationService.class);
                                                            stopService(intentservice);
                                                        }

                                                        progress.setVisibility(View.INVISIBLE);
                                                        progress_background.setVisibility(View.INVISIBLE);

                                                        bitLayout.setVisibility(View.GONE);

                                                    }

                                                    @Override
                                                    public void failure(RetrofitError error) {

                                                        //Toast.makeText(JobDetailActivity.this, "Failed, Please Try Again!", Toast.LENGTH_SHORT).show();

                                                        if (error.getBody() == null) {
                                                            Toast.makeText(JobDetailActivity.this,
                                                                    "Cannot connect to server!",
                                                                    Toast.LENGTH_SHORT).show();
                                                        } else {

                                                            String errmsg = error.getBody().toString();
                                                            String errcode = "";

                                                            try {
                                                                JSONObject errobj = new JSONObject(errmsg);

                                                                errcode = errobj.getJSONObject("err")
                                                                        .getString("message");

                                                                Toast.makeText(JobDetailActivity.this, errcode,
                                                                        Toast.LENGTH_SHORT).show();

                                                            } catch (JSONException e) {
                                                                e.printStackTrace();
                                                            }

                                                        }

                                                        progress.setVisibility(View.INVISIBLE);
                                                        progress_background.setVisibility(View.INVISIBLE);

                                                    }
                                                });

                                    } catch (UnsupportedEncodingException e) {
                                        e.printStackTrace();
                                    }

                                }

                            }

                            progress.setVisibility(View.INVISIBLE);
                            progress_background.setVisibility(View.INVISIBLE);

                        }

                        @Override
                        public void onNegative(MaterialDialog dialog) {
                            super.onNegative(dialog);

                            dialog.dismiss();
                            progress.setVisibility(View.INVISIBLE);
                            progress_background.setVisibility(View.INVISIBLE);

                        }
                    }

                    ).build();

            dialog.show();

            EditText request_secret_code = (EditText) dialog.findViewById(R.id.request_secret_code);
            /*EditText request_msg = (EditText) dialog.findViewById(R.id.request_msg);*/
            request_secret_code.setTypeface(MyTypeFace.get(JobDetailActivity.this, MyTypeFace.NORMAL));
            /*request_msg.setTypeface(MyTypeFace.get(JobDetailActivity.this, MyTypeFace.NORMAL));*/

        }

        break;

    case R.id.job_report:

        isFirstDialog = true;

        totalprice = Double.parseDouble(jobitem.get_price());

        final MaterialDialog dialog = new MaterialDialog.Builder(this).customView(R.layout.report_layout, true)
                .positiveText("REPORT").positiveColor(R.color.white).positiveColorRes(R.color.white)
                .negativeText("CANCEL").negativeColorRes(R.color.white).backgroundColorRes(R.color.primary)
                .typeface("ciclefina.ttf", "ciclegordita.ttf").callback(new MaterialDialog.ButtonCallback() {
                    @Override
                    public void onPositive(final MaterialDialog dialog) {
                        super.onPositive(dialog);

                        CheckBox cb_weight = (CheckBox) dialog.findViewById(R.id.report_cb_overweight);
                        CheckBox cb_express = (CheckBox) dialog.findViewById(R.id.report_cb_express);
                        CheckBox cb_refrig = (CheckBox) dialog.findViewById(R.id.report_cb_refrigerated);
                        //CheckBox cb_type = (CheckBox) dialog.findViewById(R.id.report_cb_type);

                        final Spinner sp_weight = (Spinner) dialog.findViewById(R.id.report_spinner_overweight);
                        //final Spinner sp_type = (Spinner) dialog.findViewById(R.id.report_spinner_type);

                        EditText et_message = (EditText) dialog.findViewById(R.id.report_et_message);

                        //Refrage

                        if (!et_message.getText().toString().equals("")
                                && et_message.getText().toString() != null) {

                            if (cb_weight.isChecked() || cb_express.isChecked() || cb_refrig.isChecked()) {

                                String message = "";//et_message.getText().toString();

                                if (cb_express.isChecked()) {
                                    message += "true,";
                                } else {
                                    message += "false,";
                                }

                                if (cb_refrig.isChecked()) {
                                    message += "true,";
                                } else {
                                    message += "false,";
                                }

                                if (cb_weight.isChecked()) {
                                    message += weightlist.get(sp_weight.getSelectedItemPosition()) + ",";
                                } else {
                                    message += ",";
                                }

                                AvaliableJobsAPI.getInstance().getService().reportJob(jobitem.get_id(), token,
                                        message, "0", new Callback<String>() {
                                            @Override
                                            public void success(String s, Response response) {
                                                Toast.makeText(JobDetailActivity.this,
                                                        "Your report has successfully sent", Toast.LENGTH_SHORT)
                                                        .show();

                                                dialog.dismiss();
                                            }

                                            @Override
                                            public void failure(RetrofitError error) {
                                                //Toast.makeText(JobDetailActivity.this, "Report is Failed", Toast.LENGTH_SHORT).show();

                                                if (error.getBody() == null) {
                                                    Toast.makeText(JobDetailActivity.this,
                                                            "Cannot connect to server!", Toast.LENGTH_SHORT)
                                                            .show();
                                                } else {

                                                    String errmsg = error.getBody().toString();
                                                    String errcode = "";

                                                    try {
                                                        JSONObject errobj = new JSONObject(errmsg);

                                                        errcode = errobj.getJSONObject("err")
                                                                .getString("message");

                                                        Toast.makeText(JobDetailActivity.this, errcode,
                                                                Toast.LENGTH_SHORT).show();

                                                    } catch (JSONException e) {
                                                        e.printStackTrace();
                                                    }

                                                }

                                                dialog.dismiss();
                                            }
                                        });
                            } else {

                                Toast.makeText(JobDetailActivity.this, "Please select report reason",
                                        Toast.LENGTH_SHORT).show();
                            }

                        } else {
                            Toast.makeText(JobDetailActivity.this, "Please enter your message",
                                    Toast.LENGTH_SHORT).show();
                        }

                        progress.setVisibility(View.INVISIBLE);
                        progress_background.setVisibility(View.INVISIBLE);

                    }

                    @Override
                    public void onNegative(MaterialDialog dialog) {
                        super.onNegative(dialog);

                        dialog.dismiss();
                        progress.setVisibility(View.INVISIBLE);
                        progress_background.setVisibility(View.INVISIBLE);

                    }
                }

                ).build();

        dialog.show();

        final CheckBox cb_weight = (CheckBox) dialog.findViewById(R.id.report_cb_overweight);
        //final CheckBox cb_type = (CheckBox) dialog.findViewById(R.id.report_cb_type);

        CheckBox cb_express = (CheckBox) dialog.findViewById(R.id.report_cb_express);
        CheckBox cb_refrig = (CheckBox) dialog.findViewById(R.id.report_cb_refrigerated);
        EditText et_message = (EditText) dialog.findViewById(R.id.report_et_message);

        et_message.setTypeface(MyTypeFace.get(JobDetailActivity.this, MyTypeFace.NORMAL));
        cb_weight.setTypeface(MyTypeFace.get(JobDetailActivity.this, MyTypeFace.NORMAL));
        cb_express.setTypeface(MyTypeFace.get(JobDetailActivity.this, MyTypeFace.NORMAL));
        cb_refrig.setTypeface(MyTypeFace.get(JobDetailActivity.this, MyTypeFace.NORMAL));

        if (jobitem.getIsExpress().equals("true")) {
            cb_express.setChecked(true);
        }

        if (jobitem.getIsRefrigerated().equals("true")) {
            cb_refrig.setChecked(true);
        }

        //final TextView tv_price = (TextView) dialog.findViewById(R.id.report_price_tag);

        final Spinner sp_weight = (Spinner) dialog.findViewById(R.id.report_spinner_overweight);
        //final Spinner sp_type = (Spinner) dialog.findViewById(R.id.report_spinner_type);

        sp_weight.setEnabled(false);
        //sp_type.setEnabled(false);

        //tv_price.setText("price " + jobitem.get_price());

        sp_weight.setAdapter(new ArrayAdapter<String>(JobDetailActivity.this,
                android.R.layout.simple_spinner_dropdown_item, weightshowlist));
        //sp_type.setAdapter(new ArrayAdapter<String>(JobDetailActivity.this, android.R.layout.simple_spinner_dropdown_item, new String[]{"Other", "Express", "Refrigerated"}));

        sp_weight.setSelection(weightpos);
        //sp_type.setSelection(typepos);

        sp_weight.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

                if (!isFirstDialog) {

                    totalprice += weightPricelist.get(sp_weight.getSelectedItemPosition());

                } else {
                    isFirstDialog = false;
                }

                /*if(cb_type.isChecked()){
                    totalprice += typepricelist.get(position);
                }*/

                //                        tv_price.setText("price " + String.valueOf(totalprice));
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });

        /*sp_type.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                totalprice = Double.parseDouble(jobitem.get_price());
                if (!isFirstDialog) {
                    totalprice += typepricelist.get(position);
                
                } else {
                    isFirstDialog = false;
                }
                
                if (cb_weight.isChecked()) {
                    totalprice += weightPricelist.get(sp_weight.getSelectedItemPosition());
                }
                
                tv_price.setText("price " + String.valueOf(totalprice));
            }
                
            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                
            }
        });*/

        cb_weight.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    sp_weight.setEnabled(true);

                    totalprice += weightPricelist.get(sp_weight.getSelectedItemPosition());

                } else {
                    sp_weight.setEnabled(false);
                    totalprice -= weightPricelist.get(sp_weight.getSelectedItemPosition());
                }

                //tv_price.setText("price " + String.valueOf(totalprice));
            }
        });

        /*cb_type.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    sp_type.setEnabled(true);
                    totalprice += typepricelist.get(sp_type.getSelectedItemPosition());
                }else{
                    sp_type.setEnabled(false);
                    totalprice -= typepricelist.get(sp_type.getSelectedItemPosition());
                }
                tv_price.setText("price " + String.valueOf(totalprice));
            }
        });*/

        break;

    default:
        Intent intent = new Intent(JobDetailActivity.this, DrawerMainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        startActivity(intent);
        finish();
        break;

    }
}