Permalink
Browse files

Added language option to settings

  • Loading branch information...
dakhnod committed Jul 21, 2018
1 parent 8beba6e commit ffab2960d740da59af5b93c0e30a99221028f082
@@ -99,18 +99,16 @@ public void onServiceDisconnected(ComponentName componentName) {
bindService(new Intent(this, MainService.class), this, 0);
nameTextView.setText(intent.getStringExtra("EXTRA_USERNAME"));
findViewById(R.id.callAccept).setVisibility(View.VISIBLE);
setStatusText("calling...");
ringPhone();
View.OnClickListener optionsListener = view -> {
stopRingPhone();
if (view.getId() == R.id.callDecline) {
stopRingPhone();
Log.d(RTCCall.class.getSimpleName(), "declining call...");
currentCall.decline();
if(passiveWakeLock != null && passiveWakeLock.isHeld()) passiveWakeLock.release();
finish();
}else {
try {
stopRingPhone();
currentCall.setRemoteRenderer(findViewById(R.id.remoteRenderer));
//currentCall.setLocalRenderer(findViewById(R.id.localRenderer));
currentCall.accept(passiveCallback);
@@ -11,6 +11,7 @@
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
@@ -50,6 +51,7 @@
import java.io.IOException;
import java.util.List;
import java.util.ResourceBundle;
public class ContactListActivity extends AppCompatActivity implements ServiceConnection, MainService.ContactPingListener, AdapterView.OnItemClickListener {
private ListView contactListView;
@@ -98,7 +100,7 @@ private void checkInit() {
private void showUsernameDialog() {
AlertDialog.Builder dialog = new AlertDialog.Builder(this)
.setTitle("Hello!");
.setTitle(R.string.hello);
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
TextView tw = new TextView(this);
@@ -275,33 +277,30 @@ public void run() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
PopupMenu menu = new PopupMenu(ContactListActivity.this, view);
menu.getMenu().add("delete");
menu.getMenu().add("rename");
menu.getMenu().add("share");
menu.getMenu().add("qr-ify");
Resources res = getResources();
String delete = res.getString(R.string.delete),
rename = res.getString(R.string.rename),
share = res.getString(R.string.share),
qr = "qr-ify";
menu.getMenu().add(delete);
menu.getMenu().add(rename);
menu.getMenu().add(share);
menu.getMenu().add(qr);
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
switch (menuItem.getTitle().toString()){
case "delete": {
mainBinder.deleteContact(contacts.get(i));
refreshContactList();
break;
}
case "rename": {
showContactEditDialog(contacts.get(i));
break;
}
case "share": {
shareContact(contacts.get(i));
break;
}
case "qr-ify": {
Intent intent = new Intent(ContactListActivity.this, QRPresenterActivity.class);
intent.putExtra("EXTRA_CONTACT", contacts.get(i));
startActivity(intent);
break;
}
String title = menuItem.getTitle().toString();
if(title.equals(delete)){
mainBinder.deleteContact(contacts.get(i));
refreshContactList();
}else if(title.equals(rename)){
showContactEditDialog(contacts.get(i));
}else if(title.equals(share)){
shareContact(contacts.get(i));
}else if(title.equals(qr)){
Intent intent = new Intent(ContactListActivity.this, QRPresenterActivity.class);
intent.putExtra("EXTRA_CONTACT", contacts.get(i));
startActivity(intent);
}
return false;
}
@@ -334,9 +333,9 @@ private void showContactEditDialog(Contact c) {
EditText et = new EditText(this);
et.setText(c.getInfo());
AlertDialog dialog = new AlertDialog.Builder(this)
.setTitle("Edit contact")
.setTitle(R.string.contact_edit)
.setView(et)
.setNegativeButton("cancel", null)
.setNegativeButton(getResources().getString(R.string.cancel), null)
.setPositiveButton("ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
@@ -410,7 +409,7 @@ public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (grantResults[0] != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this, "Microphone permission needed to make calls", Toast.LENGTH_LONG).show();
Toast.makeText(this, R.string.permission_mic, Toast.LENGTH_LONG).show();
finish();
}
}
@@ -146,6 +146,7 @@ private void handleClient(Socket client) {
String response = "{\"action\":\"ringing\"}\n";
os.write(response.getBytes());
//TODO
this.currentCall = new RTCCall(client, this, request.getString("offer"));
Intent intent = new Intent(this, CallActivity.class);
intent.setAction("ACTION_ACCEPT_CALL");
@@ -271,7 +272,7 @@ void addContact(Contact c, String challenge) {
log("adding contact " + c.getName() + " " + c.getId());
} catch (ContactSqlHelper.ContactAlreadyAddedException e) {
Toast.makeText(MainService.this, "Contact already added", 0).show();
Toast.makeText(MainService.this, "Contact already added", Toast.LENGTH_SHORT).show();
}
new Thread(new ConnectRunnable(c, challenge)).start();
}
@@ -68,7 +68,7 @@ private void startManualInput(){
handleJson(et.getText().toString());
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(this, R.string.invalid_data, 0).show();
Toast.makeText(this, R.string.invalid_data, Toast.LENGTH_SHORT).show();
}
finish();
})
@@ -2,14 +2,21 @@
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import org.w3c.dom.Text;
import java.util.HashMap;
import java.util.Locale;
public class SettingsActivity extends AppCompatActivity {
String nick;
SharedPreferences prefs;
@@ -19,27 +26,59 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
setTitle("Settings");
setTitle(getResources().getString(R.string.menu_settings));
prefs = getSharedPreferences(getPackageName(), MODE_PRIVATE);
nick = prefs.getString("username", "undefined");
findViewById(R.id.changeNickLayout).setOnClickListener((v) -> changeNick());
}
private void getLocale(){
Configuration config = getResources().getConfiguration();
Locale locale = config.locale;
((TextView) findViewById(R.id.localeTv)).setText(locale.getDisplayLanguage());
Locale[] locales = new Locale[]{Locale.ENGLISH, Locale.GERMAN};
findViewById(R.id.changeLocaleLayout).setOnClickListener((v) -> {
RadioGroup group = new RadioGroup(this);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
for(int i = 0; i < locales.length; i++){
Locale l = locales[i];
RadioButton button = new RadioButton(this);
button.setId(i);
button.setText(l.getDisplayLanguage());
if(l.getISO3Language().equals(locale.getISO3Language())) button.setChecked(true);
group.addView(button);
}
builder.setView(group);
AlertDialog dialog = builder.show();
group.setOnCheckedChangeListener((a, position) -> {
Log.d("Settings", "changed locale to " + locales[position].getLanguage());
Configuration config1 = new Configuration();
config1.locale = locales[position];
getResources().updateConfiguration(config1, getResources().getDisplayMetrics());
dialog.dismiss();
});
});
}
private void changeNick(){
EditText et = new EditText(this);
et.setText(nick);
et.setSelection(nick.length());
new AlertDialog.Builder(this)
.setTitle("change nick")
.setTitle(getResources().getString(R.string.settings_change_nick))
.setView(et)
.setPositiveButton("ok", (dialogInterface, i) -> {
nick = et.getText().toString();
prefs.edit().putString("username", nick).apply();
initViews();
})
.setNegativeButton("cancel", null)
.setNegativeButton(getResources().getText(R.string.cancel), null)
.show();
}
@@ -51,5 +90,6 @@ protected void onResume() {
private void initViews(){
((TextView) findViewById(R.id.nickTv)).setText(nick);
getLocale();
}
}
@@ -14,41 +14,41 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Source:"
android:text="@string/about_source"
android:textSize="15dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="https://www.github.com/dakhnod/meshenger/"
android:text="@string/source_link"
android:textSize="15dp"
android:autoLink="web"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Author:"
android:text="@string/about_author"
android:textSize="15dp"
android:layout_marginTop="40dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Daniel Dakhno"
android:text="@string/about_author_name"
android:textSize="15dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dakhnod@gmail.com"
android:text="@string/about_author_email"
android:textSize="15dp"
android:id="@+id/mailText"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="License:"
android:text="@string/about_license"
android:textSize="15dp" />
<ProgressBar
@@ -43,7 +43,7 @@
android:id="@+id/callStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="connecting..."
android:text="@string/call_connecting"
android:textColor="@android:color/black"
android:textSize="20dp" />
@@ -21,7 +21,7 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change nick"
android:text="@string/settings_change_nick"
android:textColor="@android:color/black"
android:textSize="25dp"/>
@@ -33,6 +33,30 @@
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp"
android:id="@+id/changeLocaleLayout">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/settings_change_language"
android:textColor="@android:color/black"
android:textSize="25dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/localeTv"
android:textSize="15dp"/>
</LinearLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
@@ -6,11 +6,11 @@
<item
android:id="@+id/action_settings"
app:showAsAction="never"
android:title="Settings"/>
android:title="@string/menu_settings"/>
<item
android:id="@+id/action_about"
app:showAsAction="never"
android:title="About"/>
android:title="@string/menu_about"/>
</menu>

0 comments on commit ffab296

Please sign in to comment.