WindowExitTransition always fades views - java

I am currently trying to make a SharedElementTransition between two Activitys, which works mostyl fine, except one thing.
The ExitAnimation of the first activity consists of two slide transitions:
activity_main_transition.xml:
<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android"
android:transitionOrdering="together">
<slide android:slideEdge="bottom" android:duration="#integer/anim_duration">
<targets>
<target android:targetId="#+id/bottom_appbar"/>
<target android:targetId="#+id/fab"/>
</targets>
</slide>
<slide android:slideEdge="top" android:duration="#integer/anim_duration">
<targets>
<target android:targetId="#+id/pager"/>
</targets>
</slide>
</transitionSet>
But when the Transition plays the views not only slides, but also fades, also the transition tooks roughly a third of the time specified in the duration. I also checked while debugging and the Transitionset which got played is the one i described above. The other three transitions are working just fine, even though i use the same transition file for the enter and exit transition, so i don't have any idea what is causing this behavior.
Also some additional code:
styles.xml:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
...
<item name="android:windowContentTransitions">true</item>
<item name="android:windowExitTransition">#transition/activity_main</item>
<item name="android:windowEnterTransition">#transition/activity_main</item>
</style>
Manifest.xml:
...
<activity
android:name=".ui.activitys.MainActivity"
android:theme="#style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
...
How i start the new activity:
TextView sharedText = v.findViewById(R.id.txt_name);
String transition = ViewCompat.getTransitionName(sharedText);
ActivityOptions options = ActivityOptions.
makeSceneTransitionAnimation(getActivity(), sharedText, transition);
Intent i = new Intent(getContext(), ActivityCustomer.class);
i.putExtra("id", item.getId());
i.putExtra("title", item.getName1()+" "+item.getName2());
i.putExtra(Constants.EXTRA_TRANSITION_NAME, transition);
Transition t = getActivity().getWindow().getExitTransition();
startActivity(i, options.toBundle());

Related

How to add the <queries> tag in the manifest?

I have this code and I was told that for Android 11 I need to add the queries tag in manifest:
final PackageManager pm = getPackageManager();
Intent main = new Intent(Intent.ACTION_MAIN, null);
main.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> packages = pm.queryIntentActivities(main, 0); //get a list of installed apps.
I was told it should be this:
<queries>
<intent>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent>
</queries>
Problem is I cannot add the <category> tag. Android Studio says that the element is not allowed there. I can only add the <action> and <data> tags inside <intent>. And it seems other people on SO have this problem too. It's strange because Android's own documentation instructs us to use the <category> tag there.
The <queries> section is introduced in API 30, so be sure you use it only if you target such version upward.
It is indeed needed when, for instance, you want to launch some other apps from yours, knowing only their package name. Otherwise, using the package manager will return you some null when using functions like packageManager.getLaunchIntentForPackage("com.yyy"). You can find more information here: Package visibility in Android 11
In your case, you can just write the section like this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxx">
...
<queries>
<intent>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent>
</queries>
...
</manifest>

Android splash screen jump java

I wanted to implement a splash screen but in a correct way - no superficial delay, only showing it while the app is doing some real work. So I googled a lot and found following solution: I apply theme to SplashActivity, procced with the logic and open next activity. The problem is that splash screen jumps a little bit. Tried different options - fullscreen, no action bar for splash, no action bar for splash and following activity, android:windowDrawsSystemBarBackgrounds true\false and several others. If I set delay for 115-150 millisecs then 9 cases out of 10 there is no jump. The question is how to get rid of the jump and keep splash screen lean.
SplashActivity:
public class SplashActivity extends CheckForInternetActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
routeActivity();
}
AndroidManifest:
<activity
android:name="ru.awac.CBoRrates.SplashActivity"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity"
android:theme="#style/AppTheme.SplashScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
styles.xml:
<style name="AppTheme.SplashScreen" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#drawable/splash_screen</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
splash_screen:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item android:drawable="#android:color/white"/>
<item>
<bitmap
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:layout_margin="5dip"
android:src="#drawable/awac_presents_transparent_1" />
</item>
</layer-list>
awac_presents_transparent_1 is just a png
Youtube video of the jump

Frame-by-Frame Animated Splash-Screen

[Android Studio] I'm trying to get a few frames to display quickly one after another and then change to a different activity automatically on startup.
I'm able to make the splash activity wait the appropriate amount of time before proceeding, but the animation still isn't playing.
I'm using this person's method (https://www.youtube.com/watch?v=lGRWYJlS3d0) to animate the frames and display them to an ImageView - in the example, the animation is controlled by a stop and start button which sets the frames to loop endlessly (or not), however I would just like it to be activated and displayed when the app is launched.
The way I'm currently implementing this method is causing the app to crash once particular lines are read, but I'm probably just doing it wrong so any help will be appreciated. Thanks. :)
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.company.framebyframe">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.HOME" />
<category android:name="android.intent.category.MAIN" />
</intent-filter>
</activity>
</application>
</manifest>
activity_splash.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/splash_layout"
android:background="#drawable/custom_animation">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" />
</FrameLayout>
</android.support.constraint.ConstraintLayout>
custom_animation.xml under drawables
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/image0" android:duration="250"/>
<item android:drawable="#drawable/image1" android:duration="100"/>
<item android:drawable="#drawable/image2" android:duration="100"/>
<item android:drawable="#drawable/image3" android:duration="100"/>
<item android:drawable="#drawable/image4" android:duration="750"/>
<item android:drawable="#drawable/image3" android:duration="750"/>
<item android:drawable="#drawable/image4" android:duration="750"/>
<item android:drawable="#drawable/image3" android:duration="500"/>
<item android:drawable="#drawable/image0" android:duration="5000"/>
</animation-list>
SplashActivity.java
public class SplashActivity extends AppCompatActivity {
AnimationDrawable anim;
ImageView imageView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
imageView = (ImageView) findViewById(R.id.imageView);
imageView.setBackgroundResource(R.drawable.custom_animation);
anim = (AnimationDrawable) imageView.getBackground();
anim.start();
// // start new activity after 3.5 seconds // //
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
startNextActivity();
}
}, 3500);
}
public void startNextActivity() {
if (isFinishing())
return;
startActivity(new Intent(SplashActivity.this, MainActivity.class));
finish();
}
crashes tend to occur when i start unquoting these lines:
imageView = (ImageView) findViewById(R.id.imageView);
imageView.setBackgroundResource(R.drawable.custom_animation);
PS: if there are any naming mistakes, it might be due to me trying to make the filenames more generic and understandable, but feel free to point out anything you believe might cause problems.
You need to set the layout on the activity class, otherwise the application won't know what layout if should inflate. That's the main reason your application crashes when you try to find the image view, because you haven't set the content layout. Add this line just after super.onCreate and before you try to manipulate any UI element
setContentView(R.layout.activity_splash);
Also, remove the background declaration on the constraint layout, you're already loading the animated drawable to an image view
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/splash_layout">
...
</android.support.constraint.ConstraintLayout>

How do I add a custom picture and title to an activity's top bar

I'm targeting API level 9.
My main activity's top bar looks like this:
AndroidManifest.xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dabestappsever.bigtext" >
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name">
<activity
android:name="com.dabestappsever.bigtext.MainActivity"
android:theme="#style/Theme.AppCompat.Light.DarkActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
... MORE CODE HERE ...
</application>
</manifest>
res/menu/menu_main.xml looks like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
</menu>
I tried adding #drawable/logo to the Manifest, but no luck.
How do I add a custom icon with a custom title next to it for my main activity?
Try inserting these 2 lines inside the Activity open tag
android:icon="#drawable/<icon>"
android:label="#string/<title>"
Looks like I found part of the answer: How to set different label for launcher rather than activity title?
When I added android:label="#string/app_name" to <intent-filter> open tag, I was able to put android:label="#string/main_activity_label" in <activity> open tag, and the app label was #string/app_name while the bar in MainActivity read #string/main_activity_label
Still no luck on the icon though...
To set icon in ActionBar add getSupportActionBar().setIcon(R.drawable.icon); in onCreate() method of your activity.
public class MainActivity extends ActionBarActivity{
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); //your layout
getSupportActionBar().setIcon(R.drawable.icon); //this will set icon in actionbar
....
....
}
}
And to set title in actrionbar write following in tag of manifest file
android:label="#string/activity_title"

Android rename: unable to find explicit activity class

I have a live wallpaper based off of some open source code that I heavily modified. As the last item, I right clicked on it in Eclipse to change the package name and all was well with the world. The wallpaper works right. The settings menu works right. But when I try to click an item in the settings menu to launch another activity, I get:
10-10 16:16:56.215: E/AndroidRuntime(13825): FATAL EXCEPTION: main
10-10 16:16:56.215: E/AndroidRuntime(13825): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.nightscapecreations.orionkeysfree/ffvideolivewallpaper.frankandrobot.com.extLinkNC}; have you declared this activity in your AndroidManifest.xml?
Here is the manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.nightscapecreations.anim1"
android:versionCode="1"
android:versionName="0.9.0" >
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="9" />
<!-- Tell the system this app requires OpenGL ES 2.0. -->
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<uses-feature android:name="android.software.live_wallpaper" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:icon="#drawable/icon"
android:label="#string/app_name" >
<service
android:name="ffvideolivewallpaper.frankandrobot.com.VideoLiveWallpaper"
android:label="#string/wallpaper"
android:permission="android.permission.BIND_WALLPAPER" >
<intent-filter>
<action android:name="android.service.wallpaper.WallpaperService" />
</intent-filter>
<meta-data
android:name="android.service.wallpaper"
android:resource="#xml/wallpaper" />
</service>
<activity
android:name="ffvideolivewallpaper.frankandrobot.com.VideoLiveWallpaper"
android:label="#string/app_name" >
</activity>
<activity
android:name="ffvideolivewallpaper.frankandrobot.com.VideoWallpaperSettings"
android:exported="true"
android:label="#string/app_name" >
</activity>
<activity
android:name="ffvideolivewallpaper.frankandrobot.com.About"
android:exported="true"
android:label="#string/app_name" >
</activity>
<activity
android:name="ffvideolivewallpaper.frankandrobot.com.License"
android:exported="true"
android:label="#string/app_name" >
</activity>
<activity
android:name="ffvideolivewallpaper.frankandrobot.com.SelectVideo"
android:exported="true"
android:label="#string/app_name" >
</activity>
<activity
android:name="ffvideolivewallpaper.frankandrobot.com.extLinkNC"
android:exported="true"
android:label="#string/app_name" >
</activity>
<activity
android:name="ffvideolivewallpaper.frankandrobot.com.extLinkZazzle"
android:exported="true"
android:label="#string/app_name" >
</activity>
<activity
android:name="ffvideolivewallpaper.frankandrobot.com.extLinkFacebook"
android:exported="true"
android:label="#string/app_name" >
</activity>
<activity
android:name="ffvideolivewallpaper.frankandrobot.com.extLinkGooglePlus"
android:exported="true"
android:label="#string/app_name" >
</activity>
</application>
</manifest>
Here is the About activity, as an example, which was confirmed working before this change:
package ffvideolivewallpaper.frankandrobot.com;
import android.app.Activity;
import android.os.Bundle;
import android.text.method.LinkMovementMethod;
import android.widget.TextView;
import android.content.Intent;
import android.view.View;
import com.nightscapecreations.anim1.R;
public class About extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about);
TextView t = (TextView) findViewById(R.id.about_box);
t.setMovementMethod(LinkMovementMethod.getInstance());
}
public void showLicense(View view) {
startActivity(new Intent(About.this, License.class));
}
}
ffvideolivewallpaper.frankandrobot.com was the old package name. Eclipse added the prefix to the android:name for all activities during the package name change. What I don't understand is that if this is incorrect then why does the wallpaper work at all since the service name is qualified the exact same way?
EDIT
Dunamis made an excellent catch. The original name was
ffvideolivewallpaper.frankandrobot.com, but it's been through several name changes since then. One such name was com.nightscapecreations.orionkeysfree. It looks like there was still a reference to that old name which I totally missed in the settings xml file. Example:
<PreferenceCategory android:title="Links and Information" >
<PreferenceScreen android:title="Visit Nightscape Creations"
android:summary="See more live wallpapers, get free static wallpapers, and learn about NC by visiting us online." >
<intent
android:targetClass="ffvideolivewallpaper.frankandrobot.com.extLinkNC"
android:targetPackage="com.nightscapecreations.orionkeysfree" />
</PreferenceScreen>
However, this still does not work. I tried every combination of fully qualified name and simple dot notation ".extLinkFacebook" between this file and the manifest file, but without success. Here is the error I'm receiving now with both names fully qualified:
10-11 08:19:43.176: E/AndroidRuntime(25204): FATAL EXCEPTION: main
10-11 08:19:43.176: E/AndroidRuntime(25204): android.content.ActivityNotFoundException: Unable to find explicit activity class {ffvideolivewallpaper.frankandrobot.com/ffvideolivewallpaper.frankandrobot.com.extLinkFacebook}; have you declared this activity in your AndroidManifest.xml?
Here is the settings file for reference:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory android:title="Wallpaper Settings">
<ffvideolivewallpaper.frankandrobot.com.PrefsSlider
android:key="fps"
android:title="Framerate"
android:summary="Set the target framerate. Lower framerates will decrease resource usage. Requires wallpaper restart to take effect."
android:layout_width="fill_parent"
android:defaultValue="30"
android:orientation="vertical" />
<!-- <ListPreference -->
<!-- android:enabled="true" -->
<!-- android:key="resolution" -->
<!-- android:title="Resolution" -->
<!-- android:summary="Ultra resolution may decrease framerate. Only recommended for high end devices." -->
<!-- android:entries="#array/prefs_resolutionEntries" -->
<!-- android:entryValues="#array/prefs_resolutionValues" -->
<!-- android:defaultValue="512" /> -->
<!-- <ListPreference -->
<!-- android:enabled="true" -->
<!-- android:key="frameTonality" -->
<!-- android:title="Filters" -->
<!-- android:summary="Various effects and filters can be applied to the animation" -->
<!-- android:entries="#array/prefs_tonalityEntries" -->
<!-- android:entryValues="#array/prefs_tonalityValues" -->
<!-- android:defaultValue="1" /> -->
</PreferenceCategory>
<PreferenceCategory android:title="Links and Information" >
<PreferenceScreen android:title="Visit Nightscape Creations"
android:summary="See more live wallpapers, get free static wallpapers, and learn about NC by visiting us online." >
<intent
android:targetClass="ffvideolivewallpaper.frankandrobot.com.extLinkNC"
android:targetPackage="ffvideolivewallpaper.frankandrobot.com" />
</PreferenceScreen>
<PreferenceScreen
android:title="#string/prefsProductsHeading"
android:summary="#string/prefsProductsSummary" >
<intent
android:targetClass="ffvideolivewallpaper.frankandrobot.com.extLinkZazzle"
android:targetPackage="ffvideolivewallpaper.frankandrobot.com" />
</PreferenceScreen>
<PreferenceScreen android:title="Like on Facebook" >
<intent
android:targetClass="ffvideolivewallpaper.frankandrobot.com.extLinkFacebook"
android:targetPackage="ffvideolivewallpaper.frankandrobot.com" />
</PreferenceScreen>
<PreferenceScreen android:title="Like on Google+" >
<intent
android:targetClass="ffvideolivewallpaper.frankandrobot.com.extLinkGooglePlus"
android:targetPackage="ffvideolivewallpaper.frankandrobot.com" />
</PreferenceScreen>
</PreferenceCategory>
<PreferenceCategory android:title="About" >
<PreferenceScreen android:title="About" >
<intent
android:targetClass="ffvideolivewallpaper.frankandrobot.com.About"
android:targetPackage="ffvideolivewallpaper.frankandrobot.com" />
</PreferenceScreen>
</PreferenceCategory>
</PreferenceScreen>
Shortly after adding the bounty I found a workaround for this problem. I'm still not sure what the original issue was, though.
To resolve this I renamed the ffvideolivewallpaper.frankandrobot.com package, which contained all the code, to match that of the manifest. I had hesitated to do this as it required an update to the video.c file to change all "ffvideolivewallpaper_frankandrobot_com" references in native calls to "com_nightscapecreations_anim1" and the last time I had tried that I hosed the app so bad I had to return to a backup copy. However, after doing so today, and then search/replacing through the app to find all other references, I was able to get it to work.
I would still like to know the answer to the above question as it stands, though. It would be much easier to create new apps off this base in the future if I could just leave the main package name alone instead of bothering with a search/replace. If no one knows, though, I will just mark this as the answer.

Categories