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.oonhee.oojs.inappbrowser.InAppBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url           The url to load.
 * @param jsonObject/*from   w ww  .j  av a2 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;
        }

        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) {
                    closeDialog();
                }
            });

            // 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);
            back.setText("<");
            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);
            forward.setText(">");
            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 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);
            close.setText(buttonLabel);
            close.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    closeDialog();
                }
            });

            // WebView
            inAppWebView = new AmazonWebView(cordova.getActivity());

            CordovaActivity app = (CordovaActivity) cordova.getActivity();
            cordova.getFactory().initializeWebView(inAppWebView, 0x00FF00, false, null);

            inAppWebView.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
            inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView));
            AmazonWebViewClient client = new InAppBrowserClient(thatWebView, edittext);
            inAppWebView.setWebViewClient(client);
            AmazonWebSettings settings = inAppWebView.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(true);
            settings.setPluginState(com.amazon.android.webkit.AmazonWebSettings.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) {
                AmazonCookieManager.getInstance().removeAllCookie();
            } else if (clearSessionCache) {
                AmazonCookieManager.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:com.scoreflex.ScoreflexView.java

protected int getLayoutGravity() {
    ViewGroup.LayoutParams currentLayoutParams = getLayoutParams();
    int gravity = Scoreflex.getDefaultGravity() & Gravity.VERTICAL_GRAVITY_MASK;
    if (currentLayoutParams instanceof FrameLayout.LayoutParams) {
        FrameLayout.LayoutParams frameLayoutParams = (FrameLayout.LayoutParams) currentLayoutParams;
        gravity = (Gravity.TOP == (frameLayoutParams.gravity & Gravity.VERTICAL_GRAVITY_MASK)) ? Gravity.TOP
                : Gravity.BOTTOM;//from  w w w  . j  ava  2  s  . c  om
    }
    return gravity;
}

From source file:com.spydiko.rotationmanager.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_settings: // Refresh button
        //            if(AppSpecificOrientation.LOG) Log.d(TAG, "action_settings");
        packageManager = getPackageManager();
        UpdateData updateData = new UpdateData();
        this.adapter = new InteractiveArrayAdapter(this, activities, (AppSpecificOrientation) getApplication());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
            updateData.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null);
        else//  www.  ja  v a2s  .c  o m
            updateData.execute((Void[]) null);
        //            if(AppSpecificOrientation.LOG) Log.d(TAG, "execute");
        lv.setAdapter(adapter);
        break;
    case R.id.itemToggleService: // Play - Stop Service
        //                if(AppSpecificOrientation.LOG) Log.d(TAG, "entered");
        if (AppSpecificOrientation.isServiceRunning()) {
            item.setTitle(R.string.titleServiceStop);
            //               item.setIcon(android.R.drawable.ic_media_play);
            stopService(new Intent(this, NewOrieService.class));
            AppSpecificOrientation.setServiceRunning(false);
            //                    if(AppSpecificOrientation.LOG) Log.d(TAG, "if");
            //               if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
            item.setIcon(R.drawable.ic_off_button_rotation_manager);
        } else {
            item.setTitle(R.string.titleServiceStart);
            //               item.setIcon(android.R.drawable.ic_media_pause);
            startService(new Intent(this, NewOrieService.class));
            Toast toast = Toast.makeText(this, getString(R.string.notification_text), Toast.LENGTH_LONG);
            toast.setGravity(Gravity.TOP | Gravity.LEFT, 0, 0);
            toast.show();
            //               if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
            item.setIcon(R.drawable.ic_on_button_rotation_manager);
            //                    if(AppSpecificOrientation.LOG) Log.d(TAG, "else");
        }
        break;

    case R.id.setOnBoot: // Set broadcast receiver on or off
        if (AppSpecificOrientation.getBoot()) {
            item.setChecked(false);
            AppSpecificOrientation.setBoot(false);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
                item.setIcon(android.R.drawable.button_onoff_indicator_off);
            //                    if(AppSpecificOrientation.LOG) Log.d(TAG, "onBoot set to false");
        } else {
            item.setChecked(true);
            AppSpecificOrientation.setBoot(true);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
                item.setIcon(android.R.drawable.button_onoff_indicator_on);
            //                    if(AppSpecificOrientation.LOG) Log.d(TAG, "onBoot set to true");
        }

        break;
    case R.id.howTo: // Open How To Activity
        startActivityForResult((new Intent(this, HowToActivity.class)), 1);
        break;
    case R.id.about: // Open About Activity
        startActivityForResult((new Intent(this, AboutActivity.class)), 1);
        break;
    case R.id.donate:
        startActivity(new Intent(this, DonateActivity.class));
        break;
    case R.id.permNotification:
        if (AppSpecificOrientation.isPermNotification()) {
            item.setChecked(false);
            AppSpecificOrientation.setPermNotification(false);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
                item.setIcon(android.R.drawable.button_onoff_indicator_off);
            //                    if(AppSpecificOrientation.LOG) Log.d(TAG, "onBoot set to false");
            if (AppSpecificOrientation.isServiceRunning())
                startService(new Intent(this, NewOrieService.class));
        } else {
            item.setChecked(true);
            AppSpecificOrientation.setPermNotification(true);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
                item.setIcon(android.R.drawable.button_onoff_indicator_on);
            //                    if(AppSpecificOrientation.LOG) Log.d(TAG, "onBoot set to true");
            if (AppSpecificOrientation.isServiceRunning())
                startService(new Intent(this, NewOrieService.class));
        }

        break;
    case R.id.license:
        startActivity(new Intent(this, License.class));
        break;
    case android.R.id.home:
        menu.toggle();
        return true;
    }
    return true;
}

From source file:com.example.verticaldrawerlayout.VerticalDrawerLayout.java

/**
 * Sets the title of the drawer with the given gravity.
 * <p>//from w ww.  j a  v  a2 s .  c  om
 * When accessibility is turned on, this is the title that will be used to
 * identify the drawer to the active accessibility service.
 * 
 * @param edgeGravity
 *            Gravity.LEFT, RIGHT, START or END. Expresses which
 *            drawer to set the title for.
 * @param title
 *            The title for the drawer.
 */
public void setDrawerTitle(int edgeGravity, CharSequence title) {
    final int absGravity = GravityCompat.getAbsoluteGravity(edgeGravity, ViewCompat.getLayoutDirection(this));
    if (absGravity == Gravity.TOP) {
        mTitleTop = title;
    } else if (absGravity == Gravity.BOTTOM) {
        mTitleBottom = title;
    }
}

From source file:com.google.blockly.android.ToolboxFragment.java

/**
 * @return Computed {@link Rotation} constant for {@link #mRotateTabs} and {@link #mTabEdge}.
 *///from   w w  w .  ja v a2  s . c om
@Rotation.Enum
private int getLabelRotation() {
    if (!mRotateTabs) {
        return Rotation.NONE;
    }
    switch (mTabEdge) {
    case Gravity.LEFT:
        return Rotation.COUNTER_CLOCKWISE;
    case Gravity.RIGHT:
        return Rotation.CLOCKWISE;
    case Gravity.TOP:
        return Rotation.NONE;
    case Gravity.BOTTOM:
        return Rotation.NONE;
    case GravityCompat.START:
        return Rotation.ADAPTIVE_COUNTER_CLOCKWISE;
    case GravityCompat.END:
        return Rotation.ADAPTIVE_CLOCKWISE;
    default:
        throw new IllegalArgumentException("Invalid tabEdge: " + mTabEdge);
    }
}

From source file:com.alburivan.slickform.tooltip.SimpleTooltip.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void startAnimation() {
    final String property = mGravity == Gravity.TOP || mGravity == Gravity.BOTTOM ? "translationY"
            : "translationX";

    final ObjectAnimator anim1 = ObjectAnimator.ofFloat(mContentLayout, property, -mAnimationPadding,
            mAnimationPadding);//ww  w.ja v  a 2  s . c om
    anim1.setDuration(mAnimationDuration);
    anim1.setInterpolator(new AccelerateDecelerateInterpolator());

    final ObjectAnimator anim2 = ObjectAnimator.ofFloat(mContentLayout, property, mAnimationPadding,
            -mAnimationPadding);
    anim2.setDuration(mAnimationDuration);
    anim2.setInterpolator(new AccelerateDecelerateInterpolator());

    mAnimator = new AnimatorSet();
    mAnimator.playSequentially(anim1, anim2);
    mAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (!dismissed && isShowing()) {
                animation.start();
            }
        }
    });
    mAnimator.start();
}

From source file:com.scoreflex.ScoreflexView.java

protected View openNewView(String resource, Scoreflex.RequestParams params, boolean forceFullScreen) {
    int gravity = getLayoutGravity();
    int anim = (Gravity.TOP == (gravity & Gravity.VERTICAL_GRAVITY_MASK)) ? R.anim.scoreflex_enter_slide_down
            : R.anim.scoreflex_enter_slide_up;
    Animation animation = AnimationUtils.loadAnimation(mParentActivity, anim);

    ScoreflexView webview = new ScoreflexView(mParentActivity);
    webview.setResource(resource, params, forceFullScreen);
    ViewGroup contentView = (ViewGroup) mParentActivity.getWindow().getDecorView()
            .findViewById(android.R.id.content);
    FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT, gravity);
    webview.setLayoutParams(layoutParams);
    contentView.addView(webview);//from ww  w  . j  ava 2 s  .  co  m
    webview.startAnimation(animation);
    Scoreflex.setCurrentScoreflexView(this);
    return webview;
}

From source file:com.aidy.bottomdrawerlayout.AllDrawerLayout.java

/**
 * Check the lock mode of the drawer with the given gravity.
 * // w  ww  .j  a  va2  s  .  c o m
 * @param edgeGravity
 *            Gravity of the drawer to check
 * @return one of {@link #LOCK_MODE_UNLOCKED},
 *         {@link #LOCK_MODE_LOCKED_CLOSED} or
 *         {@link #LOCK_MODE_LOCKED_OPEN}.
 */
public int getDrawerLockMode(int edgeGravity) {
    final int absGravity = GravityCompat.getAbsoluteGravity(edgeGravity, ViewCompat.getLayoutDirection(this));
    switch (absGravity) {
    case Gravity.LEFT:
        return mLockModeLeft;
    case Gravity.RIGHT:
        return mLockModeRight;
    case Gravity.TOP:
        return mLockModeTop;
    case Gravity.BOTTOM:
        return mLockModeBottom;
    default:
        return LOCK_MODE_UNLOCKED;
    }
}

From source file:com.scoreflex.Scoreflex.java

/**
 * Changes the default gravity.//w  w  w  .java  2 s  . c  om
 *
 * @param defaultGravity
 *            The new default gravity.
 */
public static void setDefaultGravity(int defaultGravity) {
    if (Gravity.TOP == (defaultGravity & Gravity.VERTICAL_GRAVITY_MASK))
        sDefaultGravity = Gravity.TOP;
    else
        sDefaultGravity = Gravity.BOTTOM;
}

From source file:com.example.verticaldrawerlayout.VerticalDrawerLayout.java

/**
 * Returns the title of the drawer with the given gravity.
 * /*from w  w w .j  a  va 2 s  .c  om*/
 * @param edgeGravity
 *            Gravity.LEFT, RIGHT, START or END. Expresses which
 *            drawer to return the title for.
 * @return The title of the drawer, or null if none set.
 * @see #setDrawerTitle(int, CharSequence)
 */
public CharSequence getDrawerTitle(int edgeGravity) {
    final int absGravity = GravityCompat.getAbsoluteGravity(edgeGravity, ViewCompat.getLayoutDirection(this));
    if (absGravity == Gravity.TOP) {
        return mTitleTop;
    } else if (absGravity == Gravity.BOTTOM) {
        return mTitleBottom;
    }
    return null;
}