List of usage examples for android.view Gravity LEFT
int LEFT
To view the source code for android.view Gravity LEFT.
Click Source Link
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.AppStateObj.java
public void render(final Context context, final ViewGroup frame, Obj obj, boolean allowInteractions) { JSONObject content = obj.getJson();/*from ww w . j a v a 2 s .c om*/ // TODO: hack to show object history in app feeds JSONObject appState = getAppState(context, content); if (appState != null) { content = appState; } else { Log.e(TAG, "Missing inner content, probably because of format changes"); } boolean rendered = false; AppState ref = new AppState(content); String thumbnail = ref.getThumbnailImage(); if (thumbnail != null) { rendered = true; ImageView imageView = new ImageView(context); imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); App.instance().objectImages.lazyLoadImage(thumbnail.hashCode(), thumbnail, imageView); frame.addView(imageView); } thumbnail = ref.getThumbnailText(); if (thumbnail != null) { rendered = true; TextView valueTV = new TextView(context); valueTV.setText(thumbnail); valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); valueTV.setGravity(Gravity.TOP | Gravity.LEFT); frame.addView(valueTV); } thumbnail = ref.getThumbnailHtml(); if (thumbnail != null) { rendered = true; WebView webview = new WebView(context); webview.loadData(thumbnail, "text/html", "UTF-8"); webview.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); Object o = frame.getTag(R.id.object_entry); webview.setOnTouchListener(new WebViewClickListener(frame, (Integer) o)); frame.addView(webview); } if (!rendered) { String appName = content.optString(PACKAGE_NAME); if (appName.contains(".")) { appName = appName.substring(appName.lastIndexOf(".") + 1); } String text = "Welcome to " + appName + "!"; TextView valueTV = new TextView(context); valueTV.setText(text); valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); valueTV.setGravity(Gravity.TOP | Gravity.LEFT); frame.addView(valueTV); } }
From source file:com.uzmap.pkg.uzmodules.uzBMap.mode.Billboard.java
private TextView title() { TextView title = new TextView(context); title.setSingleLine();/*w w w .j a v a 2 s. c o m*/ title.setEllipsize(TruncateAt.END); title.setMaxWidth(UZCoreUtil.dipToPix(maxWidth) - 2 * iconMarginLeft + iconSize); title.setText(getTitle()); title.setTextColor(getTitleColor()); title.setTextSize(getTitleSize()); title.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL); return title; }
From source file:com.ape.cloudfile.widget.vpi.TabPageIndicator.java
private void addTab(int index, CharSequence text, int iconResId, int count) { final TabView tabView = new TabView(getContext()); tabView.mIndex = index;/*from www.j a v a2s .co m*/ tabView.setFocusable(true); tabView.setOnClickListener(mTabClickListener); tabView.setText(text); tabView.setGravity(Gravity.CENTER); tabView.setPadding(0, 15, 0, 15); tabView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14); tabView.setTextColor(getResources().getColorStateList(R.color.myos_tab_text_color)); // if (iconResId != 0) { // tabView.setCompoundDrawablesWithIntrinsicBounds(0, iconResId, 0, 0); // } if (count > 1) { tabView.setBackgroundResource(R.drawable.action_tab_background); } else { tabView.setBackgroundResource(R.drawable.tinno_title_bg_holo_light); tabView.setTextColor(getResources().getColor(R.color.tab_bar_title_color)); tabView.setPadding(20, 0, 0, 0); tabView.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL); Drawable drawable = getResources().getDrawable(R.drawable.title_panel_back); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); tabView.setCompoundDrawables(drawable, null, null, null); } //add by zjw // if(index == 0) // { // tabView.setBackgroundResource(R.drawable.title_bar_left_selector); // }else if(index == (count - 1)) // { // tabView.setBackgroundResource(R.drawable.title_bar_right_selector); // }else // { // tabView.setBackgroundResource(R.drawable.title_bar_middle_selector); // } mTabLayout.addView(tabView, new LinearLayout.LayoutParams(0, MATCH_PARENT, 1)); }
From source file:com.uzmap.pkg.uzmodules.uzBMap.mode.Billboard.java
private TextView subTitle() { TextView title = new TextView(context); title.setSingleLine();//from w ww . j a v a 2s .co m title.setEllipsize(TruncateAt.END); title.setMaxWidth(UZCoreUtil.dipToPix(maxWidth) - 2 * iconMarginLeft + iconSize); title.setText(getSubTitle()); title.setTextColor(getSubTitleColor()); title.setTextSize(getSubTitleSize()); title.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL); return title; }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.AppReferenceObj.java
public void render(final Context context, final ViewGroup frame, Obj obj, boolean allowInteractions) { JSONObject content = obj.getJson();/*from ww w. jav a2 s.co m*/ // TODO: hack to show object history in app feeds SignedObj appState = getAppStateForChildFeed(context, obj); if (appState != null) { mAppStateObj.render(context, frame, obj, allowInteractions); return; } else { String appName = content.optString(PACKAGE_NAME); if (appName.contains(".")) { // TODO: look up label. appName = appName.substring(appName.lastIndexOf(".") + 1); } String text = "Welcome to " + appName + "!"; TextView valueTV = new TextView(context); valueTV.setText(text); valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); valueTV.setGravity(Gravity.TOP | Gravity.LEFT); frame.addView(valueTV); } }
From source file:com.kyo.fitssystemwindows.FitsSystemWindowsFrameLayout.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { final boolean applyInsets = lastInsets != null && ViewCompat.getFitsSystemWindows(this); final int layoutDirection = ViewCompat.getLayoutDirection(this); final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); if (child.getVisibility() == GONE) { continue; }// w w w .ja v a 2 s .c o m final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (lp.gravity == -1) { lp.gravity = DEFAULT_CHILD_GRAVITY; } if (applyInsets) { int cgrav = GravityCompat.getAbsoluteGravity(lp.gravity, layoutDirection); if (cgrav == -1) { cgrav = DEFAULT_CHILD_GRAVITY; } else { if ((cgrav & Gravity.VERTICAL_GRAVITY_MASK) == 0) { cgrav = cgrav | Gravity.TOP; } if ((cgrav & Gravity.HORIZONTAL_GRAVITY_MASK) == 0) { cgrav = cgrav | (layoutDirection == LAYOUT_DIRECTION_LTR ? Gravity.LEFT : Gravity.RIGHT); } } if (ViewCompat.getFitsSystemWindows(child)) { final int l = child.getPaddingLeft(); final int t = child.getPaddingTop(); final int r = child.getPaddingRight(); final int b = child.getPaddingBottom(); IMPL.dispatchChildInsets(child, lp, cgrav, lastInsets); child.setPadding(l, t, r, b); } else { IMPL.applyMarginInsets(lp, cgrav, lastInsets); lp.leftMargin += lp.leftMargin2; lp.topMargin += lp.topMargin2; lp.rightMargin += lp.rightMargin2; lp.bottomMargin += lp.bottomMargin2; } } } super.onMeasure(widthMeasureSpec, heightMeasureSpec); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); if (child.getVisibility() == GONE || ViewCompat.getFitsSystemWindows(child)) { continue; } final LayoutParams lp = (LayoutParams) child.getLayoutParams(); lp.leftMargin -= lp.leftMargin2; lp.topMargin -= lp.topMargin2; lp.rightMargin -= lp.rightMargin2; lp.bottomMargin -= lp.bottomMargin2; } }
From source file:mobisocial.musubi.objects.FileObj.java
@Override public View createView(Context context, ViewGroup frame) { LinearLayout container = new LinearLayout(context); container.setLayoutParams(CommonLayouts.FULL_WIDTH); container.setOrientation(LinearLayout.HORIZONTAL); container.setGravity(Gravity.CENTER); ImageView imageView = new ImageView(context); imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); TextView valueTV = new TextView(context); valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); valueTV.setGravity(Gravity.BOTTOM | Gravity.LEFT); valueTV.setPadding(4, 0, 0, 0);/*from w w w . j av a2s.c o m*/ container.addView(imageView); container.addView(valueTV); return container; }
From source file:com.bigpigs.main.MainActivity.java
public void initView() { toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/* ww w. j av a 2 s . c o m*/ frameLayout = (FrameLayout) findViewById(R.id.container); navigationView = (NavigationView) findViewById(R.id.nav_view); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer); navHeader = navigationView.getHeaderView(0); tv_email = (TextView) navHeader.findViewById(R.id.user_email); tv_userName = (TextView) navHeader.findViewById(R.id.user_name); userAvatar = (RoundedImageView) navHeader.findViewById(R.id.user_avatar); Picasso.with(MainActivity.this).load(R.drawable.ic_avatar).fit().centerCrop().into(userAvatar); ActionBar supportActionBar = getSupportActionBar(); if (supportActionBar != null) { VectorDrawableCompat indicator = VectorDrawableCompat.create(getResources(), R.drawable.ic_menu, getTheme()); indicator.setTint(ResourcesCompat.getColor(getResources(), R.color.white, getTheme())); supportActionBar.setHomeAsUpIndicator(indicator); supportActionBar.setDisplayHomeAsUpEnabled(true); toolbar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mDrawerLayout.openDrawer(Gravity.LEFT); // Log.d(TAG,listSystemData); // Log.d(TAG,listNewsData); } }); } }
From source file:com.google.android.apps.santatracker.doodles.tilt.SwimmingFragment.java
@Override protected void firstPassLoadOnUiThread() { final FrameLayout.LayoutParams wrapperLP = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);//from w w w . j av a 2 s .c o m final SwimmingFragment that = this; scoreView = getScoreView(); pauseView = getPauseView(); int diveViewBottomMargin = (int) context.getResources().getDimension(R.dimen.dive_margin_bottom); int diveViewStartMargin = (int) context.getResources().getDimension(R.dimen.dive_margin_left); int diveViewSize = (int) context.getResources().getDimension(R.dimen.dive_image_size); FrameLayout.LayoutParams diveViewLP = new LayoutParams(diveViewSize, diveViewSize); diveViewLP.setMargins(diveViewStartMargin, 0, 0, diveViewBottomMargin); diveViewLP.gravity = Gravity.BOTTOM | Gravity.LEFT; if (VERSION.SDK_INT >= 17) { diveViewLP.setMarginStart(diveViewStartMargin); } diveView = new DiveView(context); countdownView = new TextView(context); countdownView.setGravity(Gravity.CENTER); countdownView.setTextColor(context.getResources().getColor(R.color.ui_text_yellow)); countdownView.setTypeface(Typeface.DEFAULT_BOLD); countdownView.setText("0"); countdownView.setVisibility(View.INVISIBLE); Locale locale = context.getResources().getConfiguration().locale; countdownView.setText(NumberFormat.getInstance(locale).format(3)); Point screenDimens = AndroidUtils.getScreenSize(); UIUtil.fitToBounds(countdownView, screenDimens.x / 10, screenDimens.y / 10); LinearLayout gameView = new LinearLayout(context); gameView.setOrientation(LinearLayout.VERTICAL); // Add game view. swimmingView = new SwimmingView(context); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 7); gameView.addView(swimmingView, lp); if (editorMode) { LinearLayout buttonWrapper = new LinearLayout(context); buttonWrapper.setOrientation(LinearLayout.HORIZONTAL); lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1); gameView.addView(buttonWrapper, lp); resetButton = getButton(R.string.reset_level, new OnClickListener() { @Override public void onClick(View v) { SwimmingModel level = levelManager.loadDefaultLevel(); initializeLevel(level, false); getActivity().getSharedPreferences(context.getString(R.string.swimming), Context.MODE_PRIVATE) .edit().putString(CURRENT_LEVEL_KEY, null).commit(); } }); deleteButton = getButton(R.string.delete_levels, new OnClickListener() { @Override public void onClick(View v) { DialogFragment dialogFragment = new DeleteLevelDialogFragment(); dialogFragment.show(getActivity().getFragmentManager(), "delete"); } }); loadButton = getButton(R.string.load_level, new OnClickListener() { @Override public void onClick(View v) { DialogFragment dialogFragment = new LoadLevelDialogFragment(that); dialogFragment.show(getActivity().getFragmentManager(), "load"); } }); saveButton = getButton(R.string.save_level, new OnClickListener() { @Override public void onClick(View v) { DialogFragment dialogFragment = new SaveLevelDialogFragment(that); dialogFragment.show(getActivity().getFragmentManager(), "save"); } }); collisionModeButton = new ToggleButton(context); collisionModeButton.setText(R.string.scenery_mode); collisionModeButton.setTextOff(context.getString(R.string.scenery_mode)); collisionModeButton.setTextOn(context.getString(R.string.collision_mode)); collisionModeButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { model.collisionMode = isChecked; } }); lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT, 1); buttonWrapper.addView(deleteButton, lp); buttonWrapper.addView(resetButton, lp); buttonWrapper.addView(loadButton, lp); buttonWrapper.addView(saveButton, lp); buttonWrapper.addView(collisionModeButton, lp); } sensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); accelerometerSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); if (accelerometerSensor == null) { // TODO: The game won't be playable without this, so what should we do? Log.d(TAG, "Accelerometer sensor is null"); } displayRotation = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay() .getRotation(); wrapper.addView(gameView, 0, wrapperLP); wrapper.addView(countdownView, 1); wrapper.addView(diveView, 2, diveViewLP); wrapper.addView(scoreView, 3); wrapper.addView(pauseView, 4); }
From source file:com.inductivebiblestudyapp.ui.dialogs.SimpleTooltipDialog.java
/** Adjusts the location of the dialog and positions the arrow. * //from w ww . ja va 2 s.c o m * @param dialog The dialog * @param rootView The rootView of the dialog * @param anchorLocation An X =0, Y=1 array of the anchor location via getLocationOnScreen. * @param anchorDimens An X =0, Y=1 array of anchor size in pixels * @param centered Whether to center the dialog or not. */ protected void adjustView(Dialog dialog, View rootView, int[] anchorLocation, int[] anchorDimens, boolean centered) { final int X_INDEX = 0; final int Y_INDEX = 1; try { int[] screenSize = new int[2]; getScreenDimens(screenSize); rootView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); final int rootWidth = rootView.getMeasuredWidth(); final int rootHeight = rootView.getMeasuredHeight(); final int[] screenCenter = new int[] { screenSize[X_INDEX] / 2, screenSize[Y_INDEX] / 2 }; //we have not displayed it yet, so we cannot measure location. //Instead, we will estimate based on Gravity.CENTER x and y final int[] estRootLocation = new int[] { screenCenter[X_INDEX] - rootWidth / 2, screenCenter[Y_INDEX] - rootHeight / 2 }; //if not left, right final boolean anchorToLeft = screenCenter[X_INDEX] >= anchorLocation[X_INDEX]; //if not top, bottom final boolean anchorToTop = screenCenter[Y_INDEX] >= anchorLocation[Y_INDEX]; WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes(); // lets start by calculating our midpoint //the horizontal center of the anchor relative to left side of screen final int anchorMidpointX = anchorLocation[X_INDEX] + anchorDimens[X_INDEX] / 2; //were the arrow margin should go. int arrowMarginLeft = 0; if (centered) { wmlp.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL; arrowMarginLeft = anchorMidpointX - estRootLocation[X_INDEX]; } else { //LEFT required if manually positioning. wmlp.gravity = Gravity.TOP | Gravity.LEFT; //center our dialog under our anchor as best as possible int dialogPosFromLeft = anchorMidpointX - rootWidth / 2; //check our values are sane. if (dialogPosFromLeft + rootWidth >= screenSize[X_INDEX]) { dialogPosFromLeft = screenSize[X_INDEX] - rootWidth; } else if (dialogPosFromLeft <= 0) { dialogPosFromLeft = 1; } wmlp.x = dialogPosFromLeft; arrowMarginLeft = anchorMidpointX - dialogPosFromLeft; } //horizontal positions are now calculated, now let's align our dialog vertically to be directly above our view. //the position from the top of the screen, to place the dialog. int desiredPosFromTop = 0; //the arrow params LinearLayout.LayoutParams arrowParams = null; if (anchorToTop) { //position ourself above. desiredPosFromTop = anchorLocation[Y_INDEX] + anchorDimens[Y_INDEX] - getStatusBarHeight(); mDownArrow.setVisibility(View.GONE); arrowParams = (LinearLayout.LayoutParams) mUpArrow.getLayoutParams(); } else { desiredPosFromTop = anchorLocation[Y_INDEX] - rootHeight - getStatusBarHeight(); mUpArrow.setVisibility(View.GONE); arrowParams = (LinearLayout.LayoutParams) mDownArrow.getLayoutParams(); } arrowParams.leftMargin = arrowMarginLeft; if (desiredPosFromTop >= screenSize[Y_INDEX]) { wmlp.y = screenSize[Y_INDEX] - 1; } else if (desiredPosFromTop <= 0) { wmlp.y = 1; } else { wmlp.y = desiredPosFromTop; } dialog.getWindow().setAttributes(wmlp); //force change, even at runtime. } catch (Exception e) { e.printStackTrace(); } }