Example usage for android.text TextWatcher TextWatcher

List of usage examples for android.text TextWatcher TextWatcher

Introduction

In this page you can find the example usage for android.text TextWatcher TextWatcher.

Prototype

TextWatcher

Source Link

Usage

From source file:com.goftagram.telegram.ui.Components.PasscodeView.java

public PasscodeView(final Context context) {
    super(context);

    setWillNotDraw(false);//from   www . j  a  v a  2s  .c  om
    setVisibility(GONE);

    backgroundFrameLayout = new FrameLayout(context);
    addView(backgroundFrameLayout);
    LayoutParams layoutParams = (LayoutParams) backgroundFrameLayout.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    backgroundFrameLayout.setLayoutParams(layoutParams);

    passwordFrameLayout = new FrameLayout(context);
    addView(passwordFrameLayout);
    layoutParams = (LayoutParams) passwordFrameLayout.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
    passwordFrameLayout.setLayoutParams(layoutParams);

    ImageView imageView = new ImageView(context);
    imageView.setScaleType(ImageView.ScaleType.FIT_XY);
    imageView.setImageResource(R.drawable.passcode_logo);
    passwordFrameLayout.addView(imageView);
    layoutParams = (LayoutParams) imageView.getLayoutParams();
    if (AndroidUtilities.density < 1) {
        layoutParams.width = AndroidUtilities.dp(30);
        layoutParams.height = AndroidUtilities.dp(30);
    } else {
        layoutParams.width = AndroidUtilities.dp(40);
        layoutParams.height = AndroidUtilities.dp(40);
    }
    layoutParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
    layoutParams.bottomMargin = AndroidUtilities.dp(100);
    imageView.setLayoutParams(layoutParams);

    passcodeTextView = new TextView(context);
    passcodeTextView.setTextColor(0xffffffff);
    passcodeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    passcodeTextView.setGravity(Gravity.CENTER_HORIZONTAL);
    passwordFrameLayout.addView(passcodeTextView);
    layoutParams = (LayoutParams) passcodeTextView.getLayoutParams();
    layoutParams.width = LayoutHelper.WRAP_CONTENT;
    layoutParams.height = LayoutHelper.WRAP_CONTENT;
    layoutParams.bottomMargin = AndroidUtilities.dp(62);
    layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
    passcodeTextView.setLayoutParams(layoutParams);

    passwordEditText2 = new AnimatingTextView(context);
    passwordFrameLayout.addView(passwordEditText2);
    layoutParams = (FrameLayout.LayoutParams) passwordEditText2.getLayoutParams();
    layoutParams.height = LayoutHelper.WRAP_CONTENT;
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.leftMargin = AndroidUtilities.dp(70);
    layoutParams.rightMargin = AndroidUtilities.dp(70);
    layoutParams.bottomMargin = AndroidUtilities.dp(6);
    layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
    passwordEditText2.setLayoutParams(layoutParams);

    passwordEditText = new EditText(context);
    passwordEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 36);
    passwordEditText.setTextColor(0xffffffff);
    passwordEditText.setMaxLines(1);
    passwordEditText.setLines(1);
    passwordEditText.setGravity(Gravity.CENTER_HORIZONTAL);
    passwordEditText.setSingleLine(true);
    passwordEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
    passwordEditText.setTypeface(Typeface.DEFAULT);
    passwordEditText.setBackgroundDrawable(null);
    AndroidUtilities.clearCursorDrawable(passwordEditText);
    passwordFrameLayout.addView(passwordEditText);
    layoutParams = (FrameLayout.LayoutParams) passwordEditText.getLayoutParams();
    layoutParams.height = LayoutHelper.WRAP_CONTENT;
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.leftMargin = AndroidUtilities.dp(70);
    layoutParams.rightMargin = AndroidUtilities.dp(70);
    layoutParams.bottomMargin = AndroidUtilities.dp(6);
    layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
    passwordEditText.setLayoutParams(layoutParams);
    passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_DONE) {
                processDone(false);
                return true;
            }
            return false;
        }
    });
    passwordEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            if (passwordEditText.length() == 4 && UserConfig.passcodeType == 0) {
                processDone(false);
            }
        }
    });
    if (android.os.Build.VERSION.SDK_INT < 11) {
        passwordEditText.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
            public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
                menu.clear();
            }
        });
    } else {
        passwordEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
            public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                return false;
            }

            public void onDestroyActionMode(ActionMode mode) {
            }

            public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                return false;
            }

            public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                return false;
            }
        });
    }

    checkImage = new ImageView(context);
    checkImage.setImageResource(R.drawable.passcode_check);
    checkImage.setScaleType(ImageView.ScaleType.CENTER);
    checkImage.setBackgroundResource(R.drawable.bar_selector_lock);
    passwordFrameLayout.addView(checkImage);
    layoutParams = (LayoutParams) checkImage.getLayoutParams();
    layoutParams.width = AndroidUtilities.dp(60);
    layoutParams.height = AndroidUtilities.dp(60);
    layoutParams.bottomMargin = AndroidUtilities.dp(4);
    layoutParams.rightMargin = AndroidUtilities.dp(10);
    layoutParams.gravity = Gravity.BOTTOM | Gravity.RIGHT;
    checkImage.setLayoutParams(layoutParams);
    checkImage.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            processDone(false);
        }
    });

    FrameLayout lineFrameLayout = new FrameLayout(context);
    lineFrameLayout.setBackgroundColor(0x26ffffff);
    passwordFrameLayout.addView(lineFrameLayout);
    layoutParams = (LayoutParams) lineFrameLayout.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = AndroidUtilities.dp(1);
    layoutParams.gravity = Gravity.BOTTOM | Gravity.LEFT;
    layoutParams.leftMargin = AndroidUtilities.dp(20);
    layoutParams.rightMargin = AndroidUtilities.dp(20);
    lineFrameLayout.setLayoutParams(layoutParams);

    numbersFrameLayout = new FrameLayout(context);
    addView(numbersFrameLayout);
    layoutParams = (LayoutParams) numbersFrameLayout.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
    numbersFrameLayout.setLayoutParams(layoutParams);

    lettersTextViews = new ArrayList<>(10);
    numberTextViews = new ArrayList<>(10);
    numberFrameLayouts = new ArrayList<>(10);
    for (int a = 0; a < 10; a++) {
        TextView textView = new TextView(context);
        textView.setTextColor(0xffffffff);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 36);
        textView.setGravity(Gravity.CENTER);
        textView.setText(String.format(Locale.US, "%d", a));
        numbersFrameLayout.addView(textView);
        layoutParams = (LayoutParams) textView.getLayoutParams();
        layoutParams.width = AndroidUtilities.dp(50);
        layoutParams.height = AndroidUtilities.dp(50);
        layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
        textView.setLayoutParams(layoutParams);
        numberTextViews.add(textView);

        textView = new TextView(context);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
        textView.setTextColor(0x7fffffff);
        textView.setGravity(Gravity.CENTER);
        numbersFrameLayout.addView(textView);
        layoutParams = (LayoutParams) textView.getLayoutParams();
        layoutParams.width = AndroidUtilities.dp(50);
        layoutParams.height = AndroidUtilities.dp(20);
        layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
        textView.setLayoutParams(layoutParams);
        switch (a) {
        case 0:
            textView.setText("+");
            break;
        case 2:
            textView.setText("ABC");
            break;
        case 3:
            textView.setText("DEF");
            break;
        case 4:
            textView.setText("GHI");
            break;
        case 5:
            textView.setText("JKL");
            break;
        case 6:
            textView.setText("MNO");
            break;
        case 7:
            textView.setText("PQRS");
            break;
        case 8:
            textView.setText("TUV");
            break;
        case 9:
            textView.setText("WXYZ");
            break;
        default:
            break;
        }
        lettersTextViews.add(textView);
    }
    eraseView = new ImageView(context);
    eraseView.setScaleType(ImageView.ScaleType.CENTER);
    eraseView.setImageResource(R.drawable.passcode_delete);
    numbersFrameLayout.addView(eraseView);
    layoutParams = (LayoutParams) eraseView.getLayoutParams();
    layoutParams.width = AndroidUtilities.dp(50);
    layoutParams.height = AndroidUtilities.dp(50);
    layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
    eraseView.setLayoutParams(layoutParams);
    for (int a = 0; a < 11; a++) {
        FrameLayout frameLayout = new FrameLayout(context);
        frameLayout.setBackgroundResource(R.drawable.bar_selector_lock);
        frameLayout.setTag(a);
        if (a == 10) {
            frameLayout.setOnLongClickListener(new OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    passwordEditText.setText("");
                    passwordEditText2.eraseAllCharacters(true);
                    return true;
                }
            });
        }
        frameLayout.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                int tag = (Integer) v.getTag();
                switch (tag) {
                case 0:
                    passwordEditText2.appendCharacter("0");
                    break;
                case 1:
                    passwordEditText2.appendCharacter("1");
                    break;
                case 2:
                    passwordEditText2.appendCharacter("2");
                    break;
                case 3:
                    passwordEditText2.appendCharacter("3");
                    break;
                case 4:
                    passwordEditText2.appendCharacter("4");
                    break;
                case 5:
                    passwordEditText2.appendCharacter("5");
                    break;
                case 6:
                    passwordEditText2.appendCharacter("6");
                    break;
                case 7:
                    passwordEditText2.appendCharacter("7");
                    break;
                case 8:
                    passwordEditText2.appendCharacter("8");
                    break;
                case 9:
                    passwordEditText2.appendCharacter("9");
                    break;
                case 10:
                    passwordEditText2.eraseLastCharacter();
                    break;
                }
                if (passwordEditText2.lenght() == 4) {
                    processDone(false);
                }
            }
        });
        numberFrameLayouts.add(frameLayout);
    }
    for (int a = 10; a >= 0; a--) {
        FrameLayout frameLayout = numberFrameLayouts.get(a);
        numbersFrameLayout.addView(frameLayout);
        layoutParams = (LayoutParams) frameLayout.getLayoutParams();
        layoutParams.width = AndroidUtilities.dp(100);
        layoutParams.height = AndroidUtilities.dp(100);
        layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
        frameLayout.setLayoutParams(layoutParams);
    }
}

From source file:com.haibison.android.anhuu.utils.ui.bookmark.BookmarkFragment.java

/**
 * Shows a dialog to let the user enter new name or change current name of a
 * bookmark./*  ww w  .  j  a va2s  . com*/
 * 
 * @param context
 *            {@link Context}
 * @param providerId
 *            the provider ID.
 * @param id
 *            the bookmark ID.
 * @param uri
 *            the URI to the bookmark.
 * @param name
 *            the name. To enter new name, this is the suggested name you
 *            provide. To rename, this is the old name.
 */
public static void doEnterNewNameOrRenameBookmark(final Context context, final String providerId, final int id,
        final Uri uri, final String name) {
    final AlertDialog dialog = Dlg.newAlertDlg(context);

    View view = LayoutInflater.from(context).inflate(R.layout.anhuu_f5be488d_simple_text_input_view, null);
    final EditText textName = (EditText) view.findViewById(R.id.anhuu_f5be488d_text1);
    textName.setText(name);
    textName.selectAll();
    textName.setHint(R.string.anhuu_f5be488d_hint_new_name);
    textName.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                UI.showSoftKeyboard(textName, false);
                Button btn = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
                if (btn.isEnabled())
                    btn.performClick();
                return true;
            }
            return false;
        }// onEditorAction()
    });

    dialog.setView(view);
    dialog.setIcon(R.drawable.anhuu_f5be488d_bookmarks_dark);
    dialog.setTitle(id < 0 ? R.string.anhuu_f5be488d_title_new_bookmark : R.string.anhuu_f5be488d_title_rename);
    dialog.setButton(DialogInterface.BUTTON_POSITIVE, context.getString(android.R.string.ok),
            new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String newName = textName.getText().toString().trim();
                    if (android.text.TextUtils.isEmpty(newName)) {
                        Dlg.toast(context, R.string.anhuu_f5be488d_msg_bookmark_name_is_invalid,
                                Dlg.LENGTH_SHORT);
                        return;
                    }

                    UI.showSoftKeyboard(textName, false);

                    ContentValues values = new ContentValues();
                    values.put(BookmarkContract.COLUMN_NAME, newName);

                    if (id >= 0) {
                        values.put(BookmarkContract.COLUMN_MODIFICATION_TIME,
                                DbUtils.formatNumber(new Date().getTime()));
                        context.getContentResolver().update(
                                ContentUris.withAppendedId(BookmarkContract.genContentIdUriBase(context), id),
                                values, null, null);
                    } else {
                        /*
                         * Check if the URI exists or doesn't. If it exists,
                         * update it instead of inserting the new one.
                         */
                        Cursor cursor = context.getContentResolver().query(
                                BookmarkContract.genContentUri(context), null,
                                String.format("%s = %s AND %s LIKE %s", BookmarkContract.COLUMN_PROVIDER_ID,
                                        DatabaseUtils.sqlEscapeString(providerId), BookmarkContract.COLUMN_URI,
                                        DatabaseUtils.sqlEscapeString(uri.toString())),
                                null, null);
                        try {
                            if (cursor != null && cursor.moveToFirst()) {
                                values.put(BookmarkContract.COLUMN_MODIFICATION_TIME,
                                        DbUtils.formatNumber(new Date().getTime()));
                                context.getContentResolver().update(
                                        Uri.withAppendedPath(BookmarkContract.genContentIdUriBase(context),
                                                Uri.encode(cursor.getString(
                                                        cursor.getColumnIndex(BookmarkContract._ID)))),
                                        values, null, null);
                            } else {
                                values.put(BookmarkContract.COLUMN_PROVIDER_ID, providerId);
                                values.put(BookmarkContract.COLUMN_URI, uri.toString());

                                context.getContentResolver().insert(BookmarkContract.genContentUri(context),
                                        values);
                            }
                        } finally {
                            if (cursor != null)
                                cursor.close();
                        }
                    }

                    Dlg.toast(context, context.getString(R.string.anhuu_f5be488d_msg_done), Dlg.LENGTH_SHORT);
                }// onClick()
            });

    dialog.show();
    UI.showSoftKeyboard(textName, true);

    final Button buttonOk = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
    buttonOk.setEnabled(id < 0);

    textName.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // TODO Auto-generated method stub
        }

        @Override
        public void afterTextChanged(Editable s) {
            String newName = s.toString().trim();
            boolean enabled = !android.text.TextUtils.isEmpty(newName);
            buttonOk.setEnabled(enabled);

            /*
             * If renaming, only enable button OK if new name is not equal
             * to the old one.
             */
            if (enabled && id >= 0)
                buttonOk.setEnabled(!newName.equals(name));
        }
    });
}

From source file:com.krayzk9s.imgurholo.ui.SingleImageFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    final ImgurHoloActivity activity = (ImgurHoloActivity) getActivity();
    final SharedPreferences settings = activity.getApiCall().settings;
    sort = settings.getString("CommentSort", "Best");
    boolean newData = true;
    if (commentData != null) {
        newData = false;/* w ww . j  a va2  s .com*/
    }

    mainView = inflater.inflate(R.layout.single_image_layout, container, false);
    String[] mMenuList = getResources().getStringArray(R.array.emptyList);
    if (commentAdapter == null)
        commentAdapter = new CommentAdapter(mainView.getContext());
    commentLayout = (ListView) mainView.findViewById(R.id.comment_thread);
    commentLayout.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    if (settings.getString("theme", MainActivity.HOLO_LIGHT).equals(MainActivity.HOLO_LIGHT))
        imageLayoutView = (LinearLayout) View.inflate(getActivity(), R.layout.image_view, null);
    else
        imageLayoutView = (LinearLayout) View.inflate(getActivity(), R.layout.dark_image_view, null);

    mPullToRefreshLayout = (PullToRefreshLayout) mainView.findViewById(R.id.ptr_layout);
    ActionBarPullToRefresh.from(getActivity())
            // Mark All Children as pullable
            .allChildrenArePullable()
            // Set the OnRefreshListener
            .listener(this)
            // Finally commit the setup to our PullToRefreshLayout
            .setup(mPullToRefreshLayout);
    if (savedInstanceState != null && newData) {
        imageData = savedInstanceState.getParcelable("imageData");
        inGallery = savedInstanceState.getBoolean("inGallery");
    }
    LinearLayout layout = (LinearLayout) imageLayoutView.findViewById(R.id.image_buttons);
    TextView imageDetails = (TextView) imageLayoutView.findViewById(R.id.single_image_details);
    layout.setVisibility(View.VISIBLE);
    ImageButton imageFullscreen = (ImageButton) imageLayoutView.findViewById(R.id.fullscreen);
    imageUpvote = (ImageButton) imageLayoutView.findViewById(R.id.rating_good);
    imageDownvote = (ImageButton) imageLayoutView.findViewById(R.id.rating_bad);
    ImageButton imageFavorite = (ImageButton) imageLayoutView.findViewById(R.id.rating_favorite);
    imageComment = (ImageButton) imageLayoutView.findViewById(R.id.comment);
    ImageButton imageUser = (ImageButton) imageLayoutView.findViewById(R.id.user);
    imageScore = (TextView) imageLayoutView.findViewById(R.id.single_image_score);
    TextView imageInfo = (TextView) imageLayoutView.findViewById(R.id.single_image_info);
    Log.d("imageData", imageData.getJSONObject().toString());
    if (imageData.getJSONObject().has("ups")) {
        imageUpvote.setVisibility(View.VISIBLE);
        imageDownvote.setVisibility(View.VISIBLE);
        imageScore.setVisibility(View.VISIBLE);
        imageComment.setVisibility(View.VISIBLE);
        ImageUtils.updateImageFont(imageData, imageScore);
    }
    imageInfo.setVisibility(View.VISIBLE);
    ImageUtils.updateInfoFont(imageData, imageInfo);
    imageUser.setVisibility(View.VISIBLE);
    imageFavorite.setVisibility(View.VISIBLE);
    try {
        if (!imageData.getJSONObject().has("account_url")
                || imageData.getJSONObject().getString("account_url").equals("null")
                || imageData.getJSONObject().getString("account_url").equals("[deleted]"))
            imageUser.setVisibility(View.GONE);
        if (!imageData.getJSONObject().has("vote")) {
            imageUpvote.setVisibility(View.GONE);
            imageDownvote.setVisibility(View.GONE);
        } else {
            if (imageData.getJSONObject().getString("vote") != null
                    && imageData.getJSONObject().getString("vote").equals("up"))
                imageUpvote.setImageResource(R.drawable.green_rating_good);
            else if (imageData.getJSONObject().getString("vote") != null
                    && imageData.getJSONObject().getString("vote").equals("down"))
                imageDownvote.setImageResource(R.drawable.red_rating_bad);
        }
        if (imageData.getJSONObject().getString("favorite") != null
                && imageData.getJSONObject().getBoolean("favorite"))
            imageFavorite.setImageResource(R.drawable.green_rating_favorite);
    } catch (JSONException e) {
        Log.e("Error!", e.toString());
    }
    imageFavorite.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ImageUtils.favoriteImage(singleImageFragment, imageData, (ImageButton) view, activity.getApiCall());
        }
    });
    imageUser.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ImageUtils.gotoUser(singleImageFragment, imageData);
        }
    });
    imageComment.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Activity activity = getActivity();
            final EditText newBody = new EditText(activity);
            newBody.setHint(R.string.body_hint_body);
            newBody.setLines(3);
            final TextView characterCount = new TextView(activity);
            characterCount.setText("140");
            LinearLayout commentReplyLayout = new LinearLayout(activity);
            newBody.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
                    //
                }

                @Override
                public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
                    characterCount.setText(String.valueOf(140 - charSequence.length()));
                }

                @Override
                public void afterTextChanged(Editable editable) {
                    for (int i = editable.length(); i > 0; i--) {
                        if (editable.subSequence(i - 1, i).toString().equals("\n"))
                            editable.replace(i - 1, i, "");
                    }
                }
            });
            commentReplyLayout.setOrientation(LinearLayout.VERTICAL);
            commentReplyLayout.addView(newBody);
            commentReplyLayout.addView(characterCount);
            new AlertDialog.Builder(activity).setTitle(R.string.dialog_comment_on_image_title)
                    .setView(commentReplyLayout)
                    .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            if (newBody.getText() != null && newBody.getText().toString().length() < 141) {
                                HashMap<String, Object> commentMap = new HashMap<String, Object>();
                                try {
                                    commentMap.put("comment", newBody.getText().toString());
                                    commentMap.put("image_id", imageData.getJSONObject().getString("id"));
                                    Fetcher fetcher = new Fetcher(singleImageFragment, "3/comment/",
                                            ApiCall.POST, commentMap,
                                            ((ImgurHoloActivity) getActivity()).getApiCall(), POSTCOMMENT);
                                    fetcher.execute();
                                } catch (JSONException e) {
                                    Log.e("Error!", e.toString());
                                }
                            }
                        }
                    }).setNegativeButton(R.string.dialog_answer_cancel, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            // Do nothing.
                        }
                    }).show();
        }
    });
    imageUpvote.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ImageUtils.upVote(singleImageFragment, imageData, imageUpvote, imageDownvote,
                    activity.getApiCall());
            ImageUtils.updateImageFont(imageData, imageScore);
        }
    });
    imageDownvote.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ImageUtils.downVote(singleImageFragment, imageData, imageUpvote, imageDownvote,
                    activity.getApiCall());
            ImageUtils.updateImageFont(imageData, imageScore);
        }
    });
    if (popupWindow != null) {
        popupWindow.dismiss();
    }
    popupWindow = new PopupWindow();
    imageFullscreen.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ImageUtils.fullscreen(singleImageFragment, imageData, popupWindow, mainView);
        }
    });
    ArrayAdapter<String> tempAdapter = new ArrayAdapter<String>(mainView.getContext(),
            R.layout.drawer_list_item, mMenuList);
    Log.d("URI", "YO I'M IN YOUR SINGLE FRAGMENT gallery:" + inGallery);
    imageView = (ImageView) imageLayoutView.findViewById(R.id.single_image_view);
    loadImage();
    TextView imageTitle = (TextView) imageLayoutView.findViewById(R.id.single_image_title);
    TextView imageDescription = (TextView) imageLayoutView.findViewById(R.id.single_image_description);

    try {
        String size = String
                .valueOf(NumberFormat.getIntegerInstance()
                        .format(imageData.getJSONObject().getInt(ImgurHoloActivity.IMAGE_DATA_WIDTH)))
                + "x"
                + NumberFormat.getIntegerInstance()
                        .format(imageData.getJSONObject().getInt(ImgurHoloActivity.IMAGE_DATA_HEIGHT))
                + " (" + NumberFormat.getIntegerInstance()
                        .format(imageData.getJSONObject().getInt(ImgurHoloActivity.IMAGE_DATA_SIZE))
                + "B)";
        String initial = imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TYPE) + " "
                + Html.fromHtml("&#8226;") + " " + size + " " + Html.fromHtml("&#8226;") + " " + "Views: "
                + NumberFormat.getIntegerInstance()
                        .format(imageData.getJSONObject().getInt(ImgurHoloActivity.IMAGE_DATA_VIEWS));
        imageDetails.setText(initial);
        Log.d("imagedata", imageData.getJSONObject().toString());
        if (!imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TITLE).equals("null"))
            imageTitle.setText(imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TITLE));
        else
            imageTitle.setVisibility(View.GONE);
        if (!imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION).equals("null")) {
            imageDescription
                    .setText(imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION));
            imageDescription.setVisibility(View.VISIBLE);
        } else
            imageDescription.setVisibility(View.GONE);
        commentLayout.addHeaderView(imageLayoutView);
        commentLayout.setAdapter(tempAdapter);
    } catch (JSONException e) {
        Log.e("Text Error!", e.toString());
    }
    if ((savedInstanceState == null || commentData == null) && newData) {
        commentData = new JSONParcelable();
        getComments();
        commentLayout.setAdapter(commentAdapter);
    } else if (newData) {
        commentArray = savedInstanceState.getParcelableArrayList("commentData");
        commentAdapter.addAll(commentArray);
        commentLayout.setAdapter(commentAdapter);
        commentAdapter.notifyDataSetChanged();
    } else if (commentArray != null) {
        commentAdapter.addAll(commentArray);
        commentLayout.setAdapter(commentAdapter);
        commentAdapter.notifyDataSetChanged();
    }
    return mainView;
}

From source file:com.haomee.chat.activity.ChatActivity.java

/**
 * initView/*from www. j  a  va 2s  . co m*/
 */
protected void initView() {
    report = (TextView) findViewById(R.id.report);
    report.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            Intent intent = new Intent();
            intent.setClass(ChatActivity.this, ReportActivity1.class);
            intent.putExtra("uid", uId);
            intent.putExtra("nickname", nickname);
            ChatActivity.this.startActivity(intent);
        }
    });
    attachment_linear = (LinearLayout) findViewById(R.id.attachment_linear);
    attachment_content = (TextView) findViewById(R.id.attachment_content);
    attachment_close = (ImageView) findViewById(R.id.attachment_close);
    attachment_close.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            attachment_linear.setVisibility(View.GONE);
        }
    });
    recordingContainer = findViewById(R.id.recording_container);
    game_container = findViewById(R.id.game_container);
    micImage = (ImageView) findViewById(R.id.mic_image);
    recordingHint = (TextView) findViewById(R.id.recording_hint);
    listView = (ListView) findViewById(R.id.list);
    mEditTextContent = (PasteEditText) findViewById(R.id.et_sendmessage);
    // buttonSetModeKeyboard = findViewById(R.id.btn_set_mode_keyboard);
    edittext_layout = (RelativeLayout) findViewById(R.id.edittext_layout);
    buttonSetModeVoice = (ImageView) findViewById(R.id.btn_set_mode_voice);

    buttonSend = findViewById(R.id.btn_send);
    buttonPressToSpeak = findViewById(R.id.btn_press_to_speak);
    expressionContainer = (LinearLayout) findViewById(R.id.ll_face_container);
    more_container = (LinearLayout) findViewById(R.id.more_container);
    // locationImgview = (ImageView) findViewById(R.id.btn_location);
    bt_emoticons = (ImageView) findViewById(R.id.bt_emoticons);
    loadmorePB = (ProgressBar) findViewById(R.id.pb_load_more);
    btnMore = (ImageView) findViewById(R.id.btn_more);
    all_container = findViewById(R.id.all_container);
    edittext_layout.setBackgroundResource(R.drawable.input_bar_bg_normal);

    bt_question = (ImageView) findViewById(R.id.bt_question);
    btn_game = (ImageView) findViewById(R.id.btn_game);
    questionContainer = findViewById(R.id.question_container);

    // ?,
    micImages = new Drawable[] { getResources().getDrawable(R.drawable.record_animate_01),
            getResources().getDrawable(R.drawable.record_animate_02),
            getResources().getDrawable(R.drawable.record_animate_03),
            getResources().getDrawable(R.drawable.record_animate_04),
            getResources().getDrawable(R.drawable.record_animate_05),
            getResources().getDrawable(R.drawable.record_animate_06),
            getResources().getDrawable(R.drawable.record_animate_07),
            getResources().getDrawable(R.drawable.record_animate_08),
            getResources().getDrawable(R.drawable.record_animate_09),
            getResources().getDrawable(R.drawable.record_animate_10),
            getResources().getDrawable(R.drawable.record_animate_11),
            getResources().getDrawable(R.drawable.record_animate_12),
            getResources().getDrawable(R.drawable.record_animate_13),
            getResources().getDrawable(R.drawable.record_animate_14) };

    // expressionViewpager.setAdapter(new ExpressionPagerAdapter(views));
    edittext_layout.requestFocus();
    voiceRecorder = new VoiceRecorder(micImageHandler);
    buttonPressToSpeak.setOnTouchListener(new PressToSpeakListen());
    mEditTextContent.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                edittext_layout.setBackgroundResource(R.drawable.input_bar_bg_active);
            } else {
                edittext_layout.setBackgroundResource(R.drawable.input_bar_bg_normal);
            }
        }
    });

    // ?
    mEditTextContent.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (!TextUtils.isEmpty(s)) {
                buttonSetModeVoice.setVisibility(View.GONE);
                buttonSend.setVisibility(View.VISIBLE);
            } else {
                buttonSetModeVoice.setVisibility(View.VISIBLE);
                buttonSend.setVisibility(View.GONE);
            }
        }

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

        @Override
        public void afterTextChanged(Editable s) {

        }
    });
}

From source file:com.money.manager.ex.transactions.EditTransactionCommonFunctions.java

public void initTransactionNumberControls() {
    // Transaction number

    if (!TextUtils.isEmpty(transactionEntity.getTransactionNumber())) {
        viewHolder.edtTransNumber.setText(transactionEntity.getTransactionNumber());
    }/* www.j  av a 2s  .c  om*/

    viewHolder.edtTransNumber.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void afterTextChanged(Editable editable) {
            setDirty(true);

            transactionEntity.setTransactionNumber(editable.toString());
        }
    });

    viewHolder.btnTransNumber.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AccountTransactionRepository repo = new AccountTransactionRepository(getContext());

            String sql = "SELECT MAX(CAST(" + ITransactionEntity.TRANSACTIONNUMBER + " AS INTEGER)) FROM "
                    + repo.getSource() + " WHERE " + ITransactionEntity.ACCOUNTID + "=?";

            String accountId = transactionEntity.getAccountId().toString();
            Cursor cursor = mDatabase.query(sql, accountId);
            if (cursor == null)
                return;

            if (cursor.moveToFirst()) {
                String transNumber = cursor.getString(0);
                if (TextUtils.isEmpty(transNumber)) {
                    transNumber = "0";
                }
                if ((!TextUtils.isEmpty(transNumber)) && TextUtils.isDigitsOnly(transNumber)) {
                    try {
                        // Use Money type to support very large numbers.
                        Money transactionNumber = MoneyFactory.fromString(transNumber);
                        viewHolder.edtTransNumber
                                .setText(transactionNumber.add(MoneyFactory.fromString("1")).toString());
                    } catch (Exception e) {
                        Timber.e(e, "increasing transaction number");
                    }
                }
            }
            cursor.close();
        }
    });
}

From source file:com.google.sample.cast.refplayer.chatting.MainActivity.java

public void setDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Type Your Name");
    final EditText InputName = new EditText(this);
    InputName.setInputType(InputType.TYPE_CLASS_TEXT);
    builder.setView(InputName);// w ww.j  a v  a 2  s  . c om
    builder.setPositiveButton(R.string.start_chatting, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            UserName = InputName.getText().toString();
        }
    });
    builder.setCancelable(false);
    dialog = builder.create();

    InputName.addTextChangedListener(new TextWatcher() {

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

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

        @Override
        public void afterTextChanged(Editable s) {
            if (s.length() < 1 || s.length() > 20) {
                dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
            } else {
                dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
            }
        }
    });

    dialog.show();
    dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
}

From source file:br.com.GUI.avaliacoes.AvaliarGorduraCorporal.java

public void mapearComponentes() {

    b = new Banco(getActivity(), null, null, 0);

    tomadaDobraAbdominal = (RelativeLayout) getActivity().findViewById(R.id.lytTomadaDobraAbdominal);
    tomadaDobraCoxa = (RelativeLayout) getActivity().findViewById(R.id.lytTomadaDobraCoxa);
    tomadaDobraSubscapular = (RelativeLayout) getActivity().findViewById(R.id.lytTomadaDobraSubscapular);
    tomadaDobraPeito = (RelativeLayout) getActivity().findViewById(R.id.lytTomadaDobraPeito);
    tomadaDobraLinhaAxilarMedia = (RelativeLayout) getActivity()
            .findViewById(R.id.lytTomadaDobraLinhaAxilarMedia);
    tomadaDobraTriceps = (RelativeLayout) getActivity().findViewById(R.id.lytTomadaDobraTriceps);
    tomadaDobraSuprailiaca = (RelativeLayout) getActivity().findViewById(R.id.lytTomadaDobraSuprailiaca);
    tomadaDobraPanturrilha = (RelativeLayout) getActivity().findViewById(R.id.lytPanturrilha);

    tomadaDobraAbdominal.setVisibility(View.GONE);
    tomadaDobraCoxa.setVisibility(View.GONE);
    tomadaDobraSubscapular.setVisibility(View.GONE);
    tomadaDobraPeito.setVisibility(View.GONE);
    tomadaDobraLinhaAxilarMedia.setVisibility(View.GONE);
    tomadaDobraTriceps.setVisibility(View.GONE);
    tomadaDobraSuprailiaca.setVisibility(View.GONE);
    tomadaDobraPanturrilha.setVisibility(View.GONE);

    imgTutorialTomarDobraAbdominal = (ImageView) getActivity()
            .findViewById(R.id.imgTutorialTomarDobraAbdominal);
    imgTutorialTomarDobraAbdominal.setOnClickListener(new OnClickListener() {

        @Override//from ww  w  .  java  2 s.  c om
        public void onClick(View arg0) {
            Intent i = new Intent(getActivity(), MedidaAbdominal.class);
            startActivity(i);
        }
    });
    imgTutorialTomarDobraCoxa = (ImageView) getActivity().findViewById(R.id.imgTutorialTomarDobraCoxa);
    imgTutorialTomarDobraCoxa.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            Intent i = new Intent(getActivity(), MedidaCoxa.class);
            startActivity(i);
        }
    });
    imgTutorialTomarDobraSubscapular = (ImageView) getActivity()
            .findViewById(R.id.imgTutorialTomarDobraSubscapular);
    imgTutorialTomarDobraSubscapular.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            Intent i = new Intent(getActivity(), MedidaSubscapular.class);
            startActivity(i);
        }
    });
    imgTutorialTomarDobraPeito = (ImageView) getActivity().findViewById(R.id.imgTutorialTomarDobraPeito);
    imgTutorialTomarDobraPeito.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            Intent i = new Intent(getActivity(), MedidaPeitoral.class);
            startActivity(i);
        }
    });

    imgTutorialTomarDobraLinhaAxilarMedia = (ImageView) getActivity()
            .findViewById(R.id.imgTutorialTomarDobraLinhaAxilarMedia);
    imgTutorialTomarDobraLinhaAxilarMedia.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            Intent i = new Intent(getActivity(), MedidaAxilarMedia.class);
            startActivity(i);
        }
    });
    imgTutorialTomarDobraTriceps = (ImageView) getActivity().findViewById(R.id.imgTutorialTomarDobraTriceps);
    imgTutorialTomarDobraTriceps.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            Intent i = new Intent(getActivity(), MedidaTricipital.class);
            startActivity(i);
        }
    });
    imgTutorialTomarDobraSuprailiaca = (ImageView) getActivity()
            .findViewById(R.id.imgTutorialTomarDobraSuprailiaca);
    imgTutorialTomarDobraSuprailiaca.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            Intent i = new Intent(getActivity(), MedidaSuprailiaca.class);
            startActivity(i);
        }
    });

    imgTutorialTomarDobraPanturrilha = (ImageView) getActivity()
            .findViewById(R.id.imgTutorialTomarDobraPanturrilha);
    imgTutorialTomarDobraPanturrilha.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            Intent i = new Intent(getActivity(), MedidaPanturrilha.class);
            startActivity(i);
        }
    });

    avaliacoes = getActivity().getApplicationContext().getSharedPreferences("novaAvaliacao", 0);
    editor = avaliacoes.edit();

    spnMetodoDeCalculo = (Spinner) getActivity().findViewById(R.id.spnMetodoDeCalculo);

    nmbAltura = (NumberPicker) getActivity().findViewById(R.id.nmbAltura);
    nmbPeso = (NumberPicker) getActivity().findViewById(R.id.nmbPeso);
    nmbIdade = (NumberPicker) getActivity().findViewById(R.id.nmbIdade);

    edtDobraAbdomen = (EditText) getActivity().findViewById(R.id.edtDobraAbdomen);
    edtDobraCoxa = (EditText) getActivity().findViewById(R.id.edtDobraCoxa);
    edtDobraSubscapular = (EditText) getActivity().findViewById(R.id.edtDobraSubscapular);
    edtDobraPeito = (EditText) getActivity().findViewById(R.id.edtDobraPeito);
    edtDobraLinhaAxilarMedia = (EditText) getActivity().findViewById(R.id.edtDobraLinhaAxilarMedia);
    edtDobraTriceps = (EditText) getActivity().findViewById(R.id.edtDobraTriceps);
    edtDobraSuprailiaca = (EditText) getActivity().findViewById(R.id.edtDobraSuprailiaca);
    edtDobraPanturrilha = (EditText) getActivity().findViewById(R.id.txtDobraPanturrilha);

    skDobraAbdomen = (SeekBar) getActivity().findViewById(R.id.skDobraAbdomen);
    skDobraCoxa = (SeekBar) getActivity().findViewById(R.id.skDobraCoxa);
    skDobraSubscapular = (SeekBar) getActivity().findViewById(R.id.skDobraSubscapular);
    skDobraPeito = (SeekBar) getActivity().findViewById(R.id.skDobraPeito);
    skDobraLinhaAxilarMedia = (SeekBar) getActivity().findViewById(R.id.skDobraLinhaAxilarMedia);
    skDobraTriceps = (SeekBar) getActivity().findViewById(R.id.skDobraTriceps);
    skDobraSuprailiaca = (SeekBar) getActivity().findViewById(R.id.skDobraSuprailiaca);
    skDobraPanturrilha = (SeekBar) getActivity().findViewById(R.id.skDobraPanturrilha);

    skDobraAbdomen.setMax(30);
    skDobraPeito.setMax(30);
    skDobraCoxa.setMax(30);
    skDobraLinhaAxilarMedia.setMax(30);
    skDobraSuprailiaca.setMax(30);
    skDobraTriceps.setMax(30);
    skDobraSubscapular.setMax(30);

    nmbAltura.setMinValue(0);
    nmbPeso.setMinValue(0);
    nmbAltura.setMaxValue(200);
    nmbPeso.setMaxValue(200);
    nmbIdade.setMinValue(0);
    nmbIdade.setMaxValue(150);

    nmbAltura.setWrapSelectorWheel(true);
    nmbPeso.setWrapSelectorWheel(true);
    nmbIdade.setWrapSelectorWheel(true);

    skDobraAbdomen.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar arg0) {

        }

        @Override
        public void onStartTrackingTouch(SeekBar arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
            edtDobraAbdomen.setText(String.valueOf(arg1));

        }
    });

    nmbPeso.setOnValueChangedListener(new OnValueChangeListener() {

        @Override
        public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            editor.putFloat("peso", newVal);
            editor.commit();
        }
    });

    nmbAltura.setOnValueChangedListener(new OnValueChangeListener() {

        @Override
        public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            editor.putFloat("altura", newVal);
            editor.commit();
        }
    });

    nmbIdade.setOnValueChangedListener(new OnValueChangeListener() {

        @Override
        public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            editor.putInt("idade", newVal);
            editor.commit();
        }
    });

    skDobraPeito.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar arg0) {

        }

        @Override
        public void onStartTrackingTouch(SeekBar arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
            edtDobraPeito.setText(String.valueOf(arg1));

        }
    });

    skDobraPanturrilha.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar arg0) {

        }

        @Override
        public void onStartTrackingTouch(SeekBar arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
            edtDobraPanturrilha.setText(String.valueOf(arg1));

        }
    });

    skDobraCoxa.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar arg0) {

        }

        @Override
        public void onStartTrackingTouch(SeekBar arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
            edtDobraCoxa.setText(String.valueOf(arg1));

        }
    });

    skDobraLinhaAxilarMedia.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar arg0) {

        }

        @Override
        public void onStartTrackingTouch(SeekBar arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
            edtDobraLinhaAxilarMedia.setText(String.valueOf(arg1));

        }
    });

    skDobraSuprailiaca.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar arg0) {

        }

        @Override
        public void onStartTrackingTouch(SeekBar arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
            edtDobraSuprailiaca.setText(String.valueOf(arg1));

        }
    });

    skDobraTriceps.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar arg0) {

        }

        @Override
        public void onStartTrackingTouch(SeekBar arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
            edtDobraTriceps.setText(String.valueOf(arg1));

        }
    });

    skDobraSubscapular.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar arg0) {

        }

        @Override
        public void onStartTrackingTouch(SeekBar arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
            edtDobraSubscapular.setText(String.valueOf(arg1));

        }
    });

    //Adiciona Persistencia

    edtDobraPeito.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable s) {
            try {
                editor.putFloat("dobraPeito", Float.parseFloat(s.toString()));
            } catch (Exception e) {
                editor.putFloat("dobraPeito", 0);
            } finally {
                editor.commit();
            }
        }
    });

    edtDobraAbdomen.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable s) {
            try {
                editor.putFloat("dobraAbdomen", Float.parseFloat(s.toString()));
            } catch (Exception e) {
                editor.putFloat("dobraAbdomen", 0);
            } finally {
                editor.commit();
            }

        }
    });

    edtDobraCoxa.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable s) {
            try {
                editor.putFloat("dobraCoxa", Float.parseFloat(s.toString()));
            } catch (Exception e) {
                editor.putFloat("dobraCoxa", 0);
            } finally {
                editor.commit();
            }

        }
    });

    edtDobraLinhaAxilarMedia.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable s) {
            try {
                editor.putFloat("dobraLinhaAxilarMedia", Float.parseFloat(s.toString()));
            } catch (Exception e) {
                editor.putFloat("dobraLinhaAxilarMedia", 0);
            } finally {
                editor.commit();
            }

        }
    });

    edtDobraSuprailiaca.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable s) {
            try {
                editor.putFloat("dobraSuprailiaca", Float.parseFloat(s.toString()));
            } catch (Exception e) {
                editor.putFloat("dobraSuprailiaca", 0);
            } finally {
                editor.commit();
            }

        }
    });

    edtDobraTriceps.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable s) {
            try {
                editor.putFloat("dobraTriceps", Float.parseFloat(s.toString()));
            } catch (Exception e) {
                editor.putFloat("dobraTriceps", 0);
            } finally {
                editor.commit();
            }

        }
    });

    edtDobraSubscapular.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable s) {
            try {
                editor.putFloat("dobraSubscapular", Float.parseFloat(s.toString()));

            } catch (Exception e) {
                editor.putFloat("dobraSubscapular", 0);
            } finally {
                editor.commit();
            }

        }
    });

}

From source file:com.jamiealtizer.cordova.inappbrowser.InAppBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url           The url to load.
 * @param jsonObject/*from  ww w. j av  a2s.c  o  m*/
 */
public String showWebPage(final String url, HashMap<String, Boolean> features) {
    // Determine if we should hide the location bar.
    showLocationBar = true;
    showZoomControls = true;
    openWindowHidden = false;
    if (features != null) {
        Boolean show = features.get(LOCATION);
        if (show != null) {
            showLocationBar = show.booleanValue();
        }
        Boolean zoom = features.get(ZOOM);
        if (zoom != null) {
            showZoomControls = zoom.booleanValue();
        }
        Boolean hidden = features.get(HIDDEN);
        if (hidden != null) {
            openWindowHidden = hidden.booleanValue();
        }
        Boolean hardwareBack = features.get(HARDWARE_BACK_BUTTON);
        if (hardwareBack != null) {
            hadwareBackButton = hardwareBack.booleanValue();
        }
        Boolean cache = features.get(CLEAR_ALL_CACHE);
        if (cache != null) {
            clearAllCache = cache.booleanValue();
        } else {
            cache = features.get(CLEAR_SESSION_CACHE);
            if (cache != null) {
                clearSessionCache = cache.booleanValue();
            }
        }
    }

    final CordovaWebView thatWebView = this.webView;

    // Create dialog in new thread
    Runnable runnable = new Runnable() {
        /**
         * Convert our DIP units to Pixels
         *
         * @return int
         */
        private int dpToPixels(int dipValue) {
            int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue,
                    cordova.getActivity().getResources().getDisplayMetrics());

            return value;
        }

        @SuppressLint("NewApi")
        public void run() {
            // Let's create the main dialog
            final Context ctx = cordova.getActivity();
            dialog = new InAppBrowserDialog(ctx, android.R.style.Theme_NoTitleBar);
            dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setInAppBroswer(getInAppBrowser());

            // Main container layout
            LinearLayout main = new LinearLayout(ctx);
            main.setOrientation(LinearLayout.VERTICAL);

            // Toolbar layout
            RelativeLayout toolbar = new RelativeLayout(ctx);
            //Please, no more black!
            toolbar.setBackgroundColor(android.graphics.Color.LTGRAY); // JAMIE REVIEW
            toolbar.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44)));
            toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2));
            toolbar.setHorizontalGravity(Gravity.LEFT);
            toolbar.setVerticalGravity(Gravity.CENTER_VERTICAL);

            // Action Button Container layout
            RelativeLayout actionButtonContainer = new RelativeLayout(ctx);
            actionButtonContainer.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            actionButtonContainer.setHorizontalGravity(Gravity.LEFT);
            actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);
            actionButtonContainer.setId(1);

            // Back button
            final ButtonAwesome back = new ButtonAwesome(ctx);
            RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT);
            back.setLayoutParams(backLayoutParams);
            back.setContentDescription("Back Button");
            back.setId(2);
            back.setBackgroundResource(ExternalResourceHelper.getDrawable(ctx, "buttonbackground"));
            back.setTextColor(ExternalResourceHelper.getColor(ctx, "gray"));
            back.setText(ExternalResourceHelper.getStrings(ctx, "fa_chevron_left"));
            back.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24);
            //            if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN)
            //                {
            //                    back.setBackgroundDrawable(backIcon);
            //                }
            //                else
            //                {
            //                    back.setBackground(backIcon);
            //                }
            back.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goBack();
                }
            });

            // Forward button
            final ButtonAwesome forward = new ButtonAwesome(ctx);
            RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2);
            forward.setLayoutParams(forwardLayoutParams);
            forward.setContentDescription("Forward Button");
            forward.setId(3);
            forward.setBackgroundResource(ExternalResourceHelper.getDrawable(ctx, "buttonbackground"));
            forward.setTextColor(ExternalResourceHelper.getColor(ctx, "gray"));
            forward.setText(ExternalResourceHelper.getStrings(ctx, "fa_chevron_right"));
            forward.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24);
            //            if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN)
            //                {
            //                    forward.setBackgroundDrawable(fwdIcon);
            //                }
            //                else
            //                {
            //                    forward.setBackground(fwdIcon);
            //                }
            forward.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goForward();
                }
            });

            // external button
            ButtonAwesome external = new ButtonAwesome(ctx);
            RelativeLayout.LayoutParams externalLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            externalLayoutParams.addRule(RelativeLayout.RIGHT_OF, 3);
            external.setLayoutParams(externalLayoutParams);
            external.setContentDescription("Back Button");
            external.setId(7);
            external.setBackgroundResource(ExternalResourceHelper.getDrawable(ctx, "buttonbackground"));
            external.setTextColor(ExternalResourceHelper.getColor(ctx, "white"));
            external.setText(ExternalResourceHelper.getStrings(ctx, "fa_external_link"));
            external.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24);
            external.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    openExternal(edittext.getText().toString());
                    closeDialog();
                }
            });

            // Edit Text Box
            edittext = new EditText(ctx);
            RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
            textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
            edittext.setLayoutParams(textLayoutParams);
            edittext.setId(4);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
            edittext.setImeOptions(EditorInfo.IME_ACTION_GO);
            edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE
            edittext.addTextChangedListener(new TextWatcher() {
                public void afterTextChanged(Editable s) {
                    if (s.length() > 0) {
                        if (inAppWebView.canGoBack()) {
                            back.setTextColor(ExternalResourceHelper.getColor(ctx, "white"));
                        } else {
                            back.setTextColor(ExternalResourceHelper.getColor(ctx, "gray"));
                        }
                        if (inAppWebView.canGoForward()) {
                            forward.setTextColor(ExternalResourceHelper.getColor(ctx, "white"));
                        } else {
                            forward.setTextColor(ExternalResourceHelper.getColor(ctx, "gray"));
                        }
                    }
                }

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

                public void onTextChanged(CharSequence s, int start, int before, int count) {
                }
            });
            edittext.setOnKeyListener(new View.OnKeyListener() {
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    // If the event is a key-down event on the "enter" button
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        navigate(edittext.getText().toString());
                        return true;
                    }
                    return false;
                }
            });

            // Close/Done button
            ButtonAwesome close = new ButtonAwesome(ctx);
            RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            close.setLayoutParams(closeLayoutParams);
            close.setContentDescription("Close Button");
            close.setId(5);
            close.setBackgroundResource(ExternalResourceHelper.getDrawable(ctx, "buttonbackground"));
            close.setText(ExternalResourceHelper.getStrings(ctx, "fa_times"));
            close.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24);
            close.setTextColor(ExternalResourceHelper.getColor(ctx, "white"));
            //            if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN)
            //                {
            //                    close.setBackgroundDrawable(closeIcon);
            //                }
            //                else
            //                {
            //                    close.setBackground(closeIcon);
            //                }
            close.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    closeDialog();
                }
            });

            // WebView
            inAppWebView = new WebView(ctx);
            inAppWebView.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
            inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView));
            WebViewClient client = new InAppBrowserClient(thatWebView, edittext);
            inAppWebView.setWebViewClient(client);
            WebSettings settings = inAppWebView.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(showZoomControls);
            settings.setPluginState(android.webkit.WebSettings.PluginState.ON);

            //Toggle whether this is enabled or not!
            Bundle appSettings = cordova.getActivity().getIntent().getExtras();
            boolean enableDatabase = appSettings == null ? true
                    : appSettings.getBoolean("InAppBrowserStorageEnabled", true);
            if (enableDatabase) {
                String databasePath = ctx.getApplicationContext().getDir("inAppBrowserDB", Context.MODE_PRIVATE)
                        .getPath();
                settings.setDatabasePath(databasePath);
                settings.setDatabaseEnabled(true);
            }
            settings.setDomStorageEnabled(true);

            if (clearAllCache) {
                CookieManager.getInstance().removeAllCookie();
            } else if (clearSessionCache) {
                CookieManager.getInstance().removeSessionCookie();
            }

            inAppWebView.loadUrl(url);
            inAppWebView.setId(6);
            inAppWebView.getSettings().setLoadWithOverviewMode(true);
            inAppWebView.getSettings().setUseWideViewPort(true);
            inAppWebView.requestFocus();
            inAppWebView.requestFocusFromTouch();

            // Add the back and forward buttons to our action button container layout
            actionButtonContainer.addView(back);
            actionButtonContainer.addView(forward);
            actionButtonContainer.addView(external);

            // Add the views to our toolbar
            toolbar.addView(actionButtonContainer);
            if (getShowLocationBar()) {
                toolbar.addView(edittext);
            }
            toolbar.setBackgroundColor(ExternalResourceHelper.getColor(ctx, "green"));
            toolbar.addView(close);

            // Don't add the toolbar if its been disabled
            //if (getShowLocationBar()) {
            // Add our toolbar to our main view/layout
            main.addView(toolbar);
            //}

            // Add our webview to our main view/layout
            main.addView(inAppWebView);

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.height = WindowManager.LayoutParams.MATCH_PARENT;

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
            // the goal of openhidden is to load the url and not display it
            // Show() needs to be called to cause the URL to be loaded
            if (openWindowHidden) {
                dialog.hide();
            }
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}

From source file:com.haibison.android.anhuu.FragmentFiles.java

/**
 * Setup://from w ww .j  a  v  a 2s. c  o  m
 * <p/>
 * <ul>
 * <li>button Cancel;</li>
 * <li>text field "save as" filename;</li>
 * <li>button OK;</li>
 * </ul>
 */
private void setupFooter() {
    /*
     * By default, view group footer and all its child views are hidden.
     */

    ViewGroup viewGroupFooterContainer = (ViewGroup) getView()
            .findViewById(R.id.anhuu_f5be488d_viewgroup_footer_container);
    ViewGroup viewGroupFooter = (ViewGroup) getView().findViewById(R.id.anhuu_f5be488d_viewgroup_footer);

    if (mIsSaveDialog) {
        viewGroupFooterContainer.setVisibility(View.VISIBLE);
        viewGroupFooter.setVisibility(View.VISIBLE);

        mTextSaveas.setVisibility(View.VISIBLE);
        mTextSaveas.setText(getArguments().getString(FileChooserActivity.EXTRA_DEFAULT_FILENAME));
        mTextSaveas.setOnEditorActionListener(new TextView.OnEditorActionListener() {

            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_DONE) {
                    UI.showSoftKeyboard(v, false);
                    mBtnOk.performClick();
                    return true;
                }
                return false;
            }// onEditorAction()
        });
        mTextSaveas.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                /*
                 * Do nothing.
                 */
            }// onTextChanged()

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                /*
                 * Do nothing.
                 */
            }// beforeTextChanged()

            @Override
            public void afterTextChanged(Editable s) {
                /*
                 * If the user taps a file, the tag is set to that file's
                 * URI. But if the user types the file name, we remove the
                 * tag.
                 */
                mTextSaveas.setTag(null);
            }// afterTextChanged()
        });

        mBtnOk.setVisibility(View.VISIBLE);
        mBtnOk.setOnClickListener(mBtnOk_SaveDialog_OnClickListener);
        mBtnOk.setBackgroundResource(
                UI.resolveAttribute(getActivity(), R.attr.anhuu_f5be488d_selector_button_ok_saveas));

        int size = getResources().getDimensionPixelSize(R.dimen.anhuu_f5be488d_button_ok_saveas_size);
        LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mBtnOk.getLayoutParams();
        lp.width = size;
        lp.height = size;
        mBtnOk.setLayoutParams(lp);
    } // this is in save mode
    else {
        if (mIsMultiSelection) {
            viewGroupFooterContainer.setVisibility(View.VISIBLE);
            viewGroupFooter.setVisibility(View.VISIBLE);

            ViewGroup.LayoutParams lp = viewGroupFooter.getLayoutParams();
            lp.width = ViewGroup.LayoutParams.WRAP_CONTENT;
            viewGroupFooter.setLayoutParams(lp);

            mBtnOk.setMinWidth(
                    getResources().getDimensionPixelSize(R.dimen.anhuu_f5be488d_single_button_min_width));
            mBtnOk.setText(android.R.string.ok);
            mBtnOk.setVisibility(View.VISIBLE);
            mBtnOk.setOnClickListener(mBtnOk_OpenDialog_OnClickListener);
        }
    } // this is in open mode
}