Search in sources :

Example 11 with DrawableRes

use of android.support.annotation.DrawableRes in project Pix-Art-Messenger by kriztan.

the class StartConversationActivity method onTabChanged.

private void onTabChanged() {
    @DrawableRes final int fabDrawable;
    if (getSupportActionBar().getSelectedNavigationIndex() == 0) {
        fabDrawable = R.drawable.ic_person_add_white_24dp;
    } else {
        fabDrawable = R.drawable.ic_group_add_white_24dp;
    }
    binding.fab.setImageResource(fabDrawable);
    invalidateOptionsMenu();
}
Also used : DrawableRes(android.support.annotation.DrawableRes) SuppressLint(android.annotation.SuppressLint)

Example 12 with DrawableRes

use of android.support.annotation.DrawableRes in project ForPDA by RadiationX.

the class App method getDrawableResAttr.

@DrawableRes
public static int getDrawableResAttr(Context context, @AttrRes int attr) {
    TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { attr });
    int attributeResourceId = a.getResourceId(0, 0);
    a.recycle();
    return attributeResourceId;
}
Also used : TypedArray(android.content.res.TypedArray) DrawableRes(android.support.annotation.DrawableRes)

Example 13 with DrawableRes

use of android.support.annotation.DrawableRes in project platform_packages_apps_Settings by BlissRoms.

the class DatabaseIndexingManager method indexFromResource.

@VisibleForTesting
void indexFromResource(SQLiteDatabase database, String localeStr, SearchIndexableResource sir, List<String> nonIndexableKeys) {
    final Context context = sir.context;
    XmlResourceParser parser = null;
    try {
        parser = context.getResources().getXml(sir.xmlResId);
        int type;
        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
        // Parse next until start tag is found
        }
        String nodeName = parser.getName();
        if (!NODE_NAME_PREFERENCE_SCREEN.equals(nodeName)) {
            throw new RuntimeException("XML document must start with <PreferenceScreen> tag; found" + nodeName + " at " + parser.getPositionDescription());
        }
        final int outerDepth = parser.getDepth();
        final AttributeSet attrs = Xml.asAttributeSet(parser);
        final String screenTitle = XmlParserUtils.getDataTitle(context, attrs);
        String key = XmlParserUtils.getDataKey(context, attrs);
        String title;
        String headerTitle;
        String summary;
        String headerSummary;
        String keywords;
        String headerKeywords;
        String childFragment;
        @DrawableRes int iconResId;
        ResultPayload payload;
        boolean enabled;
        final String fragmentName = sir.className;
        final int rank = sir.rank;
        final String intentAction = sir.intentAction;
        final String intentTargetPackage = sir.intentTargetPackage;
        final String intentTargetClass = sir.intentTargetClass;
        Map<String, PreferenceControllerMixin> controllerUriMap = null;
        if (fragmentName != null) {
            controllerUriMap = DatabaseIndexingUtils.getPreferenceControllerUriMap(fragmentName, context);
        }
        // Insert rows for the main PreferenceScreen node. Rewrite the data for removing
        // hyphens.
        headerTitle = XmlParserUtils.getDataTitle(context, attrs);
        headerSummary = XmlParserUtils.getDataSummary(context, attrs);
        headerKeywords = XmlParserUtils.getDataKeywords(context, attrs);
        enabled = !nonIndexableKeys.contains(key);
        // TODO: Set payload type for header results
        DatabaseRow.Builder headerBuilder = new DatabaseRow.Builder();
        headerBuilder.setLocale(localeStr).setEntries(null).setClassName(fragmentName).setScreenTitle(screenTitle).setRank(rank).setIntentAction(intentAction).setIntentTargetPackage(intentTargetPackage).setIntentTargetClass(intentTargetClass).setEnabled(enabled).setKey(key).setUserId(-1);
        // Flag for XML headers which a child element's title.
        boolean isHeaderUnique = true;
        DatabaseRow.Builder builder;
        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
                continue;
            }
            nodeName = parser.getName();
            title = XmlParserUtils.getDataTitle(context, attrs);
            key = XmlParserUtils.getDataKey(context, attrs);
            enabled = !nonIndexableKeys.contains(key);
            keywords = XmlParserUtils.getDataKeywords(context, attrs);
            iconResId = XmlParserUtils.getDataIcon(context, attrs);
            if (isHeaderUnique && TextUtils.equals(headerTitle, title)) {
                isHeaderUnique = false;
            }
            builder = new DatabaseRow.Builder();
            builder.setLocale(localeStr).setClassName(fragmentName).setScreenTitle(screenTitle).setIconResId(iconResId).setRank(rank).setIntentAction(intentAction).setIntentTargetPackage(intentTargetPackage).setIntentTargetClass(intentTargetClass).setEnabled(enabled).setKey(key).setUserId(-1);
            if (!nodeName.equals(NODE_NAME_CHECK_BOX_PREFERENCE)) {
                summary = XmlParserUtils.getDataSummary(context, attrs);
                String entries = null;
                if (nodeName.endsWith(NODE_NAME_LIST_PREFERENCE)) {
                    entries = XmlParserUtils.getDataEntries(context, attrs);
                }
                // TODO (b/62254931) index primitives instead of payload
                payload = DatabaseIndexingUtils.getPayloadFromUriMap(controllerUriMap, key);
                childFragment = XmlParserUtils.getDataChildFragment(context, attrs);
                builder.setEntries(entries).setChildClassName(childFragment).setPayload(payload);
                // Insert rows for the child nodes of PreferenceScreen
                updateOneRowWithFilteredData(database, builder, title, summary, null, /* summary off */
                keywords);
            } else {
                String summaryOn = XmlParserUtils.getDataSummaryOn(context, attrs);
                String summaryOff = XmlParserUtils.getDataSummaryOff(context, attrs);
                if (TextUtils.isEmpty(summaryOn) && TextUtils.isEmpty(summaryOff)) {
                    summaryOn = XmlParserUtils.getDataSummary(context, attrs);
                }
                updateOneRowWithFilteredData(database, builder, title, summaryOn, summaryOff, keywords);
            }
        }
        // The xml header's title does not match the title of one of the child settings.
        if (isHeaderUnique) {
            updateOneRowWithFilteredData(database, headerBuilder, headerTitle, headerSummary, null, /* summary off */
            headerKeywords);
        }
    } catch (XmlPullParserException e) {
        throw new RuntimeException("Error parsing PreferenceScreen", e);
    } catch (IOException e) {
        throw new RuntimeException("Error parsing PreferenceScreen", e);
    } finally {
        if (parser != null)
            parser.close();
    }
}
Also used : Context(android.content.Context) XmlResourceParser(android.content.res.XmlResourceParser) DrawableRes(android.support.annotation.DrawableRes) PreferenceControllerMixin(com.android.settings.core.PreferenceControllerMixin) IOException(java.io.IOException) AttributeSet(android.util.AttributeSet) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) VisibleForTesting(android.support.annotation.VisibleForTesting)

Example 14 with DrawableRes

use of android.support.annotation.DrawableRes in project edx-app-android by edx.

the class DownloadEntryAdapter method render.

@Override
public void render(BaseViewHolder tag, final Item item) {
    final ViewHolder holder = (ViewHolder) tag;
    holder.title.setText(item.getTitle());
    if (TextUtils.isEmpty(item.getDuration())) {
        holder.duration.setVisibility(View.GONE);
    } else {
        holder.duration.setVisibility(View.VISIBLE);
        holder.duration.setText(item.getDuration());
    }
    holder.progress.setProgress(item.getPercent());
    @DrawableRes final int progressDrawable;
    final String progressText;
    final String errorText;
    switch(item.getStatus()) {
        case PENDING:
            {
                progressText = getContext().getString(R.string.download_pending);
                progressDrawable = R.drawable.custom_progress_bar_horizontal_success;
                errorText = null;
                break;
            }
        case DOWNLOADING:
            {
                progressText = getByteCountProgressText(item);
                progressDrawable = R.drawable.custom_progress_bar_horizontal_success;
                errorText = null;
                break;
            }
        case FAILED:
            {
                errorText = getContext().getString(R.string.error_download_failed);
                progressDrawable = R.drawable.custom_progress_bar_horizontal_error;
                if (item.getDownloadedByteCount() > 0) {
                    progressText = getByteCountProgressText(item);
                } else {
                    progressText = null;
                }
                break;
            }
        default:
            {
                throw new IllegalArgumentException(item.getStatus().name());
            }
    }
    holder.progress.setProgressDrawable(getContext().getResources().getDrawable(progressDrawable));
    if (null == progressText) {
        holder.percent.setVisibility(View.GONE);
    } else {
        holder.percent.setText(progressText);
        holder.percent.setVisibility(View.VISIBLE);
    }
    if (null == errorText) {
        holder.error.setVisibility(View.GONE);
    } else {
        holder.error.setText(errorText);
        holder.error.setVisibility(View.VISIBLE);
    }
    holder.cross_button.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            onDeleteClicked(item);
        }
    });
}
Also used : DrawableRes(android.support.annotation.DrawableRes) OnClickListener(android.view.View.OnClickListener) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView)

Example 15 with DrawableRes

use of android.support.annotation.DrawableRes in project teamward-client by Neamar.

the class PerformanceActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_performance);
    final Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    assert getSupportActionBar() != null;
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    Game game = (Game) getIntent().getSerializableExtra("game");
    player = (Player) getIntent().getSerializableExtra("player");
    // Doing this in two steps, got some crash reports on the Store and trying to understand
    // what can be Null: player.summoner, or summoner.name.
    Summoner summoner = player.summoner;
    // HERO
    setTitle(summoner.name);
    // CHAMPION MASTERY
    View masteryHolder = findViewById(R.id.masteryHolder);
    ImageView championMasteryImage = (ImageView) findViewById(R.id.championMasteryImage);
    TextView championMasteryText = (TextView) findViewById(R.id.championMasteryText);
    TextView championPointsText = (TextView) findViewById(R.id.championPointsText);
    @DrawableRes int championMasteryResource = CHAMPION_MASTERIES_RESOURCES[player.champion.mastery];
    if (championMasteryResource == 0) {
        masteryHolder.setVisibility(View.GONE);
    } else {
        championMasteryImage.setImageResource(CHAMPION_MASTERIES_RESOURCES[player.champion.mastery]);
        championMasteryText.setText(String.format(getString(R.string.champion_mastery_lvl), player.champion.mastery));
        if (player.champion.mastery >= 5) {
            championPointsText.setText(String.format(getString(R.string.champion_points), NumberFormat.getInstance().format(player.champion.points)));
        } else {
            championPointsText.setVisibility(View.GONE);
        }
        masteryHolder.setVisibility(View.VISIBLE);
    }
    // RANKED INFORMATION
    View rankingHolder = findViewById(R.id.rankingHolder);
    ImageView rankingTierImage = (ImageView) rankingHolder.findViewById(R.id.rankingTierImage);
    TextView rankingText = (TextView) rankingHolder.findViewById(R.id.rankingText);
    TextView rankingQueue = (TextView) rankingHolder.findViewById(R.id.rankingQueue);
    if (player.rank.tier.isEmpty() || !RANKING_TIER_RESOURCES.containsKey(player.rank.tier.toLowerCase(Locale.ROOT))) {
        rankingHolder.setVisibility(View.GONE);
    } else {
        rankingTierImage.setImageResource(RANKING_TIER_RESOURCES.get(player.rank.tier.toLowerCase(Locale.ROOT)));
        rankingText.setText(String.format(getString(R.string.ranking), player.rank.tier.toUpperCase(Locale.ROOT), player.rank.division));
        rankingHolder.setVisibility(View.VISIBLE);
        rankingQueue.setText(getQueueName(player.rank.queue));
    }
    rankingHolder.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            try {
                Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://" + player.region + ".op.gg/summoner/userName=" + URLEncoder.encode(player.summoner.name, "UTF-8")));
                startActivity(browserIntent);
                Tracker.trackClickOnOpGG(PerformanceActivity.this, player);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (ActivityNotFoundException e) {
                Toast.makeText(PerformanceActivity.this, R.string.unable_to_open_browser, Toast.LENGTH_SHORT).show();
                e.printStackTrace();
            }
        }
    });
    // LAST SEASON RANKED INFORMATION
    View lastSeasonRankHolder = findViewById(R.id.lastSeasonRankHolder);
    ImageView lastRankingTierImage = (ImageView) lastSeasonRankHolder.findViewById(R.id.rankingTierImage);
    TextView lastRankingText = (TextView) lastSeasonRankHolder.findViewById(R.id.rankingText);
    // Do not display unranked, null, or any rank similar to current rank
    if (player.rank.oldTier.isEmpty() || player.rank.oldTier.equals(player.rank.tier) || !RANKING_TIER_RESOURCES.containsKey(player.rank.oldTier.toLowerCase(Locale.ROOT))) {
        lastSeasonRankHolder.setVisibility(View.GONE);
    } else {
        lastRankingTierImage.setImageResource(RANKING_TIER_RESOURCES.get(player.rank.oldTier.toLowerCase(Locale.ROOT)));
        lastRankingText.setText(String.format(getString(R.string.ranking_last_season), player.rank.oldTier.toUpperCase(Locale.ROOT)));
        lastSeasonRankHolder.setVisibility(View.VISIBLE);
    }
    // MATCHUP INFORMATION
    View matchupHolder = findViewById(R.id.matchupHolder);
    ImageView ownChampion = (ImageView) findViewById(R.id.ownChampion);
    ImageView enemyChampion = (ImageView) findViewById(R.id.enemyChampion);
    TextView matchupTextView = (TextView) findViewById(R.id.matchupStats);
    final Team playerTeam = game.getTeamForPlayer(player);
    Player oppositePlayer = null;
    if (game.teams.size() > 1) {
        Team otherTeam = game.teams.get(0) == playerTeam ? game.teams.get(1) : game.teams.get(0);
        for (Player tplayer : otherTeam.players) {
            if (player.champion.role.equals(tplayer.champion.role)) {
                oppositePlayer = tplayer;
                break;
            }
        }
    }
    if (playerTeam == null || player.champion.role.equals(ChampionInGame.UNKNOWN_ROLE) || oppositePlayer == null) {
        matchupHolder.setVisibility(View.GONE);
    } else {
        ImageLoader.getInstance().displayImage(player.champion.imageUrl, ownChampion);
        ImageLoader.getInstance().displayImage(oppositePlayer.champion.imageUrl, enemyChampion);
        if (player.champion.winRate >= 0) {
            matchupTextView.setText(String.format(Locale.getDefault(), "%d%%", player.champion.winRate));
            if (player.champion.winRate > 50) {
                matchupTextView.setTextColor(getResources().getColor(R.color.colorGoodMatchup));
            } else if (player.champion.winRate < 50) {
                matchupTextView.setTextColor(getResources().getColor(R.color.colorBadMatchup));
            }
        } else {
            matchupTextView.setText("?");
            matchupTextView.setTextColor(getResources().getColor(R.color.colorUnknownMatchup));
        }
    }
    matchupHolder.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(player.champion.ggUrl));
            try {
                startActivity(browserIntent);
            } catch (ActivityNotFoundException e) {
                Toast.makeText(PerformanceActivity.this, R.string.unable_to_open_browser, Toast.LENGTH_SHORT).show();
            }
            Tracker.trackClickOnGG(PerformanceActivity.this, player.champion.name, player.champion.id, "player_details");
        }
    });
    // MAIN CHAMPIONS
    if (player.mainChampions.size() == 0) {
        findViewById(R.id.mainsHolder).setVisibility(View.GONE);
    } else {
        ChampionPortraitView main1 = ((ChampionPortraitView) findViewById(R.id.main1));
        ChampionPortraitView main2 = ((ChampionPortraitView) findViewById(R.id.main2));
        ChampionPortraitView main3 = ((ChampionPortraitView) findViewById(R.id.main3));
        main1.setChampion(player.mainChampions.get(0));
        if (player.mainChampions.size() == 3) {
            main2.setChampion(player.mainChampions.get(1));
            main3.setChampion(player.mainChampions.get(2));
        } else if (player.mainChampions.size() == 2) {
            main2.setChampion(player.mainChampions.get(1));
            main3.setVisibility(View.GONE);
        } else {
            main2.setVisibility(View.GONE);
            main3.setVisibility(View.GONE);
        }
    }
    // RECENT MATCHES
    TextView recentMatchesText = (TextView) findViewById(R.id.recentMatchesTitle);
    recentMatchesText.setText(String.format(getString(R.string.recent_matches), player.champion.name));
    findViewById(R.id.aggregate).setVisibility(View.GONE);
    downloadPerformance();
    // TEAMWARD USER
    if (player.teamwardUser) {
        findViewById(R.id.teamwardUser).setVisibility(View.VISIBLE);
    }
}
Also used : Summoner(fr.neamar.lolgamedata.pojo.Summoner) Player(fr.neamar.lolgamedata.pojo.Player) DrawableRes(android.support.annotation.DrawableRes) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) ChampionPortraitView(fr.neamar.lolgamedata.view.ChampionPortraitView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) ChampionInGame(fr.neamar.lolgamedata.pojo.ChampionInGame) Game(fr.neamar.lolgamedata.pojo.Game) ActivityNotFoundException(android.content.ActivityNotFoundException) TextView(android.widget.TextView) Team(fr.neamar.lolgamedata.pojo.Team) ImageView(android.widget.ImageView) ChampionPortraitView(fr.neamar.lolgamedata.view.ChampionPortraitView) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

DrawableRes (android.support.annotation.DrawableRes)27 Context (android.content.Context)8 XmlResourceParser (android.content.res.XmlResourceParser)7 VisibleForTesting (android.support.annotation.VisibleForTesting)6 AttributeSet (android.util.AttributeSet)6 PreferenceControllerMixin (com.android.settings.core.PreferenceControllerMixin)6 IOException (java.io.IOException)6 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)6 Drawable (android.graphics.drawable.Drawable)5 View (android.view.View)5 Intent (android.content.Intent)4 TextView (android.widget.TextView)4 TypedArray (android.content.res.TypedArray)3 ColorInt (android.support.annotation.ColorInt)3 ImageView (android.widget.ImageView)3 Assignment (com.instructure.canvasapi2.models.Assignment)3 Assignment.submissionTypeToAPIString (com.instructure.canvasapi2.models.Assignment.submissionTypeToAPIString)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 NotificationManager (android.app.NotificationManager)2