List of usage examples for android.widget Spinner setEnabled
@Override public void setEnabled(boolean enabled)
From source file:com.mantz_it.rfanalyzer.ui.activity.MainActivity.java
public void showRecordingDialog() { if (!running || scheduler == null || demodulator == null || source == null) { toaster.showLong("Analyzer must be running to start recording"); return;/*from ww w . j a v a2 s . c o m*/ } // Check for the WRITE_EXTERNAL_STORAGE permission: if (ContextCompat.checkSelfPermission(this, "android.permission.WRITE_EXTERNAL_STORAGE") != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[] { "android.permission.WRITE_EXTERNAL_STORAGE" }, PERMISSION_REQUEST_RECORDING_WRITE_FILES); return; // wait for the permission response (handled in onRequestPermissionResult()) } final String externalDir = Environment.getExternalStorageDirectory().getAbsolutePath(); final int[] supportedSampleRates = rxSampleRate.getSupportedSampleRates(); final double maxFreqMHz = rxFrequency.getMax() / 1000000f; // max frequency of the source in MHz final int sourceType = Integer.parseInt(preferences.getString(getString(R.string.pref_sourceType), "1")); final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.US); // Get references to the GUI components: final ScrollView view = (ScrollView) this.getLayoutInflater().inflate(R.layout.start_recording, null); final EditText et_filename = (EditText) view.findViewById(R.id.et_recording_filename); final EditText et_frequency = (EditText) view.findViewById(R.id.et_recording_frequency); final Spinner sp_sampleRate = (Spinner) view.findViewById(R.id.sp_recording_sampleRate); final TextView tv_fixedSampleRateHint = (TextView) view.findViewById(R.id.tv_recording_fixedSampleRateHint); final CheckBox cb_stopAfter = (CheckBox) view.findViewById(R.id.cb_recording_stopAfter); final EditText et_stopAfter = (EditText) view.findViewById(R.id.et_recording_stopAfter); final Spinner sp_stopAfter = (Spinner) view.findViewById(R.id.sp_recording_stopAfter); // Setup the sample rate spinner: final ArrayAdapter<Integer> sampleRateAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1); for (int sampR : supportedSampleRates) sampleRateAdapter.add(sampR); sampleRateAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sp_sampleRate.setAdapter(sampleRateAdapter); // Add listener to the frequency textfield, the sample rate spinner and the checkbox: et_frequency.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) { if (et_frequency.getText().length() == 0) return; double freq = Double.parseDouble(et_frequency.getText().toString()); if (freq < maxFreqMHz) freq = freq * 1000000; et_filename.setText(simpleDateFormat.format(new Date()) + "_" + SOURCE_NAMES[sourceType] + "_" + (long) freq + "Hz_" + sp_sampleRate.getSelectedItem() + "Sps.iq"); } }); sp_sampleRate.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (et_frequency.getText().length() == 0) return; double freq = Double.parseDouble(et_frequency.getText().toString()); if (freq < maxFreqMHz) freq = freq * 1000000; et_filename.setText(simpleDateFormat.format(new Date()) + "_" + SOURCE_NAMES[sourceType] + "_" + (long) freq + "Hz_" + sp_sampleRate.getSelectedItem() + "Sps.iq"); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); cb_stopAfter.setOnCheckedChangeListener((buttonView, isChecked) -> { et_stopAfter.setEnabled(isChecked); sp_stopAfter.setEnabled(isChecked); }); // Set default frequency, sample rate and stop after values: et_frequency.setText(Long.toString(analyzerSurface.getVirtualFrequency())); int sampleRateIndex = 0; int lastSampleRate = preferences.getInt(getString(R.string.pref_recordingSampleRate), 1000000); for (; sampleRateIndex < supportedSampleRates.length; sampleRateIndex++) { if (supportedSampleRates[sampleRateIndex] >= lastSampleRate) break; } if (sampleRateIndex >= supportedSampleRates.length) sampleRateIndex = supportedSampleRates.length - 1; sp_sampleRate.setSelection(sampleRateIndex); cb_stopAfter.toggle(); // just to trigger the listener at least once! cb_stopAfter.setChecked(preferences.getBoolean(getString(R.string.pref_recordingStopAfterEnabled), false)); et_stopAfter.setText( Integer.toString(preferences.getInt(getString(R.string.pref_recordingStopAfterValue), 10))); sp_stopAfter.setSelection(preferences.getInt(getString(R.string.pref_recordingStopAfterUnit), 0)); // disable sample rate selection if demodulation is running: if (demodulationMode != Demodulator.DEMODULATION_OFF) { sampleRateAdapter.add(rxSampleRate.get()); // add the current sample rate in case it's not already in the list sp_sampleRate.setSelection(sampleRateAdapter.getPosition(rxSampleRate.get())); // select it sp_sampleRate.setEnabled(false); // disable the spinner tv_fixedSampleRateHint.setVisibility(View.VISIBLE); } // Show dialog: new AlertDialog.Builder(this).setTitle("Start recording").setView(view) .setPositiveButton("Record", (dialog, whichButton) -> { String filename = et_filename.getText().toString(); final int stopAfterUnit = sp_stopAfter.getSelectedItemPosition(); final int stopAfterValue = Integer.parseInt(et_stopAfter.getText().toString()); //todo check filename // Set the frequency in the source: if (et_frequency.getText().length() == 0) return; double freq = Double.parseDouble(et_frequency.getText().toString()); if (freq < maxFreqMHz) freq = freq * 1000000; if (freq <= rxFrequency.getMax() && freq >= rxFrequency.getMin()) rxFrequency.set((long) freq); else { toaster.showLong("Frequency is invalid!"); return; } // Set the sample rate (only if demodulator is off): if (demodulationMode == Demodulator.DEMODULATION_OFF) rxSampleRate.set((Integer) sp_sampleRate.getSelectedItem()); // Open file and start recording: recordingFile = new File(externalDir + "/" + RECORDING_DIR + "/" + filename); recordingFile.getParentFile().mkdir(); // Create directory if it does not yet exist try { scheduler.startRecording(new BufferedOutputStream(new FileOutputStream(recordingFile))); } catch (FileNotFoundException e) { Log.e(LOGTAG, "showRecordingDialog: File not found: " + recordingFile.getAbsolutePath()); } // safe preferences: SharedPreferences.Editor edit = preferences.edit(); edit.putInt(getString(R.string.pref_recordingSampleRate), (Integer) sp_sampleRate.getSelectedItem()); edit.putBoolean(getString(R.string.pref_recordingStopAfterEnabled), cb_stopAfter.isChecked()); edit.putInt(getString(R.string.pref_recordingStopAfterValue), stopAfterValue); edit.putInt(getString(R.string.pref_recordingStopAfterUnit), stopAfterUnit); edit.apply(); analyzerSurface.setRecordingEnabled(true); updateActionBar(); // if stopAfter was selected, start thread to supervise the recording: if (cb_stopAfter.isChecked()) { final String recorderSuperviserName = "Supervisor Thread"; Thread supervisorThread = new Thread(() -> { Log.i(LOGTAG, "recording_superviser: Supervisor Thread started. (Thread: " + recorderSuperviserName + ")"); try { long startTime = System.currentTimeMillis(); boolean stop = false; // We check once per half a second if the stop criteria is met: Thread.sleep(500); while (recordingFile != null && !stop) { switch (stopAfterUnit) { // see arrays.xml - recording_stopAfterUnit case 0: /* MB */ if (recordingFile.length() / 1000000 >= stopAfterValue) stop = true; break; case 1: /* GB */ if (recordingFile.length() / 1000000000 >= stopAfterValue) stop = true; break; case 2: /* sec */ if (System.currentTimeMillis() - startTime >= stopAfterValue * 1000) stop = true; break; case 3: /* min */ if (System.currentTimeMillis() - startTime >= stopAfterValue * 1000 * 60) stop = true; break; } } // stop recording: stopRecording(); } catch (InterruptedException e) { // todo: shouldn't we call stopRecording() here? how about finally{}? Log.e(LOGTAG, "recording_superviser: Interrupted!"); } catch (NullPointerException e) { Log.e(LOGTAG, "recording_superviser: Recording file is null!"); } Log.i(LOGTAG, "recording_superviser: Supervisor Thread stopped. (Thread: " + recorderSuperviserName + ")"); }, recorderSuperviserName); supervisorThread.start(); } }).setNegativeButton("Cancel", (dialog, whichButton) -> { // do nothing }).show().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); }
From source file:com.mantz_it.rfanalyzer.MainActivity.java
public void showRecordingDialog() { if (!running || scheduler == null || demodulator == null || source == null) { Toast.makeText(MainActivity.this, "Analyzer must be running to start recording", Toast.LENGTH_LONG) .show();//w ww . j a va 2s . c o m return; } // Check for the WRITE_EXTERNAL_STORAGE permission: if (ContextCompat.checkSelfPermission(this, "android.permission.WRITE_EXTERNAL_STORAGE") != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[] { "android.permission.WRITE_EXTERNAL_STORAGE" }, PERMISSION_REQUEST_RECORDING_WRITE_FILES); return; // wait for the permission response (handled in onRequestPermissionResult()) } final String externalDir = Environment.getExternalStorageDirectory().getAbsolutePath(); final int[] supportedSampleRates = source.getSupportedSampleRates(); final double maxFreqMHz = source.getMaxFrequency() / 1000000f; // max frequency of the source in MHz final int sourceType = Integer.valueOf(preferences.getString(getString(R.string.pref_sourceType), "1")); final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.US); // Get references to the GUI components: final ScrollView view = (ScrollView) this.getLayoutInflater().inflate(R.layout.start_recording, null); final EditText et_filename = (EditText) view.findViewById(R.id.et_recording_filename); final EditText et_frequency = (EditText) view.findViewById(R.id.et_recording_frequency); final Spinner sp_sampleRate = (Spinner) view.findViewById(R.id.sp_recording_sampleRate); final TextView tv_fixedSampleRateHint = (TextView) view.findViewById(R.id.tv_recording_fixedSampleRateHint); final CheckBox cb_stopAfter = (CheckBox) view.findViewById(R.id.cb_recording_stopAfter); final EditText et_stopAfter = (EditText) view.findViewById(R.id.et_recording_stopAfter); final Spinner sp_stopAfter = (Spinner) view.findViewById(R.id.sp_recording_stopAfter); // Setup the sample rate spinner: final ArrayAdapter<Integer> sampleRateAdapter = new ArrayAdapter<Integer>(this, android.R.layout.simple_list_item_1); for (int sampR : supportedSampleRates) sampleRateAdapter.add(sampR); sampleRateAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sp_sampleRate.setAdapter(sampleRateAdapter); // Add listener to the frequency textfield, the sample rate spinner and the checkbox: et_frequency.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) { if (et_frequency.getText().length() == 0) return; double freq = Double.valueOf(et_frequency.getText().toString()); if (freq < maxFreqMHz) freq = freq * 1000000; et_filename.setText(simpleDateFormat.format(new Date()) + "_" + SOURCE_NAMES[sourceType] + "_" + (long) freq + "Hz_" + sp_sampleRate.getSelectedItem() + "Sps.iq"); } }); sp_sampleRate.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (et_frequency.getText().length() == 0) return; double freq = Double.valueOf(et_frequency.getText().toString()); if (freq < maxFreqMHz) freq = freq * 1000000; et_filename.setText(simpleDateFormat.format(new Date()) + "_" + SOURCE_NAMES[sourceType] + "_" + (long) freq + "Hz_" + sp_sampleRate.getSelectedItem() + "Sps.iq"); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); cb_stopAfter.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { et_stopAfter.setEnabled(isChecked); sp_stopAfter.setEnabled(isChecked); } }); // Set default frequency, sample rate and stop after values: et_frequency.setText("" + analyzerSurface.getVirtualFrequency()); int sampleRateIndex = 0; int lastSampleRate = preferences.getInt(getString(R.string.pref_recordingSampleRate), 1000000); for (; sampleRateIndex < supportedSampleRates.length; sampleRateIndex++) { if (supportedSampleRates[sampleRateIndex] >= lastSampleRate) break; } if (sampleRateIndex >= supportedSampleRates.length) sampleRateIndex = supportedSampleRates.length - 1; sp_sampleRate.setSelection(sampleRateIndex); cb_stopAfter.toggle(); // just to trigger the listener at least once! cb_stopAfter.setChecked(preferences.getBoolean(getString(R.string.pref_recordingStopAfterEnabled), false)); et_stopAfter.setText("" + preferences.getInt(getString(R.string.pref_recordingStopAfterValue), 10)); sp_stopAfter.setSelection(preferences.getInt(getString(R.string.pref_recordingStopAfterUnit), 0)); // disable sample rate selection if demodulation is running: if (demodulationMode != Demodulator.DEMODULATION_OFF) { sampleRateAdapter.add(source.getSampleRate()); // add the current sample rate in case it's not already in the list sp_sampleRate.setSelection(sampleRateAdapter.getPosition(source.getSampleRate())); // select it sp_sampleRate.setEnabled(false); // disable the spinner tv_fixedSampleRateHint.setVisibility(View.VISIBLE); } // Show dialog: new AlertDialog.Builder(this).setTitle("Start recording").setView(view) .setPositiveButton("Record", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String filename = et_filename.getText().toString(); final int stopAfterUnit = sp_stopAfter.getSelectedItemPosition(); final int stopAfterValue = Integer.valueOf(et_stopAfter.getText().toString()); //todo check filename // Set the frequency in the source: if (et_frequency.getText().length() == 0) return; double freq = Double.valueOf(et_frequency.getText().toString()); if (freq < maxFreqMHz) freq = freq * 1000000; if (freq <= source.getMaxFrequency() && freq >= source.getMinFrequency()) source.setFrequency((long) freq); else { Toast.makeText(MainActivity.this, "Frequency is invalid!", Toast.LENGTH_LONG).show(); return; } // Set the sample rate (only if demodulator is off): if (demodulationMode == Demodulator.DEMODULATION_OFF) source.setSampleRate((Integer) sp_sampleRate.getSelectedItem()); // Open file and start recording: recordingFile = new File(externalDir + "/" + RECORDING_DIR + "/" + filename); recordingFile.getParentFile().mkdir(); // Create directory if it does not yet exist try { scheduler.startRecording(new BufferedOutputStream(new FileOutputStream(recordingFile))); } catch (FileNotFoundException e) { Log.e(LOGTAG, "showRecordingDialog: File not found: " + recordingFile.getAbsolutePath()); } // safe preferences: SharedPreferences.Editor edit = preferences.edit(); edit.putInt(getString(R.string.pref_recordingSampleRate), (Integer) sp_sampleRate.getSelectedItem()); edit.putBoolean(getString(R.string.pref_recordingStopAfterEnabled), cb_stopAfter.isChecked()); edit.putInt(getString(R.string.pref_recordingStopAfterValue), stopAfterValue); edit.putInt(getString(R.string.pref_recordingStopAfterUnit), stopAfterUnit); edit.apply(); analyzerSurface.setRecordingEnabled(true); updateActionBar(); // if stopAfter was selected, start thread to supervise the recording: if (cb_stopAfter.isChecked()) { Thread supervisorThread = new Thread() { @Override public void run() { Log.i(LOGTAG, "recording_superviser: Supervisor Thread started. (Thread: " + this.getName() + ")"); try { long startTime = System.currentTimeMillis(); boolean stop = false; // We check once per half a second if the stop criteria is met: Thread.sleep(500); while (recordingFile != null && !stop) { switch (stopAfterUnit) { // see arrays.xml - recording_stopAfterUnit case 0: /* MB */ if (recordingFile.length() / 1000000 >= stopAfterValue) stop = true; break; case 1: /* GB */ if (recordingFile.length() / 1000000000 >= stopAfterValue) stop = true; break; case 2: /* sec */ if (System.currentTimeMillis() - startTime >= stopAfterValue * 1000) stop = true; break; case 3: /* min */ if (System.currentTimeMillis() - startTime >= stopAfterValue * 1000 * 60) stop = true; break; } } // stop recording: stopRecording(); } catch (InterruptedException e) { Log.e(LOGTAG, "recording_superviser: Interrupted!"); } catch (NullPointerException e) { Log.e(LOGTAG, "recording_superviser: Recording file is null!"); } Log.i(LOGTAG, "recording_superviser: Supervisor Thread stopped. (Thread: " + this.getName() + ")"); } }; supervisorThread.start(); } } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // do nothing } }).show().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); }
From source file:org.tvbrowser.tvbrowser.TvBrowser.java
private void showEpgDonateInfo() { if (!SHOWING_DONATION_INFO && hasEpgDonateChannelsSubscribed()) { final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(TvBrowser.this); final String year = String.valueOf(Calendar.getInstance().get(Calendar.YEAR)); int month = Calendar.getInstance().get(Calendar.MONTH); final long now = System.currentTimeMillis(); long firstDownload = pref.getLong(getString(R.string.EPG_DONATE_FIRST_DATA_DOWNLOAD), now); long lastDownload = pref.getLong(getString(R.string.EPG_DONATE_LAST_DATA_DOWNLOAD), now); long lastShown = pref.getLong(getString(R.string.EPG_DONATE_LAST_DONATION_INFO_SHOWN), (now - (60 * 24 * 60 * 60000L))); Calendar monthTest = Calendar.getInstance(); monthTest.setTimeInMillis(lastShown); int shownMonth = monthTest.get(Calendar.MONTH); boolean firstTimeoutReached = (firstDownload + (14 * 24 * 60 * 60000L)) < now; boolean lastTimoutReached = lastDownload > (now - ((42 * 24 * 60 * 60000L))); boolean alreadyShowTimeoutReached = (lastShown + (14 * 24 * 60 * 60000L) < now); boolean alreadyShownThisMonth = shownMonth == month; boolean dontShowAgainThisYear = year .equals(pref.getString(getString(R.string.EPG_DONATE_DONT_SHOW_AGAIN_YEAR), "0")); boolean radomShow = Math.random() > 0.33; boolean show = firstTimeoutReached && lastTimoutReached && alreadyShowTimeoutReached && !alreadyShownThisMonth && !dontShowAgainThisYear && radomShow; //Log.d("info21", "firstTimeoutReached (" + ((now - firstDownload)/(24 * 60 * 60000L)) + "): " + firstTimeoutReached + " lastTimoutReached: " + lastTimoutReached + " alreadyShowTimeoutReached: " + alreadyShowTimeoutReached + " alreadyShownThisMonth: " + alreadyShownThisMonth + " dontShowAgainThisYear: " + dontShowAgainThisYear + " randomShow: " + radomShow + " SHOW: " + show); if (show) { AlertDialog.Builder builder = new AlertDialog.Builder(TvBrowser.this); String info = getString(R.string.epg_donate_info); String amount = getString(R.string.epg_donate_amount); String percentInfo = getString(R.string.epg_donate_percent_info); String amountValue = pref.getString( getString(R.string.EPG_DONATE_CURRENT_DONATION_AMOUNT_PREFIX) + "_" + year, getString(R.string.epg_donate_current_donation_amount_default)); int percentValue = Integer .parseInt(pref.getString(getString(R.string.EPG_DONATE_CURRENT_DONATION_PERCENT), "-1")); amount = amount.replace("{0}", year).replace("{1}", amountValue); info = info.replace("{0}", "<h2>" + amount + "</h2>"); builder.setTitle(R.string.epg_donate_name); builder.setCancelable(false); View view = getLayoutInflater().inflate(R.layout.dialog_epg_donate_info, getParentViewGroup(), false);//from w w w . j a va 2 s . co m TextView message = (TextView) view.findViewById(R.id.dialog_epg_donate_message); message.setText(Html.fromHtml(info)); message.setMovementMethod(LinkMovementMethod.getInstance()); TextView percentInfoView = (TextView) view.findViewById(R.id.dialog_epg_donate_percent_info); percentInfoView.setText(Html.fromHtml(percentInfo, null, new NewsTagHandler())); SeekBar percent = (SeekBar) view.findViewById(R.id.dialog_epg_donate_percent); percent.setEnabled(false); if (percentValue >= 0) { percent.setProgress(percentValue); } else { percentInfoView.setVisibility(View.GONE); percent.setVisibility(View.GONE); } final Spinner reason = (Spinner) view.findViewById(R.id.dialog_epg_donate_reason_selection); reason.setEnabled(false); final CheckBox dontShowAgain = (CheckBox) view.findViewById(R.id.dialog_epg_donate_dont_show_again); dontShowAgain.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { reason.setEnabled(isChecked); } }); builder.setView(view); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { SHOWING_DONATION_INFO = false; Editor edit = pref.edit(); edit.putLong(getString(R.string.EPG_DONATE_LAST_DONATION_INFO_SHOWN), now); if (dontShowAgain.isChecked()) { edit.putString(getString(R.string.EPG_DONATE_DONT_SHOW_AGAIN_YEAR), year); } edit.commit(); } }); builder.show(); SHOWING_DONATION_INFO = true; } } }
From source file:org.tvbrowser.tvbrowser.TvBrowser.java
private void updateTvData() { if (!TvDataUpdateService.IS_RUNNING) { Cursor test = getContentResolver().query(TvBrowserContentProvider.CONTENT_URI_CHANNELS, null, TvBrowserContentProvider.CHANNEL_KEY_SELECTION + "=1", null, null); if (test.getCount() > 0) { AlertDialog.Builder builder = new AlertDialog.Builder(TvBrowser.this); RelativeLayout dataDownload = (RelativeLayout) getLayoutInflater() .inflate(R.layout.dialog_data_update_selection, getParentViewGroup(), false); final Spinner days = (Spinner) dataDownload .findViewById(R.id.dialog_data_update_selection_download_days); final CheckBox pictures = (CheckBox) dataDownload .findViewById(R.id.dialog_data_update_selection_download_picture); final Spinner autoUpdate = (Spinner) dataDownload .findViewById(R.id.dialog_data_update_preferences_auto_update_selection_type); final Spinner frequency = (Spinner) dataDownload .findViewById(R.id.dialog_data_update_preferences_auto_update_selection_frequency); final CheckBox onlyWiFi = (CheckBox) dataDownload .findViewById(R.id.dialog_data_update_preferences_auto_update_selection_type_connection); final TextView timeLabel = (TextView) dataDownload .findViewById(R.id.dialog_data_update_preferences_auto_update_selection_time_label); final TextView time = (TextView) dataDownload .findViewById(R.id.dialog_data_update_preferences_auto_update_selection_time); time.setTextColor(onlyWiFi.getTextColors()); String currentDownloadDays = PrefUtils.getStringValue(R.string.DAYS_TO_DOWNLOAD, R.string.days_to_download_default); final String[] possibleDownloadDays = getResources().getStringArray(R.array.download_days); for (int i = 0; i < possibleDownloadDays.length; i++) { if (currentDownloadDays.equals(possibleDownloadDays[i])) { days.setSelection(i); break; }//w w w . jav a2s . c o m } pictures.setChecked( PrefUtils.getBooleanValue(R.string.LOAD_PICTURE_DATA, R.bool.load_picture_data_default)); String currentAutoUpdateValue = PrefUtils.getStringValue(R.string.PREF_AUTO_UPDATE_TYPE, R.string.pref_auto_update_type_default); String currentAutoUpdateFrequency = PrefUtils.getStringValue(R.string.PREF_AUTO_UPDATE_FREQUENCY, R.string.pref_auto_update_frequency_default); if (currentAutoUpdateValue.equals("0")) { frequency.setEnabled(false); onlyWiFi.setEnabled(false); timeLabel.setEnabled(false); time.setEnabled(false); frequency.setVisibility(View.GONE); onlyWiFi.setVisibility(View.GONE); timeLabel.setVisibility(View.GONE); time.setVisibility(View.GONE); } else if (currentAutoUpdateValue.equals("1")) { autoUpdate.setSelection(1); timeLabel.setEnabled(false); time.setEnabled(false); timeLabel.setVisibility(View.GONE); time.setVisibility(View.GONE); } else if (currentAutoUpdateValue.equals("2")) { autoUpdate.setSelection(2); } final String[] autoFrequencyPossibleValues = getResources() .getStringArray(R.array.pref_auto_update_frequency_values); for (int i = 0; i < autoFrequencyPossibleValues.length; i++) { if (autoFrequencyPossibleValues[i].equals(currentAutoUpdateFrequency)) { frequency.setSelection(i); break; } } onlyWiFi.setChecked(PrefUtils.getBooleanValue(R.string.PREF_AUTO_UPDATE_ONLY_WIFI, R.bool.pref_auto_update_only_wifi_default)); final AtomicInteger currentAutoUpdateTime = new AtomicInteger(PrefUtils.getIntValue( R.string.PREF_AUTO_UPDATE_START_TIME, R.integer.pref_auto_update_start_time_default)); Calendar now = Calendar.getInstance(); now.set(Calendar.HOUR_OF_DAY, currentAutoUpdateTime.get() / 60); now.set(Calendar.MINUTE, currentAutoUpdateTime.get() % 60); now.set(Calendar.SECOND, 0); now.set(Calendar.MILLISECOND, 0); time.setText(DateFormat.getTimeFormat(TvBrowser.this).format(now.getTime())); autoUpdate.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { frequency.setEnabled(position != 0); onlyWiFi.setEnabled(position != 0); if (position != 0) { frequency.setVisibility(View.VISIBLE); onlyWiFi.setVisibility(View.VISIBLE); } else { frequency.setVisibility(View.GONE); onlyWiFi.setVisibility(View.GONE); } timeLabel.setEnabled(position == 2); time.setEnabled(position == 2); if (position == 2) { timeLabel.setVisibility(View.VISIBLE); time.setVisibility(View.VISIBLE); } else { timeLabel.setVisibility(View.GONE); time.setVisibility(View.GONE); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); View.OnClickListener onClickListener = new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder b2 = new AlertDialog.Builder(TvBrowser.this); LinearLayout timeSelection = (LinearLayout) getLayoutInflater().inflate( R.layout.dialog_data_update_selection_auto_update_time, getParentViewGroup(), false); final TimePicker timePick = (TimePicker) timeSelection .findViewById(R.id.dialog_data_update_selection_auto_update_selection_time); timePick.setIs24HourView(DateFormat.is24HourFormat(TvBrowser.this)); timePick.setCurrentHour(currentAutoUpdateTime.get() / 60); timePick.setCurrentMinute(currentAutoUpdateTime.get() % 60); b2.setView(timeSelection); b2.setPositiveButton(android.R.string.ok, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { currentAutoUpdateTime .set(timePick.getCurrentHour() * 60 + timePick.getCurrentMinute()); Calendar now = Calendar.getInstance(); now.set(Calendar.HOUR_OF_DAY, currentAutoUpdateTime.get() / 60); now.set(Calendar.MINUTE, currentAutoUpdateTime.get() % 60); now.set(Calendar.SECOND, 0); now.set(Calendar.MILLISECOND, 0); time.setText(DateFormat.getTimeFormat(TvBrowser.this).format(now.getTime())); } }); b2.setNegativeButton(android.R.string.cancel, null); b2.show(); } }; time.setOnClickListener(onClickListener); timeLabel.setOnClickListener(onClickListener); builder.setTitle(R.string.download_data); builder.setView(dataDownload); builder.setPositiveButton(android.R.string.ok, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String value = possibleDownloadDays[days.getSelectedItemPosition()]; Editor settings = PreferenceManager.getDefaultSharedPreferences(TvBrowser.this).edit(); if (PrefUtils.getStringValueAsInt(R.string.PREF_AUTO_UPDATE_RANGE, R.string.pref_auto_update_range_default) < Integer.parseInt(value)) { settings.putString(getString(R.string.PREF_AUTO_UPDATE_RANGE), value); } settings.putString(getString(R.string.DAYS_TO_DOWNLOAD), value); settings.putBoolean(getString(R.string.LOAD_PICTURE_DATA), pictures.isChecked()); settings.putString(getString(R.string.PREF_AUTO_UPDATE_TYPE), String.valueOf(autoUpdate.getSelectedItemPosition())); if (autoUpdate.getSelectedItemPosition() == 1 || autoUpdate.getSelectedItemPosition() == 2) { settings.putString(getString(R.string.PREF_AUTO_UPDATE_FREQUENCY), autoFrequencyPossibleValues[frequency.getSelectedItemPosition()]); settings.putBoolean(getString(R.string.PREF_AUTO_UPDATE_ONLY_WIFI), onlyWiFi.isChecked()); if (autoUpdate.getSelectedItemPosition() == 2) { settings.putInt(getString(R.string.PREF_AUTO_UPDATE_START_TIME), currentAutoUpdateTime.get()); } } settings.commit(); IOUtils.handleDataUpdatePreferences(TvBrowser.this); Intent startDownload = new Intent(TvBrowser.this, TvDataUpdateService.class); startDownload.putExtra(TvDataUpdateService.TYPE, TvDataUpdateService.TV_DATA_TYPE); startDownload.putExtra(getResources().getString(R.string.DAYS_TO_DOWNLOAD), Integer.parseInt(value)); startService(startDownload); updateProgressIcon(true); } }); builder.setNegativeButton(android.R.string.cancel, null); builder.show(); } else { Cursor test2 = getContentResolver().query(TvBrowserContentProvider.CONTENT_URI_CHANNELS, null, null, null, null); boolean loadAgain = test2.getCount() < 1; test2.close(); selectChannels(loadAgain); } test.close(); } }
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 w w w .j av a 2 s. c o m*/ 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; } }
From source file:com.sentaroh.android.TaskAutomation.Config.ProfileMaintenanceActionProfile.java
final static private void editActivityExtraDataItem(final GlobalParameters mGlblParms, final int sel_pos) { // ??/*w w w. j a v a2 s . co m*/ final Dialog dialog = new Dialog(mGlblParms.context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // dialog.getWindow().setSoftInputMode( // WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); dialog.setContentView(R.layout.edit_activity_extra_data_item_dlg); final TextView dlg_msg = (TextView) dialog.findViewById(R.id.edit_activity_extra_data_item_msg); // final TextView dlg_title = (TextView) dialog.findViewById(R.id.edit_activity_extra_data_item_title); // CommonDialog.setDlgBoxSizeLimit(dialog,true); final Button btn_cancel = (Button) dialog.findViewById(R.id.edit_activity_extra_data_item_cancel_btn); final Button btn_ok = (Button) dialog.findViewById(R.id.edit_activity_extra_data_item_ok_btn); final EditText et_key = (EditText) dialog.findViewById(R.id.edit_activity_extra_data_item_key); final EditText et_string = (EditText) dialog.findViewById(R.id.edit_activity_extra_data_item_data_string); final EditText et_int = (EditText) dialog.findViewById(R.id.edit_activity_extra_data_item_data_int); final CheckBox cb_array = (CheckBox) dialog.findViewById(R.id.edit_activity_extra_data_item_array); final Button btn_add_array = (Button) dialog.findViewById(R.id.edit_activity_extra_data_item_add_array); final ListView lv_array = (ListView) dialog.findViewById(R.id.edit_activity_extra_data_item_array_listview); final TextView lv_spacer = (TextView) dialog.findViewById(R.id.edit_activity_extra_data_item_array_spacer); final Spinner spinnerExtraDataType = (Spinner) dialog .findViewById(R.id.edit_activity_extra_data_item_data_type); final CustomSpinnerAdapter adapterExtraDataType = new CustomSpinnerAdapter(mGlblParms.context, R.layout.custom_simple_spinner_item); adapterExtraDataType.setTextColor(Color.BLACK); setSpinnerExtraDataType(mGlblParms, dialog, spinnerExtraDataType, adapterExtraDataType, PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_STRING); final Spinner spinnerExtraDataBoolean = (Spinner) dialog .findViewById(R.id.edit_activity_extra_data_item_data_boolean); final CustomSpinnerAdapter adapterExtraDataBoolean = new CustomSpinnerAdapter(mGlblParms.context, R.layout.custom_simple_spinner_item); adapterExtraDataBoolean.setTextColor(Color.BLACK); setSpinnerExtraDataBoolean(mGlblParms, dialog, spinnerExtraDataBoolean, adapterExtraDataBoolean, "false"); final Button update_apply = (Button) dialog .findViewById(R.id.edit_activity_extra_data_item_data_update_apply); final Button update_cancel = (Button) dialog .findViewById(R.id.edit_activity_extra_data_item_data_update_cancel); update_apply.setVisibility(Button.GONE); update_cancel.setVisibility(Button.GONE); spinnerExtraDataBoolean.setVisibility(Spinner.GONE); et_string.setVisibility(EditText.GONE); et_int.setVisibility(EditText.GONE); btn_add_array.setVisibility(Button.GONE); lv_array.setVisibility(ListView.GONE); lv_spacer.setVisibility(TextView.VISIBLE); final ArrayList<DataArrayEditListItem> aed_array_list = new ArrayList<DataArrayEditListItem>(); final AdapterDataArrayEditList aed_array_adapter = new AdapterDataArrayEditList(mGlblParms.context, R.layout.data_array_edit_list_item, aed_array_list); lv_array.setAdapter(aed_array_adapter); setActivityExtraDataEditItemViewVisibility(mGlblParms, dialog, aed_array_adapter, spinnerExtraDataType); cb_array.setChecked(false); if (sel_pos != -1) { et_key.setEnabled(false); et_key.setTextColor(Color.WHITE); et_key.selectAll(); et_key.setText(mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).key_value); if (mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).data_type .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_STRING)) { et_string.setText(mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).data_value); spinnerExtraDataType.setSelection(0); } else if (mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).data_type .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_INT)) { et_int.setText(mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).data_value); spinnerExtraDataType.setSelection(1); } else if (mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).data_type .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_BOOLEAN)) { spinnerExtraDataType.setSelection(2); if (mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).data_value.equals("false")) spinnerExtraDataBoolean.setSelection(0); else spinnerExtraDataBoolean.setSelection(1); } mGlblParms.currentSelectedExtraDataType = spinnerExtraDataType.getSelectedItem().toString(); if (mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).data_value_array .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_ARRAY_YES)) { cb_array.setChecked(true); et_string.setText(""); et_int.setText(""); createActivityExtraDataArrayList(aed_array_adapter, mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos)); aed_array_adapter.notifyDataSetChanged(); update_apply.setVisibility(Button.GONE); update_cancel.setVisibility(Button.GONE); spinnerExtraDataBoolean.setVisibility(Spinner.GONE); et_string.setVisibility(EditText.GONE); et_int.setVisibility(EditText.GONE); btn_add_array.setVisibility(Button.VISIBLE); lv_array.setVisibility(ListView.VISIBLE); lv_spacer.setVisibility(TextView.GONE); } else { cb_array.setChecked(false); update_apply.setVisibility(Button.GONE); update_cancel.setVisibility(Button.GONE); spinnerExtraDataBoolean.setVisibility(Spinner.GONE); et_string.setVisibility(EditText.GONE); et_int.setVisibility(EditText.GONE); btn_add_array.setVisibility(Button.GONE); lv_array.setVisibility(ListView.GONE); lv_spacer.setVisibility(TextView.VISIBLE); if (mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).data_type .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_STRING)) { et_string.setVisibility(EditText.VISIBLE); } else if (mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).data_type .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_INT)) { et_int.setVisibility(EditText.VISIBLE); } else if (mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos).data_type .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_BOOLEAN)) { spinnerExtraDataBoolean.setVisibility(Spinner.VISIBLE); } } } btn_add_array.setOnClickListener(new OnClickListener() { @Override final public void onClick(View arg0) { String n_data = ""; if (spinnerExtraDataType.getSelectedItem() .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_STRING)) { n_data = ""; } else if (spinnerExtraDataType.getSelectedItem() .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_INT)) { n_data = "0"; } else if (spinnerExtraDataType.getSelectedItem() .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_BOOLEAN)) { n_data = "false"; } DataArrayEditListItem aeda_item = new DataArrayEditListItem(); aeda_item.data_value = n_data; aed_array_adapter.add(aeda_item); aed_array_adapter.notifyDataSetChanged(); } }); NotifyEvent ntfy = new NotifyEvent(mGlblParms.context); ntfy.setListener(new NotifyEventListener() { @Override final public void positiveResponse(Context c, Object[] o) { spinnerExtraDataType.setEnabled(false); String c_data = (String) o[0]; if (spinnerExtraDataType.getSelectedItem() .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_STRING)) { et_string.setText(c_data); spinnerExtraDataBoolean.setVisibility(Spinner.GONE); et_string.setVisibility(EditText.VISIBLE); et_int.setVisibility(EditText.GONE); et_string.requestFocus(); } else if (spinnerExtraDataType.getSelectedItem() .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_INT)) { et_int.setText(c_data); spinnerExtraDataBoolean.setVisibility(Spinner.GONE); et_string.setVisibility(EditText.GONE); et_int.setVisibility(EditText.VISIBLE); et_int.requestFocus(); } else if (spinnerExtraDataType.getSelectedItem() .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_BOOLEAN)) { if (c_data.equals("false")) spinnerExtraDataBoolean.setSelection(0); else spinnerExtraDataBoolean.setSelection(1); spinnerExtraDataBoolean.setVisibility(Spinner.VISIBLE); et_string.setVisibility(EditText.GONE); et_int.setVisibility(EditText.GONE); } update_apply.setVisibility(Button.VISIBLE); update_cancel.setVisibility(Button.VISIBLE); btn_ok.setEnabled(false); btn_cancel.setEnabled(false); cb_array.setEnabled(false); btn_add_array.setEnabled(false); } @Override final public void negativeResponse(Context c, Object[] o) { } }); aed_array_adapter.setEditBtnNotifyListener(ntfy); update_apply.setVisibility(Button.GONE); update_cancel.setVisibility(Button.GONE); update_apply.setOnClickListener(new View.OnClickListener() { final public void onClick(View v) { boolean no_err = auditActivityExtraData(mGlblParms, dialog, spinnerExtraDataType, spinnerExtraDataBoolean); if (!no_err) return; int pos = -1; for (int i = 0; i < aed_array_list.size(); i++) { if (aed_array_list.get(i).while_edit) { pos = i; break; } } if (spinnerExtraDataType.getSelectedItem() .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_STRING)) { aed_array_list.get(pos).data_value = et_string.getText().toString(); aed_array_list.get(pos).while_edit = false; } else if (spinnerExtraDataType.getSelectedItem() .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_INT)) { aed_array_list.get(pos).data_value = et_int.getText().toString(); aed_array_list.get(pos).while_edit = false; } else if (spinnerExtraDataType.getSelectedItem() .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_BOOLEAN)) { String n_boolean = "true"; if (spinnerExtraDataBoolean.getSelectedItem().toString().equals("false")) n_boolean = "false"; aed_array_list.get(pos).data_value = n_boolean; aed_array_list.get(pos).while_edit = false; } et_string.setText(""); et_int.setText(""); et_string.setVisibility(EditText.GONE); et_int.setVisibility(EditText.GONE); spinnerExtraDataBoolean.setVisibility(Spinner.GONE); aed_array_adapter.notifyDataSetChanged(); update_apply.setVisibility(Button.GONE); update_cancel.setVisibility(Button.GONE); spinnerExtraDataType.setEnabled(true); btn_ok.setEnabled(true); btn_cancel.setEnabled(true); cb_array.setEnabled(true); btn_add_array.setEnabled(true); } }); update_cancel.setOnClickListener(new View.OnClickListener() { final public void onClick(View v) { for (int i = 0; i < aed_array_list.size(); i++) { aed_array_list.get(i).while_edit = false; } et_string.setText(""); et_int.setText(""); et_string.setVisibility(EditText.GONE); et_int.setVisibility(EditText.GONE); spinnerExtraDataBoolean.setVisibility(Spinner.GONE); aed_array_adapter.notifyDataSetChanged(); update_apply.setVisibility(Button.GONE); update_cancel.setVisibility(Button.GONE); spinnerExtraDataType.setEnabled(true); btn_ok.setEnabled(true); btn_cancel.setEnabled(true); cb_array.setEnabled(true); btn_add_array.setEnabled(true); } }); // CANCEL? btn_cancel.setOnClickListener(new View.OnClickListener() { final public void onClick(View v) { dialog.dismiss(); } }); // OK? btn_ok.setOnClickListener(new View.OnClickListener() { final public void onClick(View v) { ActivityExtraDataItem aedi = null; if (sel_pos == -1) {//Add item if (et_key.getText().toString().equals("")) { dlg_msg.setText(mGlblParms.context .getString(R.string.msgs_edit_profile_action_activity_extra_data_key_name_missing)); return; } aedi = new ActivityExtraDataItem(); } else {//Edit item aedi = mGlblParms.activityExtraDataEditListAdapter.getItem(sel_pos); } aedi.key_value = et_key.getText().toString(); if (cb_array.isChecked()) { if (aed_array_list.size() == 0) { dlg_msg.setText(mGlblParms.context.getString( R.string.msgs_edit_profile_action_activity_extra_data_array_data_missing)); return; } aedi.data_value_array = PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_ARRAY_YES; aedi.data_type = spinnerExtraDataType.getSelectedItem().toString(); aedi.data_value = ""; // Log.v("","array size="+aed_array_list.size()); for (int i = 0; i < aed_array_list.size(); i++) { if (aedi.data_type.equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_STRING)) { // aedi.data_value+="\u00a0"+aed_array_list.get(i).array_data_value+"\u0003"; aedi.data_value += aed_array_list.get(i).data_value + "\u0003"; // GeneralUtilities.hexString("String",aed_array_list.get(i).array_data_value.getBytes(),0,aed_array_list.get(i).array_data_value.getBytes().length); } else { aedi.data_value += aed_array_list.get(i).data_value + "\u0003"; // GeneralUtilities.hexString("int",aed_array_list.get(i).data_value.getBytes(),0,aed_array_list.get(i).data_value.getBytes().length); } } // GeneralUtilities.hexString("test",aedi.data_value.getBytes(),0,aedi.data_value.getBytes().length); // Log.v("","dv="+aedi.data_value.replaceAll("\u0003", ";")); } else { boolean no_err = auditActivityExtraData(mGlblParms, dialog, spinnerExtraDataType, spinnerExtraDataBoolean); if (!no_err) return; else { aedi.data_value_array = PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_ARRAY_NO; aedi.data_type = spinnerExtraDataType.getSelectedItem().toString(); if (spinnerExtraDataType.getSelectedItem().toString() .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_STRING)) { aedi.data_value = et_string.getText().toString(); } else if (spinnerExtraDataType.getSelectedItem().toString() .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_INT)) { aedi.data_value = et_int.getText().toString(); } else if (spinnerExtraDataType.getSelectedItem().toString() .equals(PROFILE_ACTION_TYPE_ACTIVITY_EXTRA_DATA_VALUE_BOOLEAN)) { if (spinnerExtraDataBoolean.getSelectedItem().toString().equals("false")) aedi.data_value = "false"; else aedi.data_value = "true"; } } } if (sel_pos == -1) mGlblParms.activityExtraDataEditListAdapter.add(aedi); if (mGlblParms.activityExtraDataEditListAdapter.getItem(0).key_value.equals("")) mGlblParms.activityExtraDataEditListAdapter.remove(0); mGlblParms.activityExtraDataEditListAdapter.notifyDataSetChanged(); dialog.dismiss(); } }); // Cancel? dialog.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { btn_cancel.performClick(); } }); // dialog.setCancelable(false); dialog.show(); }