use of android.util.DisplayMetrics in project UltimateRecyclerView by cymcsg.
the class TestAdvancedAdmobActivity method createadmob.
private RelativeLayout createadmob() {
AdSize adSize = AdSize.SMART_BANNER;
DisplayMetrics dm = getResources().getDisplayMetrics();
double density = dm.density * 160;
double x = Math.pow(dm.widthPixels / density, 2);
double y = Math.pow(dm.heightPixels / density, 2);
double screenInches = Math.sqrt(x + y);
if (screenInches > 8) {
// > 728 X 90
adSize = AdSize.LEADERBOARD;
} else if (screenInches > 6) {
// > 468 X 60
adSize = AdSize.MEDIUM_RECTANGLE;
} else {
// > 320 X 50
adSize = AdSize.BANNER;
}
adSize = AdSize.MEDIUM_RECTANGLE;
final AdView mAdView = new AdView(this);
mAdView.setAdSize(adSize);
mAdView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
// Create an ad request.
AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
if (admob_test_mode)
// Optionally populate the ad request builder.
adRequestBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
// Start loading the ad.
mAdView.loadAd(adRequestBuilder.build());
DisplayMetrics displaymetrics = new DisplayMetrics();
final RelativeLayout layout = AdGoogleDisplaySupport.initialSupport(this, displaymetrics);
final double ratio = AdGoogleDisplaySupport.ratioMatching(displaymetrics);
final int ad_height = AdGoogleDisplaySupport.defaultHeight(displaymetrics);
AdGoogleDisplaySupport.panelAdjust(mAdView, (int) (ad_height * ratio));
// get display info
/* G.display_w = displayMetrics.widthPixels;
G.display_h = displayMetrics.heightPixels;
G.scale = Math.max(G.display_w/1280.0f, G.display_h/800.0f);*/
mAdView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
super.onAdLoaded();
int h = mAdView.getLayoutParams().height;
AdGoogleDisplaySupport.scale(mAdView, ratio);
AdGoogleDisplaySupport.panelAdjust(mAdView, (int) (h * ratio));
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
}
});
layout.addView(mAdView);
return layout;
}
use of android.util.DisplayMetrics in project UltimateAndroid by cymcsg.
the class TextRoundCornerProgressBar method setup.
@SuppressLint("NewApi")
private void setup(Context context, AttributeSet attrs) {
int color;
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RoundCornerProgress);
autoTextChange = typedArray.getBoolean(R.styleable.RoundCornerProgress_rcp_autoTextChange, false);
DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, radius, metrics);
radius = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcp_backgroundRadius, radius);
textViewValue = (TextView) findViewById(R.id.round_corner_progress_text);
textSize = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcp_textProgressSize, textSize);
textViewValue.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
textViewValue.setTextColor(typedArray.getColor(R.styleable.RoundCornerProgress_rcp_textProgressColor, textColor));
text = typedArray.getString(R.styleable.RoundCornerProgress_rcp_textProgress);
text = (text == null) ? "" : text;
textViewValue.setText(text);
textPadding = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcp_textProgressPadding, textPadding);
textViewValue.setPadding(textPadding, 0, textPadding, 0);
textUnit = typedArray.getString(R.styleable.RoundCornerProgress_rcp_textProgressUnit);
textUnit = (textUnit == null) ? "" : textUnit;
textWidth = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcp_textProgressWidth, textWidth);
layoutBackground = (LinearLayout) findViewById(R.id.round_corner_progress_background);
padding = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcp_backgroundPadding, padding);
layoutBackground.setPadding(padding, padding, padding, padding);
if (!isBackgroundColorSetBeforeDraw) {
color = typedArray.getColor(R.styleable.RoundCornerProgress_rcp_backgroundColor, backgroundColor);
setBackgroundColor(color);
}
ViewTreeObserver observer = layoutBackground.getViewTreeObserver();
observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
layoutBackground.getViewTreeObserver().removeOnGlobalLayoutListener(this);
int height = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
backgroundWidth = layoutBackground.getMeasuredWidth() - textWidth;
height = layoutBackground.getMeasuredHeight();
} else {
backgroundWidth = layoutBackground.getWidth() - textWidth;
height = layoutBackground.getHeight();
}
backgroundHeight = (height == 0) ? (int) dp2px(DEFAULT_PROGRESS_BAR_HEIGHT) : height;
ViewGroup.LayoutParams params = (ViewGroup.LayoutParams) layoutBackground.getLayoutParams();
params.width = backgroundWidth;
params.height = backgroundHeight;
layoutBackground.setLayoutParams(params);
setProgress(progress);
}
});
layoutProgress = (LinearLayout) findViewById(R.id.round_corner_progress_progress);
if (!isProgressColorSetBeforeDraw) {
color = typedArray.getColor(R.styleable.RoundCornerProgress_rcp_progressColor, progressColor);
setProgressColor(color);
}
if (!isMaxProgressSetBeforeDraw) {
max = (int) typedArray.getInt(R.styleable.RoundCornerProgress_rcp_max, 0);
}
if (!isProgressSetBeforeDraw) {
progress = (int) typedArray.getInt(R.styleable.RoundCornerProgress_rcp_progress, 0);
}
typedArray.recycle();
}
use of android.util.DisplayMetrics in project UltimateAndroid by cymcsg.
the class Marker method resetSizes.
public void resetSizes(String maxValue) {
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
//Account for negative numbers... is there any proper way of getting the biggest string between our range????
mNumber.setText("-" + maxValue);
//Do a first forced measure call for the TextView (with the biggest text content),
//to calculate the max width and use always the same.
//this avoids the TextView from shrinking and growing when the text content changes
int wSpec = MeasureSpec.makeMeasureSpec(displayMetrics.widthPixels, MeasureSpec.AT_MOST);
int hSpec = MeasureSpec.makeMeasureSpec(displayMetrics.heightPixels, MeasureSpec.AT_MOST);
mNumber.measure(wSpec, hSpec);
mWidth = Math.max(mNumber.getMeasuredWidth(), mNumber.getMeasuredHeight());
removeView(mNumber);
addView(mNumber, new FrameLayout.LayoutParams(mWidth, mWidth, Gravity.LEFT | Gravity.TOP));
}
use of android.util.DisplayMetrics in project UltimateAndroid by cymcsg.
the class MaterialProgressDrawable method setSizeParameters.
private void setSizeParameters(double progressCircleWidth, double progressCircleHeight, double centerRadius, double strokeWidth, float arrowWidth, float arrowHeight) {
final Ring ring = mRing;
final DisplayMetrics metrics = mResources.getDisplayMetrics();
final float screenDensity = metrics.density;
mWidth = progressCircleWidth * screenDensity;
mHeight = progressCircleHeight * screenDensity;
ring.setStrokeWidth((float) strokeWidth * screenDensity);
ring.setCenterRadius(centerRadius * screenDensity);
ring.setColorIndex(0);
ring.setArrowDimensions(arrowWidth * screenDensity, arrowHeight * screenDensity);
ring.setInsets((int) mWidth, (int) mHeight);
}
use of android.util.DisplayMetrics in project UltimateAndroid by cymcsg.
the class MaterialProgressDrawable method setSizeParameters.
private void setSizeParameters(double progressCircleWidth, double progressCircleHeight, double centerRadius, double strokeWidth, float arrowWidth, float arrowHeight) {
final Ring ring = mRing;
final DisplayMetrics metrics = mResources.getDisplayMetrics();
final float screenDensity = metrics.density;
mWidth = progressCircleWidth * screenDensity;
mHeight = progressCircleHeight * screenDensity;
ring.setStrokeWidth((float) strokeWidth * screenDensity);
ring.setCenterRadius(centerRadius * screenDensity);
ring.setColorIndex(0);
ring.setArrowDimensions(arrowWidth * screenDensity, arrowHeight * screenDensity);
ring.setInsets((int) mWidth, (int) mHeight);
}
Aggregations