public void showShareCommentDialog(Context context, final DialogFlowController controller) {

    final EditText text = new EditText(context);
    text.setMinLines(5);
    text.setGravity(Gravity.TOP);

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle("Share");
    builder.setMessage("Enter a comment (Optional)");
    builder.setPositiveButton(
        "OK",
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            controller.onContinue(text.getText().toString());
          }
        });
    builder.setNegativeButton(
        "Cancel",
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            controller.onCancel();
          }
        });

    AlertDialog dialog = builder.create();
    dialog.setView(text);
    dialog.show();
  }
Example #2
0
  /**
   * Shows the 'Reply to ...' editor.
   *
   * @param post
   */
  private void showPostEditor(final Post post) {
    final EditText view = new EditText(this);
    view.setSingleLine(false);
    view.setLines(4);
    view.setMinLines(4);
    view.setMaxLines(4);

    new AlertDialog.Builder(this)
        .setTitle(post == null ? "New Post" : "Reply to @" + post.getAuthor())
        .setView(view)
        .setMessage(post == null ? null : post.getText())
        .setPositiveButton(
            "Post",
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();

                final String id = (post != null) ? post.getId() : null;
                new AddPostTask(id, myStreamPostsAdapter, accessToken)
                    .execute(view.getText().toString());
              }
            })
        .setNegativeButton(
            "Cancel",
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
              }
            })
        .show();
  }
Example #3
0
  private void initCommentBox() {
    alert = new AlertDialog.Builder(this);

    // Set an EditText view to get user input
    input = new EditText(this);
    input.setHint("Enter your comment...");
    input.setMinLines(3);
    input.setMinWidth(200);

    alert.setView(input);

    alert.setPositiveButton(
        "Post",
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton) {
            String value = input.getText().toString();

            if (value.length() > 0) {
              CommentUploader up =
                  new CommentUploader(
                      getApplicationContext(),
                      gaze.id,
                      value,
                      Installation.id(getApplicationContext()));
              up.execute();
            }
            return;
          }
        });

    alert.setNegativeButton(
        "Cancel",
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton) {
            return;
          }
        });

    alert.show();
    input.requestFocus();

    input.postDelayed(
        new Runnable() {

          public void run() {
            InputMethodManager keyboard =
                (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

            keyboard.showSoftInput(input, 0);
          }
        },
        100);
  }
  @Override
  public void setValues(
      DataKind kind, ValuesDelta entry, EntityDelta state, boolean readOnly, ViewIdGenerator vig) {
    super.setValues(kind, entry, state, readOnly, vig);
    // Remove edit texts that we currently have
    if (mFieldEditTexts != null) {
      for (EditText fieldEditText : mFieldEditTexts) {
        mFields.removeView(fieldEditText);
      }
      mFieldEditTexts = null;
    }
    if (localGroupsSelectors != null) {
      for (View view : localGroupsSelectors) {
        mFields.removeView(view);
      }
      localGroupsSelectors = null;
    }
    boolean hidePossible = false;

    int fieldCount = kind.fieldList.size();
    if (LocalGroup.CONTENT_ITEM_TYPE.equals(kind.mimeType))
      localGroupsSelectors = new LocalGroupsSelector[fieldCount];
    else mFieldEditTexts = new EditText[fieldCount];
    for (int index = 0; index < fieldCount; index++) {
      final EditField field = kind.fieldList.get(index);
      if (LocalGroup.CONTENT_ITEM_TYPE.equals(kind.mimeType)) {
        final LocalGroupsSelector localGroupsSelector =
            new LocalGroupsSelector(mContext, entry, field.column);
        localGroupsSelector.setOnGroupSelectListener(
            new OnGroupSelectListener() {
              @Override
              public void onGroupChanged() {
                setDeleteButtonVisible(localGroupsSelector.getGroupId() > -1);
              }
            });
        // Show the delete button if we have a non-null value
        setDeleteButtonVisible(localGroupsSelector.getGroupId() > -1);
        localGroupsSelectors[index] = localGroupsSelector;
        mFields.addView(localGroupsSelector);
      } else {
        final EditText fieldView = new EditText(mContext);
        /*Begin: Modified by bxinchun for change the layout 2012/07/24*/
        /*Begin: Modified by xiepengfei for change the layout 2012/05/02*/
        LinearLayout.LayoutParams params =
            new LinearLayout.LayoutParams(
                LayoutParams.MATCH_PARENT,
                field.isMultiLine() ? LayoutParams.WRAP_CONTENT : mMinFieldHeight);
        params.bottomMargin = 10;
        fieldView.setLayoutParams(params);
        /*End: Modified by xiepengfei for change the layout 2012/05/02*/
        /*End: Modified by bxinchun for change the layout 2012/07/24*/

        // Set either a minimum line requirement or a minimum height (because {@link TextView}
        // only takes one or the other at a single time).
        if (field.minLines != 0) {
          fieldView.setMinLines(field.minLines);
        } else {
          fieldView.setMinHeight(mMinFieldHeight);
        }
        fieldView.setTextAppearance(getContext(), android.R.style.TextAppearance_Medium);
        fieldView.setGravity(Gravity.TOP);
        /*Begin: Modified by xiepengfei for change the layout 2012/05/02*/
        fieldView.setBackgroundResource(R.drawable.edit_editor_background);
        fieldView.setTextSize(20);
        fieldView.setTextColor(Color.BLACK);
        /*End: Modified by xiepengfei for change the layout 2012/05/02*/
        mFieldEditTexts[index] = fieldView;
        fieldView.setId(vig.getId(state, kind, entry, index));
        if (field.titleRes > 0) {
          fieldView.setHint(field.titleRes);
        }
        int inputType = field.inputType;
        fieldView.setInputType(inputType);
        if (inputType == InputType.TYPE_CLASS_PHONE) {
          PhoneNumberFormatter.setPhoneNumberFormattingTextWatcher(mContext, fieldView);
        }

        // Show the "next" button in IME to navigate between text fields
        // TODO: Still need to properly navigate to/from sections without text fields,
        // See Bug: 5713510
        fieldView.setImeOptions(EditorInfo.IME_ACTION_NEXT);

        // Read current value from state
        final String column = field.column;
        final String value = entry.getAsString(column);
        fieldView.setText(value);

        // Show the delete button if we have a non-null value
        setDeleteButtonVisible(value != null);

        // Prepare listener for writing changes
        fieldView.addTextChangedListener(
            new TextWatcher() {
              @Override
              public void afterTextChanged(Editable s) {
                // Trigger event for newly changed value
                onFieldChanged(column, s.toString());
              }

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

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

        fieldView.setEnabled(isEnabled() && !readOnly);

        if (field.shortForm) {
          hidePossible = true;
          mHasShortAndLongForms = true;
          fieldView.setVisibility(mHideOptional ? View.VISIBLE : View.GONE);
        } else if (field.longForm) {
          hidePossible = true;
          mHasShortAndLongForms = true;
          fieldView.setVisibility(mHideOptional ? View.GONE : View.VISIBLE);
        } else {
          // Hide field when empty and optional value
          final boolean couldHide = (!ContactsUtils.isGraphic(value) && field.optional);
          final boolean willHide = (mHideOptional && couldHide);
          fieldView.setVisibility(willHide ? View.GONE : View.VISIBLE);
          hidePossible = hidePossible || couldHide;
        }

        mFields.addView(fieldView);
      }
    }

    // When hiding fields, place expandable
    setupExpansionView(hidePossible, mHideOptional);
    mExpansionView.setEnabled(!readOnly && isEnabled());
  }
  @Override
  public void setValues(
      DataKind kind,
      ValuesDelta entry,
      RawContactDelta state,
      boolean readOnly,
      ViewIdGenerator vig) {
    super.setValues(kind, entry, state, readOnly, vig);
    // Remove edit texts that we currently have
    if (mFieldEditTexts != null) {
      for (EditText fieldEditText : mFieldEditTexts) {
        mFields.removeView(fieldEditText);
      }
    }
    boolean hidePossible = false;

    int fieldCount = kind.fieldList.size();
    mFieldEditTexts = new EditText[fieldCount];
    for (int index = 0; index < fieldCount; index++) {
      final EditField field = kind.fieldList.get(index);
      final EditText fieldView = new EditText(mContext);
      fieldView.setLayoutParams(
          new LinearLayout.LayoutParams(
              LayoutParams.MATCH_PARENT,
              field.isMultiLine() ? LayoutParams.WRAP_CONTENT : mMinFieldHeight));
      // Set either a minimum line requirement or a minimum height (because {@link TextView}
      // only takes one or the other at a single time).
      if (field.minLines != 0) {
        fieldView.setMinLines(field.minLines);
      } else {
        fieldView.setMinHeight(mMinFieldHeight);
      }
      fieldView.setTextAppearance(getContext(), android.R.style.TextAppearance_Medium);
      fieldView.setGravity(Gravity.TOP);
      mFieldEditTexts[index] = fieldView;
      fieldView.setId(vig.getId(state, kind, entry, index));

      if (field.titleRes > 0) {
        fieldView.setHint(field.titleRes);
      }
      /** M:AAS @ { update fieldView's hint text */
      if (Phone.CONTENT_ITEM_TYPE.equals(kind.mimeType)) {
        int type = SimUtils.isAdditionalNumber(entry) ? 1 : 0;
        ExtensionManager.getInstance()
            .getContactDetailExtension()
            .updateView(
                fieldView,
                type,
                ContactDetailExtension.VIEW_UPDATE_HINT,
                ExtensionManager.COMMD_FOR_AAS);
      }
      /** M: @ } */

      /** M: New Feature xxx @{ */
      /* original code int inputType = field.inputType; */
      final int inputType = field.inputType;
      /** @} */
      fieldView.setInputType(inputType);
      if (inputType == InputType.TYPE_CLASS_PHONE) {
        /** M: New Feature xxx @{ */
        /*
         * original code
         * PhoneNumberFormatter.setPhoneNumberFormattingTextWatcher
         * (mContext, fieldView);
         */
        // add by mediatek
        ExtensionManager.getInstance()
            .getContactDetailExtension()
            .setViewKeyListener(fieldView, ContactPluginDefault.COMMD_FOR_OP01);
        PhoneNumberFormatter.setPhoneNumberFormattingTextWatcher(mContext, fieldView, null);
        /** @} */
      }

      // Show the "next" button in IME to navigate between text fields
      // TODO: Still need to properly navigate to/from sections without text fields,
      // See Bug: 5713510
      fieldView.setImeOptions(EditorInfo.IME_ACTION_NEXT);

      // Read current value from state
      final String column = field.column;
      final String value = entry.getAsString(column);

      /*
       * Bug Fix by Mediatek Begin.
       *   Original Android's code:
       *     xxx
       *   CR ID: ALPS00244669
       *   Descriptions:
       */
      Log.i(TAG, "setValues setFilter");
      fieldView.setFilters(new InputFilter[] {new InputFilter.LengthFilter(FIELD_VIEW_MAX)});
      /*
       * Bug Fix by Mediatek End.
       */

      fieldView.setText(value);

      // Show the delete button if we have a non-null value
      setDeleteButtonVisible(value != null);

      // Prepare listener for writing changes
      fieldView.addTextChangedListener(
          new TextWatcher() {
            /** M: New Feature xxx @{ */
            int location = 0;

            /** @} */
            @Override
            public void afterTextChanged(Editable s) {
              // Trigger event for newly changed value
              /** M: New Feature Easy Porting @{ */
              /* original code onFieldChanged(column, s.toString()); */
              String phoneText = s.toString();
              phoneText =
                  ExtensionManager.getInstance()
                      .getContactDetailExtension()
                      .TextChanged(
                          inputType, s, phoneText, location, ContactPluginDefault.COMMD_FOR_OP01);
              onFieldChanged(column, phoneText);
              /** @} */
            }

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

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

      fieldView.setEnabled(isEnabled() && !readOnly);

      if (field.shortForm) {
        hidePossible = true;
        mHasShortAndLongForms = true;
        fieldView.setVisibility(mHideOptional ? View.VISIBLE : View.GONE);
      } else if (field.longForm) {
        hidePossible = true;
        mHasShortAndLongForms = true;
        fieldView.setVisibility(mHideOptional ? View.GONE : View.VISIBLE);
      } else {
        // Hide field when empty and optional value
        final boolean couldHide = (!ContactsUtils.isGraphic(value) && field.optional);
        final boolean willHide = (mHideOptional && couldHide);
        fieldView.setVisibility(willHide ? View.GONE : View.VISIBLE);
        hidePossible = hidePossible || couldHide;
      }

      mFields.addView(fieldView);
    }

    // When hiding fields, place expandable
    setupExpansionView(hidePossible, mHideOptional);
    mExpansionView.setEnabled(!readOnly && isEnabled());
  }
Example #6
0
  private void createNewContactObject(String type, View my_contact_view) {
    if (my_contact_view == null) {
      my_contact_view = fragment_mycontact.getView();
    }

    if (my_contact_view == null) return;

    LinearLayout ll_data;
    List<String> list = new ArrayList<String>();
    int it = android.text.InputType.TYPE_CLASS_TEXT;
    int hint = 0;

    // Typen setzen:
    List<Integer> list_number = new ArrayList<Integer>();

    for (int i = 0; i < array_en_type.length; i++) {
      if (array_en_type[i].equals(type)) {
        list_number.add(i);
      }
    }

    for (int i = 0; i < list_number.size(); i++) {
      list.add((array_en_name[list_number.get(i)]));
    }

    final String[] spinnerArray = list.toArray(new String[list.size()]);

    // -----------

    LinearLayout ll_telephone =
        (LinearLayout) my_contact_view.findViewById(R.id.mycontact_ll_data_telephone);
    LinearLayout ll_email =
        (LinearLayout) my_contact_view.findViewById(R.id.mycontact_ll_data_email);
    LinearLayout ll_other =
        (LinearLayout) my_contact_view.findViewById(R.id.mycontact_ll_data_other);

    // new row
    LinearLayout row = new LinearLayout(this);
    row.setOrientation(LinearLayout.HORIZONTAL);

    DisplayMetrics tmp_metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(tmp_metrics);
    int resolution_width = tmp_metrics.widthPixels;

    final boolean large_screen = (resolution_width >= 720);

    final EditText et = new EditText(this);
    LayoutParams lp_et;
    lp_et = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1);

    if (type.equals("number")) {
      ll_data = ll_telephone;

      it = InputType.TYPE_CLASS_PHONE;

      hint = R.string.telephone;

    } else if (type.equals("email")) {
      ll_data = ll_email;

      it = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;

      hint = R.string.email;

    } else {
      ll_data = ll_other;

      if (type.equals("address")) {

        et.setMinLines(1);
        et.setMaxLines(3);
        et.setLines(2);

        hint = R.string.address;
        it =
            InputType.TYPE_CLASS_TEXT
                | InputType
                    .TYPE_TEXT_FLAG_MULTI_LINE; // android.text.InputType.TYPE_TEXT_VARIATION_POSTAL_ADDRESS;
        lp_et = new LayoutParams(LayoutParams.WRAP_CONTENT, large_screen ? 130 : 90, 1);

        row.setLayoutParams(
            new LayoutParams(LayoutParams.MATCH_PARENT, (large_screen ? 130 : 90) + 20));

        et.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION);
        // et.setGravity(Gravity.LEFT | Gravity.TOP );

      } else if (type.equals("website")) {
        hint = R.string.website;
        it = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI;
      }
    }

    ((LinearLayout) ll_data.getParent()).setVisibility(LinearLayout.VISIBLE);

    et.setTextSize(large_screen ? 16 : 14); // EditText-Textgr��e
    et.setEms(10);
    et.setHint(hint);

    et.setInputType(it);

    lp_et.setMargins(0, 3, 0, 0);
    et.setLayoutParams(lp_et);

    Spinner spinner = new Spinner(this);
    LayoutParams lp_spinner =
        new LayoutParams(
            large_screen ? Functions.dpsToPx(this, 100) : Functions.dpsToPx(this, 80), /*300 : 200*/
            LayoutParams.MATCH_PARENT);

    lp_spinner.setMargins(0, 3, 0, 0);

    MySpinnerArrayAdapter dataAdapter = new MySpinnerArrayAdapter(this, list, large_screen);

    dataAdapter.setDropDownViewResource(
        android.support.v7.appcompat.R.layout.support_simple_spinner_dropdown_item);

    spinner.setAdapter(dataAdapter);
    spinner.setLayoutParams(lp_spinner);

    spinner.setOnItemSelectedListener(
        new OnItemSelectedListener() {

          @Override
          public void onItemSelected(
              final AdapterView<?> adapterView, final View view, int arg2, long arg3) {
            final Spinner spinner = (Spinner) adapterView;
            MySpinnerArrayAdapter adapter = (MySpinnerArrayAdapter) spinner.getAdapter();
            if (adapter
                .getItem(arg2)
                .toLowerCase(new Locale("en"))
                .equals(getString(R.string.en_custom).toLowerCase(new Locale("en")))) {

              LinearLayout ll = new LinearLayout(MainActivity.this);
              final EditText et = new EditText(MainActivity.this);

              LinearLayout.LayoutParams layoutParams =
                  new LinearLayout.LayoutParams(
                      LinearLayout.LayoutParams.MATCH_PARENT,
                      LinearLayout.LayoutParams.WRAP_CONTENT);
              layoutParams.setMargins(0, 20, 0, 0);

              et.setTextColor(Color.BLACK);
              et.requestFocus();

              // et.setHint(R.string.place);

              ll.addView(et, layoutParams);

              AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
              builder
                  .setView(ll)
                  .setTitle(R.string.message_custom_en)
                  .setPositiveButton(
                      android.R.string.ok,
                      new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {

                          String[] newItems = new String[spinnerArray.length + 1];
                          System.arraycopy(spinnerArray, 0, newItems, 0, spinnerArray.length);
                          newItems[newItems.length - 1] = et.getText().toString();

                          MySpinnerArrayAdapter adapter =
                              new MySpinnerArrayAdapter(
                                  getApplicationContext(),
                                  newItems,
                                  ((MySpinnerArrayAdapter) spinner.getAdapter()).getLargeScreen());
                          spinner.setAdapter(adapter);
                          spinner.setSelection(newItems.length - 1);
                        }
                      })
                  .setNegativeButton(
                      android.R.string.cancel,
                      new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {}
                      })
                  .create()
                  .show();
            }
          }

          @Override
          public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub

          }
        });

    Button btn = new Button(this);
    btn.setText("x");
    LayoutParams lp_btn = new LayoutParams(Functions.dpsToPx(this, 32), LayoutParams.WRAP_CONTENT);
    lp_btn.setMargins(-10, 0, -10, 0);
    btn.setLayoutParams(lp_btn);
    btn.setBackgroundColor(Color.TRANSPARENT);

    btn.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            if (((LinearLayout) v.getParent().getParent()).getChildCount() == 1) {
              ((LinearLayout) v.getParent().getParent().getParent()).setVisibility(View.GONE);
            }
            ((LinearLayout) v.getParent().getParent()).removeView((LinearLayout) v.getParent());
          }
        });

    row.addView(et);
    row.addView(spinner);
    row.addView(btn);

    row.setTag(type);

    ll_data.addView(row);
  }
Example #7
0
  public void displayAccounts() {
    accounts = b2evolution.DB.getAccounts(this);
    HashMap<?, ?> notificationOptions = b2evolution.DB.getNotificationOptions(this);
    boolean sound = false, vibrate = false, light = false, taglineValue = false;
    String tagline = "";

    if (notificationOptions != null) {
      if (notificationOptions.get("sound").toString().equals("1")) {
        sound = true;
      }
      if (notificationOptions.get("vibrate").toString().equals("1")) {
        vibrate = true;
      }
      if (notificationOptions.get("light").toString().equals("1")) {
        light = true;
      }
      if (notificationOptions.get("tagline_flag").toString().equals("1")) {
        taglineValue = true;
      }
      tagline = notificationOptions.get("tagline").toString();
    }

    if (accounts.size() > 0) {
      ScrollView sv = new ScrollView(this);
      sv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
      sv.setBackgroundColor(Color.parseColor("#FFFFFFFF"));
      LinearLayout layout = new LinearLayout(this);

      layout.setPadding(14, 14, 14, 14);
      layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

      layout.setOrientation(LinearLayout.VERTICAL);
      layout.setGravity(Gravity.LEFT);

      final LinearLayout cbLayout = new LinearLayout(this);

      cbLayout.setLayoutParams(
          new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

      cbLayout.setOrientation(LinearLayout.VERTICAL);

      LinearLayout.LayoutParams section1Params =
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

      section1Params.setMargins(0, 0, 0, 20);

      LinearLayout section1 = new LinearLayout(this);
      section1.setBackgroundDrawable(getResources().getDrawable(R.drawable.content_bg));
      section1.setLayoutParams(section1Params);
      section1.setOrientation(LinearLayout.VERTICAL);

      LinearLayout.LayoutParams headerParams =
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
      headerParams.setMargins(1, 1, 1, 0);
      TextView textView = new TextView(this);
      textView.setLayoutParams(headerParams);
      textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
      textView.setTypeface(Typeface.DEFAULT_BOLD);
      textView.setPadding(0, 4, 0, 4);
      textView.setShadowLayer(1, 0, 2, Color.parseColor("#FFFFFFFF"));
      textView.setBackgroundDrawable(getResources().getDrawable(R.drawable.content_bg_header));
      textView.setText("  " + getResources().getText(R.string.comment_notifications));

      section1.addView(textView);

      LinearLayout.LayoutParams cbParams =
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
      cbParams.setMargins(4, 0, 0, 6);

      for (int i = 0; i < accounts.size(); i++) {

        HashMap<?, ?> curHash = (HashMap<?, ?>) accounts.get(i);
        String curBlogName = curHash.get("blogName").toString();
        String accountID = curHash.get("id").toString();
        int runService = Integer.valueOf(curHash.get("runService").toString());
        accountNames.add(i, curBlogName);

        final CheckBox checkBox = new CheckBox(this);
        checkBox.setTextColor(Color.parseColor("#444444"));
        checkBox.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
        checkBox.setText(EscapeUtils.unescapeHtml(curBlogName));
        checkBox.setId(Integer.valueOf(accountID));
        checkBox.setLayoutParams(cbParams);

        if (runService == 1) {
          checkBox.setChecked(true);
        }

        cbLayout.addView(checkBox);
      }

      if (cbLayout.getChildCount() > 0) {
        section1.addView(cbLayout);
      }

      // add spinner and buttons
      TextView textView2 = new TextView(this);
      LinearLayout.LayoutParams labelParams =
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
      labelParams.setMargins(8, 0, 0, 0);
      textView2.setLayoutParams(labelParams);
      textView2.setTextColor(Color.parseColor("#444444"));
      textView2.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
      textView2.setText(getResources().getText(R.string.notifications_interval));

      section1.addView(textView2);

      final Spinner sInterval = new Spinner(this);
      LinearLayout.LayoutParams spinnerParams =
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
      spinnerParams.setMargins(4, 0, 4, 10);
      sInterval.setLayoutParams(spinnerParams);
      ArrayAdapter<Object> sIntervalArrayAdapter =
          new ArrayAdapter<Object>(
              this,
              R.layout.spinner_textview,
              new String[] {
                "5 Minutes",
                "10 Minutes",
                "15 Minutes",
                "30 Minutes",
                "1 Hour",
                "3 Hours",
                "6 Hours",
                "12 Hours",
                "Daily"
              });
      sIntervalArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      sInterval.setAdapter(sIntervalArrayAdapter);
      String interval = b2evolution.DB.getInterval(this);

      if (interval != "") {
        sInterval.setSelection(sIntervalArrayAdapter.getPosition(interval));
      }

      section1.addView(sInterval);

      final LinearLayout nOptionsLayout = new LinearLayout(this);

      nOptionsLayout.setLayoutParams(
          new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

      nOptionsLayout.setOrientation(LinearLayout.VERTICAL);

      CheckBox soundCB = new CheckBox(this);
      soundCB.setTag("soundCB");
      soundCB.setTextColor(Color.parseColor("#444444"));
      soundCB.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
      soundCB.setText(getResources().getText(R.string.notification_sound));
      soundCB.setLayoutParams(cbParams);
      soundCB.setChecked(sound);

      nOptionsLayout.addView(soundCB);

      CheckBox vibrateCB = new CheckBox(this);
      vibrateCB.setTag("vibrateCB");
      vibrateCB.setTextColor(Color.parseColor("#444444"));
      vibrateCB.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
      vibrateCB.setText(getResources().getText(R.string.notification_vibrate));
      vibrateCB.setLayoutParams(cbParams);
      vibrateCB.setChecked(vibrate);

      nOptionsLayout.addView(vibrateCB);

      CheckBox lightCB = new CheckBox(this);
      lightCB.setTag("lightCB");
      lightCB.setTextColor(Color.parseColor("#444444"));
      lightCB.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
      lightCB.setText(getResources().getText(R.string.notification_blink));
      lightCB.setLayoutParams(cbParams);
      lightCB.setChecked(light);

      nOptionsLayout.addView(lightCB);

      section1.addView(nOptionsLayout);

      layout.addView(section1);

      final LinearLayout section2 = new LinearLayout(this);
      section2.setBackgroundDrawable(getResources().getDrawable(R.drawable.content_bg));
      section2.setOrientation(LinearLayout.VERTICAL);
      LinearLayout.LayoutParams section2Params =
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
      section2Params.setMargins(0, 0, 0, 20);
      section2.setLayoutParams(section2Params);
      section2.setPadding(0, 0, 0, 10);

      TextView section2lbl = new TextView(this);
      section2lbl.setLayoutParams(headerParams);
      section2lbl.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
      section2lbl.setTypeface(Typeface.DEFAULT_BOLD);
      section2lbl.setShadowLayer(1, 0, 2, Color.parseColor("#FFFFFFFF"));
      section2lbl.setPadding(0, 4, 0, 4);
      section2lbl.setText("  " + getResources().getText(R.string.post_signature));
      section2lbl.setBackgroundDrawable(getResources().getDrawable(R.drawable.content_bg_header));

      section2.addView(section2lbl);

      CheckBox taglineCB = new CheckBox(this);
      taglineCB.setTag("taglineCB");
      taglineCB.setTextColor(Color.parseColor("#444444"));
      taglineCB.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
      taglineCB.setText(getResources().getText(R.string.add_tagline));
      taglineCB.setLayoutParams(cbParams);
      taglineCB.setChecked(taglineValue);

      section2.addView(taglineCB);

      EditText taglineET = new EditText(this);
      LinearLayout.LayoutParams taglineParams =
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
      taglineParams.setMargins(4, 0, 4, 4);
      taglineET.setLayoutParams(taglineParams);
      if (tagline != null) {
        if (tagline.equals("")) {
          if (BlackBerryUtils.getInstance().isBlackBerry())
            taglineET.setText(getResources().getText(R.string.posted_from_blackberry));
          else taglineET.setText(getResources().getText(R.string.posted_from));
        } else {
          taglineET.setText(tagline);
        }
      }
      taglineET.setMinLines(2);
      section2.addView(taglineET);

      layout.addView(section2);

      final LinearLayout section3 = new LinearLayout(this);
      section3.setOrientation(LinearLayout.HORIZONTAL);
      section3.setGravity(Gravity.RIGHT);
      LinearLayout.LayoutParams section3Params =
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
      section3Params.setMargins(0, 0, 0, 20);
      section3.setLayoutParams(section3Params);

      final Button cancel = new Button(this);

      LinearLayout.LayoutParams cancelParams =
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
      cancelParams.setMargins(0, 0, 10, 0);
      cancel.setLayoutParams(cancelParams);
      cancel.setBackgroundDrawable(getResources().getDrawable(R.drawable.b2evo_button_small));
      cancel.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
      cancel.setText(getResources().getText(R.string.cancel));
      cancel.setOnClickListener(
          new Button.OnClickListener() {
            public void onClick(View v) {
              finish();
            }
          });
      section3.addView(cancel);

      final Button save = new Button(this);

      save.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT));
      save.setBackgroundDrawable(getResources().getDrawable(R.drawable.b2evo_button_small));
      save.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
      save.setText(getResources().getText(R.string.save));

      save.setOnClickListener(
          new Button.OnClickListener() {
            public void onClick(View v) {

              boolean sound = false, vibrate = false, light = false, tagValue = false;
              checkCtr = 0;

              int listItemCount = cbLayout.getChildCount();
              for (int i = 0; i < listItemCount; i++) {
                CheckBox cbox = (CheckBox) cbLayout.getChildAt(i);
                int id = cbox.getId();
                if (cbox.isChecked()) {
                  checkCtr++;
                  b2evolution.DB.updateNotificationFlag(id, true);
                  Log.i("CommentService", "Service enabled for " + cbox.getText());
                } else {
                  b2evolution.DB.updateNotificationFlag(id, false);
                }
              }

              int noOptionsItemCount = nOptionsLayout.getChildCount();
              for (int i = 0; i < noOptionsItemCount; i++) {
                CheckBox cbox = (CheckBox) nOptionsLayout.getChildAt(i);
                if (cbox.getTag().equals("soundCB")) {
                  sound = cbox.isChecked();
                } else if (cbox.getTag().equals("vibrateCB")) {
                  vibrate = cbox.isChecked();
                } else if (cbox.getTag().equals("lightCB")) {
                  light = cbox.isChecked();
                }
              }

              CheckBox tagFlag = (CheckBox) section2.getChildAt(1);
              tagValue = tagFlag.isChecked();

              EditText taglineET = (EditText) section2.getChildAt(2);
              String taglineText = taglineET.getText().toString();

              b2evolution.DB.updateNotificationSettings(
                  sInterval.getSelectedItem().toString(),
                  sound,
                  vibrate,
                  light,
                  tagValue,
                  taglineText);

              if (checkCtr > 0) {

                String updateInterval = sInterval.getSelectedItem().toString();
                int UPDATE_INTERVAL = 3600000;

                // configure time interval
                if (updateInterval.equals("5 Minutes")) {
                  UPDATE_INTERVAL = 300000;
                } else if (updateInterval.equals("10 Minutes")) {
                  UPDATE_INTERVAL = 600000;
                } else if (updateInterval.equals("15 Minutes")) {
                  UPDATE_INTERVAL = 900000;
                } else if (updateInterval.equals("30 Minutes")) {
                  UPDATE_INTERVAL = 1800000;
                } else if (updateInterval.equals("1 Hour")) {
                  UPDATE_INTERVAL = 3600000;
                } else if (updateInterval.equals("3 Hours")) {
                  UPDATE_INTERVAL = 10800000;
                } else if (updateInterval.equals("6 Hours")) {
                  UPDATE_INTERVAL = 21600000;
                } else if (updateInterval.equals("12 Hours")) {
                  UPDATE_INTERVAL = 43200000;
                } else if (updateInterval.equals("Daily")) {
                  UPDATE_INTERVAL = 86400000;
                }

                Intent intent = new Intent(Preferences.this, CommentBroadcastReceiver.class);
                PendingIntent pIntent = PendingIntent.getBroadcast(Preferences.this, 0, intent, 0);

                AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);

                alarmManager.setRepeating(
                    AlarmManager.RTC_WAKEUP,
                    System.currentTimeMillis() + (5 * 1000),
                    UPDATE_INTERVAL,
                    pIntent);

              } else {
                Intent stopIntent = new Intent(Preferences.this, CommentBroadcastReceiver.class);
                PendingIntent stopPIntent =
                    PendingIntent.getBroadcast(Preferences.this, 0, stopIntent, 0);
                AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
                alarmManager.cancel(stopPIntent);

                Intent service = new Intent(Preferences.this, CommentService.class);
                stopService(service);
              }

              finish();
            }
          });

      section3.addView(save);
      layout.addView(section3);

      sv.addView(layout);

      setContentView(sv);
    }
  }