Android Open Source - AndroidUIExample My Activity






From Project

Back to project page AndroidUIExample.

License

The source code is released under:

Apache License

If you think the Android project AndroidUIExample 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 com.example.androidui;
/*  w w w  .j av  a 2  s.com*/
import action.BackAction;
import action.CloseAction;
import action.DrawerAction;
import action.PlusAction;
import action.SymbolAction;

import android.media.MediaPlayer;

import android.os.Bundle;
import android.os.Vibrator;
import android.view.Menu;
import android.view.MenuItem;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.Point;
import android.view.View;
import android.widget.CheckBox;
import android.widget.Toast;

import com.example.androidui.RevealColorView;

public class MyActivity extends Activity implements View.OnClickListener {

  private RevealColorView revealColorView;
  private ActionView actionView;
  private View selectedView;
  private int backgroundColor;
  private Vibrator vib;
  private CheckBox checkbox;
  
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);
        vib = (Vibrator) this.getSystemService(VIBRATOR_SERVICE);
        
    revealColorView = (RevealColorView) findViewById(R.id.reveal);
    actionView = (ActionView) findViewById(R.id.action);
    backgroundColor = Color.parseColor("#212121");
        
    findViewById(R.id.btn_1).setOnClickListener(this);
    findViewById(R.id.btn_2).setOnClickListener(this);
    findViewById(R.id.btn_3).setOnClickListener(this);
    findViewById(R.id.btn_4).setOnClickListener(this);  
    }

  @Override
  public void onClick(View v) {
    final int color = getColor(v);
    final Point p = getLocationInView(revealColorView, v);
    final MediaPlayer mpButtonClick1 = MediaPlayer.create(this, R.raw.fuuton_rasenshuriken);
    final MediaPlayer mpButtonClick2 = MediaPlayer.create(this, R.raw.fuuton_rasenshuriken);
    final MediaPlayer mpButtonClick3 = MediaPlayer.create(this, R.raw.fuuton_rasenshuriken);
    final MediaPlayer mpButtonClick4 = MediaPlayer.create(this, R.raw.fuuton_rasenshuriken);
    
    checkbox = (CheckBox) findViewById(R.id.checkBox1);

    if (selectedView == v) {
      revealColorView.hide(p.x, p.y, backgroundColor, 0, 300, null);
      actionView.setAction(new DrawerAction(), ActionView.ROTATE_COUNTER_CLOCKWISE);
      selectedView = null;
    } else {
      revealColorView.reveal(p.x, p.y, color, v.getHeight() / 2, 340, null);
      if (findViewById(R.id.btn_1) == v) {
        if (checkbox.isChecked()) {
          actionView.setAction(new BackAction(), ActionView.ROTATE_CLOCKWISE);
        }
        else {
          actionView.setAction(new BackAction(), ActionView.ROTATE_COUNTER_CLOCKWISE);
        }
        mpButtonClick1.start();
        vib.vibrate(50);
        String button1 = "Color 1 Selected";
      
        Toast.makeText(this, button1, Toast.LENGTH_SHORT)
        .show();
      }
      else if (findViewById(R.id.btn_2) == v) {
        if (checkbox.isChecked()) {
          actionView.setAction(new PlusAction(), ActionView.ROTATE_CLOCKWISE);
        }
        else {
          actionView.setAction(new PlusAction(), ActionView.ROTATE_COUNTER_CLOCKWISE);
        }
        mpButtonClick2.start();
        vib.vibrate(50);
        String button2 = "Color 2 Selected";
      
        Toast.makeText(this, button2, Toast.LENGTH_SHORT)
        .show();
      }
      else if (findViewById(R.id.btn_3) == v) {
        if (checkbox.isChecked()) {
          actionView.setAction(new SymbolAction(), ActionView.ROTATE_CLOCKWISE);
        }
        else {
          actionView.setAction(new SymbolAction(), ActionView.ROTATE_COUNTER_CLOCKWISE);
        }
        mpButtonClick3.start();
        vib.vibrate(50);
        String button3 = "Color 3 Selected";
      
        Toast.makeText(this, button3, Toast.LENGTH_SHORT)
        .show();
      }
      else if (findViewById(R.id.btn_4) == v) {
        if (checkbox.isChecked()) {
          actionView.setAction(new CloseAction(), ActionView.ROTATE_CLOCKWISE);
        }
        else {
          actionView.setAction(new CloseAction(), ActionView.ROTATE_COUNTER_CLOCKWISE);
        }
        mpButtonClick4.start();
        vib.vibrate(50);
        String button4 = "Color 4 Selected";
    
        Toast.makeText(this, button4, Toast.LENGTH_SHORT)
        .show();
      }
      selectedView = v;
    }
  }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.my, menu);
        return true;
    }
    
  private Point getLocationInView(View src, View target) {
    final int[] l0 = new int[2];
    src.getLocationOnScreen(l0);

    final int[] l1 = new int[2];
    target.getLocationOnScreen(l1);

    l1[0] = l1[0] - l0[0] + target.getWidth() / 2;
    l1[1] = l1[1] - l0[1] + target.getHeight() / 2;

    return new Point(l1[0], l1[1]);
  }

  private int getColor(View view) {
    return Color.parseColor((String) view.getTag());
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {

    case R.id.action_settings:
      Toast.makeText(this, "Settings selected", Toast.LENGTH_SHORT)
      .show();
      break;

    }
    return true;
  } 
}




Java Source Code List

action.Action.java
action.BackAction.java
action.CloseAction.java
action.DrawerAction.java
action.LineSegment.java
action.PlusAction.java
action.SymbolAction.java
com.example.androidui.ActionView.java
com.example.androidui.MyActivity.java
com.example.androidui.RevealColorView.java
util.BakedBezierInterpolator.java
util.UiHelper.java