Example usage for android.view View getResources

List of usage examples for android.view View getResources

Introduction

In this page you can find the example usage for android.view View getResources.

Prototype

public Resources getResources() 

Source Link

Document

Returns the resources associated with this view.

Usage

From source file:com.justplay1.shoppist.utils.NavigationViewActions.java

/**
 * Returns a {@link ViewAction} that navigates to a menu item in {@link NavigationView} using a
 * menu item resource id./*  w ww .jav a 2 s  . c  o m*/
 * <p>
 * <p>
 * View constraints:
 * <ul>
 * <li>View must be a child of a {@link DrawerLayout}
 * <li>View must be of type {@link NavigationView}
 * <li>View must be visible on screen
 * <li>View must be displayed on screen
 * <ul>
 *
 * @param menuItemId the resource id of the menu item
 * @return a {@link ViewAction} that navigates on a menu item
 */
public static ViewAction navigateTo(final int menuItemId) {

    return new ViewAction() {

        @Override
        public void perform(UiController uiController, View view) {
            NavigationView navigationView = (NavigationView) view;
            Menu menu = navigationView.getMenu();
            if (null == menu.findItem(menuItemId)) {
                throw new PerformException.Builder().withActionDescription(this.getDescription())
                        .withViewDescription(HumanReadables.describe(view))
                        .withCause(new RuntimeException(getErrorMessage(menu, view))).build();
            }
            menu.performIdentifierAction(menuItemId, 0);
            uiController.loopMainThreadUntilIdle();
        }

        private String getErrorMessage(Menu menu, View view) {
            String NEW_LINE = System.getProperty("line.separator");
            StringBuilder errorMessage = new StringBuilder(
                    "Menu item was not found, " + "available menu items:").append(NEW_LINE);
            for (int position = 0; position < menu.size(); position++) {
                errorMessage.append("[MenuItem] position=").append(position);
                MenuItem menuItem = menu.getItem(position);
                if (menuItem != null) {
                    CharSequence itemTitle = menuItem.getTitle();
                    if (itemTitle != null) {
                        errorMessage.append(", title=").append(itemTitle);
                    }
                    if (view.getResources() != null) {
                        int itemId = menuItem.getItemId();
                        try {
                            errorMessage.append(", id=");
                            String menuItemResourceName = view.getResources().getResourceName(itemId);
                            errorMessage.append(menuItemResourceName);
                        } catch (Resources.NotFoundException nfe) {
                            errorMessage.append("not found");
                        }
                    }
                    errorMessage.append(NEW_LINE);
                }
            }
            return errorMessage.toString();
        }

        @Override
        public String getDescription() {
            return "click on menu item with id";
        }

        @Override
        public Matcher<View> getConstraints() {
            return allOf(isAssignableFrom(NavigationView.class),
                    withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE), isDisplayingAtLeast(90));
        }
    };

}

From source file:com.mifos.mifosxdroid.tests.action.NavigationViewActions.java

/**
 * Returns a {@link ViewAction} that navigates to a menu item in {@link NavigationView} using a
 * menu item resource id.//from ww w . java 2 s  . c  o m
 * <p/>
 * <p/>
 * View constraints:
 * <ul>
 * <li>View must be a child of a {@link DrawerLayout}
 * <li>View must be of type {@link NavigationView}
 * <li>View must be visible on screen
 * <li>View must be displayed on screen
 * <ul>
 *
 * @param menuItemId the resource id of the menu item
 * @return a {@link ViewAction} that navigates on a menu item
 */
public static ViewAction navigateTo(final int menuItemId) {

    return new ViewAction() {

        @Override
        public void perform(UiController uiController, View view) {
            NavigationView navigationView = (NavigationView) view;
            Menu menu = navigationView.getMenu();
            if (null == menu.findItem(menuItemId)) {
                throw new PerformException.Builder().withActionDescription(this.getDescription())
                        .withViewDescription(HumanReadables.describe(view))
                        .withCause(new RuntimeException(getErrorMessage(menu, view))).build();
            }
            menu.performIdentifierAction(menuItemId, 0);
            uiController.loopMainThreadUntilIdle();
        }

        private String getErrorMessage(Menu menu, View view) {
            String NEW_LINE = System.getProperty("line.separator");
            StringBuilder errorMessage = new StringBuilder(20)
                    .append("Menu item was not found, available menu items:").append(NEW_LINE);
            for (int position = 0; position < menu.size(); position++) {
                errorMessage.append("[MenuItem] position=").append(position);
                MenuItem menuItem = menu.getItem(position);
                if (menuItem != null) {
                    CharSequence itemTitle = menuItem.getTitle();
                    if (itemTitle != null) {
                        errorMessage.append(", title=").append(itemTitle);
                    }
                    if (view.getResources() != null) {
                        int itemId = menuItem.getItemId();
                        try {
                            errorMessage.append(", id=");
                            String menuItemResourceName = view.getResources().getResourceName(itemId);
                            errorMessage.append(menuItemResourceName);
                        } catch (NotFoundException nfe) {
                            errorMessage.append("not found");
                        }
                    }
                    errorMessage.append(NEW_LINE);
                }
            }
            return errorMessage.toString();
        }

        @Override
        public String getDescription() {
            return "click on menu item with id";
        }

        @Override
        public Matcher<View> getConstraints() {
            return allOf(isAssignableFrom(NavigationView.class),
                    withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE), isDisplayingAtLeast(90));
        }
    };

}

From source file:com.grarak.kerneladiutor.views.recyclerview.ContributorView.java

@Override
public void onCreateView(View view) {
    super.onCreateView(view);

    CircularImageView image = (CircularImageView) view.findViewById(R.id.image);
    TextView name = (TextView) view.findViewById(R.id.name);
    TextView contributions = (TextView) view.findViewById(R.id.contributions);

    if (Utils.DARK_THEME) {
        name.setTextColor(ContextCompat.getColor(view.getContext(), R.color.white));
    }/*  w ww.  ja  v a  2  s .c  o  m*/
    Utils.loadImagefromUrl(mContributor.getAvatarUrl(), image, 200, 200);
    name.setText(mContributor.getLogin());
    contributions.setText(view.getResources().getString(R.string.commits, mContributor.getContributions()));
}

From source file:com.bitants.wally.fragments.LatestFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    gridView.setClipToPadding(false);//from w  ww .  j  a va2 s . c  o  m
    setInsets(getActivity(), gridView, false, 0,
            view.getResources().getDimensionPixelSize(R.dimen.gridview_bottom_padding));
}

From source file:com.andreadec.musicplayer.adapters.BrowserArrayAdapter.java

@Override
public View getView(int position, View view, ViewGroup parent) {
    int type = getItemViewType(position);
    Object value = values.get(position);
    ViewHolder viewHolder;//from ww w  .jav  a  2 s  .  c  o m
    if (view == null) {
        viewHolder = new ViewHolder();
        if (type == TYPE_ACTION) {
            view = inflater.inflate(R.layout.action_item, parent, false);
            viewHolder.title = (TextView) view.findViewById(R.id.textView);
            viewHolder.title.setTextColor(view.getResources().getColor(R.color.orange1));
            viewHolder.image = (ImageView) view.findViewById(R.id.imageView);
            viewHolder.image.setImageResource(R.drawable.back);
        } else if (type == TYPE_DIRECTORY) {
            view = inflater.inflate(R.layout.folder_item, parent, false);
            viewHolder.title = (TextView) view.findViewById(R.id.textViewFolderItemFolder);
        } else if (type == TYPE_SONG) {
            view = inflater.inflate(R.layout.song_item, parent, false);
            viewHolder.title = (TextView) view.findViewById(R.id.textViewSongItemTitle);
            viewHolder.artist = (TextView) view.findViewById(R.id.textViewSongItemArtist);
            viewHolder.image = (ImageView) view.findViewById(R.id.imageViewItemImage);
            viewHolder.card = view.findViewById(R.id.card);
        }
    } else {
        viewHolder = (ViewHolder) view.getTag();
    }
    if (type == TYPE_ACTION) {
        Action action = (Action) value;
        viewHolder.title.setText(action.msg);
    } else if (type == TYPE_DIRECTORY) {
        File file = (File) value;
        viewHolder.title.setText(file.getName());
    } else if (type == TYPE_SONG) {
        BrowserSong song = (BrowserSong) value;
        String trackNumber = "";
        if (song.getTrackNumber() != null)
            trackNumber = song.getTrackNumber() + ". ";
        viewHolder.title.setText(trackNumber + song.getTitle());
        viewHolder.artist.setText(song.getArtist());
        if (song.equals(playingSong)) {
            viewHolder.card.setBackgroundResource(R.drawable.card_playing);
            viewHolder.image.setImageResource(R.drawable.play_orange);
        } else {
            viewHolder.card.setBackgroundResource(R.drawable.card);
            if (showSongImage) {
                viewHolder.image.setImageDrawable(songImage);
                if (song.hasImage()) {
                    Bitmap image;
                    synchronized (imagesCache) {
                        image = imagesCache.get(song.getUri());
                    }
                    if (image != null) {
                        viewHolder.image.setImageBitmap(image);
                    } else
                        new ImageLoaderTask(song, viewHolder.image, imagesCache, listImageSize).execute();
                }
            }
        }
    }
    view.setTag(viewHolder);
    return view;
}

From source file:rhcad.touchvg.view.internal.ImageCache.java

public final Drawable getImage(View view, String name) {
    Drawable drawable = mCache != null ? mCache.get(name) : null;

    if (drawable == null && view != null) {
        if (name.indexOf(BITMAP_PREFIX) == 0) {
            // is R.drawable.resName
            final String resName = name.substring(BITMAP_PREFIX.length());
            int id = view.getResources().getIdentifier(resName, "drawable",
                    view.getContext().getPackageName());
            drawable = this.addBitmap(view.getResources(), id, name);
        } else if (name.indexOf(SVG_PREFIX) == 0) {
            // is R.raw.resName
            final String resName = name.substring(SVG_PREFIX.length());
            int id = view.getResources().getIdentifier(resName, "raw",
                    view.getContext().getPackageName());
            drawable = this.addSVG(view.getResources(), id, name);
        } else if (name.endsWith(".svg")) {
            drawable = this.addSVGFile(getImagePath(name), name);
        } else {/*from   ww w . j a  va 2s.  c  om*/
            drawable = this.addBitmapFile(view.getResources(), getImagePath(name), name);
        }
    }

    return drawable;
}

From source file:org.level28.android.moca.ui.schedule.SessionListFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    final Resources res = view.getResources();

    // Get a hold on all view elements
    mListView = (ListView) view.findViewById(android.R.id.list);
    mProgressBar = (ProgressBar) view.findViewById(R.id.progressLoading);
    mEmptyView = (TextView) view.findViewById(android.R.id.empty);

    // Backward compatibility sucks
    if (!isHoneycomb) {
        // Force the Holo Light background color for this fragment on
        // gingerbread and lower
        view.setBackgroundColor(res.getColor(R.color.background_holo_light));

        // If we're running on Gingerbread or lower we have to override the
        // divider drawable for consistency
        mListView.setDivider(res.getDrawable(R.drawable.list_divider));
    }/*from  w  w  w  .j  a  v a2  s .c o  m*/

    // Set divider height to 2dp
    mListView.setDividerHeight(2);

    // Set item click listener
    mListView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            onListItemClick((ListView) parent, view, position, id);
        }
    });

    mListView.setAdapter(mAdapter);
}

From source file:org.mozilla.focus.widget.TelemetrySwitchPreference.java

@Override
protected void onBindView(final View view) {
    super.onBindView(view);

    final Switch switchWidget = view.findViewById(R.id.switch_widget);

    switchWidget.setChecked(TelemetryWrapper.isTelemetryEnabled(getContext()));

    switchWidget.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override//from   ww w.j  a  v  a  2 s. co  m
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            TelemetryWrapper.setTelemetryEnabled(getContext(), isChecked);
        }
    });

    final Resources resources = view.getResources();

    final TextView summary = view.findViewById(android.R.id.summary);
    summary.setText(resources.getString(R.string.preference_mozilla_telemetry_summary2,
            resources.getString(R.string.app_name)));

    final TextView learnMoreLink = view.findViewById(R.id.link);
    learnMoreLink.setPaintFlags(learnMoreLink.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
    learnMoreLink.setTextColor(ContextCompat.getColor(view.getContext(), R.color.colorAction));
    learnMoreLink.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // This is a hardcoded link: if we ever end up needing more of these links, we should
            // move the link into an xml parameter, but there's no advantage to making it configurable now.
            final String url = SupportUtils.getSumoURLForTopic(getContext(), "usage-data");
            final String title = getTitle().toString();

            final Intent intent = InfoActivity.getIntentFor(getContext(), url, title);
            getContext().startActivity(intent);
        }
    });

    final TypedArray backgroundDrawableArray = view.getContext()
            .obtainStyledAttributes(new int[] { R.attr.selectableItemBackground });
    final Drawable backgroundDrawable = backgroundDrawableArray.getDrawable(0);
    backgroundDrawableArray.recycle();
    learnMoreLink.setBackground(backgroundDrawable);

    // We still want to allow toggling the pref by touching any part of the pref (except for
    // the "learn more" link)
    setOnPreferenceClickListener(new OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            switchWidget.toggle();
            return true;
        }
    });
}

From source file:com.vrem.wifianalyzer.wifi.channelavailable.ChannelAvailableAdapter.java

@NonNull
@Override/*from www . j av a  2s  .  co  m*/
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    View view = convertView;
    if (view == null) {
        LayoutInflater layoutInflater = MainContext.INSTANCE.getMainActivity().getLayoutInflater();
        view = layoutInflater.inflate(R.layout.channel_available_details, parent, false);
    }

    WiFiChannelCountry wiFiChannelCountry = getItem(position);
    ((TextView) view.findViewById(R.id.channel_available_country))
            .setText(wiFiChannelCountry.getCountryCode() + " - " + wiFiChannelCountry.getCountryName());
    ((TextView) view.findViewById(R.id.channel_available_title_ghz_2)).setText(String.format(Locale.ENGLISH,
            "%s : ", view.getResources().getString(WiFiBand.GHZ2.getTextResource())));
    ((TextView) view.findViewById(R.id.channel_available_ghz_2))
            .setText(StringUtils.join(wiFiChannelCountry.getChannelsGHZ2().toArray(), ","));
    ((TextView) view.findViewById(R.id.channel_available_title_ghz_5)).setText(String.format(Locale.ENGLISH,
            "%s : ", view.getResources().getString(WiFiBand.GHZ5.getTextResource())));
    ((TextView) view.findViewById(R.id.channel_available_ghz_5))
            .setText(StringUtils.join(wiFiChannelCountry.getChannelsGHZ5().toArray(), ","));
    return view;
}

From source file:com.apptentive.android.sdk.module.messagecenter.view.holder.MessageComposerHolder.java

public MessageComposerHolder(View itemView) {
    super(itemView);
    images = new ArrayList<ImageItem>();
    closeButton = (ImageButton) itemView.findViewById(R.id.close_button);
    title = (TextView) itemView.findViewById(R.id.title);
    attachButton = (ImageButton) itemView.findViewById(R.id.attach_button);
    sendButton = (ImageButton) itemView.findViewById(R.id.send_button);
    message = (EditText) itemView.findViewById(R.id.message);
    attachments = (ApptentiveImageGridView) itemView.findViewById(R.id.attachments);

    maxAllowedAttachments = itemView.getResources()
            .getInteger(R.integer.apptentive_image_grid_default_attachments_total);

    ColorStateList colors = ContextCompat.getColorStateList(itemView.getContext(),
            Util.getResourceIdFromAttribute(itemView.getContext().getTheme(),
                    R.attr.apptentiveButtonTintColorStateList));
    // Use a color state list for button tint state on Lollipop. On prior platforms, need to apply state color manually.
    Drawable closeButtonDrawable = DrawableCompat.wrap(closeButton.getDrawable());
    DrawableCompat.setTintList(closeButtonDrawable, colors);
    closeButton.setImageDrawable(closeButtonDrawable);
    // Use a color state list for button tint state on Lollipop. On prior platforms, need to apply state color manually.
    Drawable sendButtonDrawable = DrawableCompat.wrap(sendButton.getDrawable());
    DrawableCompat.setTintList(sendButtonDrawable, colors);
    sendButton.setImageDrawable(sendButtonDrawable);
    // Use a color state list for button tint state on Lollipop. On prior platforms, need to apply state color manually.
    Drawable attachButtonDrawable = DrawableCompat.wrap(attachButton.getDrawable());
    DrawableCompat.setTintList(attachButtonDrawable, colors);
    attachButton.setImageDrawable(attachButtonDrawable);
}