Android Open Source - Resonos-Android-Framework Action






From Project

Back to project page Resonos-Android-Framework.

License

The source code is released under:

Apache License

If you think the Android project Resonos-Android-Framework 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.resonos.apps.library;
/*  ww  w  .ja va  2 s . c  om*/
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.View;

import com.resonos.apps.library.util.AppUtils;

/**
 * This class denotes a menu item for the action bar, or for the custom toolbar widget
 * @author Chris Newhouse
 */
public class Action {

  // constants
  public static final int ICON_BITMAP = -1;
  public static final int ICON_NONE = 0;
  public static final int ALPHA_DISABLED = 100;
  
  // global vars
  private static int counter = 0;
  
  // data
  public String text;
  public int icon;
  public int id;
  private Bitmap bmp;
  public boolean wt, over;
  public Enum<?> tag;
  public boolean nonPressable = false, disabled = false, pressed = false;
  public View customControl = null;
  public boolean customControlFill = false;
  public boolean newRow = false;
  public boolean priority = true;
//  public ActionProvider actionProvider = null;

  /**
   * 
   * Construct a new Action for an ActionBar or ToolBar using a resource for image
   * @param Title
   * @param i, the icon resource id, or 0 for none
   * @param true to show text instead of tooltip
   * @param true to put into the overflow menu (ActionBar only)
   * @param this is the tag of the action from the enum for this toolbar/actionbar
   */
  public Action(String t, int i, boolean withText, boolean overflow,
      Enum<?> tg) {
    text = t;
    icon = i;
    wt = withText;
    over = overflow;
    id = counter++;
    tag = tg;
  }

  /**
   * Construct a new Action for an ActionBar or ToolBar using a bitmap
   * @param Title
   * @param The bitmap to use
   * @param true to show text instead of tooltip
   * @param true to put into the overflow menu (ActionBar only)
   * @param this is the tag of the action from the enum for this toolbar/actionbar
   */
  public Action(String t, Bitmap bmp, boolean withText, boolean overflow,
      Enum<?> tg) {
    text = t;
    icon = ICON_BITMAP;
    this.bmp = bmp;
    wt = withText;
    over = overflow;
    id = counter++;
    tag = tg;
  }

  /**
   * set this action to be not pressable (toolbar only)
   * @return this action for chaining
   */
  public Action setNonPressable() {
    nonPressable = true;
    return this;
  }

  /**
   * set this action to forced in the actionbar or not
   * @return true = forced, false = if room
   */
  public Action setPriority(boolean high) {
    priority = high;
    return this;
  }

  /**
   * Set this action to be disabled
   * @return this action for chaining
   */
  public Action setDisabled() {
    disabled = true;
    return this;
  }

  /**
   * Set this action to be not pressable (toolbar only)
   * @return this action for chaining
   */
  public Action setPressed(boolean p) {
    pressed = p;
    return this;
  }

//    commented out because ActionBarSherlock is not at a state where
//      the ShareActionProvider is actually bug free
//      it just causes random crashes to occur in my experience
//  /**
//   * Adds an Action Provider to this button (ActionBar only)
//   * @return this action for chaining
//   */
//  public Action actionProvider(ActionProvider ap) {
//    actionProvider = ap;
//    return this;
//  }
  
  /**
   * Set this action to be on a new row (toolbar only).
   * All subsequent actions will be on this row.
   * @return this action for chaining
   */
  public Action newRow() {
    newRow = true;
    return this;
  }
  
  /**
   * Add a custom View in this Action (toolbar only)
   * @param the custom view
   * @param true if you want this control to fill the rest of the row
   * @return this action for chaining
   */
  public Action customControl(View v, boolean fill) {
    customControl = v;
    customControlFill = fill;
    nonPressable = true;
    return this;
  }

  /**
   * Gets the drawable for the icon in this button, whether it is a bitmap or resource
   * @param Context to access resources
   * @return the drawable, or null if there is none
   */
  public Drawable getDrawable(Context mCX) {
    if (icon == Action.ICON_BITMAP)
      return new BitmapDrawable(mCX.getResources(), bmp);
    else if (icon != Action.ICON_NONE) {
      if (disabled) {
        Drawable d = AppUtils.getMutableDrawable(mCX, icon);
        d.setAlpha(ALPHA_DISABLED);
        return d;
      } else
        return mCX.getResources().getDrawable(icon);
    } else
      return null;
  }
}




Java Source Code List

com.resonos.apps.library.Action.java
com.resonos.apps.library.AlertFragment.java
com.resonos.apps.library.App.java
com.resonos.apps.library.BaseFragment.java
com.resonos.apps.library.FragmentBaseActivity.java
com.resonos.apps.library.file.AltAndroidFileHandle.java
com.resonos.apps.library.file.AltAndroidFiles.java
com.resonos.apps.library.file.AltFileHandle.java
com.resonos.apps.library.file.FileCache.java
com.resonos.apps.library.media.AudioVisualizer.java
com.resonos.apps.library.media.BitmapMemoryCache.java
com.resonos.apps.library.media.HueColorFilter.java
com.resonos.apps.library.media.ImageLoader.java
com.resonos.apps.library.media.MediaScannerNotifier.java
com.resonos.apps.library.model.Coord.java
com.resonos.apps.library.model.ImmutableCoord.java
com.resonos.apps.library.tabviewpager.CustomViewPager.java
com.resonos.apps.library.tabviewpager.PageIndicator.java
com.resonos.apps.library.tabviewpager.TabPageIndicator.java
com.resonos.apps.library.tabviewpager.TabViewPagerAdapter.java
com.resonos.apps.library.tabviewpager.TabViewPagerFragment.java
com.resonos.apps.library.tabviewpager.TitleProvider.java
com.resonos.apps.library.util.AppUtils.java
com.resonos.apps.library.util.ErrorReporter.java
com.resonos.apps.library.util.LifecycleTaskQueue.java
com.resonos.apps.library.util.M.java
com.resonos.apps.library.util.NetworkClient.java
com.resonos.apps.library.util.NetworkRequest.java
com.resonos.apps.library.util.ParameterList.java
com.resonos.apps.library.util.SensorReader.java
com.resonos.apps.library.util.TouchViewWorker.java
com.resonos.apps.library.util.ViewServer.java
com.resonos.apps.library.widget.DashboardLayout.java
com.resonos.apps.library.widget.FormBuilder.java
com.resonos.apps.library.widget.FormElement.java
com.resonos.apps.library.widget.ListFormBuilder.java
com.resonos.apps.library.widget.PopupWindows3D.java
com.resonos.apps.library.widget.QuickAction3D.java
com.resonos.apps.library.widget.RangeSeekBar.java
com.resonos.apps.library.widget.SeekBar.java
com.resonos.apps.library.widget.ToolBarButton.java
com.resonos.apps.library.widget.ToolBar.java