Example #1
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    txt_title = (TextView) this.findViewById(R.id.cht_alert_txt_title);
    txt_body = (TextView) this.findViewById(R.id.cht_alert_txt_body);
    btn_yes = (Button) this.findViewById(R.id.cht_alert_btn_yes);
    btn_no = (Button) this.findViewById(R.id.cht_alert_btn_no);
    try {
      chatSession = ((ChatSession) getSession());
      moduleManager = chatSession.getModuleManager();
      chatManager = moduleManager.getChatManager();
      errorManager = getSession().getErrorManager();

    } catch (Exception e) {
      if (errorManager != null)
        errorManager.reportUnexpectedSubAppException(
            SubApps.CHT_CHAT,
            UnexpectedSubAppExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_FRAGMENT,
            e);
    }
    txt_title.setText(title);
    txt_body.setText(body);

    setUpListeners();
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    View layout = inflater.inflate(R.layout.contact_edit_fragment, container, false);
    try {
      // Contact cont= chatSession.getSelectedContact();
      // TODO: metodo nuevo que lo buscara del module del actor
      // connections//chatManager.getChatUserIdentities();
      for (ChatActorCommunityInformation cont :
          chatManager.listAllConnectedChatActor(
              chatManager.newInstanceChatActorCommunitySelectableIdentity(
                  chatManager.getIdentityChatUsersFromCurrentDeviceUser().get(0)),
              2000,
              0)) {
        if (cont.getPublicKey() == chatSession.getData(ChatSession.CONTACT_DATA)) {
          contactname.add(cont.getAlias());
          contactid.add(cont.getPublicKey());
          contactalias.add(cont.getAlias());
          ByteArrayInputStream bytes = new ByteArrayInputStream(cont.getImage());
          BitmapDrawable bmd = new BitmapDrawable(bytes);
          contacticon.add(bmd.getBitmap());
          ContactAdapter adapter =
              new ContactAdapter(
                  getActivity(), contactname, contactalias, contactid, "edit", errorManager);
          // FermatTextView name =(FermatTextView)layout.findViewById(R.id.contact_name);
          // name.setText(contactname.get(0));
          // FermatTextView id =(FermatTextView)layout.findViewById(R.id.uuid);
          // id.setText(contactid.get(0).toString());

          // create bitmap from resource
          // Bitmap bm = BitmapFactory.decodeResource(getResources(), contacticon.get(0));

          // set circle bitmap
          ImageView mImage = (ImageView) layout.findViewById(R.id.contact_image);
          mImage.setImageBitmap(getCircleBitmap(contacticon.get(0)));
          break;
        }
      }
      aliasET = (EditText) layout.findViewById(R.id.aliasEdit);
      aliasET.setText(contactalias.get(0));
      saveBtn = (Button) layout.findViewById(R.id.saveContactButton);
      RelativeLayout contain = (RelativeLayout) layout.findViewById(R.id.containere);
    } catch (Exception e) {
      if (errorManager != null)
        errorManager.reportUnexpectedSubAppException(
            SubApps.CHT_CHAT,
            UnexpectedSubAppExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_FRAGMENT,
            e);
    }

    toolbar.setNavigationOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            changeActivity(Activities.CHT_CHAT_OPEN_CHATLIST, appSession.getAppPublicKey());
          }
        });

    //        saveBtn.setOnClickListener(new View.OnClickListener() {
    //            @Override
    //            public void onClick(View v) {
    //                String aliasText = aliasET.getText().toString();
    //                if (TextUtils.isEmpty(aliasText)) {
    //                    return;
    //                }
    //                try {
    //                    for (ChatActorCommunityInformation cont:
    // chatManager.listAllConnectedChatActor(
    //                            (ChatActorCommunitySelectableIdentity) chatManager.
    //                                    getIdentityChatUsersFromCurrentDeviceUser().get(0), 2000,
    // 0)) {
    //                        if (cont.getPublicKey() ==
    // chatSession.getData(ChatSession.CONTACT_DATA)) {
    //                            cont.setAlias(aliasText);
    //                            //TODO:Cardozo revisar esta logica ya no aplica, esto viene de un
    // metodo nuevo que lo buscara del module del actor
    // connections//chatManager.getChatUserIdentities();
    //                            //chatManager.saveContact(con);
    //                            Toast.makeText(getActivity(), "Contact Updated",
    // Toast.LENGTH_SHORT).show();
    //                            //} catch (CantSaveContactException e) {
    //                            //
    // errorManager.reportUnexpectedSubAppException(SubApps.CHT_CHAT,
    // UnexpectedSubAppExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_FRAGMENT, e);
    //
    //                        }
    //                    }
    //                }catch (Exception e){
    //                    if (errorManager != null)
    //                        errorManager.reportUnexpectedSubAppException(SubApps.CHT_CHAT,
    // UnexpectedSubAppExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_FRAGMENT, e);
    //                }
    //            }
    //        });

    return layout;
    // loadDummyHistory();
    // Inflate the list fragment layout
    // return inflater.inflate(R.layout.contact_list_fragment, container, false);
  }
Example #3
0
  public void onClick(View v) {
    int id = v.getId();
    if (id == R.id.cht_alert_btn_yes) {
      dismiss();
      if (AlertType == 1) {
        try {
          // appSession.setData(ChatSession.CONNECTION_DATA, contactConn);
          // Contact conn = chatSession.getSelectedConnection();
          if (chatManager.getContactByLocalPublicKey(contactConn.getRemoteActorPublicKey())
              == null) {
            ContactImpl newContact = new ContactImpl();
            newContact.setAlias(contactConn.getAlias());
            newContact.setRemoteActorType(contactConn.getRemoteActorType());
            newContact.setRemoteActorPublicKey(contactConn.getRemoteActorPublicKey());
            newContact.setRemoteName(contactConn.getRemoteName());
            newContact.setContactId(UUID.randomUUID());
            newContact.setCreationDate(System.currentTimeMillis());
            newContact.setContactStatus(contactConn.getContactStatus());
            newContact.setProfileImage(contactConn.getProfileImage());
            chatManager.saveContact(newContact);
            addcontact = true;
            Toast.makeText(getActivity(), "Contact added", Toast.LENGTH_SHORT).show();
            // changeActivity(Activities.CHT_CHAT_OPEN_CONTACTLIST, appSession.getAppPublicKey());
            // dismiss();
          } else {
            Toast.makeText(getActivity(), "Contact already exist", Toast.LENGTH_SHORT).show();

            // changeActivity(Activities.CHT_CHAT_OPEN_CONTACTLIST, appSession.getAppPublicKey());
            // dismiss();
          }
          dismiss();
          mAdapterCallback.onMethodCallbackContacts(); // solution to access to update contacts. j

        } catch (CantSaveContactException e) {
          errorManager.reportUnexpectedSubAppException(
              SubApps.CHT_CHAT,
              UnexpectedSubAppExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_FRAGMENT,
              e);
        } catch (Exception e) {
          errorManager.reportUnexpectedSubAppException(
              SubApps.CHT_CHAT,
              UnexpectedSubAppExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_FRAGMENT,
              e);
        }
        // changeActivity(Activities.CHT_CHAT_OPEN_CHATLIST, appSession.getAppPublicKey());
      } else if (AlertType == 2) {
        try {
          Contact con = chatSession.getSelectedContact();
          chatManager.deleteContact(con);
          List<Contact> cont = chatManager.getContacts();
          if (cont.size() > 0) {
            for (int i = 0; i < cont.size(); i++) {
              contactname.add(cont.get(i).getAlias());
              contactid.add(cont.get(i).getContactId());
              ByteArrayInputStream bytes = new ByteArrayInputStream(cont.get(i).getProfileImage());
              BitmapDrawable bmd = new BitmapDrawable(bytes);
              contacticon.add(bmd.getBitmap());
            }
            final ContactListAdapter adaptador =
                new ContactListAdapter(
                    getActivity(),
                    contactname,
                    contacticon,
                    contactid,
                    chatManager,
                    moduleManager,
                    errorManager,
                    chatSession,
                    getSession(),
                    null);
            adaptador.refreshEvents(contactname, contacticon, contactid);
          }
        } catch (CantGetContactException e) {
          errorManager.reportUnexpectedSubAppException(
              SubApps.CHT_CHAT,
              UnexpectedSubAppExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_FRAGMENT,
              e);
        } catch (Exception e) {
          errorManager.reportUnexpectedSubAppException(
              SubApps.CHT_CHAT,
              UnexpectedSubAppExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_FRAGMENT,
              e);
        }
        delete_contact = true;
      }
    }

    if (id == R.id.cht_alert_btn_no) {
      dismiss();
    }
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // mIsTwoPaneLayout = getResources().getBoolean(R.bool.has_two_panes);

    // Let this fragment contribute menu items
    // setHasOptionsMenu(true);

    try {
      chatSession = ((ChatSession) appSession);
      chatManager = chatSession.getModuleManager();
      // chatManager=moduleManager.getChatManager();
      errorManager = appSession.getErrorManager();
      toolbar = getToolbar();
      toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.cht_ic_back_buttom));
    } catch (Exception e) {
      // CommonLogger.exception(TAG + "oncreate", e.getMessage(), e);
      if (errorManager != null)
        errorManager.reportUnexpectedSubAppException(
            SubApps.CHT_CHAT,
            UnexpectedSubAppExceptionSeverity.DISABLES_SOME_FUNCTIONALITY_WITHIN_THIS_FRAGMENT,
            e);
    }

    // Check if this fragment is part of a two-pane set up or a single pane by reading a
    // boolean from the application resource directories. This lets allows us to easily specify
    // which screen sizes should use a two-pane layout by setting this boolean in the
    // corresponding resource size-qualified directory.
    // mIsTwoPaneLayout = getResources().getBoolean(R.bool.has_two_panes);

    // Let this fragment contribute menu items
    // setHasOptionsMenu(true);

    // Create the main contacts adapter
    //        mAdapter = new ContactsAdapter(getActivity());
    //
    //        if (savedInstanceState != null) {
    //            // If we're restoring state after this fragment was recreated then
    //            // retrieve previous search term and previously selected search
    //            // result.
    //            mSearchTerm = savedInstanceState.getString(SearchManager.QUERY);
    //            mPreviouslySelectedSearchItem =
    //                    savedInstanceState.getInt(STATE_PREVIOUSLY_SELECTED_KEY, 0);
    //        }

    /*
     * An ImageLoader object loads and resizes an image in the background and binds it to the
     * QuickContactBadge in each item layout of the ListView. ImageLoader implements memory
     * caching for each image, which substantially improves refreshes of the ListView as the
     * user scrolls through it.
     *
     * To learn more about downloading images asynchronously and caching the results, read the
     * Android training class Displaying Bitmaps Efficiently.
     *
     * http://developer.android.com/training/displaying-bitmaps/
     */
    //        mImageLoader = new ImageLoader(getActivity(), getListPreferredItemHeight()) {
    //            @Override
    //            protected Bitmap processBitmap(Object data) {
    //                // This gets called in a background thread and passed the data from
    //                // ImageLoader.loadImage().
    //                return loadContactPhotoThumbnail((String) data, getImageSize());
    //            }
    //        };
    //
    //        // Set a placeholder loading image for the image loader
    //        mImageLoader.setLoadingImage(R.drawable.ic_contact_picture_holo_light);

    // Add a cache to the image loader
    // mImageLoader.addImageCache(getActivity().getSupportFragmentManager(), 0.1f);

  }