Example usage for android.content.res Resources getColor

List of usage examples for android.content.res Resources getColor

Introduction

In this page you can find the example usage for android.content.res Resources getColor.

Prototype

@ColorInt
@Deprecated
public int getColor(@ColorRes int id) throws NotFoundException 

Source Link

Document

Returns a color integer associated with a particular resource ID.

Usage

From source file:com.f16gaming.pathofexilestatistics.PoeEntry.java

public AlertDialog getInfoDialog(Activity activity, Resources res) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    LayoutInflater inflater = activity.getLayoutInflater();
    View view = inflater.inflate(R.layout.info, null);
    String nameFormat = res.getString(R.string.info_name);
    String accountFormat = res.getString(R.string.info_account);
    String rankFormat = res.getString(R.string.info_rank);
    String levelFormat = res.getString(R.string.info_level);
    String classFormat = res.getString(R.string.info_class);
    String experienceFormat = res.getString(R.string.info_experience);
    ((TextView) view.findViewById(R.id.info_name)).setText(String.format(nameFormat, name));
    ((TextView) view.findViewById(R.id.info_account)).setText(String.format(accountFormat, account));
    ((TextView) view.findViewById(R.id.info_rank)).setText(String.format(rankFormat, rank));
    ((TextView) view.findViewById(R.id.info_level)).setText(String.format(levelFormat, level));
    ((TextView) view.findViewById(R.id.info_class)).setText(String.format(classFormat, className));
    ((TextView) view.findViewById(R.id.info_experience)).setText(String.format(experienceFormat, experience));

    TextView status = (TextView) view.findViewById(R.id.info_status);
    status.setText(online ? R.string.online : R.string.offline);
    status.setTextColor(online ? res.getColor(R.color.online) : res.getColor(R.color.offline));

    builder.setTitle(R.string.info_title).setView(view).setPositiveButton(android.R.string.ok,
            new DialogInterface.OnClickListener() {
                @Override//  ww  w.  jav a2s .  c om
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
    return builder.create();
}

From source file:com.rexmtorres.android.patternlock.PatternLockView.java

@SuppressWarnings("deprecation")
public PatternLockView(Context context, AttributeSet attrs) {
    super(context, attrs);

    mContext = getContext();//from   www . j  a v  a 2s  .c  o m

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PatternLockView,
            R.attr.patternLockViewStyle, 0);
    final String aspect = a.getString(R.styleable.PatternLockView_aspect);
    if ("square".equals(aspect)) {
        mAspect = ASPECT_SQUARE;
    } else if ("lock_width".equals(aspect)) {
        mAspect = ASPECT_LOCK_WIDTH;
    } else if ("lock_height".equals(aspect)) {
        mAspect = ASPECT_LOCK_HEIGHT;
    } else {
        mAspect = ASPECT_SQUARE;
    }
    setClickable(true);
    mPathPaint.setAntiAlias(true);
    mPathPaint.setDither(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        mRegularColor = context.getColor(R.color.lock_pattern_view_regular_color);
        mErrorColor = context.getColor(R.color.lock_pattern_view_error_color);
        mSuccessColor = context.getColor(R.color.lock_pattern_view_success_color);
    } else {
        Resources resources = context.getResources();

        mRegularColor = resources.getColor(R.color.lock_pattern_view_regular_color);
        mErrorColor = resources.getColor(R.color.lock_pattern_view_error_color);
        mSuccessColor = resources.getColor(R.color.lock_pattern_view_success_color);
    }

    mRegularColor = a.getColor(R.styleable.PatternLockView_regularColor, mRegularColor);
    mErrorColor = a.getColor(R.styleable.PatternLockView_errorColor, mErrorColor);
    mSuccessColor = a.getColor(R.styleable.PatternLockView_successColor, mSuccessColor);

    int pathColor = a.getColor(R.styleable.PatternLockView_pathColor, mRegularColor);

    // [START rexmtorres 20160401] If set, replaces the pattern dots with the specified bitmap.
    Drawable oDotDrawable = a.getDrawable(R.styleable.PatternLockView_dotBitmap);

    if (oDotDrawable != null) {
        if (oDotDrawable instanceof BitmapDrawable) {
            m_oDotBitmap = ((BitmapDrawable) oDotDrawable).getBitmap();
            m_oBigDotBitmap = Bitmap.createScaledBitmap(m_oDotBitmap, (int) (m_oDotBitmap.getWidth() * 1.25),
                    (int) (m_oDotBitmap.getHeight() * 1.25), false);
        }
    }
    // [END rexmtorres 20160401]

    a.recycle();

    mPathPaint.setColor(pathColor);
    mPathPaint.setStyle(Paint.Style.STROKE);
    mPathPaint.setStrokeJoin(Paint.Join.ROUND);
    mPathPaint.setStrokeCap(Paint.Cap.ROUND);
    mPathWidth = getResources().getDimensionPixelSize(R.dimen.lock_pattern_dot_line_width);
    mPathPaint.setStrokeWidth(mPathWidth);
    mDotSize = getResources().getDimensionPixelSize(R.dimen.lock_pattern_dot_size);
    mDotSizeActivated = getResources().getDimensionPixelSize(R.dimen.lock_pattern_dot_size_activated);
    mPaint.setAntiAlias(true);
    mPaint.setDither(true);
    mCellStates = new CellState[3][3];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            mCellStates[i][j] = new CellState();
            mCellStates[i][j].radius = mDotSize / 2;
            mCellStates[i][j].row = i;
            mCellStates[i][j].col = j;
            mCellStates[i][j].bitmapDot = m_oDotBitmap;
        }
    }

    mFastOutSlowInInterpolator = new FastOutSlowInInterpolator();
    mLinearOutSlowInInterpolator = new LinearOutSlowInInterpolator();
    mExploreByTouchHelper = new PatternExploreByTouchHelper(this);
    ViewCompat.setAccessibilityDelegate(this, mExploreByTouchHelper);
    mAccessibilityManager = (AccessibilityManager) mContext.getSystemService(Context.ACCESSIBILITY_SERVICE);
    mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
}

From source file:com.android.launcher3.allapps.AllAppsGridAdapter.java

public AllAppsGridAdapter(Launcher launcher, AlphabeticalAppsList apps, View.OnTouchListener touchListener,
        View.OnClickListener iconClickListener, View.OnLongClickListener iconLongClickListener) {
    Resources res = launcher.getResources();
    mLauncher = launcher;//w w w.  ja v  a2 s.c o  m
    mApps = apps;
    mEmptySearchMessage = res.getString(R.string.all_apps_loading_message);
    mGridSizer = new GridSpanSizer();
    mGridLayoutMgr = new AppsGridLayoutManager(launcher);
    mGridLayoutMgr.setSpanSizeLookup(mGridSizer);
    mItemDecoration = new GridItemDecoration();
    mLayoutInflater = LayoutInflater.from(launcher);
    mTouchListener = touchListener;
    mIconClickListener = iconClickListener;
    mIconLongClickListener = iconLongClickListener;
    mSectionNamesMargin = res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin);
    mSectionHeaderOffset = res.getDimensionPixelSize(R.dimen.all_apps_grid_section_y_offset);
    mIsRtl = Utilities.isRtl(res);

    mSectionTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mSectionTextPaint.setTextSize(res.getDimensionPixelSize(R.dimen.all_apps_grid_section_text_size));
    mSectionTextPaint.setColor(res.getColor(R.color.all_apps_grid_section_text_color));

    mPredictedAppsDividerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPredictedAppsDividerPaint.setStrokeWidth(Utilities.pxFromDp(1f, res.getDisplayMetrics()));
    mPredictedAppsDividerPaint.setColor(0x1E000000);
    mPredictionBarDividerOffset = (-res.getDimensionPixelSize(R.dimen.all_apps_prediction_icon_bottom_padding)
            + res.getDimensionPixelSize(R.dimen.all_apps_icon_top_bottom_padding)) / 2;
}

From source file:com.wanikani.androidnotifier.WebReviewActivity.java

/**
 * Called when the action is initially displayed. It initializes the objects
 * and starts loading the review page./*w  w w.j a v  a  2s . com*/
 *    @param bundle the saved bundle
 */
@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);

    Resources res;

    CookieSyncManager.createInstance(this);
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    mh = new MenuHandler(this, new MenuListener());

    if (SettingsActivity.getFullscreen(this)) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
    }

    setContentView(R.layout.web_review);

    res = getResources();

    selectedColor = res.getColor(R.color.selected);
    unselectedColor = res.getColor(R.color.unselected);

    muteDrawable = res.getDrawable(R.drawable.ic_mute);
    notMutedDrawable = res.getDrawable(R.drawable.ic_not_muted);

    kbstatus = KeyboardStatus.INVISIBLE;

    bar = (ProgressBar) findViewById(R.id.pb_reviews);
    dbar = (ProgressBar) findViewById(R.id.pb_download);

    ignbtn = (ImageButton) findViewById(R.id.btn_ignore);
    ignbtn.setOnClickListener(new IgnoreButtonListener());

    /* First of all get references to views we'll need in the near future */
    splashView = findViewById(R.id.wv_splash);
    contentView = findViewById(R.id.wv_content);
    msgw = (TextView) findViewById(R.id.tv_message);
    wv = (FocusWebView) findViewById(R.id.wv_reviews);

    wv.getSettings().setJavaScriptEnabled(true);
    wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    wv.getSettings().setSupportMultipleWindows(false);
    wv.getSettings().setUseWideViewPort(false);
    wv.getSettings().setDatabaseEnabled(true);
    wv.getSettings().setDomStorageEnabled(true);
    wv.getSettings().setDatabasePath(getFilesDir().getPath() + "/wv");
    wv.addJavascriptInterface(new WKNKeyboard(), "wknKeyboard");
    wv.setScrollBarStyle(ScrollView.SCROLLBARS_OUTSIDE_OVERLAY);
    wv.setWebViewClient(new WebViewClientImpl());
    wv.setWebChromeClient(new WebChromeClientImpl());

    download = getIntent().getAction().equals(DOWNLOAD_ACTION);
    if (download) {
        downloadPrefix = getIntent().getStringExtra(EXTRA_DOWNLOAD_PREFIX);
        wv.setDownloadListener(fda = new FileDownloader());
    }

    wv.loadUrl(getIntent().getData().toString());

    nativeKeyboard = new NativeKeyboard(this, wv);
    localIMEKeyboard = new LocalIMEKeyboard(this, wv);

    muteH = (ImageButton) findViewById(R.id.kb_mute_h);
    muteH.setOnClickListener(new MuteListener());

    singleb = (Button) findViewById(R.id.kb_single);
    singleb.setOnClickListener(new SingleListener());

    if (SettingsActivity.getTimerReaper(this)) {
        reaper = new TimerThreadsReaper();
        rtask = reaper.createTask(new Handler(), 2, 7000);
        rtask.setListener(new ReaperTaskListener());
    }
}

From source file:com.mikecorrigan.trainscorekeeper.Players.java

@SuppressLint("NewApi")
public Players(final Activity context, ViewGroup viewGroup, final JSONArray jsonPlayers) {
    Log.vc(VERBOSE, TAG,//ww w . j  a v a  2  s .co m
            "ctor: context=" + context + ", viewGroup=" + viewGroup + ", jsonPlayers=" + jsonPlayers);

    viewGroup.removeAllViews();

    Resources resources = context.getResources();

    String[] playerNames = resources.getStringArray(R.array.playerNames);

    TypedArray drawablesArray = resources.obtainTypedArray(R.array.playerDrawables);

    TypedArray colorIdsArray = resources.obtainTypedArray(R.array.playerTextColors);
    int[] colorIds = new int[colorIdsArray.length()];
    for (int i = 0; i < colorIdsArray.length(); i++) {
        colorIds[i] = colorIdsArray.getResourceId(i, -1);
    }

    listeners = new HashSet<Listener>();
    players = new SparseArray<Player>();

    for (int i = 0; i < playerNames.length; i++) {
        PlayerButton toggleButton = new PlayerButton(context);
        toggleButton.setPlayerId(i);
        LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT, 1f);
        toggleButton.setLayoutParams(layoutParams);
        Drawable drawable = drawablesArray.getDrawable(i);
        int sdk = android.os.Build.VERSION.SDK_INT;
        if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
            toggleButton.setBackgroundDrawable(drawable);
        } else {
            toggleButton.setBackground(drawable);
        }
        toggleButton.setPadding(10, 10, 10, 10);
        toggleButton.setTextColor(resources.getColor(colorIds[i]));
        toggleButton.setOnClickListener(onSelect);

        viewGroup.addView(toggleButton);

        final String name = playerNames[i];

        boolean enabled = true;

        // If the players configuration is available, determine which players are enabled.
        if (jsonPlayers != null) {
            enabled = false;
            for (int j = 0; j < jsonPlayers.length(); j++) {
                String jsonName = jsonPlayers.optString(j, "");
                if (jsonName.equalsIgnoreCase(name)) {
                    enabled = true;
                    break;
                }
            }
        }

        Player player = new Player(toggleButton, i, name, enabled);
        players.put(i, player);
    }

    setSelection(-1);

    drawablesArray.recycle();
    colorIdsArray.recycle();
}

From source file:com.lite.android.launcher3.allapps.AllAppsGridAdapter.java

public AllAppsGridAdapter(Launcher launcher, AlphabeticalAppsList apps, View.OnTouchListener touchListener,
        View.OnClickListener iconClickListener, View.OnLongClickListener iconLongClickListener) {
    Resources res = launcher.getResources();
    mLauncher = launcher;// w  ww.ja va  2  s  .co  m
    mApps = apps;
    mEmptySearchMessage = res.getString(R.string.all_apps_loading_message);
    mGridSizer = new GridSpanSizer();
    mGridLayoutMgr = new AppsGridLayoutManager(launcher);
    mGridLayoutMgr.setSpanSizeLookup(mGridSizer);
    mItemDecoration = new GridItemDecoration();
    mLayoutInflater = LayoutInflater.from(launcher);
    mTouchListener = touchListener;
    mIconClickListener = iconClickListener;
    mIconLongClickListener = iconLongClickListener;
    mSectionNamesMargin = mSectionStrategy == AllAppsContainerView.SECTION_STRATEGY_GRID
            ? res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin)
            : res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin_with_sections);

    mAllAppsTextColor = mGridTheme == AllAppsContainerView.GRID_THEME_DARK
            ? res.getColor(R.color.quantum_panel_text_color_dark)
            : res.getColor(R.color.quantum_panel_text_color);

    mSectionHeaderOffset = res.getDimensionPixelSize(R.dimen.all_apps_grid_section_y_offset);

    mSectionTextPaint = new Paint();
    mSectionTextPaint.setTextSize(res.getDimensionPixelSize(R.dimen.all_apps_grid_section_text_size));
    int sectionTextColorId = mGridTheme == AllAppsContainerView.GRID_THEME_DARK
            ? R.color.all_apps_grid_section_text_color_dark
            : R.color.all_apps_grid_section_text_color;
    mSectionTextPaint.setColor(res.getColor(sectionTextColorId));
    mSectionTextPaint.setAntiAlias(true);

    mPredictedAppsDividerPaint = new Paint();
    mPredictedAppsDividerPaint.setStrokeWidth(Utilities.pxFromDp(1f, res.getDisplayMetrics()));
    mPredictedAppsDividerPaint.setColor(0x1E000000);
    mPredictedAppsDividerPaint.setAntiAlias(true);
    mPredictionBarDividerOffset = res.getDimensionPixelSize(R.dimen.all_apps_prediction_bar_divider_offset);

    // Resolve the market app handling additional searches
    PackageManager pm = launcher.getPackageManager();
    ResolveInfo marketInfo = pm.resolveActivity(createMarketSearchIntent(""),
            PackageManager.MATCH_DEFAULT_ONLY);
    if (marketInfo != null) {
        mMarketAppName = marketInfo.loadLabel(pm).toString();
    }

    mRemoteFolderManager = launcher.getRemoteFolderManager();
}

From source file:com.jacr.instagramtrendreader.ImageDetails.java

@SuppressWarnings({ "unchecked" })
@Override/*from w  ww.j  a v  a  2s  . co  m*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activitiy_image_details);

    if (getIntent() != null) {
        Bundle b = getIntent().getExtras();
        listThumbnailKeys = (ArrayList<Integer>) b.get(KEY_THUMBNAIL_KEYS);
        listThumbnailData = (ArrayList<List<String>>) b.get(KEY_THUMBNAIL_DATA);
        final int currentKey = b.getInt(KEY_THUMBNAIL_ACTUAL_KEY);

        /* Views */
        ViewPager mPager = (ViewPager) findViewById(R.id.pagerMain);
        CirclePageIndicator mIndicator = (CirclePageIndicator) findViewById(R.id.indicator);

        /* ActionBar */
        Resources r = getResources();
        actionBar = super.getActionBar(true);
        actionBar.setIcon(r.getDrawable(R.drawable.ic_menu_gallery));

        /* Viewpager and Indicator */
        mAdapter = new ViewPagerAdapter<ImageDetailsFragment>(getSupportFragmentManager());

        /*
         * With the name of the image, extract the hash for the Associated
         * data (we don't use listThumbnailKeys for now).
         */
        File[] imageList = Util.readFilesFromFileDirectory(this);
        for (int i = 0; i < imageList.length; i++) {
            int keyIterator = Integer.parseInt(imageList[i].getName());
            String date = Util.nulo2Vacio(getThumbnailDataByKey(keyIterator, FeedReader.THUMBNAIL_DATE));
            String author = Util.nulo2Vacio(getThumbnailDataByKey(keyIterator, FeedReader.THUMBNAIL_AUTHOR));
            String tags = Util.nulo2Vacio(getThumbnailDataByKey(keyIterator, FeedReader.THUMBNAIL_TAGS));
            String urlImage = Util.nulo2Vacio(getThumbnailDataByKey(keyIterator, FeedReader.THUMBNAIL_URL));
            mAdapter.addFragment(ImageDetailsFragment.newInstance(imageList[i], urlImage, date, author, tags));

        }
        mPager.setAdapter(mAdapter);
        mIndicator.setViewPager(mPager);
        mIndicator.setHorizontalScrollBarEnabled(true);
        mIndicator.setHorizontalFadingEdgeEnabled(true);
        mIndicator.setBackgroundColor(r.getColor(R.color.white));
        mIndicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

            @Override
            public void onPageSelected(int arg0) {
                setDataRelationshipViewPager(arg0);
            }

            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {

            }

            @Override
            public void onPageScrollStateChanged(int arg0) {

            }
        });

        // Show image
        int idxKey = listThumbnailKeys.indexOf(currentKey);
        mPager.setCurrentItem(idxKey);
        setDataRelationshipViewPager(idxKey);

    }

}

From source file:com.android.contacts.ShortcutIntentBuilder.java

/**
 * Generates a phone number shortcut icon. Adds an overlay describing the type of the phone
 * number, and if there is a photo also adds the call action icon.
 *//*  w  w  w.j  a  va 2  s . c  om*/
private Bitmap generatePhoneNumberIcon(Drawable photo, int phoneType, String phoneLabel, int actionResId) {
    final Resources r = mContext.getResources();
    final float density = r.getDisplayMetrics().density;

    final Drawable phoneDrawable = r.getDrawableForDensity(actionResId, mIconDensity);
    // These icons have the same height and width so either is fine for the size.
    final Bitmap phoneIcon = BitmapUtil.drawableToBitmap(phoneDrawable, phoneDrawable.getIntrinsicHeight());

    Bitmap icon = generateQuickContactIcon(photo);
    Canvas canvas = new Canvas(icon);

    // Copy in the photo
    Paint photoPaint = new Paint();
    photoPaint.setDither(true);
    photoPaint.setFilterBitmap(true);
    Rect dst = new Rect(0, 0, mIconSize, mIconSize);

    // Create an overlay for the phone number type if we're pre-O. O created shortcuts have the
    // app badge which overlaps the type overlay.
    CharSequence overlay = Phone.getTypeLabel(r, phoneType, phoneLabel);
    if (!BuildCompat.isAtLeastO() && overlay != null) {
        TextPaint textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);
        textPaint.setTextSize(r.getDimension(R.dimen.shortcut_overlay_text_size));
        textPaint.setColor(r.getColor(R.color.textColorIconOverlay));
        textPaint.setShadowLayer(4f, 0, 2f, r.getColor(R.color.textColorIconOverlayShadow));

        final FontMetricsInt fmi = textPaint.getFontMetricsInt();

        // First fill in a darker background around the text to be drawn
        final Paint workPaint = new Paint();
        workPaint.setColor(mOverlayTextBackgroundColor);
        workPaint.setStyle(Paint.Style.FILL);
        final int textPadding = r.getDimensionPixelOffset(R.dimen.shortcut_overlay_text_background_padding);
        final int textBandHeight = (fmi.descent - fmi.ascent) + textPadding * 2;
        dst.set(0, mIconSize - textBandHeight, mIconSize, mIconSize);
        canvas.drawRect(dst, workPaint);

        overlay = TextUtils.ellipsize(overlay, textPaint, mIconSize, TruncateAt.END);
        final float textWidth = textPaint.measureText(overlay, 0, overlay.length());
        canvas.drawText(overlay, 0, overlay.length(), (mIconSize - textWidth) / 2,
                mIconSize - fmi.descent - textPadding, textPaint);
    }

    // Draw the phone action icon as an overlay
    int iconWidth = icon.getWidth();
    if (BuildCompat.isAtLeastO()) {
        // On O we need to calculate where the phone icon goes slightly differently. The whole
        // canvas area is 108dp, a centered circle with a diameter of 66dp is the "safe zone".
        // So we start the drawing the phone icon at
        // 108dp - 21 dp (distance from right edge of safe zone to the edge of the canvas)
        // - 24 dp (size of the phone icon) on the x axis (left)
        // The y axis is simply 21dp for the distance to the safe zone (top).
        // See go/o-icons-eng for more details and a handy picture.
        final int left = (int) (mIconSize - (45 * density));
        final int top = (int) (21 * density);
        canvas.drawBitmap(phoneIcon, left, top, photoPaint);
    } else {
        dst.set(iconWidth - ((int) (20 * density)), -1, iconWidth, ((int) (19 * density)));
        canvas.drawBitmap(phoneIcon, null, dst, photoPaint);
    }

    canvas.setBitmap(null);
    return icon;
}

From source file:com.gdgdevfest.android.apps.devfestbcn.ui.tablet.TracksDropdownFragment.java

private void loadTrack(Cursor cursor, boolean triggerCallback) {
    final int trackColor;
    final Resources res = getResources();

    if (cursor != null) {
        trackColor = cursor.getInt(TracksAdapter.TracksQuery.TRACK_COLOR);

        mTrackId = cursor.getString(TracksAdapter.TracksQuery.TRACK_ID);

        String trackName = cursor.getString(TracksAdapter.TracksQuery.TRACK_NAME);

        mTitle.setText(trackName);// w  ww  .ja v a2  s  .  c o m
        mAbstract.setText(cursor.getString(TracksAdapter.TracksQuery.TRACK_ABSTRACT));

        int iconResId = res.getIdentifier("track_" + ParserUtils.sanitizeId(trackName), "drawable",
                getActivity().getPackageName());
        if (iconResId != 0) {
            BitmapDrawable sourceIconDrawable = (BitmapDrawable) res.getDrawable(iconResId);
            Bitmap icon = Bitmap.createBitmap(sourceIconDrawable.getIntrinsicWidth(),
                    sourceIconDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(icon);
            sourceIconDrawable.setBounds(0, 0, icon.getWidth(), icon.getHeight());
            sourceIconDrawable.draw(canvas);
            BitmapDrawable iconDrawable = new BitmapDrawable(res, icon);
            mIcon.setImageDrawable(iconDrawable);
        } else {
            mIcon.setImageDrawable(null);
        }
    } else {
        trackColor = res.getColor(R.color.all_track_color);
        mTrackId = ScheduleContract.Tracks.ALL_TRACK_ID;

        mIcon.setImageDrawable(null);
        switch (mViewType) {
        case VIEW_TYPE_SESSIONS:
            mTitle.setText(R.string.all_tracks_sessions);
            mAbstract.setText(R.string.all_tracks_subtitle_sessions);
            break;
        case VIEW_TYPE_SANDBOX:
            mTitle.setText(R.string.all_tracks_sandbox);
            mAbstract.setText(R.string.all_tracks_subtitle_sandbox);
            break;
        }
    }

    mRootView.setBackgroundColor(trackColor);
    mCallbacks.onTrackNameAvailable(mTrackId, mTitle.getText().toString());

    if (triggerCallback) {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                mCallbacks.onTrackSelected(mTrackId);
            }
        });
    }
}

From source file:com.conferenceengineer.android.iosched.ui.tablet.TracksDropdownFragment.java

private void loadTrack(Cursor cursor, boolean triggerCallback) {
    final int trackColor;
    final Resources res = getResources();

    if (cursor != null) {
        trackColor = cursor.getInt(TracksAdapter.TracksQuery.TRACK_COLOR);

        mTrackId = cursor.getString(TracksAdapter.TracksQuery.TRACK_ID);

        String trackName = cursor.getString(TracksAdapter.TracksQuery.TRACK_NAME);

        mTitle.setText(trackName);/*w  w w  .  j  av a2 s.com*/
        mAbstract.setText(cursor.getString(TracksAdapter.TracksQuery.TRACK_ABSTRACT));

        int iconResId = res.getIdentifier("track_" + ParserUtils.sanitizeId(trackName), "drawable",
                getActivity().getPackageName());
        if (iconResId != 0) {
            BitmapDrawable sourceIconDrawable = (BitmapDrawable) res.getDrawable(iconResId);
            Bitmap icon = Bitmap.createBitmap(sourceIconDrawable.getIntrinsicWidth(),
                    sourceIconDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(icon);
            sourceIconDrawable.setBounds(0, 0, icon.getWidth(), icon.getHeight());
            sourceIconDrawable.draw(canvas);
            BitmapDrawable iconDrawable = new BitmapDrawable(res, icon);
            mIcon.setImageDrawable(iconDrawable);
        } else {
            mIcon.setImageDrawable(null);
        }
    } else {
        trackColor = res.getColor(R.color.all_track_color);
        mTrackId = ScheduleContract.Tracks.ALL_TRACK_ID;

        mIcon.setImageDrawable(null);
        switch (mViewType) {
        case VIEW_TYPE_SESSIONS:
            mTitle.setText(R.string.all_tracks_sessions);
            mAbstract.setText(R.string.all_tracks_subtitle_sessions);
            break;
        case VIEW_TYPE_OFFICE_HOURS:
            mTitle.setText(R.string.all_tracks_office_hours);
            mAbstract.setText(R.string.all_tracks_subtitle_office_hours);
            break;
        case VIEW_TYPE_SANDBOX:
            mTitle.setText(R.string.all_tracks_sandbox);
            mAbstract.setText(R.string.all_tracks_subtitle_sandbox);
            break;
        }
    }

    mRootView.setBackgroundColor(trackColor);
    mCallbacks.onTrackNameAvailable(mTrackId, mTitle.getText().toString());

    if (triggerCallback) {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                mCallbacks.onTrackSelected(mTrackId);
            }
        });
    }
}