use of com.android.tools.idea.model.AndroidModuleInfo in project android by JetBrains.
the class NewAndroidComponentAction method update.
@Override
public void update(AnActionEvent e) {
DataContext dataContext = e.getDataContext();
Module module = LangDataKeys.MODULE.getData(dataContext);
if (module == null) {
return;
}
AndroidModuleInfo moduleInfo = AndroidModuleInfo.get(module);
if (moduleInfo == null) {
return;
}
Presentation presentation = e.getPresentation();
int moduleMinSdkVersion = moduleInfo.getMinSdkVersion().getApiLevel();
if (myMinSdkVersion > moduleMinSdkVersion) {
presentation.setText(AndroidBundle.message("android.wizard.action.requires.minsdk", myTemplateName, myMinSdkVersion));
presentation.setEnabled(false);
} else if (myRequireAppTheme) {
ThemeHelper themeHelper = new ThemeHelper(module);
if (themeHelper.getAppThemeName() == null) {
presentation.setText(AndroidBundle.message("android.wizard.action.no.app.theme", myTemplateName));
presentation.setEnabled(false);
}
}
}
use of com.android.tools.idea.model.AndroidModuleInfo in project android by JetBrains.
the class AddAndroidActivityPath method getDirectories.
private Map<String, Object> getDirectories() {
Map<String, Object> templateParameters = Maps.newHashMap();
Module module = getModule();
assert module != null;
AndroidFacet facet = AndroidFacet.getInstance(module);
assert facet != null;
AndroidPlatform platform = AndroidPlatform.getInstance(module);
if (platform != null) {
templateParameters.put(ATTR_BUILD_API, platform.getTarget().getVersion().getFeatureLevel());
templateParameters.put(ATTR_BUILD_API_STRING, getBuildApiString(platform.getTarget().getVersion()));
}
// Read minSdkVersion and package from manifest and/or build.gradle files
AndroidModuleInfo moduleInfo = AndroidModuleInfo.get(facet);
AndroidModel androidModel = facet.getAndroidModel();
SourceProvider sourceProvider1 = myState.get(KEY_SOURCE_PROVIDER);
if (sourceProvider1 != null && androidModel != null) {
String packageName = myState.get(KEY_PACKAGE_NAME);
assert packageName != null;
templateParameters.putAll(selectSourceProvider(sourceProvider1, androidModel, module, packageName));
}
AndroidVersion minSdkVersion = moduleInfo.getMinSdkVersion();
String minSdkName = minSdkVersion.getApiString();
templateParameters.put(ATTR_MIN_API, minSdkName);
templateParameters.put(ATTR_TARGET_API, moduleInfo.getTargetSdkVersion().getApiLevel());
templateParameters.put(ATTR_MIN_API_LEVEL, minSdkVersion.getFeatureLevel());
templateParameters.put(ATTR_IS_LIBRARY_MODULE, facet.isLibraryProject());
try {
templateParameters.put(ATTR_DEBUG_KEYSTORE_SHA1, KeystoreUtils.sha1(getDebugKeystore(facet)));
} catch (Exception e) {
LOG.info("Could not compute SHA1 hash of debug keystore.", e);
templateParameters.put(ATTR_DEBUG_KEYSTORE_SHA1, "");
}
@SuppressWarnings("deprecation") String projectLocation = NewModuleWizardState.ATTR_PROJECT_LOCATION;
Project project = getProject();
assert project != null;
templateParameters.put(projectLocation, project.getBasePath());
// We're really interested in the directory name on disk, not the module name. These will be different if you give a module the same
// name as its containing project.
String moduleName = new File(module.getModuleFilePath()).getParentFile().getName();
templateParameters.put(FormFactorUtils.ATTR_MODULE_NAME, moduleName);
return templateParameters;
}
use of com.android.tools.idea.model.AndroidModuleInfo in project android by JetBrains.
the class ConvertToWebpAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
Project project = e.getProject();
if (project == null) {
return;
}
Module module = e.getData(LangDataKeys.MODULE);
if (module == null) {
module = e.getData(LangDataKeys.MODULE_CONTEXT);
}
int minSdkVersion = Integer.MAX_VALUE;
if (module != null) {
AndroidModuleInfo info = AndroidModuleInfo.get(module);
if (info != null) {
minSdkVersion = Math.min(minSdkVersion, info.getMinSdkVersion().getFeatureLevel());
}
} else {
Module[] modules = e.getData(LangDataKeys.MODULE_CONTEXT_ARRAY);
if (modules != null) {
for (Module m : modules) {
AndroidModuleInfo info = AndroidModuleInfo.get(m);
if (info != null) {
minSdkVersion = Math.min(minSdkVersion, info.getMinSdkVersion().getFeatureLevel());
}
}
}
}
VirtualFile[] files = e.getRequiredData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
perform(project, minSdkVersion, files);
}
use of com.android.tools.idea.model.AndroidModuleInfo in project android by JetBrains.
the class ThemeEditorUtils method getMinApiLevel.
public static int getMinApiLevel(@NotNull Module module) {
AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet == null) {
return 1;
}
AndroidModuleInfo moduleInfo = AndroidModuleInfo.get(facet);
return moduleInfo.getMinSdkVersion().getApiLevel();
}
use of com.android.tools.idea.model.AndroidModuleInfo in project android by JetBrains.
the class ConfigureTemplateParametersStep method onProceeding.
/**
* When finished with this step, calculate and install a bunch of values that will be used in our
* template's <a href="http://freemarker.incubator.apache.org/docs/dgui_quickstart_basics.html">data model.</a>
*/
@Override
protected void onProceeding() {
// canGoForward guarantees this optional value is present
AndroidSourceSet sourceSet = getModel().getSourceSet().get();
AndroidProjectPaths paths = sourceSet.getPaths();
File moduleRoot = paths.getModuleRoot();
if (moduleRoot == null) {
getLog().error(String.format("%s failure: can't create files because module root is not found. Please report this error.", getTitle()));
return;
}
// Some parameter values should be saved for later runs through this wizard, so do that first.
for (RowEntry rowEntry : myParameterRows.values()) {
rowEntry.accept();
}
// Prepare the template data-model, starting from scratch and filling in all values we know
Map<String, Object> templateValues = getModel().getTemplateValues();
templateValues.clear();
for (Parameter parameter : myParameterRows.keySet()) {
ObservableValue<?> property = myParameterRows.get(parameter).getProperty();
if (property != null) {
templateValues.put(parameter.id, property.get());
}
}
templateValues.put(ATTR_PACKAGE_NAME, myPackageName.get());
templateValues.put(ATTR_SOURCE_PROVIDER_NAME, sourceSet.getName());
// Android Modules are called Gradle Projects
templateValues.put(ATTR_IS_NEW_PROJECT, isNewModule());
if (isNewModule()) {
templateValues.put(ATTR_IS_LAUNCHER, true);
}
try {
File sha1File = myFacet == null ? getOrCreateDefaultDebugKeystore() : getDebugKeystore(myFacet);
templateValues.put(ATTR_DEBUG_KEYSTORE_SHA1, KeystoreUtils.sha1(sha1File));
} catch (Exception e) {
getLog().info("Could not compute SHA1 hash of debug keystore.", e);
templateValues.put(ATTR_DEBUG_KEYSTORE_SHA1, "");
}
if (myFacet == null) {
// If we don't have an AndroidFacet, we must have the Android Sdk info
AndroidVersionsInfo.VersionItem buildVersion = getModel().androidSdkInfo().getValue();
templateValues.put(ATTR_MIN_API_LEVEL, buildVersion.getApiLevel());
templateValues.put(ATTR_MIN_API, buildVersion.getApiLevelStr());
templateValues.put(ATTR_BUILD_API, buildVersion.getBuildApiLevel());
templateValues.put(ATTR_BUILD_API_STRING, buildVersion.getBuildApiLevelStr());
templateValues.put(ATTR_TARGET_API, buildVersion.getTargetApiLevel());
templateValues.put(ATTR_TARGET_API_STRING, buildVersion.getTargetApiLevelStr());
} else {
AndroidPlatform platform = AndroidPlatform.getInstance(myFacet.getModule());
if (platform != null) {
templateValues.put(ATTR_BUILD_API, platform.getTarget().getVersion().getFeatureLevel());
templateValues.put(ATTR_BUILD_API_STRING, getBuildApiString(platform.getTarget().getVersion()));
}
AndroidModuleInfo moduleInfo = AndroidModuleInfo.get(myFacet);
AndroidVersion minSdkVersion = moduleInfo.getMinSdkVersion();
String minSdkName = minSdkVersion.getApiString();
templateValues.put(ATTR_MIN_API, minSdkName);
templateValues.put(ATTR_TARGET_API, moduleInfo.getTargetSdkVersion().getApiLevel());
templateValues.put(ATTR_MIN_API_LEVEL, minSdkVersion.getFeatureLevel());
templateValues.put(ATTR_IS_LIBRARY_MODULE, myFacet.isLibraryProject());
// Register application-wide settings
String applicationPackage = AndroidPackageUtils.getPackageForApplication(myFacet);
if (!myPackageName.get().equals(applicationPackage)) {
templateValues.put(ATTR_APPLICATION_PACKAGE, AndroidPackageUtils.getPackageForApplication(myFacet));
}
}
// Register the resource directories associated with the active source provider
templateValues.put(ATTR_PROJECT_OUT, FileUtil.toSystemIndependentName(moduleRoot.getAbsolutePath()));
String packageAsDir = myPackageName.get().replace('.', File.separatorChar);
File srcDir = paths.getSrcDirectory();
if (srcDir != null) {
srcDir = new File(srcDir, packageAsDir);
templateValues.put(ATTR_SRC_DIR, getRelativePath(moduleRoot, srcDir));
templateValues.put(ATTR_SRC_OUT, FileUtil.toSystemIndependentName(srcDir.getAbsolutePath()));
}
File testDir = paths.getTestDirectory();
if (testDir != null) {
testDir = new File(testDir, packageAsDir);
templateValues.put(ATTR_TEST_DIR, getRelativePath(moduleRoot, testDir));
templateValues.put(ATTR_TEST_OUT, FileUtil.toSystemIndependentName(testDir.getAbsolutePath()));
}
File resDir = paths.getResDirectory();
if (resDir != null) {
templateValues.put(ATTR_RES_DIR, getRelativePath(moduleRoot, resDir));
templateValues.put(ATTR_RES_OUT, FileUtil.toSystemIndependentName(resDir.getPath()));
}
File manifestDir = paths.getManifestDirectory();
if (manifestDir != null) {
templateValues.put(ATTR_MANIFEST_DIR, getRelativePath(moduleRoot, manifestDir));
templateValues.put(ATTR_MANIFEST_OUT, FileUtil.toSystemIndependentName(manifestDir.getPath()));
}
File aidlDir = paths.getAidlDirectory();
if (aidlDir != null) {
templateValues.put(ATTR_AIDL_DIR, getRelativePath(moduleRoot, aidlDir));
templateValues.put(ATTR_AIDL_OUT, FileUtil.toSystemIndependentName(aidlDir.getPath()));
}
templateValues.put(PROJECT_LOCATION_ID, moduleRoot.getParent());
// We're really interested in the directory name on disk, not the module name. These will be different if you give a module the same
// name as its containing project.
String moduleName = moduleRoot.getName();
templateValues.put(ATTR_MODULE_NAME, moduleName);
}
Aggregations