19 | * Constant Value: "org.openintents.action.EDIT_AUTOMATION_SETTINGS" 20 | *
21 | */ 22 | public static final String ACTION_EDIT_AUTOMATION = "org.openintents.action.EDIT_AUTOMATION"; 23 | 24 | /** 25 | * Broadcast Action: This broadcast is sent to the same package in order to 26 | * activate an automation. 27 | * 28 | * There can only be one broadcast receiver per package that implements this 29 | * intent. Any differentiation should be done through intent extras. 30 | * 31 | *32 | * Constant Value: "org.openintents.action.EDIT_AUTOMATION_SETTINGS" 33 | *
34 | */ 35 | public static final String ACTION_RUN_AUTOMATION = "org.openintents.action.RUN_AUTOMATION"; 36 | 37 | /** 38 | * String extra containing a human readable description of the action to be 39 | * performed. 40 | * 41 | *42 | * Constant Value: "org.openintents.extra.DESCRIPTION" 43 | *
44 | */ 45 | public static final String EXTRA_DESCRIPTION = "org.openintents.extra.DESCRIPTION"; 46 | 47 | } 48 | -------------------------------------------------------------------------------- /ShoppingList/src/main/java/org/openintents/intents/FileManagerIntents.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 OpenIntents.org 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 org.openintents.intents; 18 | 19 | // Version Dec 9, 2008 20 | 21 | 22 | /** 23 | * Provides OpenIntents actions, extras, and categories used by providers. 24 | *These specifiers extend the standard Android specifiers.
25 | */ 26 | public final class FileManagerIntents { 27 | 28 | /** 29 | * Activity Action: Pick a file through the file manager, or let user 30 | * specify a custom file name. 31 | * Data is the current file name or file name suggestion. 32 | * Returns a new file name as file URI in data. 33 | * 34 | *Constant Value: "org.openintents.action.PICK_FILE"
35 | */ 36 | public static final String ACTION_PICK_FILE = "org.openintents.action.PICK_FILE"; 37 | 38 | /** 39 | * Activity Action: Pick a directory through the file manager, or let user 40 | * specify a custom file name. 41 | * Data is the current directory name or directory name suggestion. 42 | * Returns a new directory name as file URI in data. 43 | * 44 | *Constant Value: "org.openintents.action.PICK_DIRECTORY"
45 | */ 46 | public static final String ACTION_PICK_DIRECTORY = "org.openintents.action.PICK_DIRECTORY"; 47 | 48 | /** 49 | * The title to display. 50 | * 51 | *This is shown in the title bar of the file manager.
52 | * 53 | *Constant Value: "org.openintents.extra.TITLE"
54 | */ 55 | public static final String EXTRA_TITLE = "org.openintents.extra.TITLE"; 56 | 57 | /** 58 | * The text on the button to display. 59 | * 60 | *Depending on the use, it makes sense to set this to "Open" or "Save".
61 | * 62 | *Constant Value: "org.openintents.extra.BUTTON_TEXT"
63 | */ 64 | public static final String EXTRA_BUTTON_TEXT = "org.openintents.extra.BUTTON_TEXT"; 65 | 66 | } 67 | -------------------------------------------------------------------------------- /ShoppingList/src/main/java/org/openintents/intents/GeneralIntents.java: -------------------------------------------------------------------------------- 1 | package org.openintents.intents; 2 | 3 | /** 4 | * @author Ben 5 | * @version 1.0.0 6 | */ 7 | public class GeneralIntents { 8 | 9 | /** 10 | * Inserts a items from intent extras into any list. 11 | */ 12 | public static final String ACTION_INSERT_FROM_EXTRAS = "org.openintents.action.INSERT_FROM_EXTRAS"; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /ShoppingList/src/main/java/org/openintents/intents/ProviderIntents.java: -------------------------------------------------------------------------------- 1 | package org.openintents.intents; 2 | 3 | //Version Nov 21, 2008 4 | 5 | /** 6 | * Provides OpenIntents actions, extras, and categories used by providers. 7 | *8 | * These specifiers extend the standard Android specifiers. 9 | *
10 | */ 11 | public final class ProviderIntents { 12 | 13 | /** 14 | * Broadcast Action: Sent after a new entry has been inserted. 15 | * 16 | *17 | * Constant Value: "org.openintents.action.INSERTED" 18 | *
19 | */ 20 | public static final String ACTION_INSERTED = "org.openintents.action.INSERTED"; 21 | 22 | /** 23 | * Broadcast Action: Sent after an entry has been modified. 24 | * 25 | *26 | * Constant Value: "org.openintents.action.MODIFIED" 27 | *
28 | */ 29 | public static final String ACTION_MODIFIED = "org.openintents.action.MODIFIED"; 30 | 31 | /** 32 | * Broadcast Action: Sent after an entry has been deleted. 33 | * 34 | *35 | * Constant Value: "org.openintents.action.DELETED" 36 | *
37 | */ 38 | public static final String ACTION_DELETED = "org.openintents.action.DELETED"; 39 | 40 | /** 41 | * Added by the ACTION_DELETED broadcast if it contains a where clause. 42 | * 43 | *44 | * The extra contains a long[] which contains the row IDs of all rows 45 | * affected by the where clause. It contains NULL if all rows specified by 46 | * the URI are affected. 47 | *
48 | * 49 | *50 | * Constant Value: "org.openintents.extra.AFFECTED_ROWS" 51 | *
52 | */ 53 | public static final String EXTRA_AFFECTED_ROWS = "org.openintents.extra.AFFECTED_ROWS"; 54 | } 55 | -------------------------------------------------------------------------------- /ShoppingList/src/main/java/org/openintents/intents/ProviderUtils.java: -------------------------------------------------------------------------------- 1 | package org.openintents.intents; 2 | 3 | //Version Nov 21, 2008 4 | 5 | import android.database.Cursor; 6 | import android.database.sqlite.SQLiteDatabase; 7 | import android.provider.BaseColumns; 8 | import android.text.TextUtils; 9 | 10 | public class ProviderUtils { 11 | 12 | /** 13 | * Returns the row IDs of all affected rows. 14 | * 15 | * @param db 16 | * @param table 17 | * @param whereClause 18 | * @param whereArgs 19 | * @return 20 | */ 21 | public static long[] getAffectedRows(SQLiteDatabase db, String table, 22 | String whereClause, String[] whereArgs) { 23 | if (TextUtils.isEmpty(whereClause)) { 24 | return null; 25 | } 26 | 27 | Cursor c = db.query(table, new String[]{BaseColumns._ID}, 28 | whereClause, whereArgs, null, null, null); 29 | long[] affectedRows = null; 30 | if (c != null) { 31 | affectedRows = new long[c.getCount()]; 32 | for (int i = 0; c.moveToNext(); i++) { 33 | affectedRows[i] = c.getLong(0); 34 | } 35 | } 36 | c.close(); 37 | return affectedRows; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /ShoppingList/src/main/java/org/openintents/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 21 | 22 | 23 | 24 | Basic package of OpenIntents applications. 25 | 26 |29 | The provider packages contain all definitions required to access the OpenIntents 30 | ContentProviders from other applications. 31 |
32 | 33 |34 | Convenience methods allow for an even easier access to frequently needed data. 35 |
36 | 37 |13 | * If the signature is changed make sure that the corresponding implementations are changed 14 | * because Android Studio does only show usage for the current build flavor. 15 | */ 16 | public class BaseOptionalDependencies { 17 | 18 | public void onResumeShoppingActivity(Activity context) { 19 | // do nothing; 20 | } 21 | 22 | public ToggleBoughtInputMethod getToggleBoughtInputMethod(Context context, ShoppingItemsView itemsView) { 23 | return null; 24 | } 25 | 26 | public SyncSupport getSyncSupport(final Context context) { 27 | return new NoSyncSupport(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ShoppingList/src/main/java/org/openintents/shopping/LogConstants.java: -------------------------------------------------------------------------------- 1 | package org.openintents.shopping; 2 | 3 | public class LogConstants { 4 | public final static String TAG = "Shopping"; 5 | public final static boolean debug = false; 6 | } 7 | -------------------------------------------------------------------------------- /ShoppingList/src/main/java/org/openintents/shopping/ShoppingActivity.java: -------------------------------------------------------------------------------- 1 | package org.openintents.shopping; 2 | 3 | /** 4 | * The main activity prior to version 1.4 was ".ShoppingActivity". Home screens 5 | * may still contain a direct link to the old activity, therefore this class 6 | * must never be renamed or moved. 7 | *
8 | * This class is derived from .ui.ShoppingActivity which contains the actual 9 | * implementation. 10 | * 11 | * This solution is used instead of using an activity-alias in the Manifest, 12 | * because the activity-alias does not respect the 13 | * android:windowSoftInputMode="stateHidden|adjustResize" setting. 14 | */ 15 | public class ShoppingActivity extends 16 | org.openintents.shopping.ui.ShoppingActivity { 17 | 18 | /** 19 | * For the implementation, see .ui.ShoppingActivity. 20 | */ 21 | } 22 | -------------------------------------------------------------------------------- /ShoppingList/src/main/java/org/openintents/shopping/ShoppingApplication.java: -------------------------------------------------------------------------------- 1 | package org.openintents.shopping; 2 | 3 | import android.app.Application; 4 | 5 | public class ShoppingApplication extends Application { 6 | public OptionalDependencies dependencies() { 7 | return new OptionalDependencies(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /ShoppingList/src/main/java/org/openintents/shopping/ShoppingBackupAgent.java: -------------------------------------------------------------------------------- 1 | package org.openintents.shopping; 2 | 3 | import android.app.backup.BackupAgentHelper; 4 | import android.app.backup.BackupDataInput; 5 | import android.app.backup.BackupDataOutput; 6 | import android.app.backup.FileBackupHelper; 7 | import android.app.backup.SharedPreferencesBackupHelper; 8 | import android.os.ParcelFileDescriptor; 9 | import android.util.Log; 10 | 11 | import org.openintents.shopping.provider.ShoppingDatabase; 12 | 13 | import java.io.IOException; 14 | 15 | public class ShoppingBackupAgent extends BackupAgentHelper { 16 | private static final String TAG = "ShoppingBackupAgent"; 17 | private static final boolean debug = false || LogConstants.debug; 18 | 19 | // The name of the SharedPreferences file 20 | private static final String PREFS = "org.openintents.shopping_preferences"; 21 | 22 | // A key to uniquely identify the set of backup data 23 | private static final String PREFS_BACKUP_KEY = "prefs"; 24 | 25 | private static final String DB_BACKUP_KEY = "db"; 26 | 27 | // Allocate a helper and add it to the backup agent 28 | public void onCreate() { 29 | if (debug) { 30 | Log.v(TAG, "onCreate"); 31 | } 32 | SharedPreferencesBackupHelper prefsHelper = new SharedPreferencesBackupHelper( 33 | this.getApplicationContext(), PREFS); 34 | addHelper(PREFS_BACKUP_KEY, prefsHelper); 35 | 36 | FileBackupHelper helper = new FileBackupHelper(this, "../databases/" 37 | + ShoppingDatabase.DATABASE_NAME); 38 | addHelper(DB_BACKUP_KEY, helper); 39 | } 40 | 41 | @Override 42 | public void onRestore(BackupDataInput data, int appVersionCode, 43 | ParcelFileDescriptor newState) throws IOException { 44 | if (debug) { 45 | Log.v(TAG, "onRestore"); 46 | } 47 | super.onRestore(data, appVersionCode, newState); 48 | } 49 | 50 | @Override 51 | public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data, 52 | ParcelFileDescriptor newState) throws IOException { 53 | if (debug) { 54 | Log.v(TAG, "onBackup"); 55 | } 56 | super.onBackup(oldState, data, newState); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /ShoppingList/src/main/java/org/openintents/shopping/automation/AutomationActions.java: -------------------------------------------------------------------------------- 1 | package org.openintents.shopping.automation; 2 | 3 | import android.content.ContentValues; 4 | import android.content.Context; 5 | import android.net.Uri; 6 | 7 | import org.openintents.shopping.library.provider.ShoppingContract; 8 | import org.openintents.shopping.library.provider.ShoppingContract.Contains; 9 | import org.openintents.shopping.library.provider.ShoppingContract.Status; 10 | 11 | public class AutomationActions { 12 | 13 | public static void cleanUpList(Context context, Uri uri) { 14 | 15 | if (uri != null) { 16 | long id = Integer.parseInt(uri.getLastPathSegment()); 17 | 18 | // by changing state 19 | ContentValues values = new ContentValues(); 20 | values.put(Contains.STATUS, Status.REMOVED_FROM_LIST); 21 | context.getContentResolver().update( 22 | Contains.CONTENT_URI, 23 | values, 24 | ShoppingContract.Contains.LIST_ID + " = " + id + " AND " 25 | + ShoppingContract.Contains.STATUS + " = " 26 | + ShoppingContract.Status.BOUGHT, null 27 | ); 28 | } 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /ShoppingList/src/main/java/org/openintents/shopping/automation/AutomationReceiver.java: -------------------------------------------------------------------------------- 1 | package org.openintents.shopping.automation; 2 | 3 | import android.content.BroadcastReceiver; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.net.Uri; 7 | import android.util.Log; 8 | 9 | import org.openintents.intents.ShoppingListIntents; 10 | import org.openintents.shopping.LogConstants; 11 | 12 | public class AutomationReceiver extends BroadcastReceiver { 13 | 14 | private final static String TAG = "AutomationReceiver"; 15 | private final static boolean debug = false || LogConstants.debug; 16 | 17 | @Override 18 | public void onReceive(Context context, Intent intent) { 19 | if (debug) { 20 | Log.i(TAG, "Receive intent: " + intent.toString()); 21 | } 22 | 23 | final String action = intent 24 | .getStringExtra(ShoppingListIntents.EXTRA_ACTION); 25 | final String dataString = intent 26 | .getStringExtra(ShoppingListIntents.EXTRA_DATA); 27 | Uri data = null; 28 | if (dataString != null) { 29 | data = Uri.parse(dataString); 30 | } 31 | if (debug) { 32 | Log.i(TAG, "action: " + action + ", data: " + dataString); 33 | } 34 | 35 | if (ShoppingListIntents.TASK_CLEAN_UP_LIST.equals(action)) { 36 | // Clean up list. 37 | if (data != null) { 38 | if (debug) { 39 | Log.i(TAG, "Clean up list " + data); 40 | } 41 | AutomationActions.cleanUpList(context, data); 42 | } 43 | } 44 | 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /ShoppingList/src/main/java/org/openintents/shopping/sync/NoSyncSupport.java: -------------------------------------------------------------------------------- 1 | package org.openintents.shopping.sync; 2 | 3 | import android.content.ContentValues; 4 | import android.database.Cursor; 5 | import android.net.Uri; 6 | 7 | import org.openintents.shopping.SyncSupport; 8 | 9 | public class NoSyncSupport implements SyncSupport { 10 | @Override 11 | public boolean isAvailable() { 12 | return false; 13 | } 14 | 15 | @Override 16 | public void pushListItem(long listId, Cursor cursor) { 17 | 18 | } 19 | 20 | @Override 21 | public void pushList(Cursor cursor) { 22 | 23 | } 24 | 25 | @Override 26 | public boolean isSyncEnabled() { 27 | return false; 28 | } 29 | 30 | @Override 31 | public void setSyncEnabled(boolean enableSync) { 32 | 33 | } 34 | 35 | @Override 36 | public void updateListItem(long listId, Uri itemUri, ContentValues values) { 37 | 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /ShoppingList/src/main/java/org/openintents/shopping/theme/ThemeShoppingList.java: -------------------------------------------------------------------------------- 1 | package org.openintents.shopping.theme; 2 | 3 | public class ThemeShoppingList { 4 | 5 | // For Shopping list theme 6 | // (move to separate class eventually) 7 | 8 | public static final String SHOPPING_LIST_THEME = "org.openintents.shoppinglist"; 9 | 10 | public static final String background = "background"; 11 | public static final String backgroundPadding = "backgroundPadding"; 12 | public static final String backgroundPaddingLeft = "backgroundPaddingLeft"; 13 | public static final String backgroundPaddingTop = "backgroundPaddingTop"; 14 | public static final String backgroundPaddingRight = "backgroundPaddingRight"; 15 | public static final String backgroundPaddingBottom = "backgroundPaddingBottom"; 16 | public static final String divider = "divider"; 17 | public static final String shopping_divider = "shopping_divider"; 18 | public static final String textTypeface = "textTypeface"; 19 | public static final String textUpperCaseFont = "textUpperCaseFont"; 20 | public static final String textSizeTiny = "textSizeTiny"; 21 | public static final String textSizeSmall = "textSizeSmall"; 22 | public static final String textSizeMedium = "textSizeMedium"; 23 | public static final String textSizeLarge = "textSizeLarge"; 24 | public static final String textColor = "textColor"; 25 | public static final String textColorPrice = "textColorPrice"; 26 | public static final String textColorChecked = "textColorChecked"; 27 | public static final String textColorPriority = "textColorPriority"; 28 | public static final String textStrikethroughChecked = "textStrikethroughChecked"; 29 | public static final String textSuffixUnchecked = "textSuffixUnchecked"; 30 | public static final String textSuffixChecked = "textSuffixChecked"; 31 | public static final String showCheckBox = "showCheckBox"; 32 | 33 | public static final String lineMode = "lineMode"; 34 | public static final String lineColor = "lineColor"; 35 | } 36 | -------------------------------------------------------------------------------- /ShoppingList/src/main/java/org/openintents/shopping/ui/PickItemsActivity.java: -------------------------------------------------------------------------------- 1 | package org.openintents.shopping.ui; 2 | 3 | import android.app.Activity; 4 | import android.os.Build; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | import android.widget.Button; 8 | 9 | import org.openintents.shopping.R; 10 | import org.openintents.shopping.ui.widget.ShoppingItemsView; 11 | 12 | public class PickItemsActivity extends Activity { 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | 17 | super.onCreate(savedInstanceState); 18 | 19 | setContentView(R.layout.activity_pick_items); 20 | 21 | final ShoppingItemsView listItems = (ShoppingItemsView) findViewById(R.id.list_items); 22 | listItems.setPickItemsDlgMode(); 23 | 24 | String listId = getIntent().getData().getLastPathSegment(); 25 | listItems.fillItems(this, Long.parseLong(listId)); 26 | // mListItems.setListTheme(ShoppingListView.MARK_CHECKBOX); 27 | listItems.setListTheme("1"); 28 | // mListItems.setOnItemClickListener(new OnItemClickListener() { 29 | 30 | // 31 | // public void onItemClick(AdapterView parent, View v, int pos, long id) 32 | // { 33 | // mListItems.toggleItemRemovedFromList(pos); 34 | // v.invalidate(); 35 | // } 36 | 37 | // 38 | // }); 39 | 40 | } 41 | 42 | public void onButton1Click(View view) { 43 | finish(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /ShoppingList/src/main/java/org/openintents/shopping/ui/SnackbarUndoOperation.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * borrowed from AOSP UnifiedEmail app 3 | * 4 | * Copyright (C) 2011 Google Inc. 5 | * Licensed to The Android Open Source Project. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *******************************************************************************/ 19 | package org.openintents.shopping.ui; 20 | 21 | import android.content.Context; 22 | import android.view.View; 23 | 24 | /** 25 | * A simple holder class that stores the information to undo the application of a folder. 26 | */ 27 | public class SnackbarUndoOperation implements View.OnClickListener { 28 | public static final int UNDO = 0; 29 | public static final int ERROR = 1; 30 | protected final int mCount; 31 | protected final boolean mBatch; 32 | protected final int mType; 33 | 34 | /** 35 | * Create a SnackbarUndoOperation 36 | * 37 | * @param count Number of conversations this action would be applied to. 38 | * @param type type of action 39 | * @param batch whether it is a batch operation 40 | */ 41 | public SnackbarUndoOperation(int count, int type, boolean batch) { 42 | mCount = count; 43 | mBatch = batch; 44 | mType = type; 45 | } 46 | 47 | public int getType() { 48 | return mType; 49 | } 50 | 51 | public boolean isBatchUndo() { 52 | return mBatch; 53 | } 54 | 55 | /** 56 | * Get a string description of the operation that will be performed 57 | * when the user taps the undo bar. 58 | */ 59 | public String getDescription(Context context) { 60 | final int resId = -1; 61 | 62 | return (resId == -1) ? "" : 63 | String.format(context.getResources().getQuantityString(resId, mCount), mCount); 64 | } 65 | 66 | public String getSingularDescription(Context context) { 67 | final int resId = -1; 68 | return (resId == -1) ? "" : context.getString(resId); 69 | } 70 | 71 | @Override 72 | public void onClick(View view) { 73 | 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /ShoppingList/src/main/java/org/openintents/shopping/ui/ToggleBoughtInputMethod.java: -------------------------------------------------------------------------------- 1 | package org.openintents.shopping.ui; 2 | 3 | 4 | public interface ToggleBoughtInputMethod { 5 | public void release(); 6 | } 7 | -------------------------------------------------------------------------------- /ShoppingList/src/main/java/org/openintents/shopping/ui/UndoListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Google Inc. 3 | * Licensed to The Android Open Source Project. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.openintents.shopping.ui; 19 | 20 | /** 21 | * Classes that can undo an operation should implement this interface. 22 | */ 23 | public interface UndoListener { 24 | public void onUndoAvailable(SnackbarUndoOperation undoOp); 25 | } 26 | -------------------------------------------------------------------------------- /ShoppingList/src/main/java/org/openintents/shopping/ui/dialog/DialogActionListener.java: -------------------------------------------------------------------------------- 1 | package org.openintents.shopping.ui.dialog; 2 | 3 | public interface DialogActionListener { 4 | 5 | public void onAction(String name); 6 | } 7 | -------------------------------------------------------------------------------- /ShoppingList/src/main/java/org/openintents/shopping/ui/dialog/NewListDialog.java: -------------------------------------------------------------------------------- 1 | package org.openintents.shopping.ui.dialog; 2 | 3 | import android.content.Context; 4 | 5 | import org.openintents.shopping.R; 6 | 7 | public class NewListDialog extends RenameListDialog { 8 | 9 | public NewListDialog(Context context) { 10 | super(context); 11 | 12 | setTitle(R.string.ask_new_list); 13 | } 14 | 15 | public NewListDialog(Context context, DialogActionListener listener) { 16 | super(context); 17 | 18 | setTitle(R.string.ask_new_list); 19 | setDialogActionListener(listener); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /ShoppingList/src/main/java/org/openintents/shopping/ui/dialog/RenameListDialog.java: -------------------------------------------------------------------------------- 1 | package org.openintents.shopping.ui.dialog; 2 | 3 | import android.app.AlertDialog; 4 | import android.content.Context; 5 | import android.content.DialogInterface; 6 | import android.content.DialogInterface.OnClickListener; 7 | import android.text.method.KeyListener; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.widget.EditText; 11 | 12 | import org.openintents.shopping.R; 13 | import org.openintents.shopping.ui.PreferenceActivity; 14 | 15 | public class RenameListDialog extends AlertDialog implements OnClickListener { 16 | 17 | protected EditText mEditText; 18 | private Context mContext; 19 | private DialogActionListener mDialogActionListener; 20 | 21 | public RenameListDialog(Context context) { 22 | super(context); 23 | mContext = context; 24 | init(); 25 | } 26 | 27 | public RenameListDialog(Context context, String name, 28 | DialogActionListener listener) { 29 | super(context); 30 | mContext = context; 31 | init(); 32 | setName(name); 33 | setDialogActionListener(listener); 34 | } 35 | 36 | /** 37 | * @param context 38 | */ 39 | private void init() { 40 | LayoutInflater inflater = LayoutInflater.from(mContext); 41 | final View view = inflater.inflate(R.layout.dialog_rename_list, null); 42 | setView(view); 43 | 44 | mEditText = (EditText) view.findViewById(R.id.edittext); 45 | 46 | KeyListener kl = PreferenceActivity 47 | .getCapitalizationKeyListenerFromPrefs(mContext); 48 | mEditText.setKeyListener(kl); 49 | 50 | setIcon(android.R.drawable.ic_menu_edit); 51 | setTitle(R.string.ask_rename_list); 52 | 53 | setButton(mContext.getText(R.string.ok), this); 54 | setButton2(mContext.getText(R.string.cancel), this); 55 | } 56 | 57 | public void setName(String name) { 58 | mEditText.setText(name); 59 | 60 | // To move cursor position to the end of list's name 61 | mEditText.setSelection(name.length()); 62 | } 63 | 64 | public void setDialogActionListener(DialogActionListener listener) { 65 | mDialogActionListener = listener; 66 | } 67 | 68 | public void onClick(DialogInterface dialog, int which) { 69 | if (which == BUTTON1) { 70 | pressOk(); 71 | } 72 | 73 | } 74 | 75 | public void pressOk() { 76 | String name = mEditText.getText().toString(); 77 | mDialogActionListener.onAction(name); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /ShoppingList/src/main/java/org/openintents/shopping/ui/widget/QuickSelectMenu.java: -------------------------------------------------------------------------------- 1 | package org.openintents.shopping.ui.widget; 2 | 3 | import android.content.Context; 4 | import android.view.Menu; 5 | import android.view.MenuItem; 6 | import android.view.View; 7 | 8 | /* This class exposes a subset of PopupMenu functionality, and chooses whether 9 | * to use the platform PopupMenu (on Honeycomb or above) or a backported version. 10 | */ 11 | public class QuickSelectMenu { 12 | 13 | private android.support.v7.widget.PopupMenu mImplPlatform; 14 | 15 | private OnItemSelectedListener mItemSelectedListener; 16 | 17 | public QuickSelectMenu(Context context, View anchor) { 18 | mImplPlatform = new android.support.v7.widget.PopupMenu(context, anchor); 19 | mImplPlatform 20 | .setOnMenuItemClickListener(new android.support.v7.widget.PopupMenu.OnMenuItemClickListener() { 21 | @Override 22 | public boolean onMenuItemClick(MenuItem item) { 23 | return onMenuItemClickImpl(item); 24 | } 25 | }); 26 | } 27 | 28 | // not sure if we want to expose this or just an add() method. 29 | public Menu getMenu() { 30 | return mImplPlatform.getMenu(); 31 | } 32 | 33 | public void setOnItemSelectedListener(OnItemSelectedListener listener) { 34 | mItemSelectedListener = listener; 35 | } 36 | 37 | public void show() { 38 | mImplPlatform.show(); 39 | } 40 | 41 | public boolean onMenuItemClickImpl(MenuItem item) { 42 | CharSequence name = item.getTitle(); 43 | int id = item.getItemId(); 44 | this.mItemSelectedListener.onItemSelected(name, id); 45 | return true; 46 | } 47 | 48 | // popup.setOnMenuItemClickListener(new 49 | // android.widget.PopupMenu.OnMenuItemClickListener() { 50 | 51 | /** 52 | * Interface responsible for receiving menu item click events if the items 53 | * themselves do not have individual item click listeners. 54 | */ 55 | public interface OnItemSelectedListener { 56 | /** 57 | * This method will be invoked when an item is selected. 58 | * 59 | * @param item {@link CharSequence} that was selected 60 | * @param id 61 | */ 62 | public void onItemSelected(CharSequence item, int id); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /ShoppingList/src/main/java/org/openintents/util/BackupManagerWrapper.java: -------------------------------------------------------------------------------- 1 | package org.openintents.util; 2 | 3 | import android.app.backup.BackupManager; 4 | import android.content.Context; 5 | 6 | public class BackupManagerWrapper { 7 | /* class initialization fails when this throws an exception */ 8 | static { 9 | try { 10 | Class.forName("android.app.backup.BackupManager"); 11 | } catch (Exception ex) { 12 | throw new RuntimeException(ex); 13 | } 14 | } 15 | 16 | private BackupManager mInstance; 17 | 18 | public BackupManagerWrapper(Context ctx) { 19 | mInstance = new BackupManager(ctx); 20 | 21 | } 22 | 23 | /* calling here forces class initialization */ 24 | public static void checkAvailable() { 25 | } 26 | 27 | public void dataChanged() { 28 | mInstance.dataChanged(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ShoppingList/src/main/java/org/openintents/util/MenuIntentOptionsWithIcons.java: -------------------------------------------------------------------------------- 1 | package org.openintents.util; 2 | 3 | import android.content.ComponentName; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.content.pm.PackageManager; 7 | import android.content.pm.ResolveInfo; 8 | import android.view.Menu; 9 | import android.view.MenuItem; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * Adds intent options with icons. 15 | * 16 | * This code is retrieved from this message: 17 | * http://groups.google.com/group/android 18 | * -developers/browse_frm/thread/3fed25cdda765b02 19 | */ 20 | public class MenuIntentOptionsWithIcons { 21 | 22 | private Context mContext; 23 | private Menu mMenu; 24 | 25 | public MenuIntentOptionsWithIcons(Context context, Menu menu) { 26 | mContext = context; 27 | mMenu = menu; 28 | } 29 | 30 | public int addIntentOptions(int group, int id, int categoryOrder, 31 | ComponentName caller, Intent[] specifics, Intent intent, int flags, 32 | MenuItem[] outSpecificItems) { 33 | PackageManager pm = mContext.getPackageManager(); 34 | final List