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.landenlabs.all_devtool.ConsoleFragment.java

private static int pxToDp(int px) {
    return (int) (px / Resources.getSystem().getDisplayMetrics().density);
}

From source file:com.nttec.everychan.ui.presentation.HtmlParser.java

private static void startImg(SpannableStringBuilder text, Attributes attributes, HtmlParser.ImageGetter img) {
    String src = attributes.getValue("", "src");
    Drawable d = null;/*  w  w  w  .j ava2s. co  m*/

    if (img != null) {
        d = img.getDrawable(src);
    }

    if (d == null) {
        d = ResourcesCompat.getDrawable(Resources.getSystem(), android.R.drawable.ic_menu_report_image, null);
        d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
    }

    int len = text.length();
    text.append("\uFFFC");

    text.setSpan(new ImageSpan(d, src), len, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}

From source file:android.support.v7.widget.AppCompatTextViewAutoSizeHelper.java

/** @hide */
@RestrictTo(LIBRARY_GROUP)/*from w ww .  j a v  a  2 s .  com*/
void setTextSizeInternal(int unit, float size) {
    Resources res = mContext == null ? Resources.getSystem() : mContext.getResources();

    setRawTextSize(TypedValue.applyDimension(unit, size, res.getDisplayMetrics()));
}

From source file:com.nttec.everychan.ui.presentation.HtmlParser.java

private static void endFont(SpannableStringBuilder text) {
    int len = text.length();
    Object obj = getLast(text, Font.class);
    int where = text.getSpanStart(obj);

    text.removeSpan(obj);//from w w w.j a  va  2 s.c o m

    if (where != len) {
        Font f = (Font) obj;

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

        if (f.mStyle != null) {
            List<Object> styleSpans = parseStyleAttributes(f.mStyle);
            for (Object span : styleSpans) {
                text.setSpan(span, where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
    }
}

From source file:com.example.angelina.travelapp.map.MapFragment.java

/**
 * Populate the place detail contained/*  ww w  .  ja  v  a 2 s . c  om*/
 * within the bottom sheet
 * @param place - Place item selected by user
 */
@Override
public final void showDetail(final Place place) {
    final TextView txtName = (TextView) mBottomSheet.findViewById(R.id.placeName);
    txtName.setText(place.getName());
    String address = place.getAddress();
    final String[] splitStrs = TextUtils.split(address, ",");
    if (splitStrs.length > 0) {
        address = splitStrs[0];
    }
    final TextView txtAddress = (TextView) mBottomSheet.findViewById(R.id.placeAddress);
    txtAddress.setText(address);
    final TextView txtPhone = (TextView) mBottomSheet.findViewById(R.id.placePhone);
    txtPhone.setText(place.getPhone());

    final LinearLayout linkLayout = (LinearLayout) mBottomSheet.findViewById(R.id.linkLayout);
    // Hide the link placeholder if no link is found
    if (place.getURL().isEmpty()) {
        linkLayout.setLayoutParams(new LinearLayoutCompat.LayoutParams(0, 0));
        linkLayout.requestLayout();
    } else {
        final int height = (int) (48 * Resources.getSystem().getDisplayMetrics().density);
        linkLayout.setLayoutParams(
                new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, height));
        linkLayout.requestLayout();
        final TextView txtUrl = (TextView) mBottomSheet.findViewById(R.id.placeUrl);
        txtUrl.setText(place.getURL());
    }

    final TextView txtType = (TextView) mBottomSheet.findViewById(R.id.placeType);
    txtType.setText(place.getType());

    // Assign the appropriate icon
    final Drawable d = CategoryHelper.getDrawableForPlace(place, getActivity());
    txtType.setCompoundDrawablesWithIntrinsicBounds(d, null, null, null);
    bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);

    // Center map on selected place
    mPresenter.centerOnPlace(place);
    mShowSnackbar = false;
    centeredPlaceName = place.getName();
}

From source file:com.achep.acdisplay.Config.java

/**
 * @return the size (or height only) of collapsed views.
 * @see #getIconSizePx()/*from  w  ww .j  av a  2  s  .  c  o  m*/
 * @see #ICON_SIZE_DP
 * @see #ICON_SIZE_PX
 */
public int getIconSize(String type) {
    switch (type) {
    case ICON_SIZE_PX:
        DisplayMetrics dm = Resources.getSystem().getDisplayMetrics();
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mUiIconSize, dm);
    case ICON_SIZE_DP:
        return mUiIconSize;
    default:
        throw new IllegalArgumentException(type + " is not a valid icon size type.");
    }
}

From source file:com.achep.acdisplay.ui.fragments.AcDisplayFragment.java

/**
 * Changes current scene to given one.//from ww w . j ava 2  s  .com
 *
 * @see #showWidget(com.achep.acdisplay.ui.components.Widget)
 */
@SuppressLint("NewApi")
protected synchronized final void goScene(@NonNull SceneCompat sceneCompat, boolean animate) {
    if (mCurrentScene == sceneCompat)
        return;
    mCurrentScene = sceneCompat;
    if (DEBUG)
        Log.d(TAG, "Going to " + sceneCompat);

    if (Device.hasKitKatApi())
        animate &= mSceneContainer.isLaidOut();
    if (!animate) {
        sceneCompat.enter();
        return;
    }

    if (Device.hasKitKatApi()) {
        final Scene scene = sceneCompat.getScene();
        try {
            // This must be a synchronization problem with Android's Scene or TransitionManager,
            // but those were declared as final classes, so I have no idea how to fix it.
            TransitionManager.go(scene, mTransitionSwitchScene);
        } catch (IllegalStateException e) {
            Log.w(TAG, "TransitionManager has failed switching scenes!");

            ViewGroup viewGroup = (ViewGroup) getSceneView().getParent();
            viewGroup.removeView(getSceneView());

            try {
                // Reset internal scene's tag to make it work again.
                int id = Resources.getSystem().getIdentifier("current_scene", "id", "android");
                Method method = View.class.getMethod("setTagInternal", int.class, Object.class);
                method.setAccessible(true);
                method.invoke(viewGroup, id, null);
            } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e2) {
                throw new RuntimeException("An attempt to fix the TransitionManager has failed.");
            }

            TransitionManager.go(scene, mTransitionSwitchScene);
        }
    } else {
        sceneCompat.enter();

        if (getActivity() != null) {
            // TODO: Better animation for Jelly Bean users.
            float density = getResources().getDisplayMetrics().density;
            getSceneView().setAlpha(0.6f);
            getSceneView().setRotationX(6f);
            getSceneView().setTranslationY(6f * density);
            getSceneView().animate().alpha(1).rotationX(0).translationY(0);
        }
    }
}

From source file:ti.modules.titanium.ui.widget.collectionview.TiCollectionView.java

public TiCollectionView(TiViewProxy proxy, Activity activity) {
    super(proxy);

    // initializing variables
    sections = Collections.synchronizedList(new ArrayList<AbsListSectionProxy>());
    itemTypeCount = new AtomicInteger(CUSTOM_TEMPLATE_ITEM_TYPE);
    defaultTemplateBinding = defaultTemplateKey;
    defaultTemplate.setType(BUILT_IN_TEMPLATE_ITEM_TYPE);
    processTemplates(null);//w w w.j  a  va2s .co m

    caseInsensitive = true;
    ignoreExactMatch = false;

    // handling marker
    HashMap<String, Integer> preloadMarker = ((AbsListViewProxy) proxy).getPreloadMarker();
    if (preloadMarker != null) {
        setMarker(preloadMarker);
    } else {
        resetMarker();
    }

    final KrollProxy fProxy = proxy;
    layoutManager = new TiGridLayoutManager(activity);

    // trick to get scrollbar to be initialized!
    mRecyclerView = new FastScrollRecyclerView(activity, null,
            Resources.getSystem().getIdentifier("listViewStyle", "attr", "android")) {
        // private boolean viewFocused = false;
        private boolean selectionSet = false;

        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            // if ((Build.VERSION.SDK_INT >= 18 && !changed && viewFocused))
            // {
            // viewFocused = false;
            // super.onLayout(changed, left, top, right, bottom);
            // return;
            // }
            // Starting with API 21, setSelection() triggers another layout
            // pass, so we need to end it here to prevent
            // an infinite loop
            if (Build.VERSION.SDK_INT >= 21 && selectionSet) {
                selectionSet = false;
                return;
            }
            OnFocusChangeListener focusListener = null;
            View focusedView = findFocus();
            int cursorPosition = -1;
            if (focusedView != null) {
                if (focusedView instanceof EditText) {
                    cursorPosition = ((EditText) focusedView).getSelectionStart();
                }
                OnFocusChangeListener listener = focusedView.getOnFocusChangeListener();
                if (listener != null && listener instanceof TiUIView) {
                    focusedView.setOnFocusChangeListener(null);
                    focusListener = listener;
                }
            }
            if (focusedView != null) {
                setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
            }
            super.onLayout(changed, left, top, right, bottom);
            setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);

            if (changed) {
                TiUIHelper.firePostLayoutEvent(TiCollectionView.this);
            }

            // Layout is finished, re-enable focus events.
            if (focusedView != null) {
                // If the configuration changed, we manually fire the blur
                // event
                if (changed) {
                    focusedView.setOnFocusChangeListener(focusListener);
                    if (focusListener != null) {
                        focusListener.onFocusChange(focusedView, false);
                    }
                } else {
                    // Ok right now focus is with listView. So set it back
                    // to the focusedView
                    // viewFocused = true;
                    focusedView.requestFocus();
                    focusedView.setOnFocusChangeListener(focusListener);
                    // Restore cursor position
                    if (cursorPosition != -1) {
                        ((EditText) focusedView).setSelection(cursorPosition);
                        selectionSet = true;
                    }

                }
            }
        }
        // @Override
        // protected void onLayout(boolean changed, int left, int top,
        // int right, int bottom) {
        //
        // super.onLayout(changed, left, top, right, bottom);
        // if (changed) {
        // TiUIHelper.firePostLayoutEvent(TiCollectionView.this);
        // }
        //
        // }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            if (mColumnsWidth != null && !mColumnsWidth.isUnitFixed()) {
                layoutManager.setColumnWidth(mColumnsWidth.getAsPixels(this));
                // } else if (gridAdapter.updateNumColumns()) {
                // adapter.notifyDataSetChanged();
            }
            layoutManager.requestColumnUpdate();
        }

        @Override
        public void dispatchSetPressed(boolean pressed) {
            if (propagateSetPressed(this, pressed)) {
                super.dispatchSetPressed(pressed);
            }
        }

        @Override
        public boolean dispatchTouchEvent(MotionEvent event) {
            if (touchPassThrough(getParentViewForChild(), event))
                return false;
            return super.dispatchTouchEvent(event);
        }

        // @Override
        // public boolean dispatchTouchEvent(MotionEvent event) {
        // if (touchPassThrough == true)
        // return false;
        // return super.dispatchTouchEvent(event);
        // }

        @Override
        protected void dispatchDraw(Canvas canvas) {
            try {
                super.dispatchDraw(canvas);
            } catch (IndexOutOfBoundsException e) {
                // samsung error
            }
        }
    };
    // mRecyclerView.setClipChildren(false);

    mAdapter = new TiBaseAdapter(mRecyclerView.getContext(), null);
    mAdapter.setDisplayHeaders(true);
    mSwipeMenuTouchListener = new SwipeMenuTouchListener(this);
    mRecyclerView.addOnItemTouchListener(mSwipeMenuTouchListener);
    mRecyclerView.setItemAnimator(new TiItemAnimator());
    mRecyclerView.setHorizontalScrollBarEnabled(false);
    mRecyclerView.setVerticalScrollBarEnabled(true);
    mRecyclerView.setHasFixedSize(true);
    layoutManager.setSmoothScrollbarEnabled(true);
    mRecyclerView.addOnScrollListener(new OnScrollListener() {
        private boolean scrollTouch = false;
        private Timer endTimer = null;

        public void cancelEndCall() {
            if (endTimer != null) {
                endTimer.cancel();
                endTimer = null;
            }
        }

        public void delayEndCall() {
            cancelEndCall();
            endTimer = new Timer();

            TimerTask action = new TimerTask() {
                public void run() {
                    scrollTouch = false;
                    if (fProxy.hasListeners(TiC.EVENT_SCROLLEND, false)) {
                        fProxy.fireEvent(TiC.EVENT_SCROLLEND, dictForScrollEvent(), false, false);
                    }
                }

            };

            this.endTimer.schedule(action, 200);
        }

        @Override
        public void onScrollStateChanged(RecyclerView view, int scrollState) {

            view.requestDisallowInterceptTouchEvent(scrollState != ViewPager.SCROLL_STATE_IDLE);
            if (scrollState == RecyclerView.SCROLL_STATE_IDLE) {
                if (scrollTouch) {
                    delayEndCall();
                }
            } else if (scrollState == RecyclerView.SCROLL_STATE_SETTLING) {
                cancelEndCall();
            } else if (scrollState == RecyclerView.SCROLL_STATE_DRAGGING) {
                cancelEndCall();
                if (hideKeyboardOnScroll && hasFocus()) {
                    blur();
                }
                if (scrollTouch == false) {
                    scrollTouch = true;
                    if (fProxy.hasListeners(TiC.EVENT_SCROLLSTART, false)) {
                        fProxy.fireEvent(TiC.EVENT_SCROLLSTART, dictForScrollEvent(), false, false);
                    }
                }
            }
        }

        @Override
        public void onScrolled(RecyclerView view, int dx, int dy) {
            if (dx == 0 && dy == 0) {
                return;
            }

            if (fProxy.hasListeners(TiC.EVENT_SCROLL, false)) {
                fProxy.fireEvent(TiC.EVENT_SCROLL, dictForScrollEvent(), false, false);
            }
        }
    });

    // mRecyclerView.setOnStickyHeaderChangedListener(
    // new OnStickyHeaderChangedListener() {
    //
    // @Override
    // public void onStickyHeaderChanged(
    // StickyListHeadersListViewAbstract l, View header,
    // int itemPosition, long headerId) {
    // // for us headerId is the section index
    // int sectionIndex = (int) headerId;
    // if (fProxy.hasListeners(TiC.EVENT_HEADER_CHANGE,
    // false)) {
    // KrollDict data = new KrollDict();
    // AbsListSectionProxy section = null;
    // synchronized (sections) {
    // if (sectionIndex >= 0
    // && sectionIndex < sections.size()) {
    // section = sections.get(sectionIndex);
    // } else {
    // return;
    // }
    // }
    // data.put(TiC.PROPERTY_HEADER_VIEW, section
    // .getHoldedProxy(TiC.PROPERTY_HEADER_VIEW));
    // data.put(TiC.PROPERTY_SECTION, section);
    // data.put(TiC.PROPERTY_SECTION_INDEX, sectionIndex);
    // fProxy.fireEvent(TiC.EVENT_HEADER_CHANGE, data,
    // false, false);
    // }
    // }
    // });

    mRecyclerView.setEnabled(true);
    getLayoutParams().autoFillsHeight = true;
    getLayoutParams().autoFillsWidth = true;
    mRecyclerView.setFocusable(true);
    mRecyclerView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);

    // try {
    //     isCheck = TiRHelper.getApplicationResource(
    //             "drawable.btn_check_buttonless_on_64");
    //     hasChild = TiRHelper.getApplicationResource("drawable.btn_more_64");
    //     disclosure = TiRHelper
    //             .getApplicationResource("drawable.disclosure_64");
    // } catch (ResourceNotFoundException e) {
    //     Log.e(TAG, "XML resources could not be found!!!", Log.DEBUG_MODE);
    // }

    // RelativeLayout layout = new RelativeLayout(proxy.getActivity()) {
    // @Override
    // protected void onLayout(boolean changed, int left, int top,
    // int right, int bottom) {
    // super.onLayout(changed, left, top, right, bottom);
    // if (changed) {
    // TiUIHelper.firePostLayoutEvent(TiCollectionView.this);
    // }
    // }
    //
    // @Override
    // public void dispatchSetPressed(boolean pressed) {
    // if (propagateSetPressed(this, pressed)) {
    // super.dispatchSetPressed(pressed);
    // }
    // }
    //
    // @Override
    // public boolean dispatchTouchEvent(MotionEvent event) {
    // if (touchPassThrough(getParentViewForChild(), event))
    // return false;
    // return super.dispatchTouchEvent(event);
    // }
    //
    // };
    // layout.addView(mRecyclerView);
    setNativeView(mRecyclerView);

    // needs to be fired after because
    // getStickyHeadersHolder will be called and need nativeView
    mRecyclerView.setLayoutManager(layoutManager);
    mAdapter.setLayoutManager(layoutManager);
    mRecyclerView.setAdapter(mAdapter);
}

From source file:com.daiv.android.twitter.ui.drawer_activities.DrawerActivity.java

public void setUpTheme() {

    actionBar = getActionBar();//w  ww  .j a  v  a 2 s .  com

    if (!getResources().getBoolean(R.bool.isTablet)) {
        actionBar.setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
    } else {
        actionBar.setIcon(R.mipmap.ic_launcher);
    }

    if (Build.VERSION.SDK_INT > 18 && settings.uiExtras
            && (getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE
                    || getResources().getBoolean(R.bool.isTablet))
            && !MainActivity.isPopup) {
        translucent = true;
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION
                | WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

        try {
            int immersive = android.provider.Settings.System.getInt(getContentResolver(), "immersive_mode");

            if (immersive == 1) {
                translucent = false;
            }
        } catch (Exception e) {
        }
    } else {
        translucent = false;
    }

    Utils.setUpTheme(context, settings);

    /*if (settings.addonTheme) {
    getWindow().getDecorView().setBackgroundColor(settings.backgroundColor);
    } else {
    TypedArray a = context.getTheme().obtainStyledAttributes(new int[]{R.attr.windowBackground});
    int resource = a.getResourceId(0, 0);
    a.recycle();
            
    getWindow().getDecorView().setBackgroundResource(resource);
    }*/

    // this is a super hacky workaround for the theme problems that some people were having... but it works ok
    int actionBarTitleId = 0;
    TextView title = null;
    try {
        actionBarTitleId = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
    } catch (Exception e) {
        // just in case
    }

    if (actionBarTitleId > 0) {
        title = (TextView) findViewById(actionBarTitleId);
    }

    switch (settings.theme) {
    case AppSettings.THEME_LIGHT:
        getActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.ab_solid_light_holo));
        if (title != null) {
            title.setTextColor(Color.BLACK);
        }
        break;
    case AppSettings.THEME_DARK:
        getActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.ab_solid_dark));
        if (title != null) {
            title.setTextColor(Color.WHITE);
        }
        break;
    case AppSettings.THEME_BLACK:
        getActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.ab_solid_black));
        if (title != null) {
            title.setTextColor(Color.WHITE);
        }
        break;
    }

    Utils.setActionBar(context, true);
}

From source file:com.mobicage.rogerthat.util.ui.SendMessageView.java

private void setPictureSelected() {
    if (!new File(mUriSavedFile.getPath()).exists()) {
        UIUtils.showLongToast(mActivity, mActivity.getString(R.string.error_please_try_again));
        return;// w ww  . j a  v a  2  s  . com
    }

    IOUtils.compressPicture(mUriSavedFile, 600000);
    mUploadFileExtenstion = AttachmentViewerActivity.CONTENT_TYPE_JPEG;

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = 4;

    Bitmap bitmap = ImageHelper.getBitmapFromFile(mUriSavedFile.getPath(), options);
    Drawable d = new BitmapDrawable(Resources.getSystem(), bitmap);
    mAttachmentPreview.setImageDrawable(d);
    mAttachmentContainer.setVisibility(View.VISIBLE);

    mHasImageSelected = true;
    initImageButtonsNavigation();
}