diff --git a/app/build.gradle b/app/build.gradle index 73766d0..6cfe864 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,13 +1,14 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 23 - buildToolsVersion '25.0.0' + namespace "homebrew.fuyuri_seiji.org.conditionalreminder" + compileSdkVersion 36 + buildToolsVersion '36.0.0' defaultConfig { applicationId "homebrew.fuyuri_seiji.org.conditionalreminder" - minSdkVersion 19 - targetSdkVersion 22 + minSdkVersion 21 + targetSdkVersion 36 versionCode 1 versionName "1.0" } @@ -17,18 +18,25 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + lint { + baseline = file("lint-baseline.xml") + } } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - testCompile 'junit:junit:4.12' - compile 'com.android.support:appcompat-v7:23.3.0' - compile "com.android.support:percent:23.3.0" - compile 'com.google.android.gms:play-services:8.4.0' - compile 'com.android.support:cardview-v7:23.3.0' - compile 'com.android.support:recyclerview-v7:23.3.0' - compile 'com.android.support:design:23.3.0' - - compile 'com.squareup.picasso:picasso:2.5.2' - compile 'com.getbase:floatingactionbutton:1.3.0' + implementation fileTree(dir: 'libs', include: ['*.jar']) + testImplementation 'junit:junit:4.12' + implementation 'androidx.appcompat:appcompat:1.6.1' + implementation "androidx.percentlayout:percentlayout:1.0.0" + implementation 'com.google.android.gms:play-services-base:18.3.0' + implementation 'com.google.android.libraries.places:places:3.1.0' + implementation 'androidx.cardview:cardview:1.0.0' + implementation 'androidx.recyclerview:recyclerview:1.3.0' + implementation 'com.google.android.material:material:1.10.0' + implementation 'com.squareup.picasso:picasso:2.8' + implementation 'com.getbase:floatingactionbutton:1.10.1' } diff --git a/app/lint-baseline.xml b/app/lint-baseline.xml new file mode 100644 index 0000000..e3dad05 --- /dev/null +++ b/app/lint-baseline.xml @@ -0,0 +1,747 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b6c8612..7df45d3 100755 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,5 @@ - + + + android:label="@string/title_activity_maps" + android:exported="true"> diff --git a/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/CondsAdapter.java b/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/CondsAdapter.java index d60aecd..1de00fa 100644 --- a/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/CondsAdapter.java +++ b/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/CondsAdapter.java @@ -3,7 +3,6 @@ import android.content.Context; import android.content.Intent; import android.location.Location; -import android.support.v7.widget.RecyclerView; import android.text.Editable; import android.text.TextWatcher; import android.util.Log; @@ -23,6 +22,8 @@ import java.util.Arrays; import java.util.Collections; +import androidx.recyclerview.widget.RecyclerView; + /** * Created by sbbg on 5/1/2016 AD. */ diff --git a/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/DefaultItemTouchHelper.java b/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/DefaultItemTouchHelper.java index c609ff1..15111bc 100644 --- a/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/DefaultItemTouchHelper.java +++ b/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/DefaultItemTouchHelper.java @@ -1,7 +1,8 @@ package homebrew.fuyuri_seiji.org.conditionalreminder; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.helper.ItemTouchHelper; + +import androidx.recyclerview.widget.ItemTouchHelper; +import androidx.recyclerview.widget.RecyclerView; /** * Created by sbbg on 5/2/2016 AD. diff --git a/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/EditCondsActivity.java b/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/EditCondsActivity.java index 433f892..5e2d05c 100644 --- a/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/EditCondsActivity.java +++ b/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/EditCondsActivity.java @@ -5,10 +5,7 @@ import android.content.res.Configuration; import android.graphics.Rect; import android.location.Location; -import android.support.v4.content.LocalBroadcastManager; -import android.support.v7.app.AppCompatActivity; import android.os.Bundle; -import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.Menu; import android.view.MenuInflater; @@ -17,7 +14,10 @@ import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.widget.Toast; -import com.getbase.floatingactionbutton.FloatingActionsMenu; + +import androidx.appcompat.app.AppCompatActivity; + +import androidx.recyclerview.widget.RecyclerView; import com.getbase.floatingactionbutton.FloatingActionsMenu; @@ -50,7 +50,7 @@ protected void onCreate( Bundle savedInstanceState ) { args.putDouble( "longitude", intent.getDoubleExtra( "longitude", 0.0 ) ); args.putString( "name", intent.getStringExtra( "name" ) ); fragment.setArguments( args ); - getFragmentManager().beginTransaction().add( R.id.layout_recyclerview, fragment ).commit(); + getSupportFragmentManager().beginTransaction().add( R.id.layout_recyclerview, fragment ).commit(); } } @@ -65,19 +65,16 @@ public boolean onCreateOptionsMenu( Menu menu ) { @Override public boolean onOptionsItemSelected( MenuItem item ) { super.onOptionsItemSelected( item ); - switch (item.getItemId()) { - case R.id.action_save: - // User chose the "Settings" item, show the app settings UI... - //remind_db.insertRemind( new Remind() ); - Log.d( LOGTAG, "SAVE TRIGGER" ); - saveRemind(); - return true; - - default: - // If we got here, the user's action was not recognized. - // Invoke the superclass to handle it. - return super.onOptionsItemSelected(item); + if (item.getItemId() == R.id.action_save) { + // User chose the "Settings" item, show the app settings UI... + //remind_db.insertRemind( new Remind() ); + Log.d(LOGTAG, "SAVE TRIGGER"); + saveRemind(); + return true; } + // If we got here, the user's action was not recognized. + // Invoke the superclass to handle it. + return super.onOptionsItemSelected(item); } private void saveRemind() { diff --git a/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/EditCondsListFragment.java b/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/EditCondsListFragment.java index a1207d3..7592e8d 100644 --- a/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/EditCondsListFragment.java +++ b/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/EditCondsListFragment.java @@ -1,16 +1,18 @@ package homebrew.fuyuri_seiji.org.conditionalreminder; -import android.app.Fragment; import android.location.Location; import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.helper.ItemTouchHelper; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import androidx.recyclerview.widget.ItemTouchHelper; + /** * Created by sbbg on 5/2/2016 AD. */ @@ -26,7 +28,7 @@ public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle s } @Override - public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); // FOR FAKE/TEST diff --git a/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/LocationRemindService.java b/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/LocationRemindService.java index 1b3372e..620f6a1 100644 --- a/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/LocationRemindService.java +++ b/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/LocationRemindService.java @@ -18,10 +18,15 @@ import android.os.IBinder; import android.os.Message; import android.os.Messenger; -import android.support.v7.app.NotificationCompat; import android.util.Log; import android.widget.Toast; +import androidx.core.app.ActivityCompat; +import androidx.core.app.NotificationCompat; +import androidx.core.content.ContextCompat; +import android.Manifest; +import android.content.pm.PackageManager; + import java.util.ArrayList; /** @@ -58,7 +63,11 @@ public void onCreate() listener = new RemindLocationListener(); Criteria criteria = new Criteria(); String provider = locationManager.getBestProvider( criteria, true ); - locationManager.requestLocationUpdates( provider, 4000, 0, listener ); + if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { + locationManager.requestLocationUpdates( provider, 4000, 0, listener ); + } else { + Toast.makeText(this, "Location permission not granted", Toast.LENGTH_SHORT).show(); + } //intent = new Intent( SERVICE_INIT_ACTION ); } @@ -148,6 +157,10 @@ private void showNotification( long remind_id, String place, String todo ) { if ( !isNotificationEnabled ) // If the flag is DISABLED! return ; // do nothing + if (ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { + return; + } + Intent resultIntent = new Intent( this, RemindsListActivity.class ); // // Because clicking the notification opens a new ("special") activity, there's // // no need to create an artificial back stack. diff --git a/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/MapsActivity.java b/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/MapsActivity.java index 7ac56f2..b0979d8 100755 --- a/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/MapsActivity.java +++ b/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/MapsActivity.java @@ -10,28 +10,33 @@ import android.location.LocationManager; import android.location.LocationListener; import android.location.Criteria; -import android.support.v4.app.FragmentActivity; import android.os.Bundle; -import android.support.v7.app.AlertDialog; import android.util.Log; import android.view.View; - +import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.app.AppCompatActivity; import com.google.android.gms.common.api.Status; -import com.google.android.gms.location.places.Place; -import com.google.android.gms.location.places.ui.PlaceAutocompleteFragment; -import com.google.android.gms.location.places.ui.PlaceSelectionListener; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.OnMapReadyCallback; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.MarkerOptions; - +import com.google.android.libraries.places.api.Places; +import com.google.android.libraries.places.api.model.Place; +import com.google.android.libraries.places.widget.AutocompleteSupportFragment; +import com.google.android.libraries.places.widget.listener.PlaceSelectionListener; import java.util.ArrayList; +import java.util.Arrays; +import android.Manifest; +import android.content.pm.PackageManager; +import androidx.core.app.ActivityCompat; -public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { +public class MapsActivity extends AppCompatActivity implements OnMapReadyCallback { private GoogleMap mMap; - private PlaceAutocompleteFragment autocompleteFragment; + private static final int LOCATION_PERMISSION_REQUEST_CODE = 1; + private AutocompleteSupportFragment autocompleteFragment; private String LOGTAG = new String( "ConditionalFinder.MapsActivity::" ); private LocationManager locationManager; private LocationListener locationListener; @@ -53,17 +58,31 @@ protected void onCreate( Bundle savedInstanceState ) { this.startService( intentServiceTrigger ); } + // Initialize Places. + Places.initialize(getApplicationContext(), getString(R.string.google_maps_key)); + places = new ArrayList(); // Obtain the SupportMapFragment and get notified when the map is ready to be used. SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); - mapFragment.getMapAsync( this ); - autocompleteFragment = ( PlaceAutocompleteFragment ) - getFragmentManager().findFragmentById( R.id.place_autocomplete_fragment ); - autocompleteFragment.setOnPlaceSelectedListener( new PlaceSelectionListener() { + if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, LOCATION_PERMISSION_REQUEST_CODE); + } else { + mapFragment.getMapAsync(this); + } + + // Initialize the AutocompleteSupportFragment. + autocompleteFragment = (AutocompleteSupportFragment) + getSupportFragmentManager().findFragmentById(R.id.place_autocomplete_fragment); + + // Specify the types of place data to return. + autocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME, Place.Field.LAT_LNG)); + + // Set up a PlaceSelectionListener to handle the response. + autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() { @Override - public void onPlaceSelected( Place place ) { + public void onPlaceSelected(@NonNull Place place) { // TODO: ONLY 1 PLACE IS SELECTED HERE !! places.add( place ); // ============= GET distance ( MyLocation, Selected Place ) =============== @@ -85,11 +104,11 @@ public void onPlaceSelected( Place place ) { } @Override - public void onError(Status status) { + public void onError(@NonNull Status status) { // TODO: Handle the error. Log.i( LOGTAG, "An error occurred: " + status ); } - } ); + }); } /** @@ -116,11 +135,25 @@ public void onMapReady(GoogleMap googleMap) { //mMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).title("You are here!").snippet("Consider yourself located")); } + @Override + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); + if (requestCode == LOCATION_PERMISSION_REQUEST_CODE) { + if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() + .findFragmentById(R.id.map); + mapFragment.getMapAsync(this); + } + } + } + @Override protected void onPause() { super.onPause(); - locationManager.removeUpdates( locationListener ); - Log.d( LOGTAG, "Location Update STOP" ); + if (locationManager != null && locationListener != null) { + locationManager.removeUpdates( locationListener ); + Log.d( LOGTAG, "Location Update STOP" ); + } } @Override @@ -131,6 +164,9 @@ protected void onResume() { public void MoveToMyLocation() { + if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + return; + } Log.d( LOGTAG, "Location Update START" ); mMap.setMyLocationEnabled( true ); // Get LocationManager object from System Service LOCATION_SERVICE @@ -155,7 +191,9 @@ public void MoveToMyLocation() double latitude = myLocation.getLatitude(); double longitude = myLocation.getLongitude(); LatLng latLng = new LatLng( latitude, longitude ); - autocompleteFragment.setBoundsBias( Utility.LatLngBoundsFromCenter( latLng, 100 ) ); + autocompleteFragment.setLocationBias( com.google.android.libraries.places.api.model.RectangularBounds.newInstance( + Utility.LatLngBoundsFromCenter( latLng, 100 ) + ) ); mMap.moveCamera( CameraUpdateFactory.newLatLng( latLng ) ); } @@ -205,7 +243,9 @@ public void onLocationChanged( Location location ) { myLocation.setLongitude( longitude ); mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng) ); // Set Bounds for complement result: - autocompleteFragment.setBoundsBias( Utility.LatLngBoundsFromCenter( latLng, 100 ) ); + autocompleteFragment.setLocationBias( com.google.android.libraries.places.api.model.RectangularBounds.newInstance( + Utility.LatLngBoundsFromCenter( latLng, 100 ) + ) ); } @Override diff --git a/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/RemindsAdapter.java b/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/RemindsAdapter.java index 391019b..f6f13ec 100644 --- a/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/RemindsAdapter.java +++ b/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/RemindsAdapter.java @@ -1,7 +1,6 @@ package homebrew.fuyuri_seiji.org.conditionalreminder; import android.content.Context; -import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -15,6 +14,8 @@ import java.util.ArrayList; import java.util.Collections; +import androidx.recyclerview.widget.RecyclerView; + /** * Created by sbbg on 5/6/2016 AD. */ diff --git a/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/RemindsListActivity.java b/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/RemindsListActivity.java index 2d4d4fa..415adb8 100644 --- a/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/RemindsListActivity.java +++ b/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/RemindsListActivity.java @@ -1,11 +1,9 @@ package homebrew.fuyuri_seiji.org.conditionalreminder; import android.content.Intent; -import android.support.v7.app.ActionBar; -import android.support.v7.app.AppCompatActivity; import android.os.Bundle; -import android.view.Menu; -import android.view.MenuInflater; + +import androidx.appcompat.app.AppCompatActivity; public class RemindsListActivity extends AppCompatActivity { RemindDBManager remind_db; @@ -20,7 +18,7 @@ protected void onCreate( Bundle savedInstanceState ) { if ( savedInstanceState == null ) { RemindsListFragment fragment = new RemindsListFragment(); - getFragmentManager().beginTransaction().add( R.id.layout_remindslist, fragment ).commit(); + getSupportFragmentManager().beginTransaction().add( R.id.layout_remindslist, fragment ).commit(); } } diff --git a/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/RemindsListFragment.java b/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/RemindsListFragment.java index a6a989e..90cb9cc 100644 --- a/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/RemindsListFragment.java +++ b/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/RemindsListFragment.java @@ -1,16 +1,17 @@ package homebrew.fuyuri_seiji.org.conditionalreminder; -import android.app.Fragment; import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.helper.ItemTouchHelper; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import androidx.recyclerview.widget.ItemTouchHelper; + /** * Created by sbbg on 5/6/2016 AD. */ @@ -18,7 +19,7 @@ public class RemindsListFragment extends Fragment { private static String LOGTAG = "RemindsListFragment"; - private removeNotifyInterface removeReceiver; + private RemoveNotifyInterface removeReceiver; private RemindsAdapter adapter; @@ -76,11 +77,11 @@ public void onSwiped( RecyclerView.ViewHolder viewHolder, int direction ) { itemTouchHelper.attachToRecyclerView( recyclerview_reminds ); } - public interface removeNotifyInterface { + public interface RemoveNotifyInterface { public void remove( int index ); } - public class RemoveNotifierToUI implements RemindsListFragment.removeNotifyInterface { + public class RemoveNotifierToUI implements RemindsListFragment.RemoveNotifyInterface { @Override public void remove( int index ) { getActivity().runOnUiThread(new Runnable() { diff --git a/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/Utility.java b/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/Utility.java index 1ed9875..553cb65 100644 --- a/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/Utility.java +++ b/app/src/main/java/homebrew/fuyuri_seiji/org/conditionalreminder/Utility.java @@ -44,6 +44,6 @@ public static void loadMapThumbnail( Context context, ImageView view, LatLng cen + "&size=" + view.getMeasuredWidth() + "x" + view.getMeasuredHeight() + "&key=" + context.getResources().getString( R.string.google_maps_key ); Log.d( "loadMapThumbnail:", "REQUEST = " + request ); - Picasso.with( context ).load( request ).into( view ); + Picasso.get().load( request ).into( view ); } } diff --git a/app/src/main/res/layout/activity_maps.xml b/app/src/main/res/layout/activity_maps.xml index 94e72d7..6f92bbb 100755 --- a/app/src/main/res/layout/activity_maps.xml +++ b/app/src/main/res/layout/activity_maps.xml @@ -22,7 +22,7 @@ android:layout_height="wrap_content" android:orientation="horizontal" android:weightSum="10"> - - +