类android.graphics.drawable.GradientDrawable.Orientation源码实例Demo

下面列出了怎么用android.graphics.drawable.GradientDrawable.Orientation的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: brailleback   文件: SearchView.java
public SearchView(Context context, StringBuilder queryText) {
    super(context);

    mContext = context;
    mQueryText = queryText;

    mPaint = new Paint();
    mPaint.setAntiAlias(true);

    final SurfaceHolder holder = getHolder();
    holder.setFormat(PixelFormat.TRANSLUCENT);
    holder.addCallback(mSurfaceCallback);

    final Resources res = context.getResources();

    int mExtremeRadius = 128;

    // Gradient colors.
    final int gradientInnerColor = res.getColor(R.color.search_overlay);
    final int gradientOuterColor = res.getColor(R.color.search_overlay);
    final int[] colors = new int[] {gradientInnerColor, gradientOuterColor};
    mGradientBackground =
            new GradientDrawable(Orientation.TOP_BOTTOM, colors);
    mGradientBackground.setGradientType(GradientDrawable.LINEAR_GRADIENT);
}
 
/**
 * Initializes the views.
 *
 * @param rootView View that contains all the content, such as the label, gradient view, etc.
 * @param textResourceId The resource ID of the text to show on the label.
 * @param seekBarMax The range of the seek bar.
 * @param seekBarListener The listener for when the seek bar value changes.
 */
ColorPickerAdvancedComponent(final View rootView,
        final int textResourceId,
        final int seekBarMax,
        final OnSeekBarChangeListener seekBarListener) {
    mGradientView = rootView.findViewById(R.id.gradient);
    mText = (TextView) rootView.findViewById(R.id.text);
    mText.setText(textResourceId);
    mGradientDrawable = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, null);
    mSeekBar = (SeekBar) rootView.findViewById(R.id.seek_bar);
    mSeekBar.setOnSeekBarChangeListener(seekBarListener);
    mSeekBar.setMax(seekBarMax);
    // Setting the thumb offset means the seek bar thumb can move all the way to each end
    // of the gradient view.
    Context context = rootView.getContext();
    int offset = context.getResources()
                        .getDrawable(R.drawable.color_picker_advanced_select_handle)
                        .getIntrinsicWidth();
    mSeekBar.setThumbOffset(offset / 2);
}
 
/**
 * Initializes the views.
 *
 * @param rootView View that contains all the content, such as the label, gradient view, etc.
 * @param textResourceId The resource ID of the text to show on the label.
 * @param seekBarMax The range of the seek bar.
 * @param seekBarListener The listener for when the seek bar value changes.
 */
ColorPickerAdvancedComponent(final View rootView,
        final int textResourceId,
        final int seekBarMax,
        final OnSeekBarChangeListener seekBarListener) {
    mGradientView = rootView.findViewById(R.id.gradient);
    mText = (TextView) rootView.findViewById(R.id.text);
    mText.setText(textResourceId);
    mGradientDrawable = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, null);
    mSeekBar = (SeekBar) rootView.findViewById(R.id.seek_bar);
    mSeekBar.setOnSeekBarChangeListener(seekBarListener);
    mSeekBar.setMax(seekBarMax);
    // Setting the thumb offset means the seek bar thumb can move all the way to each end
    // of the gradient view.
    Context context = rootView.getContext();
    int offset = context.getResources()
                        .getDrawable(R.drawable.color_picker_advanced_select_handle)
                        .getIntrinsicWidth();
    mSeekBar.setThumbOffset(offset / 2);
}
 
源代码4 项目: geopaparazzi   文件: FormListFragment.java
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    List<String> fragmentTitles = mFragmentListSupporter.getListTitles();

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_activated_1,
            fragmentTitles.toArray(new String[fragmentTitles.size()]));

    int color = Compat.getColor(getActivity(), R.color.formcolor);
    int[] colors = {0, color, 0};
    ListView listView = getListView();
    listView.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
    listView.setDividerHeight(2);

    listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    listView.setFocusableInTouchMode(true);
    StateListDrawable selector = new StateListDrawable();
    selector.addState(new int[]{-android.R.attr.state_pressed}, new ColorDrawable(Compat.getColor(getContext(), R.color.main_selection)));
    listView.setSelector(selector);

    setListAdapter(adapter);

    if (fragmentTitles.size() > 0)
        listView.setItemChecked(0, true);
}
 
源代码5 项目: actual-number-picker   文件: Coloring.java
/**
 * Creates a new drawable (implementation of the Drawable object may vary depending on OS version).<br>
 * Drawable will be colored with given color, and clipped to match given boundaries.
 *
 * @param color Integer color used to color the output drawable
 * @param bounds Four-dimensional vector bounds
 * @return Colored and clipped drawable object
 */
@SuppressWarnings("UnusedDeclaration")
public Drawable createDrawable(int color, Rect bounds) {
    // init normal state drawable
    Drawable drawable = new GradientDrawable(Orientation.BOTTOM_TOP, new int[] {
            color, color
    }).mutate();
    if (color == Color.TRANSPARENT) {
        drawable.setAlpha(0);
    }
    drawable.setBounds(bounds);
    return drawable;
}
 
/**
 * Sets the colors for the gradient view to interpolate through.
 *
 * @param newColors The set of colors representing the interpolation points for the gradient.
 */
public void setGradientColors(int[] newColors) {
    mGradientColors = newColors.clone();
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        Orientation currentOrientation = Orientation.LEFT_RIGHT;
        mGradientDrawable = new GradientDrawable(currentOrientation, mGradientColors);
    } else {
        mGradientDrawable.setColors(mGradientColors);
    }
    ApiCompatibilityUtils.setBackgroundForView(mGradientView, mGradientDrawable);
}
 
/**
 * Sets the colors for the gradient view to interpolate through.
 *
 * @param newColors The set of colors representing the interpolation points for the gradient.
 */
public void setGradientColors(int[] newColors) {
    mGradientColors = newColors.clone();
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        Orientation currentOrientation = Orientation.LEFT_RIGHT;
        mGradientDrawable = new GradientDrawable(currentOrientation, mGradientColors);
    } else {
        mGradientDrawable.setColors(mGradientColors);
    }
    ApiCompatibilityUtils.setBackgroundForView(mGradientView, mGradientDrawable);
}
 
源代码8 项目: actual-number-picker   文件: Coloring.java
/**
 * Creates a new {@code StateListDrawable} drawable. States that should be provided are "normal",<br>
 * "clicked" (pressed) and "checked" (selected). All states are actually integer colors.<br>
 * Optionally, {@code shouldFade} can be set to false to avoid the fading effect.<br>
 * <br>
 * Note: <i>{@link Color#TRANSPARENT} can be used to supply a transparent state.</i>
 *
 * @param normal Color for the idle state
 * @param clicked Color for the clicked/pressed state
 * @param checked Color for the checked/selected state
 * @param shouldFade Set to true to enable the fading effect, false otherwise
 * @return A {@link StateListDrawable} drawable object ready for use
 */
@SuppressLint({
        "InlinedApi", "NewApi"
})
public Drawable createStateDrawable(int normal, int clicked, int checked, boolean shouldFade) {
    // init state arrays
    int[] selectedState = new int[] {
            android.R.attr.state_selected
    };
    int[] pressedState = new int[] {
            android.R.attr.state_pressed
    };
    int[] checkedState = new int[] {
            android.R.attr.state_checked
    };
    int[] focusedState = new int[] {
            android.R.attr.state_focused
    };
    int[] activatedState = new int[] {};
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) {
        activatedState = new int[] {
                android.R.attr.state_activated
        };
    }

    // init normal state drawable
    Drawable normalDrawable = new GradientDrawable(Orientation.BOTTOM_TOP, new int[] {
            normal, normal
    }).mutate();
    if (normal == Color.TRANSPARENT)
        normalDrawable.setAlpha(0);
    else
        normalDrawable.setBounds(BOUNDS, BOUNDS, BOUNDS, BOUNDS);

    // init clicked state drawable
    Drawable clickedDrawable = new GradientDrawable(Orientation.BOTTOM_TOP, new int[] {
            clicked, clicked
    }).mutate();
    if (clicked == Color.TRANSPARENT)
        clickedDrawable.setAlpha(0);
    else
        clickedDrawable.setBounds(BOUNDS, BOUNDS, BOUNDS, BOUNDS);

    // init checked state drawable
    Drawable checkedDrawable = new GradientDrawable(Orientation.BOTTOM_TOP, new int[] {
            checked, checked
    }).mutate();
    if (checked == Color.TRANSPARENT)
        checkedDrawable.setAlpha(0);
    else
        checkedDrawable.setBounds(BOUNDS, BOUNDS, BOUNDS, BOUNDS);

    // init focused state drawable (use normal color)
    Drawable focusedDrawable = new GradientDrawable(Orientation.BOTTOM_TOP, new int[] {
            normal, normal
    }).mutate();
    if (normal == Color.TRANSPARENT)
        focusedDrawable.setAlpha(0);
    else
        focusedDrawable.setBounds(BOUNDS, BOUNDS, BOUNDS, BOUNDS);

    // prepare state list (order of adding states is important!)
    StateListDrawable states = new StateListDrawable();
    states.addState(pressedState, clickedDrawable);
    if (!shouldFade) {
        states.addState(selectedState, clickedDrawable);
        states.addState(focusedState, focusedDrawable);
        states.addState(checkedState, checkedDrawable);
    }

    // add fade effect if applicable
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) {
        if (shouldFade) {
            states.addState(new int[] {}, normalDrawable);
            states.setEnterFadeDuration(0);
            states.setExitFadeDuration(FADE_DURATION);
        } else {
            states.addState(activatedState, clickedDrawable);
            states.addState(new int[] {}, normalDrawable);
        }
    } else {
        states.addState(new int[] {}, normalDrawable);
    }

    return states;
}
 
源代码9 项目: XCL-Charts   文件: AboutActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	requestWindowFeature(Window.FEATURE_NO_TITLE); // 设置没标题
	setContentView(R.layout.activity_about);

	GradientDrawable grad = new GradientDrawable(// 渐变色 WHITE
			Orientation.TOP_BOTTOM, new int[] {
					Color.rgb(133, 224, 224),
					Color.rgb(51, 136, 103) });
	getWindow().setBackgroundDrawable(grad);

	TextView tv_title = (TextView) findViewById(R.id.tv_title);
	String html = "<big><font color ='red'>XCL-Charts</font></big><br/>"			
			+ "&nbsp;&nbsp;&nbsp;&nbsp;版本: 2.4<br/>"
			+ "&nbsp;&nbsp;&nbsp;&nbsp;最后更新: 2015-09-26<br/>"
			+ "&nbsp;&nbsp;&nbsp;&nbsp;QQ交流群: 374780627<br/>"
				+ "<big><font color ='red'>License</font></big><br/>"
			+ "&nbsp;&nbsp;&nbsp;&nbsp;Apache v2 License开源协议。"
			+ "<br/><big><font color ='red'>代码托管地址</font></big><br/>"
			+ "<br/>GitHub:https://github.com/xcltapestry/XCL-Charts" ;
	CharSequence charSequence = Html.fromHtml(html);
	tv_title.setText(charSequence);
	tv_title.setMovementMethod(LinkMovementMethod.getInstance());

	TextView tv_info = (TextView) findViewById(R.id.tv_info);
	final String htmlInfo = "<html><head><title></title></head><body>"
			+ " <br/><big>About the Author</big>"
			+ " <br/><b>熊传亮</b>"
			+ "   <br/>&nbsp;&nbsp;&nbsp;&nbsp;有Oracle 10g OCP 及IBM Certified Systems Expert认证," +
			"会点数据库、C/C++、Golang、挂着架构师的空名头,其实就一做后台的。 "
			+ " <b>^_^</b>"		
			+ " <br/><br/>有什么改进或建议可发邮件联系或至博客留言。 "
			+ " <br/><big>Blog:http://blog.csdn.net/xcl168</big> "
			+ " <br/><big>Mail:[email protected]</big> "
			+ " <br/><br/>感谢 cubehead、cmeiyuan、cheyiliu、Pand、哈哈、chenqiang等提交代码及其它网友的支持与反馈。"
			
			+ "</body></html>";
	CharSequence charSequenceInfo = Html.fromHtml(htmlInfo);
	tv_info.setText(charSequenceInfo);
	tv_info.setMovementMethod(LinkMovementMethod.getInstance());
}
 
源代码10 项目: SlotMachine   文件: WheelView.java
void init(Context context) {
	
	mFullViewRect = new Rect();
	
	mReelScroller = new SlotReelScroller(context, this);
	
	mWhiteBackgroundPaint = new Paint();
	mWhiteBackgroundPaint.setColor(Color.WHITE);

	topShadow = new GradientDrawable(Orientation.TOP_BOTTOM, SHADOWS_COLORS);
	bottomShadow = new GradientDrawable(Orientation.BOTTOM_TOP, SHADOWS_COLORS);
	
	mSlotItems = new ArrayList<DrawSlotItem>();		
}
 
 类方法
 同包方法