Android Open Source - rsmonitor-heartrate Upload Photo Result Dialog






From Project

Back to project page rsmonitor-heartrate.

License

The source code is released under:

GNU General Public License

If you think the Android project rsmonitor-heartrate listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.facebook.android;
//from  ww w.  j a va2s .com
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.text.util.Linkify;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.renaultsport.heartrate.R;

public class UploadPhotoResultDialog extends Dialog {

    private String response, photo_id;
    private TextView mOutput, mUsefulTip;
    private Button mViewPhotoButton, mTagPhotoButton;
    private ImageView mUploadedPhoto;
    private Activity activity;
    private ProgressDialog dialog;
    private boolean hidePhoto = false;
    private Handler mHandler;

    public UploadPhotoResultDialog(Activity activity, String title, String response) {
        super(activity);
        this.activity = activity;
        this.response = response;
        setTitle(title);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mHandler = new Handler();

        setContentView(R.layout.upload_photo_response);
        LayoutParams params = getWindow().getAttributes();
        params.width = LayoutParams.FILL_PARENT;
        params.height = LayoutParams.FILL_PARENT;
        getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);

        mOutput = (TextView) findViewById(R.id.apiOutput);
        mUsefulTip = (TextView) findViewById(R.id.usefulTip);
        mViewPhotoButton = (Button) findViewById(R.id.view_photo_button);
        mTagPhotoButton = (Button) findViewById(R.id.tag_photo_button);
        mUploadedPhoto = (ImageView) findViewById(R.id.uploadedPhoto);

        JSONObject json;
        try {
            json = Util.parseJson(response);
            final String photo_id = json.getString("id");
            this.photo_id = photo_id;

            mOutput.setText(json.toString(2));
            mUsefulTip.setText(activity.getString(R.string.photo_tip));
            Linkify.addLinks(mUsefulTip, Linkify.WEB_URLS);

            mViewPhotoButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (hidePhoto) {
                        mViewPhotoButton.setText(R.string.view_photo);
                        hidePhoto = false;
                        mUploadedPhoto.setImageBitmap(null);
                    } else {
                        hidePhoto = true;
                        mViewPhotoButton.setText(R.string.hide_photo);
                        /*
                         * Source tag: view_photo_tag
                         */
                        Bundle params = new Bundle();
                        params.putString("fields", "picture");
                        dialog = ProgressDialog.show(activity, "",
                                activity.getString(R.string.please_wait), true, true);
                        dialog.show();
                        Utility.mAsyncRunner.request(photo_id, params,
                                new ViewPhotoRequestListener());
                    }
                }
            });
            mTagPhotoButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    /*
                     * Source tag: tag_photo_tag
                     */
                    setTag();
                }
            });
        } catch (JSONException e) {
            setText(activity.getString(R.string.exception) + e.getMessage());
        } catch (FacebookError e) {
            setText(activity.getString(R.string.facebook_error) + e.getMessage());
        }
    }

    public void setTag() {
        String relativePath = photo_id + "/tags/" + Utility.userUID;
        Bundle params = new Bundle();
        params.putString("x", "5");
        params.putString("y", "5");
        Utility.mAsyncRunner.request(relativePath, params, "POST", new TagPhotoRequestListener(),
                null);
    }

    public class ViewPhotoRequestListener extends BaseRequestListener {

        @Override
        public void onComplete(final String response, final Object state) {
            try {
                JSONObject json = Util.parseJson(response);
                final String pictureURL = json.getString("picture");
                if (TextUtils.isEmpty(pictureURL)) {
                    setText("Error getting \'picture\' field of the photo");
                } else {
                    mHandler.post(new Runnable() {
                        @Override
                        public void run() {
                            new FetchImage().execute(pictureURL);
                        }
                    });
                }
            } catch (JSONException e) {
                dialog.dismiss();
                setText(activity.getString(R.string.exception) + e.getMessage());
            } catch (FacebookError e) {
                dialog.dismiss();
                setText(activity.getString(R.string.facebook_error) + e.getMessage());
            }
        }

        public void onFacebookError(FacebookError error) {
            dialog.dismiss();
            setText(activity.getString(R.string.facebook_error) + error.getMessage());
        }
    }

    public class TagPhotoRequestListener extends BaseRequestListener {

        @Override
        public void onComplete(final String response, final Object state) {
            if (response.equals("true")) {
                String message = "User tagged in photo at (5, 5)" + "\n";
                message += "Api Response: " + response;
                setText(message);
            } else {
                setText("User could not be tagged.");
            }
        }

        public void onFacebookError(FacebookError error) {
            setText(activity.getString(R.string.facebook_error) + error.getMessage());
        }
    }

    public void setText(final String txt) {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                mOutput.setText(txt);
            }
        });
    }

    private class FetchImage extends AsyncTask<String, Void, Bitmap> {
        @Override
        protected Bitmap doInBackground(String... urls) {
            return Utility.getBitmap(urls[0]);
        }

        @Override
        protected void onPostExecute(Bitmap result) {
            dialog.dismiss();
            mUploadedPhoto.setImageBitmap(result);
        }
    }
}




Java Source Code List

com.facebook.android.AsyncFacebookRunner.java
com.facebook.android.BaseDialogListener.java
com.facebook.android.BaseRequestListener.java
com.facebook.android.DialogError.java
com.facebook.android.FQLQuery.java
com.facebook.android.FacebookError.java
com.facebook.android.FacebookFunctions.java
com.facebook.android.Facebook.java
com.facebook.android.FbDialog.java
com.facebook.android.FieldsConnectionsDialog.java
com.facebook.android.FriendsGetProfilePics.java
com.facebook.android.FriendsList.java
com.facebook.android.GraphExplorer.java
com.facebook.android.IntentUriHandler.java
com.facebook.android.LoginButton.java
com.facebook.android.PermissionsDialog.java
com.facebook.android.Places.java
com.facebook.android.SessionEvents.java
com.facebook.android.SessionStore.java
com.facebook.android.TokenRefreshDialog.java
com.facebook.android.UpdateStatusResultDialog.java
com.facebook.android.UploadPhotoResultDialog.java
com.facebook.android.Util.java
com.facebook.android.Utility.java
com.googlecode.android.widgets.DateSlider.AlternativeDateSlider.java
com.googlecode.android.widgets.DateSlider.CustomDateSlider.java
com.googlecode.android.widgets.DateSlider.DateSlider.java
com.googlecode.android.widgets.DateSlider.DateTimeSlider.java
com.googlecode.android.widgets.DateSlider.DefaultDateSlider.java
com.googlecode.android.widgets.DateSlider.MonthYearDateSlider.java
com.googlecode.android.widgets.DateSlider.ScrollLayout.java
com.googlecode.android.widgets.DateSlider.TimeSlider.java
com.googlecode.android.widgets.DateSlider.TimeView.java
com.renaultsport.heartrate.ActivityMain.java
com.renaultsport.heartrate.ActivityRecord.java
com.renaultsport.heartrate.ActivitySplash.java
com.renaultsport.heartrate.ActivityUpload.java
com.renaultsport.heartrate.ActivityVideoReader.java
com.renaultsport.heartrate.ActivityWarning.java
com.renaultsport.heartrate.MainApplication.java
com.renaultsport.heartrate.utils.CaptureCamera.java
com.renaultsport.heartrate.utils.ClientThread.java
com.renaultsport.heartrate.utils.Constants.java
com.renaultsport.heartrate.utils.RunEncoder.java
team.stride.tabs.TabGroupActivity.java