List of usage examples for android.support.v4.content.res ResourcesCompat getDrawable
public static Drawable getDrawable(Resources resources, int i, Theme theme) throws NotFoundException
From source file:com.makotogo.mobile.hoursdroid.HoursDetailFragment.java
private void configureBeginDate(View view) { TextView beginDateTextView = (TextView) view.findViewById(R.id.textview_hours_detail_begin_date); beginDateTextView.setEnabled(isThisHoursRecordNotActive()); if (isThisHoursRecordActive()) { beginDateTextView/* w w w . j a va 2 s. co m*/ .setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.no_border, null)); } else { beginDateTextView .setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.rounded_border, null)); } beginDateTextView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { FragmentManager fragmentManager = getFragmentManager(); // If there is already a Date displayed, use that. Date dateToUse = (mHours.getBegin() == null) ? new Date() : mHours.getBegin(); DateTimePickerFragment datePickerFragment = FragmentFactory.createDatePickerFragment(dateToUse, "Begin", DateTimePickerFragment.BOTH); datePickerFragment.setTargetFragment(HoursDetailFragment.this, REQUEST_BEGIN_DATE_PICKER); datePickerFragment.show(fragmentManager, DateTimePickerFragment.DIALOG_TAG); } }); if (mHours.getBegin() != null) { LocalDateTime beginDateTime = new LocalDateTime(mHours.getBegin().getTime()); beginDateTextView.setText(beginDateTime.toString(DATE_FORMAT_PATTERN)); } }
From source file:org.getlantern.firetweet.fragment.CustomTabsFragment.java
@Override public void onPrepareOptionsMenu(final Menu menu) { final Resources res = getResources(); final boolean hasOfficialKeyAccounts = Utils.hasAccountSignedWithOfficialKeys(getActivity()); final boolean forcePrivateAPI = mPreferences.getBoolean(KEY_FORCE_USING_PRIVATE_APIS, false); final long[] accountIds = getAccountIds(getActivity()); final MenuItem itemAdd = menu.findItem(R.id.add_submenu); if (itemAdd != null && itemAdd.hasSubMenu()) { final SubMenu subMenu = itemAdd.getSubMenu(); subMenu.clear();//from w ww. j a v a2 s.com final HashMap<String, CustomTabConfiguration> map = getConfiguraionMap(); final List<Entry<String, CustomTabConfiguration>> tabs = new ArrayList<>(map.entrySet()); Collections.sort(tabs, CustomTabConfigurationComparator.SINGLETON); for (final Entry<String, CustomTabConfiguration> entry : tabs) { final String type = entry.getKey(); final CustomTabConfiguration conf = entry.getValue(); final boolean isOfficiakKeyAccountRequired = TAB_TYPE_ACTIVITIES_ABOUT_ME.equals(type) || TAB_TYPE_ACTIVITIES_BY_FRIENDS.equals(type); final boolean accountIdRequired = conf .getAccountRequirement() == CustomTabConfiguration.ACCOUNT_REQUIRED; final Intent intent = new Intent(INTENT_ACTION_ADD_TAB); intent.setClass(getActivity(), CustomTabEditorActivity.class); intent.putExtra(EXTRA_TYPE, type); intent.putExtra(EXTRA_OFFICIAL_KEY_ONLY, isOfficiakKeyAccountRequired); final MenuItem subItem = subMenu.add(conf.getDefaultTitle()); final boolean disabledByNoAccount = accountIdRequired && accountIds.length == 0; final boolean disabledByNoOfficialKey = !forcePrivateAPI && isOfficiakKeyAccountRequired && !hasOfficialKeyAccounts; final boolean disabledByDuplicateTab = conf.isSingleTab() && isTabAdded(getActivity(), type); final boolean shouldDisable = disabledByDuplicateTab || disabledByNoOfficialKey || disabledByNoAccount; subItem.setVisible(!shouldDisable); subItem.setEnabled(!shouldDisable); final Drawable icon = ResourcesCompat.getDrawable(res, conf.getDefaultIcon(), null); subItem.setIcon(icon); subItem.setIntent(intent); } } ThemeUtils.applyColorFilterToMenuIcon(getActivity(), menu); }
From source file:com.linkloving.dyh08.logic.UI.launch.view.wheelview.WheelView.java
/** * Sets the drawable for the wheel foreground * * @param resource/*w ww .java 2 s . c o m*/ */ public void setWheelForeground(int resource) { wheelForeground = resource; centerDrawable = ResourcesCompat.getDrawable(getResources(), wheelForeground, null); }
From source file:com.linkloving.dyh08.logic.UI.launch.view.wheelview.WheelView.java
/** * Initializes resources//from w w w . j a v a 2s. c om */ private void initResourcesIfNecessary() { if (centerDrawable == null) centerDrawable = ResourcesCompat.getDrawable(getResources(), wheelForeground, null); if (topShadow == null) topShadow = new GradientDrawable(Orientation.TOP_BOTTOM, SHADOWS_COLORS); if (bottomShadow == null) { bottomShadow = new GradientDrawable(Orientation.BOTTOM_TOP, SHADOWS_COLORS); } setBackgroundResource(wheelBackground); }
From source file:com.eng.arab.translator.androidtranslator.activity.NumberViewActivity.java
private void setupFloatingSearch() { mSearchView.setOnHomeActionClickListener(new FloatingSearchView.OnHomeActionClickListener() { @Override/* w w w . j a v a 2s. c om*/ public void onHomeClicked() { } }); mSearchView.setOnQueryChangeListener(new FloatingSearchView.OnQueryChangeListener() { @Override public void onSearchTextChanged(String oldQuery, final String newQuery) { if (!oldQuery.equals("") && newQuery.equals("")) { mSearchView.clearSuggestions(); } else { //this shows the top left circular progress //you can call it where ever you want, but //it makes sense to do it when loading something in //the background. mSearchView.showProgress(); //simulates a query call to a data source //with a new query. NumberDataHelper.findSuggestions(getApplicationContext(), newQuery, 5, FIND_SUGGESTION_SIMULATED_DELAY, new NumberDataHelper.OnFindSuggestionsListener() { @Override public void onResults(List<NumberSuggestion> results) { //this will swap the data and //render the collapse/expand animations as necessary mSearchView.swapSuggestions(results); //let the users know that the background //process has completed mSearchView.hideProgress(); } }); } Log.d(TAG, "onSearchTextChanged()"); } }); mSearchView.setOnSearchListener(new FloatingSearchView.OnSearchListener() { @Override public void onSuggestionClicked(final SearchSuggestion searchSuggestion) { NumberSuggestion numberSuggestion = (NumberSuggestion) searchSuggestion; NumberDataHelper.findNumbers(getApplicationContext(), numberSuggestion.getWord(), new NumberDataHelper.OnFindNumberListener() { @Override public void onResults(List<NumberWrapper> results) { mSearchResultsAdapter.swapData(results); } }); Log.d(TAG, "onSuggestionClicked()"); mLastQuery = searchSuggestion.getWord(); } @Override public void onSearchAction(String query) { mLastQuery = query; NumberDataHelper.findNumbers(getApplicationContext(), query, new NumberDataHelper.OnFindNumberListener() { @Override public void onResults(List<NumberWrapper> results) { mSearchResultsAdapter.swapData(results); } }); Log.d(TAG, "onSearchAction()"); } }); mSearchView.setOnFocusChangeListener(new FloatingSearchView.OnFocusChangeListener() { @Override public void onFocus() { //show suggestions when search bar gains focus (typically history suggestions) // NumberDataHelper cdh = new NumberDataHelper(); // cdh.setContext(getApplicationContext()); mSearchView.swapSuggestions(NumberDataHelper.getHistory(getApplicationContext(), 5)); Log.d(TAG, "onFocus()"); } @Override public void onFocusCleared() { //set the title of the bar so that when focus is returned a new query begins mSearchView.setSearchBarTitle(mLastQuery); //you can also set setSearchText(...) to make keep the query there when not focused and when focus returns //mSearchView.setSearchText(searchSuggestion.getWord()); Log.d(TAG, "onFocusCleared()"); } }); //handle menu clicks the same way as you would //in a regular activity mSearchView.setOnMenuItemClickListener(new FloatingSearchView.OnMenuItemClickListener() { @Override public void onActionMenuItemSelected(MenuItem item) { if (item.getItemId() == R.id.action_refresh_list) { /*mIsDarkSearchTheme = true; //demonstrate setting colors for items mSearchView.setBackgroundColor(Color.parseColor("#787878")); mSearchView.setViewTextColor(Color.parseColor("#e9e9e9")); mSearchView.setHintTextColor(Color.parseColor("#e9e9e9")); mSearchView.setActionMenuOverflowColor(Color.parseColor("#e9e9e9")); mSearchView.setMenuItemIconColor(Color.parseColor("#e9e9e9")); mSearchView.setLeftActionIconColor(Color.parseColor("#e9e9e9")); mSearchView.setClearBtnColor(Color.parseColor("#e9e9e9")); mSearchView.setDividerColor(Color.parseColor("#BEBEBE")); mSearchView.setLeftActionIconColor(Color.parseColor("#e9e9e9"));*/ populateCardList(); } else if (item.getItemId() == R.id.action_voice_rec) { Intent voiceRecognize = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); voiceRecognize.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName()); voiceRecognize.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); voiceRecognize.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "ar-EG"); voiceRecognize.putExtra(RecognizerIntent.EXTRA_PROMPT, "Say the letter in ARABIC..."); /*voiceRecognize.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true); */ voiceRecognize.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 100); startActivityForResult(voiceRecognize, REQUEST_CODE); } else { //just print action //Toast.makeText(getApplicationContext().getApplicationContext(), item.getTitle(), // Toast.LENGTH_SHORT).show(); } } }); //use this listener to listen to menu clicks when app:floatingSearch_leftAction="showHome" mSearchView.setOnHomeActionClickListener(new FloatingSearchView.OnHomeActionClickListener() { @Override public void onHomeClicked() { startActivity(new Intent(NumberViewActivity.this, MainActivity.class) .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)); overridePendingTransition(R.anim.left_to_right, R.anim.right_to_left); Log.d(TAG, "onHomeClicked()"); } }); /* * Here you have access to the left icon and the text of a given suggestion * item after as it is bound to the suggestion list. You can utilize this * callback to change some properties of the left icon and the text. For example, you * can load the left icon images using your favorite image loading library, or change text color. * * * Important: * Keep in mind that the suggestion list is a RecyclerView, so views are reused for different * items in the list. */ mSearchView.setOnBindSuggestionCallback(new SearchSuggestionsAdapter.OnBindSuggestionCallback() { @Override public void onBindSuggestion(View suggestionView, ImageView leftIcon, TextView textView, SearchSuggestion item, int itemPosition) { NumberSuggestion numberSuggestion = (NumberSuggestion) item; String textColor = mIsDarkSearchTheme ? "#ffffff" : "#000000"; String textLight = mIsDarkSearchTheme ? "#bfbfbf" : "#787878"; if (numberSuggestion.getIsHistory()) { leftIcon.setImageDrawable( ResourcesCompat.getDrawable(getResources(), R.drawable.ic_history_black_24dp, null)); Util.setIconColor(leftIcon, Color.parseColor(textColor)); leftIcon.setAlpha(.36f); } else { leftIcon.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_lightbulb_outline_black_24dp, null)); Util.setIconColor(leftIcon, Color.parseColor(textColor)); leftIcon.setAlpha(.36f); /*leftIcon.setAlpha(0.0f); leftIcon.setImageDrawable(null);*/ } textView.setTextColor(Color.parseColor(textColor)); String text = numberSuggestion.getWord().replaceFirst(mSearchView.getQuery(), "<font color=\"" + textLight + "\">" + mSearchView.getQuery() + "</font>"); textView.setText(Html.fromHtml(text)); } }); //listen for when suggestion list expands/shrinks in order to move down/up the //search results list mSearchView.setOnSuggestionsListHeightChanged(new FloatingSearchView.OnSuggestionsListHeightChanged() { @Override public void onSuggestionsListHeightChanged(float newHeight) { mSearchResultsList.setTranslationY(newHeight); } }); }
From source file:android.support.graphics.drawable.VectorDrawableCompat.java
/** * Create a VectorDrawableCompat object. * * @param res the resources./*from ww w .ja v a2 s. c o m*/ * @param resId the resource ID for VectorDrawableCompat object. * @param theme the theme of this vector drawable, it can be null. * @return a new VectorDrawableCompat or null if parsing error is found. */ @Nullable public static VectorDrawableCompat create(@NonNull Resources res, @DrawableRes int resId, @Nullable Theme theme) { if (Build.VERSION.SDK_INT >= 23) { final VectorDrawableCompat drawable = new VectorDrawableCompat(); drawable.mDelegateDrawable = ResourcesCompat.getDrawable(res, resId, theme); drawable.mCachedConstantStateDelegate = new VectorDrawableDelegateState( drawable.mDelegateDrawable.getConstantState()); return drawable; } try { final XmlPullParser parser = res.getXml(resId); final AttributeSet attrs = Xml.asAttributeSet(parser); int type; while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) { // Empty loop } if (type != XmlPullParser.START_TAG) { throw new XmlPullParserException("No start tag found"); } return createFromXmlInner(res, parser, attrs, theme); } catch (XmlPullParserException e) { Log.e(LOGTAG, "parser error", e); } catch (IOException e) { Log.e(LOGTAG, "parser error", e); } return null; }
From source file:com.application.akscorp.yandextranslator2017.TranslateScreen.java
/** * Create custom edittext with right button and Runnable action *///from w w w .ja v a2 s . c o m private void EditTextControl() { editTextInputFrazeForTranslate.defineButton( new MyPair<Drawable, Runnable>().mp(ResourcesCompat.getDrawable(getActivity().getResources(), R.drawable.ic_volume_up_blue_grey_300_36dp, null), Speech()), new MyPair<Drawable, Runnable>().mp(ResourcesCompat.getDrawable(getActivity().getResources(), R.drawable.ic_mic_blue_grey_300_36dp, null), Record()), new MyPair<Drawable, Runnable>().mp(ResourcesCompat.getDrawable(getActivity().getResources(), R.drawable.ic_close_blue_grey_300_36dp, null), Clear())); editTextInputFrazeForTranslate.getEditText().addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } private Timer timer = new Timer(); private final long DELAY = 1300; @Override public void afterTextChanged(Editable s) { timer.cancel(); timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { if (IsTranslateEnable && myApp.AUTOTRANSLATE_ENABLE) { IsTranslateEnable = false; TranslateWork(); } } }, DELAY); } }); }
From source file:com.makotogo.mobile.hoursdroid.HoursDetailFragment.java
private void configureEndDate(View view) { TextView endDateTextView = (TextView) view.findViewById(R.id.textview_hours_detail_end_date); endDateTextView.setEnabled(isThisHoursRecordNotActive()); if (isThisHoursRecordActive()) { endDateTextView.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.no_border, null)); } else {//from w ww. j a va 2 s. co m endDateTextView .setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.rounded_border, null)); } endDateTextView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { FragmentManager fragmentManager = getFragmentManager(); // If there is already a Date displayed, use that. Date dateToUse = (mHours.getEnd() == null) ? new Date() : mHours.getEnd(); DateTimePickerFragment datePickerFragment = FragmentFactory.createDatePickerFragment(dateToUse, "End", DateTimePickerFragment.BOTH); datePickerFragment.setTargetFragment(HoursDetailFragment.this, REQUEST_END_DATE_PICKER); datePickerFragment.show(fragmentManager, DateTimePickerFragment.DIALOG_TAG); } }); if (mHours.getEnd() != null) { LocalDateTime endDateTime = new LocalDateTime(mHours.getEnd().getTime()); endDateTextView.setText(endDateTime.toString(DATE_FORMAT_PATTERN)); } }
From source file:com.kmagic.solitaire.DrawMaster.java
/** * Draw cards with big single center suite * @param r application resources reference *///from www . ja v a 2s . c o m private void drawBigCards(final Resources r) { final Bitmap[] bigSuit = new Bitmap[4]; final Bitmap[] suit = new Bitmap[4]; Canvas canvas; final String[] card_values = mResources.getStringArray(R.array.card_values); final Paint cardFrontPaint = new Paint(); final Paint cardBorderPaint = new Paint(); final Paint textPaintLeft = getTextPaint(mSuitsSize, Paint.Align.LEFT); Drawable drawable = ResourcesCompat.getDrawable(r, R.drawable.cardback, null); mCardHidden = Bitmap.createBitmap(Card.WIDTH, Card.HEIGHT, Bitmap.Config.ARGB_8888); canvas = new Canvas(mCardHidden); drawable.setBounds(0, 0, Card.WIDTH, Card.HEIGHT); drawable.draw(canvas); for (int i = 0; i < 4; i++) { suit[i] = Bitmap.createBitmap((int) mSuitsSizeHalf, (int) mSuitsSizeHalf, Bitmap.Config.ARGB_8888); canvas = new Canvas(suit[i]); drawSuit(i, canvas, mSuitsSizeHalf); } for (int i = 0; i < 4; i++) { bigSuit[i] = Bitmap.createBitmap((int) mSuitsSize, (int) mSuitsSize, Bitmap.Config.ARGB_8888); canvas = new Canvas(bigSuit[i]); drawSuit(i, canvas, mSuitsSize); } cardBorderPaint.setARGB(255, 0, 0, 0); cardFrontPaint.setARGB(255, 255, 255, 255); RectF rectf = new RectF(); for (int suitIdx = 0; suitIdx < 4; suitIdx++) { for (int valueIdx = 0; valueIdx < 13; valueIdx++) { mCardBitmap[suitIdx * 13 + valueIdx] = Bitmap.createBitmap(Card.WIDTH, Card.HEIGHT, Bitmap.Config.ARGB_8888); canvas = new Canvas(mCardBitmap[suitIdx * 13 + valueIdx]); drawCardBackground(rectf, canvas, cardBorderPaint, cardFrontPaint); drawCardValue(textPaintLeft, canvas, card_values[valueIdx], suit[suitIdx], suitIdx); // Middle canvas.drawBitmap(bigSuit[suitIdx], Card.WIDTH / 2 - mSuitsSizeHalf, Card.HEIGHT / 2 - mSuitsSizeHalf, mSuitPaint); } } }
From source file:org.mariotaku.twidere.fragment.support.UserFragment.java
private void showRelationship(ParcelableUser user, Relationship relationship) { mRelationship = relationship;/*from w w w.jav a 2s.co m*/ if (user == null) return; invalidateOptionsMenu(); final boolean isMyself = user.account_id == user.id; if (isMyself) { mFollowButton.setText(R.string.edit); mFollowButton.setVisibility(View.VISIBLE); } else if (relationship != null) { final int drawableRes; mFollowButton.setEnabled(!relationship.isSourceBlockedByTarget()); if (relationship.isSourceBlockedByTarget()) { mPagesErrorContainer.setVisibility(View.VISIBLE); final String displayName = mUserColorNameManager.getDisplayName(user, mNameFirst, true); mPagesErrorText.setText(getString(R.string.blocked_by_user_summary, displayName)); mPagesErrorIcon.setImageResource(R.drawable.ic_info_error_generic); mPagesContent.setVisibility(View.GONE); } else if (!relationship.isSourceFollowingTarget() && user.is_protected) { mPagesErrorContainer.setVisibility(View.VISIBLE); final String displayName = mUserColorNameManager.getDisplayName(user, mNameFirst, true); mPagesErrorText.setText(getString(R.string.user_protected_summary, displayName)); mPagesErrorIcon.setImageResource(R.drawable.ic_info_locked); mPagesContent.setVisibility(View.GONE); } else { mPagesErrorContainer.setVisibility(View.GONE); mPagesErrorText.setText(null); mPagesContent.setVisibility(View.VISIBLE); } if (relationship.isSourceBlockingTarget()) { mFollowButton.setText(R.string.unblock); drawableRes = R.drawable.ic_follow_blocked; } else if (relationship.isSourceFollowingTarget()) { mFollowButton.setText(R.string.unfollow); if (relationship.isTargetFollowingSource()) { drawableRes = R.drawable.ic_follow_bidirectional; } else { drawableRes = R.drawable.ic_follow_outgoing; } } else if (user.is_follow_request_sent) { mFollowButton.setText(R.string.requested); if (relationship.isTargetFollowingSource()) { drawableRes = R.drawable.ic_follow_incoming; } else { drawableRes = R.drawable.ic_follow_pending; } } else { mFollowButton.setText(R.string.follow); if (relationship.isTargetFollowingSource()) { drawableRes = R.drawable.ic_follow_incoming; } else { drawableRes = R.drawable.ic_follow_none; } } final Drawable icon = ResourcesCompat.getDrawable(getResources(), drawableRes, null); final int iconSize = Math.round(mFollowButton.getTextSize() * 1.4f); icon.setBounds(0, 0, iconSize, iconSize); icon.setColorFilter(mFollowButton.getCurrentTextColor(), Mode.SRC_ATOP); mFollowButton.setCompoundDrawables(icon, null, null, null); mFollowButton.setCompoundDrawablePadding(Math.round(mFollowButton.getTextSize() * 0.25f)); final ContentResolver resolver = getContentResolver(); final ContentValues cachedValues = ParcelableUser.makeCachedUserContentValues(user); resolver.insert(CachedUsers.CONTENT_URI, cachedValues); mFollowButton.setVisibility(View.VISIBLE); } else { mFollowButton.setText(null); mFollowButton.setVisibility(View.GONE); mPagesErrorContainer.setVisibility(View.GONE); mPagesContent.setVisibility(View.VISIBLE); } }