Search in sources :

Example 1 with ActivityListElement

use of org.netxms.ui.android.main.views.ActivityListElement in project netxms by netxms.

the class ActivityListAdapter method getView.

/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getView(int, android.view.View,
	 * android.view.ViewGroup)
	 */
@SuppressWarnings("deprecation")
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ActivityListElement view = null;
    if (position >= 0 && position < getCount()) {
        if (convertView == null) {
            view = new ActivityListElement(context, imageId[position], textId[position]);
            view.setLayoutParams(new GridView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        } else {
            view = (ActivityListElement) convertView;
        }
        Drawable infoLayer = null;
        switch(activityId[position]) {
            case HomeScreen.ACTIVITY_ALARMS:
                if (numAlarms > 0)
                    infoLayer = parent.getResources().getDrawable(numAlarms >= MAX_ALARMS ? alarmId[0] : alarmId[numAlarms]);
                break;
            case HomeScreen.ACTIVITY_NODES:
            case HomeScreen.ACTIVITY_ENTIRENETWORK:
            case HomeScreen.ACTIVITY_DASHBOARDS:
                if (topNodes != null) {
                    AbstractObject obj = topNodes.get(activityId[position]);
                    if (obj != null) {
                        switch(obj.getStatus()) {
                            case WARNING:
                            case MINOR:
                            case MAJOR:
                            case CRITICAL:
                                infoLayer = parent.getResources().getDrawable(statusImageId[obj.getStatus().getValue()]);
                                break;
                            case NORMAL:
                            case UNKNOWN:
                            case UNMANAGED:
                            case DISABLED:
                            case TESTING:
                            default:
                                break;
                        }
                    }
                }
                break;
        }
        Drawable[] layers;
        if (infoLayer != null) {
            layers = new Drawable[2];
            layers[1] = infoLayer;
        } else
            layers = new Drawable[1];
        layers[0] = parent.getResources().getDrawable(imageId[position]);
        ImageView objectIcon = (ImageView) view.getChildAt(0);
        LayerDrawable drawable = new LayerDrawable(layers);
        if (layers.length > 1)
            drawable.setLayerInset(1, layers[0].getIntrinsicWidth() - layers[1].getIntrinsicWidth(), layers[0].getIntrinsicHeight() - layers[1].getIntrinsicHeight(), 0, 0);
        objectIcon.setImageDrawable(drawable);
    }
    return view;
}
Also used : AbstractObject(org.netxms.client.objects.AbstractObject) LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) Drawable(android.graphics.drawable.Drawable) GridView(android.widget.GridView) ImageView(android.widget.ImageView) ActivityListElement(org.netxms.ui.android.main.views.ActivityListElement)

Aggregations

Drawable (android.graphics.drawable.Drawable)1 LayerDrawable (android.graphics.drawable.LayerDrawable)1 GridView (android.widget.GridView)1 ImageView (android.widget.ImageView)1 AbstractObject (org.netxms.client.objects.AbstractObject)1 ActivityListElement (org.netxms.ui.android.main.views.ActivityListElement)1