/**
   * 获得ScrollView最大垂直滚动距离
   *
   * @param scrollView
   * @return
   */
  private int getMaxScrollY() {
    int tmpY = mContentScrollView.getScrollY();

    mContentScrollView.scrollTo(getScrollX(), 5000);
    int maxY = mContentScrollView.getScrollY();

    mContentScrollView.scrollTo(mContentScrollView.getScrollX(), tmpY);
    return maxY;
  }
  public void onDragOver(DragObject d) {
    final DragView dragView = d.dragView;
    final int scrollOffset = mScrollView.getScrollY();
    final float[] r = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, dragView, null);
    r[0] -= getPaddingLeft();
    r[1] -= getPaddingTop();

    final long downTime = SystemClock.uptimeMillis();
    final MotionEvent translatedEv =
        MotionEvent.obtain(downTime, downTime, MotionEvent.ACTION_MOVE, d.x, d.y, 0);

    if (!mAutoScrollHelper.isEnabled()) {
      mAutoScrollHelper.setEnabled(true);
    }

    final boolean handled = mAutoScrollHelper.onTouch(this, translatedEv);
    translatedEv.recycle();

    if (handled) {
      mReorderAlarm.cancelAlarm();
    } else {
      mTargetCell =
          mContent.findNearestArea((int) r[0], (int) r[1] + scrollOffset, 1, 1, mTargetCell);
      if (isLayoutRtl()) {
        mTargetCell[0] = mContent.getCountX() - mTargetCell[0] - 1;
      }
      if (mTargetCell[0] != mPreviousTargetCell[0] || mTargetCell[1] != mPreviousTargetCell[1]) {
        mReorderAlarm.cancelAlarm();
        mReorderAlarm.setOnAlarmListener(mReorderAlarmListener);
        mReorderAlarm.setAlarm(REORDER_DELAY);
        mPreviousTargetCell[0] = mTargetCell[0];
        mPreviousTargetCell[1] = mTargetCell[1];
      }
    }
  }
  @Override
  public void onResume() {
    super.onResume();

    int scrollY = mScrollView.getScrollY(); // for verticalScrollView
    mListener.onScrollY(scrollY, 0, mFragmentId);
  }
Exemple #4
0
  @Test
  public void shouldSmoothScrollTo() throws Exception {
    ScrollView scrollView = new ScrollView(null);
    scrollView.smoothScrollTo(7, 6);

    assertEquals(7, scrollView.getScrollX());
    assertEquals(6, scrollView.getScrollY());
  }
  public void animateSubjectOut(final SubjectCard materia) {
    final List<View> toBeAnimated = new ArrayList<View>();
    boolean after = false;
    for (SubjectCard mtr : mSubjectCards) {
      if (after) toBeAnimated.add(mtr);
      if (mtr == materia) after = true;
    }
    toBeAnimated.add(mAddButton);
    final int numberToBeAnimated = toBeAnimated.size();

    int maxScroll = mScrollView.getChildAt(0).getHeight() - mScrollView.getHeight(),
        materiaHeight = materia.getHeight();
    final int initScroll = mScrollView.getScrollY(),
        scrollBy =
            ((maxScroll < initScroll + materiaHeight)
                    ? Math.max(maxScroll - materiaHeight, 0)
                    : initScroll)
                - initScroll;
    ValueAnimator listAnimator = ValueAnimator.ofFloat(0, -materiaHeight);
    listAnimator.setInterpolator(new DecelerateInterpolator(3.2f));
    listAnimator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            float value = (Float) animation.getAnimatedValue();
            for (int i = 0; i < numberToBeAnimated; i++)
              ViewHelper.setTranslationY(toBeAnimated.get(i), value);
            ViewHelper.setScrollY(
                mScrollView, (int) (initScroll + scrollBy * animation.getAnimatedFraction()));
          }
        });
    listAnimator.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationEnd(Animator animation) {
            mSubjectCards.remove(materia);
            mSubjectsLayout.removeView(materia);
            mSqlHelper.remove(materia.getData().getSqlID());
            updateTotal();
            mScrollView.setVerticalScrollBarEnabled(true);
            mScrollView.setOnTouchListener(null);
            for (View mtr : toBeAnimated) ViewHelper.setTranslationY(mtr, 0);
          }
        });
    listAnimator.setDuration(700);
    mScrollView.setVerticalScrollBarEnabled(false);
    mScrollView.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            return true;
          }
        }); // disable user scrolling during the animation

    if (ViewHelper.getTranslationX(materia) == 0) materia.swipeRight(0, 0);
    listAnimator.setStartDelay(500);
    listAnimator.start();
  }
 @Override
 protected boolean isReadyForPullDown() {
   if (mRefreshableView.getChildCount() > 0
       && mRefreshableView.getChildAt(0) instanceof ScrollView) {
     ScrollView mScrollView = (ScrollView) mRefreshableView.getChildAt(0);
     return mScrollView.getScrollY() == 0;
   }
   return mRefreshableView.getScrollY() == 0;
 }
 /**
  * Copy From ScrollView (API Level >= 14)
  *
  * @param direction Negative to check scrolling up, positive to check scrolling down.
  * @return true if the scrollView can be scrolled in the specified direction, false otherwise
  */
 private boolean scrollViewCanScrollVertically(ScrollView scrollView, int direction) {
   final int offset = Math.max(0, scrollView.getScrollY());
   final int range = computeVerticalScrollRange(scrollView) - scrollView.getHeight();
   if (range == 0) return false;
   if (direction < 0) { // scroll up
     return offset > 0;
   } else { // scroll down
     return offset < range - 1;
   }
 }
  @Override
  protected boolean isReadyForPullUp() {
    View scrollViewChild = mRefreshableView.getChildAt(0);
    if (null != scrollViewChild) {
      if (scrollViewChild instanceof ScrollView) {
        ScrollView mScrollView = (ScrollView) scrollViewChild;
        scrollViewChild = mScrollView.getChildAt(0);
        if (null != scrollViewChild)
          return mScrollView.getScrollY() >= (scrollViewChild.getHeight() - getHeight());
      }
      return mRefreshableView.getScrollY() >= (scrollViewChild.getHeight() - getHeight());
    }

    return false;
  }
 @Override
 public void handleMessage(Message msg) {
   super.handleMessage(msg);
   if (scroll.getScrollY() + height + 100 >= background.getHeight()) {
     if (!isLoading && !isLoaddone) {
       new LoadDataAsync().execute();
     }
   }
   //			if(scroll.getScrollY() != y){
   //				((TextView)findViewById(R.id.slide_btn)).getBackground().setAlpha(100);
   //			}else{
   //				((TextView)findViewById(R.id.slide_btn)).getBackground().setAlpha(255);
   //			}
   //			y = scroll.getScrollY();
 }
  /**
   * Copy From ScrollView (API Level >= 14)
   *
   * <p>The scroll range of a scroll view is the overall height of all of its children.
   */
  private int computeVerticalScrollRange(ScrollView scrollView) {
    final int count = scrollView.getChildCount();
    final int contentHeight =
        scrollView.getHeight() - scrollView.getPaddingBottom() - scrollView.getPaddingTop();
    if (count == 0) {
      return contentHeight;
    }

    int scrollRange = scrollView.getChildAt(0).getBottom();
    final int scrollY = scrollView.getScrollY();
    final int overscrollBottom = Math.max(0, scrollRange - contentHeight);
    if (scrollY < 0) {
      scrollRange -= scrollY;
    } else if (scrollY > overscrollBottom) {
      scrollRange += scrollY - overscrollBottom;
    }

    return scrollRange;
  }
Exemple #11
0
  public void setDashboardVisibility(
      boolean visible, DashboardType type, DashboardType prevItem, boolean animation) {
    if (visible == this.visible && type == visibleType) {
      return;
    }
    this.previousVisibleType = prevItem;
    this.visible = visible;
    boolean refresh = this.visibleType == type;
    this.visibleType = type;
    DashboardOnMap.staticVisible = visible;
    DashboardOnMap.staticVisibleType = type;
    mapActivity.enableDrawer();
    if (visible) {
      mapViewLocation = mapActivity.getMapLocation();
      mapRotation = mapActivity.getMapRotate();
      mapLinkedToLocation = mapActivity.getMapViewTrackingUtilities().isMapLinkedToLocation();
      myLocation = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation();
      mapActivity.getMapViewTrackingUtilities().setDashboard(this);
      mapActivity.disableDrawer();
      dashboardView.setVisibility(View.VISIBLE);
      if (isActionButtonVisible()) {
        actionButton.setVisibility(View.VISIBLE);
      } else {
        hideActionButton();
      }
      updateDownloadBtn();
      View listViewLayout = dashboardView.findViewById(R.id.dash_list_view_layout);
      ScrollView scrollView = (ScrollView) dashboardView.findViewById(R.id.main_scroll);
      if (visibleType == DashboardType.DASHBOARD) {
        addOrUpdateDashboardFragments();
        scrollView.setVisibility(View.VISIBLE);
        scrollView.scrollTo(0, 0);
        listViewLayout.setVisibility(View.GONE);
        onScrollChanged(scrollView.getScrollY(), false, false);
      } else {
        scrollView.setVisibility(View.GONE);
        listViewLayout.setVisibility(View.VISIBLE);
        if (listView instanceof ObservableListView) {
          onScrollChanged(listView.getScrollY(), false, false);
        }
        if (refresh) {
          refreshContent(false);
        } else {
          updateListAdapter();
          updateListBackgroundHeight();
        }
      }
      mapActivity
          .findViewById(R.id.toolbar_back)
          .setVisibility(isBackButtonVisible() ? View.VISIBLE : View.GONE);
      mapActivity.findViewById(R.id.MapHudButtonsOverlay).setVisibility(View.INVISIBLE);

      updateToolbarActions();
      // fabButton.showFloatingActionButton();
      open(dashboardView.findViewById(R.id.animateContent), animation);
      updateLocation(true, true, false);
      //			addOrUpdateDashboardFragments();
    } else {
      mapActivity.getMapViewTrackingUtilities().setDashboard(null);
      hide(dashboardView.findViewById(R.id.animateContent), animation);
      mapActivity.findViewById(R.id.MapHudButtonsOverlay).setVisibility(View.VISIBLE);
      hideActionButton();
      for (WeakReference<DashBaseFragment> df : fragList) {
        if (df.get() != null) {
          df.get().onCloseDash();
        }
      }
    }
  }
  @Override
  public View onCreateView(
      final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_settings, container, false);

    baseColor = getResources().getColor(R.color.primary);

    final UserVM userModel = users().get(myUid());

    final TextView nameView = (TextView) view.findViewById(R.id.name);

    bind(nameView, userModel.getName());

    view.findViewById(R.id.notifications)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                startActivity(new Intent(getActivity(), NotificationsActivity.class));
              }
            });

    view.findViewById(R.id.helpSettings)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                startActivity(new Intent(getActivity(), HelpActivity.class));
              }
            });

    final LinearLayout nickContainer = (LinearLayout) view.findViewById(R.id.nickContainer);
    final LinearLayout contactsContainer = (LinearLayout) view.findViewById(R.id.phoneContainer);
    final FrameLayout about = (FrameLayout) view.findViewById(R.id.about);

    // TODO: Move bindings to onResume

    bind(
        userModel.getNick(),
        new ValueChangedListener<String>() {
          @Override
          public void onChanged(final String val, ValueModel<String> valueModel) {
            final View recordView = inflater.inflate(R.layout.contact_record, nickContainer, false);
            TintImageView tintImageView = (TintImageView) recordView.findViewById(R.id.recordIcon);
            tintImageView.setVisibility(View.INVISIBLE);
            String value =
                (val != null && !val.isEmpty()) ? val : getString(R.string.nickname_empty);
            String title = getString(R.string.nickname);

            ((TextView) recordView.findViewById(R.id.value)).setText(value);
            ((TextView) recordView.findViewById(R.id.title)).setText(title);
            nickContainer.removeAllViews();
            nickContainer.addView(
                recordView,
                new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Screen.dp(72)));

            recordView.setOnClickListener(
                new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                    final MaterialDialog.Builder builder =
                        new MaterialDialog.Builder(getActivity());
                    LinearLayout fl = new LinearLayout(getActivity());
                    fl.setOrientation(LinearLayout.VERTICAL);

                    builder.input(
                        getString(R.string.nickname),
                        val,
                        false,
                        new MaterialDialog.InputCallback() {
                          @Override
                          public void onInput(
                              final MaterialDialog materialDialog,
                              final CharSequence charSequence) {
                            execute(
                                messenger()
                                    .executeExternalCommand(
                                        new RequestEditNickName(charSequence.toString())),
                                R.string.progress_common,
                                new CommandCallback<ResponseSeq>() {
                                  @Override
                                  public void onResult(ResponseSeq res) {
                                    getActivity()
                                        .runOnUiThread(
                                            new Runnable() {
                                              @Override
                                              public void run() {
                                                ((TextView) recordView.findViewById(R.id.value))
                                                    .setText(charSequence.toString());
                                                materialDialog.dismiss();
                                              }
                                            });
                                  }

                                  @Override
                                  public void onError(final Exception e) {
                                    getActivity()
                                        .runOnUiThread(
                                            new Runnable() {
                                              @Override
                                              public void run() {
                                                Toast.makeText(
                                                        getActivity(),
                                                        e.getMessage(),
                                                        Toast.LENGTH_LONG)
                                                    .show();
                                              }
                                            });
                                  }
                                });
                          }
                        });

                    builder.show();
                  }
                });
          }
        });

    about.findViewById(R.id.title).setVisibility(View.GONE);
    about.findViewById(R.id.recordIcon).setVisibility(View.INVISIBLE);
    ((TextView) about.findViewById(R.id.value)).setText(getString(R.string.about_user_me));
    about.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            getActivity().startActivity(Intents.editUserAbout(getActivity()));
          }
        });

    bind(
        userModel.getPhones(),
        new ValueChangedListener<ArrayListUserPhone>() {
          @Override
          public void onChanged(ArrayListUserPhone val, ValueModel<ArrayListUserPhone> valueModel) {
            if (val.size() == 0) {
              contactsContainer.setVisibility(View.GONE);
            } else {
              contactsContainer.setVisibility(View.VISIBLE);
              for (int i = 0; i < val.size(); i++) {
                final UserPhone record = val.get(i);
                View recordView =
                    inflater.inflate(R.layout.contact_record, contactsContainer, false);
                TintImageView tintImageView =
                    (TintImageView) recordView.findViewById(R.id.recordIcon);
                if (i == 0) {
                  tintImageView.setResource(R.drawable.ic_call_white_36dp);
                  tintImageView.setVisibility(View.VISIBLE);
                } else {
                  tintImageView.setVisibility(View.INVISIBLE);
                }

                if (i != val.size() - 1) {
                  recordView.findViewById(R.id.divider).setVisibility(View.VISIBLE);
                } else {
                  recordView.findViewById(R.id.divider).setVisibility(View.GONE);
                }

                String _phoneNumber;
                try {
                  Phonenumber.PhoneNumber number =
                      PhoneNumberUtil.getInstance().parse("+" + record.getPhone(), "us");
                  _phoneNumber =
                      PhoneNumberUtil.getInstance()
                          .format(number, PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL);
                } catch (NumberParseException e) {
                  e.printStackTrace();
                  _phoneNumber = "+" + record.getPhone();
                }
                final String phoneNumber = _phoneNumber;

                ((TextView) recordView.findViewById(R.id.value)).setText(phoneNumber);
                ((TextView) recordView.findViewById(R.id.title)).setText(record.getTitle());
                contactsContainer.addView(
                    recordView,
                    new LinearLayout.LayoutParams(
                        ViewGroup.LayoutParams.MATCH_PARENT, Screen.dp(72)));

                recordView.setOnClickListener(
                    new View.OnClickListener() {
                      @Override
                      public void onClick(View v) {
                        new AlertDialog.Builder(getActivity())
                            .setItems(
                                new CharSequence[] {
                                  getString(R.string.phone_menu_call).replace("{0}", phoneNumber),
                                  getString(R.string.phone_menu_sms).replace("{0}", phoneNumber),
                                  getString(R.string.phone_menu_share).replace("{0}", phoneNumber),
                                  getString(R.string.phone_menu_copy)
                                },
                                new DialogInterface.OnClickListener() {
                                  @Override
                                  public void onClick(DialogInterface dialog, int which) {
                                    if (which == 0) {
                                      startActivity(
                                          new Intent(Intent.ACTION_DIAL)
                                              .setData(Uri.parse("tel:+" + record.getPhone())));
                                    } else if (which == 1) {
                                      startActivity(
                                          new Intent(Intent.ACTION_VIEW)
                                              .setData(Uri.parse("sms:+" + record.getPhone())));
                                    } else if (which == 2) {
                                      startActivity(
                                          new Intent(Intent.ACTION_SEND)
                                              .setType("text/plain")
                                              .putExtra(
                                                  Intent.EXTRA_TEXT,
                                                  getString(R.string.settings_share_text)
                                                      .replace("{0}", phoneNumber)
                                                      .replace("{1}", userModel.getName().get())));
                                    } else if (which == 3) {
                                      ClipboardManager clipboard =
                                          (ClipboardManager)
                                              getActivity()
                                                  .getSystemService(Context.CLIPBOARD_SERVICE);
                                      ClipData clip =
                                          ClipData.newPlainText("Phone number", phoneNumber);
                                      clipboard.setPrimaryClip(clip);
                                      Toast.makeText(
                                              getActivity(),
                                              R.string.toast_phone_copied,
                                              Toast.LENGTH_SHORT)
                                          .show();
                                    }
                                  }
                                })
                            .show()
                            .setCanceledOnTouchOutside(true);
                      }
                    });
                recordView.setOnLongClickListener(
                    new View.OnLongClickListener() {
                      @Override
                      public boolean onLongClick(View v) {
                        android.content.ClipboardManager clipboard =
                            (android.content.ClipboardManager)
                                getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                        android.content.ClipData clip =
                            android.content.ClipData.newPlainText(
                                "Phone number", "+" + record.getPhone());
                        clipboard.setPrimaryClip(clip);
                        Toast.makeText(
                                getActivity(), R.string.toast_phone_copied, Toast.LENGTH_SHORT)
                            .show();
                        return true;
                      }
                    });
              }
            }
          }
        });

    view.findViewById(R.id.chatSettings)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                startActivity(new Intent(getActivity(), ChatSettingsActivity.class));
              }
            });

    view.findViewById(R.id.encryption)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                startActivity(new Intent(getActivity(), SecuritySettingsActivity.class));
              }
            });

    view.findViewById(R.id.askQuestion)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                execute(
                    messenger().findUsers("75551234567"),
                    R.string.progress_common,
                    new CommandCallback<UserVM[]>() {
                      @Override
                      public void onResult(UserVM[] res) {
                        if (res.length >= 1) {
                          startActivity(
                              Intents.openPrivateDialog(res[0].getId(), true, getActivity()));
                        }
                      }

                      @Override
                      public void onError(Exception e) {}
                    });
              }
            });

    avatarView = (CoverAvatarView) view.findViewById(R.id.avatar);
    avatarView.setBkgrnd((ImageView) view.findViewById(R.id.avatar_bgrnd));

    bind(avatarView, users().get(myUid()).getAvatar());

    view.findViewById(R.id.avatar)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                startActivity(ViewAvatarActivity.viewAvatar(myUid(), getActivity()));
              }
            });

    final ScrollView scrollView = ((ScrollView) view.findViewById(R.id.scrollContainer));

    scrollView
        .getViewTreeObserver()
        .addOnScrollChangedListener(
            new ViewTreeObserver.OnScrollChangedListener() {
              @Override
              public void onScrollChanged() {
                updateActionBar(scrollView.getScrollY());
              }
            });

    updateActionBar(scrollView.getScrollY());

    return view;
  }
 public int getScrollY() {
   if (mScrollView != null) {
     return mScrollView.getScrollY();
   }
   return 0;
 }
  @Override
  public View onCreateView(
      final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_settings, container, false);

    shp = getActivity().getSharedPreferences("wallpaper", Context.MODE_PRIVATE);
    ed = shp.edit();

    baseColor = getResources().getColor(R.color.primary);
    final ActorStyle style = ActorSDK.sharedActor().style;
    final UserVM userModel = users().get(myUid());

    final TextView nameView = (TextView) view.findViewById(R.id.name);
    nameView.setShadowLayer(1, 1, 1, style.getDividerColor());
    nameView.setTextColor(style.getProfileTitleColor());
    bind(nameView, userModel.getName());

    view.findViewById(R.id.notifications)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                startActivity(new Intent(getActivity(), NotificationsActivity.class));
              }
            });

    view.findViewById(R.id.helpSettings)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                startActivity(new Intent(getActivity(), HelpActivity.class));
              }
            });

    final LinearLayout nickContainer = (LinearLayout) view.findViewById(R.id.nickContainer);
    final LinearLayout contactsContainer = (LinearLayout) view.findViewById(R.id.phoneContainer);
    final FrameLayout about = (FrameLayout) view.findViewById(R.id.about);

    // TODO: Move bindings to onResume
    bind(
        userModel.getNick(),
        new ValueChangedListener<String>() {
          @Override
          public void onChanged(final String val, Value<String> Value) {
            final View recordView = inflater.inflate(R.layout.contact_record, nickContainer, false);
            recordView
                .findViewById(R.id.divider)
                .setBackgroundColor(ActorSDK.sharedActor().style.getDividerColor());
            TintImageView nickIcon = (TintImageView) recordView.findViewById(R.id.recordIcon);
            nickIcon.setTint(ActorSDK.sharedActor().style.getSettingsCategoryTextColor());
            nickIcon.setResource(R.drawable.ic_star_white_36dp);

            String value =
                (val != null && !val.isEmpty()) ? val : getString(R.string.nickname_empty);
            String title = getString(R.string.nickname);

            TextView nickValue = (TextView) recordView.findViewById(R.id.value);
            nickValue.setText(value);
            nickValue.setTextColor(style.getTextPrimaryColor());
            TextView nickTitle = (TextView) recordView.findViewById(R.id.title);
            nickTitle.setText(title);
            nickTitle.setTextColor(style.getTextSecondaryColor());
            nickContainer.removeAllViews();
            nickContainer.addView(
                recordView,
                new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Screen.dp(72)));

            recordView.setOnClickListener(
                new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                    getActivity().startActivity(Intents.editUserNick(getActivity()));
                  }
                });
          }
        });

    final TextView aboutTitle = (TextView) about.findViewById(R.id.value);
    TintImageView aboutIcon = (TintImageView) about.findViewById(R.id.recordIcon);
    aboutIcon.setTint(ActorSDK.sharedActor().style.getSettingsCategoryTextColor());
    aboutIcon.setResource(R.drawable.ic_editor_format_quote_36dp);
    TextView aboutValue = (TextView) about.findViewById(R.id.title);
    aboutTitle.setTextColor(style.getTextPrimaryColor());
    aboutValue.setTextColor(style.getTextSecondaryColor());
    aboutValue.setText(getString(R.string.about_user_me));
    aboutTitle.setEllipsize(TextUtils.TruncateAt.END);
    about
        .findViewById(R.id.divider)
        .setBackgroundColor(ActorSDK.sharedActor().style.getDividerColor());
    about.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            getActivity().startActivity(Intents.editUserAbout(getActivity()));
          }
        });

    bind(
        userModel.getAbout(),
        new ValueChangedListener<String>() {
          @Override
          public void onChanged(String val, Value<String> valueModel) {
            if (val != null && !val.isEmpty()) {
              aboutTitle.setText(val);
            } else {
              aboutTitle.setText(getString(R.string.edit_about_edittext_hint));
            }
          }
        });

    bind(
        userModel.getPhones(),
        new ValueChangedListener<ArrayListUserPhone>() {
          @Override
          public void onChanged(ArrayListUserPhone val, Value<ArrayListUserPhone> Value) {
            if (val.size() == 0) {
              noPhones = true;
            } else {
              contactsContainer.setVisibility(View.VISIBLE);
              for (int i = 0; i < val.size(); i++) {
                final UserPhone record = val.get(i);
                View recordView =
                    inflater.inflate(R.layout.contact_record, contactsContainer, false);
                TintImageView tintImageView =
                    (TintImageView) recordView.findViewById(R.id.recordIcon);
                tintImageView.setTint(ActorSDK.sharedActor().style.getSettingsCategoryTextColor());
                if (i == 0) {
                  tintImageView.setResource(R.drawable.ic_call_white_36dp);
                  tintImageView.setVisibility(View.VISIBLE);
                } else {
                  tintImageView.setVisibility(View.INVISIBLE);
                }

                View divider = recordView.findViewById(R.id.divider);
                if (i == val.size() - 1
                    && (userModel.getEmails().get() == null
                        || userModel.getEmails().get().isEmpty())) {
                  divider.setVisibility(View.GONE);
                } else {
                  divider.setVisibility(View.VISIBLE);
                }
                divider.setBackgroundColor(ActorSDK.sharedActor().style.getDividerColor());

                String _phoneNumber;
                try {
                  Phonenumber.PhoneNumber number =
                      PhoneNumberUtil.getInstance().parse("+" + record.getPhone(), "us");
                  _phoneNumber =
                      PhoneNumberUtil.getInstance()
                          .format(number, PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL);
                } catch (NumberParseException e) {
                  e.printStackTrace();
                  _phoneNumber = "+" + record.getPhone();
                }
                final String phoneNumber = _phoneNumber;

                TextView value = (TextView) recordView.findViewById(R.id.value);
                value.setTextColor(style.getTextPrimaryColor());
                value.setText(phoneNumber);
                TextView title = (TextView) recordView.findViewById(R.id.title);
                title.setTextColor(style.getTextSecondaryColor());
                title.setText(record.getTitle());
                contactsContainer.addView(
                    recordView,
                    new LinearLayout.LayoutParams(
                        ViewGroup.LayoutParams.MATCH_PARENT, Screen.dp(72)));

                recordView.setOnClickListener(
                    new View.OnClickListener() {
                      @Override
                      public void onClick(View v) {
                        new AlertDialog.Builder(getActivity())
                            .setItems(
                                new CharSequence[] {
                                  getString(R.string.phone_menu_call).replace("{0}", phoneNumber),
                                  getString(R.string.phone_menu_sms).replace("{0}", phoneNumber),
                                  getString(R.string.phone_menu_share).replace("{0}", phoneNumber),
                                  getString(R.string.phone_menu_copy)
                                },
                                new DialogInterface.OnClickListener() {
                                  @Override
                                  public void onClick(DialogInterface dialog, int which) {
                                    if (which == 0) {
                                      startActivity(
                                          new Intent(Intent.ACTION_DIAL)
                                              .setData(Uri.parse("tel:+" + record.getPhone())));
                                    } else if (which == 1) {
                                      startActivity(
                                          new Intent(Intent.ACTION_VIEW)
                                              .setData(Uri.parse("sms:+" + record.getPhone())));
                                    } else if (which == 2) {
                                      startActivity(
                                          new Intent(Intent.ACTION_SEND)
                                              .setType("text/plain")
                                              .putExtra(
                                                  Intent.EXTRA_TEXT,
                                                  getString(R.string.settings_share_text)
                                                      .replace("{0}", phoneNumber)
                                                      .replace("{1}", userModel.getName().get())));
                                    } else if (which == 3) {
                                      ClipboardManager clipboard =
                                          (ClipboardManager)
                                              getActivity()
                                                  .getSystemService(Context.CLIPBOARD_SERVICE);
                                      ClipData clip =
                                          ClipData.newPlainText("Phone number", phoneNumber);
                                      clipboard.setPrimaryClip(clip);
                                      Toast.makeText(
                                              getActivity(),
                                              R.string.toast_phone_copied,
                                              Toast.LENGTH_SHORT)
                                          .show();
                                    }
                                  }
                                })
                            .show()
                            .setCanceledOnTouchOutside(true);
                      }
                    });
                recordView.setOnLongClickListener(
                    new View.OnLongClickListener() {
                      @Override
                      public boolean onLongClick(View v) {
                        ClipboardManager clipboard =
                            (ClipboardManager)
                                getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                        ClipData clip =
                            ClipData.newPlainText("Phone number", "+" + record.getPhone());
                        clipboard.setPrimaryClip(clip);
                        Toast.makeText(
                                getActivity(), R.string.toast_phone_copied, Toast.LENGTH_SHORT)
                            .show();
                        return true;
                      }
                    });
              }
            }
          }
        });

    bind(
        userModel.getEmails(),
        new ValueChangedListener<ArrayListUserEmail>() {
          @Override
          public void onChanged(ArrayListUserEmail val, Value<ArrayListUserEmail> Value) {
            if (val.size() == 0) {
              noEmails = true;
            } else {
              contactsContainer.setVisibility(View.VISIBLE);
              for (int i = 0; i < val.size(); i++) {
                final UserEmail record = val.get(i);
                View recordView =
                    inflater.inflate(R.layout.contact_record, contactsContainer, false);
                TintImageView tintImageView =
                    (TintImageView) recordView.findViewById(R.id.recordIcon);
                tintImageView.setTint(ActorSDK.sharedActor().style.getSettingsCategoryTextColor());
                if (i == 0) {
                  tintImageView.setResource(R.drawable.ic_email_white_36dp);
                  tintImageView.setVisibility(View.VISIBLE);
                } else {
                  tintImageView.setVisibility(View.INVISIBLE);
                }

                View divider = recordView.findViewById(R.id.divider);
                if (i != val.size() - 1) {
                  divider.setVisibility(View.VISIBLE);
                } else {
                  divider.setVisibility(View.GONE);
                }
                divider.setBackgroundColor(ActorSDK.sharedActor().style.getDividerColor());

                final String email = record.getEmail();

                TextView value = (TextView) recordView.findViewById(R.id.value);
                value.setTextColor(style.getTextPrimaryColor());
                value.setText(email);
                TextView title = (TextView) recordView.findViewById(R.id.title);
                title.setTextColor(style.getTextSecondaryColor());
                title.setText(record.getTitle());
                contactsContainer.addView(
                    recordView,
                    new LinearLayout.LayoutParams(
                        ViewGroup.LayoutParams.MATCH_PARENT, Screen.dp(72)));

                recordView.setOnClickListener(
                    new View.OnClickListener() {
                      @Override
                      public void onClick(View v) {
                        new AlertDialog.Builder(getActivity())
                            .setItems(
                                new CharSequence[] {
                                  getString(R.string.email_menu_email).replace("{0}", email),
                                  getString(R.string.phone_menu_copy)
                                },
                                new DialogInterface.OnClickListener() {
                                  @Override
                                  public void onClick(DialogInterface dialog, int which) {
                                    if (which == 0) {
                                      startActivity(
                                          new Intent(
                                              Intent.ACTION_SENDTO,
                                              Uri.fromParts("mailto", record.getEmail(), null)));
                                    } else if (which == 1) {
                                      ClipboardManager clipboard =
                                          (ClipboardManager)
                                              getActivity()
                                                  .getSystemService(Context.CLIPBOARD_SERVICE);
                                      ClipData clip = ClipData.newPlainText("Email", email);
                                      clipboard.setPrimaryClip(clip);
                                      Toast.makeText(
                                              getActivity(),
                                              R.string.toast_email_copied,
                                              Toast.LENGTH_SHORT)
                                          .show();
                                    }
                                  }
                                })
                            .show()
                            .setCanceledOnTouchOutside(true);
                      }
                    });
                recordView.setOnLongClickListener(
                    new View.OnLongClickListener() {
                      @Override
                      public boolean onLongClick(View v) {
                        ClipboardManager clipboard =
                            (ClipboardManager)
                                getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                        ClipData clip = ClipData.newPlainText("Email", "+" + record.getEmail());
                        clipboard.setPrimaryClip(clip);
                        Toast.makeText(
                                getActivity(), R.string.toast_email_copied, Toast.LENGTH_SHORT)
                            .show();
                        return true;
                      }
                    });
              }
            }
          }
        });

    if (noEmails && noPhones) {
      contactsContainer.setVisibility(View.GONE);
      about.findViewById(R.id.divider).setVisibility(View.INVISIBLE);
    }

    view.findViewById(R.id.chatSettings)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                startActivity(new Intent(getActivity(), ChatSettingsActivity.class));
              }
            });

    view.findViewById(R.id.encryption)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                startActivity(new Intent(getActivity(), SecuritySettingsActivity.class));
              }
            });

    view.findViewById(R.id.askQuestion)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                execute(
                    messenger().findUsers("75551234567"),
                    R.string.progress_common,
                    new CommandCallback<UserVM[]>() {
                      @Override
                      public void onResult(UserVM[] res) {
                        if (res.length >= 1) {
                          startActivity(
                              Intents.openPrivateDialog(res[0].getId(), true, getActivity()));
                        }
                      }

                      @Override
                      public void onError(Exception e) {}
                    });
              }
            });

    TextView settingsHeaderText = (TextView) view.findViewById(R.id.settings_header_text);
    settingsHeaderText.setTextColor(ActorSDK.sharedActor().style.getSettingsCategoryTextColor());

    TextView settingsNotificationsTitle =
        (TextView) view.findViewById(R.id.settings_notifications_title);
    settingsNotificationsTitle.setTextColor(ActorSDK.sharedActor().style.getSettingsTitleColor());

    TextView settingsChatTitle = (TextView) view.findViewById(R.id.settings_chat_title);
    settingsChatTitle.setTextColor(ActorSDK.sharedActor().style.getSettingsTitleColor());

    TextView securityTitle = (TextView) view.findViewById(R.id.settings_security_title);
    securityTitle.setTextColor(ActorSDK.sharedActor().style.getSettingsTitleColor());

    TintImageView securityIcon = (TintImageView) view.findViewById(R.id.settings_security_icon);
    securityIcon.setTint(style.getSettingsIconColor());

    TextView helpTitle = (TextView) view.findViewById(R.id.settings_help_title);
    helpTitle.setTextColor(ActorSDK.sharedActor().style.getSettingsTitleColor());

    TintImageView helpIcon = (TintImageView) view.findViewById(R.id.settings_help_icon);
    helpIcon.setTint(style.getSettingsIconColor());

    TextView askTitle = (TextView) view.findViewById(R.id.settings_ask_title);
    askTitle.setTextColor(ActorSDK.sharedActor().style.getSettingsTitleColor());

    TintImageView askIcon = (TintImageView) view.findViewById(R.id.settings_ask_icon);
    askIcon.setTint(style.getSettingsIconColor());

    TintImageView notificationsSettingsIcon =
        (TintImageView) view.findViewById(R.id.settings_notification_icon);
    notificationsSettingsIcon.setTint(style.getSettingsIconColor());

    TintImageView chatSettingsIcon = (TintImageView) view.findViewById(R.id.settings_chat_icon);
    chatSettingsIcon.setTint(style.getSettingsIconColor());

    view.findViewById(R.id.after_phone_divider)
        .setBackgroundColor(ActorSDK.sharedActor().style.getBackyardBackgroundColor());
    view.findViewById(R.id.bottom_divider)
        .setBackgroundColor(ActorSDK.sharedActor().style.getBackyardBackgroundColor());

    view.findViewById(R.id.divider1)
        .setBackgroundColor(ActorSDK.sharedActor().style.getDividerColor());
    view.findViewById(R.id.divider2)
        .setBackgroundColor(ActorSDK.sharedActor().style.getDividerColor());
    view.findViewById(R.id.divider3)
        .setBackgroundColor(ActorSDK.sharedActor().style.getDividerColor());
    view.findViewById(R.id.divider4)
        .setBackgroundColor(ActorSDK.sharedActor().style.getDividerColor());

    if (getBeforeNickSettingsView() != null) {
      FrameLayout beforeNick = (FrameLayout) view.findViewById(R.id.before_nick_container);
      beforeNick.addView(
          getBeforeNickSettingsView(),
          FrameLayout.LayoutParams.MATCH_PARENT,
          FrameLayout.LayoutParams.WRAP_CONTENT);
    }
    if (getBeforeNickSettingsView() != null) {
      FrameLayout afterPhone = (FrameLayout) view.findViewById(R.id.after_phone_container);
      afterPhone.addView(
          getAfterPhoneSettingsView(),
          FrameLayout.LayoutParams.MATCH_PARENT,
          FrameLayout.LayoutParams.WRAP_CONTENT);
    }
    if (getSettingsTopView() != null) {
      FrameLayout settingsTop = (FrameLayout) view.findViewById(R.id.settings_top_container);
      settingsTop.addView(
          getSettingsTopView(),
          FrameLayout.LayoutParams.MATCH_PARENT,
          FrameLayout.LayoutParams.WRAP_CONTENT);
    }
    if (getSettingsBottomView() != null) {
      FrameLayout settingsBot = (FrameLayout) view.findViewById(R.id.settings_bottom_container);
      settingsBot.addView(
          getSettingsBottomView(),
          FrameLayout.LayoutParams.MATCH_PARENT,
          FrameLayout.LayoutParams.WRAP_CONTENT);
    }

    if (getBeforeSettingsCategories() != null) {
      LinearLayout beforeSettings =
          (LinearLayout) view.findViewById(R.id.before_settings_container);
      addCategories(beforeSettings, getBeforeSettingsCategories(), inflater);
    }

    if (getAfterSettingsCategories() != null) {
      LinearLayout afterSettings = (LinearLayout) view.findViewById(R.id.after_settings_container);
      addCategories(afterSettings, getAfterSettingsCategories(), inflater);
    }

    avatarView = (CoverAvatarView) view.findViewById(R.id.avatar);
    ImageView avatarBkgrnd = (ImageView) view.findViewById(R.id.avatar_bgrnd);
    avatarBkgrnd.setBackgroundColor(ActorSDK.sharedActor().style.getAvatarBackgroundColor());
    avatarView.setBkgrnd(avatarBkgrnd);

    bind(avatarView, users().get(myUid()).getAvatar());

    // Wallpaper
    LinearLayout wallpaperContainer = (LinearLayout) view.findViewById(R.id.background_container);
    wallpaperContainer.setBackgroundColor(style.getMainBackgroundColor());
    ((TextView) view.findViewById(R.id.settings_wallpaper_title))
        .setTextColor(style.getSettingsCategoryTextColor());
    view.findViewById(R.id.wallpaperDivider).setBackgroundColor(style.getBackyardBackgroundColor());
    View.OnClickListener ocl =
        new View.OnClickListener() {

          @Override
          public void onClick(final View v) {
            Intent i = new Intent(getActivity(), PickWallpaperActivity.class);
            int j = 0;
            Object tag = v.getTag();
            if (tag != null && tag instanceof Integer) {
              j = (int) tag;
            }
            i.putExtra("EXTRA_ID", j);
            startActivity(i);
          }
        };
    int previewSize = 80;
    LinearLayout.LayoutParams params =
        new LinearLayout.LayoutParams(Screen.dp(previewSize), Screen.dp(previewSize));
    for (int i = 0; i < 3; i++) {
      FrameLayout frame = new FrameLayout(getActivity());
      BackgroundPreviewView bckgrnd = new BackgroundPreviewView(getActivity());
      bckgrnd.init(Screen.dp(previewSize), Screen.dp(previewSize));
      bckgrnd.bind(i);
      // bckgrnd.setPadding(Screen.dp(5), Screen.dp(10), Screen.dp(5), Screen.dp(20));
      frame.setTag(i);
      frame.setOnClickListener(ocl);
      frame.addView(bckgrnd);
      wallpaperContainer.addView(frame, params);
    }
    TintImageView next = new TintImageView(getActivity());
    next.setResource(R.drawable.ic_keyboard_arrow_right_white_36dp);
    next.setTint(style.getSettingsIconColor());
    next.setOnClickListener(ocl);
    next.setTag(-1);
    wallpaperContainer.addView(
        next, new LinearLayout.LayoutParams(Screen.dp(40), Screen.dp(previewSize)));

    view.findViewById(R.id.avatar)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                startActivity(ViewAvatarActivity.viewAvatar(myUid(), getActivity()));
              }
            });

    final ScrollView scrollView = ((ScrollView) view.findViewById(R.id.scrollContainer));
    scrollView.setBackgroundColor(ActorSDK.sharedActor().style.getMainBackgroundColor());
    scrollView
        .getViewTreeObserver()
        .addOnScrollChangedListener(
            new ViewTreeObserver.OnScrollChangedListener() {
              @Override
              public void onScrollChanged() {
                updateActionBar(scrollView.getScrollY());
              }
            });

    updateActionBar(scrollView.getScrollY());

    return view;
  }
 protected void onSaveInstanceState(Bundle b) {
   super.onSaveInstanceState(b);
   b.putBoolean("changed", changed);
   b.putIntArray("ARTICLE_SCROLL_POSITION", new int[] {sv.getScrollX(), sv.getScrollY()});
 }