Created
August 31, 2018 19:36
-
-
Save payne911/d778f16cd440d9a8fb6f5418bd3056bd to your computer and use it in GitHub Desktop.
Buggy thing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout 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:id="@+id/circle_preview_slider" | |
android:visibility="visible" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:background="@android:color/darker_gray" | |
android:orientation="vertical"> | |
<!-- | |
android:progressDrawable="@drawable/slider_progress" | |
android:thumb="@drawable/thumb_img" | |
--> | |
<SeekBar | |
android:id="@+id/circle_mz_seekBar" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="8dp" | |
android:layout_marginEnd="8dp" | |
android:layout_marginLeft="8dp" | |
android:layout_marginRight="8dp" | |
android:layout_marginStart="8dp" | |
android:layout_marginTop="3dp" | |
android:max="10000" | |
android:maxHeight="3dp" | |
android:paddingLeft="10dp" | |
android:paddingRight="10dp" | |
android:progress="1000" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintTop_toTopOf="parent" /> | |
<android.support.constraint.ConstraintLayout | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<EditText | |
android:id="@+id/circle_mz_amnt_meters" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="8dp" | |
android:layout_marginEnd="8dp" | |
android:layout_marginLeft="8dp" | |
android:layout_marginRight="8dp" | |
android:layout_marginStart="8dp" | |
android:layout_marginTop="8dp" | |
android:layout_weight="1" | |
android:ems="10" | |
android:inputType="number" | |
android:maxLength="6" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintEnd_toStartOf="@+id/circle_mz_confirm" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintTop_toTopOf="parent" /> | |
<ImageButton | |
android:id="@+id/circle_mz_cancel" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="8dp" | |
android:layout_marginEnd="24dp" | |
android:layout_marginRight="24dp" | |
android:layout_marginTop="8dp" | |
android:layout_weight="1" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintTop_toTopOf="parent" | |
app:srcCompat="@drawable/ic_clear_black_24dp" /> | |
<ImageButton | |
android:id="@+id/circle_mz_confirm" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="8dp" | |
android:layout_marginEnd="68dp" | |
android:layout_marginRight="68dp" | |
android:layout_marginTop="8dp" | |
android:layout_weight="1" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintEnd_toStartOf="@+id/circle_mz_cancel" | |
app:layout_constraintTop_toTopOf="parent" | |
app:srcCompat="@drawable/ic_check_black_24dp" /> | |
</android.support.constraint.ConstraintLayout> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.payne.simpletestapp.mainActivities; | |
import android.arch.lifecycle.ViewModelProviders; | |
import android.content.Context; | |
import android.content.DialogInterface; | |
import android.content.Intent; | |
import android.content.SharedPreferences; | |
import android.os.Build; | |
import android.os.Bundle; | |
import android.os.Vibrator; | |
import android.preference.PreferenceManager; | |
import android.support.design.widget.Snackbar; | |
import android.support.v4.app.ActivityOptionsCompat; | |
import android.support.v7.app.AlertDialog; | |
import android.support.v7.app.AppCompatActivity; | |
import android.support.v7.widget.SearchView; | |
import android.support.v7.widget.Toolbar; | |
import android.text.InputType; | |
import android.util.Log; | |
import android.view.Gravity; | |
import android.view.LayoutInflater; | |
import android.view.Menu; | |
import android.view.MenuItem; | |
import android.view.View; | |
import android.view.Window; | |
import android.view.inputmethod.InputMethodManager; | |
import android.widget.Button; | |
import android.widget.EditText; | |
import android.widget.LinearLayout; | |
import android.widget.PopupWindow; | |
import android.widget.SeekBar; | |
import android.widget.Toast; | |
import com.example.payne.simpletestapp.alerts.alertViewModel.AlertViewModel; | |
import com.example.payne.simpletestapp.alerts.AlertWrapper; | |
import com.example.payne.simpletestapp.alerts.BasicAlert; | |
import com.example.payne.simpletestapp.alerts.Geometry; | |
import com.example.payne.simpletestapp.alerts.UserAlert; | |
import com.example.payne.simpletestapp.alerts.alertViewModel.AlertViewModelSingletonFactory; | |
import com.example.payne.simpletestapp.animator.MyAnimator; | |
import com.example.payne.simpletestapp.appUtils.App; | |
import com.example.payne.simpletestapp.appUtils.AppTag; | |
import com.example.payne.simpletestapp.authentification.AuthUIActivity; | |
import com.example.payne.simpletestapp.deviceStorage.preferences.SettingsPrefActivity; | |
import com.example.payne.simpletestapp.map.MapDisplay; | |
import com.example.payne.simpletestapp.R; | |
import com.example.payne.simpletestapp.map.pins.BasicPin; | |
import com.example.payne.simpletestapp.map.pins.PinBundle; | |
import com.example.payne.simpletestapp.map.pins.UserPin; | |
import com.example.payne.simpletestapp.monitoredZones.MonitoredZone; | |
import com.example.payne.simpletestapp.notifications.MyFirebaseMessagingService; | |
import com.example.payne.simpletestapp.server.Server; | |
import com.example.payne.simpletestapp.wip.InternetCheck; | |
import com.example.payne.simpletestapp.alertForm.NewAlertFormIntent; | |
import com.example.payne.simpletestapp.user.User; | |
import com.example.payne.simpletestapp.user.karma.Karma; | |
import com.example.payne.simpletestapp.user.karma.KarmaActions; | |
import com.example.payne.simpletestapp.user.karma.KarmaController; | |
import com.example.payne.simpletestapp.user.karma.karmaAPI.KarmaBuilder; | |
import org.osmdroid.api.IGeoPoint; | |
import org.osmdroid.api.IMapController; | |
import org.osmdroid.config.Configuration; | |
import org.osmdroid.tileprovider.tilesource.TileSourceFactory; | |
import org.osmdroid.util.BoundingBox; | |
import org.osmdroid.util.GeoPoint; | |
import org.osmdroid.views.MapView; | |
import org.osmdroid.views.overlay.MapEventsOverlay; | |
import java.util.List; | |
import me.toptas.fancyshowcase.FancyShowCaseView; | |
import lombok.Getter; | |
import static com.example.payne.simpletestapp.appUtils.AppTag.APP_FLOW; | |
import static com.example.payne.simpletestapp.appUtils.AppTag.CACHE; | |
import static com.example.payne.simpletestapp.appUtils.AppTag.CENTER_LAT; | |
import static com.example.payne.simpletestapp.appUtils.AppTag.CENTER_LNG; | |
import static com.example.payne.simpletestapp.appUtils.AppTag.MAIN_IS_FIRST_RUN; | |
import static com.example.payne.simpletestapp.appUtils.AppTag.ZOOM_LVL; | |
/** | |
* Classe de la carte. | |
*/ | |
public class MainActivity extends AppCompatActivity { | |
// positionnement initial au lancement de la carte | |
public static double[] init_center_pos = new double[2]; | |
// | |
public MapView mapView; | |
private MainMapEventReceiver eventReceiver; | |
private MapEventsOverlay mapEventsOverlay; | |
public static Menu menu; | |
public static MapDisplay myMapDisplay; | |
@Getter | |
private MainActivityIntent mainIntent; | |
public MyAnimator myAnimator; | |
private boolean firstRun = true; | |
private InternetCheck internetCheck; | |
private SharedPreferences sharedPreferences; | |
// =========================================================================== | |
// Android Lifecycle methods | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
Log.i(APP_FLOW, "\nmain onCreate"); | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS); | |
getWindow().setAllowEnterTransitionOverlap(true); | |
getWindow().setAllowReturnTransitionOverlap(true); | |
} | |
//----------------------------------------------------------------------- | |
// On create init | |
App.getInstance().setActivityInstance(this); | |
myAnimator = new MyAnimator(this); | |
// is first run ? | |
firstRun = savedInstanceState == null || | |
savedInstanceState.getBoolean(MAIN_IS_FIRST_RUN, true); | |
// ----------------------------------------------------------------------- | |
// setup Firebase and permissions | |
MyFirebaseMessagingService.setUpRegistrationToken(); | |
AuthUIActivity.setUpAuthSyncUp(); | |
// Loading Preferences stored in the phone (or initializing them) | |
PreferenceManager.setDefaultValues(this, R.xml.preferences, false); | |
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); | |
final Context ctx = getApplicationContext(); | |
Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx)); | |
// ----------------------------------------------------------------------- | |
// Fetch AlertViewModel and setup Listener | |
AlertViewModel alertModel = ViewModelProviders | |
.of(this, AlertViewModelSingletonFactory.getInstance()) | |
.get(AlertViewModel.class); | |
alertModel.getLiveAlerts().observe(this, this::redrawLivePin); | |
alertModel.getUserAlerts().observe(this, this::redrawUserPin); | |
alertModel.getHistAlerts().observe(this, this::redrawHistPin); | |
// ----------------------------------------------------------------------- | |
// setup map display | |
// Inflate and create the mapView | |
setContentView(R.layout.activity_main); | |
// maps event | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
mapView = findViewById(R.id.map_v21); | |
} else { | |
mapView = findViewById(R.id.map); | |
} | |
eventReceiver = new MainMapEventReceiver(this, mapView); | |
mapEventsOverlay = new MapEventsOverlay(eventReceiver); | |
mapView.getOverlays().add(0, mapEventsOverlay); | |
mapView.setTileSource(TileSourceFactory.MAPNIK); | |
// set zoom control and multi-touch gesture | |
mapView.setBuiltInZoomControls(false); | |
mapView.setMultiTouchControls(true); | |
// default initial centered position | |
init_center_pos[0] = (double) sharedPreferences.getFloat(AppTag.LAST_KNOWN_LOC_LAT, 45.5161F); | |
init_center_pos[1] = (double) sharedPreferences.getFloat(AppTag.LAST_KNOWN_LOC_LNG, -73.6568F); | |
if (firstRun) { | |
// default initial position | |
recenterMap(init_center_pos[0], init_center_pos[1], 7.0); | |
} else { | |
recenterMap(savedInstanceState.getDouble(CENTER_LAT, init_center_pos[0]), | |
savedInstanceState.getDouble(CENTER_LNG, init_center_pos[1]), | |
savedInstanceState.getDouble(ZOOM_LVL, 7)); | |
} | |
myMapDisplay = new MapDisplay(mapView, this); | |
mapView.setOnDragListener( (view, event) -> { | |
Log.i(CACHE, event.toString()); | |
return true; | |
}); | |
// ----------------------------------------------------------------------- | |
// Populating the Toolbar | |
Toolbar toolbar = findViewById(R.id.toolbar); | |
setSupportActionBar(toolbar); | |
getSupportActionBar().setTitle(""); | |
// Logo button | |
findViewById(R.id.logo).setOnClickListener(view -> | |
Snackbar.make(view, "Merci d'utiliser Acclimate :) ", Snackbar.LENGTH_LONG) | |
.setAction("Action", null).show()); | |
// ----------------------------------------------------------------------- | |
// debug and test | |
/* ************* * | |
* Testing KARMA * | |
* ************* */ | |
User testUser = new User(); | |
testUser.setKarma(new Karma(0)); | |
KarmaController kc = new KarmaController(testUser); | |
KarmaActions karma = KarmaBuilder.createPointHandler(KarmaActions.class, kc); | |
kc.setPoints(100); | |
karma.testKarmaSnack(mapView); | |
/* ************** * | |
* FIN TEST KARMA * | |
* ************** */ | |
// redraw map screen | |
alertModel.forceUpdate(); | |
mapView.invalidate(); | |
} | |
@Override | |
public void onStart() { | |
super.onStart(); | |
getSupportActionBar().setTitle(""); | |
Log.i(APP_FLOW, "main onStart"); | |
// Synchronizing phone while setting up Auth | |
AuthUIActivity.setUpAuthSyncUp(); | |
} | |
@Override | |
public void onResume() { | |
super.onResume(); | |
//this will refresh the osmdroid configuration on resuming. | |
//if you make changes to the configuration, use | |
//SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); | |
//Configuration.getInstance().load(this, PreferenceManager.getDefaultSharedPreferences(this)); | |
mapView.onResume(); //needed for compass, my location overlays, v6.0.0 and up | |
Log.i(APP_FLOW, "main onResume"); | |
AlertViewModel alertModel = ViewModelProviders | |
.of(this, AlertViewModelSingletonFactory.getInstance()) | |
.get(AlertViewModel.class); | |
List<BasicAlert> liveAlertList = alertModel.getLiveAlerts().getValue(); | |
List<BasicAlert> histAlertList = alertModel.getHistAlerts().getValue(); | |
List<UserAlert> userALertList = alertModel.getUserAlerts().getValue(); | |
BasicAlert[] currentLiveAlerts = liveAlertList.toArray(new BasicAlert[liveAlertList.size()]); | |
BasicAlert[] currentHistAlerts = liveAlertList.toArray(new BasicAlert[histAlertList.size()]); | |
UserAlert[] currentUserAlerts = userALertList.toArray(new UserAlert[userALertList.size()]); | |
AlertWrapper wrapper = new AlertWrapper(); | |
wrapper.setLive(currentLiveAlerts); | |
wrapper.setUser(currentUserAlerts); | |
wrapper.setHisto(new BasicAlert[0]); | |
myMapDisplay.setupDisplay(wrapper); | |
// return to saved position | |
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); | |
BoundingBox box = new BoundingBox( | |
sp.getFloat(AppTag.CURRENT_POS_BOX_NORTH,45.5161f), | |
sp.getFloat(AppTag.CURRENT_POS_BOX_EAST, -72.6568f), | |
sp.getFloat(AppTag.CURRENT_POS_BOX_SOUTH,44.5161f), | |
sp.getFloat(AppTag.CURRENT_POS_BOX_WEST, -73.6568f)); | |
GeoPoint center = new GeoPoint( | |
sp.getFloat(AppTag.CURRENT_POS_CENTER_LAT, sharedPreferences.getFloat(AppTag.LAST_KNOWN_LOC_LAT, 45.5161F)), | |
sp.getFloat(AppTag.CURRENT_POS_CENTER_LNG, sharedPreferences.getFloat(AppTag.LAST_KNOWN_LOC_LNG, -73.6568F)) | |
); | |
Log.i(APP_FLOW, "fetched center = " + center.toDoubleString()); | |
// Log.i(APP_FLOW, ((GeoPoint) mapView.getMapCenter()).toDoubleString()); | |
mapView.setExpectedCenter(center); | |
// mapView.getController().zoomTo(sp.getFloat(AppTag.CURRENT_POS_ZOOM_LVL, 17)); | |
// mapView.getController().setCenter(center); | |
} | |
@Override | |
public void onPause() { | |
super.onPause(); | |
//this will refresh the osmdroid configuration on resuming. | |
//if you make changes to the configuration, use | |
//SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); | |
//Configuration.getInstance().save(this, prefs); | |
mapView.onPause(); //needed for compass, my location overlays, v6.0.0 and up | |
// TODO: Save "Last Known Location" save if "GPS_filter" is activated | |
// save current view position | |
BoundingBox currentPos = mapView.getBoundingBox(); | |
GeoPoint currentCenter = (GeoPoint) mapView.getMapCenter(); | |
Log.i(APP_FLOW, "saved center = " + currentCenter.toDoubleString()); | |
sharedPreferences.edit() | |
.putFloat(AppTag.CURRENT_POS_BOX_NORTH, Double.valueOf(currentPos.getLatNorth()).floatValue()) | |
.putFloat(AppTag.CURRENT_POS_BOX_EAST, Double.valueOf(currentPos.getLonEast()).floatValue()) | |
.putFloat(AppTag.CURRENT_POS_BOX_SOUTH, Double.valueOf(currentPos.getLatSouth()).floatValue()) | |
.putFloat(AppTag.CURRENT_POS_BOX_WEST, Double.valueOf(currentPos.getLonWest()).floatValue()) | |
.putFloat(AppTag.CURRENT_POS_CENTER_LAT,Double.valueOf(currentCenter.getLatitude()).floatValue()) | |
.putFloat(AppTag.CURRENT_POS_CENTER_LNG,Double.valueOf(currentCenter.getLongitude()).floatValue()) | |
.putFloat(AppTag.CURRENT_POS_ZOOM_LVL, Double.valueOf(mapView.getZoomLevelDouble()).floatValue()) | |
.apply(); | |
} | |
/** | |
* SAVE HERE CONFIGURATION YOU WANT TO SURVIVE ROTATION CHANGE | |
* @param outState | |
*/ | |
@Override | |
public void onSaveInstanceState(Bundle outState){ | |
// ------------------------------------------- | |
// save current boundingBox | |
IGeoPoint center = mapView.getMapCenter(); | |
outState.putDouble(CENTER_LNG , center.getLongitude()); | |
outState.putDouble(CENTER_LAT , center.getLatitude()); | |
outState.putDouble(ZOOM_LVL, mapView.getZoomLevelDouble()); | |
// ------------------------------------------- | |
// save if main activity is launched for the first time when app run | |
outState.putBoolean(MAIN_IS_FIRST_RUN, false); | |
// ------------------------------------------- | |
// save current pin display options... already saved in PinController ? | |
super.onSaveInstanceState(outState); | |
} | |
// =========================================================================== | |
// Display and menu methods | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
// Inflate the menu; this adds items to the action bar if it is present. | |
getMenuInflater().inflate(R.menu.menu_main, menu); | |
MainActivity.menu = menu; | |
// myMapDisplay.refresh(); | |
//Setting up Search bar | |
MenuItem ourSearchItem = menu.findItem(R.id.action_search); | |
SearchView sv = (SearchView) ourSearchItem.getActionView(); | |
sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() { | |
@Override | |
public boolean onQueryTextSubmit(String query) { | |
myMapDisplay.centerOnGoogleQuery(query); | |
return false; | |
} | |
@Override | |
public boolean onQueryTextChange(String newText) { | |
return false; | |
} | |
}); | |
return true; | |
} | |
@Override | |
public boolean onOptionsItemSelected(MenuItem item) { | |
switch (item.getItemId()) { | |
// Bouton d'ajout de MonitoredZone | |
case (R.id.add): | |
// Uniquement si authentifié ! | |
if (AuthUIActivity.mAuth.getCurrentUser() != null) { | |
findViewById(R.id.add).setEnabled(false); | |
// Uniquement s'il y a internet ! | |
internetCheck = new InternetCheck(hasInternet -> { | |
findViewById(R.id.add).setEnabled(true); | |
if(hasInternet) { | |
// Prompt for the type of MZ | |
AlertDialog.Builder builder = new AlertDialog.Builder(this); | |
builder.setTitle("Quel type de zone voulez-vous ajouter?"); | |
// Set up the buttons | |
builder.setNeutralButton("Cancel", (dialog, which) -> dialog.cancel()); | |
builder.setNegativeButton("Cercle", (dialog, which) -> { | |
// Extracting the center of the screen | |
GeoPoint center = myMapDisplay.getCenter(); // (Lat, Lng, Alt) | |
double[] coords = {center.getLatitude(), center.getLongitude()}; | |
Geometry newGeometry = new Geometry(); | |
newGeometry.setType("Point"); | |
newGeometry.setCoordinates(coords); | |
MonitoredZone newMz = new MonitoredZone(); | |
newMz.setGeometry(newGeometry); | |
promptRadius(newMz); | |
}); | |
builder.setPositiveButton("Rectangle", (dialog, which) -> { | |
// Extraction de la BoundingBox | |
double[] coords = myMapDisplay.getBoundingBoxEdges(); // (double) topCoord, botCoord, rightCoord, leftCoord | |
double[] northWest = {coords[0], coords[3]}; // top, left | |
double[] southEast = {coords[1], coords[2]}; // bottom, right | |
double[][] polyCoords = {northWest, southEast}; | |
Geometry newGeometry = new Geometry(); | |
newGeometry.setType("Polygon"); | |
newGeometry.setPolyCoordinates(polyCoords); | |
MonitoredZone newMz = new MonitoredZone(); | |
newMz.setGeometry(newGeometry); | |
promptName(newMz); | |
}); | |
// Dialog | |
AlertDialog dialog = builder.create(); | |
dialog.show(); | |
} else { | |
myAnimator.fastShakingAnimation(findViewById(R.id.add)); | |
Snackbar.make(mapView, "Une connection internet est requise", Snackbar.LENGTH_SHORT) | |
.setAction("Action", null).show(); | |
} | |
}); | |
} else { | |
// Exemples de cette librairie @ https://github.com/faruktoptas/FancyShowCaseView/blob/master/app/src/main/java/me/toptas/fancyshowcasesample/MainActivity.java | |
focusOnUserIdentification(); | |
} | |
break; | |
// Bouton pour accéder aux Préférences | |
case (R.id.settings): | |
Intent intent = new Intent(getApplicationContext(), SettingsPrefActivity.class); | |
startActivity(intent); | |
break; | |
// Bouton pour accéder à l'Authentification | |
case (R.id.profileBtn): | |
Intent intent2 = new Intent(getApplicationContext(), AuthUIActivity.class); | |
startActivity(intent2); | |
break; | |
default: | |
break; | |
} | |
return super.onOptionsItemSelected(item); | |
} | |
/** | |
* Used to prompt the user for a name for his new MonitoredZone | |
* @param mz | |
*/ | |
private void promptName(MonitoredZone mz) { | |
// Prompt for the name of the MZ | |
AlertDialog.Builder builder = new AlertDialog.Builder(this); | |
builder.setTitle("Veuillez nommer votre Zone"); | |
// Set up the input TODO: style | |
final EditText input = new EditText(this); | |
input.setInputType(InputType.TYPE_CLASS_TEXT); | |
builder.setView(input); | |
// Set up the buttons | |
builder.setNegativeButton("Cancel", (dialog, which) -> dialog.cancel()); | |
builder.setPositiveButton("OK", (dialog, which) -> { | |
mz.setZoneId(null); | |
mz.setUser(App.getInstance().getCurrentUser()); | |
mz.setDateCreation(Server.getCurrentTimeFormatted()); | |
mz.setName(input.getText().toString()); // allows duplicated names... | |
myMapDisplay.getZoneController().createPolygonZone(mz); | |
}); | |
// Dialog | |
AlertDialog dialog = builder.create(); | |
dialog.setOnShowListener(d -> { | |
InputMethodManager inM = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); | |
inM.showSoftInput(input, InputMethodManager.SHOW_IMPLICIT); | |
}); | |
dialog.show(); | |
} | |
/** | |
* TODO: | |
* | |
* @param mz | |
*/ | |
private void promptRadius(MonitoredZone mz) { | |
// LayoutInflater inflater = (LayoutInflater) MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); | |
// View layout = inflater.inflate(R.layout.circle_preview_slider, findViewById(R.id.preview_slider)); | |
// SeekBar seekBar = new SeekBar(this); | |
// seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { | |
// @Override | |
// public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { | |
// // TODO: progress = [0,100], doit être une mesure entière en MÈTRES | |
// mz.setRadius(progress * 100 + 1); | |
// Log.w("seekbar", "progress (int) = " + progress + " | fromUser: " + fromUser); | |
// } | |
// | |
// @Override | |
// public void onStartTrackingTouch(SeekBar seekBar) { } | |
// @Override | |
// public void onStopTrackingTouch(SeekBar seekBar) { } | |
// }); | |
PopupWindow popupWindow = new PopupWindow(LinearLayout.LayoutParams.MATCH_PARENT, 130); | |
//popupWindow.setContentView(seekBar); | |
popupWindow.setContentView((View) getResources().getLayout(R.layout.circle_preview_slider)); | |
popupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.home_gradient)); //TODO: nicer background | |
popupWindow.setAnimationStyle(-1); //TODO: see https://stackoverflow.com/a/9751208/9768291 | |
popupWindow.showAtLocation(findViewById(R.id.toolbar), Gravity.TOP, 0,0); | |
// TODO: à la fin | |
//promptName(mz); | |
} | |
// =========================================================================== | |
// Osmdroid controls methods | |
/* | |
@Override | |
public boolean singleTapConfirmedHelper(GeoPoint p) { | |
Log.i(AppTag.MAP, "Single tap at " + p.toIntString()); | |
InfoWindow.closeAllInfoWindowsOn(mapView); | |
return true; | |
} | |
@Override | |
public boolean longPressHelper(GeoPoint p) { | |
MainActivityHelper helper = new MainActivityHelper(); | |
Log.i(AppTag.MAP, "Long pressed"); | |
if (AuthUIActivity.mAuth.getCurrentUser() != null) { | |
return helper.switchToUserAlertForm(this, p); | |
} else { | |
helper.focusOnUserAuth(this, getString(R.string.required_auth_for_alerts)); | |
return false; | |
} | |
}*/ | |
// =========================================================================== | |
// Helper methods | |
/** | |
* @param p | |
*/ | |
private void askForAddUserPin(final GeoPoint p) { | |
AlertDialog alertDialog = new AlertDialog.Builder(this) | |
.setMessage("Voulez vous ajouter une nouvelle alerte ?") | |
.setPositiveButton("Nouvelle alerte", (arg0, arg1) -> { | |
smallZoonInAnimaton(mapView.getBoundingBox(), p); | |
// Set content view to alertForm ? | |
NewAlertFormIntent alertFormIntent = new NewAlertFormIntent(getApplicationContext()); | |
alertFormIntent.setData(p); | |
// Check if we're running on Android 5.0 or higher | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
// getWindow().setExitTransition(new Explode()); | |
// getWindow().setEnterTransition(new Explode()); | |
// smallZoonInAnimaton(mapView.getBoundingBox(), p); | |
ActivityOptionsCompat options = ActivityOptionsCompat. | |
makeSceneTransitionAnimation(this, mapView, "map_trans"); | |
startActivity(alertFormIntent,options.toBundle()); | |
} else { | |
startActivity(alertFormIntent); | |
} | |
}) | |
.setNegativeButton("Annuler", (dialog, which) -> { | |
Toast.makeText(MainActivity.this, "Retour à la carte", | |
Toast.LENGTH_SHORT).show(); | |
}) | |
.setIcon(R.drawable.ic_upload) | |
.create(); | |
// if there is no internet, we override the Positive Button on click listener to refuse the action | |
// todo : test, maybe add vibrator to the AlertDialog? :D | |
alertDialog.setOnShowListener( dialog -> { | |
Button button = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE); | |
if (!InternetCheck.synchronous(getApplicationContext())){ | |
button.setOnClickListener( view -> { | |
Toast.makeText(MainActivity.this, getText(R.string.no_connection_for_add_alert), | |
Toast.LENGTH_SHORT).show(); | |
myAnimator.fastShakingAnimation(button); | |
}); | |
} | |
}); | |
alertDialog.show(); | |
} | |
/** | |
* Pour centrer la map aux coordonnées données. | |
* Plus le zoom est un grand nombre, plus on est zoomed in. | |
* | |
* @param lat | |
* @param lon | |
* @param zoom | |
*/ | |
private void recenterMap(double lat, double lon, double zoom) { | |
final IMapController mapController = mapView.getController(); | |
final GeoPoint startPoint = new GeoPoint(lat, lon); | |
Log.w("MainActivity GPS", " lat: " + lat + " lon: " + lon); | |
mapController.setCenter(startPoint); | |
mapController.setZoom(zoom); | |
} | |
// Listeners for ModelView modification. Updates the UI with new pin whne | |
// the contents of alerts changes. | |
private void redrawLivePin(List<BasicAlert> liveAlerts){ | |
PinBundle<BasicPin> livePinBundle = myMapDisplay.updateLivePin(liveAlerts); | |
mapView.getOverlayManager().addAll(livePinBundle.toAdd()); | |
mapView.getOverlayManager().removeAll(livePinBundle.toRemove()); | |
} | |
private void redrawUserPin(List<UserAlert> userAlerts){ | |
PinBundle<UserPin> userPinBundle = myMapDisplay.updateUserPin(userAlerts); | |
mapView.getOverlayManager().addAll(userPinBundle.toAdd()); | |
mapView.getOverlayManager().removeAll(userPinBundle.toRemove()); | |
} | |
private void redrawHistPin(List<BasicAlert> histoAlerts){ | |
PinBundle<BasicPin> histoPinBundle = myMapDisplay.updateHistoPin(histoAlerts); | |
mapView.getOverlayManager().addAll(histoPinBundle.toAdd()); | |
mapView.getOverlayManager().removeAll(histoPinBundle.toRemove()); | |
} | |
private void smallZoonInAnimaton(BoundingBox currentBox, GeoPoint center){ | |
double latSpan = mapView.getLatitudeSpanDouble(); | |
double lngSpan = mapView.getLongitudeSpanDouble(); | |
double dx = latSpan / 16d; | |
double dy = lngSpan/ 16d; | |
BoundingBox innerBox = new BoundingBox( | |
currentBox.getLatNorth() - dy, | |
currentBox.getLonEast() - dx, | |
currentBox.getLatSouth() + dy, | |
currentBox.getLonWest() + dx); | |
mapView.zoomToBoundingBox(innerBox, true); | |
} | |
/** | |
* @param requestCode | |
* @param resultCode | |
* @param data | |
*/ | |
@Override | |
public void onActivityResult(int requestCode, int resultCode, Intent data) { | |
super.onActivityResult(requestCode, resultCode, data); | |
Log.i("_photo", "inMain :( " + requestCode +" "+ resultCode); | |
} | |
private void focusOnUserIdentification(){ | |
new FancyShowCaseView.Builder(this) | |
.focusOn(findViewById(R.id.profileBtn)) | |
.focusCircleRadiusFactor(0.8) | |
.title("Vous devez être authentifié") | |
.titleStyle(R.style.MyTitleStyle, Gravity.CENTER) | |
.build() | |
.show(); | |
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); | |
v.vibrate(130); | |
myAnimator.fastShakingAnimation(findViewById(R.id.profileBtn)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment