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.appsimobile.appsii.AbstractHotspotHelper.java

@SuppressWarnings("deprecation")
protected WindowManager.LayoutParams createHotspotParams(HotspotItem conf, SharedPreferences prefs) {

    Display display = mWindowManager.getDefaultDisplay();
    mHeight = display.getHeight();/*from   ww  w  .j a v a  2 s. c  o  m*/

    float pct = conf.mHeightRelativeToViewHeight;
    int realHeight = (int) (mHeight * pct);
    if (realHeight < mDp56)
        realHeight = mDp56;

    int y = (int) (conf.mYPosRelativeToView * mHeight);

    int hotspotWidth = prefs.getInt("pref_hotspot_width", 22);

    int width = (int) (hotspotWidth * AppsiApplication.getDensity(mContext));

    int xOffset = 0;

    if (conf.mLeft) {
        WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
                WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                        | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
                        | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                        | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
                PixelFormat.TRANSLUCENT);
        params.gravity = Gravity.LEFT | Gravity.TOP;
        params.x = xOffset;
        params.y = y;
        params.width = width;
        params.height = realHeight;
        return params;
    } else {
        WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
                WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                        | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
                        | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                        | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
                PixelFormat.TRANSLUCENT);
        params.gravity = Gravity.RIGHT | Gravity.TOP;
        params.x = xOffset;
        params.y = y;
        params.width = width;
        params.height = realHeight;
        return params;
    }
}

From source file:com.simas.vc.file_chooser.FileChooser.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = super.onCreateView(inflater, container, savedInstanceState);

    // Make the window always appear on the top of the screen
    try {/* w ww. ja va 2  s. co m*/
        WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
        lp.copyFrom(getDialog().getWindow().getAttributes());
        lp.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
        getDialog().getWindow().setAttributes(lp);
    } catch (NullPointerException e) {
        Log.e(TAG, "Failed to set FileChooser window gravity!", e);
    }

    return view;
}

From source file:com.culinars.culinars.WrapContentViewPager.java

/**
 * Allows to redraw the view size to wrap the content of the bigger child.
 *
 * @param widthMeasureSpec  with measured
 * @param heightMeasureSpec height measured
 *///from www. ja va2  s . c  o m
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    widthMeasuredSpec = widthMeasureSpec;
    int mode = MeasureSpec.getMode(heightMeasureSpec);

    if (mode == MeasureSpec.UNSPECIFIED || mode == MeasureSpec.AT_MOST) {
        if (height == 0) {
            // measure vertical decor (i.e. PagerTitleStrip) based on ViewPager implementation
            decorHeight = 0;
            for (int i = 0; i < getChildCount(); i++) {
                View child = getChildAt(i);
                LayoutParams lp = (LayoutParams) child.getLayoutParams();
                if (lp != null && lp.isDecor) {
                    int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
                    boolean consumeVertical = vgrav == Gravity.TOP || vgrav == Gravity.BOTTOM;
                    if (consumeVertical) {
                        decorHeight += child.getMeasuredHeight();
                    }
                }
            }

            // make sure that we have an height (not sure if this is necessary because it seems that onPageScrolled is called right after
            int position = getCurrentItem();
            View child = getViewAtPosition(position);
            if (child != null) {
                height = measureViewHeight(child);
            }
            Log.d(TAG, "onMeasure height:" + height + " decor:" + decorHeight);

        }
        int totalHeight = height + decorHeight + getPaddingBottom() + getPaddingTop();
        heightMeasureSpec = MeasureSpec.makeMeasureSpec(totalHeight, MeasureSpec.EXACTLY);
        Log.d(TAG, "onMeasure total height:" + totalHeight);
    }

    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

From source file:com.rodrigopontes.androidbubbles.BubblesManager.java

private void initialize() {
    windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Point point = new Point();
    windowManager.getDefaultDisplay().getSize(point);
    screenWidth = (short) point.x;
    screenHeight = (short) point.y;
    int statusBarResId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
    statusBarHeight = (short) context.getResources().getDimensionPixelSize(statusBarResId);

    bubbleTrash = new BubbleTrash();
    bubbleTrashParams = new WindowManager.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_PHONE,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
                    | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
            PixelFormat.TRANSLUCENT);//from   w  w  w .  ja  v  a2 s.  co  m
    bubbleTrashParams.gravity = Gravity.TOP | Gravity.START;
    bubbleTrash.getFrameLayout().measure(screenWidth, screenHeight);
    bubbleTrashWidth = (short) (bubbleTrash.getFrameLayout().getMeasuredWidth()
            * BubblesProperties.TRASH_INCREASE_SIZE);
    bubbleTrashHeight = (short) (bubbleTrash.getFrameLayout().getMeasuredHeight()
            * BubblesProperties.TRASH_INCREASE_SIZE);
    bubbleTrash.getFrameLayout().setMinimumWidth(bubbleTrashWidth);
    bubbleTrash.getFrameLayout().setMinimumHeight(bubbleTrashHeight);
    bubbleTrash.getImageView().measure(screenWidth, screenHeight);
    bubbleTrash.getImageView().setX(bubbleTrashWidth / 2 - bubbleTrash.getImageView().getMeasuredWidth() / 2);
    bubbleTrash.getImageView().setY(bubbleTrashHeight / 2 - bubbleTrash.getImageView().getMeasuredHeight() / 2);
    bubbleTrash.getImageViewForeground().measure(screenWidth, screenHeight);
    bubbleTrash.getImageViewForeground()
            .setX(bubbleTrashWidth / 2 - bubbleTrash.getImageViewForeground().getMeasuredWidth() / 2);
    bubbleTrash.getImageViewForeground()
            .setY(bubbleTrashHeight / 2 - bubbleTrash.getImageViewForeground().getMeasuredHeight() / 2);
    bubbleTrashParams.x = (screenWidth - bubbleTrashWidth) / 2;
    bubbleTrashParams.y = screenHeight + BubblesProperties.TRASH_ENTER_SPEED;
    windowManager.addView(bubbleTrash.getFrameLayout(), bubbleTrashParams);
}

From source file:com.facebook.android.MainPage.java

/** Called when the activity is first created. */
@Override//from ww w .  ja  v  a  2  s  . c om
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (APP_ID == null) {
        Util.showAlert(this, "Warning",
                "Facebook Applicaton ID must be " + "specified before running this example: see Example.java");
    }

    setContentView(R.layout.main);
    mMovieNameInput = (EditText) findViewById(R.id.title);
    mMediaSpinner = (Spinner) findViewById(R.id.media);
    mSearchButton = (Button) findViewById(R.id.search);
    mFacebook = new Facebook(APP_ID);
    mAsyncRunner = new AsyncFacebookRunner(mFacebook);

    SessionStore.restore(mFacebook, this);
    SessionEvents.addAuthListener(new SampleAuthListener());
    SessionEvents.addLogoutListener(new SampleLogoutListener());
    // set up the Spinner for the media list selection
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.media_list,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mMediaSpinner.setAdapter(adapter);

    //for search button         
    final Context context = this;
    mSearchButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            String servletURL;
            String movieName = mMovieNameInput.getText().toString();
            // check the input text of movie, if the text is empty give user alert
            movieName = movieName.trim();
            if (movieName.length() == 0) {
                Toast toast = Toast.makeText(context, "Please enter a movie name", Toast.LENGTH_LONG);
                toast.setGravity(Gravity.TOP | Gravity.CENTER, 0, 70);
                toast.show();
            }
            // if movie name is not empty
            else {
                // remove any extra whitespace
                movieName = movieName.replaceAll("\\s+", "+");
                String mediaList = mMediaSpinner.getSelectedItem().toString();
                if (mediaList.equals("Feature Film")) {
                    mediaList = "feature";
                }
                mediaList = mediaList.replaceAll("\\s+", "+");
                // construct the query string
                // construct the final URL to Servlet
                //String servletString = "?" + "title=" + movieName + "&" + "title_type=" + mediaList;
                //servletURL = "http://cs-server.usc.edu:10854/examples/servlet/Amovie"
                //+ servletString;
                //String servletString = "?" + "title=" + movieName + "&" + "media=" + mediaList;
                //servletURL = "http://cs-server.usc.edu:34404/examples/servlet/HelloWorldExample?title=" + movieName + "&" + "media=" + mediaList;
                //+ servletString;
                servletURL = "http://cs-server.usc.edu:10854/examples/servlet/Amovie?title=" + movieName + "&"
                        + "title_type=" + mediaList;
                BufferedReader in = null;
                try {
                    // REFERENCE: this part of code is modified from:
                    // "Example of HTTP GET Request using HttpClient in Android"
                    // http://w3mentor.com/learn/java/android-development/android-http-services/example-of-http-get-request-using-httpclient-in-android/
                    // get response (JSON string) from Servlet 
                    HttpClient client = new DefaultHttpClient();
                    HttpGet request = new HttpGet();
                    request.setURI(new URI(servletURL));
                    HttpResponse response = client.execute(request);
                    in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
                    StringBuffer sb = new StringBuffer("");
                    String line = "";
                    String NL = System.getProperty("line.separator");
                    while ((line = in.readLine()) != null) {
                        sb.append(line + NL);
                    }
                    in.close();
                    String page = sb.toString();
                    //test for JSON string
                    /*LinearLayout lView = new LinearLayout(context);
                    TextView myText = new TextView(context);
                    myText.setText(page);
                    lView.addView(myText);
                    setContentView(lView);*/

                    // convert the JSON string to real JSON and get out the movie JSON array
                    // to check if there is any movie data
                    JSONObject finalJson;
                    JSONObject movieJson;
                    JSONArray movieJsonArray;
                    finalJson = new JSONObject(page);
                    movieJson = finalJson.getJSONObject("results");
                    //System.out.println(movieJson);
                    movieJsonArray = movieJson.getJSONArray("result");

                    // if the response contains some movie data
                    if (movieJsonArray.length() != 0) {

                        // start the ListView activity, and pass the JSON string to it
                        Intent intent = new Intent(context, MovieListActivity.class);
                        intent.putExtra("finalJson", page);
                        startActivity(intent);
                    }
                    // if the response does not contain any movie data,
                    // show user that there is no result for this search
                    else {
                        Toast toast = Toast.makeText(getBaseContext(), "No movie found for this search",
                                Toast.LENGTH_LONG);
                        toast.setGravity(Gravity.CENTER, 0, 0);
                        toast.show();
                    }
                } catch (URISyntaxException e) {
                    e.printStackTrace();
                } catch (ClientProtocolException e) {
                    e.printStackTrace();
                } catch (JSONException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    if (in != null) {
                        try {
                            in.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    });
}

From source file:com.fibrobook.viewpager.custom.CardFragment.java

public void symphtomsView(LinearLayout l) {

    LayoutParams params = new LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT,
            android.view.ViewGroup.LayoutParams.MATCH_PARENT, Gravity.TOP);

    ListView symphtomList = new ListView(getActivity());
    symphtomList.setLayoutParams(params);

    ArrayAdapter<Disease> adapter = new ArrayAdapter<Disease>(getActivity(),
            android.R.layout.simple_list_item_1, symphtoms);
    symphtomList.setAdapter(adapter);//from w  ww  . ja  va2 s  .c om
    symphtomList.setClickable(true);

    symphtomList.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapter, View v, int position, long id) {
            ratingDialog = new Dialog(getActivity(), com.fibrobook.R.style.FullHeightDialog);
            ratingDialog.setContentView(com.fibrobook.R.layout.rating_dialog);
            ratingDialog.setCancelable(true);
            RatingBar ratingBar = (RatingBar) ratingDialog.findViewById(com.fibrobook.R.id.dialog_ratingbar);

            int i = 0;
            boolean exists = false;
            while (i < ds.size()) {
                if (symphtoms.get(position).getId() == ds.get(i).getDisease().getId()) {
                    ads = ds.get(i);
                    ratingBar.setRating(ads.getIntensity());
                    exists = true;
                    break;
                }
                i++;
            }
            if (!exists)
                ads = new SymphtomSummary(MainActivity.user, symphtoms.get(position), MainActivity.date);

            Button updateButton = (Button) ratingDialog.findViewById(com.fibrobook.R.id.rank_dialog_button);
            updateButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    RatingBar ratingBar = (RatingBar) ratingDialog
                            .findViewById(com.fibrobook.R.id.dialog_ratingbar);
                    ads.setIntensity(ratingBar.getRating());
                    SymphtomSummaryDAO dao = new SymphtomSummaryDAO(getActivity());
                    dao.save(ads);
                    ds = dao.getSymphtomSummary(MainActivity.date);
                    dao.close();
                    ratingDialog.dismiss();
                }
            });
            ratingDialog.show();
        }

    });

    l.addView(symphtomList);
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.JoinNotificationObj.java

@Override
public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) {
    TextView valueTV = new TextView(context);
    valueTV.setText("I'm here!");
    valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    valueTV.setGravity(Gravity.TOP | Gravity.LEFT);
    frame.addView(valueTV);/*  w w w  .ja v  a2  s. c o  m*/
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.LinkObj.java

public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) {
    JSONObject content = obj.getJson();//from   w ww . ja  v a  2s.  c om
    TextView valueTV = new TextView(context);
    String title;
    if (content.has(TITLE)) {
        title = "Link: " + content.optString(TITLE);
    } else {
        title = content.optString(URI);
    }
    valueTV.setText(title);
    valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    valueTV.setGravity(Gravity.TOP | Gravity.LEFT);
    if (Linkify.addLinks(valueTV, Linkify.ALL)) {
        if (!allowInteractions)
            valueTV.setMovementMethod(null);
    }

    frame.addView(valueTV);
}

From source file:com.linkbubble.ui.BubbleFlowView.java

public BubbleFlowView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    mViews = new ArrayList<View>();

    mContent = new FrameLayout(context);
    mContent.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT));

    addView(mContent);//from   w  ww .  ja va  2  s .  c  o  m

    mIsExpanded = true;

    setOnTouchListener(mOnTouchListener);

    mVerticalGestureDetector = new GestureDetector(mVerticalGestureListener);
}

From source file:com.freegeek.android.materialbanner.MaterialBanner.java

private void init(Context context, AttributeSet attrs) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MaterialBanner);
    mIndicatorMargin = (int) a.getDimension(R.styleable.MaterialBanner_indicatorMargin, dip2Pix(context, 10));
    mIndicatorGravity = IndicatorGravity.valueOf(a.getInt(R.styleable.MaterialBanner_indicatorGravity, 0));
    mIndicatorInside = a.getBoolean(R.styleable.MaterialBanner_indicatorInside, true);
    mMatch = a.getBoolean(R.styleable.MaterialBanner_match, false);
    a.recycle();//w w w  .j  a v a2  s  . c  o m

    View view = LayoutInflater.from(context).inflate(R.layout.material_banner, this, true);

    mCardView = (CardView) view.findViewById(R.id.card_view);
    mViewPager = (MaterialViewPager) view.findViewById(R.id.view_pager);
    mCardContainer = (FrameLayout) view.findViewById(R.id.container);
    mCardContainer = (FrameLayout) view.findViewById(R.id.card_container);
    mIndicatorContainer = (FrameLayout) view.findViewById(R.id.indicator_container);

    mIndicatorParams = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    mIndicatorParams.gravity = Gravity.CENTER;

    mCardParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.MATCH_PARENT);
    mCardParams.gravity = Gravity.TOP;

    //set Z value. bring indicator view to front,view.bringToFront does't work on 6.0
    ViewCompat.setZ(mCardView, 1);
    ViewCompat.setZ(mViewPager, 2);

    ViewCompat.setZ(mCardContainer, 1);
    ViewCompat.setZ(mIndicatorContainer, 2);

    updateMargin();
    setMatch(mMatch);
    adSwitchTask = new AdSwitchTask(this);

}