Example usage for android.view Gravity CENTER_VERTICAL

List of usage examples for android.view Gravity CENTER_VERTICAL

Introduction

In this page you can find the example usage for android.view Gravity CENTER_VERTICAL.

Prototype

int CENTER_VERTICAL

To view the source code for android.view Gravity CENTER_VERTICAL.

Click Source Link

Document

Place object in the vertical center of its container, not changing its size.

Usage

From source file:eu.pellerito.popularmoviesproject2.fragment.DetailFragment.java

private void viewTrailer(@NonNull List<MovieTrailer> trailer) {

    if ((mContext != null) && (trailerArrayList != null)) {

        LayoutInflater layoutInflater = (LayoutInflater) mContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        final String[] strKey = new String[1];

        for (int i = 0; i < trailer.size(); i++) {

            strKey[0] = trailer.get(i).getKey();

            View view = layoutInflater.inflate(R.layout.layout_trailer, layoutWrapper, false);

            LinearLayout linearLayoutWrapper = ButterKnife.findById(view, R.id.trailer_wrapper);

            LinearLayout.LayoutParams layoutParamsImage = new LinearLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

            layoutParamsImage.setMargins(8, 8, 8, 8);

            if (trailerTitle != null) {
                separatorTrailer.setVisibility(View.VISIBLE);
                trailerTitle.setVisibility(View.VISIBLE);
            }/*from  w w w.ja  v a 2 s  .c  om*/

            final ImageView image = new ImageView(mContext);
            image.setTag(trailer.get(i).getName());
            image.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.youtube));

            image.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    playTrailer(strKey[0]);
                }
            });

            LinearLayout.LayoutParams layoutParamsTextView = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

            layoutParamsTextView.setMargins(8, 8, 8, 8);

            TextView textView = new TextView(mContext);
            textView.setText(trailer.get(i).getName());
            textView.setGravity(Gravity.CENTER_VERTICAL);
            textView.setLines(2);

            linearLayoutWrapper.addView(image, layoutParamsImage);
            linearLayoutWrapper.addView(textView, layoutParamsTextView);

            if (layoutBaseTrailer != null) {
                layoutBaseTrailer.addView(linearLayoutWrapper);
            }

        }
    }
}

From source file:com.cloudexplorers.plugins.childBrowser.ChildBrowser.java

/**
 * Display a new browser with the specified URL.
 * /* w w w .  ja  va  2 s . c om*/
 * @param url
 *          The url to load.
 * @param jsonObject
 */
public String showWebPage(final String url, JSONObject options) {
    // Determine if we should hide the location bar.
    if (options != null) {
        showLocationBar = options.optBoolean("showLocationBar", true);
    }

    // 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;
        }

        public void run() {
            // Let's create the main dialog
            dialog = new Dialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar);
            dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                public void onDismiss(DialogInterface dialog) {
                    try {
                        JSONObject obj = new JSONObject();
                        obj.put("type", CLOSE_EVENT);

                        sendUpdate(obj, false);
                    } catch (JSONException e) {
                        Log.d(LOG_TAG, "Should never happen");
                    }
                }
            });

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

            // Toolbar layout
            RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());
            toolbar.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.FILL_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.TOP);

            // Action Button Container layout
            RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity());
            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
            ImageButton back = new ImageButton(cordova.getActivity());
            RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
            backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT);
            back.setLayoutParams(backLayoutParams);
            back.setContentDescription("Back Button");
            back.setId(2);
            try {
                back.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_left.png"));
            } catch (IOException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }
            back.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goBack();
                }
            });

            // Forward button
            ImageButton forward = new ImageButton(cordova.getActivity());
            RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
            forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2);
            forward.setLayoutParams(forwardLayoutParams);
            forward.setContentDescription("Forward Button");
            forward.setId(3);
            try {
                forward.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_right.png"));
            } catch (IOException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }
            forward.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goForward();
                }
            });

            // Edit Text Box
            edittext = new EditText(cordova.getActivity());
            RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.FILL_PARENT, LayoutParams.FILL_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.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 button
            ImageButton close = new ImageButton(cordova.getActivity());
            RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
            closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            close.setLayoutParams(closeLayoutParams);
            forward.setContentDescription("Close Button");
            close.setId(5);
            try {
                close.setImageBitmap(loadDrawable("www/childbrowser/icon_close.png"));
            } catch (IOException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }
            close.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    closeDialog();
                }
            });

            // WebView
            webview = new WebView(cordova.getActivity());
            webview.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
            webview.setWebChromeClient(new WebChromeClient());
            WebViewClient client = new ChildBrowserClient(edittext);
            webview.setWebViewClient(client);
            WebSettings settings = webview.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(true);
            settings.setPluginsEnabled(true);
            settings.setDomStorageEnabled(true);

            webview.loadUrl(url);
            webview.setId(6);
            webview.getSettings().setLoadWithOverviewMode(true);
            webview.getSettings().setUseWideViewPort(true);
            webview.getSettings().setJavaScriptEnabled(true);
            webview.getSettings().setPluginsEnabled(true);

            webview.requestFocus();
            webview.requestFocusFromTouch();

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

            // Add the views to our toolbar
            toolbar.addView(actionButtonContainer);
            toolbar.addView(edittext);
            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(webview);

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

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
        }

        private Bitmap loadDrawable(String filename) throws java.io.IOException {
            InputStream input = cordova.getActivity().getAssets().open(filename);
            return BitmapFactory.decodeStream(input);
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}

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

protected void initializeViews() {
    LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    layout.setGravity(Gravity.CENTER_HORIZONTAL);
    TextView textview = new TextView(this);
    textview.setText(" PhpForAndroid " + version);
    ImageView imageView = new ImageView(this);
    imageView.setImageDrawable(getResources().getDrawable(R.drawable.pfa));
    layout.addView(imageView);/*w  ww.j  a v  a 2 s . c  om*/
    mButton = new Button(this);
    mAboutButton = new Button(this);
    MarginLayoutParams marginParams = new MarginLayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT);
    final float scale = getResources().getDisplayMetrics().density;
    int marginPixels = (int) (MARGIN_DIP * scale + 0.5f);
    marginParams.setMargins(marginPixels, marginPixels, marginPixels, marginPixels);
    mButton.setLayoutParams(marginParams);
    mAboutButton.setLayoutParams(marginParams);
    layout.addView(textview);
    layout.addView(mButton);
    layout.addView(mAboutButton);

    mProgressLayout = new LinearLayout(this);
    mProgressLayout.setOrientation(LinearLayout.HORIZONTAL);
    mProgressLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    mProgressLayout.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);

    LinearLayout bottom = new LinearLayout(this);
    bottom.setOrientation(LinearLayout.HORIZONTAL);
    bottom.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    bottom.setGravity(Gravity.CENTER_VERTICAL);
    mProgressLayout.addView(bottom);

    TextView message = new TextView(this);
    message.setText("   In Progress...");
    message.setTextSize(20);
    message.setTypeface(Typeface.DEFAULT_BOLD);
    message.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    ProgressBar bar = new ProgressBar(this);
    bar.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    bottom.addView(bar);
    bottom.addView(message);
    mProgressLayout.setVisibility(View.INVISIBLE);

    layout.addView(mProgressLayout);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setProgressBarIndeterminateVisibility(false);

    setContentView(layout);
}

From source file:com.tencent.tws.assistant.widget.CheckBox.java

private void setRippleBackground(boolean isSupportTintDrawable, Drawable orgDrawable, int rippleColor) {
    if (orgDrawable != null && isSupportTintDrawable) {
        ColorStateList csl = createNormalStateList(rippleColor);
        final int verticalGravity = getGravity() & Gravity.VERTICAL_GRAVITY_MASK;
        final int drawableHeight = orgDrawable.getIntrinsicHeight();
        final int drawableWidth = orgDrawable.getIntrinsicWidth();
        final float scale = 0.3f;
        final float drawableScaleHeight = drawableHeight * scale;
        final float drawableScaleWidth = drawableWidth * scale;

        final int top;
        switch (verticalGravity) {
        case Gravity.BOTTOM:
            top = (int) (getHeight() - drawableHeight - drawableScaleHeight);
            break;
        case Gravity.CENTER_VERTICAL:
            top = (int) (((getHeight() - drawableHeight) / 2) - drawableScaleHeight);
            break;
        default:/* w ww. j a  v a2 s  . c  o m*/
            top = (int) (-drawableScaleHeight);
        }
        final int bottom = (int) (top + drawableHeight + drawableScaleHeight * 2);
        final int left = (int) (isLayoutRtl() ? getWidth() - drawableWidth - drawableScaleWidth
                : -drawableScaleWidth);
        final int right = (int) (isLayoutRtl() ? getWidth() + drawableScaleWidth
                : drawableWidth + drawableScaleWidth);

        TwsRippleDrawable rippleDrawable = new TwsRippleDrawable(csl, null, null,
                TwsRippleDrawable.RIPPLE_STYLE_RING);
        rippleDrawable.twsSetHotspotBounds(left, top, right, bottom);
        setBackgroundDrawable(rippleDrawable);
    }
}

From source file:com.hp.map.CustomerMapActivity.java

public void menuDialog() {
    final Dialog dialog = new Dialog(this);
    LayoutInflater li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = li.inflate(R.layout.menu_dialog, null, false);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(v);/*  ww w .j  av a 2  s. c om*/

    dialog.setTitle("Danh mc chnh");

    Display display = getWindowManager().getDefaultDisplay();

    dialog.getWindow().setLayout(2 * display.getWidth() / 3, LayoutParams.FILL_PARENT);
    dialog.getWindow().getAttributes().gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL;

    lv = (ListView) dialog.findViewById(R.id.menu_list_view);

    lv.setAdapter(
            new DialogArrayAdapter(context, android.R.layout.simple_list_item_1, DetailListData.MENU_LIST));
    lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            // TODO Auto-generated method stub
            DetailsList selectedValue = (DetailsList) lv.getAdapter().getItem(arg2);
            if (selectedValue.activityClass != null) {
                //if sigout
                if (selectedValue.activityClass == LoginActivity.class) {
                    //LoginActivity.threadLooper.quit();
                }
                startActivity(new Intent(context, selectedValue.activityClass));
            }
        }
    });

    dialog.show();

    //      ImageView iv = (ImageView)dialog.findViewById(R.id.menu_list_view);
    //      iv.setImageResource(1);
}

From source file:im.ene.lab.io_timer.ui.widget.MiniDrawerLayout.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    mInLayout = true;//from   ww w  .j  a v  a  2 s  . c om
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);

        if (child.getVisibility() == GONE) {
            continue;
        }

        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        if (isContentView(child)) {
            child.layout(lp.leftMargin, lp.topMargin, lp.leftMargin + child.getMeasuredWidth(),
                    lp.topMargin + child.getMeasuredHeight());
        } else { // Drawer, if it wasn't onMeasure would have thrown an exception.
            final int childWidth = child.getMeasuredWidth();
            final int childHeight = child.getMeasuredHeight();
            int childLeft;

            final float newOffset;
            childLeft = mCollapseWidth + (int) (lp.onScreen * (mExpandWidth - mCollapseWidth));
            // (float) (left - mCollapseWidth) / range
            newOffset = (float) (childLeft - mCollapseWidth) / (mExpandWidth - mCollapseWidth);

            final boolean changeOffset = newOffset != lp.onScreen;

            final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;

            switch (vgrav) {
            default:
            case Gravity.TOP: {
                child.layout(childLeft, lp.topMargin, childLeft + childWidth, lp.topMargin + childHeight);
                break;
            }

            case Gravity.BOTTOM: {
                final int height = b - t;
                child.layout(childLeft, height - lp.bottomMargin - child.getMeasuredHeight(),
                        childLeft + childWidth, height - lp.bottomMargin);
                break;
            }

            case Gravity.CENTER_VERTICAL: {
                final int height = b - t;
                int childTop = (height - childHeight) / 2;

                // Offset for margins. If things don't fit right because of
                // bad measurement before, oh well.
                if (childTop < lp.topMargin) {
                    childTop = lp.topMargin;
                } else if (childTop + childHeight > height - lp.bottomMargin) {
                    childTop = height - lp.bottomMargin - childHeight;
                }
                child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);
                break;
            }
            }

            if (changeOffset) {
                setDrawerViewOffset(child, newOffset);
            }
        }
    }
    mInLayout = false;
    mFirstLayout = false;
}

From source file:com.app.plugins.childBrowser.ChildBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url           The url to load.
 * @param jsonObject //from  w  w w  . ja  v  a 2 s  .  co  m
 */
public String showWebPage(final String url, JSONObject options) {
    // Determine if we should hide the location bar.
    if (options != null) {
        showLocationBar = options.optBoolean("showLocationBar", false);
    }

    final WebView parent = this.webView;

    // Create dialog in new thread 
    Runnable runnable = new Runnable() {
        public void run() {
            dialog = new Dialog(cordova.getActivity(), android.R.style.Theme_Black_NoTitleBar_Fullscreen);

            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                public void onDismiss(DialogInterface dialog) {
                    try {
                        JSONObject obj = new JSONObject();
                        obj.put("type", CLOSE_EVENT);

                        sendUpdate(obj, false);
                    } catch (JSONException e) {
                        Log.d(LOG_TAG, "Should never happen");
                    }
                }
            });

            //LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
            //LinearLayout.LayoutParams forwardParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
            //LinearLayout.LayoutParams editParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT, 1.0f);
            LinearLayout.LayoutParams closeParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            LinearLayout.LayoutParams wvParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
                    LayoutParams.FILL_PARENT);

            LinearLayout main = new LinearLayout(cordova.getActivity());
            main.setOrientation(LinearLayout.VERTICAL);

            LinearLayout toolbar = new LinearLayout(cordova.getActivity());
            toolbar.setOrientation(LinearLayout.HORIZONTAL);

            /*
            ImageButton back = new ImageButton((Context) ctx);
            back.getBackground().setAlpha(0);
            back.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                goBack();
            }
            });
            back.setId(1);
            try {
            back.setImageBitmap(loadDrawable("plugins/childbrowser/icon_arrow_left.png"));
            } catch (IOException e) {
            Log.e(LOG_TAG, e.getMessage(), e);
            }
            back.setLayoutParams(backParams);
                    
            ImageButton forward = new ImageButton((Context) ctx);
            forward.getBackground().setAlpha(0);
            forward.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                goForward();
            }
            });
            forward.setId(2);
            try {
            forward.setImageBitmap(loadDrawable("plugins/childbrowser/icon_arrow_right.png"));
            } catch (IOException e) {
            Log.e(LOG_TAG, e.getMessage(), e);
            }               
            forward.setLayoutParams(forwardParams);
            */

            /*
            edittext = new EditText((Context) ctx);
            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;
            }
            });
            edittext.setId(3);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setLayoutParams(editParams);
            */
            //edittext = new EditText((Context) ctx);
            //edittext.setVisibility(View.GONE);

            LinearLayout.LayoutParams titleParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.FILL_PARENT, 1.0f);
            TextView title = new TextView(cordova.getActivity());
            title.setId(1);
            title.setLayoutParams(titleParams);
            title.setGravity(Gravity.CENTER_VERTICAL);
            title.setTypeface(null, Typeface.BOLD);

            ImageButton close = new ImageButton(cordova.getActivity());
            close.getBackground().setAlpha(0);
            close.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    closeDialog();
                }
            });
            close.setId(4);
            try {
                close.setImageBitmap(loadDrawable("plugins/childbrowser/icon_close.png"));
            } catch (IOException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }
            close.setLayoutParams(closeParams);

            childWebView = new WebView(cordova.getActivity());
            childWebView.getSettings().setJavaScriptEnabled(true);
            childWebView.getSettings().setBuiltInZoomControls(true);
            WebViewClient client = new ChildBrowserClient(parent, ctx, title/*, edittext*/);
            childWebView.setWebViewClient(client);
            childWebView.loadUrl(url);
            childWebView.setId(5);
            childWebView.setInitialScale(0);
            childWebView.setLayoutParams(wvParams);
            childWebView.requestFocus();
            childWebView.requestFocusFromTouch();

            //toolbar.addView(back);
            //toolbar.addView(forward);
            //toolbar.addView(edittext);
            toolbar.addView(close);
            toolbar.addView(title);

            if (getShowLocationBar()) {
                main.addView(toolbar);
            }
            main.addView(childWebView);

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.FILL_PARENT;
            lp.height = WindowManager.LayoutParams.FILL_PARENT;
            lp.verticalMargin = 0f;
            lp.horizontalMargin = 0f;

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
        }

        private Bitmap loadDrawable(String filename) throws java.io.IOException {
            InputStream input = cordova.getActivity().getAssets().open(filename);
            return BitmapFactory.decodeStream(input);
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}

From source file:android.support.design.widget.TextInputLayout.java

@Override
public void addView(View child, int index, final ViewGroup.LayoutParams params) {
    if (child instanceof EditText) {
        // Make sure that the EditText is vertically at the bottom, so that it sits on the
        // EditText's underline
        FrameLayout.LayoutParams flp = new FrameLayout.LayoutParams(params);
        flp.gravity = Gravity.CENTER_VERTICAL | (flp.gravity & ~Gravity.VERTICAL_GRAVITY_MASK);
        mInputFrame.addView(child, flp);

        // Now use the EditText's LayoutParams as our own and update them to make enough space
        // for the label
        mInputFrame.setLayoutParams(params);
        updateInputLayoutMargins();//w ww  .  j  av  a  2 s  .  co m

        setEditText((EditText) child);
    } else {
        // Carry on adding the View...
        super.addView(child, index, params);
    }
}

From source file:paulscode.android.mupen64plusae.game.GameActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.i("GameActivity", "onCreate");
    super.setTheme(android.support.v7.appcompat.R.style.Theme_AppCompat_NoActionBar);

    //Allow volume keys to control media volume if they are not mapped
    final SharedPreferences mPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    final boolean volKeyMapped = mPreferences.getBoolean("inputVolumeMappable", false);
    final AppData appData = new AppData(this);
    final GlobalPrefs globalPrefs = new GlobalPrefs(this, appData);
    if (!volKeyMapped && globalPrefs.audioPlugin.enabled) {
        setVolumeControlStream(AudioManager.STREAM_MUSIC);
    }//  ww w.  jav  a2s.  co  m

    mControllers = new ArrayList<>();
    mMogaController = Controller.getInstance(this);

    // Get the intent data
    final Bundle extras = this.getIntent().getExtras();
    if (extras == null)
        throw new Error("ROM path and MD5 must be passed via the extras bundle when starting GameActivity");
    mRomPath = extras.getString(ActivityHelper.Keys.ROM_PATH);
    mRomMd5 = extras.getString(ActivityHelper.Keys.ROM_MD5);
    mRomCrc = extras.getString(ActivityHelper.Keys.ROM_CRC);
    String romHeaderName = extras.getString(ActivityHelper.Keys.ROM_HEADER_NAME);
    byte romCountryCode = extras.getByte(ActivityHelper.Keys.ROM_COUNTRY_CODE);
    String artPath = extras.getString(ActivityHelper.Keys.ROM_ART_PATH);
    String romGoodName = extras.getString(ActivityHelper.Keys.ROM_GOOD_NAME);
    String legacySaveName = extras.getString(ActivityHelper.Keys.ROM_LEGACY_SAVE);
    boolean doRestart = extras.getBoolean(ActivityHelper.Keys.DO_RESTART, false);
    if (TextUtils.isEmpty(mRomPath) || TextUtils.isEmpty(mRomMd5))
        throw new Error("ROM path and MD5 must be passed via the extras bundle when starting GameActivity");

    // Initialize MOGA controller API
    // TODO: Remove hack after MOGA SDK is fixed
    // mMogaController.init();
    MogaHack.init(mMogaController, this);

    // Get app data and user preferences
    mGlobalPrefs = new GlobalPrefs(this, appData);

    mGamePrefs = new GamePrefs(this, mRomMd5, mRomCrc, romHeaderName, romGoodName,
            RomHeader.countryCodeToSymbol(romCountryCode), appData, mGlobalPrefs, legacySaveName);
    String cheatArgs = mGamePrefs.getCheatArgs();

    mAutoSaveManager = new GameAutoSaveManager(mGamePrefs, mGlobalPrefs.maxAutoSaves);

    mGlobalPrefs.enforceLocale(this);

    final Window window = this.getWindow();

    // Enable full-screen mode
    window.setFlags(LayoutParams.FLAG_FULLSCREEN, LayoutParams.FLAG_FULLSCREEN);
    window.setFlags(LayoutParams.FLAG_LAYOUT_IN_SCREEN, LayoutParams.FLAG_LAYOUT_IN_SCREEN);

    // Keep screen from going to sleep
    window.setFlags(LayoutParams.FLAG_KEEP_SCREEN_ON, LayoutParams.FLAG_KEEP_SCREEN_ON);

    // Set the screen orientation
    this.setRequestedOrientation(mGlobalPrefs.displayOrientation);

    // If the orientation changes, the screensize info changes, so we must refresh dependencies
    mGlobalPrefs = new GlobalPrefs(this, appData);
    mGamePrefs = new GamePrefs(this, mRomMd5, mRomCrc, romHeaderName, romGoodName,
            RomHeader.countryCodeToSymbol(romCountryCode), appData, mGlobalPrefs, legacySaveName);

    mFirstStart = true;

    //TODO: Figure out why we call this in the middle
    super.onCreate(savedInstanceState);

    // Lay out content and get the views
    this.setContentView(R.layout.game_activity);
    mSurface = (GameSurface) this.findViewById(R.id.gameSurface);
    mOverlay = (GameOverlay) this.findViewById(R.id.gameOverlay);
    mDrawerLayout = (GameDrawerLayout) this.findViewById(R.id.drawerLayout);
    mGameSidebar = (GameSidebar) this.findViewById(R.id.gameSidebar);

    // Don't darken the game screen when the drawer is open
    mDrawerLayout.setScrimColor(0x0);

    // Make the background solid black
    mSurface.getRootView().setBackgroundColor(0xFF000000);
    mSurface.SetGameSurfaceCreatedListener(this);

    if (!TextUtils.isEmpty(artPath) && new File(artPath).exists())
        mGameSidebar.setImage(new BitmapDrawable(this.getResources(), artPath));

    mGameSidebar.setTitle(romGoodName);
    // Initialize the objects and data files interfacing to the emulator core
    CoreInterface.initialize(this, mSurface, mGamePrefs, mRomPath, mRomMd5, cheatArgs, doRestart);

    // Handle events from the side bar
    mGameSidebar.setActionHandler(this, R.menu.game_drawer);

    //Reload menus
    ReloadAllMenus();

    // Listen to game surface events (created, changed, destroyed)
    mSurface.getHolder().addCallback(this);

    // Update the GameSurface size
    mSurface.getHolder().setFixedSize(mGamePrefs.videoRenderWidth, mGamePrefs.videoRenderHeight);
    final FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mSurface.getLayoutParams();
    params.width = Math.round(mGamePrefs.videoSurfaceWidth * (mGamePrefs.videoSurfaceZoom / 100.f));
    params.height = Math.round(mGamePrefs.videoSurfaceHeight * (mGamePrefs.videoSurfaceZoom / 100.f));

    if ((mGlobalPrefs.displayOrientation & 1) == 1)
        params.gravity = mGlobalPrefs.displayPosition | Gravity.CENTER_HORIZONTAL;
    else
        params.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;

    mSurface.setLayoutParams(params);

    // Initialize the screen elements
    if (mGamePrefs.isTouchscreenEnabled || mGlobalPrefs.isFpsEnabled) {
        // The touch map and overlay are needed to display frame rate and/or controls
        mTouchscreenMap = new VisibleTouchMap(this.getResources());
        mTouchscreenMap.load(mGamePrefs.touchscreenSkin, mGamePrefs.touchscreenProfile,
                mGamePrefs.isTouchscreenAnimated, mGlobalPrefs.isFpsEnabled, mGlobalPrefs.touchscreenScale,
                mGlobalPrefs.touchscreenTransparency);
        mOverlay.initialize(mTouchscreenMap, !mGamePrefs.isTouchscreenHidden, mGlobalPrefs.isFpsEnabled,
                mGamePrefs.isAnalogHiddenWhenSensor, mGamePrefs.isTouchscreenAnimated);
    }

    // Initialize user interface devices
    initControllers(mOverlay);

    // Override the peripheral controllers' key provider, to add some extra
    // functionality
    mOverlay.setOnKeyListener(this);

    if (savedInstanceState == null) {
        // Show the drawer at the start and have it hide itself
        // automatically
        mDrawerLayout.openDrawer(GravityCompat.START);
        mDrawerLayout.postDelayed(new Runnable() {
            @Override
            public void run() {
                mDrawerLayout.closeDrawer(GravityCompat.START);
            }
        }, 1000);
    }

    mDrawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {

        @Override
        public void onDrawerClosed(View arg0) {
            NativeExports.emuResume();
        }

        @Override
        public void onDrawerOpened(View arg0) {
            NativeExports.emuPause();
            ReloadAllMenus();
        }

        @Override
        public void onDrawerSlide(View arg0, float arg1) {

        }

        @Override
        public void onDrawerStateChanged(int newState) {

        }

    });
}

From source file:nuclei.ui.view.ButtonBarView.java

void dataSetChanged() {
    mLabelAnimators.clear();// ww w  .  j a  v  a 2s .  c o  m
    mButtons.removeAllViews();

    if (mAdapter == null) {
        mItems = null;
        return;
    }

    final int count = mAdapter.getCount();
    final View.OnClickListener listener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            int position = 0;
            for (Item item : mItems) {
                if (item.view == v) {
                    setSelectedItem(position);
                    break;
                }
                position++;
            }
        }
    };

    final LayoutInflater inflater = LayoutInflater.from(getContext());

    if (mItems == null || mItems.length != count)
        mItems = new Item[count];

    for (int i = 0; i < count; i++) {
        final int textId = mAdapter.getTitle(i);
        final int imageId = mAdapter.getDrawable(i);
        Item item = new Item(textId, imageId);

        item.view = (ViewGroup) inflater
                .inflate(mOrientation == 1 ? R.layout.cyto_view_button_horizontal_bar_item
                        : R.layout.cyto_view_button_vertical_bar_item, this, false);
        item.view.setOnClickListener(listener);

        item.imageView = (ImageView) item.view.findViewById(R.id.image);
        if (item.textId != 0)
            item.imageView.setContentDescription(getResources().getString(item.textId));
        item.imageView.setImageResource(item.imageId);
        item.imageView.setColorFilter(mUnselectedTint, PorterDuff.Mode.SRC_ATOP);

        item.textView = (TextView) item.view.findViewById(R.id.text);
        if (item.textView != null) {
            item.textView.setText(item.textId);

            if (count > 4)
                item.textView.setVisibility(GONE);
        }

        mItems[i] = item;

        LinearLayout.LayoutParams params = mOrientation == 1
                ? new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1)
                : new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT);
        params.gravity = mOrientation == 1 ? Gravity.CENTER_VERTICAL : Gravity.CENTER_HORIZONTAL;
        mButtons.addView(item.view, params);
    }
}