OSDN Git Service

Cleanup from previous commits
[android-x86/packages-apps-Taskbar.git] / app / src / nonlib / java / com / farmerbb / taskbar / activity / PersistentShortcutLaunchActivity.java
1 /* Copyright 2020 Braden Farmer
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 package com.farmerbb.taskbar.activity;
17
18 import android.app.Activity;
19 import android.content.ActivityNotFoundException;
20 import android.content.Intent;
21 import android.net.Uri;
22 import android.os.Bundle;
23
24 import com.farmerbb.taskbar.R;
25 import com.farmerbb.taskbar.util.AppEntry;
26 import com.farmerbb.taskbar.util.ApplicationType;
27 import com.farmerbb.taskbar.util.U;
28
29 public class PersistentShortcutLaunchActivity extends Activity {
30
31     @Override
32     protected void onCreate(Bundle savedInstanceState) {
33         super.onCreate(savedInstanceState);
34
35         String packageName = getIntent().getStringExtra("package_name");
36         String componentName = getIntent().getStringExtra("component_name");
37         String windowSize = getIntent().getStringExtra("window_size");
38
39         if(!U.canDrawOverlays(this) && windowSize != null) {
40             Intent intent = new Intent(this, DummyActivity.class);
41             intent.putExtra("show_permission_dialog", true);
42             intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
43
44             startActivity(intent);
45         } else if(packageName != null && componentName != null) {
46             final AppEntry entry = new AppEntry(packageName, componentName, null, null, false);
47
48             U.launchApp(this, entry, windowSize, () -> {
49                 Intent intent = new Intent(Intent.ACTION_VIEW);
50                 intent.setData(Uri.parse("https://play.google.com/store/apps/details?id=" + packageName));
51
52                 try {
53                     startActivity(intent, U.getActivityOptionsBundle(this, ApplicationType.APP_PORTRAIT, null));
54                 } catch (ActivityNotFoundException | IllegalArgumentException e1) { /* Gracefully fail */ }
55             });
56         } else
57             U.showToast(this, R.string.tb_invalid_shortcut);
58
59         finish();
60     }
61 }