예제 #1
0
파일: WidgetView.java 프로젝트: fesch/CanZE
 public void setDrawable(Drawable drawable) {
   this.drawable = drawable;
   // if(drawable.getDrawSurface()==null)
   drawable.setDrawSurface(this);
   repaint();
 }
예제 #2
0
  public void init(final Context context, AttributeSet attrs) {
    // register our interest in hearing about changes to our surface
    SurfaceHolder holder = getHolder();
    holder.addCallback(this);
    // make sure we get key events
    setFocusable(true);

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);

    // read attributes
    if (attrs != null) {
      try {
        // create configured widget
        String[] widgets = {
          "Tacho", "Kompass", "Bar", "BatteryBar", "Plotter", "Label", "Timeplot", "BarGraph"
        };
        TypedArray attributes =
            context.getTheme().obtainStyledAttributes(attrs, R.styleable.WidgetView, 0, 0);
        int widgetIndex = attributes.getInt(R.styleable.WidgetView_widget, 0);
        if (widgetIndex < widgets.length) {
          String widget = widgets[widgetIndex];
          // MainActivity.debug("WidgetView: I am a "+widget);
          Class clazz = Class.forName("lu.fisch.canze.widgets." + widget);
          Constructor<?> constructor = clazz.getConstructor(null);
          drawable = (Drawable) constructor.newInstance();
          drawable.setDrawSurface(this);
          // apply attributes
          setMin(attributes.getInt(R.styleable.WidgetView_min, 0));
          setMax(attributes.getInt(R.styleable.WidgetView_max, 0));
          setMajorTicks(attributes.getInt(R.styleable.WidgetView_majorTicks, 0));
          setMinorTicks(attributes.getInt(R.styleable.WidgetView_minorTicks, 0));
          setTitle(attributes.getString(R.styleable.WidgetView_text));
          setShowLabels(attributes.getBoolean(R.styleable.WidgetView_showLabels, true));
          setShowValue(attributes.getBoolean(R.styleable.WidgetView_showValue, true));
          setInverted(attributes.getBoolean(R.styleable.WidgetView_isInverted, false));
          fieldSID = attributes.getString(R.styleable.WidgetView_fieldSID);

          String colorRangesJson = attributes.getString(R.styleable.WidgetView_colorRanges);
          if (!colorRangesJson.trim().isEmpty())
            setColorRanges(new ColorRanges(colorRangesJson.replace("'", "\"")));

          // MainActivity.debug("WidgetView: My SID is "+fieldSID);

          if (MainActivity.milesMode) setTitle(drawable.getTitle().replace("km", "mi"));

          repaint();
        } else {
          MainActivity.debug(
              "WidgetIndex " + widgetIndex + " is wrong!? Not registered in <WidgetView>?");
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    // in case your application needs one or more timers,
    // you have to put them here
    /*Timer timer = new Timer();
          timer.schedule(new TimerTask() {
    	@Override
    	public void run() {
    		repaint();
    	}
    }, 100, 100);
    */
  }
예제 #3
0
파일: WidgetView.java 프로젝트: fesch/CanZE
 public void reset() {
   drawable.reset();
   repaint();
 }
예제 #4
0
 @Override
 public void surfaceCreated(SurfaceHolder arg0) {
   // do a first painting
   repaint();
 }