Add a button to save username and password (sometimes it wouldn't stick)

This commit is contained in:
downthecrop 2022-02-28 10:42:48 -08:00
parent 15046c5d2e
commit b7ec6803dd
2 changed files with 29 additions and 4 deletions

View file

@ -91,6 +91,11 @@ public class SettingsActivity extends Activity {
final SwitchMaterial righthanded = findViewById(R.id.righthanded);
final SeekBar mouseSpeed = findViewById(R.id.mouseslider);
final Button loadConfig = findViewById(R.id.loadconfig);
final Button saveLogin = findViewById(R.id.savelogin);
//For storing string value in sharedPreference
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = preferences.edit();
loadConfig.setOnTouchListener((v, event) -> {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
@ -100,9 +105,17 @@ public class SettingsActivity extends Activity {
return false;
});
//For storing string value in sharedPreference
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = preferences.edit();
saveLogin.setOnTouchListener((v, event) -> {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
editor.putString("password",password.getText().toString());
editor.putString("username",username.getText().toString());
editor.commit();
Toast.makeText(this, "Saved login data. Please restart the app.",
Toast.LENGTH_SHORT).show();
return true;
}
return false;
});
// Restore from saved values
username.setText(preferences.getString("username",""));
@ -125,6 +138,7 @@ public class SettingsActivity extends Activity {
System.out.println("Password: "+password.getText());
editor.putString("password",password.getText().toString());
editor.commit();
return true;
}
return false;
});
@ -135,7 +149,6 @@ public class SettingsActivity extends Activity {
editor.putInt("mousespeed",mouseSpeed.getProgress());
editor.commit();
LauncherPreferences.PREF_MOUSESPEED = mouseSpeed.getProgress();
}
@Override

View file

@ -45,6 +45,17 @@
app:layout_constraintTop_toBottomOf="@+id/username"
tools:layout_editor_absoluteX="-1dp" />
<Button
android:id="@+id/savelogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:text="Save Username &amp; Password"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/righthanded" />
<TextView
android:id="@+id/mousespeed_text"
android:layout_width="match_parent"
@ -89,5 +100,6 @@
android:text="Load Config"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/righthanded" />
</LinearLayout>
</ScrollView>