-
Notifications
You must be signed in to change notification settings - Fork 51
/
ShortcutUtils.java
115 lines (93 loc) · 2.85 KB
/
ShortcutUtils.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* Last Launcher
* Copyright (C) 2019,2020 Shubham Tyagi
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.subhamtyagi.lastlauncher.utils;
import android.content.Context;
import android.content.Intent;
import java.util.ArrayList;
import io.github.subhamtyagi.lastlauncher.model.Shortcut;
/**
* This class manages Shortcut installed by user
* most of the methods are now wrapper to Database
*/
public class ShortcutUtils {
private Database db;
public ShortcutUtils(Context context) {
if (null == db) {
synchronized (ShortcutUtils.class) {
if (null == db) {
db = new Database(context);
}
}
}
}
public void close() {
db.close();
}
private void checkDB() throws Throwable {
if (db == null) {
throw new Throwable("Db is null");
}
}
public ArrayList<Shortcut> getAllShortcuts() {
return db.getAllShortcuts();
}
/**
* Add new shortcut
*
* @param shortcut instance of shortcut to be added
*/
public void addShortcut(Shortcut shortcut) {
db.insertShortcut(shortcut.getName(), shortcut.getUri());
}
/**
* remove the shortcuts
*
* @param shortcut to be removed
*/
public void removeShortcut(Shortcut shortcut) {
db.deleteShortcuts(shortcut.getName());
}
/**
* return true if shortcut is already install
*
* @param name uri of shortcut
* @return true if already installed
*/
public boolean isShortcutAlreadyAvailable(String name) {
return db.shortcutsExists(name);
}
/**
* number of shortcut installed
*
* @return number of shortcut installed in this launcher
*/
public int getShortcutCounts() {
return db.getShortcutsCounts();
}
public boolean isShortcutToApp(String uri) {
try {
Intent intent = Intent.parseUri(uri, 0);
if (intent.getCategories() != null && intent.getCategories().contains(Intent.CATEGORY_LAUNCHER) && Intent.ACTION_MAIN.equals(intent.getAction())) {
return true;
}
} catch (Exception e) {
return false;
}
return false;
}
}