In my application I have a main activity with a GoogleMap fragment inside it. The map often moves its camera and draws markers and polylines without a direct user interaction (i.e to follow a target).
The problem occurs when I start other translucent/transparent activities on top of that main one. I cannot use dialogs, views of fragments, unfortunately I have to use only activities. So I declared their style as:
<style name="AppTheme.Transparent" parent="AppTheme">
<item name="android:windowNoTitle">true</item>
<item name="android:background">#android:color/transparent</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:windowIsTranslucent">true</item>
</style>
These activities have some views placed on top of a semi-transparent black background, so one can see the map behind them. The problem is that the map drawing is not updated at all while behind these activities, despite the fact that the code that, for example, move the camera actually runs (I can see it from logs or debugging). The map drawing is updated correctly only after (and immediately) the overlay translucent activity is closed. The strange fact is that other views placed on the main activity (for example, text views showing target coordinates) are correctly updated while behind the translucent activity, also if they are placed on top of the maps.
Is there someone who knows why is this happening, and if there is a way to force map redrawing while host activity is not in the foreground?
Related
I am trying to understand what animation is used in the Google Maps application.
The part I am trying to understand is when you click on the textbox in the toolbar. The layout animates to present a completely new screen with a few items sliding in from the bottom.
How is this done? Is it a bottom sheet becoming visible? Is it a new activity with shared element transitions?
That is called activity transitions. Where you choose which layouts should been moved to a second activity. See also the official documentation about animations: http://developer.android.com/training/material/animations.html#Transitions
Another good point to start it the video talk from the Google Developers: https://www.youtube.com/watch?v=RhiPJByIMrM
Basically you need to modify the style like here:
<style name="BaseAppTheme" parent="android:Theme.Material">
<!-- enable window content transitions -->
<item name="android:android:windowActivityTransitions">true</item>
<!-- specify enter and exit transitions -->
<item name="android:windowEnterTransition">#transition/explode</item>
<item name="android:windowExitTransition">#transition/explode</item>
<!-- specify shared element transitions -->
<item name="android:windowSharedElementEnterTransition">
#transition/change_image_transform</item>
<item name="android:windowSharedElementExitTransition">
#transition/change_image_transform</item>
</style>
You also need to specify a special attribute called android:transitionName to say the system that you want to move that from one activity to a second one.
This is a single activity that has 2 modes: map mode and input+list mode.
You can have a FrameLayout and within have the map root view (visible) and the input root view (gone). When you want to open the list, you make it visible and use ViewAnimation to animate it going up.
A better approach is to break these 2 main views into 2 fragments, and animate the fragment.
The example that you are talking about is basically Google Places AutoComplete Api.
Please follow the link for the same :
https://developers.google.com/places/android-api/autocomplete
I've been working on an app and I've reaching the point where it requires me to display a menu window in the middle of the screen.
I've been using an AlertDialog object filled with a custom View but now it was required of me to "surround" the window with a semi-transparent white glow as opposed to the default grayish one. I did a similar with the fade-in color of some navigation drawers I have on my app but in that case I had a specific method to quickly help me solve that problem. So far I haven't found anything that helps me solve this one.
I tried creating a default style with a new "windowBackground" value but I encountered 3 problems from the get-go:
I'm no longer able to shut the AlertDialog down by clicking outside the layout (I'm guessing because by changing the color that way everything is now the layout)
The menu window is now surrounded by a black outline that wasn't there before
By using the filtering search inside the layout, which manipulates the members of a list, the window collapses on itself
Is there any way to accomplish what I want more or less directly?
I'm not really sure about it, but you can use this in your styles.xml
<style name="MyDialogTheme" parent="android:Theme.AppCompat.Light.Dialog">
<item name="android:windowFrame">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">#color/your_light_color</item>
<item name="android:backgroundDimEnabled">false</item>
And if you want to dismiss the dialog when clicking outside, use this:
dialog.setCanceledOnTouchOutside(true);
or
<item name="windowCloseOnTouchOutside">true</item>
in your styles.xml
I put together a very simple app that uses shared element transitions when starting an activity with Dialog theme (source code on github).
I got the following result:
As you can see there are 2 problems with the transition/animation:
The animation is only visible in the area of the dialog activity so it clips and looks ugly.
There is no transition/animation when I tap outside the activity to
go back.
How can I fix these problems? Any help would be appreciated.
EDIT: After Quanturium's answer I did the following things to get it working:
Use the following theme instead of a Dialog theme:
<style name="AppTheme.Transparent" parent="AppTheme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
Use a CardView as the background for Dialog look and for rounded corners and shadows.
Call finishAfterTransition(); when user taps outside the CardView.
Now it looks like this (code), the CardView needs refining to better match the Dialog, but it's working at least.:
An activity transition works like this. When you start your second activity, it is displayed on top of your first one with a transparent background. The shared elements are positioned the same way they are on the first activity and then animated to the correct position specified on the second activity.
In your case you are using android:theme="#style/Theme.AppCompat.Dialog" which mean the size of the second activity's drawing area is smaller than the one from the first activity. This explains the clipping and the no transition when clicking outside.
What you want to do is get rid of that theme, and implement your own layout with a dark background / shadow in order to be able to execute your smooth transition.
I'm attempting to create a GDK app that has a similar user interface as the sample Timer app in that it launches sub-activities in which to render CardScrollView instances that cycle through valid selections.
My problem is that once I am at the point where I cycle through the numbers, the CardScrollView stops rendering while the scrolling is in motion. I can see the previous activity revealed and rendering until the activity containing the currently active cards stop scrolling.
Is there something obvious I'm missing here?
In my case, the answer was that I'd foolishly applied the "MenuStyle" style that the Timer activity uses to all my sub-activities in the AndroidManifest. This style specifies the following:
<style name="MenuTheme" parent="#android:style/Theme.DeviceDefault">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">#null</item>
</style>
So indeed, given the null animation style and the transparent background, nothing would be displayed while the CardScrollView is in motion.
Whenever i launch my app, a white screen appears in the beginning with the title bar. I don't want this screen to be appear in my app. I have read previous questions, but answers are not clear to me.
I'm also using splash screen, but white screen appears before that.
I don't want to change the theme style, because it either increases the minimum sdkVersion or changes the style of edittext, buttons, checkboxes etc
Please help me to keep me out of this.
Thank you.
Preface: For questions like this you should post your starting activities xml and the onCreate() and associated methods.
When android starts your application it will typically use a black view to indicate that it is launching, this my change to white with your theme/style selected. If you are loading the view correctly then you should only see this blank (white or black) page for 50-200 ms (I can't find the google document for this right now). If you are doing a lot of work in your onCreate method then it will take longer.
Typically to make my views display faster I will simply do the majority of the linking work after it has loaded. ex:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.initial_activity_layout);
//We use a handler so that the activity starts very fast
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
delayedInit();
}
}, 100);
}
Additionally, mobile applications should typically not have a splash screen unless they take quite a while to load the contents (e.g. games, first time launch files, etc.) and should not be used just to brand your application, or display your company name.
Update (July 31, 2015)
Google apps are now moving in the direction of having splash screens (see drive, GMail, etc.)
Additionally, You shouldn't be doing any work other than de-referencing views in the onCreate() method. Any long running operations such as retrieving information from memory (database, prefs, etc.) should be done in an AsyncTaskLoader or AsyncTask.
If you are using AppCompatActivity then create below theme in style.xml :
<style name="Theme.Transparent" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowIsTranslucent">true</item>
</style>
And in manifest file for SplashActivity add theme :
android:theme="#style/Theme.Transparent"
Add below line in your Theme of splash screen as you wrote you are using splash screen
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowIsTranslucent">true</item>
1- Make windowDisablePreview false in your style.xml
<item name="android:windowDisablePreview">false</item>
2- Add windowBackground in your style.xml.
<item name="android:windowBackground">#drawable/your_background</item>