# Conflicts:
#	app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalFragment.java
This commit is contained in:
Matan Bar Yosef 2016-07-09 02:37:58 +03:00
commit c2fdbc6a22
8 changed files with 175 additions and 66 deletions

View file

@ -27,7 +27,7 @@ import java.util.List;
*/
public class GPSUtils extends Service implements LocationListener {
private static final String TAG ="GPSUtils" ;
private static final String TAG = "GPSUtils";
private final Context mContext;
// flag for GPS status
@ -53,7 +53,7 @@ public class GPSUtils extends Service implements LocationListener {
getLocation();
}
// public Location getLocation() {
// public Location getLocation() {
// LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
// if (locationManager != null) {
// Location lastKnownLocationGPS = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
@ -70,7 +70,7 @@ public class GPSUtils extends Service implements LocationListener {
// }
public Location getLocation() {
try {
Log.d("TAG","in get location");
Log.d("TAG", "in get location");
locationManager =
(LocationManager) mContext
.getSystemService(LOCATION_SERVICE);
@ -91,10 +91,10 @@ public class GPSUtils extends Service implements LocationListener {
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) {
Log.e("TAG", "No Permissions");
((MainActivity)mContext).setLocationPermission(false);
Utils.setLocationPermission(false);
return null;
}else{
((MainActivity)mContext).setLocationPermission(true);
} else {
Utils.setLocationPermission(true);
}
Log.d(TAG, "Network");
if (locationManager != null) {
@ -120,8 +120,7 @@ public class GPSUtils extends Service implements LocationListener {
}
}
}
}
else{
} else {
location = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
}
}
@ -133,7 +132,7 @@ public class GPSUtils extends Service implements LocationListener {
return location;
}
public void showSettingsAlert(){
public void showSettingsAlert() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);
// Setting Dialog Title
@ -144,7 +143,7 @@ public class GPSUtils extends Service implements LocationListener {
// On pressing Settings button
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);
mContext.startActivity(intent);
}
@ -188,13 +187,13 @@ public class GPSUtils extends Service implements LocationListener {
return null;
}
public List<Address> getFromLocation(double latitude, double longitude, int maxResults){
public List<Address> getFromLocation(double latitude, double longitude, int maxResults) {
try {
List<Address> addresses;
geocoder = new Geocoder(mContext);
if (latitude != 0 || longitude != 0) {
addresses = geocoder.getFromLocation(latitude ,
addresses = geocoder.getFromLocation(latitude,
longitude, maxResults);
return addresses;
@ -212,11 +211,11 @@ public class GPSUtils extends Service implements LocationListener {
/**
* Function to get latitude
* */
public double getLatitude(){
if(location != null){
*/
public double getLatitude() {
if (location != null) {
latitude = location.getLatitude();
}else{
} else {
Log.d("Tag", "Got NULL");
}
@ -226,9 +225,9 @@ public class GPSUtils extends Service implements LocationListener {
/**
* Function to get longitude
* */
public double getLongitude(){
if(location != null){
*/
public double getLongitude() {
if (location != null) {
longitude = location.getLongitude();
}
@ -236,21 +235,20 @@ public class GPSUtils extends Service implements LocationListener {
return longitude;
}
public Location getLastKnownLocation(){
public Location getLastKnownLocation() {
if (location == null)
return getLocation();
return location;
}
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++) {
listAddress.get(0).getAddressLine(i);
address += listAddress.get(0).getAddressLine(i)+" ";
address += listAddress.get(0).getAddressLine(i) + " ";
}
return address;
}

View file

@ -3,6 +3,8 @@ package com.android_app.matan.ara.sagi.thesocialnotework;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
@ -40,6 +42,8 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
private final String LOGIN_PATH = "/login";
private LoginActivity self; //this
protected LinearLayout layout;
private boolean permissionsReturend = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -59,6 +63,9 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
this.mLoginButton.setOnClickListener(this);
this.mLoginButton.setEnabled(false);
//check for permission
// while(!permissionsReturend);
}
private void removeFocuse() {
@ -220,5 +227,42 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
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;
// }
// }
// }
}

View file

@ -1,9 +1,11 @@
package com.android_app.matan.ara.sagi.thesocialnotework;
import android.*;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
@ -11,6 +13,7 @@ import android.os.Bundle;
import android.os.StrictMode;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.LayoutInflater;
@ -24,6 +27,7 @@ import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.Toast;
import com.android.volley.Response;
import com.android.volley.VolleyError;
@ -44,7 +48,6 @@ public class MainActivity extends AppCompatActivity
protected final String TAG = "[TSN / MainActivity]";
protected User user;
private GPSUtils gpsUtils;
private boolean locationPermission;
private GmapFragment gmapFragment;
private PersonalFragment personalFragment;
private SettingsFragment settingsFragment;
@ -53,6 +56,7 @@ public class MainActivity extends AppCompatActivity
private ImageView menu_avatar;
private MainActivity self;
private NavigationView nav_view;
private final int FINE_PERM = 0, CAMERA_PERM = 1;
@Override
@ -60,6 +64,8 @@ public class MainActivity extends AppCompatActivity
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.self = this;
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("Personal Notes");
setSupportActionBar(toolbar);
@ -69,11 +75,6 @@ public class MainActivity extends AppCompatActivity
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
@ -91,7 +92,7 @@ public class MainActivity extends AppCompatActivity
//Get The Nav_View Avatar View
nav_view = (NavigationView) findViewById(R.id.nav_view);
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
@ -154,14 +155,14 @@ public class MainActivity extends AppCompatActivity
setSupportActionBar(toolbar);
} else if (id == R.id.nav_map) {
Log.d(TAG,"Before going to map");
Log.d(TAG, "Before going to map");
toolbar.setTitle("Map");
setSupportActionBar(toolbar);
ft.replace(R.id.fragment_container, gmapFragment);
ft.commit();
} 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.commit();
} else if (id == R.id.nav_settings) {
@ -189,20 +190,44 @@ public class MainActivity extends AppCompatActivity
return this.gpsUtils;
}
public void setLocationPermission(boolean locationPermission) {
this.locationPermission = locationPermission;
}
public User getUser(){
public User getUser() {
return user;
}
public String getUserId(){return user.getId();}
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;
}
}
}
}
}

View file

@ -52,7 +52,6 @@ import java.util.List;
public class PersonalFragment extends Fragment {
protected ListView noteList;
private final int FINE_PERM = 0;
private final String BASE_URL = "http://thesocialnotework-api.appspot.com/api";
private GPSUtils gpsUtils;
private List<Note> listOfNotes;
@ -60,6 +59,8 @@ public class PersonalFragment extends Fragment {
private String userId;
private final String TAG = "[TSN/PersonalFragment]";
private MainActivity activity;
private final int FINE_PERM = 0, CAMERA_PERM = 1;
public PersonalFragment() {
// Required empty public constructor
@ -75,8 +76,18 @@ public class PersonalFragment extends Fragment {
Bundle bundle = getArguments();
this.userId = activity.getUserId();
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);
@ -288,9 +299,6 @@ public class PersonalFragment extends Fragment {
}
private void addNoteFromJsonObj(JSONObject noteObject, Date time) throws JSONException {
Note addNote = new Note(
noteObject.getString("id"),
@ -326,6 +334,7 @@ public class PersonalFragment extends Fragment {
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
noteViewDialog.show();
// dialog.getWindow().setAttributes(lp);
//get note_view_full layout elements

View file

@ -1,12 +1,16 @@
package com.android_app.matan.ara.sagi.thesocialnotework;
import android.*;
import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
@ -14,6 +18,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
public class SettingsFragment extends Fragment {
private static final String ARG_PARAM1 = "param1";
@ -105,10 +110,17 @@ public class SettingsFragment extends Fragment {
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();
}
}

View file

@ -40,7 +40,8 @@ public class Utils {
public static final String BASE_URL = "http://thesocialnotework-api.appspot.com/api";
public static ProgressDialog progress;
private static HashMap<String, Bitmap> bitmapHash = new HashMap<>();
private static boolean mLocationPermission = false;
private static boolean mCameraPermission = false;
public static Bitmap getBitmapFromURL(String url) {
@ -185,4 +186,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;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 308 B