diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5edb4ee --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +*.iml +.gradle +/local.properties +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser new file mode 100644 index 0000000..91c2b2c Binary files /dev/null and b/.idea/caches/build_file_checksums.ser differ diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..30aa626 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..7ac24c7 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..99202cc --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..19f1823 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,28 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 28 + defaultConfig { + applicationId "com.example.nikolavalcic.packbuddy" + minSdkVersion 15 + targetSdkVersion 28 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'com.android.support.constraint:constraint-layout:1.1.3' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'com.android.support.test:runner:1.0.2' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + compile 'com.squareup.okhttp3:okhttp:3.4.1' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/androidTest/java/com/example/nikolavalcic/packbuddy/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/example/nikolavalcic/packbuddy/ExampleInstrumentedTest.java new file mode 100644 index 0000000..2abfc62 --- /dev/null +++ b/app/src/androidTest/java/com/example/nikolavalcic/packbuddy/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.nikolavalcic.packbuddy; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.example.nikolavalcic.packbuddy", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..692edf7 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/example/nikolavalcic/packbuddy/MainActivity.java b/app/src/main/java/com/example/nikolavalcic/packbuddy/MainActivity.java new file mode 100644 index 0000000..029a1d3 --- /dev/null +++ b/app/src/main/java/com/example/nikolavalcic/packbuddy/MainActivity.java @@ -0,0 +1,337 @@ +package com.example.nikolavalcic.packbuddy; + +import android.app.Activity; +import android.graphics.Color; +import android.os.AsyncTask; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.Spinner; +import android.widget.TextView; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.*; + +import java.util.ArrayList; +import java.util.concurrent.ExecutionException; + +import okhttp3.OkHttpClient; + + + + +import android.os.Bundle; +//import android.support.design.widget.FloatingActionButton; +//import android.support.design.widget.Snackbar; +//import android.support.v7.app.AppCompatActivity; +//import android.support.v7.widget.Toolbar; +import android.view.View; +import android.view.Menu; +import android.view.MenuItem; + +import android.app.Activity; +import android.os.AsyncTask; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.IOException; +import java.lang.reflect.Array; +import java.util.concurrent.ExecutionException; + +import okhttp3.Call; +import okhttp3.Callback; +import okhttp3.Credentials; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; + +import org.json.*; + + + + +public class MainActivity extends Activity { + + class Item{ + String item; + Double weight; + Double price; + String currency; + public Item( String item, Double weight, Double price,String currency) { + this.item=item; + this.weight=weight; + this.price=price; + this.currency=currency; + } + } + ArrayList items = new ArrayList(); + + //list.add("Item2"); + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + Spinner dropdown3 = findViewById(R.id.spinner3); + String[] items = new String[]{"USD", "CAD", "EUR", "JPY", "GBP", "INR"}; + ArrayAdapter adapter3 = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, items); + dropdown3.setAdapter(adapter3); + + Spinner dropdown2 = findViewById(R.id.spinner2); + ArrayAdapter adapter2 = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, items); + dropdown2.setAdapter(adapter2); + + Spinner dropdown1 = findViewById(R.id.spinner1); + ArrayAdapter adapter1 = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, items); + dropdown1.setAdapter(adapter1); + + Spinner dropdownDest = findViewById(R.id.destCur); + ArrayAdapter adapterDest = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, items); + dropdownDest.setAdapter(adapterDest); + //dropdown1.select + Log.i("Selected", dropdown1.getSelectedItem().toString()); + } + + public void updateTable(){ + + } + + public void printItems(){ + for (int i=0; i=0; i--){ + items.remove(i); + } + } + + + //get items as written in the table + public void getItems(){ + clearItems(); + LinearLayout root=(LinearLayout) findViewById(R.id.itemsPanel); + + for (int i=1; i { + + OkHttpClient client = new OkHttpClient(); + + @Override + protected String doInBackground(String...params) { + + Log.e("PARAM 0", params[0]); + + Request.Builder builder = new Request.Builder(); + builder.url(params[0]); //params is all the arguments i think + builder.addHeader("Authorization", Credentials.basic("universityofwaterloo738297875", "ri5ump0mb771ukp2luajv50r43")); + Request request = builder.build(); + + try { + Log.i("DEBUG", "TRY ENTERED"); + Response response = client.newCall(request).execute(); + String s = response.body().string(); + Log.i("side", s); + return s; + } catch (Exception e) { + Log.i("DEBUG", "EXCEPTION CAUGHT"); + e.printStackTrace(); + return null; + } + //return null; + } + + @Override + protected void onPostExecute(String s) { + //super.onPostExecute(s); + Log.i("DEBUG", "executed post"); + Log.e("DEBUG", " " + s); + Log.i("DEBUG", s); + //txtString.setText(s); + //txtString.setText("sdf"); + //return s; + } + } + + public void KnapSackAlgo(View view){ + + LinearLayout root=(LinearLayout) findViewById(R.id.itemsPanel); + + for (int i=0; i= wt[i]) + m2 = m[i - 1][j - wt[i]] + val[i]; + /** select max of m1, m2 **/ + m[i][j] = Math.max(m1, m2); + sol[i][j] = m2 > m1 ? 1 : 0; + } + } + /** make list of what all items to finally select **/ + int[] selected = new int[N + 1]; + for (int n = N, w = W; n > 0; n--) { + if (sol[n][w] != 0) { + selected[n] = 1; + w = w - wt[n]; + } else + selected[n] = 0; + } + return selected; +// /** Print finally selected items **/ +// System.out.println("\nItems selected : "); +// for (int i = 1; i < N + 1; i++) +// if (selected[i] == 1) +// System.out.print(i + " "); +// System.out.println(); +// } + } + } + + +} diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..c7bd21d --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..d5fccc5 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..119bbba --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,269 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +