@Override
    public View onCreateView(
        LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      final View rootView = inflater.inflate(R.layout.fragment_section_main, container, false);
      EditText add = (EditText) rootView.findViewById(R.id.editAddress);
      // EditText port = (EditText) rootView.findViewById(R.id.editPort);
      EditText key = (EditText) rootView.findViewById(R.id.editKey);
      add.setImeOptions(EditorInfo.IME_ACTION_DONE);
      key.setImeOptions(EditorInfo.IME_ACTION_DONE);
      SharedPreferences myPrefs = getActivity().getSharedPreferences("myPrefs", MODE_PRIVATE);
      add.setText(myPrefs.getString("address", ""));
      key.setText(myPrefs.getString("key", ""));

      getActivity()
          .getWindow()
          .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
      rootView
          .findViewById(R.id.playbutton)
          .setOnClickListener(
              new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                  startFoldit(rootView);
                }
              });
      // Tutorial view highlight app important parts

      return rootView;
    }
Exemplo n.º 2
0
  /** OnClickListener methods */
  @Override
  public void onClick(View view) {
    if (editText == null) {
      editText = new EditText(Utils.mainActivity);
      editText.setGravity(Gravity.CENTER);
      editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
    }

    if (inputType != null) {
      if (inputType.toLowerCase().equals("numeric"))
        editText.setInputType(InputType.TYPE_CLASS_NUMBER);
      else
        editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    } else if (lastLive instanceof Integer) editText.setInputType(InputType.TYPE_CLASS_NUMBER);
    else editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);

    textView.setVisibility(View.GONE);
    if (editText.getParent() != null) {
      ((LinearLayout) editText.getParent()).findViewById(tv_id).setVisibility(View.VISIBLE);
      ((LinearLayout) editText.getParent()).removeView(editText);
    }

    elementFrame.addView(editText);
    editText.setOnEditorActionListener(this);
    editText.setText(lastEdit.toString());
    editText.requestFocus();
    editText.setSelection(0, editText.getText().length());
    Utils.imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED);
  }
Exemplo n.º 3
0
  public void createAlertDialog() {
    final EditText edtUsername = new EditText(getSherlockActivity());
    edtUsername.setSingleLine();
    edtUsername.setImeOptions(EditorInfo.IME_ACTION_DONE);

    final AlertDialog alert =
        new AlertDialog.Builder(getSherlockActivity())
            .setTitle("Coderwall")
            .setMessage("Please enter " + (username == null ? "your" : "a") + " username")
            .setView(edtUsername)
            .setPositiveButton(
                "Ok",
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {
                    createTask(edtUsername.getText().toString().trim(), true).execute();
                  }
                })
            .show();

    edtUsername.setOnEditorActionListener(
        new OnEditorActionListener() {
          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            alert.getButton(AlertDialog.BUTTON_POSITIVE).performClick();
            return false;
          }
        });
  }
Exemplo n.º 4
0
 @Override
 @NonNull
 protected LinearLayout makeCenterView() {
   LinearLayout rootLayout = new LinearLayout(activity);
   rootLayout.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
   rootLayout.setOrientation(LinearLayout.VERTICAL);
   blackColorView = new ColorPanelView(activity);
   //noinspection ResourceType
   blackColorView.setId(BLACK_ID);
   blackColorView.setLayoutParams(
       new LinearLayout.LayoutParams(MATCH_PARENT, ConvertUtils.toPx(activity, 30)));
   blackColorView.setPointerDrawable(
       CompatUtils.getDrawable(activity, R.drawable.color_picker_cursor_bottom));
   blackColorView.setLockPointerInBounds(false);
   blackColorView.setOnColorChangedListener(
       new ColorPanelView.OnColorChangedListener() {
         @Override
         public void onColorChanged(ColorPanelView view, int color) {
           updateCurrentColor(color);
         }
       });
   rootLayout.addView(blackColorView);
   multiColorView = new ColorPanelView(activity);
   //noinspection ResourceType
   multiColorView.setId(MULTI_ID);
   multiColorView.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, 0, 1.0f));
   multiColorView.setPointerDrawable(
       CompatUtils.getDrawable(activity, R.drawable.color_picker_cursor_top));
   multiColorView.setLockPointerInBounds(true);
   multiColorView.setOnColorChangedListener(
       new ColorPanelView.OnColorChangedListener() {
         @Override
         public void onColorChanged(ColorPanelView view, int color) {
           updateCurrentColor(color);
         }
       });
   rootLayout.addView(multiColorView);
   LinearLayout previewLayout = new LinearLayout(activity);
   previewLayout.setOrientation(LinearLayout.HORIZONTAL);
   previewLayout.setGravity(Gravity.CENTER);
   previewLayout.setLayoutParams(
       new LinearLayout.LayoutParams(MATCH_PARENT, ConvertUtils.toPx(activity, 30)));
   hexValView = new EditText(activity);
   hexValView.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
   hexValView.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
   hexValView.setImeOptions(EditorInfo.IME_ACTION_DONE);
   hexValView.setGravity(Gravity.CENTER);
   hexValView.setBackgroundColor(initColor);
   hexValView.setTextColor(Color.BLACK);
   hexValView.setShadowLayer(3, 0, 2, Color.WHITE); // 设置阴影,以便背景色为黑色系列时仍然看得见
   hexValView.setMinEms(6);
   hexValView.setMaxEms(8);
   hexValView.setPadding(0, 0, 0, 0);
   hexValView.setSingleLine(true);
   hexValView.setOnEditorActionListener(this);
   hexValDefaultColor = hexValView.getTextColors();
   previewLayout.addView(hexValView);
   rootLayout.addView(previewLayout);
   return rootLayout;
 }
Exemplo n.º 5
0
  public void renameFolderOrFiles(final int position) {
    final String fileName = mainFiles[position].getName();
    final EditText editText_fileName = new EditText(this);

    editText_fileName.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN);
    editText_fileName.setText(fileName);

    new AlertDialog.Builder(this)
        .setTitle("请输入")
        .setView(editText_fileName)
        .setPositiveButton(
            "确定",
            new OnClickListener() {

              @Override
              public void onClick(DialogInterface di, int arg1) {
                String newName = editText_fileName.getText().toString();
                File newFile =
                    new File(mainFiles[position].getParentFile() + File.separator + newName);
                mainFiles[0].renameTo(newFile);
                updateFilesView(position);
              }
            })
        .setNegativeButton("取消", null)
        .show();
  }
Exemplo n.º 6
0
 private EditText createRenameEditText(String fileName) {
   EditText editText = new EditText(this);
   editText.setText(
       fileName.substring(0, fileName.length() - FileController.FILE_EXTENSION.length()));
   editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
   editText.setSelection(editText.getText().length());
   return editText;
 }
Exemplo n.º 7
0
  private EditText createEditText(
      String hint, int inputType, int imeOption, boolean shouldMoveToNext, final String key) {

    EditText ret = new EditText(mContext);
    LinearLayout.LayoutParams params =
        new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    ret.setLayoutParams(params);
    ret.setHint(hint);

    ret.setInputType(inputType);
    ret.setImeOptions(imeOption);

    if (shouldMoveToNext) {
      ret.setOnEditorActionListener(
          new OnEditorActionListener() {

            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
              if (mDelegate != null) {
                if (EditorInfo.IME_ACTION_NEXT == actionId) {
                  mDelegate.scroll(CreateAccountDelegate.FORWARD);
                } else {
                  processForm();
                }

                return true;
              } else {
                return false;
              }
            }
          });
    }

    ret.addTextChangedListener(
        new TextWatcher() {

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

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

          @Override
          public void afterTextChanged(Editable s) {
            mFormData.put(key, s.toString());
          }
        });

    return ret;
  }
Exemplo n.º 8
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.fragment_draft, null);

    mDB = new DatabaseHelper(getActivity());

    mDraft = (TextView) view.findViewById(R.id.draft_data);
    mDraftEdit = (EditText) view.findViewById(R.id.draft_edittext);
    mDraftEdit.setImeOptions(EditorInfo.IME_ACTION_DONE);

    if (!mDB.checkDraftExists(0)) {
      Log.d("GDTM", "Not exist!");
      mDB.addDraftData(0, "");
    } else {
      String dbString = mDB.getDraftData(0);
      mDraft.setText(dbString);
    }

    MainActivity.setShowEditButton(true);
    MainActivity.setOnMainMenuEditButtonListener(
        new OnMainMenuEditButtonListener() {

          @Override
          public void onMainMenuEditButtonListener(boolean isChecked) {
            if (isChecked) {
              mDraftEdit.setVisibility(View.VISIBLE);
              mDraft.setVisibility(View.GONE);
              String dbDraft = mDB.getDraftData(0);
              if (!dbDraft.equalsIgnoreCase("")) {
                mDraftEdit.setText(dbDraft);
              }
            } else {
              hideKeyboard();
              mDraftEdit.setVisibility(View.GONE);
              mDraft.setVisibility(View.VISIBLE);

              String draft = mDraftEdit.getText().toString();

              mDraft.setText(draft);

              mDB.updateDraft(0, draft);
            }
          }
        });

    return view;
  }
Exemplo n.º 9
0
 public void handleKeyboardType(int type, boolean autocorrect) {
   // Switched the keyboard handler to use the inputType rather than the rawInputType
   // This is kinda brute-force but more effective for most use-cases
   switch (type) {
     case KEYBOARD_ASCII:
       tv.setKeyListener(TextKeyListener.getInstance(autocorrect, Capitalize.NONE));
       tv.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL);
       // tv.setRawInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL);
       break;
     case KEYBOARD_NUMBERS_PUNCTUATION:
       tv.setInputType(InputType.TYPE_CLASS_NUMBER);
       // tv.setKeyListener(DigitsKeyListener.getInstance());
       break;
     case KEYBOARD_URL:
       Log.i(LCAT, "Setting keyboard type URL-3");
       // tv.setKeyListener(TextKeyListener.getInstance(autocorrect, Capitalize.NONE));
       tv.setImeOptions(EditorInfo.IME_ACTION_GO);
       // tv.setRawInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
       tv.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
       break;
     case KEYBOARD_NUMBER_PAD:
       tv.setKeyListener(DigitsKeyListener.getInstance(true, true));
       // tv.setRawInputType(InputType.TYPE_CLASS_NUMBER);
       tv.setInputType(InputType.TYPE_CLASS_NUMBER);
       break;
     case KEYBOARD_PHONE_PAD:
       tv.setKeyListener(DialerKeyListener.getInstance());
       // tv.setRawInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_CLASS_PHONE);
       tv.setInputType(InputType.TYPE_CLASS_PHONE);
       break;
     case KEYBOARD_EMAIL_ADDRESS:
       // tv.setKeyListener(TextKeyListener.getInstance(autocorrect, Capitalize.NONE));
       tv.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
       break;
     case KEYBOARD_DEFAULT:
       tv.setKeyListener(TextKeyListener.getInstance(autocorrect, Capitalize.NONE));
       // tv.setRawInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL);
       tv.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL);
       break;
     case KEYBOARD_PASSWORD:
       tv.setKeyListener(TextKeyListener.getInstance(false, Capitalize.NONE));
       // tv.setRawInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
       tv.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
       break;
   }
 }
  private void initialize() {
    setOrientation(VERTICAL);
    if (isInEditMode()) {
      return;
    }

    View view =
        LayoutInflater.from(mContext).inflate(R.layout.widget_float_labeled_edit_text, this);

    hintTextView = (TextView) view.findViewById(R.id.FloatLabeledEditTextHint);
    editText = (EditText) view.findViewById(R.id.FloatLabeledEditTextEditText);

    if (hint != null) {
      setHint(hint);
    }

    editText.setImeOptions(imeOptions);

    if (imeActionId > -1 && !TextUtils.isEmpty(imeActionLabel)) {
      editText.setImeActionLabel(imeActionLabel, imeActionId);
    }

    editText.setSingleLine(singleLine);
    hintTextView.setTextColor(hintColor != null ? hintColor : ColorStateList.valueOf(Color.BLACK));
    editText.setTextColor(textColor != null ? textColor : ColorStateList.valueOf(Color.BLACK));

    if (inputType != EditorInfo.TYPE_NULL) {
      editText.setInputType(inputType);
    }

    hintTextView.setVisibility(View.INVISIBLE);
    AnimatorProxy.wrap(hintTextView).setAlpha(0); // Need this for compat reasons
    editText.addTextChangedListener(onTextChanged);
    editText.setOnFocusChangeListener(onFocusChanged);

    editText.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            if (mClickListener != null) mClickListener.onClick(FloatLabeledEditText.this);
          }
        });
  }
  /**
   * Begin edit text.
   *
   * @param view the view
   */
  private void beginEditText(final DrawableHighlightView view) {
    mLogger.info("beginEditText", view);

    EditText editText = null;

    if (view == topHv) {
      editText = editTopText;
    } else if (view == bottomHv) {
      editText = editBottomText;
    }

    if (editText != null) {
      mEditTextWatcher.view = null;
      editText.removeTextChangedListener(mEditTextWatcher);

      final EditableDrawable editable = (EditableDrawable) view.getContent();
      final String oldText = (String) editable.getText();
      editText.setText(oldText);
      editText.setSelection(editText.length());
      editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
      editText.requestFocusFromTouch();

      Handler handler = new Handler();
      ResultReceiver receiver = new ResultReceiver(handler);

      if (!mInputManager.showSoftInput(editText, 0, receiver)) {
        mInputManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); // TODO: verify
      }

      mEditTextWatcher.view = view;
      editText.setOnEditorActionListener(this);
      editText.addTextChangedListener(mEditTextWatcher);

      ((ImageViewDrawableOverlay) mImageView).setSelectedHighlightView(view);
      ((EditableDrawable) view.getContent())
          .setText(((EditableDrawable) view.getContent()).getText());
      view.forceUpdate();
    }
  }
  @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());
  }
Exemplo n.º 13
0
  @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());
  }
Exemplo n.º 14
0
  private void init() {
    mCurrentDirectory = Environment.getExternalStorageDirectory();
    mInitialDirectory = Environment.getExternalStorageDirectory();

    this.setBackgroundResource(R.drawable.bg_pathbar);
    this.setInAnimation(getContext(), R.anim.fade_in);
    this.setOutAnimation(getContext(), R.anim.fade_out);

    // RelativeLayout1
    RelativeLayout standardModeLayout = new RelativeLayout(getContext());
    { // I use a block here so that layoutParams can be used as a variable name further down.
      android.widget.ViewFlipper.LayoutParams layoutParams =
          new android.widget.ViewFlipper.LayoutParams(
              LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
      standardModeLayout.setLayoutParams(layoutParams);

      this.addView(standardModeLayout);
    }

    // ImageButton -- GONE. Kept this code in case we need to use an right-aligned button in the
    // future.
    mSwitchToManualModeButton = new ImageButton(getContext());
    {
      android.widget.RelativeLayout.LayoutParams layoutParams =
          new android.widget.RelativeLayout.LayoutParams(
              LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
      layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);

      mSwitchToManualModeButton.setLayoutParams(layoutParams);
      mSwitchToManualModeButton.setId(10);
      mSwitchToManualModeButton.setImageResource(R.drawable.ic_navbar_edit);
      mSwitchToManualModeButton.setBackgroundResource(R.drawable.bg_navbar_btn);
      mSwitchToManualModeButton.setVisibility(View.GONE);

      standardModeLayout.addView(mSwitchToManualModeButton);
    }

    // ImageButton -- GONE. Kept this code in case we need to use an left-aligned button in the
    // future.
    ImageButton cdToRootButton = new ImageButton(getContext());
    {
      android.widget.RelativeLayout.LayoutParams layoutParams =
          new android.widget.RelativeLayout.LayoutParams(
              LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
      layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);

      cdToRootButton.setLayoutParams(layoutParams);
      cdToRootButton.setId(11);
      cdToRootButton.setBackgroundResource(R.drawable.bg_navbar_btn);
      cdToRootButton.setImageResource(R.drawable.ic_navbar_home);
      cdToRootButton.setScaleType(ScaleType.CENTER_INSIDE);
      cdToRootButton.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              cd("/");
            }
          });
      cdToRootButton.setVisibility(View.GONE);

      standardModeLayout.addView(cdToRootButton);
    }

    // Horizontal ScrollView container
    mPathButtonsContainer = new HorizontalScrollView(getContext());
    {
      android.widget.RelativeLayout.LayoutParams layoutParams =
          new android.widget.RelativeLayout.LayoutParams(
              LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
      layoutParams.addRule(RelativeLayout.LEFT_OF, mSwitchToManualModeButton.getId());
      layoutParams.addRule(RelativeLayout.RIGHT_OF, cdToRootButton.getId());
      layoutParams.alignWithParent = true;

      mPathButtonsContainer.setLayoutParams(layoutParams);
      mPathButtonsContainer.setHorizontalScrollBarEnabled(false);
      mPathButtonsContainer.setHorizontalFadingEdgeEnabled(true);

      standardModeLayout.addView(mPathButtonsContainer);
    }

    // PathButtonLayout
    mPathButtons = new PathButtonLayout(getContext());
    {
      android.widget.LinearLayout.LayoutParams layoutParams =
          new android.widget.LinearLayout.LayoutParams(
              LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);

      mPathButtons.setLayoutParams(layoutParams);
      mPathButtons.setNavigationBar(this);

      mPathButtonsContainer.addView(mPathButtons);
    }

    // RelativeLayout2
    RelativeLayout manualModeLayout = new RelativeLayout(getContext());
    {
      android.widget.ViewFlipper.LayoutParams layoutParams =
          new android.widget.ViewFlipper.LayoutParams(
              LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
      manualModeLayout.setLayoutParams(layoutParams);

      this.addView(manualModeLayout);
    }

    // ImageButton
    mGoButton = new ImageButton(getContext());
    {
      android.widget.RelativeLayout.LayoutParams layoutParams =
          new android.widget.RelativeLayout.LayoutParams(
              LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
      layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);

      mGoButton.setLayoutParams(layoutParams);
      mGoButton.setId(20);
      mGoButton.setBackgroundResource(R.drawable.bg_navbar_btn);
      mGoButton.setImageResource(R.drawable.ic_navbar_accept);
      mGoButton.setScaleType(ScaleType.CENTER_INSIDE);
      mGoButton.setOnClickListener(
          new View.OnClickListener() {

            @Override
            public void onClick(View v) {
              manualInputCd(mPathEditText.getText().toString());
            }
          });

      manualModeLayout.addView(mGoButton);
    }

    // EditText
    mPathEditText = new EditText(getContext());
    {
      android.widget.RelativeLayout.LayoutParams layoutParams =
          new android.widget.RelativeLayout.LayoutParams(
              LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
      layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
      layoutParams.alignWithParent = true;
      layoutParams.addRule(RelativeLayout.LEFT_OF, mGoButton.getId());

      mPathEditText.setLayoutParams(layoutParams);
      mPathEditText.setBackgroundResource(R.drawable.bg_navbar_textfield);
      mPathEditText.setTextColor(Color.BLACK);
      mPathEditText.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
      mPathEditText.setImeOptions(EditorInfo.IME_ACTION_GO);
      mPathEditText.setOnEditorActionListener(
          new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
              if (actionId == EditorInfo.IME_ACTION_GO
                  || (event.getAction() == KeyEvent.ACTION_DOWN
                      && (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_CENTER
                          || event.getKeyCode() == KeyEvent.KEYCODE_ENTER))) {
                if (manualInputCd(v.getText().toString()))
                  // Since we have successfully navigated.
                  return true;
              }

              return false;
            }
          });

      manualModeLayout.addView(mPathEditText);
    }
  }
Exemplo n.º 15
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    ActivityTaskManager.getInstance().putActivity("Login", this);

    temp = this;
    database = new DBManager(this);

    username = (EditText) findViewById(R.id.username);
    password = (EditText) findViewById(R.id.password);
    login = (TextView) findViewById(R.id.login);
    register = (TextView) findViewById(R.id.register);
    rememberPass = (CheckBox) findViewById(R.id.rememberPass);
    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    relativeLayout = (RelativeLayout) findViewById(R.id.loginRelative);
    autoLogin = (CheckBox) findViewById(R.id.autoLogin);

    relativeLayout.setVisibility(View.INVISIBLE);
    // progressBar.setVisibility(View.INVISIBLE);

    String cacheName = database.getCacheName();
    username.setText(cacheName);

    mHandler =
        new Handler() {
          @Override
          public void handleMessage(Message msg) {
            if (msg.what == 0x111) {
              runningFlag = 1;
              // relativeLayout.setVisibility(View.VISIBLE);
              // progressBar.setVisibility(View.VISIBLE);
            } else {
              String name = username.getText().toString(); // 获取edittext里的用户名密码
              String pass = password.getText().toString();
              if (database.checkUser(name, pass)) {
                SharedPreferences mySharedPreferences =
                    getSharedPreferences(
                        "info", Activity.MODE_PRIVATE); // 利用SharedPreferences保存当前用户id
                SharedPreferences.Editor editor = mySharedPreferences.edit();

                editor.putInt("userId", database.getIdByName(name));
                editor.commit();

                int auto = 0;
                if (autoLogin.isChecked()) {
                  auto = 1;
                }
                if (rememberPass.isChecked()) {
                  database.addCache(name, pass, 1, auto); // 修改缓存的用户名
                } else {
                  database.addCache(name, pass, 0, auto);
                }

                Intent intentToMain = new Intent();
                intentToMain.setClass(Login.this, MainActivity.class);
                startActivity(intentToMain);
                relativeLayout.setVisibility(View.INVISIBLE);
                // finish();
              } else {
                relativeLayout.setVisibility(View.INVISIBLE);
                runningFlag = 0;
                Toast toast =
                    Toast.makeText(getApplicationContext(), "用户名或密码不正确", Toast.LENGTH_SHORT);
                toast.show();
              }
            }
          }
        };

    if (1 == database.getCacheFlag()) {
      String pass = database.getCachePassword();
      password.setText(pass);
      rememberPass.setChecked(true);
    }

    password.setImeOptions(EditorInfo.IME_ACTION_DONE);
    password.setOnEditorActionListener(
        new TextView.OnEditorActionListener() {
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE
                || (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
              System.out.println(login.performClick());
              return true;
            }
            return false;
          }
        });
    login.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            isInterrupted = false;
            mProgressStatus = 0;
            if (0 == username.getText().length()) { // 判断用户名是否为空
              // relativeLayout.setVisibility(View.INVISIBLE);
              Toast toast = Toast.makeText(getApplicationContext(), "请输入用户名", Toast.LENGTH_SHORT);
              toast.show();
            } else if (0 == password.getText().length()) { // 判断密码是否为空
              // relativeLayout.setVisibility(View.INVISIBLE);
              Toast toast = Toast.makeText(getApplicationContext(), "请输入密码", Toast.LENGTH_SHORT);
              toast.show();
            } else {
              relativeLayout.setVisibility(View.VISIBLE);
              thread =
                  new Thread(
                      new Runnable() {
                        @Override
                        public void run() {
                          while (!isInterrupted) {
                            mProgressStatus = doWork();
                            Message m = new Message();
                            if (mProgressStatus < 100) {
                              m.what = 0x111;
                              mHandler.sendMessage(m);
                            } else {
                              m.what = 0x110;
                              mHandler.sendMessage(m);
                              break;
                            }
                          }
                        }

                        private int doWork() {
                          mProgressStatus += 10;
                          try {
                            // progressBar.setVisibility(View.VISIBLE);
                            Thread.sleep(100);
                          } catch (InterruptedException e) {
                            e.printStackTrace();
                          }
                          return mProgressStatus;
                        }
                      });
              thread.start();
            }
          }
        });

    register.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent intentToReg = new Intent();
            intentToReg.setClass(Login.this, Register.class);
            startActivity(intentToReg);
          }
        });

    autoLogin.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            if (autoLogin.isChecked()) {
              rememberPass.setChecked(true);
            }
          }
        });

    if (1 == database.getAuto()) { // 自动登录
      autoLogin.setChecked(true);
      login.performClick();
    }
  }
Exemplo n.º 16
0
  @Override
  public View createView(LayoutInflater inflater) {
    if (fragmentView == null) {
      searching = false;
      searchWas = false;

      actionBar.setBackButtonImage(R.drawable.ic_ab_back);
      actionBar.setAllowOverlayTitle(true);
      if (isAlwaysShare) {
        actionBar.setTitle(
            LocaleController.getString("AlwaysShareWithTitle", R.string.AlwaysShareWithTitle));
      } else if (isNeverShare) {
        actionBar.setTitle(
            LocaleController.getString("NeverShareWithTitle", R.string.NeverShareWithTitle));
      } else {
        actionBar.setTitle(
            isBroadcast
                ? LocaleController.getString("NewBroadcastList", R.string.NewBroadcastList)
                : LocaleController.getString("NewGroup", R.string.NewGroup));
        actionBar.setSubtitle(
            LocaleController.formatString(
                "MembersCount", R.string.MembersCount, selectedContacts.size(), maxCount));
      }

      actionBar.setActionBarMenuOnItemClick(
          new ActionBar.ActionBarMenuOnItemClick() {
            @Override
            public void onItemClick(int id) {
              if (id == -1) {
                finishFragment();
              } else if (id == done_button) {
                if (selectedContacts.isEmpty()) {
                  return;
                }
                ArrayList<Integer> result = new ArrayList<>();
                result.addAll(selectedContacts.keySet());
                if (isAlwaysShare || isNeverShare) {
                  if (delegate != null) {
                    delegate.didSelectUsers(result);
                  }
                  finishFragment();
                } else {
                  Bundle args = new Bundle();
                  args.putIntegerArrayList("result", result);
                  args.putBoolean("broadcast", isBroadcast);
                  presentFragment(new GroupCreateFinalActivity(args));
                }
              }
            }
          });
      ActionBarMenu menu = actionBar.createMenu();
      menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));

      searchListViewAdapter = new ContactsSearchAdapter(getParentActivity(), null, false);
      searchListViewAdapter.setCheckedMap(selectedContacts);
      searchListViewAdapter.setUseUserCell(true);
      listViewAdapter = new ContactsAdapter(getParentActivity(), true, false, null);
      listViewAdapter.setCheckedMap(selectedContacts);

      fragmentView = new LinearLayout(getParentActivity());
      LinearLayout linearLayout = (LinearLayout) fragmentView;
      linearLayout.setOrientation(LinearLayout.VERTICAL);

      FrameLayout frameLayout = new FrameLayout(getParentActivity());
      linearLayout.addView(frameLayout);
      LinearLayout.LayoutParams layoutParams =
          (LinearLayout.LayoutParams) frameLayout.getLayoutParams();
      layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
      layoutParams.height = LinearLayout.LayoutParams.WRAP_CONTENT;
      layoutParams.gravity = Gravity.TOP;
      frameLayout.setLayoutParams(layoutParams);

      userSelectEditText = new EditText(getParentActivity());
      userSelectEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
      userSelectEditText.setHintTextColor(0xff979797);
      userSelectEditText.setTextColor(0xff212121);
      userSelectEditText.setInputType(
          InputType.TYPE_TEXT_VARIATION_FILTER
              | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
              | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
      userSelectEditText.setMinimumHeight(AndroidUtilities.dp(54));
      userSelectEditText.setSingleLine(false);
      userSelectEditText.setLines(2);
      userSelectEditText.setMaxLines(2);
      userSelectEditText.setVerticalScrollBarEnabled(true);
      userSelectEditText.setHorizontalScrollBarEnabled(false);
      userSelectEditText.setPadding(0, 0, 0, 0);
      userSelectEditText.setImeOptions(
          EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
      userSelectEditText.setGravity(
          (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
      AndroidUtilities.clearCursorDrawable(userSelectEditText);
      frameLayout.addView(userSelectEditText);
      FrameLayout.LayoutParams layoutParams1 =
          (FrameLayout.LayoutParams) userSelectEditText.getLayoutParams();
      layoutParams1.width = FrameLayout.LayoutParams.MATCH_PARENT;
      layoutParams1.height = FrameLayout.LayoutParams.WRAP_CONTENT;
      layoutParams1.leftMargin = AndroidUtilities.dp(10);
      layoutParams1.rightMargin = AndroidUtilities.dp(10);
      layoutParams1.gravity = Gravity.TOP;
      userSelectEditText.setLayoutParams(layoutParams1);

      if (isAlwaysShare) {
        userSelectEditText.setHint(
            LocaleController.getString(
                "AlwaysShareWithPlaceholder", R.string.AlwaysShareWithPlaceholder));
      } else if (isNeverShare) {
        userSelectEditText.setHint(
            LocaleController.getString(
                "NeverShareWithPlaceholder", R.string.NeverShareWithPlaceholder));
      } else {
        userSelectEditText.setHint(
            LocaleController.getString("SendMessageTo", R.string.SendMessageTo));
      }
      if (Build.VERSION.SDK_INT >= 11) {
        userSelectEditText.setTextIsSelectable(false);
      }
      userSelectEditText.addTextChangedListener(
          new TextWatcher() {
            @Override
            public void beforeTextChanged(
                CharSequence charSequence, int start, int count, int after) {
              if (!ignoreChange) {
                beforeChangeIndex = userSelectEditText.getSelectionStart();
                changeString = new SpannableString(charSequence);
              }
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {}

            @Override
            public void afterTextChanged(Editable editable) {
              if (!ignoreChange) {
                boolean search = false;
                int afterChangeIndex = userSelectEditText.getSelectionEnd();
                if (editable.toString().length() < changeString.toString().length()) {
                  String deletedString = "";
                  try {
                    deletedString =
                        changeString.toString().substring(afterChangeIndex, beforeChangeIndex);
                  } catch (Exception e) {
                    FileLog.e("tmessages", e);
                  }
                  if (deletedString.length() > 0) {
                    if (searching && searchWas) {
                      search = true;
                    }
                    Spannable span = userSelectEditText.getText();
                    for (int a = 0; a < allSpans.size(); a++) {
                      XImageSpan sp = allSpans.get(a);
                      if (span.getSpanStart(sp) == -1) {
                        allSpans.remove(sp);
                        selectedContacts.remove(sp.uid);
                      }
                    }
                    if (!isAlwaysShare && !isNeverShare) {
                      actionBar.setSubtitle(
                          LocaleController.formatString(
                              "MembersCount",
                              R.string.MembersCount,
                              selectedContacts.size(),
                              maxCount));
                    }
                    listView.invalidateViews();
                  } else {
                    search = true;
                  }
                } else {
                  search = true;
                }
                if (search) {
                  String text = userSelectEditText.getText().toString().replace("<", "");
                  if (text.length() != 0) {
                    searching = true;
                    searchWas = true;
                    if (listView != null) {
                      listView.setAdapter(searchListViewAdapter);
                      searchListViewAdapter.notifyDataSetChanged();
                      if (android.os.Build.VERSION.SDK_INT >= 11) {
                        listView.setFastScrollAlwaysVisible(false);
                      }
                      listView.setFastScrollEnabled(false);
                      listView.setVerticalScrollBarEnabled(true);
                    }
                    if (emptyTextView != null) {
                      emptyTextView.setText(
                          LocaleController.getString("NoResult", R.string.NoResult));
                    }
                    searchListViewAdapter.searchDialogs(text);
                  } else {
                    searchListViewAdapter.searchDialogs(null);
                    searching = false;
                    searchWas = false;
                    listView.setAdapter(listViewAdapter);
                    listViewAdapter.notifyDataSetChanged();
                    if (android.os.Build.VERSION.SDK_INT >= 11) {
                      listView.setFastScrollAlwaysVisible(true);
                    }
                    listView.setFastScrollEnabled(true);
                    listView.setVerticalScrollBarEnabled(false);
                    emptyTextView.setText(
                        LocaleController.getString("NoContacts", R.string.NoContacts));
                  }
                }
              }
            }
          });

      LinearLayout emptyTextLayout = new LinearLayout(getParentActivity());
      emptyTextLayout.setVisibility(View.INVISIBLE);
      emptyTextLayout.setOrientation(LinearLayout.VERTICAL);
      linearLayout.addView(emptyTextLayout);
      layoutParams = (LinearLayout.LayoutParams) emptyTextLayout.getLayoutParams();
      layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
      layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
      emptyTextLayout.setLayoutParams(layoutParams);
      emptyTextLayout.setOnTouchListener(
          new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
              return true;
            }
          });

      emptyTextView = new TextView(getParentActivity());
      emptyTextView.setTextColor(0xff808080);
      emptyTextView.setTextSize(20);
      emptyTextView.setGravity(Gravity.CENTER);
      emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
      emptyTextLayout.addView(emptyTextView);
      layoutParams = (LinearLayout.LayoutParams) emptyTextView.getLayoutParams();
      layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
      layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
      layoutParams.weight = 0.5f;
      emptyTextView.setLayoutParams(layoutParams);

      FrameLayout frameLayout2 = new FrameLayout(getParentActivity());
      emptyTextLayout.addView(frameLayout2);
      layoutParams = (LinearLayout.LayoutParams) frameLayout2.getLayoutParams();
      layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
      layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
      layoutParams.weight = 0.5f;
      frameLayout2.setLayoutParams(layoutParams);

      listView = new LetterSectionsListView(getParentActivity());
      listView.setEmptyView(emptyTextLayout);
      listView.setVerticalScrollBarEnabled(false);
      listView.setDivider(null);
      listView.setDividerHeight(0);
      listView.setFastScrollEnabled(true);
      listView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
      listView.setAdapter(listViewAdapter);
      if (Build.VERSION.SDK_INT >= 11) {
        listView.setFastScrollAlwaysVisible(true);
        listView.setVerticalScrollbarPosition(
            LocaleController.isRTL
                ? ListView.SCROLLBAR_POSITION_LEFT
                : ListView.SCROLLBAR_POSITION_RIGHT);
      }
      linearLayout.addView(listView);
      layoutParams = (LinearLayout.LayoutParams) listView.getLayoutParams();
      layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
      layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
      listView.setLayoutParams(layoutParams);
      listView.setOnItemClickListener(
          new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
              TLRPC.User user = null;
              if (searching && searchWas) {
                user = searchListViewAdapter.getItem(i);
              } else {
                int section = listViewAdapter.getSectionForPosition(i);
                int row = listViewAdapter.getPositionInSectionForPosition(i);
                if (row < 0 || section < 0) {
                  return;
                }
                user = (TLRPC.User) listViewAdapter.getItem(section, row);
              }
              if (user == null) {
                return;
              }

              boolean check = true;
              if (selectedContacts.containsKey(user.id)) {
                check = false;
                try {
                  XImageSpan span = selectedContacts.get(user.id);
                  selectedContacts.remove(user.id);
                  SpannableStringBuilder text =
                      new SpannableStringBuilder(userSelectEditText.getText());
                  text.delete(text.getSpanStart(span), text.getSpanEnd(span));
                  allSpans.remove(span);
                  ignoreChange = true;
                  userSelectEditText.setText(text);
                  userSelectEditText.setSelection(text.length());
                  ignoreChange = false;
                } catch (Exception e) {
                  FileLog.e("tmessages", e);
                }
              } else {
                if (selectedContacts.size() == maxCount) {
                  return;
                }
                ignoreChange = true;
                XImageSpan span = createAndPutChipForUser(user);
                span.uid = user.id;
                ignoreChange = false;
              }
              if (!isAlwaysShare && !isNeverShare) {
                actionBar.setSubtitle(
                    LocaleController.formatString(
                        "MembersCount", R.string.MembersCount, selectedContacts.size(), maxCount));
              }
              if (searching || searchWas) {
                ignoreChange = true;
                SpannableStringBuilder ssb = new SpannableStringBuilder("");
                for (ImageSpan sp : allSpans) {
                  ssb.append("<<");
                  ssb.setSpan(
                      sp,
                      ssb.length() - 2,
                      ssb.length(),
                      SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
                userSelectEditText.setText(ssb);
                userSelectEditText.setSelection(ssb.length());
                ignoreChange = false;

                searchListViewAdapter.searchDialogs(null);
                searching = false;
                searchWas = false;
                listView.setAdapter(listViewAdapter);
                listViewAdapter.notifyDataSetChanged();
                if (android.os.Build.VERSION.SDK_INT >= 11) {
                  listView.setFastScrollAlwaysVisible(true);
                }
                listView.setFastScrollEnabled(true);
                listView.setVerticalScrollBarEnabled(false);
                emptyTextView.setText(
                    LocaleController.getString("NoContacts", R.string.NoContacts));
              } else {
                if (view instanceof UserCell) {
                  ((UserCell) view).setChecked(check, true);
                }
              }
            }
          });
      listView.setOnScrollListener(
          new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView absListView, int i) {
              if (i == SCROLL_STATE_TOUCH_SCROLL) {
                AndroidUtilities.hideKeyboard(userSelectEditText);
              }
              if (listViewAdapter != null) {
                listViewAdapter.setIsScrolling(i != SCROLL_STATE_IDLE);
              }
            }

            @Override
            public void onScroll(
                AbsListView absListView,
                int firstVisibleItem,
                int visibleItemCount,
                int totalItemCount) {
              if (absListView.isFastScrollEnabled()) {
                AndroidUtilities.clearDrawableAnimation(absListView);
              }
            }
          });
    } else {
      ViewGroup parent = (ViewGroup) fragmentView.getParent();
      if (parent != null) {
        parent.removeView(fragmentView);
      }
    }
    return fragmentView;
  }
Exemplo n.º 17
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);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    settings = ((OsmandApplication) getApplication()).getSettings();
    setContentView(R.layout.search_by_name);

    initializeTask = getInitializeTask();
    uiHandler = new UIUpdateHandler();
    namesFilter = new NamesFilter();
    addFooterViews();
    final NamesAdapter namesAdapter =
        new NamesAdapter(new ArrayList<T>(), createComparator()); // $NON-NLS-1$
    setListAdapter(namesAdapter);

    collator = OsmAndCollator.primaryCollator();

    progress = (ProgressBar) findViewById(R.id.ProgressBar);

    searchText = (EditText) findViewById(R.id.SearchText);
    searchText.addTextChangedListener(
        new TextWatcher() {

          @Override
          public void afterTextChanged(Editable s) {
            String newFilter = s.toString();
            String newEndingText = endingText;
            if (newEndingText.length() > 0) {
              while (!newFilter.endsWith(newEndingText) && newEndingText.length() > 0) {
                newEndingText = newEndingText.substring(1);
              }
              newFilter = newFilter.substring(0, newFilter.length() - newEndingText.length());
            }
            updateTextBox(newFilter, newEndingText, endingObject, false);
            querySearch(newFilter);
          }

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

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {}
        });
    // Not perfect
    //		filter.setOnClickListener(new OnClickListener() {
    //			}
    //		});
    searchText.setImeOptions(EditorInfo.IME_ACTION_DONE);
    searchText.requestFocus();
    searchText.setOnEditorActionListener(
        new OnEditorActionListener() {
          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER))
                || (actionId == EditorInfo.IME_ACTION_DONE)) {
              if (endingObject != null) {
                itemSelectedBase(endingObject, v);
              }
              return true;
            }
            return false;
          }
        });

    progress.setVisibility(View.INVISIBLE);
    findViewById(R.id.ResetButton)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                reset();
              }
            });
    selectAddress = getIntent() != null && getIntent().hasExtra(SELECT_ADDRESS);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    if (initializeTask != null) {
      initializeTask.execute();
    }
  }
Exemplo n.º 19
0
 public void setImeOptions(int imeOptions) {
   dataEdit.setImeOptions(imeOptions | EditorInfo.IME_FLAG_FORCE_ASCII);
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    getWindow().setBackgroundDrawable(new ColorDrawable(0x80000000));

    LinearLayout layout = new LinearLayout(mParentActivity);
    layout.setOrientation(LinearLayout.VERTICAL);

    LinearLayout.LayoutParams layoutParams =
        new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);

    mTextViewTitle = new TextView(mParentActivity);
    LinearLayout.LayoutParams textviewParams =
        new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    textviewParams.leftMargin = textviewParams.rightMargin = convertDipsToPixels(10);
    mTextViewTitle.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    layout.addView(mTextViewTitle, textviewParams);

    mInputEditText = new EditText(mParentActivity);
    LinearLayout.LayoutParams editTextParams =
        new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    editTextParams.leftMargin = editTextParams.rightMargin = convertDipsToPixels(10);

    layout.addView(mInputEditText, editTextParams);

    setContentView(layout, layoutParams);

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

    mInputMode = mMsg.inputMode;
    mInputFlag = mMsg.inputFlag;
    mReturnType = mMsg.returnType;
    mMaxLength = mMsg.maxLength;

    mTextViewTitle.setText(mMsg.title);
    mInputEditText.setText(mMsg.content);

    int oldImeOptions = mInputEditText.getImeOptions();
    mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    oldImeOptions = mInputEditText.getImeOptions();

    switch (mInputMode) {
      case kEditBoxInputModeAny:
        mInputModeContraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE;
        break;
      case kEditBoxInputModeEmailAddr:
        mInputModeContraints =
            InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
        break;
      case kEditBoxInputModeNumeric:
        mInputModeContraints = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED;
        break;
      case kEditBoxInputModePhoneNumber:
        mInputModeContraints = InputType.TYPE_CLASS_PHONE;
        break;
      case kEditBoxInputModeUrl:
        mInputModeContraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI;
        break;
      case kEditBoxInputModeDecimal:
        mInputModeContraints =
            InputType.TYPE_CLASS_NUMBER
                | InputType.TYPE_NUMBER_FLAG_DECIMAL
                | InputType.TYPE_NUMBER_FLAG_SIGNED;
        break;
      case kEditBoxInputModeSingleLine:
        mInputModeContraints = InputType.TYPE_CLASS_TEXT;
        break;
      default:
        break;
    }

    if (mIsMultiline) {
      mInputModeContraints |= InputType.TYPE_TEXT_FLAG_MULTI_LINE;
    }

    mInputEditText.setInputType(mInputModeContraints | mInputFlagConstraints);

    switch (mInputFlag) {
      case kEditBoxInputFlagPassword:
        mInputFlagConstraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD;
        break;
      case kEditBoxInputFlagSensitive:
        mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
        break;
      case kEditBoxInputFlagInitialCapsWord:
        mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_WORDS;
        break;
      case kEditBoxInputFlagInitialCapsSentence:
        mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
        break;
      case kEditBoxInputFlagInitialCapsAllCharacters:
        mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS;
        break;
      default:
        break;
    }
    mInputEditText.setInputType(mInputFlagConstraints | mInputModeContraints);

    switch (mReturnType) {
      case kKeyboardReturnTypeDefault:
        mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_NONE);
        break;
      case kKeyboardReturnTypeDone:
        mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_DONE);
        break;
      case kKeyboardReturnTypeSend:
        mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_SEND);
        break;
      case kKeyboardReturnTypeSearch:
        mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_SEARCH);
        break;
      case kKeyboardReturnTypeGo:
        mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_GO);
        break;
      default:
        mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_NONE);
        break;
    }

    if (mMaxLength > 0) {
      mInputEditText.setFilters(new InputFilter[] {new InputFilter.LengthFilter(mMaxLength)});
    }

    Handler initHandler = new Handler();
    initHandler.postDelayed(
        new Runnable() {
          public void run() {
            mInputEditText.requestFocus();
            mInputEditText.setSelection(mInputEditText.length());
            openKeyboard();
          }
        },
        200);

    mInputEditText.setOnEditorActionListener(
        new OnEditorActionListener() {
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            // if user didn't set keyboard type,
            // this callback will be invoked twice with 'KeyEvent.ACTION_DOWN' and
            // 'KeyEvent.ACTION_UP'
            if (actionId != EditorInfo.IME_NULL
                || (actionId == EditorInfo.IME_NULL
                    && event != null
                    && event.getAction() == KeyEvent.ACTION_DOWN)) {
              // Log.d("EditBox", "actionId: "+actionId +",event: "+event);
              mParentActivity.setEditBoxResult(mInputEditText.getText().toString());
              closeKeyboard();
              dismiss();
              return true;
            }
            return false;
          }
        });
  }
Exemplo n.º 21
0
  public ActionBarMenuItem setIsSearchField(boolean value) {
    if (value && searchField == null) {
      searchField = new EditText(getContext());
      searchField.setTextSize(18);
      searchField.setTextColor(0xffffffff);
      searchField.setSingleLine(true);
      searchField.setBackgroundResource(R.drawable.search_light_states);
      searchField.setPadding(0, 0, 0, 0);
      searchField.setInputType(EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
      if (android.os.Build.VERSION.SDK_INT < 11) {
        searchField.setOnCreateContextMenuListener(
            new OnCreateContextMenuListener() {
              public void onCreateContextMenu(
                  ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
                menu.clear();
              }
            });
      } else {
        searchField.setCustomSelectionActionModeCallback(
            new ActionMode.Callback() {
              public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                return false;
              }

              public void onDestroyActionMode(ActionMode mode) {}

              public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                return false;
              }

              public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                return false;
              }
            });
      }
      searchField.setOnEditorActionListener(
          new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
              if (actionId == EditorInfo.IME_ACTION_SEARCH
                  || event != null
                      && event.getAction() == KeyEvent.ACTION_UP
                      && event.getKeyCode() == KeyEvent.KEYCODE_SEARCH) {
                AndroidUtilities.hideKeyboard(searchField);
              }
              return false;
            }
          });
      searchField.addTextChangedListener(
          new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
              if (listener != null) {
                listener.onTextChanged(searchField);
              }
            }

            @Override
            public void afterTextChanged(Editable s) {}
          });

      /*
          ImageView img = (ImageView) searchView.findViewById(R.id.search_close_btn);
      if (img != null) {
          img.setImageResource(R.drawable.ic_msg_btn_cross_custom);
      }
           */
      try {
        Field mCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes");
        mCursorDrawableRes.setAccessible(true);
        mCursorDrawableRes.set(searchField, R.drawable.search_carret);
      } catch (Exception e) {
        // nothing to do
      }
      if (Build.VERSION.SDK_INT >= 11) {
        searchField.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN | EditorInfo.IME_ACTION_SEARCH);
        searchField.setTextIsSelectable(false);
      } else {
        searchField.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
      }
      parentMenu.addView(searchField, 0);
      LinearLayout.LayoutParams layoutParams =
          (LinearLayout.LayoutParams) searchField.getLayoutParams();
      layoutParams.weight = 1;
      layoutParams.width = 0;
      layoutParams.gravity = Gravity.CENTER_VERTICAL;
      layoutParams.height = AndroidUtilities.dp(36);
      layoutParams.rightMargin = AndroidUtilities.dp(22);
      layoutParams.leftMargin = AndroidUtilities.dp(6);
      searchField.setLayoutParams(layoutParams);
      searchField.setVisibility(GONE);
    }
    isSearchField = value;
    return this;
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    isTraining = getIntent().getBooleanExtra("Training", true);
    setContentView(R.layout.face_detect_surface_view);

    screenWidth = MainPageActivity.getScreenHeight();
    screenHeight = MainPageActivity.getScreenWidth();

    mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.fd_activity_surface_view);
    mOpenCvCameraView.setCvCameraViewListener(this);

    captureButton = (ImageView) findViewById(R.id.capturebutton);
    captureText = (TextView) findViewById(R.id.capturetext);
    captureButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            closeSoftInput();
            if (capturingImage) {
              captureText.setText("Start Capturing");
              capturingImage = false;
              captureButton.setImageResource(R.drawable.capturestart);
            } else {
              captureText.setText("Stop Capturing");
              captureButton.setImageResource(R.drawable.capturestop);
              capturingImage = true;
            }
          }
        });

    backButton = (ImageView) findViewById(R.id.backbutton);
    backButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            goBack();
          }
        });

    saveButton = (Button) findViewById(R.id.addtodbbutton);
    saveButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            closeSoftInput();
            if (isTraining) {
              insertToDatabase();
            } else {
              // deleteFromDatabase();
              updateThisPerson();
            }
          }
        });

    nameEdit = (EditText) findViewById(R.id.nameedit);
    nameEdit.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);

    deleteButton = (Button) findViewById(R.id.deletefromdbbutton);
    resetImagesForTraining();
    initOtherViews();
    if (!isTraining) {
      final int personIndex = getIntent().getIntExtra("personIndex", -1);
      new Thread(
              new Runnable() {

                @Override
                public void run() {
                  FaceDetectionUtils.faceDataSource.open();
                  persons = FaceDetectionUtils.faceDataSource.getAllPersons();
                  FaceDetectionUtils.faceDataSource.close();
                  thisPerson = persons.get(personIndex);
                  setImagesForDatabaseEdit();
                  FaceDetectionActivity.this.runOnUiThread(
                      new Runnable() {

                        @Override
                        public void run() {
                          nameEdit.setText(thisPerson.getName());
                          saveButton.setText("Update this person");
                        }
                      });
                }
              })
          .start();
      deleteButton.setVisibility(View.VISIBLE);
      deleteButton.setOnClickListener(
          new OnClickListener() {

            @Override
            public void onClick(View v) {
              closeSoftInput();
              deleteFromDatabase();
            }
          });
    }
    mOpenCvCameraView.enableView();
    bgLayout = (LinearLayout) findViewById(R.id.face_detect_layout);
    bgLayout.setOnTouchListener(
        new View.OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            closeSoftInput();
            return false;
          }
        });
  }
Exemplo n.º 23
0
  /**
   * Called when the activity is starting inflating the activity's UI. This is where most
   * initialization should go.
   */
  @Override
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    LOADING_MAP = getString(R.string.newmap_loading_map);
    UPLOADING_MAP = getString(R.string.newmap_uploading_map);
    FETCH_PROBLEM = getString(R.string.newmap_loading_problem);
    UPLOAD_PROBLEM = getString(R.string.newmap_uploading_problem);
    EMPTY_URL = getString(R.string.newmap_empty_url);
    EMPTY_MAP_NAME = getString(R.string.newmap_empty_map_name);

    setContentView(R.layout.newmap_view);
    inputUrl = (EditText) findViewById(R.id.map_url);
    inputUrl.setImeOptions(EditorInfo.IME_ACTION_GO);
    inputUrl.setOnEditorActionListener(
        new OnEditorActionListener() {

          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_GO) {
              String urlString = v.getText().toString();
              if (urlString == null || urlString.trim().length() == 0) {
                showAlert(EMPTY_URL);
                return false;
              }

              showDialog(ID_DIALOG_LOADING);
              DownloadImageTask task = new DownloadImageTask(NewMapActivity.this);
              task.execute(urlString);
            }

            return false;
          }
        });

    inputMapName = (EditText) findViewById(R.id.map_name);
    inputMapName.setImeOptions(EditorInfo.IME_ACTION_DONE);
    inputMapName.setOnFocusChangeListener(
        new OnFocusChangeListener() {
          @Override
          public void onFocusChange(View v, boolean hasFocus) {
            checkEnableSave();
          }
        });

    inputMapName.setOnEditorActionListener(
        new OnEditorActionListener() {

          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
              String mapName = v.getText().toString();
              if (mapName == null || mapName.trim().length() == 0) {
                showAlert(EMPTY_MAP_NAME);
                return false;
              }

              checkEnableSave();
            }

            return false;
          }
        });
    setSave(false);
    Button urlChoiceButton = (Button) findViewById(R.id.pick_image_url_button);
    urlChoiceButton.setOnClickListener(enableURLChoice);
    Button phoneChoiceButton = (Button) findViewById(R.id.pick_image_phone_button);
    phoneChoiceButton.setOnClickListener(enablePhoneChoice);
    Button saveButton = (Button) findViewById(R.id.save_map_button);
    saveButton.setOnClickListener(saveMap);
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitle(R.string.ll_title);
    setContentView(R.layout.lightlevels);

    mSensorRange =
        (int)
            ((SensorManager) getSystemService(SENSOR_SERVICE))
                .getDefaultSensor(Sensor.TYPE_LIGHT)
                .getMaximumRange();
    mHandler = new Handler();
    mSave = (Button) findViewById(R.id.btn_save);
    mSave.setOnClickListener(this);
    mDefaults = (Button) findViewById(R.id.btn_default);
    mDefaults.setOnClickListener(this);
    mReload = (Button) findViewById(R.id.btn_reload);
    mReload.setOnClickListener(this);
    mSensor = (TextView) findViewById(R.id.ll_tw_lux_value);
    mScreen = (TextView) findViewById(R.id.ll_tw_lcd_value);
    mButtons = (TextView) findViewById(R.id.ll_tw_btn_value);
    mKeyboard = (TextView) findViewById(R.id.ll_tw_kb_value);
    mNumLevels = (Button) findViewById(R.id.btn_num_levels);
    mNumLevels.setOnClickListener(this);

    if (getResources().getConfiguration().keyboard == Configuration.KEYBOARD_NOKEYS) {
      ((TableLayout) findViewById(R.id.ll_table_info)).removeView(findViewById(R.id.table_row_kb));
      ((TableRow) findViewById(R.id.ll_table_row_headers))
          .removeView(findViewById(R.id.ll_tw_header_kb));
      mHasKeyboard = false;
    } else {
      mHasKeyboard = true;
    }

    mEditor = new EditText(this);
    mEditor.setInputType(InputType.TYPE_CLASS_NUMBER);
    mEditor.setImeOptions(EditorInfo.IME_ACTION_NONE);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder
        .setPositiveButton(
            getString(android.R.string.ok),
            new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int id) {
                dialogOk();
              }
            })
        .setNegativeButton(
            android.R.string.cancel,
            new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
              }
            })
        .setView(mEditor);
    mDialog = builder.create();
    mDialog.setOwnerActivity(this);
    mDialog
        .getWindow()
        .setSoftInputMode(
            WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE
                | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

    loadData(false);
    mHasChanges = false;
    updateButtons();
  }
Exemplo n.º 25
0
 public void handleReturnKeyType(int type) {
   switch (type) {
     case RETURNKEY_GO:
       tv.setImeOptions(EditorInfo.IME_ACTION_GO);
       break;
     case RETURNKEY_GOOGLE:
       tv.setImeOptions(EditorInfo.IME_ACTION_GO);
       break;
     case RETURNKEY_JOIN:
       tv.setImeOptions(EditorInfo.IME_ACTION_DONE);
       break;
     case RETURNKEY_NEXT:
       tv.setImeOptions(EditorInfo.IME_ACTION_NEXT);
       break;
     case RETURNKEY_ROUTE:
       tv.setImeOptions(EditorInfo.IME_ACTION_DONE);
       break;
     case RETURNKEY_SEARCH:
       tv.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
       break;
     case RETURNKEY_YAHOO:
       tv.setImeOptions(EditorInfo.IME_ACTION_GO);
       break;
     case RETURNKEY_DONE:
       tv.setImeOptions(EditorInfo.IME_ACTION_DONE);
       break;
     case RETURNKEY_EMERGENCY_CALL:
       tv.setImeOptions(EditorInfo.IME_ACTION_GO);
       break;
     case RETURNKEY_DEFAULT:
       tv.setImeOptions(EditorInfo.IME_ACTION_UNSPECIFIED);
       break;
     case RETURNKEY_SEND:
       tv.setImeOptions(EditorInfo.IME_ACTION_SEND);
       break;
   }
 }
Exemplo n.º 26
0
  @SuppressWarnings("deprecation")
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (isP(_P.secrecy) && !ENC) {
      setTitle("Initializing " + Main.name + "...");
      return;
    }

    Intent caller = getIntent();
    if (caller != null) {
      try {
        String tmp = caller.getStringExtra(_I.Main_setAbsoluteFolder.name());
        if (tmp == null) {
          finish();
          return;
        }
        setAbsoluteFolder(tmp);

        tmp = caller.getStringExtra(_I.Main_setFolderShowname.name());
        if (tmp == null) {
          finish();
          return;
        }
        setFolderShowname(tmp);
      } catch (Exception e) {
        e.printStackTrace();
        return;
      }
    }

    WatchImpl.enable = false;

    l1 = new RelativeLayout(this);

    int xi = 0;
    while (true) {
      if (!checkFiles(xi)) break;
      xi++;
    }
    if (xi > max) max = xi;

    thetexts = new Vector<InnerEdit>(max + 5);

    ScrollView sv = new ScrollView(this);
    l1.addView(sv);

    RelativeLayout.LayoutParams sv_lp = (RelativeLayout.LayoutParams) sv.getLayoutParams();
    sv_lp.width = RelativeLayout.LayoutParams.MATCH_PARENT;
    sv_lp.height = RelativeLayout.LayoutParams.WRAP_CONTENT;
    sv_lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    sv.setLayoutParams(sv_lp);

    l2 = new LinearLayout(this);
    l2.setOrientation(LinearLayout.VERTICAL);
    l2.setLayoutParams(
        new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    sv.addView(l2);

    ArrayList<String> vals = null;
    ArrayList<Integer> ids = null;
    int newone = -1;
    int focusone = -1;

    if (caller != null) {
      if (caller.getBooleanExtra("OKAY", false)) {
        vals = caller.getStringArrayListExtra("vals");
        ids = caller.getIntegerArrayListExtra("ids");
        newone = caller.getIntExtra("newone", -1);
        focusone = caller.getIntExtra("curfocus", -1);
      }
    }

    if (newone > 0) max = newone + 1;

    setTitle(title(max));

    for (int i = 0; i < max; i++) {
      EditText t2 = new EditText(this);
      t2.setId(i);
      t2.setOnFocusChangeListener(
          new OnFocusChangeListener() {

            @Override
            public void onFocusChange(View v, boolean hasFocus) {
              if (hasFocus) curfocus = (EditText) v;
            }
          });
      t2.setImeOptions(EditorInfo.IME_ACTION_DONE);
      t2.setOnEditorActionListener(one);
      InnerEdit in = new InnerEdit(t2);
      thetexts.add(in);
      t2.addTextChangedListener(new WatchImpl(in));
      l2.addView(t2, 0);
      if (ids != null && ids.contains(i)) {
        String tmp = vals.get(ids.indexOf(i));
        if (tmp != null) t2.setText(tmp);
        else t2.setText("err");
        in.changed = true;
      } else {
        if (checkFiles(i)) {
          String x = loadFiles(i);
          t2.setText(x);
        } else {
          t2.setText("");
        }
      }

      if (focusone >= 0) {
        if (i == focusone) t2.requestFocus();
      } else {
        if (i == max - 1) t2.requestFocus();
      }
    }

    WatchImpl.enable = true;

    Button b1 = new Button(this);
    b1.setText("  Save  ");

    b1.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            int ctr = 0;
            for (int i = 0; i < max; i++) {
              if (thetexts.get(i).changed || !checkFiles(i)) {
                storeFiles(i, thetexts.get(i).edit.getText().toString());
                ctr++;
                thetexts.get(i).changed = false;
              }
            }
            Toast.makeText(me, "Saved (" + ctr + ")", Toast.LENGTH_SHORT).show();
          }
        });

    Button b2 = new Button(this);
    b2.setText("  Add  ");

    b2.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            EditText t2 = new EditText(me);
            t2.setOnFocusChangeListener(
                new OnFocusChangeListener() {

                  @Override
                  public void onFocusChange(View v, boolean hasFocus) {
                    if (hasFocus) curfocus = (EditText) v;
                  }
                });
            t2.setImeOptions(EditorInfo.IME_ACTION_DONE);
            t2.setOnEditorActionListener(one);

            l2.addView(t2, 0);
            t2.setId(max);
            max++;
            InnerEdit in = new InnerEdit(t2, true);
            thetexts.add(in);
            t2.addTextChangedListener(new WatchImpl(in));
            setTitle(title(max));
            t2.requestFocus();
          }
        });

    Button b3 = new Button(this);
    b3.setText("Save & Exit");
    b3.setOnClickListener(
        new OnClickListener() {
          // TODO: reduce redundancy

          @Override
          public void onClick(View v) {
            int ctr = 0;
            for (int i = 0; i < max; i++) {
              if (thetexts.get(i).changed || !checkFiles(i)) {
                storeFiles(i, thetexts.get(i).edit.getText().toString());
                ctr++;
                thetexts.get(i).changed = false;
              }
            }
            if (ctr > 0) Toast.makeText(me, "Saved (" + ctr + ")", Toast.LENGTH_SHORT).show();
            else Toast.makeText(me, "Quick Exit", Toast.LENGTH_SHORT).show();

            finish();
          }
        });

    Button b4 = new Button(this);
    b4.setText("Return");

    b4.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            for (int i = 0; i < max; i++) {
              if (thetexts.get(i).changed || !checkFiles(i)) {
                Toast.makeText(me, "unsaved data", Toast.LENGTH_SHORT).show();
                return;
              }
            }

            startActivity(new Intent(me, Startup.class));
            finish();
          }
        });

    HorizontalScrollView hori = new HorizontalScrollView(this);
    LinearLayout ll_hori = new LinearLayout(this);
    ll_hori.setOrientation(LinearLayout.HORIZONTAL);

    ll_hori.addView(b1);
    ll_hori.addView(b3);
    ll_hori.addView(b2);
    ll_hori.addView(b4);

    hori.addView(ll_hori);
    l1.addView(hori);
    RelativeLayout.LayoutParams lp =
        new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    hori.setLayoutParams(lp);
    hori.setId(121232);

    sv_lp = (RelativeLayout.LayoutParams) sv.getLayoutParams();
    sv_lp.addRule(RelativeLayout.ABOVE, hori.getId());
    sv.setLayoutParams(sv_lp);

    BitmapDrawable bd =
        new BitmapDrawable(
            getResources(), BitmapFactory.decodeResource(getResources(), R.drawable.back_base));
    bd.setTileModeXY(TileMode.MIRROR, TileMode.REPEAT);
    l1.setBackgroundDrawable(bd);

    setContentView(l1);
  }
Exemplo n.º 27
0
  public static ScrollView generateTeamLayout(Context context, boolean pit) {
    RelativeLayout layout = new RelativeLayout(context);
    ScrollView scrollView = new ScrollView(context);
    BufferedReader reader =
        new BufferedReader(
            new InputStreamReader(
                context
                    .getResources()
                    .openRawResource(pit ? R.raw.team_config_pit : R.raw.team_config_match)));
    try {
      String line = reader.readLine(); // The version
      Log.d(
          MainActivity.APP_TAG,
          "Loaded " + (pit ? "pit" : "match") + " config file version " + line);
      if (pit) configVersionPit = line;
      else configVersionMatch = line;
      int last = -1;
      while ((line = reader.readLine()) != null) {
        TextView header = null;
        View[] view;
        int idOffset = Integer.MAX_VALUE;
        String[] l;
        if (line.contains(":")) {
          l = line.split(":");
          RelativeLayout.LayoutParams params =
              new RelativeLayout.LayoutParams(
                  RelativeLayout.LayoutParams.WRAP_CONTENT,
                  RelativeLayout.LayoutParams.WRAP_CONTENT);
          header = new TextView(context);
          header.setText(l[1].substring(2));
          header.setTextSize(20f);
          header.setId(idOffset - View.generateViewId());
          if (last != -1) {
            if (l[1].charAt(1) == '0') params.addRule(RelativeLayout.BELOW, last);
            else {
              params.addRule(RelativeLayout.RIGHT_OF, last);
              params.addRule(RelativeLayout.ALIGN_TOP, last);
            }
          }
          header.setPadding(
              header.getPaddingLeft(),
              header.getPaddingTop(),
              header.getPaddingRight() + 20,
              header.getPaddingBottom());
          header.setLayoutParams(params);
          boolean below = false;

          switch (Integer.parseInt(l[1].charAt(0) + "")) {
            case 0: // Checkbox
              view = new View[] {new CheckBox(context)};
              break;
            case 1: // Spinner
              Spinner spinner = new Spinner(context);
              ArrayList<String> l1 = new ArrayList<>();
              l1.add("None");
              l1.addAll(Arrays.asList(l[2].split(",")));
              spinner.setAdapter(
                  new ArrayAdapter<>(context, android.R.layout.simple_spinner_dropdown_item, l1));
              view = new View[] {spinner};
              break;
            case 2:
              { // Number
                EditText editText = new EditText(context);
                editText.setInputType(InputType.TYPE_CLASS_NUMBER);
                editText.setSingleLine();
                editText.setImeOptions(0x00000005); // Next
                view = new View[] {editText};
                break;
              }
            case 3:
              { // Text
                EditText editText = new EditText(context);
                editText.setSingleLine();
                editText.setImeOptions(0x00000005); // Next
                view = new View[] {editText};
                break;
              }
            case 4: // Text for Teams
              AutoCompleteTextView autoCompleteTextView = new AutoCompleteTextView(context);
              autoCompleteTextView.setAdapter(
                  new ArrayAdapter<>(
                      context, android.R.layout.simple_dropdown_item_1line, MainActivity.teamList));
              autoCompleteTextView.setSingleLine();
              autoCompleteTextView.setImeOptions(0x00000005); // Next
              view = new View[] {autoCompleteTextView};
              break;
            case 5:
              { // Multiline field
                EditText editText = new EditText(context);
                editText.setSingleLine(false);
                view = new View[] {editText};
                below = true;
                break;
              }
            case 6:
              { // Number Entry with Plus
                final EditText editText = new EditText(context);
                ImageButton button = new ImageButton(context);
                button.setImageResource(R.drawable.ic_action_new);
                button.setOnClickListener(
                    new View.OnClickListener() {
                      @Override
                      public void onClick(View v) {
                        if (editText.getText().toString().equals("")) editText.setText("1");
                        else
                          editText.setText(
                              "" + (Integer.parseInt(editText.getText().toString()) + 1));
                      }
                    });
                editText.setInputType(InputType.TYPE_CLASS_NUMBER);
                editText.setSingleLine();
                editText.setImeOptions(0x00000005); // Next
                view = new View[] {editText, button};
                break;
              }
            default:
              Log.e(
                  MainActivity.APP_TAG,
                  "Invalid file format for team config, error at line: " + line);
              return null;
          }

          if (view.length == 1) {
            RelativeLayout.LayoutParams params1 =
                new RelativeLayout.LayoutParams(
                    RelativeLayout.LayoutParams.WRAP_CONTENT,
                    RelativeLayout.LayoutParams.WRAP_CONTENT);
            if (below) params1.addRule(RelativeLayout.BELOW, header.getId());
            else {
              params1.addRule(RelativeLayout.ALIGN_TOP, header.getId());
              params1.addRule(RelativeLayout.RIGHT_OF, header.getId());
            }
            view[0].setId(Integer.parseInt(l[0]));
            view[0].setLayoutParams(params1);
          } else {
            for (int i = 0; i < view.length; i++) {
              RelativeLayout.LayoutParams params1 =
                  new RelativeLayout.LayoutParams(
                      RelativeLayout.LayoutParams.WRAP_CONTENT,
                      RelativeLayout.LayoutParams.WRAP_CONTENT);
              if (i == 0) {
                if (below) params1.addRule(RelativeLayout.BELOW, header.getId());
                else {
                  params1.addRule(RelativeLayout.ALIGN_TOP, header.getId());
                  params1.addRule(RelativeLayout.RIGHT_OF, header.getId());
                }
                view[0].setId(Integer.parseInt(l[0]));
                view[0].setLayoutParams(params1);
                continue;
              }
              params1.addRule(RelativeLayout.ALIGN_TOP, view[i - 1].getId());
              params1.addRule(RelativeLayout.RIGHT_OF, view[i - 1].getId());

              view[i].setId(Integer.parseInt(l[0]) + i);
              view[i].setLayoutParams(params1);
            }
          }
        } else {
          RelativeLayout.LayoutParams params =
              new RelativeLayout.LayoutParams(
                  RelativeLayout.LayoutParams.WRAP_CONTENT,
                  RelativeLayout.LayoutParams.WRAP_CONTENT);
          TextView v = new TextView(context);
          v.setText(line);
          v.setTextSize(30f);
          v.setId(idOffset - View.generateViewId());
          if (last != -1) params.addRule(RelativeLayout.BELOW, last);
          v.setLayoutParams(params);
          view = new View[] {v};
        }

        if (header != null) layout.addView(header);
        for (View v : view) layout.addView(v);
        last = view[view.length - 1].getId();
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
    scrollView.addView(layout);
    return scrollView;
  }
Exemplo n.º 28
0
  @Override
  public View createView(Context context, LayoutInflater inflater) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("EditName", R.string.EditName));
    actionBar.setActionBarMenuOnItemClick(
        new ActionBar.ActionBarMenuOnItemClick() {
          @Override
          public void onItemClick(int id) {
            if (id == -1) {
              finishFragment();
            } else if (id == done_button) {
              if (firstNameField.getText().length() != 0) {
                saveName();
                finishFragment();
              }
            }
          }
        });

    ActionBarMenu menu = actionBar.createMenu();
    doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));

    TLRPC.User user = MessagesController.getInstance().getUser(UserConfig.getClientUserId());
    if (user == null) {
      user = UserConfig.getCurrentUser();
    }

    fragmentView = new LinearLayout(context);
    fragmentView.setLayoutParams(
        new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    ((LinearLayout) fragmentView).setOrientation(LinearLayout.VERTICAL);
    fragmentView.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            return true;
          }
        });

    firstNameField = new EditText(context);
    firstNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    firstNameField.setHintTextColor(0xff979797);
    firstNameField.setTextColor(0xff212121);
    firstNameField.setMaxLines(1);
    firstNameField.setLines(1);
    firstNameField.setSingleLine(true);
    firstNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
    firstNameField.setInputType(
        InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    firstNameField.setImeOptions(EditorInfo.IME_ACTION_NEXT);
    firstNameField.setHint(LocaleController.getString("FirstName", R.string.FirstName));
    AndroidUtilities.clearCursorDrawable(firstNameField);
    ((LinearLayout) fragmentView).addView(firstNameField);
    LinearLayout.LayoutParams layoutParams =
        (LinearLayout.LayoutParams) firstNameField.getLayoutParams();
    layoutParams.topMargin = AndroidUtilities.dp(24);
    layoutParams.height = AndroidUtilities.dp(36);
    layoutParams.leftMargin = AndroidUtilities.dp(24);
    layoutParams.rightMargin = AndroidUtilities.dp(24);
    layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
    firstNameField.setLayoutParams(layoutParams);
    firstNameField.setOnEditorActionListener(
        new TextView.OnEditorActionListener() {
          @Override
          public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_NEXT) {
              lastNameField.requestFocus();
              lastNameField.setSelection(lastNameField.length());
              return true;
            }
            return false;
          }
        });

    lastNameField = new EditText(context);
    lastNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    lastNameField.setHintTextColor(0xff979797);
    lastNameField.setTextColor(0xff212121);
    lastNameField.setMaxLines(1);
    lastNameField.setLines(1);
    lastNameField.setSingleLine(true);
    lastNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
    lastNameField.setInputType(
        InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    lastNameField.setImeOptions(EditorInfo.IME_ACTION_DONE);
    lastNameField.setHint(LocaleController.getString("LastName", R.string.LastName));
    AndroidUtilities.clearCursorDrawable(lastNameField);
    ((LinearLayout) fragmentView).addView(lastNameField);
    layoutParams = (LinearLayout.LayoutParams) lastNameField.getLayoutParams();
    layoutParams.topMargin = AndroidUtilities.dp(16);
    layoutParams.height = AndroidUtilities.dp(36);
    layoutParams.leftMargin = AndroidUtilities.dp(24);
    layoutParams.rightMargin = AndroidUtilities.dp(24);
    layoutParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
    lastNameField.setLayoutParams(layoutParams);
    lastNameField.setOnEditorActionListener(
        new TextView.OnEditorActionListener() {
          @Override
          public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_DONE) {
              doneButton.performClick();
              return true;
            }
            return false;
          }
        });

    if (user != null) {
      firstNameField.setText(user.first_name);
      firstNameField.setSelection(firstNameField.length());
      lastNameField.setText(user.last_name);
    }

    return fragmentView;
  }