@Override protected void onListItemClick(ListView l, View v, int position, long id) { Uri uri = ContentUris.withAppendedId(getIntent().getData(), id); String action = getIntent().getAction(); if (Intent.ACTION_PICK.equals(action) || Intent.ACTION_GET_CONTENT.equals(action)) { // The caller is waiting for us to return a record selected by // the user. The have clicked on one, so return it now. setResult(RESULT_OK, new Intent().setData(uri)); } else { // Launch activity to view/edit the currently selected item startActivity(new Intent(Intent.ACTION_EDIT, uri)); } }
/// @} private void buildDefaultState() { mState = new State(); final Intent intent = getIntent(); final String action = intent.getAction(); if (Intent.ACTION_OPEN_DOCUMENT.equals(action)) { mState.action = ACTION_OPEN; } else if (Intent.ACTION_CREATE_DOCUMENT.equals(action)) { mState.action = ACTION_CREATE; } else if (Intent.ACTION_GET_CONTENT.equals(action)) { mState.action = ACTION_GET_CONTENT; } else if (Intent.ACTION_OPEN_DOCUMENT_TREE.equals(action)) { mState.action = ACTION_OPEN_TREE; } else if (DocumentsContract.ACTION_MANAGE_ROOT.equals(action)) { mState.action = ACTION_MANAGE; } if (mState.action == ACTION_OPEN || mState.action == ACTION_GET_CONTENT) { mState.allowMultiple = intent.getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE, false); } if (mState.action == ACTION_MANAGE) { mState.acceptMimes = new String[] {"*/*"}; mState.allowMultiple = true; } else if (intent.hasExtra(Intent.EXTRA_MIME_TYPES)) { mState.acceptMimes = intent.getStringArrayExtra(Intent.EXTRA_MIME_TYPES); } else { mState.acceptMimes = new String[] {intent.getType()}; } mState.localOnly = intent.getBooleanExtra(Intent.EXTRA_LOCAL_ONLY, false); mState.forceAdvanced = intent.getBooleanExtra(DocumentsContract.EXTRA_SHOW_ADVANCED, false); mState.showAdvanced = mState.forceAdvanced | LocalPreferences.getDisplayAdvancedDevices(this); if (mState.action == ACTION_MANAGE) { mState.showSize = true; } else { mState.showSize = LocalPreferences.getDisplayFileSize(this); } }
/** * This method is called when the user clicks a note in the displayed list. * * <p>This method handles incoming actions of either PICK (get data from the provider) or * GET_CONTENT (get or create data). If the incoming action is EDIT, this method sends a new * Intent to start NoteEditor. * * @param l The ListView that contains the clicked item * @param v The View of the individual item * @param position The position of v in the displayed list * @param id The row ID of the clicked item */ @Override protected void OnListItemClick(ListView l, View v, int position, long id) { // Constructs a new URI from the incoming URI and the row ID Uri uri = ContentUris.withAppendedId(getIntent().getData(), id); // Gets the action from the incoming Intent String action = getIntent().getAction(); // Handles requests for note data if (Intent.ACTION_PICK.equals(action) || Intent.ACTION_GET_CONTENT.equals(action)) { // Sets the result to return to the component that called this Activity. The // result contains the new URI setResult(RESULT_OK, new Intent().setData(uri)); } else { // Sends out an Intent to start an Activity that can handle ACTION_EDIT. The // Intent's data is the note ID URI. The effect is to call NoteEdit. StartActivity(new Intent(Intent.ACTION_EDIT, uri)); } }
@Override void executeOnUiThread(MessageContextMenu menu, MessageEditorData editorData) { Uri uri = MatchedUri.getTimelineItemUri( editorData.ma.getUserId(), menu.messageList.getTimelineType(), menu.messageList.isTimelineCombined(), menu.messageList.getSelectedUserId(), menu.getMsgId()); String action = menu.messageList.getActivity().getIntent().getAction(); if (Intent.ACTION_PICK.equals(action) || Intent.ACTION_GET_CONTENT.equals(action)) { if (MyLog.isLoggable(this, MyLog.DEBUG)) { MyLog.d(this, "onItemClick, setData=" + uri); } menu.messageList.getActivity().setResult(Activity.RESULT_OK, new Intent().setData(uri)); } else { if (MyLog.isLoggable(this, MyLog.DEBUG)) { MyLog.d(this, "onItemClick, startActivity=" + uri); } menu.messageList.getActivity().startActivity(MyAction.VIEW_CONVERSATION.getIntent(uri)); } }
/** * Called when the activity is first created. * * @param icicle */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); /// M: set the music style Audio. setVolumeControlStream(AudioManager.STREAM_MUSIC); int sortMode = TRACK_MENU; if (icicle == null) { mSelectedUri = getIntent().getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI); /// M: Retrieve the Drmlevel from intent @{ mDrmLevel = getIntent().getIntExtra(OmaDrmStore.DrmExtra.EXTRA_DRM_LEVEL, -1); MusicLogUtils.d(TAG, "onCreate: drmlevel=" + mDrmLevel); /// @} } else { mSelectedUri = (Uri) icicle.getParcelable(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI); // Retrieve list state. This will be applied after the // QueryHandler has run. mListState = icicle.getParcelable(LIST_STATE_KEY); mListHasFocus = icicle.getBoolean(FOCUS_KEY); sortMode = icicle.getInt(SORT_MODE_KEY, sortMode); /// M: Returns the value associated with the given key(SELECTED_POS|DRM_LEVEL), or // defaultValue // if no mapping of the desired type exists for the given key. @{ mPrevSelectedPos = icicle.getInt(SELECTED_POS, -1); mDrmLevel = icicle.getInt(DRM_LEVEL, -1); MusicLogUtils.d( TAG, "onCreate: drmlevel(restored) = " + mDrmLevel + ", mSelectedUri = " + mSelectedUri); /// @} } if (Intent.ACTION_GET_CONTENT.equals(getIntent().getAction())) { mBaseUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; } else { mBaseUri = getIntent().getData(); if (mBaseUri == null) { MusicLogUtils.w(TAG, "No data URI given to PICK action"); finish(); return; } } setContentView(R.layout.music_picker); /// M: Creates a DrmManagerClient. if (MusicFeatureOption.IS_SUPPORT_DRM) { mDrmClient = new OmaDrmClient(this); } /// M: add for chinese sorting mSortOrder = MediaStore.Audio.Media.TITLE_PINYIN_KEY; final ListView listView = getListView(); listView.setItemsCanFocus(false); mAdapter = new TrackListAdapter( this, listView, R.layout.music_picker_item, new String[] {}, new int[] {}); setListAdapter(mAdapter); listView.setTextFilterEnabled(true); // We manually save/restore the listview state listView.setSaveEnabled(false); mQueryHandler = new QueryHandler(this); // mProgressContainer = findViewById(R.id.progressContainer); // mListContainer = findViewById(R.id.listContainer); mOkayButton = findViewById(R.id.okayButton); mOkayButton.setOnClickListener(this); /// M: Only when user select a audio we need set ok button enable. mOkayButton.setEnabled(false); mCancelButton = findViewById(R.id.cancelButton); mCancelButton.setOnClickListener(this); // If there is a currently selected Uri, then try to determine who // it is. if (mSelectedUri != null) { Uri.Builder builder = mSelectedUri.buildUpon(); String path = mSelectedUri.getEncodedPath(); int idx = path.lastIndexOf('/'); if (idx >= 0) { path = path.substring(0, idx); } builder.encodedPath(path); Uri baseSelectedUri = builder.build(); MusicLogUtils.v(TAG, "Selected Uri: " + mSelectedUri); MusicLogUtils.v(TAG, "Selected base Uri: " + baseSelectedUri); MusicLogUtils.v(TAG, "Base Uri: " + mBaseUri); if (baseSelectedUri.equals(mBaseUri)) { // If the base Uri of the selected Uri is the same as our // content's base Uri, then use the selection! mSelectedId = ContentUris.parseId(mSelectedUri); } } /// M: add IntentFilter action and register a Listener for SD card status changed @{ IntentFilter f = new IntentFilter(); f.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED); f.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED); f.addAction(Intent.ACTION_MEDIA_UNMOUNTED); f.addAction(Intent.ACTION_MEDIA_MOUNTED); f.addDataScheme("file"); registerReceiver(mScanListener, f); /// @} mIsBroadcastReg = true; setSortMode(sortMode); }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setVolumeControlStream(AudioManager.STREAM_MUSIC); int sortMode = TRACK_MENU; if (icicle == null) { mSelectedUri = getIntent().getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI); mDrmLevel = getIntent().getIntExtra(DrmStore.DrmExtra.EXTRA_DRM_LEVEL, -1); MusicLogUtils.d(TAG, "onCreate: drmlevel=" + mDrmLevel); } else { mSelectedUri = (Uri) icicle.getParcelable(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI); // Retrieve list state. This will be applied after the // QueryHandler has run mListState = icicle.getParcelable(LIST_STATE_KEY); mListHasFocus = icicle.getBoolean(FOCUS_KEY); sortMode = icicle.getInt(SORT_MODE_KEY, sortMode); mPrevSelectedPos = icicle.getInt(SELECTED_POS, -1); mDrmLevel = icicle.getInt(DRM_LEVEL, -1); MusicLogUtils.d(TAG, "onCreate: drmlevel(restored)=" + mDrmLevel); } if (Intent.ACTION_GET_CONTENT.equals(getIntent().getAction())) { mBaseUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; } else { mBaseUri = getIntent().getData(); if (mBaseUri == null) { MusicLogUtils.w(TAG, "No data URI given to PICK action"); finish(); return; } } setContentView(R.layout.music_picker); LinearLayout mainLayout = (LinearLayout) findViewById(R.id.mainLayout); /* if (FeatureOption.MTK_THEMEMANAGER_APP) { mainLayout.setThemeContentBgColor(0xff000000); } */ mSortOrder = MediaStore.Audio.Media.TITLE_KEY; if (FeatureOption.MTK_DRM_APP) { mDrmClient = new DrmManagerClient(this); } final ListView listView = getListView(); listView.setItemsCanFocus(false); mAdapter = new TrackListAdapter( this, listView, R.layout.music_picker_item, new String[] {}, new int[] {}); setListAdapter(mAdapter); listView.setTextFilterEnabled(true); // We manually save/restore the listview state listView.setSaveEnabled(false); mQueryHandler = new QueryHandler(this); mProgressContainer = findViewById(R.id.progressContainer); mListContainer = findViewById(R.id.listContainer); mOkayButton = findViewById(R.id.okayButton); mOkayButton.setOnClickListener(this); mCancelButton = findViewById(R.id.cancelButton); mCancelButton.setOnClickListener(this); // If there is a currently selected Uri, then try to determine who // it is. if (mSelectedUri != null) { Uri.Builder builder = mSelectedUri.buildUpon(); String path = mSelectedUri.getEncodedPath(); int idx = path.lastIndexOf('/'); if (idx >= 0) { path = path.substring(0, idx); } builder.encodedPath(path); Uri baseSelectedUri = builder.build(); MusicLogUtils.v(TAG, "Selected Uri: " + mSelectedUri); MusicLogUtils.v(TAG, "Selected base Uri: " + baseSelectedUri); MusicLogUtils.v(TAG, "Base Uri: " + mBaseUri); if (baseSelectedUri.equals(mBaseUri)) { // If the base Uri of the selected Uri is the same as our // content's base Uri, then use the selection! mSelectedId = ContentUris.parseId(mSelectedUri); } } setSortMode(sortMode); }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); int sortMode = TRACK_MENU; if (icicle == null) { mSelectedUri = getIntent().getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI); } else { mSelectedUri = (Uri) icicle.getParcelable(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI); // Retrieve list state. This will be applied after the // QueryHandler has run mListState = icicle.getParcelable(LIST_STATE_KEY); mListHasFocus = icicle.getBoolean(FOCUS_KEY); sortMode = icicle.getInt(SORT_MODE_KEY, sortMode); } if (Intent.ACTION_GET_CONTENT.equals(getIntent().getAction())) { mBaseUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; } else { mBaseUri = getIntent().getData(); if (mBaseUri == null) { Log.w("MusicPicker", "No data URI given to PICK action"); finish(); return; } } setContentView(R.layout.music_picker); if (android.os.Environment.getExternalStorageState() .equals(android.os.Environment.MEDIA_REMOVED) || android.os.Environment.getExternalStorageState() .equals(android.os.Environment.MEDIA_UNMOUNTED)) { Toast.makeText(this, getResources().getString(R.string.no_sd_card), Toast.LENGTH_LONG).show(); } mSortOrder = MediaStore.Audio.Media.TITLE_KEY; final ListView listView = getListView(); listView.setItemsCanFocus(false); mAdapter = new TrackListAdapter( this, listView, R.layout.music_picker_item, new String[] {}, new int[] {}); setListAdapter(mAdapter); listView.setTextFilterEnabled(true); // We manually save/restore the listview state listView.setSaveEnabled(false); mQueryHandler = new QueryHandler(this); mProgressContainer = findViewById(R.id.progressContainer); mListContainer = findViewById(R.id.listContainer); mOkayButton = findViewById(R.id.okayButton); mOkayButton.setOnClickListener(this); mCancelButton = findViewById(R.id.cancelButton); mCancelButton.setOnClickListener(this); // If there is a currently selected Uri, then try to determine who // it is. if (mSelectedUri != null) { Uri.Builder builder = mSelectedUri.buildUpon(); String path = mSelectedUri.getEncodedPath(); int idx = path.lastIndexOf('/'); if (idx >= 0) { path = path.substring(0, idx); } builder.encodedPath(path); Uri baseSelectedUri = builder.build(); if (DBG) Log.v(TAG, "Selected Uri: " + mSelectedUri); if (DBG) Log.v(TAG, "Selected base Uri: " + baseSelectedUri); if (DBG) Log.v(TAG, "Base Uri: " + mBaseUri); if (baseSelectedUri.equals(mBaseUri)) { // If the base Uri of the selected Uri is the same as our // content's base Uri, then use the selection! mSelectedId = ContentUris.parseId(mSelectedUri); } } setSortMode(sortMode); }
boolean isPickIntent() { String action = getIntent().getAction(); return (Intent.ACTION_PICK.equals(action) || Intent.ACTION_GET_CONTENT.equals(action)); }
public ContactsRequest resolveIntent(Intent intent) { ContactsRequest request = new ContactsRequest(); String action = intent.getAction(); Log.i(TAG, "Called with action: " + action); if (UI.LIST_DEFAULT.equals(action)) { request.setActionCode(ContactsRequest.ACTION_DEFAULT); } else if (UI.LIST_ALL_CONTACTS_ACTION.equals(action)) { request.setActionCode(ContactsRequest.ACTION_ALL_CONTACTS); } else if (UI.LIST_CONTACTS_WITH_PHONES_ACTION.equals(action)) { request.setActionCode(ContactsRequest.ACTION_CONTACTS_WITH_PHONES); } else if (UI.LIST_STARRED_ACTION.equals(action)) { request.setActionCode(ContactsRequest.ACTION_STARRED); } else if (UI.LIST_FREQUENT_ACTION.equals(action)) { request.setActionCode(ContactsRequest.ACTION_FREQUENT); } else if (UI.LIST_STREQUENT_ACTION.equals(action)) { request.setActionCode(ContactsRequest.ACTION_STREQUENT); } else if (UI.LIST_GROUP_ACTION.equals(action)) { request.setActionCode(ContactsRequest.ACTION_GROUP); // We no longer support UI.GROUP_NAME_EXTRA_KEY } else if (Intent.ACTION_PICK.equals(action)) { final String resolvedType = intent.resolveType(mContext); if (Contacts.CONTENT_TYPE.equals(resolvedType)) { request.setActionCode(ContactsRequest.ACTION_PICK_CONTACT); } else if (People.CONTENT_TYPE.equals(resolvedType)) { request.setActionCode(ContactsRequest.ACTION_PICK_CONTACT); request.setLegacyCompatibilityMode(true); } else if (Phone.CONTENT_TYPE.equals(resolvedType)) { request.setActionCode(ContactsRequest.ACTION_PICK_PHONE); } else if (Phones.CONTENT_TYPE.equals(resolvedType)) { request.setActionCode(ContactsRequest.ACTION_PICK_PHONE); request.setLegacyCompatibilityMode(true); } else if (StructuredPostal.CONTENT_TYPE.equals(resolvedType)) { request.setActionCode(ContactsRequest.ACTION_PICK_POSTAL); } else if (ContactMethods.CONTENT_POSTAL_TYPE.equals(resolvedType)) { request.setActionCode(ContactsRequest.ACTION_PICK_POSTAL); request.setLegacyCompatibilityMode(true); } else if (Email.CONTENT_TYPE.equals(resolvedType)) { request.setActionCode(ContactsRequest.ACTION_PICK_EMAIL); } } else if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) { String component = intent.getComponent().getClassName(); if (component.equals("alias.DialShortcut")) { request.setActionCode(ContactsRequest.ACTION_CREATE_SHORTCUT_CALL); } else if (component.equals("alias.MessageShortcut")) { request.setActionCode(ContactsRequest.ACTION_CREATE_SHORTCUT_SMS); } else { request.setActionCode(ContactsRequest.ACTION_CREATE_SHORTCUT_CONTACT); } } else if (Intent.ACTION_GET_CONTENT.equals(action)) { String type = intent.getType(); if (Contacts.CONTENT_ITEM_TYPE.equals(type)) { request.setActionCode(ContactsRequest.ACTION_PICK_OR_CREATE_CONTACT); } else if (Phone.CONTENT_ITEM_TYPE.equals(type)) { request.setActionCode(ContactsRequest.ACTION_PICK_PHONE); } else if (Phones.CONTENT_ITEM_TYPE.equals(type)) { request.setActionCode(ContactsRequest.ACTION_PICK_PHONE); request.setLegacyCompatibilityMode(true); } else if (StructuredPostal.CONTENT_ITEM_TYPE.equals(type)) { request.setActionCode(ContactsRequest.ACTION_PICK_POSTAL); } else if (ContactMethods.CONTENT_POSTAL_ITEM_TYPE.equals(type)) { request.setActionCode(ContactsRequest.ACTION_PICK_POSTAL); request.setLegacyCompatibilityMode(true); } else if (People.CONTENT_ITEM_TYPE.equals(type)) { request.setActionCode(ContactsRequest.ACTION_PICK_OR_CREATE_CONTACT); request.setLegacyCompatibilityMode(true); } } else if (Intent.ACTION_INSERT_OR_EDIT.equals(action)) { request.setActionCode(ContactsRequest.ACTION_INSERT_OR_EDIT_CONTACT); } else if (Intent.ACTION_SEARCH.equals(action)) { // See if the suggestion was clicked with a search action key (call button) if ("call".equals(intent.getStringExtra(SearchManager.ACTION_MSG))) { String query = intent.getStringExtra(SearchManager.QUERY); if (!TextUtils.isEmpty(query)) { Intent newIntent = new Intent(Intent.ACTION_CALL_PRIVILEGED, Uri.fromParts("tel", query, null)); request.setRedirectIntent(newIntent); } } else { request.setQueryString(intent.getStringExtra(SearchManager.QUERY)); request.setSearchMode(true); } } else if (Intent.ACTION_VIEW.equals(action)) { final String resolvedType = intent.resolveType(mContext); if (ContactsContract.Contacts.CONTENT_TYPE.equals(resolvedType) || android.provider.Contacts.People.CONTENT_TYPE.equals(resolvedType)) { request.setActionCode(ContactsRequest.ACTION_ALL_CONTACTS); } else { request.setActionCode(ContactsRequest.ACTION_VIEW_CONTACT); request.setContactUri(intent.getData()); intent.setAction(Intent.ACTION_DEFAULT); intent.setData(null); } } else if (UI.FILTER_CONTACTS_ACTION.equals(action)) { // When we get a FILTER_CONTACTS_ACTION, it represents search in the context // of some other action. Let's retrieve the original action to provide proper // context for the search queries. request.setActionCode(ContactsRequest.ACTION_DEFAULT); Bundle extras = intent.getExtras(); if (extras != null) { request.setQueryString(extras.getString(UI.FILTER_TEXT_EXTRA_KEY)); ContactsRequest originalRequest = (ContactsRequest) extras.get(ContactsSearchManager.ORIGINAL_REQUEST_KEY); if (originalRequest != null) { request.copyFrom(originalRequest); } } request.setSearchMode(true); // Since this is the filter activity it receives all intents // dispatched from the SearchManager for security reasons // so we need to re-dispatch from here to the intended target. } else if (Intents.SEARCH_SUGGESTION_CLICKED.equals(action)) { Uri data = intent.getData(); // See if the suggestion was clicked with a search action key (call button) if ("call".equals(intent.getStringExtra(SearchManager.ACTION_MSG))) { Intent newIntent = new Intent(mContext, CallContactActivity.class); newIntent.setData(data); request.setRedirectIntent(newIntent); } else { request.setActionCode(ContactsRequest.ACTION_VIEW_CONTACT); request.setContactUri(data); intent.setAction(Intent.ACTION_DEFAULT); intent.setData(null); } } else if (Intents.SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED.equals(action)) { request.setRedirectIntent(new Intent(Intent.ACTION_CALL_PRIVILEGED, intent.getData())); } else if (Intents.SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED.equals(action)) { // TODO actually support this in EditContactActivity. String number = intent.getData().getSchemeSpecificPart(); Intent newIntent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI); newIntent.putExtra(Intents.Insert.PHONE, number); request.setRedirectIntent(newIntent); } // Allow the title to be set to a custom String using an extra on the intent String title = intent.getStringExtra(UI.TITLE_EXTRA_KEY); if (title != null) { request.setActivityTitle(title); } return request; }