Commit a9f48eed authored by Corentin Mors's avatar Corentin Mors
Browse files

Implement settings in the android app

parent 528e8845
package fr.pixelswap.onmap.onmap;
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatDelegate;
import android.support.v7.widget.Toolbar;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
/**
* A {@link android.preference.PreferenceActivity} which implements and proxies the necessary calls
* to be used with AppCompat.
*/
public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
private AppCompatDelegate mDelegate;
@Override
protected void onCreate(Bundle savedInstanceState) {
getDelegate().installViewFactory();
getDelegate().onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
getDelegate().onPostCreate(savedInstanceState);
}
public ActionBar getSupportActionBar() {
return getDelegate().getSupportActionBar();
}
public void setSupportActionBar(@Nullable Toolbar toolbar) {
getDelegate().setSupportActionBar(toolbar);
}
@Override
public MenuInflater getMenuInflater() {
return getDelegate().getMenuInflater();
}
@Override
public void setContentView(@LayoutRes int layoutResID) {
getDelegate().setContentView(layoutResID);
}
@Override
public void setContentView(View view) {
getDelegate().setContentView(view);
}
@Override
public void setContentView(View view, ViewGroup.LayoutParams params) {
getDelegate().setContentView(view, params);
}
@Override
public void addContentView(View view, ViewGroup.LayoutParams params) {
getDelegate().addContentView(view, params);
}
@Override
protected void onPostResume() {
super.onPostResume();
getDelegate().onPostResume();
}
@Override
protected void onTitleChanged(CharSequence title, int color) {
super.onTitleChanged(title, color);
getDelegate().setTitle(title);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
getDelegate().onConfigurationChanged(newConfig);
}
@Override
protected void onStop() {
super.onStop();
getDelegate().onStop();
}
@Override
protected void onDestroy() {
super.onDestroy();
getDelegate().onDestroy();
}
public void invalidateOptionsMenu() {
getDelegate().invalidateOptionsMenu();
}
private AppCompatDelegate getDelegate() {
if (mDelegate == null) {
mDelegate = AppCompatDelegate.create(this, null);
}
return mDelegate;
}
}
......@@ -2,10 +2,6 @@ package fr.pixelswap.onmap.onmap;
import android.app.Application;
import android.util.Log;
import java.net.URISyntaxException;
import io.socket.client.IO;
import io.socket.client.Socket;
......@@ -17,7 +13,7 @@ public class ChatApplication extends Application {
try {
mSocket = IO.socket("http://192.168.43.158:3000");
} catch(Exception e){
Log.e("OM_ERROR", e.toString());
e.printStackTrace();
}
}
......
......@@ -5,14 +5,15 @@ import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Base64;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
......@@ -28,20 +29,9 @@ import android.widget.Toast;
import org.json.JSONException;
import org.json.JSONObject;
import java.security.NoSuchAlgorithmException;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.KeySpec;
import java.util.ArrayList;
import java.util.List;
import javax.crypto.Cipher;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.SecretKeySpec;
import io.socket.client.Socket;
import io.socket.emitter.Emitter;
......@@ -66,7 +56,9 @@ public class ChatFragment extends Fragment {
private String mUsername;
private Socket mSocket;
private String mPassword = "azerty";
private String mPassword;
public SharedPreferences settings;
private Boolean isConnected = true;
......@@ -81,6 +73,7 @@ public class ChatFragment extends Fragment {
@Override
public void onAttach(Context context) {
super.onAttach(context);
settings = PreferenceManager.getDefaultSharedPreferences(context);
mAdapter = new MessageAdapter(context, mMessages);
if (context instanceof Activity){
//this.listener = (MainActivity) context;
......@@ -129,8 +122,8 @@ public class ChatFragment extends Fragment {
mSocket.off("new message", onNewMessage);
mSocket.off("user joined", onUserJoined);
mSocket.off("user left", onUserLeft);
mSocket.off("typing", onTyping);
mSocket.off("stop typing", onStopTyping);
//mSocket.off("typing", onTyping);
//mSocket.off("stop typing", onStopTyping);
}
@Override
......@@ -189,18 +182,15 @@ public class ChatFragment extends Fragment {
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.e("OM_LOG", "test ok");
//Log.e("OM_LOG", Activity.RESULT_OK + " ou " + resultCode);
/*if (Activity.RESULT_OK != resultCode) {
if (Activity.RESULT_OK != resultCode) {
getActivity().finish();
return;
}*/
}
mUsername = data.getStringExtra("username");
int numUsers = data.getIntExtra("numUsers", 1);
//addLog(getResources().getString(R.string.message_welcome));
addLog(getResources().getString(R.string.message_welcome));
//addParticipantsLog(numUsers);
}
......@@ -266,7 +256,8 @@ public class ChatFragment extends Fragment {
}
private void startSignIn() {
mUsername = "mike";
mUsername = settings.getString("mUsername", "Guest");
mPassword = settings.getString("mPassword", "azerty");
mSocket.emit("add user", mUsername, "one");
//Intent intent = new Intent(getActivity(), LoginActivity.class);
//startActivityForResult(intent, REQUEST_LOGIN);
......
......@@ -4,6 +4,7 @@ import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.location.Criteria;
import android.location.Location;
......@@ -17,6 +18,9 @@ import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import org.osmdroid.api.IMapController;
......@@ -83,6 +87,17 @@ public class MainActivity extends AppCompatActivity {
//Permissions handled above
final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
final String serverAddress = settings.getString("serverAddress", null);
final String mUsername = settings.getString("mUsername", null);
final String mPassword = settings.getString("mPassword", null);
if (serverAddress == null || mUsername == null || mPassword == null) {
Intent intent = new Intent(getBaseContext(), SettingsActivity.class);
startActivity(intent);
finish();
}
// Set up location getters
LocationManager mLocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
......@@ -123,6 +138,17 @@ public class MainActivity extends AppCompatActivity {
ChatApplication app = (ChatApplication) getApplication();
mSocket = app.getSocket();
Button settingsButton = findViewById(R.id.accessSettings);
settingsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getBaseContext(), SettingsActivity.class);
startActivity(intent);
finish();
}
});
}
private void displayMyCurrentLocationOverlay() {
......
package fr.pixelswap.onmap.onmap;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class SettingsActivity extends AppCompatActivity {
......@@ -9,5 +15,30 @@ public class SettingsActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
Button settingsButton = findViewById(R.id.buttonSettings);
settingsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
SharedPreferences.Editor edit = settings.edit();
EditText serverInput = findViewById(R.id.editServer);
EditText usernameInput = findViewById(R.id.editUsername);
EditText passwordInput = findViewById(R.id.editPassword);
edit.putString("serverAddress", serverInput.getText().toString());
edit.putString("mUsername", usernameInput.getText().toString());
edit.putString("mPassword", passwordInput.getText().toString());
edit.apply();
Intent intent = new Intent(getBaseContext(), MainActivity.class);
startActivity(intent);
finish();
}
});
}
}
......@@ -46,6 +46,15 @@
android:text="Open Chat"
android:textSize="14sp" />
<Button
android:id="@+id/accessSettings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:gravity="center_vertical"
android:text="Settings" />
</LinearLayout>
<fragment
......
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorPrimary">#0c61b1</color>
<color name="colorPrimaryDark">#002c57</color>
<color name="colorAccent">#D81B60</color>
<color name="username0">#e21400</color>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment