use of org.wordpress.android.editor.EditorMediaUploadListener in project WordPress-Android by wordpress-mobile.
the class EditorExampleActivity method onActivityResult.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (data == null) {
return;
}
Uri mediaUri = data.getData();
MediaFile mediaFile = new MediaFile();
String mediaId = String.valueOf(System.currentTimeMillis());
mediaFile.setMediaId(mediaId);
mediaFile.setVideo(mediaUri.toString().contains("video"));
switch(requestCode) {
case ADD_MEDIA_ACTIVITY_REQUEST_CODE:
mEditorFragment.appendMediaFile(mediaFile, mediaUri.toString(), null);
if (mEditorFragment instanceof EditorMediaUploadListener) {
simulateFileUpload(mediaId, mediaUri.toString());
}
break;
case ADD_MEDIA_FAIL_ACTIVITY_REQUEST_CODE:
mEditorFragment.appendMediaFile(mediaFile, mediaUri.toString(), null);
if (mEditorFragment instanceof EditorMediaUploadListener) {
simulateFileUploadFail(mediaId, mediaUri.toString());
}
break;
case ADD_MEDIA_SLOW_NETWORK_REQUEST_CODE:
mEditorFragment.appendMediaFile(mediaFile, mediaUri.toString(), null);
if (mEditorFragment instanceof EditorMediaUploadListener) {
simulateSlowFileUpload(mediaId, mediaUri.toString());
}
break;
}
}
use of org.wordpress.android.editor.EditorMediaUploadListener in project WordPress-Android by wordpress-mobile.
the class EditPostActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
((WordPress) getApplication()).component().inject(this);
mDispatcher.register(this);
setContentView(R.layout.new_edit_post_activity);
if (savedInstanceState == null) {
mSite = (SiteModel) getIntent().getSerializableExtra(WordPress.SITE);
} else {
mSite = (SiteModel) savedInstanceState.getSerializable(WordPress.SITE);
}
// Check whether to show the visual editor
PreferenceManager.setDefaultValues(this, R.xml.account_settings, false);
//AppPrefs.setAztecEditorAvailable(true);
//AppPrefs.setAztecEditorEnabled(true);
mShowAztecEditor = AppPrefs.isAztecEditorEnabled();
mShowNewEditor = AppPrefs.isVisualEditorEnabled();
// Set up the action bar.
final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
FragmentManager fragmentManager = getFragmentManager();
Bundle extras = getIntent().getExtras();
String action = getIntent().getAction();
if (savedInstanceState == null) {
if (!getIntent().hasExtra(EXTRA_POST) || Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action) || NEW_MEDIA_POST.equals(action) || getIntent().hasExtra(EXTRA_IS_QUICKPRESS)) {
if (getIntent().hasExtra(EXTRA_QUICKPRESS_BLOG_ID)) {
// QuickPress might want to use a different blog than the current blog
int localSiteId = getIntent().getIntExtra(EXTRA_QUICKPRESS_BLOG_ID, -1);
mSite = mSiteStore.getSiteByLocalId(localSiteId);
}
mIsPage = extras.getBoolean(EXTRA_IS_PAGE);
mIsNewPost = true;
if (mSite == null) {
showErrorAndFinish(R.string.blog_not_found);
return;
}
if (!mSite.isVisible()) {
showErrorAndFinish(R.string.error_blog_hidden);
return;
}
// Create a new post
List<Long> categories = new ArrayList<>();
categories.add((long) SiteSettingsInterface.getDefaultCategory(WordPress.getContext()));
String postFormat = SiteSettingsInterface.getDefaultFormat(WordPress.getContext());
mPost = mPostStore.instantiatePostModel(mSite, mIsPage, categories, postFormat);
} else if (extras != null) {
// Load post passed in extras
mPost = (PostModel) extras.getSerializable(EXTRA_POST);
if (mPost != null) {
mOriginalPost = mPost.clone();
mIsPage = mPost.isPage();
}
} else {
// A postId extra must be passed to this activity
showErrorAndFinish(R.string.post_not_found);
return;
}
} else {
mDroppedMediaUris = savedInstanceState.getParcelable(STATE_KEY_DROPPED_MEDIA_URIS);
if (savedInstanceState.containsKey(STATE_KEY_ORIGINAL_POST)) {
try {
mPost = (PostModel) savedInstanceState.getSerializable(STATE_KEY_CURRENT_POST);
mOriginalPost = (PostModel) savedInstanceState.getSerializable(STATE_KEY_ORIGINAL_POST);
} catch (ClassCastException e) {
mPost = null;
}
}
mEditorFragment = (EditorFragmentAbstract) fragmentManager.getFragment(savedInstanceState, STATE_KEY_EDITOR_FRAGMENT);
if (mEditorFragment instanceof EditorMediaUploadListener) {
mEditorMediaUploadListener = (EditorMediaUploadListener) mEditorFragment;
}
}
if (mSite == null) {
ToastUtils.showToast(this, R.string.blog_not_found, ToastUtils.Duration.SHORT);
finish();
return;
}
if (mHasSetPostContent = mEditorFragment != null) {
mEditorFragment.setImageLoader(mImageLoader);
}
// Ensure we have a valid post
if (mPost == null) {
showErrorAndFinish(R.string.post_not_found);
return;
}
if (mIsNewPost) {
trackEditorCreatedPost(action, getIntent());
}
setTitle(StringUtils.unescapeHTML(SiteUtils.getSiteNameOrHomeURL(mSite)));
mSectionsPagerAdapter = new SectionsPagerAdapter(fragmentManager);
// Set up the ViewPager with the sections adapter.
mViewPager = (WPViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
mViewPager.setOffscreenPageLimit(2);
mViewPager.setPagingEnabled(false);
// When swiping between different sections, select the corresponding
// tab. We can also use ActionBar.Tab#select() to do this if we have
// a reference to the Tab.
mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
invalidateOptionsMenu();
if (position == PAGE_CONTENT) {
setTitle(StringUtils.unescapeHTML(SiteUtils.getSiteNameOrHomeURL(mSite)));
} else if (position == PAGE_SETTINGS) {
setTitle(mPost.isPage() ? R.string.page_settings : R.string.post_settings);
hidePhotoChooser();
} else if (position == PAGE_PREVIEW) {
setTitle(mPost.isPage() ? R.string.preview_page : R.string.preview_post);
hidePhotoChooser();
savePostAsync(new AfterSavePostListener() {
@Override
public void onPostSave() {
if (mEditPostPreviewFragment != null) {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (mEditPostPreviewFragment != null) {
mEditPostPreviewFragment.loadPost();
}
}
});
}
}
});
}
}
});
ActivityId.trackLastActivity(ActivityId.POST_EDITOR);
}
use of org.wordpress.android.editor.EditorMediaUploadListener in project WordPress-Android by wordpress-mobile.
the class EditorExampleActivity method simulateSlowFileUpload.
private void simulateSlowFileUpload(final String mediaId, final String mediaUrl) {
Thread thread = new Thread() {
@Override
public void run() {
try {
sleep(5000);
float count = (float) 0.1;
while (count < 1.1) {
sleep(2000);
((EditorMediaUploadListener) mEditorFragment).onMediaUploadProgress(mediaId, count);
count += 0.1;
}
MediaFile mediaFile = new MediaFile();
mediaFile.setMediaId(MEDIA_REMOTE_ID_SAMPLE);
mediaFile.setFileURL(mediaUrl);
((EditorMediaUploadListener) mEditorFragment).onMediaUploadSucceeded(mediaId, mediaFile);
if (mFailedUploads.containsKey(mediaId)) {
mFailedUploads.remove(mediaId);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
thread.start();
}
use of org.wordpress.android.editor.EditorMediaUploadListener in project WordPress-Android by wordpress-mobile.
the class EditorExampleActivity method simulateFileUpload.
private void simulateFileUpload(final String mediaId, final String mediaUrl) {
Thread thread = new Thread() {
@Override
public void run() {
try {
float count = (float) 0.1;
while (count < 1.1) {
sleep(500);
((EditorMediaUploadListener) mEditorFragment).onMediaUploadProgress(mediaId, count);
count += 0.1;
}
MediaFile mediaFile = new MediaFile();
mediaFile.setMediaId(MEDIA_REMOTE_ID_SAMPLE);
mediaFile.setFileURL(mediaUrl);
((EditorMediaUploadListener) mEditorFragment).onMediaUploadSucceeded(mediaId, mediaFile);
if (mFailedUploads.containsKey(mediaId)) {
mFailedUploads.remove(mediaId);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
thread.start();
}
Aggregations