Example usage for android.util DisplayMetrics DENSITY_LOW

List of usage examples for android.util DisplayMetrics DENSITY_LOW

Introduction

In this page you can find the example usage for android.util DisplayMetrics DENSITY_LOW.

Prototype

int DENSITY_LOW

To view the source code for android.util DisplayMetrics DENSITY_LOW.

Click Source Link

Document

Standard quantized DPI for low-density screens.

Usage

From source file:org.solovyev.android.calculator.ActivityUi.java

private void addHelpInfo(@Nonnull Activity activity, @Nonnull View root) {
    if (CalculatorApplication.isMonkeyRunner(activity)) {
        if (root instanceof ViewGroup) {
            final TextView helperTextView = new TextView(activity);

            final DisplayMetrics dm = new DisplayMetrics();
            activity.getWindowManager().getDefaultDisplay().getMetrics(dm);

            helperTextView.setTextSize(15);
            helperTextView.setTextColor(Color.WHITE);

            final Configuration c = activity.getResources().getConfiguration();

            final StringBuilder helpText = new StringBuilder();
            helpText.append("Size: ");
            if (Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_XLARGE, c)) {
                helpText.append("xlarge");
            } else if (Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE, c)) {
                helpText.append("large");
            } else if (Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_NORMAL, c)) {
                helpText.append("normal");
            } else if (Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_SMALL, c)) {
                helpText.append("small");
            } else {
                helpText.append("unknown");
            }/*from   w  ww.  j a v a2s  .  c o m*/

            helpText.append(" (").append(dm.widthPixels).append("x").append(dm.heightPixels).append(")");

            helpText.append(" Density: ");
            switch (dm.densityDpi) {
            case DisplayMetrics.DENSITY_LOW:
                helpText.append("ldpi");
                break;
            case DisplayMetrics.DENSITY_MEDIUM:
                helpText.append("mdpi");
                break;
            case DisplayMetrics.DENSITY_HIGH:
                helpText.append("hdpi");
                break;
            case DisplayMetrics.DENSITY_XHIGH:
                helpText.append("xhdpi");
                break;
            case DisplayMetrics.DENSITY_TV:
                helpText.append("tv");
                break;
            }

            helpText.append(" (").append(dm.densityDpi).append(")");

            helperTextView.setText(helpText);

            ((ViewGroup) root).addView(helperTextView, new ViewGroup.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        }
    }
}

From source file:org.altusmetrum.AltosDroid.AltosDroid.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (D)//from  ww  w . ja va 2  s  . c o  m
        Log.e(TAG, "+++ ON CREATE +++");

    // Get local Bluetooth adapter
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    // If the adapter is null, then Bluetooth is not supported
    if (mBluetoothAdapter == null) {
        Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
        finish();
        return;
    }

    // Initialise preferences
    prefs = new AltosDroidPreferences(this);
    AltosPreferences.init(prefs);

    // Set up the window layout
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(R.layout.altosdroid);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);

    // Create the Tabs and ViewPager
    mTabHost = (TabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup();

    mViewPager = (AltosViewPager) findViewById(R.id.pager);
    mViewPager.setOffscreenPageLimit(4);

    mTabsAdapter = new TabsAdapter(this, mTabHost, mViewPager);

    mTabsAdapter.addTab(mTabHost.newTabSpec("pad").setIndicator("Pad"), TabPad.class, null);
    mTabsAdapter.addTab(mTabHost.newTabSpec("ascent").setIndicator("Ascent"), TabAscent.class, null);
    mTabsAdapter.addTab(mTabHost.newTabSpec("descent").setIndicator("Descent"), TabDescent.class, null);
    mTabsAdapter.addTab(mTabHost.newTabSpec("landed").setIndicator("Landed"), TabLanded.class, null);
    mTabsAdapter.addTab(mTabHost.newTabSpec("map").setIndicator("Map"), TabMap.class, null);

    // Scale the size of the Tab bar for different screen densities
    // This probably won't be needed when we start supporting ICS+ tabs.
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int density = metrics.densityDpi;

    if (density == DisplayMetrics.DENSITY_XHIGH)
        tabHeight = 65;
    else if (density == DisplayMetrics.DENSITY_HIGH)
        tabHeight = 45;
    else if (density == DisplayMetrics.DENSITY_MEDIUM)
        tabHeight = 35;
    else if (density == DisplayMetrics.DENSITY_LOW)
        tabHeight = 25;
    else
        tabHeight = 65;

    for (int i = 0; i < 5; i++)
        mTabHost.getTabWidget().getChildAt(i).getLayoutParams().height = tabHeight;

    // Set up the custom title
    mTitle = (TextView) findViewById(R.id.title_left_text);
    mTitle.setText(R.string.app_name);
    mTitle = (TextView) findViewById(R.id.title_right_text);

    // Display the Version
    mVersion = (TextView) findViewById(R.id.version);
    mVersion.setText("Version: " + BuildInfo.version + "  Built: " + BuildInfo.builddate + " "
            + BuildInfo.buildtime + " " + BuildInfo.buildtz + "  (" + BuildInfo.branch + "-"
            + BuildInfo.commitnum + "-" + BuildInfo.commithash + ")");

    mCallsignView = (TextView) findViewById(R.id.callsign_value);
    mRSSIView = (TextView) findViewById(R.id.rssi_value);
    mSerialView = (TextView) findViewById(R.id.serial_value);
    mFlightView = (TextView) findViewById(R.id.flight_value);
    mStateView = (TextView) findViewById(R.id.state_value);
    mAgeView = (TextView) findViewById(R.id.age_value);

    timer.scheduleAtFixedRate(new TimerTask() {
        public void run() {
            onTimerTick();
        }
    }, 1000L, 100L);

    mAltosVoice = new AltosVoice(this);
}

From source file:uni.oulu.mentor.TeacherVisionActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //DO NOT USE THIS SERVICE YET, DOES NOT WORK
    //Intent intent = new Intent(this, TeacherVisionService.class);
    //startService(intent);
    /*Idea from http://stackoverflow.com/questions/2902640/android-get-the-screen-resolution-pixels-as-integer-values */
    @SuppressWarnings("deprecation")
    int screenWidthPix = getWindowManager().getDefaultDisplay().getWidth();
    @SuppressWarnings("deprecation")
    int screenHeightPix = getWindowManager().getDefaultDisplay().getHeight();
    /*Idea from http://stackoverflow.com/questions/5015094/determine-device-screen-category-small-normal-large-xlarge-using-code*/
    if ((getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE)
        screenType = 3;/*from   w w w . j a v  a 2s .c o  m*/
    else if ((getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE)
        screenType = 4;
    else if ((getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL)
        screenType = 1;
    else if ((getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL)
        screenType = 2;
    //screen density is investigated here
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int density = metrics.densityDpi;
    if (density == DisplayMetrics.DENSITY_HIGH) {
        //400 dpi is 600px
        if (screenType == 1)
            translationX = 240; //240 / 1.5 = 160
        else if (screenType == 2)
            translationX = 315; //315 / 1.5 = 210 in dpi, screen 800 pix wide screen, needs about 1024/400 = 800/x => 312,5, 2.56
        else if (screenType == 3)
            translationX = 540; //540 / 1.5 = 360 in dpi
        else if (screenType == 4)
            translationX = 600; //600 / 1.5 = 400 in dpi   
    } else if (density == DisplayMetrics.DENSITY_MEDIUM) {
        //400 dpi is 400px
        if (screenType == 1)
            translationX = 160; //160 / 1 = 160 in dpi
        else if (screenType == 2)
            translationX = 210; //210 / 1 = 210 in dpi
        else if (screenType == 3)
            translationX = 360; //360 / 1 = 360 in dpi
        else if (screenType == 4)
            translationX = 400; //400 / 1 = 400 in dpi
    } else if (density == DisplayMetrics.DENSITY_LOW) {
        //400 dpi is 300px
        if (screenType == 1)
            translationX = 120; //120 / 0.75 = 160 in dpi
        else if (screenType == 2)
            translationX = 158; //158 / 0.75 = 210 in dpi
        else if (screenType == 3)
            translationX = 270; //270 / 0.75 = 360 in dpi
        else if (screenType == 4)
            translationX = 300; //300 / 0.75 = 400 in dpi
    } else if (density == DisplayMetrics.DENSITY_XHIGH || density == DisplayMetrics.DENSITY_XXHIGH) {
        //400 dpi is 800px
        if (screenType == 1)
            translationX = 320; //320 / 2 = 160 in dpi
        else if (screenType == 2)
            translationX = 420; // 420 / 2 = 210 in dpi
        else if (screenType == 3)
            translationX = 720; // 720 / 2 = 360 in dpi
        else if (screenType == 4)
            translationX = 800; // 800 / 2 = 400 in dpi         
    } else {
        //not supported
    }
    int offsetX = ((int) screenWidthPix / 20);
    int offsetY = ((int) screenHeightPix / 10);
    maxPosOpenX = screenWidthPix;
    //boundary for minimum amount of width on x-axis, where the touch is seen as panel open touch
    minPosOpenX = screenWidthPix - offsetX;
    //boundary for maximum amount of width on x-axis, where the touch is seen as panel close touch
    maxPosCloseX = screenWidthPix - translationX + offsetX;
    //boundary for minimum amount of width on x-axis, where the touch is seen as panel close touch
    minPosCloseX = screenWidthPix - translationX - offsetX;
    //boundary for maximum amount of height on y-axis, where the touch is seen as panel open or close touch
    maxPosY = (screenHeightPix / 2) + offsetY;
    //boundary for minimum amount of height on y-axis, where the touch is seen as panel open or close touch
    minPosY = (screenHeightPix / 2) - offsetY;
    //instantiation of lists
    onlineStudentsList = new ArrayList<Student>();
    feedbacksList = new ArrayList<Feedback>();
    questionsList = new ArrayList<Question>();
    answersList = new ArrayList<Answer>();
    ownQuestionsList = new ArrayList<Question>();
    //data stored for this user is fetched here, from the previous activity, and stored into the teacher instance
    Intent intent2 = getIntent();
    teacher = (Teacher) intent2.getParcelableExtra("teacherObj");
    ipStr = getResources().getString(R.string.IP);
    usersUrl = "http://" + ipStr + "/mentor/users";
    coursesUrl = "http://" + ipStr + "/mentor/courses";
    //default preferences are fetched, and listener is set to listen for preference changes
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    sp.registerOnSharedPreferenceChangeListener(this);
    //SharedPreferences.Editor editor = sp.edit();
    //editor.putString("flaretimePref", "5");
    //editor.clear();
    //editor.commit();
    // In case of notifications are added later
    /*String ns = Context.NOTIFICATION_SERVICE;
    mNotificationManager = (NotificationManager) getSystemService(ns);
    icon = R.drawable.mlogo2;*/
    //AndAR preview
    renderer = new CustomRenderer();//optional, may be set to null
    super.setNonARRenderer(renderer);//or might be omitted
    try {
        //register an object for each marker type
        artoolkit = super.getArtoolkit();
        oneObject = new CustomObject("onePatt", "onePatt.patt", 80.0, new double[] { 0, 0 }); //name, pattern, markerWidth, markerCenter, customColor
        twoObject = new CustomObject("twoPatt", "twoPatt.patt", 80.0, new double[] { 0, 0 }); //name, pattern, markerWidth, markerCenter
        threeObject = new CustomObject("threePatt", "threePatt.patt", 80.0, new double[] { 0, 0 }); //name, pattern, markerWidth, markerCenter
        artoolkit.registerARObject(oneObject);
        artoolkit.registerARObject(twoObject);
        artoolkit.registerARObject(threeObject);
    } catch (AndARException ex) {
        Log.e("AndARException ", ex.getMessage());
    }
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View vv = inflater.inflate(R.layout.activity_teacher_vision, null);
    //screen width and height in pixels
    screenWidth = (float) this.getApplicationContext().getResources().getDisplayMetrics().widthPixels;
    screenHeight = (float) this.getApplicationContext().getResources().getDisplayMetrics().heightPixels;
    inflater.inflate(R.layout.fragment_teacher_vision, null);
    //UI elements are added on top of AndAR by calling this addContentView-method instead of setContentView
    super.addContentView(vv, (new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)));
    //create a layout for settings button. add it over video frames
    LinearLayout lil = new LinearLayout(this);
    Button settingsButton = new Button(this);
    settingsButton.setText("Settings");
    settingsButton.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    settingsButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            getFragmentManager().beginTransaction().replace(android.R.id.content, new PrefsFragment())
                    .addToBackStack("settings").commit();
        }
    });
    lil.addView(settingsButton);
    super.addContentView(lil, (new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)));
    //starts the AndAR
    startPreview();
    //mDetector is instantiated here for detecting gestures
    mDetector = new GestureDetectorCompat(this, new SwipeGestureListener());
    //view pager instantiation, also mAdapter instantiated and set as adapter for view pager
    mPager = (ViewPager) findViewById(R.id.pager);
    mAdapter = new TabAdapter(getFragmentManager(), mPager);
    mPager.setAdapter(mAdapter);
    //begin to poll online users
    pollUsersCancelled = false;
    pollUsersTask = new PollUsersTask(this);
    pollUsersTask.execute();
    //begin to poll feedbacks
    pollFeedbacksCancelled = false;
    pollFeedbacksTask = new PollFeedbacksTask(this);
    pollFeedbacksTask.execute();
    //begin to poll questions
    pollQuestionsCancelled = false;
    pollQuestionsTask = new PollQuestionsTask(this);
    pollQuestionsTask.execute();
    //begin to poll answers
    pollAnswersCancelled = false;
    pollAnswersTask = new PollAnswersTask(this);
    pollAnswersTask.execute();
    //initialize tab buttons
    button = (Button) findViewById(R.id.goto_first);
    //first one is not enabled at the beginning, because the user is in first tab at first 
    button.setEnabled(false);
    button2 = (Button) findViewById(R.id.goto_second);
    button3 = (Button) findViewById(R.id.goto_last);
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            mPager.setCurrentItem(0);
            button.setEnabled(false);
            button2.setEnabled(true);
            button3.setEnabled(true);
        }
    });
    button2.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            mPager.setCurrentItem(1);
            button.setEnabled(true);
            button2.setEnabled(false);
            button3.setEnabled(true);
        }
    });
    button3.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            mPager.setCurrentItem(2);
            button.setEnabled(true);
            button2.setEnabled(true);
            button3.setEnabled(false);
        }
    });
}

From source file:com.linkbubble.util.Util.java

private static int getAlertIconDensityDpi(Context context) {
    if (sDensityDpi == null) {
        sDensityDpi = context.getResources().getDisplayMetrics().densityDpi;
    }/*  www .  j  a  va  2s . c  om*/

    switch (sDensityDpi) {
    case DisplayMetrics.DENSITY_LOW:
    case DisplayMetrics.DENSITY_MEDIUM:
        return DisplayMetrics.DENSITY_LOW;
    case DisplayMetrics.DENSITY_TV:
    case DisplayMetrics.DENSITY_HIGH:
        return DisplayMetrics.DENSITY_MEDIUM;
    case DisplayMetrics.DENSITY_XHIGH:
        return DisplayMetrics.DENSITY_HIGH;
    case DisplayMetrics.DENSITY_XXHIGH:
    case DisplayMetrics.DENSITY_XXXHIGH:
        return DisplayMetrics.DENSITY_XHIGH;
    }

    return sDensityDpi;
}

From source file:com.mobicage.rogerthat.MainService.java

public int getScreenScale() {
    // Based on UIScreen.scale on iOS
    if (mScreenScale == null) {
        switch (getResources().getDisplayMetrics().densityDpi) {
        case DisplayMetrics.DENSITY_LOW:
            mScreenScale = 1;// w  w  w .j av a  2 s .c o m
            break;
        case DisplayMetrics.DENSITY_MEDIUM:
            mScreenScale = 2;
            break;
        case DisplayMetrics.DENSITY_HIGH:
            mScreenScale = 3;
            break;
        default:
            mScreenScale = 2;
            break;
        }
    }

    return mScreenScale;
}

From source file:org.zywx.wbpalmstar.engine.universalex.EUExWindow.java

public void openAdMsg(String[] parm) {
    EBrowserWindow curWind = mBrwView.getBrowserWindow();
    if (null == curWind) {
        return;/*from   w  ww.ja  va  2s  .  c  om*/
    }
    WWidgetData wd = mBrwView.getCurrentWidget();
    boolean b1 = mBrwView.checkType(EBrwViewEntry.VIEW_TYPE_MAIN);
    boolean b2 = 0 == wd.m_widgetAdStatus;
    boolean b3 = parm.length < 4;
    if (!b1 || b2 || b3) {
        // 0 means do not show ad
        return;
    }
    String inType = parm[0];
    String inDTime = parm[1];
    String inInterval = parm[2];
    String inFlag = parm[3];
    int type = 0, flag = 0, dtime = 0, interval = 0, w = RelativeLayout.LayoutParams.FILL_PARENT, h = 50;
    MessageDigest md = null;
    int density = ESystemInfo.getIntence().mDensityDpi;
    switch (density) {
    case DisplayMetrics.DENSITY_LOW:
        h = 40;
        break;
    case DisplayMetrics.DENSITY_MEDIUM:
        h = 50;
        break;
    case DisplayMetrics.DENSITY_HIGH:
        h = 60;
        break;
    case 320: // DisplayMetrics.DENSITY_XHIGH from 2.3.3
        h = 70;
        break;
    }
    try {
        if (null != inType && inType.length() != 0) {
            type = Integer.parseInt(inType);
        }

        if (null != inDTime && inDTime.length() != 0) {
            dtime = Integer.parseInt(inDTime);
        }

        if (null != inInterval && inInterval.length() != 0) {
            interval = Integer.parseInt(inInterval);
        }

        if (null != inFlag && inFlag.length() != 0) {
            flag = Integer.parseInt(inFlag);
        }
        md = MessageDigest.getInstance("MD5");
    } catch (Exception e) {
        errorCallback(0, EUExCallback.F_E_UEXWINDOW_EVAL, "Illegal parameter");
        return;
    }
    StringBuffer sb = new StringBuffer(m_AdUrl);
    sb.append("?appid=");
    sb.append(wd.m_appId);
    sb.append("&pt=1");
    sb.append("&dw=");
    sb.append(ESystemInfo.getIntence().mWidthPixels);
    sb.append("&dh=");
    sb.append(ESystemInfo.getIntence().mHeightPixels);
    sb.append("&md5=");
    if (null == md) {
        return;
    }
    String jid = wd.m_appId + "BD7463CD-D608-BEB4-C633-EF3574213060";
    md.reset();
    md.update(jid.getBytes());
    byte[] md5Bytes = md.digest();
    StringBuffer hexValue = new StringBuffer();
    for (int i = 0; i < md5Bytes.length; i++) {
        int val = ((int) md5Bytes[i]) & 0xff;
        if (val < 16)
            hexValue.append("0");
        hexValue.append(Integer.toHexString(val));
    }
    sb.append(hexValue);
    sb.append("&type=");
    if (type == 1) {
        sb.append(1);
        h = w;
    } else {
        sb.append(0);
    }
    String url = sb.toString();
    curWind.openAd(type, url, dtime * 1000, h, w, interval * 1000, flag);
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Returns the device resolution type./*from  w ww  . ja v  a  2  s.  co m*/
 * 
 * @param context
 * @return   {@link es.javocsoft.android.lib.toolbox.ToolBox.DEVICE_RESOLUTION_TYPE}
 */
public static DEVICE_RESOLUTION_TYPE device_getResolutionType(Context context) {
    DEVICE_RESOLUTION_TYPE res = null;

    DisplayMetrics metrics = new DisplayMetrics();
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    windowManager.getDefaultDisplay().getMetrics(metrics);

    switch (metrics.densityDpi) {
    case DisplayMetrics.DENSITY_LOW:
        res = DEVICE_RESOLUTION_TYPE.ldpi;
        break;
    case DisplayMetrics.DENSITY_MEDIUM:
        res = DEVICE_RESOLUTION_TYPE.mdpi;
        break;
    case DisplayMetrics.DENSITY_HIGH:
        res = DEVICE_RESOLUTION_TYPE.hdpi;
        break;
    case DisplayMetrics.DENSITY_XHIGH:
        res = DEVICE_RESOLUTION_TYPE.xhdpi;
        break;
    case DisplayMetrics.DENSITY_XXHIGH:
        res = DEVICE_RESOLUTION_TYPE.xxhdpi;
        break;
    }

    return res;
}