protected void dialogSave(final LedMatrixModel mtx) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage(getResources().getString(R.string.save_confirm));
    // builder.

    editNameInDialog = new EditText(this);
    editNameInDialog.setSingleLine(true);
    editNameInDialog.setFocusable(true);
    editNameInDialog.setSelectAllOnFocus(true);
    editNameInDialog.setText(mtx.getName());

    builder.setView(editNameInDialog);

    builder.setPositiveButton(
        getString(R.string.ok).toUpperCase(),
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            updateMatrixInfo(mtx);
            mtx.setName(editNameInDialog.getText().toString());

            if (mtx.getId() > 0) {
              mtxDAO.update(mtx);
              Log.v(TAG, "Updated: " + " " + currMatrix.toString());
            } else {
              long ret = mtxDAO.save(currMatrix);
              mtx.setId((int) ret);
              Log.v(TAG, "Saved: " + ret + " " + currMatrix.toString());
            }

            getActionBar().setTitle(getString(R.string.title_image) + ":" + currMatrix.getName());
          }
        });

    builder.setNegativeButton(
        getString(R.string.cancel).toUpperCase(),
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
          }
        });
    builder.create().show();
  }
Exemplo n.º 2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.category);

    types = getResources().getStringArray(R.array.attribute_types);

    scrollView = (ScrollView) findViewById(R.id.scroll);

    categoryTitle = new EditText(this);
    categoryTitle.setSingleLine();

    Intent intent = getIntent();
    if (intent != null) {
      long id = intent.getLongExtra(CATEGORY_ID_EXTRA, -1);
      if (id != -1) {
        category = db.getCategory(id);
      }
    }

    attributeCursor = db.getAllAttributes();
    startManagingCursor(attributeCursor);
    attributeAdapter =
        new SimpleCursorAdapter(
            this,
            android.R.layout.simple_spinner_dropdown_item,
            attributeCursor,
            new String[] {AttributeColumns.NAME},
            new int[] {android.R.id.text1});

    if (category.id == -1) {
      categoryCursor = db.getCategories(true);
    } else {
      categoryCursor = db.getCategoriesWithoutSubtree(category.id);
    }
    startManagingCursor(categoryCursor);

    LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
    parentCategoryText =
        x.addListNode(layout, R.id.category, R.string.parent, R.string.select_category);

    LinearLayout titleLayout = new LinearLayout(this);
    LayoutInflater layoutInflater = LayoutInflater.from(this);
    layoutInflater.inflate(R.layout.category_title, titleLayout, true);
    incomeExpenseButton = (ToggleButton) titleLayout.findViewById(R.id.toggle);
    categoryTitle = (EditText) titleLayout.findViewById(R.id.primary);
    x.addEditNode(layout, R.string.title, titleLayout);

    attributesLayout =
        (LinearLayout)
            x.addTitleNodeNoDivider(layout, R.string.attributes).findViewById(R.id.layout);
    x.addInfoNodePlus(
        attributesLayout, R.id.new_attribute, R.id.add_attribute, R.string.add_attribute);
    addAttributes();
    parentAttributesLayout =
        (LinearLayout)
            x.addTitleNodeNoDivider(layout, R.string.parent_attributes).findViewById(R.id.layout);
    addParentAttributes();

    categoryAdapter =
        new CategoryListAdapter(
            db, this, android.R.layout.simple_spinner_dropdown_item, categoryCursor);

    Button bOk = (Button) findViewById(R.id.bOK);
    bOk.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View view) {
            if (checkEditText(categoryTitle, "title", true, 100)) {
              category.title = text(categoryTitle);
              setCategoryType(category);
              int count = attributesLayout.getChildCount();
              ArrayList<Attribute> attributes = new ArrayList<Attribute>(count);
              for (int i = 0; i < count; i++) {
                View v = attributesLayout.getChildAt(i);
                Object o = v.getTag();
                if (o instanceof Attribute) {
                  attributes.add((Attribute) o);
                }
              }
              long id = db.insertOrUpdate(category, attributes);
              Intent data = new Intent();
              data.putExtra(DatabaseHelper.CategoryColumns._id.name(), id);
              setResult(RESULT_OK, data);
              finish();
            }
          }
        });

    Button bCancel = (Button) findViewById(R.id.bCancel);
    bCancel.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View view) {
            setResult(RESULT_CANCELED, null);
            finish();
          }
        });

    editCategory();
  }