Skip to content

Commit f30dd1a

Browse files
committed
Framework updates and fullscreen
1 parent bae7d9f commit f30dd1a

File tree

19 files changed

+235
-65
lines changed

19 files changed

+235
-65
lines changed

app/build.gradle

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 31
4+
compileSdkVersion 33
55
defaultConfig {
66
applicationId "org.nitri.opentopo"
77
minSdkVersion 21
8-
targetSdkVersion 30
9-
versionCode 34
10-
versionName "1.12.4"
8+
targetSdkVersion 33
9+
versionCode 35
10+
versionName "1.13"
1111
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1212
vectorDrawables.useSupportLibrary = true
1313
}
@@ -21,12 +21,11 @@ android {
2121
sourceCompatibility = '1.8'
2222
targetCompatibility = '1.8'
2323
}
24-
lintOptions {
24+
namespace 'org.nitri.opentopo'
25+
lint {
2526
abortOnError false
26-
disable 'ExpiredTargetSdkVersion'
27-
disable 'ExpiringTargetSdkVersion'
27+
disable 'ExpiredTargetSdkVersion', 'ExpiringTargetSdkVersion'
2828
}
29-
namespace 'org.nitri.opentopo'
3029
configurations.all {
3130
resolutionStrategy.force 'com.android.support:appcompat-v7:28.0.0'
3231
}
@@ -35,19 +34,20 @@ android {
3534
dependencies {
3635
implementation fileTree(dir: 'libs', include: ['*.jar'])
3736
//noinspection GradleCompatible
38-
implementation 'androidx.appcompat:appcompat:1.3.1'
39-
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
40-
implementation 'androidx.recyclerview:recyclerview:1.2.1'
41-
implementation 'com.google.android.material:material:1.4.0'
42-
implementation 'org.osmdroid:osmdroid-android:6.0.3'
37+
implementation 'androidx.appcompat:appcompat:1.6.1'
38+
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
39+
implementation 'androidx.recyclerview:recyclerview:1.3.0'
40+
implementation 'com.google.android.material:material:1.9.0'
41+
implementation 'org.osmdroid:osmdroid-android:6.1.16'
4342
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
4443
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
4544
implementation 'com.squareup.retrofit2:retrofit:2.7.2'
4645
implementation 'com.squareup.retrofit2:converter-gson:2.7.2'
47-
implementation 'com.google.code.gson:gson:2.8.6'
46+
implementation 'com.google.code.gson:gson:2.9.0'
4847
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
49-
implementation 'androidx.room:room-runtime:2.3.0'
50-
annotationProcessor 'androidx.room:room-compiler:2.3.0'
48+
implementation 'androidx.room:room-runtime:2.5.2'
49+
annotationProcessor 'androidx.room:room-compiler:2.5.2'
50+
implementation "androidx.preference:preference:1.2.0"
5151
implementation 'net.danlew:android.joda:2.10.9.1'
5252
implementation 'com.github.k3b:k3b-geoHelper:1.1.5'
5353
implementation 'com.github.ticofab:android-gpx-parser:2.0.1'
@@ -61,6 +61,6 @@ dependencies {
6161
exclude group: 'com.android.support', module: 'exifinterface'
6262
}
6363
testImplementation 'junit:junit:4.13.2'
64-
androidTestImplementation 'androidx.test:runner:1.4.0'
65-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
64+
androidTestImplementation 'androidx.test:runner:1.5.2'
65+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
6666
}

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
android:roundIcon="@mipmap/ic_launcher_round"
1818
android:supportsRtl="true"
1919
android:theme="@style/AppTheme">
20-
<activity android:name=".MainActivity">
20+
<activity android:name=".MainActivity"
21+
android:exported="true">
2122
<intent-filter>
2223
<action android:name="android.intent.action.MAIN" />
2324
<category android:name="android.intent.category.LAUNCHER" />

app/src/main/java/org/nitri/opentopo/GpxDetailFragment.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
import androidx.constraintlayout.widget.ConstraintLayout;
1010
import androidx.fragment.app.Fragment;
1111
import androidx.core.content.res.ResourcesCompat;
12-
import androidx.lifecycle.Lifecycle;
13-
import androidx.lifecycle.LifecycleObserver;
14-
import androidx.lifecycle.OnLifecycleEvent;
1512
import androidx.lifecycle.ViewModelProvider;
1613
import androidx.recyclerview.widget.LinearLayoutManager;
1714
import androidx.recyclerview.widget.RecyclerView;

app/src/main/java/org/nitri/opentopo/MainActivity.java

Lines changed: 106 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,26 @@
33
import android.Manifest;
44
import android.content.ContentResolver;
55
import android.content.Intent;
6+
import android.content.SharedPreferences;
67
import android.content.pm.PackageManager;
78
import android.net.Uri;
89
import android.os.Bundle;
10+
import androidx.preference.PreferenceManager;
11+
12+
import android.os.Handler;
913
import android.text.TextUtils;
1014
import android.util.Log;
1115
import android.view.MenuItem;
16+
import android.view.MotionEvent;
1217
import android.widget.Toast;
1318

1419
import androidx.annotation.NonNull;
20+
import androidx.appcompat.app.ActionBar;
1521
import androidx.appcompat.app.AppCompatActivity;
1622
import androidx.core.app.ActivityCompat;
17-
import androidx.fragment.app.Fragment;
23+
import androidx.core.view.WindowCompat;
24+
import androidx.core.view.WindowInsetsCompat;
25+
import androidx.core.view.WindowInsetsControllerCompat;
1826
import androidx.lifecycle.ViewModelProvider;
1927

2028
import org.nitri.opentopo.model.GpxViewModel;
@@ -41,6 +49,9 @@ public class MainActivity extends AppCompatActivity implements MapFragment.OnFra
4149
protected static final String WAY_POINT_DETAIL_FRAGMENT_TAG = "way_point_detail_fragment";
4250
protected static final String NEARBY_FRAGMENT_TAG = "nearby_fragment";
4351

52+
private static final String PREF_FULLSCREEN = "fullscreen";
53+
private static final String PREF_FULLSCREEN_ON_MAP_TAP = "fullscreen_on_map_tap";
54+
4455
private static final int REQUEST_LOCATION_PERMISSION = 1;
4556
private static final int REQUEST_STORAGE_PERMISSION = 2;
4657
private static final int READ_REQUEST_CODE = 69;
@@ -51,8 +62,14 @@ public class MainActivity extends AppCompatActivity implements MapFragment.OnFra
5162
private Uri mGpxUri;
5263
private boolean mZoomToGpx;
5364
private NearbyItem mSelectedNearbyPlace;
54-
private Fragment mMapFragment;
65+
private MapFragment mMapFragment;
5566
private GpxViewModel mGpxViewModel;
67+
boolean mFullscreen = false;
68+
private WindowInsetsControllerCompat windowInsetsController;
69+
private ActionBar actionBar;
70+
private boolean mFullscreenOnMapTap;
71+
private SharedPreferences mPrefs;
72+
private Handler handler;
5673

5774
@Override
5875
protected void onCreate(Bundle savedInstanceState) {
@@ -62,6 +79,12 @@ protected void onCreate(Bundle savedInstanceState) {
6279
mGpxUriString = savedInstanceState.getString(GPX_URI_STATE);
6380
}
6481

82+
handler = new Handler(getMainLooper());
83+
84+
mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
85+
86+
mFullscreenOnMapTap = mPrefs.getBoolean(PREF_FULLSCREEN_ON_MAP_TAP, false);
87+
6588
mGpxViewModel = new ViewModelProvider(this).get(GpxViewModel.class);
6689

6790
Intent intent = getIntent();
@@ -77,8 +100,24 @@ protected void onCreate(Bundle savedInstanceState) {
77100
}
78101

79102
if (savedInstanceState != null) {
80-
mMapFragment = getSupportFragmentManager().getFragment(savedInstanceState, MAP_FRAGMENT_TAG);
103+
mMapFragment = (MapFragment) getSupportFragmentManager().getFragment(savedInstanceState, MAP_FRAGMENT_TAG);
81104
}
105+
106+
windowInsetsController =
107+
WindowCompat.getInsetsController(getWindow(), getWindow().getDecorView());
108+
windowInsetsController.setSystemBarsBehavior(
109+
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
110+
);
111+
112+
actionBar = getSupportActionBar();
113+
114+
setFullscreen(mPrefs.getBoolean(PREF_FULLSCREEN, false));
115+
}
116+
117+
@Override
118+
public boolean dispatchTouchEvent(MotionEvent ev) {
119+
//tapDetector.onTouchEvent(ev);
120+
return super.dispatchTouchEvent(ev);
82121
}
83122

84123
private void handleIntent(Intent intent) {
@@ -101,13 +140,48 @@ private void handleIntent(Intent intent) {
101140
}
102141
}
103142

143+
private void setFullscreen(boolean fullscreen) {
144+
handler.removeCallbacksAndMessages(null);
145+
if (windowInsetsController == null)
146+
return;
147+
if (fullscreen) {
148+
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars());
149+
if (actionBar != null) {
150+
actionBar.hide();
151+
}
152+
if (mMapFragment != null) {
153+
handler.postDelayed( () ->
154+
mMapFragment.showZoomControls(false), 3000);
155+
}
156+
} else {
157+
windowInsetsController.show(WindowInsetsCompat.Type.systemBars());
158+
if (actionBar != null) {
159+
actionBar.show();
160+
}
161+
if (mMapFragment != null) {
162+
mMapFragment.showZoomControls(true);
163+
}
164+
}
165+
mFullscreen = fullscreen;
166+
167+
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
168+
SharedPreferences.Editor editor = preferences.edit();
169+
editor.putBoolean(PREF_FULLSCREEN, mFullscreen);
170+
editor.apply();
171+
172+
}
173+
private void toggleFullscreen() {
174+
mFullscreen = !mFullscreen;
175+
setFullscreen(mFullscreen);
176+
}
177+
104178

105179
private void addMapFragment() {
106180
if (mapFragmentAdded()) {
107181
return;
108182
}
109183
if (mGeoPointFromIntent == null) {
110-
mMapFragment = getSupportFragmentManager().findFragmentByTag(MAP_FRAGMENT_TAG);
184+
mMapFragment = (MapFragment) getSupportFragmentManager().findFragmentByTag(MAP_FRAGMENT_TAG);
111185
if (mMapFragment == null) {
112186
mMapFragment = MapFragment.newInstance();
113187
}
@@ -145,7 +219,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
145219
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
146220
if (requestCode == REQUEST_LOCATION_PERMISSION) {
147221
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
148-
addMapFragment();
222+
addMapFragment();
149223
} else {
150224
finish();
151225
}
@@ -273,4 +347,31 @@ public NearbyItem getSelectedNearbyPlace() {
273347
public void clearSelectedNearbyPlace() {
274348
mSelectedNearbyPlace = null;
275349
}
350+
351+
@Override
352+
public void onMapTap() {
353+
if (mFullscreenOnMapTap) {
354+
toggleFullscreen();
355+
}
356+
}
357+
358+
@Override
359+
public void onMapLongPress() {
360+
361+
}
362+
363+
@Override
364+
public void setFullscreenOnMapTap(boolean fullscreenOnMapTap) {
365+
mFullscreenOnMapTap = fullscreenOnMapTap;
366+
mPrefs.edit().putBoolean(PREF_FULLSCREEN_ON_MAP_TAP, fullscreenOnMapTap).apply();
367+
}
368+
369+
public boolean isFullscreenOnMapTap() {
370+
return mFullscreenOnMapTap;
371+
}
372+
373+
@Override
374+
public boolean isFullscreen() {
375+
return mFullscreen;
376+
}
276377
}

0 commit comments

Comments
 (0)