@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Intent sharedIntent = getIntent(); final String action = sharedIntent.getAction(); ArrayList<Uri> uris = null; if (Intent.ACTION_SEND.equals(action)) { Uri uri = sharedIntent.getParcelableExtra(Intent.EXTRA_STREAM); if (null != uri) { uris = new ArrayList<Uri>(); uris.add(uri); } } else if (Intent.ACTION_SEND_MULTIPLE.equals(action)) { uris = sharedIntent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); } if (null != uris && !uris.isEmpty()) { PhotoUploadController controller = PhotupApplication.getApplication(this).getPhotoUploadController(); for (Uri uri : uris) { controller.addSelection(PhotoUpload.getSelection(uri)); } } Intent intent = new Intent(this, PhotoSelectionActivity.class); intent.putExtra(PhotoSelectionActivity.EXTRA_DEFAULT_TAB, PhotoSelectionActivity.TAB_SELECTED); startActivity(intent); finish(); }
private List<String> getFileList(Intent intent) { ArrayList<String> list = new ArrayList<String>(); if (Intent.ACTION_SEND.equals(intent.getAction())) { Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM); if (uri != null) { String path = getRealPathFromURI(uri); list.add(path); } else { Toast.makeText(this, "Unable get SEND media: " + uri, Toast.LENGTH_LONG).show(); } } else if (Intent.ACTION_SEND_MULTIPLE.equals(intent.getAction())) { if (intent.hasExtra(Intent.EXTRA_STREAM) == false) { Toast.makeText(this, "Unable get SEND_MULTI media: empty payload", Toast.LENGTH_LONG) .show(); return Collections.emptyList(); } ArrayList<Parcelable> urls = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); for (Parcelable p : urls) { Uri uri = (Uri) p; String path = getRealPathFromURI(uri); list.add(path); } } return list; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.send_activity); if (Intent.ACTION_SEND.contentEquals(getIntent().getAction())) { Button ok = (Button) findViewById(R.id.buttonOk); Button cancel = (Button) findViewById(R.id.buttonCancel); EditText edit = (EditText) findViewById(R.id.editText1); edit.setText(getIntent().getStringExtra(Intent.EXTRA_TEXT)); ok.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(ActivitySend.this, "Enviando mensagem", Toast.LENGTH_SHORT).show(); finish(); } }); cancel.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { finish(); } }); return; } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Intent intent = getIntent(); Uri uri = intent.getData(); if (uri != null) { MainActivity.addLink(this, uri.toString()); Uri newUri = Uri.parse("view-source:" + uri.toString()); startChrome(newUri); } if (Intent.ACTION_SEND.equals(intent.getAction())) { Bundle extras = intent.getExtras(); if (extras != null) { String text = extras.getString(Intent.EXTRA_TEXT); Pattern pattern = Pattern.compile(URL_PATTERN); if (text != null) { Matcher m = pattern.matcher(text); if (m.find()) { String url = m.group(1); MainActivity.addLink(this, url); Uri newUri = Uri.parse("view-source:" + url); startChrome(newUri); } } } } this.finish(); }
@Override protected void onResume() { super.onResume(); Intent intent = getIntent(); if (Intent.ACTION_SEND.equals(intent.getAction())) { Uri uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); uriOCR(uri); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.add_bookmark); Intent intent = getIntent(); if (Intent.ACTION_SEND.equals(intent.getAction()) && intent.hasExtra(Intent.EXTRA_TEXT)) { bookmark = new Bookmark(); ShareCompat.IntentReader reader = ShareCompat.IntentReader.from(this); String url = StringUtils.getUrl(reader.getText().toString()); bookmark.setUrl(url); if (reader.getSubject() != null) bookmark.setDescription(reader.getSubject()); if (url.equals("")) { Toast.makeText(this, R.string.add_bookmark_invalid_url, Toast.LENGTH_LONG).show(); } if (intent.hasExtra(Constants.EXTRA_DESCRIPTION)) { bookmark.setDescription(intent.getStringExtra(Constants.EXTRA_DESCRIPTION)); } bookmark.setNotes(intent.getStringExtra(Constants.EXTRA_NOTES)); bookmark.setTagString(intent.getStringExtra(Constants.EXTRA_TAGS)); bookmark.setShared(!intent.getBooleanExtra(Constants.EXTRA_PRIVATE, privateDefault)); try { Bookmark old = BookmarkManager.GetByUrl(bookmark.getUrl(), this); bookmark = old.copy(); } catch (Exception e) { } } else if (Intent.ACTION_EDIT.equals(intent.getAction())) { int id = Integer.parseInt(intent.getData().getLastPathSegment()); try { bookmark = BookmarkManager.GetById(id, this); oldBookmark = bookmark.copy(); update = true; } catch (ContentNotFoundException e) { e.printStackTrace(); } } if (update) setTitle(getString(R.string.add_bookmark_edit_title)); else setTitle(getString(R.string.add_bookmark_add_title)); frag = (AddBookmarkFragment) getSupportFragmentManager().findFragmentById(R.id.add_bookmark_fragment); frag.loadBookmark(bookmark, oldBookmark); }
private boolean receivedIntent(Intent i) { return Constants.ACTION_SHORTCUT.equals(i.getAction()) || Constants.ACTION_NOTIFICATION_CLICK.equals(i.getAction()) || Constants.ACTION_WIDGET.equals(i.getAction()) || Constants.ACTION_TAKE_PHOTO.equals(i.getAction()) || ((Intent.ACTION_SEND.equals(i.getAction()) || Intent.ACTION_SEND_MULTIPLE.equals(i.getAction()) || Constants.INTENT_GOOGLE_NOW.equals(i.getAction())) && i.getType() != null) || i.getAction().contains(Constants.ACTION_NOTIFICATION_CLICK); }
@Override public void onCreate(Bundle savedInstanceState) { if (Intent.ACTION_VIEW.equals(getIntent().getAction()) || Intent.ACTION_SEND.equals(getIntent().getAction()) || Intent.ACTION_SENDTO.equals(getIntent().getAction()) || Intent.ACTION_CREATE_SHORTCUT.equals(getIntent().getAction())) { ActivityManager.getInstance().startNewTask(this); } super.onCreate(savedInstanceState); if (isFinishing()) { return; } setContentView(R.layout.contact_list); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_default); toolbar.setOnClickListener(this); drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); drawerToggle = new ActionBarDrawerToggle( this, drawerLayout, toolbar, R.string.application_title_short, R.string.application_title_short); drawerLayout.setDrawerListener(drawerToggle); toolbar.inflateMenu(R.menu.contact_list); optionsMenu = toolbar.getMenu(); setUpSearchView(optionsMenu); toolbar.setOnMenuItemClickListener(this); barPainter = new BarPainter(this, toolbar); barPainter.setDefaultColor(); toolbar.setTitle(R.string.application_title_full); if (savedInstanceState != null) { sendText = savedInstanceState.getString(SAVED_SEND_TEXT); action = savedInstanceState.getString(SAVED_ACTION); } else { getSupportFragmentManager() .beginTransaction() .add(R.id.container, new ContactListFragment(), CONTACT_LIST_TAG) .commit(); sendText = null; action = getIntent().getAction(); } getIntent().setAction(null); }
/** 处理其他应用的数据 */ public void getOtherAppsData() { shareIntent = getIntent(); String action = shareIntent.getAction(); String type = shareIntent.getType(); if (Intent.ACTION_SEND.equals(action) && type != null) { if ("text/plain".equals(type)) { handleSendText(shareIntent); // 处理文本 } } else { } }
private void openMainActivity() { Intent previousIntent = getIntent(); if (Intent.ACTION_SEND.equals(previousIntent.getAction()) || Intent.ACTION_SEND_MULTIPLE.equals(previousIntent.getAction())) { Intent intent = new Intent(previousIntent); intent.setClass(this, SearchableActivity.class); startActivity(intent); } else { Intent intent = new Intent(getApplicationContext(), MainActivity.class); startActivity(intent); } finish(); }
private void setupTextBody() { this.txtBody = (EditText) findViewById(R.id.txtBody); final TextView txtCharRemaining = (TextView) findViewById(R.id.txtCharRemaining); this.txtBody.addTextChangedListener(new TextCounterWatcher(txtCharRemaining, this.txtBody)); if (Intent.ACTION_SEND.equals(getIntent().getAction()) && "text/plain".equals(getIntent().getType())) { final String intentText = getIntent().getStringExtra(Intent.EXTRA_TEXT); if (intentText != null) { this.txtBody.setText(intentText); this.txtBody.setSelection(this.txtBody.getText().length()); } } }
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); Intent intent = getIntent(); if (intent == null) { finish(); } else { String action = intent.getAction(); if (Intents.Encode.ACTION.equals(action) || Intent.ACTION_SEND.equals(action)) { setContentView(R.layout.encode); } else { finish(); } } }
private void setupAttachemnt(final Bundle savedInstanceState) { if (savedInstanceState != null) this.attachment = savedInstanceState.getParcelable(ARG_ATTACHMENT); if (this.attachment == null) this.attachment = this.intentExtras.getParcelable(ARG_ATTACHMENT); if (this.attachment == null && Intent.ACTION_SEND.equals(getIntent().getAction()) && getIntent().getType() != null && getIntent().getType().startsWith("image/")) { final Uri intentUri = getIntent().getParcelableExtra(Intent.EXTRA_STREAM); if (ImageMetadata.isUnderstoodResource(intentUri)) { this.attachment = intentUri; } else { DialogHelper.alert(this, "Unknown resource:\n" + intentUri); } } redrawAttachment(); ((Button) findViewById(R.id.btnAttach)).setOnClickListener(this.attachClickListener); }
@Override public void onManagerConnected(int status) { switch (status) { case LoaderCallbackInterface.SUCCESS: { init_sd_imgs(); // mat_share = new Mat(); Bitmap bitmap_share = null; Intent intent = getIntent(); String action = intent.getAction(); String type = intent.getType(); if (Intent.ACTION_SEND.equals(action) && type != null) { if ("text/plain".equals(type)) { handleSendText(intent); } else if (type.startsWith("image/")) { bitmap_share = handleSendImage(intent); } } Fragment fragment = new GalleryFragment(); if (mat_share == null && bitmap_share != null) { mat_share = new Mat(); Utils.bitmapToMat(bitmap_share, mat_share); } if (mat_share != null) { fragment = new RcvGridFragment(MainActivity.this); } getFragmentManager().beginTransaction().replace(R.id.container, fragment).commit(); } break; default: { super.onManagerConnected(status); } break; } }
/** @see android.app.Activity#onCreate(android.os.Bundle) */ @Override protected void onCreate(Bundle savedInstanceState) { if (Log.DEBUG) { Log.v("GoogleContactsActivity: onCreate() start"); } super.onCreate(savedInstanceState); setContentView(R.layout.gcontactlist); mSyncCounter = (TextView) findViewById(R.id.sync_google_counter); Button syncButton = (Button) findViewById(R.id.start_sync_button); syncButton.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { sync(); } }); mDb = new DbAdapter(this); mDb.open(false); transport.setVersionHeader(GoogleContacts.VERSION); AtomParser atomParser = new AtomParser(); atomParser.namespaceDictionary = GoogleContactsAtom.NAMESPACE_DICTIONARY; transport.addParser(atomParser); transport.applicationName = APP_NAME; HttpTransport.setLowLevelHttpTransport(ApacheHttpTransport.INSTANCE); Intent intent = getIntent(); if (Intent.ACTION_SEND.equals(intent.getAction())) { if (Log.DEBUG) { Log.v("Intent.ACTION_SEND.equals( intent.getAction() )"); } sendData = new SendData(intent, getContentResolver()); } else if (Intent.ACTION_MAIN.equals(intent.getAction())) { if (Log.DEBUG) { Log.v("Intent.ACTION_MAIN.equals( intent.getAction() )"); } sendData = null; } gotAccount(false); if (Log.DEBUG) { Log.v("GoogleContactsActivity: onCreate() stop"); } }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.receiver); final Button cancelbtn = (Button) findViewById(R.id.ButtonCancel); // cancelbtn.setEnabled(false); cancelbtn.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // streamtask.cancel(true); finish(); } }); try { Intent intent = getIntent(); String action = intent.getAction(); String type = intent.getType(); if ((!(Intent.ACTION_SEND.equals(action))) || (type == null)) { throw new RuntimeException("Unknown intent action or type"); } if (!("text/plain".equals(type))) { throw new RuntimeException("Type is not text/plain"); } String extra = intent.getStringExtra(Intent.EXTRA_TEXT); if (extra == null) { throw new RuntimeException("Cannot get shared text"); } final DownloadStreamTask streamtask = new DownloadStreamTask(this); // Once created, a task is executed very simply: streamtask.execute(extra); } catch (Exception e) { Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show(); } }
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent(); String action = intent.getAction(); String type = intent.getType(); if (Intent.ACTION_SEND.equals(action) && type != null) { if ("text/plain".equals(type)) { handleSendText(intent); } else if (type.startsWith("image/")) { handleSendImage(intent); } } else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) { if (type.startsWith("image/")) { handleSendMultipleImages(intent); } } else { } }
/** * 响应从图片分享进入的事件 * * @param intent */ private void respondExternal(Intent intent) { currentFragment = (TalkPubFragment) mFragment.get(); String action = intent.getAction(); String type = intent.getType(); if (Intent.ACTION_SEND.equals(action) && type != null) { if ("text/plain".equals(type)) { handleSendText(intent); // Handle text being sent } else if (type.startsWith("image/")) { handleSendImage(intent); // Handle single image being sent } } else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) { if (type.startsWith("image/")) { handleSendMultipleImages(intent); // Handle multiple images // being sent } } else { // Handle other intents, such as being started from the home screen } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Fabric.with(this, new Crashlytics()); setContentView(R.layout.activity_compose); Toolbar toolbar = (Toolbar) findViewById(R.id.sharelock_toolbar); setSupportActionBar(toolbar); getSupportActionBar().setTitle(null); bus = EventBus.getDefault(); handler = new Handler(); Intent intent = getIntent(); String action = intent.getAction(); String type = intent.getType(); String sharedText = null; if (Intent.ACTION_SEND.equals(action) && type != null) { if ("text/plain".equals(type)) { sharedText = intent.getStringExtra(Intent.EXTRA_TEXT); } } if (savedInstanceState == null) { final SecretInputFragment fragment = new SecretInputFragment(); if (sharedText != null) { Bundle arguments = new Bundle(); arguments.putString(SecretInputFragment.SECRET_INPUT_FRAGMENT_SECRET_ARGUMENT, sharedText); fragment.setArguments(arguments); } getSupportFragmentManager() .beginTransaction() .replace(R.id.sharelock_compose_container, fragment) .commit(); } else { secret = savedInstanceState.getParcelable(COMPOSE_CREATED_SECRET); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.app); // Set up a broadcast receiver to receive results IntentFilter filter = new IntentFilter(); filter.addAction(PostResponseReceiver.ACTION_PROGRESS); filter.addAction(PostResponseReceiver.ACTION_RESULT); filter.addCategory(Intent.CATEGORY_DEFAULT); receiver = new PostResponseReceiver(); registerReceiver(receiver, filter); Intent intent = getIntent(); String action = intent.getAction(); // If we are handling a share intent, pass along the intent if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) { doPost(intent); } }
/** Returns true the intent URI targets a note. Either an edit/view or insert. */ boolean isNoteIntent(final Intent intent) { if (intent == null) { return false; } if (Intent.ACTION_SEND.equals(intent.getAction()) || "com.google.android.gm.action.AUTO_SEND".equals(intent.getAction())) { return true; } if (intent.getData() != null && (Intent.ACTION_EDIT.equals(intent.getAction()) || Intent.ACTION_VIEW.equals(intent.getAction()) || Intent.ACTION_INSERT.equals(intent.getAction())) && (intent.getData().getPath().startsWith(LegacyDBHelper.NotePad.Notes.PATH_VISIBLE_NOTES) || intent.getData().getPath().startsWith(LegacyDBHelper.NotePad.Notes.PATH_NOTES) || intent.getData().getPath().startsWith(Task.URI.getPath())) && !intent.getData().getPath().startsWith(TaskList.URI.getPath())) { return true; } return false; }
private void handleIntent(Intent intent) { String action = intent.getAction(); String type = intent.getType(); getAllAlbums(); if (Intent.ACTION_SEARCH.equals(action)) { String query = intent.getStringExtra(SearchManager.QUERY); Log.d("CMPE137", "Query: " + query); mSendPhoto = false; } else { mSendPhoto = true; if (Intent.ACTION_SEND.equals(action) && type != null) { if (type.startsWith("image/")) { handleSendImage(intent); // Handle single image being sent } } else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) { if (type.startsWith("image/")) { handleSendMultipleImages(intent); // Handle multiple images being sent } } } }
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.storeindevice); Intent intent = getIntent(); Bundle extras = intent.getExtras(); String action = intent.getAction(); // if this is from the share menu if (Intent.ACTION_SEND.equals(action)) { if (extras.containsKey(Intent.EXTRA_STREAM)) { try { // Check VisualREST authentication parameters SharedPreferences prefs = getSharedPreferences("AccountSettings", MODE_PRIVATE); String username = prefs.getString("username", ""); String password = prefs.getString("password", ""); Intent intentUpload = new Intent(getBaseContext(), HTTPRequestService.class); Bundle extrasUpload = new Bundle(); extrasUpload.putInt("action", 5); // "uploadMetadata" extrasUpload.putString("username", username); extrasUpload.putString("password", password); extrasUpload.putBundle("extras", extras); intentUpload.putExtras(extrasUpload); startService(intentUpload); } catch (Exception e) { Log.e(this.getClass().getName(), e.toString()); } } else if (extras.containsKey(Intent.EXTRA_TEXT)) { return; } } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.statusnewactivity_layout); initLayout(); Intent intent = getIntent(); String action = intent.getAction(); String type = intent.getType(); if (Intent.ACTION_SEND.equals(action) && type != null) { if ("text/plain".equals(type)) { handleSendText(intent); } else if (type.startsWith("image/")) { handleSendImage(intent); } } else { handleNormalOperation(intent); } if (getEmotionsTask == null || getEmotionsTask.getStatus() == MyAsyncTask.Status.FINISHED) { getEmotionsTask = new GetEmotionsTask(); getEmotionsTask.executeOnExecutor(MyAsyncTask.THREAD_POOL_EXECUTOR); } }
protected void handleSendEvent() { // Get intent, action and MIME type Intent intent = getIntent(); String action = intent.getAction(); String type = intent.getType(); if (Intent.ACTION_SEND.equals(action) && type != null) { if ("text/plain".equals(type)) { // Handle text being sent String url = extractUrlFromText(intent.getStringExtra(Intent.EXTRA_TEXT)); if (url == null || url == "") finish(); etUrl.setText(url); } else if (type.startsWith("image/")) {; // Handle single image being sent } } else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) { if (type.startsWith("image/")) {; // Handle multiple images being sent } } else { // Handle other intents, such as being started from the home screen } }
@Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); // Get intent, action and MIME type Intent intent = getIntent(); String action = intent.getAction(); String type = intent.getType(); if (Intent.ACTION_SEND.equals(action) && type != null) { if ("text/plain".equals(type)) { handleSendText(intent); // Handle text being sent } else if (type.startsWith("image/")) { handleSendImage(intent); // Handle single image being sent } } else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) { if (type.startsWith("image/")) { handleSendMultipleImages(intent); // Handle multiple images being sent } } else { // Handle other intents, such as being started from the home screen } }
@Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_addplace); connectViewElements(); // Get intent, action and MIME type Intent intent = getIntent(); String action = intent.getAction(); String type = intent.getType(); if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) { origin = 0; // NFC getNfcTagInfo(intent); } else { if (Intent.ACTION_SEND.equals(action) && type != null) { origin = 1; // Photo getPhotoInfo(type, intent); } // String photoPath = getIntent().getStringExtra("placePhotoPath"); if (placePic != null) { Bitmap ThumbImage = PictureUtility.decodeSampledBitmapFromPath( PictureUtility.getRealPathFromURI(imageUri, SavePlace.this), 400, 400); placePic.setImageBitmap(ThumbImage); } } savePlace.setOnClickListener( new OnClickListener() { public void onClick(View v) { switch (origin) { case 0: // nfc newPlace.setAudioLocation(audioLoc); newPlace.setNote(commentBlock.getText().toString()); newPlace.setVideoLocation(videoLoc); PropertiesUtility.writePlaceToFile(v.getContext(), newPlace); Intent intent = new Intent(v.getContext(), ActivityMap.class); intent.putExtra("origin", origin); Places.getItems().add(newPlace); startActivity(intent); finish(); break; case 1: // photo String picPath = PictureUtility.getRealPathFromURI(imageUri, SavePlace.this); int[] tempCoords = PictureUtility.isCoordinatesValid(PictureUtility.getCoordsFromPhoto(picPath)) ? PictureUtility.getCoordsFromPhoto(picPath) : currentCoordinates; if (PictureUtility.isCoordinatesValid(tempCoords)) { newPlace = new Place(new GeoPoint(tempCoords[0], tempCoords[1]), "", ""); newPlace.setAudioLocation(audioLoc); newPlace.setNote(commentBlock.getText().toString()); newPlace.setVideoLocation(videoLoc); newPlace.setPhotoLocation( PictureUtility.getRealPathFromURI(imageUri, SavePlace.this)); PropertiesUtility.writePlaceToFile(v.getContext(), newPlace); Intent intent3 = new Intent(v.getContext(), ActivityMap.class); Places.getItems().add(newPlace); intent3.putExtra("origin", origin); startActivity(new Intent(v.getContext(), HomePage.class)); startActivity(intent3); finish(); } else { Intent intent2 = new Intent(v.getContext(), ChooseMethodForLocation.class); intent2.putExtra("origin", origin); startActivityForResult(intent2, 1); } break; default: System.err.println("Unknown source type"); break; } } }); recordAudio.setOnClickListener( new OnClickListener() { public void onClick(View v) { Button recBt = (Button) v; if (recBt.getText().equals(v.getResources().getString(R.string.rec_start_button))) { recBt.setText(v.getResources().getString(R.string.rec_stop_button)); mRecorder = AudioUtility.getMediaRecorder(); audioLoc = AudioUtility.startRecording(mRecorder); } else { recBt.setText(v.getResources().getString(R.string.rec_start_button)); AudioUtility.stopRecording(mRecorder); } } }); playAudio.setOnClickListener( new OnClickListener() { public void onClick(View v) { if (playAudio.getText().equals(v.getResources().getString(R.string.rec_play_button))) { if (audioLoc.length() > 5) { playAudio.setText(v.getResources().getString(R.string.rec_stop_button)); mPlayer = AudioUtility.startPlaying(audioLoc); } } else { playAudio.setText(v.getResources().getString(R.string.rec_play_button)); AudioUtility.stopPlaying(mPlayer); } } }); recordVideo.setOnClickListener( new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); Uri fileUri = VideoUtility.getOutputMediaFileUri(VideoUtility.MEDIA_TYPE_VIDEO); intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0); startActivityForResult(intent, VideoUtility.CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE); } }); playVideo.setOnClickListener( new OnClickListener() { public void onClick(View v) { if (videoLoc.length() > 5) { Intent intent = new Intent(v.getContext(), PlayVideo.class); intent.putExtra("videoLoc", videoLoc); startActivityForResult(intent, 0); } } }); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.add_task); ArrayList<Task> tasks; try { tasks = TodoUtil.loadTasksFromFile(); } catch (IOException e) { Log.e(TAG, e.getMessage(), e); tasks = new ArrayList<Task>(); } final Intent intent = getIntent(); final String action = intent.getAction(); // create shortcut and exit // create shortcut and exit if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) { Log.d(TAG, "Setting up shortcut icon"); setupShortcut(); finish(); return; } else if (Intent.ACTION_SEND.equals(action)) { Log.d(TAG, "Share"); share_text = (String) intent.getCharSequenceExtra(Intent.EXTRA_TEXT); Log.d(TAG, share_text); } m_app = (TodoApplication) getApplication(); // title bar label titleBarLabel = (TextView) findViewById(R.id.title_bar_label); // text final EditText textInputField = (EditText) findViewById(R.id.taskText); textInputField.setGravity(Gravity.TOP); if (share_text != null) { textInputField.setText(share_text); } Task task = (Task) getIntent().getSerializableExtra(Constants.EXTRA_TASK); if (task != null) { m_backup = task; textInputField.setText(task.inFileFormat()); setTitle(R.string.update); titleBarLabel.setText(R.string.update); } else { setTitle(R.string.addtask); titleBarLabel.setText(R.string.addtask); } textInputField.setSelection(textInputField.getText().toString().length()); // priorities priorities = (Spinner) findViewById(R.id.priorities); final ArrayList<String> prioArr = new ArrayList<String>(); prioArr.add("Priority"); prioArr.addAll(Priority.rangeInCode(Priority.A, Priority.E)); priorities.setAdapter(Util.newSpinnerAdapter(this, prioArr)); if (m_backup != null) { int index = prioArr.indexOf(m_backup.getPriority().getCode()); priorities.setSelection(index < 0 ? 0 : index); } priorities.setOnItemSelectedListener( new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long id) { int cursorPosition = textInputField.getSelectionStart(); String currentText = textInputField.getText().toString(); Priority priority = Priority.NONE; if (position > 0) { String item = prioArr.get(position); char p = item.charAt(0); priority = Priority.toPriority(p); } String text = PriorityTextSplitter.getInstance().split(currentText).text; textInputField.setText(Strings.insertPadded(text, 0, priority.inFileFormat())); textInputField.setSelection( CursorPositionCalculator.calculate( cursorPosition, currentText, textInputField.getText().toString())); } @Override public void onNothingSelected(AdapterView<?> arg0) {} }); // projects projects = (Spinner) findViewById(R.id.projects); final ArrayList<String> projectsArr = TaskHelper.getProjects(tasks); projectsArr.add(0, "Project"); projects.setAdapter(Util.newSpinnerAdapter(this, projectsArr)); projects.setOnItemSelectedListener( new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long id) { if (position > 0) { int cursorPosition = textInputField.getSelectionStart(); String currentText = textInputField.getText().toString(); String item = "+" + projectsArr.get(position); textInputField.setText(Strings.insertPadded(currentText, cursorPosition, item)); textInputField.setSelection( CursorPositionCalculator.calculate( cursorPosition, currentText, textInputField.getText().toString())); } projects.setSelection(0); } @Override public void onNothingSelected(AdapterView<?> arg0) {} }); // contexts contexts = (Spinner) findViewById(R.id.contexts); final ArrayList<String> contextsArr = TaskHelper.getContexts(tasks); contextsArr.add(0, "Context"); contexts.setAdapter(Util.newSpinnerAdapter(this, contextsArr)); contexts.setOnItemSelectedListener( new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long id) { if (position > 0) { int cursorPosition = textInputField.getSelectionStart(); String currentText = textInputField.getText().toString(); String item = "@" + contextsArr.get(position); textInputField.setText(Strings.insertPadded(currentText, cursorPosition, item)); textInputField.setSelection( CursorPositionCalculator.calculate( cursorPosition, currentText, textInputField.getText().toString())); } contexts.setSelection(0); } @Override public void onNothingSelected(AdapterView<?> arg0) {} }); // cancel Button cancel = (Button) findViewById(R.id.cancel); cancel.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { finish(); } }); // add Button addBtn = (Button) findViewById(R.id.addTask); if (m_backup != null) { addBtn.setText(R.string.update); } addBtn.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // strip line breaks final String input = textInputField.getText().toString().replaceAll("\\r\\n|\\r|\\n", " "); TodoApplication app = (TodoApplication) getApplication(); DropboxAPI api = app.getAPI(); new AsyncTask<Object, Void, Boolean>() { protected void onPreExecute() { m_ProgressDialog = ProgressDialog.show(AddTask.this, getTitle(), "Please wait...", true); } @Override protected Boolean doInBackground(Object... params) { try { DropboxAPI api = (DropboxAPI) params[0]; Task task = (Task) params[1]; String input = (String) params[2]; TodoApplication m_app = (TodoApplication) params[3]; if (api != null) { if (task != null) { task.update(input); return m_app.m_util.updateTask(task); } else { return m_app.m_util.addTask(input); } } } catch (Exception e) { Log.e(TAG, "input: " + input + " - " + e.getMessage()); } return false; } protected void onPostExecute(Boolean result) { if (result) { String res = m_backup != null ? getString(R.string.updated_task) : getString(R.string.added_task); Util.showToastLong(AddTask.this, res); finish(); } else { String res = m_backup != null ? getString(R.string.update_task_failed) : getString(R.string.add_task_failed); Util.showToastLong(AddTask.this, res); } } }.execute(api, m_backup, input, m_app); } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ArrayList<String> dirStringList = new ArrayList<String>(); setContentView(R.layout.share); TextView tv = (TextView) findViewById(R.id.filelist); TextView amount = (TextView) findViewById(R.id.amount_of_files); AutoCompleteTextView destination = (AutoCompleteTextView) findViewById(R.id.destination); Spinner exists = (Spinner) findViewById(R.id.exists); /* set default options */ // ((CheckBox) findViewById(R.id.copy)).setChecked(false); /* get existing album(directory) list from ORION_ROOT */ File rootDir = new File(ORION_ROOT); if (rootDir.exists() && rootDir.isDirectory()) { ArrayList<File> dirList = new ArrayList<File>(Arrays.asList(rootDir.listFiles())); Iterator<File> e = dirList.iterator(); while (e.hasNext()) { dirStringList.add(((File) e.next()).getName()); } } /* sort and insert default destinations. */ Collections.sort(dirStringList); SimpleDateFormat nowFormatted = new SimpleDateFormat("yyyyMMdd"); default_destination = nowFormatted.format(new Date()).toString(); destination.setText(default_destination); /* remove default folder from 'existing album list'. but Camera */ dirStringList.add(0, "<Camera>"); /* make array and adapter for spinner and auto-completion. */ String[] dirArray = new String[dirStringList.size()]; dirStringList.toArray(dirArray); Log.i("gallorg", "existing dirs(array): " + Arrays.asList(dirArray).toString()); /* disabling drop-down auto-completion. ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, dirArray); destination.setAdapter(adapter); */ ArrayAdapter<String> adapterSpinner = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, dirArray); exists.setAdapter(adapterSpinner); exists.setOnItemSelectedListener(this); /* get selected files and add it to src list (counting and debugging purpose.) */ Intent intent = getIntent(); Bundle extras = intent.getExtras(); if (Intent.ACTION_SEND.equals(intent.getAction())) { if (extras != null) { Uri fileUri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM); fileArray.add(UriUtils.getFileFromUri(fileUri, this)); uriList.add(fileUri); } else { tv.append(", extras == null"); } } else if (Intent.ACTION_SEND_MULTIPLE.equals(intent.getAction())) { if (extras != null) { ArrayList<Uri> uriArray = extras.getParcelableArrayList(Intent.EXTRA_STREAM); uriList.addAll(uriArray); Iterator<Uri> e = uriArray.iterator(); while (e.hasNext()) { fileArray.add(UriUtils.getFileFromUri((Uri) e.next(), this)); } } else { tv.append(", extras == null"); } } /* file list for debugging. */ Iterator<File> e = fileArray.iterator(); while (e.hasNext()) { File file = (File) e.next(); if (file.exists() && file.isFile()) { tv.append("* " + file.getName()); } tv.append("\n"); } Log.d("gallorg", "selected content list: " + uriList.toString()); Log.d("gallorg", "selected file list: " + fileArray.toString()); /* display amount of selected files. */ amount.setText(Integer.toString(fileArray.size())); /* button binding. */ btnMove = (Button) findViewById(R.id.ok); btnCancel = (Button) findViewById(R.id.cancel); btnMove.setOnClickListener(this); btnCancel.setOnClickListener(this); }
@Override protected void onCreate(Bundle savedInstanceState) { Log.i(TAG, "onCreate"); super.onCreate(savedInstanceState); String prefsName = getString(R.string.prefs_name); String destinationKey = getString(R.string.destination_key); prefs = getSharedPreferences(prefsName, Context.MODE_PRIVATE); thisFolder = new File( prefs.getString( destinationKey, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) .getPath() + "/SaveThis")); if (!thisFolder.exists()) if (!thisFolder.mkdirs()) Toast.makeText(this, "please check external write permission", Toast.LENGTH_LONG).show(); Intent intent = getIntent(); if (intent != null) { String action = intent.getAction(); if (Intent.ACTION_MAIN.equals(action)) { setContentView(R.layout.activity_main); textPath = (TextView) findViewById(R.id.textPath); textPath.setText(thisFolder.getPath()); textPath.setOnClickListener(this); btnChange = (Button) findViewById(R.id.btnChange); btnChange.setOnClickListener(this); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeAsUpIndicator(R.mipmap.ic_launcher); } } else if (Intent.ACTION_SEND.equals(action)) { String type = intent.getType(); if ("application/octet-stream".equals(type)) { Uri stream = intent.getParcelableExtra(Intent.EXTRA_STREAM); if (stream != null) { String scheme = stream.getScheme(); if ("file".equals(scheme)) { File source = new File(stream.getPath()); File destination = new File(thisFolder, stream.getLastPathSegment()); if (copyFile(source, destination)) Toast.makeText(this, "success~", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "stream scheme mismatch: " + scheme, Toast.LENGTH_LONG).show(); } } else { Toast.makeText(this, "stream is null", Toast.LENGTH_LONG).show(); } } else if (type != null) { Toast.makeText(this, "intent type mismatch: " + type, Toast.LENGTH_LONG).show(); } else { Toast.makeText(this, "intent type is null", Toast.LENGTH_LONG).show(); } finish(); } else if (action != null) { Toast.makeText(this, "intent action mismatch: " + action, Toast.LENGTH_LONG).show(); } else { Toast.makeText(this, "intent action is null", Toast.LENGTH_LONG).show(); } } else { Toast.makeText(this, "intent is null", Toast.LENGTH_LONG).show(); } }