Android Open Source - pinpoint-android Device Metrics






From Project

Back to project page pinpoint-android.

License

The source code is released under:

MIT License

If you think the Android project pinpoint-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package co.islovely.pinpoint;
/*from   w ww.  j  a va  2 s .c om*/
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build;
import android.os.Build.VERSION;
import android.util.DisplayMetrics;
import org.json.JSONException;
import org.json.JSONObject;

public class DeviceMetrics {
  private DisplayMetrics displayMetrics;

  private PackageManager packageManager;

  public DeviceMetrics(PackageManager packageManager, DisplayMetrics displayMetrics) {
    this.displayMetrics = displayMetrics;
    this.packageManager = packageManager;
  }

  public JSONObject toJSON() {
    JSONObject
        json = new JSONObject(),
        launcher = new JSONObject(),
        screen = new JSONObject(),
        sdk = new JSONObject();

    try {
      json.put("manufacturer", Build.MANUFACTURER);
      json.put("model", Build.MODEL);

      sdk.put("release", Build.VERSION.RELEASE);
      sdk.put("version", Build.VERSION.SDK_INT);
      json.put("sdk", sdk);

      if (null != this.displayMetrics) {
        screen.put("height", this.displayMetrics.heightPixels);
        screen.put("width", this.displayMetrics.widthPixels);
        screen.put("density", this.displayMetrics.density);
        json.put("screen", screen);
      }

      if (null != this.packageManager) {
        ActivityInfo activityInfo = (this.packageManager.resolveActivity(
            new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME),
            PackageManager.MATCH_DEFAULT_ONLY
        )).activityInfo;

        launcher.put("packageName", activityInfo.packageName);
        launcher.put("name", activityInfo.name);

        PackageInfo packageInfo = null;
        try {
          packageInfo = this.packageManager.getPackageInfo(activityInfo.packageName, 0);
        } catch (NameNotFoundException exception) {
          Pinpoint.log("Could not find additional information on launcher.");
        }

        if (null != packageInfo) {
          launcher.put("firstInstalledAt", packageInfo.firstInstallTime);
          launcher.put("lastUpdatedAt", packageInfo.lastUpdateTime);
          launcher.put("versionName", packageInfo.versionName);
          launcher.put("versionCode", packageInfo.versionCode);
        }

        json.put("launcher", launcher);
      }
    } catch (JSONException exception) {
      Pinpoint.log("Could not create JSONObject from DeviceMetrics.");
    }

    return json;
  }
}




Java Source Code List

co.islovely.pinpoint.ColumnsActivity.java
co.islovely.pinpoint.Configuration.java
co.islovely.pinpoint.DeviceMetrics.java
co.islovely.pinpoint.GridActivity.java
co.islovely.pinpoint.HomescreenAdapter.java
co.islovely.pinpoint.HomescreenSelectActivity.java
co.islovely.pinpoint.Homescreen.java
co.islovely.pinpoint.IntermissionActivity.java
co.islovely.pinpoint.LauncherItem.java
co.islovely.pinpoint.LauncherReader.java
co.islovely.pinpoint.LayoutConfigurationActivity.java
co.islovely.pinpoint.MainActivity.java
co.islovely.pinpoint.MyApplication.java
co.islovely.pinpoint.PinpointActivity.java
co.islovely.pinpoint.Pinpoint.java
co.islovely.pinpoint.QuadrantsActivity.java
co.islovely.pinpoint.RowsActivity.java
co.islovely.pinpoint.StatisticsActivity.java
co.islovely.pinpoint.TaskLogEntry.java
co.islovely.pinpoint.TaskLog.java
co.islovely.pinpoint.TaskManager.java
co.islovely.pinpoint.Task.java
co.islovely.pinpoint.User.java
util.Base64.java