Example usage for android.util TypedValue TypedValue

List of usage examples for android.util TypedValue TypedValue

Introduction

In this page you can find the example usage for android.util TypedValue TypedValue.

Prototype

TypedValue

Source Link

Usage

From source file:android.support.v7ox.app.AppCompatDelegateImplV7.java

private ViewGroup createSubDecor() {
    TypedArray a = mContext.obtainStyledAttributes(R.styleable.AppCompatTheme);

    if (!a.hasValue(R.styleable.AppCompatTheme_windowActionBar_ox)) {
        a.recycle();//from w  w w .  j a va  2 s.com
        throw new IllegalStateException(
                "You need to use a Theme.AppCompat theme (or descendant) with this activity.");
    }

    if (a.getBoolean(R.styleable.AppCompatTheme_windowNoTitle_ox, false)) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
    } else if (a.getBoolean(R.styleable.AppCompatTheme_windowActionBar_ox, false)) {
        // Don't allow an action bar if there is no title.
        requestWindowFeature(FEATURE_SUPPORT_ACTION_BAR);
    }
    if (a.getBoolean(R.styleable.AppCompatTheme_windowActionBarOverlay_ox, false)) {
        requestWindowFeature(FEATURE_SUPPORT_ACTION_BAR_OVERLAY);
    }
    if (a.getBoolean(R.styleable.AppCompatTheme_windowActionModeOverlay_ox, false)) {
        requestWindowFeature(FEATURE_ACTION_MODE_OVERLAY);
    }
    mIsFloating = a.getBoolean(R.styleable.AppCompatTheme_android_windowIsFloating, false);
    a.recycle();

    final LayoutInflater inflater = LayoutInflater.from(mContext);
    ViewGroup subDecor = null;

    if (!mWindowNoTitle) {
        if (mIsFloating) {
            // If we're floating, inflate the dialog title decor
            subDecor = (ViewGroup) inflater.inflate(R.layout.abc_dialog_title_material, null);

            // Floating windows can never have an action bar, reset the flags
            mHasActionBar = mOverlayActionBar = false;
        } else if (mHasActionBar) {
            /**
             * This needs some explanation. As we can not use the android:theme attribute
             * pre-L, we emulate it by manually creating a LayoutInflater using a
             * ContextThemeWrapper pointing to actionBarTheme.
             */
            TypedValue outValue = new TypedValue();
            mContext.getTheme().resolveAttribute(R.attr.actionBarTheme_ox, outValue, true);

            Context themedContext;
            if (outValue.resourceId != 0) {
                themedContext = new ContextThemeWrapper(mContext, outValue.resourceId);
            } else {
                themedContext = mContext;
            }

            // Now inflate the view using the themed context and set it as the content view
            subDecor = (ViewGroup) LayoutInflater.from(themedContext).inflate(R.layout.abc_screen_toolbar,
                    null);

            mDecorContentParent = (DecorContentParent) subDecor.findViewById(R.id.decor_content_parent);
            mDecorContentParent.setWindowCallback(getWindowCallback());

            /**
             * Propagate features to DecorContentParent
             */
            if (mOverlayActionBar) {
                mDecorContentParent.initFeature(FEATURE_SUPPORT_ACTION_BAR_OVERLAY);
            }
            if (mFeatureProgress) {
                mDecorContentParent.initFeature(Window.FEATURE_PROGRESS);
            }
            if (mFeatureIndeterminateProgress) {
                mDecorContentParent.initFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
            }
        }
    } else {
        if (mOverlayActionMode) {
            subDecor = (ViewGroup) inflater.inflate(R.layout.abc_screen_simple_overlay_action_mode, null);
        } else {
            subDecor = (ViewGroup) inflater.inflate(R.layout.abc_screen_simple, null);
        }

        if (Build.VERSION.SDK_INT >= 21) {
            // If we're running on L or above, we can rely on ViewCompat's
            // setOnApplyWindowInsetsListener
            ViewCompat.setOnApplyWindowInsetsListener(subDecor, new OnApplyWindowInsetsListener() {
                @Override
                public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
                    final int top = insets.getSystemWindowInsetTop();
                    final int newTop = updateStatusGuard(top);

                    if (top != newTop) {
                        insets = insets.replaceSystemWindowInsets(insets.getSystemWindowInsetLeft(), newTop,
                                insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom());
                    }

                    // Now apply the insets on our view
                    return ViewCompat.onApplyWindowInsets(v, insets);
                }
            });
        } else {
            // Else, we need to use our own FitWindowsViewGroup handling
            ((FitWindowsViewGroup) subDecor)
                    .setOnFitSystemWindowsListener(new FitWindowsViewGroup.OnFitSystemWindowsListener() {
                        @Override
                        public void onFitSystemWindows(Rect insets) {
                            insets.top = updateStatusGuard(insets.top);
                        }
                    });
        }
    }

    if (subDecor == null) {
        throw new IllegalArgumentException("AppCompat does not support the current theme features: { "
                + "windowActionBar: " + mHasActionBar + ", windowActionBarOverlay: " + mOverlayActionBar
                + ", android:windowIsFloating: " + mIsFloating + ", windowActionModeOverlay: "
                + mOverlayActionMode + ", windowNoTitle: " + mWindowNoTitle + " }");
    }

    if (mDecorContentParent == null) {
        mTitleView = (TextView) subDecor.findViewById(R.id.title);
    }

    // Make the decor optionally fit system windows, like the window's decor
    ViewUtils.makeOptionalFitsSystemWindows(subDecor);

    final ViewGroup decorContent = (ViewGroup) mWindow.findViewById(android.R.id.content);
    final ContentFrameLayout abcContent = (ContentFrameLayout) subDecor
            .findViewById(R.id.action_bar_activity_content);

    // There might be Views already added to the Window's content view so we need to
    // migrate them to our content view
    while (decorContent.getChildCount() > 0) {
        final View child = decorContent.getChildAt(0);
        decorContent.removeViewAt(0);
        abcContent.addView(child);
    }

    // Now set the Window's content view with the decor
    mWindow.setContentView(subDecor);

    // Change our content FrameLayout to use the android.R.id.content id.
    // Useful for fragments.
    decorContent.setId(View.NO_ID);
    abcContent.setId(android.R.id.content);

    // The decorContent may have a foreground drawable set (windowContentOverlay).
    // Remove this as we handle it ourselves
    if (decorContent instanceof FrameLayout) {
        decorContent.setForeground(null);
    }

    abcContent.setAttachListener(new ContentFrameLayout.OnAttachListener() {
        @Override
        public void onAttachedFromWindow() {
        }

        @Override
        public void onDetachedFromWindow() {
            dismissPopups();
        }
    });

    return subDecor;
}

From source file:android.support.v7ox.app.ToolbarActionBar.java

private void ensureListMenuPresenter(Menu menu) {
    if (mListMenuPresenter == null && (menu instanceof MenuBuilder)) {
        MenuBuilder mb = (MenuBuilder) menu;

        Context context = mDecorToolbar.getContext();
        final TypedValue outValue = new TypedValue();
        final Resources.Theme widgetTheme = context.getResources().newTheme();
        widgetTheme.setTo(context.getTheme());

        // First apply the actionBarPopupTheme
        widgetTheme.resolveAttribute(R.attr.actionBarPopupTheme_ox, outValue, true);
        if (outValue.resourceId != 0) {
            widgetTheme.applyStyle(outValue.resourceId, true);
        }/*from   w w  w  .  ja  v a 2  s  .c o  m*/

        // Apply the panelMenuListTheme
        widgetTheme.resolveAttribute(R.attr.panelMenuListTheme_ox, outValue, true);
        if (outValue.resourceId != 0) {
            widgetTheme.applyStyle(outValue.resourceId, true);
        } else {
            widgetTheme.applyStyle(R.style.Theme_AppCompat_CompactMenu, true);
        }

        context = new ContextThemeWrapper(context, 0);
        context.getTheme().setTo(widgetTheme);

        // Finally create the list menu presenter
        mListMenuPresenter = new ListMenuPresenter(context, R.layout.abc_list_menu_item_layout);
        mListMenuPresenter.setCallback(new PanelMenuPresenterCallback());
        mb.addMenuPresenter(mListMenuPresenter);
    }
}

From source file:com.example.google.walkway.MainActivity.java

private void setSelectedPlace(int index) {
    Log.d(LOG_TAG, String.format("showSelectedPlace(%d)", index));

    // Toggle the selected place in the listview.
    mPlaceListView.getChildAt(mSelectedPlaceIndex).setSelected(false);
    mPlaceListView.getChildAt(index).setSelected(true);

    if (mPlaceViewPager != null) {
        mPlaceViewPager.setCurrentItem(index);
    }/*from   w ww.  j a v  a2 s  . c o  m*/

    // TODO reset the map zoom if details previously displayed

    // Set the non-selected place markers to a dots.
    mMarkers[mSelectedPlaceIndex].setIcon(BitmapDescriptorFactory.fromBitmap(getDotMarkerBitmap()));
    mMarkers[mSelectedPlaceIndex].setAnchor(.5f, .5f);

    // Replace the currently selected maker with the full marker.
    float hue = this.getResources().getInteger(R.integer.place_marker_hue);
    mMarkers[index].setIcon(BitmapDescriptorFactory.defaultMarker(hue));
    mMarkers[index].setAnchor(.5f, 1f);

    // Determine if the marker is in the middle 80% of the map view.
    LatLng coords = mMarkers[index].getPosition();
    Point point = mMap.getProjection().toScreenLocation(coords);

    View view = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getView();

    // XXX dupe code

    TypedValue tv = new TypedValue();
    int actionbarHeight = 0;
    if (getTheme().resolveAttribute(R.attr.actionBarSize, tv, true)) {
        actionbarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
    }

    // Pad the bottom of the map to accommodate the place viewpager.
    int viewPagerHeight = 0;
    if (mPlaceViewPager != null) {
        viewPagerHeight = mPlaceViewPager.getHeight();
    }

    // XXX end dupe code

    int width = view.getWidth();
    int height = view.getHeight() - viewPagerHeight - actionbarHeight;
    point.y -= actionbarHeight;

    if (point.x < .2 * width || point.x > .8 * width || point.y < .2 * height || point.y > .8 * height) {
        int recenterTime = getResources().getInteger(R.integer.map_recenter_ms);
        mMap.animateCamera(CameraUpdateFactory.newLatLng(coords), recenterTime, null);
    }

    mSelectedPlaceIndex = index;
}

From source file:com.miz.functions.MizLib.java

/**
 * Add a padding with a height of the ActionBar to the top of a given View
 * @param c/*from  ww  w .  j a va  2s  .c om*/
 * @param v
 */
public static void addActionBarPadding(Context c, View v) {
    int mActionBarHeight = 0;
    TypedValue tv = new TypedValue();
    if (c.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
        mActionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,
                c.getResources().getDisplayMetrics());
    else
        mActionBarHeight = 0; // No ActionBar style (pre-Honeycomb or ActionBar not in theme)

    v.setPadding(0, mActionBarHeight, 0, 0);
}

From source file:com.evandroid.musica.MainLyricActivity.java

@TargetApi(21)
public void setNavBarColor(Integer color) {
    if (Build.VERSION.SDK_INT >= 20) {
        if (color == null) {
            TypedValue typedValue = new TypedValue();
            Resources.Theme theme = getTheme();
            theme.resolveAttribute(android.R.attr.navigationBarColor, typedValue, true);
            color = typedValue.data;//  w w w .j a  va 2 s  . co m
        }
        getWindow().setNavigationBarColor(color);
    }
}

From source file:android.support.v7.app.ActionBarImplBase.java

@Override
public Context getThemedContext() {
    if (mThemedContext == null) {
        TypedValue outValue = new TypedValue();
        Resources.Theme currentTheme = mContext.getTheme();
        currentTheme.resolveAttribute(R.attr.actionBarWidgetTheme, outValue, true);
        final int targetThemeRes = outValue.resourceId;

        if (targetThemeRes != 0) {
            mThemedContext = new ContextThemeWrapper(mContext, targetThemeRes);
        } else {/*from  w  ww  . ja va  2s.  c om*/
            mThemedContext = mContext;
        }
    }
    return mThemedContext;
}

From source file:com.esminis.server.library.activity.main.MainViewImpl.java

private void setupToolbar(@NonNull AppCompatActivity activity) {
    Toolbar toolbar = (Toolbar) activity.findViewById(R.id.toolbar);
    if (toolbar != null) {
        toolbar.setLogo(VectorDrawableCompat.create(activity.getResources(), R.drawable.ic_toolbar, null));
        toolbar.inflateMenu(R.menu.main);
        TypedValue attribute = new TypedValue();
        activity.getTheme().resolveAttribute(android.R.attr.textColorPrimary, attribute, true);
        if (attribute.resourceId > 0) {
            final VectorDrawableCompat icon = VectorDrawableCompat.create(activity.getResources(),
                    R.drawable.ic_info, null);
            if (icon != null) {
                icon.setTint(ContextCompat.getColor(activity, attribute.resourceId));
                toolbar.getMenu().findItem(R.id.menu_about).setIcon(new InsetDrawable(icon, 0));
            }/*from   w  ww.j a  v  a 2s  . c o m*/
        }
        activity.setSupportActionBar(toolbar);
    }
}

From source file:com.miz.functions.MizLib.java

/**
 * Add a padding with a height of the ActionBar to the bottom of a given View
 * @param c//from w  w w  .j a  va  2 s.  co  m
 * @param v
 */
public static void addActionBarPaddingBottom(Context c, View v) {
    int mActionBarHeight = 0;
    TypedValue tv = new TypedValue();
    if (c.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
        mActionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,
                c.getResources().getDisplayMetrics());
    else
        mActionBarHeight = 0; // No ActionBar style (pre-Honeycomb or ActionBar not in theme)

    v.setPadding(0, 0, 0, mActionBarHeight);
}

From source file:android_network.hetnet.vpn_service.Util.java

public static void setTheme(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    boolean dark = prefs.getBoolean("dark_theme", false);
    String theme = prefs.getString("theme", "teal");
    if (theme.equals("teal"))
        context.setTheme(dark ? R.style.AppThemeTealDark : R.style.AppThemeTeal);
    else if (theme.equals("blue"))
        context.setTheme(dark ? R.style.AppThemeBlueDark : R.style.AppThemeBlue);
    else if (theme.equals("purple"))
        context.setTheme(dark ? R.style.AppThemePurpleDark : R.style.AppThemePurple);
    else if (theme.equals("amber"))
        context.setTheme(dark ? R.style.AppThemeAmberDark : R.style.AppThemeAmber);
    else if (theme.equals("orange"))
        context.setTheme(dark ? R.style.AppThemeOrangeDark : R.style.AppThemeOrange);
    else if (theme.equals("green"))
        context.setTheme(dark ? R.style.AppThemeGreenDark : R.style.AppThemeGreen);

    if (context instanceof Activity && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        TypedValue tv = new TypedValue();
        context.getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
        ((Activity) context).setTaskDescription(new ActivityManager.TaskDescription(null, null, tv.data));
    }//from  w ww  . j  a  v a 2s .co  m
}

From source file:com.miz.functions.MizLib.java

/**
 * Add a margin with a height of the ActionBar to the top of a given View contained in a FrameLayout
 * @param c/*w  ww . jav a  2  s  . co  m*/
 * @param v
 */
public static void addActionBarMargin(Context c, View v) {
    int mActionBarHeight = 0;
    TypedValue tv = new TypedValue();
    if (c.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
        mActionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,
                c.getResources().getDisplayMetrics());
    else
        mActionBarHeight = 0; // No ActionBar style (pre-Honeycomb or ActionBar not in theme)

    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.MATCH_PARENT);
    params.setMargins(0, mActionBarHeight, 0, 0);
    v.setLayoutParams(params);
}