Java Code Examples for android.widget.EditText#setGravity()

The following examples show how to use android.widget.EditText#setGravity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EditTextSettingsCell.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public EditTextSettingsCell(Context context) {
    super(context);

    textView = new EditText(context);
    textView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    textView.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    textView.setLines(1);
    textView.setMaxLines(1);
    textView.setSingleLine(true);
    textView.setEllipsize(TextUtils.TruncateAt.END);
    textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
    textView.setBackgroundDrawable(null);
    textView.setPadding(0, 0, 0, 0);
    textView.setInputType(textView.getInputType() |EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES);
    addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 17, 0, 17, 0));
}
 
Example 2
Source File: MiscTweaksActivity.java    From Kernel-Tuner with GNU General Public License v3.0 6 votes vote down vote up
private void showSetReadAheadDialog(Misc misc)
{
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    builder.setTitle(R.string.read_ahead_cache_size);

    final EditText input = new EditText(this);
    input.setText(misc.getValue().substring(0, misc.getValue().length() - 2));
    input.setSelectAllOnFocus(true);
    input.setInputType(InputType.TYPE_CLASS_NUMBER);
    input.setGravity(Gravity.CENTER_HORIZONTAL);
    input.requestFocus();

    builder.setPositiveButton(getResources().getString(R.string.set), new DialogInterface.OnClickListener()
    {
        @Override
        public void onClick(DialogInterface dialog, int which)
        {
            RCommand.setReadAhead(input.getText().toString(), MiscTweaksActivity.this);
        }
    });
    builder.setNegativeButton(getResources().getString(R.string.cancel), null);
    builder.setView(input);
    builder.show();
}
 
Example 3
Source File: PatientIdElement.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected View createView(Context c) {

    et = new EditText(c);
    et.setPadding(10, 5, 10, 5);
    et.setText(answer);
    et.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT));
    et.setGravity(Gravity.CENTER_HORIZONTAL);
    et.setKeyListener(new DialerKeyListener());

    LinearLayout ll = new LinearLayout(c);
    ll.setOrientation(LinearLayout.VERTICAL);

    ll.addView(et, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT));
    ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT));

    //SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(c);
    boolean barcodeEnable = true; //sp.getBoolean(Constants.PREFERENCE_BARCODE_ENABLED, false);

    if (barcodeEnable) {
        barcodeButton = new Button(c);
        barcodeButton.setText(c.getResources().getString(
                R.string.procedurerunner_scan_id));
        barcodeButton.setOnClickListener(this);
        barcodeButton.setGravity(Gravity.CENTER_HORIZONTAL);
        ll.addView(barcodeButton, new LinearLayout.LayoutParams(
                LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    }
    return encapsulateQuestion(c, ll);
}
 
Example 4
Source File: EditPage.java    From AndroidLinkup with GNU General Public License v2.0 5 votes vote down vote up
private LinearLayout getMainBody() {
	LinearLayout llMainBody = new LinearLayout(getContext());
	llMainBody.setOrientation(LinearLayout.VERTICAL);
	LinearLayout.LayoutParams lpMain = new LinearLayout.LayoutParams(
			LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
	lpMain.weight = 1;
	int dp_4 = dipToPx(getContext(), 4);
	lpMain.setMargins(dp_4, dp_4, dp_4, dp_4);
	llMainBody.setLayoutParams(lpMain);

	LinearLayout llContent = new LinearLayout(getContext());
	LinearLayout.LayoutParams lpContent = new LinearLayout.LayoutParams(
			LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
	lpContent.weight = 1;
	llMainBody.addView(llContent, lpContent);

	// 文字输入区域
	etContent = new EditText(getContext());
	etContent.setGravity(Gravity.LEFT | Gravity.TOP);
	etContent.setBackgroundDrawable(null);
	etContent.setText(String.valueOf(reqData.get("text")));
	etContent.addTextChangedListener(this);
	LinearLayout.LayoutParams lpEt = new LinearLayout.LayoutParams(
			LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	lpEt.weight = 1;
	etContent.setLayoutParams(lpEt);
	llContent.addView(etContent);

	llContent.addView(getThumbView());
	llMainBody.addView(getBodyBottom());

	return llMainBody;
}
 
Example 5
Source File: ConfigureStandupTimer.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private View createMeetingLengthTextBox() {
    meetingLengthEditText = new EditText(this);
    meetingLengthEditText.setGravity(Gravity.CENTER);
    meetingLengthEditText.setKeyListener(new DigitsKeyListener());
    meetingLengthEditText.setRawInputType(InputType.TYPE_CLASS_PHONE);
    meetingLengthEditText.setLayoutParams(new LayoutParams(dipsToPixels(60), LayoutParams.WRAP_CONTENT));
    meetingLengthEditText.setText(Integer.toString(meetingLength));
    meetingLengthEditText.setLines(1);

    meetingLengthSpinner = null;
    return meetingLengthEditText;
}
 
Example 6
Source File: ConfigureStandupTimer.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private View createMeetingLengthTextBox() {
    meetingLengthEditText = new EditText(this);
    meetingLengthEditText.setGravity(Gravity.CENTER);
    meetingLengthEditText.setKeyListener(new DigitsKeyListener());
    meetingLengthEditText.setRawInputType(InputType.TYPE_CLASS_PHONE);
    meetingLengthEditText.setLayoutParams(new LayoutParams(dipsToPixels(60), LayoutParams.WRAP_CONTENT));
    meetingLengthEditText.setText(Integer.toString(meetingLength));
    meetingLengthEditText.setLines(1);

    meetingLengthSpinner = null;
    return meetingLengthEditText;
}
 
Example 7
Source File: EditPage.java    From WeCenterMobile-Android with GNU General Public License v2.0 5 votes vote down vote up
private LinearLayout getMainBody() {
	LinearLayout llMainBody = new LinearLayout(getContext());
	llMainBody.setOrientation(LinearLayout.VERTICAL);
	LinearLayout.LayoutParams lpMain = new LinearLayout.LayoutParams(
			LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
	lpMain.weight = 1;
	int dp_4 = dipToPx(getContext(), 4);
	lpMain.setMargins(dp_4, dp_4, dp_4, dp_4);
	llMainBody.setLayoutParams(lpMain);

	LinearLayout llContent = new LinearLayout(getContext());
	LinearLayout.LayoutParams lpContent = new LinearLayout.LayoutParams(
			LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
	lpContent.weight = 1;
	llMainBody.addView(llContent, lpContent);

	// 文字输入区域
	etContent = new EditText(getContext());
	etContent.setGravity(Gravity.LEFT | Gravity.TOP);
	etContent.setBackgroundDrawable(null);
	etContent.setText(String.valueOf(reqData.get("text")));
	etContent.addTextChangedListener(this);
	LinearLayout.LayoutParams lpEt = new LinearLayout.LayoutParams(
			LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	lpEt.weight = 1;
	etContent.setLayoutParams(lpEt);
	llContent.addView(etContent);

	llContent.addView(getThumbView());
	llMainBody.addView(getBodyBottom());

	return llMainBody;
}
 
Example 8
Source File: NativeElementView.java    From htmlview with Apache License 2.0 5 votes vote down vote up
static NativeElementView createTextArea(final Context context, final Element element) {
  int textSize = element.getScaledPx(Style.FONT_SIZE);
  EditText editText = new EditText(context);
  editText.setSingleLine(false);
  editText.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
  editText.setGravity(Gravity.TOP);
  // TODO: Calculate lines based on height if fixed.
  editText.setLines(element.getAttributeInt("rows", 2));
  editText.setVerticalScrollBarEnabled(true);
  LayoutParams params = new LayoutParams(0, LayoutParams.WRAP_CONTENT);
  editText.setLayoutParams(params);
  NativeElementView result = new NativeElementView(context, element, false, editText);
  result.reset();
  return result;
}
 
Example 9
Source File: EditPage.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
private LinearLayout getMainBody() {
	LinearLayout llMainBody = new LinearLayout(getContext());
	llMainBody.setOrientation(LinearLayout.VERTICAL);
	LayoutParams lpMain = new LayoutParams(
			LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
	lpMain.weight = 1;
	int dp_4 = dipToPx(getContext(), 4);
	lpMain.setMargins(dp_4, dp_4, dp_4, dp_4);
	llMainBody.setLayoutParams(lpMain);

	LinearLayout llContent = new LinearLayout(getContext());
	LayoutParams lpContent = new LayoutParams(
			LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
	lpContent.weight = 1;
	llMainBody.addView(llContent, lpContent);

	// share content editor
	etContent = new EditText(getContext());
	etContent.setGravity(Gravity.LEFT | Gravity.TOP);
	etContent.setBackgroundDrawable(null);
	etContent.setText(String.valueOf(shareParamMap.get("text")));
	etContent.addTextChangedListener(this);
	LayoutParams lpEt = new LayoutParams(
			LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	lpEt.weight = 1;
	etContent.setLayoutParams(lpEt);
	llContent.addView(etContent);

	llContent.addView(getThumbView());
	llMainBody.addView(getBodyBottom());

	return llMainBody;
}
 
Example 10
Source File: ScalableLayout.java    From ScalableLayout with Apache License 2.0 5 votes vote down vote up
/**
 * adds new EditText with (TextSize, Left, Top, Width, Height) parameters
 * @param pScale_TextSize
 * @param pScale_Left
 * @param pScale_Top
 * @param pScale_Width
 * @param pScale_Height
 * @return created EditText instance
 */
public EditText addNewEditText(float pScale_TextSize, float pScale_Left, float pScale_Top, float pScale_Width, float pScale_Height) {
    EditText ret = new EditText(getContext());
    addView(ret, pScale_Left, pScale_Top, pScale_Width, pScale_Height);

    setScale_TextSize(ret, pScale_TextSize);
    ret.setGravity(Gravity.CENTER);
    ret.setTextColor(Color.BLACK);
    return ret;
}
 
Example 11
Source File: EditPage.java    From Huochexing12306 with Apache License 2.0 5 votes vote down vote up
private LinearLayout getMainBody() {
	LinearLayout llMainBody = new LinearLayout(getContext());
	llMainBody.setOrientation(LinearLayout.VERTICAL);
	LinearLayout.LayoutParams lpMain = new LinearLayout.LayoutParams(
			LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
	lpMain.weight = 1;
	int dp_4 = dipToPx(getContext(), 4);
	lpMain.setMargins(dp_4, dp_4, dp_4, dp_4);
	llMainBody.setLayoutParams(lpMain);

	LinearLayout llContent = new LinearLayout(getContext());
	LinearLayout.LayoutParams lpContent = new LinearLayout.LayoutParams(
			LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
	lpContent.weight = 1;
	llMainBody.addView(llContent, lpContent);

	// 文字输入区域
	etContent = new EditText(getContext());
	etContent.setGravity(Gravity.LEFT | Gravity.TOP);
	etContent.setBackgroundDrawable(null);
	etContent.setText(String.valueOf(reqData.get("text")));
	etContent.addTextChangedListener(this);
	LinearLayout.LayoutParams lpEt = new LinearLayout.LayoutParams(
			LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	lpEt.weight = 1;
	etContent.setLayoutParams(lpEt);
	llContent.addView(etContent);

	llContent.addView(getThumbView());
	llMainBody.addView(getBodyBottom());

	return llMainBody;
}
 
Example 12
Source File: Pinview.java    From Pinview with MIT License 5 votes vote down vote up
/**
 * Takes care of styling the editText passed in the param.
 * tag is the index of the editText.
 *
 * @param styleEditText
 * @param tag
 */
private void generateOneEditText(EditText styleEditText, String tag) {
    params.setMargins(mSplitWidth / 2, mSplitWidth / 2, mSplitWidth / 2, mSplitWidth / 2);
    filters[0] = new InputFilter.LengthFilter(1);
    styleEditText.setFilters(filters);
    styleEditText.setLayoutParams(params);
    styleEditText.setGravity(Gravity.CENTER);
    styleEditText.setCursorVisible(mCursorVisible);

    if (!mCursorVisible) {
        styleEditText.setClickable(false);
        styleEditText.setHint(mHint);

        styleEditText.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                // When back space is pressed it goes to delete mode and when u click on an edit Text it should get out of the delete mode
                mDelPressed = false;
                return false;
            }
        });
    }
    styleEditText.setBackgroundResource(mPinBackground);
    styleEditText.setPadding(0, 0, 0, 0);
    styleEditText.setTag(tag);
    styleEditText.setInputType(getKeyboardInputType());
    styleEditText.addTextChangedListener(this);
    styleEditText.setOnFocusChangeListener(this);
    styleEditText.setOnKeyListener(this);
}
 
Example 13
Source File: PlusMinusNum.java    From K-Sonic with MIT License 4 votes vote down vote up
private void initView() {
    setOrientation(LinearLayout.HORIZONTAL);

    // =========@center Layout
    centerLL = new LinearLayout(getContext());
    editText = new EditText(getContext());
    editText.setInputType(InputType.TYPE_CLASS_NUMBER);//TYPE_NULL
    editText.setText(String.valueOf(num));
    editText.setTextColor(0xff229EBF);
    editText.setBackgroundResource(R.drawable.num_edit);
    editText.setPadding(0, 0, 0, 0);
    editText.setGravity(Gravity.CENTER);
    editText.setMinimumWidth(ediTextMinimumWidth);
    LayoutParams ediTextLP = new LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.MATCH_PARENT);
    editText.setLayoutParams(ediTextLP);

    LayoutParams centerLP = new LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.MATCH_PARENT);
    centerLP.gravity = Gravity.CENTER;
    centerLL.setLayoutParams(centerLP);
    centerLL.setFocusable(true);
    centerLL.setFocusableInTouchMode(true);


    // =========@left/right Layout
    minusButton = new Button(getContext());
    minusButton.setText(minusButtonText);
    minusButton.setTextColor(0xff666666);
    minusButton.setTag(minusButtonText);
    minusButton.setBackgroundResource(R.drawable.num_minus);
    minusButton.setPadding(0, 0, 0, 0);

    plusButton = new Button(getContext());
    plusButton.setText(plusButtonText);
    plusButton.setTextColor(0xff666666);
    plusButton.setTag(plusButtonText);
    plusButton.setBackgroundResource(R.drawable.num_plus);
    plusButton.setPadding(0, 0, 0, 0);

    LayoutParams buttonLP = new LayoutParams(
            buttonWidth,
            LinearLayout.LayoutParams.MATCH_PARENT);
    plusButton.setLayoutParams(buttonLP);
    minusButton.setLayoutParams(buttonLP);
}
 
Example 14
Source File: BodyPartDetailsFragment.java    From fastnfitness with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void onClick(View v) {
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
        LinearLayout.LayoutParams.MATCH_PARENT,
        LinearLayout.LayoutParams.WRAP_CONTENT
    );

    editDate = new TextView(getContext());
    Date date = DateConverter.getNewDate();
    editDate.setLayoutParams(params);
    editDate.setText(DateConverter.dateToLocalDateStr(date, getContext()));
    editDate.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
    editDate.setGravity(Gravity.CENTER);
    editDate.setOnClickListener((view) -> {
        Calendar calendar = Calendar.getInstance();

        calendar.setTime(DateConverter.getNewDate());
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        int month = calendar.get(Calendar.MONTH);
        int year = calendar.get(Calendar.YEAR);

        DatePickerDialog datePickerDialog = new DatePickerDialog(getContext(), getBodyPartDetailsFragment(), year, month, day);

        datePickerDialog.show();
    });

    editText = new EditText(getContext());
    editText.setText("");
    editText.setHint("Enter value here");
    editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
    editText.setGravity(Gravity.CENTER);
    editText.setLayoutParams(params);
    editText.requestFocus();
    editText.selectAll();

    LinearLayout linearLayout = new LinearLayout(getContext().getApplicationContext());

    linearLayout.setLayoutParams(params);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.addView(editDate);
    linearLayout.addView(editText);

    final SweetAlertDialog dialog = new SweetAlertDialog(getContext(), SweetAlertDialog.NORMAL_TYPE)
        .setTitleText(getString(R.string.new_measure))
        .showCancelButton(true)
        .setCancelClickListener(sDialog -> {
            editText.clearFocus();
            Keyboard.hide(getContext(), editText);
            sDialog.dismissWithAnimation();})
        .setCancelText(getContext().getString(R.string.global_cancel))
        .setConfirmText(getContext().getString(R.string.AddLabel))
        .setConfirmClickListener(sDialog -> {
            Keyboard.hide(sDialog.getContext(), editText);
            float value = 0;
            try {
                value = Float.parseFloat(editText.getText().toString());
                Date lDate = DateConverter.localDateStrToDate(editDate.getText().toString(), getContext());
                mBodyMeasureDb.addBodyMeasure(lDate, mInitialBodyPart.getId(), value, getProfile().getId());
                refreshData();
            } catch (Exception e) {
                KToast.errorToast(getActivity(),"Format Error", Gravity.BOTTOM, KToast.LENGTH_SHORT);
            }

            sDialog.dismissWithAnimation();
        });
    dialog.setCustomView(linearLayout);
    dialog.setOnShowListener(sDialog -> Keyboard.show(getContext(), editText));
    dialog.show();
}
 
Example 15
Source File: EditableInputView.java    From fastnfitness with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
protected void editDialog(Context context) {
    if (!mActivateDialog) return;

    if (mCustomerDialogBuilder != null) {
        mCustomerDialogBuilder.customerDialogBuilder(this).show();
    } else {
        if ((valueTextView.getInputType() & InputType.TYPE_CLASS_DATETIME) > 0) {
            Calendar calendar = Calendar.getInstance();

            calendar.setTime(DateConverter.localDateStrToDate(getText(), getContext()));
            int day = calendar.get(Calendar.DAY_OF_MONTH);
            int month = calendar.get(Calendar.MONTH);
            int year = calendar.get(Calendar.YEAR);

            DatePickerDialog datePickerDialog = new DatePickerDialog(
                getContext(), this, year, month, day);
            datePickerDialog.show();
        } else {
            final EditText editText = new EditText(context);
            editText.setText(mTextValue);
            editText.setGravity(Gravity.CENTER);
            editText.setInputType(textViewInputType);
            editText.requestFocus();

            LinearLayout linearLayout = new LinearLayout(context.getApplicationContext());
            linearLayout.setOrientation(LinearLayout.VERTICAL);
            linearLayout.addView(editText);

            final SweetAlertDialog dialog = new SweetAlertDialog(context, SweetAlertDialog.NORMAL_TYPE)
                .setTitleText(mTitle)
                .setCancelText(getContext().getString(R.string.global_cancel))
                .setHideKeyBoardOnDismiss(true)
                .setCancelClickListener(sDialog -> {
                    editText.clearFocus();
                    Keyboard.hide(context, editText);
                    sDialog.dismissWithAnimation();})
                .setConfirmClickListener(sDialog -> {
                    editText.clearFocus();
                    Keyboard.hide(context, editText);
                    setText(editText.getText().toString());
                    sDialog.dismissWithAnimation();
                    if (mConfirmClickListener != null)
                        mConfirmClickListener.onTextChanged(EditableInputView.this);
                });
                dialog.setOnDismissListener(sDialog -> {
                    rootView.requestFocus();
                    InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Activity.INPUT_METHOD_SERVICE);
                    if ( imm !=null)
                        imm.hideSoftInputFromWindow(rootView.getWindowToken(), 0);});
                    //Keyboard.hide(context, editText);});
                dialog.setOnShowListener(sDialog -> {
                    editText.requestFocus();
                    Keyboard.show(context, editText);
                });

            dialog.setCustomView(linearLayout);
            dialog.show();
        }
    }
}
 
Example 16
Source File: EditableInputViewWithDate.java    From fastnfitness with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected void editDialog(Context context) {
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
        LinearLayout.LayoutParams.MATCH_PARENT,
        LinearLayout.LayoutParams.WRAP_CONTENT
    );

    final TextView editDate = new TextView(getContext());
    date = DateConverter.getNewDate();
    editDate.setLayoutParams(params);
    editDate.setText(DateConverter.dateToLocalDateStr(date, getContext()));
    editDate.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
    editDate.setGravity(Gravity.CENTER);
    editDate.setOnClickListener((view) -> {
            Calendar calendar = Calendar.getInstance();

            calendar.setTime(DateConverter.getNewDate());
            int day = calendar.get(Calendar.DAY_OF_MONTH);
            int month = calendar.get(Calendar.MONTH);
            int year = calendar.get(Calendar.YEAR);

            DatePickerDialog datePickerDialog = new DatePickerDialog(getContext(), getEditableInputViewWithDate(), year, month, day);
            dateEditView = editDate;
            datePickerDialog.show();
    });

    final EditText editText = new EditText(context);
    if (getText().contentEquals("-")) {
        editText.setText("");
        editText.setHint("Enter value here");
    } else {
        editText.setText(getText());
    }
    editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
    editText.setGravity(Gravity.CENTER);
    editText.setLayoutParams(params);
    editText.requestFocus();
    editText.selectAll();

    LinearLayout linearLayout = new LinearLayout(getContext().getApplicationContext());

    linearLayout.setLayoutParams(params);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.addView(editDate);
    linearLayout.addView(editText);

    final SweetAlertDialog dialog = new SweetAlertDialog(context, SweetAlertDialog.NORMAL_TYPE)
        .setTitleText(mTitle)
        .showCancelButton(true)
        .setCancelClickListener(sDialog -> {
            editText.clearFocus();
            Keyboard.hide(context, editText);
            sDialog.dismissWithAnimation();})
        .setCancelText(getContext().getString(R.string.global_cancel))
        .setConfirmText(getContext().getString(R.string.AddLabel))
        .setConfirmClickListener(sDialog -> {
            Keyboard.hide(sDialog.getContext(), editText);
            setText(editText.getText().toString());
            if (mConfirmClickListener != null)
                mConfirmClickListener.onTextChanged(EditableInputViewWithDate.this);
            sDialog.dismissWithAnimation();
        });
    dialog.setCustomView(linearLayout);
    dialog.setOnShowListener(sDialog -> Keyboard.show(getContext(), editText));
    dialog.show();
}
 
Example 17
Source File: GEditTextView.java    From geopaparazzi with GNU General Public License v3.0 4 votes vote down vote up
/**
     * @param context               the context to use.
     * @param attrs                 attributes.
     * @param parentView            parent
     * @param label                 label
     * @param value                 value
     * @param type                  the text type.
     * @param lines                 the lines num.
     * @param constraintDescription constraints
     * @param readonly              if <code>false</code>, the item is disabled for editing.
     */
    public GEditTextView(Context context, AttributeSet attrs, LinearLayout parentView, String label, String value, int type,
                         int lines, String constraintDescription, boolean readonly) {
        super(context, attrs);

        LinearLayout textLayout = new LinearLayout(context);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT);
        layoutParams.setMargins(10, 10, 10, 10);
        textLayout.setLayoutParams(layoutParams);
        textLayout.setOrientation(LinearLayout.VERTICAL);
        parentView.addView(textLayout);

        TextView textView = new TextView(context);
        textView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        textView.setPadding(2, 2, 2, 2);
        textView.setText(label.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription);
        textView.setTextColor(Compat.getColor(context, R.color.formcolor));

        textLayout.addView(textView);

        editView = new EditText(context);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        params.setMargins(15, 25, 15, 15);
        editView.setLayoutParams(params);
//        editView.setPadding(15, 5, 15, 5);
        editView.setText(value);
        editView.setEnabled(!readonly);

        switch (type) {
            case 1:
                editView.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
                break;
            case 2:
                editView.setInputType(InputType.TYPE_CLASS_PHONE);
                break;
            case 3:
                editView.setInputType(InputType.TYPE_CLASS_DATETIME);
                break;
            case 4:
                editView.setInputType(InputType.TYPE_CLASS_NUMBER);
                break;
            default:
                break;
        }

        if (lines > 0) {
            editView.setLines(lines);
            editView.setGravity(Gravity.TOP);
        }

        textLayout.addView(editView);
    }
 
Example 18
Source File: LocalIMEKeyboard.java    From WaniKani-for-Android with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Constructor
 * @param wav parent activity
 * @param wv the integrated browser
 */
public LocalIMEKeyboard (WebReviewActivity wav, FocusWebView wv)
{
    Resources res;

    this.wav = wav;
    this.wv = wv;

    editable = true;
    bpos = new BoxPosition ();

    imm = (InputMethodManager) wav.getSystemService (Context.INPUT_METHOD_SERVICE);

    disableSuggestions = PrefManager.getNoSuggestion() | PrefManager.getRomaji();

    dm = wav.getResources ().getDisplayMetrics ();

    ime = new JapaneseIME ();

    ew = (EditText) wav.findViewById (R.id.ime);
    divw = wav.findViewById (R.id.ime_div);
    imel = new IMEListener ();
    ew.addTextChangedListener (imel);
    ew.setInputType (InputType.TYPE_CLASS_TEXT);
    ew.setOnEditorActionListener (imel);
    ew.setGravity (Gravity.CENTER);
    ew.setImeActionLabel (">>", EditorInfo.IME_ACTION_DONE);
    ew.setImeOptions (EditorInfo.IME_ACTION_DONE);

    qvw = (TextView) wav.findViewById (R.id.txt_question_override);

    next = (Button) wav.findViewById (R.id.ime_next);
    next.setOnClickListener (imel);

    srsv = wav.findViewById (R.id.v_srs);

    jsl = new JSListener ();
    wv.addJavascriptInterface (jsl, "wknJSListener");

    wki = new WaniKaniImprove (wav, wv);
    wv.registerListener (new WebViewListener ());

    res = wav.getResources ();
    correctFG = res.getColor (R.color.correctfg);
    incorrectFG = res.getColor (R.color.incorrectfg);
    ignoredFG = res.getColor (R.color.ignoredfg);

    setupSRSColors (res);

    correctBG = R.drawable.card_reviews_edittext_correct;
    incorrectBG = R.drawable.card_reviews_edittext_incorrect;
    ignoredBG = R.drawable.card_reviews_edittext_ignored;

    cmap = new EnumMap<WaniKaniItem.Type, Integer> (WaniKaniItem.Type.class);
    cmap.put (WaniKaniItem.Type.RADICAL, res.getColor (R.color.wanikani_radical));
    cmap.put (WaniKaniItem.Type.KANJI, res.getColor (R.color.wanikani_kanji));
    cmap.put (WaniKaniItem.Type.VOCABULARY, res.getColor (R.color.wanikani_vocabulary));
}
 
Example 19
Source File: FragmentCharacteristicDetail.java    From EFRConnect-android with Apache License 2.0 4 votes vote down vote up
private void addValue(final Field field) {

        LinearLayout parentLayout = new LinearLayout(context);
        LinearLayout.LayoutParams parentParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        parentLayout.setOrientation(LinearLayout.VERTICAL);

        parentParams.setMargins(0, defaultMargin, 0, defaultMargin / 2);
        parentLayout.setLayoutParams(parentParams);

        LinearLayout valueLayout = addValueLayout();
        TextView fieldNameView = addValueFieldName(field.getName(), valueLayout.getId());
        fieldNameView.setGravity(Gravity.CENTER_VERTICAL);
        fieldNameView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.characteristic_list_item_value_label_text_size));
        TextView fieldUnitView = addValueUnit(field);
        fieldUnitView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.characteristic_list_item_value_label_text_size));
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        layoutParams.gravity = Gravity.BOTTOM;
        fieldUnitView.setLayoutParams(layoutParams);
        hidableViews.add(fieldUnitView);

        if (!parseProblem && field.getReference() == null) {
            String format = field.getFormat();
            String val = readNextValue(format);


            if (!(format.toLowerCase().equals("utf8s") || format.toLowerCase().equals("utf16s"))) {
                int decimalExponentAbs = (int) abs(field.getDecimalExponent());
                double divider = Math.pow(10, decimalExponentAbs);
                double valDouble = Double.parseDouble(val);
                double valTmp = valDouble / divider;
                val = Double.toString(valTmp);
            } else {
                writeString = true;
                val = val.replace("\0", "");
            }


            if (writeable || writeableWithoutResponse) {
                // inline field value
                EditText fieldValueEdit = addValueEdit(field, val);
                fieldValueEdit.setGravity(Gravity.CENTER_VERTICAL);
                LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 0.5f);
                params.setMargins(8, 0, 0, 0);
                params.gravity = Gravity.CENTER_VERTICAL;
                fieldValueEdit.setLayoutParams(params);
                fieldValueEdit.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.characteristic_list_item_value_text_size));
                editTexts.add(fieldValueEdit);
                TextView fieldValue = (TextView) addFieldName(fieldValueEdit.getText().toString());
                fieldValue.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.characteristic_list_item_value_text_size));
                hidableViews.add(fieldValue);
                fieldValue.setTextColor(ContextCompat.getColor(getActivity(), R.color.silabs_primary_text));
                valueLayout.addView(fieldValue);

                // dialog field value
                // field name
                View fieldName = addFieldName(field.getName());
                params = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 0.5f);
                params.setMargins(0, 0, 8, 0);
                params.gravity = Gravity.CENTER_VERTICAL;
                fieldName.setLayoutParams(params);
                // container for editable field value and field name
                LinearLayout fieldContainer = new LinearLayout(context);
                fieldContainer.setOrientation(LinearLayout.HORIZONTAL);
                params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                params.setMargins(0, 5, 0, 5);
                fieldContainer.setLayoutParams(params);
                fieldContainer.addView(fieldName);
                fieldContainer.addView(fieldValueEdit);
                fieldContainer.setPadding(0, FIELD_CONTAINER_PADDING_TOP, 0, FIELD_CONTAINER_PADDING_BOTTOM);
                writableFieldsContainer.addView(fieldContainer);
            } else {
                TextView fieldValueView = addValueText(val);
                fieldValueView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.characteristic_list_item_value_text_size));
                hidableViews.add(fieldValueView);
                valueLayout.addView(fieldValueView);
            }

            updateSaveButtonState();
        }

        valueLayout.addView(fieldUnitView);
        parentLayout.addView(valueLayout);
        parentLayout.addView(fieldNameView);
        valuesLayout.addView(parentLayout);
    }
 
Example 20
Source File: OOM.java    From Kernel-Tuner with GNU General Public License v3.0 4 votes vote down vote up
private final void Dialog(String dialogTitle, String currentValue, final int option){
	AlertDialog.Builder builder = new AlertDialog.Builder(this);

	builder.setTitle(dialogTitle);

	builder.setMessage(getResources().getString(R.string.gov_new_value));

	builder.setIcon(isLight ? R.drawable.edit_light : R.drawable.edit_dark);


	final EditText input = new EditText(this);
	input.setHint(currentValue);
	input.selectAll();
	input.setInputType(InputType.TYPE_CLASS_NUMBER);
	input.setGravity(Gravity.CENTER_HORIZONTAL);

	builder.setPositiveButton(getResources().getString(R.string.apply), new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which)
			{
				switch(option){
				case 0:
					new setOOM().execute(Utility.mbToPages(Utility.parseInt(input.getText().toString(), 0)),
                               Utility.mbToPages(visibleSeek.getProgress()),
                               Utility.mbToPages(secondarySeek.getProgress()),
                               Utility.mbToPages(hiddenSeek.getProgress()),
                               Utility.mbToPages(contentSeek.getProgress()),
                               Utility.mbToPages(emptySeek.getProgress()));
					break;
				case 1:
					new setOOM().execute(Utility.mbToPages(foregroundSeek.getProgress()),
                               Utility.mbToPages(Utility.parseInt(input.getText().toString(), 0)),
                               Utility.mbToPages(secondarySeek.getProgress()),
                               Utility.mbToPages(hiddenSeek.getProgress()),
                               Utility.mbToPages(contentSeek.getProgress()),
                               Utility.mbToPages(emptySeek.getProgress()));
					break;
				case 2:
					new setOOM().execute(Utility.mbToPages(foregroundSeek.getProgress()),
                               Utility.mbToPages(visibleSeek.getProgress()),
                               Utility.mbToPages(Utility.parseInt(input.getText().toString(), 0)),
                               Utility.mbToPages(hiddenSeek.getProgress()),
                               Utility.mbToPages(contentSeek.getProgress()),
                               Utility.mbToPages(emptySeek.getProgress()));
					break;
				case 3:
					new setOOM().execute(Utility.mbToPages(foregroundSeek.getProgress()),
                               Utility.mbToPages(visibleSeek.getProgress()),
                               Utility.mbToPages(secondarySeek.getProgress()),
                               Utility.mbToPages(Utility.parseInt(input.getText().toString(), 0)),
                               Utility.mbToPages(contentSeek.getProgress()),
                               Utility.mbToPages(emptySeek.getProgress()));
					break;
				case 4:
					new setOOM().execute(Utility.mbToPages(foregroundSeek.getProgress()),
                               Utility.mbToPages(visibleSeek.getProgress()),
                               Utility.mbToPages(secondarySeek.getProgress()),
                               Utility.mbToPages(hiddenSeek.getProgress()),
                               Utility.mbToPages(Utility.parseInt(input.getText().toString(), 0)),
                               Utility.mbToPages(emptySeek.getProgress()));
					break;
				case 5:
					new setOOM().execute(Utility.mbToPages(foregroundSeek.getProgress()),
                               Utility.mbToPages(visibleSeek.getProgress()),
                               Utility.mbToPages(secondarySeek.getProgress()),
                               Utility.mbToPages(hiddenSeek.getProgress()),
                               Utility.mbToPages(contentSeek.getProgress()),
                               Utility.mbToPages(Utility.parseInt(input.getText().toString(), 0)));
					break;
					
				}
				

				
				
			}
		});
	builder.setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener(){

			@Override
			public void onClick(DialogInterface arg0, int arg1)
			{
				

			}

		});
	builder.setView(input);

	AlertDialog alert = builder.create();

	alert.show();
}