Example usage for android.util DisplayMetrics DENSITY_HIGH

List of usage examples for android.util DisplayMetrics DENSITY_HIGH

Introduction

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

Prototype

int DENSITY_HIGH

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

Click Source Link

Document

Standard quantized DPI for high-density screens.

Usage

From source file:watch.oms.omswatch.application.OMSApplication.java

/**
 * Checks if the device is a tablet or a phone
 * /* w w w . ja  va2  s . c  o  m*/
 * @param
 *
 * @return Returns true if the device is a Tablet
 */
public boolean isTabletDevice() {
    // Verifies if the Generalized Size of the device is XLARGE to be
    // considered a Tablet
    boolean xlarge = ((activity.getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE);

    // If XLarge, checks if the Generalized Density is at least MDPI
    // (160dpi)
    if (xlarge) {
        DisplayMetrics metrics = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

        // MDPI=160, DEFAULT=160, DENSITY_HIGH=240, DENSITY_MEDIUM=160,
        // DENSITY_TV=213, DENSITY_XHIGH=320
        if (metrics.densityDpi == DisplayMetrics.DENSITY_DEFAULT
                || metrics.densityDpi == DisplayMetrics.DENSITY_HIGH
                || metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM
                || metrics.densityDpi == DisplayMetrics.DENSITY_TV
                || metrics.densityDpi == DisplayMetrics.DENSITY_XHIGH) {

            // Yes, this is a tablet!
            return true;
        }
    }
    return false;
}

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");
            }// w w w  .j a  v a 2s. com

            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 w ww  .  ja  v a 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;/*w ww. ja v  a  2s .c  om*/
    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.cypress.cysmart.BLEServiceFragments.HealthTemperatureService.java

/**
 * Setting up the aChart Third party library
 * @param parent//  ww  w  .j ava2  s.c  o m
 */
private void setupChart(View parent) {
    /**
     * Setting graph titles
     */
    String graphTitle = getResources().getString(R.string.health_temperature_graph);
    String graphXAxis = getResources().getString(R.string.health_temperature_time);
    String graphYAxis = getResources().getString(R.string.health_temperature_temperature);

    // Creating an  XYSeries for temperature
    mTempEratureDataSeries = new XYSeries(graphTitle);

    // Creating a dataset to hold each series
    XYMultipleSeriesDataset mDataset = new XYMultipleSeriesDataset();

    // Adding temperature Series to the dataset
    mDataset.addSeries(mTempEratureDataSeries);

    // Creating XYSeriesRenderer to customize
    XYSeriesRenderer mRenderer = new XYSeriesRenderer();
    mRenderer.setColor(getResources().getColor(R.color.main_bg_color));
    mRenderer.setPointStyle(PointStyle.CIRCLE);
    mRenderer.setFillPoints(true);
    mRenderer.setLineWidth(5);

    int deviceDPi = getResources().getDisplayMetrics().densityDpi;
    switch (getResources().getDisplayMetrics().densityDpi) {
    case DisplayMetrics.DENSITY_XHIGH:
        mMultiRenderer.setMargins(new int[] { 40, 90, 25, 10 });
        mMultiRenderer.setAxisTitleTextSize(Constants.TEXT_SIZE_XHDPI);
        mMultiRenderer.setChartTitleTextSize(Constants.TEXT_SIZE_XHDPI);
        mMultiRenderer.setLabelsTextSize(Constants.TEXT_SIZE_XHDPI);
        mMultiRenderer.setLegendTextSize(Constants.TEXT_SIZE_XHDPI);
        break;
    case DisplayMetrics.DENSITY_HIGH:
        mMultiRenderer.setMargins(new int[] { 30, 50, 25, 10 });
        mMultiRenderer.setAxisTitleTextSize(Constants.TEXT_SIZE_HDPI);
        mMultiRenderer.setChartTitleTextSize(Constants.TEXT_SIZE_HDPI);
        mMultiRenderer.setLabelsTextSize(Constants.TEXT_SIZE_HDPI);
        mMultiRenderer.setLegendTextSize(Constants.TEXT_SIZE_HDPI);
        break;
    case DisplayMetrics.DENSITY_XXHIGH:
        mMultiRenderer.setMargins(new int[] { 50, 100, 35, 20 });
        mMultiRenderer.setAxisTitleTextSize(Constants.TEXT_SIZE_XXHDPI);
        mMultiRenderer.setChartTitleTextSize(Constants.TEXT_SIZE_XXHDPI);
        mMultiRenderer.setLabelsTextSize(Constants.TEXT_SIZE_XXHDPI);
        mMultiRenderer.setLegendTextSize(Constants.TEXT_SIZE_XXHDPI);
        break;

    default:
        if (deviceDPi > DisplayMetrics.DENSITY_XXHIGH && deviceDPi < DisplayMetrics.DENSITY_XXXHIGH) {
            mMultiRenderer.setMargins(new int[] { 50, 100, 35, 20 });
            mMultiRenderer.setAxisTitleTextSize(Constants.TEXT_SIZE_XXHDPI);
            mMultiRenderer.setChartTitleTextSize(Constants.TEXT_SIZE_XXHDPI);
            mMultiRenderer.setLabelsTextSize(Constants.TEXT_SIZE_XXHDPI);
            mMultiRenderer.setLegendTextSize(Constants.TEXT_SIZE_XXHDPI);
        } else {
            mMultiRenderer.setMargins(new int[] { 30, 50, 25, 10 });
            mMultiRenderer.setAxisTitleTextSize(Constants.TEXT_SIZE_LDPI);
            mMultiRenderer.setChartTitleTextSize(Constants.TEXT_SIZE_LDPI);
            mMultiRenderer.setLabelsTextSize(Constants.TEXT_SIZE_LDPI);
            mMultiRenderer.setLegendTextSize(Constants.TEXT_SIZE_LDPI);
        }
        break;
    }
    mMultiRenderer.setXTitle(graphXAxis);
    mMultiRenderer.setLabelsColor(Color.BLACK);
    mMultiRenderer.setYTitle(graphYAxis);
    mMultiRenderer.setMarginsColor(Color.argb(0x00, 0xff, 0x00, 0x00));
    mMultiRenderer.setPanEnabled(true, true);
    mMultiRenderer.setYLabelsColor(0, Color.BLACK);
    mMultiRenderer.setXLabelsColor(Color.BLACK);
    mMultiRenderer.setApplyBackgroundColor(true);
    mMultiRenderer.setBackgroundColor(Color.WHITE);
    mMultiRenderer.setGridColor(Color.BLACK);
    mMultiRenderer.setShowGrid(true);
    mMultiRenderer.setShowLegend(false);

    // Adding mRenderer to multipleRenderer
    mMultiRenderer.addSeriesRenderer(mRenderer);

    // Getting a reference to LinearLayout of the MainActivity Layout
    mGraphLayoutParent = (LinearLayout) parent.findViewById(R.id.chart_container);

    mChart = ChartFactory.getLineChartView(getActivity(), mDataset, mMultiRenderer);

    // Adding the Line Chart to the LinearLayout
    mGraphLayoutParent.addView(mChart);

}

From source file:com.cypress.cysmart.BLEServiceFragments.HeartRateService.java

/**
 * Setting up the aChart Third party library
 * @param parent//from ww w .  j a  v a2 s . c o m
 */
private void setupChart(View parent) {
    /**
     * Setting graph titles
     */
    String graphTitle = getResources().getString(R.string.hrm_graph_label);
    String graphXAxis = getResources().getString(R.string.health_temperature_time);
    String graphYAxis = getResources().getString(R.string.hrm_graph_label);

    // Creating an  XYSeries for temperature
    mDataSeries = new XYSeries(graphTitle);

    // Creating a dataset to hold each series
    XYMultipleSeriesDataset mDataset = new XYMultipleSeriesDataset();

    // Adding temperature Series to the dataset
    mDataset.addSeries(mDataSeries);

    // Creating XYSeriesRenderer to customize
    XYSeriesRenderer mRenderer = new XYSeriesRenderer();
    mRenderer.setColor(getResources().getColor(R.color.main_bg_color));
    mRenderer.setPointStyle(PointStyle.CIRCLE);
    mRenderer.setFillPoints(true);
    mRenderer.setLineWidth(3);

    // Creating a XYMultipleSeriesRenderer to customize the whole chart
    XYMultipleSeriesRenderer mMultiRenderer = new XYMultipleSeriesRenderer();
    int deviceDPi = getResources().getDisplayMetrics().densityDpi;
    switch (deviceDPi) {
    case DisplayMetrics.DENSITY_XHIGH:
        mMultiRenderer.setMargins(new int[] { 40, 90, 25, 10 });
        mMultiRenderer.setAxisTitleTextSize(Constants.TEXT_SIZE_XHDPI);
        mMultiRenderer.setChartTitleTextSize(Constants.TEXT_SIZE_XHDPI);
        mMultiRenderer.setLabelsTextSize(Constants.TEXT_SIZE_XHDPI);
        mMultiRenderer.setLegendTextSize(Constants.TEXT_SIZE_XHDPI);
        break;
    case DisplayMetrics.DENSITY_HIGH:
        mMultiRenderer.setMargins(new int[] { 30, 50, 25, 10 });
        mMultiRenderer.setAxisTitleTextSize(Constants.TEXT_SIZE_HDPI);
        mMultiRenderer.setChartTitleTextSize(Constants.TEXT_SIZE_HDPI);
        mMultiRenderer.setLabelsTextSize(Constants.TEXT_SIZE_HDPI);
        mMultiRenderer.setLegendTextSize(Constants.TEXT_SIZE_HDPI);
        break;
    case DisplayMetrics.DENSITY_XXHIGH:
        mMultiRenderer.setMargins(new int[] { 50, 100, 35, 20 });
        mMultiRenderer.setAxisTitleTextSize(Constants.TEXT_SIZE_XXHDPI);
        mMultiRenderer.setChartTitleTextSize(Constants.TEXT_SIZE_XXHDPI);
        mMultiRenderer.setLabelsTextSize(Constants.TEXT_SIZE_XXHDPI);
        mMultiRenderer.setLegendTextSize(Constants.TEXT_SIZE_XXHDPI);
        break;
    default:
        if (deviceDPi > DisplayMetrics.DENSITY_XXHIGH && deviceDPi < DisplayMetrics.DENSITY_XXXHIGH) {
            mMultiRenderer.setMargins(new int[] { 50, 100, 35, 20 });
            mMultiRenderer.setAxisTitleTextSize(Constants.TEXT_SIZE_XXHDPI);
            mMultiRenderer.setChartTitleTextSize(Constants.TEXT_SIZE_XXHDPI);
            mMultiRenderer.setLabelsTextSize(Constants.TEXT_SIZE_XXHDPI);
            mMultiRenderer.setLegendTextSize(Constants.TEXT_SIZE_XXHDPI);
        } else {
            mMultiRenderer.setMargins(new int[] { 30, 50, 25, 10 });
            mMultiRenderer.setAxisTitleTextSize(Constants.TEXT_SIZE_LDPI);
            mMultiRenderer.setChartTitleTextSize(Constants.TEXT_SIZE_LDPI);
            mMultiRenderer.setLabelsTextSize(Constants.TEXT_SIZE_LDPI);
            mMultiRenderer.setLegendTextSize(Constants.TEXT_SIZE_LDPI);
        }
        break;
    }
    mMultiRenderer.setXTitle(graphXAxis);
    mMultiRenderer.setLabelsColor(Color.BLACK);
    mMultiRenderer.setYTitle(graphYAxis);
    mMultiRenderer.setMarginsColor(Color.argb(0x00, 0xff, 0x00, 0x00));
    mMultiRenderer.setPanEnabled(true, true);
    mMultiRenderer.setYLabelsColor(0, Color.BLACK);
    mMultiRenderer.setXLabelsColor(Color.BLACK);
    mMultiRenderer.setApplyBackgroundColor(true);
    mMultiRenderer.setBackgroundColor(Color.WHITE);
    mMultiRenderer.setGridColor(Color.BLACK);
    mMultiRenderer.setShowGrid(true);
    mMultiRenderer.setShowLegend(false);

    // Adding mRenderer to multipleRenderer
    mMultiRenderer.addSeriesRenderer(mRenderer);

    // Getting a reference to LinearLayout of the MainActivity Layout
    mGraphLayoutParent = (LinearLayout) parent.findViewById(R.id.chart_container);

    mChart = ChartFactory.getLineChartView(getActivity(), mDataset, mMultiRenderer);

    // Adding the Line Chart to the LinearLayout
    mGraphLayoutParent.addView(mChart);

}

From source file:com.cypress.cysmart.BLEServiceFragments.CSCService.java

/**
 * Setting up the aChart Third party library
 *
 * @param parent// w  w  w . j  a v a  2s. c om
 */
private void setupChart(View parent) {
    /**
     * Setting graph titles
     */
    String graphTitle = getResources().getString(R.string.csc_fragment);
    String graphXAxis = getResources().getString(R.string.health_temperature_time);
    String graphYAxis = getResources().getString(R.string.csc_cadence_graph);

    // Creating an  XYSeries for running speed
    mDataSeries = new XYSeries(graphTitle);

    // Creating a dataset to hold each series
    XYMultipleSeriesDataset mDataset = new XYMultipleSeriesDataset();

    // Adding temperature Series to the dataset
    mDataset.addSeries(mDataSeries);

    // Creating XYSeriesRenderer to customize
    XYSeriesRenderer mRenderer = new XYSeriesRenderer();
    mRenderer.setColor(getResources().getColor(R.color.main_bg_color));
    mRenderer.setPointStyle(PointStyle.CIRCLE);
    mRenderer.setFillPoints(true);
    mRenderer.setLineWidth(5);

    // Creating a XYMultipleSeriesRenderer to customize the whole chart
    XYMultipleSeriesRenderer mMultiRenderer = new XYMultipleSeriesRenderer();
    int deviceDPi = getResources().getDisplayMetrics().densityDpi;
    switch (getResources().getDisplayMetrics().densityDpi) {
    case DisplayMetrics.DENSITY_XHIGH:
        mMultiRenderer.setMargins(new int[] { 40, 90, 25, 10 });
        mMultiRenderer.setAxisTitleTextSize(Constants.TEXT_SIZE_XHDPI);
        mMultiRenderer.setChartTitleTextSize(Constants.TEXT_SIZE_XHDPI);
        mMultiRenderer.setLabelsTextSize(Constants.TEXT_SIZE_XHDPI);
        mMultiRenderer.setLegendTextSize(Constants.TEXT_SIZE_XHDPI);
        break;
    case DisplayMetrics.DENSITY_HIGH:
        mMultiRenderer.setMargins(new int[] { 30, 50, 25, 10 });
        mMultiRenderer.setAxisTitleTextSize(Constants.TEXT_SIZE_HDPI);
        mMultiRenderer.setChartTitleTextSize(Constants.TEXT_SIZE_HDPI);
        mMultiRenderer.setLabelsTextSize(Constants.TEXT_SIZE_HDPI);
        mMultiRenderer.setLegendTextSize(Constants.TEXT_SIZE_HDPI);
        break;
    case DisplayMetrics.DENSITY_XXHIGH:
        mMultiRenderer.setMargins(new int[] { 50, 100, 35, 20 });
        mMultiRenderer.setAxisTitleTextSize(Constants.TEXT_SIZE_XXHDPI);
        mMultiRenderer.setChartTitleTextSize(Constants.TEXT_SIZE_XXHDPI);
        mMultiRenderer.setLabelsTextSize(Constants.TEXT_SIZE_XXHDPI);
        mMultiRenderer.setLegendTextSize(Constants.TEXT_SIZE_XXHDPI);
        break;

    default:
        if (deviceDPi > DisplayMetrics.DENSITY_XXHIGH && deviceDPi < DisplayMetrics.DENSITY_XXXHIGH) {
            mMultiRenderer.setMargins(new int[] { 50, 100, 35, 20 });
            mMultiRenderer.setAxisTitleTextSize(Constants.TEXT_SIZE_XXHDPI);
            mMultiRenderer.setChartTitleTextSize(Constants.TEXT_SIZE_XXHDPI);
            mMultiRenderer.setLabelsTextSize(Constants.TEXT_SIZE_XXHDPI);
            mMultiRenderer.setLegendTextSize(Constants.TEXT_SIZE_XXHDPI);
        } else {
            mMultiRenderer.setMargins(new int[] { 30, 50, 25, 10 });
            mMultiRenderer.setAxisTitleTextSize(Constants.TEXT_SIZE_LDPI);
            mMultiRenderer.setChartTitleTextSize(Constants.TEXT_SIZE_LDPI);
            mMultiRenderer.setLabelsTextSize(Constants.TEXT_SIZE_LDPI);
            mMultiRenderer.setLegendTextSize(Constants.TEXT_SIZE_LDPI);
        }
        break;
    }
    mMultiRenderer.setXTitle(graphXAxis);
    mMultiRenderer.setLabelsColor(Color.BLACK);
    mMultiRenderer.setYTitle(graphYAxis);
    mMultiRenderer.setYAxisMin(0);
    mMultiRenderer.setXAxisMin(0);
    mMultiRenderer.setMarginsColor(Color.argb(0x00, 0xff, 0x00, 0x00));
    mMultiRenderer.setPanEnabled(true, true);
    mMultiRenderer.setZoomEnabled(false, false);
    mMultiRenderer.setYLabelsColor(0, Color.BLACK);
    mMultiRenderer.setXLabelsColor(Color.BLACK);
    mMultiRenderer.setApplyBackgroundColor(true);
    mMultiRenderer.setBackgroundColor(Color.WHITE);
    mMultiRenderer.setGridColor(Color.BLACK);
    mMultiRenderer.setShowGrid(true);
    mMultiRenderer.setShowLegend(false);

    // Adding mRenderer to multipleRenderer
    mMultiRenderer.addSeriesRenderer(mRenderer);

    // Getting a reference to LinearLayout of the MainActivity Layout
    mGraphLayoutParent = (LinearLayout) parent.findViewById(R.id.chart_container);

    mChart = ChartFactory.getLineChartView(getActivity(), mDataset, mMultiRenderer);

    // Adding the Line Chart to the LinearLayout
    mGraphLayoutParent.addView(mChart);

}

From source file:com.cypress.cysmart.BLEServiceFragments.RSCService.java

/**
 * Setting up the aChart Third party library
 *
 * @param parent/* w w  w .ja  v a2s  .co m*/
 */
private void setupChart(View parent) {
    /**
     * Setting graph titles
     */
    String graphTitle = getResources().getString(R.string.rsc_fragment);
    String graphXAxis = getResources().getString(R.string.health_temperature_time);
    String graphYAxis = getResources().getString(R.string.rsc_avg_speed);

    // Creating an  XYSeries for running speed
    mDataSeries = new XYSeries(graphTitle);

    // Creating a dataset to hold each series
    XYMultipleSeriesDataset mDataset = new XYMultipleSeriesDataset();

    // Adding temperature Series to the dataset
    mDataset.addSeries(mDataSeries);

    // Creating XYSeriesRenderer to customize
    XYSeriesRenderer mRenderer = new XYSeriesRenderer();
    mRenderer.setColor(getResources().getColor(R.color.main_bg_color));
    mRenderer.setPointStyle(PointStyle.CIRCLE);
    mRenderer.setFillPoints(true);
    mRenderer.setLineWidth(5);

    // Creating a XYMultipleSeriesRenderer to customize the whole chart
    XYMultipleSeriesRenderer mMultiRenderer = new XYMultipleSeriesRenderer();
    int deviceDPi = getResources().getDisplayMetrics().densityDpi;
    switch (getResources().getDisplayMetrics().densityDpi) {
    case DisplayMetrics.DENSITY_XHIGH:
        mMultiRenderer.setMargins(new int[] { 40, 90, 25, 10 });
        mMultiRenderer.setAxisTitleTextSize(Constants.TEXT_SIZE_XHDPI);
        mMultiRenderer.setChartTitleTextSize(Constants.TEXT_SIZE_XHDPI);
        mMultiRenderer.setLabelsTextSize(Constants.TEXT_SIZE_XHDPI);
        mMultiRenderer.setLegendTextSize(Constants.TEXT_SIZE_XHDPI);
        break;
    case DisplayMetrics.DENSITY_HIGH:
        mMultiRenderer.setMargins(new int[] { 30, 50, 25, 10 });
        mMultiRenderer.setAxisTitleTextSize(Constants.TEXT_SIZE_HDPI);
        mMultiRenderer.setChartTitleTextSize(Constants.TEXT_SIZE_HDPI);
        mMultiRenderer.setLabelsTextSize(Constants.TEXT_SIZE_HDPI);
        mMultiRenderer.setLegendTextSize(Constants.TEXT_SIZE_HDPI);
        break;
    case DisplayMetrics.DENSITY_XXHIGH:
        mMultiRenderer.setMargins(new int[] { 50, 100, 35, 20 });
        mMultiRenderer.setAxisTitleTextSize(Constants.TEXT_SIZE_XXHDPI);
        mMultiRenderer.setChartTitleTextSize(Constants.TEXT_SIZE_XXHDPI);
        mMultiRenderer.setLabelsTextSize(Constants.TEXT_SIZE_XXHDPI);
        mMultiRenderer.setLegendTextSize(Constants.TEXT_SIZE_XXHDPI);
        break;

    default:
        if (deviceDPi > DisplayMetrics.DENSITY_XXHIGH && deviceDPi < DisplayMetrics.DENSITY_XXXHIGH) {
            mMultiRenderer.setMargins(new int[] { 50, 100, 35, 20 });
            mMultiRenderer.setAxisTitleTextSize(Constants.TEXT_SIZE_XXHDPI);
            mMultiRenderer.setChartTitleTextSize(Constants.TEXT_SIZE_XXHDPI);
            mMultiRenderer.setLabelsTextSize(Constants.TEXT_SIZE_XXHDPI);
            mMultiRenderer.setLegendTextSize(Constants.TEXT_SIZE_XXHDPI);
        } else {
            mMultiRenderer.setMargins(new int[] { 30, 50, 25, 10 });
            mMultiRenderer.setAxisTitleTextSize(Constants.TEXT_SIZE_LDPI);
            mMultiRenderer.setChartTitleTextSize(Constants.TEXT_SIZE_LDPI);
            mMultiRenderer.setLabelsTextSize(Constants.TEXT_SIZE_LDPI);
            mMultiRenderer.setLegendTextSize(Constants.TEXT_SIZE_LDPI);
        }
        break;
    }
    mMultiRenderer.setXTitle(graphXAxis);
    mMultiRenderer.setLabelsColor(Color.BLACK);
    mMultiRenderer.setYTitle(graphYAxis);
    mMultiRenderer.setYAxisMin(0);
    mMultiRenderer.setXAxisMin(0);
    mMultiRenderer.setMarginsColor(Color.argb(0x00, 0xff, 0x00, 0x00));
    mMultiRenderer.setPanEnabled(true, true);
    mMultiRenderer.setZoomEnabled(false, false);
    mMultiRenderer.setYLabelsColor(0, Color.BLACK);
    mMultiRenderer.setXLabelsColor(Color.BLACK);
    mMultiRenderer.setApplyBackgroundColor(true);
    mMultiRenderer.setBackgroundColor(Color.WHITE);
    mMultiRenderer.setGridColor(Color.BLACK);
    mMultiRenderer.setShowGrid(true);
    mMultiRenderer.setShowLegend(false);

    // Adding mRenderer to multipleRenderer
    mMultiRenderer.addSeriesRenderer(mRenderer);

    // Getting a reference to LinearLayout of the MainActivity Layout
    mGraphLayoutParent = (LinearLayout) parent.findViewById(R.id.chart_container);

    mChart = ChartFactory.getLineChartView(getActivity(), mDataset, mMultiRenderer);

    // Adding the Line Chart to the LinearLayout
    mGraphLayoutParent.addView(mChart);

}

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

private static int getAlertIconDensityDpi(Context context) {
    if (sDensityDpi == null) {
        sDensityDpi = context.getResources().getDisplayMetrics().densityDpi;
    }//from w  ww .ja  va2s.  c o  m

    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:org.mozilla.gecko.GeckoAppShell.java

static private Bitmap getLauncherIcon(Bitmap aSource) {
    final int kOffset = 6;
    final int kRadius = 5;
    int kIconSize;
    int kOverlaySize;
    switch (getDpi()) {
    case DisplayMetrics.DENSITY_MEDIUM:
        kIconSize = 48;//w ww  .  jav  a  2 s  . c  o  m
        kOverlaySize = 32;
        break;
    case DisplayMetrics.DENSITY_XHIGH:
        kIconSize = 96;
        kOverlaySize = 48;
        break;
    case DisplayMetrics.DENSITY_HIGH:
    default:
        kIconSize = 72;
        kOverlaySize = 32;
    }

    Bitmap bitmap = Bitmap.createBitmap(kIconSize, kIconSize, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    // draw a base color
    Paint paint = new Paint();

    if (aSource == null) {
        float[] hsv = new float[3];
        hsv[0] = 32.0f;
        hsv[1] = 1.0f;
        hsv[2] = 1.0f;
        paint.setColor(Color.HSVToColor(hsv));
        canvas.drawRoundRect(new RectF(kOffset, kOffset, kIconSize - kOffset, kIconSize - kOffset), kRadius,
                kRadius, paint);
    } else {
        int color = BitmapUtils.getDominantColor(aSource);
        paint.setColor(color);
        canvas.drawRoundRect(new RectF(kOffset, kOffset, kIconSize - kOffset, kIconSize - kOffset), kRadius,
                kRadius, paint);
        paint.setColor(Color.argb(100, 255, 255, 255));
        canvas.drawRoundRect(new RectF(kOffset, kOffset, kIconSize - kOffset, kIconSize - kOffset), kRadius,
                kRadius, paint);
    }

    // draw the overlay
    Bitmap overlay = BitmapFactory.decodeResource(GeckoApp.mAppContext.getResources(), R.drawable.home_bg);
    canvas.drawBitmap(overlay, null, new Rect(0, 0, kIconSize, kIconSize), null);

    // draw the bitmap
    if (aSource == null)
        aSource = BitmapFactory.decodeResource(GeckoApp.mAppContext.getResources(), R.drawable.home_star);

    if (aSource.getWidth() < kOverlaySize || aSource.getHeight() < kOverlaySize) {
        canvas.drawBitmap(aSource, null,
                new Rect(kIconSize / 2 - kOverlaySize / 2, kIconSize / 2 - kOverlaySize / 2,
                        kIconSize / 2 + kOverlaySize / 2, kIconSize / 2 + kOverlaySize / 2),
                null);
    } else {
        canvas.drawBitmap(aSource, null,
                new Rect(kIconSize / 2 - aSource.getWidth() / 2, kIconSize / 2 - aSource.getHeight() / 2,
                        kIconSize / 2 + aSource.getWidth() / 2, kIconSize / 2 + aSource.getHeight() / 2),
                null);
    }

    return bitmap;
}