• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 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 
17 package com.example.android.notepad;
18 
19 import com.example.android.notepad.NotePad;
20 
21 import android.app.Activity;
22 import android.content.Intent;
23 import android.content.Intent.ShortcutIconResource;
24 import android.os.Bundle;
25 import android.provider.LiveFolders;
26 
27 /**
28  * This Activity creates a live folder Intent and
29  * sends it back to HOME. From the data in the Intent, HOME creates a live folder and displays
30  * its icon in the Home view.
31  * When the user clicks the icon, Home uses the data it got from the Intent to retrieve information
32  * from a content provider and display it in a View.
33  *
34  * The intent filter for this Activity is set to ACTION_CREATE_LIVE_FOLDER, which
35  * HOME sends in response to a long press and selection of Live Folder.
36  */
37 public class NotesLiveFolder extends Activity {
38 
39     /**
40      * All of the work is done in onCreate(). The Activity doesn't actually display a UI.
41      * Instead, it sets up an Intent and returns it to its caller (the HOME activity).
42      */
43     @Override
onCreate(Bundle savedInstanceState)44     protected void onCreate(Bundle savedInstanceState) {
45         super.onCreate(savedInstanceState);
46 
47         /*
48          * Gets the incoming Intent and its action. If the incoming Intent was
49          * ACTION_CREATE_LIVE_FOLDER, then create an outgoing Intent with the
50          * necessary data and send back OK. Otherwise, send back CANCEL.
51          */
52         final Intent intent = getIntent();
53         final String action = intent.getAction();
54 
55         if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equals(action)) {
56 
57             // Creates a new Intent.
58             final Intent liveFolderIntent = new Intent();
59 
60             /*
61              * The following statements put data into the outgoing Intent. Please see
62              * {@link android.provider.LiveFolders for a detailed description of these
63              * data values. From this data, HOME sets up a live folder.
64              */
65             // Sets the URI pattern for the content provider backing the folder.
66             liveFolderIntent.setData(NotePad.Notes.LIVE_FOLDER_URI);
67 
68             // Adds the display name of the live folder as an Extra string.
69             String foldername = getString(R.string.live_folder_name);
70             liveFolderIntent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME, foldername);
71 
72             // Adds the display icon of the live folder as an Extra resource.
73             ShortcutIconResource foldericon =
74                 Intent.ShortcutIconResource.fromContext(this, R.drawable.live_folder_notes);
75             liveFolderIntent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON, foldericon);
76 
77             // Add the display mode of the live folder as an integer. The specified
78             // mode causes the live folder to display as a list.
79             liveFolderIntent.putExtra(
80                     LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE,
81                     LiveFolders.DISPLAY_MODE_LIST);
82 
83             /*
84              * Adds a base action for items in the live folder list, as an Intent. When the
85              * user clicks an individual note in the list, the live folder fires this Intent.
86              *
87              * Its action is ACTION_EDIT, so it triggers the Note Editor activity. Its
88              * data is the URI pattern for a single note identified by its ID. The live folder
89              * automatically adds the ID value of the selected item to the URI pattern.
90              *
91              * As a result, Note Editor is triggered and gets a single note to retrieve by ID.
92              */
93             Intent returnIntent
94                     = new Intent(Intent.ACTION_EDIT, NotePad.Notes.CONTENT_ID_URI_PATTERN);
95             liveFolderIntent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT, returnIntent);
96 
97             /* Creates an ActivityResult object to propagate back to HOME. Set its result indicator
98              * to OK, and sets the returned Intent to the live folder Intent that was just
99              * constructed.
100              */
101             setResult(RESULT_OK, liveFolderIntent);
102 
103         } else {
104 
105             // If the original action was not ACTION_CREATE_LIVE_FOLDER, creates an
106             // ActivityResult with the indicator set to CANCELED, but do not return an Intent
107             setResult(RESULT_CANCELED);
108         }
109 
110         // Closes the Activity. The ActivityObject is propagated back to the caller.
111         finish();
112     }
113 }
114