Java Code Examples for android.util.TypedValue
The following examples show how to use
android.util.TypedValue.
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: toktok-android Author: TokTok File: MessageActivity.java License: GNU General Public License v3.0 | 6 votes |
private void startOverLayFriend() { SlideInContactsLayout overlayContactsLayout = (SlideInContactsLayout) getLayoutInflater().inflate( R.layout.overlay_contacts, null, false); WindowManager.LayoutParams params = new WindowManager.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, PixelFormat.TRANSLUCENT ); getWindowManager().addView(overlayContactsLayout, params); TypedValue tv = new TypedValue(); int actionBarHeight = getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true) ? TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics()) : 0; overlayContactsLayout.start(this, Friend.lorem, actionBarHeight); }
Example #2
Source Project: PersianDateRangePicker Author: bkhezry File: Utils.java License: Apache License 2.0 | 6 votes |
/** * Gets the colorAccent from the current context, if possible/available * * @param context * @return -1 if accent color invalid, otherwise the accent color of the current context */ public static int getAccentColorFromThemeIfAvailable(Context context) { TypedValue typedValue = new TypedValue(); //First, try the android:colorAccent if (Build.VERSION.SDK_INT >= 21) { context.getTheme().resolveAttribute(android.R.attr.colorAccent, typedValue, true); return typedValue.data; } //Next, try colorAccent from support lib int colorAccentResId = context.getResources().getIdentifier("colorAccent", "attr", context.getPackageName()); if (colorAccentResId == 0) { return -1; } if (!context.getTheme().resolveAttribute(colorAccentResId, typedValue, true)) { return -1; } return typedValue.data; }
Example #3
Source Project: Yahala-Messenger Author: wmhameed File: CardFragment.java License: MIT License | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); FrameLayout fl = new FrameLayout(getActivity()); fl.setLayoutParams(params); final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources() .getDisplayMetrics()); TextView v = new TextView(getActivity()); params.setMargins(margin, margin, margin, margin); v.setLayoutParams(params); v.setLayoutParams(params); v.setGravity(Gravity.CENTER); v.setBackgroundResource(R.drawable.background_card); v.setText("CARD " + (position + 1)); fl.addView(v); return fl; }
Example #4
Source Project: revolution-irc Author: MCMrARM File: IRCColorUtils.java License: GNU General Public License v3.0 | 6 votes |
public static void loadColors(Resources.Theme theme, int resId) { TypedArray ta = theme.obtainStyledAttributes(resId, R.styleable.IRCColors); sColorValues = new int[R.styleable.IRCColors.length]; for (int i = 0; i < sColorValues.length; i++) { try { int j = i; TypedValue tv; while ((tv = ta.peekValue(j)) != null && tv.type == TypedValue.TYPE_ATTRIBUTE) j = Arrays.binarySearch(R.styleable.IRCColors, tv.data); sColorValues[i] = ta.getColor(j, Color.RED); } catch (UnsupportedOperationException e) { e.printStackTrace(); sColorValues[i] = Color.RED; } } ta.recycle(); }
Example #5
Source Project: android_9.0.0_r45 Author: lulululbj File: TypedArray.java License: Apache License 2.0 | 6 votes |
/** * Retrieves the styled string value for the attribute at <var>index</var>. * <p> * If the attribute is not a string, this method will attempt to coerce * it to a string. * * @param index Index of attribute to retrieve. * * @return CharSequence holding string data. May be styled. Returns * {@code null} if the attribute is not defined or could not be * coerced to a string. * @throws RuntimeException if the TypedArray has already been recycled. */ public CharSequence getText(@StyleableRes int index) { if (mRecycled) { throw new RuntimeException("Cannot make calls to a recycled instance!"); } index *= STYLE_NUM_ENTRIES; final int[] data = mData; final int type = data[index + STYLE_TYPE]; if (type == TypedValue.TYPE_NULL) { return null; } else if (type == TypedValue.TYPE_STRING) { return loadStringValueAt(index); } final TypedValue v = mValue; if (getValueAt(index, v)) { return v.coerceToString(); } // We already checked for TYPE_NULL. This should never happen. throw new RuntimeException("getText of bad type: 0x" + Integer.toHexString(type)); }
Example #6
Source Project: FancyPlaces Author: gabm File: SlidingTabLayout.java License: GNU General Public License v3.0 | 6 votes |
/** * Create a default view to be used for tabs. This is called if a custom tab view is not set via * {@link #setCustomTabView(int, int)}. */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTypeface(Typeface.DEFAULT_BOLD); textView.setLayoutParams(new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); textView.setAllCaps(true); int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); return textView; }
Example #7
Source Project: android-percent-support-extend Author: hongyangAndroid File: PercentLayoutHelper.java License: Apache License 2.0 | 6 votes |
private void supportTextSize(int widthHint, int heightHint, View view, PercentLayoutInfo info) { //textsize percent support PercentLayoutInfo.PercentVal textSizePercent = info.textSizePercent; if (textSizePercent == null) return; int base = getBaseByModeAndVal(widthHint, heightHint, textSizePercent.basemode); float textSize = (int) (base * textSizePercent.percent); //Button 和 EditText 是TextView的子类 if (view instanceof TextView) { ((TextView) view).setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); } }
Example #8
Source Project: Huochexing12306 Author: SShineTeam File: EditPage.java License: Apache License 2.0 | 6 votes |
private LinearLayout getBodyBottom() { LinearLayout llBottom = new LinearLayout(getContext()); llBottom.setLayoutParams(new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); String platform = String.valueOf(reqData.get("platform")); LinearLayout line = getAtLine(platform); if (line != null) { llBottom.addView(line); } // 字数统计 tvCounter = new TextView(getContext()); tvCounter.setText(String.valueOf(MAX_TEXT_COUNT)); tvCounter.setTextColor(0xffcfcfcf); tvCounter.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); tvCounter.setTypeface(Typeface.DEFAULT_BOLD); LinearLayout.LayoutParams lpCounter = new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lpCounter.gravity = Gravity.CENTER_VERTICAL; tvCounter.setLayoutParams(lpCounter); llBottom.addView(tvCounter); return llBottom; }
Example #9
Source Project: AndroidTint Author: iQuick File: ThemeHelper.java License: Apache License 2.0 | 6 votes |
public static ColorStateList resolveActionTextColorStateList(Context context, @AttrRes int colorAttr, ColorStateList fallback) { TypedArray a = context.getTheme().obtainStyledAttributes(new int[]{colorAttr}); try { final TypedValue value = a.peekValue(0); if (value == null) { return fallback; } if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT && value.type <= TypedValue.TYPE_LAST_COLOR_INT) { return getActionTextStateList(context, value.data); } else { final ColorStateList stateList = a.getColorStateList(0); if (stateList != null) { return stateList; } else { return fallback; } } } finally { a.recycle(); } }
Example #10
Source Project: TelePlus-Android Author: TelePlusDev File: HintDialogCell.java License: GNU General Public License v2.0 | 6 votes |
public HintDialogCell(Context context) { super(context); imageView = new BackupImageView(context); imageView.setRoundRadius(AndroidUtilities.dp(27)); addView(imageView, LayoutHelper.createFrame(54, 54, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 7, 0, 0)); nameTextView = new TextView(context); nameTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText)); nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12); nameTextView.setMaxLines(2); nameTextView.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL); nameTextView.setLines(2); nameTextView.setEllipsize(TextUtils.TruncateAt.END); addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 6, 64, 6, 0)); }
Example #11
Source Project: Telegram Author: DrKLO File: Bulletin.java License: GNU General Public License v2.0 | 6 votes |
public TwoLineLayout(@NonNull Context context) { super(context); final int undoInfoColor = Theme.getColor(Theme.key_undo_infoColor); addView(imageView = new BackupImageView(context), LayoutHelper.createFrameRelatively(29, 29, Gravity.START | Gravity.CENTER_VERTICAL, 12, 12, 12, 12)); final LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.VERTICAL); addView(linearLayout, LayoutHelper.createFrameRelatively(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.START | Gravity.CENTER_VERTICAL, 54, 8, 12, 8)); titleTextView = new TextView(context); titleTextView.setSingleLine(); titleTextView.setTextColor(undoInfoColor); titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); titleTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); linearLayout.addView(titleTextView); subtitleTextView = new TextView(context); subtitleTextView.setMaxLines(2); subtitleTextView.setTextColor(undoInfoColor); subtitleTextView.setTypeface(Typeface.SANS_SERIF); subtitleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13); linearLayout.addView(subtitleTextView); }
Example #12
Source Project: Ecommerce-Morningmist-Android Author: ZonCon File: FragmentAccountCreate.java License: Creative Commons Zero v1.0 Universal | 6 votes |
@Override public void formatUI() { // TODO Auto-generated method stub tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, (int) (MainActivity.TEXT_SIZE_TITLE)); tvEmail.setTextSize(TypedValue.COMPLEX_UNIT_SP, (int) (MainActivity.TEXT_SIZE_TILE)); editEmail.setTextSize(TypedValue.COMPLEX_UNIT_SP, (int) (MainActivity.TEXT_SIZE_TILE)); tvPassword.setTextSize(TypedValue.COMPLEX_UNIT_SP, (int) (MainActivity.TEXT_SIZE_TILE)); tvRepassword.setTextSize(TypedValue.COMPLEX_UNIT_SP, (int) (MainActivity.TEXT_SIZE_TILE)); editPassword.setTextSize(TypedValue.COMPLEX_UNIT_SP, (int) (MainActivity.TEXT_SIZE_TILE)); editRepassword.setTextSize(TypedValue.COMPLEX_UNIT_SP, (int) (MainActivity.TEXT_SIZE_TILE)); butSave.setTextSize(TypedValue.COMPLEX_UNIT_SP, (int) (MainActivity.TEXT_SIZE_TILE)); butSave.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.dark_shadow_background)); butSave.setPadding(MainActivity.SPACING/2, MainActivity.SPACING/2, MainActivity.SPACING/2, MainActivity.SPACING/2); editPassword.setEnabled(false); editPassword.setBackgroundColor(getResources().getColor(R.color.light_gray)); editRepassword.setEnabled(false); editRepassword.setBackgroundColor(getResources().getColor(R.color.light_gray)); }
Example #13
Source Project: zhangshangwuda Author: Consoar File: SearchView.java License: Apache License 2.0 | 6 votes |
/** * For a given suggestion and a given cursor row, get the action message. If * not provided by the specific row/column, also check for a single * definition (for the action key). * * @param c The cursor providing suggestions * @param actionKey The actionkey record being examined * * @return Returns a string, or null if no action key message for this * suggestion */ // TODO private static String getActionKeyMessage(Cursor c, SearchableInfo.ActionKeyInfo actionKey) { // TODO String result = null; // TODO // check first in the cursor data, for a suggestion-specific message // TODO final String column = actionKey.getSuggestActionMsgColumn(); // TODO if (column != null) { // TODO result = SuggestionsAdapter.getColumnString(c, column); // TODO } // TODO // If the cursor didn't give us a message, see if there's a single // TODO // message defined // TODO // for the actionkey (for all suggestions) // TODO if (result == null) { // TODO result = actionKey.getSuggestActionMsg(); // TODO } // TODO return result; // TODO } private int getSearchIconId() { TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(R.attr.searchViewSearchIcon, outValue, true); return outValue.resourceId; }
Example #14
Source Project: android-gif-drawable-eclipse-sample Author: koral-- File: GifTextureView.java License: MIT License | 6 votes |
private static InputSource findSource(final TypedArray textureViewAttributes) { final TypedValue value = new TypedValue(); if (!textureViewAttributes.getValue(R.styleable.GifTextureView_gifSource, value)) { return null; } if (value.resourceId != 0) { final String type = textureViewAttributes.getResources().getResourceTypeName(value.resourceId); if ("drawable".equals(type) || "raw".equals(type)) { return new InputSource.ResourcesSource(textureViewAttributes.getResources(), value.resourceId); } else if (!"string".equals(type)) { throw new IllegalArgumentException("Expected string, drawable or raw resource, type " + type + " " + "cannot be converted to GIF"); } } return new InputSource.AssetSource(textureViewAttributes.getResources().getAssets(), value.string.toString()); }
Example #15
Source Project: FastLib Author: AriesHoo File: WebViewActivity.java License: Apache License 2.0 | 6 votes |
private void showDownDialog(String url) { UIActionSheetDialog actionSheetDialog = new UIActionSheetDialog.ListSheetBuilder(mContext) .addItem(Html.fromHtml(String.format(mFormat, mFilePath))) .setOnItemClickListener((dialog, itemView, i) -> { switch (i) { case 0: downImg(url); break; } }) .setCancel(com.aries.library.fast.R.string.fast_cancel) .setNavigationBarControl(this) .setTextSizeUnit(TypedValue.COMPLEX_UNIT_DIP) .create(); actionSheetDialog.show(); }
Example #16
Source Project: Emoji Author: vanniktech File: Utils.java License: Apache License 2.0 | 6 votes |
@ColorInt static int resolveColor(final Context context, @AttrRes final int resource, @ColorRes final int fallback) { final TypedValue value = new TypedValue(); context.getTheme().resolveAttribute(resource, value, true); final int resolvedColor; if (value.resourceId != 0) { resolvedColor = ContextCompat.getColor(context, value.resourceId); } else { resolvedColor = value.data; } if (resolvedColor != 0) { return resolvedColor; } else { return ContextCompat.getColor(context, fallback); } }
Example #17
Source Project: Tok-Android Author: InsightIM File: SystemBarConfig.java License: GNU General Public License v3.0 | 5 votes |
@TargetApi(14) private int getActionBarHeight(Context context) { int result = 0; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { TypedValue tv = new TypedValue(); context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true); result = TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics()); } return result; }
Example #18
Source Project: ExoMedia Author: brianwernick File: ResourceUtil.java License: Apache License 2.0 | 5 votes |
/** * Resolves the reference to an attribute, returning the root resource id. * * @param context The context to use when determining the root id * @param attr The attribute to resolve * @return The resource id pointing to the de-referenced attribute */ @AnyRes public static int getResolvedResourceId(Context context, @AttrRes int attr) { TypedValue typedValue = new TypedValue(); Resources.Theme theme = context.getTheme(); theme.resolveAttribute(attr, typedValue, true); if (typedValue.type == TypedValue.TYPE_REFERENCE) { return typedValue.data; } return typedValue.resourceId; }
Example #19
Source Project: narrate-android Author: timothymiko File: PreferenceCard.java License: Apache License 2.0 | 5 votes |
protected void init() { setOrientation(LinearLayout.VERTICAL); ViewGroup.LayoutParams lp = getLayoutParams(); if (lp == null) { lp = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); setLayoutParams(lp); } gap = getResources().getDimensionPixelOffset(R.dimen.default_gap); setBackgroundResource(R.drawable.settings_card); setPadding(gap, gap, gap, gap); mTitle = new SwitchPreference(getContext()); mTitle.setId(R.id.settings_title); mTitle.getTextView().setTypeface(null, Typeface.BOLD); mTitle.getTextView().setTextColor(getResources().getColor(R.color.accent)); mTitle.getTextView().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); mTitle.setSwitchVisibility(GONE); mTitle.setOnCheckedChangedListener(this); addView(mTitle); mTitle.setPadding(0, 0, 0, gap); MarginLayoutParams mlp = (MarginLayoutParams) getLayoutParams(); mlp.bottomMargin = gap / 2; requestLayout(); }
Example #20
Source Project: belvedere Author: zendesk File: Utils.java License: Apache License 2.0 | 5 votes |
static int getThemeColor(Context context, int attr){ final TypedValue outValue = new TypedValue(); final Resources.Theme theme = context.getTheme(); final boolean wasResolved = theme.resolveAttribute(attr, outValue, true); if (wasResolved) { return outValue.resourceId == 0 ? outValue.data : ContextCompat.getColor(context, outValue.resourceId); } else { return Color.BLACK; } }
Example #21
Source Project: PhotoViewCropper Author: wangeason File: CropOverlayView.java License: Apache License 2.0 | 5 votes |
private void init(Context context) { DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); mHandleRadius = HandleUtil.getTargetRadius(context); mSnapRadius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, SNAP_RADIUS_DP, displayMetrics); mBorderPaint = PaintUtil.newBorderPaint(context); mGuidelinePaint = PaintUtil.newGuidelinePaint(); mBackgroundPaint = PaintUtil.newBackgroundPaint(context); mCornerPaint = PaintUtil.newCornerPaint(context); // Sets the values for the corner sizes mCornerOffset = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_CORNER_OFFSET_DP, displayMetrics); mCornerExtension = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_CORNER_EXTENSION_DP, displayMetrics); mCornerLength = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_CORNER_LENGTH_DP, displayMetrics); // Sets guidelines to default until specified otherwise mGuidelines = CropImageView.DEFAULT_GUIDELINES; }
Example #22
Source Project: TelePlus-Android Author: TelePlusDev File: BotSwitchCell.java License: GNU General Public License v2.0 | 5 votes |
public BotSwitchCell(Context context) { super(context); textView = new TextView(context); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15); textView.setTextColor(Theme.getColor(Theme.key_chat_botSwitchToInlineText)); textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); textView.setSingleLine(true); textView.setEllipsize(TextUtils.TruncateAt.END); textView.setMaxLines(1); textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT)); addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), 14, 0, 14, 0)); }
Example #23
Source Project: AndroidWallet Author: Cocos-BCX File: StatusBarUtils.java License: GNU General Public License v3.0 | 5 votes |
/** * 获得 ActionBar 的高度 * * @param context * @return */ public static int getActionBarHeight(Context context) { int result = 0; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { TypedValue tv = new TypedValue(); context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true); result = TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics()); } return result; }
Example #24
Source Project: rpicheck Author: eidottermihi File: RunCommandDialog.java License: MIT License | 5 votes |
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { final AlertDialog.Builder builder = new AlertDialog.Builder( getActivity()); this.device = (RaspberryDeviceBean) this.getArguments() .getSerializable("pi"); this.command = (CommandBean) this.getArguments().getSerializable("cmd"); if (this.getArguments().getString("passphrase") != null) { this.passphrase = this.getArguments().getString("passphrase"); } builder.setTitle(getString(R.string.run_cmd_dialog_title, this.command.getName())); // fetching the theme-dependent icon TypedValue icon = new TypedValue(); if (getActivity().getTheme().resolveAttribute(R.attr.ic_dialog_run, icon, true)) { builder.setIcon(icon.resourceId); } builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // just closing the dialog } }); final LayoutInflater inflater = getActivity().getLayoutInflater(); final View view = inflater.inflate(R.layout.dialog_command_run, null); builder.setView(view); consoleOutput = (TextView) view.findViewById(R.id.runCommandOutput); consoleOutput.setMovementMethod(new ScrollingMovementMethod()); if (savedInstanceState != null) { this.didRun = savedInstanceState.getBoolean("didRun", false); } return builder.create(); }
Example #25
Source Project: Android-ObservableScrollView Author: ksoichiro File: UiTestUtils.java License: Apache License 2.0 | 5 votes |
public static void swipeHorizontally(InstrumentationTestCase test, View v, Direction direction) { int[] xy = new int[2]; v.getLocationOnScreen(xy); final int viewWidth = v.getWidth(); final int viewHeight = v.getHeight(); float distanceFromEdge = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, v.getResources().getDisplayMetrics()); float xStart = xy[0] + ((direction == Direction.LEFT) ? (viewWidth - distanceFromEdge) : distanceFromEdge); float xEnd = xy[0] + ((direction == Direction.LEFT) ? distanceFromEdge : (viewWidth - distanceFromEdge)); float y = xy[1] + (viewHeight / 2.0f); TouchUtils.drag(test, xStart, xEnd, y, y, DRAG_STEP_COUNT); }
Example #26
Source Project: AndroidViewUtils Author: Sage42 File: ClickToOpenCloseLayout.java License: Apache License 2.0 | 5 votes |
private void init(final Context context, final AttributeSet attrs) { final TypedArray args = context.obtainStyledAttributes(attrs, R.styleable.clickToOpenClosedLayout); // extract closed height from attribs (or use default) and convert to px final int closedHeight = args.getInt(R.styleable.clickToOpenClosedLayout_closedHeight, ClickToOpenCloseLayout.DEFAULT_HEIGHT_CLOSED_DP); this.mHeightClosed = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, closedHeight, this .getResources().getDisplayMetrics()); // extract max open height from attribs (or use default) and convert to px final int maxHeightOpen = args.getInt(R.styleable.clickToOpenClosedLayout_maxCardHeight, ClickToOpenCloseLayout.DEFAULT_MAX_HEIGHT_OPENED_DP); this.mMaxHeightOpen = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, maxHeightOpen, this .getResources().getDisplayMetrics()); // extra initial close animation duration from attribs this.mInitialAnimationDuration = args.getInt(R.styleable.clickToOpenClosedLayout_initialAnimationDuration, ClickToOpenCloseLayout.DEFAULT_INITIAL_ANIMATION_DURATION); // extra open/close animation duration from attribs this.mAnimationDuration = args.getInt(R.styleable.clickToOpenClosedLayout_animationDuration, ClickToOpenCloseLayout.DEFAULT_ANIMATION_DURATION); args.recycle(); }
Example #27
Source Project: iGap-Android Author: RooyeKhat-Media File: SlidingTabStrip.java License: GNU Affero General Public License v3.0 | 5 votes |
SlidingTabStrip(Context context, AttributeSet attrs) { super(context, attrs); setWillNotDraw(false); final float density = getResources().getDisplayMetrics().density; TypedValue outValue = new TypedValue(); context.getTheme().resolveAttribute(R.attr.colorForeground, outValue, true); final int themeForegroundColor = outValue.data; mDefaultBottomBorderColor = setColorAlpha(themeForegroundColor, DEFAULT_BOTTOM_BORDER_COLOR_ALPHA); mDefaultTabColorizer = new SimpleTabColorizer(); mDefaultTabColorizer.setIndicatorColors(DEFAULT_SELECTED_INDICATOR_COLOR); mDefaultTabColorizer.setDividerColors(setColorAlpha(themeForegroundColor, DEFAULT_DIVIDER_COLOR_ALPHA)); mBottomBorderThickness = (int) (DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS * density); mBottomBorderPaint = new Paint(); mBottomBorderPaint.setColor(mDefaultBottomBorderColor); mSelectedIndicatorThickness = (int) (SELECTED_INDICATOR_THICKNESS_DIPS * density); mSelectedIndicatorPaint = new Paint(); mDividerHeight = DEFAULT_DIVIDER_HEIGHT; mDividerPaint = new Paint(); mDividerPaint.setStrokeWidth((int) (DEFAULT_DIVIDER_THICKNESS_DIPS * density)); }
Example #28
Source Project: TelePlus-Android Author: TelePlusDev File: ThemeCell.java License: GNU General Public License v2.0 | 5 votes |
public ThemeCell(Context context, boolean nightTheme) { super(context); setWillNotDraw(false); isNightTheme = nightTheme; paint = new Paint(Paint.ANTI_ALIAS_FLAG); textView = new TextView(context); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); textView.setLines(1); textView.setMaxLines(1); textView.setSingleLine(true); textView.setPadding(0, 0, 0, AndroidUtilities.dp(1)); textView.setEllipsize(TextUtils.TruncateAt.END); textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL); addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 53 + 48 : 60, 0, LocaleController.isRTL ? 60 : 53 + 48, 0)); checkImage = new ImageView(context); checkImage.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_featuredStickers_addedIcon), PorterDuff.Mode.MULTIPLY)); checkImage.setImageResource(R.drawable.sticker_added); if (!isNightTheme) { addView(checkImage, LayoutHelper.createFrame(19, 14, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.CENTER_VERTICAL, 17 + 38, 0, 17 + 38, 0)); optionsButton = new ImageView(context); optionsButton.setFocusable(false); optionsButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.getColor(Theme.key_stickers_menuSelector))); optionsButton.setImageResource(R.drawable.ic_ab_other); optionsButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_stickers_menu), PorterDuff.Mode.MULTIPLY)); optionsButton.setScaleType(ImageView.ScaleType.CENTER); addView(optionsButton, LayoutHelper.createFrame(48, 48, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.TOP)); } else { addView(checkImage, LayoutHelper.createFrame(19, 14, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.CENTER_VERTICAL, 17, 0, 17, 0)); } }
Example #29
Source Project: FastAccess Author: k0shk0sh File: AppCompatColorPreference.java License: GNU General Public License v3.0 | 5 votes |
private int getColor(int attrId) { TypedValue typedValue = new TypedValue(); Resources.Theme theme = getContext().getTheme(); theme.resolveAttribute(attrId, typedValue, true); TypedArray arr = getContext().obtainStyledAttributes(typedValue.data, new int[]{attrId}); int color = arr.getColor(0, -1); arr.recycle(); return color; }
Example #30
Source Project: BigApp_Discuz_Android Author: BigAppOS File: FollowListPage.java License: Apache License 2.0 | 5 votes |
public PRTHeader(Context context) { super(context); setOrientation(VERTICAL); LinearLayout llInner = new LinearLayout(context); LinearLayout.LayoutParams lpInner = new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lpInner.gravity = Gravity.CENTER_HORIZONTAL; addView(llInner, lpInner); ivArrow = new RotateImageView(context); int resId = getBitmapRes(context, "ssdk_oks_ptr_ptr"); if (resId > 0) { ivArrow.setImageResource(resId); } int dp_32 = dipToPx(context, 32); LayoutParams lpIv = new LayoutParams(dp_32, dp_32); lpIv.gravity = Gravity.CENTER_VERTICAL; llInner.addView(ivArrow, lpIv); pbRefreshing = new ProgressBar(context); llInner.addView(pbRefreshing, lpIv); pbRefreshing.setVisibility(View.GONE); tvHeader = new TextView(getContext()); tvHeader.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); tvHeader.setGravity(Gravity.CENTER); int dp_10 = com.mob.tools.utils.R.dipToPx(getContext(), 10); tvHeader.setPadding(dp_10, dp_10, dp_10, dp_10); tvHeader.setTextColor(0xff000000); LayoutParams lpTv = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lpTv.gravity = Gravity.CENTER_VERTICAL; llInner.addView(tvHeader, lpTv); }