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:com.ADORCE.controls.MainViewActivity.java

private void showThemeChooserDialog() {
    AlertDialog.Builder b = new AlertDialog.Builder(this);
    Adapter adapter = new ArrayAdapter<>(this, R.layout.simple_list_item_single_choice,
            getResources().getStringArray(R.array.theme_items));
    b.setTitle(getString(R.string.theme_chooser_dialog_title)).setSingleChoiceItems((ListAdapter) adapter,
            PreferenceManager.getDefaultSharedPreferences(this).getInt("theme_prefs", 0),
            new DialogInterface.OnClickListener() {
                @Override/* w w  w .j  a v a 2s .c o m*/
                public void onClick(DialogInterface dialog, int which) {
                    //Invokes method initTheme(int) - next method based on chosen theme
                    initTheme(which);
                }
            });
    AlertDialog d = b.create();
    d.show();
    TypedValue typedValue = new TypedValue();
    Resources.Theme theme = this.getTheme();
    theme.resolveAttribute(R.attr.colorAccent, typedValue, true);

    Button cancel = d.getButton(AlertDialog.BUTTON_NEGATIVE);
    cancel.setTextColor(typedValue.data);
    Button ok = d.getButton(AlertDialog.BUTTON_POSITIVE);
    ok.setTextColor(typedValue.data);
    d.getWindow().setBackgroundDrawableResource(R.drawable.dialog_bg);
    ListView lv = d.getListView();
    int paddingTop = Math.round(this.getResources().getDimension(R.dimen.dialog_listView_top_padding));
    int paddingBottom = Math.round(this.getResources().getDimension(R.dimen.dialog_listView_bottom_padding));
    lv.setPadding(0, paddingTop, 0, paddingBottom);
}

From source file:ly.apps.android.rest.client.example.activities.MainActivity.java

private void checkImmersiveMode() {
    FrameLayout.LayoutParams params;/* ww w.ja va 2  s.co m*/
    TypedValue typedValue;
    int actionBarHeight;
    Resources.Theme theme;

    typedValue = new TypedValue();
    theme = getTheme();
    params = (FrameLayout.LayoutParams) linearLayoutContent.getLayoutParams();

    if (theme != null && params != null) {
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
                && theme.resolveAttribute(android.R.attr.actionBarSize, typedValue, true)) {
            actionBarHeight = TypedValue.complexToDimensionPixelSize(typedValue.data,
                    getResources().getDisplayMetrics());
            params.setMargins(0, actionBarHeight + getStatusBarHeight(), 0, getNavigationBarHeight());

        }
    }

}

From source file:com.example.android.wizardpager.MainFragment.java

private void updateBottomBar() {
    int position = mPager.getCurrentItem();
    if (position == mCurrentPageSequence.size()) {
        mNextButton.setText(R.string.finish);
        mNextButton.setBackgroundResource(R.drawable.finish_background);
        mNextButton.setTextAppearance(getActivity(), R.style.TextAppearanceFinish);
    } else {//w w  w.  j  av a2 s  .  com
        mNextButton.setText(mEditingAfterReview ? R.string.review : R.string.next);
        mNextButton.setBackgroundResource(R.drawable.selectable_item_background);
        TypedValue v = new TypedValue();
        getActivity().getTheme().resolveAttribute(android.R.attr.textAppearanceMedium, v, true);
        mNextButton.setTextAppearance(getActivity(), v.resourceId);
        mNextButton.setEnabled(position != mPagerAdapter.getCutOffPage());
    }

    mPrevButton.setVisibility(position <= 0 ? View.INVISIBLE : View.VISIBLE);
}

From source file:com.appeaser.sublimenavigationviewlibrary.SublimeThemer.java

private void setDefaultCheckableItemTintList() {
    TypedValue value = new TypedValue();
    if (mContext.getTheme().resolveAttribute(android.R.attr.textColorPrimary, value, true)) {
        ColorStateList baseColor = mContext.getResources().getColorStateList(value.resourceId);
        if (mContext.getTheme().resolveAttribute(R.attr.colorPrimary, value, true)) {
            int colorPrimary = value.data;
            int defaultColor = baseColor.getDefaultColor();
            mCheckableItemTintList = new ColorStateList(
                    new int[][] { DISABLED_STATE_SET, CHECKABLE_ITEM_CHECKED_STATE_SET, EMPTY_STATE_SET },
                    new int[] { baseColor.getColorForState(DISABLED_STATE_SET, defaultColor), colorPrimary,
                            defaultColor });
        }/*from w  w w  . jav a 2  s  .co  m*/
    }

    if (mCheckableItemTintList == null) {
        // Defaults
        boolean isLightTheme = mDefaultTheme == SublimeThemer.DefaultTheme.LIGHT;

        int defDisabled = isLightTheme
                ? mContext.getResources().getColor(R.color.snv_primary_text_disabled_material_light)
                : mContext.getResources().getColor(R.color.snv_primary_text_disabled_material_dark);
        int defChecked = isLightTheme ? mContext.getResources().getColor(R.color.snv_primary_material_light)
                : mContext.getResources().getColor(R.color.snv_primary_material_dark);
        int defEmptySet = isLightTheme
                ? mContext.getResources().getColor(R.color.snv_primary_text_default_material_light)
                : mContext.getResources().getColor(R.color.snv_primary_text_default_material_dark);
        mCheckableItemTintList = new ColorStateList(
                new int[][] { DISABLED_STATE_SET, CHECKABLE_ITEM_CHECKED_STATE_SET, EMPTY_STATE_SET },
                new int[] { defDisabled, defChecked, defEmptySet });
    }
}

From source file:com.ch.ch_library.smartlayout.SmartTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.//from  ww w.  j a v a2s .c om
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextColor(mTabViewTextColor);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTabViewTextSize);
    textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.MATCH_PARENT));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(mTabViewTextAllCaps);
    }

    textView.setPadding(mTabViewTextHorizontalPadding, 0, mTabViewTextHorizontalPadding, 0);

    if (mTabViewTextMinWidth > 0) {
        textView.setMinWidth(mTabViewTextMinWidth);
    }

    return textView;
}

From source file:com.google.android.apps.gutenberg.ScannerActivity.java

private int calcSlideDistance() {
    DisplayMetrics metrics = getResources().getDisplayMetrics();
    int height = metrics.heightPixels;
    TypedValue value = new TypedValue();
    getTheme().resolveAttribute(android.R.attr.listPreferredItemHeight, value, true);
    float itemHeight = value.getDimension(metrics);
    float paddingTop = getResources().getDimension(R.dimen.list_vertical_padding);
    return (int) ((height - itemHeight + paddingTop) / 2);
}

From source file:com.aboveware.sms.contacts.ContactSuggestionsAdapter.java

private CharSequence formatUrl(CharSequence url) {
    if (mUrlColor == null) {
        // Lazily get the URL color from the current theme.
        TypedValue colorValue = new TypedValue();
        mContext.getTheme().resolveAttribute(R.attr.textColorSearchUrl, colorValue, true);
        mUrlColor = mContext.getResources().getColorStateList(colorValue.resourceId);
    }//from www  . j a v a 2 s .  c  o m

    SpannableString text = new SpannableString(url);
    text.setSpan(new TextAppearanceSpan(null, 0, 0, mUrlColor, null), 0, url.length(),
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return text;
}

From source file:android.support.v14.preference.PreferenceFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    TypedArray a = mStyledContext.obtainStyledAttributes(null, R.styleable.PreferenceFragment,
            TypedArrayUtils.getAttr(mStyledContext,
                    android.support.v7.preference.R.attr.preferenceFragmentStyle,
                    AndroidResources.ANDROID_R_PREFERENCE_FRAGMENT_STYLE),
            0);/* ww w.  j  av  a  2 s  .  co  m*/

    mLayoutResId = a.getResourceId(R.styleable.PreferenceFragment_android_layout, mLayoutResId);

    final Drawable divider = a.getDrawable(R.styleable.PreferenceFragment_android_divider);
    final int dividerHeight = a.getDimensionPixelSize(R.styleable.PreferenceFragment_android_dividerHeight, -1);

    a.recycle();

    // Need to theme the inflater to pick up the preferenceFragmentListStyle
    final TypedValue tv = new TypedValue();
    getActivity().getTheme().resolveAttribute(android.support.v7.preference.R.attr.preferenceTheme, tv, true);
    final int theme = tv.resourceId;

    final Context themedContext = new ContextThemeWrapper(inflater.getContext(), theme);
    final LayoutInflater themedInflater = inflater.cloneInContext(themedContext);

    final View view = themedInflater.inflate(mLayoutResId, container, false);

    final View rawListContainer = view.findViewById(AndroidResources.ANDROID_R_LIST_CONTAINER);
    if (!(rawListContainer instanceof ViewGroup)) {
        throw new RuntimeException("Content has view with id attribute "
                + "'android.R.id.list_container' that is not a ViewGroup class");
    }

    final ViewGroup listContainer = (ViewGroup) rawListContainer;

    final RecyclerView listView = onCreateRecyclerView(themedInflater, listContainer, savedInstanceState);
    if (listView == null) {
        throw new RuntimeException("Could not create RecyclerView");
    }

    mList = listView;

    listView.addItemDecoration(mDividerDecoration);
    setDivider(divider);
    if (dividerHeight != -1) {
        setDividerHeight(dividerHeight);
    }

    listContainer.addView(mList);
    mHandler.post(mRequestFocus);

    return view;
}

From source file:com.alusorstroke.jjvm.MainActivity.java

private int getDrawerWidth() {
    // Navigation Drawer layout width
    int width = getResources().getDisplayMetrics().widthPixels;

    TypedValue tv = new TypedValue();
    int actionBarHeight;
    if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
        actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
    } else {//from  w  ww . j  a  v  a 2  s .  co m
        actionBarHeight = 0;
    }

    int possibleMinDrawerWidth = width - actionBarHeight;

    int maxDrawerWidth = getResources().getDimensionPixelSize(R.dimen.drawer_width);

    return Math.min(possibleMinDrawerWidth, maxDrawerWidth);
}

From source file:com.androprogrammer.tutorials.customviews.SlidingTabLayout.java

protected ImageView createDefaultIconTabView(Context context) {
    ImageView tabIconImageView = new ImageView(context);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        tabIconImageView.setBackgroundResource(outValue.resourceId);
    }/*from  www  .  j  a  va2  s. co  m*/

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    tabIconImageView.setPadding(padding, padding, padding, padding);

    return tabIconImageView;
}