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:
parent
8466b14d8f
commit
22afe8ac5f
@ -22,6 +22,9 @@
|
|||||||
|
|
||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
|
import org.solovyev.android.Check;
|
||||||
|
import org.solovyev.android.calculator.floating.FloatingCalculatorService;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
@ -54,9 +57,6 @@ import android.view.ViewGroup;
|
|||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
|
|
||||||
import org.solovyev.android.Check;
|
|
||||||
import org.solovyev.android.calculator.floating.FloatingCalculatorService;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
@ -283,6 +283,33 @@ public final class App {
|
|||||||
processViewsOfType0(view, viewClass, viewProcessor);
|
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
|
@Nonnull
|
||||||
public static <T> ArrayAdapter<T> makeSimpleSpinnerAdapter(@NonNull Context context) {
|
public static <T> ArrayAdapter<T> makeSimpleSpinnerAdapter(@NonNull Context context) {
|
||||||
return new ArrayAdapter<>(context, R.layout.support_simple_spinner_dropdown_item);
|
return new ArrayAdapter<>(context, R.layout.support_simple_spinner_dropdown_item);
|
||||||
|
@ -22,6 +22,11 @@
|
|||||||
|
|
||||||
package org.solovyev.android.calculator.functions;
|
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.annotation.TargetApi;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
@ -36,18 +41,19 @@ import android.view.Gravity;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.inputmethod.EditorInfo;
|
import android.view.inputmethod.EditorInfo;
|
||||||
import android.widget.*;
|
import android.widget.EditText;
|
||||||
import org.solovyev.android.Check;
|
import android.widget.ImageButton;
|
||||||
import org.solovyev.android.calculator.App;
|
import android.widget.ImageView;
|
||||||
import org.solovyev.android.calculator.Preferences;
|
import android.widget.LinearLayout;
|
||||||
import org.solovyev.android.calculator.R;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
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.MATCH_PARENT;
|
||||||
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
|
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
|
||||||
|
|
||||||
@ -278,11 +284,9 @@ public class FunctionParamsView extends LinearLayout {
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
private EditText getParamView(@Nonnull ViewGroup row) {
|
private EditText getParamView(@Nonnull ViewGroup row) {
|
||||||
final TextInputLayout paramLabel = getParamLabel(row);
|
final TextInputLayout paramLabel = getParamLabel(row);
|
||||||
for (int i = 0; i < paramLabel.getChildCount(); i++) {
|
final EditText paramView = App.find(paramLabel, EditText.class);
|
||||||
final View child = paramLabel.getChildAt(i);
|
if (paramView != null) {
|
||||||
if (child instanceof EditText) {
|
return paramView;
|
||||||
return (EditText) child;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Check.shouldNotHappen();
|
Check.shouldNotHappen();
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user