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:cn.wyx.android.swipeback.swipe.SwipeBackLayout.java

private int getNavigationBarHeight() {
    Resources resources = getResources();
    int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
    //?NavigationBar
    return resources.getDimensionPixelSize(resourceId);
}

From source file:org.chromium.ChromeNotifications.java

private void makeNotification(final CordovaArgs args) throws JSONException {
    String notificationId = args.getString(0);
    JSONObject options = args.getJSONObject(1);
    Resources resources = cordova.getActivity().getResources();
    Bitmap largeIcon = makeBitmap(options.getString("iconUrl"),
            resources.getDimensionPixelSize(android.R.dimen.notification_large_icon_width),
            resources.getDimensionPixelSize(android.R.dimen.notification_large_icon_height));
    int smallIconId = resources.getIdentifier("notification_icon", "drawable",
            cordova.getActivity().getPackageName());
    if (smallIconId == 0) {
        smallIconId = resources.getIdentifier("icon", "drawable", cordova.getActivity().getPackageName());
    }/* w w w . j av  a2s.c  om*/
    NotificationCompat.Builder builder = new NotificationCompat.Builder(cordova.getActivity())
            .setSmallIcon(smallIconId).setContentTitle(options.getString("title"))
            .setContentText(options.getString("message")).setLargeIcon(largeIcon)
            .setPriority(options.optInt("priority"))
            .setContentIntent(makePendingIntent(NOTIFICATION_CLICKED_ACTION, notificationId, -1,
                    PendingIntent.FLAG_CANCEL_CURRENT))
            .setDeleteIntent(makePendingIntent(NOTIFICATION_CLOSED_ACTION, notificationId, -1,
                    PendingIntent.FLAG_CANCEL_CURRENT));
    double eventTime = options.optDouble("eventTime");
    if (eventTime != 0) {
        builder.setWhen(Math.round(eventTime));
    }
    JSONArray buttons = options.optJSONArray("buttons");
    if (buttons != null) {
        for (int i = 0; i < buttons.length(); i++) {
            JSONObject button = buttons.getJSONObject(i);
            builder.addAction(android.R.drawable.ic_dialog_info, button.getString("title"), makePendingIntent(
                    NOTIFICATION_BUTTON_CLICKED_ACTION, notificationId, i, PendingIntent.FLAG_CANCEL_CURRENT));
        }
    }
    String type = options.getString("type");
    Notification notification;
    if ("image".equals(type)) {
        NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle(builder);
        String bigImageUrl = options.optString("imageUrl");
        if (!bigImageUrl.isEmpty()) {
            bigPictureStyle.bigPicture(makeBitmap(bigImageUrl, 0, 0));
        }
        notification = bigPictureStyle.build();
    } else if ("list".equals(type)) {
        NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(builder);
        JSONArray items = options.optJSONArray("items");
        if (items != null) {
            for (int i = 0; i < items.length(); i++) {
                JSONObject item = items.getJSONObject(i);
                inboxStyle.addLine(Html.fromHtml("<b>" + item.getString("title")
                        + "</b>&nbsp;&nbsp;&nbsp;&nbsp;" + item.getString("message")));
            }
        }
        notification = inboxStyle.build();
    } else {
        if ("progress".equals(type)) {
            int progress = options.optInt("progress");
            builder.setProgress(100, progress, false);
        }
        NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle(builder);
        bigTextStyle.bigText(options.getString("message"));
        notification = bigTextStyle.build();
    }
    notificationManager.notify(notificationId.hashCode(), notification);
}

From source file:com.taobao.weex.extend.module.actionsheet.WXActionSheet.java

private boolean checkDeviceHasNavigationBar(Context context) {
    boolean hasNavigationBar = false;
    Resources rs = context.getResources();
    int id = rs.getIdentifier("config_showNavigationBar", "bool", "android");
    if (id > 0) {
        hasNavigationBar = rs.getBoolean(id);
    }//from   www . j  ava  2  s . c  o  m
    try {
        Class systemPropertiesClass = Class.forName("android.os.SystemProperties");
        Method m = systemPropertiesClass.getMethod("get", String.class);
        String navBarOverride = (String) m.invoke(systemPropertiesClass, "qemu.hw.mainkeys");
        if ("1".equals(navBarOverride)) {
            hasNavigationBar = false;
        } else if ("0".equals(navBarOverride)) {
            hasNavigationBar = true;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return hasNavigationBar;
}

From source file:com.thinkman.thinkutils.view.ActionSheet.java

public int getNavBarHeight(Context c) {
    int result = 0;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        boolean hasMenuKey = ViewConfiguration.get(c).hasPermanentMenuKey();
        boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);

        if (!hasMenuKey && !hasBackKey) {
            //The device has a navigation bar
            Resources resources = c.getResources();

            int orientation = getResources().getConfiguration().orientation;
            int resourceId;
            if (isTablet(c)) {
                resourceId = resources.getIdentifier(
                        orientation == Configuration.ORIENTATION_PORTRAIT ? "navigation_bar_height"
                                : "navigation_bar_height_landscape",
                        "dimen", "android");
            } else {
                resourceId = resources.getIdentifier(
                        orientation == Configuration.ORIENTATION_PORTRAIT ? "navigation_bar_height"
                                : "navigation_bar_width",
                        "dimen", "android");
            }/*from ww w  . ja va 2s.co m*/

            if (resourceId > 0) {
                return getResources().getDimensionPixelSize(resourceId);
            }
        }
    }
    return result;
}

From source file:de.appplant.cordova.plugin.emailcomposer.EmailComposer.java

/**
 * @return/*from  ww w .  j a  v a  2s  .  c o  m*/
 *      The resource ID for the given resource.
 */
private int getResId(String resPath) {
    Resources res = cordova.getActivity().getResources();

    String pkgName = getPackageName();
    String dirName = resPath.substring(0, resPath.lastIndexOf('/'));
    String fileName = resPath.substring(resPath.lastIndexOf('/') + 1);
    String resName = fileName.substring(0, fileName.lastIndexOf('.'));

    int resId = res.getIdentifier(resName, dirName, pkgName);

    return resId;
}

From source file:de.appplant.cordova.plugin.notification.Asset.java

/**
 * @return The resource ID for the given resource.
 *//*w  ww .j  a  va  2  s.  co  m*/
private int getResId(String resPath) {
    Resources res = activity.getResources();
    int resId;
    String pkgName = getPackageName();
    String dirName = "drawable";
    String fileName = resPath;
    if (resPath.contains("/")) {
        dirName = resPath.substring(0, resPath.lastIndexOf('/'));
        fileName = resPath.substring(resPath.lastIndexOf('/') + 1);
    }
    String resName = fileName.substring(0, fileName.lastIndexOf('.'));
    resId = res.getIdentifier(resName, dirName, pkgName);
    if (resId == 0) {
        resId = res.getIdentifier(resName, "drawable", pkgName);
    }
    return resId;
}

From source file:com.wewow.MainActivity.java

public static boolean checkDeviceHasNavigationBar(Context context) {
    boolean hasNavigationBar = false;
    Resources rs = context.getResources();
    int id = rs.getIdentifier("config_showNavigationBar", "bool", "android");
    if (id > 0) {
        hasNavigationBar = rs.getBoolean(id);
    }// w ww  .  ja va  2  s  .c  o m
    try {
        Class systemPropertiesClass = Class.forName("android.os.SystemProperties");
        Method m = systemPropertiesClass.getMethod("get", String.class);
        String navBarOverride = (String) m.invoke(systemPropertiesClass, "qemu.hw.mainkeys");
        if ("1".equals(navBarOverride)) {
            hasNavigationBar = false;
        } else if ("0".equals(navBarOverride)) {
            hasNavigationBar = true;
        }
    } catch (Exception e) {

    }
    return hasNavigationBar;

}

From source file:com.ramzcalender.RWeekCalendar.java

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    nowView.setVisibility(View.GONE);

    /**/*from   w  w w .  j  a  va2  s.  c  o m*/
     * Checking for any customization values
     */

    if (getArguments().containsKey(CALENDER_BACKGROUND)) {

        mBackground.setBackgroundColor(getArguments().getInt(CALENDER_BACKGROUND));

    }

    if (getArguments().containsKey(DATE_SELECTOR_BACKGROUND)) {

        selectorDateIndicatorValue = getArguments().getString(DATE_SELECTOR_BACKGROUND);

    }

    if (getArguments().containsKey(CURRENT_DATE_BACKGROUND)) {

        currentDateIndicatorValue = getArguments().getInt(CURRENT_DATE_BACKGROUND);

    }

    if (getArguments().containsKey(CALENDER_TYPE)) {

        calenderType = getArguments().getInt(CALENDER_TYPE);
    }

    if (getArguments().containsKey(PRIMARY_BACKGROUND)) {

        monthView.setTextColor(getArguments().getInt(PRIMARY_BACKGROUND));
        primaryTextColor = getArguments().getInt(PRIMARY_BACKGROUND);

    }

    if (getArguments().containsKey(SECONDARY_BACKGROUND)) {

        nowView.setTextColor(getArguments().getInt(SECONDARY_BACKGROUND));
        sundayTv.setTextColor(getArguments().getInt(SECONDARY_BACKGROUND));
        mondayTv.setTextColor(getArguments().getInt(SECONDARY_BACKGROUND));
        tuesdayTv.setTextColor(getArguments().getInt(SECONDARY_BACKGROUND));
        wednesdayTv.setTextColor(getArguments().getInt(SECONDARY_BACKGROUND));
        thursdayTv.setTextColor(getArguments().getInt(SECONDARY_BACKGROUND));
        fridayTv.setTextColor(getArguments().getInt(SECONDARY_BACKGROUND));
        saturdayTv.setTextColor(getArguments().getInt(SECONDARY_BACKGROUND));

    }

    if (getArguments().containsKey(PACKAGENAME)) {

        PAKAGENAMEVALUE = getArguments().getString(PACKAGENAME);//its for showing the resource value from the parent package

    }

    if (getArguments().containsKey(NOW_BACKGROUND)) {

        Resources resources = getResources();
        nowView.setBackgroundResource(resources.getIdentifier(
                getArguments().getString(RWeekCalendar.NOW_BACKGROUND), "drawable", PAKAGENAMEVALUE));

    }

    //----------------------------------------------------------------------------------------------//

    /*If the selected calender is FDF Calender the resent the day names according to the starting days*/
    if (calenderType != NORMAL_CALENDER) {
        int startingDate = new LocalDateTime().dayOfWeek().get();
        if (startingDate == 1) {

            sundayTv.setText("Mon");
            mondayTv.setText("Tue");
            tuesdayTv.setText("Wed");
            wednesdayTv.setText("Thu");
            thursdayTv.setText("Fri");
            fridayTv.setText("Sat");
            saturdayTv.setText("Sun");

        } else if (startingDate == 2) {

            sundayTv.setText("Tue");
            mondayTv.setText("Wed");
            tuesdayTv.setText("Thu");
            wednesdayTv.setText("Fri");
            thursdayTv.setText("Sat");
            fridayTv.setText("Sun");
            saturdayTv.setText("Mon");

        } else if (startingDate == 3) {

            sundayTv.setText("Wed");
            mondayTv.setText("Thu");
            tuesdayTv.setText("Fri");
            wednesdayTv.setText("Sat");
            thursdayTv.setText("Sun");
            fridayTv.setText("Mon");
            saturdayTv.setText("Tue");

        } else if (startingDate == 4) {

            sundayTv.setText("Thu");
            mondayTv.setText("Fri");
            tuesdayTv.setText("Sat");
            wednesdayTv.setText("Sun");
            thursdayTv.setText("Mon");
            fridayTv.setText("Tue");
            saturdayTv.setText("Wed");

        } else if (startingDate == 5) {

            sundayTv.setText("Fri");
            mondayTv.setText("Sat");
            tuesdayTv.setText("Sun");
            wednesdayTv.setText("Mon");
            thursdayTv.setText("Tue");
            fridayTv.setText("Wed");
            saturdayTv.setText("Thu");

        } else if (startingDate == 6) {

            sundayTv.setText("Sat");
            mondayTv.setText("Sun");
            tuesdayTv.setText("Mon");
            wednesdayTv.setText("Tue");
            thursdayTv.setText("Wed");
            fridayTv.setText("Thu");
            saturdayTv.setText("Fri");

        }
    }

    /*Setting Calender Adaptor*/

    mAdaptor = new CalenderAdaptor(getActivity().getSupportFragmentManager());
    pager.setAdapter(mAdaptor);

    /*CalUtil is called*/

    CalUtil mCal = new CalUtil();
    //date calculation called according to the typr
    if (calenderType != NORMAL_CALENDER) {
        mCal.calculate(mStartDate, FDF_CALENDER);
    } else {
        mCal.calculate(mStartDate, NORMAL_CALENDER);
    }

    mStartDate = mCal.getStartDate();//sets start date from CalUtil

    //Setting the month name and selected date listener
    monthView.setText(selectedDate.monthOfYear().getAsShortText() + " "
            + selectedDate.year().getAsShortText().toUpperCase());
    calenderListener.onSelectDate(selectedDate);

    CURRENT_WEEK_POSITION = Weeks.weeksBetween(mStartDate, selectedDate).getWeeks();

    pager.setCurrentItem(CURRENT_WEEK_POSITION);
    /*Week change Listener*/

    pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int weekNumber) {

            int addDays = weekNumber * 7;

            selectedDate = mStartDate.plusDays(addDays); //add 7 days to the selected date

            monthView.setText(selectedDate.monthOfYear().getAsShortText() + "-"
                    + selectedDate.year().getAsShortText().toUpperCase());

            if (weekNumber == CURRENT_WEEK_POSITION) {

                //the first week comes to view
                nowView.setVisibility(View.GONE);

            } else {

                //the first week goes from view nowView set visible for Quick return to first week

                nowView.setVisibility(View.VISIBLE);
            }

        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });

    /**
     * Change view to  the date of the current week
     */

    nowView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            calenderListener.onSelectDate(new LocalDateTime());

            pager.setCurrentItem(CURRENT_WEEK_POSITION);

        }
    });

    /**
     * For quick selection of a date.Any picker or custom date picker can de used
     */
    monthView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            calenderListener.onSelectPicker();

        }
    });

}

From source file:org.jitsi.android.gui.call.CallInfoDialogFragment.java

/**
 * Updates section displaying ICE information for given
 * <tt>callPeerMediaHandler</tt>.
 *
 * @param callPeerMediaHandler the call peer for which ICE information will
 * be displayed./*from w  w  w  . j  ava2  s  .co m*/
 */
private void updateIceSection(CallPeerMediaHandler<?> callPeerMediaHandler) {
    // ICE state.
    String iceState = null;
    if (callPeerMediaHandler != null) {
        iceState = callPeerMediaHandler.getICEState();
    }

    boolean iceStateVisible = iceState != null && !iceState.equals("Terminated");

    ensureVisible(getView(), R.id.iceState, iceStateVisible);
    ensureVisible(getView(), R.id.iceStateLabel, iceStateVisible);

    if (iceStateVisible) {
        Resources resources = getResources();
        int strId = resources.getIdentifier("service_gui_callinfo_ICE_STATE_" + iceState.toUpperCase(),
                "string", getActivity().getPackageName());
        setTextViewValue(R.id.iceState, resources.getString(strId));
    }

    // Total harvesting time.
    long harvestingTime = 0;
    if (callPeerMediaHandler != null) {
        harvestingTime = callPeerMediaHandler.getTotalHarvestingTime();
    }

    boolean isTotalHarvestTime = harvestingTime != 0;

    ensureVisible(getView(), R.id.totalHarvestTime, isTotalHarvestTime);
    ensureVisible(getView(), R.id.totalHarvestLabel, isTotalHarvestTime);

    if (isTotalHarvestTime) {
        String harvestStr = getHarvestTimeStr(harvestingTime, callPeerMediaHandler.getNbHarvesting());

        setTextViewValue(getView(), R.id.totalHarvestTime, harvestStr);
    }

    // Current harvester time if ICE agent is harvesting.
    String[] harvesterNames = { "GoogleTurnCandidateHarvester", "GoogleTurnSSLCandidateHarvester",
            "HostCandidateHarvester", "JingleNodesHarvester", "StunCandidateHarvester",
            "TurnCandidateHarvester", "UPNPHarvester" };
    int[] harvesterLabels = { R.id.googleTurnLabel, R.id.googleTurnSSlLabel, R.id.hostHarvesterLabel,
            R.id.jingleNodesLabel, R.id.stunHarvesterLabel, R.id.turnHarvesterLabel, R.id.upnpHarvesterLabel };
    int[] harvesterValues = { R.id.googleTurnTime, R.id.googleTurnSSlTime, R.id.hostHarvesterTime,
            R.id.jingleNodesTime, R.id.stunHarvesterTime, R.id.turnHarvesterTime, R.id.upnpHarvesterTime };
    for (int i = 0; i < harvesterLabels.length; ++i) {
        harvestingTime = 0;

        if (callPeerMediaHandler != null) {
            harvestingTime = callPeerMediaHandler.getHarvestingTime(harvesterNames[i]);
        }

        boolean visible = harvestingTime != 0;

        ensureVisible(getView(), harvesterLabels[i], visible);
        ensureVisible(getView(), harvesterValues[i], visible);

        if (visible) {
            int harvestCount = callPeerMediaHandler.getNbHarvesting(harvesterNames[i]);

            setTextViewValue(getView(), harvesterValues[i], getHarvestTimeStr(harvestingTime, harvestCount));
        }
    }
}

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

/**
 * Applies a style to the map overlays associated with a given location provider.
 * //from w  w  w  . ja  v a2  s  . c  o 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(STYLE_FILL, R.color.circle_gray_fill));
        circle.getPaintStroke().setColor(style.getColor(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(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();
}