Example usage for android.widget TextView getLayoutParams

List of usage examples for android.widget TextView getLayoutParams

Introduction

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

Prototype

@ViewDebug.ExportedProperty(deepExport = true, prefix = "layout_")
public ViewGroup.LayoutParams getLayoutParams() 

Source Link

Document

Get the LayoutParams associated with this view.

Usage

From source file:kr.wdream.ui.Components.PasscodeView.java

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

    setWillNotDraw(false);/*from  w  w w . j  a  v  a 2s . c  o  m*/
    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(kr.wdream.storyshop.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);
            }
        }
    });
    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(kr.wdream.storyshop.R.drawable.passcode_check);
    checkImage.setScaleType(ImageView.ScaleType.CENTER);
    checkImage.setBackgroundResource(kr.wdream.storyshop.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(kr.wdream.storyshop.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(kr.wdream.storyshop.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:ir.besteveryeverapp.ui.Components.PasscodeView.java

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

    setWillNotDraw(false);//  w ww . ja  v a 2  s . 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.setTypeface(FontManager.instance().getTypeface());
    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);
            }
        }
    });
    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.setTypeface(FontManager.instance().getTypeface());
        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.setTypeface(FontManager.instance().getTypeface());
        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.goftagram.telegram.ui.Components.PasscodeView.java

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

    setWillNotDraw(false);//w  ww  .  j  a va 2  s.  c  o  m
    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:github.daneren2005.dsub.fragments.SelectDirectoryFragment.java

private void setupTextDisplay(final View header) {
    final TextView titleView = (TextView) header.findViewById(R.id.select_album_title);
    if (playlistName != null) {
        titleView.setText(playlistName);
    } else if (podcastName != null) {
        titleView.setText(podcastName);/*  ww  w  .  ja v  a 2 s .  c  o m*/
        titleView.setPadding(0, 6, 4, 8);
    } else if (name != null) {
        titleView.setText(name);

        if (artistInfo != null) {
            titleView.setPadding(0, 6, 4, 8);
        }
    } else if (share != null) {
        titleView.setVisibility(View.GONE);
    }

    int songCount = 0;

    Set<String> artists = new HashSet<String>();
    Set<Integer> years = new HashSet<Integer>();
    Integer totalDuration = 0;
    for (Entry entry : entries) {
        if (!entry.isDirectory()) {
            songCount++;
            if (entry.getArtist() != null) {
                artists.add(entry.getArtist());
            }
            if (entry.getYear() != null) {
                years.add(entry.getYear());
            }
            Integer duration = entry.getDuration();
            if (duration != null) {
                totalDuration += duration;
            }
        }
    }

    final TextView artistView = (TextView) header.findViewById(R.id.select_album_artist);
    if (podcastDescription != null || artistInfo != null) {
        artistView.setVisibility(View.VISIBLE);
        String text = podcastDescription != null ? podcastDescription : artistInfo.getBiography();
        Spanned spanned = null;
        if (text != null) {
            spanned = Html.fromHtml(text);
        }
        artistView.setText(spanned);
        artistView.setSingleLine(false);
        final int minLines = context.getResources().getInteger(R.integer.TextDescriptionLength);
        artistView.setLines(minLines);
        artistView.setTextAppearance(context, android.R.style.TextAppearance_Small);

        final Spanned spannedText = spanned;
        artistView.setOnClickListener(new View.OnClickListener() {
            @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
            @Override
            public void onClick(View v) {
                if (artistView.getMaxLines() == minLines) {
                    // Use LeadingMarginSpan2 to try to make text flow around image
                    Display display = context.getWindowManager().getDefaultDisplay();
                    ImageView coverArtView = (ImageView) header.findViewById(R.id.select_album_art);
                    coverArtView.measure(display.getWidth(), display.getHeight());

                    int height, width;
                    ViewGroup.MarginLayoutParams vlp = (ViewGroup.MarginLayoutParams) coverArtView
                            .getLayoutParams();
                    if (coverArtView.getDrawable() != null) {
                        height = coverArtView.getMeasuredHeight() + coverArtView.getPaddingBottom();
                        width = coverArtView.getWidth() + coverArtView.getPaddingRight();
                    } else {
                        height = coverArtView.getHeight();
                        width = coverArtView.getWidth() + coverArtView.getPaddingRight();
                    }
                    float textLineHeight = artistView.getPaint().getTextSize();
                    int lines = (int) Math.ceil(height / textLineHeight);

                    SpannableString ss = new SpannableString(spannedText);
                    ss.setSpan(new MyLeadingMarginSpan2(lines, width), 0, ss.length(),
                            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

                    View linearLayout = header.findViewById(R.id.select_album_text_layout);
                    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) linearLayout
                            .getLayoutParams();
                    int[] rules = params.getRules();
                    rules[RelativeLayout.RIGHT_OF] = 0;
                    params.leftMargin = vlp.rightMargin;

                    artistView.setText(ss);
                    artistView.setMaxLines(100);

                    vlp = (ViewGroup.MarginLayoutParams) titleView.getLayoutParams();
                    vlp.leftMargin = width;
                } else {
                    artistView.setMaxLines(minLines);
                }
            }
        });
        artistView.setMovementMethod(LinkMovementMethod.getInstance());
    } else if (topTracks) {
        artistView.setText(R.string.menu_top_tracks);
        artistView.setVisibility(View.VISIBLE);
    } else if (showAll) {
        artistView.setText(R.string.menu_show_all);
        artistView.setVisibility(View.VISIBLE);
    } else if (artists.size() == 1) {
        String artistText = artists.iterator().next();
        if (years.size() == 1) {
            artistText += " - " + years.iterator().next();
        }
        artistView.setText(artistText);
        artistView.setVisibility(View.VISIBLE);
    } else {
        artistView.setVisibility(View.GONE);
    }

    TextView songCountView = (TextView) header.findViewById(R.id.select_album_song_count);
    TextView songLengthView = (TextView) header.findViewById(R.id.select_album_song_length);
    if (podcastDescription != null || artistInfo != null) {
        songCountView.setVisibility(View.GONE);
        songLengthView.setVisibility(View.GONE);
    } else {
        String s = context.getResources().getQuantityString(R.plurals.select_album_n_songs, songCount,
                songCount);
        songCountView.setText(s.toUpperCase());
        songLengthView.setText(Util.formatDuration(totalDuration));
    }
}

From source file:org.de.jmg.learn._MainActivity.java

public void getVokabel(final boolean showBeds, boolean LoadNext, boolean requestFocusEdWord, boolean DontPrompt)
        throws Exception {

    if (iv != null) {
        iv.setVisibility(View.GONE);
    }//w w  w . j  av  a 2s.c o m
    if (iv2 != null)
        iv2.setVisibility(View.GONE);
    try {
        if (_btnRight == null)
            return;
        EndEdit(DontPrompt);
        setBtnsEnabled(true);
        if (showBeds && _vok.getIndex() >= 1) {
            _btnRight.setEnabled(true);
            _btnWrong.setEnabled(true);
            _btnEdit.setEnabled(true);
            _btnSkip.setEnabled(true);
            _btnView.setEnabled(true);
        } else {
            _btnRight.setEnabled(false);
            _btnWrong.setEnabled(false);
            if (_vok.getIndex() < 1) {
                _btnEdit.setEnabled(false);
                _btnSkip.setEnabled(false);
                _btnView.setEnabled(false);
            }
        }
        if (LoadNext)
            _vok.setLernIndex((short) (_vok.getLernIndex() + 1));

        View v;
        TextView t;
        String txtBed = getString(R.string.cloze);

        if (showBeds) {
            v = findViewById(R.id.txtMeaning1);
            t = (TextView) v;
            assert t != null;
            t.setText(lib.getSpanableString(_vok.getBedeutung1()));
            txtBed = t.getText().toString();
        }

        v = findViewById(R.id.word);
        t = (TextView) v;
        assert t != null;
        String txtWord = getString(R.string.cloze);
        if (!_vok.reverse || showBeds) {
            t.setText(lib.getSpanableString(_vok.getWort()), TextView.BufferType.SPANNABLE);
            txtWord = t.getText().toString();
            txtWord = replaceClozes(txtWord, txtBed);
            speak(txtWord, _vok.getLangWord(), "word", true);
        } else {
            t.setText("");
        }

        if (_vok.getSprache() == EnumSprachen.Hebrew || _vok.getSprache() == EnumSprachen.Griechisch
                || (_vok.getFontWort().getName().equalsIgnoreCase("Cardo"))) {
            t.setTypeface(_vok.TypefaceCardo);
            _txtedWord.setTypeface(_vok.TypefaceCardo);
        } else {
            t.setTypeface(Typeface.DEFAULT);
            _txtedWord.setTypeface(Typeface.DEFAULT);
        }
        t.scrollTo(0, 0);

        v = findViewById(R.id.Comment);
        t = (TextView) v;
        assert t != null;
        t.setVisibility(View.VISIBLE);

        SpannableString tspanKom = lib.getSpanableString(_vok.getKommentar());
        URLSpan[] urlSpans = tspanKom.getSpans(0, tspanKom.length(), URLSpan.class);
        for (final URLSpan span : urlSpans) {
            int start = tspanKom.getSpanStart(span);
            int end = tspanKom.getSpanEnd(span);
            String txt = tspanKom.toString().substring(start, end);
            if (txtIsPicture(txt)) {
                tspanKom.removeSpan(span);
                tspanKom.setSpan(new urlclickablespan(span.getURL()) {
                    @Override
                    public void onClick(View widget) {
                        Bitmap b;
                        try {
                            b = lib.downloadpicture(this.url);
                        } catch (Exception ex) {
                            b = null;
                        }
                        if (b != null) {
                            if (iv == null) {
                                iv = new ImageView(context);
                                SetTouchListener(iv);
                            }
                            b = resizeBM(b);
                            iv.setImageBitmap(b);
                            if (iv.getParent() == null) {
                                try {
                                    LayoutParams p = _txtMeaning1.getLayoutParams();
                                    //p.width = LayoutParams.WRAP_CONTENT;
                                    //p.height = LayoutParams.WRAP_CONTENT;
                                    rellayoutMain.addView(iv, p);
                                } catch (Exception ex) {
                                    Log.e("addImageView", ex.getMessage(), ex);
                                }
                            } else {
                                Log.d("ImageView", "exists");
                            }
                            _txtMeaning1.setVisibility(View.GONE);
                            iv.setVisibility(View.VISIBLE);
                        }
                    }
                }, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
        t.setText(tspanKom, TextView.BufferType.SPANNABLE);

        if (_vok.getSprache() == EnumSprachen.Hebrew || _vok.getSprache() == EnumSprachen.Griechisch
                || (_vok.getFontKom().getName().equalsIgnoreCase("Cardo"))) {
            t.setTypeface(_vok.TypefaceCardo);
            _txtedKom.setTypeface(_vok.TypefaceCardo);
        } else {
            t.setTypeface(Typeface.DEFAULT);
            _txtedKom.setTypeface(Typeface.DEFAULT);
        }
        if (_isSmallDevice && libString.IsNullOrEmpty(t.getText().toString())) {
            t.setVisibility(View.GONE);
        } else {
            t.setVisibility(View.VISIBLE);
        }
        t.scrollTo(0, 0);

        v = findViewById(R.id.txtMeaning1);
        t = (TextView) v;
        assert t != null;
        if (!libString.IsNullOrEmpty(_vok.getBedeutung2())) {
            t.setImeOptions(EditorInfo.IME_ACTION_NEXT);
        }
        if (_vok.reverse || showBeds) {
            SpannableString tspan = lib.getSpanableString(_vok.getBedeutung1());
            //final String picname = _main.getString(R.string.picture);
            t.setVisibility(View.VISIBLE);
            if (txtIsPicture(tspan.toString())) {
                URLSpan urlspn[] = tspan.getSpans(0, tspan.length(), URLSpan.class);
                for (URLSpan url : urlspn) {
                    Bitmap b;
                    try {
                        b = lib.downloadpicture(url.getURL());
                    } catch (Exception ex) {
                        b = null;
                    }
                    if (b != null) {
                        if (iv == null) {
                            iv = new ImageView(context);
                            SetTouchListener(iv);
                        }
                        b = resizeBM(b);
                        iv.setImageBitmap(b);
                        if (iv.getParent() == null) {
                            try {
                                LayoutParams p = t.getLayoutParams();
                                //p.width = LayoutParams.WRAP_CONTENT;
                                //p.height = LayoutParams.WRAP_CONTENT;
                                rellayoutMain.addView(iv, p);
                            } catch (Exception ex) {
                                Log.e("Imagview", ex.getMessage(), ex);
                            }
                        } else {
                            Log.d("ImageView", "exists");
                        }
                        t.setVisibility(View.GONE);
                        iv.setVisibility(View.VISIBLE);
                    }
                }

            } else {
                // iv.setVisibility(View.GONE);
                t.setVisibility(View.VISIBLE);
            }

            t.setText(tspan);
        } else {
            t.setText(Vokabel.getComment(_vok.getBedeutung1()));
        }
        if (_vok.reverse || showBeds) {
            String txt = t.getText().toString();
            txt = replaceClozes(txt, txtWord);
            speak(txt, _vok.getLangMeaning(), "meaning1", _vok.reverse);
        }
        if (_vok.getFontBed().getName().equalsIgnoreCase("Cardo")) {
            t.setTypeface(_vok.TypefaceCardo);
        } else {
            t.setTypeface(Typeface.DEFAULT);
        }
        t.setOnFocusChangeListener(FocusListenerMeaning1);
        t.scrollTo(0, 0);

        v = findViewById(R.id.txtMeaning2);
        t = (TextView) v;
        assert t != null;
        t.setText((_vok.reverse || showBeds ? _vok.getBedeutung2() : Vokabel.getComment(_vok.getBedeutung2())));
        if (_vok.getFontBed().getName().equalsIgnoreCase("Cardo")) {
            t.setTypeface(_vok.TypefaceCardo);
        } else {
            t.setTypeface(Typeface.DEFAULT);
        }
        if (libString.IsNullOrEmpty(_vok.getBedeutung2()) || _vok.getCardMode()) {
            t.setVisibility(View.GONE);
            _txtMeaning1.setImeOptions(EditorInfo.IME_ACTION_DONE);
        } else {
            t.setVisibility(View.VISIBLE);
            _txtMeaning1.setImeOptions(EditorInfo.IME_ACTION_NEXT);
            if (_vok.reverse || showBeds) {
                String txt = t.getText().toString();
                //if (txtWord != null)
                //   txt = txt.replaceAll("_{2,}", txtWord).replaceAll("\\.{4,}", txtWord);
                speak(txt, _vok.getLangMeaning(), "meaning2");
            }
        }

        v = findViewById(R.id.txtMeaning3);
        t = (TextView) v;
        assert t != null;
        t.setText((_vok.reverse || showBeds ? _vok.getBedeutung3() : Vokabel.getComment(_vok.getBedeutung3())));
        if (_vok.getFontBed().getName().equalsIgnoreCase("Cardo")) {
            t.setTypeface(_vok.TypefaceCardo);
        } else {
            t.setTypeface(Typeface.DEFAULT);
        }
        if (libString.IsNullOrEmpty(_vok.getBedeutung3()) || _vok.getCardMode()) {
            t.setVisibility(View.GONE);
            _txtMeaning2.setImeOptions(EditorInfo.IME_ACTION_DONE);
        } else {
            t.setVisibility(View.VISIBLE);
            _txtMeaning2.setImeOptions(EditorInfo.IME_ACTION_NEXT);
            _txtMeaning3.setImeOptions(EditorInfo.IME_ACTION_DONE);
            if (_vok.reverse || showBeds) {
                String txt = t.getText().toString();
                //if (txtWord != null)
                //   txt = txt.replaceAll("_{2,}", txtWord).replaceAll("\\.{4,}", txtWord);
                speak(txt, _vok.getLangMeaning(), "meaning3");
            }
        }

        if (_vok.reverse && showBeds)
            speak(txtWord, _vok.getLangWord(), "word");

        lib.setBgEditText(_txtMeaning1, _MeaningBG);
        lib.setBgEditText(_txtMeaning2, _MeaningBG);
        lib.setBgEditText(_txtMeaning3, _MeaningBG);
        if (!_isSmallDevice && !requestFocusEdWord) {
            _txtMeaning1.requestFocus();
        } else {
            if (!requestFocusEdWord)
                _txtWord.requestFocus();
            else
                _txtedWord.requestFocus();
        }
        SetActionBarTitle();

        _scrollView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

            @Override
            public void onGlobalLayout() {

                lib.removeLayoutListener(_scrollView.getViewTreeObserver(), this);
                hideKeyboard();
                if (showBeds) {
                    _scrollView.scrollTo(0, _txtMeaning1.getTop());
                } else {
                    _txtWord.requestFocus();
                    _scrollView.fullScroll(View.FOCUS_UP);
                }
            }
        });

    } catch (Exception e) {

        lib.ShowException(_main, e);
    }

}

From source file:github.popeen.dsub.fragments.SelectDirectoryFragment.java

private void setupTextDisplay(final View header) {

    final TextView titleView = (TextView) header.findViewById(R.id.select_album_title);
    if (playlistName != null) {
        titleView.setText(playlistName);
    } else if (podcastName != null) {
        Collections.reverse(entries);
        titleView.setText(podcastName);/* w ww .  j a va2  s  . co  m*/
        titleView.setPadding(0, 6, 4, 8);
    } else if (name != null) {
        titleView.setText(name);
        if (artistInfo != null) {
            titleView.setPadding(0, 6, 4, 8);
        }
    } else if (share != null) {
        titleView.setVisibility(View.GONE);
    }

    int songCount = 0;

    Set<String> artists = new HashSet<String>();
    Set<Integer> years = new HashSet<Integer>();
    totalDuration = 0;
    for (Entry entry : entries) {
        if (!entry.isDirectory()) {
            songCount++;
            if (entry.getArtist() != null) {
                artists.add(entry.getArtist());
            }
            if (entry.getYear() != null) {
                years.add(entry.getYear());
            }
            Integer duration = entry.getDuration();
            if (duration != null) {
                totalDuration += duration;
            }
        }
    }
    String artistName = "";
    bookDescription = "Could not collect any info about the book at this time";
    try {

        artistName = artists.iterator().next();
        String endpoint = "getBookDirectory";
        if (Util.isTagBrowsing(context)) {
            endpoint = "getBook";
        }
        SharedPreferences prefs = Util.getPreferences(context);
        String url = Util.getRestUrl(context, endpoint) + "&id=" + directory.getId() + "&f=json";

        Log.w("GetInfo", url);
        String artist, title;
        int year = 0;
        artist = title = "";

        try {
            artist = artists.iterator().next();
        } catch (Exception e) {
            Log.w("GetInfoArtist", e.toString());
        }
        try {
            title = titleView.getText().toString();
        } catch (Exception e) {
            Log.w("GetInfoTitle", e.toString());
        }
        try {
            year = years.iterator().next();
        } catch (Exception e) {
            Log.w("GetInfoYear", e.toString());
        }

        BookInfoAPIParams params = new BookInfoAPIParams(url, artist, title, year);
        bookInfo = new BookInfoAPI(context).execute(params).get();
        bookDescription = bookInfo[0];
        bookReader = bookInfo[1];

    } catch (Exception e) {
        Log.w("GetInfoError", e.toString());
    }
    if (bookDescription.equals("noInfo")) {
        bookDescription = "The server has no description for this book";
    }

    final TextView artistView = (TextView) header.findViewById(R.id.select_album_artist);
    if (podcastDescription != null || artistInfo != null || bookDescription != null) {
        artistView.setVisibility(View.VISIBLE);

        String text = "";
        if (bookDescription != null) {
            text = bookDescription;
        }
        if (podcastDescription != null) {
            text = podcastDescription;
        }
        if (artistInfo != null) {
            text = artistInfo.getBiography();
        }
        Spanned spanned = null;
        if (text != null) {
            String newText = "";
            try {
                if (!artistName.equals("")) {
                    newText += "<b>" + context.getResources().getString(R.string.main_artist) + "</b>: "
                            + artistName + "<br/>";
                }
            } catch (Exception e) {
            }
            try {
                if (totalDuration > 0) {
                    newText += "<b>" + context.getResources().getString(R.string.album_book_reader) + "</b>: "
                            + bookReader + "<br/>";
                }
            } catch (Exception e) {
            }
            try {
                if (totalDuration > 0) {
                    newText += "<b>" + context.getResources().getString(R.string.album_book_length) + "</b>: "
                            + Util.formatDuration(totalDuration) + "<br/>";
                }
            } catch (Exception e) {
            }
            try {
                newText += text + "<br/>";
            } catch (Exception e) {
            }
            spanned = Html.fromHtml(newText);
        }

        artistView.setText(spanned);
        artistView.setSingleLine(false);
        final int minLines = context.getResources().getInteger(R.integer.TextDescriptionLength);
        artistView.setLines(minLines);
        artistView.setTextAppearance(context, android.R.style.TextAppearance_Small);

        final Spanned spannedText = spanned;
        artistView.setOnClickListener(new View.OnClickListener() {
            @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
            @Override
            public void onClick(View v) {
                if (artistView.getMaxLines() == minLines) {
                    // Use LeadingMarginSpan2 to try to make text flow around image
                    Display display = context.getWindowManager().getDefaultDisplay();
                    ImageView coverArtView = (ImageView) header.findViewById(R.id.select_album_art);
                    coverArtView.measure(display.getWidth(), display.getHeight());

                    int height, width;
                    ViewGroup.MarginLayoutParams vlp = (ViewGroup.MarginLayoutParams) coverArtView
                            .getLayoutParams();
                    if (coverArtView.getDrawable() != null) {
                        height = coverArtView.getMeasuredHeight() + coverArtView.getPaddingBottom();
                        width = coverArtView.getWidth() + coverArtView.getPaddingRight();
                    } else {
                        height = coverArtView.getHeight();
                        width = coverArtView.getWidth() + coverArtView.getPaddingRight();
                    }
                    float textLineHeight = artistView.getPaint().getTextSize();

                    int lines = (int) Math.ceil(height / textLineHeight) + 1;

                    SpannableString ss = new SpannableString(spannedText);
                    ss.setSpan(new MyLeadingMarginSpan2(lines, width), 0, ss.length(),
                            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

                    View linearLayout = header.findViewById(R.id.select_album_text_layout);
                    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) linearLayout
                            .getLayoutParams();
                    int[] rules = params.getRules();
                    rules[RelativeLayout.RIGHT_OF] = 0;
                    params.leftMargin = vlp.rightMargin;

                    artistView.setText(ss);
                    artistView.setMaxLines(100);

                    vlp = (ViewGroup.MarginLayoutParams) titleView.getLayoutParams();
                    vlp.leftMargin = width;
                } else {
                    artistView.setMaxLines(minLines);
                }
            }
        });
        artistView.setMovementMethod(LinkMovementMethod.getInstance());
    } else if (topTracks) {
        artistView.setText(R.string.menu_top_tracks);
        artistView.setVisibility(View.VISIBLE);
    } else if (showAll) {
        artistView.setText(R.string.menu_show_all);
        artistView.setVisibility(View.VISIBLE);
    } else if (artists.size() == 1) {
        String artistText = artists.iterator().next();
        if (years.size() == 1) {
            artistText += " - " + years.iterator().next();
        }
        artistView.setText(artistText);
        artistView.setVisibility(View.VISIBLE);
    } else {
        artistView.setVisibility(View.GONE);
    }

    TextView songCountView = (TextView) header.findViewById(R.id.select_album_song_count);
    TextView songLengthView = (TextView) header.findViewById(R.id.select_album_song_length);
    if (podcastDescription != null || artistInfo != null) {
        songCountView.setVisibility(View.GONE);
        songLengthView.setVisibility(View.GONE);
    } else {
        String s = context.getResources().getQuantityString(R.plurals.select_album_n_songs, songCount,
                songCount);

        songCountView.setVisibility(View.GONE);
        songLengthView.setVisibility(View.GONE);
    }
}

From source file:com.initialxy.cordova.themeablebrowser.ThemeableBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url//w ww.  ja  v  a  2 s.c om
 * @param features
 * @return
 */
public String showWebPage(final String url, final Options features) {
    final CordovaWebView thatWebView = this.webView;

    // Create dialog in new thread
    Runnable runnable = new Runnable() {
        @SuppressLint("NewApi")
        public void run() {
            // Let's create the main dialog
            dialog = new ThemeableBrowserDialog(cordova.getActivity(), android.R.style.Theme_Black_NoTitleBar,
                    features.hardwareback);
            if (!features.disableAnimation) {
                dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            }
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setThemeableBrowser(getThemeableBrowser());

            // Main container layout
            ViewGroup main = null;

            if (features.fullscreen) {
                main = new FrameLayout(cordova.getActivity());
            } else {
                main = new LinearLayout(cordova.getActivity());
                ((LinearLayout) main).setOrientation(LinearLayout.VERTICAL);
            }

            // Toolbar layout
            Toolbar toolbarDef = features.toolbar;
            FrameLayout toolbar = new FrameLayout(cordova.getActivity());
            toolbar.setBackgroundColor(hexStringToColor(
                    toolbarDef != null && toolbarDef.color != null ? toolbarDef.color : "#ffffffff"));
            toolbar.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT,
                    dpToPixels(toolbarDef != null ? toolbarDef.height : TOOLBAR_DEF_HEIGHT)));

            if (toolbarDef != null && (toolbarDef.image != null || toolbarDef.wwwImage != null)) {
                try {
                    Drawable background = getImage(toolbarDef.image, toolbarDef.wwwImage,
                            toolbarDef.wwwImageDensity);
                    setBackground(toolbar, background);
                } catch (Resources.NotFoundException e) {
                    emitError(ERR_LOADFAIL,
                            String.format("Image for toolbar, %s, failed to load", toolbarDef.image));
                } catch (IOException ioe) {
                    emitError(ERR_LOADFAIL,
                            String.format("Image for toolbar, %s, failed to load", toolbarDef.wwwImage));
                }
            }

            // Left Button Container layout
            LinearLayout leftButtonContainer = new LinearLayout(cordova.getActivity());
            FrameLayout.LayoutParams leftButtonContainerParams = new FrameLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            leftButtonContainerParams.gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL;
            leftButtonContainer.setLayoutParams(leftButtonContainerParams);
            leftButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);

            // Right Button Container layout
            LinearLayout rightButtonContainer = new LinearLayout(cordova.getActivity());
            FrameLayout.LayoutParams rightButtonContainerParams = new FrameLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            rightButtonContainerParams.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL;
            rightButtonContainer.setLayoutParams(rightButtonContainerParams);
            rightButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);

            // Edit Text Box
            edittext = new EditText(cordova.getActivity());
            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.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.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;
                }
            });

            // Back button
            final Button back = createButton(features.backButton, "back button", new View.OnClickListener() {
                public void onClick(View v) {
                    emitButtonEvent(features.backButton, inAppWebView.getUrl());

                    if (features.backButtonCanClose && !canGoBack()) {
                        closeDialog();
                    } else {
                        goBack();
                    }
                }
            });

            if (back != null) {
                back.setEnabled(features.backButtonCanClose);
            }

            // Forward button
            final Button forward = createButton(features.forwardButton, "forward button",
                    new View.OnClickListener() {
                        public void onClick(View v) {
                            emitButtonEvent(features.forwardButton, inAppWebView.getUrl());

                            goForward();
                        }
                    });

            if (forward != null) {
                forward.setEnabled(false);
            }

            // Close/Done button
            Button close = createButton(features.closeButton, "close button", new View.OnClickListener() {
                public void onClick(View v) {
                    emitButtonEvent(features.closeButton, inAppWebView.getUrl());
                    closeDialog();
                }
            });

            // Menu button
            Spinner menu = features.menu != null ? new MenuSpinner(cordova.getActivity()) : null;
            if (menu != null) {
                menu.setLayoutParams(
                        new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                menu.setContentDescription("menu button");
                setButtonImages(menu, features.menu, DISABLED_ALPHA);

                // We are not allowed to use onClickListener for Spinner, so we will use
                // onTouchListener as a fallback.
                menu.setOnTouchListener(new View.OnTouchListener() {
                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
                        if (event.getAction() == MotionEvent.ACTION_UP) {
                            emitButtonEvent(features.menu, inAppWebView.getUrl());
                        }
                        return false;
                    }
                });

                if (features.menu.items != null) {
                    HideSelectedAdapter<EventLabel> adapter = new HideSelectedAdapter<EventLabel>(
                            cordova.getActivity(), android.R.layout.simple_spinner_item, features.menu.items);
                    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                    menu.setAdapter(adapter);
                    menu.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                        @Override
                        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                            if (inAppWebView != null && i < features.menu.items.length) {
                                emitButtonEvent(features.menu.items[i], inAppWebView.getUrl(), i);
                            }
                        }

                        @Override
                        public void onNothingSelected(AdapterView<?> adapterView) {
                        }
                    });
                }
            }

            // Title
            final TextView title = features.title != null ? new TextView(cordova.getActivity()) : null;
            final TextView subtitle = features.title != null ? new TextView(cordova.getActivity()) : null;
            if (title != null) {
                FrameLayout.LayoutParams titleParams = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                        LayoutParams.FILL_PARENT);
                titleParams.gravity = Gravity.CENTER;
                title.setLayoutParams(titleParams);
                title.setSingleLine();
                title.setEllipsize(TextUtils.TruncateAt.END);
                title.setGravity(Gravity.CENTER | Gravity.TOP);
                title.setTextColor(
                        hexStringToColor(features.title.color != null ? features.title.color : "#000000ff"));
                title.setTypeface(title.getTypeface(), Typeface.BOLD);
                title.setTextSize(TypedValue.COMPLEX_UNIT_PT, 8);

                FrameLayout.LayoutParams subtitleParams = new FrameLayout.LayoutParams(
                        LayoutParams.MATCH_PARENT, LayoutParams.FILL_PARENT);
                titleParams.gravity = Gravity.CENTER;
                subtitle.setLayoutParams(subtitleParams);
                subtitle.setSingleLine();
                subtitle.setEllipsize(TextUtils.TruncateAt.END);
                subtitle.setGravity(Gravity.CENTER | Gravity.BOTTOM);
                subtitle.setTextColor(hexStringToColor(
                        features.title.subColor != null ? features.title.subColor : "#000000ff"));
                subtitle.setTextSize(TypedValue.COMPLEX_UNIT_PT, 6);
                subtitle.setVisibility(View.GONE);

                if (features.title.staticText != null) {
                    title.setGravity(Gravity.CENTER);
                    title.setText(features.title.staticText);
                } else {
                    subtitle.setVisibility(View.VISIBLE);
                }
            }

            // WebView
            inAppWebView = new WebView(cordova.getActivity());
            final ViewGroup.LayoutParams inAppWebViewParams = features.fullscreen
                    ? new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
                    : new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0);
            if (!features.fullscreen) {
                ((LinearLayout.LayoutParams) inAppWebViewParams).weight = 1;
            }
            inAppWebView.setLayoutParams(inAppWebViewParams);
            inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView));
            WebViewClient client = new ThemeableBrowserClient(thatWebView, new PageLoadListener() {

                @Override
                public void onPageStarted(String url) {
                    if (inAppWebView != null && title != null && features.title != null
                            && features.title.staticText == null && features.title.showPageTitle
                            && features.title.loadingText != null) {
                        title.setText(features.title.loadingText);
                        subtitle.setText(url);
                    }
                }

                @Override
                public void onPageFinished(String url, boolean canGoBack, boolean canGoForward) {
                    if (inAppWebView != null && title != null && features.title != null
                            && features.title.staticText == null && features.title.showPageTitle) {
                        title.setText(inAppWebView.getTitle());
                        subtitle.setText(inAppWebView.getUrl());
                    }

                    if (back != null) {
                        back.setEnabled(canGoBack || features.backButtonCanClose);
                    }

                    if (forward != null) {
                        forward.setEnabled(canGoForward);
                    }
                }
            });
            inAppWebView.setWebViewClient(client);
            WebSettings settings = inAppWebView.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(features.zoom);
            settings.setDisplayZoomControls(false);
            settings.setPluginState(android.webkit.WebSettings.PluginState.ON);

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

            if (features.clearcache) {
                CookieManager.getInstance().removeAllCookie();
            } else if (features.clearsessioncache) {
                CookieManager.getInstance().removeSessionCookie();
            }

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

            // Add buttons to either leftButtonsContainer or
            // rightButtonsContainer according to user's alignment
            // configuration.
            int leftContainerWidth = 0;
            int rightContainerWidth = 0;

            if (features.customButtons != null) {
                for (int i = 0; i < features.customButtons.length; i++) {
                    final BrowserButton buttonProps = features.customButtons[i];
                    final int index = i;
                    Button button = createButton(buttonProps, String.format("custom button at %d", i),
                            new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    if (inAppWebView != null) {
                                        emitButtonEvent(buttonProps, inAppWebView.getUrl(), index);
                                    }
                                }
                            });

                    if (ALIGN_RIGHT.equals(buttonProps.align)) {
                        rightButtonContainer.addView(button);
                        rightContainerWidth += button.getLayoutParams().width;
                    } else {
                        leftButtonContainer.addView(button, 0);
                        leftContainerWidth += button.getLayoutParams().width;
                    }
                }
            }

            // Back and forward buttons must be added with special ordering logic such
            // that back button is always on the left of forward button if both buttons
            // are on the same side.
            if (forward != null && features.forwardButton != null
                    && !ALIGN_RIGHT.equals(features.forwardButton.align)) {
                leftButtonContainer.addView(forward, 0);
                leftContainerWidth += forward.getLayoutParams().width;
            }

            if (back != null && features.backButton != null && ALIGN_RIGHT.equals(features.backButton.align)) {
                rightButtonContainer.addView(back);
                rightContainerWidth += back.getLayoutParams().width;
            }

            if (back != null && features.backButton != null && !ALIGN_RIGHT.equals(features.backButton.align)) {
                leftButtonContainer.addView(back, 0);
                leftContainerWidth += back.getLayoutParams().width;
            }

            if (forward != null && features.forwardButton != null
                    && ALIGN_RIGHT.equals(features.forwardButton.align)) {
                rightButtonContainer.addView(forward);
                rightContainerWidth += forward.getLayoutParams().width;
            }

            if (menu != null) {
                if (features.menu != null && ALIGN_RIGHT.equals(features.menu.align)) {
                    rightButtonContainer.addView(menu);
                    rightContainerWidth += menu.getLayoutParams().width;
                } else {
                    leftButtonContainer.addView(menu, 0);
                    leftContainerWidth += menu.getLayoutParams().width;
                }
            }

            if (close != null) {
                if (features.closeButton != null && ALIGN_RIGHT.equals(features.closeButton.align)) {
                    rightButtonContainer.addView(close);
                    rightContainerWidth += close.getLayoutParams().width;
                } else {
                    leftButtonContainer.addView(close, 0);
                    leftContainerWidth += close.getLayoutParams().width;
                }
            }

            // Add the views to our toolbar
            toolbar.addView(leftButtonContainer);
            // Don't show address bar.
            // toolbar.addView(edittext);
            toolbar.addView(rightButtonContainer);

            if (title != null) {
                int titleMargin = Math.max(leftContainerWidth, rightContainerWidth);

                FrameLayout.LayoutParams titleParams = (FrameLayout.LayoutParams) title.getLayoutParams();
                titleParams.setMargins(titleMargin, 8, titleMargin, 0);
                toolbar.addView(title);
            }

            if (subtitle != null) {
                int subtitleMargin = Math.max(leftContainerWidth, rightContainerWidth);

                FrameLayout.LayoutParams subtitleParams = (FrameLayout.LayoutParams) subtitle.getLayoutParams();
                subtitleParams.setMargins(subtitleMargin, 0, subtitleMargin, 8);
                toolbar.addView(subtitle);
            }

            if (features.fullscreen) {
                // If full screen mode, we have to add inAppWebView before adding toolbar.
                main.addView(inAppWebView);
            }

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

            if (!features.fullscreen) {
                // If not full screen, we add inAppWebView after adding toolbar.
                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 (features.hidden) {
                dialog.hide();
            }
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}