List of usage examples for android.view WindowManager getDefaultDisplay
public Display getDefaultDisplay();
From source file:com.superlity.test.recyclelistviewtest.emoji.SlidingTabLayout.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)}.// w w w . j a va2s. c om */ public TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point size = new Point(); // display.getSize(size); textView.setWidth((int) (size.x / 7)); textView.setGravity(Gravity.LEFT); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTypeface(Typeface.DEFAULT_BOLD); textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); textView.setAllCaps(true); int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); return textView; }
From source file:com.xnote.lol.xnote.views.SlidingTabLayout.java
public SlidingTabLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // determining width of screen to set padding to the tabs so they take the entire screen: WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point size = new Point(); display.getSize(size);/*from w ww. j av a2 s . c om*/ mScreenHorizontalWidth = size.x; // Disable the Scroll Bar setHorizontalScrollBarEnabled(false); // Make sure that the Tab Strips fills this View setFillViewport(true); mTitleOffset = (int) (TITLE_OFFSET_DIPS * getResources().getDisplayMetrics().density); mTabStrip = new SlidingTabStrip(context); addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); // initializing iconMap: mIconMap = new HashMap<Integer, TwoThings<Drawable, Drawable>>(); for (int i = 0; i < 3; i++) { // TODO: get rid of hardcoded value. int iconId = getIconResourceByPosition(i); Drawable positive = context.getResources().getDrawable(iconId); // TODO: deprecated! Drawable negative = context.getResources().getDrawable(iconId).mutate(); negative.setColorFilter(new PorterDuffColorFilter(SlidingTabStrip.DEFAULT_SELECTED_INDICATOR_COLOR, PorterDuff.Mode.MULTIPLY)); mIconMap.put(i, new TwoThings<Drawable, Drawable>(positive, negative)); } }
From source file:by.airport.airport_timetable.helpers.SlidingTabLayout.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 w ww . j a v a 2 s . c om*/ */ protected TextView createDefaultTabView(Context context) { WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = windowManager.getDefaultDisplay(); Point size = new Point(); display.getSize(size); TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTypeface(Typeface.DEFAULT_BOLD); textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); textView.setAllCaps(true); int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); textView.setWidth(size.x / 2); return textView; }
From source file:com.fisheradelakin.ribbit.utils.SlidingTabLayout.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 w ww . j ava 2 s .co m */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTypeface(Typeface.DEFAULT_BOLD); 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); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); // fit tabs to width of screen WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point size = new Point(); display.getSize(size); textView.setWidth(size.x / 2); // change number by how many tabs i have return textView; }
From source file:com.inductivebiblestudyapp.ui.dialogs.SimpleTooltipDialog.java
/** * Returns screen size in size 2 array./* w ww . j a v a 2 s . co m*/ * Taken directly from: * https://github.com/kvirair/Quick-Action/blob/master/src/garin/artemiy/quickaction/library/QuickAction.java * @param dimens 0 will become X size, 1 Y size. */ @SuppressWarnings("deprecation") protected void getScreenDimens(int[] dimens) { if (dimens.length < 2) { throw new IllegalArgumentException("Cannot store result in length <2"); } final int X = 0; final int Y = 1; WindowManager windowManager = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { Display display = windowManager.getDefaultDisplay(); Point size = new Point(); display.getSize(size); dimens[X] = size.x; dimens[Y] = size.y; } else { dimens[X] = windowManager.getDefaultDisplay().getWidth(); dimens[Y] = windowManager.getDefaultDisplay().getHeight(); } }
From source file:com.phicdy.mycuration.ui.TopActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_top); curationFragment = new CurationListFragment(); // Create the adapter that will return a fragment for each of the three // primary sections of the activity. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); mViewPager.addOnPageChangeListener(new PageChangeListener()); track = (ViewGroup) findViewById(R.id.track); trackScroller = (HorizontalScrollView) findViewById(R.id.track_scroller); indicator = (View) findViewById(R.id.indicator); WindowManager wm = getWindowManager(); Display disp = wm.getDefaultDisplay(); Point size = new Point(); disp.getSize(size);/* w ww. j a v a 2s .c om*/ int displayWidth = size.x; LayoutInflater inflater = LayoutInflater.from(this); for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { final int position = i; ImageView ivTab = (ImageView) inflater.inflate(R.layout.tab_item, track, false); ivTab.setImageResource(mSectionsPagerAdapter.getImageResource(position)); ivTab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mViewPager.setCurrentItem(position); } }); final LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) ivTab.getLayoutParams(); layoutParams.width = displayWidth / mSectionsPagerAdapter.getCount(); ivTab.setLayoutParams(layoutParams); track.addView(ivTab); } final float density = getResources().getDisplayMetrics().density; indicatorOffset = (int) (INDICATOR_OFFSET_DP * density); setTitle(getString(R.string.home)); dbAdapter = DatabaseAdapter.getInstance(getApplicationContext()); setAlarmManager(); }
From source file:agilec.ikeaswipe.utils.SlidingTabLayout.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)}.// w w w . j a va 2 s . c o m */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTypeface(Typeface.DEFAULT_BOLD); 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(true); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); // TODO: Use setCustomTabView(int, int) instead of the following modification to createDefaultTabView. // Get the screen size. WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point size = new Point(); display.getSize(size); int width = size.x; // Get the number of tabs in the viewPager. final PagerAdapter adapter = mViewPager.getAdapter(); // Set the width of the textViews to fill up the entire screen. textView.setWidth(width / adapter.getCount()); return textView; }
From source file:com.example.rachid.myapplication.SlidingTabLayout.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)}./*w w w . ja v a2 s . c o m*/ */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTypeface(Typeface.DEFAULT_BOLD); 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(true); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); // AADIDO: Ajustar pantalla // --------------------------------------------------------------------------------------- WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point size = new Point(); display.getSize(size); textView.setWidth(size.x / 3); // --------------------------------------------------------------------------------------- return textView; }
From source file:com.zzisoo.toylibrary.adapter.ToyListAdapter.java
private void setItemSize(View v) { Context c = v.getContext();//from w w w . j av a 2 s . co m WindowManager wm = (WindowManager) v.getContext().getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); int x = display.getWidth(); int y = display.getHeight(); int nwidth = x; if (Config.isLandscape(c)) { ((TextView) v.findViewById(R.id.tvToyTitle)).setMaxLines(Config.TITLE_MAX_LINE_LANDSCAPE); nwidth = x > y ? x : y; } else { ((TextView) v.findViewById(R.id.tvToyTitle)).setMaxLines(Config.TITLE_MAX_LINE_PORTRAIT); nwidth = x < y ? x : y; } int nItemPerWidth = nwidth / Config.getSpans(c); Log.e(TAG, ">>>" + x + "/" + y + " -->" + nItemPerWidth); v.findViewById(R.id.imageview_Background) .setLayoutParams(new LinearLayout.LayoutParams(nItemPerWidth, nItemPerWidth)); }
From source file:com.dtd.thevyshka.Utils.SlidingTabLayout.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)}./*ww w. j a v a 2s .c om*/ */ @SuppressLint("NewApi") protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point size = new Point(); display.getSize(size); textView.setWidth(size.x / mTabCount); textView.setGravity(Gravity.CENTER); textView.setTextSize(12);//TODO adapting to all textView.setTypeface(Typeface.DEFAULT_BOLD); textView.setTextColor(ContextCompat.getColor(context, R.color.white)); 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(true); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding / 2, padding, padding / 2, padding); return textView; }