Search in sources :

Example 11 with EditText

use of android.widget.EditText in project cordova-android-chromeview by thedracle.

the class CordovaChromeClient method onJsPrompt.

/**
     * Tell the client to display a prompt dialog to the user.
     * If the client returns true, WebView will assume that the client will
     * handle the prompt dialog and call the appropriate JsPromptResult method.
     *
     * Since we are hacking prompts for our own purposes, we should not be using them for
     * this purpose, perhaps we should hack console.log to do this instead!
     *
     * @param view
     * @param url
     * @param message
     * @param defaultValue
     * @param result
     */
@Override
public boolean onJsPrompt(ChromeView view, String url, String message, String defaultValue, JsPromptResult result) {
    // Security check to make sure any requests are coming from the page initially
    // loaded in webview and not another loaded in an iframe.
    boolean reqOk = false;
    if (url.startsWith("file://") || Config.isUrlWhiteListed(url)) {
        reqOk = true;
    }
    // prompt(this.stringify(args), "gap:"+this.stringify([service, action, callbackId, true]));
    if (reqOk && defaultValue != null && defaultValue.length() > 3 && defaultValue.substring(0, 4).equals("gap:")) {
        JSONArray array;
        try {
            array = new JSONArray(defaultValue.substring(4));
            String service = array.getString(0);
            String action = array.getString(1);
            String callbackId = array.getString(2);
            String r = this.appView.exposedJsApi.exec(service, action, callbackId, message);
            result.confirm(r == null ? "" : r);
        } catch (JSONException e) {
            e.printStackTrace();
            return false;
        }
    } else // Sets the native->JS bridge mode. 
    if (reqOk && defaultValue != null && defaultValue.equals("gap_bridge_mode:")) {
        this.appView.exposedJsApi.setNativeToJsBridgeMode(Integer.parseInt(message));
        result.confirm("");
    } else // Polling for JavaScript messages 
    if (reqOk && defaultValue != null && defaultValue.equals("gap_poll:")) {
        String r = this.appView.exposedJsApi.retrieveJsMessages();
        result.confirm(r == null ? "" : r);
    } else // Do NO-OP so older code doesn't display dialog
    if (defaultValue != null && defaultValue.equals("gap_init:")) {
        result.confirm("OK");
    } else // Show dialog
    {
        final JsPromptResult res = result;
        AlertDialog.Builder dlg = new AlertDialog.Builder(this.cordova.getActivity());
        dlg.setMessage(message);
        final EditText input = new EditText(this.cordova.getActivity());
        if (defaultValue != null) {
            input.setText(defaultValue);
        }
        dlg.setView(input);
        dlg.setCancelable(false);
        dlg.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                String usertext = input.getText().toString();
                res.confirm(usertext);
            }
        });
        dlg.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                res.cancel();
            }
        });
        dlg.create();
        dlg.show();
    }
    return true;
}
Also used : AlertDialog(android.app.AlertDialog) EditText(android.widget.EditText) DialogInterface(android.content.DialogInterface) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) JsPromptResult(android.webkit.JsPromptResult)

Example 12 with EditText

use of android.widget.EditText in project platform_frameworks_base by android.

the class NekoLand method showNameDialog.

private void showNameDialog(final Cat cat) {
    final Context context = new ContextThemeWrapper(this, android.R.style.Theme_Material_Light_Dialog_NoActionBar);
    // TODO: Move to XML, add correct margins.
    View view = LayoutInflater.from(context).inflate(R.layout.edit_text, null);
    final EditText text = (EditText) view.findViewById(android.R.id.edit);
    text.setText(cat.getName());
    text.setSelection(cat.getName().length());
    final int size = context.getResources().getDimensionPixelSize(android.R.dimen.app_icon_size);
    Drawable catIcon = cat.createIcon(this, size, size).loadDrawable(this);
    new AlertDialog.Builder(context).setTitle(" ").setIcon(catIcon).setView(view).setPositiveButton(android.R.string.ok, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            cat.logRename(context);
            cat.setName(text.getText().toString().trim());
            mPrefs.addCat(cat);
        }
    }).show();
}
Also used : Context(android.content.Context) EditText(android.widget.EditText) AlertDialog(android.app.AlertDialog) ContextThemeWrapper(android.view.ContextThemeWrapper) DialogInterface(android.content.DialogInterface) Drawable(android.graphics.drawable.Drawable) OnClickListener(android.content.DialogInterface.OnClickListener) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView)

Example 13 with EditText

use of android.widget.EditText in project platform_frameworks_base by android.

the class ChangeText method captureValues.

private void captureValues(TransitionValues transitionValues) {
    if (transitionValues.view instanceof TextView) {
        TextView textview = (TextView) transitionValues.view;
        transitionValues.values.put(PROPNAME_TEXT, textview.getText());
        if (textview instanceof EditText) {
            transitionValues.values.put(PROPNAME_TEXT_SELECTION_START, textview.getSelectionStart());
            transitionValues.values.put(PROPNAME_TEXT_SELECTION_END, textview.getSelectionEnd());
        }
        if (mChangeBehavior > CHANGE_BEHAVIOR_KEEP) {
            transitionValues.values.put(PROPNAME_TEXT_COLOR, textview.getCurrentTextColor());
        }
    }
}
Also used : EditText(android.widget.EditText) TextView(android.widget.TextView)

Example 14 with EditText

use of android.widget.EditText in project platform_frameworks_base by android.

the class ChangeText method createAnimator.

@Override
public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
    if (startValues == null || endValues == null || !(startValues.view instanceof TextView) || !(endValues.view instanceof TextView)) {
        return null;
    }
    final TextView view = (TextView) endValues.view;
    Map<String, Object> startVals = startValues.values;
    Map<String, Object> endVals = endValues.values;
    final CharSequence startText = startVals.get(PROPNAME_TEXT) != null ? (CharSequence) startVals.get(PROPNAME_TEXT) : "";
    final CharSequence endText = endVals.get(PROPNAME_TEXT) != null ? (CharSequence) endVals.get(PROPNAME_TEXT) : "";
    final int startSelectionStart, startSelectionEnd, endSelectionStart, endSelectionEnd;
    if (view instanceof EditText) {
        startSelectionStart = startVals.get(PROPNAME_TEXT_SELECTION_START) != null ? (Integer) startVals.get(PROPNAME_TEXT_SELECTION_START) : -1;
        startSelectionEnd = startVals.get(PROPNAME_TEXT_SELECTION_END) != null ? (Integer) startVals.get(PROPNAME_TEXT_SELECTION_END) : startSelectionStart;
        endSelectionStart = endVals.get(PROPNAME_TEXT_SELECTION_START) != null ? (Integer) endVals.get(PROPNAME_TEXT_SELECTION_START) : -1;
        endSelectionEnd = endVals.get(PROPNAME_TEXT_SELECTION_END) != null ? (Integer) endVals.get(PROPNAME_TEXT_SELECTION_END) : endSelectionStart;
    } else {
        startSelectionStart = startSelectionEnd = endSelectionStart = endSelectionEnd = -1;
    }
    if (!startText.equals(endText)) {
        final int startColor;
        final int endColor;
        if (mChangeBehavior != CHANGE_BEHAVIOR_IN) {
            view.setText(startText);
            if (view instanceof EditText) {
                setSelection(((EditText) view), startSelectionStart, startSelectionEnd);
            }
        }
        Animator anim;
        if (mChangeBehavior == CHANGE_BEHAVIOR_KEEP) {
            startColor = endColor = 0;
            anim = ValueAnimator.ofFloat(0, 1);
            anim.addListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator animation) {
                    if (startText.equals(view.getText())) {
                        // Only set if it hasn't been changed since anim started
                        view.setText(endText);
                        if (view instanceof EditText) {
                            setSelection(((EditText) view), endSelectionStart, endSelectionEnd);
                        }
                    }
                }
            });
        } else {
            startColor = (Integer) startVals.get(PROPNAME_TEXT_COLOR);
            endColor = (Integer) endVals.get(PROPNAME_TEXT_COLOR);
            // Fade out start text
            ValueAnimator outAnim = null, inAnim = null;
            if (mChangeBehavior == CHANGE_BEHAVIOR_OUT_IN || mChangeBehavior == CHANGE_BEHAVIOR_OUT) {
                outAnim = ValueAnimator.ofInt(255, 0);
                outAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        int currAlpha = (Integer) animation.getAnimatedValue();
                        view.setTextColor(currAlpha << 24 | startColor & 0xff0000 | startColor & 0xff00 | startColor & 0xff);
                    }
                });
                outAnim.addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        if (startText.equals(view.getText())) {
                            // Only set if it hasn't been changed since anim started
                            view.setText(endText);
                            if (view instanceof EditText) {
                                setSelection(((EditText) view), endSelectionStart, endSelectionEnd);
                            }
                        }
                        // restore opaque alpha and correct end color
                        view.setTextColor(endColor);
                    }
                });
            }
            if (mChangeBehavior == CHANGE_BEHAVIOR_OUT_IN || mChangeBehavior == CHANGE_BEHAVIOR_IN) {
                inAnim = ValueAnimator.ofInt(0, 255);
                inAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        int currAlpha = (Integer) animation.getAnimatedValue();
                        view.setTextColor(currAlpha << 24 | Color.red(endColor) << 16 | Color.green(endColor) << 8 | Color.red(endColor));
                    }
                });
                inAnim.addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationCancel(Animator animation) {
                        // restore opaque alpha and correct end color
                        view.setTextColor(endColor);
                    }
                });
            }
            if (outAnim != null && inAnim != null) {
                anim = new AnimatorSet();
                ((AnimatorSet) anim).playSequentially(outAnim, inAnim);
            } else if (outAnim != null) {
                anim = outAnim;
            } else {
                // Must be an in-only animation
                anim = inAnim;
            }
        }
        TransitionListener transitionListener = new TransitionListenerAdapter() {

            int mPausedColor = 0;

            @Override
            public void onTransitionPause(Transition transition) {
                if (mChangeBehavior != CHANGE_BEHAVIOR_IN) {
                    view.setText(endText);
                    if (view instanceof EditText) {
                        setSelection(((EditText) view), endSelectionStart, endSelectionEnd);
                    }
                }
                if (mChangeBehavior > CHANGE_BEHAVIOR_KEEP) {
                    mPausedColor = view.getCurrentTextColor();
                    view.setTextColor(endColor);
                }
            }

            @Override
            public void onTransitionResume(Transition transition) {
                if (mChangeBehavior != CHANGE_BEHAVIOR_IN) {
                    view.setText(startText);
                    if (view instanceof EditText) {
                        setSelection(((EditText) view), startSelectionStart, startSelectionEnd);
                    }
                }
                if (mChangeBehavior > CHANGE_BEHAVIOR_KEEP) {
                    view.setTextColor(mPausedColor);
                }
            }
        };
        addListener(transitionListener);
        if (DBG) {
            Log.d(LOG_TAG, "createAnimator returning " + anim);
        }
        return anim;
    }
    return null;
}
Also used : EditText(android.widget.EditText) AnimatorSet(android.animation.AnimatorSet) ValueAnimator(android.animation.ValueAnimator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) TextView(android.widget.TextView)

Example 15 with EditText

use of android.widget.EditText in project AsmackService by rtreffer.

the class AuthenticatorActivity method onCreate.

/**
     * Create an AuthenticatorActivity based on a bundle.
     */
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    accountManager = AccountManager.get(this);
    final Intent intent = getIntent();
    String username = intent.getStringExtra(PARAM_USERNAME);
    requestWindowFeature(Window.FEATURE_LEFT_ICON);
    setContentView(com.googlecode.asmack.R.layout.authenticator_activity);
    getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, android.R.drawable.ic_dialog_alert);
    EditText usernameEdit = (EditText) findViewById(R.id.username_edit);
    usernameEdit.setText(username);
}
Also used : EditText(android.widget.EditText) Intent(android.content.Intent)

Aggregations

EditText (android.widget.EditText)655 View (android.view.View)309 TextView (android.widget.TextView)220 DialogInterface (android.content.DialogInterface)143 AlertDialog (android.app.AlertDialog)126 Button (android.widget.Button)126 Intent (android.content.Intent)99 LinearLayout (android.widget.LinearLayout)79 ImageView (android.widget.ImageView)61 AlertDialog (android.support.v7.app.AlertDialog)54 ScrollView (android.widget.ScrollView)52 LayoutInflater (android.view.LayoutInflater)48 AdapterView (android.widget.AdapterView)46 ViewGroup (android.view.ViewGroup)42 Editable (android.text.Editable)41 Context (android.content.Context)40 RecyclerView (android.support.v7.widget.RecyclerView)40 ListView (android.widget.ListView)39 Dialog (android.app.Dialog)36 Bundle (android.os.Bundle)36