Don't crash on function save

Internals of TextInputLayout have changed and EditText
now is not on the first level
This commit is contained in:
serso 2016-08-21 12:24:34 +02:00
parent 8466b14d8f
commit 22afe8ac5f
2 changed files with 46 additions and 15 deletions

View File

@ -22,6 +22,9 @@
package org.solovyev.android.calculator;
import org.solovyev.android.Check;
import org.solovyev.android.calculator.floating.FloatingCalculatorService;
import android.app.Activity;
import android.app.Application;
import android.app.Dialog;
@ -54,9 +57,6 @@ import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.ArrayAdapter;
import org.solovyev.android.Check;
import org.solovyev.android.calculator.floating.FloatingCalculatorService;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
@ -283,6 +283,33 @@ public final class App {
processViewsOfType0(view, viewClass, viewProcessor);
}
@Nullable
public static <T> T find(@Nonnull View view, @Nonnull Class<T> viewClass) {
return find0(view, viewClass);
}
private static <T> T find0(View view, Class<T> viewClass) {
if (view instanceof ViewGroup) {
final ViewGroup viewGroup = (ViewGroup) view;
if (viewClass.isAssignableFrom(ViewGroup.class)) {
//noinspection unchecked
return (T) view;
}
for (int index = 0; index < viewGroup.getChildCount(); index++) {
final T child = find0(viewGroup.getChildAt(index), viewClass);
if (child != null) {
return child;
}
}
} else if (viewClass.isAssignableFrom(view.getClass())) {
//noinspection unchecked
return (T) view;
}
return null;
}
@Nonnull
public static <T> ArrayAdapter<T> makeSimpleSpinnerAdapter(@NonNull Context context) {
return new ArrayAdapter<>(context, R.layout.support_simple_spinner_dropdown_item);

View File

@ -22,6 +22,11 @@
package org.solovyev.android.calculator.functions;
import org.solovyev.android.Check;
import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.Preferences;
import org.solovyev.android.calculator.R;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Resources;
@ -36,18 +41,19 @@ import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.*;
import org.solovyev.android.Check;
import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.Preferences;
import org.solovyev.android.calculator.R;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
@ -278,11 +284,9 @@ public class FunctionParamsView extends LinearLayout {
@Nonnull
private EditText getParamView(@Nonnull ViewGroup row) {
final TextInputLayout paramLabel = getParamLabel(row);
for (int i = 0; i < paramLabel.getChildCount(); i++) {
final View child = paramLabel.getChildAt(i);
if (child instanceof EditText) {
return (EditText) child;
}
final EditText paramView = App.find(paramLabel, EditText.class);
if (paramView != null) {
return paramView;
}
Check.shouldNotHappen();
return null;