Advertisement
vovan333

MOJ GOWNOCODE

Oct 16th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.12 KB | None | 0 0
  1. package com.asmjs.phoneinfo;
  2.  
  3. import android.graphics.Point;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.os.Bundle;
  6. import android.view.Display;
  7. import android.widget.TextView;
  8. import android.widget.Toast;
  9.  
  10. import java.io.BufferedReader;
  11. import java.io.FileReader;
  12. import java.io.IOException;
  13.  
  14. public class MainActivity extends AppCompatActivity
  15. {
  16.     private void SetCPUCoreCount(int count)
  17.     {
  18.         String[] possibilities = {"single-core", "double-core", "triple-core", "quad-core"};
  19.         TextView CPUCoreCount = (TextView) findViewById(R.id.CPUCoreCount);
  20.         CPUCoreCount.setText(possibilities[count - 1].toUpperCase());
  21.     }
  22.  
  23.     private void SetCPUFrequency(float frequency)
  24.     {
  25.         TextView CPUFrequency = (TextView) findViewById(R.id.CPUFrequency);
  26.         CPUFrequency.setText(String.valueOf(frequency));
  27.     }
  28.  
  29.     private void SetDisplaySize(int width, int height)
  30.     {
  31.         TextView displayResolution = (TextView) findViewById(R.id.displaySize);
  32.         String resolution = String.valueOf(width) + "x" + String.valueOf(height);
  33.         displayResolution.setText(resolution);
  34.     }
  35.  
  36.     private void SetDisplaySize(Point size)
  37.     {
  38.         SetDisplaySize(size.x, size.y);
  39.     }
  40.  
  41.     private void SetDisplayType(String type)
  42.     {
  43.         TextView displayType = (TextView) findViewById(R.id.displayType);
  44.         displayType.setText(type);
  45.     }
  46.  
  47.     private String ReadFile(String filename) throws IOException
  48.     {
  49.         String output = "";
  50.         String line = "";
  51.         FileReader fr = new FileReader(filename);
  52.         BufferedReader br = new BufferedReader(fr);
  53.         while ((line = br.readLine()) != null)
  54.         {
  55.             output += line + "\n";
  56.         }
  57.         return output;
  58.     }
  59.  
  60.     private int GetCPUCoreCount()
  61.     {
  62.         return Runtime.getRuntime().availableProcessors();
  63.     }
  64.  
  65.     private void MakeToast(String message, int duration)
  66.     {
  67.         Toast toast = Toast.makeText(getApplicationContext(), message, duration);
  68.         toast.show();
  69.     }
  70.  
  71.     private float GetCPUFrequency()
  72.     {
  73.         String filename = "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq";
  74.         try
  75.         {
  76.             float freq = Float.parseFloat(ReadFile(filename));
  77.             return freq / 1000000;
  78.         }
  79.         catch (IOException ex)
  80.         {
  81.             MakeToast("An IOException occurred when attempted to get CPU frequency info.", Toast.LENGTH_LONG);
  82.             return 0;
  83.         }
  84.     }
  85.  
  86.     private Point GetDisplaySize()
  87.     {
  88.         Display display = getWindowManager().getDefaultDisplay();
  89.         Point size = new Point();
  90.         display.getSize(size);
  91.         return size;
  92.     }
  93.  
  94.     private void initialize()
  95.     {
  96.         SetCPUCoreCount(GetCPUCoreCount());
  97.         SetCPUFrequency(GetCPUFrequency());
  98.         SetDisplaySize(GetDisplaySize());
  99.         SetDisplayType("IPS+");
  100.     }
  101.  
  102.     @Override
  103.     protected void onCreate(Bundle savedInstanceState)
  104.     {
  105.         super.onCreate(savedInstanceState);
  106.         setContentView(R.layout.activity_main);
  107.         initialize();
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement