Skip to content

Commit 6585d49

Browse files
committed
able to edit user name in settings
1 parent 8ce59ea commit 6585d49

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

app/src/main/java/org/redcross/openmapkit/MapActivity.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import android.support.design.widget.Snackbar;
1515
import android.support.v7.app.ActionBar;
1616
import android.support.v7.app.AppCompatActivity;
17+
import android.text.InputType;
1718
import android.view.Menu;
1819
import android.view.MenuItem;
1920
import android.view.TouchDelegate;
@@ -22,6 +23,7 @@
2223
import android.view.WindowManager;
2324
import android.widget.AdapterView;
2425
import android.widget.Button;
26+
import android.widget.EditText;
2527
import android.widget.ImageButton;
2628
import android.widget.LinearLayout;
2729
import android.widget.ListView;
@@ -527,6 +529,36 @@ public void onClick(DialogInterface dialog, int id) {
527529
}
528530
}
529531

532+
private void inputOSMCredentials() {
533+
final SharedPreferences userNamePref = getSharedPreferences("org.redcross.openmapkit.USER_NAME", Context.MODE_PRIVATE);
534+
AlertDialog.Builder builder = new AlertDialog.Builder(this);
535+
builder.setTitle("OpenStreetMap User Name");
536+
builder.setMessage("Please enter your OpenStreetMap user name.");
537+
final EditText input = new EditText(this);
538+
input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
539+
String userName = userNamePref.getString("userName", null);
540+
if (userName != null) {
541+
input.setText(userName);
542+
}
543+
builder.setView(input);
544+
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
545+
@Override
546+
public void onClick(DialogInterface dialog, int id) {
547+
// just dismiss
548+
}
549+
});
550+
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
551+
@Override
552+
public void onClick(DialogInterface dialog, int which) {
553+
String userName = input.getText().toString();
554+
SharedPreferences.Editor editor = userNamePref.edit();
555+
editor.putString("userName", userName);
556+
editor.apply();
557+
}
558+
});
559+
builder.show();
560+
}
561+
530562
private void askIfDownloadOSM() {
531563
AlertDialog.Builder builder = new AlertDialog.Builder(this);
532564
builder.setTitle(R.string.downloadOSMTitle);
@@ -589,6 +621,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
589621
} else if (id == R.id.mbtilessettings) {
590622
basemap.presentMBTilesOptions();
591623
return true;
624+
} else if (id == R.id.osmcredentials) {
625+
inputOSMCredentials();
626+
return true;
592627
} else if (id == R.id.osmsettings) {
593628
presentOSMOptions();
594629
return true;

app/src/main/res/menu/menu_map.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
<item
2626
android:id="@+id/mbtilessettings"
2727
android:title="@string/action_mbtilessettings" />
28+
<item
29+
android:id="@+id/osmcredentials"
30+
android:title="@string/action_osmcredentials" />
2831
<item
2932
android:id="@+id/osmdownloader"
3033
android:title="@string/action_osmdownloader" />

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
<string name="app_name">OpenMapKit</string>
55

6+
<string name="action_osmcredentials">OSM User Name</string>
67
<string name="action_osmdownloader">OSM XML Downloader</string>
78
<!-- osm menu -->
89
<string name="action_osmsettings">OSM XML Layers</string>

0 commit comments

Comments
 (0)