List of usage examples for android.content Intent getData
public @Nullable Uri getData()
From source file:com.kll.collect.android.activities.FormEntryActivity.java
/** Called when the activity is first created. */ @Override/*w ww . j a va2 s . c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // must be at the beginning of any activity that can be called from an // external intent try { Collect.createODKDirs(); } catch (RuntimeException e) { createErrorDialog(e.getMessage(), EXIT); return; } Log.i("Activity", "Created"); mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); mSharedPreferences .registerOnSharedPreferenceChangeListener(new SharedPreferences.OnSharedPreferenceChangeListener() { @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { compressImage = mSharedPreferences .getBoolean(PreferencesActivity.KEY_ENABLE_IMAGE_COMPRESSION, false); } }); setContentView(R.layout.form_entry); /* setTitle(getString(R.string.app_name) + " > " + getString(R.string.loading_form));*/ setTitle(getString(R.string.app_name)); Log.i("Entry", "Form"); mErrorMessage = null; //progressBar = (ProgressBar) findViewById(R.id.progress); //progressBar.setVisibility(ProgressBar.VISIBLE); //progressBar.setProgress(0); mBeenSwiped = false; mAlertDialog = null; mCurrentView = null; mInAnimation = null; mOutAnimation = null; mGestureDetector = new GestureDetector(this, this); mQuestionHolder = (LinearLayout) findViewById(R.id.questionholder); // get admin preference settings mAdminPreferences = getSharedPreferences(AdminPreferencesActivity.ADMIN_PREFERENCES, 0); mNextButton = (ImageButton) findViewById(R.id.form_forward_button); mNextButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mBeenSwiped = true; showNextView(); } }); mBackButton = (ImageButton) findViewById(R.id.form_back_button); mBackButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mBeenSwiped = true; showPreviousView(); } }); needLocation = mSharedPreferences.getBoolean(PreferencesActivity.KEY_GPS_FIX, false); if (needLocation) { mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 5, this); } // Load JavaRosa modules. needed to restore forms. new XFormsModule().registerModule(); // needed to override rms property manager org.javarosa.core.services.PropertyManager.setPropertyManager(new PropertyManager(getApplicationContext())); String startingXPath = null; String waitingXPath = null; String instancePath = null; Boolean newForm = true; if (savedInstanceState != null) { if (savedInstanceState.containsKey(KEY_FORMPATH)) { mFormPath = savedInstanceState.getString(KEY_FORMPATH); } if (savedInstanceState.containsKey(KEY_INSTANCEPATH)) { instancePath = savedInstanceState.getString(KEY_INSTANCEPATH); } if (savedInstanceState.containsKey(KEY_XPATH)) { startingXPath = savedInstanceState.getString(KEY_XPATH); Log.i(t, "startingXPath is: " + startingXPath); } if (savedInstanceState.containsKey(KEY_XPATH_WAITING_FOR_DATA)) { waitingXPath = savedInstanceState.getString(KEY_XPATH_WAITING_FOR_DATA); Log.i(t, "waitingXPath is: " + waitingXPath); } if (savedInstanceState.containsKey(NEWFORM)) { newForm = savedInstanceState.getBoolean(NEWFORM, true); } if (savedInstanceState.containsKey(KEY_ERROR)) { mErrorMessage = savedInstanceState.getString(KEY_ERROR); } } // If a parse error message is showing then nothing else is loaded // Dialogs mid form just disappear on rotation. if (mErrorMessage != null) { createErrorDialog(mErrorMessage, EXIT); return; } // Check to see if this is a screen flip or a new form load. Object data = getLastNonConfigurationInstance(); if (data instanceof FormLoaderTask) { mFormLoaderTask = (FormLoaderTask) data; } else if (data instanceof SaveToDiskTask) { mSaveToDiskTask = (SaveToDiskTask) data; } else if (data == null) { if (!newForm) { if (Collect.getInstance().getFormController() != null) { refreshCurrentView(); } else { Log.w(t, "Reloading form and restoring state."); // we need to launch the form loader to load the form // controller... mFormLoaderTask = new FormLoaderTask(instancePath, startingXPath, waitingXPath); Collect.getInstance().getActivityLogger().logAction(this, "formReloaded", mFormPath); // TODO: this doesn' work (dialog does not get removed): // showDialog(PROGRESS_DIALOG); // show dialog before we execute... Log.i("Loader", "Executing"); mFormLoaderTask.execute(mFormPath); } return; } // Not a restart from a screen orientation change (or other). Collect.getInstance().setFormController(null); CompatibilityUtils.invalidateOptionsMenu(this); Intent intent = getIntent(); if (intent != null) { Uri uri = intent.getData(); if (getContentResolver().getType(uri).equals(InstanceColumns.CONTENT_ITEM_TYPE)) { // get the formId and version for this instance... String jrFormId = null; String jrVersion = null; { Cursor instanceCursor = null; try { instanceCursor = getContentResolver().query(uri, null, null, null, null); if (instanceCursor.getCount() != 1) { this.createErrorDialog("Bad URI: " + uri, EXIT); return; } else { instanceCursor.moveToFirst(); instancePath = instanceCursor.getString( instanceCursor.getColumnIndex(InstanceColumns.INSTANCE_FILE_PATH)); Collect.getInstance().getActivityLogger().logAction(this, "instanceLoaded", instancePath); jrFormId = instanceCursor .getString(instanceCursor.getColumnIndex(InstanceColumns.JR_FORM_ID)); int idxJrVersion = instanceCursor.getColumnIndex(InstanceColumns.JR_VERSION); jrVersion = instanceCursor.isNull(idxJrVersion) ? null : instanceCursor.getString(idxJrVersion); } } finally { if (instanceCursor != null) { instanceCursor.close(); } } } String[] selectionArgs; String selection; if (jrVersion == null) { selectionArgs = new String[] { jrFormId }; selection = FormsColumns.JR_FORM_ID + "=? AND " + FormsColumns.JR_VERSION + " IS NULL"; } else { selectionArgs = new String[] { jrFormId, jrVersion }; selection = FormsColumns.JR_FORM_ID + "=? AND " + FormsColumns.JR_VERSION + "=?"; } { Cursor formCursor = null; try { formCursor = getContentResolver().query(FormsColumns.CONTENT_URI, null, selection, selectionArgs, null); if (formCursor.getCount() == 1) { formCursor.moveToFirst(); mFormPath = formCursor .getString(formCursor.getColumnIndex(FormsColumns.FORM_FILE_PATH)); } else if (formCursor.getCount() < 1) { this.createErrorDialog( getString(R.string.parent_form_not_present, jrFormId) + ((jrVersion == null) ? "" : "\n" + getString(R.string.version) + " " + jrVersion), EXIT); return; } else if (formCursor.getCount() > 1) { // still take the first entry, but warn that // there are multiple rows. // user will need to hand-edit the SQLite // database to fix it. formCursor.moveToFirst(); mFormPath = formCursor .getString(formCursor.getColumnIndex(FormsColumns.FORM_FILE_PATH)); this.createErrorDialog(getString(R.string.survey_multiple_forms_error), EXIT); return; } } finally { if (formCursor != null) { formCursor.close(); } } } } else if (getContentResolver().getType(uri).equals(FormsColumns.CONTENT_ITEM_TYPE)) { Cursor c = null; try { c = getContentResolver().query(uri, null, null, null, null); if (c.getCount() != 1) { this.createErrorDialog("Bad URI: " + uri, EXIT); return; } else { c.moveToFirst(); mFormPath = c.getString(c.getColumnIndex(FormsColumns.FORM_FILE_PATH)); // This is the fill-blank-form code path. // See if there is a savepoint for this form that // has never been // explicitly saved // by the user. If there is, open this savepoint // (resume this filled-in // form). // Savepoints for forms that were explicitly saved // will be recovered // when that // explicitly saved instance is edited via // edit-saved-form. final String filePrefix = mFormPath.substring(mFormPath.lastIndexOf('/') + 1, mFormPath.lastIndexOf('.')) + "_"; final String fileSuffix = ".xml.save"; File cacheDir = new File(Collect.CACHE_PATH); File[] files = cacheDir.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { String name = pathname.getName(); return name.startsWith(filePrefix) && name.endsWith(fileSuffix); } }); // see if any of these savepoints are for a // filled-in form that has never been // explicitly saved by the user... for (int i = 0; i < files.length; ++i) { File candidate = files[i]; String instanceDirName = candidate.getName().substring(0, candidate.getName().length() - fileSuffix.length()); File instanceDir = new File( Collect.INSTANCES_PATH + File.separator + instanceDirName); File instanceFile = new File(instanceDir, instanceDirName + ".xml"); if (instanceDir.exists() && instanceDir.isDirectory() && !instanceFile.exists()) { // yes! -- use this savepoint file instancePath = instanceFile.getAbsolutePath(); break; } } } } finally { if (c != null) { c.close(); } } } else { Log.e(t, "unrecognized URI"); this.createErrorDialog("Unrecognized URI: " + uri, EXIT); return; } mFormLoaderTask = new FormLoaderTask(instancePath, null, null); Collect.getInstance().getActivityLogger().logAction(this, "formLoaded", mFormPath); showDialog(PROGRESS_DIALOG); // show dialog before we execute... Log.i("Loader", "Executing"); mFormLoaderTask.execute(mFormPath); } } }
From source file:com.app.uafeed.activity.EditFeedActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { UiUtils.setPreferenceTheme(this); super.onCreate(savedInstanceState); getActionBar().setDisplayHomeAsUpEnabled(true); setContentView(R.layout.activity_feed_edit); setResult(RESULT_CANCELED);/* www .j ava 2s. c om*/ Intent intent = getIntent(); mTabHost = (TabHost) findViewById(R.id.tabHost); mNameEditText = (EditText) findViewById(R.id.feed_title); mUrlEditText = (EditText) findViewById(R.id.feed_url); mRetrieveFulltextCb = (CheckBox) findViewById(R.id.retrieve_fulltext); mFiltersListView = (ListView) findViewById(android.R.id.list); View tabWidget = findViewById(android.R.id.tabs); View buttonLayout = findViewById(R.id.button_layout); mTabHost.setup(); mTabHost.addTab(mTabHost.newTabSpec("feedTab").setIndicator(getString(R.string.tab_feed_title)) .setContent(R.id.feed_tab)); mTabHost.addTab(mTabHost.newTabSpec("filtersTab").setIndicator(getString(R.string.tab_filters_title)) .setContent(R.id.filters_tab)); mTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { @Override public void onTabChanged(String s) { invalidateOptionsMenu(); } }); if (savedInstanceState != null) { mTabHost.setCurrentTab(savedInstanceState.getInt(STATE_CURRENT_TAB)); } if (intent.getAction().equals(Intent.ACTION_INSERT) || intent.getAction().equals(Intent.ACTION_SEND)) { setTitle(R.string.new_feed_title); tabWidget.setVisibility(View.GONE); if (intent.hasExtra(Intent.EXTRA_TEXT)) { mUrlEditText.setText(intent.getStringExtra(Intent.EXTRA_TEXT)); } } else if (intent.getAction().equals(Intent.ACTION_EDIT)) { setTitle(R.string.edit_feed_title); buttonLayout.setVisibility(View.GONE); mFiltersCursorAdapter = new FiltersCursorAdapter(this, null); mFiltersListView.setAdapter(mFiltersCursorAdapter); mFiltersListView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { startActionMode(mFilterActionModeCallback); mFiltersCursorAdapter.setSelectedFilter(position); mFiltersListView.invalidateViews(); return true; } }); getLoaderManager().initLoader(0, null, this); if (savedInstanceState == null) { Cursor cursor = getContentResolver().query(intent.getData(), FEED_PROJECTION, null, null, null); if (cursor.moveToNext()) { mPreviousName = cursor.getString(0); mNameEditText.setText(mPreviousName); mUrlEditText.setText(cursor.getString(1)); mRetrieveFulltextCb.setChecked(cursor.getInt(2) == 1); cursor.close(); } else { cursor.close(); Toast.makeText(EditFeedActivity.this, R.string.error, Toast.LENGTH_SHORT).show(); finish(); } } } }
From source file:com.carlrice.reader.activity.EditFeedActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { UiUtils.setPreferenceTheme(this); super.onCreate(savedInstanceState); setContentView(R.layout.activity_feed_edit); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/*from www .j a v a 2 s.c o m*/ getSupportActionBar().setDisplayHomeAsUpEnabled(true); setResult(RESULT_CANCELED); Intent intent = getIntent(); mTabHost = (TabHost) findViewById(R.id.tabHost); mNameEditText = (EditText) findViewById(R.id.feed_title); mUrlEditText = (EditText) findViewById(R.id.feed_url); mRetrieveFulltextCb = (CheckBox) findViewById(R.id.retrieve_fulltext); mFiltersListView = (ListView) findViewById(android.R.id.list); View tabWidget = findViewById(android.R.id.tabs); View buttonLayout = findViewById(R.id.button_layout); mTabHost.setup(); mTabHost.addTab(mTabHost.newTabSpec("feedTab").setIndicator(getString(R.string.tab_feed_title)) .setContent(R.id.feed_tab)); mTabHost.addTab(mTabHost.newTabSpec("filtersTab").setIndicator(getString(R.string.tab_filters_title)) .setContent(R.id.filters_tab)); mTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { @Override public void onTabChanged(String s) { invalidateOptionsMenu(); } }); if (savedInstanceState != null) { mTabHost.setCurrentTab(savedInstanceState.getInt(STATE_CURRENT_TAB)); } if (intent.getAction().equals(Intent.ACTION_INSERT) || intent.getAction().equals(Intent.ACTION_SEND)) { setTitle(R.string.new_feed_title); tabWidget.setVisibility(View.GONE); if (intent.hasExtra(Intent.EXTRA_TEXT)) { mUrlEditText.setText(intent.getStringExtra(Intent.EXTRA_TEXT)); } } else if (intent.getAction().equals(Intent.ACTION_EDIT)) { setTitle(R.string.edit_feed_title); buttonLayout.setVisibility(View.GONE); mFiltersCursorAdapter = new FiltersCursorAdapter(this, Constants.EMPTY_CURSOR); mFiltersListView.setAdapter(mFiltersCursorAdapter); mFiltersListView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { startSupportActionMode(mFilterActionModeCallback); mFiltersCursorAdapter.setSelectedFilter(position); mFiltersListView.invalidateViews(); return true; } }); getLoaderManager().initLoader(0, null, this); if (savedInstanceState == null) { Cursor cursor = getContentResolver().query(intent.getData(), FEED_PROJECTION, null, null, null); if (cursor.moveToNext()) { mNameEditText.setText(cursor.getString(0)); mUrlEditText.setText(cursor.getString(1)); mRetrieveFulltextCb.setChecked(cursor.getInt(2) == 1); cursor.close(); } else { cursor.close(); Toast.makeText(EditFeedActivity.this, R.string.error, Toast.LENGTH_SHORT).show(); finish(); } } } }
From source file:com.dycody.android.idealnote.DetailFragment.java
@SuppressLint("NewApi") @Override/*from ww w . j a v a2 s. c om*/ public void onActivityResult(int requestCode, int resultCode, Intent intent) { // Fetch uri from activities, store into adapter and refresh adapter Attachment attachment; if (resultCode == Activity.RESULT_OK) { switch (requestCode) { case TAKE_PHOTO: attachment = new Attachment(attachmentUri, Constants.MIME_TYPE_IMAGE); addAttachment(attachment); mAttachmentAdapter.notifyDataSetChanged(); mGridView.autoresize(); break; case TAKE_VIDEO: // Gingerbread doesn't allow custom folder so data are retrieved from intent if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) { attachment = new Attachment(attachmentUri, Constants.MIME_TYPE_VIDEO); } else { attachment = new Attachment(intent.getData(), Constants.MIME_TYPE_VIDEO); } addAttachment(attachment); mAttachmentAdapter.notifyDataSetChanged(); mGridView.autoresize(); break; case FILES: onActivityResultManageReceivedFiles(intent); break; case SET_PASSWORD: noteTmp.setPasswordChecked(true); lockUnlock(); break; case SKETCH: attachment = new Attachment(attachmentUri, Constants.MIME_TYPE_SKETCH); addAttachment(attachment); mAttachmentAdapter.notifyDataSetChanged(); mGridView.autoresize(); break; case CATEGORY: Toast.makeText(getActivity(), R.string.category_saved, Toast.LENGTH_SHORT).show(); //mainActivity.showMessage(R.string.category_saved, ONStyle.CONFIRM); Category category = intent.getParcelableExtra("category"); noteTmp.setCategory(category); setTagMarkerColor(category); break; case DETAIL: Toast.makeText(getActivity(), R.string.note_updated, Toast.LENGTH_SHORT).show(); //mainActivity.showMessage(R.string.note_updated, ONStyle.CONFIRM); break; default: Log.e(Constants.TAG, "Wrong element choosen: " + requestCode); } } }
From source file:net.fred.feedex.activity.EditFeedActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { UiUtils.setPreferenceTheme(this); super.onCreate(savedInstanceState); setContentView(R.layout.activity_feed_edit); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/* w w w.j av a2 s .c om*/ getSupportActionBar().setDisplayHomeAsUpEnabled(true); setResult(RESULT_CANCELED); Intent intent = getIntent(); mTabHost = (TabHost) findViewById(R.id.tabHost); mNameEditText = (EditText) findViewById(R.id.feed_title); mUrlEditText = (EditText) findViewById(R.id.feed_url); mRetrieveFulltextCb = (CheckBox) findViewById(R.id.retrieve_fulltext); mFiltersListView = (ListView) findViewById(android.R.id.list); View tabWidget = findViewById(android.R.id.tabs); mTabHost.setup(); mTabHost.addTab(mTabHost.newTabSpec("feedTab").setIndicator(getString(R.string.tab_feed_title)) .setContent(R.id.feed_tab)); mTabHost.addTab(mTabHost.newTabSpec("filtersTab").setIndicator(getString(R.string.tab_filters_title)) .setContent(R.id.filters_tab)); mTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { @Override public void onTabChanged(String s) { invalidateOptionsMenu(); } }); if (savedInstanceState != null) { mTabHost.setCurrentTab(savedInstanceState.getInt(STATE_CURRENT_TAB)); } if (intent.getAction().equals(Intent.ACTION_INSERT) || intent.getAction().equals(Intent.ACTION_SEND)) { setTitle(R.string.new_feed_title); tabWidget.setVisibility(View.GONE); if (intent.hasExtra(Intent.EXTRA_TEXT)) { mUrlEditText.setText(intent.getStringExtra(Intent.EXTRA_TEXT)); } } else if (intent.getAction().equals(Intent.ACTION_VIEW)) { setTitle(R.string.new_feed_title); tabWidget.setVisibility(View.GONE); mUrlEditText.setText(intent.getDataString()); } else if (intent.getAction().equals(Intent.ACTION_EDIT)) { setTitle(R.string.edit_feed_title); mFiltersCursorAdapter = new FiltersCursorAdapter(this, Constants.EMPTY_CURSOR); mFiltersListView.setAdapter(mFiltersCursorAdapter); mFiltersListView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { startSupportActionMode(mFilterActionModeCallback); mFiltersCursorAdapter.setSelectedFilter(position); mFiltersListView.invalidateViews(); return true; } }); getLoaderManager().initLoader(0, null, this); if (savedInstanceState == null) { Cursor cursor = getContentResolver().query(intent.getData(), FEED_PROJECTION, null, null, null); if (cursor != null && cursor.moveToNext()) { mNameEditText.setText(cursor.getString(0)); mUrlEditText.setText(cursor.getString(1)); mRetrieveFulltextCb.setChecked(cursor.getInt(2) == 1); if (cursor.getInt(3) == 1) { // if it's a group, we cannot edit it finish(); } } else { UiUtils.showMessage(EditFeedActivity.this, R.string.error); finish(); } if (cursor != null) { cursor.close(); } } } }
From source file:com.dwdesign.tweetings.activity.ComposeActivity.java
@Override public void onActivityResult(final int requestCode, final int resultCode, final Intent intent) { switch (requestCode) { case REQUEST_SCHEDULE_DATE: { if (resultCode == Activity.RESULT_OK) { Bundle bundle = intent.getExtras(); mScheduleDate = bundle.getString(INTENT_KEY_SCHEDULE_DATE_TIME); } else {/* w w w . j a va 2 s .c om*/ if (mScheduleDate != null) { mScheduleDate = null; } } setMenu(); break; } case REQUEST_TAKE_PHOTO: { if (resultCode == Activity.RESULT_OK) { final File file = new File(mImageUri.getPath()); if (file.exists()) { mIsImageAttached = false; mIsPhotoAttached = true; mImageThumbnailPreview.setVisibility(View.VISIBLE); reloadAttachedImageThumbnail(file); } else { mIsPhotoAttached = false; } setMenu(); boolean isAutoUpload = mPreferences.getBoolean(PREFERENCE_KEY_AUTO_UPLOAD, false); if (!isNullOrEmpty(mUploadProvider) && mIsPhotoAttached && isAutoUpload) { postMedia(); } } break; } case REQUEST_PICK_IMAGE: { if (resultCode == Activity.RESULT_OK) { final Uri uri = intent.getData(); final File file = uri == null ? null : new File(getImagePathFromUri(this, uri)); if (file != null && file.exists()) { mImageUri = Uri.fromFile(file); mIsPhotoAttached = false; mIsImageAttached = true; mImageThumbnailPreview.setVisibility(View.VISIBLE); reloadAttachedImageThumbnail(file); } else { mIsImageAttached = false; } setMenu(); boolean isAutoUpload = mPreferences.getBoolean(PREFERENCE_KEY_AUTO_UPLOAD, false); if (!isNullOrEmpty(mUploadProvider) && mIsImageAttached && isAutoUpload) { postMedia(); } } break; } case REQUEST_SELECT_ACCOUNT: { if (resultCode == Activity.RESULT_OK) { final Bundle bundle = intent.getExtras(); if (bundle == null) { break; } final long[] account_ids = bundle.getLongArray(INTENT_KEY_IDS); if (account_ids != null) { mAccountIds = account_ids; if (mInReplyToStatusId <= 0 && !Intent.ACTION_SEND.equals(getIntent().getAction())) { final SharedPreferences.Editor editor = mPreferences.edit(); editor.putString(PREFERENCE_KEY_COMPOSE_ACCOUNTS, ArrayUtils.toString(mAccountIds, ',', false)); editor.commit(); } mColorIndicator.setColor(getAccountColors(this, account_ids)); } } break; } case REQUEST_EDIT_IMAGE: { if (resultCode == Activity.RESULT_OK) { final Uri uri = intent.getData(); final File file = uri == null ? null : new File(getImagePathFromUri(this, uri)); if (file != null && file.exists()) { mImageUri = Uri.fromFile(file); reloadAttachedImageThumbnail(file); } else { break; } setMenu(); } break; } case REQUEST_EXTENSION_COMPOSE: { if (resultCode == Activity.RESULT_OK) { final Bundle extras = intent.getExtras(); if (extras == null) { break; } final String text = extras.getString(INTENT_KEY_TEXT); final String append = extras.getString(INTENT_KEY_APPEND_TEXT); if (text != null) { mEditText.setText(text); mText = parseString(mEditText.getText()); } else if (append != null) { mEditText.append(append); mText = parseString(mEditText.getText()); } } break; } case ACTION_REQUEST_FEATHER: if (resultCode == RESULT_OK) { final Uri uri = intent.getData(); final File file = uri == null ? null : new File(getImagePathFromUri(this, uri)); if (file != null && file.exists()) { mImageUri = Uri.fromFile(file); reloadAttachedImageThumbnail(file); } else { break; } setMenu(); } break; } }
From source file:org.planetmono.dcuploader.ActivityUploader.java
@SuppressWarnings("unchecked") @Override/* w w w.j av a 2 s. c o m*/ public void onCreate(Bundle savedState) { super.onCreate(savedState); initViews(); if (formLocation) queryLocation(true); if (savedState != null) { if (savedState.containsKey("tempfile")) tempFile = new File(savedState.getString("tempfile")); if (savedState.containsKey("target")) resolveTarget(savedState.getString("target")); if (savedState.containsKey("tempfiles")) tempFiles = savedState.getStringArrayList("tempfiles"); if (savedState.containsKey("contents")) { contents = new ArrayList<Uri>(); String[] carr = savedState.getStringArray("contents"); for (String s : carr) contents.add(Uri.parse(s)); } } postfix = "from <a href=\"http://palladium.planetmono.org/dcuploader\">DCUploader</a>"; Button uploadVisit = (Button) findViewById(R.id.upload_visit); if (passThrough || target == null) uploadVisit.setEnabled(false); else uploadVisit.setEnabled(true); /* populate data by getting STREAM parameter */ Intent i = getIntent(); Bundle b = i.getExtras(); String action = i.getAction(); if (action.equals(Intent.ACTION_SEND) || action.equals(Intent.ACTION_SEND_MULTIPLE)) { called = true; if (i.hasExtra(Intent.EXTRA_STREAM)) { Object o = b.get(Intent.EXTRA_STREAM); /* quick and dirty. any better idea? */ try { contents.add((Uri) o); } catch (Exception e1) { try { contents = (ArrayList<Uri>) ((ArrayList<Uri>) o).clone(); } catch (Exception e2) { } } boolean exceeded = false; if (contents.size() > 5) { exceeded = true; do { contents.remove(5); } while (contents.size() > 5); } galleryChanged = true; updateImageButtons(); resetThumbnails(); updateGallery(); if (exceeded) Toast.makeText(this, " 5 . 5 ??? ? ?.", Toast.LENGTH_LONG).show(); } if (i.hasExtra(Intent.EXTRA_TEXT)) { ((EditText) findViewById(R.id.upload_text)).setText(b.getString(Intent.EXTRA_TEXT)); } } else if (action.equals("share")) { called = true; /* HTC web browser uses non-standard intent */ ((EditText) findViewById(R.id.upload_text)).setText(b.getString(Intent.EXTRA_TITLE)); } else if (action.equals(Intent.ACTION_VIEW)) { Uri uri = i.getData(); if (i.getCategories().contains(Intent.CATEGORY_BROWSABLE)) { passThrough = true; Pattern p = Pattern.compile("id=([\\-a-zA-Z0-9_]+)"); Matcher m = p.matcher(uri.toString()); if (m.find()) { resolveTarget(m.group(1)); } else { passThrough = false; } if (uri.getHost().equals(Application.HOST_DCMYS)) { destination = Application.DESTINATION_DCMYS; postfix = "from dc.m.dcmys.kr w/ <a href=\"http://palladium.planetmono.org/dcuploader\">DCUploader</a>"; } else if (uri.getHost().equals(Application.HOST_MOOLZO)) { destination = Application.DESTINATION_MOOLZO; postfix = "- From m.oolzo.com w/ <a href=\"http://palladium.planetmono.org/dcuploader\">DCUploader</a>"; } else if (uri.getHost().equals(Application.HOST_DCINSIDE)) { destination = Application.DESTINATION_DCINSIDE; } setDefaultImage(); } } reloadConfigurations(); }
From source file:com.ccxt.whl.activity.SettingsFragmentC_0815.java
/** * onActivityResult//from w ww .j a v a 2s. com */ public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == USERPIC_REQUEST_CODE_CAMERA) { // ?? if (cameraFile != null && cameraFile.exists()) { //sendPicture(cameraFile.getAbsolutePath()); Log.d("log", "cameraFile" + cameraFile.getAbsolutePath()); //?uri imageUri = Uri.fromFile(cameraFile); imageUri = Uri.fromFile(cameraFile); cropImageUri(imageUri, 200, 200, USERPIC_REQUEST_CODE_CUT); } } else if (requestCode == USERPIC_REQUEST_CODE_LOCAL) { //?? if (imageUritest != null) { // Bitmap bitmap = decodeUriAsBitmap(imageUritest);//decode bitmap //iv_user_photo.setImageBitmap(bitmap); Log.d("log", "imageUri==>" + imageUritest); iv_user_photo.setImageURI(imageUri); RequestParams params = new RequestParams(); // final String contentType = RequestParams.APPLICATION_OCTET_STREAM; File file = Uritofile(imageUritest); //File file = new File(imageUri.getPath()); if (file.exists()) { try { params.put("headurl", file, "image/jpg"); params.put("user", DemoApplication.getInstance().getUser()); params.put("param", "headurl"); HttpRestClient.post(Constant.UPDATE_USER_URL, params, responseHandler); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { Toast toast = Toast.makeText(getActivity(), "?SD??", Toast.LENGTH_SHORT); } } else { Toast toast = Toast.makeText(getActivity(), "?SD??", Toast.LENGTH_SHORT); } } else if (requestCode == USERPIC_REQUEST_CODE_LOCAL_19) { // ?19 if (data != null) { Uri selectedImage = data.getData(); if (selectedImage != null) { //?uri imageUri = selectedImage; //sendPicByUri(selectedImage); imageUri = selectedImage; sendPicByUri(selectedImage); //Log.d("log","selectedImage"+selectedImage); } } } else if (requestCode == USERPIC_REQUEST_CODE_CUT) {//?19 // ? if (data != null) { Log.d("log", "imageUribundle==>" + imageUri); iv_user_photo.setImageURI(imageUri); RequestParams params = new RequestParams(); // final String contentType = RequestParams.APPLICATION_OCTET_STREAM; File file = Uritofile(imageUri); //File file = new File(imageUri.getPath()); if (file.exists()) { try { params.put("headurl", file, "image/jpeg"); params.put("user", DemoApplication.getInstance().getUser()); params.put("param", "headurl"); HttpRestClient.post(Constant.UPDATE_USER_URL, params, responseHandler); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { Toast toast = Toast.makeText(getActivity(), "?SD??", Toast.LENGTH_SHORT); } //params.put(key, file, ) //**??data //Bitmap bitmap = data.getParcelableExtra("data"); // Bitmap bitmap = data.getExtras().getParcelable("data"); /* // ByteArrayOutputStream out = new ByteArrayOutputStream(); // bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); */ //this.iv_image.setImageBitmap(bitmap); } else { Toast toast = Toast.makeText(getActivity(), "?SD??", Toast.LENGTH_SHORT); } /* try { // // tempFile.delete(); } catch (Exception e) { e.printStackTrace(); } */ RequestParams params = new RequestParams(); final String contentType = RequestParams.APPLICATION_OCTET_STREAM; // params.put(key, file, contentType) //HttpRestClient.post(url, params, responseHandler) } }
From source file:org.getlantern.firetweet.util.Utils.java
public static Fragment createFragmentForIntent(final Context context, final Intent intent) { final Uri uri = intent.getData(); return createFragmentForIntent(context, matchLinkId(uri), intent); }
From source file:de.vanita5.twittnuker.util.Utils.java
public static Fragment createFragmentForIntent(final Context context, final Intent intent) { final long start = System.currentTimeMillis(); intent.setExtrasClassLoader(context.getClassLoader()); final Bundle extras = intent.getExtras(); final Uri uri = intent.getData(); final Fragment fragment; if (uri == null) return null; final Bundle args = new Bundle(); if (extras != null) { args.putAll(extras);// w w w . j a v a 2s . c o m } switch (matchLinkId(uri)) { case LINK_ID_STATUS: { fragment = new StatusFragment(); if (!args.containsKey(EXTRA_STATUS_ID)) { final String param_status_id = uri.getQueryParameter(QUERY_PARAM_STATUS_ID); args.putLong(EXTRA_STATUS_ID, ParseUtils.parseLong(param_status_id)); } break; } case LINK_ID_USER: { fragment = new UserProfileFragment(); final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME); final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID); if (!args.containsKey(EXTRA_SCREEN_NAME)) { args.putString(EXTRA_SCREEN_NAME, paramScreenName); } if (!args.containsKey(EXTRA_USER_ID)) { args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(param_user_id)); } break; } case LINK_ID_USER_LIST_MEMBERSHIPS: { fragment = new UserListMembershipsListFragment(); final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME); final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID); if (!args.containsKey(EXTRA_SCREEN_NAME)) { args.putString(EXTRA_SCREEN_NAME, paramScreenName); } if (!args.containsKey(EXTRA_USER_ID)) { args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(param_user_id)); } break; } case LINK_ID_USER_TIMELINE: { fragment = new UserTimelineFragment(); final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME); final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID); if (!args.containsKey(EXTRA_SCREEN_NAME)) { args.putString(EXTRA_SCREEN_NAME, paramScreenName); } if (!args.containsKey(EXTRA_USER_ID)) { args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(param_user_id)); } if (isEmpty(paramScreenName) && isEmpty(param_user_id)) return null; break; } case LINK_ID_USER_FAVORITES: { fragment = new UserFavoritesFragment(); final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME); final String paramUserId = uri.getQueryParameter(QUERY_PARAM_USER_ID); if (!args.containsKey(EXTRA_SCREEN_NAME)) { args.putString(EXTRA_SCREEN_NAME, paramScreenName); } if (!args.containsKey(EXTRA_USER_ID)) { args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(paramUserId)); } if (!args.containsKey(EXTRA_SCREEN_NAME) && !args.containsKey(EXTRA_USER_ID)) return null; break; } case LINK_ID_USER_FOLLOWERS: { fragment = new UserFollowersFragment(); final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME); final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID); if (!args.containsKey(EXTRA_SCREEN_NAME)) { args.putString(EXTRA_SCREEN_NAME, paramScreenName); } if (!args.containsKey(EXTRA_USER_ID)) { args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(param_user_id)); } if (isEmpty(paramScreenName) && isEmpty(param_user_id)) return null; break; } case LINK_ID_USER_FRIENDS: { fragment = new UserFriendsFragment(); final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME); final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID); if (!args.containsKey(EXTRA_SCREEN_NAME)) { args.putString(EXTRA_SCREEN_NAME, paramScreenName); } if (!args.containsKey(EXTRA_USER_ID)) { args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(param_user_id)); } if (isEmpty(paramScreenName) && isEmpty(param_user_id)) return null; break; } case LINK_ID_USER_BLOCKS: { fragment = new UserBlocksListFragment(); break; } case LINK_ID_MUTES_USERS: { fragment = new MutesUsersListFragment(); break; } case LINK_ID_DIRECT_MESSAGES_CONVERSATION: { fragment = new DirectMessagesConversationFragment(); final String paramRecipientId = uri.getQueryParameter(QUERY_PARAM_RECIPIENT_ID); final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME); final long conversationId = ParseUtils.parseLong(paramRecipientId); if (conversationId > 0) { args.putLong(EXTRA_RECIPIENT_ID, conversationId); } else if (paramScreenName != null) { args.putString(EXTRA_SCREEN_NAME, paramScreenName); } break; } case LINK_ID_USER_LIST: { fragment = new UserListDetailsFragment(); final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME); final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID); final String param_list_id = uri.getQueryParameter(QUERY_PARAM_LIST_ID); final String paramListName = uri.getQueryParameter(QUERY_PARAM_LIST_NAME); if (isEmpty(param_list_id) && (isEmpty(paramListName) || isEmpty(paramScreenName) && isEmpty(param_user_id))) return null; args.putInt(EXTRA_LIST_ID, ParseUtils.parseInt(param_list_id)); args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(param_user_id)); args.putString(EXTRA_SCREEN_NAME, paramScreenName); args.putString(EXTRA_LIST_NAME, paramListName); break; } case LINK_ID_USER_LISTS: { fragment = new UserListsListFragment(); final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME); final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID); if (!args.containsKey(EXTRA_SCREEN_NAME)) { args.putString(EXTRA_SCREEN_NAME, paramScreenName); } if (!args.containsKey(EXTRA_USER_ID)) { args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(param_user_id)); } if (isEmpty(paramScreenName) && isEmpty(param_user_id)) return null; break; } case LINK_ID_USER_LIST_TIMELINE: { fragment = new UserListTimelineFragment(); final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME); final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID); final String param_list_id = uri.getQueryParameter(QUERY_PARAM_LIST_ID); final String paramListName = uri.getQueryParameter(QUERY_PARAM_LIST_NAME); if (isEmpty(param_list_id) && (isEmpty(paramListName) || isEmpty(paramScreenName) && isEmpty(param_user_id))) return null; args.putInt(EXTRA_LIST_ID, ParseUtils.parseInt(param_list_id)); args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(param_user_id)); args.putString(EXTRA_SCREEN_NAME, paramScreenName); args.putString(EXTRA_LIST_NAME, paramListName); break; } case LINK_ID_USER_LIST_MEMBERS: { fragment = new UserListMembersFragment(); final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME); final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID); final String param_list_id = uri.getQueryParameter(QUERY_PARAM_LIST_ID); final String paramListName = uri.getQueryParameter(QUERY_PARAM_LIST_NAME); if (isEmpty(param_list_id) && (isEmpty(paramListName) || isEmpty(paramScreenName) && isEmpty(param_user_id))) return null; args.putInt(EXTRA_LIST_ID, ParseUtils.parseInt(param_list_id)); args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(param_user_id)); args.putString(EXTRA_SCREEN_NAME, paramScreenName); args.putString(EXTRA_LIST_NAME, paramListName); break; } case LINK_ID_USER_LIST_SUBSCRIBERS: { fragment = new UserListSubscribersFragment(); final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME); final String param_user_id = uri.getQueryParameter(QUERY_PARAM_USER_ID); final String param_list_id = uri.getQueryParameter(QUERY_PARAM_LIST_ID); final String paramListName = uri.getQueryParameter(QUERY_PARAM_LIST_NAME); if (isEmpty(param_list_id) && (isEmpty(paramListName) || isEmpty(paramScreenName) && isEmpty(param_user_id))) return null; args.putInt(EXTRA_LIST_ID, ParseUtils.parseInt(param_list_id)); args.putLong(EXTRA_USER_ID, ParseUtils.parseLong(param_user_id)); args.putString(EXTRA_SCREEN_NAME, paramScreenName); args.putString(EXTRA_LIST_NAME, paramListName); break; } case LINK_ID_SAVED_SEARCHES: { fragment = new SavedSearchesListFragment(); break; } case LINK_ID_USER_MENTIONS: { fragment = new UserMentionsFragment(); final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME); if (!args.containsKey(EXTRA_SCREEN_NAME) && !isEmpty(paramScreenName)) { args.putString(EXTRA_SCREEN_NAME, paramScreenName); } if (isEmpty(args.getString(EXTRA_SCREEN_NAME))) return null; break; } case LINK_ID_INCOMING_FRIENDSHIPS: { fragment = new IncomingFriendshipsFragment(); break; } case LINK_ID_USERS: { fragment = new UsersListFragment(); break; } case LINK_ID_STATUSES: { fragment = new StatusesListFragment(); break; } case LINK_ID_STATUS_RETWEETERS: { fragment = new StatusRetweetersListFragment(); if (!args.containsKey(EXTRA_STATUS_ID)) { final String param_status_id = uri.getQueryParameter(QUERY_PARAM_STATUS_ID); args.putLong(EXTRA_STATUS_ID, ParseUtils.parseLong(param_status_id)); } break; } case LINK_ID_STATUS_FAVORITERS: { fragment = new StatusFavoritersListFragment(); if (!args.containsKey(EXTRA_STATUS_ID)) { final String param_status_id = uri.getQueryParameter(QUERY_PARAM_STATUS_ID); args.putLong(EXTRA_STATUS_ID, ParseUtils.parseLong(param_status_id)); } break; } case LINK_ID_STATUS_REPLIES: { fragment = new StatusRepliesListFragment(); if (!args.containsKey(EXTRA_STATUS_ID)) { final String paramStatusId = uri.getQueryParameter(QUERY_PARAM_STATUS_ID); args.putLong(EXTRA_STATUS_ID, ParseUtils.parseLong(paramStatusId)); } if (!args.containsKey(EXTRA_SCREEN_NAME)) { final String paramScreenName = uri.getQueryParameter(QUERY_PARAM_SCREEN_NAME); args.putString(EXTRA_SCREEN_NAME, paramScreenName); } break; } case LINK_ID_SEARCH: { final String param_query = uri.getQueryParameter(QUERY_PARAM_QUERY); if (isEmpty(param_query)) return null; args.putString(EXTRA_QUERY, param_query); fragment = new SearchFragment(); break; } default: { return null; } } final String param_account_id = uri.getQueryParameter(QUERY_PARAM_ACCOUNT_ID); if (param_account_id != null) { args.putLong(EXTRA_ACCOUNT_ID, ParseUtils.parseLong(param_account_id)); } else { final String param_account_name = uri.getQueryParameter(QUERY_PARAM_ACCOUNT_NAME); if (param_account_name != null) { args.putLong(EXTRA_ACCOUNT_ID, getAccountId(context, param_account_name)); } else { final long account_id = getDefaultAccountId(context); if (isMyAccount(context, account_id)) { args.putLong(EXTRA_ACCOUNT_ID, account_id); } } } fragment.setArguments(args); if (isDebugBuild()) { Log.d(LOGTAG, String.format("createFragmentForIntent used %d ms", System.currentTimeMillis() - start)); } return fragment; }