-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 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
1 parent
89ab952
commit 975fd32
Showing
28 changed files
with
581 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
186 changes: 185 additions & 1 deletion
186
app/src/main/java/com/starlight/powerdroid/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
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.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.