@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_history_point); if (savedInstanceState != null) point = savedInstanceState.getParcelable("point"); else { if (this.getIntent() != null && this.getIntent().getExtras() != null && this.getIntent().getExtras().getParcelable("point") != null) point = this.getIntent().getExtras().getParcelable("point"); else { Toast.makeText(this, "Fail!", Toast.LENGTH_SHORT).show(); this.finish(); } } // TOOLBAR Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setTitle("Chart - " + point.getName()); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(false); // this will define the period of your requisition. In the other words, this defines how much // datas you want Spinner spinner_period = (Spinner) findViewById(R.id.spinner_period); String[] items = new String[8]; items[0] = "Not defined"; items[1] = "7 days"; items[2] = "15 days"; items[3] = "1 month"; items[4] = "3 months"; items[5] = "6 months"; items[6] = "1 year"; items[7] = "Set time"; ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.row_spn, items); adapter.setDropDownViewResource(R.layout.row_spn_dropdown); spinner_period.setAdapter(adapter); ImageView iv_setting = (ImageView) findViewById(R.id.setting); iv_setting.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (!point.getCategoryString().equals("weather") && !point.getCategoryString().equals("luminosity")) { Dialog.Builder builder = new SimpleDialog.Builder(R.style.SimpleDialog) { @Override protected void onBuildDone(Dialog dialog) { dialog.layoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); if (point.getPrice() != 0) ((EditText) dialog.findViewById(R.id.custom_et_value)) .setText("" + point.getPrice()); } @Override public void onPositiveActionClicked( com.rey.material.app.DialogFragment fragment) { String value = ((EditText) fragment.getDialog().findViewById(R.id.custom_et_value)) .getText() .toString(); DataBase db = new DataBase(PointHistoryActivity.this); point.setPrice(Double.parseDouble(value)); db.updatePoint(point); db.closeDataBase(); super.onPositiveActionClicked(fragment); } @Override public void onNegativeActionClicked( com.rey.material.app.DialogFragment fragment) { Toast.makeText(PointHistoryActivity.this, "Cancelled", Toast.LENGTH_SHORT) .show(); super.onNegativeActionClicked(fragment); } }; String value = null; if (point.getCategoryString().equals("water")) value = "Price of water (R$/m³)"; else if (point.getCategoryString().equals("energy")) value = "Price of energy (R$/KW)"; else value = "Consumption of energy (W)"; builder .title(value) .positiveAction("OK") .negativeAction("CANCEL") .contentView(R.layout.set_value_point) .style(R.style.SimpleDialog); com.rey.material.app.DialogFragment fragment = com.rey.material.app.DialogFragment.newInstance(builder); fragment.show(PointHistoryActivity.this.getSupportFragmentManager(), null); } else Toast.makeText( PointHistoryActivity.this, "Not allowed to this category of point", Toast.LENGTH_SHORT) .show(); } }); spinner_period.setOnItemSelectedListener( new Spinner.OnItemSelectedListener() { @Override public void onItemSelected(Spinner spinner, View view, int i, long l) { if (i != 0 && !point.getCategoryString().equals("null")) { Calendar cal = Calendar.getInstance(); switch (i) { case 1: cal.add(Calendar.DATE, -7); periodData = 7; new AsyncTasks(PointHistoryActivity.this, cal, point, PointHistoryActivity.this) .execute(2); progressDialogOn(); break; case 2: cal.add(Calendar.DATE, -15); periodData = 15; new AsyncTasks(PointHistoryActivity.this, cal, point, PointHistoryActivity.this) .execute(2); progressDialogOn(); break; case 3: cal.add(Calendar.DATE, -30); periodData = 30; new AsyncTasks(PointHistoryActivity.this, cal, point, PointHistoryActivity.this) .execute(2); progressDialogOn(); break; case 4: cal.add(Calendar.MONTH, -3); periodData = 3; new AsyncTasks(PointHistoryActivity.this, cal, point, PointHistoryActivity.this) .execute(2); progressDialogOn(); break; case 5: cal.add(Calendar.MONTH, -6); periodData = 6; new AsyncTasks(PointHistoryActivity.this, cal, point, PointHistoryActivity.this) .execute(2); progressDialogOn(); break; case 6: cal.add(Calendar.YEAR, -1); periodData = 12; new AsyncTasks(PointHistoryActivity.this, cal, point, PointHistoryActivity.this) .execute(2); progressDialogOn(); break; case 7: /*DialogFragment fragment = new DateRangePickerFragment(); fragment.show(getSupportFragmentManager(), null);*/ break; } } else Toast.makeText( PointHistoryActivity.this, "Add any hierarchy to your point. After you can create your chart.", Toast.LENGTH_SHORT) .show(); } }); tvOne = (TextView) findViewById(R.id.tv_value_one); tvTwo = (TextView) findViewById(R.id.tv_value_two); tvThree = (TextView) findViewById(R.id.tv_value_three); if (point.getCategoryString().equals("water") || point.getCategoryString().equals("energy")) { tvOne.setText("Total:"); tvTwo.setText("Average:"); tvThree.setText("Amount payable:"); } else if (point.getCategoryString().equals("weather")) { tvOne.setText("Average:"); tvTwo.setText("Maximum:"); tvThree.setText("Minimum:"); } else if (point.getCategoryString().equals("light")) { tvOne.setText("Time On:"); tvTwo.setText("Time Off:"); tvThree.setText("Consumption:"); } }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override protected void onCreate() { View v = LayoutInflater.from(getContext()).inflate(R.layout.dialog_recurring, null); setContentView(v); FrameLayout fl_mode = (FrameLayout) v.findViewById(R.id.rd_fl_mode); final ScrollView sv_repeat = (ScrollView) v.findViewById(R.id.rd_sv_repeat); final LinearLayout ll_repeat = (LinearLayout) v.findViewById(R.id.rd_ll_repeat); mModeSpinner = (Spinner) fl_mode.findViewById(R.id.rd_spn_mode); mEndSpinner = (Spinner) v.findViewById(R.id.rd_spn_end); mPeriodEditText = (EditText) v.findViewById(R.id.rd_et_period); mPeriodUnitTextView = (TextView) v.findViewById(R.id.rd_tv_period_unit); mSameDayRadioButton = (RadioButton) v.findViewById(R.id.rd_month_rb_same); mSameWeekdayRadioButton = (RadioButton) v.findViewById(R.id.rd_month_rb_week); mEndNumEditText = (EditText) v.findViewById(R.id.rd_et_end_num); mEndNumUnitTextView = (TextView) v.findViewById(R.id.rd_tv_end_num_unit); mEndDateButton = (Button) v.findViewById(R.id.rd_bt_end_date); mWeekView = (WeekView) v.findViewById(R.id.rd_wv_week); sv_repeat .getViewTreeObserver() .addOnGlobalLayoutListener( new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { showDivider(ll_repeat.getMeasuredHeight() > sv_repeat.getMeasuredHeight()); } }); mHeaderBackground = new HeaderDrawable(getContext()); ViewCompat.setPaddingRelative(fl_mode, mContentPadding, 0, mContentPadding, 0); ViewUtil.setBackground(fl_mode, mHeaderBackground); ViewCompat.setPaddingRelative( ll_repeat, mContentPadding, mActionOuterPadding, mContentPadding, mActionPadding); mModeAdapter = new ModeAdapter(); mModeSpinner.setAdapter(mModeAdapter); mModeSpinner.setOnItemSelectedListener( new Spinner.OnItemSelectedListener() { @Override public void onItemSelected(Spinner parent, View view, int position, long id) { onModeSelected(position); } }); mEndAdapter = new EndAdapter(); mEndSpinner.setAdapter(mEndAdapter); mEndSpinner.setOnItemSelectedListener( new Spinner.OnItemSelectedListener() { @Override public void onItemSelected(Spinner parent, View view, int position, long id) { onEndSelected(position); } }); mPeriodEditText.addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void onTextChanged(CharSequence s, int start, int before, int count) {} @Override public void afterTextChanged(Editable s) { onPeriodChanged(); } }); mPeriodEditText.setOnKeyListener( new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_UP) { String text = mPeriodEditText.getText().toString(); if (TextUtils.isEmpty(text)) mPeriodEditText.setText(String.valueOf(mRecurring.getPeriod())); } return false; } }); CompoundButton.OnCheckedChangeListener mCheckChangeListener = new android.widget.CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged( android.widget.CompoundButton buttonView, boolean isChecked) { if (isChecked) { if (buttonView == mSameDayRadioButton) mSameWeekdayRadioButton.setChecked(false); else mSameDayRadioButton.setChecked(false); onMonthSettingChanged(); } } }; mSameDayRadioButton.setOnCheckedChangeListener(mCheckChangeListener); mSameWeekdayRadioButton.setOnCheckedChangeListener(mCheckChangeListener); mEndNumEditText.addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void onTextChanged(CharSequence s, int start, int before, int count) {} @Override public void afterTextChanged(Editable s) { onEventNumberChanged(); } }); mEndNumEditText.setOnKeyListener( new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_UP) { String text = mEndNumEditText.getText().toString(); if (TextUtils.isEmpty(text)) mEndNumEditText.setText(String.valueOf(mRecurring.getEventNumber())); } return false; } }); View.OnClickListener mDateClickListener = new View.OnClickListener() { @Override public void onClick(View v) { final DatePickerDialog dialog = new DatePickerDialog(getContext(), mDatePickerDialogStyleId); long minTime = System.currentTimeMillis(); Calendar cal = dialog.getCalendar(); cal.setTimeInMillis(minTime); cal.add(Calendar.YEAR, 100); long maxTime = cal.getTimeInMillis(); dialog .dateRange(minTime, maxTime) .date((long) mEndDateButton.getTag()) .positiveAction(mPositiveAction.getText()) .positiveActionClickListener( new View.OnClickListener() { @Override public void onClick(View v) { onEndDateChanged(dialog.getDate()); dialog.dismiss(); } }) .negativeAction(mNegativeAction.getText()) .negativeActionClickListener( new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }) .show(); } }; mEndDateButton.setOnClickListener(mDateClickListener); mWeekView.setOnDaySelectionChangedListener(this); }