|
14 | 14 | import android.support.design.widget.Snackbar; |
15 | 15 | import android.support.v7.app.ActionBar; |
16 | 16 | import android.support.v7.app.AppCompatActivity; |
| 17 | +import android.text.InputType; |
17 | 18 | import android.view.Menu; |
18 | 19 | import android.view.MenuItem; |
19 | 20 | import android.view.TouchDelegate; |
|
22 | 23 | import android.view.WindowManager; |
23 | 24 | import android.widget.AdapterView; |
24 | 25 | import android.widget.Button; |
| 26 | +import android.widget.EditText; |
25 | 27 | import android.widget.ImageButton; |
26 | 28 | import android.widget.LinearLayout; |
27 | 29 | import android.widget.ListView; |
@@ -527,6 +529,36 @@ public void onClick(DialogInterface dialog, int id) { |
527 | 529 | } |
528 | 530 | } |
529 | 531 |
|
| 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 | + |
530 | 562 | private void askIfDownloadOSM() { |
531 | 563 | AlertDialog.Builder builder = new AlertDialog.Builder(this); |
532 | 564 | builder.setTitle(R.string.downloadOSMTitle); |
@@ -589,6 +621,9 @@ public boolean onOptionsItemSelected(MenuItem item) { |
589 | 621 | } else if (id == R.id.mbtilessettings) { |
590 | 622 | basemap.presentMBTilesOptions(); |
591 | 623 | return true; |
| 624 | + } else if (id == R.id.osmcredentials) { |
| 625 | + inputOSMCredentials(); |
| 626 | + return true; |
592 | 627 | } else if (id == R.id.osmsettings) { |
593 | 628 | presentOSMOptions(); |
594 | 629 | return true; |
|
0 commit comments