类android.util.TypedValue源码实例Demo

下面列出了怎么用android.util.TypedValue的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: toktok-android   文件: MessageActivity.java
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);
}
 
源代码2 项目: PersianDateRangePicker   文件: Utils.java
/**
 * 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;
}
 
源代码3 项目: Yahala-Messenger   文件: CardFragment.java
@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;
}
 
源代码4 项目: revolution-irc   文件: IRCColorUtils.java
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();
}
 
源代码5 项目: android_9.0.0_r45   文件: TypedArray.java
/**
 * 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));
}
 
源代码6 项目: FancyPlaces   文件: SlidingTabLayout.java
/**
 * 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;
}
 
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);
    }
}
 
源代码8 项目: Huochexing12306   文件: EditPage.java
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;
}
 
源代码9 项目: AndroidTint   文件: ThemeHelper.java
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();
    }
}
 
源代码10 项目: TelePlus-Android   文件: HintDialogCell.java
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));
}
 
源代码11 项目: Telegram   文件: Bulletin.java
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);
}
 
@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));
}
 
源代码13 项目: zhangshangwuda   文件: SearchView.java
/**
 * 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;
}
 
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());
}
 
源代码15 项目: FastLib   文件: WebViewActivity.java
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();
}
 
源代码16 项目: Emoji   文件: Utils.java
@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);
  }
}
 
源代码17 项目: Tok-Android   文件: SystemBarConfig.java
@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;
}
 
源代码18 项目: ExoMedia   文件: ResourceUtil.java
/**
 * 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;
}
 
源代码19 项目: narrate-android   文件: PreferenceCard.java
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();
}
 
源代码20 项目: belvedere   文件: Utils.java
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;
        }
    }
 
源代码21 项目: PhotoViewCropper   文件: CropOverlayView.java
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;
    }
 
源代码22 项目: TelePlus-Android   文件: BotSwitchCell.java
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));
}
 
源代码23 项目: AndroidWallet   文件: StatusBarUtils.java
/**
 * 获得 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;
}
 
源代码24 项目: rpicheck   文件: RunCommandDialog.java
@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();
}
 
源代码25 项目: Android-ObservableScrollView   文件: UiTestUtils.java
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);
}
 
源代码26 项目: AndroidViewUtils   文件: ClickToOpenCloseLayout.java
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();
}
 
源代码27 项目: iGap-Android   文件: SlidingTabStrip.java
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));
}
 
源代码28 项目: TelePlus-Android   文件: ThemeCell.java
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));
    }
}
 
源代码29 项目: FastAccess   文件: AppCompatColorPreference.java
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;
}
 
源代码30 项目: BigApp_Discuz_Android   文件: FollowListPage.java
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);
}
 
 类所在包