Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package se.meanalytics.loopme20.CreateNewLoop;
- import android.content.BroadcastReceiver;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.content.IntentFilter;
- import android.database.Cursor;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import android.graphics.Color;
- import android.graphics.Matrix;
- import android.graphics.Xfermode;
- import android.media.ExifInterface;
- import android.net.Uri;
- import android.os.Vibrator;
- import android.provider.MediaStore;
- import android.provider.OpenableColumns;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.support.v7.app.AlertDialog;
- import android.text.Editable;
- import android.text.TextWatcher;
- import android.view.Gravity;
- import android.view.MotionEvent;
- import android.view.View;
- import android.view.animation.Animation;
- import android.view.animation.BounceInterpolator;
- import android.view.animation.ScaleAnimation;
- import android.widget.CheckBox;
- import android.widget.EditText;
- import android.widget.ImageView;
- import android.widget.LinearLayout;
- import android.widget.ProgressBar;
- import android.widget.RelativeLayout;
- import android.widget.TableLayout;
- import android.widget.TextView;
- import android.widget.Toast;
- import com.google.android.gms.analytics.HitBuilders;
- import com.google.android.gms.analytics.Tracker;
- import com.loopj.android.http.JsonHttpResponseHandler;
- import org.apache.commons.io.FilenameUtils;
- import Models.Loop;
- import cz.msebera.android.httpclient.Header;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.io.ByteArrayOutputStream;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.text.DateFormat;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.TimeZone;
- import Models.Group;
- import Models.Tag;
- import Models.Task;
- import se.meanalytics.loopme20.R;
- import se.meanalytics.loopme20.fileManagement.FileManager;
- import se.meanalytics.loopme20.webStuff.WebApiMethods;
- import v3.Log;
- import v3.LoopMeApp;
- public class CreateNewLoop extends AppCompatActivity implements View.OnClickListener {
- // Google Analytics
- Tracker tracker;
- private int selectedFeeling = -90; // must select feeling
- private static final int ENABLED = 255;
- private static final int DISABLED = 100;
- private boolean can_post_anonymous;
- private boolean isTagsAvailable = false;
- AlertDialog.Builder dialogBuilder;
- public static final String TAG = "CreateNewLoop";
- public static final String GROUP_ANONYMOUS = "anony";
- private ArrayList<String> selectedTagsArray;
- private ArrayList<String> roleTypeArray = new ArrayList<>();
- private Task preselectedTag;
- private WebApiMethods mWebApiMethods;
- private TextView recipients_textView;
- private TextView approve_textView;
- private TextView group_name;
- private TextView anonymous_text;
- private ImageView one;
- private ImageView two;
- private ImageView three;
- private ImageView four;
- private ImageView five;
- private ImageView back_button;
- private EditText input_message;
- private CheckBox anonymous_checkbox;
- private RelativeLayout send_loop_button;
- private LinearLayout linearTags;
- private LinearLayout anonymous_layout;
- private LinearLayout followup_body_layout;
- private ProgressBar loading_progressBar;
- private TextView can_read_TextView;
- private TextView can_read_and_approve_TextView;
- public File file1;
- // TODO change this value depending on physical screen size in inch...
- private static final int BIG_TEXT_SIZE = 13;
- private static final int MEDIUM_TEXT_SIZE = 10;
- private static final int SMALL_TEXT_SIZE = 9;
- public static final int BIG_TAG_COLUMS = 3;
- //V3
- private Group group;
- private Task task;
- private Tag tags;
- private LinearLayout task_description_layout;
- private RelativeLayout choose_task_layout;
- private RelativeLayout choose_task_button;
- private RelativeLayout change_task_button;
- private RelativeLayout can_be_approved;
- private TextView feeling_and_tags_text;
- private TextView task_name;
- private TextView task_description;
- private ArrayList<Task> taskList;
- private ArrayList<Tag> tagsList;
- private ImageView task_information_icon;
- private ImageView text_information_icon;
- private ImageView feeling_information_icon;
- private ImageView members_that_can_read_loop_information_icon;
- private LinearLayout feelings_layout;
- private ImageView ivFile;
- private RelativeLayout rlFile;
- private ImageView ivClose;
- private TextView tvFollowupQuestion;
- private EditText etFollowupAnswer;
- private RelativeLayout rlUploadImage;
- private TextView tvFilename;
- private ImageView ivAddFile, ivRemoveFile;
- private ProgressBar pbSendLoop;
- private TextView tvSendLoop;
- private int loop_type;
- public static final int INFO_LOOP = 1;
- private ArrayList<Tag> freeTargetList = new ArrayList<>();
- private ArrayList<Task> obligatoryTargetList = new ArrayList<>();
- public File file;
- private Intent data;
- int REQUEST_CAMERA = 0, SELECT_PHOTO = 1, SELECT_FILE = 2;
- int imageWidth = 400, imageHeight = 400;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- overridePendingTransition(R.anim.right_slide_in, R.anim.nothing);
- setContentView(R.layout.v3_create_loop);
- // Google Analytics
- // Obtain the shared Tracker instance.
- LoopMeApp application = (LoopMeApp) getApplication();
- tracker = application.getDefaultTracker();
- // Google Analytics
- selectedTagsArray = new ArrayList<>();
- can_be_approved = (RelativeLayout) findViewById(R.id.can_be_approved);
- // Followup question stuff
- followup_body_layout = (LinearLayout) findViewById(R.id.followup_body_layout);
- this.tvFollowupQuestion = (TextView) findViewById(R.id.tvQuestion);
- this.etFollowupAnswer = (EditText) findViewById(R.id.followup_body);
- this.ivAddFile = (ImageView) findViewById(R.id.ivAddFile);
- this.ivRemoveFile = (ImageView) findViewById(R.id.ivRemoveFile);
- followup_body_layout.setVisibility(View.GONE);
- mWebApiMethods = new WebApiMethods(this);
- dialogBuilder = new AlertDialog.Builder(this);
- loading_progressBar = (ProgressBar) findViewById(R.id.loading_progressBar);
- group = (Group) getIntent().getSerializableExtra("group");
- Task recivedTask = (Task) getIntent().getSerializableExtra("task");
- if (recivedTask != null) {
- // Is target
- this.task = recivedTask;
- setChosenTarget(this.task);
- if (!recivedTask.needsApproval)
- can_be_approved.setVisibility(View.GONE);
- } else {
- can_be_approved.setVisibility(View.GONE);
- }
- // Get targets and tags from intent
- taskList = (ArrayList<Task>) getIntent().getSerializableExtra("taskList");
- tagsList = (ArrayList<Tag>) getIntent().getSerializableExtra("tagsList");
- if (taskList != null) {
- obligatoryTargetList.addAll(taskList);
- }
- if (tagsList != null) {
- freeTargetList.addAll(tagsList);
- }
- loop_type = getIntent().getIntExtra("loop_type", 0);
- can_post_anonymous = getIntent().getBooleanExtra(GROUP_ANONYMOUS, false);
- task_information_icon = (ImageView) findViewById(R.id.task_information_icon);
- task_information_icon.setOnClickListener(this);
- text_information_icon = (ImageView) findViewById(R.id.text_information_icon);
- text_information_icon.setOnClickListener(this);
- feeling_information_icon = (ImageView) findViewById(R.id.feeling_information_icon);
- feeling_information_icon.setOnClickListener(this);
- feelings_layout = (LinearLayout) findViewById(R.id.feelings_layout);
- feeling_and_tags_text = (TextView) findViewById(R.id.feeling_and_tags_text);
- members_that_can_read_loop_information_icon = (ImageView) findViewById(R.id.members_that_can_read_loop_information_icon);
- members_that_can_read_loop_information_icon.setOnClickListener(this);
- linearTags = (LinearLayout) findViewById(R.id.tags_layout);
- group_name = (TextView) findViewById(R.id.group_name);
- group_name.setText("" + group.name);
- send_loop_button = (RelativeLayout) findViewById(R.id.send_button);
- send_loop_button.setOnClickListener(this);
- task_description_layout = (LinearLayout) findViewById(R.id.task_description_layout);
- pbSendLoop = (ProgressBar) findViewById(R.id.pbSendLoop);
- pbSendLoop.setVisibility(View.GONE);
- tvSendLoop = (TextView) findViewById(R.id.tvSendLoop);
- task_description_layout.setVisibility(View.GONE);
- choose_task_layout = (RelativeLayout) findViewById(R.id.choose_task_layout);
- choose_task_button = (RelativeLayout) findViewById(R.id.choose_task_button);
- choose_task_button.setOnClickListener(this);
- change_task_button = (RelativeLayout) findViewById(R.id.change_task_button);
- change_task_button.setOnClickListener(this);
- task_name = (TextView) findViewById(R.id.task_name);
- task_description = (TextView) findViewById(R.id.task_description);
- can_read_TextView = (TextView) findViewById(R.id.can_read_TextView);
- can_read_and_approve_TextView = (TextView) findViewById(R.id.can_read_and_approve_TextView);
- TextView header_text = (TextView) findViewById(R.id.header_text);
- // File uploads (Images, Videos, etc..)
- rlFile = (RelativeLayout) findViewById(R.id.rlFile);
- ivFile = (ImageView) findViewById(R.id.ivFile);
- rlUploadImage = (RelativeLayout) findViewById(R.id.rlUploadImage);
- rlUploadImage.setVisibility(View.VISIBLE);
- tvFilename = (TextView) findViewById(R.id.tvUploadFile);
- ivClose = (ImageView) findViewById(R.id.ivClose);
- recipients_textView = (TextView) findViewById(R.id.member_type_that_can_see_loop);
- approve_textView = (TextView) findViewById(R.id.member_type_that_can_see_and_approve_loop);
- recipients_textView.setOnClickListener(this);
- rlFile.setVisibility(View.GONE);
- rlUploadImage.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- selectImage();
- }
- });
- ivClose.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- ivFile.setImageDrawable(null);
- file = null;
- rlFile.setVisibility(View.GONE);
- rlUploadImage.setVisibility(View.VISIBLE);
- }
- });
- String loopTypeStr = "reflection";
- if (loop_type == INFO_LOOP) {
- loopTypeStr = "info";
- header_text.setText(R.string._send_info);
- }
- //getMyRecipients(group._id, loopTypeStr); // Get the number of recipients for this looptype...
- recipients_textView.setText("");
- approve_textView.setText("");
- String roleName = "";
- String roleCanApprove = "";
- String recipientText = recipients_textView.getText().toString();
- if (!recipientText.equals("")) {
- recipientText += ", ";
- }
- String approveText = approve_textView.getText().toString();
- if (!approveText.equals("")) {
- approveText += ", ";
- }
- for (int i = 0; i < group.roles.length; i++) {
- if (group.roles[i].permission.loops.view_others == true) {
- if (group.roles[i].permission.reports.approve == true) {
- if (hasRoleMembers(group.roles[i]._id, group)) {
- roleCanApprove = group.roles[i].name;
- approveText += roleCanApprove + ", ";
- }
- }
- if (hasRoleMembers(group.roles[i]._id, group)) {
- roleName = group.roles[i].name;
- recipientText += roleName + ", ";
- }
- }
- if (group.roles[i].isSubscriber) {
- for (int j = 0; j < group.members_.length; j++) {
- if (group.members_[j].subscriptions == null)
- continue;
- else {
- for (int k = 0; k < group.members_[j].subscriptions.length; k++)
- if (group.members_[j].subscriptions[k]._id != null) {
- if (LoopMeApp.myUser._id.equals(group.members_[j].subscriptions[k]._id)) {
- roleName = group.members_[j].user.name;
- recipientText += roleName + ", ";
- }
- }
- }
- }
- }
- approve_textView.setText(approveText);
- }
- recipientText=recipientText.substring(0,recipientText.length()-2);
- recipients_textView.setText(recipientText);
- anonymous_text = (TextView) findViewById(R.id.anonymous_text);
- anonymous_text.setText(R.string.anonymous);
- anonymous_checkbox = (CheckBox) findViewById(R.id.anonymous_checkbox);
- anonymous_layout = (LinearLayout) findViewById(R.id.anonymous_layout);
- if (task == null) {
- if (can_post_anonymous) {
- anonymous_layout.setVisibility(View.VISIBLE);
- } else {
- anonymous_layout.setVisibility(View.INVISIBLE);
- anonymous_checkbox.setChecked(false);
- }
- } else {
- anonymous_layout.setVisibility(View.GONE);
- feeling_and_tags_text.setText(R.string._feeling_and_tags);
- choose_task_layout.setVisibility(View.GONE);
- change_task_button.setVisibility(View.GONE);
- task_description_layout.setVisibility(View.VISIBLE);
- task_name.setText("" + task.name);
- task_description.setText("" + task.description);
- }
- one = (ImageView) findViewById(R.id.very_sad_smiley_icon);
- one.setOnClickListener(this);
- two = (ImageView) findViewById(R.id.sad_smiley_icon);
- two.setOnClickListener(this);
- three = (ImageView) findViewById(R.id.neutral_smiley_icon);
- three.setOnClickListener(this);
- four = (ImageView) findViewById(R.id.happy_smiley_icon);
- four.setOnClickListener(this);
- five = (ImageView) findViewById(R.id.very_happy_smiley_icon);
- five.setOnClickListener(this);
- back_button = (ImageView) findViewById(R.id.back_button);
- back_button.setOnClickListener(this);
- setAlphaOnSendButton(DISABLED); //Disable the button so user gets notified when all necessary feilds are filled in
- input_message = (EditText) findViewById(R.id.text_body);
- TextWatcher tw = new TextWatcher() {
- public void afterTextChanged(Editable s) {
- }
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- enableButtonHelpMethod();
- }
- };
- input_message.addTextChangedListener(tw);
- etFollowupAnswer.addTextChangedListener(tw);
- input_message.setOnTouchListener(new View.OnTouchListener() {
- @Override
- public boolean onTouch(View v, MotionEvent event) {
- if (v.getId() == R.id.text_body) {
- v.getParent().requestDisallowInterceptTouchEvent(true);
- switch (event.getAction() & MotionEvent.ACTION_MASK) {
- case MotionEvent.ACTION_UP:
- v.getParent().requestDisallowInterceptTouchEvent(false);
- break;
- }
- }
- return false;
- }
- });
- if (loop_type == INFO_LOOP) {
- anonymous_layout.setVisibility(View.GONE);
- feelings_layout.setVisibility(View.GONE);
- choose_task_layout.setVisibility(View.GONE);
- change_task_button.setVisibility(View.GONE);
- task_description_layout.setVisibility(View.GONE);
- followup_body_layout.setVisibility(View.GONE);
- feeling_and_tags_text.setVisibility(View.GONE);
- feeling_information_icon.setVisibility(View.GONE);
- can_read_TextView.setText(R.string._can_be_seen_by);
- }
- if (loop_type != INFO_LOOP) {
- can_read_TextView.setText(R.string._can_be_seen_by);
- can_read_and_approve_TextView.setText(R.string._can_be_seen_and_approved_by);
- getFreeAndObligatoryTargets();
- }
- }
- //This is the handler that will manager to process the broadcast intent
- private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- //Vibrate
- Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
- // Vibrate for 100 milliseconds
- v.vibrate(100);
- }
- };
- @Override
- public void onPause() {
- super.onPause();
- this.unregisterReceiver(mMessageReceiver);
- }
- @Override
- protected void onResume() {
- super.onResume();
- this.registerReceiver(mMessageReceiver, new IntentFilter("unique_name"));
- // Google Analytics
- tracker.setScreenName(TAG);
- tracker.send(new HitBuilders.ScreenViewBuilder().build());
- }
- private void getFreeAndObligatoryTargets() {
- if (group.activeTask != null) {
- for (int i = 0; i < group.activeTask.length; i++) {
- obligatoryTargetList.add(group.activeTask[i]);
- //isTagsAvailable = true;
- }
- } else {
- if (tagsList != null) {
- for (int i = 0; i < tagsList.size(); i++) {
- if (tagsList.get(i).status == 1) {
- freeTargetList.add(tagsList.get(i));
- isTagsAvailable = true;
- }
- }
- }
- }
- drawAvailableTags();
- }
- /* private void getMyRecipients(final String groupId, String loopTyp){ //MÅSTE FIXAS HOS SENO. INGEN LOOPTYPE SKA SKICKAS
- mWebApiMethods.(groupId, loopTyp, new JsonHttpResponseHandler() {
- @Override
- public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
- super.onSuccess(statusCode, headers, response);
- recipients_textView.setText("");
- try {
- for (int i = 0; i < response.length(); i++) {
- String roleId = response.getJSONObject(i).getString("_id");
- String roleName = response.getJSONObject(i).getString("name");
- String recipientText = recipients_textView.getText().toString();
- if (!recipientText.equals("")) {
- recipientText += ", ";
- }
- int count = group.getMembersCountByRole(roleId);
- recipientText += roleName + " (" + count + ")";
- recipients_textView.setText(recipientText);
- }
- } catch (JSONException e) {
- e.printStackTrace();
- }
- synchronized (this) {
- notify();
- }
- }
- @Override
- public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
- super.onFailure(statusCode, headers, throwable, errorResponse);
- //TODO HANDLE THIS
- }
- });
- }*/
- @Override
- public void onClick(View v) {
- switch (v.getId()) {
- case R.id.very_sad_smiley_icon:
- unselectSmileys();
- one.setImageResource(R.mipmap.v3_mood_very_sad_white_icon);
- one.setBackgroundColor(Color.parseColor("#E31B19"));
- one.setAlpha(0.8f);
- selectedFeeling = -2;
- break;
- case R.id.sad_smiley_icon:
- unselectSmileys();
- two.setImageResource(R.mipmap.v3_mood_sad_white_icon);
- two.setBackgroundColor(Color.parseColor("#e6a04e"));
- two.setAlpha(0.8f);
- selectedFeeling = -1;
- break;
- case R.id.neutral_smiley_icon:
- unselectSmileys();
- three.setImageResource(R.mipmap.v3_mood_neutral_white_icon);
- three.setBackgroundColor(Color.parseColor("#299BF2"));
- three.setAlpha(0.8f);
- selectedFeeling = 0;
- break;
- case R.id.happy_smiley_icon:
- unselectSmileys();
- four.setImageResource(R.mipmap.v3_mood_happy_white_icon);
- four.setBackgroundColor(Color.parseColor("#49d394"));
- four.setAlpha(0.8f);
- selectedFeeling = 1;
- break;
- case R.id.very_happy_smiley_icon:
- unselectSmileys();
- five.setImageResource(R.mipmap.v3_mood_very_happy_white_icon);
- five.setBackgroundColor(Color.parseColor("#14CC00"));
- five.setAlpha(0.8f);
- selectedFeeling = 2;
- break;
- case R.id.back_button:
- if (input_message.getText().toString().length() > 0) {
- confirmExitDialog();
- } else {
- finishWithResult(RESULT_CANCELED);
- }
- break;
- case R.id.send_button:
- sendLoopDialog();
- break;
- case R.id.member_type_that_can_see_loop:
- showMembersInDialogue(roleTypeArray);
- break;
- case R.id.choose_task_button:
- showTasksInDialogue(false);
- break;
- case R.id.change_task_button:
- showTasksInDialogue(true);
- break;
- case R.id.task_information_icon:
- showInformationDialogue("task");
- break;
- case R.id.text_information_icon:
- showInformationDialogue("text");
- break;
- case R.id.feeling_information_icon:
- showInformationDialogue("feeling");
- break;
- case R.id.members_that_can_read_loop_information_icon:
- showInformationDialogue("members");
- break;
- }
- try {
- Object[] obj = (Object[]) v.getTag();
- String itemPressed = (String) obj[2];
- TextView tv = (TextView) obj[1];
- if (itemPressed != null) {
- if (!selectedTagsArray.contains(itemPressed)) {
- selectedTagsArray.add(itemPressed);
- v.setBackgroundResource(R.drawable.rounded_corner_tag);
- tv.setTextColor(Color.WHITE);
- } else {
- selectedTagsArray.remove(itemPressed);
- v.setBackgroundResource(R.drawable.rounded_corner_tag_white);
- tv.setTextColor(Color.GRAY);
- }
- ScaleAnimation scaleAnimation = new ScaleAnimation(1, 0.9f, 1, 0.9f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
- scaleAnimation.setInterpolator(new BounceInterpolator());
- scaleAnimation.setDuration(500);
- v.startAnimation(scaleAnimation);
- }
- } catch (NullPointerException npe) {
- }
- enableButtonHelpMethod();
- }
- public void setChosenTarget(Task task) {
- this.task = task;
- if (task != null && task.followupQuestion != null) {
- if (!task.followupQuestion.isEmpty()) {
- this.tvFollowupQuestion.setText(task.followupQuestion);
- this.followup_body_layout.setVisibility(View.VISIBLE);
- } else {
- this.followup_body_layout.setVisibility(View.GONE);
- }
- }
- }
- public Task getChosenTask() {
- return this.task;
- }
- public boolean hasRoleMembers(String roles, Group group) {
- for (int j = 0; j < group.members_.length; j++) {
- if (roles.equals(group.members_[j].role)) {
- return true;
- }
- }
- return false;
- }
- private void showInformationDialogue(String type) {
- String information_text = "";
- String title_text = "";
- switch (type) {
- case "task":
- information_text = getString(R.string._expl_task);
- title_text = getString(R.string._expl_task_title);
- break;
- case "text":
- information_text = getString(R.string._expl_message);
- title_text = getString(R.string._expl_message_title);
- if (loop_type == INFO_LOOP) {
- information_text = getString(R.string._expl_message_info);
- title_text = getString(R.string._expl_message_title_info);
- }
- break;
- case "feeling":
- information_text = getString(R.string._expl_feeling_and_tags);
- title_text = getString(R.string._expl_feeling_and_tags_title);
- break;
- case "members":
- information_text = getString(R.string._expl_who_can_see);
- title_text = getString(R.string._expl_who_can_see_title);
- if (loop_type == INFO_LOOP) {
- information_text = getString(R.string._expl_who_can_see_info);
- title_text = getString(R.string._expl_who_can_see_title_info);
- }
- break;
- }
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setTitle(title_text);
- builder.setMessage(information_text);
- builder.setPositiveButton(getString(R.string.OK), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- //Do nothing
- }
- });
- builder.create().show();
- }
- private void showTasksInDialogue(final Boolean change_back_to_free_loop) {
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setTitle(getString(R.string._choose));
- int my_approved = 0;
- int my_pending = 0;
- int lenght = 0;
- if (group.activeTask != null) {
- ArrayList<String> roles = new ArrayList<>();
- for (int i = 0; i < group.activeTask.length; i++) {
- if (group.activeTask[i].progress != null) {
- for (int j = 0; j < group.activeTask[i].progress.length; j++) {
- for (int k = 0; k < group.activeTask[i].progress[j].member.length; k++) {
- if (group.activeTask[i].progress[j].member[k].user.equals(group.myMember.user)) {
- my_approved = group.activeTask[i].progress[j].member[k].progress.approved;
- my_pending = group.activeTask[i].progress[j].member[k].progress.pending;
- }
- }
- }
- if (my_approved + my_pending != group.activeTask[i].count) {
- DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
- formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
- Date date = null;
- Date date1 = null;
- try {
- String sd = formatter.format(Calendar.getInstance().getTime());
- if (group.activeTask[i].deadline != null) {
- date = (Date) formatter.parse(group.activeTask[i].deadline);
- date1 = (Date) formatter.parse(sd);
- long timeLeft = date.getTime() - date1.getTime();
- if (timeLeft < 0 && group.activeTask[i].lateSubmissionsAllowed == false) {
- continue;
- } else roles.add(group.activeTask[i].name);
- } else roles.add(group.activeTask[i].name);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- }
- }
- }
- final CharSequence[] task = new CharSequence[roles.size()];
- if (change_back_to_free_loop) {
- task[0] = getString(R.string._free_loop);
- for (int i = 0; i < roles.size(); i++) {
- task[i] = roles.get(i);
- }
- } else {
- for (int i = 0; i < roles.size(); i++) {
- task[i] = roles.get(i);
- }
- }
- builder.setItems(task, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- if (change_back_to_free_loop == false || (change_back_to_free_loop == true && which != 0)) {
- setChosenTarget(group.activeTask[which]);
- choose_task_layout.setVisibility(View.GONE);
- task_description_layout.setVisibility(View.VISIBLE);
- task_name.setText("" + getChosenTask().name);
- task_description.setText("" + getChosenTask().description);
- if (group.activeTask[which].needsApproval == false)
- can_be_approved.setVisibility(View.GONE);
- anonymous_layout.setVisibility(View.GONE);
- } else {
- setChosenTarget(null);
- choose_task_layout.setVisibility(View.VISIBLE);
- task_description_layout.setVisibility(View.GONE);
- if (can_post_anonymous == true) {
- anonymous_layout.setVisibility(View.VISIBLE);
- } else
- anonymous_layout.setVisibility(View.GONE);
- }
- enableButtonHelpMethod();
- }
- });
- builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- //Do nothing
- enableButtonHelpMethod();
- }
- });
- builder.create().show();
- } else {
- builder.setMessage(getString(R.string._there_are_no_tasks_in_this_group));
- builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- //Do nothing
- enableButtonHelpMethod();
- }
- });
- builder.create().show();
- }
- }
- private void showMembersInDialogue(ArrayList<String> al) {
- String message = "";
- if (al.size() != 0) {
- for (int i = 0; i < roleTypeArray.size(); i++) {
- message = message + roleTypeArray.get(i).toString() + "\n";
- }
- message = message.substring(0, message.length() - 1);
- dialogBuilder.setTitle(getString(R.string.recipients));
- dialogBuilder.setMessage(message);
- dialogBuilder.setPositiveButton(getString(R.string.OK), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- //do nothing
- }
- });
- dialogBuilder.create().show();
- }
- }
- private void setAlphaOnSendButton(int alpha) {
- send_loop_button.getBackground().setAlpha(alpha);
- if (alpha == DISABLED) {
- send_loop_button.setClickable(false);
- } else {
- send_loop_button.setClickable(true);
- }
- }
- // Reset the feelings
- private void unselectSmileys() {
- one.setImageResource(R.mipmap.v3_mood_very_sad_gray_icon);
- two.setImageResource(R.mipmap.v3_mood_sad_gray_icon);
- three.setImageResource(R.mipmap.v3_mood_neutral_gray_icon);
- four.setImageResource(R.mipmap.v3_mood_happy_gray_icon);
- five.setImageResource(R.mipmap.v3_mood_very_happy_gray_icon);
- one.setBackgroundColor(Color.TRANSPARENT);
- two.setBackgroundColor(Color.TRANSPARENT);
- three.setBackgroundColor(Color.TRANSPARENT);
- four.setBackgroundColor(Color.TRANSPARENT);
- five.setBackgroundColor(Color.TRANSPARENT);
- }
- private void drawAvailableTags() {
- Log.d(TAG, "drawAvailableTags");
- int itemCount = 0;
- linearTags.removeAllViews();
- int numberOfRows = freeTargetList.size() / BIG_TAG_COLUMS;
- if ((freeTargetList.size() % BIG_TAG_COLUMS) != 0) // division is even
- numberOfRows++;
- for (int i = 0; i < numberOfRows; i++) {
- LinearLayout lay = new LinearLayout(this);
- lay.setOrientation(LinearLayout.HORIZONTAL);
- LinearLayout.LayoutParams LLParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 105);
- lay.setWeightSum(BIG_TAG_COLUMS);
- lay.setLayoutParams(LLParams);
- for (int j = 0; j < BIG_TAG_COLUMS; j++) {
- TextView myTag = new TextView(this);
- myTag.setLayoutParams(new TableLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT, 1f));
- if (preselectedTag != null && itemCount < freeTargetList.size()) {
- Log.d(TAG, "preselectedTag.name: " + preselectedTag);
- Log.d(TAG, "freeTargetList.get(itemCount).name: " + freeTargetList.get(itemCount).name);
- if (freeTargetList.get(itemCount)._id.equals(preselectedTag._id)) {
- selectedTagsArray.add(freeTargetList.get(itemCount)._id);
- }
- }
- if (itemCount >= freeTargetList.size()) {
- myTag.setText("");
- lay.addView(myTag);
- itemCount++;
- } else {
- myTag.setGravity(Gravity.CENTER);
- if (freeTargetList.get(itemCount).name.length() > 50) {
- myTag.setTextSize(SMALL_TEXT_SIZE);
- } else if (freeTargetList.get(itemCount).name.length() > 30) {
- myTag.setTextSize(MEDIUM_TEXT_SIZE);
- } else {
- myTag.setTextSize(BIG_TEXT_SIZE);
- }
- if (selectedTagsArray.contains(freeTargetList.get(itemCount)._id)) {
- myTag.setBackgroundResource(R.drawable.rounded_corner_tag);
- myTag.setTextColor(Color.WHITE);
- } else {
- myTag.setBackgroundResource(R.drawable.rounded_corner_tag_white);
- }
- myTag.setText(freeTargetList.get(itemCount).name);
- myTag.setClickable(true);
- myTag.setOnClickListener(this);
- Object[] obj = new Object[3];
- obj[0] = freeTargetList.get(itemCount).name;
- obj[1] = myTag;
- obj[2] = freeTargetList.get(itemCount)._id;
- myTag.setTag(obj);
- lay.addView(myTag);
- itemCount++;
- }
- }
- linearTags.addView(lay);
- }
- }
- @Override
- public void onBackPressed() {
- if (input_message.getText().toString().length() > 0) {
- confirmExitDialog();
- } else {
- finishWithResult(RESULT_CANCELED);
- super.onBackPressed();
- }
- }
- private void confirmExitDialog() {
- DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- switch (which) {
- case DialogInterface.BUTTON_POSITIVE:
- finishWithResult(RESULT_CANCELED);
- break;
- case DialogInterface.BUTTON_NEGATIVE:
- break;
- }
- }
- };
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setMessage(getString(R.string.cancel_loop)).setPositiveButton(getString(R.string.yes), dialogClickListener)
- .setNegativeButton(getString(R.string.no), dialogClickListener).show();
- }
- private static final int READ_REQUEST_CODE = 42;
- private void selectImage() {
- // TODO: TESTING
- // ACTION_OPEN_DOCUMENT is the intent to choose a file via the system's file
- // browser.
- //Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
- // Filter to only show results that can be "opened", such as a
- // file (as opposed to a list of contacts or timezones)
- //intent.addCategory(Intent.CATEGORY_OPENABLE);
- // Filter to show only images, using the image MIME data type.
- // If one wanted to search for ogg vorbis files, the type would be "audio/ogg".
- // To search for all documents available via installed storage providers,
- // it would be "*/*".
- //intent.setType("image/*");
- //startActivityForResult(intent, READ_REQUEST_CODE);
- // TODO: TESTING
- // TODO: REMOVE "false" to make code work
- if (this.file == null) {
- final CharSequence[] items = {getString(R.string._take_photo), getString(R.string._choose_photo), getString(R.string._choose_file),
- getString(R.string._cancel)};
- android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(this);
- builder.setTitle(R.string._add_photo);
- builder.setItems(items, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int item) {
- if (item == 0) {
- Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
- //Toast.makeText(getApplicationContext(), R.string._cannot_take_photos_yet, Toast.LENGTH_LONG).show();
- startActivityForResult(intent, REQUEST_CAMERA);
- } else if (item == 1) {
- //userChoosenTask="Choose from Library";
- Intent intent = new Intent();
- //intent.setType("*/*");
- intent.setType("image/*");
- intent.setAction(Intent.ACTION_GET_CONTENT);//
- //Toast.makeText(getApplicationContext(), R.string._cannot_upload_photos_yet, Toast.LENGTH_LONG).show();
- startActivityForResult(Intent.createChooser(intent, "Select Photo"), SELECT_PHOTO); // COMMENT THIS BACK IN !!!!
- } else if (item == 2) {
- //userChoosenTask="Choose from Library";
- Intent intent = new Intent();
- intent.setType("*/*");
- //intent.setType("image/*");
- //Toast.makeText(getApplicationContext(), R.string._cannot_upload_files_yet, Toast.LENGTH_LONG).show();
- intent.setAction(Intent.ACTION_GET_CONTENT);//
- startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE);
- } else {
- dialog.dismiss();
- }
- }
- });
- builder.show();
- } else {
- this.file = null;
- tvFilename.setText(getString(R.string._upload_file));
- this.ivAddFile.setVisibility(View.VISIBLE);
- this.ivRemoveFile.setVisibility(View.GONE);
- }
- }
- String filename = null;
- public File getFileByUri(Uri uri) {
- Log.d("FILE_EXISTSSS", "getFileByUri");
- try {
- /*if (filesize >= FILE_SIZE_LIMIT) {
- Toast.makeText(this,"The selected file is too large. Selet a new file with size less than 2mb",Toast.LENGTH_LONG).show();
- } else {*/
- String mimeType = getContentResolver().getType(uri);
- if (mimeType == null) {
- String path = FileManager.getPath(this, uri);
- if (path == null) {
- filename = FilenameUtils.getName(uri.toString());
- } else {
- File file = new File(path);
- filename = file.getName();
- }
- Log.d("FILE_EXISTSSS", "mimeType");
- } else {
- Uri returnUri = uri;
- Cursor returnCursor = getContentResolver().query(returnUri, null, null, null, null);
- int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
- int sizeIndex = returnCursor.getColumnIndex(OpenableColumns.SIZE);
- returnCursor.moveToFirst();
- filename = returnCursor.getString(nameIndex);
- String size = Long.toString(returnCursor.getLong(sizeIndex));
- Log.d("FILE_EXISTSSS", "returnUri");
- }
- File fileSave = getExternalFilesDir(null);
- fileSave = getFilesDir();
- String sourcePath = getExternalFilesDir(null).toString();
- File returnFile = new File(sourcePath + "/" + filename);
- try {
- copyFileStream(returnFile, uri, this);
- Log.d("FILE_EXISTSSS", "copyFileStream");
- } catch (Exception e) {
- e.printStackTrace();
- Log.d("FILE_EXISTSSS", "copyFileStream exception");
- }
- Toast.makeText(this, "Path: " + fileSave.getPath(), Toast.LENGTH_LONG).show();
- return returnFile; //new File(filename);
- //}
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
- @Override
- public void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- if (resultCode == RESULT_OK) {
- if (requestCode == SELECT_FILE || requestCode == SELECT_PHOTO) {
- File file = FileManager.getFileByUri(this, data.getData());
- //if (file.exists()) {
- this.file = file;
- this.data = data;
- loadFileOrImagePreview();
- /*} else {
- Toast.makeText(this, getString(R.string.fileupload_could_not_find_file), Toast.LENGTH_LONG).show();
- }*/
- } else if (requestCode == REQUEST_CAMERA) {
- File file = FileManager.getFileByUri(this, data.getData());
- Bitmap bitmap1 = (Bitmap) data.getExtras().get("data");
- cropImage(bitmap1);
- scaleImage(bitmap1, imageWidth, imageHeight);
- ivFile.setImageBitmap(bitmap1);
- displayImage(bitmap1);
- this.file = bitmapToFile(bitmap1, "CameraPhoto.jpg");
- }
- }
- }
- private void loadFileOrImagePreview() {
- if (file != null) {
- String imageRegex = "(.*/)*.+\\.(png|jpg|gif|bmp|jpeg|PNG|JPG|GIF|BMP)$";
- if (file.getName().matches(imageRegex)) {
- Log.d("onActivityResult", "previewImage: " + file.getAbsolutePath());
- Log.d("onActivityResult", "previewImage: " + data.getType());
- previewImage(file, data);
- } else {
- Log.d("onActivityResult", "displayFile");
- displayFile(file);
- }
- }
- }
- private void previewImage(File file, Intent data) {
- Log.d("onActivityResult", "previewImage: ");
- Bitmap bGallery = onSelectFromGalleryResult(data);
- Bitmap cropped = cropImage(bGallery);
- Bitmap scaled = scaleImage(cropped, imageWidth, imageHeight);
- Bitmap bOrientation = fixImageOrientation(file.getPath(), scaled);
- displayImage(bOrientation);
- this.file = bitmapToFile(bOrientation, file.getPath());
- }
- private void copyFileStream(File dest, Uri uri, Context context)
- throws IOException {
- InputStream is = null;
- OutputStream os = null;
- try {
- is = context.getContentResolver().openInputStream(uri);
- os = new FileOutputStream(dest);
- byte[] buffer = new byte[1024];
- int length;
- while ((length = is.read(buffer)) > 0) {
- os.write(buffer, 0, length);
- }
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- is.close();
- os.close();
- }
- }
- public Bitmap cropImage(Bitmap bitmap) {
- if (bitmap.getWidth() >= bitmap.getHeight()) {
- return Bitmap.createBitmap(bitmap, bitmap.getWidth() / 2 - bitmap.getHeight() / 2, 0, bitmap.getHeight(), bitmap.getHeight());
- } else {
- return Bitmap.createBitmap(bitmap, 0, bitmap.getHeight() / 2 - bitmap.getWidth() / 2, bitmap.getWidth(), bitmap.getWidth());
- }
- }
- public Bitmap scaleImage(Bitmap bitmap, int width, int height) {
- return bitmap;//Bitmap.createScaledBitmap(bitmap, width, height, true);
- }
- public Bitmap fixImageOrientation(String filePath, Bitmap bitmap) {
- try {
- ExifInterface ei = new ExifInterface(filePath);
- int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
- switch (orientation) {
- case ExifInterface.ORIENTATION_ROTATE_90:
- Log.d("ROTATE", "90");
- bitmap = rotateImage(bitmap, 90);
- break;
- case ExifInterface.ORIENTATION_ROTATE_180:
- Log.d("ROTATE", "180");
- bitmap = rotateImage(bitmap, 180);
- break;
- case ExifInterface.ORIENTATION_ROTATE_270:
- Log.d("ROTATE", "270");
- bitmap = rotateImage(bitmap, 270);
- break;
- // etc.
- }
- } catch (IOException ioe) {
- ioe.printStackTrace();
- }
- return bitmap;
- }
- public static Bitmap rotateImage(Bitmap source, float angle) {
- Matrix matrix = new Matrix();
- matrix.postRotate(angle);
- return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
- }
- public void displayImage(final Bitmap bitmap) {
- rlFile.setVisibility(View.VISIBLE);
- rlUploadImage.setVisibility(View.GONE);
- ivFile.setImageBitmap(bitmap);
- ivFile.invalidate();
- }
- public void displayFile(final File file) {
- this.file = file;
- rlFile.setVisibility(View.GONE);
- ivAddFile.setVisibility(View.GONE);
- ivRemoveFile.setVisibility(View.VISIBLE);
- if (file == null) {
- tvFilename.setText("File is null!!");
- } else {
- tvFilename.setText(file.getPath());
- }
- }
- private Bitmap onSelectFromGalleryResult(Intent data) {
- Bitmap bm = null;
- if (data != null) {
- /*
- try {
- //bm = MediaStore.Images.Media.getBitmap(getApplicationContext().getContentResolver(), data.getData());
- } catch (IOException e) {
- e.printStackTrace();
- }
- */
- bm = decodeSampledBitmapFromResource(data.getData(), imageWidth, imageHeight); //decodeSampledBitmapFromResource(data.getData())
- }
- return bm;
- }
- // TESTING
- public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
- // Raw height and width of image
- final int height = options.outHeight;
- final int width = options.outWidth;
- int inSampleSize = 1;
- if (height > reqHeight || width > reqWidth) {
- final int halfHeight = height / 2;
- final int halfWidth = width / 2;
- // Calculate the largest inSampleSize value that is a power of 2 and keeps both
- // height and width larger than the requested height and width.
- while ((halfHeight / inSampleSize) >= reqHeight && (halfWidth / inSampleSize) >= reqWidth) {
- inSampleSize *= 2;
- }
- }
- return inSampleSize;
- }
- public Bitmap decodeSampledBitmapFromResource(Uri uri, int reqWidth, int reqHeight) {
- try {
- // First decode with inJustDecodeBounds=true to check dimensions
- final BitmapFactory.Options options = new BitmapFactory.Options();
- options.inJustDecodeBounds = true;
- options.inPreferredConfig = Bitmap.Config.RGB_565;
- options.inDither = true;
- BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null, options);
- // Calculate inSampleSize
- options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
- // Decode bitmap with inSampleSize set
- options.inJustDecodeBounds = false;
- return BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null, options);
- } catch (FileNotFoundException fnfe) {
- fnfe.printStackTrace();
- }
- return null;
- }
- // TESTING
- public String getRealPathFromURI(Uri uri) {
- ///* ALT 1
- Cursor cursor = getContentResolver().query(uri, null, null, null, null);
- cursor.moveToFirst();
- int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
- Log.d("getRealPathFromURI", "idx:" + idx);
- return cursor.getString(idx);
- //*/
- /* ALT 2
- String[] filePathColumn = {MediaStore.Images.Media.DATA};
- Cursor cursor = getContentResolver().query(uri, filePathColumn, null, null, null);
- String yourRealPath = null;
- if(cursor.moveToFirst()){
- int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
- yourRealPath = cursor.getString(columnIndex);
- } else {
- //boooo, cursor doesn't have rows ...
- }
- cursor.close();
- return yourRealPath;
- */
- }
- public File bitmapToFile(Bitmap bitmap, String filePath) {
- // Upload image
- try {
- Log.d("saveImage", "try 1");
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- bitmap.compress(Bitmap.CompressFormat.PNG, 80, bos);
- byte[] bArr = bos.toByteArray();
- bos.flush();
- bos.close();
- String fileName = filePath;
- if (fileName.contains("/")) {
- fileName = fileName.substring(fileName.lastIndexOf('/') + 1);
- }
- FileOutputStream fos = openFileOutput(fileName/*"test_image_name.png"*/, Context.MODE_PRIVATE);
- fos.write(bArr);
- fos.flush();
- fos.close();
- Log.d("FILE_UPLOOOAD", "getFilesDir().getAbsolutePath(): " + getFilesDir().getAbsolutePath());
- Log.d("FILE_UPLOOOAD", "getFilesDir().getName(): " + getFilesDir().getName());
- Log.d("FILE_UPLOOOAD", "getFilesDir().getPath(): " + getFilesDir().getPath());
- File mFile = new File(getFilesDir().getAbsolutePath(), fileName/*"test_image_name.png"*/);
- Log.d("saveImage", "try 2");
- return mFile;
- } catch (IOException ioe) {
- ioe.printStackTrace();
- }
- return null;
- }
- public File uploadFile(String filePath) {
- // Upload image
- try {
- String fileName = filePath;
- if (fileName.contains("/")) {
- fileName = fileName.substring(fileName.lastIndexOf('/') + 1);
- }
- FileOutputStream fos = openFileOutput(fileName/*"test_image_name.png"*/, Context.MODE_WORLD_WRITEABLE);
- fos.write(fileName.getBytes());
- fos.flush();
- fos.close();
- Log.d("FILE_UPLOOOAD", "getFilesDir().getAbsolutePath(): " + getFilesDir().getAbsolutePath());
- Log.d("FILE_UPLOOOAD", "getFilesDir().getName(): " + getFilesDir().getName());
- Log.d("FILE_UPLOOOAD", "getFilesDir().getPath(): " + getFilesDir().getPath());
- File mFile = new File(getFilesDir().getAbsolutePath(), fileName/*"test_image_name.png"*/);
- Log.d("saveImage", "try 2");
- return mFile;
- } catch (IOException ioe) {
- ioe.printStackTrace();
- }
- return null;
- }
- private void sendLoopDialog() {
- String[] tagIds = new String[freeTargetList.size()];
- for (int k = 0; k < selectedTagsArray.size(); k++) {
- tagIds[k] = selectedTagsArray.get(k);
- }
- if (tagIds.length > 0 && selectedTagsArray.size() <= 0) {
- dialogBuilder.setTitle("ERROR");
- dialogBuilder.setMessage("You need to choose at least one tag");
- dialogBuilder.setPositiveButton(getString(R.string.OK), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- if (loading_progressBar != null) {
- loading_progressBar.setVisibility(View.GONE);
- }
- }
- });
- dialogBuilder.create().show();
- send_loop_button.setEnabled(true);
- pbSendLoop.setVisibility(View.GONE);
- tvSendLoop.setVisibility(View.VISIBLE);
- } else {
- send_loop_button.setEnabled(false);
- AlertDialog.Builder bildah = new AlertDialog.Builder(this);
- bildah.setTitle(getString(R.string._confirm_loop_sending_title));
- bildah.setMessage(getString(R.string._confirm_loop_sending_message));
- bildah.setPositiveButton(getString(R.string._send), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- sendLoop();
- }
- });
- bildah.setOnCancelListener(new DialogInterface.OnCancelListener() {
- @Override
- public void onCancel(DialogInterface dialog) {
- send_loop_button.setEnabled(true);
- }
- });
- bildah.setNegativeButton(getString(R.string._cancel), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- send_loop_button.setEnabled(true);
- }
- });
- bildah.create().show();
- }
- }
- private void sendLoop() {
- pbSendLoop.setVisibility(View.VISIBLE);
- tvSendLoop.setVisibility(View.GONE);
- String message = input_message.getText().toString();
- Boolean anonymous = anonymous_checkbox.isChecked();
- //targetArr är id på targeten man har valt, om man då har valt en.
- if (loop_type == INFO_LOOP) {
- File[] files = new File[1];
- files[0] = this.file;
- mWebApiMethods.createNewInfo(group._id, message, files, new JsonHttpResponseHandler() {
- @Override
- public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
- super.onSuccess(statusCode, headers, response);
- finishWithResult(RESULT_OK);
- overridePendingTransition(R.anim.nothing, R.anim.right_slide_out);
- send_loop_button.setEnabled(true);
- pbSendLoop.setVisibility(View.GONE);
- tvSendLoop.setVisibility(View.VISIBLE);
- }
- @Override
- public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
- super.onFailure(statusCode, headers, throwable, errorResponse);
- dialogBuilder.setTitle(getString(R.string.connection_refused));
- dialogBuilder.setMessage(getString(R.string.connection_refused_info));
- dialogBuilder.setPositiveButton(getString(R.string.OK), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- loading_progressBar.setVisibility(View.GONE);
- }
- });
- dialogBuilder.create().show();
- send_loop_button.setEnabled(true);
- pbSendLoop.setVisibility(View.GONE);
- tvSendLoop.setVisibility(View.VISIBLE);
- }
- });
- } else {
- String targets = null;
- Task task = null;
- String followup = etFollowupAnswer.getText().toString();
- String chosen_target[] = new String[1];
- if (getChosenTask() != null) {
- chosen_target[0] = getChosenTask()._id;
- targets = chosen_target[0];
- task = getChosenTask();
- }
- String[] tagIds = new String[freeTargetList.size()];
- for (int k = 0; k < selectedTagsArray.size(); k++) {
- tagIds[k] = selectedTagsArray.get(k);
- }
- File[] files = new File[1];
- files[0] = this.file;
- mWebApiMethods.createNewReflection(group._id, message, followup, tagIds, selectedFeeling, anonymous, targets, files, new JsonHttpResponseHandler() {
- @Override
- public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
- finishWithResult(RESULT_OK);
- overridePendingTransition(R.anim.nothing, R.anim.right_slide_out);
- super.onSuccess(statusCode, headers, response);
- synchronized (this) {
- notify();
- }
- send_loop_button.setEnabled(true);
- pbSendLoop.setVisibility(View.GONE);
- tvSendLoop.setVisibility(View.VISIBLE);
- }
- @Override
- public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
- super.onFailure(statusCode, headers, throwable, errorResponse);
- dialogBuilder.setTitle(getString(R.string.connection_refused));
- dialogBuilder.setMessage(getString(R.string.connection_refused_info));
- dialogBuilder.setPositiveButton(getString(R.string.OK), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- if (loading_progressBar != null) {
- loading_progressBar.setVisibility(View.GONE);
- }
- }
- });
- dialogBuilder.create().show();
- send_loop_button.setEnabled(true);
- pbSendLoop.setVisibility(View.GONE);
- tvSendLoop.setVisibility(View.VISIBLE);
- }
- });
- }
- }
- private void finishWithResult(int result) {
- Intent intent = new Intent();
- intent.putExtra("task", task);
- intent.putExtra("group", group);
- setResult(result, intent);
- finish();
- overridePendingTransition(R.anim.nothing, R.anim.right_slide_out);
- }
- private boolean isSendable() {
- if (loop_type == INFO_LOOP) {
- if (this.input_message.getText().toString().trim().length() <= 0) {
- return false;
- }
- } else {
- if (this.input_message.getText().toString().trim().length() <= 0) {
- return false;
- }
- // NEW
- if (isTagsAvailable && selectedTagsArray.isEmpty()) {
- return false;
- }
- // NEW
- /*if (task != null) {
- if (task.followupQuestion != null) {
- Toast.makeText(CreateNewLoop.this,"LOOPINFO", Toast.LENGTH_SHORT).show();
- return etFollowupAnswer.getText().toString().length() > 0;
- }
- }*/
- if (selectedFeeling == -90) {
- return false;
- }
- }
- return true;
- }
- private void enableButtonHelpMethod() {
- if (isSendable()) {
- setAlphaOnSendButton(ENABLED);
- } else {
- setAlphaOnSendButton(DISABLED);
- }
- }
- }
Add Comment
Please, Sign In to add comment