List of usage examples for android.content.res Resources getIdentifier
public int getIdentifier(String name, String defType, String defPackage)
From source file:org.totschnig.myexpenses.dialog.HelpDialogFragment.java
private int resolve(Resources resources, String resIdString, String defType, String packageName) { return resources.getIdentifier(resIdString, defType, packageName); }
From source file:com.crystal.CrystalBeanWallpapers.Wallpaper.java
private void fetchWallpapers(Resources resources, String packageName, int list) { final String[] extras = resources.getStringArray(list); for (String extra : extras) { int res = resources.getIdentifier(extra, "drawable", packageName); if (res != 0) { mWallpapers.add(res);/*from w ww. j a v a 2 s . c o m*/ } } }
From source file:com.hrs.filltheform.dialog.FillTheFormDialog.java
private int getStatusBarHeight() { Resources resources = context.getResources(); int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { return resources.getDimensionPixelSize(resourceId); }/*from ww w . ja v a 2 s. c o m*/ return 0; }
From source file:com.gruporaido.tasker_library.util.Helper.java
/** * Gets Navigation bar height if there is one, 0 otherwise * * @return/*from w w w . j av a2 s .co m*/ */ public int navigationBarSize() { Resources resources = mContext.getResources(); int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); if (resourceId > 0) { return resources.getDimensionPixelSize(resourceId); } return 0; }
From source file:com.affectiva.affdexme.MetricSelector.java
void initContent(LayoutInflater inflater, Resources res, String packageName) { View content = inflater.inflate(R.layout.grid_item, this, true); String resourceName = MetricsManager.getLowerCaseName(metric); videoOverlay = (TextView) content.findViewById(R.id.video_overlay); int videoId = res.getIdentifier(resourceName, "raw", packageName); if (isEmoji) { videoResourceURIs = null;//from w ww.j a v a 2 s.co m } else if (metric == MetricsManager.Emotions.VALENCE) { videoResourceURIs = new Uri[2]; videoResourceURIs[0] = Uri.parse(String.format("android.resource://%s/%d", packageName, videoId)); videoResourceURIs[1] = Uri.parse(String.format("android.resource://%s/%d", packageName, res.getIdentifier(resourceName + "0", "raw", packageName))); } else { videoResourceURIs = new Uri[1]; videoResourceURIs[0] = Uri.parse(String.format("android.resource://%s/%d", packageName, videoId)); } videoResourceURIIndex = 0; //set up image if (isEmoji) { resourceName += "_emoji"; } picId = res.getIdentifier(resourceName, "drawable", packageName); imageView = (ImageView) content.findViewById(R.id.grid_item_image_view); imageViewBeneath = (ImageView) content.findViewById(R.id.grid_item_image_view_beneath); imageView.setImageResource(picId); imageViewBeneath.setImageResource(picId); imageViewBeneath.setVisibility(GONE); videoHolder = (FrameLayout) content.findViewById(R.id.video_holder); backgroundLayout = (RelativeLayout) content.findViewById(R.id.grid_item_background); gridItemTextView = (TextView) content.findViewById(R.id.grid_item_text); gridItemTextView.setText(MetricsManager.getCapitalizedName(metric)); itemSelectedOverLimitColor = ContextCompat.getColor(getContext(), R.color.grid_item_chosen_over_limit); itemNotSelectedColor = ContextCompat.getColor(getContext(), R.color.grid_item_not_chosen); itemSelectedColor = ContextCompat.getColor(getContext(), R.color.grid_item_chosen); }
From source file:com.weekcalendar.WeekCalendarFragment.java
private void handleCustomizationArguments() { if (getArguments() == null) { return;/*from w ww. j a v a 2s . c om*/ } if (getArguments().containsKey(ARGUMENT_PACKAGE_NAME)) { //its for showing the resource value from the parent package PACKAGE_NAME_VALUE = getArguments().getString(ARGUMENT_PACKAGE_NAME); } if (getArguments().containsKey(ARGUMENT_CALENDER_BACKGROUND_COLOR)) { mBackground.setBackgroundColor(getArguments().getInt(ARGUMENT_CALENDER_BACKGROUND_COLOR)); } if (getArguments().containsKey(ARGUMENT_SELECTED_DATE_BACKGROUND)) { mSelectorDateIndicatorValue = getArguments().getString(ARGUMENT_SELECTED_DATE_BACKGROUND); } if (getArguments().containsKey(ARGUMENT_SELECTED_DATE_HIGHLIGHT_COLOR)) { mSelectorHighlightColor = getArguments().getInt(ARGUMENT_SELECTED_DATE_HIGHLIGHT_COLOR); } if (getArguments().containsKey(ARGUMENT_CURRENT_DATE_TEXT_COLOR)) { mCurrentDateIndicatorValue = getArguments().getInt(ARGUMENT_CURRENT_DATE_TEXT_COLOR); } if (getArguments().containsKey(ARGUMENT_WEEK_COUNT)) { if (getArguments().getInt(ARGUMENT_WEEK_COUNT) > 0) mWeekCount = getArguments().getInt(ARGUMENT_WEEK_COUNT); } if (getArguments().containsKey(ARGUMENT_PRIMARY_TEXT_COLOR)) { mMonthView.setTextColor(getArguments().getInt(ARGUMENT_PRIMARY_TEXT_COLOR)); mPrimaryTextColor = getArguments().getInt(ARGUMENT_PRIMARY_TEXT_COLOR); } if (getArguments().containsKey(ARGUMENT_DAY_TEXT_SIZE)) { mPrimaryTextSize = getArguments().getInt(ARGUMENT_DAY_TEXT_SIZE); } if (getArguments().containsKey(ARGUMENT_DAY_TEXT_STYLE)) { mPrimaryTextStyle = getArguments().getInt(ARGUMENT_DAY_TEXT_STYLE); } if (getArguments().containsKey(ARGUMENT_SECONDARY_TEXT_COLOR)) { mNowView.setTextColor(getArguments().getInt(ARGUMENT_SECONDARY_TEXT_COLOR)); mSundayTv.setTextColor(getArguments().getInt(ARGUMENT_SECONDARY_TEXT_COLOR)); mMondayTv.setTextColor(getArguments().getInt(ARGUMENT_SECONDARY_TEXT_COLOR)); mTuesdayTv.setTextColor(getArguments().getInt(ARGUMENT_SECONDARY_TEXT_COLOR)); mWednesdayTv.setTextColor(getArguments().getInt(ARGUMENT_SECONDARY_TEXT_COLOR)); mThursdayTv.setTextColor(getArguments().getInt(ARGUMENT_SECONDARY_TEXT_COLOR)); mFridayTv.setTextColor(getArguments().getInt(ARGUMENT_SECONDARY_TEXT_COLOR)); mSaturdayTv.setTextColor(getArguments().getInt(ARGUMENT_SECONDARY_TEXT_COLOR)); } if (getArguments().containsKey(ARGUMENT_SECONDARY_TEXT_SIZE)) { int secondaryTextSize = getArguments().getInt(ARGUMENT_SECONDARY_TEXT_SIZE); ViewUtils.setTextSize(secondaryTextSize, mNowView, mSundayTv, mMondayTv, mTuesdayTv, mWednesdayTv, mThursdayTv, mFridayTv, mSaturdayTv); } if (getArguments().containsKey(ARGUMENT_SECONDARY_TEXT_STYLE)) { int secondaryTextStyle = getArguments().getInt(ARGUMENT_SECONDARY_TEXT_STYLE); ViewUtils.setTextType(secondaryTextStyle, mNowView, mSundayTv, mMondayTv, mTuesdayTv, mWednesdayTv, mThursdayTv, mFridayTv, mSaturdayTv); } if (getArguments().containsKey(ARGUMENT_DISPLAY_DATE_PICKER)) { mDisplayDatePicker = getArguments().getBoolean(ARGUMENT_DISPLAY_DATE_PICKER); if (!mDisplayDatePicker) { mFrameDatePicker.setVisibility(View.GONE); } } if (getArguments().containsKey(ARGUMENT_NOW_BACKGROUND) && mDisplayDatePicker) { Resources resources = getResources(); mNowView.setBackgroundResource( resources.getIdentifier(getArguments().getString(WeekCalendarFragment.ARGUMENT_NOW_BACKGROUND), "drawable", PACKAGE_NAME_VALUE)); } mEventDays = (long[]) getArguments().get(ARGUMENT_EVENT_DAYS); if (getArguments().containsKey(ARGUMENT_EVENT_COLOR)) { mEventColor = getArguments().getString(ARGUMENT_EVENT_COLOR); } String dayHeaderLength = getArguments().getString(ARGUMENT_DAY_HEADER_LENGTH); setHeaderLength(dayHeaderLength); }
From source file:com.android.screenspeak.formatter.EventSpeechRule.java
/** * Returns a resource identifier from the given <code>context</code> for the text * content of a <code>node</code>. * <p>/*www.jav a 2s. c o m*/ * Note: The resource identifier format is: @<package * name>:<type>/<resource name> * </p> * * @param context The parent context. * @param resName A valid resource name. * @return A resource identifier, or {@code -1} if the resource name is * invalid. */ private static int getResourceIdentifierContent(Context context, String resName) { if (resName == null) { return -1; } final Matcher matcher = mResourceIdentifier.matcher(resName); if (!matcher.matches()) { return -1; } final Resources res = context.getResources(); final String defaultPackage = (matcher.groupCount() < 2) ? context.getPackageName() : null; final int resId = res.getIdentifier(resName.substring(1), null, defaultPackage); if (resId == 0) { LogUtils.log(EventSpeechRule.class, Log.ERROR, "Failed to load resource: %s", resName); } return resId; }
From source file:com.example.mapsample.view.ActionSheet.java
public int getNavBarHeight(Context context) { int navigationBarHeight = 0; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Resources rs = context.getResources(); int id = rs.getIdentifier("navigation_bar_height", "dimen", "android"); if (id > 0 && checkDeviceHasNavigationBar(context)) { navigationBarHeight = rs.getDimensionPixelSize(id); }// w w w .java 2 s.c om } return navigationBarHeight; }
From source file:com.example.mapsample.view.ActionSheet.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 ww w. ja v a 2 s . co 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.weekcalendar.WeekFragment.java
@SuppressWarnings("unchecked") @Override// w w w . j ava2 s. com public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); /*Setting the date info in the Application class*/ mStartDate = AppController.getInstance().getDate(); mCurrentDate = AppController.getInstance().getDate(); /*Setting the Resources values and Customization values to the views*/ String identifierName = getArguments().getString(WeekCalendarFragment.ARGUMENT_SELECTED_DATE_BACKGROUND); if (identifierName != null) { Resources resources = getActivity().getResources(); mSelectorDateIndicatorValue = resources.getIdentifier(identifierName, "drawable", WeekCalendarFragment.PACKAGE_NAME_VALUE); } mCurrentDateIndicatorValue = getArguments().getInt(WeekCalendarFragment.ARGUMENT_CURRENT_DATE_TEXT_COLOR); mSelectorHighlightColor = getArguments() .getInt(WeekCalendarFragment.ARGUMENT_SELECTED_DATE_HIGHLIGHT_COLOR); mDatePosition = getArguments().getInt(POSITION_KEY); int addDays = mDatePosition * 7; mStartDate = mStartDate.plusDays(addDays);//Adding the 7days to the previous week mSelectedDate = AppController.getInstance().getSelected(); /*Fetching the data's for the week to display*/ for (int i = 0; i < 7; i++) { if (mSelectedDate != null) { if (mSelectedDate.getDayOfMonth() == mStartDate.getDayOfMonth()) { /*Indicate if the day is selected*/ setSelectedDateBackground(mTextViewArray[i]); AppController.getInstance().setSelected(null);//null the selected date } } mDateInWeekArray.add(mStartDate);//Adding the days in the selected week to list mStartDate = mStartDate.plusDays(1); //Next day } int primaryTextStyle = getArguments().getInt(WeekCalendarFragment.ARGUMENT_DAY_TEXT_STYLE, -1); int primaryTextSize = getArguments().getInt(WeekCalendarFragment.ARGUMENT_DAY_TEXT_SIZE, 0); if (primaryTextSize > 0 || primaryTextStyle > -1) { for (TextView tv : mTextViewArray) { if (primaryTextSize > 0) { tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, primaryTextSize); } if (primaryTextStyle > -1) { tv.setTypeface(tv.getTypeface(), primaryTextStyle); } } } /*Setting color in the week views*/ mPrimaryTextColor = getArguments().getInt(WeekCalendarFragment.ARGUMENT_PRIMARY_TEXT_COLOR); for (TextView tv : mTextViewArray) { tv.setTextColor(mPrimaryTextColor); } long[] eventDaysPrim = (long[]) getArguments().getSerializable(WeekCalendarFragment.ARGUMENT_EVENT_DAYS); ArrayList<LocalDateTime> eventDays = new ArrayList<>(); if (eventDaysPrim != null) { for (long eventDay : eventDaysPrim) { eventDays.add(LocalDateTime.fromDateFields(new Date(eventDay))); } } int eventColorDrawable = getEventColorDrawable( getArguments().getString(WeekCalendarFragment.ARGUMENT_EVENT_COLOR)); /*Displaying the days in the week views*/ int dayOfWeek = 0; for (TextView dayTv : mTextViewArray) { dayTv.setText(Integer.toString(mDateInWeekArray.get(dayOfWeek).getDayOfMonth())); if (!eventDays.isEmpty()) { if (CalUtil.isDayInList(mDateInWeekArray.get(dayOfWeek), eventDays)) { mImageViewArray[dayOfWeek].setImageResource(eventColorDrawable); } } dayOfWeek++; } /*if the selected week is the current week indicates the current day*/ if (mDatePosition == 0) { for (int i = 0; i < 7; i++) { if (Calendar.getInstance().get(Calendar.DAY_OF_MONTH) == mDateInWeekArray.get(i).getDayOfMonth()) { mCurrentDateIndex = i; mTextViewArray[i].setTextColor(mCurrentDateIndicatorValue); } } } setSelectedDateBackground(mTextViewArray[0]); //Setting the first days of the week as selected /** * Click listener of all week days with the indicator change and passing listener info. */ mSundayTv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mSelectedDateInfo(0); setSelectedDateBackground((TextView) view); } }); mMondayTv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mSelectedDateInfo(1); setSelectedDateBackground((TextView) view); } }); mTuesdayTv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mSelectedDateInfo(2); setSelectedDateBackground((TextView) view); } }); mWednesdayTv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mSelectedDateInfo(3); setSelectedDateBackground((TextView) view); } }); mThursdayTv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mSelectedDateInfo(4); setSelectedDateBackground((TextView) view); } }); mFridayTv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mSelectedDateInfo(5); setSelectedDateBackground((TextView) view); } }); mSaturdayTv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mSelectedDateInfo(6); setSelectedDateBackground((TextView) view); } }); }