4141public class InstallSuccess extends AlertActivity {
4242 private static final String LOG_TAG = InstallSuccess .class .getSimpleName ();
4343
44+ @ Nullable
45+ private PackageUtil .AppSnippet mAppSnippet ;
46+
47+ @ Nullable
48+ private String mAppPackageName ;
49+
50+ @ Nullable
51+ private Intent mLaunchIntent ;
52+
4453 @ Override
4554 protected void onCreate (@ Nullable Bundle savedInstanceState ) {
4655 super .onCreate (savedInstanceState );
@@ -55,59 +64,73 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
5564 Intent intent = getIntent ();
5665 ApplicationInfo appInfo =
5766 intent .getParcelableExtra (PackageUtil .INTENT_ATTR_APPLICATION_INFO );
67+ mAppPackageName = appInfo .packageName ;
5868 Uri packageURI = intent .getData ();
5969
6070 // Set header icon and title
61- PackageUtil .AppSnippet as ;
6271 PackageManager pm = getPackageManager ();
6372
6473 if ("package" .equals (packageURI .getScheme ())) {
65- as = new PackageUtil .AppSnippet (pm .getApplicationLabel (appInfo ),
74+ mAppSnippet = new PackageUtil .AppSnippet (pm .getApplicationLabel (appInfo ),
6675 pm .getApplicationIcon (appInfo ));
6776 } else {
6877 File sourceFile = new File (packageURI .getPath ());
69- as = PackageUtil .getAppSnippet (this , appInfo , sourceFile );
78+ mAppSnippet = PackageUtil .getAppSnippet (this , appInfo , sourceFile );
7079 }
7180
72- mAlert .setIcon (as .icon );
73- mAlert .setTitle (as .label );
74- mAlert .setView (R .layout .install_content_view );
75- mAlert .setButton (DialogInterface .BUTTON_POSITIVE , getString (R .string .launch ), null ,
76- null );
77- mAlert .setButton (DialogInterface .BUTTON_NEGATIVE , getString (R .string .done ),
78- (ignored , ignored2 ) -> {
79- if (appInfo .packageName != null ) {
80- Log .i (LOG_TAG , "Finished installing " + appInfo .packageName );
81- }
82- finish ();
83- }, null );
84- setupAlert ();
85- requireViewById (R .id .install_success ).setVisibility (View .VISIBLE );
86- // Enable or disable "launch" button
87- Intent launchIntent = getPackageManager ().getLaunchIntentForPackage (
88- appInfo .packageName );
89- boolean enabled = false ;
90- if (launchIntent != null ) {
91- List <ResolveInfo > list = getPackageManager ().queryIntentActivities (launchIntent ,
92- 0 );
93- if (list != null && list .size () > 0 ) {
94- enabled = true ;
95- }
96- }
81+ mLaunchIntent = getPackageManager ().getLaunchIntentForPackage (mAppPackageName );
82+
83+ bindUi ();
84+ }
85+ }
86+
87+ @ Override
88+ protected void onResume () {
89+ super .onResume ();
90+ bindUi ();
91+ }
9792
98- Button launchButton = mAlert .getButton (DialogInterface .BUTTON_POSITIVE );
99- if (enabled ) {
100- launchButton .setOnClickListener (view -> {
101- try {
102- startActivity (launchIntent );
103- } catch (ActivityNotFoundException | SecurityException e ) {
104- Log .e (LOG_TAG , "Could not start activity" , e );
93+ private void bindUi () {
94+ if (mAppSnippet == null ) {
95+ return ;
96+ }
97+
98+ mAlert .setIcon (mAppSnippet .icon );
99+ mAlert .setTitle (mAppSnippet .label );
100+ mAlert .setView (R .layout .install_content_view );
101+ mAlert .setButton (DialogInterface .BUTTON_POSITIVE , getString (R .string .launch ), null ,
102+ null );
103+ mAlert .setButton (DialogInterface .BUTTON_NEGATIVE , getString (R .string .done ),
104+ (ignored , ignored2 ) -> {
105+ if (mAppPackageName != null ) {
106+ Log .i (LOG_TAG , "Finished installing " + mAppPackageName );
105107 }
106108 finish ();
107- });
108- } else {
109- launchButton .setEnabled (false );
109+ }, null );
110+ setupAlert ();
111+ requireViewById (R .id .install_success ).setVisibility (View .VISIBLE );
112+ // Enable or disable "launch" button
113+ boolean enabled = false ;
114+ if (mLaunchIntent != null ) {
115+ List <ResolveInfo > list = getPackageManager ().queryIntentActivities (mLaunchIntent ,
116+ 0 );
117+ if (list != null && list .size () > 0 ) {
118+ enabled = true ;
110119 }
111120 }
121+
122+ Button launchButton = mAlert .getButton (DialogInterface .BUTTON_POSITIVE );
123+ if (enabled ) {
124+ launchButton .setOnClickListener (view -> {
125+ try {
126+ startActivity (mLaunchIntent );
127+ } catch (ActivityNotFoundException | SecurityException e ) {
128+ Log .e (LOG_TAG , "Could not start activity" , e );
129+ }
130+ finish ();
131+ });
132+ } else {
133+ launchButton .setEnabled (false );
134+ }
112135 }
113136}
0 commit comments