List of usage examples for android.view Gravity CENTER_VERTICAL
int CENTER_VERTICAL
To view the source code for android.view Gravity CENTER_VERTICAL.
Click Source Link
From source file:cz.babi.android.remoteme.service.ConnectionService.java
@Override public void onDestroy() { if (Common.DEBUG) Log.d(TAG_CLASS_NAME, "[onDestroy]"); /* Cancel the persistent notification. */ if (isNotificationVisible) notificationManager.cancel(NOTIFICATION_ID); /* If Wi-Fi is locked we need to unlock it. */ if (wifiLock.isHeld()) unlockWifi();//w ww .jav a 2 s . c om /* If there was no error we send 'bye bye' message to server and show toast to user. */ if (!disconnectWithError) { /* Just tell to server that we are disconnecting. */ SimpleMessage byeBye = Message.BYE_BYE; String message = byeBye.toString(); if (needEncryptedCommunication) message = AES128_DEFAULT.encryptText(byeBye.toString()); out.println(message); out.flush(); /* Tell the user we stopped. */ LayoutInflater mInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View toastLayout = mInflater.inflate(R.layout.toast_normal, null); TextView text = (TextView) toastLayout.findViewById(R.id.normal_text); text.setText(R.string.connection_service_disconnected_text); Toast toast = new Toast(this); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(Toast.LENGTH_LONG); toast.setView(toastLayout); toast.show(); } }
From source file:ticwear.design.widget.StretchingLayout.java
public StretchingLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mCollapsingTextHelper = new CollapsingTextHelper(this); mCollapsingTextHelper.setTextSizeInterpolator(AnimationUtils.DECELERATE_INTERPOLATOR); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CollapsingToolbarLayout, defStyleAttr, R.style.Widget_Ticwear_CollapsingToolbar); mCollapsingTextHelper//from ww w .j av a2s . c o m .setExpandedTextGravity(a.getInt(R.styleable.CollapsingToolbarLayout_tic_expandedTitleGravity, GravityCompat.START | Gravity.BOTTOM)); mCollapsingTextHelper .setCollapsedTextGravity(a.getInt(R.styleable.CollapsingToolbarLayout_tic_collapsedTitleGravity, GravityCompat.START | Gravity.CENTER_VERTICAL)); mExpandedMarginStart = mExpandedMarginTop = mExpandedMarginEnd = mExpandedMarginBottom = a .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMargin, 0); if (a.hasValue(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMarginStart)) { mExpandedMarginStart = a .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMarginStart, 0); } if (a.hasValue(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMarginEnd)) { mExpandedMarginEnd = a .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMarginEnd, 0); } if (a.hasValue(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMarginTop)) { mExpandedMarginTop = a .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMarginTop, 0); } if (a.hasValue(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMarginBottom)) { mExpandedMarginBottom = a .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMarginBottom, 0); } mCollapsingTitleEnabled = a.getBoolean(R.styleable.CollapsingToolbarLayout_tic_titleEnabled, true); setTitle(a.getText(R.styleable.CollapsingToolbarLayout_android_title)); // First load the default text appearances mCollapsingTextHelper.setExpandedTextAppearance(R.style.TextAppearance_Ticwear_CollapsingToolbar_Expanded); mCollapsingTextHelper.setCollapsedTextAppearance(R.style.TextAppearance_Ticwear_TitleBar_Title); // Now overlay any custom text appearances if (a.hasValue(R.styleable.CollapsingToolbarLayout_tic_expandedTitleTextAppearance)) { mCollapsingTextHelper.setExpandedTextAppearance( a.getResourceId(R.styleable.CollapsingToolbarLayout_tic_expandedTitleTextAppearance, 0)); } if (a.hasValue(R.styleable.CollapsingToolbarLayout_tic_collapsedTitleTextAppearance)) { mCollapsingTextHelper.setCollapsedTextAppearance( a.getResourceId(R.styleable.CollapsingToolbarLayout_tic_collapsedTitleTextAppearance, 0)); } a.recycle(); setWillNotDraw(false); ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4.view.OnApplyWindowInsetsListener() { @Override public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { if (isShown()) { mLastInsets = insets; requestLayout(); return insets.consumeSystemWindowInsets(); } else { return insets; } } }); }
From source file:com.android.tabletcustomui.views.LeftCircleContainer.java
private void addCircle(int position, final int value, float diff, double ratio) { final int radius = value / 2; final RectF mOval = new RectF(); mOval.set(0 + diff, 0 + diff, value - diff, value - diff); final Paint mPaintClip = new Paint(); mPaintClip.setStyle(Paint.Style.FILL); mPaintClip.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.OVERLAY)); mPaintClip.setAntiAlias(true);/* w w w . j av a2 s . co m*/ final PointF pointF = new PointF(mOval.centerX(), mOval.centerY()); final Path clipPath = new Path(); clipPath.addCircle(pointF.x, pointF.y, (float) (radius * ratio), Path.Direction.CW); View circleView; if (position == 0) { mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_blue)); circleView = new View(getContext()) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.clipPath(clipPath, Region.Op.DIFFERENCE); canvas.drawArc(mOval, 330, 10, true, mPaintClip); canvas.drawArc(mOval, 342, 20, true, mPaintClip); canvas.drawArc(mOval, 4, 10, true, mPaintClip); canvas.drawArc(mOval, 240, 10, true, mPaintClip); canvas.drawArc(mOval, 252, 20, true, mPaintClip); canvas.drawArc(mOval, 275, 10, true, mPaintClip); canvas.drawArc(mOval, 150, 10, true, mPaintClip); canvas.drawArc(mOval, 162, 20, true, mPaintClip); canvas.drawArc(mOval, 185, 10, true, mPaintClip); canvas.drawArc(mOval, 60, 10, true, mPaintClip); canvas.drawArc(mOval, 72, 20, true, mPaintClip); canvas.drawArc(mOval, 95, 10, true, mPaintClip); } }; FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; circleView.setLayoutParams(layoutParams); this.addView(circleView); animateClockWise(circleView); } else if (position == 1) { mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_dark_blue)); circleView = new View(getContext()) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.clipPath(clipPath, Region.Op.DIFFERENCE); canvas.drawCircle(pointF.x, pointF.y, radius, mPaintClip); } }; FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; circleView.setLayoutParams(layoutParams); this.addView(circleView); animateClockWise(circleView); } else if (position == 2) { mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_blue)); circleView = new View(getContext()) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.clipPath(clipPath, Region.Op.DIFFERENCE); canvas.drawArc(mOval, 55, 190, true, mPaintClip); } }; FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; circleView.setLayoutParams(layoutParams); this.addView(circleView); animateClockWise(circleView); } else if (position == 3) { mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_blue)); circleView = new View(getContext()) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.clipPath(clipPath, Region.Op.DIFFERENCE); canvas.drawArc(mOval, 240, 190, true, mPaintClip); canvas.drawArc(mOval, 80, 150, true, mPaintClip); } }; FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; circleView.setLayoutParams(layoutParams); this.addView(circleView); animateClockWise(circleView); } else if (position == 4) { mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_blue)); circleView = new View(getContext()) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.clipPath(clipPath, Region.Op.DIFFERENCE); canvas.drawArc(mOval, 335, 150, true, mPaintClip); canvas.drawArc(mOval, 140, 180, true, mPaintClip); } }; FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; circleView.setLayoutParams(layoutParams); this.addView(circleView); animateClockWise(circleView); } else if (position == 5) { mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_light_grey)); circleView = new View(getContext()) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.clipPath(clipPath, Region.Op.DIFFERENCE); canvas.drawArc(mOval, 330, 150, true, mPaintClip); canvas.drawArc(mOval, 140, 150, true, mPaintClip); } }; FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; circleView.setLayoutParams(layoutParams); this.addView(circleView); animateClockWise(circleView); } else if (position == 6) { mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_purple_color)); circleView = new View(getContext()) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.clipPath(clipPath, Region.Op.DIFFERENCE); canvas.drawArc(mOval, 290, 5, true, mPaintClip); canvas.drawArc(mOval, 297, 20, true, mPaintClip); canvas.drawArc(mOval, 319, 20, true, mPaintClip); canvas.drawArc(mOval, 60, 15, true, mPaintClip); canvas.drawArc(mOval, 77, 8, true, mPaintClip); } }; FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; circleView.setLayoutParams(layoutParams); this.addView(circleView); animateClockWise(circleView); } else if (position == 7) { mPaintClip.setColor(getContext().getResources().getColor(R.color.circle_dark_blue)); circleView = new View(getContext()) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.clipPath(clipPath, Region.Op.DIFFERENCE); canvas.drawArc(mOval, 160, 10, true, mPaintClip); canvas.drawArc(mOval, 172, 30, true, mPaintClip); canvas.drawArc(mOval, 204, 30, true, mPaintClip); canvas.drawArc(mOval, 236, 10, true, mPaintClip); canvas.drawArc(mOval, 20, 20, true, mPaintClip); canvas.drawArc(mOval, 42, 8, true, mPaintClip); } }; FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(value, value); layoutParams.gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL; circleView.setLayoutParams(layoutParams); this.addView(circleView); animateAntiClockWise(circleView); } }
From source file:cn.njmeter.njmeter.widget.spinner.NiceSpinner.java
private void init(Context context, AttributeSet attrs) { Resources resources = getResources(); TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NiceSpinner); int defaultPadding = resources.getDimensionPixelSize(R.dimen.one_and_a_half_grid_unit); setGravity(Gravity.CENTER_VERTICAL | Gravity.START); setPadding(resources.getDimensionPixelSize(R.dimen.three_grid_unit), defaultPadding, defaultPadding, defaultPadding);// ww w . j av a 2s . co m setClickable(true); backgroundSelector = typedArray.getResourceId(R.styleable.NiceSpinner_backgroundSelector, R.drawable.selector); setBackgroundResource(backgroundSelector); textColor = typedArray.getColor(R.styleable.NiceSpinner_textTint, getDefaultTextColor(context)); setTextColor(textColor); listView = new ListView(context); // Set the spinner's id into the listview to make it pretend to be the right parent in // onItemClick listView.setId(getId()); listView.setDivider(new ColorDrawable(Color.GRAY)); listView.setDividerHeight(1); listView.setItemsCanFocus(true); //hide vertical and horizontal scrollbars listView.setVerticalScrollBarEnabled(false); listView.setHorizontalScrollBarEnabled(false); listView.setOverScrollMode(OVER_SCROLL_NEVER); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { selectedIndex = position; if (onItemClickListener != null) { onItemClickListener.onItemClick(parent, view, position, id); } if (onItemSelectedListener != null) { onItemSelectedListener.onItemSelected(parent, view, position, id); } adapter.setSelectedIndex(position); setTextInternal(adapter.getItemInDataset(position).toString()); dismissDropDown(); } }); popupWindow = new PopupWindow(context); popupWindow.setContentView(listView); popupWindow.setOutsideTouchable(true); popupWindow.setFocusable(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { popupWindow.setElevation(DEFAULT_ELEVATION); popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.spinner_drawable)); } else { popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.drop_down_shadow)); } popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { if (!isArrowHidden) { animateArrow(false); } } }); isArrowHidden = typedArray.getBoolean(R.styleable.NiceSpinner_hideArrow, false); arrowDrawableTint = typedArray.getColor(R.styleable.NiceSpinner_arrowTint, Integer.MAX_VALUE); arrowDrawableResId = typedArray.getResourceId(R.styleable.NiceSpinner_arrowDrawable, R.drawable.arrow); dropDownListPaddingBottom = typedArray .getDimensionPixelSize(R.styleable.NiceSpinner_dropDownListPaddingBottom, 0); typedArray.recycle(); measureDisplayHeight(); }
From source file:widgets.Graphical_Range.java
public Graphical_Range(tracerengine Trac, Activity context, String address, String name, int id, int dev_id, String state_key, String url, String usage, String parameters, String model_id, int update, int widgetSize, int session_type, int place_id, String place_type, SharedPreferences params) throws JSONException { super(context, Trac, id, name, "", usage, widgetSize, session_type, place_id, place_type, mytag, container); this.Tracer = Trac; this.address = address; this.url = url; this.dev_id = dev_id; this.id = id; this.state_key = state_key; this.usage = usage; this.update = update; this.wname = name; this.myself = this; this.session_type = session_type; this.place_id = place_id; this.place_type = place_type; this.context = context; stateThread = 1;//from www . j a va 2 s . c o m this.stateS = getResources().getText(R.string.State).toString(); mytag = "Graphical_Range(" + dev_id + ")"; this.params = params; login = params.getString("http_auth_username", null); password = params.getString("http_auth_password", null); //get parameters JSONObject jparam = new JSONObject(parameters.replaceAll(""", "\"")); command = jparam.getString("command"); valueMin = jparam.getInt("valueMin"); valueMax = jparam.getInt("valueMax"); range = valueMax - valueMin; scale = 100 / range; try { test_unite = jparam.getString("unit"); } catch (JSONException e) { test_unite = "%"; } if (test_unite == null || test_unite.length() == 0) { test_unite = "%"; } String[] model = model_id.split("\\."); type = model[0]; //linearlayout horizontal body bodyPanHorizontal = new LinearLayout(context); bodyPanHorizontal.setLayoutParams( new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, Gravity.CENTER_VERTICAL)); bodyPanHorizontal.setOrientation(LinearLayout.HORIZONTAL); //right panel with different info and seekbars rightPan = new FrameLayout(context); rightPan.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); rightPan.setPadding(0, 0, 10, 0); // panel leftPan = new LinearLayout(context); leftPan.setLayoutParams( new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, Gravity.BOTTOM)); leftPan.setOrientation(LinearLayout.VERTICAL); leftPan.setGravity(Gravity.CENTER_VERTICAL); leftPan.setPadding(4, 5, 0, 0); state = new TextView(context); state.setTextColor(Color.BLACK); state.setPadding(20, 0, 0, 0); animation = new AlphaAnimation(0.0f, 1.0f); animation.setDuration(1000); //first seekbar variator seekBarVaria = new SeekBar(context); seekBarVaria.setProgress(0); seekBarVaria.setMax(valueMax - valueMin); seekBarVaria.setLayoutParams( new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL)); seekBarVaria.setProgressDrawable(getResources().getDrawable(R.drawable.bgseekbarvaria)); seekBarVaria.setThumb(getResources().getDrawable(R.drawable.buttonseekbar)); seekBarVaria.setThumbOffset(-3); seekBarVaria.setOnSeekBarChangeListener(this); seekBarVaria.setPadding(0, 0, 15, 7); leftPan.addView(state); leftPan.addView(seekBarVaria); rightPan.addView(leftPan); bodyPanHorizontal.addView(rightPan); super.LL_topPan.removeView(super.LL_featurePan); super.LL_infoPan.addView(bodyPanHorizontal); handler = new Handler() { @Override public void handleMessage(Message msg) { /// Deprecated method to die ///////////////////////////////////////// if (activate) { Tracer.d(mytag, "Handler receives a request to die "); //That seems to be a zombie removeView(LL_background); myself.setVisibility(GONE); if (container != null) { container.removeView(myself); container.recomputeViewAttributes(myself); } try { finalize(); } catch (Throwable t) { } //kill the handler thread itself /////////////////////////////////////////////////////////////////// } else { int new_val = 0; if (msg.what == 9999) { //state_engine send us a signal to notify value changed if (session == null) return; try { Tracer.d(mytag, "Handler receives a new value from cache_engine <" + session.getValue() + ">"); new_val = Integer.parseInt(session.getValue()); } catch (Exception e) { new_val = 0; } //#1649 //Value min and max should be the limit of the widget if (new_val <= valueMin) { state.setText(stateS + valueMin + " " + test_unite); } else if (new_val > valueMin && new_val < valueMax) { state.setText(stateS + new_val + " " + test_unite); } else if (new_val >= valueMax) { state.setText(stateS + valueMax + " " + test_unite); } state.setAnimation(animation); new SBAnim(seekBarVaria.getProgress(), new_val - valueMin).execute(); } else if (msg.what == 9998) { // state_engine send us a signal to notify it'll die ! Tracer.d(mytag, "state engine disappeared ===> Harakiri !"); session = null; realtime = false; removeView(LL_background); myself.setVisibility(GONE); if (container != null) { container.removeView(myself); container.recomputeViewAttributes(myself); } try { finalize(); } catch (Throwable t) { } //kill the handler thread itself } } } }; //================================================================================ /* * New mechanism to be notified by widgetupdate engine when our value is changed * */ WidgetUpdate cache_engine = WidgetUpdate.getInstance(); if (cache_engine != null) { session = new Entity_client(dev_id, state_key, mytag, handler, session_type); if (Tracer.get_engine().subscribe(session)) { realtime = true; //we're connected to engine //each time our value change, the engine will call handler handler.sendEmptyMessage(9999); //Force to consider current value in session } } //================================================================================ }
From source file:edu.ptu.navpattern.tooltip.Tooltip.java
private View getContentView(final Builder builder) { GradientDrawable drawable = new GradientDrawable(); drawable.setColor(builder.mBackgroundColor); drawable.setCornerRadius(builder.mCornerRadius); LinearLayout vgContent = new LinearLayout(builder.mContext); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { vgContent.setBackground(drawable); } else {/*from w w w . j a v a 2s. com*/ //noinspection deprecation vgContent.setBackgroundDrawable(drawable); } int padding = (int) builder.mPadding; vgContent.setPadding(padding, padding, padding, padding); vgContent.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams textViewParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0); textViewParams.gravity = Gravity.CENTER; textViewParams.topMargin = 1; vgContent.setLayoutParams(textViewParams); vgContent.setDividerDrawable(vgContent.getResources().getDrawable(R.drawable.divider_line)); vgContent.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE); if (builder.itemText != null && builder.itemText.length > 0) { for (int i = 0; i < builder.itemText.length; i++) { TextView textView = new TextView(builder.mContext); textView.setText(builder.itemText[i]); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 44); textView.setTextColor(0xffffffff); textView.setGravity(Gravity.CENTER_VERTICAL); if (builder.itemLogo != null && builder.itemLogo.length > i) { Drawable drawableLeft = builder.mContext.getResources().getDrawable(builder.itemLogo[i]); /// ??,??. // drawableLeft.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); // textView.setCompoundDrawables(drawableLeft, null, null, null); // textView.setCompoundDrawablePadding(4); // textView.setBackgroundDrawable(drawableLeft); LinearLayout linearLayout = new LinearLayout(builder.mContext); linearLayout.setMinimumHeight((int) dpToPx(44f)); linearLayout.setOrientation(LinearLayout.HORIZONTAL); linearLayout.setGravity(Gravity.CENTER_VERTICAL); ImageView icon = new ImageView(builder.mContext); icon.setImageDrawable(drawableLeft); linearLayout.addView(icon); linearLayout.addView(textView); vgContent.addView(linearLayout); final int position = i; linearLayout.setClickable(false); linearLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (builder.mOnItemClickListener != null) { builder.mOnItemClickListener.onClick(position); } mTouchListener.onTouch(v, MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, v.getLeft() + 5, v.getTop() + 5, 0)); } }); } else { vgContent.addView(textView); final int position = i; textView.setClickable(false); textView.setMinimumHeight((int) dpToPx(44f)); textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (builder.mOnItemClickListener != null) { builder.mOnItemClickListener.onClick(position); } mTouchListener.onTouch(v, null); } }); } } } mArrowView = new ImageView(builder.mContext); mArrowView.setImageDrawable(builder.mArrowDrawable); LinearLayout.LayoutParams arrowLayoutParams; if (mGravity == Gravity.TOP || mGravity == Gravity.BOTTOM) { arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowWidth, (int) builder.mArrowHeight, 0); } else { arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowHeight, (int) builder.mArrowWidth, 0); } arrowLayoutParams.gravity = Gravity.CENTER; mArrowView.setLayoutParams(arrowLayoutParams); mContentView = new LinearLayout(builder.mContext); mContentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); mContentView.setOrientation(mGravity == Gravity.START || mGravity == Gravity.END ? LinearLayout.HORIZONTAL : LinearLayout.VERTICAL); padding = (int) dpToPx(5); switch (mGravity) { case Gravity.START: mContentView.setPadding(0, 0, padding, 0); break; case Gravity.TOP: case Gravity.BOTTOM: mContentView.setPadding(padding, 0, padding, 0); break; case Gravity.END: mContentView.setPadding(padding, 0, 0, 0); break; } if (mGravity == Gravity.TOP || mGravity == Gravity.START) { mContentView.addView(vgContent); mContentView.addView(mArrowView); } else { mContentView.addView(mArrowView); mContentView.addView(vgContent); } if (builder.isCancelable || builder.isDismissOnClick) { mContentView.setOnTouchListener(mTouchListener); } return mContentView; }
From source file:at.alladin.rmbt.android.map.overlay.RMBTBalloonOverlayView.java
public void setBalloonData(final RMBTBalloonOverlayItem item, final ViewGroup parent) { // map our custom item data to fields // title.setText(item.getTitle()); resultItems = item.getResultItems(); resultListView.removeAllViews();//from w ww . j a v a2 s. co m final float scale = getResources().getDisplayMetrics().density; final int leftRightItem = Helperfunctions.dpToPx(5, scale); final int topBottomItem = Helperfunctions.dpToPx(3, scale); final int leftRightDiv = Helperfunctions.dpToPx(0, scale); final int topBottomDiv = Helperfunctions.dpToPx(0, scale); final int heightDiv = Helperfunctions.dpToPx(1, scale); final int topBottomImg = Helperfunctions.dpToPx(1, scale); if (resultItems != null && resultItems.length() > 0) { for (int i = 0; i < 1; i++) // JSONObject resultListItem; try { final JSONObject result = resultItems.getJSONObject(i); final LayoutInflater resultInflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View resultView = resultInflater.inflate(R.layout.balloon_overlay_listitem, parent); final LinearLayout measurementLayout = (LinearLayout) resultView .findViewById(R.id.resultMeasurementList); measurementLayout.setVisibility(View.GONE); final LinearLayout netLayout = (LinearLayout) resultView.findViewById(R.id.resultNetList); netLayout.setVisibility(View.GONE); final TextView measurementHeader = (TextView) resultView.findViewById(R.id.resultMeasurement); measurementHeader.setVisibility(View.GONE); final TextView netHeader = (TextView) resultView.findViewById(R.id.resultNet); netHeader.setVisibility(View.GONE); final TextView dateHeader = (TextView) resultView.findViewById(R.id.resultDate); dateHeader.setVisibility(View.GONE); dateHeader.setText(result.optString("time_string")); final JSONArray measurementArray = result.getJSONArray("measurement"); final JSONArray netArray = result.getJSONArray("net"); for (int j = 0; j < measurementArray.length(); j++) { final JSONObject singleItem = measurementArray.getJSONObject(j); final LinearLayout measurememtItemLayout = new LinearLayout(context); // (LinearLayout)measurememtItemView.findViewById(R.id.measurement_item); measurememtItemLayout.setLayoutParams( new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT)); measurememtItemLayout.setGravity(Gravity.CENTER_VERTICAL); measurememtItemLayout.setPadding(leftRightItem, topBottomItem, leftRightItem, topBottomItem); final TextView itemTitle = new TextView(context, null, R.style.balloonResultItemTitle); itemTitle.setLayoutParams( new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 0.4f)); itemTitle.setTextAppearance(context, R.style.balloonResultItemTitle); itemTitle.setWidth(0); itemTitle.setGravity(Gravity.LEFT); itemTitle.setText(singleItem.getString("title")); measurememtItemLayout.addView(itemTitle); final ImageView itemClassification = new ImageView(context); itemClassification.setLayoutParams( new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.MATCH_PARENT, 0.1f)); itemClassification.setPadding(0, topBottomImg, 0, topBottomImg); // itemClassification.set setGravity(Gravity.LEFT); itemClassification.setImageDrawable(getResources().getDrawable( Helperfunctions.getClassificationImage(singleItem.getInt("classification")))); measurememtItemLayout.addView(itemClassification); final TextView itemValue = new TextView(context, null, R.style.balloonResultItemValue); itemValue.setLayoutParams( new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 0.5f)); itemValue.setTextAppearance(context, R.style.balloonResultItemValue); itemValue.setWidth(0); itemValue.setGravity(Gravity.LEFT); itemValue.setText(singleItem.getString("value")); measurememtItemLayout.addView(itemValue); measurementLayout.addView(measurememtItemLayout); final View divider = new View(context); divider.setLayoutParams(new LinearLayout.LayoutParams( android.view.ViewGroup.LayoutParams.MATCH_PARENT, heightDiv, 1)); divider.setPadding(leftRightDiv, topBottomDiv, leftRightDiv, topBottomDiv); divider.setBackgroundResource(R.drawable.bg_trans_light_10); measurementLayout.addView(divider); measurementLayout.invalidate(); } for (int j = 0; j < netArray.length(); j++) { final JSONObject singleItem = netArray.getJSONObject(j); final LinearLayout netItemLayout = new LinearLayout(context); // (LinearLayout)measurememtItemView.findViewById(R.id.measurement_item); netItemLayout.setLayoutParams( new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT)); netItemLayout.setPadding(leftRightItem, topBottomItem, leftRightItem, topBottomItem); netItemLayout.setGravity(Gravity.CENTER_VERTICAL); final TextView itemTitle = new TextView(context, null, R.style.balloonResultItemTitle); itemTitle.setLayoutParams( new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 0.4f)); itemTitle.setTextAppearance(context, R.style.balloonResultItemTitle); itemTitle.setWidth(0); itemTitle.setGravity(Gravity.LEFT); itemTitle.setText(singleItem.getString("title")); netItemLayout.addView(itemTitle); final ImageView itemClassification = new ImageView(context); itemClassification.setLayoutParams( new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.MATCH_PARENT, 0.1f)); itemClassification.setPadding(0, topBottomImg, 0, topBottomImg); itemClassification.setImageDrawable( context.getResources().getDrawable(R.drawable.traffic_lights_none)); netItemLayout.addView(itemClassification); final TextView itemValue = new TextView(context, null, R.style.balloonResultItemValue); itemValue.setLayoutParams( new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 0.5f)); itemValue.setTextAppearance(context, R.style.balloonResultItemValue); itemValue.setWidth(0); itemValue.setGravity(Gravity.LEFT); itemValue.setText(singleItem.optString("value", null)); netItemLayout.addView(itemValue); netLayout.addView(netItemLayout); final View divider = new View(context); divider.setLayoutParams(new LinearLayout.LayoutParams( android.view.ViewGroup.LayoutParams.MATCH_PARENT, heightDiv, 1)); divider.setPadding(leftRightDiv, topBottomDiv, leftRightDiv, topBottomDiv); divider.setBackgroundResource(R.drawable.bg_trans_light_10); netLayout.addView(divider); netLayout.invalidate(); } measurementHeader.setVisibility(View.VISIBLE); netHeader.setVisibility(View.VISIBLE); measurementLayout.setVisibility(View.VISIBLE); netLayout.setVisibility(View.VISIBLE); dateHeader.setVisibility(View.VISIBLE); resultListView.addView(resultView); Log.d(DEBUG_TAG, "View Added"); // codeText.setText(resultListItem.getString("sync_code")); } catch (final JSONException e) { e.printStackTrace(); } progessBar.setVisibility(View.GONE); emptyView.setVisibility(View.GONE); resultListView.setVisibility(View.VISIBLE); resultListView.invalidate(); } else { Log.i(DEBUG_TAG, "LEERE LISTE"); progessBar.setVisibility(View.GONE); emptyView.setVisibility(View.VISIBLE); emptyView.setText(context.getString(R.string.error_no_data)); emptyView.invalidate(); } }
From source file:org.borderstone.tagtags.TTStartActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setTheme(R.style.AppTheme); this.setContentView(R.layout.activity_start); Toolbar toolbar = (Toolbar) this.findViewById(R.id.toolbar); //toolbar.inflateMenu(R.menu.menu_start); toolbar.setTitle("TagTags"); toolbar.setVisibility(View.VISIBLE); TTStartActivity.me = getApplicationContext(); protocol.setAction("android.intent.action.PROTOCOL"); settings.setAction("android.intent.action.SETTINGS"); Constants.init(new File(this.getFilesDir(), "bsettings.txt"), this.getApplicationContext()); Constants.fileListener = this; /*Load variables that are stored in a text file keeping version info and info about third party resources here, for easy editing*/ try {/*www . ja v a 2 s . c o m*/ BufferedReader reader = new BufferedReader( new InputStreamReader(this.getResources().openRawResource(R.raw.appinfo))); String line = reader.readLine(); String[] t; while (line != null) { t = line.split(":"); if (line.startsWith("#thirdparty:")) thirdparty += t[1] + "\n"; else if (line.startsWith("#recentchanges:")) recentchanges += "-- " + t[1] + "\n"; line = reader.readLine(); } //just to remove the final new line. if (!thirdparty.equals("")) thirdparty = thirdparty.substring(0, thirdparty.length() - 1); if (!recentchanges.equals("")) recentchanges = recentchanges.substring(0, recentchanges.length() - 1); } catch (Exception ignored) { } //Most of the code below is purely for aesthetics! txtPhilosophy = new BTitleLabel(this); txtPhilosophy.setTypeface(Typeface.DEFAULT_BOLD); txtPhilosophy.setLayoutParams(Constants.defaultParams); txtPhilosophy.setOnClickListener(this); txtPhilosophy.setTextColor(Color.BLACK); txtVersion = new BStandardLabel(this); txtVersion.setText("Recent changes:\n" + recentchanges); txtVersion.setLayoutParams(Constants.defaultParams); txtVersion.setTextColor(Color.BLACK); try { PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0); toolbar.setSubtitle("v. " + pInfo.versionName); } catch (PackageManager.NameNotFoundException ignored) { } toolbar.setNavigationIcon(R.drawable.drawer); ImageView slu = new ImageView(this); ImageView sites = new ImageView(this); slu.setImageResource(R.drawable.slulogo); sites.setImageResource(R.drawable.sites); LinearLayout llLogos = new LinearLayout(this); llLogos.setOrientation(LinearLayout.HORIZONTAL); llLogos.setGravity(Gravity.END | Gravity.CENTER_VERTICAL); llLogos.addView(slu); llLogos.addView(sites); setPhiloText(); LinearLayout back = (LinearLayout) this.findViewById(R.id.back); back.setOrientation(LinearLayout.VERTICAL); txtPhilosophy.setLayoutParams(Constants.defaultParams); txtPhilosophy.setBackgroundResource(R.drawable.border); txtVersion.setLayoutParams(Constants.defaultParams); txtVersion.setBackgroundResource(R.drawable.border_recurring); back.addView(txtPhilosophy); back.addView(txtVersion); back.addView(llLogos); lblSettings = new BButton(this); lblDownload = new BButton(this); lblDownload.setIcon(R.drawable.download); lblSettings.setIcon(R.drawable.settings); lblSettings.setText("Settings"); lblDownload.setText("Download from server"); lblSettings.setOnClickListener(this); lblDownload.setOnClickListener(this); if (!checkPermissions()) { final Intent intro = new Intent(); intro.setAction("android.intent.action.INTRO"); this.startActivity(intro); } BTitleLabel lblProperties = new BTitleLabel(this); BTitleLabel lblLocal = new BTitleLabel(this); fileNavView = new BFileNavView(this, this); lblProperties.setTextSize(Constants.fontSize + 2); lblLocal.setTextSize(Constants.fontSize + 2); lblProperties.setText("PROPERTIES"); lblProperties.setTextColor(Color.WHITE); lblProperties.setGravity(Gravity.CENTER); lblLocal.setText("LOCAL FILES"); lblLocal.setTextColor(Color.WHITE); lblLocal.setGravity(Gravity.CENTER); final DrawerLayout drawerLayout = (DrawerLayout) this.findViewById(R.id.startDrawerLayout); final LinearLayout drawer = (LinearLayout) this.findViewById(R.id.drawer); drawer.setClickable(false); drawer.bringToFront(); drawer.addView(lblProperties); drawer.addView(lblDownload); drawer.addView(lblSettings); drawer.addView(lblLocal); drawer.addView(fileNavView); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!drawerLayout.isDrawerOpen(Gravity.LEFT)) drawerLayout.openDrawer(Gravity.LEFT); else drawerLayout.closeDrawer(Gravity.LEFT); } }); }
From source file:com.uzmap.pkg.uzmodules.uzBMap.mode.Billboard.java
private LinearLayout titleLayout() { LinearLayout titleLayout = new LinearLayout(context); LayoutParams layoutParams = new LayoutParams(UZCoreUtil.dipToPix(width - iconSize - 30), UZCoreUtil.dipToPix(height)); layoutParams.setMargins(UZCoreUtil.dipToPix(10), 0, UZCoreUtil.dipToPix(10), 0); titleLayout.setLayoutParams(layoutParams); titleLayout.setOrientation(LinearLayout.VERTICAL); LinearLayout titleLayout2 = new LinearLayout(context); LayoutParams layoutParams2 = new LayoutParams(UZCoreUtil.dipToPix(width - iconSize - 30), UZCoreUtil.dipToPix(height - 10)); titleLayout2.setGravity(Gravity.CENTER_VERTICAL); titleLayout2.setOrientation(LinearLayout.VERTICAL); titleLayout2.setLayoutParams(layoutParams2); titleLayout.addView(titleLayout2);/*w ww. j a va 2 s . c o m*/ titleLayout2.addView(title()); titleLayout2.addView(subTitle()); return titleLayout; }
From source file:rosmi.acagild.alarmclock.ringing.ShareFragment.java
private static void drawStamp(Context context, Bitmap bitmap, String question) { Canvas canvas = new Canvas(bitmap); canvas.drawBitmap(bitmap, 0, 0, null); float opacity = 0.7f; int horizontalPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, context.getResources().getDisplayMetrics()); int verticalPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, context.getResources().getDisplayMetrics()); int textSize = 16; // defined in SP int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 16, context.getResources().getDisplayMetrics()); LinearLayout layout = new LinearLayout(context); layout.setOrientation(LinearLayout.HORIZONTAL); layout.setBackgroundResource(R.drawable.rounded_corners); layout.getBackground().setAlpha((int) (opacity * 255)); layout.setPadding(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding); ImageView logo = new ImageView(context); logo.setImageDrawable(ContextCompat.getDrawable(context, R.mipmap.ic_launcher)); layout.addView(logo);/* ww w. j a v a2 s.com*/ TextView textView = new TextView(context); textView.setVisibility(View.VISIBLE); if (question != null) { textView.setText(question); } else { textView.setText("Mimicker"); } textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, textSize); textView.setPadding(horizontalPadding, 0, 0, 0); LinearLayout.LayoutParams centerInParent = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); centerInParent.gravity = Gravity.CENTER_VERTICAL; layout.addView(textView, centerInParent); layout.measure(canvas.getWidth(), height); layout.layout(0, 0, layout.getMeasuredWidth(), layout.getMeasuredHeight()); canvas.translate(horizontalPadding, (float) (canvas.getHeight() * 0.8 - height)); float scale = Math.min(1.0f, canvas.getWidth() / 1080f); canvas.scale(scale, scale); layout.draw(canvas); }