Example usage for android.graphics.drawable ShapeDrawable draw

List of usage examples for android.graphics.drawable ShapeDrawable draw

Introduction

In this page you can find the example usage for android.graphics.drawable ShapeDrawable draw.

Prototype

@Override
    public void draw(Canvas canvas) 

Source Link

Usage

From source file:eu.trentorise.smartcampus.widget.shortcuts.StackWidgetService.java

@Override
public RemoteViews getViewAt(int position) {
    // position will always range from 0 to getCount() - 1.

    // We construct a remote views item based on our widget item xml
    // file, and set the
    // text based on the position.
    RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.widget_item);
    ShapeDrawable sd1 = new ShapeDrawable(new RectShape());
    sd1.getPaint().setColor(0xFFFFFFFF);
    sd1.getPaint().setStyle(Style.STROKE);
    sd1.getPaint().setStrokeWidth(1);/*from   w w  w  .  jav  a  2 s  .  c  o  m*/
    Canvas c = new Canvas();
    sd1.draw(c);
    Bitmap b = Bitmap.createBitmap(120, 120, Bitmap.Config.ARGB_8888);
    c.drawBitmap(b, 0, 0, sd1.getPaint());
    // Next, we set a fill-intent which will be used to fill-in the
    // pending intent template
    // which is set on the collection view in StackWidgetProvider.

    if (ALLPREFERENCES != null && ALLPREFERENCES[position] != null) { //ALLPREFERENCES  dimensionato come le preferenze selezionate

        BookmarkDescriptor myDescriptor = ALLPREFERENCES[position];

        // set the widgetbutton
        if (WidgetHelper.PARAM_TYPE.equals(myDescriptor.params.get(0).name)) { //controllare con gli input da config activity?
            String type = myDescriptor.params.get(0).value;
            if (WidgetHelper.TYPE_DT.equals(type)) {
                // dt -> put icons and hide text
                rv.setViewVisibility(R.id.text_widget_item, View.GONE);
                rv.setImageViewResource(R.id.image_widget_item,
                        Integer.parseInt(myDescriptor.params.get(2).value));

                rv.setInt(R.id.image_widget_item, "setBackgroundResource", R.drawable.rounded_border_dt);

            } else if (WidgetHelper.TYPE_JP.equals(type)) {
                // jp -> put text and hide icon

                rv.setViewVisibility(R.id.image_widget_item, View.GONE);
                // rv.setImageViewBitmap(R.id.text_widget_item,
                // getBackground(Color.parseColor("#6EB046")));
                if (!("0".equals(myDescriptor.params.get(2).value))) {
                    //bus
                    rv.setTextViewTextSize(R.id.text_widget_item, TypedValue.COMPLEX_UNIT_DIP, 80);

                    rv.setTextViewText(R.id.text_widget_item, RoutesHelper.getShortNameByRouteIdAndAgencyID(
                            myDescriptor.params.get(4).value, myDescriptor.params.get(3).value)); //4,3
                    rv.setTextColor(R.id.text_widget_item, Integer.parseInt(myDescriptor.params.get(2).value));//rv.setInt(R.id.text_widget_item, "setBackgroundColor",
                    //Integer.parseInt(myDescriptor.params.get(2).value));
                    rv.setInt(R.id.text_widget_item, "setBackgroundResource", R.drawable.rounded_border_jp);

                } else {
                    //train
                    rv.setTextViewTextSize(R.id.text_widget_item, TypedValue.COMPLEX_UNIT_DIP, 12);
                    //controllo contesto getRouteDescriptor i vari parametri
                    rv.setTextViewText(R.id.text_widget_item,
                            mContext.getString(
                                    RoutesHelper.getRouteDescriptorByRouteId(myDescriptor.params.get(3).value,
                                            myDescriptor.params.get(4).value).getNameResource()));
                    rv.setTextColor(R.id.text_widget_item, Color.BLACK);//Int(R.id.text_widget_item, "setBackgroundColor",Color.BLACK);
                    rv.setInt(R.id.text_widget_item, "setBackgroundResource", R.drawable.rounded_border_jp);

                }

            } else if (WidgetHelper.TYPE_JP_PARKINGS.equals(type)) {
                // jp parcheggio -> put text and hide icon
                rv.setViewVisibility(R.id.text_widget_item, View.GONE);
                rv.setImageViewResource(R.id.image_widget_item,
                        Integer.parseInt(myDescriptor.params.get(2).value));
                rv.setInt(R.id.image_widget_item, "setBackgroundResource", R.drawable.rounded_border_jp);

            }
            BookmarkDescriptor bookmark = myDescriptor;
            Bundle extras = new Bundle();
            extras.putString(StackWidgetProvider.EXTRA_INTENT, bookmark.getIntent());
            if (bookmark.getParams() != null) {
                for (Param param : bookmark.getParams()) {
                    extras.putString(param.name, param.value);

                }

            }
            Intent fillInIntent = new Intent(bookmark.getIntent());
            fillInIntent.putExtras(extras);
            rv.setOnClickFillInIntent(R.id.layout, fillInIntent);
        }

    }
    // Return the remote views object.
    // AppWidgetManager manager = AppWidgetManager.getInstance(mContext);
    // manager.updateAppWidget(thisWidget, rv);
    return rv;
}