merge commit
This commit is contained in:
commit
27c92af38d
6
.idea/encodings.xml
Normal file
6
.idea/encodings.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/app/src/main/java/com/uam/wmi/findmytutor/activity/MapFragment.java" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
@ -18,7 +18,7 @@
|
||||
android:theme="@style/AppTheme">
|
||||
<activity
|
||||
android:name=".activity.StartupActivity"
|
||||
android:label="@string/app_name"
|
||||
android:label="@string/title_activity_startup"
|
||||
android:launchMode="singleInstance"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
<intent-filter>
|
||||
@ -44,9 +44,6 @@
|
||||
android:name=".activity.SharingActivity"
|
||||
android:label="@string/title_activity_sharing" />
|
||||
|
||||
|
||||
|
||||
|
||||
<service
|
||||
android:name=".service.BackgroundLocalizationService"
|
||||
android:exported="false"
|
||||
@ -54,9 +51,7 @@
|
||||
android:enabled="true"
|
||||
/>
|
||||
|
||||
<activity android:name=".activity.ProfileActivity" />
|
||||
<!--<activity android:name=".activity.MapActivity" />-->
|
||||
<activity android:name=".activity.NotificationsActivity" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
@ -1,109 +0,0 @@
|
||||
package com.uam.wmi.findmytutor;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.amulyakhare.textdrawable.TextDrawable;
|
||||
import com.amulyakhare.textdrawable.util.ColorGenerator;
|
||||
|
||||
import com.uam.wmi.findmytutor.activity.MainActivity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class ListViewAdapter extends ArrayAdapter<String> {
|
||||
|
||||
|
||||
private MainActivity activity;
|
||||
private List<String> friendList;
|
||||
private List<String> searchList;
|
||||
|
||||
public ListViewAdapter(MainActivity context, int resource, List<String> objects) {
|
||||
super(context, resource, objects);
|
||||
this.activity = context;
|
||||
this.friendList = objects;
|
||||
this.searchList = new ArrayList<>();
|
||||
this.searchList.addAll(friendList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return friendList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItem(int position) {
|
||||
return friendList.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
ViewHolder holder;
|
||||
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
|
||||
// If holder not exist then locate all view from UI file.
|
||||
if (convertView == null) {
|
||||
// inflate UI from XML file
|
||||
convertView = inflater.inflate(R.layout.item_listview, parent, false);
|
||||
// get all UI view
|
||||
holder = new ViewHolder(convertView);
|
||||
// set tag for holder
|
||||
convertView.setTag(holder);
|
||||
} else {
|
||||
// if holder created, get tag from view
|
||||
holder = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
holder.friendName.setText(getItem(position));
|
||||
|
||||
//get first letter of each String item
|
||||
String firstLetter = String.valueOf(getItem(position).charAt(0));
|
||||
|
||||
ColorGenerator generator = ColorGenerator.MATERIAL; // or use DEFAULT
|
||||
// generate random color
|
||||
int color = generator.getColor(getItem(position));
|
||||
|
||||
TextDrawable drawable = TextDrawable.builder()
|
||||
.buildRound(firstLetter, color); // radius in px
|
||||
|
||||
holder.imageView.setImageDrawable(drawable);
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
// Filter method
|
||||
public void filter(String charText) {
|
||||
charText = charText.toLowerCase(Locale.getDefault());
|
||||
friendList.clear();
|
||||
if (charText.length() == 0) {
|
||||
friendList.addAll(searchList);
|
||||
} else {
|
||||
for (String s : searchList) {
|
||||
if (s.toLowerCase(Locale.getDefault()).contains(charText)) {
|
||||
friendList.add(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private class ViewHolder {
|
||||
private ImageView imageView;
|
||||
private TextView friendName;
|
||||
|
||||
public ViewHolder(View v) {
|
||||
imageView = (ImageView) v.findViewById(R.id.image_view);
|
||||
friendName = (TextView) v.findViewById(R.id.text);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,16 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
import android.content.Context;
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.BottomNavigationView;
|
||||
import android.support.design.widget.NavigationView;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
@ -18,13 +23,12 @@ import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.uam.wmi.findmytutor.ListViewAdapter;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.service.BackgroundLocalizationService;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -44,7 +48,12 @@ public abstract class BaseActivity
|
||||
// 4 search
|
||||
private ListView listView;
|
||||
private ArrayList<String> stringArrayList;
|
||||
private ListViewAdapter adapter;
|
||||
private SharingFragment sharingFragment;
|
||||
protected static final int REQUEST_PERMISSIONS = 100;
|
||||
boolean boolean_permission;
|
||||
protected boolean isTutor;
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
@ -91,6 +100,12 @@ public abstract class BaseActivity
|
||||
);
|
||||
navigationView = findViewById(R.id.navigation);
|
||||
navigationView.setOnNavigationItemSelectedListener(this);
|
||||
sharingFragment = new SharingFragment();
|
||||
|
||||
isTutor = PrefUtils.getIsTutor(getApplicationContext());
|
||||
if (!isTutor) {
|
||||
navigationView.findViewById(R.id.nav_profile).setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -108,23 +123,6 @@ public abstract class BaseActivity
|
||||
toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
}
|
||||
private void setData() {
|
||||
stringArrayList = new ArrayList<>();
|
||||
stringArrayList.add("Quynh Trang");
|
||||
stringArrayList.add("Hoang Bien");
|
||||
stringArrayList.add("Duc Tuan");
|
||||
stringArrayList.add("Dang Thanh");
|
||||
stringArrayList.add("Xuan Luu");
|
||||
stringArrayList.add("Phan Thanh");
|
||||
stringArrayList.add("Kim Kien");
|
||||
stringArrayList.add("Ngo Trang");
|
||||
stringArrayList.add("Thanh Ngan");
|
||||
stringArrayList.add("Nguyen Duong");
|
||||
stringArrayList.add("Quoc Cuong");
|
||||
stringArrayList.add("Tran Ha");
|
||||
stringArrayList.add("Vu Danh");
|
||||
stringArrayList.add("Minh Meo");
|
||||
}
|
||||
|
||||
|
||||
private void setUpNav() {
|
||||
@ -149,6 +147,41 @@ public abstract class BaseActivity
|
||||
setUpNav();
|
||||
|
||||
actionBarDrawerToggle.syncState();
|
||||
Log.e("erororr", "guewa!" + isTutor);
|
||||
|
||||
// if (isTutor && getContentViewId() == R.layout.activity_map) {
|
||||
if (isTutor) {
|
||||
Log.e("erororr", "taaaaaak!");
|
||||
fn_permission();
|
||||
}
|
||||
}
|
||||
|
||||
private void fn_permission() {
|
||||
if ((ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
|
||||
|
||||
if ((ActivityCompat.shouldShowRequestPermissionRationale(BaseActivity.this, android.Manifest.permission.ACCESS_FINE_LOCATION))) {
|
||||
|
||||
} else {
|
||||
ActivityCompat.requestPermissions(BaseActivity.this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION
|
||||
|
||||
},
|
||||
REQUEST_PERMISSIONS);
|
||||
}
|
||||
} else {
|
||||
|
||||
if (isTutor) {
|
||||
Intent intent = new Intent(getApplicationContext(), BackgroundLocalizationService.class);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
startForegroundService(intent);
|
||||
} else {
|
||||
startService(intent);
|
||||
}
|
||||
|
||||
} else {
|
||||
Toast.makeText(getApplicationContext(), "Please enable the gps", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -172,10 +205,10 @@ public abstract class BaseActivity
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
if (TextUtils.isEmpty(newText)) {
|
||||
adapter.filter("");
|
||||
listView.clearTextFilter();
|
||||
//adapter.filter("");
|
||||
//listView.clearTextFilter();
|
||||
} else {
|
||||
adapter.filter(newText);
|
||||
//adapter.filter(newText);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -192,6 +225,21 @@ public abstract class BaseActivity
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
|
||||
switch (requestCode) {
|
||||
case REQUEST_PERMISSIONS: {
|
||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
boolean_permission = true;
|
||||
} else {
|
||||
Toast.makeText(getApplicationContext(), "Please allow the permission", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
@ -204,36 +252,41 @@ public abstract class BaseActivity
|
||||
overridePendingTransition(0,0);
|
||||
}
|
||||
|
||||
private void setFragment(Fragment fragment) {
|
||||
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
|
||||
fragmentTransaction.replace(R.id.activity_content, fragment);
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
|
||||
private void removeFragment(Fragment fragment) {
|
||||
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
|
||||
fragmentTransaction.remove(fragment);
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
||||
|
||||
|
||||
|
||||
navigationView.postDelayed(() -> {
|
||||
int itemId = item.getItemId();
|
||||
if (itemId == R.id.nav_map) {
|
||||
startActivity(new Intent(this, MapActivity.class));
|
||||
} else if (itemId == R.id.nav_profile) {
|
||||
startActivity(new Intent(this, ProfileActivity.class));
|
||||
} else if (itemId == R.id.nav_notif) {
|
||||
startActivity(new Intent(this, NotificationsActivity.class));
|
||||
}
|
||||
finish();
|
||||
}, 300);
|
||||
return true;
|
||||
removeFragment(sharingFragment);
|
||||
|
||||
// navigationView.postDelayed(() -> {
|
||||
// int itemId = item.getItemId();
|
||||
// switch (itemId) {
|
||||
// case R.id.nav_profile:
|
||||
// startActivity(new Intent(this, ProfileActivity.class));
|
||||
// case R.id.nav_map:
|
||||
// startActivity(new Intent(this, MapActivity.class));
|
||||
// case R.id.nav_notif:
|
||||
// startActivity(new Intent(this, NotificationsActivity.class));
|
||||
// }
|
||||
//
|
||||
// finish();
|
||||
// }, 300);
|
||||
// return true;
|
||||
// startActivity(new Intent(this, MapActivity.class));
|
||||
} else if (itemId == R.id.nav_profile) {
|
||||
// startActivity(new Intent(this, ProfileActivity.class));
|
||||
setFragment(sharingFragment);
|
||||
|
||||
} else if (itemId == R.id.nav_notif) {
|
||||
//startActivity(new Intent(this, NotificationsActivity.class));
|
||||
setFragment(sharingFragment);
|
||||
}
|
||||
//finish();
|
||||
}, 300);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updateNavigationBarState() {
|
||||
|
@ -1,293 +0,0 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.BottomNavigationView;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.SearchView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
import com.mapbox.mapboxsdk.maps.MapFragment;
|
||||
import com.uam.wmi.findmytutor.ListViewAdapter;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.service.BackgroundLocalizationService;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
private BottomNavigationView mMainNav;
|
||||
private FrameLayout mMainFrame;
|
||||
private boolean isTutor;
|
||||
private MapFragment mapFragment;
|
||||
private NotificationFragment notificationFragment;
|
||||
private ProfileFragment profileFragment;;
|
||||
|
||||
private static final int REQUEST_PERMISSIONS = 100;
|
||||
boolean boolean_permission;
|
||||
|
||||
private DrawerLayout drawerLayout;
|
||||
private ActionBarDrawerToggle actionBarDrawerToggle;
|
||||
|
||||
|
||||
// 4 search
|
||||
private ListView listView;
|
||||
private ArrayList<String> stringArrayList;
|
||||
private ListViewAdapter adapter;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
Bundle extras = getIntent().getExtras();
|
||||
Mapbox.getInstance(this, getString(R.string.access_token));
|
||||
|
||||
configureconfigureNavigationDrawer();
|
||||
configureBottomNavigationView();
|
||||
configureLogoutButton();
|
||||
|
||||
}
|
||||
|
||||
private void configureconfigureNavigationDrawer() {
|
||||
listView = findViewById(R.id.list_item);
|
||||
Toolbar toolbar = findViewById(R.id.toolbar_main);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
setData();
|
||||
adapter = new ListViewAdapter(this, R.layout.item_listview, stringArrayList);
|
||||
listView.setAdapter(adapter);
|
||||
|
||||
listView.setOnItemClickListener((parent, view, position, id) -> Toast.makeText(MainActivity.this, (String)parent.getItemAtPosition(position), Toast.LENGTH_SHORT).show());
|
||||
|
||||
drawerLayout = findViewById(R.id.drawer_layout);
|
||||
|
||||
actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
|
||||
drawerLayout.addDrawerListener(actionBarDrawerToggle);
|
||||
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
actionBar.setDisplayShowTitleEnabled(false);
|
||||
|
||||
if (actionBar != null) {
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setHomeButtonEnabled(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void setFragment(Fragment fragment) {
|
||||
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
|
||||
fragmentTransaction.replace(R.id.main_frame, fragment);
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
|
||||
private void configureBottomNavigationView(){
|
||||
|
||||
mMainFrame = findViewById(R.id.main_frame);
|
||||
mMainNav = findViewById(R.id.main_nav);
|
||||
isTutor = PrefUtils.getIsTutor(getApplicationContext());
|
||||
|
||||
if (!isTutor) {
|
||||
mMainNav.findViewById(R.id.nav_profile).setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
mapFragment = new MapFragment();
|
||||
notificationFragment = new NotificationFragment();
|
||||
profileFragment = new ProfileFragment();
|
||||
|
||||
// Default frag here
|
||||
setFragment(mapFragment);
|
||||
mMainNav.setSelectedItemId(R.id.nav_map);
|
||||
|
||||
/* code below is resposible for changing colours of tabs in main tab menu */
|
||||
mMainNav.setOnNavigationItemSelectedListener(item -> {
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case R.id.nav_map:
|
||||
setFragment(mapFragment);
|
||||
return true;
|
||||
case R.id.nav_notif:
|
||||
setFragment(notificationFragment);
|
||||
return true;
|
||||
case R.id.nav_profile:
|
||||
setFragment(profileFragment);
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void configureLogoutButton(){
|
||||
// Logout button
|
||||
final FloatingActionButton button = findViewById(R.id.logoutButton);
|
||||
|
||||
button.setOnClickListener(view -> {
|
||||
PrefUtils.cleanUserLocalStorage(getApplicationContext());
|
||||
|
||||
Intent i = getBaseContext().getPackageManager()
|
||||
.getLaunchIntentForPackage(getBaseContext().getPackageName());
|
||||
if (i != null) {
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
}
|
||||
startActivity(i);
|
||||
finish();
|
||||
});
|
||||
}
|
||||
|
||||
// mock 4 search bar
|
||||
private void setData() {
|
||||
stringArrayList = new ArrayList<>();
|
||||
stringArrayList.add("Quynh Trang");
|
||||
stringArrayList.add("Hoang Bien");
|
||||
stringArrayList.add("Duc Tuan");
|
||||
stringArrayList.add("Dang Thanh");
|
||||
stringArrayList.add("Xuan Luu");
|
||||
stringArrayList.add("Phan Thanh");
|
||||
stringArrayList.add("Kim Kien");
|
||||
stringArrayList.add("Ngo Trang");
|
||||
stringArrayList.add("Thanh Ngan");
|
||||
stringArrayList.add("Nguyen Duong");
|
||||
stringArrayList.add("Quoc Cuong");
|
||||
stringArrayList.add("Tran Ha");
|
||||
stringArrayList.add("Vu Danh");
|
||||
stringArrayList.add("Minh Meo");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu( Menu menu) {
|
||||
getMenuInflater().inflate( R.menu.menu_main, menu);
|
||||
|
||||
MenuItem myActionMenuItem = menu.findItem( R.id.action_search);
|
||||
final SearchView searchView = (SearchView) myActionMenuItem.getActionView();
|
||||
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
if (TextUtils.isEmpty(newText)) {
|
||||
adapter.filter("");
|
||||
listView.clearTextFilter();
|
||||
} else {
|
||||
adapter.filter(newText);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostCreate(Bundle savedInstanceState) {
|
||||
super.onPostCreate(savedInstanceState);
|
||||
|
||||
actionBarDrawerToggle.syncState();
|
||||
|
||||
if (isTutor) {
|
||||
fn_permission();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
actionBarDrawerToggle.onConfigurationChanged(newConfig);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (actionBarDrawerToggle.onOptionsItemSelected(item)) {
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void fn_permission() {
|
||||
if ((ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
|
||||
|
||||
if ((ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, android.Manifest.permission.ACCESS_FINE_LOCATION))) {
|
||||
|
||||
} else {
|
||||
ActivityCompat.requestPermissions(MainActivity.this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION
|
||||
|
||||
},
|
||||
REQUEST_PERMISSIONS);
|
||||
}
|
||||
} else {
|
||||
|
||||
if (isTutor) {
|
||||
Intent intent = new Intent(getApplicationContext(), BackgroundLocalizationService.class);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
startForegroundService(intent);
|
||||
} else {
|
||||
startService(intent);
|
||||
}
|
||||
|
||||
} else {
|
||||
Toast.makeText(getApplicationContext(), "Please enable the gps", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
|
||||
switch (requestCode) {
|
||||
case REQUEST_PERMISSIONS: {
|
||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
boolean_permission = true;
|
||||
} else {
|
||||
Toast.makeText(getApplicationContext(), "Please allow the permission", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,49 +1,195 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.animation.TypeEvaluator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.widget.Toast;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerViewOptions;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.model.Coordinate;
|
||||
import com.uam.wmi.findmytutor.network.RetrofitClientInstance;
|
||||
import com.uam.wmi.findmytutor.service.BackgroundLocalizationService;
|
||||
import com.uam.wmi.findmytutor.service.CoordinateService;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.annotations.NonNull;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.observers.DisposableSingleObserver;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
|
||||
public class MapActivity extends BaseActivity
|
||||
implements OnMapReadyCallback {
|
||||
|
||||
|
||||
public class MapActivity extends BaseActivity {
|
||||
private MapView mapView;
|
||||
String tag = "LifeCycleEvents";
|
||||
private static final int REQUEST_PERMISSIONS = 100;
|
||||
private boolean isTutor;
|
||||
|
||||
|
||||
private MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
private int mInterval = 10000;
|
||||
private Handler mHandler;
|
||||
|
||||
private Map<String,Coordinate> coordsMap = new HashMap<>();
|
||||
|
||||
private CoordinateService coordinateService;
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
private Runnable mStatusChecker;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
final SharedPreferences sharedPref = getSharedPreferences("fmtPrefs", Context.MODE_PRIVATE);
|
||||
final String authToken = sharedPref.getString("authToken",null);
|
||||
|
||||
mStatusChecker = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try{
|
||||
fetchTopCoords();
|
||||
} finally {
|
||||
mHandler.postDelayed(mStatusChecker, mInterval);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
coordinateService = RetrofitClientInstance.createService(CoordinateService.class,"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiJhM2MxMDU1YS1kZDM0LTQ5ZWItYTFkNS0xY2E5YTE2YzY0ODgiLCJzdWIiOiJzdHJpbmciLCJqdGkiOiI4NTA0NDA5NS00NjBkLTQzZDgtYjMxMC0xYmNiNWMxNGExZjQiLCJleHAiOjE1NDMzNTAzMzQsImlzcyI6Imh0dHA6Ly9maW5kbXl0dXRvci5jb20iLCJhdWQiOiJodHRwOi8vZmluZG15dHV0b3IuY29tIn0.xGyu6iBeq9xF0ufBd01jNzILLq1NeYa-5MeVOiPahD8");
|
||||
|
||||
mHandler = new Handler();
|
||||
Bundle extras = getIntent().getExtras();
|
||||
|
||||
Mapbox.getInstance(this, getString(R.string.access_token));
|
||||
mapView = findViewById(R.id.mapView);
|
||||
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
|
||||
isTutor = PrefUtils.getIsTutor(getApplicationContext());
|
||||
|
||||
if (isTutor) {
|
||||
fn_permission();
|
||||
}
|
||||
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
|
||||
// Customize map with markers, polylines, etc.
|
||||
|
||||
});
|
||||
|
||||
mapView.getMapAsync(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapReady(MapboxMap map) {
|
||||
mapboxMap = map;
|
||||
final Marker marker = mapboxMap.addMarker(new MarkerViewOptions()
|
||||
.position(new LatLng(52.466782,16.927549)));
|
||||
mStatusChecker.run();
|
||||
|
||||
mapboxMap.addOnMapClickListener(new MapboxMap.OnMapClickListener() {
|
||||
@Override
|
||||
public void onMapClick(@NonNull LatLng point) {
|
||||
|
||||
// When the user clicks on the map, we want to animate the marker to that
|
||||
// location.
|
||||
ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position",
|
||||
new LatLngEvaluator(), marker.getPosition(), point);
|
||||
markerAnimator.setDuration(2000);
|
||||
markerAnimator.start();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static class LatLngEvaluator implements TypeEvaluator<LatLng> {
|
||||
// Method is used to interpolate the marker animation.
|
||||
|
||||
private LatLng latLng = new LatLng();
|
||||
|
||||
@Override
|
||||
public LatLng evaluate(float fraction, LatLng startValue, LatLng endValue) {
|
||||
latLng.setLatitude(startValue.getLatitude()
|
||||
+ ((endValue.getLatitude() - startValue.getLatitude()) * fraction));
|
||||
latLng.setLongitude(startValue.getLongitude()
|
||||
+ ((endValue.getLongitude() - startValue.getLongitude()) * fraction));
|
||||
return latLng;
|
||||
}
|
||||
}
|
||||
|
||||
private void fetchTopCoords() {
|
||||
disposable.add(
|
||||
// coordinateService.getTopCoordinates()
|
||||
coordinateService.getOnlineCoordinates()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeWith(new DisposableSingleObserver<List<Coordinate>>() {
|
||||
@Override
|
||||
public void onSuccess(List<Coordinate> coordsList) {
|
||||
|
||||
|
||||
for (Coordinate element : coordsList) {
|
||||
String id = element.getUserId();
|
||||
Coordinate cord = coordsMap.get(id);
|
||||
|
||||
|
||||
Log.d("mapper", "a " + mapboxMap.getMarkerViewManager());
|
||||
Log.d("mapper", "b " + coordsMap.size());
|
||||
if (cord != null) {
|
||||
if (!cord.getLongitude().equals(element.getLongitude())
|
||||
) {
|
||||
Log.d("mapper", " cos sie zienilo ");
|
||||
Marker marker = mapboxMap.addMarker(new MarkerViewOptions()
|
||||
.title(cord.getUserId())
|
||||
.position(new LatLng(cord.getLatitude(),cord.getLongitude())));
|
||||
|
||||
ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position",
|
||||
new LatLngEvaluator(), marker.getPosition(), new LatLng(element.getLatitude(),element.getLongitude()));
|
||||
markerAnimator.setDuration(2000);
|
||||
markerAnimator.start();
|
||||
|
||||
|
||||
// coordsMap.replace(id,element);
|
||||
coordsMap.remove(id);
|
||||
coordsMap.put(id,element);
|
||||
} else if (!cord.getTimeStamp().equals(element.getTimeStamp())){
|
||||
Log.d("mapper", "update");
|
||||
Log.d("mapper", " "+cord.getTimeStamp());
|
||||
Log.d("mapper", " " + element.getTimeStamp());
|
||||
// coordsMap.replace(id,element);
|
||||
coordsMap.remove(id);
|
||||
coordsMap.put(id,element);
|
||||
}
|
||||
} else {
|
||||
coordsMap.put(id,element);
|
||||
mapboxMap.addMarker(new MarkerOptions().position(new LatLng(element.getLatitude(), element.getLongitude())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("Error",e.toString());
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Add the mapView lifecycle to the activity's lifecycle methods
|
||||
@ -81,6 +227,8 @@ public class MapActivity extends BaseActivity {
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mapView.onDestroy();
|
||||
mHandler.removeCallbacks(mStatusChecker);
|
||||
disposable.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -89,9 +237,6 @@ public class MapActivity extends BaseActivity {
|
||||
mapView.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void fn_permission() {
|
||||
if ((ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
|
||||
|
||||
|
@ -1,98 +0,0 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.app.Fragment;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.network.ApiClient;
|
||||
import com.uam.wmi.findmytutor.service.CoordinateService;
|
||||
|
||||
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
*/
|
||||
public class MapFragment extends Fragment {
|
||||
private MapView mapView;
|
||||
|
||||
|
||||
public MapFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_map, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
mapView = (MapView) view.findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
CoordinateService service = ApiClient.getClient(getApplicationContext())
|
||||
.create(CoordinateService.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
mapView.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mapView.onResume();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mapView.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
mapView.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
super.onLowMemory();
|
||||
mapView.onLowMemory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
mapView.onDestroy();
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void onDestroy() {
|
||||
// super.onDestroy();
|
||||
// mapView.onDestroy();
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
mapView.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.app.Fragment;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
*/
|
||||
public class NotificationFragment extends Fragment {
|
||||
|
||||
|
||||
public NotificationFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_notification, container, false);
|
||||
}
|
||||
|
||||
}
|
@ -1,266 +0,0 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.animation.TypeEvaluator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerViewOptions;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.model.Coordinate;
|
||||
import com.uam.wmi.findmytutor.network.RetrofitClientInstance;
|
||||
import com.uam.wmi.findmytutor.service.CoordinateService;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.annotations.NonNull;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.observers.DisposableSingleObserver;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
|
||||
public class NotificationsActivity extends BaseActivity implements
|
||||
OnMapReadyCallback {
|
||||
|
||||
private int mInterval = 10000;
|
||||
private Handler mHandler;
|
||||
|
||||
private MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
private Map<String,Coordinate> coordsMap = new HashMap<>();
|
||||
|
||||
private CoordinateService coordinateService;
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// This contains the MapView in XML and needs to be called after the access token is configured.
|
||||
setContentView(R.layout.activity_notifications);
|
||||
|
||||
|
||||
// mapInit(savedInstanceState);
|
||||
|
||||
// Mapbox access token is configured here. This needs to be called either in your application
|
||||
// object or in the same activity which contains the mapview.
|
||||
Mapbox.getInstance(this, getString(R.string.access_token));
|
||||
|
||||
|
||||
|
||||
mapView = findViewById(R.id.mapView2);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(this);
|
||||
|
||||
|
||||
final SharedPreferences sharedPref = getSharedPreferences("fmtPrefs", Context.MODE_PRIVATE);
|
||||
final String authToken = sharedPref.getString("authToken",null);
|
||||
|
||||
coordinateService = RetrofitClientInstance.createService(CoordinateService.class,"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiI2YjhmNzFiMS00NDM2LTQxZGQtYjg3MC1mNzZlNjdkNDM4NDMiLCJzdWIiOiJzdHJpbmciLCJqdGkiOiJiZGRjZTAwMC0xN2U4LTQwNDUtYWZiNS1kY2RkOWNhNDFiNmQiLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3JvbGUiOiJUdXRvciIsImV4cCI6MTU0MTcxNzk2MywiaXNzIjoiaHR0cDovL2ZpbmRteXR1dG9yLmNvbSIsImF1ZCI6Imh0dHA6Ly9maW5kbXl0dXRvci5jb20ifQ.JJVNeMAwwla6DJk6X8qZUgPFKJp-Epx55W9V_fIwpgg");
|
||||
|
||||
mHandler = new Handler();
|
||||
|
||||
// fetchTopCoords();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapReady(MapboxMap map) {
|
||||
mapboxMap = map;
|
||||
final Marker marker = mapboxMap.addMarker(new MarkerViewOptions()
|
||||
.position(new LatLng(52.466782,16.927549)));
|
||||
mStatusChecker.run();
|
||||
|
||||
mapboxMap.addOnMapClickListener(new MapboxMap.OnMapClickListener() {
|
||||
@Override
|
||||
public void onMapClick(@NonNull LatLng point) {
|
||||
|
||||
// When the user clicks on the map, we want to animate the marker to that
|
||||
// location.
|
||||
ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position",
|
||||
new LatLngEvaluator(), marker.getPosition(), point);
|
||||
markerAnimator.setDuration(2000);
|
||||
markerAnimator.start();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Runnable mStatusChecker = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try{
|
||||
fetchTopCoords();
|
||||
} finally {
|
||||
mHandler.postDelayed(mStatusChecker, mInterval);
|
||||
}
|
||||
}
|
||||
};
|
||||
/*
|
||||
private void mapInit(Bundle savedInstanceState) {
|
||||
// Mapbox access token is configured here. This needs to be called either in your application
|
||||
// object or in the same activity which contains the mapview.
|
||||
Mapbox.getInstance(this, getString(R.string.access_token));
|
||||
// This contains the MapView in XML and needs to be called after the access token is configured.
|
||||
// setContentView(R.layout.activity_notifications);
|
||||
|
||||
mapView = (MapView) findViewById(R.id.mapView2);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(new OnMapReadyCallback() {
|
||||
@Override
|
||||
public void onMapReady(MapboxMap mapboxMap) {
|
||||
|
||||
final Marker marker = mapboxMap.addMarker(new MarkerViewOptions()
|
||||
.position(new LatLng(52.466782,16.927549)));
|
||||
|
||||
mapboxMap.addOnMapClickListener(new MapboxMap.OnMapClickListener() {
|
||||
@Override
|
||||
public void onMapClick(@NonNull LatLng point) {
|
||||
|
||||
// When the user clicks on the map, we want to animate the marker to that
|
||||
// location.
|
||||
ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position",
|
||||
new LatLngEvaluator(), marker.getPosition(), point);
|
||||
markerAnimator.setDuration(2000);
|
||||
markerAnimator.start();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}*/
|
||||
|
||||
private void fetchTopCoords() {
|
||||
disposable.add(
|
||||
// coordinateService.getTopCoordinates()
|
||||
coordinateService.getOnlineCoordinates()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeWith(new DisposableSingleObserver<List<Coordinate>>() {
|
||||
@Override
|
||||
public void onSuccess(List<Coordinate> coordsList) {
|
||||
|
||||
|
||||
for (Coordinate element : coordsList) {
|
||||
String id = element.getUserId();
|
||||
Coordinate cord = coordsMap.get(id);
|
||||
|
||||
|
||||
Log.d("mapper", "a " + mapboxMap.getMarkerViewManager());
|
||||
Log.d("mapper", "b " + coordsMap.size());
|
||||
if (cord != null) {
|
||||
if (!cord.getLongitude().equals(element.getLongitude())
|
||||
) {
|
||||
Log.d("mapper", " cos sie zienilo ");
|
||||
Marker marker = mapboxMap.addMarker(new MarkerViewOptions()
|
||||
.title(cord.getUserId())
|
||||
.position(new LatLng(cord.getLatitude(),cord.getLongitude())));
|
||||
|
||||
ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position",
|
||||
new LatLngEvaluator(), marker.getPosition(), new LatLng(element.getLatitude(),element.getLongitude()));
|
||||
markerAnimator.setDuration(2000);
|
||||
markerAnimator.start();
|
||||
|
||||
coordsMap.replace(id,element);
|
||||
} else if (!cord.getTimeStamp().equals(element.getTimeStamp())){
|
||||
Log.d("mapper", "update");
|
||||
Log.d("mapper", " "+cord.getTimeStamp());
|
||||
Log.d("mapper", " "+element.getTimeStamp());
|
||||
coordsMap.replace(id,element);
|
||||
}
|
||||
} else {
|
||||
coordsMap.put(id,element);
|
||||
mapboxMap.addMarker(new MarkerOptions().position(new LatLng(element.getLatitude(), element.getLongitude())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("Error",e.toString());
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
mapView.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mapView.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mapView.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
mapView.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
super.onLowMemory();
|
||||
mapView.onLowMemory();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mapView.onDestroy();
|
||||
mHandler.removeCallbacks(mStatusChecker);
|
||||
disposable.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
mapView.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
private static class LatLngEvaluator implements TypeEvaluator<LatLng> {
|
||||
// Method is used to interpolate the marker animation.
|
||||
|
||||
private LatLng latLng = new LatLng();
|
||||
|
||||
@Override
|
||||
public LatLng evaluate(float fraction, LatLng startValue, LatLng endValue) {
|
||||
latLng.setLatitude(startValue.getLatitude()
|
||||
+ ((endValue.getLatitude() - startValue.getLatitude()) * fraction));
|
||||
latLng.setLongitude(startValue.getLongitude()
|
||||
+ ((endValue.getLongitude() - startValue.getLongitude()) * fraction));
|
||||
return latLng;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getContentViewId() { return R.layout.activity_notifications; }
|
||||
|
||||
@Override
|
||||
protected int getNavigationMenuItemId() { return R.id.nav_notif; }
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
|
||||
public class ProfileActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
protected int getContentViewId() { return R.layout.activity_profile; }
|
||||
|
||||
@Override
|
||||
protected int getNavigationMenuItemId() {
|
||||
return R.id.nav_profile;
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.app.Fragment;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
*/
|
||||
public class ProfileFragment extends Fragment {
|
||||
|
||||
|
||||
public ProfileFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_profile, container, false);
|
||||
}
|
||||
|
||||
}
|
@ -31,7 +31,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
@Override
|
||||
public void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.pref_main);
|
||||
addPreferencesFromResource(R.layout.pref_main);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class SharingActivity extends AppCompatPreferenceActivity {
|
||||
@Override
|
||||
public void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.pref_sharing);
|
||||
addPreferencesFromResource(R.layout.pref_sharing);
|
||||
|
||||
Preference manualStatus = findPreference("key_manual_status");
|
||||
manualStatus.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
|
@ -0,0 +1,85 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
//public class SharingFragment {
|
||||
//}
|
||||
|
||||
public class SharingFragment extends PreferenceFragment {
|
||||
@Override
|
||||
public void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.layout.pref_sharing);
|
||||
Preference manualStatus = findPreference("key_manual_status");
|
||||
manualStatus.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
ListPreference lp = (ListPreference) findPreference("key_status_value");
|
||||
updateListPreference(lp, newValue, "manual_statuses");
|
||||
return true;
|
||||
});
|
||||
|
||||
/* Preference manualLocation = findPreference("key_sharing_enabled");
|
||||
manualLocation.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
ListPreference lp = (ListPreference) findPreference("key_sharing_enabled");
|
||||
updateListPreference(lp, newValue, "sharing_enabled");
|
||||
return true;
|
||||
});*/
|
||||
|
||||
Preference sharingLocation = findPreference("key_sharing_enabled");
|
||||
sharingLocation.setOnPreferenceChangeListener((preference, o) -> {
|
||||
Log.e("change", "1");
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||
view.setBackgroundColor(getResources().getColor(android.R.color.white));
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
protected void updateListPreference(ListPreference lp,Object newValue,String storageKey){
|
||||
CharSequence [] entries = lp.getEntries();
|
||||
Set<String> defaultEntries = new HashSet(Arrays.asList(entries));
|
||||
SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
|
||||
Set <String> manualStatusSet = sharedPref.getStringSet(storageKey,defaultEntries);
|
||||
manualStatusSet.add((String) newValue);
|
||||
String [] manualStatusArr = manualStatusSet.toArray(new String[0]);
|
||||
Arrays.sort(manualStatusArr);
|
||||
setListPreferenceData(lp.getKey(),manualStatusArr);
|
||||
SharedPreferences.Editor editor = sharedPref.edit();
|
||||
editor.putStringSet(storageKey,manualStatusSet);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
protected ListPreference setListPreferenceData(String lp_name, String [] entries) {
|
||||
ListPreference lp = (ListPreference) findPreference(lp_name);
|
||||
lp.setEntries(entries);
|
||||
CharSequence[] entryValues = new CharSequence [entries.length];
|
||||
|
||||
for (int i = 0; i < entries.length; i++){
|
||||
entryValues[i] = Integer.toString(i+1);
|
||||
}
|
||||
|
||||
lp.setDefaultValue("1");
|
||||
lp.setEntryValues(entryValues);
|
||||
|
||||
return lp;
|
||||
}
|
||||
}
|
@ -2,8 +2,9 @@ package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/drawer_layout"
|
||||
android:layout_width="match_parent"
|
||||
@ -10,6 +11,17 @@
|
||||
android:visibility="visible"
|
||||
tools:openDrawer="start">
|
||||
|
||||
<com.mapbox.mapboxsdk.maps.MapView
|
||||
android:id="@+id/mapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:visibility="visible"
|
||||
mapbox:mapbox_cameraTargetLat="52.466799"
|
||||
mapbox:mapbox_cameraTargetLng="16.927002"
|
||||
mapbox:mapbox_cameraZoom="17"
|
||||
mapbox:mapbox_styleUrl="mapbox://styles/domagalsky/cjiyzrqjp05l72rmj6ntvv2n8">
|
||||
</com.mapbox.mapboxsdk.maps.MapView>
|
||||
|
||||
<android.support.design.widget.NavigationView
|
||||
android:id="@+id/nav_view"
|
||||
android:layout_width="wrap_content"
|
||||
@ -26,6 +38,7 @@
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".activity.MainActivity">
|
||||
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
@ -10,7 +10,7 @@
|
||||
<com.mapbox.mapboxsdk.maps.MapView
|
||||
android:id="@+id/mapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="visible"
|
||||
mapbox:mapbox_cameraTargetLat="52.466799"
|
||||
mapbox:mapbox_cameraTargetLng="16.927002"
|
||||
@ -20,14 +20,4 @@
|
||||
</com.mapbox.mapboxsdk.maps.MapView>
|
||||
|
||||
|
||||
|
||||
<include
|
||||
android:id="@+id/navigation"
|
||||
layout="@layout/element_bottom_navigation"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
</android.support.constraint.ConstraintLayout>
|
@ -1,32 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".activity.NotificationsActivity">
|
||||
<!--tools:context=".examples.annotations.AnimatedMarkerActivity">-->
|
||||
|
||||
<com.mapbox.mapboxsdk.maps.MapView
|
||||
android:id="@+id/mapView2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:visibility="visible"
|
||||
mapbox:mapbox_cameraTargetLat="52.466799"
|
||||
mapbox:mapbox_cameraTargetLng="16.927002"
|
||||
mapbox:mapbox_cameraZoom="17"
|
||||
mapbox:mapbox_styleUrl="mapbox://styles/domagalsky/cjiyzrqjp05l72rmj6ntvv2n8">
|
||||
</com.mapbox.mapboxsdk.maps.MapView>
|
||||
|
||||
<include
|
||||
android:id="@+id/navigation"
|
||||
layout="@layout/element_bottom_navigation"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
</RelativeLayout>
|
@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".activity.ProfileActivity">
|
||||
|
||||
<include
|
||||
android:id="@+id/navigation"
|
||||
layout="@layout/element_bottom_navigation"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
app:layout_constraintBottom_toBottomOf="parent" />
|
||||
|
||||
</android.support.constraint.ConstraintLayout>
|
@ -5,28 +5,46 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
android:id="@+id/cl_root_coordinator"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?actionBarSize"/>
|
||||
<FrameLayout
|
||||
android:id="@+id/activity_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<android.support.design.widget.AppBarLayout
|
||||
android:id="@+id/app_bar_layout"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?actionBarSize" />
|
||||
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="?actionBarSize">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/activity_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_above="@+id/navigation"/>
|
||||
|
||||
<include
|
||||
android:id="@id/navigation"
|
||||
layout="@layout/element_bottom_navigation"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
|
||||
</LinearLayout>
|
||||
<!--<android.support.design.widget.NavigationView-->
|
||||
<!--android:id="@+id/navigation"-->
|
||||
<!--android:layout_width="wrap_content"-->
|
||||
<!--android:layout_height="match_parent"-->
|
||||
<!--android:layout_gravity="start"-->
|
||||
<!--/>-->
|
||||
<android.support.design.widget.NavigationView
|
||||
android:id="@+id/nav_view"
|
||||
android:layout_width="wrap_content"
|
||||
@ -35,5 +53,6 @@
|
||||
app:headerLayout="@layout/nav_header_main"
|
||||
app:menu="@menu/activity_main_drawer">
|
||||
|
||||
|
||||
</android.support.design.widget.NavigationView>
|
||||
</android.support.v4.widget.DrawerLayout>
|
@ -1,22 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
|
||||
tools:context=".activity.MapFragment">
|
||||
|
||||
<com.mapbox.mapboxsdk.maps.MapView
|
||||
android:id="@+id/mapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:visibility="visible"
|
||||
mapbox:mapbox_renderTextureMode="true"
|
||||
mapbox:mapbox_cameraTargetLat="52.466799"
|
||||
mapbox:mapbox_cameraTargetLng="16.927002"
|
||||
mapbox:mapbox_cameraZoom="17"
|
||||
mapbox:mapbox_styleUrl="mapbox://styles/domagalsky/cjiyzrqjp05l72rmj6ntvv2n8">
|
||||
|
||||
</com.mapbox.mapboxsdk.maps.MapView>
|
||||
|
||||
</FrameLayout>
|
@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".activity.NotificationFragment">
|
||||
|
||||
<!-- TODO: Update blank fragment layout -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="Notification fragment" />
|
||||
|
||||
</FrameLayout>
|
@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".activity.ProfileFragment">
|
||||
|
||||
<!-- TODO: Update blank fragment layout -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="Profile Frag" />
|
||||
|
||||
</FrameLayout>
|
@ -1,7 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
tools:ignore="MissingDefaultResource">
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
tools:ignore="MissingDefaultResource"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<PreferenceCategory android:title="@string/settings_category_location">
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
@ -56,6 +59,7 @@
|
||||
android:title="@string/title_manual_location"
|
||||
/>
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
Loading…
Reference in New Issue
Block a user