/*
ApicAday - Everyday.. is different, your mood, your life.
Copyright (c) 2010
Oliver Selinger <oliver.selinger@autburst.com>,
Michael Greifeneder <michael.greifeneder@autburst.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.autburst.picture;
import java.net.URLEncoder;
import org.apache.commons.codec.binary.Base64;
import android.app.Activity;
import android.app.NotificationManager;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Toast;
import com.autburst.picture.facebook.FacebookActivity;
public class FinishedUploadActivity extends Activity {
public static final String UPLOAD_FINISHED = "com.autburst.picture.UPLOAD_FINISHED";
private static final String TAG = FinishedUploadActivity.class.getName();
private ImageButton previewButton;
private ImageButton facebookButton;
private ImageButton sendButton;
private String albumName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.finished);
albumName = getIntent().getStringExtra(UploadService.ALBUM_NAME);
setButtons();
//Toast.makeText(this, "FinishedUploadActivity called for " + albumName, Toast.LENGTH_LONG);
Log.d(TAG, "FinishedUploadActivity called for " + albumName);
NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mgr.cancel(albumName, Uploader.NOTE_ID);
}
private void setButtons() {
previewButton = (ImageButton) findViewById(R.id.finishedPreview);
previewButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
showDemoVideo();
}
});
facebookButton = (ImageButton) findViewById(R.id.finishedFacebook);
facebookButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
postToFacebook();
}
});
sendButton = (ImageButton) findViewById(R.id.finishedSend);
sendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
sendLink();
}
});
}
private void showDemoVideo() {
//Preview Video
Intent intent = new Intent(this, VideoDemoActivity.class);
intent.putExtra("albumName", albumName);
startActivity(intent);
}
private void postToFacebook() {
String videoUrl = createVideoUrl();
if (videoUrl == null) {
return;
}
Log.d(TAG, "videoUrl for FB: " + videoUrl);
videoUrl = URLEncoder.encode(videoUrl);
Intent intent = new Intent(this, FacebookActivity.class);
Resources res = getResources();
intent.putExtra("application_id", "126691144034061");
intent.putExtra("message", String.format(res.getString(R.string.fb_message), new String(Base64.decodeBase64(albumName.getBytes()))));
intent.putExtra("link", videoUrl);
intent.putExtra("name", "ApicAday");
intent.putExtra("caption", res.getString(R.string.fb_caption));
intent.putExtra("description", "");
intent.putExtra("picture", "http://server.autburst.com/ApicAday/facebook_image_finish.png");
startActivity(intent);
}
/**
* Returns video URL or null if no valid URL available
* @return
*/
private String createVideoUrl() {
String savedVideoId = getSharedPreferences(Utilities.PIC_STORE, 0).getString(albumName + ".videoId", null);
if (savedVideoId == null) {
Toast.makeText(this, R.string.invalid_video_url, Toast.LENGTH_SHORT).show();
return null;
}
else {
boolean isPortrait = getSharedPreferences(Utilities.PIC_STORE, 0).getBoolean(albumName + ".portrait", true);
String videoUrl = "http://server.autburst.com/ApicAday/" + (isPortrait?"portrait":"landscape") + ".html?videoId=" + savedVideoId + "&album=" + albumName;
return videoUrl;
}
}
private void sendLink() {
String url = createVideoUrl();
if (url == null) {
return;
}
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
Resources res = getResources();
i.putExtra(Intent.EXTRA_SUBJECT, res.getString(R.string.downloadlink));
i.putExtra(Intent.EXTRA_TEXT, url);
startActivity(Intent.createChooser(i, res.getString(R.string.sendlink)));
}
}