List of usage examples for android.content.res Resources getDimensionPixelSize
public int getDimensionPixelSize(@DimenRes int id) throws NotFoundException
From source file:com.geecko.QuickLyric.fragment.LyricsViewFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); MainActivity mainActivity = (MainActivity) getActivity(); if (mainActivity == null) return;/* ww w .ja v a2 s.c om*/ CollapsingToolbarLayout toolbarLayout = (CollapsingToolbarLayout) mainActivity .findViewById(R.id.toolbar_layout); toolbarLayout.setTitle(getString(R.string.app_name)); if (((DrawerLayout) mainActivity.drawer) // drawer is locked .getDrawerLockMode(mainActivity.drawerView) == DrawerLayout.LOCK_MODE_LOCKED_CLOSED) return; inflater.inflate(lyrics, menu); // Get the SearchView and set the searchable configuration final MaterialSuggestionsSearchView materialSearchView = (MaterialSuggestionsSearchView) mainActivity .findViewById(R.id.material_search_view); materialSearchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(final String query) { materialSearchView.setSuggestions(null); materialSearchView.requestFocus(); materialSearchView.post(new Runnable() { @Override public void run() { ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(materialSearchView.getWindowToken(), 0); } }); materialSearchView.postDelayed(new Runnable() { @Override public void run() { ((MainActivity) getActivity()).search(query); materialSearchView.setSuggestions(null); } }, 90); mExpandedSearchView = false; return true; } @Override public boolean onQueryTextChange(String newText) { if (!materialSearchView.hasSuggestions()) materialSearchView.setSuggestions(materialSearchView.getHistory()); return true; } }); materialSearchView.setOnSearchViewListener(new MaterialSearchView.SearchViewListener() { @Override public void onSearchViewShown() { if (getActivity() == null) return; ((ControllableAppBarLayout) getActivity().findViewById(R.id.appbar)).expandToolbar(true); mExpandedSearchView = true; } @Override public void onSearchViewClosed() { mExpandedSearchView = false; } }); final Resources resources = getResources(); final int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android"); int statusBarHeight; if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP) statusBarHeight = 0; else if (resourceId > 0) statusBarHeight = resources.getDimensionPixelSize(resourceId); else statusBarHeight = (int) Math.ceil((Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? 24 : 25) * resources.getDisplayMetrics().density); CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) materialSearchView.getLayoutParams(); lp.setMargins(lp.leftMargin, statusBarHeight, lp.rightMargin, lp.bottomMargin); materialSearchView.setLayoutParams(lp); MenuItem searchItem = menu.findItem(R.id.action_search); materialSearchView.setMenuItem(searchItem); if (!materialSearchView.isSearchOpen() && mExpandedSearchView) { materialSearchView.showSearch(); mExpandedSearchView = false; } else if (!mExpandedSearchView) materialSearchView.closeSearch(); materialSearchView.setHint(getString(R.string.search_hint)); if (mSearchQuery != null && !mSearchQuery.equals("")) { searchItem.expandActionView(); materialSearchView.setQuery(mSearchQuery, false); if (mSearchFocused) materialSearchView.requestFocus(); else materialSearchView.clearFocus(); mSearchQuery = null; } Lyrics storedLyrics = mLyrics == null ? null : DatabaseHelper.getInstance(getActivity()).get(new String[] { mLyrics.getArtist(), mLyrics.getTitle(), mLyrics.getOriginalArtist(), mLyrics.getOriginalTrack() }); MenuItem saveMenuItem = menu.findItem(R.id.save_action); if (saveMenuItem != null) { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity()); if (mLyrics == null) saveMenuItem.setVisible(false); else if (mLyrics.getFlag() == Lyrics.POSITIVE_RESULT && sharedPref.getBoolean("pref_auto_save", true)) { if (storedLyrics == null || (mLyrics.isLRC() && !storedLyrics.isLRC())) { lyricsPresentInDB = true; new WriteToDatabaseTask().execute(this, saveMenuItem, mLyrics); } saveMenuItem.setVisible(false); } else { saveMenuItem.setIcon(lyricsPresentInDB ? R.drawable.ic_trash : R.drawable.ic_save); saveMenuItem.setTitle(lyricsPresentInDB ? R.string.remove_action : R.string.save_action); } } MenuItem resyncMenuItem = menu.findItem(R.id.resync_action); MenuItem convertMenuItem = menu.findItem(R.id.convert_action); if (resyncMenuItem != null) resyncMenuItem.setVisible(mLyrics != null && mLyrics.isLRC()); if (convertMenuItem != null) { Lyrics stored = mLyrics == null || mLyrics.isLRC() ? null : storedLyrics; convertMenuItem .setVisible((mLyrics != null && (mLyrics.isLRC())) || (stored != null && stored.isLRC())); convertMenuItem.setTitle(stored == null ? R.string.full_text_action : R.string.pref_lrc); } MenuItem shareMenuItem = menu.findItem(R.id.share_action); if (shareMenuItem != null) shareMenuItem.setVisible( mLyrics != null && mLyrics.getFlag() == Lyrics.POSITIVE_RESULT && mLyrics.getURL() != null); }
From source file:com.miz.functions.MizLib.java
public static int getNavigationBarWidth(Context context) { Resources resources = context.getResources(); int resourceId = resources.getIdentifier("navigation_bar_width", "dimen", "android"); if (resourceId > 0) { return resources.getDimensionPixelSize(resourceId); }//from ww w.j a va 2s . c om return 0; }
From source file:com.android.datetimepicker.date.MonthView.java
public MonthView(Context context, AttributeSet attr) { super(context, attr); Resources res = context.getResources(); mDayLabelCalendar = Calendar.getInstance(); mCalendar = Calendar.getInstance(); mDayOfWeekTypeface = res.getString(R.string.day_of_week_label_typeface); mMonthTitleTypeface = res.getString(R.string.sans_serif); mDayTextColor = res.getColor(R.color.date_picker_text_normal); mTodayNumberColor = res.getColor(R.color.blue); mDisabledDayTextColor = res.getColor(R.color.date_picker_text_disabled); mMonthTitleColor = res.getColor(R.color.white); mMonthTitleBGColor = res.getColor(R.color.circle_background); mStringBuilder = new StringBuilder(50); mFormatter = new Formatter(mStringBuilder, Locale.getDefault()); MINI_DAY_NUMBER_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.day_number_size); MONTH_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.month_label_size); MONTH_DAY_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.month_day_label_text_size); MONTH_HEADER_SIZE = res.getDimensionPixelOffset(R.dimen.month_list_item_header_height); DAY_SELECTED_CIRCLE_SIZE = res.getDimensionPixelSize(R.dimen.day_number_select_circle_radius); mRowHeight = (res.getDimensionPixelOffset(R.dimen.date_picker_view_animator_height) - getMonthHeaderSize()) / MAX_NUM_ROWS;/* w w w . ja v a 2 s .c o m*/ // Set up accessibility components. mTouchHelper = getMonthViewTouchHelper(); ViewCompat.setAccessibilityDelegate(this, mTouchHelper); ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); mLockAccessibilityDelegate = true; // Sets up any standard paints that will be used initView(); }
From source file:edu.hawaii.android.datetimepickermaterial.date.MonthView.java
public MonthView(Context context, AttributeSet attr) { super(context, attr); Resources res = context.getResources(); mDayLabelCalendar = Calendar.getInstance(); mCalendar = Calendar.getInstance(); mDayOfWeekTypeface = res.getString(R.string.day_of_week_label_typeface); mMonthTitleTypeface = res.getString(R.string.sans_serif); mDayTextColor = res.getColor(R.color.date_picker_text_normal); mTodayNumberColor = res.getColor(R.color.green); mDisabledDayTextColor = res.getColor(R.color.date_picker_text_disabled); mMonthTitleColor = res.getColor(R.color.white); mMonthTitleBGColor = res.getColor(R.color.circle_background); mStringBuilder = new StringBuilder(50); mFormatter = new Formatter(mStringBuilder, Locale.getDefault()); MINI_DAY_NUMBER_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.day_number_size); MONTH_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.month_label_size); MONTH_DAY_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.month_day_label_text_size); MONTH_HEADER_SIZE = res.getDimensionPixelOffset(R.dimen.month_list_item_header_height); DAY_SELECTED_CIRCLE_SIZE = res.getDimensionPixelSize(R.dimen.day_number_select_circle_radius); mRowHeight = (res.getDimensionPixelOffset(R.dimen.date_picker_view_animator_height) - getMonthHeaderSize()) / MAX_NUM_ROWS;//from www .j a v a 2 s .c o m // Set up accessibility components. mTouchHelper = getMonthViewTouchHelper(); ViewCompat.setAccessibilityDelegate(this, mTouchHelper); ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); mLockAccessibilityDelegate = true; // Sets up any standard paints that will be used initView(); }
From source file:com.limewoodmedia.nsdroid.fragments.WACouncilFragment.java
public void loadCouncil(WACouncil council, WAData data) { setCouncil(council);//from ww w. j a va2 s . c o m if (data.resolution.name != null) { atVote.setText(Html.fromHtml("<b>" + getString(R.string.wa_at_vote) + ":</b> " + data.resolution.name)); float total = data.resolution.votes.forVotes + data.resolution.votes.againstVotes; votes.setText(Html.fromHtml("<b>" + getString(R.string.wa_votes_for) + ":</b> " + format.format(data.resolution.votes.forVotes / total) + "<br/>" + "<b>" + getString(R.string.wa_votes_against) + ":</b> " + format.format(data.resolution.votes.againstVotes / total))); Calendar cal = Calendar.getInstance(Locale.ENGLISH); cal.setTimeInMillis(data.resolution.created * 1000); Log.d(TAG, "Created: " + cal.getTimeInMillis()); cal.add(Calendar.DAY_OF_YEAR, 7); Log.d(TAG, "Ending: " + cal.getTimeInMillis()); int[] daysHours = Utils.getWADaysHoursLeft(data.resolution.voteTrack.forVotes.length); int days = daysHours[0]; int hours = daysHours[1]; Resources r = getResources(); below.setText(Html.fromHtml(getString(R.string.voting_ends, days, hours, r.getQuantityString(R.plurals.days, days), r.getQuantityString(R.plurals.hours, hours)) + "<br/><br/><b>" + getString(R.string.wa_recent) + ":</b> " + data.lastResolution)); // Set up chart Log.d(TAG, "Set up values"); series.clear(); CategorySeries forVotes = new CategorySeries("For"); CategorySeries againstVotes = new CategorySeries("Against"); forVotes.add("For", data.resolution.votes.forVotes); againstVotes.add("Against", data.resolution.votes.againstVotes); series.addSeries(forVotes.toXYSeries()); series.addSeries(againstVotes.toXYSeries()); setUpChartRenderer(renderer); renderer.setYAxisMax( Math.max(data.resolution.votes.forVotes, data.resolution.votes.againstVotes) * 1.2f); LinearLayout layout = (LinearLayout) root.findViewById(R.id.at_vote_chart); chart = ChartFactory.getBarChartView(getActivity(), series, renderer, BarChart.Type.DEFAULT); layout.addView(chart, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, r.getDimensionPixelSize(R.dimen.wa_bar_chart_height))); chart.repaint(); } else { atVote.setText(R.string.none); votes.setVisibility(View.GONE); root.findViewById(R.id.at_vote_chart).setVisibility(View.GONE); below.setText(Html .fromHtml("<br/><br/><b>" + getString(R.string.wa_recent) + ":</b> " + data.lastResolution)); } }
From source file:com.superchat.date.MonthView.java
public MonthView(Context context, AttributeSet attr) { super(context, attr); Resources res = context.getResources(); mDayLabelCalendar = Calendar.getInstance(); mCalendar = Calendar.getInstance(); mDayOfWeekTypeface = res.getString(R.string.day_of_week_label_typeface); mMonthTitleTypeface = res.getString(R.string.sans_serif); mDayTextColor = res.getColor(R.color.date_picker_text_normal); mTodayNumberColor = res.getColor(R.color.blue); mDisabledDayTextColor = res.getColor(R.color.date_picker_text_disabled); mMonthTitleColor = res.getColor(android.R.color.white); mMonthTitleBGColor = res.getColor(R.color.circle_background); mStringBuilder = new StringBuilder(50); mFormatter = new Formatter(mStringBuilder, Locale.getDefault()); MINI_DAY_NUMBER_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.day_number_size); MONTH_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.month_label_size); MONTH_DAY_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.month_day_label_text_size); MONTH_HEADER_SIZE = res.getDimensionPixelOffset(R.dimen.month_list_item_header_height); DAY_SELECTED_CIRCLE_SIZE = res.getDimensionPixelSize(R.dimen.day_number_select_circle_radius); mRowHeight = (res.getDimensionPixelOffset(R.dimen.date_picker_view_animator_height) - getMonthHeaderSize()) / MAX_NUM_ROWS;// w ww. j av a2 s. c om // Set up accessibility components. mTouchHelper = getMonthViewTouchHelper(); ViewCompat.setAccessibilityDelegate(this, mTouchHelper); ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); mLockAccessibilityDelegate = true; // Sets up any standard paints that will be used initView(); }
From source file:cl.monsoon.s1next.widget.PhotoView.java
/** * Initializes the header and any static values *//*from ww w. ja v a2 s . c o m*/ private void initialize() { Context context = getContext(); if (!sInitialized) { sInitialized = true; Resources resources = context.getResources(); sCropSize = resources.getDimensionPixelSize(R.dimen.photo_view_crop_width); sCropDimPaint = new Paint(); sCropDimPaint.setAntiAlias(true); sCropDimPaint.setColor(ContextCompat.getColor(context, R.color.photo_view_crop_dim_color)); sCropDimPaint.setStyle(Style.FILL); sCropPaint = new Paint(); sCropPaint.setAntiAlias(true); sCropPaint.setColor(ContextCompat.getColor(context, R.color.photo_view_crop_dim_color)); sCropPaint.setStyle(Style.STROKE); sCropPaint.setStrokeWidth(resources.getDimension(R.dimen.photo_view_crop_stroke_width)); final ViewConfiguration configuration = ViewConfiguration.get(context); final int touchSlop = configuration.getScaledTouchSlop(); sTouchSlopSquare = touchSlop * touchSlop; } mGestureDetector = new GestureDetectorCompat(context, this, null); scaleGestureDetector = new ScaleGestureDetector(context, this); mQuickScaleEnabled = ScaleGestureDetectorCompat.isQuickScaleEnabled(scaleGestureDetector); mScaleRunnable = new ScaleRunnable(this); mTranslateRunnable = new TranslateRunnable(this); mSnapRunnable = new SnapRunnable(this); mRotateRunnable = new RotateRunnable(this); }
From source file:com.mattfred.betterpickers.calendardatepicker.MonthView.java
public MonthView(Context context) { super(context); Resources res = context.getResources(); mDayLabelCalendar = Calendar.getInstance(); mCalendar = Calendar.getInstance(); mDayOfWeekTypeface = res.getString(R.string.day_of_week_label_typeface); mMonthTitleTypeface = res.getString(R.string.sans_serif); mDayTextColorEnabled = res.getColor(R.color.date_picker_text_normal); mDayTextColorDisabled = res.getColor(R.color.date_picker_text_disabled); mTodayNumberColor = res.getColor(R.color.bpBlue); mDisabledDayColor = res.getColor(R.color.bpDarker_red); mMonthTitleColor = res.getColor(R.color.date_picker_text_normal); mMonthTitleBGColor = res.getColor(R.color.circle_background); mStringBuilder = new StringBuilder(50); mFormatter = new Formatter(mStringBuilder, Locale.getDefault()); MINI_DAY_NUMBER_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.day_number_size); MONTH_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.month_label_size); MONTH_DAY_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.month_day_label_text_size); MONTH_HEADER_SIZE = res.getDimensionPixelOffset(R.dimen.month_list_item_header_height); DAY_SELECTED_CIRCLE_SIZE = res.getDimensionPixelSize(R.dimen.day_number_select_circle_radius); mRowHeight = (res.getDimensionPixelOffset(R.dimen.date_picker_view_animator_height) - MONTH_HEADER_SIZE) / MAX_NUM_ROWS;/*from ww w . j a va 2s. c o m*/ // Set up accessibility components. mTouchHelper = new MonthViewTouchHelper(this); ViewCompat.setAccessibilityDelegate(this, mTouchHelper); ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); mLockAccessibilityDelegate = true; // Sets up any standard paints that will be used initView(); }
From source file:jp.seesaa.android.datetimepicker.date.MonthView.java
public MonthView(Context context, AttributeSet attr) { super(context, attr); Resources res = context.getResources(); mDayLabelCalendar = Calendar.getInstance(); mCalendar = Calendar.getInstance(); mDayOfWeekTypeface = res.getString(R.string.dtp_day_of_week_label_typeface); mMonthTitleTypeface = res.getString(R.string.dtp_sans_serif); mDayTextColor = res.getColor(R.color.dtp_date_picker_text_normal); mTodayNumberColor = res.getColor(R.color.dtp_blue); mDisabledDayTextColor = res.getColor(R.color.dtp_date_picker_text_disabled); mMonthTitleColor = res.getColor(R.color.dtp_white); mMonthTitleBGColor = res.getColor(R.color.dtp_circle_background); mStringBuilder = new StringBuilder(50); mFormatter = new Formatter(mStringBuilder, Locale.getDefault()); MINI_DAY_NUMBER_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.dtp_day_number_size); MONTH_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.dtp_month_label_size); MONTH_DAY_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.dtp_month_day_label_text_size); MONTH_HEADER_SIZE = res.getDimensionPixelOffset(R.dimen.dtp_month_list_item_header_height); DAY_SELECTED_CIRCLE_SIZE = res.getDimensionPixelSize(R.dimen.dtp_day_number_select_circle_radius); mRowHeight = (res.getDimensionPixelOffset(R.dimen.dtp_date_picker_view_animator_height) - getMonthHeaderSize()) / MAX_NUM_ROWS; // Set up accessibility components. mTouchHelper = getMonthViewTouchHelper(); ViewCompat.setAccessibilityDelegate(this, mTouchHelper); ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); mLockAccessibilityDelegate = true;// w w w. j a v a 2 s . co m // Sets up any standard paints that will be used initView(); }
From source file:fr.tvbarthel.apps.simpleweatherforcast.MainActivity.java
private void initRootPadding() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { final Resources resources = getResources(); final boolean isPortrait = resources.getBoolean(R.bool.is_portrait); final ActionBar actionBar = getSupportActionBar(); final ViewTreeObserver vto = mRootView.getViewTreeObserver(); if (vto.isAlive()) { vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override/*from ww w . j a v a2s . c om*/ public boolean onPreDraw() { mRootView.getViewTreeObserver().removeOnPreDrawListener(this); int paddingBottom = mRootView.getPaddingBottom(); int paddingTop = mRootView.getPaddingTop(); int paddingRight = mRootView.getPaddingRight(); int paddingLeft = mRootView.getPaddingLeft(); // Add the status bar height to the top padding. int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { paddingTop += resources.getDimensionPixelSize(resourceId); } if (isPortrait) { // Add the navigation bar height to the bottom padding. resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); if (resourceId > 0) { paddingBottom += resources.getDimensionPixelSize(resourceId); } } else { // Add the navigation bar width to the right padding. resourceId = resources.getIdentifier("navigation_bar_width", "dimen", "android"); if (resourceId > 0) { paddingRight += resources.getDimensionPixelSize(resourceId); } } mRootView.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); return true; } }); } } }