List of usage examples for android.util TypedValue complexToDimensionPixelSize
public static int complexToDimensionPixelSize(int data, DisplayMetrics metrics)
From source file:com.hellofyc.base.util.ViewUtils.java
/** * ?ActionBar/* ww w . j a v a 2 s. c o m*/ */ public static int getActionBarHeight(Context context) { TypedValue tv = new TypedValue(); if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { return TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics()); } return 0; }
From source file:com.lamcreations.scaffold.common.views.CollapsingToolbarTabLayout.java
public CollapsingToolbarTabLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); super.setCollapsedTitleTextColor(getColor(getContext(), android.R.color.transparent)); super.setExpandedTitleColor(getColor(getContext(), android.R.color.transparent)); TypedValue tv = new TypedValue(); if (getContext().getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { mActionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics()); }/*from www . j av a2s . c om*/ mTmpRect = new Rect(); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CollapsingToolbarTabLayout, defStyleAttr, R.style.Widget_Scaffold_CollapsingToolbarTabLayout); int tp; boolean isRtl = ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL; mExpandedMarginLeft = mExpandedMarginTop = mExpandedMarginRight = mExpandedMarginBottom = a .getDimensionPixelSize(R.styleable.CollapsingToolbarTabLayout_scaffoldExpandedTitleMargin, 0); if (a.hasValue(R.styleable.CollapsingToolbarTabLayout_scaffoldExpandedTitleMarginStart)) { tp = a.getDimensionPixelSize(R.styleable.CollapsingToolbarTabLayout_scaffoldExpandedTitleMarginStart, 0); if (isRtl) { mExpandedMarginRight = tp; } else { mExpandedMarginLeft = tp; } } if (a.hasValue(R.styleable.CollapsingToolbarTabLayout_scaffoldExpandedTitleMarginEnd)) { tp = a.getDimensionPixelSize(R.styleable.CollapsingToolbarTabLayout_scaffoldExpandedTitleMarginEnd, 0); if (isRtl) { mExpandedMarginLeft = tp; } else { mExpandedMarginRight = tp; } } if (a.hasValue(R.styleable.CollapsingToolbarTabLayout_scaffoldExpandedTitleMarginTop)) { mExpandedMarginTop = a.getDimensionPixelSize( R.styleable.CollapsingToolbarTabLayout_scaffoldExpandedTitleMarginTop, 0); } if (a.hasValue(R.styleable.CollapsingToolbarTabLayout_scaffoldExpandedTitleMarginBottom)) { mExpandedMarginBottom = a.getDimensionPixelSize( R.styleable.CollapsingToolbarTabLayout_scaffoldExpandedTitleMarginBottom, 0); } tp = a.getResourceId(R.styleable.CollapsingToolbarTabLayout_scaffoldExpandedTitleTextAppearance, R.style.TextAppearance_AppCompat_Title); getCollapsingTextHelper().setExpandedTextAppearance(tp); tp = a.getResourceId(R.styleable.CollapsingToolbarTabLayout_scaffoldCollapsedTitleTextAppearance, R.style.TextAppearance_AppCompat_Widget_ActionBar_Title); getCollapsingTextHelper().setCollapsedTextAppearance(tp); String title = a.getString(R.styleable.CollapsingToolbarTabLayout_scaffoldTitle); setTitle(title); a.recycle(); }
From source file:xyz.jamescarroll.genipass.Fragment.ExtFragment.java
protected View setPadding(View v) { TypedValue tv = new TypedValue(); if (getActivity().getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { v.setPadding(getDimension(R.dimen.activity_vertical_margin), TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics()) + getDimension(R.dimen.activity_horizontal_margin), getDimension(R.dimen.activity_vertical_margin), getDimension(R.dimen.activity_horizontal_margin)); }//w w w . j a v a2s. c om return v; }
From source file:org.addhen.smssync.presentation.view.ui.activity.BasePreferenceActivity.java
private void setupActionBar() { Toolbar toolbar;// w w w . ja v a 2 s . co m if (Build.VERSION.SDK_INT >= 14) { ViewGroup root = (ViewGroup) findViewById(android.R.id.list).getParent().getParent().getParent(); toolbar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.toolbar_actionbar, root, false); root.addView(toolbar, 0); } else { ViewGroup root = (ViewGroup) findViewById(android.R.id.content); ListView content = (ListView) root.getChildAt(0); root.removeAllViews(); toolbar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.toolbar_actionbar, 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 = toolbar.getHeight(); } content.setPadding(0, height, 0, 0); root.addView(content); root.addView(toolbar); } setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); toolbar.setNavigationOnClickListener(v -> navigateUp()); }
From source file:com.hangulo.powercontact.util.Utils.java
public static int getAttributeHeight(Context ctx, int resid) { int retHeight = 0; TypedValue tv = new TypedValue(); if (ctx.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { retHeight = TypedValue.complexToDimensionPixelSize(tv.data, ctx.getResources().getDisplayMetrics()); }/*from w w w.j a va 2 s. c o m*/ return retHeight; }
From source file:com.myriadmobile.library.heroviewpager.HeroViewPagerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.setContentView(R.layout.hvp__activity_base); // Calculate ActionBar height TypedValue typedValue = new TypedValue(); if (getTheme().resolveAttribute(android.R.attr.actionBarSize, typedValue, true)) { actionBarHeight = TypedValue.complexToDimensionPixelSize(typedValue.data, getResources().getDisplayMetrics()); }/* www .ja va 2 s .c om*/ mHeroContent = (FrameLayout) findViewById(R.id.hero_content); mHeroOverlay = (FrameLayout) findViewById(R.id.hero_overlay); mHeroContainer = (FrameLayout) findViewById(R.id.hvp__hero_frame); mPager = (ViewPager) findViewById(R.id.hvp__pager); mPager.setOnPageChangeListener(this); mTabHost = (TabHost) findViewById(R.id.hvp__hero_tabs); mTabHost.setup(); mTabHost.setOnTabChangedListener(this); mTabScrollView = (HorizontalScrollView) findViewById(R.id.hvp__tab_scroll_view); //TODO better logic than this? isPortrait = mHeroOverlay != null; }
From source file:com.example.examplersqr.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ////////////////////// // Setup QR Bar // ////////////////////// inAnim = AnimationUtils.loadAnimation(this, R.anim.abc_slide_in_top); outAnim = AnimationUtils.loadAnimation(this, R.anim.abc_slide_out_top); qrBar = (LinearLayout) findViewById(R.id.myQRBar); // In production, better to get this from a "values.xml" resource // in a res folder appropriate to screen size / orientation columnCount = 2;/* w w w .j a va2 s .co m*/ // Set the QRBar Height to that of the ActionBar TypedValue tv = new TypedValue(); if (getTheme().resolveAttribute(R.attr.actionBarSize, tv, true)) { qrBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics()); } tvQRBarTitle = (TextView) findViewById(R.id.tvQRBarTitle); tvQRBarTitle.setText("Tap to add item at top..."); tvQRBarTitle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { addItemAtPosition(0, "NEW CARD ADDED ON: " + new Date().toString()); } }); ////////////////////////////// // Setup Swipe To Refresh // ////////////////////////////// swiper = (TargetedSwipeRefreshLayout) findViewById(R.id.swipe_container); swiper.setSize(SwipeRefreshLayout.LARGE); swiper.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_orange_light, android.R.color.holo_green_light, android.R.color.holo_red_light); swiper.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { // This is where you should kickoff the // refreshing task. // For now, just wait a few seconds and turn off refreshing. new Handler().postDelayed(new Runnable() { @Override public void run() { if (myDataset != null && mAdapter != null) { Collections.shuffle(myDataset); mAdapter.notifyDataSetChanged(); } swiper.setRefreshing(false); } }, 5000); } }); ////////////////////////////////////////////// // Grab the StaggeredGrid & Layout Manager // ////////////////////////////////////////////// mRecycler = (RecyclerView) findViewById(R.id.rvExampleGrid); mRecycler.addItemDecoration(new QRBarDecoration(columnCount, qrBarHeight)); // mRecycler.addItemDecoration(new OverlapDecoration()); mSGLM = new StaggeredGridLayoutManager(columnCount, StaggeredGridLayoutManager.VERTICAL); mRecycler.setLayoutManager(mSGLM); ////////////////////////////// // Setup Adapter & DataSet // ////////////////////////////// myDataset = new ArrayList<String>(); // Load up the dataset with random titles for (int x = 0; x < 50; x++) { myDataset.add(someTitles[randy.nextInt(someTitles.length)]); } mAdapter = new RVAdapter(this, myDataset); ///////////////////////////////////////////// // Setup the RecyclerView Scroll Listener // ///////////////////////////////////////////// mRecycler.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); } @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { // Simple check if moved vertically. // React to scrolls of a minimum amount (3, in this case) if (dy > 3) { if (qrBar.getVisibility() == View.VISIBLE) hideQRBar(); } else if (dy < -3) { if (qrBar.getVisibility() == View.GONE) showQRBar(); } } }); // Set the RecyclerView's Adapter mRecycler.setAdapter(mAdapter); // Set the Recyclerview to be the target scrollable view // for the TargetedSwipeRefreshAdapter. swiper.setTargetScrollableView(mRecycler); }
From source file:com.msted.lensrocket.activities.SettingsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); super.onCreate(savedInstanceState); // Show the Up button in the action bar. setupActionBar();/*from w ww. jav a 2s. c o m*/ mSettingsFragment = new SettingsFragment(); Display display = getWindowManager().getDefaultDisplay(); DisplayMetrics outMetrics = new DisplayMetrics(); display.getMetrics(outMetrics); float density = getResources().getDisplayMetrics().density; float dpHeight = outMetrics.heightPixels / density; float dpWidth = outMetrics.widthPixels / density; int actionBarHeight; TypedValue tv = new TypedValue(); if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics()); } getFragmentManager().beginTransaction().replace(android.R.id.content, mSettingsFragment).commit(); }
From source file:net.pmarks.chromadoze.ChromaDoze.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);/* www . j a va 2 s . c om*/ mUiState = new UIState(getApplication()); SharedPreferences pref = getSharedPreferences(PREF_NAME, MODE_PRIVATE); mUiState.loadState(pref); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setTitle(""); mNavSpinner = (Spinner) findViewById(R.id.nav_spinner); ArrayAdapter<String> adapter = new ArrayAdapter<>(actionBar.getThemedContext(), R.layout.spinner_title, FragmentIndex.getStrings(this)); adapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item); mNavSpinner.setAdapter(adapter); mNavSpinner.setOnItemSelectedListener(this); // Created a scaled-down icon for the Toolbar. { TypedValue tv = new TypedValue(); getTheme().resolveAttribute(R.attr.actionBarSize, tv, true); int height = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics()); mToolbarIcon = getScaledImage(R.drawable.chromadoze_icon, height * 2 / 3); } // When this Activity is first created, set up the initial fragment. // After a save/restore, the framework will drop in the last-used // fragment automatically. if (savedInstanceState == null) { changeFragment(new MainFragment(), false); } }
From source file:com.Duo.music.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.jams.music.player", Context.MODE_PRIVATE); //Set the UI theme. if (mApp.getCurrentTheme() == Common.DARK_THEME) { setTheme(R.style.AppTheme);/*from w w w .j a va 2s . c o 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(); }