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.isse.weatherapp.adapter.MyWeatherCursorAdapter.java

@Override
public void onBindViewHolder(ViewHolder viewHolder, Cursor cursor) {
    final String DEGREE = "\u00b0";
    final String id = String.valueOf(cursor.getInt(cursor.getColumnIndex(WeatherEntry._ID)));

    viewHolder.txtDay.setText(cursor.getString(cursor.getColumnIndex(WeatherEntry.COLUMN_DAY)));
    viewHolder.txtDate.setText(cursor.getString(cursor.getColumnIndex(WeatherEntry.COLUMN_DATE)));
    viewHolder.txtForecast.setText(cursor.getString(cursor.getColumnIndex(WeatherEntry.COLUMN_DESCRIPTION)));
    viewHolder.txtHigh.setText(cursor.getString(cursor.getColumnIndex(WeatherEntry.COLUMN_HIGH)) + DEGREE);
    viewHolder.txtLow.setText(cursor.getString(cursor.getColumnIndex(WeatherEntry.COLUMN_LOW)) + DEGREE);
    viewHolder.txtCity.setText(Utility.getCity(mContext));

    //set icon image
    final String prefix = "ic_";
    String icon_id = prefix + cursor.getString(cursor.getColumnIndex(WeatherEntry.COLUMN_ICON));
    Resources res = mContext.getResources();
    int resourceId = res.getIdentifier(icon_id, "drawable", mContext.getPackageName());
    viewHolder.imgIcon.setImageResource(resourceId);

    viewHolder.mView.setOnClickListener(new View.OnClickListener() {
        @Override//from   ww  w  .j  a v a2s  . co m
        public void onClick(View view) {
            Uri contentUri = WeatherEntry.buildDetailsUri(Long.valueOf(id));

            if (mTwoPane) {
                Bundle arguments = new Bundle();
                arguments.putString(WeatherDetailFragment.ARG_ITEM_ID, String.valueOf(id));
                arguments.putParcelable(WeatherDetailFragment.ARG_URI, contentUri);
                WeatherDetailFragment fragment = new WeatherDetailFragment();
                fragment.setArguments(arguments);
                mFragmentManager.beginTransaction().replace(R.id.weather_detail_container, fragment).commit();
            } else {
                Context context = mContext;
                Intent intent = new Intent(context, WeatherDetailActivity.class);
                intent.putExtra(WeatherDetailFragment.ARG_ITEM_ID, String.valueOf(id));
                intent.putExtra(WeatherDetailFragment.ARG_URI, contentUri);
                intent.setData(contentUri);

                context.startActivity(intent);
            }

        }
    });
}

From source file:com.squareup.picasso3.Utils.java

static int getResourceId(Resources resources, Request data) throws FileNotFoundException {
    if (data.resourceId != 0 || data.uri == null) {
        return data.resourceId;
    }//from  w w w.  j a v a2 s.co  m

    String pkg = data.uri.getAuthority();
    if (pkg == null)
        throw new FileNotFoundException("No package provided: " + data.uri);

    int id;
    List<String> segments = data.uri.getPathSegments();
    if (segments == null || segments.isEmpty()) {
        throw new FileNotFoundException("No path segments: " + data.uri);
    } else if (segments.size() == 1) {
        try {
            id = Integer.parseInt(segments.get(0));
        } catch (NumberFormatException e) {
            throw new FileNotFoundException("Last path segment is not a resource ID: " + data.uri);
        }
    } else if (segments.size() == 2) {
        String type = segments.get(0);
        String name = segments.get(1);

        id = resources.getIdentifier(name, type, pkg);
    } else {
        throw new FileNotFoundException("More than two path segments: " + data.uri);
    }
    return id;
}

From source file:com.outsystemscloud.andrevieira.secureDevice.java

private void checkDevice() {
    boolean _isDeviceRooted = isDeviceRooted();
    boolean _isPasscodeSet = doesDeviceHaveSecuritySetup(this.cordova.getActivity());

    if (_isDeviceRooted || !_isPasscodeSet) {
        // Remove View
        View v = this.view.getView();
        ViewGroup viewParent = (ViewGroup) v.getParent();
        viewParent.removeView(v);/*from w w  w  . ja v a  2  s .  c  om*/

        // Show message and quit
        Application app = cordova.getActivity().getApplication();
        String package_name = app.getPackageName();
        Resources resources = app.getResources();
        String message = resources.getString(resources.getIdentifier("message", "string", package_name));
        String label = resources.getString(resources.getIdentifier("label", "string", package_name));
        this.alert(message, label);
    }
}

From source file:com.SmartDial.ForegroundService.java

/**
 * Retrieves the resource ID of the app icon.
 *
 * @return//w  w  w.  j a v  a 2  s .  c o  m
 *      The resource ID of the app icon
 */
private int getIconResId() {
    Context context = getApplicationContext();
    Resources res = context.getResources();
    String pkgName = context.getPackageName();

    int resId;
    resId = res.getIdentifier("icon", "drawable", pkgName);

    return resId;
}

From source file:mobi.cangol.mobile.navigation.DrawerMenuLayout.java

private int getNavBarDimen(String resourceString) {
    Resources r = getResources();
    int id = r.getIdentifier(resourceString, "dimen", "android");
    if (id > 0) {
        return r.getDimensionPixelSize(id);
    } else {/*from ww  w  .ja  v  a2  s  . c  om*/
        return 0;
    }
}

From source file:com.example.isse.weatherapp.ui.WeatherDetailFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    final String DEGREE = "\u00b0";

    if (loader.getId() == CURSOR_LOADER_ID && cursor != null && cursor.moveToFirst()) {
        int weather_id = cursor.getInt(cursor.getColumnIndex(WeatherEntry._ID));

        //get values from database
        String day = cursor.getString(cursor.getColumnIndex(WeatherEntry.COLUMN_DAY));
        String mydate = cursor.getString(cursor.getColumnIndex(WeatherEntry.COLUMN_DATE));
        String description = cursor.getString(cursor.getColumnIndex(WeatherEntry.COLUMN_DESCRIPTION));
        String high = cursor.getString(cursor.getColumnIndex(WeatherEntry.COLUMN_HIGH));
        String low = cursor.getString(cursor.getColumnIndex(WeatherEntry.COLUMN_LOW));
        String temp_morn = cursor.getString(cursor.getColumnIndex(WeatherEntry.COLUMN_TEMP_MORNING));
        String temp_night = cursor.getString(cursor.getColumnIndex(WeatherEntry.COLUMN_TEMP_NIGHT));
        String temp_eve = cursor.getString(cursor.getColumnIndex(WeatherEntry.COLUMN_TEMP_EVENING));
        String temp_day = cursor.getString(cursor.getColumnIndex(WeatherEntry.COLUMN_TEMP_DAY));
        String icon = cursor.getString(cursor.getColumnIndex(WeatherEntry.COLUMN_ICON));
        String humidity = cursor.getString(cursor.getColumnIndex(WeatherEntry.COLUMN_HUMIDITY));
        String rain = cursor.getString(cursor.getColumnIndex(WeatherEntry.COLUMN_RAIN));
        String wind = cursor.getString(cursor.getColumnIndex(WeatherEntry.COLUMN_WIND));

        //get City from shared pref
        String city = Utility.getCity(mContext);

        //action bar title
        if (appBarLayout != null) {
            appBarLayout.setTitle(city);
        }/* ww w .j a  va2 s  .co  m*/

        //set values to views
        txtCity.setText(city);
        txtDay.setText(day + ", ");
        txtDate.setText(mydate);

        txtDescription.setText(description);
        txtHigh.setText(high);
        txtLow.setText(low);

        txtTempNight.setText(temp_night + DEGREE);
        txtTempMorn.setText(temp_morn + DEGREE);
        txtTempDay.setText(temp_day + DEGREE);
        txtTempEve.setText(temp_eve + DEGREE);

        txtHumidity.setText(humidity + "%");
        txtRain.setText(rain);
        txtWind.setText(wind + "m/s");

        //set icon image
        final String prefix = "ic_";
        Resources res = mContext.getResources();
        int resourceId = res.getIdentifier(prefix + icon, "drawable", mContext.getPackageName());
        imgIcon.setImageResource(resourceId);
    }

}

From source file:com.github.piasy.bootstrap.base.android.BaseDialogFragment.java

@Override
public void onStart() {
    super.onStart();
    // Less dimmed background; see http://stackoverflow.com/q/13822842/56285
    final Window window = getDialog().getWindow();
    if (window != null) {
        final WindowManager.LayoutParams params = window.getAttributes();
        params.dimAmount = getDimAmount(); // dim only a little bit
        window.setAttributes(params);//from www. ja v  a 2 s  . co  m

        window.setLayout(getWidth(), getHeight());
        window.setGravity(getGravity());

        // 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(ContextCompat.getColor(getContext(), android.R.color.transparent));
        }
    }
}

From source file:org.jraf.android.bikey.app.ride.map.RideMapActivity.java

private boolean hasNavigationBar() {
    Resources res = getResources();
    int resourceId = res.getIdentifier("config_showNavigationBar", "bool", "android");
    if (resourceId != 0) {
        boolean hasNav = res.getBoolean(resourceId);

        return hasNav;
    }//  w ww  . j  a  v a  2s.c o m
    // Fallback
    return !ViewConfiguration.get(this).hasPermanentMenuKey();
}

From source file:de.appplant.cordova.plugin.background.ForegroundService.java

/**
 * Retrieves the resource ID of the app icon.
 *
 * @return/*  w  w  w . j  a va  2s .c  om*/
 *      The resource ID of the app icon
 */
private int getIconResId() {
    JSONObject settings = BackgroundMode.getSettings();
    Context context = getApplicationContext();
    Resources res = context.getResources();
    String pkgName = context.getPackageName();

    int resId = res.getIdentifier(settings.optString("icon", "icon"), "drawable", pkgName);

    return resId;
}

From source file:com.daxstudio.sa.base.android.BaseDialogFragment.java

@Override
public void onStart() {
    super.onStart();
    // Less dimmed background; see http://stackoverflow.com/q/13822842/56285
    final Window window = getDialog().getWindow();
    final WindowManager.LayoutParams params = window.getAttributes();
    params.dimAmount = getDimAmount(); // dim only a little bit
    window.setAttributes(params);//from www.j  a v  a 2  s  . c  o  m

    window.setLayout(getWidth(), getHeight());
    window.setGravity(getGravity());

    // 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));
        }
    }
}