public static Resources . Theme buildApptentiveInteractionTheme ( Context context ) { Resources . Theme theme = context . getResources ( ) . newTheme ( ) ; // 1. Start by basing this on the Apptentive theme. theme . applyStyle ( R . style . ApptentiveTheme_Base_Versioned , true ) ; // 2. Get the theme from the host app. Overwrite what we have so far with the app's theme from // the AndroidManifest.xml. This ensures that the app's styling shows up in our UI. int appTheme ; try { PackageManager packageManager = context . getPackageManager ( ) ; PackageInfo packageInfo = packageManager . getPackageInfo ( context . getPackageName ( ) , 0 ) ; ApplicationInfo ai = packageInfo . applicationInfo ; appTheme = ai . theme ; if ( appTheme != 0 ) { theme . applyStyle ( appTheme , true ) ; } } catch ( PackageManager . NameNotFoundException e ) { // Can't happen return null ; } // Step 3: Restore Apptentive UI window properties that may have been overridden in Step 2. This // ensures Apptentive interaction has a modal feel and look. theme . applyStyle ( R . style . ApptentiveBaseFrameTheme , true ) ; // Step 4: Apply optional theme override specified in host app's style int themeOverrideResId = context . getResources ( ) . getIdentifier ( "ApptentiveThemeOverride" , "style" , context . getPackageName ( ) ) ; if ( themeOverrideResId != 0 ) { theme . applyStyle ( themeOverrideResId , true ) ; } return theme ; }
Builds out the main theme that we would like to use for all Apptentive UI basing it on the existing app theme and adding Apptentive s theme where it doesn t override the existing app s attributes . Finally it forces changes to the theme using ApptentiveThemeOverride .