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

The following examples show how to use android.widget.EditText#post() . 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: DynamicInputUtils.java    From dynamic-support with Apache License 2.0 6 votes vote down vote up
/**
 * Show the soft input keyboard and focus it on the supplied {@link EditText}.
 *
 * @param editText The edit text to show the soft input.
 */
public static void showSoftInput(final @NonNull EditText editText) {
    editText.requestFocus();
    editText.post(new Runnable() {
        @Override
        public void run() {
            InputMethodManager inputMethodManager = (InputMethodManager)
                    editText.getContext().getSystemService(Service.INPUT_METHOD_SERVICE);
            if (inputMethodManager != null) {
                inputMethodManager.showSoftInput(editText, 0);
                editText.clearFocus();
                editText.requestFocus();
            }
        }
    });
}
 
Example 2
Source File: TestFilledFieldsNfcActivity.java    From android-nfc-lib with MIT License 6 votes vote down vote up
public void testFilledBluetoothMacAddressFieldButtonClickShowsProgressDialog() throws Exception {
        //checkAndDismissBluetoothDialog();
        makeScreenshot("init");
        final EditText text = (EditText) getActivity().findViewById(R.id.input_text_bluetooth_address);

        final String macAddress = "00:11:22:33:44";

        text.post(new Runnable() {
            @Override
            public void run() {
                text.setText(macAddress);
            }
        });

        makeScreenshot("Item_filled");
        onView(withId(R.id.input_text_bluetooth_address)).perform(click());


//        onView(withId(R.id.spinner_bluetooth_addresses)).perform(click(pressImeActionButton()));
        onView(withId(R.id.btn_write_bluetooth_nfc)).perform(click());
        makeScreenshot("Showing_progressdialog");
        checkProgressDialogShowing();
        makeScreenshot("end");
    }
 
Example 3
Source File: MainActivity.java    From FitbitAndroidSample with Apache License 2.0 6 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent){
    super.onActivityResult(requestCode, resultCode, intent);
    
    if (requestCode == GET_PIN_REQUEST) {
    	
        if (resultCode == RESULT_OK) {
            Bundle extras = intent.getExtras();
            if(extras != null){
            	final String pin = extras.getString("PIN");
            	final EditText etPIN = (EditText) findViewById(R.id.etPIN);
            	
            	etPIN.post(new Runnable() {
		@Override
		public void run() {
			etPIN.setText(pin);
		}
	});
            }
        }
    }
}
 
Example 4
Source File: InputAwareLayout.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public void showSoftkey(final EditText inputTarget) {
  postOnKeyboardOpen(new Runnable() {
    @Override public void run() {
      hideAttachedInput(true);
    }
  });
  inputTarget.post(new Runnable() {
    @Override public void run() {
      inputTarget.requestFocus();
      ServiceUtil.getInputMethodManager(inputTarget.getContext()).showSoftInput(inputTarget, 0);
    }
  });
}
 
Example 5
Source File: DebugView.java    From u2020 with Apache License 2.0 5 votes vote down vote up
private void showNewNetworkProxyDialog(final ProxyAdapter proxyAdapter) {
  final int originalSelection = networkProxyAddress.isSet() ? ProxyAdapter.PROXY : ProxyAdapter.NONE;

  View view = LayoutInflater.from(app).inflate(R.layout.debug_drawer_network_proxy, null);
  final EditText hostView = view.findViewById(R.id.debug_drawer_network_proxy_host);

  if(networkProxyAddress.isSet()) {
    String host = networkProxyAddress.get().getHostName();
    hostView.setText(host); // Set the current host.
    hostView.setSelection(0, host.length()); // Pre-select it for editing.

    // Show the keyboard. Post this to the next frame when the dialog has been attached.
    hostView.post(() -> Keyboards.showKeyboard(hostView));
  }

  new AlertDialog.Builder(getContext()) //
      .setTitle("Set Network Proxy")
      .setView(view)
      .setNegativeButton("Cancel", (dialog, i) -> {
        networkProxyView.setSelection(originalSelection);
        dialog.cancel();
      })
      .setPositiveButton("Use", (dialog, i) -> {
        String in = hostView.getText().toString();
        InetSocketAddress address = InetSocketAddressPreferenceAdapter.parse(in);
        if (address != null) {
          networkProxyAddress.set(address);
          // Force a restart to re-initialize the app with the new proxy.
          ProcessPhoenix.triggerRebirth(getContext());
        } else {
          networkProxyView.setSelection(originalSelection);
        }
      })
      .setOnCancelListener(dialogInterface -> networkProxyView.setSelection(originalSelection))
      .show();
}
 
Example 6
Source File: SmileyPickerUtility.java    From zhangshangwuda with Apache License 2.0 5 votes vote down vote up
public static void showKeyBoard(final EditText paramEditText) {
	paramEditText.requestFocus();
	paramEditText.post(new Runnable() {
		@Override
		public void run() {
			((InputMethodManager) MyApplication.getInstance()
					.getSystemService("input_method")).showSoftInput(
					paramEditText, 0);
		}
	});
}
 
Example 7
Source File: TestEmptyFieldsNfcActivity.java    From android-nfc-lib with MIT License 5 votes vote down vote up
public void testEmptyBluetoothFieldNotDisplayingAfterClick() {
    final EditText editText = (EditText) getActivity().findViewById(R.id.input_text_bluetooth_address);
    editText.post(new Runnable() {
        @Override
        public void run() {
            editText.setText(null);
        }
    });
    emptyFieldNotDisplayingToast(R.id.btn_write_bluetooth_nfc);
}
 
Example 8
Source File: InputDialogFragment.java    From AndroidPlayground with MIT License 5 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    final EditText paramEditText = (EditText) view.findViewById(R.id.mEditText);
    paramEditText.requestFocus();
    paramEditText.post(new Runnable() {

        @Override
        public void run() {
            ((InputMethodManager) getActivity().getSystemService(Context
                    .INPUT_METHOD_SERVICE)).showSoftInput(paramEditText, 0);
        }
    });
}
 
Example 9
Source File: BaseAuthFragment.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
protected void focus(final EditText editText) {
    editText.post(new Runnable() {
        @Override
        public void run() {
            editText.requestFocus();
            editText.setSelection(editText.getText().length());
        }
    });
}
 
Example 10
Source File: InputAwareLayout.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
public void showSoftkey(final EditText inputTarget) {
  postOnKeyboardOpen(new Runnable() {
    @Override public void run() {
      hideAttachedInput(true);
    }
  });
  inputTarget.post(new Runnable() {
    @Override public void run() {
      inputTarget.requestFocus();
      ServiceUtil.getInputMethodManager(inputTarget.getContext()).showSoftInput(inputTarget, 0);
    }
  });
}
 
Example 11
Source File: InputAwareLayout.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
public void showSoftkey(final EditText inputTarget) {
  postOnKeyboardOpen(() -> hideAttachedInput(true));
  inputTarget.post(() -> {
    inputTarget.requestFocus();
    ServiceUtil.getInputMethodManager(inputTarget.getContext()).showSoftInput(inputTarget, 0);
  });
}
 
Example 12
Source File: EditTextDialog.java    From BottomDialog with Apache License 2.0 5 votes vote down vote up
@Override
public void bindView(View v) {
    mEditText = (EditText) v.findViewById(R.id.edit_text);
    mEditText.post(new Runnable() {
        @Override
        public void run() {
            InputMethodManager imm =
                    (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(mEditText, 0);
        }
    });
}
 
Example 13
Source File: InputDialogFragment.java    From ChatRecyclerView with MIT License 5 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    final EditText paramEditText = (EditText) view.findViewById(R.id.mEditText);
    paramEditText.requestFocus();
    paramEditText.post(new Runnable() {

        @Override
        public void run() {
            ((InputMethodManager) getActivity().getSystemService(Context
                    .INPUT_METHOD_SERVICE)).showSoftInput(paramEditText, 0);
        }
    });
}
 
Example 14
Source File: InputDialog.java    From ChatRecyclerView with MIT License 5 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    final EditText editText = (EditText) view.findViewById(R.id.mEtInput);
    view.findViewById(R.id.mBtnSend).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mAction.send(editText.getText().toString());
            dismiss();
        }
    });
    KeyboardVisibilityEvent.setEventListener(getActivity(),
            new KeyboardVisibilityEventListener() {
                @Override
                public void onVisibilityChanged(boolean isOpen) {
                    if (!isOpen) {
                        dismiss();
                    }
                }
            });
    editText.post(new Runnable() {
        @Override
        public void run() {
            UIUtil.showKeyboard(getContext(), editText);
        }
    });
}
 
Example 15
Source File: KeyboardHelper.java    From belvedere with Apache License 2.0 5 votes vote down vote up
static void showKeyboard(final EditText editText) {
    editText.post(new Runnable() {
        @Override
        public void run() {
            if(editText.requestFocus()) {
                InputMethodManager imm = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                if(imm != null) {
                    imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
                }
            }
        }
    });
}
 
Example 16
Source File: EditTextDialog.java    From AndroidUiKit with Apache License 2.0 5 votes vote down vote up
@Override
public void bindView(View v) {
    mEditText = (EditText) v.findViewById(R.id.edit_text);
    mEditText.post(new Runnable() {
        @Override
        public void run() {
            InputMethodManager imm =
                    (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(mEditText, 0);
        }
    });
}
 
Example 17
Source File: WaveLoadingViewHolder.java    From ReadMark with Apache License 2.0 4 votes vote down vote up
private void initViews(){
    mContentView = LayoutInflater.from(mContext)
            .inflate(R.layout.item_wave_loading_view, mViewGroup, false);
    mWaveLoadingView = (WaveLoadingView) mContentView.findViewById(R.id.wave_loading_view);
    mWaveLoadingView.post(new Runnable() {
        @Override
        public void run() {
            mWaveLoadingView.setWaveColor(mBookshelf.getColor());
        }
    });
    mRedPicker = (SeekBar) mContentView.findViewById(R.id.red_picker);
    mGreenPicker = (SeekBar) mContentView.findViewById(R.id.green_picker);
    mBluePicker = (SeekBar) mContentView.findViewById(R.id.blue_picker);
    mAmpPicker = (SeekBar) mContentView.findViewById(R.id.amp_picker);
    mWavePicker = (SeekBar) mContentView.findViewById(R.id.wave_picker);
    mCurrentPage = (EditText) mContentView.findViewById(R.id.edit_current_page);
    mTotalPages = (TextView) mContentView.findViewById(R.id.text_total_page);
    mConfirmButton = (Button) mContentView.findViewById(R.id.button_confirm);
    //mCancelButton = (Button) mContentView.findViewById(R.id.button_cancel);


    mRedPicker.post(new Runnable() {
        @Override
        public void run() {
            mRedPicker.setProgress( (int)((mBookshelf.getRed() / 255.0f) * 100));
        }
    });
    mGreenPicker.post(new Runnable() {
        @Override
        public void run() {
            mGreenPicker.setProgress((int)((mBookshelf.getGreen() / 255.0f) * 100));
        }
    });
    mBluePicker.post(new Runnable() {
        @Override
        public void run() {
            mBluePicker.setProgress((int)((mBookshelf.getBlue() / 255.0f) * 100));
        }
    });
    mAmpPicker.post(new Runnable() {
        @Override
        public void run() {
            //范围是0~1
            mAmpPicker.setProgress((int) (mBookshelf.getAmpratio() * 100));
        }
    });
    mWavePicker.post(new Runnable() {
        @Override
        public void run() {
            mWavePicker.setProgress((int) (mBookshelf.getWaveratio() * 100));
        }
    });
    mCurrentPage.post(new Runnable() {
        @Override
        public void run() {
            mCurrentPage.setText(""+mBookshelf.getCurrentpage());
        }
    });
    mTotalPages.post(new Runnable() {
        @Override
        public void run() {
            mTotalPages.setText("of "+mBookshelf.getTotalpage());
        }
    });
    //mWaveLoadingView.setProgress(mBookshelf.getProgress());
    Log.e("此时progress是",mBookshelf.getProgress()+"");
    mWaveLoadingView.setTitletext(((int)(mBookshelf.getProgress() * 100)) + "" + " %");


}
 
Example 18
Source File: WaveLoadingViewHolder.java    From ReadMark with Apache License 2.0 4 votes vote down vote up
private void initViews(){
    mContentView = LayoutInflater.from(mContext)
            .inflate(R.layout.item_wave_loading_view, mViewGroup, false);
    mWaveLoadingView = (WaveLoadingView) mContentView.findViewById(R.id.wave_loading_view);
    mWaveLoadingView.post(new Runnable() {
        @Override
        public void run() {
            mWaveLoadingView.setWaveColor(mBookshelf.getColor());
        }
    });
    mRedPicker = (SeekBar) mContentView.findViewById(R.id.red_picker);
    mGreenPicker = (SeekBar) mContentView.findViewById(R.id.green_picker);
    mBluePicker = (SeekBar) mContentView.findViewById(R.id.blue_picker);
    mAmpPicker = (SeekBar) mContentView.findViewById(R.id.amp_picker);
    mWavePicker = (SeekBar) mContentView.findViewById(R.id.wave_picker);
    mCurrentPage = (EditText) mContentView.findViewById(R.id.edit_current_page);
    mTotalPages = (TextView) mContentView.findViewById(R.id.text_total_page);
    mConfirmButton = (Button) mContentView.findViewById(R.id.button_confirm);
    //mCancelButton = (Button) mContentView.findViewById(R.id.button_cancel);


    mRedPicker.post(new Runnable() {
        @Override
        public void run() {
            mRedPicker.setProgress( (int)((mBookshelf.getRed() / 255.0f) * 100));
        }
    });
    mGreenPicker.post(new Runnable() {
        @Override
        public void run() {
            mGreenPicker.setProgress((int)((mBookshelf.getGreen() / 255.0f) * 100));
        }
    });
    mBluePicker.post(new Runnable() {
        @Override
        public void run() {
            mBluePicker.setProgress((int)((mBookshelf.getBlue() / 255.0f) * 100));
        }
    });
    mAmpPicker.post(new Runnable() {
        @Override
        public void run() {
            //范围是0~1
            mAmpPicker.setProgress((int) (mBookshelf.getAmpratio() * 100));
        }
    });
    mWavePicker.post(new Runnable() {
        @Override
        public void run() {
            mWavePicker.setProgress((int) (mBookshelf.getWaveratio() * 100));
        }
    });
    mCurrentPage.post(new Runnable() {
        @Override
        public void run() {
            mCurrentPage.setText(""+mBookshelf.getCurrentpage());
        }
    });
    mTotalPages.post(new Runnable() {
        @Override
        public void run() {
            mTotalPages.setText("of "+mBookshelf.getTotalpage());
        }
    });
    //mWaveLoadingView.setProgress(mBookshelf.getProgress());
    Log.e("此时progress是",mBookshelf.getProgress()+"");
    mWaveLoadingView.setTitletext(((int)(mBookshelf.getProgress() * 100)) + "" + " %");


}
 
Example 19
Source File: FileEditorActivity.java    From Android-PreferencesManager with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle arg0) {
    setTheme(App.theme.theme);
    super.onCreate(arg0);
    setContentView(R.layout.activity_file_editor);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    Bundle b = getIntent().getExtras();
    if (b == null) {
        finish();
        return;
    }
    Picasso.with(this).load(b.<Uri>getParcelable(PreferencesFragment.ARG_ICON_URI)).error(R.drawable.ic_launcher).into((android.widget.ImageView) findViewById(android.R.id.home));

    mFile = b.getString(PreferencesFragment.ARG_FILE);
    mTitle = Utils.extractFileName(mFile);
    mPackageName = b.getString(PreferencesFragment.ARG_PACKAGE_NAME);
    mEditText = (EditText) findViewById(R.id.editText);
    //Hack to prevent EditText to request focus when the Activity is created
    mEditText.post(new Runnable() {
        @Override
        public void run() {
            mEditText.setFocusable(true);
            mEditText.setFocusableInTouchMode(true);
        }
    });

    if (arg0 == null) {
        mEditText.setText(Utils.readFile(mFile));
        mColorTheme = ColorThemeEnum.valueOf(PreferenceManager.getDefaultSharedPreferences(this).getString(KEY_COLOR_THEME, ColorThemeEnum.ECLIPSE.name()));
        setXmlFontSize(XmlFontSize.generateSize(PreferenceManager.getDefaultSharedPreferences(this).getInt(KEY_FONT_SIZE, XmlFontSize.MEDIUM.getSize())));
    } else {
        mHasContentChanged = arg0.getBoolean(KEY_HAS_CONTENT_CHANGED, false);
        mNeedUpdateOnActivityFinish = arg0.getBoolean(KEY_NEED_UPDATE_ON_ACTIVITY_FINISH, false);
        if (mNeedUpdateOnActivityFinish) {
            setResult(RESULT_OK);
        }
        mColorTheme = ColorThemeEnum.valueOf(arg0.getString(KEY_COLOR_THEME));
        setXmlFontSize(XmlFontSize.generateSize(arg0.getInt(KEY_FONT_SIZE)));
    }
    mXmlColorTheme = XmlColorTheme.createTheme(getResources(), mColorTheme);

    updateTitle();
    invalidateOptionsMenu();

    highlightXMLText(mEditText.getText());

    mEditText.clearFocus();
}
 
Example 20
Source File: SignalPinReminderDialog.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
public static void show(@NonNull Context context, @NonNull Launcher launcher, @NonNull Callback mainCallback) {
  if (!SignalStore.kbsValues().hasPin()) {
    throw new AssertionError("Must have a PIN!");
  }

  Log.i(TAG, "Showing PIN reminder dialog.");

  AlertDialog dialog = new AlertDialog.Builder(context, ThemeUtil.isDarkTheme(context) ? R.style.Theme_Signal_AlertDialog_Dark_Cornered_ColoredAccent : R.style.Theme_Signal_AlertDialog_Light_Cornered_ColoredAccent)
                                      .setView(R.layout.kbs_pin_reminder_view)
                                      .setCancelable(false)
                                      .setOnCancelListener(d -> RegistrationLockReminders.scheduleReminder(context, false))
                                      .create();

  WindowManager  windowManager = ServiceUtil.getWindowManager(context);
  Display        display       = windowManager.getDefaultDisplay();
  DisplayMetrics metrics       = new DisplayMetrics();
  display.getMetrics(metrics);

  dialog.show();
  dialog.getWindow().setLayout((int)(metrics.widthPixels * .80), ViewGroup.LayoutParams.WRAP_CONTENT);

  EditText pinEditText = (EditText) DialogCompat.requireViewById(dialog, R.id.pin);
  TextView pinStatus   = (TextView) DialogCompat.requireViewById(dialog, R.id.pin_status);
  TextView reminder    = (TextView) DialogCompat.requireViewById(dialog, R.id.reminder);
  View     skip        = DialogCompat.requireViewById(dialog, R.id.skip);
  View     submit      = DialogCompat.requireViewById(dialog, R.id.submit);

  SpannableString reminderText = new SpannableString(context.getString(R.string.KbsReminderDialog__to_help_you_memorize_your_pin));
  SpannableString forgotText   = new SpannableString(context.getString(R.string.KbsReminderDialog__forgot_pin));

  pinEditText.post(() -> {
    if (pinEditText.requestFocus()) {
      ServiceUtil.getInputMethodManager(pinEditText.getContext()).showSoftInput(pinEditText, 0);
    }
  });
  ViewCompat.setAutofillHints(pinEditText, HintConstants.AUTOFILL_HINT_PASSWORD);

  switch (SignalStore.pinValues().getKeyboardType()) {
    case NUMERIC:
      pinEditText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
      break;
    case ALPHA_NUMERIC:
      pinEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
      break;
  }

  ClickableSpan clickableSpan = new ClickableSpan() {
    @Override
    public void onClick(@NonNull View widget) {
      dialog.dismiss();
      launcher.launch(CreateKbsPinActivity.getIntentForPinChangeFromForgotPin(context), CreateKbsPinActivity.REQUEST_NEW_PIN);
    }
  };

  forgotText.setSpan(clickableSpan, 0, forgotText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

  reminder.setText(new SpannableStringBuilder(reminderText).append(" ").append(forgotText));
  reminder.setMovementMethod(LinkMovementMethod.getInstance());

  PinVerifier.Callback callback = getPinWatcherCallback(context, dialog, pinEditText, pinStatus, mainCallback);
  PinVerifier          verifier = new V2PinVerifier();

  skip.setOnClickListener(v -> {
    dialog.dismiss();
    mainCallback.onReminderDismissed(callback.hadWrongGuess());
  });

  submit.setEnabled(false);
  submit.setOnClickListener(v -> {
    Editable pinEditable = pinEditText.getText();

    verifier.verifyPin(pinEditable == null ? null : pinEditable.toString(), callback);
  });

  pinEditText.addTextChangedListener(new SimpleTextWatcher() {

    private final String localHash = Objects.requireNonNull(SignalStore.kbsValues().getLocalPinHash());

    @Override
    public void onTextChanged(String text) {
      if (text.length() >= KbsConstants.MINIMUM_PIN_LENGTH) {
        submit.setEnabled(true);

        if (PinHashing.verifyLocalPinHash(localHash, text)) {
          dialog.dismiss();
          mainCallback.onReminderCompleted(text, callback.hadWrongGuess());
        }
      } else {
        submit.setEnabled(false);
      }
    }
  });
}