Skip to content

Commit

Permalink
feat: Implement 'DataExporter'
Browse files Browse the repository at this point in the history
- Added DataExporter (aka SaveLocal), enabling users to locally save their input into a text file.
- Added popup_menu.xml to handle 'PopupMenu' (UI) functionality
- Added a variety of 'round_gradient_buttons' with different visual styles
- Updated Base Release UI
- Added the WRITE_EXTERNAL_STORAGE permission to the AndroidManifest.xml file.
- Added background (placeholder) images to drawable folder.
- Added custom colors to colors.xml
- Added two 'string array' to store spinner options in the strings.xml file.
- Fix typo in README.md

Signed-off-by: Starlight <136495168+tis-starlight@users.noreply.github.com>
  • Loading branch information
tis-starlight committed Feb 7, 2024
1 parent 89ab952 commit 975fd32
Show file tree
Hide file tree
Showing 28 changed files with 581 additions and 15 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/render.experimental.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@

- Color Picker
- Advanced Calculator
- Unit Coverters
- Unit Converters
- Encode/convert & Decode Text:
* ASCII, Binary, hex, octal and vice-versa.
- Encrypt & Decrypt messages (cipher)
- Morse Code
- Data Exporter
- Data Exporter [**WIP**]

## Getting Started

1. Clone the repository: `git clone https://github.com/tis-starlight/PowerDroid.git`
1. Clone the repository:
```git
git clone https://github.com/tis-starlight/PowerDroid.git
```
2. Open in Android Studio.
3. Build and run on your Android device or emulator.

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand Down
186 changes: 185 additions & 1 deletion app/src/main/java/com/starlight/powerdroid/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,198 @@
package com.starlight.powerdroid;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.MenuItem;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.Toast;
import android.widget.PopupMenu;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.File;

public class MainActivity extends AppCompatActivity {

// Define & Declare Variables
private EditText etName, etFatherName, etAddress, etEmail, etPhoneNumber, etDateOfBirth;
private RadioGroup radioGroupGender;
private RadioButton radioButtonMale, radioButtonFemale;
private Spinner spinnerDegree, spinnerField;
private SeekBar sliderLanguageFluency;
private Button btnFavLang, btnSaveLocal, btnSubmit;
private CheckBox checkBoxTermsConditions;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Reference & Initialize UI components
etName = findViewById(R.id.etName);
etFatherName = findViewById(R.id.etFatherName);
etAddress = findViewById(R.id.etAddress);
etEmail = findViewById(R.id.etEmail);
etPhoneNumber = findViewById(R.id.etPhoneNumber);
etDateOfBirth = findViewById(R.id.etDateOfBirth);
radioGroupGender = findViewById(R.id.radioGroupGender);
radioButtonMale = findViewById(R.id.radioButtonMale);
radioButtonFemale = findViewById(R.id.radioButtonFemale);
spinnerDegree = findViewById(R.id.Degree);
spinnerField = findViewById(R.id.Field);
sliderLanguageFluency = findViewById(R.id.sliderLanguageFluency);
btnFavLang = findViewById(R.id.btnFavLang);
btnSaveLocal = findViewById(R.id.btnSaveLocal);
btnSubmit = findViewById(R.id.btnSubmit);
checkBoxTermsConditions = findViewById(R.id.checkBoxTermsConditions);

// Set up spinners
ArrayAdapter<CharSequence> degreeAdapter = ArrayAdapter.createFromResource(
this, R.array.degree_array, android.R.layout.simple_spinner_item);
degreeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerDegree.setAdapter(degreeAdapter);

spinnerDegree.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
// Display a Toast when a degree is selected
String selectedDegree = parentView.getItemAtPosition(position).toString();
Toast.makeText(MainActivity.this, "Selected Degree: " + selectedDegree, Toast.LENGTH_SHORT).show();
}

@Override
public void onNothingSelected(AdapterView<?> parentView) {
// Do nothing if nothing is selected
}
});

ArrayAdapter<CharSequence> fieldAdapter = ArrayAdapter.createFromResource(
this, R.array.field_array, android.R.layout.simple_spinner_item);
fieldAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerField.setAdapter(fieldAdapter);

spinnerField.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
// Display a Toast when a field is selected
String selectedField = parentView.getItemAtPosition(position).toString();
Toast.makeText(MainActivity.this, "Selected Field: " + selectedField, Toast.LENGTH_SHORT).show();
}

@Override
public void onNothingSelected(AdapterView<?> parentView) {
// Do nothing if nothing is selected
}
});

btnFavLang.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Handle button click for selecting favorite language

// Initializing the popup menu and giving the reference as the current context
PopupMenu popupMenu = new PopupMenu(MainActivity.this, btnFavLang);

// Inflating popup menu from popup_menu.xml file
popupMenu.getMenuInflater().inflate(R.menu.popup_menu, popupMenu.getMenu());

// Setting up a listener for menu item clicks
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
// Toast message on menu item clicked, displaying the selected language
Toast.makeText(MainActivity.this, "Selected Language: " + menuItem.getTitle(), Toast.LENGTH_SHORT).show();
return true;
}
});

// Showing the popup menu
popupMenu.show();
}
});

btnSaveLocal.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Call method to save data to a text file with user's name
saveDataToLocalFile(etName.getText().toString());
}
});


btnSubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (checkBoxTermsConditions.isChecked()) {
// If terms and conditions are agreed
// You can perform further actions here

Toast.makeText(MainActivity.this, "Submission successful", Toast.LENGTH_SHORT).show();
}

else {
Toast.makeText(MainActivity.this, "Please agree to Terms and Conditions", Toast.LENGTH_SHORT).show();
}

}
});
}

// Method to save data to a text file
private void saveDataToLocalFile(String userName) {
String fileName = userName + "_userdata.txt"; // Name of the file to save the data with user's name
String data = ""; // String to store the data

// Append each field's data to the 'data' string
data += "Name: " + etName.getText().toString() + "\n";
data += "Father's Name: " + etFatherName.getText().toString() + "\n";
data += "Address: " + etAddress.getText().toString() + "\n";
data += "Email: " + etEmail.getText().toString() + "\n";
data += "Phone Number: " + etPhoneNumber.getText().toString() + "\n";
data += "Date of Birth: " + etDateOfBirth.getText().toString() + "\n";

// Get selected gender
int selectedGenderId = radioGroupGender.getCheckedRadioButtonId();
RadioButton selectedGenderRadioButton = findViewById(selectedGenderId);
if (selectedGenderRadioButton != null) {
data += "Gender: " + selectedGenderRadioButton.getText().toString() + "\n";
}

// Get selected degree
String selectedDegree = spinnerDegree.getSelectedItem().toString();
data += "Degree: " + selectedDegree + "\n";

// Get selected field
String selectedField = spinnerField.getSelectedItem().toString();
data += "Field: " + selectedField + "\n";

// Get selected language fluency from the seek bar
int languageFluency = sliderLanguageFluency.getProgress();
data += "Language Fluency: " + languageFluency + "\n";

// Get the Downloads directory
File downloadsDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);

// Create the file object in the Downloads directory
File file = new File(downloadsDir, fileName);

// Write data to the file
try {
FileOutputStream fos = new FileOutputStream(file);
fos.write(data.getBytes());
fos.close();
Toast.makeText(MainActivity.this, "Data saved to " + file.getAbsolutePath(), Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(MainActivity.this, "Error saving data", Toast.LENGTH_SHORT).show();
}
}
}
Binary file added app/src/main/res/drawable/background_dark1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/background_dark2.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/background_light.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/background_vector.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/round_gradient_button.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="10dp" />
<gradient
android:startColor="@color/round_gradient_button_start_color"
android:endColor="@color/round_gradient_button_end_color"
android:type="linear"
android:angle="0"/>
</shape>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/round_gradient_button1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="10dp" />
<gradient
android:startColor="@color/round_gradient_button1_start_color"
android:endColor="@color/round_gradient_button1_end_color"
android:type="linear"
android:angle="0"/>
</shape>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/round_gradient_button2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="10dp" />
<gradient
android:startColor="@color/round_gradient_button2_start_color"
android:endColor="@color/round_gradient_button2_end_color"
android:type="linear"
android:angle="0"/>
</shape>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/round_gradient_button3.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="10dp" />
<gradient
android:startColor="@color/round_gradient_button3_start_color"
android:endColor="@color/round_gradient_button3_end_color"
android:type="linear"
android:angle="0"/>
</shape>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/round_gradient_button4.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="10dp" />
<gradient
android:startColor="@color/round_gradient_button4_start_color"
android:endColor="@color/round_gradient_button4_end_color"
android:type="linear"
android:angle="0"/>
</shape>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/round_gradient_button5.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="10dp" />
<gradient
android:startColor="@color/round_gradient_button5_start_color"
android:centerColor="@color/round_gradient_button5_center_color"
android:endColor="@color/round_gradient_button5_end_color"
android:type="linear"
android:angle="0"/>
</shape>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/round_gradient_button6.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="10dp" />
<gradient
android:startColor="@color/round_gradient_button6_start_color"
android:endColor="@color/round_gradient_button6_end_color"
android:type="linear"
android:angle="0"/>
</shape>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/round_gradient_button7.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="10dp" />
<gradient
android:startColor="@color/round_gradient_button7_start_color"
android:centerColor="@color/round_gradient_button7_center_color"
android:endColor="@color/round_gradient_button7_end_color"
android:type="linear"
android:angle="0"/>
</shape>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/round_gradient_button8.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="10dp" />
<gradient
android:startColor="@color/round_gradient_button8_start_color"
android:centerColor="@color/round_gradient_button8_center_color"
android:endColor="@color/round_gradient_button8_end_color"
android:type="linear"
android:angle="0"/>
</shape>
Loading

0 comments on commit 975fd32

Please sign in to comment.