Skip to content

Commit

Permalink
handle orientation changes manually -> screen rotate is ~instantaneous (
Browse files Browse the repository at this point in the history
fixes #1217)
  • Loading branch information
westnordost committed Sep 27, 2018
1 parent 784b798 commit d327930
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 9 deletions.
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
<activity
android:windowSoftInputMode="adjustResize"
android:name="de.westnordost.streetcomplete.MainActivity"
android:label="@string/app_name" >
android:label="@string/app_name"
android:configChanges="orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand Down
23 changes: 17 additions & 6 deletions app/src/main/java/de/westnordost/streetcomplete/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.westnordost.streetcomplete;

import android.animation.ObjectAnimator;
import android.content.res.Configuration;
import android.graphics.Point;
import android.graphics.PointF;
import android.support.annotation.DrawableRes;
Expand Down Expand Up @@ -236,13 +237,8 @@ public void onServiceDisconnected(ComponentName className)
downloadProgressBar.setMax(1000);

mapFragment = (QuestsMapFragment) getSupportFragmentManager().findFragmentById(R.id.map_fragment);
mapFragment.setQuestOffsets(new Rect(
getResources().getDimensionPixelSize(R.dimen.quest_form_leftOffset),
0,
getResources().getDimensionPixelSize(R.dimen.quest_form_rightOffset),
getResources().getDimensionPixelSize(R.dimen.quest_form_bottomOffset)));

mapFragment.getMapAsync(BuildConfig.MAPZEN_API_KEY);
updateMapQuestOffsets();
}

@Override public void onStart()
Expand Down Expand Up @@ -331,6 +327,21 @@ public void onServiceDisconnected(ComponentName className)
questController.onDestroy();
}

@Override public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
findViewById(R.id.main).requestLayout();
updateMapQuestOffsets();
}

private void updateMapQuestOffsets()
{
mapFragment.setQuestOffsets(new Rect(
getResources().getDimensionPixelSize(R.dimen.quest_form_leftOffset),
0,
getResources().getDimensionPixelSize(R.dimen.quest_form_rightOffset),
getResources().getDimensionPixelSize(R.dimen.quest_form_bottomOffset)));
}

@Override public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.menu_main, menu);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.westnordost.streetcomplete.data.osmnotes;

import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Point;
import android.os.Bundle;
import android.support.annotation.NonNull;
Expand All @@ -24,7 +25,8 @@
public class CreateNoteFragment extends AbstractCreateNoteFragment
{
private EditText noteInput;
private View markerLayout;
private ViewGroup markerLayout;
private ViewGroup centeredMarkerLayout;
private View marker;

private CreateNoteListener callbackListener;
Expand All @@ -39,6 +41,7 @@ public class CreateNoteFragment extends AbstractCreateNoteFragment
{
markerLayout.startAnimation(createFallDownAnimation());
}
centeredMarkerLayout = view.findViewById(R.id.centered_marker_layout_create_note);

marker = view.findViewById(R.id.marker_create_note);

Expand All @@ -50,6 +53,17 @@ public class CreateNoteFragment extends AbstractCreateNoteFragment
return view;
}

@Override public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
centeredMarkerLayout.setPadding(
getResources().getDimensionPixelSize(R.dimen.quest_form_leftOffset),
getResources().getDimensionPixelSize(R.dimen.quest_form_topOffset),
getResources().getDimensionPixelSize(R.dimen.quest_form_rightOffset),
getResources().getDimensionPixelSize(R.dimen.quest_form_bottomOffset)
);
}

private Animation createFallDownAnimation()
{
AnimationSet a = new AnimationSet(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import android.support.design.widget.BottomSheetBehavior;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;

Expand All @@ -22,6 +24,7 @@
public abstract class AbstractBottomSheetFragment extends Fragment
{
private LinearLayout bottomSheet;
private BottomSheetBehavior bottomSheetBehavior;
private View buttonClose;

@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState)
Expand All @@ -39,7 +42,7 @@ public abstract class AbstractBottomSheetFragment extends Fragment
buttonClose = view.findViewById(R.id.close_btn);
buttonClose.setOnClickListener(v -> getActivity().onBackPressed());

BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);

View titleSpeechBubble = view.findViewById(R.id.titleSpeechBubble);
titleSpeechBubble.setOnClickListener(v -> {
Expand Down Expand Up @@ -74,6 +77,24 @@ else if(bottomSheetBehavior.getState() == STATE_COLLAPSED)
}
}

@Override public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
// I need to do everything myself... (AppCompactActivity only does this after calling this
// method. Genius!)
getResources().updateConfiguration(newConfig, getResources().getDisplayMetrics());

bottomSheetBehavior.setPeekHeight(
getResources().getDimensionPixelSize(R.dimen.quest_form_peekHeight));
View root = getView();
if(root != null)
{
ViewGroup.LayoutParams params = root.getLayoutParams();
params.width = getResources().getDimensionPixelSize(R.dimen.quest_form_width);
root.setLayoutParams(params);
}
}

private void updateCloseButtonVisibility()
{
// this is called asynchronously. It may happen that the activity is already gone when this
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/marker_create_note.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
>

<RelativeLayout
android:id="@+id/centered_marker_layout_create_note"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="@dimen/quest_form_topOffset"
Expand Down

0 comments on commit d327930

Please sign in to comment.