下面列出了android.view.WindowInsets#isRound ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void onApplyWindowInsets(WindowInsets insets) {
super.onApplyWindowInsets(insets);
Log.d("onApplyWindowInsets",
"onApplyWindowInsets: " + (insets.isRound() ? "round" : "square"));
// Load resources that have alternate values for round watches.
Resources resources = PixelWatchFace.this.getResources();
mIsRound = insets.isRound();
mChinSize = insets.getSystemWindowInsetBottom();
float timeTextSize = resources.getDimension(mIsRound
? R.dimen.digital_time_text_size_round : R.dimen.digital_time_text_size);
float dateTextSize = resources.getDimension(mIsRound
? R.dimen.digital_date_text_size_round : R.dimen.digital_date_text_size);
mTimePaint.setTextSize(timeTextSize);
mInfoPaint.setTextSize(dateTextSize);
}
@Override public WindowInsets onApplyWindowInsets(final WindowInsets insets) {
if(insets.isRound()) {
heading.setGravity(Gravity.CENTER_HORIZONTAL);
// Adjust paddings for round devices
if(!hasAdjustedPadding) {
final int padding = heading.getPaddingTop();
heading.setPadding(padding, 2 * padding, padding, padding);
list.setPadding(padding, 0, padding, 0);
hasAdjustedPadding = true;
}
} else {
heading.setGravity(Gravity.START);
}
return super.onApplyWindowInsets(insets);
}
@Override
public void onApplyWindowInsets(WindowInsets insets) {
if (insets.isRound()) {
inset = -2;
setWatchFaceStyle(new WatchFaceStyle.Builder(EarthWatchFaceService.this)
.setHotwordIndicatorGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM)
.setPeekOpacityMode(WatchFaceStyle.PEEK_OPACITY_MODE_TRANSLUCENT)
.setShowSystemUiTime(true)
.setShowUnreadCountIndicator(true)
.setStatusBarGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP)
.setViewProtectionMode(WatchFaceStyle.PROTECT_HOTWORD_INDICATOR
| WatchFaceStyle.PROTECT_STATUS_BAR)
.build());
} else {
inset = getResources().getDimensionPixelOffset(R.dimen.padding_square);
setWatchFaceStyle(new WatchFaceStyle.Builder(EarthWatchFaceService.this)
.setHotwordIndicatorGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM)
.setPeekOpacityMode(WatchFaceStyle.PEEK_OPACITY_MODE_TRANSLUCENT)
.setShowSystemUiTime(true)
.setShowUnreadCountIndicator(true)
.setStatusBarGravity(Gravity.END | Gravity.TOP)
.setViewProtectionMode(WatchFaceStyle.PROTECT_HOTWORD_INDICATOR
| WatchFaceStyle.PROTECT_STATUS_BAR)
.build());
}
}
@Override
public void onApplyWindowInsets(WindowInsets insets) {
super.onApplyWindowInsets(insets);
// Load resources that have alternate values for round watches.
Resources resources = BinaryWatchFaceService.this.getResources();
if(!insets.isRound()) {
dotYExtraOffset = getResources().getDimension(R.dimen.digital_y_square_extra_offset);
}
dotWidth = getResources().getDimension(R.dimen.circle_width);
dotMargin = getResources().getDimension(R.dimen.circle_margin);
clockYOffset = getResources().getDimension(R.dimen.digital_y_offset);
textPaint.setTextSize(resources.getDimension(R.dimen.text_size));
}
@Override
public void onApplyWindowInsets(WindowInsets insets) {
super.onApplyWindowInsets(insets);
int gravity = !insets.isRound() ? (Gravity.START | Gravity.TOP) : Gravity.CENTER;
setWatchFaceStyle(new WatchFaceStyle.Builder(LayoutFaceService.this)
.setStatusBarGravity(gravity)
.setAccentColor(0xff526cfe)
.build());
// Load the display spec - we'll need this later for measuring layoutRoot
Point displaySize = new Point();
((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay()
.getSize(displaySize);
if (layoutRoot instanceof LinearLayout) {
int height = (int) (displaySize.y * 0.28);
int width = (int) (height * 0.62);
for (LottieAnimationView digitView : digitViews) {
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) digitView.getLayoutParams();
params.width = width;
params.height = height;
}
//noinspection SuspiciousNameCombination
layoutRoot.findViewById(R.id.logo).setLayoutParams(new LinearLayout.LayoutParams(height, height));
}
// Recompute the MeasureSpec fields - these determine the actual size of the layout
int specW = View.MeasureSpec.makeMeasureSpec(displaySize.x, View.MeasureSpec.EXACTLY);
int specH = View.MeasureSpec.makeMeasureSpec(displaySize.y, View.MeasureSpec.EXACTLY);
// Update the layout
layoutRoot.measure(specW, specH);
layoutRoot.layout(0, 0, layoutRoot.getMeasuredWidth(), layoutRoot.getMeasuredHeight());
}
@Override
public void onApplyWindowInsets(WindowInsets insets) {
super.onApplyWindowInsets(insets);
mIsRound = insets.isRound();
if(mIsRound) {
mTimePaint.setTextSize(getResources().getDimension(R.dimen.font_size_time_round));
}else{
mTimePaint.setTextSize(getResources().getDimension(R.dimen.font_size_time_square));
}
}
@Override
public void onApplyWindowInsets(WindowInsets insets) {
super.onApplyWindowInsets(insets);
mYOffset = getResources().getDimension( R.dimen.y_offset );
if( insets.isRound() ) {
mXOffset = getResources().getDimension( R.dimen.x_offset_round );
} else {
mXOffset = getResources().getDimension( R.dimen.x_offset_square );
}
}
@Override
public void onApplyWindowInsets(WindowInsets insets) {
super.onApplyWindowInsets(insets);
// Load resources that have alternate values for round watches.
Resources resources = MyTapFace.this.getResources();
boolean isRound = insets.isRound();
mXOffset = resources.getDimension(isRound
? R.dimen.digital_x_offset_round : R.dimen.digital_x_offset);
float textSize = resources.getDimension(isRound
? R.dimen.digital_text_size_round : R.dimen.digital_text_size);
mTextPaint.setTextSize(textSize);
}
@Override
public void onApplyWindowInsets(WindowInsets insets) {
super.onApplyWindowInsets(insets);
// Load resources that have alternate values for round watches.
Resources resources = MyTapFace.this.getResources();
boolean isRound = insets.isRound();
mXOffset = resources.getDimension(isRound
? R.dimen.digital_x_offset_round : R.dimen.digital_x_offset);
float textSize = resources.getDimension(isRound
? R.dimen.digital_text_size_round : R.dimen.digital_text_size);
mTextPaint.setTextSize(textSize);
}
@Override
protected void onLayout(WatchShape shape, Rect screenBounds, WindowInsets screenInsets) {
super.onLayout(shape, screenBounds, screenInsets);
layoutView.onApplyWindowInsets(screenInsets);
bIsRound = screenInsets.isRound();
}
@Override
public void onApplyWindowInsets(WindowInsets insets) {
super.onApplyWindowInsets(insets);
// Load resources that have alternate values for round watches.
Resources resources = BatmanWatchFaceService.this.getResources();
boolean isRound = insets.isRound();
mXOffset = resources.getDimension(isRound
? R.dimen.digital_x_offset_round : R.dimen.digital_x_offset);
//time size
float textSize = resources.getDimension(isRound
// ? R.dimen.digital_text_size_round : R.dimen.digital_text_size);
? R.dimen.date_text_size_round : R.dimen.date_text_size);
//date size.
float datetextSize = resources.getDimension(isRound
? R.dimen.date_text_size_round : R.dimen.date_text_size);
mTextPaint_date.setTextSize(datetextSize);
mTextPaint_time.setTextSize(textSize);
//setup where everything goes.
Rect bounds = new Rect();
String text = "13:40:45"; //sample time
mTextPaint_time.getTextBounds(text, 0, text.length(), bounds );
time_height = bounds.height();
time_width = bounds.width();
text = "13:40"; //sample date ambient
mTextPaint_time.getTextBounds(text, 0, text.length(), bounds );
time_width_amb = bounds.width();
time_height_amb = bounds.height();
text = "02/27 Mon"; //sample date
mTextPaint_date.getTextBounds(text, 0, text.length(), bounds );
date_height = bounds.height();
date_width = bounds.width();
}
@Override
public void onApplyWindowInsets(WindowInsets insets) {
super.onApplyWindowInsets(insets);
// Load resources that have alternate values for round watches.
Resources resources = BatmanWatchFaceService.this.getResources();
boolean isRound = insets.isRound();
mXOffset = resources.getDimension(isRound
? R.dimen.digital_x_offset_round : R.dimen.digital_x_offset);
//time size
float textSize = resources.getDimension(isRound
// ? R.dimen.digital_text_size_round : R.dimen.digital_text_size);
? R.dimen.date_text_size_round : R.dimen.date_text_size);
//date size.
float datetextSize = resources.getDimension(isRound
? R.dimen.date_text_size_round : R.dimen.date_text_size);
mTextPaint_date.setTextSize(datetextSize);
mTextPaint_time.setTextSize(textSize);
//setup where everything goes.
Rect bounds = new Rect();
String text = "13:40:45"; //sample time
mTextPaint_time.getTextBounds(text, 0, text.length(), bounds );
time_height = bounds.height();
time_width = bounds.width();
text = "13:40"; //sample date ambient
mTextPaint_time.getTextBounds(text, 0, text.length(), bounds );
time_width_amb = bounds.width();
time_height_amb = bounds.height();
text = "02/27 Mon"; //sample date
mTextPaint_date.getTextBounds(text, 0, text.length(), bounds );
date_height = bounds.height();
date_width = bounds.width();
}