Example usage for android.widget EditText selectAll

List of usage examples for android.widget EditText selectAll

Introduction

In this page you can find the example usage for android.widget EditText selectAll.

Prototype

public void selectAll() 

Source Link

Document

Convenience for Selection#selectAll .

Usage

From source file:com.sentaroh.android.TaskAutomation.Config.ActivityMain.java

final private void renameProfileGroupDlg(final String old_loc) {
    // ??/*w  ww  . jav  a2s.  co m*/
    final Dialog dialog = new Dialog(mContext);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    //      dialog.getWindow().setSoftInputMode(
    //                WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    dialog.setContentView(R.layout.single_item_input_dlg);
    final TextView dlg_title = (TextView) dialog.findViewById(R.id.single_item_input_title);
    final EditText dlg_et_name = (EditText) dialog.findViewById(R.id.single_item_input_dir);
    //      final TextView dlg_msg = (TextView) dialog.findViewById(R.id.single_item_input_msg);
    final Button btnCancel = (Button) dialog.findViewById(R.id.single_item_input_cancel_btn);
    final Button btnOK = (Button) dialog.findViewById(R.id.single_item_input_ok_btn);
    btnOK.setEnabled(false);

    dlg_title.setText(mContext.getString(R.string.msgs_profile_group_rename_profile_group));

    CommonDialog.setDlgBoxSizeCompact(dialog);

    dlg_et_name.setText(old_loc);
    dlg_et_name.addTextChangedListener(new TextWatcher() {
        @Override
        final public void afterTextChanged(Editable s) {
            if (s.length() != 0) {
                //                dlg_et_name.selectAll();
                String newgrp = dlg_et_name.getText().toString();
                if (!newgrp.startsWith("*")) {
                    btnOK.setEnabled(true);
                    for (int i = 0; i < mGlblParms.profileGroupAdapter.getCount(); i++) {
                        if (mGlblParms.profileGroupAdapter.getItem(i).getProfileGroupName().equals(newgrp)) {
                            btnOK.setEnabled(false);
                            break;
                        }
                    }
                } else
                    btnOK.setEnabled(false);
            } else
                btnOK.setEnabled(false);
        }

        @Override
        final public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        final public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });

    final NotifyEvent ntfy = new NotifyEvent(mContext);
    ntfy.setListener(new NotifyEventListener() {
        @Override
        final public void positiveResponse(Context c, Object[] o) {
            dlg_et_name.selectAll();
            String new_loc = dlg_et_name.getText().toString();
            renameProfileGroup(true, old_loc, new_loc);
        }

        @Override
        final public void negativeResponse(Context c, Object[] o) {
        }

    });

    // CANCEL?
    btnCancel.setOnClickListener(new View.OnClickListener() {
        final public void onClick(View v) {
            dialog.dismiss();
        }
    });
    // OK?
    btnOK.setOnClickListener(new View.OnClickListener() {
        final public void onClick(View v) {
            ntfy.notifyToListener(POSITIVE, null);
            dialog.dismiss();
        }
    });
    // Cancel?
    dialog.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface arg0) {
            btnCancel.performClick();
        }
    });
    //      dialog.setOnKeyListener(new DialogOnKeyListener(context));
    //      dialog.setCancelable(false);
    dialog.show();
}

From source file:com.sentaroh.android.TaskAutomation.Config.ProfileMaintenanceActionProfile.java

final static private void editActivityExtraDataItem(final GlobalParameters mGlblParms, final int sel_pos) {
    // ??//from  w w w  . ja v  a 2s .  c  o 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();
}

From source file:com.sentaroh.android.TaskAutomation.Config.ProfileMaintenanceTimeProfile.java

final private void addProfile() {
    mDialog.setContentView(R.layout.edit_profile_time_dlg);

    final TextView dlg_title = (TextView) mDialog.findViewById(R.id.edit_profile_time_title);
    final EditText dlg_prof_name_et = (EditText) mDialog.findViewById(R.id.edit_profile_time_profile_et_name);

    final CheckBox cb_active = (CheckBox) mDialog.findViewById(R.id.edit_profile_time_enabled);
    dlg_title.setText(mGlblParms.context.getString(R.string.msgs_edit_profile_hdr_add_time));

    //      CommonDialog.setDlgBoxSizeCompact(mDialog);

    cb_active.setChecked(true);//from   w w  w.  j  a  va2  s. c  o  m

    final Spinner spinnerDateTimeType = (Spinner) mDialog.findViewById(R.id.edit_profile_time_date_time_type);
    final AdapterDateTimeTypeSpinner adapterDateTimeType = new AdapterDateTimeTypeSpinner(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    setSpinnerDateTimeType(mGlblParms, mDialog, spinnerDateTimeType, adapterDateTimeType,
            PROFILE_DATE_TIME_TYPE_ONE_SHOT);

    final Spinner spinnerYear = (Spinner) mDialog.findViewById(R.id.edit_profile_time_exec_year);
    CustomSpinnerAdapter adapterYear = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    adapterYear.setTextColor(Color.BLACK);
    setSpinnerYear(mGlblParms, mDialog, spinnerYear, adapterYear, "****/**/**");

    final Spinner spinnerMonth = (Spinner) mDialog.findViewById(R.id.edit_profile_time_exec_month);
    CustomSpinnerAdapter adapterMonth = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    adapterMonth.setTextColor(Color.BLACK);
    setSpinnerMonth(mGlblParms, mDialog, spinnerMonth, adapterMonth, "****/**/**");

    final Spinner spinnerDay = (Spinner) mDialog.findViewById(R.id.edit_profile_time_exec_day);
    CustomSpinnerAdapter adapterDay = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    adapterDay.setTextColor(Color.BLACK);
    setSpinnerDay(mGlblParms, mDialog, spinnerDay, adapterDay, "****/**/**");

    final Spinner spinnerHour = (Spinner) mDialog.findViewById(R.id.edit_profile_time_exec_hours);
    CustomSpinnerAdapter adapterHour = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    adapterHour.setTextColor(Color.BLACK);
    setSpinnerHour(mGlblParms, mDialog, spinnerHour, adapterHour, "**:**");

    final Spinner spinnerMin = (Spinner) mDialog.findViewById(R.id.edit_profile_time_exec_minutes);
    CustomSpinnerAdapter adapterMin = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    adapterMin.setTextColor(Color.BLACK);
    setSpinnerMin(mGlblParms, mDialog, spinnerMin, adapterMin, "**:**");

    setViewVisibilityByDateTimeType(mGlblParms, mDialog, PROFILE_DATE_TIME_TYPE_ONE_SHOT);

    spinnerDateTimeType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        final public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            setViewVisibilityByDateTimeType(mGlblParms, mDialog, adapterDateTimeType.getItem(position));
        }

        @Override
        final public void onNothingSelected(AdapterView<?> arg0) {
        }
    });

    // CANCEL?
    final Button btnCancel = (Button) mDialog.findViewById(R.id.edit_profile_time_cancel_btn);
    btnCancel.setOnClickListener(new View.OnClickListener() {
        final public void onClick(View v) {
            mFragment.dismiss();
        }
    });
    // OK?
    Button btnOK = (Button) mDialog.findViewById(R.id.edit_profile_time_ok_btn);
    btnOK.setOnClickListener(new View.OnClickListener() {
        final public void onClick(View v) {
            if (!isValidDayOfTheWeek(mGlblParms, mDialog, spinnerDateTimeType.getSelectedItem().toString())) {
                mGlblParms.commonDlg.showCommonDialog(false, "E", "",
                        mGlblParms.context.getString(R.string.msgs_edit_profile_day_not_selected), null);
                return;
            }
            dlg_prof_name_et.selectAll();
            String audit_msg = ProfileMaintenance.auditProfileName(mGlblParms, mGlblParms.profileAdapter,
                    mCurrentGroup, PROFILE_TYPE_TIME, dlg_prof_name_et.getText().toString());
            if (!audit_msg.equals("")) {
                mGlblParms.commonDlg.showCommonDialog(false, "E", "", audit_msg, null);
                return;
            }
            String prof_active, prof_dw = "";
            prof_dw = getDayOfTheWeekString(mGlblParms, mDialog);
            String prof_repeat_type, prof_exec_date, prof_exec_time;
            prof_repeat_type = spinnerDateTimeType.getSelectedItem().toString();
            prof_exec_date = getExecDateByDateTimeType(mGlblParms, prof_repeat_type, spinnerYear, spinnerMonth,
                    spinnerDay);
            prof_exec_time = getExecTimeByDateTimeType(mGlblParms, prof_repeat_type, spinnerHour, spinnerMin);
            if (spinnerDateTimeType.getSelectedItem().toString().equals(PROFILE_DATE_TIME_TYPE_INTERVAL)) {
                if (prof_exec_time.equals("00:00")) {
                    mGlblParms.commonDlg.showCommonDialog(false, "E", "", mGlblParms.context
                            .getString(R.string.msgs_edit_profile_time_interval_must_be_greater_than_0), null);
                    return;
                }
            }
            mFragment.dismiss();
            if (cb_active.isChecked())
                prof_active = PROFILE_ENABLED;
            else
                prof_active = PROFILE_DISABLED;

            ProfileUtilities.removeDummyProfile(mGlblParms.profileAdapter, mCurrentGroup);

            ProfileListItem ntpli = new ProfileListItem();
            ntpli.setTimeEventEntry(PROFILE_VERSION_CURRENT, mCurrentGroup,
                    ProfileUtilities.isProfileGroupActive(mGlblParms.util, mGlblParms.profileAdapter,
                            mCurrentGroup),
                    System.currentTimeMillis(), PROFILE_TYPE_TIME, dlg_prof_name_et.getText().toString(),
                    prof_active, prof_repeat_type, prof_dw, prof_exec_date, prof_exec_time);

            mGlblParms.profileAdapter.addProfItem(ntpli);
            mGlblParms.profileAdapter.sort();
            mGlblParms.profileAdapter.updateShowList();
            mGlblParms.profileAdapter.notifyDataSetChanged();
            ProfileMaintenance.putProfileListToService(mGlblParms, mGlblParms.profileAdapter, ProfileUtilities
                    .isProfileGroupActive(mGlblParms.util, mGlblParms.profileAdapter, mCurrentGroup));
        }
    });

}

From source file:com.sentaroh.android.TaskAutomation.Config.ProfileMaintenanceTaskProfile.java

final private void addProfile() {
    mDialog.setContentView(R.layout.edit_profile_task_dlg);
    final TextView dlg_title = (TextView) mDialog.findViewById(R.id.edit_profile_task_title);
    final EditText dlg_prof_name_et = (EditText) mDialog.findViewById(R.id.edit_profile_task_profile_et_name);
    final CheckBox cb_active = (CheckBox) mDialog.findViewById(R.id.edit_profile_task_enabled);
    final CheckBox cb_notification = (CheckBox) mDialog.findViewById(R.id.edit_profile_task_error_notification);
    final Spinner spinnerTriggerCat = (Spinner) mDialog
            .findViewById(R.id.edit_profile_task_exec_trigger_category);
    CustomSpinnerAdapter adapterTriggerCat = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    adapterTriggerCat.setTextColor(Color.BLACK);
    final Spinner spinnerEvent = (Spinner) mDialog.findViewById(R.id.edit_profile_task_exec_trigger_event);
    final CustomSpinnerAdapter adapterEvent = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    adapterEvent.setTextColor(Color.BLACK);
    final Button btnCancel = (Button) mDialog.findViewById(R.id.edit_profile_task_cancel_btn);
    final Button btnOK = (Button) mDialog.findViewById(R.id.edit_profile_task_ok_btn);
    //      final Button btnEdit = (Button) mDialog.findViewById(R.id.edit_profile_task_test_edit_parms);
    final CheckBox cb_enable_env_parms = (CheckBox) mDialog
            .findViewById(R.id.edit_profile_task_enable_env_parms);
    final Button btnExecute = (Button) mDialog.findViewById(R.id.edit_profile_task_test_exec);
    final Button btnEnvEdit = (Button) mDialog.findViewById(R.id.edit_profile_task_test_edit_parms);

    dlg_title.setText(mGlblParms.context.getString(R.string.msgs_edit_profile_hdr_add_task));

    //      CommonDialog.setDlgBoxSizeLimit(mDialog,true);

    cb_active.setChecked(true);//from ww w . j a  v  a2  s . co  m
    cb_notification.setChecked(false);

    adapterTriggerCat.setTextColor(Color.BLACK);
    ProfileMaintenance.setSpinnerTriggerCat(mGlblParms, mDialog, mGlblParms.profileAdapter,
            mGlblParms.profileListView, spinnerTriggerCat, adapterTriggerCat, "");

    adapterEvent.setTextColor(Color.BLACK);
    //        setSpinnerEvent(mDialog,mGlblParms.profileAdapter,mGlblParms.profileListView,spinnerEvent,adapterEvent,"");
    spinnerTriggerCat.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        final public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            if (spinnerTriggerCat.getSelectedItem().toString().equals(TRIGGER_EVENT_CATEGORY_BUILTIN)) {
                ProfileMaintenance.setSpinnerEventBuiltin(mGlblParms, mDialog, mGlblParms.profileAdapter,
                        mGlblParms.profileListView, spinnerEvent, adapterEvent, "");
            } else if (spinnerTriggerCat.getSelectedItem().toString().equals(TRIGGER_EVENT_CATEGORY_TASK)) {
                ProfileMaintenance.setSpinnerEventTask(mGlblParms, mDialog, mGlblParms.profileAdapter,
                        mGlblParms.profileListView, spinnerEvent, adapterEvent, "");
            } else if (spinnerTriggerCat.getSelectedItem().toString().equals(TRIGGER_EVENT_CATEGORY_TIME)) {
                ProfileMaintenance.setSpinnerEventTime(mGlblParms, mDialog, mGlblParms.profileAdapter,
                        mGlblParms.profileListView, spinnerEvent, adapterEvent, "");
            }
        }

        @Override
        final public void onNothingSelected(AdapterView<?> arg0) {
        }
    });

    final ArrayList<TaskActionEditListItem> adapter_act_list = new ArrayList<TaskActionEditListItem>();
    setEditTaskActionListener(mGlblParms, mDialog, mGlblParms.profileAdapter, mGlblParms.profileListView,
            mCurrentGroup, adapter_act_list);

    if (mGlblParms.immTaskTestEnvParms == null)
        ProfileMaintenance.loadEnvparmsFromService(mGlblParms);
    btnEnvEdit.setVisibility(Button.GONE);
    cb_enable_env_parms.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton arg0, boolean isChecked) {
            if (isChecked)
                btnEnvEdit.setVisibility(Button.VISIBLE);
            else
                btnEnvEdit.setVisibility(Button.GONE);
        }
    });

    // Execute?
    btnExecute.setOnClickListener(new View.OnClickListener() {
        final public void onClick(View v) {
            dlg_prof_name_et.selectAll();
            String audit_msg = ProfileMaintenance.auditProfileName(mGlblParms, mGlblParms.profileAdapter,
                    mCurrentGroup, PROFILE_TYPE_TASK, dlg_prof_name_et.getText().toString());
            if (!audit_msg.equals("")) {
                mGlblParms.commonDlg.showCommonDialog(false, "E", "", audit_msg, null);
                return;
            }
            if (spinnerEvent.getSelectedItem().toString().equals("** Profile not available **")) {
                mGlblParms.commonDlg.showCommonDialog(false, "E", "",
                        mGlblParms.context.getString(R.string.msgs_edit_profile_event_not_specified), null);
                return;
            }
            if (adapter_act_list.size() == 0) {
                mGlblParms.commonDlg.showCommonDialog(false, "E", "",
                        mGlblParms.context.getString(R.string.msgs_edit_profile_action_not_specified), null);
                return;
            }
            ProfileMaintenance.invokeTaskExecution(mGlblParms, mCurrentGroup, mGlblParms.profileAdapter,
                    dlg_prof_name_et.getText().toString(), spinnerEvent.getSelectedItem().toString(),
                    cb_notification.isChecked(), cb_enable_env_parms.isChecked(), adapter_act_list);
        }
    });
    // EnvEdit?
    btnEnvEdit.setOnClickListener(new View.OnClickListener() {
        final public void onClick(View v) {
            ProfileMaintenance.editEnvParmsDlg(mGlblParms);
        }
    });
    // CANCEL?
    btnCancel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            //            mDialog.dismiss();
            mFragment.dismiss();
        }
    });
    // OK?
    btnOK.setOnClickListener(new View.OnClickListener() {
        final public void onClick(View v) {
            dlg_prof_name_et.selectAll();
            String audit_msg = ProfileMaintenance.auditProfileName(mGlblParms, mGlblParms.profileAdapter,
                    mCurrentGroup, PROFILE_TYPE_TASK, dlg_prof_name_et.getText().toString());
            if (!audit_msg.equals("")) {
                mGlblParms.commonDlg.showCommonDialog(false, "E", "", audit_msg, null);
                return;
            }
            if (spinnerEvent.getSelectedItem().toString().equals("** Profile not available **")) {
                mGlblParms.commonDlg.showCommonDialog(false, "E", "",
                        mGlblParms.context.getString(R.string.msgs_edit_profile_event_not_specified), null);
                return;
            }
            if (adapter_act_list.size() == 0) {
                mGlblParms.commonDlg.showCommonDialog(false, "E", "",
                        mGlblParms.context.getString(R.string.msgs_edit_profile_action_not_specified), null);
                return;
            }

            mFragment.dismiss();
            String prof_active, prof_retrospec = "", prof_notification = "";
            if (cb_active.isChecked())
                prof_active = PROFILE_ENABLED;
            else
                prof_active = PROFILE_DISABLED;

            if (cb_notification.isChecked())
                prof_notification = PROFILE_ERROR_NOTIFICATION_ENABLED;
            else
                prof_notification = PROFILE_ERROR_NOTIFICATION_ENABLED;

            ProfileUtilities.removeDummyProfile(mGlblParms.profileAdapter, mCurrentGroup);

            ProfileListItem ntpli = new ProfileListItem();
            ArrayList<String> trig = new ArrayList<String>();
            //            act.add(spinnerActionProfile.getSelectedItem().toString());
            trig.add(spinnerEvent.getSelectedItem().toString());
            ArrayList<String> string_act_list = new ArrayList<String>();
            for (int i = 0; i < adapter_act_list.size(); i++)
                string_act_list.add(adapter_act_list.get(i).action);

            ntpli.setTaskEntry(PROFILE_VERSION_CURRENT, mCurrentGroup,
                    ProfileUtilities.isProfileGroupActive(mGlblParms.util, mGlblParms.profileAdapter,
                            mCurrentGroup),
                    System.currentTimeMillis(), PROFILE_TYPE_TASK, dlg_prof_name_et.getText().toString(),
                    prof_active, prof_retrospec, "0", prof_notification, string_act_list, trig);
            mGlblParms.profileAdapter.addProfItem(ntpli);
            mGlblParms.profileAdapter.sort();
            mGlblParms.profileAdapter.updateShowList();
            mGlblParms.profileAdapter.notifyDataSetChanged();
            ProfileMaintenance.putProfileListToService(mGlblParms, mGlblParms.profileAdapter, ProfileUtilities
                    .isProfileGroupActive(mGlblParms.util, mGlblParms.profileAdapter, mCurrentGroup));
        }
    });

}

From source file:com.sentaroh.android.SMBExplorer.SMBExplorerMain.java

private void addRemoteProfile(final String prof_act, final String prof_name, final String prof_user,
        final String prof_pass, final String prof_addr, final String prof_port, final String prof_share,
        final String msg_text) {

    // ??//from w ww  .  j  a  v a2  s.  c  om
    final Dialog dialog = new Dialog(this);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setContentView(R.layout.edit_remote_profile);
    final TextView dlg_msg = (TextView) dialog.findViewById(R.id.remote_profile_dlg_msg);
    if (msg_text.length() != 0) {
        dlg_msg.setText(msg_text);
    }

    dialog.setTitle("Add remote profile");

    final EditText editname = (EditText) dialog.findViewById(R.id.remote_profile_name);
    editname.setText(prof_name);
    final EditText editaddr = (EditText) dialog.findViewById(R.id.remote_profile_addr);
    editaddr.setText(prof_addr);
    final EditText edituser = (EditText) dialog.findViewById(R.id.remote_profile_user);
    edituser.setText(prof_user);
    final EditText editpass = (EditText) dialog.findViewById(R.id.remote_profile_pass);
    editpass.setText(prof_pass);
    final EditText editshare = (EditText) dialog.findViewById(R.id.remote_profile_share);
    editshare.setText(prof_share);
    final EditText editport = (EditText) dialog.findViewById(R.id.remote_profile_port_number);
    editport.setText(prof_port);

    CommonDialog.setDlgBoxSizeCompact(dialog);

    final CheckBox tg = (CheckBox) dialog.findViewById(R.id.remote_profile_active);
    if (prof_act.equals("A"))
        tg.setChecked(true);
    else
        tg.setChecked(false);

    // address?
    Button btnAddr = (Button) dialog.findViewById(R.id.remote_profile_addrbtn);
    btnAddr.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            NotifyEvent ntfy = new NotifyEvent(mContext);
            //Listen setRemoteShare response 
            ntfy.setListener(new NotifyEventListener() {
                @Override
                public void positiveResponse(Context arg0, Object[] arg1) {
                    editaddr.setText((String) arg1[1]);
                }

                @Override
                public void negativeResponse(Context arg0, Object[] arg1) {
                    dlg_msg.setText("");
                }

            });
            scanRemoteNetworkDlg(ntfy, editport.getText().toString());
        }
    });

    final Button btnGet1 = (Button) dialog.findViewById(R.id.remote_profile_get_btn1);
    btnGet1.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            btnGet1.setEnabled(false);
            String prof_addr, prof_user, prof_pass;
            editaddr.selectAll();
            prof_addr = editaddr.getText().toString();
            edituser.selectAll();
            prof_user = edituser.getText().toString();
            editpass.selectAll();
            prof_pass = editpass.getText().toString();

            setJcifsProperties(prof_user, prof_pass);

            NotifyEvent ntfy = new NotifyEvent(mContext);
            //Listen setRemoteShare response 
            ntfy.setListener(new NotifyEventListener() {
                @Override
                public void positiveResponse(Context arg0, Object[] arg1) {
                    if (!((String) arg1[0]).equals(""))
                        editshare.setText((String) arg1[0]);
                }

                @Override
                public void negativeResponse(Context arg0, Object[] arg1) {
                    dlg_msg.setText((String) arg1[0]);
                }

            });
            setRemoteShare(prof_user, prof_pass, prof_addr, ntfy);
        }
    });

    // CANCEL?
    final Button btnCancel = (Button) dialog.findViewById(R.id.remote_profile_cancel);
    btnCancel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.dismiss();
            //            setFixedOrientation(false);
        }
    });
    // OK?
    Button btnOK = (Button) dialog.findViewById(R.id.remote_profile_ok);
    btnOK.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            String new_act, new_name;
            editaddr.selectAll();
            edituser.selectAll();
            editpass.selectAll();
            editshare.selectAll();
            editname.selectAll();
            new_name = editname.getText().toString();

            if (tg.isChecked())
                new_act = "A";
            else
                new_act = "A";

            if (isProfileDuplicated("R", new_name)) {
                dlg_msg.setText(getString(R.string.msgs_add_remote_profile_duplicate));
            } else {
                dialog.dismiss();
                //               setFixedOrientation(false);
                int pos = profileListView.getFirstVisiblePosition();
                int topPos = 0;
                if (profileListView.getChildAt(0) != null)
                    profileListView.getChildAt(0).getTop();
                String prof_user = edituser.getText().toString();
                String prof_pass = editpass.getText().toString();
                String prof_addr = editaddr.getText().toString();
                String prof_share = editshare.getText().toString();
                String prof_port = editport.getText().toString();
                profileAdapter.add(new ProfileListItem("R", new_name, new_act, prof_user, prof_pass, prof_addr,
                        prof_port, prof_share, false));
                saveProfile(false, "", "");
                profileAdapter = createProfileList(false, ""); // create profile list

                profileListView.setSelectionFromTop(pos, topPos);
                profileAdapter.setNotifyOnChange(true);

                setRemoteDirBtnListener();
            }
        }
    });
    // Cancel?
    dialog.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface arg0) {
            btnCancel.performClick();
        }
    });
    //      dialog.setOnKeyListener(new DialogOnKeyListener(currentContext));
    //      setFixedOrientation(true);
    //      dialog.setCancelable(false);
    dialog.show();
}

From source file:com.sentaroh.android.SMBExplorer.SMBExplorerMain.java

private void editRemoteProfile(String prof_act, String prof_name, String prof_user, String prof_pass,
        String prof_addr, final String prof_port, String prof_share, String msg_text, final int item_num) {

    // ??//  www. ja v  a  2  s  .c o m
    final Dialog dialog = new Dialog(this);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setContentView(R.layout.edit_remote_profile);
    final TextView dlg_msg = (TextView) dialog.findViewById(R.id.remote_profile_dlg_msg);

    if (msg_text.length() != 0) {
        dlg_msg.setText(msg_text);
    }

    dialog.setTitle("Edit remote profile");

    CommonDialog.setDlgBoxSizeLimit(dialog, false);

    final EditText editname = (EditText) dialog.findViewById(R.id.remote_profile_name);
    editname.setText(prof_name);
    final EditText editaddr = (EditText) dialog.findViewById(R.id.remote_profile_addr);
    editaddr.setText(prof_addr);
    final EditText edituser = (EditText) dialog.findViewById(R.id.remote_profile_user);
    edituser.setText(prof_user);
    final EditText editpass = (EditText) dialog.findViewById(R.id.remote_profile_pass);
    editpass.setText(prof_pass);
    final EditText editshare = (EditText) dialog.findViewById(R.id.remote_profile_share);
    editshare.setText(prof_share);
    final EditText editport = (EditText) dialog.findViewById(R.id.remote_profile_port_number);
    editport.setText(prof_port);

    final CheckBox tg = (CheckBox) dialog.findViewById(R.id.remote_profile_active);
    if (prof_act.equals("A"))
        tg.setChecked(true);
    else
        tg.setChecked(false);

    // address?
    Button btnAddr = (Button) dialog.findViewById(R.id.remote_profile_addrbtn);
    btnAddr.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            NotifyEvent ntfy = new NotifyEvent(mContext);
            //Listen setRemoteShare response 
            ntfy.setListener(new NotifyEventListener() {
                @Override
                public void positiveResponse(Context arg0, Object[] arg1) {
                    editaddr.setText((String) arg1[1]);
                }

                @Override
                public void negativeResponse(Context arg0, Object[] arg1) {
                    if (arg1 != null)
                        dlg_msg.setText((String) arg1[0]);
                    else
                        dlg_msg.setText("");
                }

            });
            scanRemoteNetworkDlg(ntfy, editport.getText().toString());
        }
    });

    Button btnGet1 = (Button) dialog.findViewById(R.id.remote_profile_get_btn1);
    btnGet1.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            String prof_addr, prof_user, prof_pass;
            editaddr.selectAll();
            prof_addr = editaddr.getText().toString();
            edituser.selectAll();
            prof_user = edituser.getText().toString();
            editpass.selectAll();
            prof_pass = editpass.getText().toString();

            setJcifsProperties(prof_user, prof_pass);

            NotifyEvent ntfy = new NotifyEvent(mContext);
            //Listen setRemoteShare response 
            ntfy.setListener(new NotifyEventListener() {
                @Override
                public void positiveResponse(Context arg0, Object[] arg1) {
                    if (!((String) arg1[0]).equals(""))
                        editshare.setText((String) arg1[0]);
                }

                @Override
                public void negativeResponse(Context arg0, Object[] arg1) {
                    dlg_msg.setText((String) arg1[0]);
                }

            });
            setRemoteShare(prof_user, prof_pass, prof_addr, ntfy);
        }
    });

    // CANCEL?
    final Button btnCancel = (Button) dialog.findViewById(R.id.remote_profile_cancel);
    btnCancel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.dismiss();
            //            setFixedOrientation(false);
        }
    });
    // OK?
    Button btnOK = (Button) dialog.findViewById(R.id.remote_profile_ok);
    btnOK.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            String new_user, new_pass, new_addr, new_share, new_act, new_name;

            dialog.dismiss();
            //            setFixedOrientation(false);

            new_addr = editaddr.getText().toString();
            new_user = edituser.getText().toString();
            new_pass = editpass.getText().toString();
            new_share = editshare.getText().toString();
            new_name = editname.getText().toString();
            String new_port = editport.getText().toString();

            if (tg.isChecked())
                new_act = "A";
            else
                new_act = "I";

            int pos = profileListView.getFirstVisiblePosition();
            int topPos = 0;
            if (profileListView.getChildAt(0) != null)
                profileListView.getChildAt(0).getTop();
            ProfileListItem item = profileAdapter.getItem(item_num);

            profileAdapter.remove(item);
            profileAdapter.insert(new ProfileListItem("R", new_name, new_act, new_user, new_pass, new_addr,
                    new_port, new_share, false), item_num);

            saveProfile(false, "", "");
            //            appendProfile();
            //            profileAdapter = 
            //                  createProfileList(false); // create profile list
            profileListView.setSelectionFromTop(pos, topPos);
            profileAdapter.setNotifyOnChange(true);
        }
    });
    // Cancel?
    dialog.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface arg0) {
            btnCancel.performClick();
        }
    });
    //      dialog.setOnKeyListener(new DialogOnKeyListener(currentContext));
    //      setFixedOrientation(true);
    //      dialog.setCancelable(false);
    dialog.show();

}

From source file:com.sentaroh.android.TaskAutomation.Config.ProfileMaintenanceActionProfile.java

final private void addProfile() {
    mDialog.setContentView(R.layout.edit_profile_action_dlg);

    final TextView dlg_title = (TextView) mDialog.findViewById(R.id.edit_profile_action_title);
    dlg_title.setText(mGlblParms.context.getString(R.string.msgs_main_ccmenu_add_action));
    final EditText dlg_prof_name_et = (EditText) mDialog.findViewById(R.id.edit_profile_action_profile_et_name);

    final ArrayList<DataArrayEditListItem> comp_data_list = new ArrayList<DataArrayEditListItem>();
    final ArrayList<ActivityExtraDataItem> aed_edit_list = new ArrayList<ActivityExtraDataItem>();

    //      final CheckBox cb_active=(CheckBox)mDialog.findViewById(R.id.edit_profile_action_enabled);
    final TextView tv_sound_filename = (TextView) mDialog
            .findViewById(R.id.edit_profile_action_exec_sound_file_name);
    final CheckBox cb_music_vol = (CheckBox) mDialog
            .findViewById(R.id.edit_profile_action_profile_sound_use_volume);
    final SeekBar sb_music_vol = (SeekBar) mDialog.findViewById(R.id.edit_profile_action_profile_sound_volume);
    final Button playBtnMusic = (Button) mDialog.findViewById(R.id.edit_profile_action_profile_sound_play_back);
    final Button playBtnRingtone = (Button) mDialog
            .findViewById(R.id.edit_profile_action_profile_ringtone_play_back);
    final CheckBox cb_ringtone_vol = (CheckBox) mDialog
            .findViewById(R.id.edit_profile_action_profile_ringtone_use_volume);
    final SeekBar sb_ringtone_vol = (SeekBar) mDialog
            .findViewById(R.id.edit_profile_action_profile_ringtone_volume);
    final Spinner spinnerActionType = (Spinner) mDialog.findViewById(R.id.edit_profile_action_action_type);
    final Spinner spinnerActivityName = (Spinner) mDialog
            .findViewById(R.id.edit_profile_action_exec_activity_name);
    final Spinner spinnerActivityDataType = (Spinner) mDialog
            .findViewById(R.id.edit_profile_action_exec_activity_data_type);
    final Spinner spinnerRingtoneType = (Spinner) mDialog
            .findViewById(R.id.edit_profile_action_exec_ringtone_type);
    final Spinner spinnerRingtoneName = (Spinner) mDialog
            .findViewById(R.id.edit_profile_action_exec_ringtone_name);
    final Spinner spinnerCompareType = (Spinner) mDialog.findViewById(R.id.edit_profile_action_compare_type);
    //        final EditText et_comp_value1=(EditText)mDialog.findViewById(R.id.edit_profile_action_compare_value1);
    //        final EditText et_comp_value2=(EditText)mDialog.findViewById(R.id.edit_profile_action_compare_value2);
    //        final ListView lv_comp_data=(ListView)mDialog.findViewById(R.id.edit_profile_action_compare_value_listview);
    //        final Spinner spinnerCompareResult = (Spinner) mDialog.findViewById(R.id.edit_profile_action_compare_result);
    final Spinner spinnerCompareTarget = (Spinner) mDialog
            .findViewById(R.id.edit_profile_action_compare_target);
    final Spinner spinnerMessageType = (Spinner) mDialog.findViewById(R.id.edit_profile_action_message_type);
    //        final EditText et_msg_text=(EditText)mDialog.findViewById(R.id.edit_profile_action_message_message);
    //        final CheckBox cb_vib_used=(CheckBox)mDialog.findViewById(R.id.edit_profile_action_message_vibration);
    //        final CheckBox cb_led_used=(CheckBox)mDialog.findViewById(R.id.edit_profile_action_message_led);
    //        final RadioButton rb_msg_blue=(RadioButton)mDialog.findViewById(R.id.edit_profile_action_message_led_blue);
    //        final RadioButton rb_msg_red=(RadioButton)mDialog.findViewById(R.id.edit_profile_action_message_led_red);
    //        final RadioButton rb_msg_green=(RadioButton)mDialog.findViewById(R.id.edit_profile_action_message_led_green);
    final Spinner spinnerTimeType = (Spinner) mDialog.findViewById(R.id.edit_profile_action_time_type);
    final Spinner spinnerTimeTarget = (Spinner) mDialog.findViewById(R.id.edit_profile_action_time_target);
    final Spinner spinnerTaskType = (Spinner) mDialog.findViewById(R.id.edit_profile_action_task_type);
    final Spinner spinnerTaskTarget = (Spinner) mDialog.findViewById(R.id.edit_profile_action_task_target);
    //        final Spinner spinnerWaitTarget = (Spinner) mDialog.findViewById(R.id.edit_profile_action_wait_target);
    //        final Spinner spinnerWaitTimeoutType = (Spinner) mDialog.findViewById(R.id.edit_profile_action_wait_timeout);
    //        final Spinner spinnerWaitTimeoutValue = (Spinner) mDialog.findViewById(R.id.edit_profile_action_wait_timeout_value);
    //        final Spinner spinnerWaitTimeoutUnits = (Spinner) mDialog.findViewById(R.id.edit_profile_action_wait_timeout_units);

    final CustomSpinnerAdapter adapterActionType = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    final CustomSpinnerAdapter adapterActivityName = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    final CustomSpinnerAdapter adapterActivityDataType = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    final CustomSpinnerAdapter adapterRingtoneType = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    final CustomSpinnerAdapter adapterRingtoneName = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    final CustomSpinnerAdapter adapterCompareType = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    mGlblParms.actionCompareDataAdapter = new AdapterDataArrayEditList(mGlblParms.context,
            R.layout.data_array_edit_list_item, comp_data_list);
    final CustomSpinnerAdapter adapterCompareResult = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    final CustomSpinnerAdapter adapterCompareTarget = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    final CustomSpinnerAdapter adapterMessageType = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    final CustomSpinnerAdapter adapterTimeType = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    final CustomSpinnerAdapter adapterTimeTarget = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    final CustomSpinnerAdapter adapterTaskType = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    final CustomSpinnerAdapter adapterTaskTarget = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    final CustomSpinnerAdapter adapterWaitTarget = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    final CustomSpinnerAdapter adapterWaitTimeoutType = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    final CustomSpinnerAdapter adapterWaitTimeoutValue = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    final CustomSpinnerAdapter adapterWaitTimeoutUnits = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);

    initProfileActionWidget(mGlblParms, mDialog, null, comp_data_list, aed_edit_list, mCurrentGroup,
            mGlblParms.profileAdapter, adapterActionType, adapterActivityName, adapterActivityDataType,
            adapterRingtoneType, adapterRingtoneName, adapterCompareType, adapterCompareResult,
            adapterCompareTarget, adapterMessageType, adapterTimeType, adapterTimeTarget, adapterTaskType,
            adapterTaskTarget, adapterWaitTarget, adapterWaitTimeoutType, adapterWaitTimeoutValue,
            adapterWaitTimeoutUnits);/*from  ww w . j  a v  a2s. c o m*/

    if (mGlblParms.immTaskTestEnvParms == null)
        ProfileMaintenance.loadEnvparmsFromService(mGlblParms);

    setProfileActionActivityListener(mGlblParms, mDialog, mGlblParms.profileAdapter, mCurrentGroup,
            aed_edit_list);
    ProfileMaintenance.setProfileActionTestExecListener(mGlblParms, mDialog, mGlblParms.profileAdapter,
            mCurrentGroup, aed_edit_list);
    setProfileActionCompareListener(mGlblParms, mDialog, mGlblParms.profileAdapter, mCurrentGroup,
            adapterCompareType, "");
    setProfileActionMessageListener(mGlblParms, mDialog, mGlblParms.profileAdapter, mCurrentGroup);
    setProfileActionTimeListener(mGlblParms, mDialog, mGlblParms.profileAdapter, mCurrentGroup);
    setProfileActionTaskListener(mGlblParms, mDialog, mGlblParms.profileAdapter, mCurrentGroup, adapterTaskType,
            adapterTaskTarget, "");
    setProfileActionWaitListener(mGlblParms, mDialog);
    setProfileActionBshListener(mGlblParms, mDialog, mGlblParms.profileAdapter, mCurrentGroup, null);

    setViewVisibilityByActionType(mGlblParms, mDialog, PROFILE_ACTION_TYPE_ACTIVITY,
            PROFILE_ACTION_TYPE_ACTIVITY_DATA_TYPE_NONE);
    setActionTypeSelectionListner(mGlblParms, mDialog, spinnerActionType, adapterActionType,
            spinnerActivityDataType, adapterActivityDataType);
    ProfileMaintenance.setActionRingtoneTypeSelectionListener(mGlblParms, mDialog, spinnerRingtoneType,
            spinnerRingtoneName, adapterRingtoneName);

    // Music Listing?
    Button btnListSound = (Button) mDialog.findViewById(R.id.edit_profile_action_list_sound);
    ProfileMaintenance.setActionListSoundBtnListener(mGlblParms, mDialog, tv_sound_filename, cb_music_vol,
            sb_music_vol, btnListSound, playBtnMusic);
    ProfileMaintenance.setMusicPlayBackBtnListener(mGlblParms, mDialog, tv_sound_filename, cb_music_vol,
            sb_music_vol, playBtnMusic);
    // Ringtone ?
    ProfileMaintenance.setRingtonePlayBackBtnListener(mGlblParms, mDialog, spinnerRingtoneType,
            spinnerRingtoneName, cb_ringtone_vol, sb_ringtone_vol, playBtnRingtone);

    // CANCEL?
    final Button btnCancel = (Button) mDialog.findViewById(R.id.edit_profile_action_cancel_btn);
    btnCancel.setOnClickListener(new View.OnClickListener() {
        final public void onClick(View v) {
            ProfileMaintenance.stopMusicPlayBack(mGlblParms);
            ProfileMaintenance.stopRingtonePlayBack(mGlblParms);
            mFragment.dismiss();
        }
    });
    // OK?
    Button btnOK = (Button) mDialog.findViewById(R.id.edit_profile_action_ok_btn);
    btnOK.setOnClickListener(new View.OnClickListener() {
        final public void onClick(View v) {
            dlg_prof_name_et.selectAll();
            String audit_msg = ProfileMaintenance.auditProfileName(mGlblParms, mGlblParms.profileAdapter,
                    mCurrentGroup, PROFILE_TYPE_ACTION, dlg_prof_name_et.getText().toString());
            if (!audit_msg.equals("")) {
                mGlblParms.commonDlg.showCommonDialog(false, "E", "", audit_msg, null);
                return;
            }
            audit_msg = ProfileMaintenance.auditActionProfile(mGlblParms, mDialog, mCurrentGroup,
                    mGlblParms.profileAdapter, spinnerActionType, spinnerActivityName, spinnerActivityDataType,
                    spinnerCompareTarget, spinnerCompareType, spinnerMessageType, spinnerTimeType,
                    spinnerTimeTarget, spinnerTaskType, spinnerTaskTarget, aed_edit_list);
            if (!audit_msg.equals("")) {
                mGlblParms.commonDlg.showCommonDialog(false, "E", "", audit_msg, null);
                return;
            }
            ProfileMaintenance.stopMusicPlayBack(mGlblParms);
            ProfileMaintenance.stopRingtonePlayBack(mGlblParms);
            ProfileListItem ntpli = setProfileActionOkButtonProcess(mGlblParms, mDialog,
                    mGlblParms.profileAdapter, mCurrentGroup);
            ntpli.setActionActivityExtraData(aed_edit_list);
            ntpli.setProfileGroupShowed(true);
            mFragment.dismiss();

            ProfileUtilities.removeDummyProfile(mGlblParms.profileAdapter, mCurrentGroup);

            mGlblParms.profileAdapter.addProfItem(ntpli);
            mGlblParms.profileAdapter.sort();
            mGlblParms.profileAdapter.updateShowList();
            mGlblParms.profileAdapter.notifyDataSetChanged();
            ProfileMaintenance.putProfileListToService(mGlblParms, mGlblParms.profileAdapter, ProfileUtilities
                    .isProfileGroupActive(mGlblParms.util, mGlblParms.profileAdapter, mCurrentGroup));
        }
    });

}