List of usage examples for android.view Gravity CENTER
int CENTER
To view the source code for android.view Gravity CENTER.
Click Source Link
From source file:com.sdspikes.fireworks.FireworksActivity.java
private TextView makeNewCardTextView(int width, GameState.Card card) { width = Math.min(width, MAX_CARD_WIDTH); width = Math.max(width, MIN_CARD_WIDTH); ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(width, ViewGroup.LayoutParams.WRAP_CONTENT); TextView textView = new TextView(this); textView.setLayoutParams(params);//from w w w . j a va2 s . c o m textView.setGravity(Gravity.CENTER); textView.setText(String.valueOf(card.rank)); textView.setBackgroundResource(HandFragment.cardColorToBGColor.get(card.color)); textView.setTextColor(getResources().getColor(HandFragment.cardColorToTextColor(card.color))); return textView; }
From source file:com.stikyhive.stikyhive.ChattingActivity.java
@Override protected void onResume() { super.onResume(); Log.i(TAG, " ON RESUME"); int a;// w w w . ja v a2 s. co m RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0); params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); layoutTalk.setLayoutParams(params); layoutTalk.setGravity(Gravity.CENTER); flagRecord = false; // txtUserName = (TextView) findViewById(R.id.txtChatName); LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver, new IntentFilter(QuickstartPreferences.CHAT_REGISTRATION_COMPLETE)); if (!ChattingActivity.flagChatting) { // Log.i(TAG, " FLag Make Offer"); StikyChat stikyChat = new StikyChat("", messageServer, false, timeSendOffer, "", offerId, offerStatus, price, rate, name, null, ""); //stikyChat.setFlagStikyPayChk(flagStikyPayChk); adapter.add(stikyChat); lv.smoothScrollToPosition(adapter.getCount() - 1); if (offerId != 0) { msg = "Make Offer"; } else { msg = messageServer; } new regTask().execute("Send ... "); } }
From source file:com.stikyhive.stikyhive.ChattingActivity.java
@Override protected void onPause() { super.onPause(); //for recording if (mRecorder != null) { mRecorder.release();//from w ww . j av a 2 s . c o m mRecorder = null; } // If the screen is off then the device has been locked PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); boolean isScreenOn = powerManager.isScreenOn(); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0); params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); layoutTalk.setLayoutParams(params); layoutTalk.setGravity(Gravity.CENTER); flagRecord = false; if (!isScreenOn || flagMakeOffer || flagFullPhoto) { // The screen has been locked // do stuff... Log.i(TAG, "Screen is on..."); flagFullPhoto = false; } else { Log.i(TAG, "Screen is off...."); finish(); } Log.i(TAG, " REsume %%%%%%%%%%%%AAAAAAAAAAAAA"); /* if (this.getAction().equals(Intent.ACTION_SCREEN_OFF)) { // DO WHATEVER YOU NEED TO DO HERE wasScreenOn = false; } else { } */ }
From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardViewBase.java
@CallSuper protected void onBufferDraw(Canvas canvas, final Paint paint) { if (mKeyboardChanged) { invalidateAllKeys();/*from w w w .j av a 2s. com*/ mKeyboardChanged = false; } canvas.getClipBounds(mDirtyRect); if (mKeyboard == null) return; final boolean drawKeyboardNameText = (mKeyboardNameTextSize > 1f) && AnyApplication.getConfig().getShowKeyboardNameText(); final boolean drawHintText = (mHintTextSize > 1) && AnyApplication.getConfig().getShowHintTextOnKeys(); final boolean useCustomKeyTextColor = false; // TODO: final boolean useCustomKeyTextColor = // AnyApplication.getConfig().getUseCustomTextColorOnKeys(); final ColorStateList keyTextColor = useCustomKeyTextColor ? new ColorStateList(new int[][] { { 0 } }, new int[] { 0xFF6666FF }) : mKeyTextColor; final boolean useCustomHintColor = drawHintText && false; // TODO: final boolean useCustomHintColor = drawHintText && final ColorStateList hintColor = useCustomHintColor ? new ColorStateList(new int[][] { { 0 } }, new int[] { 0xFFFF6666 }) : mHintTextColor; // allow preferences to override theme settings for hint text position final boolean useCustomHintAlign = drawHintText && AnyApplication.getConfig().getUseCustomHintAlign(); final int hintAlign = useCustomHintAlign ? AnyApplication.getConfig().getCustomHintAlign() : mHintLabelAlign; final int hintVAlign = useCustomHintAlign ? AnyApplication.getConfig().getCustomHintVAlign() : mHintLabelVAlign; final Drawable keyBackground = mKeyBackground; final Rect clipRegion = mClipRegion; final int kbdPaddingLeft = getPaddingLeft(); final int kbdPaddingTop = getPaddingTop(); final Key[] keys = mKeys; final Key invalidKey = mInvalidatedKey; boolean drawSingleKey = false; if (invalidKey != null && canvas.getClipBounds(clipRegion)) { // TODO we should use Rect.inset and Rect.contains here. // Is clipRegion completely contained within the invalidated key? if (invalidKey.x + kbdPaddingLeft - 1 <= clipRegion.left && invalidKey.y + kbdPaddingTop - 1 <= clipRegion.top && invalidKey.x + invalidKey.width + kbdPaddingLeft + 1 >= clipRegion.right && invalidKey.y + invalidKey.height + kbdPaddingTop + 1 >= clipRegion.bottom) { drawSingleKey = true; } } for (Key keyBase : keys) { final AnyKey key = (AnyKey) keyBase; final boolean keyIsSpace = isSpaceKey(key); if (drawSingleKey && (invalidKey != key)) { continue; } if (!mDirtyRect.intersects(key.x + kbdPaddingLeft, key.y + kbdPaddingTop, key.x + key.width + kbdPaddingLeft, key.y + key.height + kbdPaddingTop)) { continue; } int[] drawableState = key.getCurrentDrawableState(mDrawableStatesProvider); if (keyIsSpace) paint.setColor(mKeyboardNameTextColor); else paint.setColor(keyTextColor.getColorForState(drawableState, 0xFF000000)); keyBackground.setState(drawableState); // Switch the character to uppercase if shift is pressed CharSequence label = key.label == null ? null : adjustLabelToShiftState(key); final Rect bounds = keyBackground.getBounds(); if ((key.width != bounds.right) || (key.height != bounds.bottom)) { keyBackground.setBounds(0, 0, key.width, key.height); } canvas.translate(key.x + kbdPaddingLeft, key.y + kbdPaddingTop); keyBackground.draw(canvas); if (TextUtils.isEmpty(label)) { Drawable iconToDraw = getIconToDrawForKey(key, false); if (iconToDraw != null/* && shouldDrawIcon */) { //http://developer.android.com/reference/android/graphics/drawable/Drawable.html#getCurrent() //http://stackoverflow.com/a/103600/1324235 final boolean is9Patch = iconToDraw.getCurrent() instanceof NinePatchDrawable; // Special handing for the upper-right number hint icons final int drawableWidth; final int drawableHeight; final int drawableX; final int drawableY; drawableWidth = is9Patch ? key.width : iconToDraw.getIntrinsicWidth(); drawableHeight = is9Patch ? key.height : iconToDraw.getIntrinsicHeight(); drawableX = (key.width + mKeyBackgroundPadding.left - mKeyBackgroundPadding.right - drawableWidth) / 2; drawableY = (key.height + mKeyBackgroundPadding.top - mKeyBackgroundPadding.bottom - drawableHeight) / 2; canvas.translate(drawableX, drawableY); iconToDraw.setBounds(0, 0, drawableWidth, drawableHeight); iconToDraw.draw(canvas); canvas.translate(-drawableX, -drawableY); if (keyIsSpace && drawKeyboardNameText) { // now a little hack, I'll set the label now, so it get // drawn. label = mKeyboardName; } } else { // ho... no icon. // I'll try to guess the text label = guessLabelForKey(key.getPrimaryCode()); } } if (label != null) { // For characters, use large font. For labels like "Done", use // small font. final FontMetrics fm; if (keyIsSpace) { paint.setTextSize(mKeyboardNameTextSize); paint.setTypeface(Typeface.DEFAULT_BOLD); if (mKeyboardNameFontMetrics == null) mKeyboardNameFontMetrics = paint.getFontMetrics(); fm = mKeyboardNameFontMetrics; } else if (label.length() > 1 && key.getCodesCount() < 2) { setPaintForLabelText(paint); if (mLabelFontMetrics == null) mLabelFontMetrics = paint.getFontMetrics(); fm = mLabelFontMetrics; } else { setPaintToKeyText(paint); if (mTextFontMetrics == null) mTextFontMetrics = paint.getFontMetrics(); fm = mTextFontMetrics; } if (isLabelOfPictographic(label)) { paint.setTextSize(2f * paint.getTextSize()); } final float labelHeight = -fm.top; // Draw a drop shadow for the text paint.setShadowLayer(mShadowRadius, mShadowOffsetX, mShadowOffsetY, mShadowColor); final float textWidth = adjustTextSizeForLabel(paint, label, key.width); // the center of the drawable space, which is value used // previously for vertically // positioning the key label final float centerY = mKeyBackgroundPadding.top + ((key.height - mKeyBackgroundPadding.top - mKeyBackgroundPadding.bottom) / (keyIsSpace ? 3 : 2));// the label on the space is a bit higher // the X coordinate for the center of the main label text is // unaffected by the hints final float textX = mKeyBackgroundPadding.left + (key.width - mKeyBackgroundPadding.left - mKeyBackgroundPadding.right) / 2; final float textY; // Some devices (mostly pre-Honeycomb, have issues with RTL text // drawing. // Of course, there is no issue with a single character :) // so, we'll use the RTL secured drawing (via StaticLayout) for // labels. if (label.length() > 1 && !AnyApplication.getConfig().workaround_alwaysUseDrawText()) { // calculate Y coordinate of top of text based on center // location textY = centerY - ((labelHeight - paint.descent()) / 2); canvas.translate(textX, textY); // RTL fix. But it costs, let do it when in need (more than // 1 character) StaticLayout labelText = new StaticLayout(label, new TextPaint(paint), (int) textWidth, Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); labelText.draw(canvas); } else { // to get Y coordinate of baseline from center of text, // first add half the height (to get to // bottom of text), then subtract the part below the // baseline. Note that fm.top is negative. textY = centerY + ((labelHeight - paint.descent()) / 2); canvas.translate(textX, textY); canvas.drawText(label, 0, label.length(), 0, 0, paint); } canvas.translate(-textX, -textY); // (-) // Turn off drop shadow paint.setShadowLayer(0, 0, 0, 0); } if (drawHintText) { if ((key.popupCharacters != null && key.popupCharacters.length() > 0) || (key.popupResId != 0) || (key.longPressCode != 0)) { Align oldAlign = paint.getTextAlign(); String hintText = null; if (key.hintLabel != null && key.hintLabel.length() > 0) { hintText = key.hintLabel.toString(); // it is the responsibility of the keyboard layout // designer to ensure that they do // not put too many characters in the hint label... } else if (key.longPressCode != 0) { if (Character.isLetterOrDigit(key.longPressCode)) hintText = Character.toString((char) key.longPressCode); } else if (key.popupCharacters != null) { final String hintString = key.popupCharacters.toString(); final int hintLength = hintString.length(); if (hintLength <= 3) hintText = hintString; } // if hintText is still null, it means it didn't fit one of // the above // cases, so we should provide the hint using the default if (hintText == null) { if (mHintOverflowLabel != null) hintText = mHintOverflowLabel; else { // theme does not provide a defaultHintLabel // use if hints are above, ... if hints are // below // (to avoid being too close to main label/icon) if (hintVAlign == Gravity.TOP) hintText = ""; else hintText = "..."; } } if (mKeyboard.isShifted()) hintText = hintText.toUpperCase(getKeyboard().getLocale()); // now draw hint paint.setTypeface(Typeface.DEFAULT); paint.setColor(hintColor.getColorForState(drawableState, 0xFF000000)); paint.setTextSize(mHintTextSize); // get the hint text font metrics so that we know the size // of the hint when // we try to position the main label (to try to make sure // they don't overlap) if (mHintTextFontMetrics == null) { mHintTextFontMetrics = paint.getFontMetrics(); } final float hintX; final float hintY; // the (float) 0.5 value is added or subtracted to just give // a little more room // in case the theme designer didn't account for the hint // label location if (hintAlign == Gravity.START) { // left paint.setTextAlign(Align.LEFT); hintX = mKeyBackgroundPadding.left + 0.5f; } else if (hintAlign == Gravity.CENTER) { // center paint.setTextAlign(Align.CENTER); hintX = mKeyBackgroundPadding.left + (key.width - mKeyBackgroundPadding.left - mKeyBackgroundPadding.right) / 2; } else { // right paint.setTextAlign(Align.RIGHT); hintX = key.width - mKeyBackgroundPadding.right - 0.5f; } if (hintVAlign == Gravity.TOP) { // above hintY = mKeyBackgroundPadding.top - mHintTextFontMetrics.top + 0.5f; } else { // below hintY = key.height - mKeyBackgroundPadding.bottom - mHintTextFontMetrics.bottom - 0.5f; } canvas.drawText(hintText, hintX, hintY, paint); paint.setTextAlign(oldAlign); } } canvas.translate(-key.x - kbdPaddingLeft, -key.y - kbdPaddingTop); } mInvalidatedKey = null; mDirtyRect.setEmpty(); }
From source file:com.devwang.logcabin.LogCabinMainActivity.java
private void toastDisplay(Context context, CharSequence text, int gravity, int ResImgId, int duration) { Toast toast = Toast.makeText(context, text, duration); if (gravity != 0) { switch (gravity) { case Gravity.CENTER: toast.setGravity(Gravity.CENTER, 0, 0);// x,y0 break; case Gravity.FILL: toast.setGravity(Gravity.FILL, 0, 0);// x,y0 break; case Gravity.BOTTOM: toast.setGravity(Gravity.BOTTOM, 0, 0); break; default:// w w w. j a v a2 s . c o m break; } } if (ResImgId != 0) { LinearLayout toastView = (LinearLayout) toast.getView(); ImageView imageCodeProject = new ImageView(getApplicationContext()); imageCodeProject.setImageResource(ResImgId); toastView.addView(imageCodeProject, 0); } toast.show(); }
From source file:com.skytree.epubtest.BookViewActivity.java
public View makeResultItem(SearchResult sr, int mode) { int inlineColor = Color.rgb(133, 105, 75); int headColor = Color.rgb(94, 61, 34); int textColor = Color.rgb(50, 40, 40); SkyLayout view = new SkyLayout(this); int itemWidth = ps(370); int itemHeight = ps(190); this.setFrame(view, 0, 0, itemWidth, itemHeight); TextView chapterLabel = null;//from w ww . ja va 2 s.co m TextView positionLabel = null; TextView textLabel = null; Button itemButton = null; itemButton = new Button(this); itemButton.setBackgroundColor(Color.TRANSPARENT); itemButton.setOnClickListener(listener); this.setFrame(itemButton, 0, 0, itemWidth, itemHeight); if (mode == 0) { // Normal case int ci = sr.chapterIndex; String chapterText = ""; chapterText = sr.chapterTitle; String positionText = String.format("%d/%d", sr.pageIndex + 1, sr.numberOfPagesInChapter); if (chapterText == null || chapterText.isEmpty()) { chapterText = "Chapter " + ci; } if (sr.pageIndex < 0 || sr.numberOfPagesInChapter < 0) { positionText = ""; } chapterLabel = this.makeLabel(3090, chapterText, Gravity.LEFT, 15, headColor); positionLabel = this.makeLabel(3091, positionText, Gravity.LEFT, 15, headColor); textLabel = this.makeLabel(3092, sr.text, Gravity.LEFT, 15, textColor); itemButton.setId(100000 + searchResults.size()); } else if (mode == 1) { // Paused chapterLabel = this.makeLabel(3090, getString(R.string.searchmore) + "....", Gravity.CENTER, 18, headColor); // positionLabel = this.makeLabel(3091, String.format("%d/%d",sr.pageIndex+1,sr.numberOfPagesInChapter), Gravity.LEFT, 15, headColor); textLabel = this.makeLabel(3092, sr.numberOfSearched + " " + getString(R.string.searchfound) + ".", Gravity.CENTER, 16, textColor); itemButton.setId(3093); } else if (mode == 2) { // finished chapterLabel = this.makeLabel(3090, getString(R.string.searchfinished), Gravity.CENTER, 18, headColor); // positionLabel = this.makeLabel(3091, String.format("%d/%d",sr.pageIndex+1,sr.numberOfPagesInChapter), Gravity.LEFT, 15, headColor); textLabel = this.makeLabel(3092, sr.numberOfSearched + " " + getString(R.string.searchfound) + ".", Gravity.CENTER, 16, textColor); itemButton.setId(3094); } textLabel.setMaxLines(3); if (mode == 0) { this.setFrame(chapterLabel, ps(20), ps(20), ps(270), ps(30)); this.setFrame(positionLabel, itemWidth - ps(85), ps(20), ps(70), ps(30)); this.setFrame(textLabel, ps(20), ps(80), itemWidth - ps(40), itemHeight - ps(80 + 20)); } else { this.setFrame(chapterLabel, ps(20), ps(20), ps(350), ps(40)); // this.setFrame(positionLabel, itemWidth-ps(80), ps(20),ps(70),ps(30)); this.setFrame(textLabel, ps(20), ps(80), itemWidth - ps(40), itemHeight - ps(80 + 20)); } view.addView(chapterLabel); if (mode == 0) view.addView(positionLabel); view.addView(textLabel); view.addView(itemButton); RectShape crs = new RectShape(); SkyDrawable cd = new SkyDrawable(crs, Color.TRANSPARENT, inlineColor, 1); view.setBackgroundDrawable(cd); return view; }
From source file:com.skytree.epubtest.BookViewActivity.java
public void makeFontBox() { int boxColor = Color.rgb(241, 238, 229); int innerBoxColor = Color.rgb(246, 244, 239); int inlineColor = Color.rgb(133, 105, 75); int width = 450; int height = 500; fontBox = new SkyBox(this); fontBox.setBoxColor(boxColor);//from w ww .j a va 2s . com fontBox.setArrowHeight(ps(25)); fontBox.setArrowDirection(false); setFrame(fontBox, ps(50), ps(200), ps(width), ps(height)); ScrollView fontBoxScrollView = new ScrollView(this); this.setFrame(fontBoxScrollView, ps(5), ps(10), ps(440), ps(height - 50)); fontBox.contentView.addView(fontBoxScrollView); // NEW SkyLayout contentLayout = new SkyLayout(this); fontBoxScrollView.addView(contentLayout, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); // #1 first make brightness controller // brView is the box containing the bright slider. int FY = 10; View brView = new View(this); RoundRectShape rrs = new RoundRectShape( new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null, null); SkyDrawable srd = new SkyDrawable(rrs, innerBoxColor, inlineColor, 1); brView.setBackgroundDrawable(srd); setFrame(brView, ps(20), ps(FY), ps(width - 40), ps(53)); contentLayout.addView(brView); // darker and brighter icons int SBS = 60; ImageButton sbb = this.makeImageButton(9005, R.drawable.brightness2x, ps(SBS), ps(SBS)); setFrame(sbb, ps(50), ps(FY), ps(SBS), ps(SBS)); sbb.setAlpha(200); int BBS = 70; ImageButton bbb = this.makeImageButton(9006, R.drawable.brightness2x, ps(BBS), ps(BBS)); setFrame(bbb, ps(width - 110), ps(FY - 5), ps(BBS), ps(BBS)); bbb.setAlpha(200); contentLayout.addView(sbb); contentLayout.addView(bbb); // making bright slider brightBar = new SeekBar(this); brightBar.setMax(999); brightBar.setId(997); brightBar.setBackgroundColor(Color.TRANSPARENT); brightBar.setOnSeekBarChangeListener(new SeekBarDelegate()); brightBar.setProgressDrawable(new LineDrawable(Color.rgb(160, 160, 160), ps(10))); brightBar.setThumbOffset(-1); setFrame(brightBar, ps(100), ps(FY + 4), ps(width - 210), ps(50)); contentLayout.addView(brightBar); // #2 second make decrese/increse font size buttons // decrease font size Button int FBY = 80; decreaseButton = new Button(this); setFrame(decreaseButton, ps(20), ps(FBY), ps(width - 40 - 20) / 2, ps(60)); decreaseButton.setText(getString(R.string.chara)); decreaseButton.setGravity(Gravity.CENTER); decreaseButton.setTextSize(14); decreaseButton.setId(5000); RoundRectShape drs = new RoundRectShape( new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null, null); SkyDrawable drd = new SkyDrawable(drs, innerBoxColor, inlineColor, 1); decreaseButton.setBackgroundDrawable(drd); decreaseButton.setOnClickListener(listener); decreaseButton.setOnTouchListener(new ButtonHighlighterOnTouchListener(decreaseButton)); contentLayout.addView(decreaseButton); // inccrease font size Button increaseButton = new Button(this); setFrame(increaseButton, ps(10 + width / 2), ps(FBY), ps(width - 40 - 20) / 2, ps(60)); increaseButton.setText(getString(R.string.chara)); increaseButton.setTextSize(18); increaseButton.setGravity(Gravity.CENTER); increaseButton.setId(5001); RoundRectShape irs = new RoundRectShape( new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null, null); SkyDrawable ird = new SkyDrawable(irs, innerBoxColor, inlineColor, 1); increaseButton.setBackgroundDrawable(ird); increaseButton.setOnClickListener(listener); increaseButton.setOnTouchListener(new ButtonHighlighterOnTouchListener(increaseButton)); contentLayout.addView(increaseButton); // # 3 make the button to increase/decrese line spacing. int LBY = 145; // deccrease line space Button decreaseLineSpaceButton = this.makeImageButton(9005, R.drawable.decline2x, ps(30), ps(30)); setFrame(decreaseLineSpaceButton, ps(20), ps(LBY), ps(width - 40 - 20) / 2, ps(60)); decreaseLineSpaceButton.setId(4000); drs = new RoundRectShape(new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null, null); drd = new SkyDrawable(drs, innerBoxColor, inlineColor, 1); decreaseLineSpaceButton.setBackgroundDrawable(drd); decreaseLineSpaceButton.setOnClickListener(listener); decreaseLineSpaceButton .setOnTouchListener(new ImageButtonHighlighterOnTouchListener(decreaseLineSpaceButton)); contentLayout.addView(decreaseLineSpaceButton); // inccrease line space Button increaseLineSpaceButton = this.makeImageButton(9005, R.drawable.incline2x, ps(30), ps(30)); setFrame(increaseLineSpaceButton, ps(10 + width / 2), ps(LBY), ps(width - 40 - 20) / 2, ps(60)); increaseLineSpaceButton.setId(4001); irs = new RoundRectShape(new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null, null); ird = new SkyDrawable(irs, innerBoxColor, inlineColor, 1); increaseLineSpaceButton.setBackgroundDrawable(ird); increaseLineSpaceButton.setOnClickListener(listener); increaseLineSpaceButton .setOnTouchListener(new ImageButtonHighlighterOnTouchListener(increaseLineSpaceButton)); contentLayout.addView(increaseLineSpaceButton); // #4 make themes selector. int TY = 220; int TH = 70; int TW = (width - 40 - 20) / 3; HorizontalScrollView themeScrollView = new HorizontalScrollView(this); themesView = new LinearLayout(this); themesView.setOrientation(LinearLayout.HORIZONTAL); themeScrollView.addView(themesView, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); for (int i = 0; i < this.themes.size(); i++) { Theme theme = themes.get(i); Button themeButton = new Button(this); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ps(TW), ps(TH)); layoutParams.setMargins(0, 0, 24, 0); themesView.addView(themeButton, layoutParams); RoundRectShape rs = new RoundRectShape( new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null, null); SkyDrawable brd = new SkyDrawable(rs, theme.backgroundColor, Color.BLACK, 1); themeButton.setBackgroundDrawable(brd); themeButton.setText(theme.name); themeButton.setTextColor(theme.foregroundColor); themeButton.setId(7000 + i); themeButton.setOnClickListener(listener); } this.setFrame(themeScrollView, ps(20), ps(TY), ps(width - 40), ps(90)); contentLayout.addView(themeScrollView); // #5 font list box int SY = 310; int fontButtonHeight = 80; int fontListHeight; fontListHeight = fontButtonHeight * fonts.size(); fontListView = new LinearLayout(this); fontListView.setOrientation(LinearLayout.VERTICAL); contentLayout.addView(fontListView); this.setFrame(fontListView, ps(20), ps(SY), ps(width - 40), ps(fontListHeight)); int inlineColor2 = Color.argb(140, 133, 105, 75); for (int i = 0; i < fonts.size(); i++) { CustomFont customFont = fonts.get(i); Button fontButton = new Button(this); fontButton.setText(customFont.fontFaceName); fontButton.setTextSize(20); Typeface tf = null; if (customFont.fontFileName == null || customFont.fontFileName.isEmpty()) { tf = this.getTypeface(customFont.fontFaceName, Typeface.BOLD); } else { tf = Typeface.createFromAsset(getAssets(), "fonts/" + customFont.fontFileName); } if (tf != null) fontButton.setTypeface(tf); fontButton.setId(5100 + i); RoundRectShape rs = new RoundRectShape( new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null, null); SkyDrawable brd = new SkyDrawable(rs, innerBoxColor, inlineColor2, 1); fontButton.setBackgroundDrawable(brd); this.setFrame(fontButton, ps(0), ps(0), ps(width - 40), ps(fontButtonHeight)); fontListView.addView(fontButton); fontButton.setOnClickListener(listener); fontButton.setOnTouchListener(new ButtonHighlighterOnTouchListener(fontButton)); } this.ePubView.addView(fontBox); this.hideFontBox(); }
From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardBaseView.java
private void onBufferDraw(Canvas canvas) { if (mKeyboardChanged) { invalidateAllKeys();/*w w w .j a va2 s . co m*/ mKeyboardChanged = false; } canvas.getClipBounds(mDirtyRect); if (mKeyboard == null) return; final boolean drawKeyboardNameText = (mKeyboardNameTextSize > 1f) && AnyApplication.getConfig().getShowKeyboardNameText(); final boolean drawHintText = (mHintTextSize > 1) && AnyApplication.getConfig().getShowHintTextOnKeys(); // TODO: calls to AnyApplication.getConfig().getXXXXX() functions are // not yet implemented, // but need to when allowing preferences to override theme settings of // these values // right now just using what should be the default values for these // unimplemented preferences final boolean useCustomKeyTextColor = false; // TODO: final boolean useCustomKeyTextColor = // AnyApplication.getConfig().getUseCustomTextColorOnKeys(); final ColorStateList keyTextColor = useCustomKeyTextColor ? new ColorStateList(new int[][] { { 0 } }, new int[] { 0xFF6666FF }) : mKeyTextColor; // TODO: ? AnyApplication.getConfig().getCustomKeyTextColorOnKeys() : // mKeyTextColor; final boolean useCustomHintColor = drawHintText && false; // TODO: final boolean useCustomHintColor = drawHintText && // AnyApplication.getConfig().getUseCustomHintColorOnKeys(); final ColorStateList hintColor = useCustomHintColor ? new ColorStateList(new int[][] { { 0 } }, new int[] { 0xFFFF6666 }) : mHintTextColor; // TODO: ? AnyApplication.getConfig().getCustomHintColorOnKeys() : // mHintTextColor; // allow preferences to override theme settings for hint text position final boolean useCustomHintAlign = drawHintText && AnyApplication.getConfig().getUseCustomHintAlign(); final int hintAlign = useCustomHintAlign ? AnyApplication.getConfig().getCustomHintAlign() : mHintLabelAlign; final int hintVAlign = useCustomHintAlign ? AnyApplication.getConfig().getCustomHintVAlign() : mHintLabelVAlign; final Paint paint = mPaint; final Drawable keyBackground = mKeyBackground; final Rect clipRegion = mClipRegion; final int kbdPaddingLeft = getPaddingLeft(); final int kbdPaddingTop = getPaddingTop(); final Key[] keys = mKeys; final Key invalidKey = mInvalidatedKey; boolean drawSingleKey = false; if (invalidKey != null && canvas.getClipBounds(clipRegion)) { // TODO we should use Rect.inset and Rect.contains here. // Is clipRegion completely contained within the invalidated key? if (invalidKey.x + kbdPaddingLeft - 1 <= clipRegion.left && invalidKey.y + kbdPaddingTop - 1 <= clipRegion.top && invalidKey.x + invalidKey.width + kbdPaddingLeft + 1 >= clipRegion.right && invalidKey.y + invalidKey.height + kbdPaddingTop + 1 >= clipRegion.bottom) { drawSingleKey = true; } } final int keyCount = keys.length; for (int i = 0; i < keyCount; i++) { final AnyKey key = (AnyKey) keys[i]; final boolean keyIsSpace = isSpaceKey(key); if (drawSingleKey && (invalidKey != key)) { continue; } if (!mDirtyRect.intersects(key.x + kbdPaddingLeft, key.y + kbdPaddingTop, key.x + key.width + kbdPaddingLeft, key.y + key.height + kbdPaddingTop)) { continue; } int[] drawableState = key.getCurrentDrawableState(mDrawableStatesProvider); if (keyIsSpace) paint.setColor(mKeyboardNameTextColor.getColorForState(drawableState, 0xFF000000)); else paint.setColor(keyTextColor.getColorForState(drawableState, 0xFF000000)); keyBackground.setState(drawableState); // Switch the character to uppercase if shift is pressed CharSequence label = key.label == null ? null : adjustCase(key).toString(); final Rect bounds = keyBackground.getBounds(); if ((key.width != bounds.right) || (key.height != bounds.bottom)) { keyBackground.setBounds(0, 0, key.width, key.height); } canvas.translate(key.x + kbdPaddingLeft, key.y + kbdPaddingTop); keyBackground.draw(canvas); if (TextUtils.isEmpty(label)) { Drawable iconToDraw = getIconToDrawForKey(key, false); if (iconToDraw != null/* && shouldDrawIcon */) { //http://developer.android.com/reference/android/graphics/drawable/Drawable.html#getCurrent() //http://stackoverflow.com/a/103600/1324235 final boolean is9Patch = iconToDraw.getCurrent() instanceof NinePatchDrawable; // Special handing for the upper-right number hint icons final int drawableWidth; final int drawableHeight; final int drawableX; final int drawableY; drawableWidth = is9Patch ? key.width : iconToDraw.getIntrinsicWidth(); drawableHeight = is9Patch ? key.height : iconToDraw.getIntrinsicHeight(); drawableX = (key.width + mKeyBackgroundPadding.left - mKeyBackgroundPadding.right - drawableWidth) / 2; drawableY = (key.height + mKeyBackgroundPadding.top - mKeyBackgroundPadding.bottom - drawableHeight) / 2; canvas.translate(drawableX, drawableY); iconToDraw.setBounds(0, 0, drawableWidth, drawableHeight); iconToDraw.draw(canvas); canvas.translate(-drawableX, -drawableY); if (keyIsSpace && drawKeyboardNameText) { // now a little hack, I'll set the label now, so it get // drawn. label = mKeyboardName; } } else { // ho... no icon. // I'll try to guess the text label = guessLabelForKey(key.codes[0]); if (TextUtils.isEmpty(label)) { Log.w(TAG, "That's unfortunate, for key " + key.codes[0] + " at (" + key.x + ", " + key.y + ") there is no icon nor label. Action ID is " + mKeyboardActionType); } } } if (label != null) { // For characters, use large font. For labels like "Done", use // small font. final FontMetrics fm; if (keyIsSpace) { paint.setTextSize(mKeyboardNameTextSize); paint.setTypeface(Typeface.DEFAULT_BOLD); if (mKeyboardNameFM == null) mKeyboardNameFM = paint.getFontMetrics(); fm = mKeyboardNameFM; } else if (label.length() > 1 && key.codes.length < 2) { paint.setTextSize(mLabelTextSize); paint.setTypeface(Typeface.DEFAULT_BOLD); if (mLabelFM == null) mLabelFM = paint.getFontMetrics(); fm = mLabelFM; } else { fm = setPaintToKeyText(paint); } final float labelHeight = -fm.top; // Draw a drop shadow for the text paint.setShadowLayer(mShadowRadius, mShadowOffsetX, mShadowOffsetY, mShadowColor); // (+)This is the trick to get RTL/LTR text correct // no matter what: StaticLayout // this should be in the top left corner of the key float textWidth = paint.measureText(label, 0, label.length()); // I'm going to try something if the key is too small for the // text: // 1) divide the text size by 1.5 // 2) if still too large, divide by 2.5 // 3) show no text if (textWidth > key.width) { Log.d(TAG, "Label '" + label + "' is too large for the key. Reducing by 1.5."); paint.setTextSize(mKeyTextSize / 1.5f); textWidth = paint.measureText(label, 0, label.length()); if (textWidth > key.width) { Log.d(TAG, "Label '" + label + "' is too large for the key. Reducing by 2.5."); paint.setTextSize(mKeyTextSize / 2.5f); textWidth = paint.measureText(label, 0, label.length()); if (textWidth > key.width) { Log.d(TAG, "Label '" + label + "' is too large for the key. Showing no text."); paint.setTextSize(0f); textWidth = paint.measureText(label, 0, label.length()); } } } // the center of the drawable space, which is value used // previously for vertically // positioning the key label final float centerY = mKeyBackgroundPadding.top + ((key.height - mKeyBackgroundPadding.top - mKeyBackgroundPadding.bottom) / (keyIsSpace ? 3 : 2));// the label on the space is a bit higher // the X coordinate for the center of the main label text is // unaffected by the hints final float centerX = mKeyBackgroundPadding.left + (key.width - mKeyBackgroundPadding.left - mKeyBackgroundPadding.right) / 2; final float textX = centerX; final float textY; // Some devices (mostly pre-Honeycomb, have issues with RTL text // drawing. // Of course, there is no issue with a single character :) // so, we'll use the RTL secured drawing (via StaticLayout) for // labels. if (label.length() > 1 && !AnyApplication.getConfig().workaround_alwaysUseDrawText()) { // calculate Y coordinate of top of text based on center // location textY = centerY - ((labelHeight - paint.descent()) / 2); canvas.translate(textX, textY); Log.d(TAG, "Using RTL fix for key draw '" + label + "'"); // RTL fix. But it costs, let do it when in need (more than // 1 character) StaticLayout labelText = new StaticLayout(label, new TextPaint(paint), (int) textWidth, Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); labelText.draw(canvas); } else { // to get Y coordinate of baseline from center of text, // first add half the height (to get to // bottom of text), then subtract the part below the // baseline. Note that fm.top is negative. textY = centerY + ((labelHeight - paint.descent()) / 2); canvas.translate(textX, textY); canvas.drawText(label, 0, label.length(), 0, 0, paint); } canvas.translate(-textX, -textY); // (-) // Turn off drop shadow paint.setShadowLayer(0, 0, 0, 0); } if (drawHintText) { if ((key.popupCharacters != null && key.popupCharacters.length() > 0) || (key.popupResId != 0) || (key.longPressCode != 0)) { Paint.Align oldAlign = paint.getTextAlign(); String hintText = null; if (key.hintLabel != null && key.hintLabel.length() > 0) { hintText = key.hintLabel.toString(); // it is the responsibility of the keyboard layout // designer to ensure that they do // not put too many characters in the hint label... } else if (key.longPressCode != 0) { if (Character.isLetterOrDigit(key.longPressCode)) hintText = Character.toString((char) key.longPressCode); } else if (key.popupCharacters != null) { final String hintString = key.popupCharacters.toString(); final int hintLength = hintString.length(); if (hintLength <= 3) hintText = hintString; } // if hintText is still null, it means it didn't fit one of // the above // cases, so we should provide the hint using the default if (hintText == null) { if (mHintOverflowLabel != null) hintText = mHintOverflowLabel.toString(); else { // theme does not provide a defaultHintLabel // use if hints are above, ... if hints are // below // (to avoid being too close to main label/icon) if (hintVAlign == Gravity.TOP) hintText = ""; else hintText = "..."; } } if (mKeyboard.isShifted()) hintText = hintText.toUpperCase(); // now draw hint paint.setTypeface(Typeface.DEFAULT); paint.setColor(hintColor.getColorForState(drawableState, 0xFF000000)); paint.setTextSize(mHintTextSize); // get the hint text font metrics so that we know the size // of the hint when // we try to position the main label (to try to make sure // they don't overlap) if (mHintTextFM == null) { mHintTextFM = paint.getFontMetrics(); } final float hintX; final float hintY; // the (float) 0.5 value is added or subtracted to just give // a little more room // in case the theme designer didn't account for the hint // label location if (hintAlign == Gravity.LEFT) { // left paint.setTextAlign(Paint.Align.LEFT); hintX = mKeyBackgroundPadding.left + (float) 0.5; } else if (hintAlign == Gravity.CENTER) { // center paint.setTextAlign(Paint.Align.CENTER); hintX = mKeyBackgroundPadding.left + (key.width - mKeyBackgroundPadding.left - mKeyBackgroundPadding.right) / 2; } else { // right paint.setTextAlign(Paint.Align.RIGHT); hintX = key.width - mKeyBackgroundPadding.right - (float) 0.5; } if (hintVAlign == Gravity.TOP) { // above hintY = mKeyBackgroundPadding.top - mHintTextFM.top + (float) 0.5; } else { // below hintY = key.height - mKeyBackgroundPadding.bottom - mHintTextFM.bottom - (float) 0.5; } canvas.drawText(hintText, hintX, hintY, paint); paint.setTextAlign(oldAlign); } } canvas.translate(-key.x - kbdPaddingLeft, -key.y - kbdPaddingTop); } mInvalidatedKey = null; // Overlay a dark rectangle to dim the keyboard if (mMiniKeyboard != null && mMiniKeyboardVisible) { paint.setColor((int) (mBackgroundDimAmount * 0xFF) << 24); canvas.drawRect(0, 0, getWidth(), getHeight(), paint); } if (FeaturesSet.DEBUG_LOG) { if (mShowTouchPoints) { for (PointerTracker tracker : mPointerTrackers) { int startX = tracker.getStartX(); int startY = tracker.getStartY(); int lastX = tracker.getLastX(); int lastY = tracker.getLastY(); paint.setAlpha(128); paint.setColor(0xFFFF0000); canvas.drawCircle(startX, startY, 3, paint); canvas.drawLine(startX, startY, lastX, lastY, paint); paint.setColor(0xFF0000FF); canvas.drawCircle(lastX, lastY, 3, paint); paint.setColor(0xFF00FF00); canvas.drawCircle((startX + lastX) / 2, (startY + lastY) / 2, 2, paint); } } } mDrawPending = false; mDirtyRect.setEmpty(); }
From source file:com.mdlive.sav.MDLiveProviderDetails.java
private void setHorizontalScrollviewTimeslots(LinearLayout layout, String str_timeslot, int position, String physId) {/*from www . ja va 2 s. c om*/ final int density = (int) getBaseContext().getResources().getDisplayMetrics().density; final Button myText = new Button(MDLiveProviderDetails.this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { myText.setElevation(0f); } horizontalscrollview.setContentDescription("Horizontal ScrollView"); myText.setTextColor(Color.GRAY); myText.setTextSize(16); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); params.setMargins(4 * density, 4 * density, 4 * density, 4 * density); myText.setLayoutParams(params); myText.setGravity(Gravity.CENTER); myText.setBackgroundResource(R.drawable.timeslot_white_rounded_corner); myText.setClickable(true); myText.setTag(timeSlotListMap.get(position).get("appointment_type")); myText.setPadding(8 * density, 4 * density, 8 * density, 4 * density); myText.setText(TimeZoneUtils.getTimeFromTimestamp(str_timeslot, this)); layout.addView(myText); if (str_appointmenttype.equalsIgnoreCase("video") || str_appointmenttype.equalsIgnoreCase("video or phone") && str_timeslot != null && !str_timeslot.equals("0")) { videoList.add(myText); } if (str_appointmenttype.equalsIgnoreCase("phone") || str_appointmenttype.equalsIgnoreCase("video or phone") && str_timeslot != null && !str_timeslot.equals("0")) { phoneList.add(myText); } clickForVideoOrPhoneTapReqFutureAction(); clickEventForHorizontalText(myText, str_timeslot, physId); }
From source file:com.kll.collect.android.activities.FormEntryActivity.java
/** * Creates a toast with the specified message. * * @param message/*from ww w .j av a2s. co m*/ */ private void showCustomToast(String message, int duration) { LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.toast_view, null); // set the text in the view TextView tv = (TextView) view.findViewById(R.id.message); tv.setText(message); Toast t = new Toast(this); t.setView(view); t.setDuration(duration); t.setGravity(Gravity.CENTER, 0, 0); t.show(); }