fragment with background

This commit is contained in:
Domagalski 2018-10-22 01:01:06 +02:00
parent 091b714b18
commit d60a3c413c
3 changed files with 76 additions and 99 deletions

View File

@ -29,7 +29,7 @@
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8 (1)" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View File

@ -6,6 +6,7 @@ import android.app.FragmentTransaction;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.BottomNavigationView;
@ -39,7 +40,6 @@ import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import android.util.Log;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.geometry.LatLng;
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;
@ -62,7 +62,7 @@ import io.reactivex.schedulers.Schedulers;
public class MainActivity extends AppCompatActivity implements
OnMapReadyCallback {
OnMapReadyCallback {
private BottomNavigationView mMainNav;
private FrameLayout mMainFrame;
@ -88,11 +88,7 @@ OnMapReadyCallback {
private CoordinateService coordinateService;
private CompositeDisposable disposable = new CompositeDisposable();
// 4 search
private ListView listView;
private ArrayList<String> stringArrayList;
private ListViewAdapter adapter;
private Runnable mStatusChecker;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -101,6 +97,17 @@ OnMapReadyCallback {
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.eyJuYW1laWQiOiI2YjhmNzFiMS00NDM2LTQxZGQtYjg3MC1mNzZlNjdkNDM4NDMiLCJzdWIiOiJzdHJpbmciLCJqdGkiOiJiZGRjZTAwMC0xN2U4LTQwNDUtYWZiNS1kY2RkOWNhNDFiNmQiLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3JvbGUiOiJUdXRvciIsImV4cCI6MTU0MTcxNzk2MywiaXNzIjoiaHR0cDovL2ZpbmRteXR1dG9yLmNvbSIsImF1ZCI6Imh0dHA6Ly9maW5kbXl0dXRvci5jb20ifQ.JJVNeMAwwla6DJk6X8qZUgPFKJp-Epx55W9V_fIwpgg");
mHandler = new Handler();
@ -108,7 +115,7 @@ OnMapReadyCallback {
Mapbox.getInstance(this, getString(R.string.access_token));
mapView = (MapView) findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
@ -141,28 +148,10 @@ OnMapReadyCallback {
}
Runnable mStatusChecker = new Runnable() {
@Override
public void run() {
try{
fetchTopCoords();
} finally {
mHandler.postDelayed(mStatusChecker, mInterval);
}
}
};
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);
@ -175,7 +164,6 @@ OnMapReadyCallback {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
}
}
private void setFragment(Fragment fragment) {
@ -200,7 +188,7 @@ OnMapReadyCallback {
profileFragment = new ProfileFragment();
// Default frag here
setFragment(mapFragment);
// setFragment(mapFragment);
mMainNav.setSelectedItemId(R.id.nav_map);
/* code below is resposible for changing colours of tabs in main tab menu */
@ -209,13 +197,12 @@ OnMapReadyCallback {
switch (item.getItemId()) {
case R.id.nav_map:
// setFragment(mapFragment);
setFragment(sharingFragment);
return true;
case R.id.nav_notif:
setFragment(notificationFragment);
return true;
case R.id.nav_profile:
setFragment(profileFragment);
setFragment(sharingFragment);
return true;
default:
return false;
@ -240,25 +227,6 @@ OnMapReadyCallback {
});
}
// 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);
@ -274,16 +242,16 @@ OnMapReadyCallback {
@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;
}
});
return true;
}
@ -376,58 +344,64 @@ OnMapReadyCallback {
private void fetchTopCoords() {
disposable.add(
// coordinateService.getTopCoordinates()
// coordinateService.getTopCoordinates()
coordinateService.getOnlineCoordinates()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableSingleObserver<List<Coordinate>>() {
@Override
public void onSuccess(List<Coordinate> coordsList) {
.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);
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())));
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();
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);
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())));
}
}
} 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
public void onError(Throwable e) {
Log.e("Error",e.toString());
}
})
);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
@Override
protected void onStart() {
super.onStart();
@ -464,12 +438,6 @@ OnMapReadyCallback {
mHandler.removeCallbacks(mStatusChecker);
disposable.dispose();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
}

View File

@ -7,6 +7,9 @@ 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;
@ -22,7 +25,6 @@ public class SharingFragment extends PreferenceFragment {
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_sharing);
Preference manualStatus = findPreference("key_manual_status");
manualStatus.setOnPreferenceChangeListener((preference, newValue) -> {
ListPreference lp = (ListPreference) findPreference("key_status_value");
@ -44,6 +46,13 @@ public class SharingFragment extends PreferenceFragment {
});
}
@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();