Merge branch 'master' of https://github.com/sagidayan/TheSocialNotework-Android
This commit is contained in:
commit
ffe73a159e
7 changed files with 347 additions and 133 deletions
|
@ -10,12 +10,9 @@ import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.android.volley.Response;
|
import com.android.volley.Response;
|
||||||
import com.android.volley.VolleyError;
|
import com.android.volley.VolleyError;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@ -27,14 +24,11 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL
|
||||||
private Button registerButton;
|
private Button registerButton;
|
||||||
private Button testBtn;
|
private Button testBtn;
|
||||||
private RegisterActivity self;
|
private RegisterActivity self;
|
||||||
|
|
||||||
protected RelativeLayout layout;
|
protected RelativeLayout layout;
|
||||||
private final String TAG = "Register Activity";
|
private final String TAG = "[TSN/RegisterActivity]";
|
||||||
|
|
||||||
private final String BASE_URL = "http://thesocialnotework-api.appspot.com/api";
|
private final String BASE_URL = "http://thesocialnotework-api.appspot.com/api";
|
||||||
private final String REG_PATH = "/register";
|
private final String REG_PATH = "/register";
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -58,15 +52,30 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL
|
||||||
this.registerButton.setOnClickListener(this);
|
this.registerButton.setOnClickListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isUsernameValid(String username) { // username validation
|
/**
|
||||||
|
* username validation
|
||||||
|
* @param username
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean isUsernameValid(String username) {
|
||||||
return !TextUtils.isEmpty(username) && username.length() > 0;
|
return !TextUtils.isEmpty(username) && username.length() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isPasswordValid(String password) { // password validation
|
/**
|
||||||
|
* password validation
|
||||||
|
* @param password
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean isPasswordValid(String password) {
|
||||||
return !TextUtils.isEmpty(password) && password.length() > 3;
|
return !TextUtils.isEmpty(password) && password.length() > 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isEmailValid(String email) { // email validation
|
/**
|
||||||
|
* email validation
|
||||||
|
* @param email
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean isEmailValid(String email) {
|
||||||
if (TextUtils.isEmpty(email))
|
if (TextUtils.isEmpty(email))
|
||||||
return false;
|
return false;
|
||||||
String expression = "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";
|
String expression = "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";
|
||||||
|
@ -75,11 +84,21 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL
|
||||||
return matcher.matches();
|
return matcher.matches();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isParamsValid(String username, String password, String email) { // private method that validates all params
|
/**
|
||||||
|
* private method that validates all params
|
||||||
|
* @param username
|
||||||
|
* @param password
|
||||||
|
* @param email
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean isParamsValid(String username, String password, String email) {
|
||||||
return (isUsernameValid(username) && isPasswordValid(password) && isEmailValid(email));
|
return (isUsernameValid(username) && isPasswordValid(password) && isEmailValid(email));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void attemptRegister() { // attempt registering
|
/**
|
||||||
|
* attempt registering
|
||||||
|
*/
|
||||||
|
private void attemptRegister() {
|
||||||
Utils.showLoadingDialog(this, "Registering", "Please Wait...");
|
Utils.showLoadingDialog(this, "Registering", "Please Wait...");
|
||||||
if (isParamsValid(mUsernameView.getText().toString(), mPasswordView.getText().toString(), mEmailView.getText().toString())) { // params are valid
|
if (isParamsValid(mUsernameView.getText().toString(), mPasswordView.getText().toString(), mEmailView.getText().toString())) { // params are valid
|
||||||
String username = mUsernameView.getText().toString();
|
String username = mUsernameView.getText().toString();
|
||||||
|
@ -101,9 +120,16 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* listener to success response on register from server
|
||||||
|
*/
|
||||||
Response.Listener<JSONObject> onRegisterSuccess = new Response.Listener<JSONObject>() {
|
Response.Listener<JSONObject> onRegisterSuccess = new Response.Listener<JSONObject>() {
|
||||||
|
/**
|
||||||
|
* on response register from server
|
||||||
|
* @param response
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(JSONObject response) { // listener to success response on register from server
|
public void onResponse(JSONObject response) {
|
||||||
Utils.dismissLoadingDialog();
|
Utils.dismissLoadingDialog();
|
||||||
try {
|
try {
|
||||||
if (response.getString("message").equals("created")) { // user created
|
if (response.getString("message").equals("created")) { // user created
|
||||||
|
@ -120,16 +146,25 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Response.ErrorListener onRegisterError = new Response.ErrorListener() {
|
Response.ErrorListener onRegisterError = new Response.ErrorListener() {
|
||||||
|
/**
|
||||||
|
* listener to error response on register from server
|
||||||
|
* @param error
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onErrorResponse(VolleyError error) { // listener to error response on register from server
|
public void onErrorResponse(VolleyError error) {
|
||||||
Utils.dismissLoadingDialog();
|
Utils.dismissLoadingDialog();
|
||||||
Toast.makeText(self, "Username is already taken. maybe: " + mUsernameView.getText().toString() + "_666 ? :)", Toast.LENGTH_LONG).show();
|
Toast.makeText(self, "Username is already taken. maybe: " + mUsernameView.getText().toString() + "_666 ? :)", Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* onclick methods to redirect to register and to login
|
||||||
|
* @param view
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) { // onclick methods to redirect to register and to login
|
public void onClick(View view) {
|
||||||
switch (view.getId()) {
|
switch (view.getId()) {
|
||||||
case R.id.ra_register_button:
|
case R.id.ra_register_button:
|
||||||
attemptRegister();
|
attemptRegister();
|
||||||
|
@ -140,7 +175,10 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void returnToLogin() { // redirect to login
|
/**
|
||||||
|
* redirect to login
|
||||||
|
*/
|
||||||
|
private void returnToLogin() {
|
||||||
Intent i = new Intent(RegisterActivity.this, LoginActivity.class);
|
Intent i = new Intent(RegisterActivity.this, LoginActivity.class);
|
||||||
startActivity(i);
|
startActivity(i);
|
||||||
finish();
|
finish();
|
||||||
|
|
|
@ -14,18 +14,37 @@ public class RoundAvatarImageView extends ImageView {
|
||||||
|
|
||||||
public static float radius = 110.0f;
|
public static float radius = 110.0f;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor I
|
||||||
|
* @param context
|
||||||
|
*/
|
||||||
public RoundAvatarImageView(Context context) {
|
public RoundAvatarImageView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor II
|
||||||
|
* @param context
|
||||||
|
* @param attrs
|
||||||
|
*/
|
||||||
public RoundAvatarImageView(Context context, AttributeSet attrs) {
|
public RoundAvatarImageView(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor III
|
||||||
|
* @param context
|
||||||
|
* @param attrs
|
||||||
|
* @param defStyle
|
||||||
|
*/
|
||||||
public RoundAvatarImageView(Context context, AttributeSet attrs, int defStyle) {
|
public RoundAvatarImageView(Context context, AttributeSet attrs, int defStyle) {
|
||||||
super(context, attrs, defStyle);
|
super(context, attrs, defStyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clip the image to a rounded avatar
|
||||||
|
* @param canvas
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void onDraw(Canvas canvas) {
|
protected void onDraw(Canvas canvas) {
|
||||||
//float radius = 36.0f;
|
//float radius = 36.0f;
|
||||||
|
|
|
@ -52,19 +52,32 @@ public class SettingsFragment extends Fragment implements View.OnClickListener,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* a function that called when this class created
|
||||||
|
*
|
||||||
|
* @param savedInstanceState
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* a function that called when view is created
|
||||||
|
*
|
||||||
|
* @param inflater
|
||||||
|
* @param container
|
||||||
|
* @param savedInstanceState
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.fragment_settings, container, false);
|
View view = inflater.inflate(R.layout.fragment_settings, container, false);
|
||||||
this.parent = (MainActivity) getActivity();
|
this.parent = (MainActivity) getActivity(); // holds the activity
|
||||||
Utils.showLoadingDialog(parent, "Just a sec...", "");
|
Utils.showLoadingDialog(parent, "Just a sec...", ""); // loading dialog
|
||||||
this.user = parent.getUser();
|
this.user = parent.getUser(); // holds the user
|
||||||
|
|
||||||
this.cameraBtn = (ImageButton) view.findViewById(R.id.btn_camera);
|
this.cameraBtn = (ImageButton) view.findViewById(R.id.btn_camera);
|
||||||
this.cameraBtn.setOnClickListener(this);
|
this.cameraBtn.setOnClickListener(this);
|
||||||
this.avatarImage = (ImageView) view.findViewById(R.id.settings_userAvater_iamgeView);
|
this.avatarImage = (ImageView) view.findViewById(R.id.settings_userAvater_iamgeView);
|
||||||
|
@ -105,21 +118,21 @@ public class SettingsFragment extends Fragment implements View.OnClickListener,
|
||||||
super.onDetach();
|
super.onDetach();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* a function that called on click
|
||||||
|
*
|
||||||
|
* @param view
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
switch (view.getId()) {
|
switch (view.getId()) {
|
||||||
case R.id.btn_camera:
|
case R.id.btn_camera:
|
||||||
//check for permission
|
|
||||||
// ActivityCompat.requestPermissions(parent, new String[]{Manifest.permission.CAMERA}, 1);
|
|
||||||
if ((ActivityCompat.checkSelfPermission(parent, android.Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED)
|
if ((ActivityCompat.checkSelfPermission(parent, android.Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED)
|
||||||
&& (ActivityCompat.checkSelfPermission(parent, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)) {
|
&& (ActivityCompat.checkSelfPermission(parent, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)) {
|
||||||
openCamera(view);
|
openCamera(view);
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(getActivity(), "No Camera or Storage Permissions granted.\n\"An App is nothing without its permissions\"", Toast.LENGTH_LONG).show();
|
Toast.makeText(getActivity(), "No Camera or Storage Permissions granted.\n\"An App is nothing without its permissions\"", Toast.LENGTH_LONG).show();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case R.id.btn_save:
|
case R.id.btn_save:
|
||||||
if (txt_password.getText().length() > 3 && txt_email.getText().length() > 0)
|
if (txt_password.getText().length() > 3 && txt_email.getText().length() > 0)
|
||||||
|
@ -147,15 +160,25 @@ public class SettingsFragment extends Fragment implements View.OnClickListener,
|
||||||
startActivityForResult(intent, 1);
|
startActivityForResult(intent, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a folder to hold the photos
|
||||||
|
*/
|
||||||
protected void createDir() {
|
protected void createDir() {
|
||||||
File f = new File(Utils.PHOTOS_DIR_PATH);
|
File f = new File(Utils.PHOTOS_DIR_PATH);
|
||||||
f.mkdirs();
|
f.mkdirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* upon receiving response from the camera
|
||||||
|
*
|
||||||
|
* @param requestCode
|
||||||
|
* @param resultCode
|
||||||
|
* @param intent
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resaultCode, Intent intent) {
|
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
||||||
super.onActivityResult(requestCode, requestCode, intent);
|
super.onActivityResult(requestCode, requestCode, intent);
|
||||||
if (resaultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
if (currentImgUri != null) {
|
if (currentImgUri != null) {
|
||||||
saveImage();
|
saveImage();
|
||||||
Log.d(TAG, "onActivityResult: Image Capured!! - Now Upload That Shit!!");
|
Log.d(TAG, "onActivityResult: Image Capured!! - Now Upload That Shit!!");
|
||||||
|
@ -169,11 +192,15 @@ public class SettingsFragment extends Fragment implements View.OnClickListener,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves the image
|
||||||
|
*/
|
||||||
private void saveImage() {
|
private void saveImage() {
|
||||||
Utils.showLoadingDialog(parent, "Saving Image...", "This Can Take a while");
|
Utils.showLoadingDialog(parent, "Saving Image...", "This Can Take a while"); // Loader
|
||||||
|
|
||||||
Bitmap b = BitmapFactory.decodeFile(currentImgUri.getPath()); // Original Image
|
Bitmap b = BitmapFactory.decodeFile(currentImgUri.getPath()); // Original Image
|
||||||
Bitmap out;
|
Bitmap out;
|
||||||
|
|
||||||
|
// Crop image
|
||||||
if (b.getWidth() >= b.getHeight()) {
|
if (b.getWidth() >= b.getHeight()) {
|
||||||
|
|
||||||
out = Bitmap.createBitmap(
|
out = Bitmap.createBitmap(
|
||||||
|
@ -183,7 +210,6 @@ public class SettingsFragment extends Fragment implements View.OnClickListener,
|
||||||
b.getHeight(),
|
b.getHeight(),
|
||||||
b.getHeight()
|
b.getHeight()
|
||||||
);
|
);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
out = Bitmap.createBitmap(
|
out = Bitmap.createBitmap(
|
||||||
b,
|
b,
|
||||||
|
@ -193,10 +219,12 @@ public class SettingsFragment extends Fragment implements View.OnClickListener,
|
||||||
b.getWidth()
|
b.getWidth()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
// Resizing image
|
||||||
out = Bitmap.createScaledBitmap(out, 320, 320, false);
|
out = Bitmap.createScaledBitmap(out, 320, 320, false);
|
||||||
|
|
||||||
File file = new File(currentImgUri.getPath());
|
File file = new File(currentImgUri.getPath());
|
||||||
FileOutputStream fOut;
|
FileOutputStream fOut;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fOut = new FileOutputStream(file);
|
fOut = new FileOutputStream(file);
|
||||||
out.compress(Bitmap.CompressFormat.PNG, 100, fOut);
|
out.compress(Bitmap.CompressFormat.PNG, 100, fOut);
|
||||||
|
@ -206,10 +234,9 @@ public class SettingsFragment extends Fragment implements View.OnClickListener,
|
||||||
out.recycle();
|
out.recycle();
|
||||||
} catch (Exception e) {}
|
} catch (Exception e) {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
JSONObject payload = new JSONObject();
|
JSONObject payload = new JSONObject();
|
||||||
|
|
||||||
|
// Upload image
|
||||||
try {
|
try {
|
||||||
payload.put("image", ImageToBase64(file.getAbsolutePath()));
|
payload.put("image", ImageToBase64(file.getAbsolutePath()));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
@ -234,6 +261,11 @@ public class SettingsFragment extends Fragment implements View.OnClickListener,
|
||||||
}, Utils.genericErrorListener);
|
}, Utils.genericErrorListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the file to base 64 bit
|
||||||
|
* @param filePath
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
private String ImageToBase64(String filePath) {
|
private String ImageToBase64(String filePath) {
|
||||||
Bitmap bm = BitmapFactory.decodeFile(filePath);
|
Bitmap bm = BitmapFactory.decodeFile(filePath);
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
|
|
@ -6,14 +6,18 @@ import android.os.Bundle;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
|
||||||
public class SplashActivity extends AppCompatActivity {
|
public class SplashActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private ImageView background;
|
private ImageView background;
|
||||||
private int timerDelay = 3500;
|
private int timerDelay = 3500;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* called when this class is created
|
||||||
|
* @param savedInstanceState
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -21,7 +25,9 @@ public class SplashActivity extends AppCompatActivity {
|
||||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||||
setContentView(R.layout.activity_splash);
|
setContentView(R.layout.activity_splash);
|
||||||
background = (ImageView) findViewById(R.id.background);
|
background = (ImageView) findViewById(R.id.background);
|
||||||
final int sdk = android.os.Build.VERSION.SDK_INT;
|
|
||||||
|
final int sdk = android.os.Build.VERSION.SDK_INT; // holds the sdk
|
||||||
|
// Configuring the method to use considering the sdk
|
||||||
if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
|
if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
|
||||||
background.setImageDrawable( getResources().getDrawable(rand_splash()) );
|
background.setImageDrawable( getResources().getDrawable(rand_splash()) );
|
||||||
} else {
|
} else {
|
||||||
|
@ -30,6 +36,7 @@ public class SplashActivity extends AppCompatActivity {
|
||||||
|
|
||||||
final String userData = Utils.getUserFromSharedPrefs(this);
|
final String userData = Utils.getUserFromSharedPrefs(this);
|
||||||
|
|
||||||
|
// Timer for the splash image until it will disappear
|
||||||
Thread timerThread = new Thread(){
|
Thread timerThread = new Thread(){
|
||||||
public void run(){
|
public void run(){
|
||||||
try{
|
try{
|
||||||
|
@ -53,6 +60,9 @@ public class SplashActivity extends AppCompatActivity {
|
||||||
timerThread.start();
|
timerThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* on pause function
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
@ -60,6 +70,10 @@ public class SplashActivity extends AppCompatActivity {
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* randomize splash screen
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
protected int rand_splash() {
|
protected int rand_splash() {
|
||||||
int min = 2, max = 4;
|
int min = 2, max = 4;
|
||||||
// Usually this can be a field rather than a method variable
|
// Usually this can be a field rather than a method variable
|
||||||
|
@ -69,10 +83,6 @@ public class SplashActivity extends AppCompatActivity {
|
||||||
// so add 1 to make it inclusive
|
// so add 1 to make it inclusive
|
||||||
int randomNum = rand.nextInt((max - min) + 1) + min;
|
int randomNum = rand.nextInt((max - min) + 1) + min;
|
||||||
switch (randomNum){
|
switch (randomNum){
|
||||||
// case 0:
|
|
||||||
// return R.drawable.splash_0;
|
|
||||||
// case 1:
|
|
||||||
// return R.drawable.splash_1;
|
|
||||||
case 2:
|
case 2:
|
||||||
return R.drawable.splash_2;
|
return R.drawable.splash_2;
|
||||||
case 3:
|
case 3:
|
||||||
|
|
|
@ -66,6 +66,8 @@ public class User {
|
||||||
Log.d(TAG, "User: Constructor Created:\n"+this.toString());
|
Log.d(TAG, "User: Constructor Created:\n"+this.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Getters & Setters //
|
||||||
|
|
||||||
public int getNumber_of_notes() {
|
public int getNumber_of_notes() {
|
||||||
return number_of_notes;
|
return number_of_notes;
|
||||||
}
|
}
|
||||||
|
@ -111,6 +113,10 @@ public class User {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get liked notes
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public Vector<String> getLiked_notes() {
|
public Vector<String> getLiked_notes() {
|
||||||
return liked_notes;
|
return liked_notes;
|
||||||
}
|
}
|
||||||
|
@ -124,10 +130,18 @@ public class User {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* convert the user object to string in order to save to the shared prefs
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public String Serialise(){
|
public String Serialise(){
|
||||||
return id + ATTARS_DELIMETER + username + ATTARS_DELIMETER + password + ATTARS_DELIMETER + email + ATTARS_DELIMETER +avatar + ATTARS_DELIMETER + serialiseNoteList();
|
return id + ATTARS_DELIMETER + username + ATTARS_DELIMETER + password + ATTARS_DELIMETER + email + ATTARS_DELIMETER +avatar + ATTARS_DELIMETER + serialiseNoteList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* convert the user note list to string in order to save to the shared prefs
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
private String serialiseNoteList() {
|
private String serialiseNoteList() {
|
||||||
String result = "";
|
String result = "";
|
||||||
for (int i = 0; i < liked_notes.size(); i++) {
|
for (int i = 0; i < liked_notes.size(); i++) {
|
||||||
|
@ -143,6 +157,10 @@ public class User {
|
||||||
return "Id: "+id+" UserName: " + username +" Password: " +password +" email: " + email+ " Avatar: " +avatar+" Liked Notes: "+liked_notes.toString();
|
return "Id: "+id+" UserName: " + username +" Password: " +password +" email: " + email+ " Avatar: " +avatar+" Liked Notes: "+liked_notes.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* update user
|
||||||
|
* @param activity
|
||||||
|
*/
|
||||||
public void updateUser(final MainActivity activity){
|
public void updateUser(final MainActivity activity){
|
||||||
VolleyUtilSingleton.getInstance(activity).post(Utils.BASE_URL + "/user/upsert", this.toJSON(), new Response.Listener<JSONObject>() {
|
VolleyUtilSingleton.getInstance(activity).post(Utils.BASE_URL + "/user/upsert", this.toJSON(), new Response.Listener<JSONObject>() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -19,8 +19,6 @@ import android.widget.ImageView;
|
||||||
|
|
||||||
import com.android.volley.Response;
|
import com.android.volley.Response;
|
||||||
import com.android.volley.VolleyError;
|
import com.android.volley.VolleyError;
|
||||||
import com.google.android.gms.maps.model.BitmapDescriptor;
|
|
||||||
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
|
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
@ -54,7 +52,12 @@ public class Utils {
|
||||||
public static final float DISTANCE_SMALL = 1000, DISTANCE_MEDIUM = 10000, DISTANCE_LONG = 100000;
|
public static final float DISTANCE_SMALL = 1000, DISTANCE_MEDIUM = 10000, DISTANCE_LONG = 100000;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets the bitmap from the url
|
||||||
|
*
|
||||||
|
* @param url
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public static Bitmap getBitmapFromURL(String url) {
|
public static Bitmap getBitmapFromURL(String url) {
|
||||||
if (Utils.bitmapHash.containsKey(url)) {
|
if (Utils.bitmapHash.containsKey(url)) {
|
||||||
Log.d(TAG, "getBitmapFromURL: Found is hash");
|
Log.d(TAG, "getBitmapFromURL: Found is hash");
|
||||||
|
@ -78,8 +81,9 @@ public class Utils {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
// //Generic response ErrorListener
|
* Generic response ErrorListener
|
||||||
|
*/
|
||||||
public static Response.ErrorListener genericErrorListener = new Response.ErrorListener() {
|
public static Response.ErrorListener genericErrorListener = new Response.ErrorListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onErrorResponse(VolleyError error) {
|
public void onErrorResponse(VolleyError error) {
|
||||||
|
@ -88,7 +92,9 @@ public class Utils {
|
||||||
Utils.dismissLoadingDialog();
|
Utils.dismissLoadingDialog();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
/**
|
||||||
|
* Generic response deleteNoteSuccessListener
|
||||||
|
*/
|
||||||
public static Response.Listener<JSONObject> deleteNoteSuccessListener = new Response.Listener<JSONObject>() {
|
public static Response.Listener<JSONObject> deleteNoteSuccessListener = new Response.Listener<JSONObject>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(JSONObject response) {
|
public void onResponse(JSONObject response) {
|
||||||
|
@ -96,7 +102,9 @@ public class Utils {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//response listener for getting all user notes
|
/**
|
||||||
|
* response listener for getting all user notes
|
||||||
|
*/
|
||||||
public static Response.Listener<JSONObject> genericSuccessListener = new Response.Listener<JSONObject>() {
|
public static Response.Listener<JSONObject> genericSuccessListener = new Response.Listener<JSONObject>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(JSONObject response) {
|
public void onResponse(JSONObject response) {
|
||||||
|
@ -104,6 +112,13 @@ public class Utils {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show loading dialog
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param title
|
||||||
|
* @param msg
|
||||||
|
*/
|
||||||
public static void showLoadingDialog(Context context, String title, String msg) {
|
public static void showLoadingDialog(Context context, String title, String msg) {
|
||||||
progress = new ProgressDialog(context);
|
progress = new ProgressDialog(context);
|
||||||
progress.setTitle(title);
|
progress.setTitle(title);
|
||||||
|
@ -112,17 +127,23 @@ public class Utils {
|
||||||
progress.show();
|
progress.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop loading dialog
|
||||||
|
*/
|
||||||
public static void dismissLoadingDialog() {
|
public static void dismissLoadingDialog() {
|
||||||
|
|
||||||
if (progress != null && progress.isShowing()) {
|
if (progress != null && progress.isShowing()) {
|
||||||
progress.dismiss();
|
progress.dismiss();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get all the notes from the object
|
||||||
|
* @param noteObject
|
||||||
|
* @param time
|
||||||
|
* @return
|
||||||
|
* @throws JSONException
|
||||||
|
*/
|
||||||
public static Note getNoteFromJsonObj(JSONObject noteObject, Date time) throws JSONException {
|
public static Note getNoteFromJsonObj(JSONObject noteObject, Date time) throws JSONException {
|
||||||
// List<Note> listOfNotes = new ArrayList<>();
|
|
||||||
|
|
||||||
Note note = new Note(
|
Note note = new Note(
|
||||||
noteObject.getString("id"),
|
noteObject.getString("id"),
|
||||||
Float.parseFloat(noteObject.getJSONObject("location").getString("lat")),
|
Float.parseFloat(noteObject.getJSONObject("location").getString("lat")),
|
||||||
|
@ -138,10 +159,13 @@ public class Utils {
|
||||||
jsonArrayToStringArray(noteObject.getJSONArray("tags"))
|
jsonArrayToStringArray(noteObject.getJSONArray("tags"))
|
||||||
);
|
);
|
||||||
return note;
|
return note;
|
||||||
// listOfNotes.add(addNote);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* convert json array to string array
|
||||||
|
* @param jArray
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public static ArrayList<String> jsonArrayToStringArray(JSONArray jArray) {
|
public static ArrayList<String> jsonArrayToStringArray(JSONArray jArray) {
|
||||||
ArrayList<String> stringArray = new ArrayList<String>();
|
ArrayList<String> stringArray = new ArrayList<String>();
|
||||||
for (int i = 0, count = jArray.length(); i < count; i++) {
|
for (int i = 0, count = jArray.length(); i < count; i++) {
|
||||||
|
@ -155,6 +179,11 @@ public class Utils {
|
||||||
return stringArray;
|
return stringArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* convert url to image view
|
||||||
|
* @param iv
|
||||||
|
* @param url
|
||||||
|
*/
|
||||||
public static void URLtoImageView(ImageView iv, String url) {
|
public static void URLtoImageView(ImageView iv, String url) {
|
||||||
if (bitmapHash.containsKey(url)) {
|
if (bitmapHash.containsKey(url)) {
|
||||||
iv.setImageBitmap(bitmapHash.get(url));
|
iv.setImageBitmap(bitmapHash.get(url));
|
||||||
|
@ -163,6 +192,9 @@ public class Utils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sets the user avatar
|
||||||
|
*/
|
||||||
private static class setUserAvatar extends AsyncTask<Void, Void, Bitmap> {
|
private static class setUserAvatar extends AsyncTask<Void, Void, Bitmap> {
|
||||||
private ImageView iv;
|
private ImageView iv;
|
||||||
private String url;
|
private String url;
|
||||||
|
@ -174,10 +206,7 @@ public class Utils {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Bitmap doInBackground(Void... v) {
|
protected Bitmap doInBackground(Void... v) {
|
||||||
// Bitmap b;
|
|
||||||
|
|
||||||
return Utils.getBitmapFromURL(url);
|
return Utils.getBitmapFromURL(url);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -185,6 +214,13 @@ public class Utils {
|
||||||
iv.setImageBitmap(b);
|
iv.setImageBitmap(b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets a rounded bitmap
|
||||||
|
* @param bitmap
|
||||||
|
* @param pixels
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {
|
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {
|
||||||
Log.d(TAG, "rounded bitmap");
|
Log.d(TAG, "rounded bitmap");
|
||||||
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap
|
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap
|
||||||
|
@ -208,26 +244,51 @@ public class Utils {
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set location permission
|
||||||
|
* @param locationPermission
|
||||||
|
*/
|
||||||
public static void setLocationPermission(boolean locationPermission) {
|
public static void setLocationPermission(boolean locationPermission) {
|
||||||
mLocationPermission = locationPermission;
|
mLocationPermission = locationPermission;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set camera permission
|
||||||
|
* @param cameraPermission
|
||||||
|
*/
|
||||||
public static void setCameraPermission(boolean cameraPermission) {
|
public static void setCameraPermission(boolean cameraPermission) {
|
||||||
mCameraPermission = cameraPermission;
|
mCameraPermission = cameraPermission;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check for permissions
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public static boolean arePermissionsGranted() {
|
public static boolean arePermissionsGranted() {
|
||||||
return (mLocationPermission && mCameraPermission);
|
return (mLocationPermission && mCameraPermission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* checks for camera permission
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public static boolean isCameraPermissionGranted() {
|
public static boolean isCameraPermissionGranted() {
|
||||||
return mCameraPermission;
|
return mCameraPermission;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* checks for location permission
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public static boolean isLocationPermissionGranted() {
|
public static boolean isLocationPermissionGranted() {
|
||||||
return mLocationPermission;
|
return mLocationPermission;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get user from shared prefs
|
||||||
|
* @param contexst
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public static String getUserFromSharedPrefs(Context contexst) {
|
public static String getUserFromSharedPrefs(Context contexst) {
|
||||||
if (prefs == null) {
|
if (prefs == null) {
|
||||||
prefs = contexst.getSharedPreferences(MainActivity.LOCAL_DATA_TSN, Context.MODE_PRIVATE);
|
prefs = contexst.getSharedPreferences(MainActivity.LOCAL_DATA_TSN, Context.MODE_PRIVATE);
|
||||||
|
@ -235,6 +296,11 @@ public class Utils {
|
||||||
return prefs.getString("UserData", null);
|
return prefs.getString("UserData", null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* update user shared pref
|
||||||
|
* @param data
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
public static void updateUserSharedPref(String data) throws Exception {
|
public static void updateUserSharedPref(String data) throws Exception {
|
||||||
if (prefs == null) throw new Exception("Prefs are not available");
|
if (prefs == null) throw new Exception("Prefs are not available");
|
||||||
SharedPreferences.Editor editor = prefs.edit();
|
SharedPreferences.Editor editor = prefs.edit();
|
||||||
|
@ -242,6 +308,10 @@ public class Utils {
|
||||||
editor.commit();
|
editor.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* remove user data
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
public static void removeUserDataFromPrefs() throws Exception {
|
public static void removeUserDataFromPrefs() throws Exception {
|
||||||
if (prefs == null) throw new Exception("Prefs are not available");
|
if (prefs == null) throw new Exception("Prefs are not available");
|
||||||
SharedPreferences.Editor editor = prefs.edit();
|
SharedPreferences.Editor editor = prefs.edit();
|
||||||
|
|
|
@ -25,6 +25,10 @@ public class VolleyUtilSingleton {
|
||||||
private final String TAG = "VolleyUtilSingleton";
|
private final String TAG = "VolleyUtilSingleton";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* volley singleton
|
||||||
|
* @param context
|
||||||
|
*/
|
||||||
private VolleyUtilSingleton(Context context) {
|
private VolleyUtilSingleton(Context context) {
|
||||||
mCtx = context;
|
mCtx = context;
|
||||||
mRequestQueue = getRequestQueue();
|
mRequestQueue = getRequestQueue();
|
||||||
|
@ -32,6 +36,11 @@ public class VolleyUtilSingleton {
|
||||||
mImageLoader = new ImageLoader(this.mRequestQueue,new LruBitmapCache());
|
mImageLoader = new ImageLoader(this.mRequestQueue,new LruBitmapCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* new singleton
|
||||||
|
* @param context
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public static synchronized VolleyUtilSingleton getInstance(Context context) {
|
public static synchronized VolleyUtilSingleton getInstance(Context context) {
|
||||||
if (mInstance == null) {
|
if (mInstance == null) {
|
||||||
mInstance = new VolleyUtilSingleton(context);
|
mInstance = new VolleyUtilSingleton(context);
|
||||||
|
@ -56,6 +65,11 @@ public class VolleyUtilSingleton {
|
||||||
return mImageLoader;
|
return mImageLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* create new user on http request
|
||||||
|
* @param url
|
||||||
|
* @param body
|
||||||
|
*/
|
||||||
public void newUser(String url, JSONObject body) {
|
public void newUser(String url, JSONObject body) {
|
||||||
JsonObjectRequest request =
|
JsonObjectRequest request =
|
||||||
new JsonObjectRequest(
|
new JsonObjectRequest(
|
||||||
|
@ -86,6 +100,13 @@ public class VolleyUtilSingleton {
|
||||||
addToRequestQueue(request);
|
addToRequestQueue(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* http post request
|
||||||
|
* @param url
|
||||||
|
* @param body
|
||||||
|
* @param successFunction
|
||||||
|
* @param errorFunction
|
||||||
|
*/
|
||||||
public void post(String url, JSONObject body, Response.Listener<JSONObject> successFunction, Response.ErrorListener errorFunction) {
|
public void post(String url, JSONObject body, Response.Listener<JSONObject> successFunction, Response.ErrorListener errorFunction) {
|
||||||
JsonObjectRequest request =
|
JsonObjectRequest request =
|
||||||
new JsonObjectRequest(
|
new JsonObjectRequest(
|
||||||
|
@ -98,6 +119,12 @@ public class VolleyUtilSingleton {
|
||||||
addToRequestQueue(request);
|
addToRequestQueue(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* http get request
|
||||||
|
* @param url
|
||||||
|
* @param successFunction
|
||||||
|
* @param errorFunction
|
||||||
|
*/
|
||||||
public void get(String url, Response.Listener<JSONObject> successFunction, Response.ErrorListener errorFunction) {
|
public void get(String url, Response.Listener<JSONObject> successFunction, Response.ErrorListener errorFunction) {
|
||||||
JsonObjectRequest request =
|
JsonObjectRequest request =
|
||||||
new JsonObjectRequest(
|
new JsonObjectRequest(
|
||||||
|
|
Loading…
Reference in a new issue