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:com.arta.lib.widget.crouton.Manager.java

@TargetApi(19)
private void handleTranslucentActionBar(ViewGroup.MarginLayoutParams params, Activity activity) {
    // Translucent status is only available as of Android 4.4 Kit Kat.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        final int flags = activity.getWindow().getAttributes().flags;
        final int translucentStatusFlag = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
        /* Checks whether translucent status is enabled for this window.
        * If true, sets the top margin to show the crouton just below the action bar. */
        if ((flags & translucentStatusFlag) == translucentStatusFlag) {
            final int actionBarContainerId = Resources.getSystem().getIdentifier("action_bar_container", "id",
                    "android");
            final View actionBarContainer = activity.findViewById(actionBarContainerId);
            // The action bar is present: the app is using a Holo theme.
            if (actionBarContainer != null) {
                final ViewGroup.MarginLayoutParams marginParams = (ViewGroup.MarginLayoutParams) params;
                marginParams.topMargin = actionBarContainer.getBottom();
            }//ww  w.j  a v  a 2s.com
        }
    }
}

From source file:com.haofeng.superne.thirdparty.crouton.Manager.java

@TargetApi(19)
private void handleTranslucentActionBar(ViewGroup.MarginLayoutParams params, Activity activity) {
    // Translucent status is only available as of Android 4.4 Kit Kat.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        final int flags = activity.getWindow().getAttributes().flags;
        final int translucentStatusFlag = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
        /* Checks whether translucent status is enabled for this window.
         * If true, sets the top margin to show the crouton just below the action bar. */
        if ((flags & translucentStatusFlag) == translucentStatusFlag) {
            final int actionBarContainerId = Resources.getSystem().getIdentifier("action_bar_container", "id",
                    "android");
            final View actionBarContainer = activity.findViewById(actionBarContainerId);
            // The action bar is present: the app is using a Holo theme.
            if (actionBarContainer != null) {
                final ViewGroup.MarginLayoutParams marginParams = (ViewGroup.MarginLayoutParams) params;
                marginParams.topMargin = actionBarContainer.getBottom();
            }/*from www  .  j a  v  a2 s.  c o  m*/
        }
    }
}

From source file:org.thomnichols.android.gmarks.GmarksProvider.java

@Override
public Uri insert(Uri uri, ContentValues initialValues) {
    // Validate the requested uri
    if (sUriMatcher.match(uri) != BOOKMARKS_URI) {
        throw new IllegalArgumentException("Unknown URI " + uri);
    }//  w  w  w .  jav a2 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(Bookmark.Columns.CREATED_DATE) == false) {
        values.put(Bookmark.Columns.CREATED_DATE, now);
    }

    if (values.containsKey(Bookmark.Columns.MODIFIED_DATE) == false) {
        values.put(Bookmark.Columns.MODIFIED_DATE, now);
    }

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

    if (values.containsKey(Bookmark.Columns.DESCRIPTION) == false) {
        values.put(Bookmark.Columns.DESCRIPTION, "");
    }

    SQLiteDatabase db = dbHelper.getWritableDatabase();
    long rowId = db.insert(BOOKMARKS_TABLE_NAME, "", values);
    if (rowId > 0) {
        Uri noteUri = ContentUris.withAppendedId(Bookmark.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

@Override
public boolean onPreferenceChange(Preference preference, Object o) {
    boolean checked = (boolean) o;
    String key = preference.getKey();
    switch (key) {
    case KEY_FORCE_ENGLISH:
        if (!checked) {
            Utils.setLocale(Resources.getSystem().getConfiguration().locale.getLanguage(), getActivity());
        }/*from  www  .  ja  va2  s .  c  om*/
    case KEY_DARK_THEME:
        getActivity().finish();
        Intent intent = new Intent(getActivity(), MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
        return true;
    case KEY_MATERIAL_ICON:
        Utils.setStartActivity(checked, getActivity());
        return true;
    case KEY_HIDE_BANNER:
        if (!Utils.DONATED) {
            ViewUtils.dialogDonate(getActivity()).show();
            return false;
        }
        return true;
    default:
        if (key.equals(KEY_SECTIONS_ICON) || key.endsWith("_enabled")) {
            if (key.equals(KEY_SECTIONS_ICON) && !Utils.DONATED) {
                ViewUtils.dialogDonate(getActivity()).show();
                return false;
            }
            Prefs.saveBoolean(key, checked, getActivity());
            ((NavigationActivity) getActivity()).appendFragments();
            return true;
        }
        break;
    }
    return false;
}

From source file:com.reliqartz.firsttipcalc.gui.MainActivity.java

@Override
public void applyFonts() {
    // Setup Fonts
    mFonts = new FontLibrary(this);
    // Apply two fonts to ActionBar, one for title & one for other TextViews
    mFontApplicator = new FontApplicator(getApplicationContext(), FontLibrary.ROBOTO_LIGHT)
            .applyFont(getWindow().getDecorView());
    final int actionBarTitleId = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
    ((TextView) getWindow().findViewById(actionBarTitleId)).setTypeface(mFonts.getFont(FontLibrary.ROBOTO));
}

From source file:com.landenlabs.all_UiDemo.frag.ImageScalesFrag.java

private Bitmap setScaledImage(final Drawable bgImage, View view, Bitmap prevScaled) {
    if (bgImage != null) {
        if (prevScaled != null)
            prevScaled.recycle();//from ww  w  .  jav  a  2  s.  c  o m

        int screenWidthPx = Resources.getSystem().getDisplayMetrics().widthPixels;
        int viewHeightPx = view.getMeasuredHeight();

        // view.setBackgroundResource(bgImage);
        if (bgImage instanceof BitmapDrawable) {
            BitmapDrawable bmDrawable = (BitmapDrawable) bgImage;
            Bitmap bmImage = bmDrawable.getBitmap();

            prevScaled = scaleCenterCrop(bmImage, screenWidthPx, viewHeightPx);
            view.setBackgroundDrawable(new BitmapDrawable(prevScaled));
        } else {

            // TODO - compute scale factor from screenWidthPx and viewHeightx
            Drawable scaleDrawable = new ScaleDrawable(bgImage, Gravity.NO_GRAVITY, 1.0f, 0.1f);
            view.setBackgroundDrawable(scaleDrawable);
        }
    }

    return prevScaled;
}

From source file:com.landenlabs.all_devtool.ConsoleFragment.java

private TextView addTextView(RelativeLayout relLayout, int belowId, int rightId, int widthDp, int heightDp,
        int padLeft) {
    float scale = Resources.getSystem().getDisplayMetrics().density;

    int widthParam = (widthDp != 0) ? dpToPx(widthDp) : RelativeLayout.LayoutParams.WRAP_CONTENT;
    int heightParam = (heightDp != 0) ? dpToPx(heightDp) : RelativeLayout.LayoutParams.WRAP_CONTENT;
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(widthParam, heightParam);

    // params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
    if (belowId != 0)
        params.addRule(RelativeLayout.BELOW, belowId);
    if (rightId != 0) {
        if (rightId > 0)
            params.addRule(RelativeLayout.ALIGN_RIGHT, rightId);
        else//  ww w.  j a  v a 2s.  com
            params.addRule(RelativeLayout.RIGHT_OF, -rightId);
    }

    // relLayout.setPadding(padLeft,  0,  0,  0);
    params.setMargins(padLeft, 0, 0, 0);

    TextView textView = new TextView(relLayout.getContext());
    textView.setLines(1);
    if (widthDp > 0)
        textView.setMaxWidth(dpToPx(widthDp));

    if (Build.VERSION.SDK_INT >= 17) {
        textView.setId(View.generateViewId());
    } else {
        textView.setId(sNextId++);
    }

    relLayout.addView(textView, params);
    return textView;
}

From source file:com.vuze.android.remote.AndroidUtilsUI.java

public static int spToPx(int sp) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp,
            Resources.getSystem().getDisplayMetrics());
}

From source file:org.protocoderrunner.apprunner.AppRunnerActivity.java

public void setToolBar(String name, Integer colorBg, Integer colorText) {
    mActionBarSet = true;//from  w w  w .ja  v  a  2  s .  c  o  m

    MLog.d("mocmoc", "setting tolbar for " + name + " " + mActionbar);

    if (mActionbar != null) {
        // home clickable if is running inside protocoderapp
        if (AppSettings.STANDALONE == false) {
            //mToolbar.setDisplayHomeAsUpEnabled(true);
            setToolbarBack();
        }

        // set color
        if (colorBg != null) {
            ColorDrawable d = new ColorDrawable();
            d.setColor(colorBg);
            mActionbar.setBackgroundDrawable(d);
        }

        // title
        if (name != null) {
            mActionbar.setTitle(name);
            MLog.d("mocmoc2", "setting tolbar for " + name + " " + mToolbar);

        }
        // set title color
        if (colorText != null) {
            int titleId = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
            TextView textTitleView = (TextView) findViewById(titleId);

            // apparently android-l doesnt have that resource
            if (textTitleView != null) {
                textTitleView.setTextColor(colorText);
            }
        }
    }
}

From source file:com.moonpi.swiftnotes.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Get lobster_two asset and create typeface
    // Set action bar title to lobster_two typeface
    lobsterTwo = Typeface.createFromAsset(getAssets(), "lobster_two.otf");

    actionBarTitle = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");

    TextView actionBarTitleView = null;//  w  w  w  .  j  a  va2 s  .  c  o m
    if (actionBarTitle != 0)
        actionBarTitleView = (TextView) getWindow().findViewById(actionBarTitle);

    if (actionBarTitleView != null) {
        if (lobsterTwo != null)
            actionBarTitleView.setTypeface(lobsterTwo);
    }

    readFromJSON();
    writeToJSON();
    readFromJSON();

    File folder = new File(Environment.getExternalStorageDirectory() + "/Swiftnotes");
    File backupFile = new File(folder, "swiftnotes_backup.json");

    if (backupFile.exists())
        backupFilePath = backupFile.getAbsolutePath();

    setContentView(R.layout.activity_main);

    listView = (ListView) findViewById(R.id.listView);
    ImageButton newNote = (ImageButton) findViewById(R.id.newNote);
    noNotes = (TextView) findViewById(R.id.noNotes);

    // Initialize NoteAdapter with notes array
    adapter = new NoteAdapter(this, notes);

    registerForContextMenu(listView);

    listView.setAdapter(adapter);
    listView.setOnItemClickListener(this);
    newNote.setOnClickListener(this);

    // If no notes, show 'Press + to add new note' text, invisible otherwise
    if (notes.length() == 0)
        noNotes.setVisibility(View.VISIBLE);
    else
        noNotes.setVisibility(View.INVISIBLE);
}