diff --git a/app/.gitignore b/app/.gitignore deleted file mode 100644 index 796b96d..0000000 --- a/app/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/app/build.gradle b/app/build.gradle deleted file mode 100644 index 7cde814..0000000 --- a/app/build.gradle +++ /dev/null @@ -1,29 +0,0 @@ -apply plugin: 'com.android.application' - -android { - compileSdkVersion 28 - defaultConfig { - applicationId "com.example.hochi.nextcompanion" - minSdkVersion 15 - targetSdkVersion 28 - versionCode 9 - versionName "0.1.7.2" - 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:appcompat-v7:28.0.0' - implementation 'com.android.support.constraint:constraint-layout:1.1.3' - implementation 'com.android.support:design:28.0.0' - 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' -} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro deleted file mode 100644 index f1b4245..0000000 --- a/app/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# 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/hochi/nextcompanion/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/example/hochi/nextcompanion/ExampleInstrumentedTest.java deleted file mode 100644 index 2759dd6..0000000 --- a/app/src/androidTest/java/com/example/hochi/nextcompanion/ExampleInstrumentedTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.example.hochi.nextcompanion; - -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.hochi.nextcompanion", appContext.getPackageName()); - } -} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml deleted file mode 100644 index f15290c..0000000 --- a/app/src/main/AndroidManifest.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/ic_launcher-web.png b/app/src/main/ic_launcher-web.png deleted file mode 100644 index e96c6aa..0000000 Binary files a/app/src/main/ic_launcher-web.png and /dev/null differ diff --git a/app/src/main/java/com/example/hochi/nextcompanion/AsyncTaskCallbacks.java b/app/src/main/java/com/example/hochi/nextcompanion/AsyncTaskCallbacks.java deleted file mode 100644 index 2099b15..0000000 --- a/app/src/main/java/com/example/hochi/nextcompanion/AsyncTaskCallbacks.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.example.hochi.nextcompanion; - -interface AsyncTaskCallbacks { - void onTaskComplete(T response); -} diff --git a/app/src/main/java/com/example/hochi/nextcompanion/LoginActivity.java b/app/src/main/java/com/example/hochi/nextcompanion/LoginActivity.java deleted file mode 100644 index 1ff8e6b..0000000 --- a/app/src/main/java/com/example/hochi/nextcompanion/LoginActivity.java +++ /dev/null @@ -1,184 +0,0 @@ -package com.example.hochi.nextcompanion; - -import android.animation.Animator; -import android.animation.AnimatorListenerAdapter; -import android.annotation.TargetApi; - -import android.content.SharedPreferences; -import android.support.v7.app.AppCompatActivity; - -import android.os.Build; -import android.os.Bundle; -import android.text.TextUtils; -import android.view.KeyEvent; -import android.view.View; -import android.view.View.OnClickListener; -import android.view.inputmethod.EditorInfo; -import android.widget.Button; -import android.widget.EditText; -import android.widget.TextView; - -import org.json.JSONObject; - - -/** - * A login screen that offers login via phone number/pin. - */ -public class LoginActivity extends AppCompatActivity implements AsyncTaskCallbacks { - - /** - * Keep track of the login task to ensure we can cancel it if requested. - */ - private RequestHandler mAuthTask = null; - - // UI references. - private TextView mPhoneView; - private EditText mPinView; - private View mProgressView; - private View mLoginFormView; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_login); - // Set up the login form. - mPhoneView = findViewById(R.id.phone); - - mPinView = findViewById(R.id.pin); - mPinView.setOnEditorActionListener(new TextView.OnEditorActionListener() { - @Override - public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) { - if (id == EditorInfo.IME_ACTION_DONE || id == EditorInfo.IME_NULL) { - attemptLogin(); - return true; - } - return false; - } - }); - - Button mPhoneSignInButton = findViewById(R.id.phone_sign_in_button); - mPhoneSignInButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View view) { - attemptLogin(); - } - }); - - mLoginFormView = findViewById(R.id.login_form); - mProgressView = findViewById(R.id.login_progress); - } - - /** - * Attempts to sign in or register the account specified by the login form. - * If there are form errors (invalid phone number, missing fields, etc.), the - * errors are presented and no actual login attempt is made. - */ - private void attemptLogin() { - if (mAuthTask != null) { - return; - } - - // Reset errors. - mPhoneView.setError(null); - mPinView.setError(null); - - // Store values at the time of the login attempt. - String phone = mPhoneView.getText().toString(); - String pin = mPinView.getText().toString(); - String[] credentials = { - "apikey=", getString(R.string.apikey), - "mobile=", mPhoneView.getText().toString(), - "pin=", mPinView.getText().toString() - }; - - boolean cancel = false; - View focusView = null; - - // Check for a valid pin, if the user entered one. - if (TextUtils.isEmpty(pin)) { - mPinView.setError(getString(R.string.error_field_required)); - focusView = mPinView; - cancel = true; - } - - // Check for a valid phone address. - if (TextUtils.isEmpty(phone)) { - mPhoneView.setError(getString(R.string.error_field_required)); - focusView = mPhoneView; - cancel = true; - } - - if (cancel) { - // There was an error; don't attempt login and focus the first - // form field with an error. - focusView.requestFocus(); - } else { - // Show a progress spinner, and kick off a background task to - // perform the user login attempt. - showProgress(true); - mAuthTask = new RequestHandler(this, "POST", - "api/login.json", credentials); - mAuthTask.execute((Void) null); - } - } - - /** - * Shows the progress UI and hides the login form. - */ - @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2) - private void showProgress(final boolean show) { - // On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow - // for very easy animations. If available, use these APIs to fade-in - // the progress spinner. - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { - int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime); - - mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE); - mLoginFormView.animate().setDuration(shortAnimTime).alpha( - show ? 0 : 1).setListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE); - } - }); - - mProgressView.setVisibility(show ? View.VISIBLE : View.GONE); - mProgressView.animate().setDuration(shortAnimTime).alpha( - show ? 1 : 0).setListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - mProgressView.setVisibility(show ? View.VISIBLE : View.GONE); - } - }); - } else { - // The ViewPropertyAnimator APIs are not available, so simply show - // and hide the relevant UI components. - mProgressView.setVisibility(show ? View.VISIBLE : View.GONE); - mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE); - } - } - - @Override - public void onTaskComplete(String response) { - //Callback called when RequestHandler finished request - if (!response.isEmpty()) { - try { - JSONObject jObject = new JSONObject(response); - JSONObject userObject = jObject.getJSONObject("user"); - String loginkey = userObject.getString("loginkey"); - SharedPreferences sharedPref = getSharedPreferences("persistence", MODE_PRIVATE); - SharedPreferences.Editor editor = sharedPref.edit(); - editor.putString("loginKey", loginkey); - editor.apply(); - } - catch (Exception e) { - e.printStackTrace(); - } - finish(); - } else { - mPinView.setError(getString(R.string.error_incorrect_pin)); - mPinView.requestFocus(); - } - } -} - diff --git a/app/src/main/java/com/example/hochi/nextcompanion/MainActivity.java b/app/src/main/java/com/example/hochi/nextcompanion/MainActivity.java deleted file mode 100644 index ee51d6e..0000000 --- a/app/src/main/java/com/example/hochi/nextcompanion/MainActivity.java +++ /dev/null @@ -1,175 +0,0 @@ -package com.example.hochi.nextcompanion; - -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.net.Uri; -import android.os.Bundle; -import android.support.design.widget.FloatingActionButton; -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.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.ListView; -import android.widget.TextView; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.ArrayList; - -public class MainActivity extends AppCompatActivity implements AsyncTaskCallbacks { - private RequestHandler getBikesTask = null; - - @Override - protected void onCreate(Bundle savedInstanceState) { - //now this "every android activity" stuff - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - Toolbar toolbar = findViewById(R.id.toolbar); - setSupportActionBar(toolbar); - final Context context = this; - - //Floating Button - FloatingActionButton fab = findViewById(R.id.fab); - fab.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent intent = new Intent(context, RentActivity.class); - startActivity(intent); - } - }); - } - - @Override - protected void onStart() { - super.onStart(); - //pre-condition: Is there a login key? - SharedPreferences sharedPref = getSharedPreferences("persistence", MODE_PRIVATE); - String defaultValue = "nokey"; - String loginKey = sharedPref.getString("loginKey", defaultValue); - //if not, go to LoginActivity - if (loginKey.equals("nokey")) { - Intent intent = new Intent(this, LoginActivity.class); - startActivity(intent); - } - else { - reloadBikeList(); - } - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - // Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.menu_main, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - // Handle action bar item clicks here. The action bar will - // automatically handle clicks on the Home/Up button, so long - // as you specify a parent activity in AndroidManifest.xml. - int id = item.getItemId(); - - - //noinspection SimplifiableIfStatement - if (id == R.id.action_logout) { - SharedPreferences sharedPref = getSharedPreferences("persistence", MODE_PRIVATE); - SharedPreferences.Editor editor = sharedPref.edit(); - editor.remove("loginKey"); - editor.apply(); - Intent intent = new Intent(this, LoginActivity.class); - startActivity(intent); - } - - if (id == R.id.action_map) { - Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.map_url))); - startActivity(browserIntent); - } - - return super.onOptionsItemSelected(item); - } - - protected void reloadBikeList() { - //get loginkey - SharedPreferences sharedPref = getSharedPreferences("persistence", MODE_PRIVATE); - String defaultValue = "nokey"; - String loginKey = sharedPref.getString("loginKey", defaultValue); - - String[] params = { - "apikey=", getString(R.string.apikey), - "loginkey=", loginKey - }; - - getBikesTask = new RequestHandler(this, "POST", - "api/getOpenRentals.json", params); - getBikesTask.execute((Void) null); - } - - @Override - public void onTaskComplete(String response) { - //Callback called when RequestHandler finished request - final Context context = this; - if (!response.isEmpty()) { - final ArrayList list = new ArrayList<>(); - try { - JSONObject jObject = new JSONObject(response); - JSONArray bikesArray = jObject.getJSONArray("rentalCollection"); - for (int i = 0; i < bikesArray.length(); i++) { - String entry; - JSONObject bike = bikesArray.getJSONObject(i); - entry = "Bike " + bike.getString("bike") - + " with lock code " + bike.getString("code"); - list.add(entry); - } - } catch (Exception e) { - e.printStackTrace(); - } - - //Create and fill list - final ListView listview = findViewById(R.id.listview); - final ArrayAdapter adapter = new ArrayAdapter<>(this, - android.R.layout.simple_list_item_1, list); - listview.setAdapter(adapter); - - //Print indicator if empty - TextView tv = findViewById(R.id.noBikes); - if(list.isEmpty()) tv.setVisibility(View.VISIBLE); - else tv.setVisibility(View.INVISIBLE); - - try { - final JSONObject jObject = new JSONObject(response); - final JSONArray bikesArray = jObject.getJSONArray("rentalCollection"); - listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, final View view, int position, long id) { - Intent intent = new Intent(context, ReturnActivity.class); - try { - JSONObject bike = bikesArray.getJSONObject(position); - String bID = bike.getString("bike"); - String stID = bike.getString("start_place"); - String lockE = bike.getString("electric_lock"); - String[] bikeArray = {bID, stID, lockE}; - intent.putExtra("bike", bikeArray); - startActivity(intent); - } - catch (JSONException e) { - e.printStackTrace(); - } - } - - }); - } catch (JSONException e) { - e.printStackTrace(); - } - } - else { - //TODO: implement error handling - } - } -} diff --git a/app/src/main/java/com/example/hochi/nextcompanion/RentActivity.java b/app/src/main/java/com/example/hochi/nextcompanion/RentActivity.java deleted file mode 100644 index 4b1eb87..0000000 --- a/app/src/main/java/com/example/hochi/nextcompanion/RentActivity.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.example.hochi.nextcompanion; - -import android.content.Intent; -import android.content.SharedPreferences; -import android.net.Uri; -import android.support.v7.app.AppCompatActivity; -import android.os.Bundle; -import android.view.View; -import android.widget.Button; -import android.widget.TextView; - -import org.w3c.dom.Text; - -public class RentActivity extends AppCompatActivity implements AsyncTaskCallbacks { - private RequestHandler rentRequestTask = null; - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_rent); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - Button mRentSubmitButton = findViewById(R.id.rent_submit_button); - mRentSubmitButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - rentRequest(); - } - }); - - Intent intent = getIntent(); - Uri data = intent.getData(); - - if (data != null) { - String bikeID = data.toString().substring(15); - ((TextView) findViewById(R.id.bike_id)).setText(bikeID); - } - } - - void rentRequest() { - //Prepare request to rent bike - TextView mBikeInput; - mBikeInput = findViewById(R.id.bike_id); - String bikeID = mBikeInput.getText().toString(); - //get loginkey - SharedPreferences sharedPref = getSharedPreferences("persistence", MODE_PRIVATE); - String defaultValue = "nokey"; - String loginKey = sharedPref.getString("loginKey", defaultValue); - - String[] params = { - "apikey=", getString(R.string.apikey), - "loginkey=", loginKey, - "bike=", bikeID - }; - - rentRequestTask = new RequestHandler(this, "POST", - "api/rent.json", params); - rentRequestTask.execute((Void) null); - } - - @Override - public void onTaskComplete(String response) { - //get back to main activity - //TODO: *any* response handling - finish(); - } -} diff --git a/app/src/main/java/com/example/hochi/nextcompanion/RequestHandler.java b/app/src/main/java/com/example/hochi/nextcompanion/RequestHandler.java deleted file mode 100644 index 2476e63..0000000 --- a/app/src/main/java/com/example/hochi/nextcompanion/RequestHandler.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.example.hochi.nextcompanion; - -import android.os.AsyncTask; - -import java.io.BufferedReader; -import java.io.DataOutputStream; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.URL; -import java.net.URLEncoder; - -public class RequestHandler extends AsyncTask { - - private String mHTTPmethod; - private String mEndpoint; - private AsyncTaskCallbacks callback; - private String[] mCredentials; - - RequestHandler(AsyncTaskCallbacks act, String HTTPmethod, - String endpoint, String[] credentials) { - mHTTPmethod = HTTPmethod; - mEndpoint = endpoint; - mCredentials = credentials; - callback = act; - } - - @Override - protected String doInBackground(Void... params) { - StringBuilder response = new StringBuilder(); - StringBuilder urlParameters = new StringBuilder(); - int i=0; - while (i { - private String[] bikeArray; - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_return); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - - - Intent intent = getIntent(); - bikeArray = intent.getStringArrayExtra("bike"); - - //if GPS and electric lock, show the instruction - TextView tv = findViewById(R.id.gps_info); - LinearLayout la = findViewById(R.id.return_form_container); - if(bikeArray[2].equals("true")) { - tv.setVisibility(View.VISIBLE); - la.setVisibility(View.INVISIBLE); - } - else { - la.setVisibility(View.VISIBLE); - tv.setVisibility(View.INVISIBLE); - Button mReturnSubmitButton = findViewById(R.id.return_submit_button); - mReturnSubmitButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - returnRequest(); - } - }); - } - } - void returnRequest() { - TextView mStationInput; - mStationInput = findViewById(R.id.return_station_id); - String stationID = mStationInput.getText().toString(); - //get loginkey - SharedPreferences sharedPref = getSharedPreferences("persistence", MODE_PRIVATE); - String defaultValue = "nokey"; - String loginKey = sharedPref.getString("loginKey", defaultValue); - - String[] params = { - "apikey=", getString(R.string.apikey), - "bike=", bikeArray[0], - "loginkey=", loginKey, - "station=", stationID, - "comment=", "" - }; - RequestHandler returnRequestTask = new RequestHandler(this, "POST", - "api/return.json", params); - returnRequestTask.execute((Void) null); - } - - @Override - public void onTaskComplete(String response) { - //get back to main activity - //TODO: *any* response handling - finish(); - } -} diff --git a/app/src/main/res/drawable/ic_add_white_24dp.xml b/app/src/main/res/drawable/ic_add_white_24dp.xml deleted file mode 100644 index b5b5ba4..0000000 --- a/app/src/main/res/drawable/ic_add_white_24dp.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml deleted file mode 100644 index de480af..0000000 --- a/app/src/main/res/layout/activity_login.xml +++ /dev/null @@ -1,78 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - -