Android Open Source - pinpoint-android Pinpoint Activity






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   ww  w. j  a va2s  . co m*/
import android.app.Activity;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import java.util.List;
import java.util.Map;

public abstract class PinpointActivity extends Activity implements OnClickListener, OnTouchListener {
  private boolean hasSelectionBeenMade = false;

  private LauncherItem launcherItem;
  private TaskLogEntry taskLogEntry;

  public LauncherItem getLauncherItem() {
    return new LauncherItem(this.launcherItem);
  }

  /**
   * Return the ID of the layout used for this activity.
   */
  protected abstract int getLayoutId();

  protected abstract int[] getButtonIds();

  protected void initializeListeners(int[] ids) {
    View view;

    for (int id : ids) {
      view = this.findViewById(id);

      view.setOnClickListener(this);
      view.setOnTouchListener(this);
    }
  }

  protected abstract boolean isClickCorrect(int id);

  @Override
  public void onBackPressed() {
    // do nothing when user presses the Back-button on the device
  }

  @Override
  public void onClick(View view) {
    this.taskLogEntry.complete();
    this.taskLogEntry.setTouchTarget(view.getTag().toString());

    if (!this.hasSelectionBeenMade) {
      view.setBackgroundResource(R.color.orange);
      this.hasSelectionBeenMade = true;

      this.taskLogEntry.setWasCorrect(this.isClickCorrect(view.getId()));

      User currentUser = Pinpoint.getCurrentUser();
      Integer currentHomescreenId = currentUser.getHomescreenIds().get(0);

      TaskLog taskLog = currentUser.getTaskLog();
      TaskManager taskManager = currentUser.getTaskManager();

      taskLog.addEntry(this.taskLogEntry);

      Task task = taskManager.getTask();

      if (null == task) {
        List<Integer> homescreenIds = currentUser.getHomescreenIds();

        if (homescreenIds.size() > 1) {
          homescreenIds.remove(0);
          this.transitionToIntermissionActivity();
        } else {
          if (currentUser == Pinpoint.getUser()) {
            Pinpoint.handoffToAttacker();
            this.transitionToIntermissionActivity();
          } else {
            this.transitionToStatisticsActivity();
          }
        }
      }

      if (null != task) {
        Intent intent = new Intent(this, task.getActivityClass());
        intent.putExtra(Pinpoint.EXTRA_LAUNCHERITEM, task.getLauncherItem());
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);

        this.startActivity(intent);
      }
    }
  }

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setContentView(this.getLayoutId());

    this.launcherItem = (LauncherItem) this.getIntent().getExtras().get(Pinpoint.EXTRA_LAUNCHERITEM);

    this.taskLogEntry = new TaskLogEntry(this.launcherItem, this.getClass());

    ((LinearLayout) this.findViewById(R.id.footer)).setLayoutParams(
      new LayoutParams(LayoutParams.MATCH_PARENT, Configuration.getInstance().getFooterHeight())
    );

    ((LinearLayout) this.findViewById(R.id.header)).setLayoutParams(
      new LayoutParams(LayoutParams.MATCH_PARENT, Configuration.getInstance().getHeaderHeight())
    );

    ((TextView) this.findViewById(R.id.footer_appName)).setText(
      launcherItem.getTitle()
    );

    if (null != this.launcherItem.getIcon()) {
      ((ImageView) this.findViewById(R.id.footer_appIcon)).setImageBitmap(
        BitmapFactory.decodeByteArray(launcherItem.getIcon(), 0, launcherItem.getIcon().length)
      );
    }

    this.initializeListeners(this.getButtonIds());
  }

  private void transitionToIntermissionActivity() {
    this.startActivity(new Intent(this, IntermissionActivity.class));
  }

  private void transitionToStatisticsActivity() {
    this.startActivity(new Intent(this, StatisticsActivity.class));
  }

  @Override
  public boolean onTouch(View view, MotionEvent event) {
    if (MotionEvent.ACTION_DOWN == event.getAction()) {
      this.taskLogEntry.setTouchCoordinates(event.getX(), event.getY());
    }

    return false;
  }
}




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