Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e9d3e22c authored by Danny Baumann's avatar Danny Baumann
Browse files

Recreate gesture store on load.

The gesture store isn't cleared on loading, so when reloading the store
after creating a new gesture the gesture instances were duplicated.

Fixes http://code.google.com/p/cyanogenmod/issues/detail?id=3476.

Change-Id: Ia7f18384820612cb6a69399ca22288c31a2d6889
parent a3eb7604
Loading
Loading
Loading
Loading
+13 −11
Original line number Diff line number Diff line
@@ -56,15 +56,14 @@ public class GestureListActivity extends ListActivity {

    private static final int REQUEST_NEW_GESTURE = 1;

    private final File mStoreFile = new File(Environment.getDataDirectory(), "/misc/lockscreen_gestures");

    private final Comparator<NamedGesture> mSorter = new Comparator<NamedGesture>() {
        public int compare(NamedGesture object1, NamedGesture object2) {
            return object1.name.compareTo(object2.name);
        }
    };

    private static GestureLibrary sStore;
    private static final File sStoreFile = new File(Environment.getDataDirectory(), "/misc/lockscreen_gestures");
    private static GestureLibrary sStore = createStore();

    private GesturesAdapter mAdapter;
    private GesturesLoadTask mTask;
@@ -79,15 +78,16 @@ public class GestureListActivity extends ListActivity {
        mAdapter = new GesturesAdapter(this);
        setListAdapter(mAdapter);

        if (sStore == null) {
            sStore = GestureLibraries.fromFile(mStoreFile);
        }
        mEmpty = (TextView) findViewById(android.R.id.empty);
        loadGestures();

        registerForContextMenu(getListView());
    }

    static GestureLibrary createStore() {
        return GestureLibraries.fromFile(sStoreFile);
    }

    static GestureLibrary getStore() {
        return sStore;
    }
@@ -202,13 +202,15 @@ public class GestureListActivity extends ListActivity {
        protected Integer doInBackground(Void... params) {
            if (isCancelled()) return STATUS_CANCELLED;

            final GestureLibrary store = sStore;
            synchronized(sStore) {
                sStore = createStore();
            }

            if (store.load()) {
                for (String name : store.getGestureEntries()) {
            if (sStore.load()) {
                for (String name : sStore.getGestureEntries()) {
                    if (isCancelled()) break;

                    for (Gesture gesture : store.getGestures(name)) {
                    for (Gesture gesture : sStore.getGestures(name)) {
                        final Bitmap bitmap = gesture.toBitmap(mThumbnailSize, mThumbnailSize,
                                mThumbnailInset, mPathColor);
                        final NamedGesture namedGesture = new NamedGesture();
@@ -249,7 +251,7 @@ public class GestureListActivity extends ListActivity {
                getListView().setVisibility(View.GONE);
                mEmpty.setVisibility(View.VISIBLE);
                mEmpty.setText(getString(R.string.gestures_error_loading,
                        mStoreFile.getAbsolutePath()));
                        sStoreFile.getAbsolutePath()));
            } else {
                findViewById(R.id.addButton).setEnabled(true);
                checkForEmpty();