Permalink
Browse files

Added settings activity, username setting

  • Loading branch information...
dakhnod committed Jul 14, 2018
1 parent 476e7f9 commit b3762e86fd9f4bb6563c035f7121ab84439b2176
@@ -52,6 +52,7 @@
<activity
android:name=".CallActivity"
android:screenOrientation="portrait" />
<activity android:name=".SettingsActivity"></activity>
</application>
</manifest>
@@ -0,0 +1,55 @@
package d.d.meshenger;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;
import org.w3c.dom.Text;
public class SettingsActivity extends AppCompatActivity {
String nick;
SharedPreferences prefs;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
setTitle("Settings");
prefs = getSharedPreferences(getPackageName(), MODE_PRIVATE);
nick = prefs.getString("username", "undefined");
findViewById(R.id.changeNickLayout).setOnClickListener((v) -> changeNick());
}
private void changeNick(){
EditText et = new EditText(this);
et.setText(nick);
et.setSelection(nick.length());
new AlertDialog.Builder(this)
.setTitle("change nick")
.setView(et)
.setPositiveButton("ok", (dialogInterface, i) -> {
nick = et.getText().toString();
prefs.edit().putString("username", nick).apply();
initViews();
})
.setNegativeButton("cancel", null)
.show();
}
@Override
protected void onResume() {
super.onResume();
initViews();
}
private void initViews(){
((TextView) findViewById(R.id.nickTv)).setText(nick);
}
}
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SettingsActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp"
android:id="@+id/changeNickLayout">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change nick"
android:textColor="@android:color/black"
android:textSize="25dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/nickTv"
android:textSize="15dp"/>
</LinearLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
@@ -3,22 +3,14 @@
xmlns:tools="http://schemas.android.com/tools"
tools:context="d.d.meshenger.ContactListActivity">
<!-- <item
android:id="@+id/action_scan_qr"
app:showAsAction="always"
android:icon="@drawable/qr_glass1"
android:title="Scan QR Code"/>
<item
android:id="@+id/action_generate_qr"
app:showAsAction="always"
android:icon="@drawable/qr"
android:title="Generate QR Code"/> -->
<!-- <item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never" /> -->
app:showAsAction="never"
android:title="Settings"/>
<item
android:id="@+id/action_about"
app:showAsAction="never"
android:title="About"/>
</menu>

0 comments on commit b3762e8

Please sign in to comment.