use of android.util.DisplayMetrics in project facebook-android-sdk by facebook.
the class Utility method setAppEventExtendedDeviceInfoParameters.
public static void setAppEventExtendedDeviceInfoParameters(JSONObject params, Context appContext) throws JSONException {
JSONArray extraInfoArray = new JSONArray();
extraInfoArray.put(EXTRA_APP_EVENTS_INFO_FORMAT_VERSION);
Utility.refreshPeriodicExtendedDeviceInfo(appContext);
// Application Manifest info:
String pkgName = appContext.getPackageName();
int versionCode = -1;
String versionName = "";
try {
PackageInfo pi = appContext.getPackageManager().getPackageInfo(pkgName, 0);
versionCode = pi.versionCode;
versionName = pi.versionName;
} catch (PackageManager.NameNotFoundException e) {
// Swallow
}
// Application Manifest info:
extraInfoArray.put(pkgName);
extraInfoArray.put(versionCode);
extraInfoArray.put(versionName);
// OS/Device info
extraInfoArray.put(Build.VERSION.RELEASE);
extraInfoArray.put(Build.MODEL);
// Locale
Locale locale;
try {
locale = appContext.getResources().getConfiguration().locale;
} catch (Exception e) {
locale = Locale.getDefault();
}
extraInfoArray.put(locale.getLanguage() + "_" + locale.getCountry());
// Time zone
extraInfoArray.put(deviceTimezoneAbbreviation);
// Carrier
extraInfoArray.put(carrierName);
// Screen dimensions
int width = 0;
int height = 0;
double density = 0;
try {
WindowManager wm = (WindowManager) appContext.getSystemService(Context.WINDOW_SERVICE);
if (wm != null) {
Display display = wm.getDefaultDisplay();
DisplayMetrics displayMetrics = new DisplayMetrics();
display.getMetrics(displayMetrics);
width = displayMetrics.widthPixels;
height = displayMetrics.heightPixels;
density = displayMetrics.density;
}
} catch (Exception e) {
// Swallow
}
extraInfoArray.put(width);
extraInfoArray.put(height);
extraInfoArray.put(String.format("%.2f", density));
// CPU Cores
extraInfoArray.put(refreshBestGuessNumberOfCPUCores());
// External Storage
extraInfoArray.put(totalExternalStorageGB);
extraInfoArray.put(availableExternalStorageGB);
extraInfoArray.put(deviceTimeZoneName);
params.put("extinfo", extraInfoArray.toString());
}
use of android.util.DisplayMetrics in project fresco by facebook.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mBitmapFactory = Fresco.getImagePipelineFactory().getPlatformBitmapFactory();
mOriginalBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.test_image);
mOriginalHeight = mOriginalBitmap.getHeight();
mOriginalWidth = mOriginalBitmap.getWidth();
// To set the size of the original image to the screen width
DisplayMetrics metrics = getResources().getDisplayMetrics();
mConversionFactor = metrics.widthPixels / (1.0f * mOriginalWidth);
setupViews();
loadBasicBitmap();
}
use of android.util.DisplayMetrics in project fresco by facebook.
the class SizeUtil method initSizeData.
/**
* Invoke one into the Activity to get info about the Display size
* @param activity The Activity
*/
public static void initSizeData(Activity activity) {
DisplayMetrics metrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
DISPLAY_WIDTH = metrics.widthPixels;
DISPLAY_HEIGHT = metrics.heightPixels;
}
use of android.util.DisplayMetrics in project cardslib by gabrielemariotti.
the class CustomThumbCard method setupInnerViewElements.
@Override
public void setupInnerViewElements(ViewGroup parent, View viewImage) {
if (viewImage != null) {
if (parent != null && parent.getResources() != null) {
DisplayMetrics metrics = parent.getResources().getDisplayMetrics();
int base = 125;
if (metrics != null) {
viewImage.getLayoutParams().width = (int) (base * metrics.density);
viewImage.getLayoutParams().height = (int) (base * metrics.density);
} else {
viewImage.getLayoutParams().width = 250;
viewImage.getLayoutParams().height = 250;
}
}
}
}
use of android.util.DisplayMetrics in project FBReaderJ by geometer.
the class EditBookmarkActivity method onCreate.
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.edit_bookmark);
myBookmark = FBReaderIntents.getBookmarkExtra(getIntent());
if (myBookmark == null) {
finish();
return;
}
final DisplayMetrics dm = getResources().getDisplayMetrics();
final int width = Math.min((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 500, dm), dm.widthPixels * 9 / 10);
final int height = Math.min((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 350, dm), dm.heightPixels * 9 / 10);
final TabHost tabHost = (TabHost) findViewById(R.id.edit_bookmark_tabhost);
tabHost.setLayoutParams(new FrameLayout.LayoutParams(new ViewGroup.LayoutParams(width, height)));
tabHost.setup();
addTab(tabHost, "text", R.id.edit_bookmark_content_text);
addTab(tabHost, "style", R.id.edit_bookmark_content_style);
addTab(tabHost, "delete", R.id.edit_bookmark_content_delete);
final ZLStringOption currentTabOption = new ZLStringOption("LookNFeel", "EditBookmark", "text");
tabHost.setCurrentTabByTag(currentTabOption.getValue());
tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
public void onTabChanged(String tag) {
if (!"delete".equals(tag)) {
currentTabOption.setValue(tag);
}
}
});
final EditText editor = (EditText) findViewById(R.id.edit_bookmark_text);
editor.setText(myBookmark.getText());
final int len = editor.getText().length();
editor.setSelection(len, len);
final Button saveTextButton = (Button) findViewById(R.id.edit_bookmark_save_text_button);
saveTextButton.setEnabled(false);
saveTextButton.setText(myResource.getResource("saveText").getValue());
saveTextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
myCollection.bindToService(EditBookmarkActivity.this, new Runnable() {
public void run() {
myBookmark.setText(editor.getText().toString());
myCollection.saveBookmark(myBookmark);
saveTextButton.setEnabled(false);
}
});
}
});
editor.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence sequence, int start, int before, int count) {
final String originalText = myBookmark.getText();
saveTextButton.setEnabled(!originalText.equals(editor.getText().toString()));
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
final Button deleteButton = (Button) findViewById(R.id.edit_bookmark_delete_button);
deleteButton.setText(myResource.getResource("deleteBookmark").getValue());
deleteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
myCollection.bindToService(EditBookmarkActivity.this, new Runnable() {
public void run() {
myCollection.deleteBookmark(myBookmark);
finish();
}
});
}
});
}
Aggregations