Example usage for android.support.v4.content.res ResourcesCompat getDrawable

List of usage examples for android.support.v4.content.res ResourcesCompat getDrawable

Introduction

In this page you can find the example usage for android.support.v4.content.res ResourcesCompat getDrawable.

Prototype

public static Drawable getDrawable(Resources resources, int i, Theme theme) throws NotFoundException 

Source Link

Usage

From source file:com.nadmm.airports.utils.UiUtils.java

static public Drawable getTintedDrawable(Context context, int resid, ColorStateList tintList) {
    // Get a mutable copy of the drawable so each can be set to a different color
    String key = String.format(Locale.US, "%d:%d", resid, tintList.getDefaultColor());
    Drawable d = getDrawableFromCache(key);
    if (d == null) {
        d = ResourcesCompat.getDrawable(context.getResources(), resid, null).mutate();
        DrawableCompat.setTintList(d, tintList);
        putDrawableIntoCache(key, d);//  w  w  w . ja  v a 2s .  c o  m
    }
    return d;
}

From source file:com.nttec.everychan.chans.dobrochan.DobroModule.java

@Override
public Drawable getChanFavicon() {
    return ResourcesCompat.getDrawable(resources, R.drawable.favicon_dobrochan, null);
}

From source file:cat.ereza.customactivityoncrash.activity.DefaultErrorReportActivity.java

@SuppressLint("PrivateResource")
@Override/* w  ww  . j  a  va2  s  .  c o m*/
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //This is needed to avoid a crash if the developer has not specified
    //an app-level theme that extends Theme.AppCompat
    TypedArray a = obtainStyledAttributes(R.styleable.AppCompatTheme);
    if (!a.hasValue(R.styleable.AppCompatTheme_windowActionBar)) {
        setTheme(R.style.Theme_AppCompat_Light_DarkActionBar);
    }
    a.recycle();

    setContentView(R.layout.customactivityoncrash_default_error_activity);

    //Close/restart button logic:
    //If a class if set, use restart.
    //Else, use close and just finish the app.
    //It is recommended that you follow this logic if implementing a custom error activity.
    Button restartButton = (Button) findViewById(R.id.customactivityoncrash_error_activity_restart_button);

    final CaocConfig config = CustomActivityOnCrash.getConfigFromIntent(getIntent());

    if (config.isShowRestartButton() && config.getRestartActivityClass() != null) {
        restartButton.setText(R.string.customactivityoncrash_error_activity_restart_app);
        restartButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CustomActivityOnCrash.restartApplication(DefaultErrorReportActivity.this, config);
            }
        });
    } else {
        restartButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CustomActivityOnCrash.closeApplication(DefaultErrorReportActivity.this, config);
            }
        });
    }

    Button moreInfoButton = (Button) findViewById(R.id.customactivityoncrash_error_activity_more_info_button);

    if (config.isShowErrorDetails()) {
        moreInfoButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //We retrieve all the error data and show it

                AlertDialog dialog = new AlertDialog.Builder(DefaultErrorReportActivity.this)
                        .setTitle(R.string.customactivityoncrash_error_activity_error_details_title)
                        .setMessage(CustomActivityOnCrash
                                .getAllErrorDetailsFromIntent(DefaultErrorReportActivity.this, getIntent()))
                        .setPositiveButton(R.string.customactivityoncrash_error_activity_error_details_close,
                                null)
                        .setNeutralButton(R.string.customactivityoncrash_error_activity_error_details_copy,
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        copyErrorToClipboard();
                                        Toast.makeText(DefaultErrorReportActivity.this,
                                                R.string.customactivityoncrash_error_activity_error_details_copied,
                                                Toast.LENGTH_SHORT).show();
                                    }
                                })
                        .show();
                TextView textView = (TextView) dialog.findViewById(android.R.id.message);
                textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources()
                        .getDimension(R.dimen.customactivityoncrash_error_activity_error_details_text_size));
            }
        });
    } else {
        moreInfoButton.setVisibility(View.GONE);
    }

    Integer defaultErrorActivityDrawableId = config.getErrorDrawable();
    ImageView errorImageView = ((ImageView) findViewById(R.id.customactivityoncrash_error_activity_image));

    if (defaultErrorActivityDrawableId != null) {
        errorImageView.setImageDrawable(
                ResourcesCompat.getDrawable(getResources(), defaultErrorActivityDrawableId, getTheme()));
    }
}

From source file:com.nttec.everychan.chans.uchan.UchanModule.java

@Override
public Drawable getChanFavicon() {
    return ResourcesCompat.getDrawable(resources, R.drawable.favicon_uchan, null);
}

From source file:com.nttec.everychan.chans.nullchan.NullchanccModule.java

@Override
public Drawable getChanFavicon() {
    return ResourcesCompat.getDrawable(resources, R.drawable.favicon_0chan, null);
}

From source file:com.nttec.everychan.chans.allchan.AllchanModule.java

@Override
public Drawable getChanFavicon() {
    return ResourcesCompat.getDrawable(resources, R.drawable.favicon_allchan, null);
}

From source file:nya.miku.wishmaster.chans.tumbach.TumbachModule.java

@Override
public Drawable getChanFavicon() {
    return ResourcesCompat.getDrawable(resources, R.drawable.favicon_tumbach, null);
}

From source file:com.apptentive.android.sdk.ApptentiveViewActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Bundle bundle = FragmentFactory.addDisplayModeToFragmentBundle(getIntent().getExtras());
    boolean isInteractionModal = bundle.getBoolean(Constants.FragmentConfigKeys.MODAL);

    ApptentiveBaseFragment newFragment = null;
    if (savedInstanceState != null) {
        // retrieve the retained fragment after orientation change using saved tag
        String savedFragmentTag = savedInstanceState.getString(FRAGMENT_TAG);
        newFragment = (ApptentiveBaseFragment) getSupportFragmentManager().findFragmentByTag(savedFragmentTag);
        /* Since we always store tags of fragments in the ViewPager upon orientation change,
         * failure of retrieval indicate internal error
         *///  w ww .java  2s .  c  om
        if (newFragment == null) {
            finish();
            return;
        }
    }
    try {
        fragmentType = bundle.getInt(Constants.FragmentConfigKeys.TYPE, Constants.FragmentTypes.UNKNOWN);

        if (fragmentType != Constants.FragmentTypes.UNKNOWN) {
            if (fragmentType == Constants.FragmentTypes.INTERACTION
                    || fragmentType == Constants.FragmentTypes.MESSAGE_CENTER_ERROR
                    || fragmentType == Constants.FragmentTypes.ABOUT) {
                bundle.putInt("toolbarLayoutId", R.id.apptentive_toolbar);
                if (newFragment == null) {
                    newFragment = FragmentFactory.createFragmentInstance(bundle);
                    isInteractionModal = newFragment.isShownAsModalDialog();
                }
                if (newFragment != null) {
                    applyApptentiveTheme(isInteractionModal);
                    newFragment.setOnTransitionListener(this);
                }
            }

            if (newFragment == null) {
                if (fragmentType == Constants.FragmentTypes.ENGAGE_INTERNAL_EVENT) {
                    String eventName = getIntent().getStringExtra(Constants.FragmentConfigKeys.EXTRA);
                    if (eventName != null) {
                        EngagementModule.engageInternal(this, eventName);
                    }
                }
                finish();
                return;
            }

        }
    } catch (Exception e) {
        ApptentiveLog.e("Error creating ApptentiveViewActivity.", e);
        MetricModule.sendError(e, null, null);
    }

    setContentView(R.layout.apptentive_viewactivity);

    toolbar = (Toolbar) findViewById(R.id.apptentive_toolbar);
    setSupportActionBar(toolbar);

    /* Add top padding by the amount of Status Bar height to avoid toolbar being covered when
     * status bar is translucent
     */
    toolbar.setPadding(0, getToolbarHeightAdjustment(!isInteractionModal), 0, 0);

    ActionBar actionBar = getSupportActionBar();

    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        int navIconResId = newFragment.getToolbarNavigationIconResourceId(getTheme());
        // Check if fragment may show an alternative navigation icon
        if (navIconResId != 0) {
            /* In order for the alternative icon has the same color used by toolbar icon,
             * need to apply the same color in toolbar theme
             * By default colorControlNormal has same value as textColorPrimary defined in toolbar theme overlay
             */
            final Drawable alternateUpArrow = ResourcesCompat.getDrawable(getResources(), navIconResId,
                    getTheme());

            int colorControlNormal = Util.getThemeColor(
                    ApptentiveInternal.getInstance().getApptentiveToolbarTheme(), R.attr.colorControlNormal);
            alternateUpArrow.setColorFilter(colorControlNormal, PorterDuff.Mode.SRC_ATOP);
            actionBar.setHomeAsUpIndicator(alternateUpArrow);
        }
    }

    //current_tab = extra.getInt(SELECTED_TAB_EXTRA_KEY, 0);
    current_tab = 0;

    addFragmentToAdapter(newFragment, newFragment.getTitle());

    // Get the ViewPager and set it's PagerAdapter so that it can display items
    viewPager = (ViewPager) findViewById(R.id.apptentive_vp);
    viewPager.setAdapter(viewPager_Adapter);

    ViewPager.OnPageChangeListener pageChangeListener = new ViewPager.OnPageChangeListener() {
        Boolean first = true;

        @Override
        public void onPageSelected(int position) {
            final ApptentiveBaseFragment currentFragment = (ApptentiveBaseFragment) viewPager_Adapter
                    .getItem(viewPager.getCurrentItem());
            // Set the Activity title for TalkBack support
            final String title = currentFragment.getTitle();
            if (currentFragment != null && currentFragment.getActivity() != null) {
                currentFragment.getActivity().setTitle(title);
            }
            if (!currentFragment.isShownAsModalDialog()) {
                toolbar.post(new Runnable() {
                    @Override
                    public void run() {
                        toolbar.setVisibility(View.VISIBLE);
                        toolbar.setTitle(title);
                    }
                });
            } else {
                toolbar.setVisibility(View.GONE);
            }
            current_tab = position;
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            if (first && positionOffset == 0 && positionOffsetPixels == 0) {
                onPageSelected(current_tab);
                first = false;
            }
        }

        @Override
        public void onPageScrollStateChanged(int pos) {
            // TODO Auto-generated method stub
        }
    };

    viewPager.addOnPageChangeListener(pageChangeListener);

    // Needed to prevent the window from being panned up when the keyboard is opened.
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
}

From source file:com.nttec.everychan.chans.vichan.VichanModule.java

@Override
public Drawable getChanFavicon() {
    return ResourcesCompat.getDrawable(resources, R.drawable.favicon_vichan, null);
}

From source file:com.ahao.preferencelibrary.preference.DialogPreference.java

/**
 * Sets the icon (resource ID) of the dialog. This will be shown on
 * subsequent dialogs.//from  ww  w . jav a2 s.co  m
 *
 * @param dialogIconRes The icon, as a resource ID.
 */
public void setDialogIcon(int dialogIconRes) {
    mDialogIcon = ResourcesCompat.getDrawable(getContext().getResources(), dialogIconRes, null);
}