MobileDeviceImpl.java 2.18 KB
/*
 * Decompiled with CFR 0_118.
 */
package com.adobe.cq.mobile.platform.impl.store;

import com.adobe.cq.mobile.platform.impl.store.FixedScreenSize;
import com.adobe.cq.mobile.platform.impl.store.MobileDevice;
import com.adobe.cq.mobile.platform.impl.store.ScreenDefinition;
import com.adobe.cq.mobile.platform.impl.store.VariableScreenSize;
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class MobileDeviceImpl
implements MobileDevice {
    private final String title;
    private final String id;
    private List<ScreenDefinition> screenDefinitions;

    private MobileDeviceImpl(String id, String title) {
        this.id = id;
        this.title = title;
    }

    public /* varargs */ MobileDeviceImpl(String id, String title, Dimension ... dimension) {
        this(id, title);
        ArrayList<FixedScreenSize> screenList = new ArrayList<FixedScreenSize>();
        for (Dimension dim : dimension) {
            screenList.add(new FixedScreenSize((int)dim.getWidth(), (int)dim.getHeight()));
        }
        this.screenDefinitions = Collections.unmodifiableList(screenList);
    }

    public MobileDeviceImpl(String id, String title, int min, int max, double ratio) {
        this(id, title, new VariableScreenSize(min, max, ratio));
    }

    public /* varargs */ MobileDeviceImpl(String id, String title, ScreenDefinition ... screenDefinitions) {
        this(id, title);
        this.screenDefinitions = Collections.unmodifiableList(Arrays.asList(screenDefinitions));
    }

    @Override
    public String getId() {
        return this.id;
    }

    @Override
    public String getTitle() {
        return this.title;
    }

    @Override
    public boolean isDimensionSupported(Dimension dimension) {
        if (dimension == null) {
            return false;
        }
        for (ScreenDefinition screen : this.screenDefinitions) {
            if (!screen.imageFits((int)dimension.getWidth(), (int)dimension.getHeight())) continue;
            return true;
        }
        return false;
    }

    @Override
    public List<ScreenDefinition> getSupportedScreens() {
        return this.screenDefinitions;
    }
}