001/** 002 * Copyright 2013 John Ericksen 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.androidtransfuse.experiment.generators; 017 018import org.androidtransfuse.adapter.ASTType; 019import org.androidtransfuse.analysis.MetaDataBuilder; 020import org.androidtransfuse.annotations.Application; 021import org.androidtransfuse.annotations.UIOptions; 022import org.androidtransfuse.experiment.ComponentBuilder; 023import org.androidtransfuse.experiment.ComponentDescriptor; 024import org.androidtransfuse.experiment.ComponentPartGenerator; 025import org.androidtransfuse.experiment.Generation; 026import org.androidtransfuse.processor.ManifestManager; 027 028import javax.inject.Inject; 029import javax.inject.Provider; 030 031import static org.androidtransfuse.util.AnnotationUtil.checkBlank; 032import static org.androidtransfuse.util.AnnotationUtil.checkDefault; 033 034/** 035 * @author John Ericksen 036 */ 037public class ApplicationManifestEntryGenerator implements Generation { 038 039 private final MetaDataBuilder metadataBuilder; 040 private final ManifestManager manifestManager; 041 private final Provider<org.androidtransfuse.model.manifest.Application> applicationProvider; 042 043 @Inject 044 public ApplicationManifestEntryGenerator(MetaDataBuilder metadataBuilder, 045 ManifestManager manifestManager, 046 Provider<org.androidtransfuse.model.manifest.Application> applicationProvider) { 047 this.metadataBuilder = metadataBuilder; 048 this.manifestManager = manifestManager; 049 this.applicationProvider = applicationProvider; 050 } 051 052 @Override 053 public void schedule(ComponentBuilder builder, ComponentDescriptor descriptor) { 054 055 if(descriptor.getTarget() != null && descriptor.getTarget().isAnnotated(Application.class)) { 056 builder.add(new ComponentPartGenerator() { 057 public void generate(ComponentDescriptor descriptor) { 058 Application applicationAnnotation = descriptor.getTarget().getAnnotation(Application.class); 059 ASTType type = descriptor.getTarget(); 060 061 org.androidtransfuse.model.manifest.Application manifestApplication = buildManifestEntry(descriptor.getPackageClass().getFullyQualifiedName(), applicationAnnotation); 062 063 manifestApplication.setMetaData(metadataBuilder.buildMetaData(type)); 064 065 manifestManager.addApplication(manifestApplication); 066 } 067 }); 068 } 069 } 070 071 private org.androidtransfuse.model.manifest.Application buildManifestEntry(String name, Application annotation) { 072 073 org.androidtransfuse.model.manifest.Application manifestApplication = applicationProvider.get(); 074 075 manifestApplication.setName(name); 076 077 manifestApplication.setLabel(checkBlank(annotation.label())); 078 manifestApplication.setAllowTaskReparenting(checkDefault(annotation.allowTaskReparenting(), false)); 079 manifestApplication.setBackupAgent(checkBlank(annotation.backupAgent())); 080 manifestApplication.setDebuggable(checkDefault(annotation.debuggable(), false)); 081 manifestApplication.setDescription(checkBlank(annotation.description())); 082 manifestApplication.setEnabled(checkDefault(annotation.enabled(), true)); 083 manifestApplication.setHasCode(checkDefault(annotation.hasCode(), true)); 084 manifestApplication.setHardwareAccelerated(checkDefault(annotation.hardwareAccelerated(), false)); 085 manifestApplication.setIcon(checkBlank(annotation.icon())); 086 manifestApplication.setKillAfterRestore(checkDefault(annotation.killAfterRestore(), true)); 087 manifestApplication.setLogo(checkBlank(annotation.logo())); 088 manifestApplication.setManageSpaceActivity(checkBlank(annotation.manageSpaceActivity())); 089 manifestApplication.setPermission(checkBlank(annotation.permission())); 090 manifestApplication.setPersistent(checkDefault(annotation.persistent(), false)); 091 manifestApplication.setProcess(checkBlank(annotation.process())); 092 manifestApplication.setRestoreAnyVersion(checkDefault(annotation.restoreAnyVersion(), false)); 093 manifestApplication.setTaskAffinity(checkBlank(annotation.taskAffinity())); 094 manifestApplication.setTheme(checkBlank(annotation.theme())); 095 manifestApplication.setUiOptions(checkDefault(annotation.uiOptions(), UIOptions.NONE)); 096 manifestApplication.setAllowBackup(annotation.allowBackup()); 097 manifestApplication.setLargeHeap(checkDefault(annotation.largeHeap(), false)); 098 manifestApplication.setSupportsRtl(checkDefault(annotation.supportsRtl(), false)); 099 manifestApplication.setRestrictedAccountType(checkDefault(annotation.restrictedAccountType(), false)); 100 manifestApplication.setVmSafeMode(checkDefault(annotation.vmSafeMode(), false)); 101 manifestApplication.setTestOnly(checkDefault(annotation.testOnly(), false)); 102 manifestApplication.setRequiredAccountType(checkBlank(annotation.requiredAccountType())); 103 104 return manifestApplication; 105 } 106 107}