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.aosijia.dragonbutler.ui.widget.ActionSheet.java

public static int getNavBarHeight(Activity activity) {
    Resources resources = activity.getResources();
    int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
    //?NavigationBar
    int height = resources.getDimensionPixelSize(resourceId);
    return height;
}

From source file:org.bottiger.podcast.utils.UIUtils.java

public static int NavigationBarHeight(Context context) {
    Resources resources = context.getResources();
    int orientation = resources.getConfiguration().orientation;

    int id = resources.getIdentifier(orientation == Configuration.ORIENTATION_PORTRAIT ? "navigation_bar_height"
            : "navigation_bar_height_landscape", "dimen", "android");
    if (id > 0) {
        return resources.getDimensionPixelSize(id);
    }// w  w  w.  ja  v a 2 s.  c o  m
    return 0;
}

From source file:com.waz.zclient.utils.ViewUtils.java

public static int getNavigationBarHeight(Context context) {
    Resources resources = context.getResources();
    String name = ViewUtils.isInPortrait(context) ? "navigation_bar_height" : "navigation_bar_height_landscape";
    int resourceId = resources.getIdentifier(name, "dimen", "android");
    if (resourceId > 0) {
        return resources.getDimensionPixelSize(resourceId);
    }/*from w  w  w .ja v  a 2 s  .  c  om*/
    return 0;
}

From source file:com.google.android.gms.common.internal.zzt.java

@Nullable
private static String a(final Context context, final String s) {
    while (true) {
        final int identifier;
        Label_0114: {//  w  w w  . j av a2 s  .com
            synchronized (zzt.a) {
                final String s2 = zzt.a.get(s);
                String string;
                if (s2 != null) {
                    // monitorexit(zzt.a)
                    string = s2;
                } else {
                    final Resources remoteResource = GooglePlayServicesUtil.getRemoteResource(context);
                    if (remoteResource == null) {
                        // monitorexit(zzt.a)
                        string = null;
                    } else {
                        identifier = remoteResource.getIdentifier(s, "string", "com.google.android.gms");
                        if (identifier != 0) {
                            break Label_0114;
                        }
                        final String value = String.valueOf(s);
                        String concat;
                        if (value.length() != 0) {
                            concat = "Missing resource: ".concat(value);
                        } else {
                            concat = new String("Missing resource: ");
                        }
                        Log.w("GoogleApiAvailability", concat);
                        // monitorexit(zzt.a)
                        string = null;
                    }
                }
                return string;
            }
        }
        final Resources resources;
        String string = resources.getString(identifier);
        if (TextUtils.isEmpty((CharSequence) string)) {
            final String value2 = String.valueOf(s);
            String concat2;
            if (value2.length() != 0) {
                concat2 = "Got empty resource: ".concat(value2);
            } else {
                concat2 = new String("Got empty resource: ");
            }
            Log.w("GoogleApiAvailability", concat2);
            // monitorexit(simpleArrayMap)
            string = null;
            return string;
        }
        zzt.a.put(s, string);
        // monitorexit(simpleArrayMap)
        return string;
    }
}

From source file:tr.com.turkcellteknoloji.turkcellupdater.Utilities.java

static int getResourceIdByName(Context context, String type, String name) {
    final Resources resources = context.getResources();
    final int id = resources.getIdentifier(name, type, context.getPackageName());
    return id;/*from   ww  w .java 2s . com*/
}

From source file:tv.ouya.sdk.OuyaUnityPlugin.java

public static String getStringResource(String name) {
    final Activity activity = IOuyaActivity.GetActivity();
    if (null == activity) {
        return "";
    }/*  www . jav  a2s . c  o  m*/
    Resources resources = activity.getResources();
    if (null == resources) {
        return "";
    }
    int id = resources.getIdentifier(name, "string", activity.getPackageName());
    if (id <= 0) {
        return "";
    }
    return resources.getString(id);
}

From source file:com.entertailion.android.slideshow.utils.Utils.java

/**
 * Load the list of featured photo web sites from embedded XML file.
 * /*  www.j  av a2 s .co  m*/
 * @see res/xml/sites.xml
 * 
 * @param context
 * @return
 */
public static ArrayList<SiteInfo> getSites(Context context) {
    ArrayList<SiteInfo> sites = new ArrayList<SiteInfo>();
    XmlResourceParser parser = null;
    try {
        Resources r = context.getResources();
        int resourceId = r.getIdentifier("sites", "xml", "com.entertailion.android.slideshow");
        if (resourceId != 0) {
            parser = context.getResources().getXml(resourceId); // R.xml.sites
            parser.next();
            int eventType = parser.getEventType();
            while (eventType != XmlPullParser.END_DOCUMENT) {
                if (eventType == XmlPullParser.START_TAG) {
                    switch (eventType) {
                    case XmlPullParser.START_DOCUMENT:
                        break;
                    case XmlPullParser.START_TAG:
                        String tagName = parser.getName();
                        if (tagName.equalsIgnoreCase("site")) {
                            String name = parser.getAttributeValue(null, "name");
                            String url = parser.getAttributeValue(null, "url");
                            sites.add(new SiteInfo(name, url));
                        }
                        break;
                    }
                }
                eventType = parser.next();
            }
        }
    } catch (Exception e) {
        Log.e(LOG_TAG, "getSites", e);
    } finally {
        if (parser != null) {
            parser.close();
        }
    }
    return sites;
}

From source file:jahirfiquitiva.iconshowcase.utilities.Utils.java

public static int getIconResId(Context context, Resources r, String p, String name, String task) {
    int res = r.getIdentifier(name, "drawable", p);
    if (res != 0) {
        return res;
    } else {//from  w w  w  .  j a v  a 2s.  co m
        if (task != null) {
            showLog(context, task, "Missing icon: " + name);
        } else {
            showLog(context, "Missing icon: " + name);
        }
        return 0;
    }
}

From source file:com.geomoby.geodeals.DemoService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//*from www .  ja v a  2  s.  c  om*/
private static void generateNotification(Context context, String message) {
    if (message.length() > 0) {

        // Parse the GeoMoby message using the GeoMessage class
        try {
            Gson gson = new Gson();
            JsonParser parser = new JsonParser();
            JsonArray Jarray = parser.parse(message).getAsJsonArray();
            ArrayList<GeoMessage> alerts = new ArrayList<GeoMessage>();
            for (JsonElement obj : Jarray) {
                GeoMessage gName = gson.fromJson(obj, GeoMessage.class);
                alerts.add(gName);
            }

            // Prepare Notification and pass the GeoMessage to an Extra
            NotificationManager notificationManager = (NotificationManager) context
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            Intent i = new Intent(context, CustomNotification.class);
            i.putParcelableArrayListExtra("GeoMessage", (ArrayList<GeoMessage>) alerts);
            PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, i,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            // Read from the /assets directory
            Resources resources = context.getResources();
            AssetManager assetManager = resources.getAssets();
            try {
                InputStream inputStream = assetManager.open("geomoby.properties");
                Properties properties = new Properties();
                properties.load(inputStream);
                String push_icon = properties.getProperty("push_icon");
                int icon = resources.getIdentifier(push_icon, "drawable", context.getPackageName());
                int not_title = resources.getIdentifier("notification_title", "string",
                        context.getPackageName());
                int not_text = resources.getIdentifier("notification_text", "string", context.getPackageName());
                int not_ticker = resources.getIdentifier("notification_ticker", "string",
                        context.getPackageName());

                // Manage notifications differently according to Android version
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

                    builder.setSmallIcon(icon).setContentTitle(context.getResources().getText(not_title))
                            .setContentText(context.getResources().getText(not_text))
                            .setTicker(context.getResources().getText(not_ticker))
                            .setContentIntent(pendingIntent).setAutoCancel(true);

                    builder.setDefaults(Notification.DEFAULT_ALL); //Vibrate, Sound and Led

                    // Because the ID remains unchanged, the existing notification is updated.
                    notificationManager.notify(notifyID, builder.build());

                } else {
                    Notification notification = new Notification(icon, context.getResources().getText(not_text),
                            System.currentTimeMillis());

                    //Setting Notification Flags
                    notification.defaults |= Notification.DEFAULT_ALL;
                    notification.flags |= Notification.FLAG_AUTO_CANCEL;

                    //Set the Notification Info
                    notification.setLatestEventInfo(context, context.getResources().getText(not_text),
                            context.getResources().getText(not_ticker), pendingIntent);

                    //Send the notification
                    // Because the ID remains unchanged, the existing notification is updated.
                    notificationManager.notify(notifyID, notification);
                }
            } catch (IOException e) {
                System.err.println("Failed to open geomoby property file");
                e.printStackTrace();
            }
        } catch (JsonParseException e) {
            Log.i(TAG, "This is not a GeoMoby notification");
            throw new RuntimeException(e);
        }
    }
}

From source file:com.linkbubble.util.Util.java

public static Integer getSystemStatusBarHeight(Context context) {
    Integer result = null;//from   w w  w.  j a  va2s. co m
    try {
        Resources resources = context.getResources();
        int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            result = resources.getDimensionPixelSize(resourceId);
        }
    } catch (Exception e) {
    }

    return result;
}