public static string ActivityXML(Design design) { StringBuilder sb = new StringBuilder(); sb.AppendLine("<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\""); sb.AppendLine(" xmlns:tools=\"http://schemas.android.com/tools\""); sb.AppendLine(" android:orientation=\"vertical\""); sb.AppendLine(" android:layout_width=\"match_parent\""); sb.AppendLine(" android:layout_height=\"match_parent\""); sb.AppendLine(string.Format(" tools:context=\"{0}.activity.{1}\">", design.OrgURL, design.ActivityName)); sb.AppendLine(); if (design.ActionBar != null) { string actionbarXML = design.ActionBar.CreateActivityLayoutXML(1); sb.AppendLine(actionbarXML); } sb.AppendLine(); if (design.Widgets != null) { for (int i = 0; i < design.Widgets.Count; i++) { string widgetXML = design.Widgets[i].CreateActivityLayoutXML(1); sb.AppendLine(widgetXML); sb.AppendLine(); } } sb.AppendLine("</LinearLayout>"); return sb.ToString(); }
public static string ActivityJavaCode(Design design) { StringBuilder sb = new StringBuilder(); sb.AppendLine(string.Format("package {0}.{1}.activity;", design.OrgURL, design.AppName)); sb.AppendLine(); sb.AppendLine("import android.support.v7.app.AppCompatActivity;"); if (design.ActionBar != null) sb.AppendLine("import android.support.v7.widget.Toolbar;"); sb.AppendLine(); if (design.ActionBar != null) sb.AppendLine("import org.androidannotations.annotations.AfterViews;"); sb.AppendLine(string.Format("import {0}.{1}.R;", design.OrgURL, design.AppName)); if (design.ActionBar != null) sb.AppendLine("import org.androidannotations.annotations.ViewById;"); sb.AppendLine(); sb.AppendLine("import org.androidannotations.annotations.EActivity;"); sb.AppendLine(); sb.AppendLine(string.Format("@EActivity (R.layout.{0})", design.LayoutName)); sb.AppendLine(string.Format("public class {0} extends AppCompatActivity ", design.ActivityName) + "{"); if (design.ActionBar != null) { sb.AppendLine(" @ViewById"); sb.AppendLine(" Toolbar toolbar;"); sb.AppendLine(); sb.AppendLine(" @AfterViews"); sb.AppendLine(" void init() {"); sb.AppendLine(" setSupportActionBar(toolbar);"); sb.AppendLine(" }"); } sb.AppendLine("}"); sb.AppendLine(); return sb.ToString(); }
public frmSegmentAnalysis(Bitmap segment, Color backgroundColour, Design design) { InitializeComponent(); _segment = segment; _backgroundColour = backgroundColour; _design = design; cmbType.Items.Add(((ViewType)0).ToString()); cmbType.Items.Add(((ViewType)1).ToString()); cmbType.Items.Add(((ViewType)2).ToString()); cmbType.Items.Add(((ViewType)3).ToString()); cmbType.Items.Add(((ViewType)4).ToString()); cmbType.Items.Add(((ViewType)5).ToString()); cmbType.Items.Add(((ViewType)6).ToString()); Analyse(); }
public static void WriteProjectToDisk(Design design) { Directory.CreateDirectory(ProjectPath); Directory.CreateDirectory(ProjectPath + AndroidManifest.FilePath); File.AppendAllText(ProjectPath + AndroidManifest.FilePathAndName, AndroidManifest.WriteManifestString(design)); Directory.CreateDirectory(ProjectPath + GradleBuild.FilePath); File.AppendAllText(ProjectPath + GradleBuild.FilePathAndName, GradleBuild.WriteGradleBuildString(design)); Directory.CreateDirectory(ProjectPath + ActivityFiles.ActivityJavaFilePath(design)); File.AppendAllText(ProjectPath + ActivityFiles.ActivityJavaFilePathAndName(design), ActivityFiles.ActivityJavaCode(design)); Directory.CreateDirectory(ProjectPath + ActivityFiles.ActivityXMLFilePath); File.AppendAllText(ProjectPath + ActivityFiles.ActivityXMLFilePathAndName(design), ActivityFiles.ActivityXML(design)); Directory.CreateDirectory(ProjectPath + Colour.XMLFilePath); File.AppendAllText(ProjectPath + Colour.XMLFilePathAndName, Colour.GenerateXML()); Directory.CreateDirectory(ProjectPath + Strings.XMLFilePath); File.AppendAllText(ProjectPath + Strings.XMLFilePathAndName, Strings.GenerateXML()); Directory.CreateDirectory(ProjectPath + Styles.Style21XMLFilePath); File.AppendAllText(ProjectPath + Styles.Style21XMLFilePathAndName, Styles.Style21XML()); Directory.CreateDirectory(ProjectPath + Styles.StyleXMLFilePath); File.AppendAllText(ProjectPath + Styles.StyleXMLFilePathAndName, Styles.StyleXML()); Directory.CreateDirectory(ProjectPath + Drawables.DrawableFilePath); Drawables.WriteBitmapsToDisk(ProjectPath + Drawables.DrawableFilePath); Directory.CreateDirectory(ProjectPath + "app\\src\\main\\res\\"); DirectoryCopy("AndroidProjectResources\\Icons\\mipmap-hdpi\\", ProjectPath + "app\\src\\main\\res\\mipmap-hdpi\\", true); DirectoryCopy("AndroidProjectResources\\Icons\\mipmap-mdpi\\", ProjectPath + "app\\src\\main\\res\\mipmap-mdpi\\", true); DirectoryCopy("AndroidProjectResources\\Icons\\mipmap-xhdpi\\", ProjectPath + "app\\src\\main\\res\\mipmap-xhdpi\\", true); DirectoryCopy("AndroidProjectResources\\Icons\\mipmap-xxhdpi\\", ProjectPath + "app\\src\\main\\res\\mipmap-xxhdpi\\", true); if (design.ActionBar != null) { Directory.CreateDirectory(ProjectPath + design.ActionBar.LayoutXMLFilePath); File.AppendAllText(ProjectPath + design.ActionBar.LayoutXMLFilePathAndName, design.ActionBar.CreateLayoutFileXML()); } }
public frmActionBarAnalysis(Bitmap segment, Color backgroundColour, frmActionBarSelection sender, Design design) { InitializeComponent(); _segment = segment; _backgroundColour = backgroundColour; _senderForm = sender; _design = design; double gini; try { Bitmap preview; Views.ActionBar result = WidgetAnalyser.AnalyseActionBar(_segment, _backgroundColour, out gini, out preview); segmentPictureBox.BackgroundImage = preview; if (result != null) { lblGini.Text = gini.ToString(); lblType.Text = result.WidgetType.ToString(); txtActionBarLabel.Text = result.TitleText; _actionbar = result; } else { lblGini.Text = ""; lblType.Text = "I'm not sure this is an action bar. If it is, enter its title."; } } catch (ArgumentNullException) { MessageBox.Show("Background colour must be selected!", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this.Close(); _senderForm.Show(); return; } }
public static string WriteManifestString(Design design) { StringBuilder sb = new StringBuilder(); sb.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); sb.AppendLine("<!-- This should only be used as a reference or guide, please copy the relevant parts out to your actual manifest file -->"); sb.AppendLine("<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\""); sb.AppendLine(string.Format(" package=\"{0}.{1}\" >", design.OrgURL, design.AppName)); sb.AppendLine(); sb.AppendLine(" <application"); sb.AppendLine(" android:allowBackup=\"true\""); sb.AppendLine(" android:icon=\"@mipmap/ic_launcher\""); sb.AppendLine(" android:label=\"@string/app_name\""); sb.AppendLine(" android:theme=\"@style/AppTheme\">"); sb.AppendLine(); sb.AppendLine(" <!-- THIS IS THE PART YOU SHOULD COPY -->"); sb.AppendLine(" <activity"); sb.AppendLine(string.Format(" android:name=\".activity.{0}_\"", design.ActivityName)); if (design.ActionBar != null) { sb.AppendLine(string.Format(" android:label=\"@string/{0}\">", design.ActionBar.TitleTextStringID)); } else { sb.AppendLine(string.Format(" android:label=\"@string/{0}\">", design.ActivityNameStringID)); } sb.AppendLine(" <intent-filter>"); sb.AppendLine(" <action android:name=\"android.intent.action.MAIN\" />"); sb.AppendLine(" <category android:name=\"android.intent.category.LAUNCHER\" />"); sb.AppendLine(" </intent-filter>"); sb.AppendLine(" </activity>"); sb.AppendLine(" </application>"); sb.AppendLine(); sb.AppendLine("</manifest>"); return sb.ToString(); }
public static string ActivityJavaFilePathAndName(Design design) { return ActivityJavaFilePath(design) + ActivityJavaFileName(design); }
public static string ActivityJavaFilePath(Design design) { string activityLocation = design.OrgURL.Replace(".","\\"); return string.Format("app\\src\\main\\java\\{0}\\{1}\\activity\\", activityLocation, design.AppName); }
public static string ActivityJavaFileName(Design design) { return design.ActivityName + ".java"; }
public static string ActivityXMLFilePathAndName(Design design) { return ActivityXMLFilePath + ActivityXMLFileName(design); }
public static string ActivityXMLFileName(Design design) { return design.LayoutName + ".xml"; }
public static string WriteGradleBuildString(Design design) { StringBuilder sb = new StringBuilder(); sb.AppendLine(); sb.AppendLine("// This XML should only be used as a reference for what to add to an existing project"); sb.AppendLine(); sb.AppendLine("apply plugin: 'com.android.application'"); sb.AppendLine("apply plugin: 'android-apt'"); sb.AppendLine("// Replace with current version"); sb.AppendLine("def AAVersion = '3.3.2'"); sb.AppendLine(); sb.AppendLine("buildscript {"); sb.AppendLine(" repositories {"); sb.AppendLine(" mavenCentral()"); sb.AppendLine(" }"); sb.AppendLine(" dependencies {"); sb.AppendLine(" // replace with the current version of the Android plugin"); sb.AppendLine(" classpath 'com.android.tools.build:gradle:1.3.0'"); sb.AppendLine(" // replace with the current version of the android-apt plugin"); sb.AppendLine(" classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'"); sb.AppendLine(" }"); sb.AppendLine("}"); sb.AppendLine(); sb.AppendLine("repositories {"); sb.AppendLine(" mavenCentral()"); sb.AppendLine(" mavenLocal()"); sb.AppendLine("}"); sb.AppendLine(); sb.AppendLine("android {"); sb.AppendLine(" compileSdkVersion 22"); sb.AppendLine(" buildToolsVersion \"22.0.1\""); sb.AppendLine(); sb.AppendLine(" defaultConfig {"); sb.AppendLine(string.Format(" applicationId \"{0}.{1}\"", design.OrgURL, design.AppName)); sb.AppendLine(" minSdkVersion 22"); sb.AppendLine(" targetSdkVersion 22"); sb.AppendLine(" versionCode 1"); sb.AppendLine(" versionName \"1.0\""); sb.AppendLine(" }"); sb.AppendLine(" buildTypes {"); sb.AppendLine(" release {"); sb.AppendLine(" minifyEnabled false"); sb.AppendLine(" proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'"); sb.AppendLine(" }"); sb.AppendLine(" }"); sb.AppendLine("}"); sb.AppendLine(); sb.AppendLine("dependencies {"); sb.AppendLine(" // Some of these dependencies are needed, others are just good to have, check them out"); sb.AppendLine(" apt \"org.androidannotations:androidannotations:$AAVersion\""); sb.AppendLine(" compile \"org.androidannotations:androidannotations-api:$AAVersion\""); sb.AppendLine(" compile fileTree(dir: 'libs', include: ['*.jar'])"); sb.AppendLine(" compile 'com.android.support:design:22.2.1'"); sb.AppendLine(" compile 'com.rengwuxian.materialedittext:library:2.1.4'"); sb.AppendLine(" compile 'com.afollestad:material-dialogs:0.7.6.0'"); sb.AppendLine("}"); sb.AppendLine(); sb.AppendLine("// YOU NEED TO COPY THIS - Required for Android Annotations"); sb.AppendLine("apt {"); sb.AppendLine(" arguments {"); sb.AppendLine(" androidManifestFile variant.outputs[0].processResources.manifestFile"); sb.AppendLine(" // if you have multiple outputs (when using splits), you may want to have other index than 0"); sb.AppendLine(); sb.AppendLine(" // you should set your package name here if you are using different application IDs"); sb.AppendLine(" // resourcePackageName \"your.package.name\""); sb.AppendLine(); sb.AppendLine(" // You can set optional annotation processing options here, like these commented options:"); sb.AppendLine(" // logLevel 'INFO'"); sb.AppendLine(" // logFile '/var/log/aa.log'"); sb.AppendLine(" }"); sb.AppendLine("}"); return sb.ToString(); }