コード例 #1
0
ファイル: LabelsActivity.java プロジェクト: Cyrus964/MyDomo
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitle(getResources().getText(R.string.title_labels));

    setContentView(R.layout.list_labels);

    ListView listLabels = (ListView) findViewById(R.id.listLabels);
    listLabels.setTextFilterEnabled(true);

    registerForContextMenu(listLabels);

    popUp = new PopupWindow(this);
    layout = new LinearLayout(this);
    lblLabelName = new TextView(this);
    txtLabelName = new EditText(this);
    txtLabelName.setText("");
    txtLabelName.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL);
    txtLabelName.setWidth(300);
    btnOk = new Button(this);
    btnOk.setText("OK");
    btnCancel = new Button(this);
    btnCancel.setText("Cancel");
    LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    layout.setOrientation(LinearLayout.VERTICAL);
    lblLabelName.setText("Label Name");
    layout.addView(lblLabelName, params);
    layout.addView(txtLabelName, params);

    LinearLayout btnLayout = new LinearLayout(this);
    btnLayout.setOrientation(LinearLayout.HORIZONTAL);
    btnLayout.addView(btnOk, params);
    btnLayout.addView(btnCancel, params);

    layout.addView(btnLayout);
    popUp.setContentView(layout);

    btnCancel.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            popUp.dismiss();
            refreshList();
            listClickable = true;
            labelCreation = false;
          }
        });

    btnOk.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO control value!
            labelToEdit.setTitle(txtLabelName.getText().toString());
            if (labelCreation) {
              getHouse().getLabels().add(labelToEdit);
              labelCreation = false;
            }
            popUp.dismiss();
            refreshList();
            try {
              myDomoService.save(getHouse());
            } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
            listClickable = true;
          }
        });

    alertDialog =
        new AlertDialog.Builder(this)
            .setTitle("Select action")
            .setAdapter(
                createControllersWithNoLabelAdapter(),
                new DialogInterface.OnClickListener() {

                  @Override
                  public void onClick(DialogInterface dialog, int position) {
                    switch (position) {
                      case RENAME:
                        showAddLabelPopup(
                            500,
                            getHouse()
                                .getLabels()
                                .get(itemPositionForAlertAction)); // TODO set proper with property
                        break;
                      case DELETE:
                        getHouse()
                            .getLabels()
                            .get(itemPositionForAlertAction)
                            .clear(); // TODO add a method when remove a label => detach all
                        // controllers
                        getHouse().getLabels().remove(itemPositionForAlertAction);
                        saveHouse(getHouse());
                        break;
                        //						case CAMERA:
                        //							try {
                        //								// Select Label
                        //								Intent intent = new Intent(LabelsActivity.this,
                        //										StreamActivity.class);
                        //								startActivity(intent);
                        //							} catch (Exception e) {
                        //								Log.e("Error when launch streaming", null, e);
                        //							}
                        //							break;
                      default:
                        break;
                    }
                    refreshList();
                  }
                });

    listLabels.setOnItemLongClickListener(
        new OnItemLongClickListener() {

          @Override
          public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            if (position == parent.getChildCount() - 1) {
              // Add new Label
              showAddLabelPopup(parent.getWidth(), null);

              return false;
            } else {
              Label labelEnum = (Label) parent.getItemAtPosition(position);
              Log.i("Item Long selected", labelEnum.toString());
              try {
                itemPositionForAlertAction = position;
                alertDialog.show();
                return true;
                // Open the label and display controllers
              } catch (Exception e) {
                Log.e("Error when selecting Label", null, e);
                return false;
              }
            }
          }
        });

    listLabels.setOnItemClickListener(
        new OnItemClickListener() {
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            if (position == parent.getChildCount() - 1) {
              // Add new Label
              showAddLabelPopup(parent.getWidth(), null);
            } else {
              Label labelEnum = (Label) parent.getItemAtPosition(position);
              Log.i("Item selected", labelEnum.toString());
              try {
                // Select Label
                Intent intent = new Intent(LabelsActivity.this, EditLabelActivity.class);
                intent.putExtra("selectedLabelId", labelEnum.getId());
                intent.putExtra("selectedLabelTitle", labelEnum.getTitle());
                startActivity(intent);
                // Open the label and display controllers
              } catch (Exception e) {
                Log.e("Error when selecting Label", null, e);
              }
            }
          }
        });
  }
コード例 #2
0
ファイル: LabelsActivity.java プロジェクト: Cyrus964/MyDomo
 @Override
 protected void onResume() {
   super.onResume();
   bindService();
   refreshList();
 }