Java Code Examples for android.support.annotation.Dimension.DP

The following are Jave code examples for showing how to use DP of the android.support.annotation.Dimension class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Customerly-Android-SDK   File: IU_Utils.java   View Source Code Vote up 5 votes
@Contract(pure = true)
@Px static int px(@Dimension(unit = Dimension.DP) int dp) {
    float dpi = Resources.getSystem().getDisplayMetrics().density;
    dpi = dpi > 100/*120, 160, 213, 240, 320, 480 or 640 dpi*/ ? dpi / 160f : dpi;
    dpi = dpi == 0 ? 1f : dpi;
    return (int) (dp * dpi);
}
 
Example 2
Project: bigbang   File: MetricsHelper.java   View Source Code Vote up 5 votes
/**
 * Retrieves the toolbar height of the current app theme.
 *
 * @param theme the device {@link Theme}
 * @param actionBarSize the current {@link ActionBar} size
 * @return the toolbar height of the current app theme
 */
@Dimension(unit = Dimension.DP)
public static int getToolbarHeight(@NonNull Theme theme, @AttrRes int actionBarSize) {
  final TypedArray styledAttributes = theme.obtainStyledAttributes(new int[] {actionBarSize});
  int toolbarHeight = (int) styledAttributes.getDimension(0, 0);
  styledAttributes.recycle();
  return toolbarHeight;
}
 
Example 3
Project: material-components-android   File: TabLayout.java   View Source Code Vote up 5 votes
@Dimension(unit = Dimension.DP)
private int getDefaultHeight() {
  boolean hasIconAndText = false;
  for (int i = 0, count = tabs.size(); i < count; i++) {
    Tab tab = tabs.get(i);
    if (tab != null && tab.getIcon() != null && !TextUtils.isEmpty(tab.getText())) {
      hasIconAndText = true;
      break;
    }
  }
  return (hasIconAndText && !inlineLabel) ? DEFAULT_HEIGHT_WITH_TEXT_ICON : DEFAULT_HEIGHT;
}
 
Example 4
Project: Customerly-Android-SDK   File: IU_Utils.java   View Source Code Vote up 5 votes
@Contract(pure = true)
@Px static int px(@Dimension(unit = Dimension.DP) int dp) {
    float dpi = Resources.getSystem().getDisplayMetrics().density;
    dpi = dpi > 100/*120, 160, 213, 240, 320, 480 or 640 dpi*/ ? dpi / 160f : dpi;
    dpi = dpi == 0 ? 1f : dpi;
    return (int) (dp * dpi);
}
 
Example 5
Project: spanner   File: Spans.java   View Source Code Vote up 4 votes
/**
 * @see android.text.style.AbsoluteSizeSpan#AbsoluteSizeSpan(int, boolean)
 */
public static Span sizeDP(@Dimension(unit = Dimension.DP) final int dp) {
    return new Span(new AbsoluteSizeSpanBuilder(dp, true));
}
 
Example 6
Project: bigbang   File: MetricsHelperTest.java   View Source Code Vote up 4 votes
@Test
public void testDpToPx() {
  @Dimension(unit = Dimension.DP) int dp = 10;
  Assert.assertEquals(25.0f, MetricsHelper.dpToPx(resources, dp));
}
 
Example 7
Project: bigbang   File: MetricsHelperTest.java   View Source Code Vote up 4 votes
@Test
public void testDpToPxInt() {
  @Dimension(unit = Dimension.DP) int dp = 3;
  Assert.assertEquals(7, MetricsHelper.dpToPxInt(resources, dp));
}
 
Example 8
Project: bigbang   File: MetricsHelperTest.java   View Source Code Vote up 4 votes
@Test
public void testDpToPx() {
  @Dimension(unit = Dimension.DP) int dp = 10;
  Assert.assertEquals(25.0f, MetricsHelper.dpToPx(resources, dp));
}
 
Example 9
Project: bigbang   File: MetricsHelperTest.java   View Source Code Vote up 4 votes
@Test
public void testDpToPxInt() {
  @Dimension(unit = Dimension.DP) int dp = 3;
  Assert.assertEquals(7, MetricsHelper.dpToPxInt(resources, dp));
}
 
Example 10
Project: material-components-android   File: TabLayout.java   View Source Code Vote up 4 votes
@Dimension(unit = Dimension.PX)
int dpToPx(@Dimension(unit = Dimension.DP) int dps) {
  return Math.round(getResources().getDisplayMetrics().density * dps);
}
 
Example 11
Project: bigbang   File: MetricsHelper.java   View Source Code Vote up 2 votes
/**
 * Converts the {@code dp} value to pixels dimension.
 *
 * @param resources to obtain the density value
 * @param dp the value in dp dimension
 * @return the converted {@code dp} value to pixels
 */
@Dimension(unit = Dimension.PX)
public static float dpToPx(@NonNull Resources resources, @Dimension(unit = Dimension.DP) float dp) {
  return dp * resources.getDisplayMetrics().density;
}
 
Example 12
Project: bigbang   File: MetricsHelper.java   View Source Code Vote up 2 votes
/**
 * Converts the {@code dp} value to pixels dimension.
 *
 * @param resources to obtain the density value
 * @param dp the value in dp dimension
 * @return the converted {@code dp} value to integer pixels
 */
@Dimension(unit = Dimension.PX)
public static int dpToPxInt(@NonNull Resources resources, @Dimension(unit = Dimension.DP) float dp) {
  return (int) dpToPx(resources, dp);
}
 
Example 13
Project: bigbang   File: MetricsHelper.java   View Source Code Vote up 2 votes
/**
 * Converts the {@code px} value to dp.
 *
 * @param resources to obtain the density value
 * @param px the value in pixels to convert to dp
 * @return the converted {@code px} value to dp
 */
@Dimension(unit = Dimension.DP)
public static float pxToDp(@NonNull Resources resources, @Dimension(unit = Dimension.PX) float px) {
  return px / resources.getDisplayMetrics().density;
}