类android.support.v4.content.res.ResourcesCompat源码实例Demo

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

private void setStateComplete() {
    setMarginBottom( false );
    circle.setBackgroundActive();

    if ( isEditable() )
        circle.setIconEdit();
    else
        circle.setIconCheck();

    title.setTextColor( ResourcesCompat.getColor(
        getResources(),
        R.color.vertical_stepper_view_black_87,
        null ) );
    title.setTypeface( title.getTypeface(), Typeface.BOLD );
    summary.setVisibility( TextUtils.isEmpty( summary.getText() ) ? View.GONE
                    : View.VISIBLE );
    contentWrapper.setVisibility( View.GONE );
}
 
源代码2 项目: vk_music_android   文件: VkAudioAdapter.java
void bind(VKApiAudio audio) {
    binding.getRoot().setOnClickListener(v -> listener.onAudioClicked(audio, getAdapterPosition()));
    binding.audioOptions.setOnClickListener(v -> showPopupMenu(v, audio));
    binding.dragHandle.setOnTouchListener((v, event) -> {
        if (startDragListener == null) {
            return false;
        }
        startDragListener.startDrag(this);
        return true;
    });
    binding.setAudio(audio);
    binding.executePendingBindings();

    if (currentAudio == null || audio.id != currentAudio.id) {
        binding.audioTitle.setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, null, null);
    } else {
        binding.audioTitle.setCompoundDrawablesRelativeWithIntrinsicBounds(
                ResourcesCompat.getDrawable(resources, R.drawable.ic_now_playing_indicator, null),
                null,
                null,
                null
        );
    }
}
 
源代码3 项目: homeassist   文件: ConnectActivity.java
private void showError(String message) {
    Drawable warningIcon = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_warning_white_18dp, null);
    SpannableStringBuilder builder = new SpannableStringBuilder();
    builder.append(message);
    mSnackbar = Snackbar.make(findViewById(android.R.id.content), builder, Snackbar.LENGTH_LONG)
            .setAction(getString(R.string.action_retry), new OnClickListener() {
                @Override
                public void onClick(View view) {
                    attemptLogin();
                }
            });
    TextView textView = mSnackbar.getView().findViewById(android.support.design.R.id.snackbar_text);
    textView.setCompoundDrawablesWithIntrinsicBounds(warningIcon, null, null, null);
    textView.setCompoundDrawablePadding(getResources().getDimensionPixelOffset(R.dimen.icon_8dp));
    mSnackbar.getView().setBackgroundColor(ResourcesCompat.getColor(getResources(), R.color.md_red_A200, null));
    mSnackbar.show();
}
 
源代码4 项目: android-material-stepper   文件: StepperLayout.java
private void setCompoundDrawablesForNavigationButtons(@DrawableRes int backDrawableResId, @DrawableRes int nextDrawableResId) {
    Drawable chevronStartDrawable = backDrawableResId != StepViewModel.NULL_DRAWABLE
            ? ResourcesCompat.getDrawable(getContext().getResources(), backDrawableResId, null)
            : null;
    Drawable chevronEndDrawable = nextDrawableResId != StepViewModel.NULL_DRAWABLE
            ? ResourcesCompat.getDrawable(getContext().getResources(), nextDrawableResId, null)
            : null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        mBackNavigationButton.setCompoundDrawablesRelativeWithIntrinsicBounds(chevronStartDrawable, null, null, null);
    } else {
        mBackNavigationButton.setCompoundDrawablesWithIntrinsicBounds(chevronStartDrawable, null, null, null);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        mNextNavigationButton.setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, chevronEndDrawable, null);
    } else {
        mNextNavigationButton.setCompoundDrawablesWithIntrinsicBounds(null, null, chevronEndDrawable, null);
    }

    TintUtil.tintTextView(mBackNavigationButton, mBackButtonColor);
    TintUtil.tintTextView(mNextNavigationButton, mNextButtonColor);
    TintUtil.tintTextView(mCompleteNavigationButton, mCompleteButtonColor);
}
 
源代码5 项目: android-map-sdk   文件: PolygonOverlayActivity.java
@Override
public void onMapReady(@NonNull NaverMap naverMap) {
    int color = ResourcesCompat.getColor(getResources(), R.color.primary, getTheme());

    PolygonOverlay polygon = new PolygonOverlay();
    polygon.setCoords(COORDS_1);
    polygon.setColor(ColorUtils.setAlphaComponent(color, 31));
    polygon.setOutlineColor(color);
    polygon.setOutlineWidth(getResources().getDimensionPixelSize(R.dimen.overlay_line_width));
    polygon.setMap(naverMap);

    PolygonOverlay polygonWithHole = new PolygonOverlay();
    polygonWithHole.setCoords(COORDS_2);
    polygonWithHole.setHoles(HOLES);
    polygonWithHole.setColor(
        ColorUtils.setAlphaComponent(ResourcesCompat.getColor(getResources(), R.color.gray, getTheme()), 127));
    polygonWithHole.setMap(naverMap);
}
 
源代码6 项目: android-docs-samples   文件: MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final Resources resources = getResources();
    final Resources.Theme theme = getTheme();
    mColorHearing = ResourcesCompat.getColor(resources, R.color.status_hearing, theme);
    mColorNotHearing = ResourcesCompat.getColor(resources, R.color.status_not_hearing, theme);

    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    mStatus = (TextView) findViewById(R.id.status);
    mText = (TextView) findViewById(R.id.text);

    mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    final ArrayList<String> results = savedInstanceState == null ? null :
            savedInstanceState.getStringArrayList(STATE_RESULTS);
    mAdapter = new ResultAdapter(results);
    mRecyclerView.setAdapter(mAdapter);
}
 
源代码7 项目: android-map-sdk   文件: GlobalZIndexActivity.java
@Override
public void onMapReady(@NonNull NaverMap naverMap) {
    PathOverlay pathOverlay = new PathOverlay();
    pathOverlay.setCoords(PATH_COORDS);
    pathOverlay.setWidth(getResources().getDimensionPixelSize(R.dimen.path_overlay_width));
    pathOverlay.setColor(ResourcesCompat.getColor(getResources(), R.color.primary, getTheme()));
    pathOverlay.setOutlineWidth(getResources().getDimensionPixelSize(R.dimen.path_overlay_outline_width));
    pathOverlay.setOutlineColor(Color.WHITE);
    pathOverlay.setMap(naverMap);

    Marker marker1 = new Marker();
    marker1.setPosition(new LatLng(37.5701761, 126.9799315));
    marker1.setCaptionText(getString(R.string.marker_over_path));
    marker1.setMap(naverMap);

    Marker marker2 = new Marker();
    marker2.setPosition(new LatLng(37.5664663, 126.9772952));
    marker2.setIcon(MarkerIcons.BLUE);
    marker2.setCaptionText(getString(R.string.marker_under_path));
    marker2.setGlobalZIndex(PathOverlay.DEFAULT_GLOBAL_Z_INDEX - 1);
    marker2.setMap(naverMap);
}
 
public CharSequence terminateToken(CharSequence text) {

            int i = text.length();

            while (i > 0 && text.charAt(i - 1) == ' ') {
                i--;
            }

            if (i > 0 && text.charAt(i - 1) == ' ') {
                return text;
            } else {
                // Returns colored text for selected token
                SpannableString sp = new SpannableString(String.format(formattedOfString, text));
                int textColor = ResourcesCompat.getColor(getResources(), R.color.colorPrimary, null);
                sp.setSpan(new ForegroundColorSpan(textColor), 0, text.length() + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                return sp;
            }
        }
 
源代码9 项目: candybar-library   文件: DrawableHelper.java
@Nullable
public static Drawable getHighQualityIcon(@NonNull Context context, String packageName) {
    try {
        PackageManager packageManager = context.getPackageManager();
        ApplicationInfo info = packageManager.getApplicationInfo(
                packageName, PackageManager.GET_META_DATA);

        Resources resources = packageManager.getResourcesForApplication(packageName);
        int density = DisplayMetrics.DENSITY_XXHIGH;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            density = DisplayMetrics.DENSITY_XXXHIGH;
        }

        Drawable drawable = ResourcesCompat.getDrawableForDensity(
                resources, info.icon, density, null);
        if (drawable != null) return drawable;
        return info.loadIcon(packageManager);
    } catch (Exception | OutOfMemoryError e) {
        LogUtil.e(Log.getStackTraceString(e));
    }
    return null;
}
 
源代码10 项目: Kandroid   文件: TaskEditActivity.java
private void setButtonColor() {
    if (kanboardColors == null || defaultColor == null)
        return;

    btnColor.setEnabled(true);

    Drawable dot = ResourcesCompat.getDrawable(getResources(), R.drawable.shape_circle, null);
    if (colorId != null && kanboardColors.get(colorId) != null) {  //FIXME: it seems that colorId can have a value that is not in the list. Fallback to defaultColor for now.
        dot.setColorFilter(kanboardColors.get(colorId).getBackground(), PorterDuff.Mode.MULTIPLY);
        btnColor.setText(Utils.fromHtml(getString(R.string.taskedit_color, kanboardColors.get(colorId).getName())));
    } else {
        dot.setColorFilter(kanboardColors.get(defaultColor).getBackground(), PorterDuff.Mode.MULTIPLY);
        btnColor.setText(Utils.fromHtml(getString(R.string.taskedit_color, kanboardColors.get(defaultColor).getName())));
    }
    btnColor.setCompoundDrawablesRelativeWithIntrinsicBounds(dot, null, null, null);
}
 
源代码11 项目: Camera-Roll-Android-App   文件: Util.java
@SuppressWarnings("inlineValue")
public static TextView setToolbarTypeface(Toolbar toolbar) {
    for (int i = 0; i < toolbar.getChildCount(); i++) {
        View view = toolbar.getChildAt(i);
        if (view instanceof TextView) {
            TextView textView = (TextView) view;
            if (textView.getText().equals(toolbar.getTitle())) {
                Typeface typeface = ResourcesCompat
                        .getFont(toolbar.getContext(), R.font.roboto_mono_medium);
                textView.setTypeface(typeface);
                return textView;
            }
        }
    }
    return null;
}
 
源代码12 项目: MapsSDK-Native   文件: MainActivity.java
private MapImage getPinImage() {
    Drawable drawable = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_pin, null);

    int width = drawable.getIntrinsicWidth();
    int height = drawable.getIntrinsicHeight();
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);

    return new MapImage(bitmap);
}
 
源代码13 项目: MapsSDK-Native   文件: MainActivity.java
private MapImage getPinImage() {
    Drawable drawable = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_pin, null);

    int width = drawable.getIntrinsicWidth();
    int height = drawable.getIntrinsicHeight();
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);

    return new MapImage(bitmap);
}
 
源代码14 项目: GNSS_Compare   文件: MapFragment.java
/**
 * Demonstrates converting a {@link Drawable} to a {@link BitmapDescriptor},
 * for use as a marker icon.
 */
private BitmapDescriptor vectorToBitmap(@DrawableRes int id, @ColorInt int color) {
    Drawable vectorDrawable = ResourcesCompat.getDrawable(getResources(), id, null);
    Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(),
            vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    DrawableCompat.setTint(vectorDrawable, color);
    vectorDrawable.draw(canvas);
    return BitmapDescriptorFactory.fromBitmap(bitmap);
}
 
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);

    session =new UserSession(SplashActivity.this);

  Typeface typeface = ResourcesCompat.getFont(this, R.font.blacklist);

  TextView appname= findViewById(R.id.appname);
  appname.setTypeface(typeface);

    YoYo.with(Techniques.Bounce)
            .duration(7000)
            .playOn(findViewById(R.id.logo));

    YoYo.with(Techniques.FadeInUp)
            .duration(5000)
            .playOn(findViewById(R.id.appname));

        new Handler().postDelayed(new Runnable() {

        /*
         * Showing splash screen with a timer. This will be useful when you
         * want to show case your app logo / company
         */

            @Override
            public void run() {
                // This method will be executed once the timer is over
                // Start your app main activity
                startActivity(new Intent(SplashActivity.this,WelcomeActivity.class));
                finish();
            }
        }, SPLASH_TIME_OUT);
    }
 
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Typeface typeface = ResourcesCompat.getFont(this, R.font.blacklist);
    TextView appname = findViewById(R.id.appname);
    appname.setTypeface(typeface);

    //check Internet Connection
    new CheckInternetConnection(this).checkConnection();

    //retrieve session values and display on listviews
    getValues();

    //Navigation Drawer with toolbar
    inflateNavDrawer();

    //ImageSLider
    inflateImageSlider();

    if (session.getFirstTime()) {
        //tap target view
        tapview();
        session.setFirstTime(false);
    }
}
 
源代码17 项目: oversec   文件: OverlayButtonUpgradeView.java
public OverlayButtonUpgradeView(Core core, String packageName) {
    super(core, packageName);

    int myWH = isSmall() ? WH_SMALL_PX : WH_PX;

    mPortraitX = mDisplayWidth / 2 - myWH / 2;
    mPortraitY = mDisplayHeight / 2 - myWH / 2;

    //noinspection SuspiciousNameCombination
    mLandscapeX = mPortraitY;
    //noinspection SuspiciousNameCombination
    mLandscapeY = mPortraitX;


    mView.setImageDrawable(null);
    mView.setBackground(null);

    mView.postDelayed(new Runnable() {
        @Override
        public void run() {
            try {
                mView.setImageResource(R.drawable.ic_shop_black_24dp);
                mView.setBackground(
                        ResourcesCompat.getDrawable(getResources(), R.drawable.fab_bg, getContext().getTheme()));
            } catch (Exception ex) {

            }
        }
    }, IabUtil.getInstance(getContext()).getUpgradeButtonDelay(mView.getContext()));
}
 
ConnectorLineDrawer( Context context ) {
    int grey = ResourcesCompat.getColor(
        context.getResources(),
        R.color.vertical_stepper_view_grey_100,
        null );
    paint.setColor( grey );
}
 
源代码19 项目: SublimeNavigationView   文件: SublimeThemer.java
public Drawable getGroupCollapseDrawable() {
    if (mGroupCollapseDrawable == null) {
        mGroupCollapseDrawable = ResourcesCompat.getDrawable(mContext.getResources(),
                R.drawable.snv_collapse, mContext.getTheme());
    }

    // Return a new drawable since this method will be
    // called multiple times
    return mGroupCollapseDrawable.getConstantState().newDrawable();
}
 
源代码20 项目: AlbumCameraRecorder   文件: CheckRadioView.java
private void init() {
    mSelectedColor = ResourcesCompat.getColor(
            getResources(), R.color.blue_item_checkCircle_backgroundColor,
            getContext().getTheme());
    mUnSelectUdColor = ResourcesCompat.getColor(
            getResources(), R.color.blue_check_original_radio_disable,
            getContext().getTheme());
    setChecked(false);
}
 
源代码21 项目: leanback-showcase   文件: SearchFragment.java
@Override
public void onCreate(Bundle savedInstanceState) {
    AndroidSupportInjection.inject(this);
    super.onCreate(savedInstanceState);
    setBadgeDrawable(ResourcesCompat.getDrawable(getActivity().getResources(),
            R.drawable.ic_add_row_circle_black_24dp, getActivity().getTheme()));

    setTitle("Search Using Live Data");
    setSearchResultProvider(this);
    setOnItemViewClickedListener(viewOnClickListenerMap.get(this.getClass()));
}
 
源代码22 项目: homeassist   文件: LibraryFragment.java
@Override
public void onBindViewHolder(final LibraryViewHolder viewHolder, final int position) {
    final Library library = libraries.get(position);

    viewHolder.mNameView.setText(library.name);

    String subText = library.author;
    if (library.license != null) {
        subText += ", " + library.license;
    }
    viewHolder.mCodeView.setText(subText);

    if (library.website != null) {
        viewHolder.mItemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d("YouQi", "clicked");
                String url = library.website;
                CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
                //builder.setStartAnimations(this, R.anim.right_in, R.anim.left_out);
                //builder.setExitAnimations(this, android.R.anim.slide_in_left, android.R.anim.slide_out_right);
                builder.setToolbarColor(ResourcesCompat.getColor(getResources(), R.color.colorPrimary, null));
                CustomTabsIntent customTabsIntent = builder.build();
                customTabsIntent.launchUrl(getActivity(), Uri.parse(url));
                getActivity().overridePendingTransition(R.anim.stay_still, R.anim.fade_out);
            }
        });
    }
}
 
源代码23 项目: homeassist   文件: EditActivity.java
private Paint getDividerPaint() {
    Paint paint = new Paint();
    paint.setStrokeWidth(1);
    paint.setColor(ResourcesCompat.getColor(getResources(), R.color.colorDivider, null));
    paint.setAntiAlias(true);
    paint.setPathEffect(new DashPathEffect(new float[]{25.0f, 25.0f}, 0));
    return paint;
}
 
源代码24 项目: android-docs-samples   文件: SentimentFragment.java
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Resources resources = getResources();
    final Resources.Theme theme = getActivity().getTheme();
    mColorPositive = ResourcesCompat.getColor(resources, R.color.score_positive, theme);
    mColorNeutral = ResourcesCompat.getColor(resources, R.color.score_neutral, theme);
    mColorNegative = ResourcesCompat.getColor(resources, R.color.score_negative, theme);
}
 
源代码25 项目: homeassist   文件: MainActivity.java
@NonNull
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
    if (convertView == null) {
        convertView = View.inflate(getContext(), android.R.layout.simple_list_item_1, null);
    }

    ((TextView) convertView.findViewById(android.R.id.text1)).setText(items.get(position).getLine(getContext()));
    ((TextView) convertView.findViewById(android.R.id.text1)).setTextColor(ResourcesCompat.getColor(getResources(), R.color.md_white_1000, null));
    return convertView;
}
 
源代码26 项目: badgebutton   文件: MainActivity.java
Drawable wrap(int icon) {
    Drawable drawable = ResourcesCompat.getDrawable(getResources(),icon, getTheme());
    if (mTint == null) {
        mTint = ResourcesCompat.getColorStateList(getResources(), R.color.tab, getTheme());
    }
    if (drawable != null) {
        drawable = DrawableCompat.wrap(drawable.mutate());
        DrawableCompat.setTintList(drawable, mTint);
    }
    return drawable;
}
 
@Override
public void onMapReady(@NonNull NaverMap naverMap) {
    ArrowheadPathOverlay arrowheadPathOverlay = new ArrowheadPathOverlay();
    arrowheadPathOverlay.setCoords(COORDS);
    arrowheadPathOverlay.setWidth(getResources().getDimensionPixelSize(R.dimen.arrowhead_path_overlay_width));
    arrowheadPathOverlay.setColor(Color.WHITE);
    arrowheadPathOverlay.setOutlineWidth(
        getResources().getDimensionPixelSize(R.dimen.arrowhead_path_overlay_outline_width));
    arrowheadPathOverlay.setOutlineColor(ResourcesCompat.getColor(getResources(), R.color.primary, getTheme()));
    arrowheadPathOverlay.setMap(naverMap);
}
 
源代码28 项目: android-map-sdk   文件: CircleOverlayActivity.java
@Override
public void onMapReady(@NonNull NaverMap naverMap) {
    int color = ResourcesCompat.getColor(getResources(), R.color.primary, getTheme());

    CircleOverlay circleOverlay = new CircleOverlay();
    circleOverlay.setCenter(new LatLng(37.5666102, 126.9783881));
    circleOverlay.setRadius(500);
    circleOverlay.setColor(ColorUtils.setAlphaComponent(color, 31));
    circleOverlay.setOutlineColor(color);
    circleOverlay.setOutlineWidth(getResources().getDimensionPixelSize(R.dimen.overlay_line_width));
    circleOverlay.setMap(naverMap);
}
 
/**
*This function will process the incoming text into mention format
* You have to implement the processing logic
* */
public void setMentioningText(String text) {

    map.clear();

    Pattern p = Pattern.compile("\\[([^]]+)]\\(([^ )]+)\\)");
    Matcher m = p.matcher(text);

    String finalDesc = text;

    while (m.find()) {
        MentionPerson mentionPerson = new MentionPerson();
        String name = m.group(1);
        String id = m.group(2);
        //Processing Logic
        finalDesc = finalDesc.replace("@[" + name + "](" + id + ")", "@" + name);

        mentionPerson.name = name;
        mentionPerson.id = id;
        map.put("@" + name, mentionPerson);
    }
    int textColor = ResourcesCompat.getColor(getResources(), R.color.colorPrimary, null);
    Spannable spannable = new SpannableString(finalDesc);
    for (Map.Entry<String, MentionPerson> stringMentionPersonEntry : map.entrySet()) {
        int startIndex = finalDesc.indexOf(stringMentionPersonEntry.getKey());
        int endIndex = startIndex + stringMentionPersonEntry.getKey().length();
                   spannable.setSpan(new ForegroundColorSpan(textColor), startIndex, endIndex , Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    setText(spannable);
}
 
private void init() {

        int textColor = ResourcesCompat.getColor(getResources(), R.color.colorPrimary, null);
        setLinkTextColor(textColor);
        setLinksClickable(true);
        setMovementMethod(LinkMovementMethod.getInstance());
        setFocusable(false);
    }