Example usage for android.widget EditText EditText

List of usage examples for android.widget EditText EditText

Introduction

In this page you can find the example usage for android.widget EditText EditText.

Prototype

public EditText(Context context) 

Source Link

Usage

From source file:jp.gr.java_conf.ya.shiobeforandroid3.UpdateTweetDrive.java

private final void simpleauth() {
    // Password?/*from   ww  w  . j ava2  s .  c  o m*/
    pref_app = PreferenceManager.getDefaultSharedPreferences(this);
    final String pref_appPassword = pref_app.getString("pref_appPassword", "");
    if (pref_appPassword.equals("") == false) {
        WriteLog.write(this, "(pref_appPassword.equals(\"\") == false)");
        final EditText editView = new EditText(UpdateTweetDrive.this);
        new AlertDialog.Builder(UpdateTweetDrive.this).setIcon(android.R.drawable.ic_dialog_info)
                .setTitle(R.string.enter_password).setView(editView)
                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    @Override
                    public final void onClick(final DialogInterface dialog, final int whichButton) {
                        if (editView.getText().toString().equals(pref_appPassword) == false) {
                            WriteLog.write(UpdateTweetDrive.this,
                                    getString(R.string.wrong_password) + ": " + editView.getText().toString());
                            finish();
                        }
                    }
                }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public final void onClick(final DialogInterface dialog, final int whichButton) {
                        WriteLog.write(UpdateTweetDrive.this, getString(R.string.cancelled));
                        finish();
                    }
                }).show();
    }
}

From source file:com.xrmaddness.offthegrid.ListActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {

    case R.id.action_settings:

        Intent intent = new Intent(this, SettingsActivity.class);
        startActivityForResult(intent, SETTINGS_DONE);

        return true;

    case R.id.action_my_fingerprint: {
        String fingerprint;//from   www .j  a va 2  s .  c  o  m
        if (pgp == null) {
            fingerprint = "No keys available, fill in email address first in settings";
        } else {
            fingerprint = pgp.fingerprint(pgp.my_user_id);
            if (fingerprint == null) {
                fingerprint = "No key found";
            }
        }

        AlertDialog.Builder alert = new AlertDialog.Builder(this);

        alert.setMessage(fingerprint);
        alert.setTitle(R.string.action_my_fingerprint);
        alert.setPositiveButton("OK", null);
        alert.setCancelable(true);
        alert.create().show();

        return true;
    }

    case R.id.action_add_contact: {
        if (pgp == null)
            return true;

        AlertDialog.Builder alert = new AlertDialog.Builder(this);

        alert.setTitle(R.string.action_add_contact);
        alert.setMessage(R.string.dialog_add_contact);

        // Set an EditText view to get user input 
        final EditText input = new EditText(this);
        input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
        alert.setView(input);

        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                String value = input.getText().toString();

                Log.d("add_contact", value);
                add_contact(value);
            }
        });

        alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
            }
        });

        alert.show();
        return true;
    }
    case R.id.action_add_group: {
        if (pgp == null)
            return true;

        AlertDialog.Builder alert = new AlertDialog.Builder(this);

        alert.setTitle(R.string.action_add_group);
        alert.setMessage(R.string.dialog_add_group);

        // Set an EditText view to get user input 
        final EditText input = new EditText(this);
        input.setInputType(InputType.TYPE_CLASS_TEXT);
        alert.setView(input);

        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                String value = input.getText().toString();

                Log.d("add_group", value);
                add_group(value);
            }
        });

        alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
            }
        });

        alert.show();
        return true;
    }

    case R.id.action_show_license: {
        String license = version_get() + "\n";

        AssetManager am = getAssets();
        InputStream is;
        try {
            is = am.open("license.txt");
            license += filestring.is2str(is);
            is.close();

            is = am.open("spongycastle_license.txt");
            license += filestring.is2str(is);
            is.close();

            is = am.open("javamail_license.txt");
            license += filestring.is2str(is);
            is.close();
        } catch (IOException e) {
            Log.e("show license", e.getMessage());
        }

        AlertDialog.Builder alert = new AlertDialog.Builder(this);

        alert.setMessage(license);
        alert.setTitle(R.string.action_show_license);
        alert.setPositiveButton("OK", null);
        alert.setCancelable(true);
        alert.create().show();

        return true;

    }

    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.googlecode.android_scripting.activity.ScriptManager.java

private void rename(final File file) {
    final EditText newName = new EditText(this);
    newName.setText(file.getName());// w  ww .  ja  va  2 s  .com
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle(getString(R.string.s_Rename));
    alert.setView(newName);
    alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            String name = newName.getText().toString();
            if (name.length() == 0) {
                Log.e(ScriptManager.this, getString(R.string.s_Nameempty));
                return;
            } else {
                for (File f : mScripts) {
                    if (f.getName().equals(name)) {
                        Log.e(ScriptManager.this, String.format(getString(R.string.s_Exists), name));
                        return;
                    }
                }
            }
            if (!FileUtils.rename(file, name)) {
                throw new RuntimeException(String.format(getString(R.string.s_Cannotrename), file.getPath()));
            }
            mAdapter.notifyDataSetInvalidated();
        }
    });
    alert.show();
}

From source file:com.ccxt.whl.activity.SettingsFragment.java

/**
 * /* w ww . j  a  v a 2  s  . co  m*/
 */
public void change_age(String age) {

    final EditText texta = new EditText(getActivity());
    texta.setText(age);
    //EditText
    texta.setKeyListener(new NumberKeyListener() {
        public int getInputType() {
            return InputType.TYPE_CLASS_PHONE;
        }

        @Override
        protected char[] getAcceptedChars() {
            // TODO Auto-generated method stub
            char[] numbers = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
            return numbers;
        }
    });
    new AlertDialog.Builder(getActivity()).setTitle("")
            .setIcon(android.R.drawable.ic_dialog_info).setView(texta)
            .setPositiveButton("", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    String age = texta.getEditableText().toString();
                    RequestParams params = new RequestParams();

                    params.add("user", DemoApplication.getInstance().getUser());
                    params.add("age", age);
                    params.add("param", "age");
                    params.add("uid", uid);
                    HttpRestClient.get(Constant.UPDATE_USER_URL, params, responseHandler);
                    pd.show();
                    dialog.dismiss();
                    //?  
                }
            }).setNegativeButton("?", null).show();
    //return true; 
}

From source file:com.raspi.chatapp.ui.chatting.ChatFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    // if clicked attach perform the onAttackClicked. Easy.
    case R.id.action_attach:
        init = true;//w ww. j av a 2  s  . c  om
        mListener.onAttachClicked(getActivity().findViewById(R.id.action_attach));
        return true;
    // if clicked rename open the dialog where the user can rename this chat
    case R.id.action_rename:
        // this will be the shown editText (without emojicons, I might wanna
        // change this in the future, let's see)
        final EditText newName = new EditText(getActivity());
        // prefix the EditText with the current name
        newName.setText(chatName);
        // the title comes from the resources and will include the current
        // chatName
        String title = getResources().getString(R.string.change_name_title) + " " + chatName;
        new AlertDialog.Builder(getContext()).setTitle(title).setMessage(R.string.change_name).setView(newName)
                .setPositiveButton(R.string.rename, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // when clicking rename retrieve the messageHistory
                        MessageHistory messageHistory = new MessageHistory(getContext());
                        String name = newName.getText().toString();
                        // update the db
                        messageHistory.renameChat(buddyId, name);
                        // set the current chatName
                        chatName = name;
                        actionBar.setTitle(chatName);
                    }
                }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // yeah there also is a negative button...
                    }
                }).show();
        return true;
    }
    // otherwise return false, I have not caught the event
    return false;
}

From source file:foam.starwisp.StarwispBuilder.java

public void Build(final StarwispActivity ctx, final String ctxname, JSONArray arr, ViewGroup parent) {

    if (StarwispLinearLayout.m_DisplayMetrics == null) {
        StarwispLinearLayout.m_DisplayMetrics = ctx.getResources().getDisplayMetrics();
    }/*from  w w  w. jav  a 2  s.  c  o  m*/

    try {
        String type = arr.getString(0);

        //Log.i("starwisp","building started "+type);

        if (type.equals("build-fragment")) {
            String name = arr.getString(1);
            int ID = arr.getInt(2);
            Fragment fragment = ActivityManager.GetFragment(name);
            LinearLayout inner = new LinearLayout(ctx);
            inner.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            inner.setId(ID);
            FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction();
            fragmentTransaction.add(ID, fragment);
            fragmentTransaction.commit();
            parent.addView(inner);
            return;
        }

        if (type.equals("map")) {
            int ID = arr.getInt(1);
            LinearLayout inner = new LinearLayout(ctx);
            inner.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            inner.setId(ID);
            Fragment mapfrag = SupportMapFragment.newInstance();
            FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction();
            fragmentTransaction.add(ID, mapfrag);
            fragmentTransaction.commit();
            parent.addView(inner);
            return;
        }

        if (type.equals("drawmap")) {
            final LinearLayout inner = new LinearLayout(ctx);
            inner.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            DrawableMap dm = new DrawableMap();
            dm.init(arr.getInt(1), inner, (StarwispActivity) ctx, this, arr.getString(3));
            parent.addView(inner);
            m_DMaps.put(arr.getInt(1), dm);
            return;
        }

        if (type.equals("linear-layout")) {
            StarwispLinearLayout.Build(this, ctx, ctxname, arr, parent);
            return;
        }

        if (type.equals("relative-layout")) {
            StarwispRelativeLayout.Build(this, ctx, ctxname, arr, parent);
            return;
        }

        if (type.equals("draggable")) {
            final LinearLayout v = new LinearLayout(ctx);
            final int id = arr.getInt(1);
            final String behaviour_type = arr.getString(5);
            v.setPadding(20, 20, 20, 10);
            v.setId(id);
            v.setOrientation(StarwispLinearLayout.BuildOrientation(arr.getString(2)));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            v.setClickable(true);
            v.setFocusable(true);

            JSONArray col = arr.getJSONArray(4);
            v.setBackgroundResource(R.drawable.draggable);

            GradientDrawable drawable = (GradientDrawable) v.getBackground();
            final int colour = Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2));
            drawable.setColor(colour);

            /*LayerDrawable bgDrawable = (LayerDrawable)v.getBackground();
            GradientDrawable bgShape = (GradientDrawable)bgDrawable.findDrawableByLayerId(R.id.draggableshape);
            bgShape.setColor(colour);*/
            /*v.getBackground().setColorFilter(colour, PorterDuff.Mode.MULTIPLY);*/

            parent.addView(v);
            JSONArray children = arr.getJSONArray(6);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }

            // Sets a long click listener for the ImageView using an anonymous listener object that
            // implements the OnLongClickListener interface
            if (!behaviour_type.equals("drop-only") && !behaviour_type.equals("drop-only-consume")) {
                v.setOnLongClickListener(new View.OnLongClickListener() {
                    public boolean onLongClick(View vv) {
                        if (id != 99) {
                            ClipData dragData = new ClipData(
                                    new ClipDescription("" + id,
                                            new String[] { ClipDescription.MIMETYPE_TEXT_PLAIN }),
                                    new ClipData.Item("" + id));

                            View.DragShadowBuilder myShadow = new MyDragShadowBuilder(v);
                            Log.i("starwisp", "start drag id " + vv.getId() + " " + v);
                            v.startDrag(dragData, myShadow, v, 0);
                            v.setVisibility(View.GONE);
                            return true;
                        }
                        return false;
                    }
                });
            }

            if (!behaviour_type.equals("drag-only")) {
                // ye gads - needed as drag/drop doesn't deal with nested targets
                final StarwispBuilder that = this;

                v.setOnDragListener(new View.OnDragListener() {
                    public boolean onDrag(View vv, DragEvent event) {

                        //Log.i("starwisp","on drag event happened");

                        final int action = event.getAction();
                        switch (action) {
                        case DragEvent.ACTION_DRAG_STARTED:
                            //Log.i("starwisp","Drag started"+v );
                            if (event.getClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
                                // returns true to indicate that the View can accept the dragged data.
                                return true;
                            } else {
                                // Returns false. During the current drag and drop operation, this View will
                                // not receive events again until ACTION_DRAG_ENDED is sent.
                                return false;
                            }
                        case DragEvent.ACTION_DRAG_ENTERED: {
                            if (that.m_LastDragHighlighted != null) {
                                that.m_LastDragHighlighted.getBackground().setColorFilter(null);
                            }
                            v.getBackground().setColorFilter(0x77777777, PorterDuff.Mode.MULTIPLY);
                            that.m_LastDragHighlighted = v;
                            //Log.i("starwisp","Drag entered"+v );
                            return true;
                        }
                        case DragEvent.ACTION_DRAG_LOCATION: {
                            //View dragee = (View)event.getLocalState();
                            //dragee.setVisibility(View.VISIBLE);
                            //Log.i("starwisp","Drag location"+v );
                            return true;
                        }
                        case DragEvent.ACTION_DRAG_EXITED: {
                            //Log.i("starwisp","Drag exited "+v );
                            v.getBackground().setColorFilter(null);
                            return true;
                        }
                        case DragEvent.ACTION_DROP: {
                            v.getBackground().setColorFilter(null);
                            //Log.i("starwisp","Drag dropped "+v );
                            View otherw = (View) event.getLocalState();
                            //Log.i("starwisp","removing from parent "+((View)otherw.getParent()).getId());

                            // check we are not adding to ourself
                            if (id != otherw.getId()) {
                                ((ViewManager) otherw.getParent()).removeView(otherw);
                                //Log.i("starwisp","adding to " + id);

                                if (!behaviour_type.equals("drop-only-consume")) {
                                    v.addView(otherw);
                                }
                            }
                            otherw.setVisibility(View.VISIBLE);
                            return true;
                        }
                        case DragEvent.ACTION_DRAG_ENDED: {
                            //Log.i("starwisp","Drag ended "+v );
                            v.getBackground().setColorFilter(null);

                            View dragee = (View) event.getLocalState();
                            dragee.setVisibility(View.VISIBLE);

                            if (event.getResult()) {
                                //Log.i("starwisp","sucess " );
                            } else {
                                //Log.i("starwisp","fail " );
                            }
                            ;
                            return true;
                        }
                        // An unknown action type was received.
                        default:
                            //Log.e("starwisp","Unknown action type received by OnDragListener.");
                            break;
                        }
                        ;
                        return true;
                    }
                });
                return;
            }
        }

        if (type.equals("frame-layout")) {
            FrameLayout v = new FrameLayout(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(3);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        /*
        if (type.equals("grid-layout")) {
        GridLayout v = new GridLayout(ctx);
        v.setId(arr.getInt(1));
        v.setRowCount(arr.getInt(2));
        //v.setColumnCount(arr.getInt(2));
        v.setOrientation(BuildOrientation(arr.getString(3)));
        v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
                
        parent.addView(v);
        JSONArray children = arr.getJSONArray(5);
        for (int i=0; i<children.length(); i++) {
            Build(ctx,ctxname,new JSONArray(children.getString(i)), v);
        }
                
        return;
        }
        */

        if (type.equals("scroll-view")) {
            HorizontalScrollView v = new HorizontalScrollView(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(3);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        if (type.equals("scroll-view-vert")) {
            ScrollView v = new ScrollView(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(3);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        if (type.equals("view-pager")) {
            ViewPager v = new ViewPager(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            v.setOffscreenPageLimit(3);
            final JSONArray items = arr.getJSONArray(3);

            v.setAdapter(new FragmentPagerAdapter(ctx.getSupportFragmentManager()) {

                @Override
                public int getCount() {
                    return items.length();
                }

                @Override
                public Fragment getItem(int position) {
                    try {
                        String fragname = items.getString(position);
                        return ActivityManager.GetFragment(fragname);
                    } catch (JSONException e) {
                        Log.e("starwisp", "Error parsing fragment data " + e.toString());
                    }
                    return null;
                }
            });
            parent.addView(v);
            return;
        }

        if (type.equals("space")) {
            // Space v = new Space(ctx); (class not found runtime error??)
            TextView v = new TextView(ctx);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
        }

        if (type.equals("image-view")) {
            ImageView v = new ImageView(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            v.setAdjustViewBounds(true);

            String image = arr.getString(2);

            if (image.startsWith("/")) {
                Bitmap b = BitmapCache.Load(image);
                if (b != null) {
                    v.setImageBitmap(b);
                }
            } else {
                int id = ctx.getResources().getIdentifier(image, "drawable", ctx.getPackageName());
                v.setImageResource(id);
            }

            parent.addView(v);
        }

        if (type.equals("image-button")) {
            ImageButton v = new ImageButton(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));

            String image = arr.getString(2);

            if (image.startsWith("/")) {
                v.setImageBitmap(BitmapCache.Load(image));
            } else {
                int id = ctx.getResources().getIdentifier(image, "drawable", ctx.getPackageName());
                v.setImageResource(id);
            }

            final String fn = arr.getString(4);
            v.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    Callback(ctx, ctxname, v.getId());
                }
            });

            v.setAdjustViewBounds(true);
            v.setScaleType(ImageView.ScaleType.CENTER_INSIDE);

            parent.addView(v);
        }

        if (type.equals("text-view")) {
            TextView v = new TextView(ctx);
            v.setId(arr.getInt(1));
            v.setText(Html.fromHtml(arr.getString(2)), BufferType.SPANNABLE);
            v.setTextSize(arr.getInt(3));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            v.setLinkTextColor(0xff00aa00);

            // uncomment all this to get hyperlinks to work in text...
            // should make this an option of course

            //v.setClickable(true); // make links
            //v.setMovementMethod(LinkMovementMethod.getInstance());
            //v.setEnabled(true);   // go to browser
            /*v.setOnTouchListener(new View.OnTouchListener() {
            public boolean onTouch(View vv, MotionEvent event) {
                return false;
            }
            };*/

            if (arr.length() > 5) {
                if (arr.getString(5).equals("left")) {
                    v.setGravity(Gravity.LEFT);
                } else {
                    if (arr.getString(5).equals("fill")) {
                        v.setGravity(Gravity.FILL);
                    } else {
                        v.setGravity(Gravity.CENTER);
                    }
                }
            } else {
                v.setGravity(Gravity.CENTER);
            }
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            parent.addView(v);
        }

        if (type.equals("debug-text-view")) {
            TextView v = (TextView) ctx.getLayoutInflater().inflate(R.layout.debug_text, null);
            //                v.setBackgroundResource(R.color.black);
            v.setId(arr.getInt(1));
            //                v.setText(Html.fromHtml(arr.getString(2)));
            //                v.setTextColor(R.color.white);
            //                v.setTextSize(arr.getInt(3));
            //                v.setMovementMethod(LinkMovementMethod.getInstance());
            //                v.setMaxLines(10);
            //                v.setVerticalScrollBarEnabled(true);
            //                v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            //v.setMovementMethod(new ScrollingMovementMethod());

            /*
            if (arr.length()>5) {
            if (arr.getString(5).equals("left")) {
                v.setGravity(Gravity.LEFT);
            } else {
                if (arr.getString(5).equals("fill")) {
                    v.setGravity(Gravity.FILL);
                } else {
                    v.setGravity(Gravity.CENTER);
                }
            }
            } else {
            v.setGravity(Gravity.LEFT);
            }
            v.setTypeface(((StarwispActivity)ctx).m_Typeface);*/
            parent.addView(v);
        }

        if (type.equals("web-view")) {
            WebView v = new WebView(ctx);
            v.setId(arr.getInt(1));
            v.setVerticalScrollBarEnabled(false);
            v.loadData(arr.getString(2), "text/html", "utf-8");
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            parent.addView(v);
        }

        if (type.equals("edit-text")) {
            final EditText v = new EditText(ctx);
            v.setId(arr.getInt(1));
            v.setText(arr.getString(2));
            v.setTextSize(arr.getInt(3));
            v.setGravity(Gravity.LEFT | Gravity.TOP);

            String inputtype = arr.getString(4);
            if (inputtype.equals("text")) {
                //v.setInputType(InputType.TYPE_CLASS_TEXT);
            } else if (inputtype.equals("numeric")) {
                v.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL
                        | InputType.TYPE_NUMBER_FLAG_SIGNED);
            } else if (inputtype.equals("email")) {
                v.setInputType(InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS);
            }

            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(5)));
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            final String fn = arr.getString(5);
            //v.setSingleLine(true);

            v.addTextChangedListener(new TextWatcher() {
                public void afterTextChanged(Editable s) {
                    CallbackArgs(ctx, ctxname, v.getId(), "\"" + s.toString() + "\"");
                }

                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                }

                public void onTextChanged(CharSequence s, int start, int before, int count) {
                }
            });

            parent.addView(v);
        }

        if (type.equals("button")) {
            Button v = new Button(ctx);
            v.setId(arr.getInt(1));
            v.setText(arr.getString(2));
            v.setTextSize(arr.getInt(3));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            final String fn = arr.getString(5);
            v.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    Callback(ctx, ctxname, v.getId());
                }
            });

            parent.addView(v);
        }

        if (type.equals("colour-button")) {
            Button v = new Button(ctx);
            v.setId(arr.getInt(1));
            v.setText(arr.getString(2));
            v.setTextSize(arr.getInt(3));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            JSONArray col = arr.getJSONArray(6);
            v.getBackground().setColorFilter(
                    Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2)),
                    PorterDuff.Mode.MULTIPLY);
            final String fn = arr.getString(5);
            v.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    Callback(ctx, ctxname, v.getId());
                }
            });
            parent.addView(v);
        }

        if (type.equals("toggle-button")) {
            ToggleButton v = new ToggleButton(ctx);
            if (arr.getString(5).equals("fancy")) {
                v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_fancy, null);
            }

            if (arr.getString(5).equals("yes")) {
                v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_yes, null);
            }

            if (arr.getString(5).equals("maybe")) {
                v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_maybe, null);
            }

            if (arr.getString(5).equals("no")) {
                v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_no, null);
            }

            v.setId(arr.getInt(1));
            v.setText(arr.getString(2));
            v.setTextSize(arr.getInt(3));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            final String fn = arr.getString(6);
            v.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    String arg = "#f";
                    if (((ToggleButton) v).isChecked())
                        arg = "#t";
                    CallbackArgs(ctx, ctxname, v.getId(), arg);
                }
            });
            parent.addView(v);
        }

        if (type.equals("seek-bar")) {
            SeekBar v = new SeekBar(ctx);
            v.setId(arr.getInt(1));
            v.setMax(arr.getInt(2));
            v.setProgress(arr.getInt(2) / 2);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            final String fn = arr.getString(4);

            v.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                public void onProgressChanged(SeekBar v, int a, boolean s) {
                    CallbackArgs(ctx, ctxname, v.getId(), Integer.toString(a));
                }

                public void onStartTrackingTouch(SeekBar v) {
                }

                public void onStopTrackingTouch(SeekBar v) {
                }
            });
            parent.addView(v);
        }

        if (type.equals("spinner")) {
            Spinner v = new Spinner(ctx);
            final int wid = arr.getInt(1);
            v.setId(wid);
            final JSONArray items = arr.getJSONArray(2);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            v.setMinimumWidth(100); // stops tiny buttons
            ArrayList<String> spinnerArray = new ArrayList<String>();

            for (int i = 0; i < items.length(); i++) {
                spinnerArray.add(items.getString(i));
            }

            ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<String>(ctx, R.layout.spinner_item,
                    spinnerArray) {
                public View getView(int position, View convertView, ViewGroup parent) {
                    View v = super.getView(position, convertView, parent);
                    ((TextView) v).setTypeface(((StarwispActivity) ctx).m_Typeface);
                    return v;
                }
            };

            spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner_layout);

            v.setAdapter(spinnerArrayAdapter);
            v.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                public void onItemSelected(AdapterView<?> a, View v, int pos, long id) {
                    CallbackArgs(ctx, ctxname, wid, "" + pos);
                }

                public void onNothingSelected(AdapterView<?> v) {
                }
            });

            parent.addView(v);
        }

        if (type.equals("nomadic")) {
            final int wid = arr.getInt(1);
            NomadicSurfaceView v = new NomadicSurfaceView(ctx, wid);
            v.setId(wid);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            Log.e("starwisp", "built the thing");
            parent.addView(v);
            Log.e("starwisp", "addit to the view");
        }

        if (type.equals("canvas")) {
            StarwispCanvas v = new StarwispCanvas(ctx);
            final int wid = arr.getInt(1);
            v.setId(wid);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            v.SetDrawList(arr.getJSONArray(3));
            parent.addView(v);
        }

        if (type.equals("camera-preview")) {
            PictureTaker pt = new PictureTaker();
            CameraPreview v = new CameraPreview(ctx, pt);
            final int wid = arr.getInt(1);
            v.setId(wid);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);

            Log.i("starwisp", "in camera-preview...");

            List<List<String>> info = v.mPictureTaker.GetInfo();
            // can't find a way to do this via a callback yet
            String arg = "'(";
            for (List<String> e : info) {
                arg += "(" + e.get(0) + " " + e.get(1) + ")";
                //Log.i("starwisp","converting prop "+arg);
            }
            arg += ")";
            m_Scheme.eval("(set! camera-properties " + arg + ")");
        }

        if (type.equals("button-grid")) {
            LinearLayout horiz = new LinearLayout(ctx);
            final int id = arr.getInt(1);
            final String buttontype = arr.getString(2);
            horiz.setId(id);
            horiz.setOrientation(LinearLayout.HORIZONTAL);
            parent.addView(horiz);
            int height = arr.getInt(3);
            int textsize = arr.getInt(4);
            LayoutParams lp = BuildLayoutParams(arr.getJSONArray(5));
            JSONArray buttons = arr.getJSONArray(6);
            int count = buttons.length();
            int vertcount = 0;
            LinearLayout vert = null;

            for (int i = 0; i < count; i++) {
                JSONArray button = buttons.getJSONArray(i);

                if (vertcount == 0) {
                    vert = new LinearLayout(ctx);
                    vert.setId(0);
                    vert.setOrientation(LinearLayout.VERTICAL);
                    horiz.addView(vert);
                }
                vertcount = (vertcount + 1) % height;

                if (buttontype.equals("button")) {
                    Button b = new Button(ctx);
                    b.setId(button.getInt(0));
                    b.setText(button.getString(1));
                    b.setTextSize(textsize);
                    b.setLayoutParams(lp);
                    b.setTypeface(((StarwispActivity) ctx).m_Typeface);
                    final String fn = arr.getString(6);
                    b.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            CallbackArgs(ctx, ctxname, id, "" + v.getId() + " #t");
                        }
                    });
                    vert.addView(b);
                } else if (buttontype.equals("toggle")) {
                    ToggleButton b = new ToggleButton(ctx);
                    b.setId(button.getInt(0));
                    b.setText(button.getString(1));
                    b.setTextSize(textsize);
                    b.setLayoutParams(lp);
                    b.setTypeface(((StarwispActivity) ctx).m_Typeface);
                    final String fn = arr.getString(6);
                    b.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            String arg = "#f";
                            if (((ToggleButton) v).isChecked())
                                arg = "#t";
                            CallbackArgs(ctx, ctxname, id, "" + v.getId() + " " + arg);
                        }
                    });
                    vert.addView(b);
                }
            }
        }

    } catch (JSONException e) {
        Log.e("starwisp", "Error parsing [" + arr.toString() + "] " + e.toString());
    }

    //Log.i("starwisp","building ended");

}

From source file:com.ccxt.whl.activity.SettingsFragment.java

/**
 * //w w  w .j  av a 2  s  .  c om
 */
public void change_nickname(String nickname) {

    final EditText texta = new EditText(getActivity());
    texta.setText(nickname);
    new AlertDialog.Builder(getActivity()).setTitle("")
            .setIcon(android.R.drawable.ic_dialog_info).setView(texta)
            .setPositiveButton("", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    String nickname = texta.getEditableText().toString();
                    RequestParams params = new RequestParams();

                    params.add("user", DemoApplication.getInstance().getUser());
                    params.add("nickname", nickname);
                    params.add("param", "nickname");
                    params.add("uid", uid);
                    HttpRestClient.get(Constant.UPDATE_USER_URL, params, responseHandler);
                    pd.show();
                    dialog.dismiss();
                    //?  
                }
            }).setNegativeButton("?", null).show();
    //return true; 
}

From source file:ar.com.tristeslostrestigres.diasporanativewebapp.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    if (id == R.id.notifications) {

        if (Helpers.isOnline(MainActivity.this)) {

            //                webView.stopLoading();
            ///* w  w w. j  a v a2s.  co  m*/
            //                WebView wvNotifications = new WebView(MainActivity.this);
            //                wvNotifications.loadUrl("https://" + podDomain + "/notifications");
            //
            //                final AlertDialog d = new AlertDialog.Builder(MainActivity.this).setView(wvNotifications)
            //                        .setPositiveButton("Close", new DialogInterface.OnClickListener() {
            //                            @TargetApi(11)
            //                            public void onClick(DialogInterface dialog, int id) {
            //                                dialog.cancel();
            //                            }
            //                        }).show();
            //
            ////                wvNotifications.setWebChromeClient(new WebChromeClient() {
            ////
            ////                   public void onProgressChanged(WebView view, int progress) {
            ////                       progressBar.setProgress(progress);
            //
            ////                       if (progress > 0 && progress <= 60) {
            ////                           view.loadUrl("javascript: ( function() {" +
            ////                                   "    if (document.getElementById('notification')) {" +
            ////                                   "       var count = document.getElementById('notification').innerHTML;" +
            ////                                   "       NotificationCounter.setNotificationCount(count.replace(/(\\r\\n|\\n|\\r)/gm, \"\"));" +
            ////                                   "    } else {" +
            ////                                   "       NotificationCounter.setNotificationCount('0');" +
            ////                                   "    }" +
            ////                                   "    if (document.getElementById('conversation')) {" +
            ////                                   "       var count = document.getElementById('conversation').innerHTML;" +
            ////                                   "       NotificationCounter.setConversationCount(count.replace(/(\\r\\n|\\n|\\r)/gm, \"\"));" +
            ////                                   "    } else {" +
            ////                                   "       NotificationCounter.setConversationCount('0');" +
            ////                                   "    }" +
            ////                                   "})();");
            ////                       }
            //
            ////                       if (progress > 60) {
            ////                           view.loadUrl("javascript: ( function() {" +
            ////                                   "    if(document.getElementById('main_nav')) {" +
            ////                                   "        document.getElementById('main_nav').parentNode.removeChild(" +
            ////                                   "        document.getElementById('main_nav'));" +
            ////                                   "    } else if (document.getElementById('main-nav')) {" +
            ////                                   "        document.getElementById('main-nav').parentNode.removeChild(" +
            ////                                   "        document.getElementById('main-nav'));" +
            ////                                   "    }" +
            ////                                   "})();");
            //////                           fab.setVisibility(View.VISIBLE);
            ////                       }
            //
            ////                       if (progress == 100) {
            ////                           fab.collapse();
            ////                           progressBar.setVisibility(View.GONE);
            ////                       } else {
            ////                           progressBar.setVisibility(View.VISIBLE);
            ////                       }
            ////                   }
            ////               });
            //
            //                        wvNotifications.setWebViewClient(new WebViewClient() {
            //                            @Override
            //                            public boolean shouldOverrideUrlLoading(WebView view, String url) {
            //                                if (!url.equals("https://" + podDomain + "/notifications")) {
            //                                    Intent urlIntent = new Intent(MainActivity.URL_MESSAGE);
            //                                    urlIntent.putExtra("url", url);
            //                                    sendBroadcast(urlIntent);
            //                                }
            //                                d.dismiss();
            //                                return true;
            //                            }
            //                        });

            webView.loadUrl("https://" + podDomain + "/notifications");
            return true;
        } else {
            Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT)
                    .show();
            return false;
        }
    }

    if (id == R.id.conversations) {
        if (Helpers.isOnline(MainActivity.this)) {
            webView.loadUrl("https://" + podDomain + "/conversations");
            return true;
        } else {
            Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT)
                    .show();
            return false;
        }
    }

    if (id == R.id.search) {
        fab.collapse();
        if (Helpers.isOnline(MainActivity.this)) {
            final AlertDialog.Builder alert = new AlertDialog.Builder(this);
            final EditText input = new EditText(this);
            alert.setView(input);
            alert.setTitle(R.string.search_alert_title);
            alert.setPositiveButton(R.string.search_alert_people, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    String inputTag = input.getText().toString().trim();
                    String cleanTag = inputTag.replaceAll("\\*", "");
                    // this validate the input data for tagfind
                    if (cleanTag.isEmpty()) {
                        dialog.cancel(); // if user dont have added a tag
                        Snackbar.make(getWindow().findViewById(R.id.drawer),
                                R.string.search_alert_bypeople_validate_needsomedata, Snackbar.LENGTH_LONG)
                                .show();
                    } else { // User have added a search tag
                        txtTitle.setText(R.string.fab1_title_person);
                        webView.loadUrl("https://" + podDomain + "/people.mobile?q=" + cleanTag);
                    }
                }
            }).setNegativeButton(R.string.search_alert_tag, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    String inputTag = input.getText().toString().trim();
                    String cleanTag = inputTag.replaceAll("\\#", "");
                    // this validate the input data for tagfind
                    if (cleanTag.isEmpty()) {
                        dialog.cancel(); // if user hasn't added a tag
                        Snackbar.make(getWindow().findViewById(R.id.drawer),
                                R.string.search_alert_bytags_validate_needsomedata, Snackbar.LENGTH_LONG)
                                .show();
                    } else { // User have added a search tag
                        txtTitle.setText(R.string.fab1_title_tag);
                        webView.loadUrl("https://" + podDomain + "/tags/" + cleanTag);
                    }
                }
            }).setNeutralButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    //
                }
            });
            alert.show();
        }
    }

    if (id == R.id.reload) {
        if (Helpers.isOnline(MainActivity.this)) {
            webView.reload();
            return true;
        } else {
            Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT)
                    .show();
            return false;
        }
    }

    if (id == R.id.mobile) {
        if (Helpers.isOnline(MainActivity.this)) {
            webView.loadUrl("https://" + podDomain + "/mobile/toggle");
            return true;
        } else {
            Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT)
                    .show();
            return false;
        }
    }

    if (id == R.id.loadImg) {
        if (Helpers.isOnline(MainActivity.this)) {
            wSettings.setLoadsImagesAutomatically(!pm.getLoadImages());
            pm.setLoadImages(!pm.getLoadImages());
            webView.loadUrl(webView.getUrl());
            return true;
        } else {
            Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT)
                    .show();
            return false;
        }
    }

    if (id == R.id.fontSize) {
        if (Helpers.isOnline(MainActivity.this)) {
            alertFormElements();
            return true;
        } else {
            Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT)
                    .show();
            return false;
        }
    }

    if (id == R.id.exit) {
        if (Helpers.isOnline(MainActivity.this)) {
            new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert)
                    .setMessage(getString(R.string.confirm_sign_out))
                    .setPositiveButton(getString(android.R.string.yes).toUpperCase(),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    webView.clearCache(true);
                                    Intent i = new Intent(MainActivity.this, PodsActivity.class);
                                    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                                    startActivity(i);
                                    finish();
                                }
                            })
                    .setNegativeButton(getString(android.R.string.no).toUpperCase(), null).show();
            return true;
        } else {
            Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT)
                    .show();
            return false;
        }
    }

    return super.onOptionsItemSelected(item);
}

From source file:gov.wa.wsdot.android.wsdot.ui.trafficmap.TrafficMapActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    mTracker = ((WsdotApplication) getApplication()).getDefaultTracker();

    switch (item.getItemId()) {
    case R.id.best_times_to_travel:
        Intent chartsIntent = new Intent(this, TravelChartsActivity.class);
        chartsIntent.putExtra("title", bestTimesTitle);
        startActivity(chartsIntent);/*from   w ww  .  j  a v  a 2s  .  c  om*/
        break;
    case R.id.set_favorite:
        AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.WSDOT_popup);

        final EditText textEntryView = new EditText(this);
        textEntryView.setInputType(InputType.TYPE_CLASS_TEXT);
        builder.setView(textEntryView);
        builder.setMessage(R.string.add_location_dialog);
        builder.setNegativeButton(R.string.cancel, (dialog, whichButton) -> dialog.dismiss());
        builder.setPositiveButton(R.string.submit, (dialog, whichButton) -> {
            String value = textEntryView.getText().toString();
            dialog.dismiss();

            MapLocationEntity location = new MapLocationEntity();

            location.setTitle(value);

            location.setLatitude(mMap.getProjection().getVisibleRegion().latLngBounds.getCenter().latitude);
            location.setLongitude(mMap.getProjection().getVisibleRegion().latLngBounds.getCenter().longitude);
            location.setZoom((int) mMap.getCameraPosition().zoom);

            favoriteMapLocationViewModel.addMapLocation(location);

        });
        AlertDialog alertDialog = builder.create();
        alertDialog.show();
        return true;
    case R.id.refresh:
        refreshOverlays(item);
        return true;
    case R.id.alerts_in_area:
        if (mMap != null) {
            LatLngBounds mBounds = mMap.getProjection().getVisibleRegion().latLngBounds;
            Intent alertsIntent = new Intent(this, HighwayAlertListActivity.class);
            alertsIntent.putExtra("nelat", mBounds.northeast.latitude);
            alertsIntent.putExtra("nelong", mBounds.northeast.longitude);
            alertsIntent.putExtra("swlat", mBounds.southwest.latitude);
            alertsIntent.putExtra("swlong", mBounds.southwest.longitude);
            startActivity(alertsIntent);
        }
        return true;
    case R.id.express_lanes:
        Intent expressIntent = new Intent(this, SeattleExpressLanesActivity.class);
        startActivity(expressIntent);
        return true;
    case android.R.id.home:
        finish();
        return true;
    case R.id.social_media:
        Intent socialIntent = new Intent(this, SocialMediaTabActivity.class);
        startActivity(socialIntent);
        return true;
    case R.id.travel_times:
        Intent timesIntent = new Intent(this, TravelTimesActivity.class);
        startActivity(timesIntent);
        return true;
    case R.id.news:
        Intent newsIntent = new Intent(this, NewsActivity.class);
        startActivity(newsIntent);
        return true;
    case R.id.goto_bellingham:
        mTracker.setScreenName("/Traffic Map/Go To Location/Bellingham");
        mTracker.send(new HitBuilders.ScreenViewBuilder().build());
        goToLocation(48.756302, -122.46151, 12);
        UIUtils.refreshActionBarMenu(this);
        return true;
    case R.id.goto_chehalis:
        mTracker.setScreenName("/Traffic Map/Go To Location/Chehalis");
        mTracker.send(new HitBuilders.ScreenViewBuilder().build());
        goToLocation(46.635529, -122.937698, 11);
        UIUtils.refreshActionBarMenu(this);
        return true;
    case R.id.goto_everett:
        mTracker.setScreenName("/Traffic Map/Go To Location/Everett");
        mTracker.send(new HitBuilders.ScreenViewBuilder().build());
        goToLocation(47.967976, -122.197627, 12);
        UIUtils.refreshActionBarMenu(this);
        return true;
    case R.id.goto_hoodcanal:
        mTracker.setScreenName("/Traffic Map/Go To Location/Hood Canal");
        mTracker.send(new HitBuilders.ScreenViewBuilder().build());
        goToLocation(47.85268, -122.628365, 13);
        UIUtils.refreshActionBarMenu(this);
        return true;
    case R.id.goto_mtvernon:
        mTracker.setScreenName("/Traffic Map/Go To Location/Mt. Vernon");
        mTracker.send(new HitBuilders.ScreenViewBuilder().build());
        goToLocation(48.420657, -122.334824, 13);
        UIUtils.refreshActionBarMenu(this);
        return true;
    case R.id.goto_stanwood:
        mTracker.setScreenName("/Traffic Map/Go To Location/Standwood");
        mTracker.send(new HitBuilders.ScreenViewBuilder().build());
        goToLocation(48.22959, -122.34581, 13);
        UIUtils.refreshActionBarMenu(this);
        return true;
    case R.id.goto_monroe:
        mTracker.setScreenName("/Traffic Map/Go To Location/Monroe");
        mTracker.send(new HitBuilders.ScreenViewBuilder().build());
        goToLocation(47.859476, -121.972446, 14);
        UIUtils.refreshActionBarMenu(this);
        return true;
    case R.id.goto_sultan:
        mTracker.setScreenName("/Traffic Map/Go To Location/Sultan");
        mTracker.send(new HitBuilders.ScreenViewBuilder().build());
        goToLocation(47.86034, -121.812286, 13);
        UIUtils.refreshActionBarMenu(this);
        return true;
    case R.id.goto_olympia:
        mTracker.setScreenName("/Traffic Map/Go To Location/Olympia");
        mTracker.send(new HitBuilders.ScreenViewBuilder().build());
        goToLocation(47.021461, -122.899933, 13);
        UIUtils.refreshActionBarMenu(this);
        return true;
    case R.id.goto_seattle:
        mTracker.setScreenName("/Traffic Map/Go To Location/Seattle");
        mTracker.send(new HitBuilders.ScreenViewBuilder().build());
        goToLocation(47.5990, -122.3350, 12);
        UIUtils.refreshActionBarMenu(this);
        return true;
    case R.id.goto_spokane:
        mTracker.setScreenName("/Traffic Map/Go To Location/Spokane");
        mTracker.send(new HitBuilders.ScreenViewBuilder().build());
        goToLocation(47.658566, -117.425995, 12);
        UIUtils.refreshActionBarMenu(this);
        return true;
    case R.id.goto_tacoma:
        mTracker.setScreenName("/Traffic Map/Go To Location/Tacoma");
        mTracker.send(new HitBuilders.ScreenViewBuilder().build());
        goToLocation(47.206275, -122.46254, 12);
        UIUtils.refreshActionBarMenu(this);
        return true;
    case R.id.goto_vancouver:
        mTracker.setScreenName("/Traffic Map/Go To Location/Vancouver");
        mTracker.send(new HitBuilders.ScreenViewBuilder().build());
        goToLocation(45.639968, -122.610512, 11);
        UIUtils.refreshActionBarMenu(this);
        return true;
    case R.id.goto_wenatchee:
        mTracker.setScreenName("/Traffic Map/Go To Location/Wenatchee");
        mTracker.send(new HitBuilders.ScreenViewBuilder().build());
        goToLocation(47.435867, -120.309563, 12);
        UIUtils.refreshActionBarMenu(this);
        return true;
    case R.id.goto_snoqualmiepass:
        mTracker.setScreenName("/Traffic Map/Go To Location/Snoqualmie Pass");
        mTracker.send(new HitBuilders.ScreenViewBuilder().build());
        goToLocation(47.404481, -121.4232569, 12);
        UIUtils.refreshActionBarMenu(this);
        return true;
    case R.id.goto_tricities:
        mTracker.setScreenName("/Traffic Map/Go To Location/Tri-Cities");
        mTracker.send(new HitBuilders.ScreenViewBuilder().build());
        goToLocation(46.2503607, -119.2063781, 11);
        UIUtils.refreshActionBarMenu(this);
        return true;
    case R.id.goto_yakima:
        mTracker.setScreenName("/Traffic Map/Go To Location/Yakima");
        mTracker.send(new HitBuilders.ScreenViewBuilder().build());
        goToLocation(46.6063273, -120.4886952, 11);
        UIUtils.refreshActionBarMenu(this);
        return true;
    case R.id.map_legend:
        AlertDialog.Builder imageDialog = new AlertDialog.Builder(this, R.style.WSDOT_popup);
        LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);

        View layout = inflater.inflate(R.layout.map_legend_layout, null);
        imageDialog.setView(layout);
        imageDialog.setPositiveButton(R.string.submit, (dialog, whichButton) -> dialog.dismiss());
        imageDialog.create();
        imageDialog.show();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:es.farfuteam.vncpp.controller.CanvasActivity.java

/**
 * @return The new dialog/*w ww  . jav a2s . c  o  m*/
 * @brief Show the dialog with the password needed message
 * @details Show the dialog with the password needed message
 */
private Dialog passwordNeededDialog() {

    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    String info = getString(R.string.password_title);
    String body = getString(R.string.password_dialog);

    builder.setTitle(info);
    builder.setMessage(body);
    // Set an EditText view to get user password 
    final EditText input = new EditText(this);
    input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    builder.setView(input);

    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.cancel();
            pass = "";
            waitDialog = false;
        }
    });
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

            String str = input.getEditableText().toString();
            pass = str;
            waitDialog = false;
        }

    });

    return builder.create();
}