Example usage for android.view Gravity TOP

List of usage examples for android.view Gravity TOP

Introduction

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

Prototype

int TOP

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

Click Source Link

Document

Push object to the top of its container, not changing its size.

Usage

From source file:com.dtworkshop.inappcrossbrowser.WebViewBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url           The url to load.
 *///from   www .java 2 s .  c o  m
public String showWebPage(final String url, HashMap<String, Boolean> features) {
    // Determine if we should hide the location bar.
    showLocationBar = true;
    openWindowHidden = false;
    if (features != null) {
        Boolean show = features.get(LOCATION);
        if (show != null) {
            showLocationBar = show.booleanValue();
        }
        Boolean hidden = features.get(HIDDEN);
        if (hidden != null) {
            openWindowHidden = hidden.booleanValue();
        }
        Boolean cache = features.get(CLEAR_ALL_CACHE);
        if (cache != null) {
            clearAllCache = cache.booleanValue();
        } else {
            cache = features.get(CLEAR_SESSION_CACHE);
            if (cache != null) {
                clearSessionCache = cache.booleanValue();
            }
        }
    }

    final CordovaWebView thatWebView = this.webView;

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

            return value;
        }

        @SuppressLint("NewApi")
        public void run() {
            // Let's create the main dialog
            dialog = new InAppBrowserDialog(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.setInAppBroswer(getInAppBrowser());

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

            // Toolbar layout
            RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());
            //Please, no more black!
            toolbar.setBackgroundColor(android.graphics.Color.LTGRAY);
            toolbar.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44)));
            toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2));
            toolbar.setHorizontalGravity(Gravity.LEFT);
            toolbar.setVerticalGravity(Gravity.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
            Button back = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT);
            back.setLayoutParams(backLayoutParams);
            back.setContentDescription("Back Button");
            back.setId(2);
            Resources activityRes = cordova.getActivity().getResources();
            int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable",
                    cordova.getActivity().getPackageName());
            Drawable backIcon = activityRes.getDrawable(backResId);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                back.setBackgroundDrawable(backIcon);
            } else {
                back.setBackground(backIcon);
            }
            back.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goBack();
                }
            });

            // Forward button
            Button forward = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2);
            forward.setLayoutParams(forwardLayoutParams);
            forward.setContentDescription("Forward Button");
            forward.setId(3);
            int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable",
                    cordova.getActivity().getPackageName());
            Drawable fwdIcon = activityRes.getDrawable(fwdResId);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                forward.setBackgroundDrawable(fwdIcon);
            } else {
                forward.setBackground(fwdIcon);
            }
            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.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
            textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
            edittext.setLayoutParams(textLayoutParams);
            edittext.setId(4);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
            edittext.setImeOptions(EditorInfo.IME_ACTION_GO);
            edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE
            edittext.setOnKeyListener(new View.OnKeyListener() {
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    // If the event is a key-down event on the "enter" button
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        navigate(edittext.getText().toString());
                        return true;
                    }
                    return false;
                }
            });

            // Close/Done button
            Button close = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            close.setLayoutParams(closeLayoutParams);
            forward.setContentDescription("Close Button");
            close.setId(5);
            int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable",
                    cordova.getActivity().getPackageName());
            Drawable closeIcon = activityRes.getDrawable(closeResId);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                close.setBackgroundDrawable(closeIcon);
            } else {
                close.setBackground(closeIcon);
            }
            close.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    closeDialog();
                }
            });

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

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

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

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

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

            // 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(inAppWebView);

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

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

From source file:com.crearo.gpslogger.ui.fragments.display.GpsSimpleViewFragment.java

@Override
public void onClick(View view) {
    Toast toast = new Toast(getActivity());
    switch (view.getId()) {
    case R.id.simpleview_imgSatelliteCount:
        toast = getToast(R.string.txt_satellites);
        break;// w  w w  . ja  va2  s  .  co  m
    case R.id.simpleview_imgAccuracy:
        toast = getToast(R.string.txt_accuracy);
        break;

    case R.id.simpleview_imgAltitude:
        toast = getToast(R.string.txt_altitude);
        break;

    case R.id.simpleview_imgDirection:
        toast = getToast(R.string.txt_direction);
        break;

    case R.id.simpleview_imgDuration:
        toast = getToast(R.string.txt_travel_duration);
        break;

    case R.id.simpleview_imgSpeed:
        toast = getToast(R.string.txt_speed);
        break;

    case R.id.simpleview_distance:
        toast = getToast(R.string.txt_travel_distance);
        break;

    case R.id.simpleview_points:
        toast = getToast(R.string.txt_number_of_points);
        break;

    case R.id.simpleview_imgLink:
        toast = getToast(preferenceHelper.getCustomLoggingUrl());
        break;

    }

    int location[] = new int[2];
    view.getLocationOnScreen(location);
    toast.setGravity(Gravity.TOP | Gravity.LEFT, location[0], location[1]);
    toast.show();
}

From source file:com.h6ah4i.android.materialshadowninepatch.MaterialShadowContainerView.java

@SuppressLint("RtlHardcoded")
private void fixChildViewGravity() {
    for (int i = 0; i < getChildCount(); i++) {
        View childView = getChildAt(i);
        LayoutParams params = (LayoutParams) childView.getLayoutParams();

        if (params.gravity == -1) {
            params.gravity = Gravity.TOP | Gravity.LEFT;
        }/*from  w  ww  . j  av a 2 s .c  o  m*/

        childView.setLayoutParams(params);
    }
}

From source file:com.hippo.drawerlayout.DrawerLayout.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    mInLayout = true;/*from  www  . ja v a 2 s  .  co  m*/
    final int width = r - l;
    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();
        int additionalTopMargin = 0;
        int additionalBottomMargin = 0;
        if (child instanceof DrawerLayoutChild) {
            DrawerLayoutChild dlc = (DrawerLayoutChild) child;
            additionalTopMargin = dlc.getAdditionalTopMargin();
            additionalBottomMargin = dlc.getAdditionalBottomMargin();
        }
        if (child == mContentView) {
            child.layout(lp.leftMargin, lp.topMargin + additionalTopMargin,
                    lp.leftMargin + child.getMeasuredWidth(),
                    lp.topMargin + additionalTopMargin + child.getMeasuredHeight());
        } else if (child == mShadow) {
            child.layout(0, 0, child.getMeasuredWidth(), 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;
            float percent;

            if (child == mLeftDrawer) {
                percent = mLeftPercent;
                childLeft = -childWidth + (int) (childWidth * percent);
            } else { // Right; onMeasure checked for us.
                percent = mRightPercent;
                childLeft = width - (int) (childWidth * percent);
            }

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

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

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

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

            final int newVisibility = percent > 0 ? VISIBLE : INVISIBLE;
            if (child.getVisibility() != newVisibility) {
                child.setVisibility(newVisibility);
            }
        }
    }
    mInLayout = false;
}

From source file:com.uproot.trackme.LocationActivity.java

public void Toast(String s, int Xoff, int Yoff) {
    Context context = getApplicationContext();
    CharSequence text = s;//  w w  w . j av  a2s. c om
    int duration = Toast.LENGTH_LONG;
    Toast toast = Toast.makeText(context, text, duration);
    toast.setGravity(Gravity.TOP | Gravity.LEFT, Xoff, Yoff);
    toast.show();
}

From source file:com.webcomm.plugin.CustomInAppBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url           The url to load.
 * @param jsonObject//from w  w w . jav a2  s  .co m
 */
public String showWebPage(final String url, HashMap<String, Boolean> features) {
    // Determine if we should hide the location bar.
    showLocationBar = true;
    openWindowHidden = false;
    if (features != null) {
        Boolean show = features.get(LOCATION);
        if (show != null) {
            showLocationBar = show.booleanValue();
        }
        Boolean hidden = features.get(HIDDEN);
        if (hidden != null) {
            openWindowHidden = hidden.booleanValue();
        }
        Boolean cache = features.get(CLEAR_ALL_CACHE);
        if (cache != null) {
            clearAllCache = cache.booleanValue();
        } else {
            cache = features.get(CLEAR_SESSION_CACHE);
            if (cache != null) {
                clearSessionCache = cache.booleanValue();
            }
        }
    }

    final CordovaWebView thatWebView = this.webView;

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

            return value;
        }

        @SuppressLint("NewApi")
        public void run() {
            // Let's create the main dialog
            dialog = new CustomInAppBrowserDialog(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.setInAppBroswer(getInAppBrowser());

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

            // Toolbar layout
            RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());
            //Please, no more black! 
            toolbar.setBackgroundColor(android.graphics.Color.LTGRAY);
            toolbar.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44)));
            toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2));
            toolbar.setHorizontalGravity(Gravity.LEFT);
            toolbar.setVerticalGravity(Gravity.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
            Button back = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT);
            back.setLayoutParams(backLayoutParams);
            back.setContentDescription("Back Button");
            back.setId(2);
            Resources activityRes = cordova.getActivity().getResources();
            int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable",
                    cordova.getActivity().getPackageName());
            Drawable backIcon = activityRes.getDrawable(backResId);
            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                back.setBackgroundDrawable(backIcon);
            } else {
                back.setBackground(backIcon);
            }
            back.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goBack();
                }
            });

            // Forward button
            Button forward = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2);
            forward.setLayoutParams(forwardLayoutParams);
            forward.setContentDescription("Forward Button");
            forward.setId(3);
            int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable",
                    cordova.getActivity().getPackageName());
            Drawable fwdIcon = activityRes.getDrawable(fwdResId);
            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                forward.setBackgroundDrawable(fwdIcon);
            } else {
                forward.setBackground(fwdIcon);
            }
            forward.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goForward();
                }
            });

            // 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.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/Done button
            Button close = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            close.setLayoutParams(closeLayoutParams);
            forward.setContentDescription("Close Button");
            close.setId(5);
            int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable",
                    cordova.getActivity().getPackageName());
            Drawable closeIcon = activityRes.getDrawable(closeResId);
            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                close.setBackgroundDrawable(closeIcon);
            } else {
                close.setBackground(closeIcon);
            }
            close.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    closeDialog();
                }
            });

            // WebView
            inAppWebView = new WebView(cordova.getActivity());
            inAppWebView.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
            inAppWebView.setWebChromeClient(new CustomInAppChromeClient(thatWebView));
            // [Modify]
            inAppWebView.addJavascriptInterface(
                    new WebAppInterface(cordova.getActivity().getApplicationContext()), "CustomInAppBrowser");
            WebViewClient client = new InAppBrowserClient(thatWebView, edittext);
            inAppWebView.setWebViewClient(client);
            WebSettings settings = inAppWebView.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(true);
            settings.setPluginState(android.webkit.WebSettings.PluginState.ON);

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

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

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

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

            // 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(inAppWebView);

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

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

From source file:android.support.wear.widget.drawer.WearableDrawerLayout.java

@Override
public void addView(View child, int index, ViewGroup.LayoutParams params) {
    super.addView(child, index, params);

    if (!(child instanceof WearableDrawerView)) {
        return;//from  ww  w.ja v a2s .com
    }

    WearableDrawerView drawerChild = (WearableDrawerView) child;
    drawerChild.setDrawerController(new WearableDrawerController(this, drawerChild));
    int childGravity = ((FrameLayout.LayoutParams) params).gravity;
    // Check for preferential gravity if no gravity is set in the layout.
    if (childGravity == Gravity.NO_GRAVITY || childGravity == GRAVITY_UNDEFINED) {
        ((FrameLayout.LayoutParams) params).gravity = drawerChild.preferGravity();
        childGravity = drawerChild.preferGravity();
        drawerChild.setLayoutParams(params);
    }
    WearableDrawerView drawerView;
    if (childGravity == Gravity.TOP) {
        mTopDrawerView = drawerChild;
        drawerView = mTopDrawerView;
    } else if (childGravity == Gravity.BOTTOM) {
        mBottomDrawerView = drawerChild;
        drawerView = mBottomDrawerView;
    } else {
        drawerView = null;
    }

    if (drawerView != null) {
        drawerView.addOnLayoutChangeListener(this);
    }
}

From source file:com.google.android.apps.muzei.MuzeiActivity.java

private void setupArtDetailModeUi() {
    mChromeContainerView = findViewById(R.id.chrome_container);
    mStatusBarScrimView = findViewById(R.id.statusbar_scrim);

    mChromeContainerView.setBackground(ScrimUtil.makeCubicGradientScrimDrawable(0xaa000000, 8, Gravity.BOTTOM));

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        mStatusBarScrimView.setVisibility(View.GONE);
        mStatusBarScrimView = null;//  w ww. jav a2 s .  c o m
    } else {
        mStatusBarScrimView.setBackground(ScrimUtil.makeCubicGradientScrimDrawable(0x44000000, 8, Gravity.TOP));
    }

    mMetadataView = findViewById(R.id.metadata);

    final float metadataSlideDistance = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
            getResources().getDisplayMetrics());
    mContainerView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
        @Override
        public void onSystemUiVisibilityChange(int vis) {
            final boolean visible = (vis & View.SYSTEM_UI_FLAG_LOW_PROFILE) == 0;

            boolean showArtDetailChrome = (mUiMode == UI_MODE_ART_DETAIL);
            mChromeContainerView.setVisibility(showArtDetailChrome ? View.VISIBLE : View.GONE);
            mChromeContainerView.animate().alpha(visible ? 1f : 0f)
                    .translationY(visible ? 0 : metadataSlideDistance).setDuration(200)
                    .withEndAction(new Runnable() {
                        @Override
                        public void run() {
                            if (!visible) {
                                mChromeContainerView.setVisibility(View.GONE);
                            }
                        }
                    });

            if (mStatusBarScrimView != null) {
                mStatusBarScrimView.setVisibility(showArtDetailChrome ? View.VISIBLE : View.GONE);
                mStatusBarScrimView.animate().alpha(visible ? 1f : 0f).setDuration(200)
                        .withEndAction(new Runnable() {
                            @Override
                            public void run() {
                                if (!visible) {
                                    mStatusBarScrimView.setVisibility(View.GONE);
                                }
                            }
                        });
            }
        }
    });

    mTitleView = (TextView) findViewById(R.id.title);
    mBylineView = (TextView) findViewById(R.id.byline);
    mAttributionView = (TextView) findViewById(R.id.attribution);

    setupOverflowButton();

    mNextButton = findViewById(R.id.next_button);
    mNextButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mSourceManager.sendAction(MuzeiArtSource.BUILTIN_COMMAND_ID_NEXT_ARTWORK);
            mNextFakeLoading = true;
            showNextFakeLoading();
        }
    });
    CheatSheet.setup(mNextButton);

    mPanScaleProxyView = (PanScaleProxyView) findViewById(R.id.pan_scale_proxy);
    mPanScaleProxyView.setMaxZoom(5);
    mPanScaleProxyView.setOnViewportChangedListener(new PanScaleProxyView.OnViewportChangedListener() {
        @Override
        public void onViewportChanged() {
            if (mGuardViewportChangeListener) {
                return;
            }

            ArtDetailViewport.getInstance().setViewport(mCurrentViewportId,
                    mPanScaleProxyView.getCurrentViewport(), true);
        }
    });
    mPanScaleProxyView.setOnOtherGestureListener(new PanScaleProxyView.OnOtherGestureListener() {
        @Override
        public void onSingleTapUp() {
            if (mUiMode == UI_MODE_ART_DETAIL) {
                showHideChrome((mContainerView.getSystemUiVisibility() & View.SYSTEM_UI_FLAG_LOW_PROFILE) != 0);
            }
        }
    });

    mLoadingContainerView = findViewById(R.id.image_loading_container);
    mLoadingIndicatorView = (AnimatedMuzeiLoadingSpinnerView) findViewById(R.id.image_loading_indicator);
    mLoadErrorContainerView = findViewById(R.id.image_error_container);
    mLoadErrorEasterEggView = findViewById(R.id.error_easter_egg);

    findViewById(R.id.image_error_retry_button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            showNextFakeLoading();
            startService(TaskQueueService.getDownloadCurrentArtworkIntent(MuzeiActivity.this));
        }
    });
}

From source file:com.pressurelabs.flowopensource.TheHubActivity.java

/**
 * Displays a popup window prompting the user to
 *
 * Confirm the changes to the name, saving the new name to file and updating the UI.
 *
 * Cancel the changes, returning the user back to the original state before editing
 *
 * @param newName new name to be used/*from   w ww  .  j a v a2s .  c  om*/
 * @param cardPosition position of cardview in adapter
 * @param cardViewClicked the cardview view object clicked
 * @param switcher the viewSwitcher object used to rename
 */
private void showEditPopupWindow(final EditText newName, View cardViewClicked, final ViewSwitcher switcher,
        final int cardPosition) {
    LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = layoutInflater.inflate(R.layout.popup_window_editing, null);

    LinearLayout viewGroup = (LinearLayout) layout.findViewById(R.id.popup_editing);

    // Creating the PopupWindow
    final PopupWindow popupEditing = new PopupWindow(layout, RecyclerView.LayoutParams.WRAP_CONTENT,
            RecyclerView.LayoutParams.WRAP_CONTENT);

    int dividerMargin = viewGroup.getDividerPadding(); // Top bottom
    int popupPadding = layout.getPaddingBottom();
    int popupDisplayHeight = -(cardViewClicked.getHeight() - dividerMargin - popupPadding);

    // Prevents border from appearing outside popupwindow
    popupEditing.setBackgroundDrawable(new ColorDrawable());
    popupEditing.setFocusable(false);

    // Getting a reference to Close button, and close the popup when clicked.
    ImageView confirmEdit = (ImageView) layout.findViewById(R.id.popup_confirm_item_changes);

    confirmEdit.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Flow toChange = rvContent.get(cardPosition);
            if (newName.getText().toString().equals("")) {
                // Need to optimize this so that the dialog does NOT disappear and just display toast
                Toast.makeText(TheHubActivity.this, "This Flow needs a name!", Toast.LENGTH_LONG).show();
            } else {
                toChange.setName(newName.getText().toString());
                manager.overwrite(toChange.getUuid(), toChange);
                adapter.notifyDataSetChanged();
                switcher.showNext();
                menuState = AppConstants.MENU_ITEMS_NATIVE;
                invalidateOptionsMenu();
                popupEditing.dismiss();
                newName.clearFocus();
            }

        }
    });

    ImageView cancelEdit = (ImageView) layout.findViewById(R.id.popup_cancel_item_changes);

    cancelEdit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switcher.showNext();
            menuState = AppConstants.MENU_ITEMS_NATIVE;
            invalidateOptionsMenu();
            popupEditing.dismiss();
        }
    });

    // Displaying the popup at the specified location, + offsets.
    popupEditing.showAsDropDown(cardViewClicked, cardViewClicked.getMeasuredWidth(), popupDisplayHeight,
            Gravity.TOP);
    editingPopup = popupEditing;
}

From source file:com.cleveroad.audiowidget.AudioWidget.java

private void show(View view, int left, int top) {
    if (view.getParent() != null || view.getWindowToken() != null) {
        windowManager.removeView(view);/*from   w w  w.ja  v  a 2 s .c o m*/
    }
    WindowManager.LayoutParams params = new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_PHONE,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                    | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
                    | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
            PixelFormat.TRANSLUCENT);
    params.gravity = Gravity.START | Gravity.TOP;
    params.x = left;
    params.y = top;
    windowManager.addView(view, params);
}