diff options
Diffstat (limited to 'app/src/main/java/app/fedilab/android/imageeditor/TextEditorDialogFragment.java')
-rw-r--r-- | app/src/main/java/app/fedilab/android/imageeditor/TextEditorDialogFragment.java | 61 |
1 files changed, 29 insertions, 32 deletions
diff --git a/app/src/main/java/app/fedilab/android/imageeditor/TextEditorDialogFragment.java b/app/src/main/java/app/fedilab/android/imageeditor/TextEditorDialogFragment.java index e65dcd382..e366618a7 100644 --- a/app/src/main/java/app/fedilab/android/imageeditor/TextEditorDialogFragment.java +++ b/app/src/main/java/app/fedilab/android/imageeditor/TextEditorDialogFragment.java @@ -32,10 +32,9 @@ import app.fedilab.android.R; public class TextEditorDialogFragment extends DialogFragment { public static final String TAG = TextEditorDialogFragment.class.getSimpleName(); - public static final String EXTRA_INPUT_TEXT = "extra_input_text"; - public static final String EXTRA_COLOR_CODE = "extra_color_code"; + private static final String EXTRA_INPUT_TEXT = "extra_input_text"; + private static final String EXTRA_COLOR_CODE = "extra_color_code"; private EditText mAddTextEditText; - private TextView mAddTextDoneTextView; private InputMethodManager mInputMethodManager; private int mColorCode; private TextEditor mTextEditor; @@ -64,7 +63,7 @@ public class TextEditorDialogFragment extends DialogFragment { super.onStart(); Dialog dialog = getDialog(); //Make dialog full screen with transparent background - if (dialog != null) { + if (dialog != null && dialog.getWindow() != null) { int width = ViewGroup.LayoutParams.MATCH_PARENT; int height = ViewGroup.LayoutParams.MATCH_PARENT; dialog.getWindow().setLayout(width, height); @@ -82,41 +81,39 @@ public class TextEditorDialogFragment extends DialogFragment { public void onViewCreated(@NotNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mAddTextEditText = view.findViewById(R.id.add_text_edit_text); - mInputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); - mAddTextDoneTextView = view.findViewById(R.id.add_text_done_tv); - - //Setup the color picker for text color - RecyclerView addTextColorPickerRecyclerView = view.findViewById(R.id.add_text_color_picker_recycler_view); - LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false); - addTextColorPickerRecyclerView.setLayoutManager(layoutManager); - addTextColorPickerRecyclerView.setHasFixedSize(true); - ColorPickerAdapter colorPickerAdapter = new ColorPickerAdapter(getActivity()); - //This listener will change the text color when clicked on any color from picker - colorPickerAdapter.setOnColorPickerClickListener(new ColorPickerAdapter.OnColorPickerClickListener() { - @Override - public void onColorPickerClickListener(int colorCode) { + if (getActivity() != null) { + mInputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); + TextView mAddTextDoneTextView = view.findViewById(R.id.add_text_done_tv); + + + //Setup the color picker for text color + RecyclerView addTextColorPickerRecyclerView = view.findViewById(R.id.add_text_color_picker_recycler_view); + LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false); + addTextColorPickerRecyclerView.setLayoutManager(layoutManager); + addTextColorPickerRecyclerView.setHasFixedSize(true); + ColorPickerAdapter colorPickerAdapter = new ColorPickerAdapter(getActivity()); + //This listener will change the text color when clicked on any color from picker + colorPickerAdapter.setOnColorPickerClickListener(colorCode -> { mColorCode = colorCode; mAddTextEditText.setTextColor(colorCode); - } - }); - addTextColorPickerRecyclerView.setAdapter(colorPickerAdapter); - mAddTextEditText.setText(getArguments().getString(EXTRA_INPUT_TEXT)); - mColorCode = getArguments().getInt(EXTRA_COLOR_CODE); - mAddTextEditText.setTextColor(mColorCode); - mInputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); - - //Make a callback on activity when user is done with text editing - mAddTextDoneTextView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - mInputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); + }); + addTextColorPickerRecyclerView.setAdapter(colorPickerAdapter); + assert getArguments() != null; + mAddTextEditText.setText(getArguments().getString(EXTRA_INPUT_TEXT)); + mColorCode = getArguments().getInt(EXTRA_COLOR_CODE); + mAddTextEditText.setTextColor(mColorCode); + mInputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); + + //Make a callback on activity when user is done with text editing + mAddTextDoneTextView.setOnClickListener(view1 -> { + mInputMethodManager.hideSoftInputFromWindow(view1.getWindowToken(), 0); dismiss(); String inputText = mAddTextEditText.getText().toString(); if (!TextUtils.isEmpty(inputText) && mTextEditor != null) { mTextEditor.onDone(inputText, mColorCode); } - } - }); + }); + } } |