1729f5231bf95ec7946fc4c510d44db303b07614dChris Wren/* 2729f5231bf95ec7946fc4c510d44db303b07614dChris Wren * Copyright (C) 2013 The Android Open Source Project 3729f5231bf95ec7946fc4c510d44db303b07614dChris Wren * 4729f5231bf95ec7946fc4c510d44db303b07614dChris Wren * Licensed under the Apache License, Version 2.0 (the "License"); 5729f5231bf95ec7946fc4c510d44db303b07614dChris Wren * you may not use this file except in compliance with the License. 6729f5231bf95ec7946fc4c510d44db303b07614dChris Wren * You may obtain a copy of the License at 7729f5231bf95ec7946fc4c510d44db303b07614dChris Wren * 8729f5231bf95ec7946fc4c510d44db303b07614dChris Wren * http://www.apache.org/licenses/LICENSE-2.0 9729f5231bf95ec7946fc4c510d44db303b07614dChris Wren * 10729f5231bf95ec7946fc4c510d44db303b07614dChris Wren * Unless required by applicable law or agreed to in writing, software 11729f5231bf95ec7946fc4c510d44db303b07614dChris Wren * distributed under the License is distributed on an "AS IS" BASIS, 12729f5231bf95ec7946fc4c510d44db303b07614dChris Wren * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13729f5231bf95ec7946fc4c510d44db303b07614dChris Wren * See the License for the specific language governing permissions and 14729f5231bf95ec7946fc4c510d44db303b07614dChris Wren * limitations under the License. 15729f5231bf95ec7946fc4c510d44db303b07614dChris Wren */ 16729f5231bf95ec7946fc4c510d44db303b07614dChris Wrenpackage com.android.dreams.phototable; 17729f5231bf95ec7946fc4c510d44db303b07614dChris Wren 18729f5231bf95ec7946fc4c510d44db303b07614dChris Wrenimport android.content.BroadcastReceiver; 19729f5231bf95ec7946fc4c510d44db303b07614dChris Wrenimport android.content.Context; 20729f5231bf95ec7946fc4c510d44db303b07614dChris Wrenimport android.content.Intent; 21729f5231bf95ec7946fc4c510d44db303b07614dChris Wrenimport android.net.Uri; 22729f5231bf95ec7946fc4c510d44db303b07614dChris Wrenimport android.util.Log; 23729f5231bf95ec7946fc4c510d44db303b07614dChris Wren 24729f5231bf95ec7946fc4c510d44db303b07614dChris Wrenimport java.util.ArrayList; 25729f5231bf95ec7946fc4c510d44db303b07614dChris Wrenimport java.util.List; 26729f5231bf95ec7946fc4c510d44db303b07614dChris Wren 27729f5231bf95ec7946fc4c510d44db303b07614dChris Wrenpublic class PhotoDreamSettingsReceiver extends BroadcastReceiver { 28729f5231bf95ec7946fc4c510d44db303b07614dChris Wren private static final String TAG = "PhotoDreamSettingsReceiver"; 29729f5231bf95ec7946fc4c510d44db303b07614dChris Wren private static final String LOCAL_AUTHORITY = "media"; 30729f5231bf95ec7946fc4c510d44db303b07614dChris Wren private static final String INTERNAL = "internal"; 318b9a4b63266b3fe57b8f1e63b9012e87001f4b6cChris Wren private static final boolean DEBUG = false; 32729f5231bf95ec7946fc4c510d44db303b07614dChris Wren 33729f5231bf95ec7946fc4c510d44db303b07614dChris Wren public static final String ACTION_ADD_ALBUM = "add"; 34729f5231bf95ec7946fc4c510d44db303b07614dChris Wren public static final String ACTION_REMOVE_ALBUM = "remove"; 35729f5231bf95ec7946fc4c510d44db303b07614dChris Wren public static final String EXTRA_ALBUMS = "albums"; 36729f5231bf95ec7946fc4c510d44db303b07614dChris Wren 37729f5231bf95ec7946fc4c510d44db303b07614dChris Wren @Override 38729f5231bf95ec7946fc4c510d44db303b07614dChris Wren public void onReceive(Context context, Intent intent) { 39729f5231bf95ec7946fc4c510d44db303b07614dChris Wren AlbumSettings settings[] = { 40729f5231bf95ec7946fc4c510d44db303b07614dChris Wren AlbumSettings.getAlbumSettings( 41729f5231bf95ec7946fc4c510d44db303b07614dChris Wren context.getSharedPreferences(FlipperDreamSettings.PREFS_NAME, 0)), 42729f5231bf95ec7946fc4c510d44db303b07614dChris Wren AlbumSettings.getAlbumSettings( 43729f5231bf95ec7946fc4c510d44db303b07614dChris Wren context.getSharedPreferences(PhotoTableDreamSettings.PREFS_NAME, 0)) 44729f5231bf95ec7946fc4c510d44db303b07614dChris Wren }; 45729f5231bf95ec7946fc4c510d44db303b07614dChris Wren 46729f5231bf95ec7946fc4c510d44db303b07614dChris Wren boolean shown = ACTION_ADD_ALBUM.equals(intent.getAction()); 47729f5231bf95ec7946fc4c510d44db303b07614dChris Wren ArrayList<String> albumUris = intent.getStringArrayListExtra(EXTRA_ALBUMS); 48729f5231bf95ec7946fc4c510d44db303b07614dChris Wren for (String albumUriString: albumUris) { 49729f5231bf95ec7946fc4c510d44db303b07614dChris Wren Uri albumUri = Uri.parse(albumUriString); 50729f5231bf95ec7946fc4c510d44db303b07614dChris Wren String type = albumUri.getEncodedAuthority(); 51729f5231bf95ec7946fc4c510d44db303b07614dChris Wren List<String> path = albumUri.getPathSegments(); 52729f5231bf95ec7946fc4c510d44db303b07614dChris Wren 53729f5231bf95ec7946fc4c510d44db303b07614dChris Wren String albumId = null; 54729f5231bf95ec7946fc4c510d44db303b07614dChris Wren if (LOCAL_AUTHORITY.equals(type)) { 55729f5231bf95ec7946fc4c510d44db303b07614dChris Wren if (path.size() > 3) { 56729f5231bf95ec7946fc4c510d44db303b07614dChris Wren albumId = LocalSource.constructId(INTERNAL.equals(path.get(0)), path.get(3)); 57729f5231bf95ec7946fc4c510d44db303b07614dChris Wren } 58729f5231bf95ec7946fc4c510d44db303b07614dChris Wren } else { 59729f5231bf95ec7946fc4c510d44db303b07614dChris Wren if (path.size() > 1) { 60729f5231bf95ec7946fc4c510d44db303b07614dChris Wren albumId = PicasaSource.constructId(path.get(1)); 61729f5231bf95ec7946fc4c510d44db303b07614dChris Wren } 62729f5231bf95ec7946fc4c510d44db303b07614dChris Wren } 638b9a4b63266b3fe57b8f1e63b9012e87001f4b6cChris Wren if (DEBUG) Log.d(TAG, "receive: " + albumId + " is " + shown); 64729f5231bf95ec7946fc4c510d44db303b07614dChris Wren for (int idx = 0; idx < settings.length; idx++) { 65729f5231bf95ec7946fc4c510d44db303b07614dChris Wren settings[idx].setAlbumEnabled(albumId, shown); 66729f5231bf95ec7946fc4c510d44db303b07614dChris Wren } 67729f5231bf95ec7946fc4c510d44db303b07614dChris Wren } 68729f5231bf95ec7946fc4c510d44db303b07614dChris Wren } 69729f5231bf95ec7946fc4c510d44db303b07614dChris Wren} 70