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:de.baumann.thema.Wallpaper.java

private void fetchWallpapers(Resources resources, String packageName) {
    final String[] extras = resources.getStringArray(R.array.wallpapers);
    for (String extra : extras) {
        int res = resources.getIdentifier(extra, "drawable", packageName);
        if (res != 0) {
            sWallpapers.add(res);// w  w  w . j  a  va2 s . co  m
        }
    }
}

From source file:com.numenta.taurus.instance.InstanceListActivity.java

private void configureSearchView(@NonNull final SearchView searchView) {
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    // Assumes current activity is the searchable activity
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    // Handle query events
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override//from ww w  .  j  ava2s .  com
        public boolean onQueryTextSubmit(String query) {
            // Hide Keyboard on submit
            InputMethodManager imm = (InputMethodManager) searchView.getContext()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            if (imm != null) {
                imm.hideSoftInputFromWindow(searchView.getWindowToken(), 0);
            }

            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            // Filter list as the user types
            _listFragment.applyFilter(newText);
            return true;
        }
    });

    // FIXME: Android does not support styling the search view across all versions.
    // For now, "peek" into internal API to make the appropriate changes to the SearchView.
    // In the future we should use the official android API to customize the SearchView widget.
    // See android.R.layout.search_view for the layout we are "peeking". It is no guarantee it
    // will work on all public android versions and/or OEM customizations.
    // This HACK is only valid for the POC phase. We should find a better solution before releasing
    Resources resources = searchView.getResources();

    // Style search box and text
    int searchPlateId = resources.getIdentifier("android:id/search_plate", null, null);
    View searchPlate = searchView.findViewById(searchPlateId);
    if (searchPlate != null) {
        int searchTextId = resources.getIdentifier("android:id/search_src_text", null, null);
        TextView searchText = (TextView) searchPlate.findViewById(searchTextId);
        if (searchText != null) {
            searchPlate.setBackgroundResource(android.R.drawable.editbox_background);
            searchText.setPadding(5, 0, 0, 0);
            searchText.setTextColor(Color.BLACK);
            searchText.setHintTextColor(Color.LTGRAY);
        }
    }
}

From source file:com.mobirix.battlefieldcommander.activity.BillingNativeActivity.java

public void sendNotification(int id, String title, String message) {
    Intent intent = new Intent(this, BillingNativeActivity.class);
    //intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Resources res = this.getResources();
    int icon = res.getIdentifier("ic_stat_ic_notification", "drawable", this.getPackageName());

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this).setSmallIcon(icon) //todo
            .setContentTitle(title).setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(id /* ID of notification */, notificationBuilder.build());
}

From source file:org.zywx.wbpalmstar.platform.push.PushRecieveMsgReceiver.java

private void buildPushNotification(Context context, Intent intent, PushDataInfo dataInfo) {
    String title = dataInfo.getTitle();
    String body = dataInfo.getAlert();
    String message = dataInfo.getPushDataString();
    Builder builder = new Builder(context);
    builder.setAutoCancel(true);/*from w ww.  j  a  va2 s.  c o m*/
    builder.setContentTitle(title); // 
    builder.setContentText(body); // 
    builder.setTicker(body); // ??

    String[] remindType = dataInfo.getRemindType();
    if (remindType != null) {
        if (remindType.length == 3) {
            builder.setDefaults(Notification.DEFAULT_ALL);
        } else {
            int defaults = 0;
            for (int i = 0; i < remindType.length; i++) {
                if ("sound".equalsIgnoreCase(remindType[i])) {
                    defaults = Notification.DEFAULT_SOUND;
                    continue;
                }
                if ("shake".equalsIgnoreCase(remindType[i])) {
                    defaults = defaults | Notification.DEFAULT_VIBRATE;
                    continue;
                }
                if ("breathe".equalsIgnoreCase(remindType[i])) {
                    defaults = defaults | Notification.DEFAULT_LIGHTS;
                    continue;
                }
            }
            builder.setDefaults(defaults);
        }
    }

    Resources res = context.getResources();
    int icon = res.getIdentifier("icon", "drawable", intent.getPackage());
    builder.setSmallIcon(icon);
    builder.setWhen(System.currentTimeMillis()); // 

    String iconUrl = dataInfo.getIconUrl();
    boolean isDefaultIcon = !TextUtils.isEmpty(iconUrl) && "default".equalsIgnoreCase(iconUrl);
    Bitmap bitmap = null;
    if (!isDefaultIcon) {
        bitmap = getIconBitmap(context, iconUrl);
    }
    String fontColor = dataInfo.getFontColor();
    RemoteViews remoteViews = null;
    if (!TextUtils.isEmpty(fontColor)) {
        int color = BUtility.parseColor(fontColor);
        int alphaColor = parseAlphaColor(fontColor);
        remoteViews = new RemoteViews(intent.getPackage(), EUExUtil.getResLayoutID("push_notification_view"));
        // Title
        remoteViews.setTextViewText(EUExUtil.getResIdID("notification_title"), title);
        remoteViews.setTextColor(EUExUtil.getResIdID("notification_title"), color);
        // Body
        remoteViews.setTextViewText(EUExUtil.getResIdID("notification_body"), body);
        remoteViews.setTextColor(EUExUtil.getResIdID("notification_body"), alphaColor);
        // LargeIcon
        if (bitmap != null) {
            remoteViews.setImageViewBitmap(EUExUtil.getResIdID("notification_largeIcon"), bitmap);
        } else {
            remoteViews.setImageViewResource(EUExUtil.getResIdID("notification_largeIcon"),
                    EUExUtil.getResDrawableID("icon"));
        }
        // Time
        SimpleDateFormat format = new SimpleDateFormat("HH:mm");
        remoteViews.setTextViewText(EUExUtil.getResIdID("notification_time"),
                format.format(System.currentTimeMillis()));
        remoteViews.setTextColor(EUExUtil.getResIdID("notification_time"), alphaColor);
        builder.setContent(remoteViews);
    }

    Intent notiIntent = new Intent(context, EBrowserActivity.class);
    notiIntent.putExtra("ntype", F_TYPE_PUSH);
    notiIntent.putExtra("data", body);
    notiIntent.putExtra("message", message);
    Bundle bundle = new Bundle();
    bundle.putSerializable(PushReportConstants.PUSH_DATA_INFO_KEY, dataInfo);
    notiIntent.putExtras(bundle);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, notificationNB, notiIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(pendingIntent);

    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = builder.build();
    // Android v4bug2.3?Builder?NotificationRemoteView??
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB && remoteViews != null) {
        notification.contentView = remoteViews;
    }
    manager.notify(notificationNB, notification);
    notificationNB++;
}

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

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    Resources res = mContext.getResources();
    if (mUpgrade == null) {
        mUpgrade = "upgrade_tables_v";
    }/*from  w w  w  .  ja  v  a2  s.co m*/
    for (int i = oldVersion; i < newVersion; i++) { // execute the upgrade scripts [old, new)
        try {
            execScript(db, res, res.getIdentifier(mUpgrade + i, "raw", mContext.getPackageName()));
        } catch (IOException e) {
            throw new RuntimeException("upgrading database", e);
        }
    }
}

From source file:org.akvo.flow.service.SurveyDownloadService.java

private Survey loadSurvey(Survey survey) {
    InputStream in = null;//from  w  w  w .  j a va  2s  . c o  m
    Survey hydratedDurvey = null;
    try {
        if (ConstantUtil.RESOURCE_LOCATION.equalsIgnoreCase(survey.getLocation())) {
            // load from resource
            Resources res = getResources();
            in = res.openRawResource(res.getIdentifier(survey.getFileName(), ConstantUtil.RAW_RESOURCE,
                    ConstantUtil.RESOURCE_PACKAGE));
        } else {
            // load from file
            File f = new File(FileUtil.getFilesDir(FileType.FORMS), survey.getFileName());
            in = new FileInputStream(f);
        }
        hydratedDurvey = SurveyDao.loadSurvey(survey, in);
    } catch (FileNotFoundException e) {
        Log.e(TAG, "Could not parse survey survey file", e);
        PersistentUncaughtExceptionHandler.recordException(e);
    } finally {
        FileUtil.close(in);
    }
    return hydratedDurvey;
}

From source file:org.miaowo.miaowo.util.Html.java

private static void endFont(Editable text) {
    int len = text.length();
    Font f = getLast(text, Font.class);
    int where = text.getSpanStart(f);
    text.removeSpan(f);/*ww  w. j  a  v  a  2 s  .  c o  m*/

    if (where != len) {
        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 = ResourcesCompat.getColorStateList(res, colorRes, null);
                    text.setSpan(new TextAppearanceSpan(null, 0, 0, colors, null), where, len,
                            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
            } else {
                int c = Color.parseColor(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);
        }
    }
}

From source file:com.hartcode.hartweather.detail.WeatherDetailActivityFragment.java

public void setWeather(@NonNull Weather weather) {
    Resources resources = this.view.getResources();
    this.txtCityName.setText(weather.cityName);
    String temp = String.format(resources.getString(R.string.temp_format), (int) weather.temp, (char) 0x00B0);
    this.txtWeatherTemp.setText(temp);
    Drawable iconResource = ContextCompat.getDrawable(this.view.getContext(),
            resources.getIdentifier(resources.getString(R.string.weather_image_prefix) + weather.icon,
                    resources.getString(R.string.weather_image_resource_type),
                    this.view.getContext().getPackageName()));
    this.imgWeather.setImageDrawable(iconResource);
    this.txtWeatherName.setText(weather.main);
    temp = String.format(resources.getString(R.string.temp_low_format), (int) weather.temp_min, (char) 0x00B0);
    this.txtLowTemp.setText(temp);
    temp = String.format(resources.getString(R.string.temp_high_format), (int) weather.temp_max, (char) 0x00B0);
    this.txtHighTemp.setText(temp);
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(weather.lastUpdate);
    SimpleDateFormat sdfDate = new SimpleDateFormat(resources.getString(R.string.simple_date_format),
            Locale.US);//from  w  w w .ja v a2  s.c  o  m
    String lastUpdate = String.format(resources.getString(R.string.last_update_format),
            sdfDate.format(calendar.getTime()));
    this.txtLastUpdate.setText(lastUpdate);
}

From source file:org.totschnig.myexpenses.dialog.ContribDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Activity ctx = getActivity();/*w ww. j  ava  2  s .  c o  m*/
    Resources res = getResources();
    Context wrappedCtx = DialogUtils.wrapContext2(ctx);
    String featureList = Utils.getContribFeatureLabelsAsFormattedList(ctx, feature);
    String featureDescription;
    if (feature.hasTrial)
        featureDescription = getString(R.string.dialog_contrib_premium_feature,
                "<i>" + getString(res.getIdentifier("contrib_feature_" + feature + "_label", "string",
                        ctx.getPackageName())) + "</i>")
                + (usagesLeft > 0
                        ? res.getQuantityString(R.plurals.dialog_contrib_usage_count, usagesLeft, usagesLeft)
                        : getString(R.string.dialog_contrib_no_usages_left));
    else
        featureDescription = getString(res.getIdentifier("contrib_feature_" + feature + "_description",
                "string", ctx.getPackageName()));
    CharSequence message = Html.fromHtml((String) TextUtils.concat(featureDescription, " ",
            getString(R.string.dialog_contrib_reminder_remove_limitation), " ",
            getString(R.string.dialog_contrib_reminder_gain_access), "<br>", featureList));
    return new AlertDialog.Builder(wrappedCtx).setTitle(R.string.dialog_title_contrib_feature)
            .setMessage(message).setNegativeButton(R.string.dialog_contrib_no, this)
            .setPositiveButton(R.string.dialog_contrib_yes, this).create();
}

From source file:com.smartcodeunited.demo.bluetooth.activity.BaseActivity.java

public int getNavigationBarHeight() {
    Resources resources = getResources();
    int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
    if (resourceId > 0 && hasNavigationBar()) {
        return resources.getDimensionPixelSize(resourceId);
    }/*w w w.j a va  2 s .c o m*/
    return 0;
}