In my application i should use Vertical Stepper and for this i added below library : VerticalStepperForm.
I should use this stepper into service and for this i write below codes.
But when use this codes into Service, when click on EditText not open soft keyboard (not show me any keyboard), but when use this codes into activity, it's not bug and show me keyboard.
But into service not show any keyboard!
My service codes:
public class FloatingLayoutService extends Service implements StepperFormListener {
private WindowManager windowManager;
private ConstraintLayout floatingLayout, floatingLay_root, floatingLay_main;
private IBinder binder = new ServiceBinder();
private LinearLayout floatingLay_headerLay;
private List<Step> steps = new ArrayList();
private List<Integer> intList = new ArrayList<>();
private List<TestStepsListResponse.Datum> testPlans = new ArrayList<>();
//Timer
private boolean running;
private int stepIndex = 1;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
//Inflate the layout using LayoutInflater
LayoutInflater li = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
floatingLayout = (ConstraintLayout) li.inflate(R.layout.service_floating_layout, null);
//Init view
initUi();
//Set layout params to display the controls over any screen.
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
// From API26, TYPE_PHONE deprecated. Use TYPE_APPLICATION_OVERLAY for O
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
params.type = WindowManager.LayoutParams.TYPE_PHONE;
//Initial position of the floating controls
params.gravity = Gravity.BOTTOM | Gravity.START;
params.x = 0;
params.y = 0;
//Add the controls view to windowManager
windowManager.addView(floatingLayout, params);
//Steps
testPlans = App.testPlansList;
for (int i = 0; i < testPlans.size(); i++) {
if (testPlans.get(i).getItemType().equals(ConstKeys.TEST_STEP_TEXT_RESPONSE)) {
StepDynamicEdt stepDynamicTxt = new StepDynamicEdt(testPlans.get(i).getTitle(), testPlans.get(i).getDesc());
// add to list
steps.add(stepDynamicTxt);
intList.add(i);
} else {
StepDynamicTxt stepDynamicEdt = new StepDynamicTxt(testPlans.get(i).getTitle(), testPlans.get(i).getDesc());
// add to list
steps.add(stepDynamicEdt);
}
}
floatingLay_stepper.setup(this, steps)
.allowNonLinearNavigation(false)
.displayCancelButtonInLastStep(false)
.displayBottomNavigation(false)
.confirmationStepTitle("OK")
.stepNextButtonText("Next")
.lastStepNextButtonText("Finish")
.includeConfirmationStep(false)
.init();
return START_STICKY;
}
StepDynamicEdt class codes:
public class StepDynamicEdt extends Step<String> {
private static final int MIN_CHARACTERS = 1;
private EditText editText;
private String errorMessage;
public StepDynamicEdt(String title) {
this(title, "");
}
public StepDynamicEdt(String title, String subtitle) {
super(title, subtitle);
}
@NonNull
@Override
protected View createStepContentLayout() {
//Create view programmatically
editText = new EditText(getContext());
editText.setHint("User name");
editText.setSingleLine(true);
editText.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) {
markAsCompletedOrUncompleted(true);
}
@Override
public void afterTextChanged(Editable s) {
}
});
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
getFormView().goToNextStep(true);
return false;
}
});
errorMessage = "Insert 1 character";
return editText;
}
@Override
public String getStepData() {
Editable text = editText.getText();
if (text != null) {
return text.toString();
}
return "";
}
@Override
public String getStepDataAsHumanReadableString() {
String name = getStepData();
return name == null || name.isEmpty() ? "Empty" : name;
}
@Override
public void restoreStepData(String data) {
if (editText != null) {
editText.setText(data);
}
}
@Override
protected IsDataValid isStepDataValid(String stepData) {
if (stepData.length() < MIN_CHARACTERS) {
return new IsDataValid(false, errorMessage);
} else {
return new IsDataValid(true);
}
}
@Override
protected void onStepOpened(boolean animated) {
// No need to do anything here
}
@Override
protected void onStepClosed(boolean animated) {
// No need to do anything here
}
@Override
protected void onStepMarkedAsCompleted(boolean animated) {
// No need to do anything here
}
@Override
protected void onStepMarkedAsUncompleted(boolean animated) {
// No need to do anything here
}
}
Update : I added below code into StepDynamicEdt class, but again not open keyboard!
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(
Context.INPUT_METHOD_SERVICE);
Objects.requireNonNull(imm).showSoftInput(editText, 0);
How can i fix it and open keyboard into service ?