Android Open Source - pinpoint-android Launcher Item






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 w w .j  a va 2  s . c om*/
import java.io.Serializable;
import java.util.Arrays;
import org.json.JSONException;
import org.json.JSONObject;
import util.Base64;

public final class LauncherItem implements Serializable {
  private static final long serialVersionUID = 0L;

  public static final int
      CONTAINER_DOCK = -101,
      CONTAINER_SCREEN = -100,
      ITEMTYPE_APPLICATION = 0,
      ITEMTYPE_SHORTCUT = 1,
      ITEMTYPE_FOLDER = 2,
      ITEMTYPE_WIDGET = 4;

  public static final String
      ITEMTYPE_APPLICATION_STRING = "Application",
      ITEMTYPE_SHORTCUT_STRING = "Shortcut",
      ITEMTYPE_FOLDER_STRING = "Folder",
      ITEMTYPE_WIDGET_STRING = "Widget";

  private final byte[] icon;

  private final int
      appWidgetId,
      cellX,
      cellY,
      container,
      id,
      itemType,
      screen,
      spanX,
      spanY;

  private final String
      intent,
      title;

  public LauncherItem(int id, String title, String intent, int container, int
      screen, int cellX, int cellY, int spanX, int spanY, int itemType, int
      appWidgetId, byte[] icon) {
    this.appWidgetId = appWidgetId;
    this.cellX = cellX;
    this.cellY = cellY;
    this.container = container;
    this.icon = icon;
    this.id = id;
    this.intent = intent;
    this.itemType = itemType;
    this.screen = screen;
    this.spanX = spanX;
    this.spanY = spanY;
    this.title = title;
  }

  public LauncherItem(LauncherItem launcherItem) {
    this(launcherItem.getId(),
        launcherItem.getTitle(),
        launcherItem.getIntent(),
        launcherItem.getContainer(),
        launcherItem.getScreen(),
        launcherItem.getCellX(),
        launcherItem.getCellY(),
        launcherItem.getSpanX(),
        launcherItem.getSpanY(),
        launcherItem.getItemType(),
        launcherItem.getAppWidgetId(),
        launcherItem.getIcon());
  }

  public int getAppWidgetId() {
    return this.appWidgetId;
  }

  public int getCellX() {
    return this.cellX;
  }

  public int getContainer() {
    return this.container;
  }

  public int getCellY() {
    return this.cellY;
  }

  public byte[] getIcon() {
    if (null != this.icon) {
      return Arrays.copyOf(this.icon, this.icon.length);
    }

    return null;
  }

  public int getId() {
    return this.id;
  }

  public String getIntent() {
    return this.intent;
  }

  public int getItemType() {
    return this.itemType;
  }

  public String getItemTypeString() {
    switch (this.itemType) {
      case LauncherItem.ITEMTYPE_APPLICATION:
        return LauncherItem.ITEMTYPE_APPLICATION_STRING;
      case LauncherItem.ITEMTYPE_SHORTCUT:
        return LauncherItem.ITEMTYPE_SHORTCUT_STRING;
      case LauncherItem.ITEMTYPE_FOLDER:
        return LauncherItem.ITEMTYPE_FOLDER_STRING;
      case LauncherItem.ITEMTYPE_WIDGET:
        return LauncherItem.ITEMTYPE_WIDGET_STRING;
    }

    return "UNKNOWN [" + this.itemType + "]";
  }

  public String getTitle() {
    return this.title;
  }

  public int getScreen() {
    return this.screen;
  }

  public int getSpanX() {
    return this.spanX;
  }

  public int getSpanY() {
    return this.spanY;
  }

  public boolean isApplication() {
    return this.itemType == LauncherItem.ITEMTYPE_APPLICATION;
  }

  public boolean isFolder() {
    return this.itemType == LauncherItem.ITEMTYPE_FOLDER;
  }

  public boolean isInDock() {
    return this.container == LauncherItem.CONTAINER_DOCK;
  }

  public boolean isOnScreen() {
    return this.container == LauncherItem.CONTAINER_SCREEN;
  }

  public boolean isShortcut() {
    return this.itemType == LauncherItem.ITEMTYPE_SHORTCUT;
  }

  public JSONObject toJSON() {
    JSONObject
        jsonObject = new JSONObject(),
        position = new JSONObject(),
        span = new JSONObject();

    StringBuilder base64Icon = new StringBuilder();
    if (null != this.icon) {
      base64Icon.append("data:image/png;base64,")
          .append(Base64.encodeToString(this.icon, false));
    }

    try {
      jsonObject.put("appWidgetId", this.appWidgetId);
      jsonObject.put("container", this.container);
      jsonObject.put("icon", base64Icon);
      jsonObject.put("id", this.id);
      jsonObject.put("intent", this.intent);
      jsonObject.put("itemType", this.getItemTypeString());
      jsonObject.put("screen", this.screen);
      jsonObject.put("title", this.title);

      position.put("x", this.cellX);
      position.put("y", this.cellY);
      jsonObject.put("position", position);

      span.put("x", this.spanX);
      span.put("y", this.spanY);
      jsonObject.put("span", span);
    } catch (JSONException exception) {
      Pinpoint.log("Could not create JSONObject from LauncherItem.");
    }

    return jsonObject;
  }
}




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