浏览代码

python integration working + apply new coding style everywhere (except in CustomAdapter.java)

Noah Vogt 3 年之前
父节点
当前提交
bf92a2e75e

+ 13 - 1
app/build.gradle

@@ -1,5 +1,6 @@
 plugins {
     id 'com.android.application'
+    id 'com.chaquo.python'
 }
 
 android {
@@ -16,9 +17,19 @@ android {
         versionCode 1
         versionName "1.0"
 
-        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+        ndk {
+            abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
+        }
+        python {
+            buildPython "/usr/bin/python3"
+        }
+    packagingOptions {
+        exclude 'META-INF/NOTICE.md'
     }
 
+
+        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+
     buildTypes {
         release {
             minifyEnabled false
@@ -30,6 +41,7 @@ android {
         targetCompatibility JavaVersion.VERSION_1_8
     }
 }
+}
 
 dependencies {
 

+ 50 - 56
app/src/main/java/com/noahvogt/miniprojekt/MainActivity.java

@@ -1,7 +1,6 @@
 package com.noahvogt.miniprojekt;
 
 import android.os.Bundle;
-
 import android.view.Menu;
 import android.view.View;
 import android.widget.Button;
@@ -14,33 +13,23 @@ import androidx.appcompat.app.AppCompatActivity;
 import androidx.appcompat.widget.Toolbar;
 import androidx.drawerlayout.widget.DrawerLayout;
 import androidx.fragment.app.DialogFragment;
-
-import android.view.LayoutInflater;
-import android.view.Menu;
-import android.view.View;
-import android.view.ViewGroup;
-
-import com.noahvogt.miniprojekt.ui.home.CustomAdapter;
-import com.noahvogt.miniprojekt.ui.home.Data;
-
-import androidx.recyclerview.widget.LinearLayoutManager;
-import androidx.recyclerview.widget.RecyclerView;
-import androidx.recyclerview.widget.StaggeredGridLayoutManager;
-
-import java.util.ArrayList;
-
-
-import com.google.android.material.navigation.NavigationView;
-
-
 import androidx.navigation.NavController;
 import androidx.navigation.Navigation;
 import androidx.navigation.ui.AppBarConfiguration;
 import androidx.navigation.ui.NavigationUI;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
 
-
+import com.chaquo.python.Python;
+import com.chaquo.python.android.AndroidPlatform;
 import com.google.android.material.navigation.NavigationView;
 import com.google.android.material.snackbar.Snackbar;
+import com.noahvogt.miniprojekt.ui.home.CustomAdapter;
+import com.noahvogt.miniprojekt.ui.home.Data;
+
+import java.util.ArrayList;
+
+import com.chaquo.python.android.PyApplication;
 
 import static com.noahvogt.miniprojekt.R.id.drawer_layout;
 
@@ -48,20 +37,13 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
 
     private AppBarConfiguration mAppBarConfiguration;
 
-    //imported by simon 2.may from RecyclerView Programm, changed to 23.may Simon to ArrayList<Data>...
+    /* declare vars that should always be used / shown by default */
     protected ArrayList<Data> data;
-
     private AlertDialog dialog;
+    private EditText newemail_name, newemail_email, newemail_password; /* may not be private */
 
-    private EditText newemail_name, newemail_email, newemail_password; // may not be private
-
-    // empty descriptor
-    public MainActivity() {
-    }
-
-
-
-
+    /* empty descriptor */
+    public MainActivity() {}
 
 
     @Override
@@ -69,7 +51,12 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
 
-        // define button listeners
+        /*
+        if (! Python.isStarted()) {
+           Python.start(new AndroidPlatform(this));
+        }
+         define button listeners
+        */
 
         Button add_email_button = (Button) findViewById(R.id.addEmailButton);
         add_email_button.setOnClickListener(new View.OnClickListener() {
@@ -88,13 +75,17 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
             }
         });
 
+        /* invoke toolbar */
         Toolbar toolbar = findViewById(R.id.toolbar);
         setSupportActionBar(toolbar);
 
+        /* invoke drawer */
         DrawerLayout drawer = findViewById(drawer_layout);
         NavigationView navigationView = findViewById(R.id.nav_view);
-        // Passing each menu ID as a set of Ids because each
-        // menu should be considered as top level destinations.
+        /*
+         Passing each menu ID as a set of Ids because each
+         menu should be considered as top level destinations.
+        */
         mAppBarConfiguration = new AppBarConfiguration.Builder(
                 R.id.nav_home, R.id.nav_gallery, R.id.nav_slideshow)
                 .setDrawerLayout(drawer)
@@ -103,14 +94,16 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
         NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
         NavigationUI.setupWithNavController(navigationView, navController);
 
+        /* invoke recycleViewer */
+
         //initDataset();
-        // Lookup the recyclerview in activity layou
+        /* Lookup the recyclerview in activity layout */
         RecyclerView recyclerView = findViewById(R.id.recyclerView);
-        // Initialize contacts
+        /* Initialize contacts */
         data = Data.createContactsList(20);
-        // Create adapter passing in the sample user data
+        /* Create adapter passing in the sample user data */
         CustomAdapter adapter = new CustomAdapter(data);
-        // Attach the adapter to the recyclerview to populate items
+        /* Attach the adapter to the recyclerview to populate items */
         recyclerView.setAdapter(adapter);
         recyclerView.setLayoutManager(new LinearLayoutManager(this));
     }
@@ -119,7 +112,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
 
     @Override
     public boolean onCreateOptionsMenu(Menu menu) {
-        // Inflate the menu; this adds items to the action bar if it is present.
+        /* Inflate the menu; this adds items to the action bar if it is present. */
         getMenuInflater().inflate(R.menu.create_message_options_menu, menu);
         return true;
     }
@@ -132,35 +125,40 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
     }
 
 
-    // better leave empty to avoid any listener disambiguity
+    /* better leave empty to avoid any listener disambiguity */
     public void onClick(View view) {}
 
 
     public void createNewEmailDialog(){
-        // define View window
+        /* define View window */
         AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
         final View emailPopupView = getLayoutInflater().inflate(R.layout.popup, null);
 
-        // init text field variables
+        /* init text field variables */
         newemail_name = emailPopupView.findViewById(R.id.popup_material_name_asking_text);
         newemail_email = emailPopupView.findViewById(R.id.popup_material_email_asking_text);
         newemail_password = emailPopupView.findViewById(R.id.popup_material_password_asking_text);
 
-        // init button variables
+        /* init button variables */
         Button newemail_save_button = (Button) emailPopupView.findViewById(R.id.saveButton);
-        // may not be private
+        /* may not be private */
         Button newemail_cancel_button = (Button) emailPopupView.findViewById(R.id.cancelButton);
 
-        // open View window
-        dialogBuilder.setView(emailPopupView);
+        if (! Python.isStarted()) {
+            Python.start(new AndroidPlatform(this));
+        }
+
+
+        /* open View window */
+            dialogBuilder.setView(emailPopupView);
         dialog = dialogBuilder.create();
         dialog.show();
 
-        // store user input
+        /* store user input */
         newemail_save_button.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
-                // store user input (only needed for DEBUGGING)
+                /* store user input (only needed for DEBUGGING) */
                 String name = newemail_name.getText().toString();
                 String email = newemail_email.getText().toString();
                 String password = newemail_password.getText().toString();
@@ -169,33 +167,29 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
                     return;
                 }
 
-                // show all strings the user gave, this will later be stored to a secure database and checked for validation
+                /* show all strings the user gave, this will later be stored to a secure database and checked for validation */
                 showToast(name);
                 showToast(email);
                 showToast(password);
-
-
-                showSnackbar(emailPopupView,"save button clicked");
             }
         });
 
         newemail_cancel_button.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
-                // define save button here
                 dialog.dismiss();
             }
         });
 
     }
 
-    // show debug output in  specific view
+    /* show debug output in  specific view */
     private void showSnackbar(View View, String text) {
         Snackbar.make(View, text, Snackbar.LENGTH_LONG)
                 .setAction("Action", null).show();
     }
 
-    // like showSnackbar(), but global and uglier
+    /* like showSnackbar(), but global and uglier */
     private void showToast(String text) {
         Toast.makeText(MainActivity.this, text, Toast.LENGTH_SHORT).show();
     }

+ 3 - 3
app/src/main/java/com/noahvogt/miniprojekt/mailFunctions.java

@@ -5,7 +5,7 @@ import android.widget.EditText;
 
 public class mailFunctions {
 
-    // TODO: resolve endIcon style conflict
+    /* TODO: resolve endIcon style conflict */
 
     public static boolean validateName(EditText emailName) {
         String name = emailName.getText().toString().trim();
@@ -51,13 +51,13 @@ public class mailFunctions {
 
     public static boolean validateSubject(EditText emailSubject) {
         String subject = emailSubject.getText().toString();
-        // TODO: check email protocol specification for what is allowed for subjects
+        /* TODO: check email protocol specification for what is allowed for subjects */
         return true;
     }
 
     public static boolean validateMessageBody(EditText emailMessageBody) {
         String messageBody = emailMessageBody.getText().toString();
-        // TODO: check email protocol specification for what is allowed for message bodies
+        /* TODO: check email protocol specification for what is allowed for message bodies */
         return true;
     }
 

+ 16 - 16
app/src/main/java/com/noahvogt/miniprojekt/messageCreateFragment.java

@@ -25,7 +25,7 @@ public class messageCreateFragment extends DialogFragment implements PopupMenu.O
 
 
 
-    // set theming style
+    /* set theming style */
     @Override
     public void onCreate(@Nullable Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -36,10 +36,10 @@ public class messageCreateFragment extends DialogFragment implements PopupMenu.O
     @Nullable
     @Override
     public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
-        // set and inflate layout
+        /* set and inflate layout */
         View view = inflater.inflate(R.layout.message_create_fragment, container, false);
 
-        // init vars
+        /* init vars */
 
         ImageButton closeButton = view.findViewById(R.id.create_message_close_button);
         ImageButton sendButton = view.findViewById(R.id.create_message_send_button);
@@ -51,15 +51,15 @@ public class messageCreateFragment extends DialogFragment implements PopupMenu.O
         EditText subjectObject = (EditText) view.findViewById(R.id.create_message_subject_text);
         EditText messageBodyObject = (EditText) view.findViewById(R.id.create_message_body_text);
 
-        // get string vars, MAYBE NOT HERE
+        /* get string vars, MAYBE NOT HERE */
         String sendingAddress = sendingAddressObject.getText().toString();
         String receivingAddress = receivingAddressObject.getText().toString();
         String subject = subjectObject.getText().toString();
         String messageBody = messageBodyObject.getText().toString();
 
-        // TODO: add cc + bcc functionality
+        /* TODO: add cc + bcc functionality */
 
-        // button listeners
+        /* button listeners */
 
         closeButton.setOnClickListener(new View.OnClickListener() {
             @Override
@@ -67,13 +67,13 @@ public class messageCreateFragment extends DialogFragment implements PopupMenu.O
                 String subject = subjectObject.getText().toString();
                 String messageBody = messageBodyObject.getText().toString();
 
-                // give alert dialog box to user in case input fields are not empty
+                /* give alert dialog box to user in case input fields are not empty */
 
                 if (subject.isEmpty() && messageBody.isEmpty()) {
                     dismiss();
                 }
                 else {
-                    // setup dialog
+                    /* setup dialog */
                     AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
                     alertDialogBuilder.setTitle("Warning");
                     alertDialogBuilder
@@ -81,18 +81,18 @@ public class messageCreateFragment extends DialogFragment implements PopupMenu.O
                             .setCancelable(false)
                             .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
                                 public void onClick(DialogInterface dialog, int id) {
-                                    // if this button is clicked, close the whole fragment
+                                    /* if this button is clicked, close the whole fragment */
                                     dismiss();
                                 }
                             })
                             .setNegativeButton("No",new DialogInterface.OnClickListener() {
                                 public void onClick(DialogInterface dialog,int id) {
-                                    // if this button is clicked, just close the dialog box
+                                    /* if this button is clicked, just close the dialog box */
                                     dialog.cancel();
                                 }
                             });
 
-                    // create + show alert dialog
+                    /* create + show alert dialog */
                     AlertDialog alertDialog = alertDialogBuilder.create();
                     alertDialog.show();
                 }
@@ -102,7 +102,7 @@ public class messageCreateFragment extends DialogFragment implements PopupMenu.O
         attachButton.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
-                // TODO: add file attachment functionality
+                /* TODO: add file attachment functionality */
             }
         });
 
@@ -119,13 +119,13 @@ public class messageCreateFragment extends DialogFragment implements PopupMenu.O
         sendButton.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
-                // init vars, MAYBE NEEDED FOR LATER
+                /* init vars, MAYBE NEEDED FOR LATER */
                 String sendingAddress = sendingAddressObject.getText().toString();
                 String receivingAddress = receivingAddressObject.getText().toString();
                 String subject = subjectObject.getText().toString();
                 String messageBody = messageBodyObject.getText().toString();
 
-                // check for valid input
+                /* check for valid input */
                 if (mailFunctions.validateMessageBody(messageBodyObject) && mailFunctions.validateSubject(subjectObject) &&
                 mailFunctions.validateEmail(receivingAddressObject) && mailFunctions.validateEmail(sendingAddressObject) &&
                 !mailFunctions.checkForSameEmail(sendingAddressObject, receivingAddressObject)) {
@@ -135,7 +135,7 @@ public class messageCreateFragment extends DialogFragment implements PopupMenu.O
                     Toast.makeText(getActivity(), "Please check your input", Toast.LENGTH_SHORT).show();
                 }
 
-                // TODO: implement actual sending functionality
+                /* TODO: implement actual sending functionality */
             }
         });
 
@@ -168,7 +168,7 @@ public class messageCreateFragment extends DialogFragment implements PopupMenu.O
             case R.id.create_message_item_4:
                 Toast.makeText(getActivity(), "item 4 clicked", Toast.LENGTH_LONG).show();
                 return true;
-            default: // this case should never occur
+            default: /* this case should never occur */
                 return false;
         }
     }

+ 4 - 5
build.gradle

@@ -3,12 +3,11 @@ buildscript {
     repositories {
         google()
         jcenter()
+        maven { url "https://chaquo.com/maven" }
     }
     dependencies {
-        classpath 'com.android.tools.build:gradle:4.2.1'
-
-        // NOTE: Do not place your application dependencies here; they belong
-        // in the individual module build.gradle files
+        classpath 'com.android.tools.build:gradle:4.0.2'
+        classpath "com.chaquo.python:gradle:9.1.0"
     }
 }
 
@@ -21,4 +20,4 @@ allprojects {
 
 task clean(type: Delete) {
     delete rootProject.buildDir
-}
+}

+ 3 - 3
gradle/wrapper/gradle-wrapper.properties

@@ -1,6 +1,6 @@
-#Mon Apr 19 17:45:09 CEST 2021
+#Wed Aug 25 19:12:25 CEST 2021
 distributionBase=GRADLE_USER_HOME
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
 distributionPath=wrapper/dists
-zipStoreBase=GRADLE_USER_HOME
 zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
+zipStoreBase=GRADLE_USER_HOME