• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.dreams.phototable;
17 
18 import android.content.BroadcastReceiver;
19 import android.content.Context;
20 import android.content.Intent;
21 import android.net.Uri;
22 import android.util.Log;
23 
24 import java.util.ArrayList;
25 import java.util.List;
26 
27 public class PhotoDreamSettingsReceiver extends BroadcastReceiver {
28     private static final String TAG = "PhotoDreamSettingsReceiver";
29     private static final String LOCAL_AUTHORITY = "media";
30     private static final String INTERNAL = "internal";
31     private static final boolean DEBUG = false;
32 
33     public static final String ACTION_ADD_ALBUM = "add";
34     public static final String ACTION_REMOVE_ALBUM = "remove";
35     public static final String EXTRA_ALBUMS = "albums";
36 
37     @Override
onReceive(Context context, Intent intent)38     public void onReceive(Context context, Intent intent) {
39         AlbumSettings settings[] = {
40                 AlbumSettings.getAlbumSettings(
41                         context.getSharedPreferences(FlipperDreamSettings.PREFS_NAME, 0)),
42                 AlbumSettings.getAlbumSettings(
43                         context.getSharedPreferences(PhotoTableDreamSettings.PREFS_NAME, 0))
44         };
45 
46         boolean shown = ACTION_ADD_ALBUM.equals(intent.getAction());
47         ArrayList<String> albumUris = intent.getStringArrayListExtra(EXTRA_ALBUMS);
48         for (String albumUriString: albumUris) {
49             Uri albumUri = Uri.parse(albumUriString);
50             String type = albumUri.getEncodedAuthority();
51             List<String> path = albumUri.getPathSegments();
52 
53             String albumId = null;
54             if (LOCAL_AUTHORITY.equals(type)) {
55                 if (path.size() > 3) {
56                     albumId = LocalSource.constructId(INTERNAL.equals(path.get(0)), path.get(3));
57                 }
58             } else {
59                 if (path.size() > 1) {
60                     albumId = PicasaSource.constructId(path.get(1));
61                 }
62             }
63             if (DEBUG) Log.d(TAG, "receive: " + albumId + " is " + shown);
64             for (int idx = 0; idx < settings.length; idx++) {
65                 settings[idx].setAlbumEnabled(albumId, shown);
66             }
67         }
68     }
69 }
70