Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
Fix NullPointerException occurring on Meizu devices
Browse files Browse the repository at this point in the history
  • Loading branch information
farhan committed May 23, 2019
1 parent 2e7cf8a commit 5d54117
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions OpenEdXMobile/res/layout/activity_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
android:paddingStart="-4dp"
android:textColorHint="@color/grey_text">

<android.support.design.widget.TextInputEditText
<android.support.v7.widget.AppCompatEditText
android:id="@+id/email_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand All @@ -91,7 +91,7 @@
android:paddingStart="-4dp"
android:textColorHint="@color/grey_text">

<android.support.design.widget.TextInputEditText
<android.support.v7.widget.AppCompatEditText
android:id="@+id/password_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
2 changes: 1 addition & 1 deletion OpenEdXMobile/res/layout/reset_password_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
android:hint="@string/email"
app:errorEnabled="true">

<android.support.design.widget.TextInputEditText
<android.support.v7.widget.AppCompatEditText
android:id="@+id/email_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Expand Down
2 changes: 1 addition & 1 deletion OpenEdXMobile/res/layout/view_register_edit_text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
android:layout_height="wrap_content"
android:textColorHint="@color/grey_text">

<android.support.design.widget.TextInputEditText
<android.support.v7.widget.AppCompatEditText
android:id="@+id/register_edit_text_tilEt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.edx.mobile.module.registration.view;

import android.support.annotation.Nullable;
import android.support.design.widget.TextInputEditText;
import android.support.design.widget.TextInputLayout;
import android.support.v4.view.ViewCompat;
import android.support.v7.widget.AppCompatEditText;
import android.text.Editable;
import android.text.Html;
import android.text.InputFilter;
Expand All @@ -26,7 +26,7 @@ public class RegistrationEditTextView implements IRegistrationFieldView {
protected RegistrationFormField mField;
private View mView;
protected TextInputLayout mTextInputLayout;
protected TextInputEditText mTextInputEditText;
protected AppCompatEditText mEditText;
protected TextView mInstructionsTextView;
protected TextView mErrorTextView;

Expand All @@ -36,20 +36,20 @@ public RegistrationEditTextView(RegistrationFormField field, View view) {
this.mView = view;

mTextInputLayout = (TextInputLayout) view.findViewById(R.id.register_edit_text_til);
mTextInputEditText = (TextInputEditText) view.findViewById(R.id.register_edit_text_tilEt);
mEditText = (AppCompatEditText) view.findViewById(R.id.register_edit_text_tilEt);
mInstructionsTextView = (TextView) view.findViewById(R.id.input_instructions);
mErrorTextView = (TextView) view.findViewById(R.id.input_error);

// set max lines for this input to be 1
mTextInputEditText.setLines(1);
mEditText.setLines(1);

// apply max length
if (mField.getRestriction().getMaxLength() > 0) {
// otherwise, you may end up disabling the field

InputFilter[] FilterArray = new InputFilter[1];
FilterArray[0] = new InputFilter.LengthFilter(mField.getRestriction().getMaxLength());
mTextInputEditText.setFilters(FilterArray);
mEditText.setFilters(FilterArray);
}

setInstructions(field.getInstructions());
Expand All @@ -58,7 +58,7 @@ public RegistrationEditTextView(RegistrationFormField field, View view) {
mTextInputLayout.setHint(mField.getLabel());

// set default
mTextInputEditText.setText(mField.getDefaultValue());
mEditText.setText(mField.getDefaultValue());

// hide error text view
mErrorTextView.setVisibility(View.GONE);
Expand All @@ -68,11 +68,11 @@ public RegistrationEditTextView(RegistrationFormField field, View view) {

// Do a11y adjustment
mTextInputLayout.setContentDescription(String.format("%s. %s.", mField.getLabel(), field.getInstructions()));
mTextInputEditText.setContentDescription(mField.getLabel());
mEditText.setContentDescription(mField.getLabel());
ViewCompat.setImportantForAccessibility(mInstructionsTextView, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO);

// Add text change listener
mTextInputEditText.addTextChangedListener(new TextWatcher() {
mEditText.addTextChangedListener(new TextWatcher() {
/*
TextWatcher events also trigger at time of registration of this listener. Which we
don't want in this case. So, to handle it, a flag is required to check if the text
Expand Down Expand Up @@ -102,19 +102,19 @@ public void afterTextChanged(Editable s) {
}

public boolean setRawValue(String value){
mTextInputEditText.setText(value);
mEditText.setText(value);
return true;
}

@Override
public JsonElement getCurrentValue() {
// turn text view content into a JsonElement and return it
return new JsonPrimitive(mTextInputEditText.getText().toString());
return new JsonPrimitive(mEditText.getText().toString());
}

@Override
public boolean hasValue() {
return !mTextInputEditText.getText().toString().isEmpty();
return !mEditText.getText().toString().isEmpty();
}

@Override
Expand Down Expand Up @@ -210,8 +210,8 @@ public void setActionListener(IActionListener actionListener) {
}

public void setEditTextFocusable(boolean focusable) {
mTextInputEditText.setFocusable(focusable);
mTextInputEditText.setFocusableInTouchMode(focusable);
mEditText.setFocusable(focusable);
mEditText.setFocusableInTouchMode(focusable);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class RegistrationEmailView extends RegistrationEditTextView {

public RegistrationEmailView(RegistrationFormField field, View view) {
super(field, view);
mTextInputEditText.setInputType(InputType.TYPE_CLASS_TEXT
mEditText.setInputType(InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class RegistrationPasswordView extends RegistrationEditTextView {

public RegistrationPasswordView(RegistrationFormField field, View view) {
super(field, view);
mTextInputEditText.setInputType(InputType.TYPE_CLASS_TEXT
mEditText.setInputType(InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_VARIATION_PASSWORD
| InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ class RegistrationTextAreaView extends RegistrationEditTextView {
public RegistrationTextAreaView(RegistrationFormField field, View view) {
super(field, view);

mTextInputEditText.setLines(INIT_LINES);
mTextInputEditText.setMaxLines(MAX_LINES);
mEditText.setLines(INIT_LINES);
mEditText.setMaxLines(MAX_LINES);

// allow multiline text
mTextInputEditText.setInputType(InputType.TYPE_CLASS_TEXT
mEditText.setInputType(InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_FLAG_MULTI_LINE);
// text should start from the left-top
mTextInputEditText.setGravity(Gravity.START | Gravity.TOP);
mEditText.setGravity(Gravity.START | Gravity.TOP);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class RegistrationTextView extends RegistrationEditTextView {

public RegistrationTextView(RegistrationFormField field, View view) {
super(field, view);
mTextInputEditText.setInputType(InputType.TYPE_CLASS_TEXT);
mEditText.setInputType(InputType.TYPE_CLASS_TEXT);
}
}

0 comments on commit 5d54117

Please sign in to comment.