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:me.kartikarora.transfersh.adapters.FileGridAdapter.java

@Override
public void bindView(View view, final Context context, Cursor cursor) {
    FileItemViewHolder holder = (FileItemViewHolder) view.getTag();
    int nameCol = cursor.getColumnIndex(FilesContract.FilesEntry.COLUMN_NAME);
    int typeCol = cursor.getColumnIndex(FilesContract.FilesEntry.COLUMN_TYPE);
    int sizeCol = cursor.getColumnIndex(FilesContract.FilesEntry.COLUMN_SIZE);
    int urlCol = cursor.getColumnIndex(FilesContract.FilesEntry.COLUMN_URL);
    final String name = cursor.getString(nameCol);
    final String type = cursor.getString(typeCol);
    final String size = cursor.getString(sizeCol);
    final String url = cursor.getString(urlCol);
    holder.fileNameTextView.setText(name);
    String ext = FilenameUtils.getExtension(name);
    int identifier = context.getResources().getIdentifier("t" + ext, "drawable", context.getPackageName());
    try {/*from w  w w . j a  v  a  2  s  .  c o m*/
        holder.fileTypeImageView
                .setImageDrawable(ResourcesCompat.getDrawable(context.getResources(), identifier, null));
    } catch (Resources.NotFoundException e) {
        e.printStackTrace();
        holder.fileTypeImageView
                .setImageDrawable(ResourcesCompat.getDrawable(context.getResources(), R.drawable.tblank, null));
    }

    holder.fileInfoImageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String message = "Name: " + name + "\n" + "File type: " + type + "\n" + "URL: " + url;
            new AlertDialog.Builder(activity).setMessage(message).setPositiveButton(android.R.string.ok, null)
                    .create().show();
        }
    });

    holder.fileShareImageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            tracker.send(
                    new HitBuilders.EventBuilder().setCategory("Action").setAction("Share : " + url).build());
            context.startActivity(new Intent().setAction(Intent.ACTION_SEND).putExtra(Intent.EXTRA_TEXT, url)
                    .setType("text/plain").addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
        }
    });

    holder.fileDownloadImageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            checkForDownload(name, type, url, view);
        }
    });
}

From source file:com.nttec.everychan.chans.sich.SichModule.java

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

From source file:com.squalala.tariki.ui.map.MapsActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);

    ButterKnife.bind(this);

    if (Build.VERSION.SDK_INT >= 23) {
        new Permission(this);
    }//from  w  ww .  j ava  2 s .co m

    final MapTileProviderBasic tileProvider = new MapTileProviderBasic(getApplicationContext());
    final ITileSource tileSource = new XYTileSource("Mapnik", 3, 19, 256, ".png",
            new String[] { Constants.TILE_SOURCE });
    //mapView.setTileSource((new XYTileSource("localMapnik", Resource, 0, 18, 256, ".png",
    //  "http://tile.openstreetmap.org/")));
    tileProvider.setTileSource(tileSource);
    map.setTileProvider(tileProvider);

    map.setBuiltInZoomControls(true);
    map.setMultiTouchControls(true);

    mapController = map.getController();
    mapController.setZoom(15);

    poiMarkers = new RadiusMarkerClusterer(this);
    map.getOverlays().add(poiMarkers);

    Drawable poiIcon = ResourcesCompat.getDrawable(getResources(), R.drawable.marker_male, null);
    myMarker = new Marker(map);
    poiMarkers.add(myMarker);

    snackbar = Snackbar.make(findViewById(android.R.id.content), getString(R.string.chargement_en_cours),
            Snackbar.LENGTH_INDEFINITE);

    presenter.onCreate();

    setupLocationManager();
}

From source file:com.giovanniterlingen.windesheim.view.Adapters.NatschoolContentAdapter.java

@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
    final TextView contentName = holder.contentName;
    final ImageView icon = holder.icon;
    final FrameLayout menuButton = holder.menuButton;
    final ImageView menuButtonImage = holder.menuButtonImage;
    contentName.setText(content.get(position).name);
    holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override//  w  ww.j  a  v  a  2s.com
        public void onClick(View v) {
            onContentClick(content.get(holder.getAdapterPosition()), holder.getAdapterPosition());
        }
    });
    if (content.get(position).type == -1) {
        icon.setImageDrawable(ResourcesCompat.getDrawable(activity.getResources(),
                getDrawableByName(content.get(position).name), null));
        menuButton.setVisibility(View.VISIBLE);
        menuButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                menuButtonImage.setImageDrawable(
                        ResourcesCompat.getDrawable(activity.getResources(), R.drawable.overflow_open, null));
                PopupMenu popupMenu = new PopupMenu(activity, menuButton);
                popupMenu.inflate(R.menu.menu_file);
                popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                    public boolean onMenuItemClick(MenuItem item) {
                        if (item.getItemId() == R.id.delete_file) {
                            showPromptDialog(holder.getAdapterPosition());
                            return true;
                        }
                        return true;
                    }
                });
                popupMenu.setOnDismissListener(new PopupMenu.OnDismissListener() {
                    @Override
                    public void onDismiss(PopupMenu menu) {
                        menuButtonImage.setImageDrawable(ResourcesCompat.getDrawable(activity.getResources(),
                                R.drawable.overflow_normal, null));
                    }
                });
                popupMenu.show();
            }
        });
    } else if (content.get(position).url == null || (content.get(position).url.length() == 0)) {
        if (content.get(position).imageUrl != null) {
            icon.setImageDrawable(
                    ResourcesCompat.getDrawable(activity.getResources(), R.drawable.ic_work, null));
        } else {
            icon.setImageDrawable(
                    ResourcesCompat.getDrawable(activity.getResources(), R.drawable.ic_folder, null));
        }
    } else {
        if (content.get(position).type == 1 || content.get(position).type == 3
                || content.get(position).type == 11) {
            icon.setImageDrawable(
                    ResourcesCompat.getDrawable(activity.getResources(), R.drawable.ic_link, null));
        } else if (content.get(position).type == 10) {
            icon.setImageDrawable(ResourcesCompat.getDrawable(activity.getResources(),
                    getDrawableByName(content.get(position).url), null));

            final TextView progressTextView = holder.progressTextView;
            final ProgressBar progressBar = holder.progressBar;
            final FrameLayout cancelButton = holder.cancelButton;

            if (content.get(position).downloading) {
                contentName.setVisibility(View.GONE);
                progressTextView.setVisibility(View.VISIBLE);
                progressBar.setVisibility(View.VISIBLE);
                if (content.get(position).progress == -1 && content.get(position).progressString == null) {
                    progressTextView.setText(activity.getResources().getString(R.string.downloading));
                    progressBar.setIndeterminate(true);
                } else {
                    progressTextView.setText(content.get(position).progressString);
                    progressBar.setIndeterminate(false);
                    progressBar.setMax(100);
                    progressBar.setProgress(content.get(position).progress);
                }
                cancelButton.setVisibility(View.VISIBLE);
                cancelButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        NotificationCenter.getInstance().postNotificationName(
                                NotificationCenter.downloadCancelled,
                                content.get(holder.getAdapterPosition()).id);
                        contentName.setVisibility(View.VISIBLE);
                        progressTextView.setVisibility(View.GONE);
                        progressBar.setVisibility(View.GONE);
                        cancelButton.setVisibility(View.GONE);
                    }
                });
            } else {
                contentName.setVisibility(View.VISIBLE);
                progressTextView.setVisibility(View.GONE);
                progressBar.setVisibility(View.GONE);
                cancelButton.setVisibility(View.GONE);
            }
        }
    }
}

From source file:com.nttec.everychan.chans.cirno.CirnoModule.java

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

From source file:org.getlantern.firetweet.activity.support.OpenStreetMapViewerActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Uri uri = getIntent().getData();
    if (uri == null || !AUTHORITY_MAP.equals(uri.getAuthority())) {
        finish();/*from w  w  w .  j  a  v a  2  s .  c  o  m*/
        return;
    }
    final double latitude = ParseUtils.parseDouble(uri.getQueryParameter(QUERY_PARAM_LAT), Double.NaN);
    final double longitude = ParseUtils.parseDouble(uri.getQueryParameter(QUERY_PARAM_LNG), Double.NaN);
    if (Double.isNaN(latitude) || Double.isNaN(longitude)) {
        finish();
        return;
    }
    mLatitude = latitude;
    mLongitude = longitude;
    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    setContentView(R.layout.activity_osm_viewer);
    mMapView.setMultiTouchControls(true);
    mMapView.setBuiltInZoomControls(true);
    mMapView.setTilesScaledToDpi(true);
    final List<Overlay> overlays = mMapView.getOverlays();
    final GeoPoint gp = new GeoPoint((int) (latitude * 1E6), (int) (longitude * 1E6));
    final Drawable d = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_map_marker, null);
    final Itemization markers = new Itemization(d, mMapView.getResourceProxy());
    final OverlayItem overlayitem = new OverlayItem("", "", gp);
    markers.addOverlay(overlayitem);
    overlays.add(markers);
    final IMapController mc = mMapView.getController();
    mc.setZoom(12);
    mc.setCenter(gp);
}

From source file:com.example.android.leanback.CardPresenter.java

@Override
public void onBindViewHolder(ViewHolder viewHolder, Object item) {
    Log.d(TAG, "onBindViewHolder for " + item.toString());
    PhotoItem photoItem = (PhotoItem) item;
    final Context context = viewHolder.view.getContext();
    Drawable drawable = ResourcesCompat.getDrawable(context.getResources(), photoItem.getImageResourceId(),
            context.getTheme());/*from  w  w w  .j  a  v  a 2 s.com*/
    ((ImageCardView) viewHolder.view).setMainImage(drawable);
    ((ImageCardView) viewHolder.view).setTitleText(photoItem.getTitle());
    if (!TextUtils.isEmpty(photoItem.getContent())) {
        ((ImageCardView) viewHolder.view).setContentText(photoItem.getContent());
    }
}

From source file:nya.miku.wishmaster.chans.ernstchan.ErnstModule.java

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

From source file:org.microg.tools.ui.Condition.java

View createView(final Context context, ViewGroup container) {
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.condition_card, container, false);
    Drawable icon = getIcon(context);//  w  ww.j av a  2  s. c  om
    if (icon != null)
        ((ImageView) view.findViewById(android.R.id.icon)).setImageDrawable(icon);
    ((TextView) view.findViewById(android.R.id.title)).setText(getTitle(context));
    ((TextView) view.findViewById(android.R.id.summary)).setText(getSummary(context));
    Button first = (Button) view.findViewById(R.id.first_action);
    first.setText(getFirstActionText(context));
    first.setOnClickListener(getFirstActionListener());
    CharSequence secondActionText = getSecondActionText(context);
    if (secondActionText != null) {
        Button second = (Button) view.findViewById(R.id.second_action);
        second.setText(secondActionText);
        second.setOnClickListener(getSecondActionListener());
        second.setVisibility(View.VISIBLE);
    }
    final View detailGroup = view.findViewById(R.id.detail_group);
    final ImageView expandIndicator = (ImageView) view.findViewById(R.id.expand_indicator);
    View.OnClickListener expandListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (detailGroup.getVisibility() == View.VISIBLE) {
                expandIndicator.setImageDrawable(ResourcesCompat.getDrawable(context.getResources(),
                        R.drawable.ic_expand_more, context.getTheme()));
                detailGroup.setVisibility(View.GONE);
            } else {
                expandIndicator.setImageDrawable(ResourcesCompat.getDrawable(context.getResources(),
                        R.drawable.ic_expand_less, context.getTheme()));
                detailGroup.setVisibility(View.VISIBLE);
            }
        }
    };
    view.findViewById(R.id.collapsed_group).setOnClickListener(expandListener);
    expandIndicator.setOnClickListener(expandListener);
    view.setTag(this);
    return view;
}

From source file:android.support.graphics.drawable.AnimatedVectorDrawableCompat.java

/**
 * Create a AnimatedVectorDrawableCompat object.
 *
 * @param context the context for creating the animators.
 * @param resId   the resource ID for AnimatedVectorDrawableCompat object.
 * @return a new AnimatedVectorDrawableCompat or null if parsing error is found.
 *///ww w. j  a  v a2 s . co  m
@Nullable
public static AnimatedVectorDrawableCompat create(@NonNull Context context, @DrawableRes int resId) {
    if (Build.VERSION.SDK_INT >= 23) {
        final AnimatedVectorDrawableCompat drawable = new AnimatedVectorDrawableCompat(context);
        drawable.mDelegateDrawable = ResourcesCompat.getDrawable(context.getResources(), resId,
                context.getTheme());
        drawable.mDelegateDrawable.setCallback(drawable.mCallback);
        drawable.mCachedConstantStateDelegate = new AnimatedVectorDrawableDelegateState(
                drawable.mDelegateDrawable.getConstantState());
        return drawable;
    }
    Resources resources = context.getResources();
    try {
        final XmlPullParser parser = resources.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(context, context.getResources(), parser, attrs, context.getTheme());
    } catch (XmlPullParserException e) {
        Log.e(LOGTAG, "parser error", e);
    } catch (IOException e) {
        Log.e(LOGTAG, "parser error", e);
    }
    return null;
}