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.example.pagergallerysample.PagerGalleryAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {

    View root = mInflater.inflate(R.layout.item, null);
    ImageView img = (ImageView) root.findViewById(R.id.item_img);
    Resources res = mContext.get().getResources();
    int resId = res.getIdentifier("item" + (position + 1), "drawable", mContext.get().getPackageName());
    img.setImageResource(resId);// w w w .ja  v  a2 s  . c  o m
    TextView txt = (TextView) root.findViewById(R.id.item_label);
    txt.setText("item " + (position + 1));
    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(100,
            RelativeLayout.LayoutParams.MATCH_PARENT);
    root.setLayoutParams(lp);
    container.addView(root);
    return root;
}

From source file:com.github.piasy.chatrecyclerview.example.InputDialogFragment.java

@Override
public void onStart() {
    super.onStart();
    Window window = getDialog().getWindow();
    window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    window.setBackgroundDrawableResource(android.R.color.transparent);

    final Resources res = getResources();
    final int titleDividerId = res.getIdentifier("titleDivider", "id", "android");
    if (titleDividerId > 0) {
        final View titleDivider = getDialog().findViewById(titleDividerId);
        if (titleDivider != null) {
            titleDivider.setBackgroundColor(res.getColor(android.R.color.transparent));
        }//from ww  w.j  av  a  2 s.  c o  m
    }
}

From source file:com.teisentraeger.populationquiz.ItemAdapter.java

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    super.onBindViewHolder(holder, position);
    String text = mItemList.get(position).second.name;
    holder.mText.setText(text);//from w  ww  . ja va2 s .c om

    holder.itemView.setTag(text);

    Resources res = mContext.getResources();
    int resID = res.getIdentifier(mItemList.get(position).second.getFilename(), "drawable",
            mContext.getPackageName());
    holder.mImage.setImageResource(resID);

}

From source file:com.nttec.everychan.ui.presentation.HtmlParser.java

private static void endFont(SpannableStringBuilder text) {
    int len = text.length();
    Object obj = getLast(text, Font.class);
    int where = text.getSpanStart(obj);

    text.removeSpan(obj);//from   w  ww  .j  a  va  2  s . c om

    if (where != len) {
        Font f = (Font) obj;

        if (!TextUtils.isEmpty(f.mColor)) {
            if (f.mColor.startsWith("@")) {
                Resources res = Resources.getSystem();
                String name = f.mColor.substring(1);
                int colorRes = res.getIdentifier(name, "color", "android");
                if (colorRes != 0) {
                    ColorStateList colors = CompatibilityUtils.getColorStateList(res, colorRes);
                    text.setSpan(new TextAppearanceSpan(null, 0, 0, colors, null), where, len,
                            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
            } else {
                int c = ColorHidden.getHtmlColor(f.mColor);
                if (c != -1) {
                    text.setSpan(new ForegroundColorSpan(c | 0xFF000000), where, len,
                            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
            }
        }

        if (f.mFace != null) {
            text.setSpan(new TypefaceSpan(f.mFace), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        if (f.mStyle != null) {
            List<Object> styleSpans = parseStyleAttributes(f.mStyle);
            for (Object span : styleSpans) {
                text.setSpan(span, where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
    }
}

From source file:com.atwal.wakeup.battery.util.Utilities.java

public static int getInternalDimensionSize(Resources res, String key) {
    int result = 0;
    int resourceId = res.getIdentifier(key, "dimen", "android");
    if (resourceId > 0) {
        result = res.getDimensionPixelSize(resourceId);
    }//from w  ww . jav a2s  .  c  o m
    return result;
}

From source file:com.atwal.wakeup.battery.util.Utilities.java

@TargetApi(14)
public static boolean hasNavBar(Context context) {
    final String SHOW_NAV_BAR_RES_NAME = "config_showNavigationBar";
    String sNavBarOverride = null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        try {/*ww w .j ava  2 s .c o m*/
            Class c = Class.forName("android.os.SystemProperties");
            Method m = c.getDeclaredMethod("get", String.class);
            m.setAccessible(true);
            sNavBarOverride = (String) m.invoke(null, "qemu.hw.mainkeys");
        } catch (Throwable e) {
            sNavBarOverride = null;
        }
    }
    Resources res = context.getResources();
    int resourceId = res.getIdentifier(SHOW_NAV_BAR_RES_NAME, "bool", "android");
    if (resourceId != 0) {
        boolean hasNav = res.getBoolean(resourceId);
        // check override flag (see static block)
        if ("1".equals(sNavBarOverride)) {
            hasNav = false;
        } else if ("0".equals(sNavBarOverride)) {
            hasNav = true;
        }
        return hasNav;
    } else { // fallback
        return !ViewConfiguration.get(context).hasPermanentMenuKey();
    }
}

From source file:me.tassoevan.cordova.ForegroundService.java

private int getIconResId() {
    Context context = getApplicationContext();
    Resources res = context.getResources();
    String pkgName = context.getPackageName();

    return res.getIdentifier("icon", "drawable", pkgName);
}

From source file:com.github.piasy.chatrecyclerview.example.InputDialog.java

@Override
public void onStart() {
    super.onStart();
    // without title and title divider

    // Less dimmed background; see http://stackoverflow.com/q/13822842/56285
    Window window = getDialog().getWindow();
    WindowManager.LayoutParams params = window.getAttributes();
    //CHECKSTYLE:OFF
    params.dimAmount = 0;/*ww  w .  j ava2s  . co  m*/
    //CHECKSTYLE:ON
    window.setAttributes(params);

    window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    window.setGravity(Gravity.BOTTOM);

    // Transparent background; see http://stackoverflow.com/q/15007272/56285
    // (Needed to make dialog's alpha shadow look good)
    window.setBackgroundDrawableResource(android.R.color.transparent);

    final Resources res = getResources();
    final int titleDividerId = res.getIdentifier("titleDivider", "id", "android");
    if (titleDividerId > 0) {
        final View titleDivider = getDialog().findViewById(titleDividerId);
        if (titleDivider != null) {
            titleDivider.setBackgroundColor(res.getColor(android.R.color.transparent));
        }
    }
}

From source file:net.sf.sprockets.database.sqlite.DbOpenHelper.java

@Override
public void onCreate(SQLiteDatabase db) {
    Resources res = mContext.getResources();
    if (mCreate == 0) {
        mCreate = res.getIdentifier("create_tables", "raw", mContext.getPackageName());
    }//from  w  w w . ja va2s.  c  o m
    try {
        execScript(db, res, mCreate);
    } catch (IOException e) {
        throw new RuntimeException("creating database", e);
    }
}

From source file:com.iniciacomunicacion.devicenotification.DeviceNotification.java

/**
 * Adds notification//from w  w w.j av  a 2  s  .c o  m
 * 
 * @param callbackContext, Callback context of the request from Cordova
 * @param title, The title of notification
 * @param message, The content text of the notification
 * @param Id, The unique ID of the notification
 * @param seconds
 */
public void add(CallbackContext callbackContext, String ticker, String title, String message, int id) {

    Resources res = DeviceNotification.context.getResources();
    int ic_launcher = res.getIdentifier("icon", "drawable", cordova.getActivity().getPackageName());

    /* Version 4.x
    NotificationManager notificationManager = (NotificationManager)DeviceNotification.activity.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification.Builder(DeviceNotification.Context)
    .setTicker(ticker)
    .setContentTitle(title)
    .setContentText(message)
    .setSmallIcon(ic_launcher)
    .setWhen(System.currentTimeMillis())
    .setAutoCancel(true)
    .build();
    notification.flags = Notification.FLAG_AUTO_CANCEL | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND;
    notificationManager.notify(id, notification);*/

    //Version 2.x
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(DeviceNotification.activity)
            .setSmallIcon(ic_launcher).setWhen(System.currentTimeMillis()).setContentTitle(title)
            .setContentText(message).setTicker(ticker);
    Intent resultIntent = new Intent(DeviceNotification.activity, DeviceNotification.activity.getClass());
    PendingIntent resultPendingIntent = PendingIntent.getActivity(DeviceNotification.activity, 0, resultIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotifyMgr = (NotificationManager) DeviceNotification.activity
            .getSystemService(android.content.Context.NOTIFICATION_SERVICE);
    mNotifyMgr.notify(id, mBuilder.build());
}