added permissions checks and handling
This commit is contained in:
parent
e72bbb3fcf
commit
92138f26bb
7 changed files with 178 additions and 67 deletions
|
@ -27,7 +27,7 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public class GPSUtils extends Service implements LocationListener {
|
public class GPSUtils extends Service implements LocationListener {
|
||||||
|
|
||||||
private static final String TAG ="GPSUtils" ;
|
private static final String TAG = "GPSUtils";
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
|
||||||
// flag for GPS status
|
// flag for GPS status
|
||||||
|
@ -53,7 +53,7 @@ public class GPSUtils extends Service implements LocationListener {
|
||||||
getLocation();
|
getLocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
// public Location getLocation() {
|
// public Location getLocation() {
|
||||||
// LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
|
// LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
|
||||||
// if (locationManager != null) {
|
// if (locationManager != null) {
|
||||||
// Location lastKnownLocationGPS = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
|
// Location lastKnownLocationGPS = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
|
||||||
|
@ -69,14 +69,14 @@ public class GPSUtils extends Service implements LocationListener {
|
||||||
// return null;
|
// return null;
|
||||||
// }
|
// }
|
||||||
public Location getLocation() {
|
public Location getLocation() {
|
||||||
try {
|
try {
|
||||||
Log.d("TAG","in get location");
|
Log.d("TAG", "in get location");
|
||||||
locationManager =
|
locationManager =
|
||||||
(LocationManager) mContext
|
(LocationManager) mContext
|
||||||
.getSystemService(LOCATION_SERVICE);
|
.getSystemService(LOCATION_SERVICE);
|
||||||
|
|
||||||
// getting GPS status
|
// getting GPS status
|
||||||
isGPSEnabled = locationManager
|
isGPSEnabled = locationManager
|
||||||
.isProviderEnabled(LocationManager.GPS_PROVIDER);
|
.isProviderEnabled(LocationManager.GPS_PROVIDER);
|
||||||
|
|
||||||
// getting network status
|
// getting network status
|
||||||
|
@ -91,10 +91,10 @@ public class GPSUtils extends Service implements LocationListener {
|
||||||
if (isNetworkEnabled) {
|
if (isNetworkEnabled) {
|
||||||
if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||||
Log.e("TAG", "No Permissions");
|
Log.e("TAG", "No Permissions");
|
||||||
((MainActivity)mContext).setLocationPermission(false);
|
Utils.setLocationPermission(false);
|
||||||
return null;
|
return null;
|
||||||
}else{
|
} else {
|
||||||
((MainActivity)mContext).setLocationPermission(true);
|
Utils.setLocationPermission(true);
|
||||||
}
|
}
|
||||||
Log.d(TAG, "Network");
|
Log.d(TAG, "Network");
|
||||||
if (locationManager != null) {
|
if (locationManager != null) {
|
||||||
|
@ -120,9 +120,8 @@ public class GPSUtils extends Service implements LocationListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else{
|
location = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
|
||||||
location = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +132,7 @@ public class GPSUtils extends Service implements LocationListener {
|
||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showSettingsAlert(){
|
public void showSettingsAlert() {
|
||||||
AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);
|
AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);
|
||||||
|
|
||||||
// Setting Dialog Title
|
// Setting Dialog Title
|
||||||
|
@ -144,7 +143,7 @@ public class GPSUtils extends Service implements LocationListener {
|
||||||
|
|
||||||
// On pressing Settings button
|
// On pressing Settings button
|
||||||
alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
|
alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog,int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
|
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
|
||||||
mContext.startActivity(intent);
|
mContext.startActivity(intent);
|
||||||
}
|
}
|
||||||
|
@ -188,13 +187,13 @@ public class GPSUtils extends Service implements LocationListener {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Address> getFromLocation(double latitude, double longitude, int maxResults){
|
public List<Address> getFromLocation(double latitude, double longitude, int maxResults) {
|
||||||
try {
|
try {
|
||||||
List<Address> addresses;
|
List<Address> addresses;
|
||||||
|
|
||||||
geocoder = new Geocoder(mContext);
|
geocoder = new Geocoder(mContext);
|
||||||
if (latitude != 0 || longitude != 0) {
|
if (latitude != 0 || longitude != 0) {
|
||||||
addresses = geocoder.getFromLocation(latitude ,
|
addresses = geocoder.getFromLocation(latitude,
|
||||||
longitude, maxResults);
|
longitude, maxResults);
|
||||||
return addresses;
|
return addresses;
|
||||||
|
|
||||||
|
@ -212,11 +211,11 @@ public class GPSUtils extends Service implements LocationListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to get latitude
|
* Function to get latitude
|
||||||
* */
|
*/
|
||||||
public double getLatitude(){
|
public double getLatitude() {
|
||||||
if(location != null){
|
if (location != null) {
|
||||||
latitude = location.getLatitude();
|
latitude = location.getLatitude();
|
||||||
}else{
|
} else {
|
||||||
Log.d("Tag", "Got NULL");
|
Log.d("Tag", "Got NULL");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,9 +225,9 @@ public class GPSUtils extends Service implements LocationListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to get longitude
|
* Function to get longitude
|
||||||
* */
|
*/
|
||||||
public double getLongitude(){
|
public double getLongitude() {
|
||||||
if(location != null){
|
if (location != null) {
|
||||||
longitude = location.getLongitude();
|
longitude = location.getLongitude();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,21 +235,20 @@ public class GPSUtils extends Service implements LocationListener {
|
||||||
return longitude;
|
return longitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location getLastKnownLocation(){
|
public Location getLastKnownLocation() {
|
||||||
if (location == null)
|
if (location == null)
|
||||||
return getLocation();
|
return getLocation();
|
||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAddress() {
|
public String getAddress() {
|
||||||
String address="";
|
String address = "";
|
||||||
|
|
||||||
|
|
||||||
|
List<Address> listAddress = getFromLocation(getLatitude(), getLongitude(), 1);
|
||||||
List<Address> listAddress = getFromLocation(getLatitude(),getLongitude(),1);
|
|
||||||
for (int i = 0; i <= listAddress.get(0).getMaxAddressLineIndex(); i++) {
|
for (int i = 0; i <= listAddress.get(0).getMaxAddressLineIndex(); i++) {
|
||||||
listAddress.get(0).getAddressLine(i);
|
listAddress.get(0).getAddressLine(i);
|
||||||
address += listAddress.get(0).getAddressLine(i)+" ";
|
address += listAddress.get(0).getAddressLine(i) + " ";
|
||||||
}
|
}
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@ package com.android_app.matan.ara.sagi.thesocialnotework;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.support.v4.app.ActivityCompat;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
|
@ -40,6 +42,8 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
|
||||||
private final String LOGIN_PATH = "/login";
|
private final String LOGIN_PATH = "/login";
|
||||||
private LoginActivity self; //this
|
private LoginActivity self; //this
|
||||||
protected LinearLayout layout;
|
protected LinearLayout layout;
|
||||||
|
private boolean permissionsReturend = false;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -59,6 +63,9 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
|
||||||
this.mLoginButton.setOnClickListener(this);
|
this.mLoginButton.setOnClickListener(this);
|
||||||
this.mLoginButton.setEnabled(false);
|
this.mLoginButton.setEnabled(false);
|
||||||
|
|
||||||
|
//check for permission
|
||||||
|
// while(!permissionsReturend);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeFocuse() {
|
private void removeFocuse() {
|
||||||
|
@ -220,5 +227,42 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
|
||||||
public void afterTextChanged(Editable editable) {
|
public void afterTextChanged(Editable editable) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// @Override
|
||||||
|
// public void onRequestPermissionsResult(int requestCode,
|
||||||
|
// String permissions[], int[] grantResults) {
|
||||||
|
// permissionsReturend = true;
|
||||||
|
// Log.d(TAG, "onRequestPermissionsResult: in func");
|
||||||
|
// switch (requestCode) {
|
||||||
|
// case FINE_PERM: {
|
||||||
|
// // If request is cancelled, the result arrays are empty.
|
||||||
|
// if (grantResults.length > 0
|
||||||
|
// && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
// Log.d(TAG, "onRequestPermissionsResult: got permission for location");
|
||||||
|
// Utils.setLocationPermission(true);
|
||||||
|
// ActivityCompat.requestPermissions(LoginActivity.this, new String[]{android.Manifest.permission.CAMERA}, CAMERA_PERM);
|
||||||
|
// } else {
|
||||||
|
// Log.d(TAG, "onRequestPermissionsResult:DIDNT get permission for location");
|
||||||
|
//
|
||||||
|
// Toast.makeText(LoginActivity.this,"No Location Permissions granted.\n\"An App is nothing without its permissions\"",Toast.LENGTH_LONG);
|
||||||
|
//// System.exit(0);
|
||||||
|
// }
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// case CAMERA_PERM: {
|
||||||
|
// if (grantResults.length > 0
|
||||||
|
// && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
// Log.d(TAG, "onRequestPermissionsResult: got permission for camera");
|
||||||
|
// Utils.setCameraPermission(true);
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// } else {
|
||||||
|
// Log.d(TAG, "onRequestPermissionsResult: DIDNT get permission for camera");
|
||||||
|
// Toast.makeText(LoginActivity.this,"No Camera Permissions granted.\n\"An App is nothing without its permissions\"",Toast.LENGTH_LONG);
|
||||||
|
// }
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package com.android_app.matan.ara.sagi.thesocialnotework;
|
package com.android_app.matan.ara.sagi.thesocialnotework;
|
||||||
|
|
||||||
|
import android.*;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
@ -11,6 +13,7 @@ import android.os.Bundle;
|
||||||
import android.os.StrictMode;
|
import android.os.StrictMode;
|
||||||
import android.support.design.widget.FloatingActionButton;
|
import android.support.design.widget.FloatingActionButton;
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
|
import android.support.v4.app.ActivityCompat;
|
||||||
import android.support.v4.app.FragmentTransaction;
|
import android.support.v4.app.FragmentTransaction;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -24,6 +27,7 @@ import android.support.v7.widget.Toolbar;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.android.volley.Response;
|
import com.android.volley.Response;
|
||||||
import com.android.volley.VolleyError;
|
import com.android.volley.VolleyError;
|
||||||
|
@ -44,15 +48,15 @@ public class MainActivity extends AppCompatActivity
|
||||||
protected final String TAG = "[TSN / MainActivity]";
|
protected final String TAG = "[TSN / MainActivity]";
|
||||||
protected User user;
|
protected User user;
|
||||||
private GPSUtils gpsUtils;
|
private GPSUtils gpsUtils;
|
||||||
private boolean locationPermission;
|
|
||||||
private GmapFragment gmapFragment;
|
private GmapFragment gmapFragment;
|
||||||
private PersonalFragment personalFragment;
|
private PersonalFragment personalFragment;
|
||||||
private SettingsFragment settingsFragment;
|
private SettingsFragment settingsFragment;
|
||||||
private Toolbar toolbar;
|
private Toolbar toolbar;
|
||||||
public static final String BASE_URL = "http://thesocialnotework-api.appspot.com/api";
|
public static final String BASE_URL = "http://thesocialnotework-api.appspot.com/api";
|
||||||
private ImageView menu_avatar;
|
private ImageView menu_avatar;
|
||||||
private MainActivity self;
|
private MainActivity self;
|
||||||
private NavigationView nav_view;
|
private NavigationView nav_view;
|
||||||
|
private final int FINE_PERM = 0, CAMERA_PERM = 1;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -60,6 +64,8 @@ public class MainActivity extends AppCompatActivity
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
this.self = this;
|
this.self = this;
|
||||||
|
|
||||||
|
|
||||||
toolbar = (Toolbar) findViewById(R.id.toolbar);
|
toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||||
toolbar.setTitle("Personal Notes");
|
toolbar.setTitle("Personal Notes");
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
@ -69,11 +75,6 @@ public class MainActivity extends AppCompatActivity
|
||||||
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
|
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
|
||||||
StrictMode.setThreadPolicy(policy);
|
StrictMode.setThreadPolicy(policy);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||||
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
|
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
|
||||||
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
|
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
|
||||||
|
@ -86,12 +87,12 @@ public class MainActivity extends AppCompatActivity
|
||||||
|
|
||||||
//get Bundle data (UserString)
|
//get Bundle data (UserString)
|
||||||
Bundle b = getIntent().getExtras();
|
Bundle b = getIntent().getExtras();
|
||||||
this.user = new User(b.getString("UserData"));
|
this.user = new User(b.getString("UserData"));
|
||||||
|
|
||||||
//Get The Nav_View Avatar View
|
//Get The Nav_View Avatar View
|
||||||
nav_view = (NavigationView) findViewById(R.id.nav_view);
|
nav_view = (NavigationView) findViewById(R.id.nav_view);
|
||||||
View header_v = nav_view.getHeaderView(0);
|
View header_v = nav_view.getHeaderView(0);
|
||||||
menu_avatar = (ImageView)header_v.findViewById(R.id.nav_user_avatar);
|
menu_avatar = (ImageView) header_v.findViewById(R.id.nav_user_avatar);
|
||||||
|
|
||||||
|
|
||||||
//Change Layout
|
//Change Layout
|
||||||
|
@ -106,7 +107,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
gpsUtils.getLocation();
|
gpsUtils.getLocation();
|
||||||
|
|
||||||
//Change The Avatar
|
//Change The Avatar
|
||||||
Utils.URLtoImageView(menu_avatar, user.getAvatar());
|
Utils.URLtoImageView(menu_avatar, user.getAvatar());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -154,14 +155,14 @@ public class MainActivity extends AppCompatActivity
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
} else if (id == R.id.nav_map) {
|
} else if (id == R.id.nav_map) {
|
||||||
|
|
||||||
Log.d(TAG,"Before going to map");
|
Log.d(TAG, "Before going to map");
|
||||||
toolbar.setTitle("Map");
|
toolbar.setTitle("Map");
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
ft.replace(R.id.fragment_container, gmapFragment);
|
ft.replace(R.id.fragment_container, gmapFragment);
|
||||||
ft.commit();
|
ft.commit();
|
||||||
} else if (id == R.id.nav_personal) {
|
} else if (id == R.id.nav_personal) {
|
||||||
|
|
||||||
Log.d(TAG,"Before going to personal");
|
Log.d(TAG, "Before going to personal");
|
||||||
ft.replace(R.id.fragment_container, personalFragment);
|
ft.replace(R.id.fragment_container, personalFragment);
|
||||||
ft.commit();
|
ft.commit();
|
||||||
} else if (id == R.id.nav_settings) {
|
} else if (id == R.id.nav_settings) {
|
||||||
|
@ -189,20 +190,44 @@ public class MainActivity extends AppCompatActivity
|
||||||
return this.gpsUtils;
|
return this.gpsUtils;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocationPermission(boolean locationPermission) {
|
|
||||||
this.locationPermission = locationPermission;
|
public User getUser() {
|
||||||
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getUserId() {
|
||||||
|
return user.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRequestPermissionsResult(int requestCode,
|
||||||
|
String permissions[], int[] grantResults) {
|
||||||
|
Log.d(TAG, "onRequestPermissionsResult: in func");
|
||||||
|
switch (requestCode) {
|
||||||
|
case FINE_PERM: {
|
||||||
|
// If request is cancelled, the result arrays are empty.
|
||||||
|
if (grantResults.length > 1) {
|
||||||
|
if (!(grantResults[0] == PackageManager.PERMISSION_GRANTED)){
|
||||||
|
Log.d(TAG, "onRequestPermissionsResult: Did Not get permission for location");
|
||||||
|
Toast.makeText(MainActivity.this, "No Location Permissions granted.\n\"An App is nothing without its permissions\"", Toast.LENGTH_LONG).show();
|
||||||
|
System.exit(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(grantResults[1] == PackageManager.PERMISSION_GRANTED)) {
|
||||||
|
Log.d(TAG, "onRequestPermissionsResult:DIDNT get permission for camera");
|
||||||
|
Toast.makeText(MainActivity.this, "No Camera Permissions granted.\nyou will not be able to change avatar", Toast.LENGTH_LONG).show();
|
||||||
|
Utils.setCameraPermission(false);
|
||||||
|
} else {
|
||||||
|
Utils.setCameraPermission(true);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public User getUser(){
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUserId(){return user.getId();}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,6 @@ import java.util.List;
|
||||||
public class PersonalFragment extends Fragment {
|
public class PersonalFragment extends Fragment {
|
||||||
|
|
||||||
protected ListView noteList;
|
protected ListView noteList;
|
||||||
private final int FINE_PERM = 0;
|
|
||||||
private final String BASE_URL = "http://thesocialnotework-api.appspot.com/api";
|
private final String BASE_URL = "http://thesocialnotework-api.appspot.com/api";
|
||||||
private GPSUtils gpsUtils;
|
private GPSUtils gpsUtils;
|
||||||
private List<Note> listOfNotes;
|
private List<Note> listOfNotes;
|
||||||
|
@ -59,6 +58,8 @@ public class PersonalFragment extends Fragment {
|
||||||
private String userId;
|
private String userId;
|
||||||
private final String TAG = "[TSN/PersonalFragment]";
|
private final String TAG = "[TSN/PersonalFragment]";
|
||||||
private MainActivity activity;
|
private MainActivity activity;
|
||||||
|
private final int FINE_PERM = 0, CAMERA_PERM = 1;
|
||||||
|
|
||||||
|
|
||||||
public PersonalFragment() {
|
public PersonalFragment() {
|
||||||
// Required empty public constructor
|
// Required empty public constructor
|
||||||
|
@ -74,8 +75,18 @@ public class PersonalFragment extends Fragment {
|
||||||
Bundle bundle = getArguments();
|
Bundle bundle = getArguments();
|
||||||
this.userId = activity.getUserId();
|
this.userId = activity.getUserId();
|
||||||
Log.d(TAG, "onCreateView: userID: " + userId);
|
Log.d(TAG, "onCreateView: userID: " + userId);
|
||||||
//check for permission
|
|
||||||
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, FINE_PERM);
|
ActivityCompat.requestPermissions(activity, new String[]{
|
||||||
|
android.Manifest.permission.ACCESS_FINE_LOCATION,
|
||||||
|
android.Manifest.permission.CAMERA
|
||||||
|
},
|
||||||
|
FINE_PERM
|
||||||
|
);
|
||||||
|
// ActivityCompat.requestPermissions(activity, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, FINE_PERM);
|
||||||
|
|
||||||
|
// if (!Utils.arePermissionsGranted()) {
|
||||||
|
// Toast.makeText(getContext(), "Missing some Permissions...\nPlease go to app info and enable them", Toast.LENGTH_LONG).show();
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
this.noteList = (ListView) view.findViewById(R.id.ps_list_listview);
|
this.noteList = (ListView) view.findViewById(R.id.ps_list_listview);
|
||||||
|
@ -287,10 +298,7 @@ public class PersonalFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void addNoteFromJsonObj(JSONObject noteObject, Date time) throws JSONException {
|
||||||
|
|
||||||
|
|
||||||
private void addNoteFromJsonObj(JSONObject noteObject, Date time) throws JSONException {
|
|
||||||
Note addNote = new Note(
|
Note addNote = new Note(
|
||||||
noteObject.getString("id"),
|
noteObject.getString("id"),
|
||||||
Float.parseFloat(noteObject.getJSONObject("location").getString("lat")),
|
Float.parseFloat(noteObject.getJSONObject("location").getString("lat")),
|
||||||
|
@ -344,7 +352,7 @@ public class PersonalFragment extends Fragment {
|
||||||
time.setText(note.getTimestamp());
|
time.setText(note.getTimestamp());
|
||||||
location.setText("Address: " + note.getAddress());
|
location.setText("Address: " + note.getAddress());
|
||||||
likes.setText("Likes: " + note.getLikes());
|
likes.setText("Likes: " + note.getLikes());
|
||||||
tags.setText("Tags: "+ note.getTags().toString());
|
tags.setText("Tags: " + note.getTags().toString());
|
||||||
permission.setText("Permission: " + (note.isPublic() ? "Public" : "Private"));
|
permission.setText("Permission: " + (note.isPublic() ? "Public" : "Private"));
|
||||||
Utils.URLtoImageView(avatar, note.getAvatar());
|
Utils.URLtoImageView(avatar, note.getAvatar());
|
||||||
|
|
||||||
|
@ -394,4 +402,7 @@ public class PersonalFragment extends Fragment {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
package com.android_app.matan.ara.sagi.thesocialnotework;
|
package com.android_app.matan.ara.sagi.thesocialnotework;
|
||||||
|
|
||||||
|
import android.*;
|
||||||
|
import android.Manifest;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
|
import android.support.v4.app.ActivityCompat;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -14,6 +18,7 @@ import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
public class SettingsFragment extends Fragment {
|
public class SettingsFragment extends Fragment {
|
||||||
private static final String ARG_PARAM1 = "param1";
|
private static final String ARG_PARAM1 = "param1";
|
||||||
|
@ -105,10 +110,17 @@ public class SettingsFragment extends Fragment {
|
||||||
|
|
||||||
public void onClick(View v)
|
public void onClick(View v)
|
||||||
{
|
{
|
||||||
|
if (ActivityCompat.checkSelfPermission((MainActivity) getActivity(),
|
||||||
|
Manifest.permission.CAMERA)
|
||||||
|
== PackageManager.PERMISSION_GRANTED) {
|
||||||
|
Log.d(TAG, "in camera Button");
|
||||||
|
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
|
||||||
|
startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
Toast.makeText(getActivity(), "No Location Permissions granted.\n\"An App is nothing without its permissions\"", Toast.LENGTH_LONG).show();
|
||||||
|
|
||||||
Log.d(TAG, "in camera Button");
|
}
|
||||||
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
|
|
||||||
startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,8 @@ public class Utils {
|
||||||
public static final String BASE_URL = "http://thesocialnotework-api.appspot.com/api";
|
public static final String BASE_URL = "http://thesocialnotework-api.appspot.com/api";
|
||||||
public static ProgressDialog progress;
|
public static ProgressDialog progress;
|
||||||
private static HashMap<String, Bitmap> bitmapHash = new HashMap<>();
|
private static HashMap<String, Bitmap> bitmapHash = new HashMap<>();
|
||||||
|
private static boolean mLocationPermission = false;
|
||||||
|
private static boolean mCameraPermission = false;
|
||||||
|
|
||||||
|
|
||||||
public static Bitmap getBitmapFromURL(String url) {
|
public static Bitmap getBitmapFromURL(String url) {
|
||||||
|
@ -156,4 +157,24 @@ public class Utils {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static void setLocationPermission(boolean locationPermission) {
|
||||||
|
mLocationPermission = locationPermission;
|
||||||
|
}
|
||||||
|
public static void setCameraPermission(boolean cameraPermission) {
|
||||||
|
mCameraPermission = cameraPermission;
|
||||||
|
}
|
||||||
|
public static boolean arePermissionsGranted() {
|
||||||
|
return (mLocationPermission && mCameraPermission);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isCameraPermissionGranted(){
|
||||||
|
return mCameraPermission;
|
||||||
|
}
|
||||||
|
public static boolean isLocationPermissionGranted(){
|
||||||
|
return mLocationPermission;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue