/** * Initialize unread number by querying system settings provider. * * @param context */ private void initUnreadNumberFromSystem() { final ContentResolver cr = mContext.getContentResolver(); final int shortcutsNum = sUnreadSupportShortcutsNum; UnreadSupportShortcut shortcut = null; for (int i = 0; i < shortcutsNum; i++) { shortcut = UNREAD_SUPPORT_SHORTCUTS.get(i); try { shortcut.mUnreadNum = android.provider.Settings.System.getInt(cr, shortcut.mKey); if (LauncherLog.DEBUG_UNREAD) { LauncherLog.d( TAG, "initUnreadNumberFromSystem: key = " + shortcut.mKey + ", unreadNum = " + shortcut.mUnreadNum); } } catch (android.provider.Settings.SettingNotFoundException e) { LauncherLog.e( TAG, "initUnreadNumberFromSystem SettingNotFoundException key = " + shortcut.mKey + ", e = " + e.getMessage()); } } if (LauncherLog.DEBUG_UNREAD) { LauncherLog.d(TAG, "initUnreadNumberFromSystem end:" + getUnreadSupportShortcutInfo()); } }
private void loadUnreadSupportShortcuts() { long start = System.currentTimeMillis(); if (LauncherLog.DEBUG_PERFORMANCE) { LauncherLog.d(TAG, "loadUnreadSupportShortcuts begin: start = " + start); } // Clear all previous parsed unread shortcuts. UNREAD_SUPPORT_SHORTCUTS.clear(); try { XmlResourceParser parser = mContext.getResources().getXml(R.xml.unread_support_shortcuts); AttributeSet attrs = Xml.asAttributeSet(parser); XmlUtils.beginDocument(parser, TAG_UNREADSHORTCUTS); final int depth = parser.getDepth(); int type = -1; while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { if (type != XmlPullParser.START_TAG) { continue; } TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.UnreadShortcut); synchronized (LOG_LOCK) { UNREAD_SUPPORT_SHORTCUTS.add( new UnreadSupportShortcut( a.getString(R.styleable.UnreadShortcut_unreadPackageName), a.getString(R.styleable.UnreadShortcut_unreadClassName), a.getString(R.styleable.UnreadShortcut_unreadKey), a.getInt(R.styleable.UnreadShortcut_unreadType, 0))); } a.recycle(); } } catch (XmlPullParserException e) { LauncherLog.w(TAG, "Got XmlPullParserException while parsing unread shortcuts.", e); } catch (IOException e) { LauncherLog.w(TAG, "Got IOException while parsing unread shortcuts.", e); } sUnreadSupportShortcutsNum = UNREAD_SUPPORT_SHORTCUTS.size(); if (LauncherLog.DEBUG_PERFORMANCE) { LauncherLog.d( TAG, "loadUnreadSupportShortcuts end: time used = " + (System.currentTimeMillis() - start) + ",sUnreadSupportShortcutsNum = " + sUnreadSupportShortcutsNum + getUnreadSupportShortcutInfo()); } }
@Override public void draw(Canvas canvas) { if (mBitmap == null) { return; } int width = canvas.getWidth(); int height = canvas.getHeight(); if (LauncherLog.DEBUG) { LauncherLog.d( TAG, "Bitmap width is " + mIntrinsicWidth + ", height is " + mIntrinsicHeight + ". Canvas width is " + width + ", height is " + height); } /// M: scale up the bitmap to make it cover the entire area float scalew = width / (float) mIntrinsicWidth; float scaleh = height / (float) mIntrinsicHeight; if (scalew > 1.0 || scaleh > 1.0) { if (LauncherLog.DEBUG) { LauncherLog.d(TAG, "Draw by scale size"); } float scale = scalew > scaleh ? scalew : scaleh; int scaledWidth = (int) (mIntrinsicWidth * scale); int scaledHeight = (int) (mIntrinsicHeight * scale); int x = (width - scaledWidth) / 2; int y = (height - scaledHeight) / 2; Bitmap scaledBitmap = Bitmap.createScaledBitmap(mBitmap, scaledWidth, scaledHeight, true); canvas.setDrawFilter( new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG)); canvas.drawBitmap(scaledBitmap, x, y, null); scaledBitmap.recycle(); scaledBitmap = null; } else { if (LauncherLog.DEBUG) { LauncherLog.d(TAG, "Draw by original size"); } int x = (width - mIntrinsicWidth) / 2; int y = (height - mIntrinsicHeight) / 2; canvas.drawBitmap(mBitmap, x, y, null); } }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (LauncherLog.DEBUG) { LauncherLog.d(TAG, "onCreateView: mEmbedded = " + mEmbedded + ", container = " + container); } findWallpapers(); /* If this fragment is embedded in the layout of this activity, then we should * generate a view to display. Otherwise, a dialog will be created in * onCreateDialog() */ if (mEmbedded) { View view = inflater.inflate(R.layout.wallpaper_chooser, container, false); view.setBackground(mWallpaperDrawable); final Gallery gallery = (Gallery) view.findViewById(R.id.gallery); gallery.setCallbackDuringFling(false); gallery.setOnItemSelectedListener(this); gallery.setAdapter(new ImageAdapter(getActivity())); View setButton = view.findViewById(R.id.set); setButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { selectWallpaper(gallery.getSelectedItemPosition()); } }); return view; } return null; }
/** * Returns a reference to a DataUtil instance. * * @return DataUtil object. */ public static synchronized DataUtil getInstance() { if (sDataUtil == null) { try { sDataUtil = (DataUtil) Class.forName("com.android.launcher2.LauncherDataUtil").newInstance(); } catch (ClassNotFoundException e) { LauncherLog.d(TAG, "LauncherDataUtil Class not found!"); } catch (InstantiationException e) { LauncherLog.d(TAG, "LauncherDataUtil Instantiation Exception!"); } catch (IllegalAccessException e) { LauncherLog.d(TAG, "LauncherDataUtil IllegalAccess Exception!"); } } LauncherLog.d(TAG, "sDataUtil = " + sDataUtil); return sDataUtil; }
@Override public void onReceive(final Context context, final Intent intent) { final String action = intent.getAction(); if (Intent.MTK_ACTION_UNREAD_CHANGED.equals(action)) { final ComponentName componentName = (ComponentName) intent.getExtra(Intent.MTK_EXTRA_UNREAD_COMPONENT); final int unreadNum = intent.getIntExtra(Intent.MTK_EXTRA_UNREAD_NUMBER, -1); if (LauncherLog.DEBUG) { LauncherLog.d( TAG, "Receive unread broadcast: componentName = " + componentName + ", unreadNum = " + unreadNum + ", mCallbacks = " + mCallbacks + getUnreadSupportShortcutInfo()); } if (mCallbacks != null && componentName != null && unreadNum != -1) { final int index = supportUnreadFeature(componentName); if (index >= 0) { boolean ret = setUnreadNumberAt(index, unreadNum); if (ret) { final UnreadCallbacks callbacks = mCallbacks.get(); if (callbacks != null) { callbacks.bindComponentUnreadChanged(componentName, unreadNum); } } } } } }
private void completeDrop(DragObject d) { ItemInfo item = (ItemInfo) d.dragInfo; if (LauncherLog.DEBUG) { LauncherLog.d( DragController.TAG, "DeleteDropTarget completeDrop: item = " + item + ",d = " + d); } if (isAllAppsApplication(d.dragSource, item)) { // Uninstall the application if it is being dragged from AppsCustomize mLauncher.startApplicationUninstallActivity((ApplicationInfo) item); } else if (isWorkspaceOrFolderApplication(d)) { LauncherModel.deleteItemFromDatabase(mLauncher, item); } else if (isWorkspaceFolder(d)) { // Remove the folder from the workspace and delete the contents from launcher model FolderInfo folderInfo = (FolderInfo) item; mLauncher.removeFolder(folderInfo); LauncherModel.deleteFolderContentsFromDatabase(mLauncher, folderInfo); } else if (isWorkspaceOrFolderWidget(d)) { // Remove the widget from the workspace mLauncher.removeAppWidget((LauncherAppWidgetInfo) item); LauncherModel.deleteItemFromDatabase(mLauncher, item); final LauncherAppWidgetInfo launcherAppWidgetInfo = (LauncherAppWidgetInfo) item; final LauncherAppWidgetHost appWidgetHost = mLauncher.getAppWidgetHost(); if (appWidgetHost != null) { // Deleting an app widget ID is a void call but writes to disk before returning // to the caller... new Thread("deleteAppWidgetId") { public void run() { appWidgetHost.deleteAppWidgetId(launcherAppWidgetInfo.appWidgetId); } }.start(); } } }
@Override public void onSaveInstanceState(Bundle outState) { outState.putBoolean(EMBEDDED_KEY, mEmbedded); if (LauncherLog.DEBUG) { LauncherLog.d( TAG, "onSaveInstanceState: outState = " + outState + ", mEmbedded = " + mEmbedded); } }
@Override public void onDestroy() { super.onDestroy(); if (LauncherLog.DEBUG) { LauncherLog.d(TAG, "onDestroy: mLoader = " + mLoader + ", this = " + this); } cancelLoader(); }
@Override public void onDetach() { super.onDetach(); if (LauncherLog.DEBUG) { LauncherLog.d(TAG, "onDetach."); } cancelLoader(); }
/* This will only be called when in XLarge mode, since this Fragment is invoked like * a dialog in that mode */ @Override public Dialog onCreateDialog(Bundle savedInstanceState) { if (LauncherLog.DEBUG) { LauncherLog.d(TAG, "onCreateDialog: savedInstanceState = " + savedInstanceState); } findWallpapers(); return null; }
/** * Get unread number of application at the given position in the supported shortcut list. * * @param index * @return */ static synchronized int getUnreadNumberAt(int index) { if (index < 0 || index >= sUnreadSupportShortcutsNum) { return 0; } if (LauncherLog.DEBUG_UNREAD) { LauncherLog.d(TAG, "getUnreadNumberAt: index = " + index + getUnreadSupportShortcutInfo()); } return UNREAD_SUPPORT_SHORTCUTS.get(index).mUnreadNum; }
@Override protected Bitmap doInBackground(Integer... params) { if (isCancelled() || !isAdded()) { // If the fragment is not added(attached) to an activity, return null. LauncherLog.d( TAG, "WallpaperLoader doInBackground: canceled = " + isCancelled() + ",isAdded() = " + isAdded() + ",activity = " + getActivity()); return null; } try { return BitmapFactory.decodeResource(getResources(), mImages.get(params[0]), mOptions); } catch (OutOfMemoryError e) { LauncherLog.e(TAG, "WallpaperLoader decode resource out of memory " + e.getMessage()); return null; } }
private void selectWallpaper(int position) { if (LauncherLog.DEBUG) { LauncherLog.d(TAG, "selectWallpaper: position = " + position + ", this = " + this); } try { WallpaperManager wpm = (WallpaperManager) getActivity().getSystemService(Context.WALLPAPER_SERVICE); wpm.setResource(mImages.get(position)); Activity activity = getActivity(); activity.setResult(Activity.RESULT_OK); activity.finish(); } catch (IOException e) { Log.e(TAG, "Failed to set wallpaper: " + e); } }
@Override public void onDismiss(DialogInterface dialog) { super.onDismiss(dialog); /* On orientation changes, the dialog is effectively "dismissed" so this is called * when the activity is no longer associated with this dying dialog fragment. We * should just safely ignore this case by checking if getActivity() returns null */ Activity activity = getActivity(); if (LauncherLog.DEBUG) { LauncherLog.d(TAG, "onDismiss: activity = " + activity + ", dialog = " + dialog); } if (activity != null) { activity.finish(); } }
/** * Whether the given component support unread feature. * * @param component * @return */ static int supportUnreadFeature(ComponentName component) { if (LauncherLog.DEBUG_UNREAD) { LauncherLog.d(TAG, "supportUnreadFeature: component = " + component); } if (component == null) { return -1; } final int size = UNREAD_SUPPORT_SHORTCUTS.size(); for (int i = 0, sz = size; i < sz; i++) { if (UNREAD_SUPPORT_SHORTCUTS.get(i).mComponent.equals(component)) { return i; } } return -1; }
/** * Set the unread number of the item in the list with the given unread number. * * @param index * @param unreadNum * @return */ static synchronized boolean setUnreadNumberAt(int index, int unreadNum) { if (index >= 0 || index < sUnreadSupportShortcutsNum) { if (LauncherLog.DEBUG_UNREAD) { LauncherLog.d( TAG, "setUnreadNumberAt: index = " + index + ",unreadNum = " + unreadNum + getUnreadSupportShortcutInfo()); } if (UNREAD_SUPPORT_SHORTCUTS.get(index).mUnreadNum != unreadNum) { UNREAD_SUPPORT_SHORTCUTS.get(index).mUnreadNum = unreadNum; return true; } } return false; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null && savedInstanceState.containsKey(EMBEDDED_KEY)) { mEmbedded = savedInstanceState.getBoolean(EMBEDDED_KEY); } else { mEmbedded = isInLayout(); } if (LauncherLog.DEBUG) { LauncherLog.d( TAG, "onCreate: savedInstanceState = " + savedInstanceState + ", mEmbedded = " + mEmbedded + ", this = " + this); } }
@Override public void onDragStart(DragSource source, Object info, int dragAction) { boolean isVisible = true; boolean isUninstall = false; // If we are dragging a widget from AppsCustomize, hide the delete target if (isAllAppsWidget(source, info)) { isVisible = false; } // If we are dragging an application from AppsCustomize, only show the control if we can // delete the app (it was downloaded), and rename the string to "uninstall" in such a case if (isAllAppsApplication(source, info)) { ApplicationInfo appInfo = (ApplicationInfo) info; if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) != 0) { isUninstall = true; } else { isVisible = false; } } if (isUninstall) { setCompoundDrawablesWithIntrinsicBounds(mUninstallDrawable, null, null, null); } else { setCompoundDrawablesWithIntrinsicBounds(mRemoveDrawable, null, null, null); } mCurrentDrawable = (TransitionDrawable) getCompoundDrawables()[0]; mActive = isVisible; mCurrentDrawable.resetTransition(); setTextColor(mOriginalTextColor); ((ViewGroup) getParent()).setVisibility(isVisible ? View.VISIBLE : View.GONE); if (getText().length() > 0) { setText(isUninstall ? R.string.delete_target_uninstall_label : R.string.delete_target_label); } Resources res = getResources(); if (isUninstall) { setPadding( res.getDimensionPixelOffset(R.dimen.uninstall_padding_left), getPaddingTop(), getPaddingRight(), getPaddingBottom()); } else { setPadding( res.getDimensionPixelOffset(R.dimen.remove_padding_left), getPaddingTop(), getPaddingRight(), getPaddingBottom()); } if (LauncherLog.DEBUG) { LauncherLog.d( DragController.TAG, "DeleteDropTarget onDragStart: isUninstall = " + isUninstall + ",isVisible = " + isVisible + ",info = " + info); } }
@Override public boolean needUpdateSearchButtonResource(ImageView view, int id) { LauncherLog.d(TAG, "default needUpdateSearchButtonResource called."); return true; }
/** * Returns a bitmap suitable for the all apps view. Used to convert pre-ICS icon bitmaps that are * stored in the database (which were 74x74 pixels at hdpi size) to the proper size (48dp). * * @param icon Icon resource. * @param context A Context object. * @return Bitmap created. */ public Bitmap createIconBitmap(Drawable icon, Context context) { LauncherLog.d(TAG, "DataUtil createIconBitmap!"); return null; }
/** * Check all the data is consistent. * * @param info ItemInfo to check. */ public void checkItemInfo(ItemInfo info) { LauncherLog.d(TAG, "DataUtil CheckItemInfo!"); }
/** Set this as the current Launcher activity object for the loader. */ public void initialize(UnreadCallbacks callbacks) { mCallbacks = new WeakReference<UnreadCallbacks>(callbacks); if (LauncherLog.DEBUG_UNREAD) { LauncherLog.d(TAG, "initialize: callbacks = " + callbacks + ", mCallbacks = " + mCallbacks); } }
public void onDrop(DragObject d) { if (LauncherLog.DEBUG) { LauncherLog.d(DragController.TAG, "DeleteDropTarget onDrop: d = " + d); } animateToTrashAndCompleteDrop(d); }
/** * Get Component Name from Resolve Info for use. * * @param info ResolveInfo for use. * @return ComponentName in ResolveInfo. */ public ComponentName getComponentNameFromResolveInfo(ResolveInfo info) { LauncherLog.d(TAG, "DataUtil getComponentNameFromResolveInfo!"); return null; }