Skip to content

Commit

Permalink
Merge pull request #258 from cbalster/make_rotation_optional
Browse files Browse the repository at this point in the history
Make rotation optional
  • Loading branch information
cbalster authored Apr 28, 2019
2 parents 28aeeda + 2776798 commit bb91d14
Show file tree
Hide file tree
Showing 15 changed files with 129 additions and 42 deletions.
13 changes: 6 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ android {

dependencies {
implementation 'com.squareup:otto:1.3.8'
implementation 'org.osmdroid:osmdroid-android:6.0.3'
implementation 'org.osmdroid:osmdroid-android:6.1.0'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
Expand All @@ -88,22 +88,21 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.jakewharton.timber:timber:4.7.1'

implementation 'com.squareup.okhttp3:okhttp:3.12.0'
implementation 'com.squareup.okhttp3:okhttp:3.12.2'
implementation "com.jakewharton:butterknife:$butterknife_version"
annotationProcessor "com.jakewharton:butterknife-compiler:$butterknife_version"

implementation 'org.ligi:AXT:0.37'
implementation 'info.metadude.android:typed-preferences:2.1.0'
implementation "com.google.dagger:dagger:$dagger_version"

compileOnly 'javax.annotation:jsr250-api:1.0'
implementation "com.google.dagger:dagger:$dagger_version"
annotationProcessor "com.google.dagger:dagger-compiler:$dagger_version"

debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.3'
debugImplementation 'com.squareup.leakcanary:leakcanary-support-fragment:1.6.3'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.3'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.0-alpha-1'

errorprone("com.google.errorprone:error_prone_core:2.3.2")
errorprone("com.google.errorprone:error_prone_core:2.3.3")
errorproneJavac("com.google.errorprone:javac:9+181-r4173-1")

testImplementation 'junit:junit:4.12'
testImplementation 'com.google.truth:truth:0.41'
Expand Down
9 changes: 0 additions & 9 deletions app/src/main/java/de/stephanlindauer/criticalmaps/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import android.app.Application;

import com.squareup.leakcanary.LeakCanary;

import org.jetbrains.annotations.NotNull;

import timber.log.Timber;
Expand All @@ -16,13 +14,6 @@ public class App extends Application {
public void onCreate() {
super.onCreate();

if (LeakCanary.isInAnalyzerProcess(this)) {
// This process is dedicated to LeakCanary for heap analysis.
// You should not init your app in this process.
return;
}
LeakCanary.install(this);

if (BuildConfig.DEBUG) {
Timber.plant(new Timber.DebugTree());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,20 @@ public void onActivityCreated(final Bundle savedState) {
R.string.map_no_internet_connection_title,
R.string.map_no_internet_connection_text));

RotationGestureOverlay rotationGestureOverlay = new RotationGestureOverlay(mapView) {
@Override
public void onRotate(float deltaAngle) {
super.onRotate(deltaAngle);
setRotationNorth.setRotation(mapView.getMapOrientation());
}
};
rotationGestureOverlay.setEnabled(true);
mapView.setMultiTouchControls(true);
mapView.getOverlays().add(rotationGestureOverlay);
if (new BooleanPreference(sharedPreferences, SharedPrefsKeys.DISABLE_MAP_ROTATION).get()) {
setRotationNorth.setVisibility(View.GONE);
} else {
RotationGestureOverlay rotationGestureOverlay = new RotationGestureOverlay(mapView) {
@Override
public void onRotate(float deltaAngle) {
super.onRotate(deltaAngle);
setRotationNorth.setRotation(mapView.getMapOrientation());
}
};
rotationGestureOverlay.setEnabled(true);
mapView.setMultiTouchControls(true);
mapView.getOverlays().add(rotationGestureOverlay);
}

if (savedState != null) {
Double zoomLevel = (Double) savedState.get(KEY_MAP_ZOOMLEVEL);
Expand All @@ -247,7 +251,10 @@ public void onRotate(float deltaAngle) {

if (zoomLevel != null && position != null && orientation != null) {
mapView.getController().setZoom(zoomLevel);
mapView.setMapOrientation(orientation);
if (!new BooleanPreference(sharedPreferences, SharedPrefsKeys.DISABLE_MAP_ROTATION)
.get()) {
mapView.setMapOrientation(orientation);
}
setToLocation(position);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public class SettingsFragment extends Fragment {
@BindView(R.id.settings_keep_screen_on_checkbox)
MaterialCheckBox keepScreenOnCheckbox;

@BindView(R.id.settings_map_rotation_checkbox)
MaterialCheckBox mapRotationCheckbox;

@Inject
StorageLocationProvider storageLocationProvider;

Expand Down Expand Up @@ -99,6 +102,9 @@ public void onViewStateRestored(@Nullable Bundle savedInstanceState) {

keepScreenOnCheckbox.setChecked(
new BooleanPreference(sharedPreferences, SharedPrefsKeys.KEEP_SCREEN_ON).get());

mapRotationCheckbox.setChecked(
!new BooleanPreference(sharedPreferences, SharedPrefsKeys.DISABLE_MAP_ROTATION).get());
}

private void updateStorageGraph() {
Expand Down Expand Up @@ -213,6 +219,12 @@ void handleKeepScreenOnChecked(boolean isChecked) {
sharedPreferences, SharedPrefsKeys.KEEP_SCREEN_ON).set(isChecked);
}

@OnCheckedChanged(R.id.settings_map_rotation_checkbox)
void handleDisableMapRotationChecked(boolean isChecked) {
new BooleanPreference(
sharedPreferences, SharedPrefsKeys.DISABLE_MAP_ROTATION).set(!isChecked);
}

@Override
public void onDestroyView() {
super.onDestroyView();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ public static String getString() {
returnString += "BRAND= " + Build.BRAND + "\n";
returnString += "DISPLAY= " + Build.DISPLAY + "\n";
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
//noinspection deprecation
returnString += "CPU_ABI= " + Build.CPU_ABI + "\n";
//noinspection deprecation
returnString += "CPU_ABI2= " + Build.CPU_ABI2 + "\n";
} else {
returnString += "SUPPORTED_ABIS= " + TextUtils.join(", ", Build.SUPPORTED_ABIS) + "\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public interface SharedPrefsKeys {
BuildConfig.APPLICATION_ID + ".SHOW_ON_LOCKSCREEN";
String KEEP_SCREEN_ON =
BuildConfig.APPLICATION_ID + ".KEEP_SCREEN_ON";
String DISABLE_MAP_ROTATION =
BuildConfig.APPLICATION_ID + ".DISABLE_MAP_ROTATION";
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ public StorageLocation getAndSaveBestStorageLocation() {
}

public void setActiveStorageLocation(StorageLocation storageLocation) {
@SuppressWarnings("ConstantConditions")
File osmdroidBasePath = new File(storageLocation.storagePath, "osmdroid");
//noinspection ResultOfMethodCallIgnored
osmdroidBasePath.mkdirs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.osmdroid.tileprovider.MapTileProviderBasic;
import org.osmdroid.tileprovider.modules.SqlTileWriter;
import org.osmdroid.tileprovider.tilesource.OnlineTileSourceBase;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.tileprovider.tilesource.XYTileSource;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.CustomZoomButtonsController;
Expand All @@ -25,7 +24,7 @@

public class MapViewUtils {

final static OnlineTileSourceBase WIKIMEDIA = new XYTileSource("Wikimedia",
private final static OnlineTileSourceBase WIKIMEDIA = new XYTileSource("Wikimedia",
1, 19, 256, ".png",
new String[] {"https://maps.wikimedia.org/osm-intl/"},
"Wikimedia maps | Map data © OpenStreetMap contributors");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public static Notification getNotification(Application application) {
notificationChannel.enableVibration(false);
notificationChannel.setLockscreenVisibility(NotificationCompat.VISIBILITY_PUBLIC);

//noinspection ConstantConditions
mNotificationManager.createNotificationChannel(notificationChannel);
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/logo.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:aapt="http://schemas.android.com/aapt"
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:viewportWidth="800"
android:viewportHeight="400"
android:width="280dp"
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

Expand Down
81 changes: 80 additions & 1 deletion app/src/main/res/layout/fragment_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
android:layout_height="match_parent"
android:orientation="vertical">

<!-- Storage Settings -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down Expand Up @@ -232,7 +233,7 @@
</LinearLayout>
</LinearLayout>


<!-- Screen Settings -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down Expand Up @@ -376,6 +377,84 @@
android:checked="true"/>
</LinearLayout>
</LinearLayout>

<!-- Map Settings -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:textAppearance="@style/TextAppearance.MaterialComponents.Body2"
android:textColor="@color/colorSecondary"
android:paddingStart="16dp"
android:paddingLeft="16dp"
android:paddingEnd="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:textAlignment="viewStart"
android:gravity="start"
android:text="@string/settings_map_header" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingEnd="?android:attr/scrollbarSize"
android:paddingRight="?android:attr/scrollbarSize">

<ImageView
android:id="@+id/settings_map_rotation_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>

<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="6dp"
android:layout_marginRight="6dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_weight="1">

<TextView
android:id="@+id/settings_map_rotation_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1"
android:text="@string/settings_map_rotation_subheading"/>

<TextView
android:id="@+id/settings_map_rotation_summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@id/settings_map_rotation_title"
android:layout_alignLeft="@id/settings_map_rotation_title"
android:layout_below="@id/settings_map_rotation_title"
android:maxLines="4"
android:textAppearance="@style/TextAppearance.MaterialComponents.Body2"
android:textColor="?android:attr/textColorSecondary"
android:text="@string/settings_map_rotation_summary"/>
</RelativeLayout>
<LinearLayout
android:id="@+id/widget_frame6"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical" >
<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/settings_map_rotation_checkbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="true"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@
<string name="settings_show_on_lockscreen_summary">Keep the app in the foreground even when locking the phone</string>
<string name="settings_keep_screen_on_subheading">Keep screen on</string>
<string name="settings_keep_screen_on_summary">Prevent the display from turning off automatically while the app is open</string>
<string name="settings_map_header">Map settings</string>
<string name="settings_map_rotation_subheading">Rotation</string>
<string name="settings_map_rotation_summary">Allow the map to be rotated</string>

<!-- time to word -->
<string name="timetoword_justnow">just now</string>
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
buildscript {
ext {
dagger_version = "2.19"
dagger_version = "2.22.1"
butterknife_version = "10.1.0"
}

Expand All @@ -11,9 +11,9 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'de.mobilej.unmock:UnMockPlugin:0.6.5'
classpath 'net.ltgt.gradle:gradle-errorprone-plugin:0.0.16'
classpath 'net.ltgt.gradle:gradle-errorprone-plugin:0.7.1'
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Jan 21 08:06:32 CET 2019
#Sun Apr 21 10:56:45 CEST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

0 comments on commit bb91d14

Please sign in to comment.