Example usage for android.util TypedValue complexToDimensionPixelSize

List of usage examples for android.util TypedValue complexToDimensionPixelSize

Introduction

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

Prototype

public static int complexToDimensionPixelSize(int data, DisplayMetrics metrics) 

Source Link

Document

Converts a complex data value holding a dimension to its final value as an integer pixel size.

Usage

From source file:com.aniruddhc.acemusic.player.BlacklistManagerActivity.BlacklistManagerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    //Initialize Context and SharedPreferences.
    mContext = this;
    mActivity = this;
    mApp = (Common) this.getApplicationContext();
    sharedPreferences = mContext.getSharedPreferences("com.aniruddhc.acemusic.player", Context.MODE_PRIVATE);

    //Set the UI theme.
    if (mApp.getCurrentTheme() == Common.DARK_THEME) {
        setTheme(R.style.AppTheme);/*from www  .j a  va  2  s.  co m*/
    } else {
        setTheme(R.style.AppThemeLight);
    }
    super.onCreate(savedInstanceState);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        getWindow().setBackgroundDrawable(UIElementsHelper.getGeneralActionBarBackground(mContext));
        int topPadding = Common.getStatusBarHeight(mContext);
        View activityView = (View) findViewById(android.R.id.content);

        //Calculate ActionBar height
        TypedValue tv = new TypedValue();
        int actionBarHeight = 0;
        if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,
                    getResources().getDisplayMetrics());
        }

        if (activityView != null) {
            activityView.setPadding(0, topPadding + actionBarHeight, 0, 0);
        }

    }

    //Retrieve the actionbar.
    actionBar = getActionBar();

    //Create a set of options to optimize the bitmap memory usage.
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    options.inJustDecodeBounds = false;
    options.inPurgeable = true;

    //Display Image Options.
    int defaultArt = UIElementsHelper.getIcon(mContext, "default_album_art_padded");
    displayImageOptions = new DisplayImageOptions.Builder().showImageForEmptyUri(R.drawable.default_album_art)
            .showImageOnFail(R.drawable.default_album_art).showStubImage(R.drawable.transparent_drawable)
            .cacheInMemory(false).cacheOnDisc(true).decodingOptions(options)
            .imageScaleType(ImageScaleType.EXACTLY).bitmapConfig(Bitmap.Config.RGB_565)
            .displayer(new FadeInBitmapDisplayer(400)).delayBeforeLoading(100).build();

    //Retrieve a list of blacklisted songs.
    AsyncGetAllSongIdsBlacklistStatusTask task = new AsyncGetAllSongIdsBlacklistStatusTask();
    task.execute();

}

From source file:com.invariantlabs.hashavua.main.MainActivity.java

private void setupSwipeRefreshLayout() {
    swipeRefreshLayout.setOnRefreshListener(this);
    swipeRefreshLayout.setColorSchemeResources(R.color.primary);
    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true);
    int actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
    int delta = Util.dpToPx(this, 64);
    swipeRefreshLayout.setProgressViewOffset(false, actionBarHeight, actionBarHeight + delta);
}

From source file:com.cyanogenmod.eleven.ui.activities.BaseActivity.java

/**
 * {@inheritDoc}/*from   w  w w  .  jav a2  s  .  com*/
 */
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Fade it in
    overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);

    // Control the media volume
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    // Bind Apollo's service
    mToken = MusicUtils.bindToService(this, this);

    // Initialize the broadcast receiver
    mPlaybackStatus = new PlaybackStatus(this);

    // Calculate ActionBar height
    TypedValue value = new TypedValue();
    if (getTheme().resolveAttribute(android.R.attr.actionBarSize, value, true)) {
        mActionBarHeight = TypedValue.complexToDimensionPixelSize(value.data,
                getResources().getDisplayMetrics());
    }

    // Set the layout
    setContentView(setContentView());

    mToolBar = (Toolbar) findViewById(R.id.toolbar);
    setActionBar(mToolBar);

    getActionBar().setTitle(getString(R.string.app_name).toUpperCase());

    // set the background on the root view
    getWindow().getDecorView().getRootView()
            .setBackgroundColor(getResources().getColor(R.color.background_color));
    // Initialze the bottom action bar
    initBottomActionBar();

    // listen to changes to the cache status
    ImageFetcher.getInstance(this).addCacheListener(this);
}

From source file:org.mariotaku.twidere.util.TwidereActionModeForChildListener.java

ActionMode startSupportActionModeFromWindow(ActionMode.Callback callback) {
    if (mActionMode != null) {
        mActionMode.finish();/*from www.j a  v  a 2  s  .c  o m*/
    }

    final ActionMode.Callback wrappedCallback = new ActionModeCallbackWrapper(callback);

    if (mActionModeView == null) {
        if (mIsFloating && mUsePopup) {
            // Use the action bar theme.
            final Context actionBarContext;
            actionBarContext = ThemeUtils.getActionBarThemedContext(mActivity,
                    mThemed.getCurrentThemeResourceId(), mThemed.getCurrentThemeColor());

            mActionModeView = new ActionBarContextView(actionBarContext);
            mActionModePopup = new PopupWindow(actionBarContext, null,
                    android.support.v7.appcompat.R.attr.actionModePopupWindowStyle);
            mActionModePopup.setContentView(mActionModeView);
            mActionModePopup.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);

            final TypedValue outValue = new TypedValue();
            actionBarContext.getTheme().resolveAttribute(android.support.v7.appcompat.R.attr.actionBarSize,
                    outValue, true);
            final int height = TypedValue.complexToDimensionPixelSize(outValue.data,
                    actionBarContext.getResources().getDisplayMetrics());
            mActionModeView.setContentHeight(height);
            ThemeUtils.setActionBarContextViewBackground(mActionModeView, mThemed.getCurrentThemeResourceId(),
                    mThemed.getCurrentThemeColor(), mThemed.getCurrentThemeBackgroundOption(), false);
            mActionModePopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
            mShowActionModePopup = new Runnable() {
                @Override
                public void run() {
                    mActionModePopup.showAtLocation(mWindow.getDecorView(),
                            Gravity.TOP | Gravity.FILL_HORIZONTAL, 0, 0);
                }
            };
        } else {
            mActionModeView = (ActionBarContextView) mWindow.findViewById(R.id.action_context_bar);
        }
    }

    if (mActionModeView != null) {
        mActionModeView.killMode();
        ActionMode mode = new StandaloneActionMode(mActionModeView.getContext(), mActionModeView,
                wrappedCallback, mActionModePopup == null);
        if (callback.onCreateActionMode(mode, mode.getMenu())) {
            mode.invalidate();
            mActionModeView.initForMode(mode);
            mActionModeView.setVisibility(View.VISIBLE);
            mActionMode = mode;
            if (mActionModePopup != null) {
                mWindow.getDecorView().post(mShowActionModePopup);
            }
            mActionModeView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);

            if (mActionModeView.getParent() != null) {
                ViewCompat.requestApplyInsets((View) mActionModeView.getParent());
            }
        } else {
            mActionMode = null;
        }

    }
    if (mActionMode != null && mAppCompatCallback != null) {
        mAppCompatCallback.onSupportActionModeStarted(mActionMode);
    }
    return mActionMode;
}

From source file:fr.matthiasbosc.translucentmap.MainActivity.java

public int getActionBarHeight() {
    int result = 0;
    mTypedValue = new TypedValue();
    if (getTheme() != null) {
        if (getTheme().resolveAttribute(android.R.attr.actionBarSize, mTypedValue, true)) {
            result = TypedValue.complexToDimensionPixelSize(mTypedValue.data,
                    getResources().getDisplayMetrics());
        }/*ww  w .  j a  v a 2  s.  co  m*/
    }
    return result;
}

From source file:com.grepsound.fragments.MyProfileFragment.java

public int getActionBarHeight() {
    if (mActionBarHeight != 0) {
        return mActionBarHeight;
    }/*  w  w  w.  ja  v  a  2s  .  co m*/

    TypedValue mTypedValue = new TypedValue();
    getActivity().getTheme().resolveAttribute(android.R.attr.actionBarSize, mTypedValue, true);
    mActionBarHeight = TypedValue.complexToDimensionPixelSize(mTypedValue.data,
            getResources().getDisplayMetrics());

    return mActionBarHeight;
}

From source file:com.aniruddhc.acemusic.player.MusicLibraryEditorActivity.MusicLibraryEditorActivity.java

@SuppressWarnings("unchecked")
@Override/*from  w w  w. j  a v a 2  s . c  o  m*/
public void onCreate(Bundle savedInstanceState) {

    //Initialize Context and SharedPreferences.
    mContext = this;
    mApp = (Common) mContext.getApplicationContext();

    //Retrieve the name/icon of the library from the arguments.
    libraryName = getIntent().getExtras().getString("LIBRARY_NAME");
    libraryIconName = getIntent().getExtras().getString("LIBRARY_ICON");

    if (getIntent().getExtras().getSerializable("SONG_IDS_HASH_SET") != null) {
        songDBIdsList = (HashSet<String>) getIntent().getExtras().getSerializable("SONG_IDS_HASH_SET");
    }

    //Set the UI theme.
    if (mApp.getCurrentTheme() == Common.DARK_THEME) {
        setTheme(R.style.AppTheme);
    } else {
        setTheme(R.style.AppThemeLight);
    }
    super.onCreate(savedInstanceState);

    //Initialize the database helper.
    dbHelper = new DBAccessHelper(mContext.getApplicationContext());

    //Create a set of options to optimize the bitmap memory usage.
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    options.inJustDecodeBounds = false;
    options.inPurgeable = true;

    //Display Image Options.
    int defaultArt = UIElementsHelper.getIcon(mContext, "default_album_art_padded");
    displayImageOptions = new DisplayImageOptions.Builder().showImageForEmptyUri(R.drawable.default_album_art)
            .showImageOnFail(R.drawable.default_album_art).showStubImage(R.drawable.transparent_drawable)
            .cacheInMemory(false).cacheOnDisc(true).decodingOptions(options)
            .imageScaleType(ImageScaleType.EXACTLY).bitmapConfig(Bitmap.Config.RGB_565)
            .displayer(new FadeInBitmapDisplayer(400)).delayBeforeLoading(100).build();

    //Attach tabs to the ActionBar.
    ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    //Add the artists tab.
    String artistsLabel = getResources().getString(R.string.artists);
    Tab tab = actionBar.newTab();
    tab.setText(artistsLabel);
    TabListener<ArtistsPickerFragment> artistsTabListener = new TabListener<ArtistsPickerFragment>(this,
            artistsLabel, ArtistsPickerFragment.class);

    tab.setTabListener(artistsTabListener);
    actionBar.addTab(tab);

    //Add the albums tab.
    String albumsLabel = getResources().getString(R.string.albums);
    tab = actionBar.newTab();
    tab.setText(albumsLabel);
    TabListener<AlbumsPickerFragment> albumsTabListener = new TabListener<AlbumsPickerFragment>(this,
            albumsLabel, AlbumsPickerFragment.class);

    tab.setTabListener(albumsTabListener);
    actionBar.addTab(tab);

    //Add the songs tab.
    String songsLabel = getResources().getString(R.string.songs);
    tab = actionBar.newTab();
    tab.setText(songsLabel);
    TabListener<SongsPickerFragment> songsTabListener = new TabListener<SongsPickerFragment>(this, songsLabel,
            SongsPickerFragment.class);

    tab.setTabListener(songsTabListener);
    actionBar.addTab(tab);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        getWindow().setBackgroundDrawable(UIElementsHelper.getGeneralActionBarBackground(mContext));
        int topPadding = Common.getStatusBarHeight(mContext);
        View activityView = (View) findViewById(android.R.id.content);

        //Calculate ActionBar height
        TypedValue tv = new TypedValue();
        int actionBarHeight = 0;
        if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,
                    getResources().getDisplayMetrics());
        }

        if (activityView != null) {
            activityView.setPadding(0, topPadding + actionBarHeight, 0, 0);
        }

    }

}

From source file:com.achep.header2actionbar.HeaderFragmentSupportV4.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Activity activity = getActivity();
    assert activity != null;
    mFrameLayout = new FrameLayout(activity);

    mHeader = onCreateHeaderView(inflater, mFrameLayout);
    mHeaderHeader = mHeader.findViewById(android.R.id.title);
    mHeaderBackground = mHeader.findViewById(android.R.id.background);
    assert mHeader.getLayoutParams() != null;
    mHeader.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
    mHeaderHeight = mHeader.getMeasuredHeight();

    mFakeHeader = new Space(activity);

    View content = onCreateContentView(inflater, mFrameLayout);
    mContentView = content;//from   www . j a  v  a2s  .c o  m
    Log.i(TAG, "container:" + container.getMeasuredHeight() + ",mHeaderHeight=" + mHeaderHeight);

    final View topContentView = container;

    if (content instanceof ListView) {
        isListViewEmpty = true;

        final ListView listView = (ListView) content;
        mFakeHeader.setLayoutParams(new ListView.LayoutParams(0, mHeaderHeight));
        listView.addHeaderView(mFakeHeader);
        listView.setOnScrollListener(new AbsListView.OnScrollListener() {

            @Override
            public void onScrollStateChanged(AbsListView absListView, int scrollState) {
                if (mOnScrollListener != null) {
                    mOnScrollListener.onScrollStateChanged(absListView, scrollState);
                }
            }

            @Override
            public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount,
                    int totalItemCount) {
                if (isListViewEmpty) {
                    scrollHeaderTo(0);
                } else {
                    final View child = absListView.getChildAt(0);
                    assert child != null;
                    scrollHeaderTo(child == mFakeHeader ? child.getTop() : -mHeaderHeight);
                }
            }
        });
    } else {
        topContentView.getViewTreeObserver()
                .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    @SuppressWarnings("deprecation")
                    @Override
                    public void onGlobalLayout() {
                        //Remove it here unless you want to get this callback for EVERY
                        //layout pass, which can get you into infinite loops if you ever
                        //modify the layout from within this method.
                        topContentView.getViewTreeObserver().removeGlobalOnLayoutListener(this);

                        //Now you can get the width and height from content
                        int actionBarHeight = 0;
                        TypedValue tv = new TypedValue();
                        if (getActivity().getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
                            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,
                                    getResources().getDisplayMetrics());
                        }
                        Log.i(TAG, "topContentView:" + topContentView.getHeight() + ", actionBarHeight:"
                                + actionBarHeight + ", getStatusBarHeight:" + getStatusBarHeight());
                        ViewGroup.LayoutParams lp = mContentView.getLayoutParams();
                        lp.height = topContentView.getHeight() - actionBarHeight - getStatusBarHeight();
                        mContentView.setLayoutParams(lp);
                    }
                });

        // Merge fake header view and content view.
        final LinearLayout view = new LinearLayout(activity);
        view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        view.setOrientation(LinearLayout.VERTICAL);
        mFakeHeader.setLayoutParams(new LinearLayout.LayoutParams(0, mHeaderHeight));
        view.addView(mFakeHeader);
        view.addView(content);

        // Put merged content to ScrollView
        final NotifyingScrollView scrollView = new NotifyingScrollView(activity);
        scrollView.addView(view);
        scrollView.setVerticalScrollBarEnabled(false);
        scrollView.setOverScrollMode(ScrollView.OVER_SCROLL_NEVER);
        scrollView.setOnScrollChangedListener(new NotifyingScrollView.OnScrollChangedListener() {
            @Override
            public void onScrollChanged(ScrollView who, int l, int t, int oldl, int oldt) {
                Log.i(TAG, "onScrollChanged scroll ot -t :" + (-t));
                scrollHeaderTo(-t);
            }
        });
        mContentWrapper = scrollView;
        content = scrollView;
    }

    mFrameLayout.addView(content);
    mFrameLayout.addView(mHeader);

    // Content overlay view always shows at the top of content.
    if ((mContentOverlay = onCreateContentOverlayView(inflater, mFrameLayout)) != null) {
        mFrameLayout.addView(mContentOverlay, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
    }

    // Post initial scroll
    mFrameLayout.post(new Runnable() {
        @Override
        public void run() {
            Log.i(TAG, "post initial scroll to 0");
            // SEAN: walk around for scroll position bug
            if (mContentWrapper != null) {
                mContentWrapper.scrollTo(0, 0);
            }
            scrollHeaderTo(0, true);
        }
    });

    return mFrameLayout;
}

From source file:com.github.howeyc.slideshow.activities.SettingsActivity.java

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    Toolbar bar;//from   w ww.ja v  a2 s.  c om

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        LinearLayout root = (LinearLayout) findViewById(android.R.id.list).getParent().getParent().getParent();
        bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false);
        root.addView(bar, 0); // insert at top
    } else {
        ViewGroup root = (ViewGroup) findViewById(android.R.id.content);
        ListView content = (ListView) root.getChildAt(0);
        root.removeAllViews();
        bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false);

        int height;
        TypedValue tv = new TypedValue();
        if (getTheme().resolveAttribute(R.attr.actionBarSize, tv, true)) {
            height = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
        } else {
            height = bar.getHeight();
        }
        content.setPadding(0, height, 0, 0);

        root.addView(content);
        root.addView(bar);
    }
    bar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });
}

From source file:com.veniosg.dir.android.activity.FileManagerActivity.java

/**
 * Calculating width based on//from   w ww. j  a  v a 2 s  . com
 * http://www.google.com/design/spec/patterns/navigation-drawer.html#navigation-drawer-specs.
 */
private void setOptimalDrawerWidth(View drawerContainer) {
    int actionBarSize = 0;
    TypedValue tv = new TypedValue();
    if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
        actionBarSize = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
    }

    ViewGroup.LayoutParams params = drawerContainer.getLayoutParams();
    DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
    int minScreenWidth = min(displayMetrics.widthPixels, displayMetrics.heightPixels);

    params.width = min(minScreenWidth - actionBarSize, 5 * actionBarSize);
    drawerContainer.requestLayout();
}