use of android.util.DisplayMetrics in project PhotoNoter by yydcdut.
the class SettingActivity method closeActivityAnimation.
private void closeActivityAnimation() {
int actionBarHeight = getActionBarSize();
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int screenHeight = dm.heightPixels;
int contentHeight = screenHeight - actionBarHeight;
AnimatorSet animation = new AnimatorSet();
animation.setDuration(Const.DURATION_ACTIVITY);
animation.playTogether(ObjectAnimator.ofFloat(mToolbarLayout, "translationY", 0, -actionBarHeight), ObjectAnimator.ofFloat(mScrollView, "translationY", 0, contentHeight));
animation.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
mIsHiding = false;
finish();
overridePendingTransition(R.anim.activity_no_animation, R.anim.activity_no_animation);
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
animation.start();
}
use of android.util.DisplayMetrics in project PhotoNoter by yydcdut.
the class SettingActivity method startActivityAnimation.
@Override
public void startActivityAnimation() {
int actionBarHeight = getActionBarSize();
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int screenHeight = dm.heightPixels;
int contentHeight = screenHeight - actionBarHeight;
AnimatorSet animation = new AnimatorSet();
animation.setDuration(Const.DURATION_ACTIVITY);
animation.playTogether(ObjectAnimator.ofFloat(mToolbarLayout, "translationY", -actionBarHeight, 0), ObjectAnimator.ofFloat(mScrollView, "translationY", contentHeight, 0));
animation.start();
}
use of android.util.DisplayMetrics in project platform_frameworks_base by android.
the class PlatLogoActivity method onAttachedToWindow.
@Override
public void onAttachedToWindow() {
final DisplayMetrics dm = getResources().getDisplayMetrics();
final float dp = dm.density;
final int size = (int) (Math.min(Math.min(dm.widthPixels, dm.heightPixels), 600 * dp) - 100 * dp);
final ImageView im = new ImageView(this);
final int pad = (int) (40 * dp);
im.setPadding(pad, pad, pad, pad);
im.setTranslationZ(20);
im.setScaleX(0.5f);
im.setScaleY(0.5f);
im.setAlpha(0f);
im.setBackground(new RippleDrawable(ColorStateList.valueOf(0xFFFFFFFF), getDrawable(com.android.internal.R.drawable.platlogo), null));
// im.setOutlineProvider(new ViewOutlineProvider() {
// @Override
// public void getOutline(View view, Outline outline) {
// outline.setOval(0, 0, view.getWidth(), view.getHeight());
// }
// });
im.setClickable(true);
im.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
im.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (mTapCount < 5)
return false;
if (REVEAL_THE_NAME) {
final Drawable overlay = getDrawable(com.android.internal.R.drawable.platlogo_m);
overlay.setBounds(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
im.getOverlay().clear();
im.getOverlay().add(overlay);
overlay.setAlpha(0);
ObjectAnimator.ofInt(overlay, "alpha", 0, 255).setDuration(500).start();
}
final ContentResolver cr = getContentResolver();
if (Settings.System.getLong(cr, Settings.System.EGG_MODE, 0) == 0) {
// For posterity: the moment this user unlocked the easter egg
try {
Settings.System.putLong(cr, Settings.System.EGG_MODE, System.currentTimeMillis());
} catch (RuntimeException e) {
Log.e("PlatLogoActivity", "Can't write settings", e);
}
}
im.post(new Runnable() {
@Override
public void run() {
try {
startActivity(new Intent(Intent.ACTION_MAIN).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS).addCategory("com.android.internal.category.PLATLOGO"));
} catch (ActivityNotFoundException ex) {
Log.e("PlatLogoActivity", "No more eggs.");
}
if (FINISH)
finish();
}
});
return true;
}
});
mTapCount++;
}
});
// Enable hardware keyboard input for TV compatibility.
im.setFocusable(true);
im.requestFocus();
im.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (keyCode != KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
++mKeyCount;
if (mKeyCount > 2) {
if (mTapCount > 5) {
im.performLongClick();
} else {
im.performClick();
}
}
return true;
} else {
return false;
}
}
});
mLayout.addView(im, new FrameLayout.LayoutParams(size, size, Gravity.CENTER));
im.animate().scaleX(1f).scaleY(1f).alpha(1f).setInterpolator(mInterpolator).setDuration(500).setStartDelay(800).start();
}
use of android.util.DisplayMetrics in project platform_frameworks_base by android.
the class ResourcesManager method applyConfigurationToResourcesLocked.
public final boolean applyConfigurationToResourcesLocked(@NonNull Configuration config, @Nullable CompatibilityInfo compat) {
try {
Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, "ResourcesManager#applyConfigurationToResourcesLocked");
if (!mResConfiguration.isOtherSeqNewer(config) && compat == null) {
if (DEBUG || DEBUG_CONFIGURATION)
Slog.v(TAG, "Skipping new config: curSeq=" + mResConfiguration.seq + ", newSeq=" + config.seq);
return false;
}
int changes = mResConfiguration.updateFrom(config);
// Things might have changed in display manager, so clear the cached displays.
mDisplays.clear();
DisplayMetrics defaultDisplayMetrics = getDisplayMetrics();
if (compat != null && (mResCompatibilityInfo == null || !mResCompatibilityInfo.equals(compat))) {
mResCompatibilityInfo = compat;
changes |= ActivityInfo.CONFIG_SCREEN_LAYOUT | ActivityInfo.CONFIG_SCREEN_SIZE | ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE;
}
Resources.updateSystemConfiguration(config, defaultDisplayMetrics, compat);
ApplicationPackageManager.configurationChanged();
//Slog.i(TAG, "Configuration changed in " + currentPackageName());
Configuration tmpConfig = null;
for (int i = mResourceImpls.size() - 1; i >= 0; i--) {
ResourcesKey key = mResourceImpls.keyAt(i);
WeakReference<ResourcesImpl> weakImplRef = mResourceImpls.valueAt(i);
ResourcesImpl r = weakImplRef != null ? weakImplRef.get() : null;
if (r != null) {
if (DEBUG || DEBUG_CONFIGURATION)
Slog.v(TAG, "Changing resources " + r + " config to: " + config);
int displayId = key.mDisplayId;
boolean isDefaultDisplay = (displayId == Display.DEFAULT_DISPLAY);
DisplayMetrics dm = defaultDisplayMetrics;
final boolean hasOverrideConfiguration = key.hasOverrideConfiguration();
if (!isDefaultDisplay || hasOverrideConfiguration) {
if (tmpConfig == null) {
tmpConfig = new Configuration();
}
tmpConfig.setTo(config);
if (!isDefaultDisplay) {
// Get new DisplayMetrics based on the DisplayAdjustments given
// to the ResourcesImpl. Udate a copy if the CompatibilityInfo
// changed, because the ResourcesImpl object will handle the
// update internally.
DisplayAdjustments daj = r.getDisplayAdjustments();
if (compat != null) {
daj = new DisplayAdjustments(daj);
daj.setCompatibilityInfo(compat);
}
dm = getDisplayMetrics(displayId, daj);
applyNonDefaultDisplayMetricsToConfiguration(dm, tmpConfig);
}
if (hasOverrideConfiguration) {
tmpConfig.updateFrom(key.mOverrideConfiguration);
}
r.updateConfiguration(tmpConfig, dm, compat);
} else {
r.updateConfiguration(config, dm, compat);
}
//Slog.i(TAG, "Updated app resources " + v.getKey()
// + " " + r + ": " + r.getConfiguration());
} else {
//Slog.i(TAG, "Removing old resources " + v.getKey());
mResourceImpls.removeAt(i);
}
}
return changes != 0;
} finally {
Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
}
}
use of android.util.DisplayMetrics in project carat by amplab.
the class Utils method convertDpToPixel.
/**
* This method converts dp unit to equivalent pixels, depending on device
* density. NEEDS UTILS TO BE INITIALIZED BEFORE USAGE.
*
* @param dp A value in dp (density independent pixels) unit. Which we need
* to convert into pixels
* @return A float value to represent px equivalent to dp depending on
* device density
*/
public static float convertDpToPixel(float dp) {
if (mMetrics == null) {
Log.e("MPChartLib-Utils", "Utils NOT INITIALIZED. You need to call Utils.init(...) at least once before calling Utils.convertDpToPixel(...). Otherwise conversion does not take place.");
return dp;
// throw new IllegalStateException(
// "Utils NOT INITIALIZED. You need to call Utils.init(...) at least once before calling Utils.convertDpToPixel(...).");
}
DisplayMetrics metrics = mMetrics;
float px = dp * (metrics.densityDpi / 160f);
return px;
}
Aggregations