Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
halo
packages_apps_Launcher3
Commits
72a9953c
Commit
72a9953c
authored
9 years ago
by
Hyunyoung Song
Browse files
Options
Download
Email Patches
Plain Diff
Load label in bg thread to prevent ANR
b/27238970 Change-Id: Ic5d77df7d5276cee07861d59427a94fb19691d9c
parent
fbf19ccc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
36 deletions
+51
-36
src/com/android/launcher3/model/WidgetsModel.java
src/com/android/launcher3/model/WidgetsModel.java
+32
-1
src/com/android/launcher3/widget/WidgetCell.java
src/com/android/launcher3/widget/WidgetCell.java
+13
-22
src/com/android/launcher3/widget/WidgetsListAdapter.java
src/com/android/launcher3/widget/WidgetsListAdapter.java
+6
-13
No files found.
src/com/android/launcher3/model/WidgetsModel.java
View file @
72a9953c
...
...
@@ -3,6 +3,7 @@ package com.android.launcher3.model;
import
android.content.ComponentName
;
import
android.content.Context
;
import
android.content.pm.PackageManager
;
import
android.content.pm.ResolveInfo
;
import
android.util.Log
;
...
...
@@ -16,6 +17,7 @@ import com.android.launcher3.Utilities;
import
com.android.launcher3.compat.AlphabeticIndexCompat
;
import
com.android.launcher3.compat.AppWidgetManagerCompat
;
import
com.android.launcher3.compat.UserHandleCompat
;
import
com.android.launcher3.util.ComponentKey
;
import
java.util.ArrayList
;
import
java.util.Collections
;
...
...
@@ -39,7 +41,11 @@ public class WidgetsModel {
/* Map of widgets and shortcuts that are tracked per package. */
private
final
HashMap
<
PackageItemInfo
,
ArrayList
<
Object
>>
mWidgetsList
;
/* Labels of widgets */
private
final
HashMap
<
ComponentKey
,
CharSequence
>
mLabels
;
private
final
AppWidgetManagerCompat
mAppWidgetMgr
;
private
final
PackageManager
mPackageMgr
;
private
final
WidgetsAndShortcutNameComparator
mWidgetAndShortcutNameComparator
;
private
final
Comparator
<
ItemInfo
>
mAppNameComparator
;
private
final
IconCache
mIconCache
;
...
...
@@ -50,6 +56,7 @@ public class WidgetsModel {
public
WidgetsModel
(
Context
context
,
IconCache
iconCache
,
AppFilter
appFilter
)
{
mAppWidgetMgr
=
AppWidgetManagerCompat
.
getInstance
(
context
);
mPackageMgr
=
context
.
getPackageManager
();
mWidgetAndShortcutNameComparator
=
new
WidgetsAndShortcutNameComparator
(
context
);
mAppNameComparator
=
(
new
AppNameComparator
(
context
)).
getAppInfoComparator
();
mIconCache
=
iconCache
;
...
...
@@ -57,13 +64,14 @@ public class WidgetsModel {
mIndexer
=
new
AlphabeticIndexCompat
(
context
);
mPackageItemInfos
=
new
ArrayList
<>();
mWidgetsList
=
new
HashMap
<>();
mRawList
=
new
ArrayList
<>();
mLabels
=
new
HashMap
<>();
}
@SuppressWarnings
(
"unchecked"
)
private
WidgetsModel
(
WidgetsModel
model
)
{
mAppWidgetMgr
=
model
.
mAppWidgetMgr
;
mPackageMgr
=
model
.
mPackageMgr
;
mPackageItemInfos
=
(
ArrayList
<
PackageItemInfo
>)
model
.
mPackageItemInfos
.
clone
();
mWidgetsList
=
(
HashMap
<
PackageItemInfo
,
ArrayList
<
Object
>>)
model
.
mWidgetsList
.
clone
();
mWidgetAndShortcutNameComparator
=
model
.
mWidgetAndShortcutNameComparator
;
...
...
@@ -72,6 +80,7 @@ public class WidgetsModel {
mAppFilter
=
model
.
mAppFilter
;
mIndexer
=
model
.
mIndexer
;
mRawList
=
(
ArrayList
<
Object
>)
model
.
mRawList
.
clone
();
mLabels
=
(
HashMap
<
ComponentKey
,
CharSequence
>)
model
.
mLabels
.
clone
();
}
// Access methods that may be deleted if the private fields are made package-private.
...
...
@@ -87,6 +96,22 @@ public class WidgetsModel {
return
mPackageItemInfos
.
get
(
pos
);
}
public
CharSequence
getLabel
(
Object
info
)
{
ComponentKey
key
;
if
(
info
instanceof
LauncherAppWidgetProviderInfo
)
{
key
=
new
ComponentKey
(((
LauncherAppWidgetProviderInfo
)
info
).
provider
,
mAppWidgetMgr
.
getUser
(((
LauncherAppWidgetProviderInfo
)
info
)));
return
mLabels
.
get
(
key
);
}
else
if
(
info
instanceof
ResolveInfo
)
{
ResolveInfo
ri
=
(
ResolveInfo
)
info
;
ComponentName
componentName
=
new
ComponentName
(
ri
.
activityInfo
.
packageName
,
ri
.
activityInfo
.
name
);
key
=
new
ComponentKey
(
componentName
,
UserHandleCompat
.
myUserHandle
());
return
mLabels
.
get
(
key
);
}
return
null
;
}
public
List
<
Object
>
getSortedWidgets
(
int
pos
)
{
return
mWidgetsList
.
get
(
mPackageItemInfos
.
get
(
pos
));
}
...
...
@@ -109,6 +134,7 @@ public class WidgetsModel {
// clear the lists.
mWidgetsList
.
clear
();
mPackageItemInfos
.
clear
();
mLabels
.
clear
();
mWidgetAndShortcutNameComparator
.
reset
();
InvariantDeviceProfile
idp
=
LauncherAppState
.
getInstance
().
getInvariantDeviceProfile
();
...
...
@@ -118,6 +144,7 @@ public class WidgetsModel {
String
packageName
=
""
;
UserHandleCompat
userHandle
=
null
;
ComponentName
componentName
=
null
;
ComponentKey
key
=
null
;
if
(
o
instanceof
LauncherAppWidgetProviderInfo
)
{
LauncherAppWidgetProviderInfo
widgetInfo
=
(
LauncherAppWidgetProviderInfo
)
o
;
...
...
@@ -137,12 +164,16 @@ public class WidgetsModel {
}
continue
;
}
key
=
new
ComponentKey
(
componentName
,
userHandle
);
mLabels
.
put
(
key
,
mAppWidgetMgr
.
loadLabel
(
widgetInfo
));
}
else
if
(
o
instanceof
ResolveInfo
)
{
ResolveInfo
resolveInfo
=
(
ResolveInfo
)
o
;
componentName
=
new
ComponentName
(
resolveInfo
.
activityInfo
.
packageName
,
resolveInfo
.
activityInfo
.
name
);
packageName
=
resolveInfo
.
activityInfo
.
packageName
;
userHandle
=
UserHandleCompat
.
myUserHandle
();
key
=
new
ComponentKey
(
componentName
,
userHandle
);
mLabels
.
put
(
key
,
resolveInfo
.
loadLabel
(
mPackageMgr
));
}
if
(
componentName
==
null
||
userHandle
==
null
)
{
...
...
This diff is collapsed.
Click to expand it.
src/com/android/launcher3/widget/WidgetCell.java
View file @
72a9953c
...
...
@@ -137,32 +137,23 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener {
}
/**
* Apply the widget provider info to the view.
* Apply the widget provider info
or the resolve info
to the view.
*/
public
void
applyFromAppWidgetProviderInfo
(
LauncherAppWidgetProviderInfo
info
,
WidgetPreviewLoader
loader
)
{
InvariantDeviceProfile
profile
=
LauncherAppState
.
getInstance
().
getInvariantDeviceProfile
();
public
void
applyFromInfo
(
Object
info
,
CharSequence
label
,
WidgetPreviewLoader
loader
)
{
mInfo
=
info
;
// TODO(hyunyoungs): setup a cache for these labels.
mWidgetName
.
setText
(
AppWidgetManagerCompat
.
getInstance
(
getContext
()).
loadLabel
(
info
));
int
hSpan
=
Math
.
min
(
info
.
spanX
,
profile
.
numColumns
);
int
vSpan
=
Math
.
min
(
info
.
spanY
,
profile
.
numRows
);
mWidgetDims
.
setText
(
String
.
format
(
mDimensionsFormatString
,
hSpan
,
vSpan
));
mWidgetPreviewLoader
=
loader
;
}
/**
* Apply the resolve info to the view.
*/
public
void
applyFromResolveInfo
(
PackageManager
pm
,
ResolveInfo
info
,
WidgetPreviewLoader
loader
)
{
mInfo
=
info
;
CharSequence
label
=
info
.
loadLabel
(
pm
);
mWidgetName
.
setText
(
label
);
mWidgetDims
.
setText
(
String
.
format
(
mDimensionsFormatString
,
1
,
1
));
mWidgetPreviewLoader
=
loader
;
if
(
info
instanceof
LauncherAppWidgetProviderInfo
)
{
InvariantDeviceProfile
profile
=
LauncherAppState
.
getInstance
().
getInvariantDeviceProfile
();
int
hSpan
=
Math
.
min
(((
LauncherAppWidgetProviderInfo
)
info
).
spanX
,
profile
.
numColumns
);
int
vSpan
=
Math
.
min
(((
LauncherAppWidgetProviderInfo
)
info
).
spanY
,
profile
.
numRows
);
mWidgetDims
.
setText
(
String
.
format
(
mDimensionsFormatString
,
hSpan
,
vSpan
));
}
if
(
info
instanceof
ResolveInfo
)
{
mWidgetDims
.
setText
(
String
.
format
(
mDimensionsFormatString
,
1
,
1
));
}
}
public
int
[]
getPreviewSize
()
{
...
...
This diff is collapsed.
Click to expand it.
src/com/android/launcher3/widget/WidgetsListAdapter.java
View file @
72a9953c
...
...
@@ -16,9 +16,7 @@
package
com.android.launcher3.widget
;
import
android.annotation.TargetApi
;
import
android.content.Context
;
import
android.content.pm.ResolveInfo
;
import
android.content.res.Resources
;
import
android.os.Build
;
import
android.support.v7.widget.RecyclerView
;
import
android.support.v7.widget.RecyclerView.Adapter
;
...
...
@@ -30,7 +28,6 @@ import android.view.ViewGroup.LayoutParams;
import
android.widget.LinearLayout
;
import
com.android.launcher3.BubbleTextView
;
import
com.android.launcher3.DeviceProfile
;
import
com.android.launcher3.Launcher
;
import
com.android.launcher3.LauncherAppState
;
import
com.android.launcher3.LauncherAppWidgetProviderInfo
;
...
...
@@ -136,17 +133,13 @@ public class WidgetsListAdapter extends Adapter<WidgetsRowViewHolder> {
}
for
(
int
i
=
0
;
i
<
infoList
.
size
();
i
++)
{
WidgetCell
widget
=
(
WidgetCell
)
row
.
getChildAt
(
i
);
if
(
infoList
.
get
(
i
)
instanceof
LauncherAppWidgetProviderInfo
)
{
LauncherAppWidgetProviderInfo
info
=
(
LauncherAppWidgetProviderInfo
)
infoList
.
get
(
i
);
PendingAddWidgetInfo
pawi
=
new
PendingAddWidgetInfo
(
mLauncher
,
info
,
null
);
widget
.
setTag
(
pawi
);
widget
.
applyFromAppWidgetProviderInfo
(
info
,
mWidgetPreviewLoader
);
}
else
if
(
infoList
.
get
(
i
)
instanceof
ResolveInfo
)
{
ResolveInfo
info
=
(
ResolveInfo
)
infoList
.
get
(
i
);
PendingAddShortcutInfo
pasi
=
new
PendingAddShortcutInfo
(
info
.
activityInfo
);
widget
.
setTag
(
pasi
);
widget
.
applyFromResolveInfo
(
mLauncher
.
getPackageManager
(),
info
,
mWidgetPreviewLoader
);
Object
info
=
infoList
.
get
(
i
);
if
(
info
instanceof
LauncherAppWidgetProviderInfo
)
{
widget
.
setTag
(
new
PendingAddWidgetInfo
(
mLauncher
,
(
LauncherAppWidgetProviderInfo
)
info
,
null
));
}
else
if
(
info
instanceof
ResolveInfo
)
{
widget
.
setTag
(
new
PendingAddShortcutInfo
(((
ResolveInfo
)
info
).
activityInfo
));
}
widget
.
applyFromInfo
(
info
,
mWidgetsModel
.
getLabel
(
info
),
mWidgetPreviewLoader
);
widget
.
ensurePreview
();
widget
.
setVisibility
(
View
.
VISIBLE
);
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment