Search in sources :

Example 46 with DisplayMetrics

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());
}
Also used : Locale(java.util.Locale) PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo) JSONArray(org.json.JSONArray) DisplayMetrics(android.util.DisplayMetrics) JSONException(org.json.JSONException) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) FacebookException(com.facebook.FacebookException) IOException(java.io.IOException) WindowManager(android.view.WindowManager) Display(android.view.Display)

Example 47 with DisplayMetrics

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();
}
Also used : DisplayMetrics(android.util.DisplayMetrics)

Example 48 with DisplayMetrics

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;
}
Also used : DisplayMetrics(android.util.DisplayMetrics)

Example 49 with DisplayMetrics

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;
            }
        }
    }
}
Also used : DisplayMetrics(android.util.DisplayMetrics)

Example 50 with DisplayMetrics

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();
                }
            });
        }
    });
}
Also used : ZLStringOption(org.geometerplus.zlibrary.core.options.ZLStringOption) DisplayMetrics(android.util.DisplayMetrics) AmbilWarnaPrefWidgetView(yuku.ambilwarna.widget.AmbilWarnaPrefWidgetView) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable)

Aggregations

DisplayMetrics (android.util.DisplayMetrics)772 WindowManager (android.view.WindowManager)107 Resources (android.content.res.Resources)99 Display (android.view.Display)78 Configuration (android.content.res.Configuration)61 Point (android.graphics.Point)57 View (android.view.View)52 SuppressLint (android.annotation.SuppressLint)47 Bitmap (android.graphics.Bitmap)42 Paint (android.graphics.Paint)42 Activity (android.app.Activity)32 ImageView (android.widget.ImageView)27 AssetManager (android.content.res.AssetManager)25 TypedArray (android.content.res.TypedArray)25 Context (android.content.Context)23 TypedValue (android.util.TypedValue)23 ViewGroup (android.view.ViewGroup)23 TextView (android.widget.TextView)22 Intent (android.content.Intent)21 RelativeLayout (android.widget.RelativeLayout)20