Example usage for android.content.res Resources getSystem

List of usage examples for android.content.res Resources getSystem

Introduction

In this page you can find the example usage for android.content.res Resources getSystem.

Prototype

public static Resources getSystem() 

Source Link

Document

Return a global shared Resources object that provides access to only system resources (no application resources), and is not configured for the current screen (can not use dimension units, does not change based on orientation, etc).

Usage

From source file:net.kjmaster.cookiemom.global.CookieActionActivity.java

private View getDoneButton() {
    Resources resources = Resources.getSystem();
    if (resources == null) {
        return null;
    }//from   ww w. j  a  v  a2s . c o m
    int doneButtonId = resources.getIdentifier("action_mode_close_button", "id", "android");
    return this.findViewById(doneButtonId);
}

From source file:com.jams.music.player.GridViewFragment.GridViewCardsAdapter.java

public GridViewCardsAdapter(Context context, GridViewFragment gridViewFragment,
        HashMap<Integer, String> dbColumnsMap) {

    super(context, -1, gridViewFragment.getCursor(), new String[] {}, new int[] {}, 0);
    mContext = context;//from  www .  ja v a 2  s . c o  m
    mGridViewFragment = gridViewFragment;
    mApp = (Common) mContext.getApplicationContext();
    mDBColumnsMap = dbColumnsMap;

    //Calculate the height and width of each item image.
    DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();

    if (mApp.isTabletInPortrait()) {
        //3 column layout.
        mWidth = (metrics.widthPixels) / 3;
        mHeight = mWidth + (mWidth / 4);
    } else if (mApp.isPhoneInLandscape() || mApp.isTabletInLandscape()) {
        //4 column layout.
        mWidth = (metrics.widthPixels) / 4;
        mHeight = mWidth + (mWidth / 5);
    } else {
        //2 column layout.
        mWidth = (metrics.widthPixels) / 3;
        mHeight = mWidth + (mWidth / 4);
    }

}

From source file:com.selcukcihan.android.namewizard.wizard.ui.BirthDateFragment.java

public static void hideYear(View view) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        int yearSpinnerId = Resources.getSystem().getIdentifier("year", "id", "android");
        if (yearSpinnerId != 0) {
            View yearSpinner = view.findViewById(yearSpinnerId);
            if (yearSpinner != null) {
                yearSpinner.setVisibility(View.GONE);
            }/*from   w w  w .  jav  a  2s  .  c o m*/
        }
    } else { //Older SDK versions
        Field f[] = view.getClass().getDeclaredFields();
        for (Field field : f) {
            if (field.getName().equals("mYearPicker") || field.getName().equals("mYearSpinner")) {
                field.setAccessible(true);
                Object yearPicker = null;
                try {
                    yearPicker = field.get(view);
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
                ((View) yearPicker).setVisibility(View.GONE);
            }
        }
    }
}

From source file:com.github.shareme.gwsmaterialuikit.library.toast.ToastCompat.java

/**
 * Construct an empty Toast object.  You must call {@link #setView} before you
 * can call {@link #show}.//  w w w. j  a v  a 2s. com
 *
 * @param context  The context to use.  Usually your {@link android.app.Application}
 *                 or {@link android.app.Activity} object.
 */
public ToastCompat(Context context) {
    mContext = context;
    mTN = new TN();
    mTN.mY = context.getResources()
            .getDimensionPixelSize(Resources.getSystem().getIdentifier("toast_y_offset", "dimen", "android"));
    mTN.mGravity = context.getResources().getInteger(
            Resources.getSystem().getIdentifier("config_toastDefaultGravity", "integer", "android"));
}

From source file:com.vinaysshenoy.okulus.OkulusImageView.java

/**
 * Converts a raw pixel value to a dp value, based on the device density
 *///  w  w w.  ja  v  a  2 s.  c o m
private static float pxToDp(float px) {
    return px / Resources.getSystem().getDisplayMetrics().density;
}

From source file:it.geosolutions.android.map.fragment.sources.SourcesFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    //set the listener for add button
    ImageButton add = (ImageButton) view.findViewById(R.id.sources_add);
    add.setOnClickListener(new OnClickListener() {

        @Override//  www  .  ja v  a  2s .  c o  m
        public void onClick(View v) {
            Intent i = new Intent(getActivity(), NewSourceActivity.class);
            getActivity().startActivityForResult(i, Constants.requestCodes.CREATE_SOURCE);

        }
    });

    //
    //Set Contextual ACTION BAR CALLBACKS
    //
    final SourcesFragment callback = this;
    ListView lv = getListView();
    lv.setLongClickable(true);
    lv.setClickable(true);
    lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    //edit - delete
    lv.setOnItemLongClickListener(new OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            LayerStore sel = adapter.getItem(position);

            if (!selected.contains(sel)) {
                getListView().setItemChecked(position, true);
                selected.add(sel);

            } else {
                getListView().setItemChecked(position, false);
                selected.remove(sel);
            }
            int numSelected = selected.size();
            if (numSelected > 0) {
                if (actionMode != null) {
                    updateCAB(numSelected);
                } else {
                    actionMode = getSherlockActivity().startActionMode(callback);
                    //override the done button to deselect all when the button is pressed
                    int doneButtonId = Resources.getSystem().getIdentifier("action_mode_close_button", "id",
                            "android");
                    View doneButton = getActivity().findViewById(doneButtonId);
                    doneButton.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            getListView().clearChoices();
                            selected = new ArrayList<LayerStore>();
                            actionMode.finish();
                        }
                    });
                }
            } else {
                if (actionMode != null) {
                    actionMode.finish();
                }
            }
            view.setSelected(true);
            return true;
        }
    });
    //browse
    lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            LayerStore s = (LayerStore) adapter.getItem(position);
            s.openDetails(getSherlockActivity());
        }
    });

    super.onViewCreated(view, savedInstanceState);
}

From source file:com.vinaysshenoy.okulus.OkulusImageView.java

/**
 * Converts a raw dp value to a pixel value, based on the device density
 *///from  w  w  w  .jav a 2  s.c  o m
public static float dpToPx(float dp) {
    return dp * Resources.getSystem().getDisplayMetrics().density;
}

From source file:org.mariotaku.twidere.view.NameView.java

private float calculateTextSize(final int unit, final float size) {
    Context c = getContext();//from w ww.  j a  va  2s.com
    Resources r;

    if (c == null)
        r = Resources.getSystem();
    else
        r = c.getResources();
    return TypedValue.applyDimension(unit, size, r.getDisplayMetrics());
}

From source file:com.example.android.notepad.CMNotesProvider.java

@Override
public Uri insert(Uri uri, ContentValues initialValues) {
    // Validate the requested uri
    if (sUriMatcher.match(uri) != NOTES) {
        throw new IllegalArgumentException("Unknown URI " + uri);
    }/* w w  w  . j a  v  a 2  s . co m*/

    ContentValues values;
    if (initialValues != null) {
        values = new ContentValues(initialValues);
    } else {
        values = new ContentValues();
    }

    Long now = Long.valueOf(System.currentTimeMillis());

    // Make sure that the fields are all set
    if (values.containsKey(NotePad.Notes.CREATED_DATE) == false) {
        values.put(NotePad.Notes.CREATED_DATE, now);
    }

    if (values.containsKey(NotePad.Notes.MODIFIED_DATE) == false) {
        values.put(NotePad.Notes.MODIFIED_DATE, now);
    }

    if (values.containsKey(NotePad.Notes.TITLE) == false) {
        Resources r = Resources.getSystem();
        values.put(NotePad.Notes.TITLE, r.getString(android.R.string.untitled));
    }

    if (values.containsKey(NotePad.Notes.NOTE) == false) {
        values.put(NotePad.Notes.NOTE, "");
    }

    CMAdapter cmadapter = new CMAdapter();
    // for the moment, use time for the key
    String key = System.currentTimeMillis() + "";
    String new_key = cmadapter.updateValue(key, values);
    if (new_key != null) {
        System.out.println("Set key: " + key + ", got key: " + new_key);
        Uri noteUri = ContentUris.withAppendedId(NotePad.Notes.CONTENT_URI, Long.parseLong(new_key));
        getContext().getContentResolver().notifyChange(noteUri, null);
        return noteUri;
    }

    //        SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    //        long rowId = db.insert(NOTES_TABLE_NAME, Notes.NOTE, values);
    //        if (rowId > 0) {
    //      Uri noteUri = ContentUris.withAppendedId(NotePad.Notes.CONTENT_URI, rowId);
    //            getContext().getContentResolver().notifyChange(noteUri, null);
    //      return noteUri;
    //        }

    throw new SQLException("Failed to insert row into " + uri);
}

From source file:com.grarak.kerneladiutor.fragments.other.SettingsFragment.java

private void init() {
    addPreferencesFromResource(R.xml.settings);

    if (Utils.DONATED) {
        getPreferenceScreen().removePreference(findPreference(KEY_AD_VIEW));
    }//from  w  w  w  .j  a va 2  s.  c  om

    SwitchPreferenceCompat forceEnglish = (SwitchPreferenceCompat) findPreference(KEY_FORCE_ENGLISH);
    if (Resources.getSystem().getConfiguration().locale.getLanguage().startsWith("en")) {
        getPreferenceScreen().removePreference(forceEnglish);
    } else {
        forceEnglish.setOnPreferenceChangeListener(this);
    }

    if (Utils.hideStartActivity()) {
        ((PreferenceCategory) findPreference(KEY_USER_INTERFACE))
                .removePreference(findPreference(KEY_MATERIAL_ICON));
    } else {
        findPreference(KEY_MATERIAL_ICON).setOnPreferenceChangeListener(this);
    }

    findPreference(KEY_DARK_THEME).setOnPreferenceChangeListener(this);
    findPreference(KEY_BANNER_RESIZER).setOnPreferenceClickListener(this);
    findPreference(KEY_HIDE_BANNER).setOnPreferenceChangeListener(this);
    findPreference(KEY_ACCENT_COLOR).setOnPreferenceClickListener(this);
    findPreference(KEY_SECTIONS_ICON).setOnPreferenceChangeListener(this);
    findPreference(KEY_APPLY_ON_BOOT_TEST).setOnPreferenceClickListener(this);
    findPreference(KEY_LOGCAT).setOnPreferenceClickListener(this);

    if (Utils.existFile("/proc/last_kmsg") || Utils.existFile("/sys/fs/pstore/console-ramoops")) {
        findPreference(KEY_LAST_KMSG).setOnPreferenceClickListener(this);
    } else {
        ((PreferenceCategory) findPreference(KEY_DEBUGGING_CATEGORY))
                .removePreference(findPreference(KEY_LAST_KMSG));
    }

    findPreference(KEY_DMESG).setOnPreferenceClickListener(this);
    findPreference(KEY_SET_PASSWORD).setOnPreferenceClickListener(this);
    findPreference(KEY_DELETE_PASSWORD).setOnPreferenceClickListener(this);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M
            || !FingerprintManagerCompat.from(getActivity()).isHardwareDetected()) {
        ((PreferenceCategory) findPreference(KEY_SECURITY_CATEGORY))
                .removePreference(findPreference(KEY_FINGERPRINT));
    } else {
        mFingerprint = findPreference(KEY_FINGERPRINT);
        mFingerprint.setEnabled(!Prefs.getString("password", "", getActivity()).isEmpty());
    }

    PreferenceCategory sectionsCategory = (PreferenceCategory) findPreference(KEY_SECTIONS);
    for (NavigationActivity.NavigationFragment navigationFragment : NavigationActivity.sFragments) {
        Fragment fragment = navigationFragment.mFragment;
        int id = navigationFragment.mId;

        if (fragment != null && fragment.getClass() != SettingsFragment.class) {
            SwitchPreferenceCompat switchPreference = new SwitchPreferenceCompat(
                    new ContextThemeWrapper(getActivity(), R.style.Preference_SwitchPreferenceCompat_Material));
            switchPreference.setSummary(getString(id));
            switchPreference.setKey(fragment.getClass().getSimpleName() + "_enabled");
            switchPreference.setChecked(
                    Prefs.getBoolean(fragment.getClass().getSimpleName() + "_enabled", true, getActivity()));
            switchPreference.setOnPreferenceChangeListener(this);
            switchPreference.setPersistent(false);
            sectionsCategory.addPreference(switchPreference);
        }
    }
}