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.VersionDialogFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { Bundle bundle = getArguments();// w ww . j av a 2 s .com Activity ctx = (Activity) getActivity(); LayoutInflater li = LayoutInflater.from(ctx); int from = bundle.getInt("from"); Resources res = getResources(); int[] versionCodes = res.getIntArray(R.array.version_codes); String[] versionNames = res.getStringArray(R.array.version_names); final ArrayList<VersionInfo> versions = new ArrayList<VersionInfo>(); for (int i = 0; i < versionCodes.length; i++) { int code = versionCodes[i]; if (from >= code) break; int resId = res.getIdentifier("whats_new_" + code, "array", ctx.getPackageName()); if (resId == 0) { Log.e(MyApplication.TAG, "missing change log entry for version " + code); } else { String changes[] = res .getStringArray(res.getIdentifier("whats_new_" + code, "array", ctx.getPackageName())); versions.add(new VersionInfo(code, versionNames[i], changes)); } } View view = li.inflate(R.layout.versiondialog, null); final ListView lv = (ListView) view.findViewById(R.id.list); ArrayAdapter<VersionInfo> adapter = new ArrayAdapter<VersionInfo>(ctx, R.layout.version_row, R.id.versionInfoName, versions) { @Override public View getView(int position, View convertView, ViewGroup parent) { LinearLayout row = (LinearLayout) super.getView(position, convertView, parent); VersionInfo version = versions.get(position); ((TextView) row.findViewById(R.id.versionInfoName)).setText(version.name); ((TextView) row.findViewById(R.id.versionInfoChanges)) .setText("- " + TextUtils.join("\n- ", version.changes)); return row; } }; lv.setAdapter(adapter); if (MyApplication.getInstance().showImportantUpgradeInfo) { view.findViewById(R.id.ImportantUpgradeInfoHeading).setVisibility(View.VISIBLE); view.findViewById(R.id.ImportantUpgradeInfoBody).setVisibility(View.VISIBLE); } AlertDialog.Builder builder = new AlertDialog.Builder(ctx) .setTitle(getString(R.string.help_heading_whats_new)).setIcon(R.drawable.icon).setView(view) .setNegativeButton(android.R.string.ok, this); if (!MyApplication.getInstance().isContribEnabled) builder.setPositiveButton(R.string.menu_contrib, this); return builder.create(); }
From source file:uc.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 .j a v a2 s. c o m*/ try { @SuppressWarnings("rawtypes") Class systemPropertiesClass = Class.forName("android.os.SystemProperties"); @SuppressWarnings("unchecked") 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.example.ray.firstapp.bottombar.BottomBar.java
private static void navBarMagic(Activity activity, final BottomBar bottomBar) { Resources res = activity.getResources(); int softMenuIdentifier = res.getIdentifier("config_showNavigationBar", "bool", "android"); int navBarIdentifier = res.getIdentifier("navigation_bar_height", "dimen", "android"); int navBarHeight = 0; if (navBarIdentifier > 0) { navBarHeight = res.getDimensionPixelSize(navBarIdentifier); }//from w ww . j a va 2 s. c om if (!bottomBar.drawBehindNavBar() || navBarHeight == 0 || (!(softMenuIdentifier > 0 && res.getBoolean(softMenuIdentifier)))) { return; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && ViewConfiguration.get(activity).hasPermanentMenuKey()) { return; } /** * Copy-paste coding made possible by: * http://stackoverflow.com/a/14871974/940036 */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { Display d = activity.getWindowManager().getDefaultDisplay(); DisplayMetrics realDisplayMetrics = new DisplayMetrics(); d.getRealMetrics(realDisplayMetrics); int realHeight = realDisplayMetrics.heightPixels; int realWidth = realDisplayMetrics.widthPixels; DisplayMetrics displayMetrics = new DisplayMetrics(); d.getMetrics(displayMetrics); int displayHeight = displayMetrics.heightPixels; int displayWidth = displayMetrics.widthPixels; boolean hasSoftwareKeys = (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0; if (!hasSoftwareKeys) { return; } } /** * End of delicious copy-paste code */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { activity.getWindow().getAttributes().flags |= WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION; if (bottomBar.useTopOffset()) { int offset; int statusBarResource = res.getIdentifier("status_bar_height", "dimen", "android"); if (statusBarResource > 0) { offset = res.getDimensionPixelSize(statusBarResource); } else { offset = MiscUtils.dpToPixel(activity, 25); } if (!bottomBar.useOnlyStatusbarOffset()) { TypedValue tv = new TypedValue(); if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { offset += TypedValue.complexToDimensionPixelSize(tv.data, res.getDisplayMetrics()); } else { offset += MiscUtils.dpToPixel(activity, 56); } } bottomBar.getUserContainer().setPadding(0, offset, 0, 0); } final View outerContainer = bottomBar.getOuterContainer(); final int navBarHeightCopy = navBarHeight; bottomBar.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @SuppressWarnings("deprecation") @Override public void onGlobalLayout() { bottomBar.shyHeightAlreadyCalculated(); int newHeight = outerContainer.getHeight() + navBarHeightCopy; outerContainer.getLayoutParams().height = newHeight; if (bottomBar.isShy()) { int defaultOffset = bottomBar.useExtraOffset() ? navBarHeightCopy : 0; bottomBar.setTranslationY(defaultOffset); ((CoordinatorLayout.LayoutParams) bottomBar.getLayoutParams()) .setBehavior(new BottomNavigationBehavior(newHeight, defaultOffset)); } ViewTreeObserver obs = outerContainer.getViewTreeObserver(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { obs.removeOnGlobalLayoutListener(this); } else { obs.removeGlobalOnLayoutListener(this); } } }); } }
From source file:com.ramzcalender.WeekFragment.java
@Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); /*Setting the date info in the Application class*/ startDate = AppController.getInstance().getDate(); mCurrentDate = AppController.getInstance().getDate(); /*Setting the Resources values and Customization values to the views*/ Resources resources = getActivity().getResources(); selectorDateIndicatorValue = resources.getIdentifier( getArguments().getString(RWeekCalendar.DATE_SELECTOR_BACKGROUND), "drawable", RWeekCalendar.PAKAGENAMEVALUE); currentDateIndicatorValue = getArguments().getInt(RWeekCalendar.CURRENT_DATE_BACKGROUND); datePosition = getArguments().getInt(RWeekCalendar.POSITIONKEY); int addDays = datePosition * 7; startDate = startDate.plusDays(addDays);//Adding the 7days to the previous week mSelectedDate = AppController.getInstance().getSelected(); textViewArray[0].setBackgroundResource(selectorDateIndicatorValue);//Setting the first days of the week as selected /*Fetching the data's for the week to display*/ for (int i = 0; i < 7; i++) { if (mSelectedDate != null) { if (mSelectedDate.getDayOfMonth() == startDate.getDayOfMonth()) { /*Indicate if the day is selected*/ textViewArray[i].setBackgroundResource(selectorDateIndicatorValue); mDateSelectedBackground(i);//Changing View selector background AppController.getInstance().setSelected(null);//null the selected date }// www .j a v a2 s. c o m } dateInWeekArray.add(startDate);//Adding the days in the selected week to list startDate = startDate.plusDays(1); //Next day } /*Setting color in the week views*/ sundayTV.setTextColor(getArguments().getInt(RWeekCalendar.PRIMARY_BACKGROUND)); mondayTv.setTextColor(getArguments().getInt(RWeekCalendar.PRIMARY_BACKGROUND)); tuesdayTv.setTextColor(getArguments().getInt(RWeekCalendar.PRIMARY_BACKGROUND)); wednesdayTv.setTextColor(getArguments().getInt(RWeekCalendar.PRIMARY_BACKGROUND)); thursdayTv.setTextColor(getArguments().getInt(RWeekCalendar.PRIMARY_BACKGROUND)); fridayTv.setTextColor(getArguments().getInt(RWeekCalendar.PRIMARY_BACKGROUND)); saturdayTv.setTextColor(getArguments().getInt(RWeekCalendar.PRIMARY_BACKGROUND)); /*Displaying the days in the week views*/ sundayTV.setText(Integer.toString(dateInWeekArray.get(0).getDayOfMonth())); mondayTv.setText(Integer.toString(dateInWeekArray.get(1).getDayOfMonth())); tuesdayTv.setText(Integer.toString(dateInWeekArray.get(2).getDayOfMonth())); wednesdayTv.setText(Integer.toString(dateInWeekArray.get(3).getDayOfMonth())); thursdayTv.setText(Integer.toString(dateInWeekArray.get(4).getDayOfMonth())); fridayTv.setText(Integer.toString(dateInWeekArray.get(5).getDayOfMonth())); saturdayTv.setText(Integer.toString(dateInWeekArray.get(6).getDayOfMonth())); /*if the selected week is the current week indicates the current day*/ if (datePosition == RWeekCalendar.CURRENT_WEEK_POSITION) { for (int i = 0; i < 7; i++) { if (Calendar.getInstance().get(Calendar.DAY_OF_MONTH) == dateInWeekArray.get(i).getDayOfMonth()) { textViewArray[i].setTextColor(currentDateIndicatorValue); textViewArray[i].setBackgroundResource(selectorDateIndicatorValue); mDateSelectedBackground(i); } } } /** * Click listener of all week days with the indicator change and passing listener info. */ sundayTV.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mSelectedDateInfo(0); sundayTV.setBackgroundResource(selectorDateIndicatorValue); mDateSelectedBackground(0); } }); mondayTv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mSelectedDateInfo(1); mondayTv.setBackgroundResource(selectorDateIndicatorValue); mDateSelectedBackground(1); } }); tuesdayTv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mSelectedDateInfo(2); tuesdayTv.setBackgroundResource(selectorDateIndicatorValue); mDateSelectedBackground(2); } }); wednesdayTv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mSelectedDateInfo(3); wednesdayTv.setBackgroundResource(selectorDateIndicatorValue); mDateSelectedBackground(3); } }); thursdayTv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mSelectedDateInfo(4); thursdayTv.setBackgroundResource(selectorDateIndicatorValue); mDateSelectedBackground(4); } }); fridayTv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mSelectedDateInfo(5); fridayTv.setBackgroundResource(selectorDateIndicatorValue); mDateSelectedBackground(5); } }); saturdayTv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mSelectedDateInfo(6); saturdayTv.setBackgroundResource(selectorDateIndicatorValue); mDateSelectedBackground(6); } }); //---------------------------------------------------------------------------------------// }
From source file:com.bevyios.gcm.BevyGcmListenerService.java
private void sendNotification(Bundle bundle) { Resources resources = getApplication().getResources(); String packageName = getApplication().getPackageName(); Class intentClass = getMainActivityClass(); if (intentClass == null) { return;/*from w w w . j a va 2 s . c o m*/ } if (applicationIsRunning()) { Intent i = new Intent("BevyGCMReceiveNotification"); i.putExtra("bundle", bundle); sendBroadcast(i); return; } int resourceId = resources.getIdentifier(bundle.getString("largeIcon"), "mipmap", packageName); Intent intent = new Intent(this, intentClass); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); //Bitmap largeIcon = BitmapFactory.decodeResource(resources, resourceId); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) //.setLargeIcon(largeIcon) .setSmallIcon(R.drawable.ic_launcher).setContentTitle("title").setContentText("content") .setAutoCancel(false).setSound(defaultSoundUri) //.setTicker(bundle.getString("ticker")) .setCategory(NotificationCompat.CATEGORY_CALL).setVisibility(NotificationCompat.VISIBILITY_PRIVATE) .setPriority(NotificationCompat.PRIORITY_HIGH).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); Notification notif = notificationBuilder.build(); notif.defaults |= Notification.DEFAULT_VIBRATE; notif.defaults |= Notification.DEFAULT_SOUND; notif.defaults |= Notification.DEFAULT_LIGHTS; notificationManager.notify(0, notif); }
From source file:me.piebridge.prevent.ui.UserGuideActivity.java
private CharSequence getLabel(PackageManager pm, ApplicationInfo info) throws PackageManager.NameNotFoundException { CharSequence label = null;// www. java2 s . c om if ("com.android.vending".equals(info.packageName)) { Resources resources = pm.getResourcesForApplication(info); int appName = resources.getIdentifier("app_name", "string", info.packageName); if (appName > 0) { label = resources.getText(appName); } } if (TextUtils.isEmpty(label)) { label = pm.getApplicationLabel(info); } return label; }
From source file:com.rockerhieu.emojicon.EmojiconsPopup.java
/** * Call this function to resize the emoji popup according to your soft keyboard size *//* w w w . j av a 2s . c om*/ public void setSizeForSoftKeyboard() { rootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (isOpened) { return; } Rect r = new Rect(); rootView.getWindowVisibleDisplayFrame(r); int screenHeight = getUsableScreenHeight(); int heightDifference = screenHeight - (r.bottom - r.top); Resources resources = mContext.getResources(); int statusBarId = resources.getIdentifier("status_bar_height", "dimen", "android"); //add support translucent status bar ??? // if (!((Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) && (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP))) { // if (statusBarId > 0) { // heightDifference -= mContext.getResources() // .getDimensionPixelSize(statusBarId); // // Log.e("keyboard height", "resourceId > 0" + heightDifference); // } // } if (statusBarId > 0) { heightDifference -= resources.getDimensionPixelSize(statusBarId); } //Resolved using http://stackoverflow.com/a/16608481/2853322 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { int navBarId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); boolean hasMenuKey; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { hasMenuKey = ViewConfiguration.get(mContext).hasPermanentMenuKey(); } else hasMenuKey = true; //Skip has menu key below ICS boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK); //This is a hack for lollipop if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { hasBackKey = false; } if (navBarId > 0 && !hasMenuKey && !hasBackKey) { heightDifference -= resources.getDimensionPixelSize(navBarId); } } // int statusBarResourceId = mContext.getResources() // .getIdentifier("status_bar_height", // "dimen", "android"); // if (statusBarResourceId > 0) { // heightDifference -= mContext.getResources() // .getDimensionPixelSize(statusBarResourceId); // } // // int navBarResourceId = mContext.getResources() // .getIdentifier("navigation_bar_height", // "dimen", "android"); // if (navBarResourceId > 0) { // heightDifference -= mContext.getResources().getDimensionPixelSize(navBarResourceId); // } if (heightDifference > 150) { keyBoardHeight = heightDifference; setSize(LayoutParams.MATCH_PARENT, keyBoardHeight); if (!isOpened) { if (onSoftKeyboardOpenCloseListener != null) onSoftKeyboardOpenCloseListener.onKeyboardOpen(keyBoardHeight); } isOpened = true; if (pendingOpen) { showAtBottom(); pendingOpen = false; } } else { isOpened = false; if (onSoftKeyboardOpenCloseListener != null) onSoftKeyboardOpenCloseListener.onKeyboardClose(); } } }); }
From source file:gl.iglou.scenegraph.MatModeInterface.java
public int getIdAssignedByR(Context pContext, String pIdString) { // Get the Context's Resources and Package Name Resources resources = pContext.getResources(); String packageName = pContext.getPackageName(); // Determine the result and return it int result = resources.getIdentifier(pIdString, "id", packageName); return result; }
From source file:tomerbu.edu.transitionsdemo.MyRecyclerAdapter.java
private void initDummyData(Context context) { Resources resources = context.getResources(); String[] dummyTexts = { "Urias persuadere, tanquam superbus vigil.", "Paradox doesnt cheerfully believe any cow but the master is what disturbs.", "Squeezed cauliflower can be made fresh by brushing with honey.", "How cloudy. You fire like a girl.", "Malfunction tightly like a seismic planet." }; for (int i = 0; i < 10; i++) { for (int j = 0; j < dummyTexts.length; j++) { int id = resources.getIdentifier(String.format(Locale.US, "cheese_%d", j + 1), "drawable", getClass().getPackage().getName()); Cheese cheese = new Cheese(dummyTexts[j], id); data.add(cheese);/*w w w . j a va 2 s . c o m*/ } } }
From source file:com.harlan.jxust.ui.view.bottombar.BottomBar.java
private static void navBarMagic(Activity activity, final BottomBar bottomBar) { Resources res = activity.getResources(); int softMenuIdentifier = res.getIdentifier("config_showNavigationBar", "bool", "android"); int navBarIdentifier = res.getIdentifier("navigation_bar_height", "dimen", "android"); int navBarHeight = 0; if (navBarIdentifier > 0) { navBarHeight = res.getDimensionPixelSize(navBarIdentifier); }/* w w w. j a v a 2 s .c o m*/ if (!bottomBar.drawBehindNavBar() || navBarHeight == 0 || (!(softMenuIdentifier > 0 && res.getBoolean(softMenuIdentifier)))) { return; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && ViewConfiguration.get(activity).hasPermanentMenuKey()) { return; } /** * Copy-paste coding made possible by: * http://stackoverflow.com/a/14871974/940036 */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { Display d = activity.getWindowManager().getDefaultDisplay(); DisplayMetrics realDisplayMetrics = new DisplayMetrics(); d.getRealMetrics(realDisplayMetrics); int realHeight = realDisplayMetrics.heightPixels; int realWidth = realDisplayMetrics.widthPixels; DisplayMetrics displayMetrics = new DisplayMetrics(); d.getMetrics(displayMetrics); int displayHeight = displayMetrics.heightPixels; int displayWidth = displayMetrics.widthPixels; boolean hasSoftwareKeys = (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0; if (!hasSoftwareKeys) { return; } } /** * End of delicious copy-paste code */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { activity.getWindow().getAttributes().flags |= WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION; if (bottomBar.useTopOffset()) { int offset; int statusBarResource = res.getIdentifier("status_bar_height", "dimen", "android"); if (statusBarResource > 0) { offset = res.getDimensionPixelSize(statusBarResource); } else { offset = MiscUtils.dpToPixel(activity, 25); } if (!bottomBar.useOnlyStatusbarOffset()) { TypedValue tv = new TypedValue(); if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { offset += TypedValue.complexToDimensionPixelSize(tv.data, res.getDisplayMetrics()); } else { offset += MiscUtils.dpToPixel(activity, 56); } } bottomBar.getUserContainer().setPadding(0, offset, 0, 0); } final View outerContainer = bottomBar.getOuterContainer(); final int navBarHeightCopy = navBarHeight; bottomBar.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @SuppressWarnings("deprecation") @Override public void onGlobalLayout() { bottomBar.shyHeightAlreadyCalculated(); int newHeight = outerContainer.getHeight() + navBarHeightCopy; outerContainer.getLayoutParams().height = newHeight; if (bottomBar.isShy()) { int defaultOffset = bottomBar.useExtraOffset() ? navBarHeightCopy : 0; bottomBar.setTranslationY(defaultOffset); ((CoordinatorLayout.LayoutParams) bottomBar.getLayoutParams()) .setBehavior(new BottomNavigationBehavior(newHeight, defaultOffset, bottomBar.isShy(), bottomBar.mIsTabletMode)); } ViewTreeObserver obs = outerContainer.getViewTreeObserver(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { obs.removeOnGlobalLayoutListener(this); } else { obs.removeGlobalOnLayoutListener(this); } } }); } }