Example usage for android.appwidget AppWidgetManager getInstance

List of usage examples for android.appwidget AppWidgetManager getInstance

Introduction

In this page you can find the example usage for android.appwidget AppWidgetManager getInstance.

Prototype

public static AppWidgetManager getInstance(Context context) 

Source Link

Document

Get the AppWidgetManager instance to use for the supplied android.content.Context Context object.

Usage

From source file:com.tlongdev.bktf.util.Utility.java

public static void notifyPricesWidgets(Context context) {
    AppWidgetManager manager = AppWidgetManager.getInstance(context);
    int[] appWidgetIds = manager
            .getAppWidgetIds(new ComponentName(context.getApplicationContext(), FavoritesWidget.class));
    manager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.list_view);
}

From source file:com.android.launcher2.Launcher.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (DEBUG_STRICT_MODE) {
        StrictMode.setThreadPolicy(/*  www.ja  v  a  2s  .c  o m*/
                new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork() // or .detectAll() for all detectable problems
                        .penaltyLog().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects()
                .detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());
    }

    super.onCreate(savedInstanceState);
    LauncherApplication app = ((LauncherApplication) getApplication());
    mSharedPrefs = getSharedPreferences(LauncherApplication.getSharedPreferencesKey(), Context.MODE_PRIVATE);
    mModel = app.setLauncher(this);
    mIconCache = app.getIconCache();
    mDragController = new DragController(this);
    mInflater = getLayoutInflater();

    mAppWidgetManager = AppWidgetManager.getInstance(this);
    mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
    mAppWidgetHost.startListening();

    // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
    // this also ensures that any synchronous binding below doesn't re-trigger another
    // LauncherModel load.
    mPaused = false;

    if (PROFILE_STARTUP) {
        android.os.Debug.startMethodTracing(Environment.getExternalStorageDirectory() + "/launcher");
    }

    checkForLocaleChange();
    setContentView(R.layout.launcher);
    setupViews();
    showFirstRunWorkspaceCling();

    registerContentObservers();

    lockAllApps();

    mSavedState = savedInstanceState;
    restoreState(mSavedState);

    // Update customization drawer _after_ restoring the states
    if (mAppsCustomizeContent != null) {
        mAppsCustomizeContent.onPackagesUpdated();
    }

    if (PROFILE_STARTUP) {
        android.os.Debug.stopMethodTracing();
    }

    if (!mRestoring) {
        if (sPausedFromUserAction) {
            // If the user leaves launcher, then we should just load items asynchronously when
            // they return.
            mModel.startLoader(true, -1);
        } else {
            // We only load the page synchronously if the user rotates (or triggers a
            // configuration change) while launcher is in the foreground
            mModel.startLoader(true, mWorkspace.getCurrentPage());
        }
    }

    if (!mModel.isAllAppsLoaded()) {
        ViewGroup appsCustomizeContentParent = (ViewGroup) mAppsCustomizeContent.getParent();
        mInflater.inflate(R.layout.apps_customize_progressbar, appsCustomizeContentParent);
    }

    // For handling default keys
    mDefaultKeySsb = new SpannableStringBuilder();
    Selection.setSelection(mDefaultKeySsb, 0);

    IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
    registerReceiver(mCloseSystemDialogsReceiver, filter);

    updateGlobalIcons();

    // On large interfaces, we want the screen to auto-rotate based on the current orientation
    unlockScreenOrientation(true);
}

From source file:com.gxapplications.android.gxsuite.launcher.Launcher.java

@SuppressWarnings("unused")
@Override/* w ww.jav  a 2 s. c  om*/
protected void onCreate(Bundle savedInstanceState) {
    if (DEBUG_STRICT_MODE) {
        StrictMode.setThreadPolicy(
                new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork() // or .detectAll() for all detectable problems
                        .penaltyLog().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects()
                .detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());
    }

    super.onCreate(savedInstanceState);
    LauncherApplication app = ((LauncherApplication) getApplication());
    mSharedPrefs = getSharedPreferences(LauncherApplication.getSharedPreferencesKey(), Context.MODE_PRIVATE);
    mModel = app.setLauncher(this);
    mIconCache = app.getIconCache();
    mDragController = new DragController(this);
    mInflater = getLayoutInflater();

    mAppWidgetManager = AppWidgetManager.getInstance(this);
    mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
    mAppWidgetHost.startListening();

    // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
    // this also ensures that any synchronous binding below doesn't re-trigger another
    // LauncherModel load.
    mPaused = false;

    if (PROFILE_STARTUP) {
        android.os.Debug.startMethodTracing(Environment.getExternalStorageDirectory() + "/launcher");
    }

    checkForLocaleChange();

    if (MainConfiguration.SCREEN_COUNT == 2) {
        if (MainConfiguration.ALLOW_DRAWER)
            setContentView(R.layout.drawer_launcher_2);
        else
            setContentView(R.layout.launcher_2);
    } else if (MainConfiguration.SCREEN_COUNT == 3) {
        if (MainConfiguration.ALLOW_DRAWER)
            setContentView(R.layout.drawer_launcher_3);
        else
            setContentView(R.layout.launcher_3);
    } else if (MainConfiguration.SCREEN_COUNT == 4) {
        if (MainConfiguration.ALLOW_DRAWER)
            setContentView(R.layout.drawer_launcher_4);
        else
            setContentView(R.layout.launcher_4);
    } else if (MainConfiguration.SCREEN_COUNT == 5) {
        if (MainConfiguration.ALLOW_DRAWER)
            setContentView(R.layout.drawer_launcher_5);
        else
            setContentView(R.layout.launcher_5);
    } else if (MainConfiguration.SCREEN_COUNT == 6) {
        if (MainConfiguration.ALLOW_DRAWER)
            setContentView(R.layout.drawer_launcher_6);
        else
            setContentView(R.layout.launcher_6);
    } else if (MainConfiguration.SCREEN_COUNT == 7) {
        if (MainConfiguration.ALLOW_DRAWER)
            setContentView(R.layout.drawer_launcher_7);
        else
            setContentView(R.layout.launcher_7);
    } else {
        setContentView(R.layout.launcher_5);
    }

    setupViews();
    showFirstRunWorkspaceCling();

    if (MainConfiguration.ALLOW_DRAWER) {
        this.drawerLayout = (DrawerLayout) this.findViewById(R.id.drawer_layout);
        ((LauncherDrawerLayout) this.drawerLayout).postInit(this, this.mWorkspace, this.mSharedPrefs);
    }

    registerContentObservers();

    lockAllApps();

    mSavedState = savedInstanceState;
    restoreState(mSavedState);

    // Update customization drawer _after_ restoring the states
    if (mAppsCustomizeContent != null) {
        mAppsCustomizeContent.onPackagesUpdated();
    }

    if (PROFILE_STARTUP) {
        android.os.Debug.stopMethodTracing();
    }

    if (!mRestoring) {
        if (sPausedFromUserAction) {
            // If the user leaves launcher, then we should just load items asynchronously when
            // they return.
            mModel.startLoader(true, -1);
        } else {
            // We only load the page synchronously if the user rotates (or triggers a
            // configuration change) while launcher is in the foreground
            mModel.startLoader(true, mWorkspace.getCurrentPage());
        }
    }

    if (!mModel.isAllAppsLoaded()) {
        ViewGroup appsCustomizeContentParent = (ViewGroup) mAppsCustomizeContent.getParent();
        mInflater.inflate(R.layout.apps_customize_progressbar, appsCustomizeContentParent);
    }

    // For handling default keys
    mDefaultKeySsb = new SpannableStringBuilder();
    Selection.setSelection(mDefaultKeySsb, 0);

    IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
    registerReceiver(mCloseSystemDialogsReceiver, filter);

    updateGlobalIcons();

    // On large interfaces, we want the screen to auto-rotate based on the current orientation
    unlockScreenOrientation(true);
}

From source file:com.grarak.kerneladiutor.fragments.tools.ProfileFragment.java

private void load(List<RecyclerViewItem> items) {
    mProfiles = new Profiles(getActivity());
    List<Profiles.ProfileItem> profileItems = mProfiles.getAllProfiles();
    if (mTaskerMode && profileItems.size() == 0) {
        Snackbar.make(getRootView(), R.string.no_profiles, Snackbar.LENGTH_LONG).show();
        return;/* www  .j a  v  a 2 s.  c  om*/
    }
    for (int i = 0; i < profileItems.size(); i++) {
        final int position = i;
        final CardView cardView = new CardView(getActivity());
        cardView.setOnMenuListener(new CardView.OnMenuListener() {
            @Override
            public void onMenuReady(final CardView cardView, PopupMenu popupMenu) {
                Menu menu = popupMenu.getMenu();
                menu.add(Menu.NONE, 0, Menu.NONE, getString(R.string.append));
                menu.add(Menu.NONE, 1, Menu.NONE, getString(R.string.edit));
                menu.add(Menu.NONE, 2, Menu.NONE, getString(R.string.details));
                final MenuItem onBoot = menu.add(Menu.NONE, 3, Menu.NONE, getString(R.string.on_boot))
                        .setCheckable(true);
                onBoot.setChecked(mProfiles.getAllProfiles().get(position).isOnBootEnabled());
                menu.add(Menu.NONE, 4, Menu.NONE, getString(R.string.export));
                menu.add(Menu.NONE, 5, Menu.NONE, getString(R.string.delete));

                popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        List<Profiles.ProfileItem> items = mProfiles.getAllProfiles();
                        switch (item.getItemId()) {
                        case 0:
                            if (Utils.DONATED) {
                                Intent intent = new Intent(getActivity(), ProfileActivity.class);
                                intent.putExtra(ProfileActivity.POSITION_INTENT, position);
                                startActivityForResult(intent, 2);
                            } else {
                                mDonateDialog = ViewUtils.dialogDonate(getActivity());
                                mDonateDialog.show();
                            }
                            break;
                        case 1:
                            if (Utils.DONATED) {
                                Intent intent = new Intent(getActivity(), ProfileEditActivity.class);
                                intent.putExtra(ProfileEditActivity.POSITION_INTENT, position);
                                startActivityForResult(intent, 3);
                            } else {
                                mDonateDialog = ViewUtils.dialogDonate(getActivity());
                                mDonateDialog.show();
                            }
                            break;
                        case 2:
                            if (items.get(position).getName() != null) {
                                List<Profiles.ProfileItem.CommandItem> commands = items.get(position)
                                        .getCommands();
                                if (commands.size() > 0) {
                                    setForegroundText(items.get(position).getName().toUpperCase());
                                    mDetailsFragment.setText(commands);
                                    showForeground();
                                } else {
                                    Utils.toast(R.string.profile_empty, getActivity());
                                }
                            }
                            break;
                        case 3:
                            onBoot.setChecked(!onBoot.isChecked());
                            items.get(position).enableOnBoot(onBoot.isChecked());
                            mProfiles.commit();
                            break;
                        case 4:
                            mExportProfile = items.get(position);
                            requestPermission(0, Manifest.permission.WRITE_EXTERNAL_STORAGE);
                            break;
                        case 5:
                            mDeleteDialog = ViewUtils.dialogBuilder(getString(R.string.sure_question),
                                    new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialogInterface, int i) {
                                        }
                                    }, new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialogInterface, int i) {
                                            mProfiles.delete(position);
                                            mProfiles.commit();
                                            reload();
                                        }
                                    }, new DialogInterface.OnDismissListener() {
                                        @Override
                                        public void onDismiss(DialogInterface dialogInterface) {
                                            mDeleteDialog = null;
                                        }
                                    }, getActivity());
                            mDeleteDialog.show();
                            break;
                        }
                        return false;
                    }
                });
            }
        });

        final DescriptionView descriptionView = new DescriptionView();
        descriptionView.setSummary(profileItems.get(i).getName());
        descriptionView.setOnItemClickListener(new RecyclerViewItem.OnItemClickListener() {
            @Override
            public void onClick(RecyclerViewItem item) {
                if (mTaskerMode) {
                    mSelectDialog = ViewUtils.dialogBuilder(
                            getString(R.string.select_question, descriptionView.getSummary()),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                }
                            }, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    ((ProfileTaskerActivity) getActivity()).finish(
                                            descriptionView.getSummary().toString(),
                                            mProfiles.getAllProfiles().get(position).getCommands());
                                }
                            }, new DialogInterface.OnDismissListener() {
                                @Override
                                public void onDismiss(DialogInterface dialogInterface) {
                                    mSelectDialog = null;
                                }
                            }, getActivity());
                    mSelectDialog.show();
                } else {
                    mApplyDialog = ViewUtils.dialogBuilder(
                            getString(R.string.apply_question, descriptionView.getSummary()),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                }
                            }, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    for (Profiles.ProfileItem.CommandItem command : mProfiles.getAllProfiles()
                                            .get(position).getCommands()) {
                                        CPUFreq.ApplyCpu applyCpu;
                                        if (command.getCommand().startsWith("#")
                                                && ((applyCpu = new CPUFreq.ApplyCpu(
                                                        command.getCommand().substring(1)))
                                                                .toString() != null)) {
                                            for (String applyCpuCommand : Service.getApplyCpu(applyCpu,
                                                    RootUtils.getSU())) {
                                                Control.runSetting(applyCpuCommand, null, null, null);
                                            }
                                        } else {
                                            Control.runSetting(command.getCommand(), null, null, null);
                                        }
                                    }
                                }
                            }, new DialogInterface.OnDismissListener() {
                                @Override
                                public void onDismiss(DialogInterface dialogInterface) {
                                    mApplyDialog = null;
                                }
                            }, getActivity());
                    try {
                        mApplyDialog.show();
                    } catch (NullPointerException ignored) {
                    }
                }
            }
        });

        if (mTaskerMode) {
            items.add(descriptionView);
        } else {
            cardView.addItem(descriptionView);
            items.add(cardView);
        }
    }

    if (!mTaskerMode) {
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getActivity());
        int appWidgetIds[] = appWidgetManager.getAppWidgetIds(new ComponentName(getActivity(), Widget.class));
        appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.profile_list);
        Tile.publishProfileTile(profileItems, getActivity());
    }
}

From source file:com.piusvelte.taplock.client.core.TapLockService.java

private void buildWidget(int appWidgetId) {
    RemoteViews rv = new RemoteViews(getPackageName(), R.layout.widget);
    String deviceName = null;//ww  w  .j  a  va  2 s . com
    for (JSONObject deviceJObj : mDevices) {
        if (deviceJObj.has(KEY_WIDGETS) && deviceJObj.has(KEY_NAME)) {
            JSONArray widgetsJArr = null;
            try {
                widgetsJArr = deviceJObj.getJSONArray(KEY_WIDGETS);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            if (widgetsJArr != null) {
                for (int i = 0, l = widgetsJArr.length(); (i < l) && (deviceName == null); i++) {
                    int widgetId;
                    try {
                        widgetId = widgetsJArr.getInt(i);
                    } catch (JSONException e) {
                        widgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
                        e.printStackTrace();
                    }
                    if ((widgetId != AppWidgetManager.INVALID_APPWIDGET_ID) && (appWidgetId == widgetId)) {
                        try {
                            deviceName = deviceJObj.getString(KEY_NAME);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        break;
                    }
                }
            }
            if (deviceName != null)
                break;
        }
    }
    if (deviceName == null)
        deviceName = "unknown";
    rv.setTextViewText(R.id.device_name, deviceName);
    rv.setOnClickPendingIntent(R.id.widget_icon,
            PendingIntent.getActivity(this, 0,
                    TapLock.getPackageIntent(this, TapLockToggle.class)
                            .setData(Uri.parse(String.format(getString(R.string.device_uri), deviceName))),
                    Intent.FLAG_ACTIVITY_NEW_TASK));
    AppWidgetManager.getInstance(this).updateAppWidget(appWidgetId, rv);
}

From source file:au.com.wallaceit.reddinator.Rservice.java

private void hideWidgetLoader(boolean goToTopOfList, boolean showError) {
    AppWidgetManager mgr = AppWidgetManager.getInstance(mContext);
    // get theme layout id
    int layout = 1;
    switch (Integer.valueOf(mSharedPreferences.getString("widgetthemepref", "1"))) {
    case 1://ww w.  j  av  a 2s  .  com
        layout = R.layout.widgetmain;
        break;
    case 2:
        layout = R.layout.widgetdark;
        break;
    case 3:
        layout = R.layout.widgetholo;
        break;
    case 4:
        layout = R.layout.widgetdarkholo;
        break;
    case 5:
        layout = R.layout.widgettrans;
        break;
    }
    RemoteViews views = new RemoteViews(mContext.getPackageName(), layout);
    views.setViewVisibility(R.id.srloader, View.INVISIBLE);
    // go to the top of the list view
    if (goToTopOfList) {
        views.setScrollPosition(R.id.listview, 0);
    }
    if (showError) {
        views.setViewVisibility(R.id.erroricon, View.VISIBLE);
    }
    mgr.partiallyUpdateAppWidget(appWidgetId, views);
}

From source file:com.andryr.musicplayer.PlaybackService.java

private void refreshAppWidgets() {

    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
    int appWidgetIds[] = appWidgetManager.getAppWidgetIds(new ComponentName(this, PlaybackWidget.class));
    PlaybackWidget.updateAppWidget(this, appWidgetIds);
}

From source file:com.android.launcher2.AsyncTaskCallback.java

public void onPackagesUpdated() {
    // Get the list of widgets and shortcuts
    mWidgets.clear();//from  www  .j av  a 2s  .  c o m
    List<AppWidgetProviderInfo> widgets = AppWidgetManager.getInstance(mLauncher).getInstalledProviders();
    Intent shortcutsIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
    List<ResolveInfo> shortcuts = mPackageManager.queryIntentActivities(shortcutsIntent, 0);
    addInstalledAppWidgets(widgets);
    mWidgets.addAll(shortcuts);
    Collections.sort(mWidgets, new LauncherModel.WidgetAndShortcutNameComparator(mPackageManager));
    updatePageCounts();
    invalidateOnDataChange();
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    PersonaLog.d("PersonaLauncher", "onCreate of personalauncher");
    mContext = this;
    mMessWithPersistence = PersonaAlmostNexusSettingsHelper.getSystemPersistent(this);
    if (mMessWithPersistence) {
        changeOrientation(PersonaAlmostNexusSettingsHelper.getDesktopOrientation(this), true);
        // setPersistent(true);
    } else {/*from   w w  w .jav a2s.com*/
        // setPersistent(false);
        changeOrientation(PersonaAlmostNexusSettingsHelper.getDesktopOrientation(this), false);
    }
    mBlockDesktop = PersonaAlmostNexusSettingsHelper.getDesktopBlocked(this);
    super.onCreate(savedInstanceState);
    mInflater = getLayoutInflater();
    mIntent = getIntent();
    PersonaAppCatalogueFilters.getInstance().init(this);
    PersonaLauncherActions.getInstance().init(this);

    mAppWidgetManager = AppWidgetManager.getInstance(this);

    mAppWidgetHost = new PersonaLauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
    mAppWidgetHost.startListening();

    if (PROFILE_STARTUP) {
        android.os.Debug.startMethodTracing("/sdcard/launcher");
    }
    updateAlmostNexusVars();
    checkForLocaleChange();
    // setWallpaperDimension();
    setContentView(R.layout.pr_launcher);
    setupViews();

    registerIntentReceivers();
    registerContentObservers();

    mSavedState = savedInstanceState;
    restoreState(mSavedState);

    if (PROFILE_STARTUP) {
        android.os.Debug.stopMethodTracing();
    }

    if (!mRestoring) {
        startLoaders();
    }

    WindowManager.LayoutParams attrs = getWindow().getAttributes();
    attrs.flags |= WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN;
    getWindow().setAttributes(attrs);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    hideStatusBar = false;

    // 290778 removed rotation animation

    /*
     * final RotateAnimation rotate = (RotateAnimation)
     * AnimationUtils.loadAnimation(this, R.anim.pr_rotate);
     * mDragLayer.setAnimation(rotate);
     * 
     * rotate.setAnimationListener(new AnimationListener() {
     * 
     * @Override public void onAnimationStart(Animation animation) {
     * 
     * }
     * 
     * @Override public void onAnimationRepeat(Animation animation) {
     * 
     * }
     * 
     * @Override public void onAnimationEnd(Animation animation) {
     * 
     * // go non-full screen WindowManager.LayoutParams attrs =
     * getWindow().getAttributes(); attrs.flags &=
     * (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
     * getWindow().setAttributes(attrs);
     * getWindow().clearFlags(WindowManager
     * .LayoutParams.FLAG_LAYOUT_NO_LIMITS); hideStatusBar=false; } });
     */

    // For handling default keys
    /*
     * mDefaultKeySsb = new SpannableStringBuilder();
     * Selection.setSelection(mDefaultKeySsb, 0);
     */

    // ADW: register a sharedpref listener
    getSharedPreferences("launcher.preferences.almostnexus", Context.MODE_PRIVATE)
            .registerOnSharedPreferenceChangeListener(this);
    showPwdExpiryScreen();
    // showAllApps(true, null);
    onloadlib();
    //WIDGET
    sendBroadcastForWidgetUpdate();
    PersonaLog.d("personalauncher", "---- oncreate of personalauncher ends ----");
}

From source file:com.android.soma.Launcher.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (DEBUG_STRICT_MODE) {
        StrictMode.setThreadPolicy(//from  w w w.j a v  a2s  .  c o  m
                new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork() // or .detectAll() for all detectable problems
                        .penaltyLog().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects()
                .detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());
    }

    super.onCreate(savedInstanceState);

    LauncherAppState.setApplicationContext(getApplicationContext());
    LauncherAppState app = LauncherAppState.getInstance();

    // Determine the dynamic grid properties
    Point smallestSize = new Point();
    Point largestSize = new Point();
    Point realSize = new Point();
    Display display = getWindowManager().getDefaultDisplay();
    display.getCurrentSizeRange(smallestSize, largestSize);
    display.getRealSize(realSize);
    DisplayMetrics dm = new DisplayMetrics();
    display.getMetrics(dm);
    // Lazy-initialize the dynamic grid
    DeviceProfile grid = app.initDynamicGrid(this, Math.min(smallestSize.x, smallestSize.y),
            Math.min(largestSize.x, largestSize.y), realSize.x, realSize.y, dm.widthPixels, dm.heightPixels);

    // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
    mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(), Context.MODE_PRIVATE);
    mModel = app.setLauncher(this);
    mIconCache = app.getIconCache();
    mIconCache.flushInvalidIcons(grid);
    mDragController = new DragController(this);
    mInflater = getLayoutInflater();

    mStats = new Stats(this);

    mAppWidgetManager = AppWidgetManager.getInstance(this);

    mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
    mAppWidgetHost.startListening();

    // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
    // this also ensures that any synchronous binding below doesn't re-trigger another
    // LauncherModel load.
    mPaused = false;

    if (PROFILE_STARTUP) {
        android.os.Debug.startMethodTracing(Environment.getExternalStorageDirectory() + "/launcher");
    }

    checkForLocaleChange();
    setContentView(R.layout.launcher);

    setupViews();
    grid.layout(this);

    registerContentObservers();

    lockAllApps();

    mSavedState = savedInstanceState;
    restoreState(mSavedState);

    // Update customization drawer _after_ restoring the states
    if (mAppsCustomizeContent != null) {
        mAppsCustomizeContent.onPackagesUpdated(LauncherModel.getSortedWidgetsAndShortcuts(this));
    }
    {
        {
            final RajawaliSurfaceView surface = new RajawaliSurfaceView(this);
            surface.setFrameRate(60.0);
            surface.setRenderMode(IRajawaliSurface.RENDERMODE_WHEN_DIRTY);

            // Add mSurface to your root view
            addContentView(surface, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT));

            mRenderer = new WallpaperRenderer(this);
            surface.setSurfaceRenderer(mRenderer);
        }
    }

    if (PROFILE_STARTUP) {
        android.os.Debug.stopMethodTracing();
    }

    if (!mRestoring) {
        if (sPausedFromUserAction) {
            // If the user leaves launcher, then we should just load items asynchronously when
            // they return.
            mModel.startLoader(true, -1);
        } else {
            // We only load the page synchronously if the user rotates (or triggers a
            // configuration change) while launcher is in the foreground
            mModel.startLoader(true, mWorkspace.getCurrentPage());
        }
    }

    // For handling default keys
    mDefaultKeySsb = new SpannableStringBuilder();
    Selection.setSelection(mDefaultKeySsb, 0);

    IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
    registerReceiver(mCloseSystemDialogsReceiver, filter);

    updateGlobalIcons();

    // On large interfaces, we want the screen to auto-rotate based on the current orientation
    unlockScreenOrientation(true);

    showFirstRunCling();

    //        following code is for Native method support test
    {

    }
}