Example usage for android.content.res Resources getIdentifier

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

Introduction

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

Prototype

public int getIdentifier(String name, String defType, String defPackage) 

Source Link

Document

Return a resource identifier for the given resource name.

Usage

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);/*from  w  w  w  . j ava  2s . co  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);//from  w w  w  . j a va 2s  .co 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_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);
            }
        });
    }
}

From source file:com.microsoft.mimickeralarm.mimics.MimicColorCaptureFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = super.onCreateView(inflater, container, savedInstanceState);

    Resources resources = getResources();

    String subscriptionKey = KeyUtilities.getToken(getActivity(), "vision");
    mVisionServiceRestClient = new VisionServiceRestClient(subscriptionKey);

    String[] questions = resources.getStringArray(R.array.vision_color_questions);
    TextView instruction = (TextView) view.findViewById(R.id.instruction_text);
    mQuestionColorName = questions[new Random().nextInt(questions.length)];
    instruction.setText(String.format(resources.getString(R.string.mimic_vision_prompt), mQuestionColorName));

    TypedArray colorCodeLower = resources.obtainTypedArray(resources
            .getIdentifier(mQuestionColorName + "_range_lower", "array", getActivity().getPackageName()));
    mQuestionColorRangeLower = new float[] { colorCodeLower.getFloat(0, 0f), colorCodeLower.getFloat(1, 0f),
            colorCodeLower.getFloat(2, 0f) };
    colorCodeLower.recycle();/*from w w  w  .ja  v  a  2s . c  o  m*/
    TypedArray colorCodeUpper = resources.obtainTypedArray(resources
            .getIdentifier(mQuestionColorName + "_range_upper", "array", getActivity().getPackageName()));
    mQuestionColorRangeUpper = new float[] { colorCodeUpper.getFloat(0, 0f), colorCodeUpper.getFloat(1, 0f),
            colorCodeUpper.getFloat(2, 0f) };
    colorCodeUpper.recycle();

    Logger.init(getActivity());
    Loggable playGameEvent = new Loggable.UserAction(Loggable.Key.ACTION_GAME_COLOR);
    Logger.track(playGameEvent);

    return view;
}

From source file:Steps.StepsFragment.java

/**
 * Determine if the sticker is new in order to set the top pulsing
 * "NEW" indicatior/* w w  w . ja  v a 2s.co  m*/
 * @param imageCategory
 * @param sticker
 */
private void determineCategoty(ImageView imageCategory, Sticker sticker) {
    //new Sticker
    if (sticker.getCount() == 0) {
        Resources resources = getActivity().getResources();
        int resourceId = resources.getIdentifier("neww", "drawable", getActivity().getPackageName());
        imageCategory.setImageBitmap(
                SampleImage.decodeSampledBitmapFromResource(getResources(), resourceId, 250, 250));
        //run the animation
        Animation pulse = AnimationUtils.loadAnimation(getActivity(), R.anim.pulse);
        pulse.setRepeatCount(Animation.INFINITE);
        imageCategory.startAnimation(pulse);
    }

}

From source file:com.android.leanlauncher.IconCache.java

public void loadIconPackDrawables(boolean forceReload) {
    final long t = SystemClock.uptimeMillis();
    synchronized (mIconPackDrawables) {
        if (!forceReload && mIconPackDrawables.size() > 0) {
            return;
        }// w  w w . j a v a  2s  .  c  o  m

        // load appfilter.xml from the icon pack package
        try {
            XmlPullParser xpp = null;

            final Resources iconPackRes = getIconPackResources();
            if (iconPackRes == null) {
                return;
            }

            int appfilterid = iconPackRes.getIdentifier("appfilter", "xml", mCurrentIconTheme);
            if (appfilterid > 0) {
                xpp = iconPackRes.getXml(appfilterid);
            } else {
                // no resource found, try to open it from assets folder
                try {
                    InputStream is = iconPackRes.getAssets().open("appfilter.xml");

                    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
                    factory.setNamespaceAware(true);
                    xpp = factory.newPullParser();
                    xpp.setInput(is, "utf-8");
                } catch (IOException e) {
                    Log.d(TAG, "Can't find appfilter.xml file in : " + mCurrentIconTheme);
                }
            }

            if (xpp != null) {
                int eventType = xpp.getEventType();
                while (eventType != XmlPullParser.END_DOCUMENT) {
                    if (eventType == XmlPullParser.START_TAG) {
                        if ("item".equals(xpp.getName())) {
                            String componentName = null;
                            String drawableName = null;

                            for (int i = 0; i < xpp.getAttributeCount(); i++) {
                                if ("component".equals(xpp.getAttributeName(i))) {
                                    componentName = xpp.getAttributeValue(i);
                                } else if ("drawable".equals(xpp.getAttributeName(i))) {
                                    drawableName = xpp.getAttributeValue(i);
                                }
                            }

                            if (TextUtils.isEmpty(componentName) || TextUtils.isEmpty(drawableName)) {
                                eventType = xpp.next();
                                continue;
                            }

                            try {
                                componentName = componentName.substring(componentName.indexOf('{') + 1,
                                        componentName.indexOf('}'));
                            } catch (StringIndexOutOfBoundsException e) {
                                Log.d(TAG, "Can't parse icon for package = " + componentName);
                                eventType = xpp.next();
                                continue;
                            }

                            ComponentName componentNameKey = ComponentName.unflattenFromString(componentName);
                            if (componentNameKey != null) {
                                mIconPackDrawables.put(componentNameKey, drawableName);
                            } else {
                                Log.d(TAG, "ComponentName can't be obtained from: " + componentName);
                            }
                        } else if ("iconback".equals(xpp.getName())) {
                            for (int i = 0; i < xpp.getAttributeCount(); i++) {
                                if (xpp.getAttributeName(i).startsWith("img")) {
                                    mIconBackgrounds.add(loadBitmapFromIconPack(xpp.getAttributeValue(i)));
                                }
                            }
                        } else if ("iconmask".equals(xpp.getName())) {
                            if (xpp.getAttributeCount() > 0 && "img1".equals(xpp.getAttributeName(0))) {
                                mIconMask = loadBitmapFromIconPack(xpp.getAttributeValue(0));
                            }
                        } else if ("iconupon".equals(xpp.getName())) {
                            if (xpp.getAttributeCount() > 0 && "img1".equals(xpp.getAttributeName(0))) {
                                mIconFront = loadBitmapFromIconPack(xpp.getAttributeValue(0));
                            }
                        } else if ("scale".equals(xpp.getName())) {
                            if (xpp.getAttributeCount() > 0 && "factor".equals(xpp.getAttributeName(0))) {
                                mIconScaleFactor = Float.valueOf(xpp.getAttributeValue(0));
                            }
                        }
                    }
                    eventType = xpp.next();
                }
            }
            Log.d(TAG, "Finished parsing icon pack: " + (SystemClock.uptimeMillis() - t) + "ms");
        } catch (XmlPullParserException e) {
            Log.d(TAG, "Cannot parse icon pack appfilter.xml" + e);
        } catch (IOException e) {
            Log.d(TAG, "Exception loading icon pack " + e);
        }
    }
}

From source file:com.vonglasow.michael.satstat.MapSectionFragment.java

/**
 * Updates internal data structures when the user's selection of location providers has changed.
 * @param providers The new set of location providers
 *//*www  .j  ava 2 s.  c  o  m*/
public void onLocationProvidersChanged(Set<String> providers) {
    Context context = this.getContext();
    List<String> allProviders = mainActivity.locationManager.getAllProviders();
    ArrayList<String> removedProviders = new ArrayList<String>();

    for (String pr : providerLocations.keySet())
        if (!providers.contains(pr))
            removedProviders.add(pr);

    // remove cached locations and invalidators for providers which are no longer selected
    for (String pr : removedProviders) {
        providerLocations.remove(pr);
        providerInvalidators.remove(pr);
    }

    // ensure there is a cached location for each chosen provider (can be null)
    for (String pr : providers) {
        if ((allProviders.indexOf(pr) >= 0) && !providerLocations.containsKey(pr)) {
            Location location = new Location("");
            providerLocations.put(pr, location);
        }
    }

    // add overlays
    updateLocationProviderStyles();

    mapCircles = new HashMap<String, Circle>();
    mapMarkers = new HashMap<String, Marker>();

    Log.d(TAG, "Provider location cache: " + providerLocations.keySet().toString());

    Layers layers = mapMap.getLayerManager().getLayers();

    // remove all layers other than tile render layer from map
    for (int i = 0; i < layers.size();)
        if ((layers.get(i) instanceof TileRendererLayer) || (layers.get(i) instanceof TileDownloadLayer)) {
            i++;
        } else {
            layers.remove(i);
        }

    for (String pr : providers) {
        // no invalidator for GPS, which is invalidated through GPS status
        if ((!pr.equals(LocationManager.GPS_PROVIDER)) && (providerInvalidators.get(pr)) == null) {
            final String provider = pr;
            final Context ctx = context;
            providerInvalidators.put(pr, new Runnable() {
                private String mProvider = provider;

                @Override
                public void run() {
                    Location location = providerLocations.get(mProvider);
                    if (location != null)
                        markLocationAsStale(location);
                    applyLocationProviderStyle(ctx, mProvider, LOCATION_PROVIDER_GRAY);
                }
            });
        }

        String styleName = assignLocationProviderStyle(pr);
        LatLong latLong;
        float acc;
        boolean visible;
        if ((providerLocations.get(pr) != null) && (providerLocations.get(pr).getProvider() != "")) {
            latLong = new LatLong(providerLocations.get(pr).getLatitude(),
                    providerLocations.get(pr).getLongitude());
            if (providerLocations.get(pr).hasAccuracy())
                acc = providerLocations.get(pr).getAccuracy();
            else
                acc = 0;
            visible = true;
            if (isLocationStale(providerLocations.get(pr)))
                styleName = LOCATION_PROVIDER_GRAY;
            Log.d("MainActivity", pr + " has " + latLong.toString());
        } else {
            latLong = new LatLong(0, 0);
            acc = 0;
            visible = false;
            Log.d("MainActivity", pr + " has no location, hiding");
        }

        // Circle layer
        Resources res = context.getResources();
        TypedArray style = res
                .obtainTypedArray(res.getIdentifier(styleName, "array", context.getPackageName()));
        Paint fill = AndroidGraphicFactory.INSTANCE.createPaint();
        float density = context.getResources().getDisplayMetrics().density;
        fill.setColor(style.getColor(STYLE_FILL, R.color.circle_gray_fill));
        fill.setStyle(Style.FILL);
        Paint stroke = AndroidGraphicFactory.INSTANCE.createPaint();
        stroke.setColor(style.getColor(STYLE_STROKE, R.color.circle_gray_stroke));
        stroke.setStrokeWidth(Math.max(1.5f * density, 1));
        stroke.setStyle(Style.STROKE);
        Circle circle = new Circle(latLong, acc, fill, stroke);
        mapCircles.put(pr, circle);
        layers.add(circle);
        circle.setVisible(visible);

        // Marker layer
        Drawable drawable = style.getDrawable(STYLE_MARKER);
        Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(drawable);
        Marker marker = new Marker(latLong, bitmap, 0, -bitmap.getHeight() * 9 / 20);
        mapMarkers.put(pr, marker);
        layers.add(marker);
        marker.setVisible(visible);
        style.recycle();
    }

    // move layers into view
    updateMap();
}

From source file:com.vonglasow.michael.satstat.ui.MapSectionFragment.java

/**
 * Applies a style to the map overlays associated with a given location provider.
 * /*ww  w.jav  a2s  .co m*/
 * This method changes the style (effectively, the color) of the circle and
 * marker overlays. Its main purpose is to switch the color of the overlays
 * between gray and the provider color.
 * 
 * @param context The context of the caller
 * @param provider The name of the location provider, as returned by
 * {@link LocationProvider.getName()}.
 * @param styleName The name of the style to apply. If it is null, the
 * default style for the provider as returned by 
 * assignLocationProviderStyle() is applied. 
 */
protected void applyLocationProviderStyle(Context context, String provider, String styleName) {
    String sn = (styleName != null) ? styleName : assignLocationProviderStyle(provider);

    Boolean isStyleChanged = !sn.equals(providerAppliedStyles.get(provider));
    Boolean needsRedraw = false;

    Resources res = context.getResources();
    TypedArray style = res.obtainTypedArray(res.getIdentifier(sn, "array", context.getPackageName()));

    // Circle layer
    Circle circle = mapCircles.get(provider);
    if (circle != null) {
        circle.getPaintFill().setColor(style.getColor(Const.STYLE_FILL, R.color.circle_gray_fill));
        circle.getPaintStroke().setColor(style.getColor(Const.STYLE_STROKE, R.color.circle_gray_stroke));
        needsRedraw = isStyleChanged && circle.isVisible();
    }

    //Marker layer
    Marker marker = mapMarkers.get(provider);
    if (marker != null) {
        Drawable drawable = style.getDrawable(Const.STYLE_MARKER);
        Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(drawable);
        marker.setBitmap(bitmap);
        needsRedraw = needsRedraw || (isStyleChanged && marker.isVisible());
    }

    if (needsRedraw)
        mapMap.getLayerManager().redrawLayers();
    providerAppliedStyles.put(provider, sn);
    style.recycle();
}

From source file:Steps.StepsFragment.java

private void showStickerMoreInfo(final Sticker clickedSticker) {
    // custom dialog
    clickedSticker.getName();/*from   w  w  w  .  j av a 2s. co  m*/
    Log.d("NAMe", clickedSticker.getName());

    final Dialog dialog = new Dialog(getActivity());

    dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            dialog.dismiss();
        }
    });

    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.BLACK));
    dialog.setContentView(R.layout.sticker_dialog);
    ImageView image = (ImageView) (dialog).findViewById(R.id.image);

    //get the correct image
    String file = clickedSticker.getImagesrc();
    file = file.substring(0, file.lastIndexOf(".")); //trim the extension
    Resources resources = getActivity().getResources();
    int resourceId = resources.getIdentifier(file, "drawable", getActivity().getPackageName());
    image.setImageBitmap(SampleImage.decodeSampledBitmapFromResource(getResources(), resourceId, 250, 250));

    //load the additional details and information
    TextView id = (TextView) (dialog).findViewById(R.id.sticker_id);
    id.setText("#" + Integer.toString(clickedSticker.getId()));

    TextView status = (TextView) (dialog).findViewById(R.id.sticker_status);
    //at this poinrt only glued and notSticker available glued=1 notGlued=0
    String statuss = clickedSticker.getStatus().equals(2) ? "1" : "0";
    Integer count = clickedSticker.getCount();
    status.setText("(" + statuss + " glued, " + count + " left)");

    TextView title = (TextView) (dialog).findViewById(R.id.sticker_title);
    title.setText(clickedSticker.getName());

    TextView rarity = (TextView) (dialog).findViewById(R.id.rarity);
    rarity.setText(clickedSticker.getPopularity());

    TextView movie = (TextView) (dialog).findViewById(R.id.sticker_movie);
    movie.setText(clickedSticker.getMovie());
    //set the layout to have the same widh and height as the  windows screen

    Display display = getActivity().getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    int height = size.y;

    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(dialog.getWindow().getAttributes());
    lp.width = width;
    lp.height = height;
    dialog.getWindow().setAttributes(lp);
    RelativeLayout mainLayout = (RelativeLayout) dialog.findViewById(R.id.showStickerLayout);
    dialog.show();
    // if button is clicked, close the custom dialog
    mainLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();

        }

    });
    //listen for the inf tab
    ImageView info = (ImageView) (dialog).findViewById(R.id.info_image);
    info.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showInfoDialog(clickedSticker);
        }

    });

}

From source file:Steps.StepsFragment.java

private void showNewSticker(final Sticker sticker_1, final Sticker sticker_2, final Sticker sticker_3) {
    // custom dialog

    final Dialog dialog = new Dialog(getActivity());

    dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override/*from   w  w w .ja  va2s  .  com*/
        public void onCancel(DialogInterface dialog) {
            dialog.dismiss();
        }
    });

    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    dialog.setContentView(R.layout.new_stickers_dialog);
    //get the correct image -1st sticker

    ImageView image = (ImageView) (dialog).findViewById(R.id.sticker1);
    image.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            showStickerMoreInfo(sticker_1);
        }
    });
    String file = sticker_1.getImagesrc();
    file = file.substring(0, file.lastIndexOf(".")); //trim the extension
    Resources resources = getActivity().getResources();
    int resourceId = resources.getIdentifier(file, "drawable", getActivity().getPackageName());
    TextView number = (TextView) (dialog).findViewById(R.id.text_sticker1);
    number.setText("#" + Integer.toString(sticker_1.getId()));
    RelativeLayout image_layout = (RelativeLayout) (dialog).findViewById(R.id.sticker1_layout);
    ImageView imageCategory = (ImageView) (dialog).findViewById(R.id.category_image1);
    determineCategoty(imageCategory, sticker_1);
    determinePicture(sticker_1, image, resourceId);
    animate(image_layout, 3000);

    //get the correct image -2nd sticker
    ImageView image2 = (ImageView) (dialog).findViewById(R.id.sticker2);
    image2.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            showStickerMoreInfo(sticker_2);
        }
    });
    String file2 = sticker_2.getImagesrc();
    file2 = file2.substring(0, file2.lastIndexOf(".")); //trim the extension
    Resources resources2 = getActivity().getResources();
    int resourceId2 = resources2.getIdentifier(file2, "drawable", getActivity().getPackageName());
    TextView number2 = (TextView) (dialog).findViewById(R.id.text_sticker2);
    number2.setText("#" + Integer.toString(sticker_2.getId()));
    RelativeLayout image_layout2 = (RelativeLayout) (dialog).findViewById(R.id.sticker2_layout);
    ImageView imageCategory2 = (ImageView) (dialog).findViewById(R.id.category_image2);
    determineCategoty(imageCategory2, sticker_2);
    determinePicture(sticker_2, image2, resourceId2);
    animate(image_layout2, 3000);

    //get the correct image -3rd sticker
    ImageView image3 = (ImageView) (dialog).findViewById(R.id.sticker3);
    image3.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            showStickerMoreInfo(sticker_3);
        }
    });
    String file3 = sticker_3.getImagesrc();
    file3 = file3.substring(0, file3.lastIndexOf(".")); //trim the extension
    Resources resources3 = getActivity().getResources();
    int resourceId3 = resources3.getIdentifier(file3, "drawable", getActivity().getPackageName());

    TextView number3 = (TextView) (dialog).findViewById(R.id.text_sticker3);
    number3.setText("#" + Integer.toString(sticker_3.getId()));
    RelativeLayout image_layout3 = (RelativeLayout) (dialog).findViewById(R.id.sticker3_layout);
    ImageView imageCategory3 = (ImageView) (dialog).findViewById(R.id.category_image3);
    determineCategoty(imageCategory3, sticker_3);
    determinePicture(sticker_3, image3, resourceId3);
    animate(image_layout3, 3000);

    Display display = getActivity().getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    int height = size.y;

    //set the layout to have the same widh and height as the  windows screen
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(dialog.getWindow().getAttributes());
    lp.width = width;
    lp.height = height;
    dialog.getWindow().setAttributes(lp);
    RelativeLayout mainLayout = (RelativeLayout) dialog.findViewById(R.id.showStickerLayout);
    dialog.show();
    // if button is clicked, close the custom dialog
    Button doneButton = (Button) (dialog).findViewById(R.id.doneButton);
    doneButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();

        }

    });
}

From source file:bluetoothchat.BluetoothChatFragment.java

private int getImageResourceIdForStickerName(String stickerName) {
    Database db = Database.getInstance(getActivity());
    Sticker sticker = db.getStickerForName(String.valueOf(stickerName));
    String file = sticker.getImagesrc();
    Resources resources = getActivity().getResources();
    //trim the extension
    file = file.substring(0, file.lastIndexOf("."));
    return resources.getIdentifier(file, "drawable", getActivity().getPackageName());
}