Skip to content

Commit

Permalink
Manifest application & activity class name methods
Browse files Browse the repository at this point in the history
  • Loading branch information
REAndroid committed Mar 2, 2024
1 parent 8708b57 commit 348b542
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/main/java/com/reandroid/app/AndroidManifest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ public interface AndroidManifest {

String getPackageName();
void setPackageName(String packageName);

String getApplicationClassName();
void setApplicationClassName(String className);

String getMainActivityClassName();
void setMainActivityClassName(String className);

Integer getVersionCode();
void setVersionCode(int version);
String getVersionName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public ResXmlElement getOrCreateMainActivity(String name){
ResXmlElement activity = getMainActivity();
if(activity == null){
ResXmlElement application = getOrCreateApplicationElement();
activity = application.createChildElement(TAG_activity);
activity = application.createChildElement(0, TAG_activity);
ResXmlElement intentFilter = activity.createChildElement(TAG_intent_filter);
ResXmlElement action = intentFilter.createChildElement(TAG_action);
ResXmlAttribute attribute = action.getOrCreateAndroidAttribute(NAME_name, ID_name);
Expand Down Expand Up @@ -371,11 +371,43 @@ public String getPackageName(){
public void setPackageName(String packageName){
ResXmlElement manifestElement = getOrCreateManifestElement();
ResXmlAttribute attribute = manifestElement.getOrCreateAttribute(NAME_PACKAGE, 0);
if(attribute == null){
return;
}
attribute.setValueAsString(packageName);
}
@Override
public String getApplicationClassName(){
ResXmlElement applicationElement = getApplicationElement();
if(applicationElement != null){
ResXmlAttribute attribute = applicationElement
.searchAttributeByResourceId(ID_name);
if(attribute != null){
return fullClassName(attribute.getValueAsString());
}
}
return null;
}
@Override
public void setApplicationClassName(String className){
ResXmlAttribute attribute = getOrCreateApplicationElement()
.getOrCreateAndroidAttribute(NAME_name, ID_name);
attribute.setValueAsString(className);
}
@Override
public String getMainActivityClassName(){
ResXmlElement mainActivity = getMainActivity();
if(mainActivity != null){
ResXmlAttribute attribute = mainActivity
.searchAttributeByResourceId(ID_name);
if(attribute != null){
return fullClassName(attribute.getValueAsString());
}
}
return null;
}
@Override
public void setMainActivityClassName(String className){
getOrCreateMainActivity(className);
}

@Override
public Integer getVersionCode(){
return getManifestAttributeInt(ID_versionCode);
Expand Down Expand Up @@ -586,7 +618,7 @@ public void ensureFullClassNames(){
application.refresh();
}
public String fullClassName(String name){
if(name == null || !name.startsWith(".")){
if(name == null || name.length() == 0 || name.charAt(0) != '.'){
return name;
}
String packageName = getPackageName();
Expand Down

0 comments on commit 348b542

Please sign in to comment.