public void updatePhotosButton() {
    int count = photoAttachAdapter.getSelectedPhotos().size();
    if (count == 0) {
      sendPhotosButton.imageView.setPadding(0, AndroidUtilities.dp(4), 0, 0);
      sendPhotosButton.imageView.setBackgroundResource(R.drawable.attach_hide_states);
      sendPhotosButton.imageView.setImageResource(R.drawable.attach_hide2);
      sendPhotosButton.textView.setText("");
    } else {
      sendPhotosButton.imageView.setPadding(AndroidUtilities.dp(2), 0, 0, 0);
      sendPhotosButton.imageView.setBackgroundResource(R.drawable.attach_send_states);
      sendPhotosButton.imageView.setImageResource(R.drawable.attach_send2);
      sendPhotosButton.textView.setText(
          LocaleController.formatString(
              "SendItems", R.string.SendItems, String.format("(%d)", count)));
    }

    if (Build.VERSION.SDK_INT >= 23
        && getContext().checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
            != PackageManager.PERMISSION_GRANTED) {
      progressView.setText(
          LocaleController.getString("PermissionStorage", R.string.PermissionStorage));
      progressView.setTextSize(16);
    } else {
      progressView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos));
      progressView.setTextSize(20);
    }
  }
  @Override
  public void applySelfActionBar() {
    if (parentActivity == null) {
      return;
    }
    ActionBar actionBar = parentActivity.getSupportActionBar();
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayUseLogoEnabled(false);
    actionBar.setDisplayShowCustomEnabled(false);
    actionBar.setCustomView(null);
    actionBar.setSubtitle(null);
    actionBar.setTitle(LocaleController.getString("NewGroup", R.string.NewGroup));

    TextView title = (TextView) parentActivity.findViewById(R.id.action_bar_title);
    if (title == null) {
      final int subtitleId =
          parentActivity.getResources().getIdentifier("action_bar_title", "id", "android");
      title = (TextView) parentActivity.findViewById(subtitleId);
    }
    if (title != null) {
      title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
      title.setCompoundDrawablePadding(0);
    }
  }
  private void createActionBarMenu() {
    ActionBarMenu menu = actionBarLayer.createMenu();
    menu.clearItems();

    if (ContactsController.getInstance().contactsDict.get(user_id) == null) {
      TLRPC.User user = MessagesController.getInstance().users.get(user_id);
      if (user == null) {
        return;
      }
      ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_other);
      if (user.phone != null && user.phone.length() != 0) {
        item.addSubItem(
            add_contact, LocaleController.getString("AddContact", R.string.AddContact), 0);
        item.addSubItem(
            block_contact, LocaleController.getString("BlockContact", R.string.BlockContact), 0);
      } else {
        item.addSubItem(
            block_contact, LocaleController.getString("BlockContact", R.string.BlockContact), 0);
      }
    } else {
      ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_other);
      item.addSubItem(
          share_contact, LocaleController.getString("ShareContact", R.string.ShareContact), 0);
      item.addSubItem(
          block_contact, LocaleController.getString("BlockContact", R.string.BlockContact), 0);
      item.addSubItem(
          edit_contact, LocaleController.getString("EditContact", R.string.EditContact), 0);
      item.addSubItem(
          delete_contact, LocaleController.getString("DeleteContact", R.string.DeleteContact), 0);
    }
  }
 @Override
 public View getSectionHeaderView(int section, View convertView, ViewGroup parent) {
   if (convertView == null) {
     LayoutInflater li =
         (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     convertView = li.inflate(R.layout.settings_section_layout, parent, false);
     convertView.setBackgroundColor(0xffffffff);
   }
   TextView textView = (TextView) convertView.findViewById(R.id.settings_section_text);
   if (selectedContacts.size() == 1) {
     textView.setText(
         selectedContacts.size() + " " + LocaleController.getString("MEMBER", R.string.MEMBER));
   } else {
     textView.setText(
         selectedContacts.size()
             + " "
             + LocaleController.getString("MEMBERS", R.string.MEMBERS));
   }
   return convertView;
 }
  @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    SupportMenuItem doneItem = (SupportMenuItem) menu.add(Menu.NONE, 0, Menu.NONE, null);
    doneItem.setShowAsAction(SupportMenuItem.SHOW_AS_ACTION_ALWAYS);
    doneItem.setActionView(R.layout.group_create_done_layout);

    TextView doneTextView = (TextView) doneItem.getActionView().findViewById(R.id.done_button);
    doneTextView.setText(LocaleController.getString("Done", R.string.Done));
    doneTextView.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            if (donePressed || parentActivity == null) {
              return;
            }
            if (nameTextView.getText().length() == 0) {
              return;
            }
            donePressed = true;

            if (avatarUpdater.uploadingAvatar != null) {
              createAfterUpload = true;
            } else {
              progressDialog = new ProgressDialog(parentActivity);
              progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading));
              progressDialog.setCanceledOnTouchOutside(false);
              progressDialog.setCancelable(false);

              final long reqId =
                  MessagesController.getInstance()
                      .createChat(
                          nameTextView.getText().toString(), selectedContacts, uploadedAvatar);

              progressDialog.setButton(
                  DialogInterface.BUTTON_NEGATIVE,
                  LocaleController.getString("Cancel", R.string.Cancel),
                  new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                      ConnectionsManager.getInstance().cancelRpc(reqId, true);
                      donePressed = false;
                      try {
                        dialog.dismiss();
                      } catch (Exception e) {
                        FileLog.e("tmessages", e);
                      }
                    }
                  });
              progressDialog.show();
            }
          }
        });
  }
  @Override
  public View getView(int i, View view, ViewGroup viewGroup) {
    int type = getItemViewType(i);
    if (type == 0) {
      if (view == null) {
        view = new DrawerProfileCell(mContext);
      }
      ((DrawerProfileCell) view)
          .setUser(MessagesController.getInstance().getUser(UserConfig.getClientUserId()));
    } else if (type == 1) {
      if (view == null) {
        view = new EmptyCell(mContext, AndroidUtilities.dp(8));
      }
    } else if (type == 2) {
      if (view == null) {
        view = new DividerCell(mContext);
      }
    } else if (type == 3) {
      if (view == null) {
        view = new DrawerActionCell(mContext);
      }
      DrawerActionCell actionCell = (DrawerActionCell) view;
      if (i == 2) {
        actionCell.setTextAndIcon(
            LocaleController.getString("NewGroup", R.string.NewGroup), R.drawable.menu_newgroup);
      } else if (i == 3) {
        actionCell.setTextAndIcon(
            LocaleController.getString("NewSecretChat", R.string.NewSecretChat),
            R.drawable.menu_secret);
      } else if (i == 4) {
        actionCell.setTextAndIcon(
            LocaleController.getString("NewChannel", R.string.NewChannel),
            R.drawable.menu_broadcast);
      } else if (i == 6) {
        actionCell.setTextAndIcon(
            LocaleController.getString("Contacts", R.string.Contacts), R.drawable.menu_contacts);
      } else if (i == 7) {
        actionCell.setTextAndIcon(
            LocaleController.getString("InviteFriends", R.string.InviteFriends),
            R.drawable.menu_invite);
      } else if (i == 8) {
        actionCell.setTextAndIcon(
            LocaleController.getString("Settings", R.string.Settings), R.drawable.menu_settings);
      } else if (i == 9) {
        actionCell.setTextAndIcon(
            LocaleController.getString("Finger2ViewFaq", R.string.Finger2ViewFaq),
            R.drawable.menu_help);
      }
    }

    return view;
  }
 public void updatePhotosButton() {
   int count = photoAttachAdapter.getSelectedPhotos().size();
   if (count == 0) {
     sendPhotosButton.imageView.setPadding(0, AndroidUtilities.dp(4), 0, 0);
     sendPhotosButton.imageView.setBackgroundResource(R.drawable.attach_hide_states);
     sendPhotosButton.imageView.setImageResource(R.drawable.attach_hide2);
     sendPhotosButton.textView.setText("");
   } else {
     sendPhotosButton.imageView.setPadding(AndroidUtilities.dp(2), 0, 0, 0);
     sendPhotosButton.imageView.setBackgroundResource(R.drawable.attach_send_states);
     sendPhotosButton.imageView.setImageResource(R.drawable.attach_send2);
     sendPhotosButton.textView.setText(
         LocaleController.formatString(
             "SendItems", R.string.SendItems, String.format("(%d)", count)));
   }
 }
  @Override
  public View createView(LayoutInflater inflater, ViewGroup container) {
    if (fragmentView == null) {
      actionBarLayer.setDisplayHomeAsUpEnabled(true, R.drawable.ic_ab_back);
      actionBarLayer.setBackOverlay(R.layout.updating_state_layout);
      if (dialog_id != 0) {
        actionBarLayer.setTitle(LocaleController.getString("SecretTitle", R.string.SecretTitle));
        actionBarLayer.setTitleIcon(R.drawable.ic_lock_white, Utilities.dp(4));
      } else {
        actionBarLayer.setTitle(LocaleController.getString("ContactInfo", R.string.ContactInfo));
      }
      actionBarLayer.setActionBarMenuOnItemClick(
          new ActionBarLayer.ActionBarMenuOnItemClick() {
            @Override
            public void onItemClick(int id) {
              if (id == -1) {
                finishFragment();
              } else if (id == block_contact) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setMessage(LocaleController.getString("AreYouSure", R.string.AreYouSure));
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                builder.setPositiveButton(
                    LocaleController.getString("OK", R.string.OK),
                    new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialogInterface, int i) {
                        TLRPC.User user = MessagesController.getInstance().users.get(user_id);
                        if (user == null) {
                          return;
                        }
                        TLRPC.TL_contacts_block req = new TLRPC.TL_contacts_block();
                        req.id = MessagesController.getInputUser(user);
                        TLRPC.TL_contactBlocked blocked = new TLRPC.TL_contactBlocked();
                        blocked.user_id = user_id;
                        blocked.date = (int) (System.currentTimeMillis() / 1000);
                        ConnectionsManager.getInstance()
                            .performRpc(
                                req,
                                new RPCRequest.RPCRequestDelegate() {
                                  @Override
                                  public void run(TLObject response, TLRPC.TL_error error) {}
                                },
                                null,
                                true,
                                RPCRequest.RPCRequestClassGeneric);
                      }
                    });
                builder.setNegativeButton(
                    LocaleController.getString("Cancel", R.string.Cancel), null);
                showAlertDialog(builder);
              } else if (id == add_contact) {
                TLRPC.User user = MessagesController.getInstance().users.get(user_id);
                Bundle args = new Bundle();
                args.putInt("user_id", user.id);
                presentFragment(new ContactAddActivity(args));
              } else if (id == share_contact) {
                Bundle args = new Bundle();
                args.putBoolean("onlySelect", true);
                args.putBoolean("serverOnly", true);
                MessagesActivity fragment = new MessagesActivity(args);
                fragment.setDelegate(UserProfileActivity.this);
                presentFragment(fragment);
              } else if (id == edit_contact) {
                Bundle args = new Bundle();
                args.putInt("user_id", user_id);
                presentFragment(new ContactAddActivity(args));
              } else if (id == delete_contact) {
                final TLRPC.User user = MessagesController.getInstance().users.get(user_id);
                if (user == null || getParentActivity() == null) {
                  return;
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setMessage(LocaleController.getString("AreYouSure", R.string.AreYouSure));
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                builder.setPositiveButton(
                    LocaleController.getString("OK", R.string.OK),
                    new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialogInterface, int i) {
                        ArrayList<TLRPC.User> arrayList = new ArrayList<TLRPC.User>();
                        arrayList.add(user);
                        ContactsController.getInstance().deleteContact(arrayList);
                      }
                    });
                builder.setNegativeButton(
                    LocaleController.getString("Cancel", R.string.Cancel), null);
                showAlertDialog(builder);
              }
            }
          });

      createActionBarMenu();

      fragmentView = inflater.inflate(R.layout.user_profile_layout, container, false);
      listAdapter = new ListAdapter(getParentActivity());

      TextView textView = (TextView) fragmentView.findViewById(R.id.start_secret_button_text);
      textView.setText(
          LocaleController.getString("StartEncryptedChat", R.string.StartEncryptedChat));

      View startSecretButton = fragmentView.findViewById(R.id.start_secret_button);
      startSecretButton.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              if (getParentActivity() == null) {
                return;
              }
              AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
              builder.setMessage(LocaleController.getString("AreYouSure", R.string.AreYouSure));
              builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
              builder.setPositiveButton(
                  LocaleController.getString("OK", R.string.OK),
                  new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                      creatingChat = true;
                      MessagesController.getInstance()
                          .startSecretChat(
                              getParentActivity(),
                              MessagesController.getInstance().users.get(user_id));
                    }
                  });
              builder.setNegativeButton(
                  LocaleController.getString("Cancel", R.string.Cancel), null);
              showAlertDialog(builder);
            }
          });
      if (dialog_id == 0) {
        startSecretButton.setVisibility(View.VISIBLE);
      } else {
        startSecretButton.setVisibility(View.GONE);
      }

      listView = (ListView) fragmentView.findViewById(R.id.listView);
      listView.setAdapter(listAdapter);
      listView.setOnItemClickListener(
          new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
              if (i == sharedMediaRow) {
                Bundle args = new Bundle();
                if (dialog_id != 0) {
                  args.putLong("dialog_id", dialog_id);
                } else {
                  args.putLong("dialog_id", user_id);
                }
                presentFragment(new MediaActivity(args));
              } else if (i == settingsKeyRow) {
                Bundle args = new Bundle();
                args.putInt("chat_id", (int) (dialog_id >> 32));
                presentFragment(new IdenticonActivity(args));
              } else if (i == settingsTimerRow) {
                if (getParentActivity() == null) {
                  return;
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(
                    LocaleController.getString("MessageLifetime", R.string.MessageLifetime));
                builder.setItems(
                    new CharSequence[] {
                      LocaleController.getString(
                          "ShortMessageLifetimeForever", R.string.ShortMessageLifetimeForever),
                      LocaleController.getString(
                          "ShortMessageLifetime2s", R.string.ShortMessageLifetime2s),
                      LocaleController.getString(
                          "ShortMessageLifetime5s", R.string.ShortMessageLifetime5s),
                      LocaleController.getString(
                          "ShortMessageLifetime1m", R.string.ShortMessageLifetime1m),
                      LocaleController.getString(
                          "ShortMessageLifetime1h", R.string.ShortMessageLifetime1h),
                      LocaleController.getString(
                          "ShortMessageLifetime1d", R.string.ShortMessageLifetime1d),
                      LocaleController.getString(
                          "ShortMessageLifetime1w", R.string.ShortMessageLifetime1w)
                    },
                    new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                        int oldValue = currentEncryptedChat.ttl;
                        if (which == 0) {
                          currentEncryptedChat.ttl = 0;
                        } else if (which == 1) {
                          currentEncryptedChat.ttl = 2;
                        } else if (which == 2) {
                          currentEncryptedChat.ttl = 5;
                        } else if (which == 3) {
                          currentEncryptedChat.ttl = 60;
                        } else if (which == 4) {
                          currentEncryptedChat.ttl = 60 * 60;
                        } else if (which == 5) {
                          currentEncryptedChat.ttl = 60 * 60 * 24;
                        } else if (which == 6) {
                          currentEncryptedChat.ttl = 60 * 60 * 24 * 7;
                        }
                        if (oldValue != currentEncryptedChat.ttl) {
                          if (listView != null) {
                            listView.invalidateViews();
                          }
                          MessagesController.getInstance().sendTTLMessage(currentEncryptedChat);
                          MessagesStorage.getInstance().updateEncryptedChat(currentEncryptedChat);
                        }
                      }
                    });
                builder.setNegativeButton(
                    LocaleController.getString("Cancel", R.string.Cancel), null);
                showAlertDialog(builder);
              } else if (i == settingsNotificationsRow) {
                Bundle args = new Bundle();
                args.putLong("dialog_id", dialog_id == 0 ? user_id : dialog_id);
                presentFragment(new ProfileNotificationsActivity(args));
              }
            }
          });
      if (dialog_id != 0) {
        MessagesController.getInstance().getMediaCount(dialog_id, classGuid, true);
      } else {
        MessagesController.getInstance().getMediaCount(user_id, classGuid, true);
      }
    } else {
      ViewGroup parent = (ViewGroup) fragmentView.getParent();
      if (parent != null) {
        parent.removeView(fragmentView);
      }
    }
    return fragmentView;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.Theme_TMessages);
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    if (AndroidUtilities.isTablet()) {
      setContentView(R.layout.intro_layout_tablet);
    } else {
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
      setContentView(R.layout.intro_layout);
    }

    if (LocaleController.isRTL) {
      icons =
          new int[] {
            R.drawable.intro7,
            R.drawable.intro6,
            R.drawable.intro5,
            R.drawable.intro4,
            R.drawable.intro3,
            R.drawable.intro2,
            R.drawable.intro1
          };
      titles =
          new int[] {
            R.string.Page7Title,
            R.string.Page6Title,
            R.string.Page5Title,
            R.string.Page4Title,
            R.string.Page3Title,
            R.string.Page2Title,
            R.string.Page1Title
          };
      messages =
          new int[] {
            R.string.Page7Message,
            R.string.Page6Message,
            R.string.Page5Message,
            R.string.Page4Message,
            R.string.Page3Message,
            R.string.Page2Message,
            R.string.Page1Message
          };
    } else {
      icons =
          new int[] {
            R.drawable.intro1,
            R.drawable.intro2,
            R.drawable.intro3,
            R.drawable.intro4,
            R.drawable.intro5,
            R.drawable.intro6,
            R.drawable.intro7
          };
      titles =
          new int[] {
            R.string.Page1Title,
            R.string.Page2Title,
            R.string.Page3Title,
            R.string.Page4Title,
            R.string.Page5Title,
            R.string.Page6Title,
            R.string.Page7Title
          };
      messages =
          new int[] {
            R.string.Page1Message,
            R.string.Page2Message,
            R.string.Page3Message,
            R.string.Page4Message,
            R.string.Page5Message,
            R.string.Page6Message,
            R.string.Page7Message
          };
    }
    viewPager = (ViewPager) findViewById(R.id.intro_view_pager);
    TextView startMessagingButton = (TextView) findViewById(R.id.start_messaging_button);
    startMessagingButton.setText(
        LocaleController.getString("StartMessaging", R.string.StartMessaging).toUpperCase());
    if (Build.VERSION.SDK_INT >= 21) {
      StateListAnimator animator = new StateListAnimator();
      animator.addState(
          new int[] {android.R.attr.state_pressed},
          ObjectAnimator.ofFloat(
                  startMessagingButton,
                  "translationZ",
                  AndroidUtilities.dp(2),
                  AndroidUtilities.dp(4))
              .setDuration(200));
      animator.addState(
          new int[] {},
          ObjectAnimator.ofFloat(
                  startMessagingButton,
                  "translationZ",
                  AndroidUtilities.dp(4),
                  AndroidUtilities.dp(2))
              .setDuration(200));
      startMessagingButton.setStateListAnimator(animator);
    }
    topImage1 = (ImageView) findViewById(R.id.icon_image1);
    topImage2 = (ImageView) findViewById(R.id.icon_image2);
    bottomPages = (ViewGroup) findViewById(R.id.bottom_pages);
    topImage2.setVisibility(View.GONE);
    viewPager.setAdapter(new IntroAdapter());
    viewPager.setPageMargin(0);
    viewPager.setOffscreenPageLimit(1);
    viewPager.addOnPageChangeListener(
        new ViewPager.OnPageChangeListener() {
          @Override
          public void onPageScrolled(
              int position, float positionOffset, int positionOffsetPixels) {}

          @Override
          public void onPageSelected(int i) {}

          @Override
          public void onPageScrollStateChanged(int i) {
            if (i == ViewPager.SCROLL_STATE_IDLE || i == ViewPager.SCROLL_STATE_SETTLING) {
              if (lastPage != viewPager.getCurrentItem()) {
                lastPage = viewPager.getCurrentItem();

                final ImageView fadeoutImage;
                final ImageView fadeinImage;
                if (topImage1.getVisibility() == View.VISIBLE) {
                  fadeoutImage = topImage1;
                  fadeinImage = topImage2;

                } else {
                  fadeoutImage = topImage2;
                  fadeinImage = topImage1;
                }

                fadeinImage.bringToFront();
                fadeinImage.setImageResource(icons[lastPage]);
                fadeinImage.clearAnimation();
                fadeoutImage.clearAnimation();

                Animation outAnimation =
                    AnimationUtils.loadAnimation(IntroActivity.this, R.anim.icon_anim_fade_out);
                outAnimation.setAnimationListener(
                    new Animation.AnimationListener() {
                      @Override
                      public void onAnimationStart(Animation animation) {}

                      @Override
                      public void onAnimationEnd(Animation animation) {
                        fadeoutImage.setVisibility(View.GONE);
                      }

                      @Override
                      public void onAnimationRepeat(Animation animation) {}
                    });

                Animation inAnimation =
                    AnimationUtils.loadAnimation(IntroActivity.this, R.anim.icon_anim_fade_in);
                inAnimation.setAnimationListener(
                    new Animation.AnimationListener() {
                      @Override
                      public void onAnimationStart(Animation animation) {
                        fadeinImage.setVisibility(View.VISIBLE);
                      }

                      @Override
                      public void onAnimationEnd(Animation animation) {}

                      @Override
                      public void onAnimationRepeat(Animation animation) {}
                    });

                fadeoutImage.startAnimation(outAnimation);
                fadeinImage.startAnimation(inAnimation);
              }
            }
          }
        });

    startMessagingButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            if (startPressed) {
              return;
            }
            startPressed = true;
            Intent intent2 = new Intent(IntroActivity.this, LaunchActivity.class);
            intent2.putExtra("fromIntro", true);
            startActivity(intent2);
            finish();
          }
        });

    if (BuildVars.DEBUG_VERSION) {
      startMessagingButton.setOnLongClickListener(
          new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
              ConnectionsManager.getInstance().switchBackend();
              return true;
            }
          });
    }

    justCreated = true;
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (fragmentView == null) {
      fragmentView = inflater.inflate(R.layout.group_create_final_layout, container, false);

      final ImageButton button2 =
          (ImageButton) fragmentView.findViewById(R.id.settings_change_avatar_button);
      button2.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View view) {

              AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);

              CharSequence[] items;

              if (avatar != null) {
                items =
                    new CharSequence[] {
                      LocaleController.getString("FromCamera", R.string.FromCamera),
                      LocaleController.getString("FromGalley", R.string.FromGalley),
                      LocaleController.getString("DeletePhoto", R.string.DeletePhoto)
                    };
              } else {
                items =
                    new CharSequence[] {
                      LocaleController.getString("FromCamera", R.string.FromCamera),
                      LocaleController.getString("FromGalley", R.string.FromGalley)
                    };
              }

              builder.setItems(
                  items,
                  new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                      if (i == 0) {
                        avatarUpdater.openCamera();
                      } else if (i == 1) {
                        avatarUpdater.openGallery();
                      } else if (i == 2) {
                        avatar = null;
                        uploadedAvatar = null;
                        avatarImage.setImage(avatar, "50_50", R.drawable.group_blue);
                      }
                    }
                  });
              builder.show().setCanceledOnTouchOutside(true);
            }
          });

      avatarImage = (BackupImageView) fragmentView.findViewById(R.id.settings_avatar_image);

      nameTextView = (EditText) fragmentView.findViewById(R.id.bubble_input_text);
      nameTextView.setHint(
          LocaleController.getString(
              "EnterGroupNamePlaceholder", R.string.EnterGroupNamePlaceholder));
      if (nameToSet != null) {
        nameTextView.setText(nameToSet);
        nameToSet = null;
      }
      listView = (PinnedHeaderListView) fragmentView.findViewById(R.id.listView);
      listView.setAdapter(new ListAdapter(parentActivity));
    } else {
      ViewGroup parent = (ViewGroup) fragmentView.getParent();
      if (parent != null) {
        parent.removeView(fragmentView);
      }
    }
    return fragmentView;
  }
    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
      int type = getItemViewType(i);
      if (type == 0) {
        BackupImageView avatarImage;
        TextView onlineText;
        TLRPC.User user = MessagesController.getInstance().users.get(user_id);
        if (view == null) {
          LayoutInflater li =
              (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          view = li.inflate(R.layout.user_profile_avatar_layout, viewGroup, false);

          onlineText = (TextView) view.findViewById(R.id.settings_online);
          avatarImage = (BackupImageView) view.findViewById(R.id.settings_avatar_image);
          avatarImage.processDetach = false;
          avatarImage.setOnClickListener(
              new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                  TLRPC.User user = MessagesController.getInstance().users.get(user_id);
                  if (user.photo != null && user.photo.photo_big != null) {
                    PhotoViewer.getInstance()
                        .openPhoto(user.photo.photo_big, UserProfileActivity.this);
                  }
                }
              });
        } else {
          avatarImage = (BackupImageView) view.findViewById(R.id.settings_avatar_image);
          onlineText = (TextView) view.findViewById(R.id.settings_online);
        }
        TextView textView = (TextView) view.findViewById(R.id.settings_name);
        Typeface typeface = Utilities.getTypeface("fonts/rmedium.ttf");
        textView.setTypeface(typeface);

        textView.setText(Utilities.formatName(user.first_name, user.last_name));
        onlineText.setText(LocaleController.formatUserStatus(user));

        TLRPC.FileLocation photo = null;
        TLRPC.FileLocation photoBig = null;
        if (user.photo != null) {
          photo = user.photo.photo_small;
          photoBig = user.photo.photo_big;
        }
        avatarImage.setImage(photo, "50_50", Utilities.getUserAvatarForId(user.id));
        avatarImage.imageReceiver.setVisible(
            !PhotoViewer.getInstance().isShowingImage(photoBig), false);
        return view;
      } else if (type == 1) {
        if (view == null) {
          LayoutInflater li =
              (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          view = li.inflate(R.layout.settings_section_layout, viewGroup, false);
        }
        TextView textView = (TextView) view.findViewById(R.id.settings_section_text);
        if (i == phoneSectionRow) {
          textView.setText(LocaleController.getString("PHONE", R.string.PHONE));
        } else if (i == settingsSectionRow) {
          textView.setText(LocaleController.getString("SETTINGS", R.string.SETTINGS));
        } else if (i == sharedMediaSectionRow) {
          textView.setText(LocaleController.getString("SHAREDMEDIA", R.string.SHAREDMEDIA));
        }
      } else if (type == 2) {
        final TLRPC.User user = MessagesController.getInstance().users.get(user_id);
        if (view == null) {
          LayoutInflater li =
              (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          view = li.inflate(R.layout.user_profile_phone_layout, viewGroup, false);
          view.setOnClickListener(
              new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                  if (user.phone == null
                      || user.phone.length() == 0
                      || getParentActivity() == null) {
                    return;
                  }
                  selectedPhone = user.phone;

                  AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());

                  builder.setItems(
                      new CharSequence[] {
                        LocaleController.getString("Copy", R.string.Copy),
                        LocaleController.getString("Call", R.string.Call)
                      },
                      new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                          if (i == 1) {
                            try {
                              Intent intent =
                                  new Intent(
                                      Intent.ACTION_DIAL, Uri.parse("tel:+" + selectedPhone));
                              intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                              getParentActivity().startActivity(intent);
                            } catch (Exception e) {
                              FileLog.e("tmessages", e);
                            }
                          } else if (i == 0) {
                            int sdk = android.os.Build.VERSION.SDK_INT;
                            if (sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
                              android.text.ClipboardManager clipboard =
                                  (android.text.ClipboardManager)
                                      ApplicationLoader.applicationContext.getSystemService(
                                          Context.CLIPBOARD_SERVICE);
                              clipboard.setText(selectedPhone);
                            } else {
                              android.content.ClipboardManager clipboard =
                                  (android.content.ClipboardManager)
                                      ApplicationLoader.applicationContext.getSystemService(
                                          Context.CLIPBOARD_SERVICE);
                              android.content.ClipData clip =
                                  android.content.ClipData.newPlainText("label", selectedPhone);
                              clipboard.setPrimaryClip(clip);
                            }
                          }
                        }
                      });
                  showAlertDialog(builder);
                }
              });
        }
        ImageButton button = (ImageButton) view.findViewById(R.id.settings_edit_name);
        button.setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                TLRPC.User user = MessagesController.getInstance().users.get(user_id);
                if (user == null || user instanceof TLRPC.TL_userEmpty) {
                  return;
                }
                NotificationCenter.getInstance()
                    .postNotificationName(MessagesController.closeChats);
                Bundle args = new Bundle();
                args.putInt("user_id", user_id);
                presentFragment(new ChatActivity(args), true);
              }
            });
        TextView textView = (TextView) view.findViewById(R.id.settings_row_text);
        TextView detailTextView = (TextView) view.findViewById(R.id.settings_row_text_detail);
        View divider = view.findViewById(R.id.settings_row_divider);
        if (i == phoneRow) {
          if (user.phone != null && user.phone.length() != 0) {
            textView.setText(PhoneFormat.getInstance().format("+" + user.phone));
          } else {
            textView.setText("Unknown");
          }
          divider.setVisibility(View.INVISIBLE);
          detailTextView.setText(LocaleController.getString("PhoneMobile", R.string.PhoneMobile));
        }
      } else if (type == 3) {
        if (view == null) {
          LayoutInflater li =
              (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          view = li.inflate(R.layout.user_profile_leftright_row_layout, viewGroup, false);
        }
        TextView textView = (TextView) view.findViewById(R.id.settings_row_text);
        TextView detailTextView = (TextView) view.findViewById(R.id.settings_row_text_detail);

        View divider = view.findViewById(R.id.settings_row_divider);
        if (i == sharedMediaRow) {
          textView.setText(LocaleController.getString("SharedMedia", R.string.SharedMedia));
          if (totalMediaCount == -1) {
            detailTextView.setText(LocaleController.getString("Loading", R.string.Loading));
          } else {
            detailTextView.setText(String.format("%d", totalMediaCount));
          }
          divider.setVisibility(View.INVISIBLE);
        } else if (i == settingsTimerRow) {
          TLRPC.EncryptedChat encryptedChat =
              MessagesController.getInstance().encryptedChats.get((int) (dialog_id >> 32));
          textView.setText(LocaleController.getString("MessageLifetime", R.string.MessageLifetime));
          divider.setVisibility(View.VISIBLE);
          if (encryptedChat.ttl == 0) {
            detailTextView.setText(
                LocaleController.getString(
                    "ShortMessageLifetimeForever", R.string.ShortMessageLifetimeForever));
          } else if (encryptedChat.ttl == 2) {
            detailTextView.setText(
                LocaleController.getString(
                    "ShortMessageLifetime2s", R.string.ShortMessageLifetime2s));
          } else if (encryptedChat.ttl == 5) {
            detailTextView.setText(
                LocaleController.getString(
                    "ShortMessageLifetime5s", R.string.ShortMessageLifetime5s));
          } else if (encryptedChat.ttl == 60) {
            detailTextView.setText(
                LocaleController.getString(
                    "ShortMessageLifetime1m", R.string.ShortMessageLifetime1m));
          } else if (encryptedChat.ttl == 60 * 60) {
            detailTextView.setText(
                LocaleController.getString(
                    "ShortMessageLifetime1h", R.string.ShortMessageLifetime1h));
          } else if (encryptedChat.ttl == 60 * 60 * 24) {
            detailTextView.setText(
                LocaleController.getString(
                    "ShortMessageLifetime1d", R.string.ShortMessageLifetime1d));
          } else if (encryptedChat.ttl == 60 * 60 * 24 * 7) {
            detailTextView.setText(
                LocaleController.getString(
                    "ShortMessageLifetime1w", R.string.ShortMessageLifetime1w));
          } else {
            detailTextView.setText(String.format("%d", encryptedChat.ttl));
          }
        }
      } else if (type == 4) {
        if (view == null) {
          LayoutInflater li =
              (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          view = li.inflate(R.layout.user_profile_identicon_layout, viewGroup, false);
        }
        TextView textView = (TextView) view.findViewById(R.id.settings_row_text);
        View divider = view.findViewById(R.id.settings_row_divider);
        divider.setVisibility(View.VISIBLE);
        IdenticonView identiconView = (IdenticonView) view.findViewById(R.id.identicon_view);
        TLRPC.EncryptedChat encryptedChat =
            MessagesController.getInstance().encryptedChats.get((int) (dialog_id >> 32));
        identiconView.setBytes(encryptedChat.auth_key);
        textView.setText(LocaleController.getString("EncryptionKey", R.string.EncryptionKey));
      } else if (type == 5) {
        if (view == null) {
          LayoutInflater li =
              (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          view = li.inflate(R.layout.settings_row_button_layout, viewGroup, false);
        }
        TextView textView = (TextView) view.findViewById(R.id.settings_row_text);
        View divider = view.findViewById(R.id.settings_row_divider);
        if (i == settingsNotificationsRow) {
          textView.setText(
              LocaleController.getString(
                  "NotificationsAndSounds", R.string.NotificationsAndSounds));
          divider.setVisibility(View.INVISIBLE);
        }
      }
      return view;
    }
Example #12
0
    public void build(int width, int height) {
      CharSequence nameString = "";
      TextPaint currentNamePaint;

      if (encryptedChat != null) {
        drawNameLock = true;
        if (!LocaleController.isRTL) {
          nameLockLeft = Utilities.dp(61 + (usePadding ? 11 : 0));
          nameLeft = Utilities.dp(65 + (usePadding ? 11 : 0)) + lockDrawable.getIntrinsicWidth();
        } else {
          nameLockLeft =
              width - Utilities.dp(63 + (usePadding ? 11 : 0)) - lockDrawable.getIntrinsicWidth();
          nameLeft = usePadding ? Utilities.dp(11) : 0;
        }
      } else {
        drawNameLock = false;
        if (!LocaleController.isRTL) {
          nameLeft = Utilities.dp(61 + (usePadding ? 11 : 0));
        } else {
          nameLeft = usePadding ? Utilities.dp(11) : 0;
        }
      }

      if (currentName != null) {
        nameString = currentName;
      } else {
        String nameString2 = "";
        if (chat != null) {
          nameString2 = chat.title;
        } else if (user != null) {
          nameString2 = Utilities.formatName(user.first_name, user.last_name);
        }
        nameString = nameString2.replace("\n", " ");
      }
      if (nameString.length() == 0) {
        if (user.phone != null && user.phone.length() != 0) {
          nameString = PhoneFormat.getInstance().format("+" + user.phone);
        } else {
          nameString = LocaleController.getString("HiddenName", R.string.HiddenName);
        }
      }
      if (encryptedChat != null) {
        currentNamePaint = nameEncryptedPaint;
      } else {
        currentNamePaint = namePaint;
      }

      if (!LocaleController.isRTL) {
        onlineWidth = nameWidth = width - nameLeft - Utilities.dp(3 + (usePadding ? 11 : 0));
      } else {
        onlineWidth = nameWidth = width - nameLeft - Utilities.dp(61 + (usePadding ? 11 : 0));
      }
      if (drawNameLock) {
        nameWidth -= Utilities.dp(6) + lockDrawable.getIntrinsicWidth();
      }

      CharSequence nameStringFinal =
          TextUtils.ellipsize(
              nameString, currentNamePaint, nameWidth - Utilities.dp(12), TextUtils.TruncateAt.END);
      nameLayout =
          new StaticLayout(
              nameStringFinal,
              currentNamePaint,
              nameWidth,
              Layout.Alignment.ALIGN_NORMAL,
              1.0f,
              0.0f,
              false);

      if (chat == null) {
        if (!LocaleController.isRTL) {
          onlineLeft = Utilities.dp(61 + (usePadding ? 11 : 0));
        } else {
          onlineLeft = usePadding ? Utilities.dp(11) : 0;
        }

        String onlineString = "";
        TextPaint currentOnlinePaint = offlinePaint;

        if (subLabel != null) {
          onlineString = subLabel;
        } else {
          if (user != null) {
            if (user.status == null) {
              onlineString = getResources().getString(R.string.Offline);
            } else {
              int currentTime = ConnectionsManager.getInstance().getCurrentTime();
              if (user.id == UserConfig.clientUserId || user.status.expires > currentTime) {
                currentOnlinePaint = onlinePaint;
                onlineString = getResources().getString(R.string.Online);
              } else {
                if (user.status.expires <= 10000) {
                  onlineString = getResources().getString(R.string.Invisible);
                } else {
                  onlineString = LocaleController.formatDateOnline(user.status.expires);
                }
              }
            }
          }
        }

        CharSequence onlineStringFinal =
            TextUtils.ellipsize(
                onlineString,
                currentOnlinePaint,
                nameWidth - Utilities.dp(12),
                TextUtils.TruncateAt.END);
        onlineLayout =
            new StaticLayout(
                onlineStringFinal,
                currentOnlinePaint,
                nameWidth,
                Layout.Alignment.ALIGN_NORMAL,
                1.0f,
                0.0f,
                false);
        nameTop = Utilities.dp(12);
      } else {
        onlineLayout = null;
        nameTop = Utilities.dp(22);
      }

      if (!LocaleController.isRTL) {
        avatarLeft = usePadding ? Utilities.dp(11) : 0;
      } else {
        avatarLeft = width - Utilities.dp(50 + (usePadding ? 11 : 0));
      }
      avatarImage.imageX = avatarLeft;
      avatarImage.imageY = avatarTop;
      avatarImage.imageW = Utilities.dp(50);
      avatarImage.imageH = Utilities.dp(50);

      double widthpx = 0;
      float left = 0;
      if (LocaleController.isRTL) {
        if (nameLayout.getLineCount() > 0) {
          left = nameLayout.getLineLeft(0);
          if (left == 0) {
            widthpx = Math.ceil(nameLayout.getLineWidth(0));
            if (widthpx < nameWidth) {
              nameLeft += (nameWidth - widthpx);
            }
          }
        }
        if (onlineLayout != null && onlineLayout.getLineCount() > 0) {
          left = onlineLayout.getLineLeft(0);
          if (left == 0) {
            widthpx = Math.ceil(onlineLayout.getLineWidth(0));
            if (widthpx < onlineWidth) {
              onlineLeft += (onlineWidth - widthpx);
            }
          }
        }
      } else {
        if (nameLayout.getLineCount() > 0) {
          left = nameLayout.getLineRight(0);
          if (left == nameWidth) {
            widthpx = Math.ceil(nameLayout.getLineWidth(0));
            if (widthpx < nameWidth) {
              nameLeft -= (nameWidth - widthpx);
            }
          }
        }
        if (onlineLayout != null && onlineLayout.getLineCount() > 0) {
          left = onlineLayout.getLineRight(0);
          if (left == onlineWidth) {
            widthpx = Math.ceil(onlineLayout.getLineWidth(0));
            if (widthpx < onlineWidth) {
              onlineLeft -= (onlineWidth - widthpx);
            }
          }
        }
      }
    }
Example #13
0
  public void buildLayout() {
    CharSequence nameString;
    TextPaint currentNamePaint;

    drawNameBroadcast = false;
    drawNameLock = false;
    drawNameGroup = false;
    drawCheck = false;
    drawNameBot = false;

    if (encryptedChat != null) {
      drawNameLock = true;
      dialog_id = ((long) encryptedChat.id) << 32;
      if (!LocaleController.isRTL) {
        nameLockLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline);
        nameLeft =
            AndroidUtilities.dp(AndroidUtilities.leftBaseline + 4)
                + lockDrawable.getIntrinsicWidth();
      } else {
        nameLockLeft =
            getMeasuredWidth()
                - AndroidUtilities.dp(AndroidUtilities.leftBaseline + 2)
                - lockDrawable.getIntrinsicWidth();
        nameLeft = AndroidUtilities.dp(11);
      }
      nameLockTop = AndroidUtilities.dp(16.5f);
    } else {
      if (chat != null) {
        if (chat.id < 0) {
          dialog_id = AndroidUtilities.makeBroadcastId(chat.id);
          drawNameBroadcast = true;
          nameLockTop = AndroidUtilities.dp(28.5f);
        } else {
          dialog_id = -chat.id;
          if (ChatObject.isChannel(chat) && !chat.megagroup) {
            drawNameBroadcast = true;
            nameLockTop = AndroidUtilities.dp(28.5f);
          } else {
            drawNameGroup = true;
            nameLockTop = AndroidUtilities.dp(30);
          }
        }
        drawCheck = chat.verified;
        if (!LocaleController.isRTL) {
          nameLockLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline);
          nameLeft =
              AndroidUtilities.dp(AndroidUtilities.leftBaseline + 4)
                  + (drawNameGroup
                      ? groupDrawable.getIntrinsicWidth()
                      : broadcastDrawable.getIntrinsicWidth());
        } else {
          nameLockLeft =
              getMeasuredWidth()
                  - AndroidUtilities.dp(AndroidUtilities.leftBaseline + 2)
                  - (drawNameGroup
                      ? groupDrawable.getIntrinsicWidth()
                      : broadcastDrawable.getIntrinsicWidth());
          nameLeft = AndroidUtilities.dp(11);
        }
      } else {
        dialog_id = user.id;
        if (!LocaleController.isRTL) {
          nameLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline);
        } else {
          nameLeft = AndroidUtilities.dp(11);
        }
        if (user.bot) {
          drawNameBot = true;
          if (!LocaleController.isRTL) {
            nameLockLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline);
            nameLeft =
                AndroidUtilities.dp(AndroidUtilities.leftBaseline + 4)
                    + botDrawable.getIntrinsicWidth();
          } else {
            nameLockLeft =
                getMeasuredWidth()
                    - AndroidUtilities.dp(AndroidUtilities.leftBaseline + 2)
                    - botDrawable.getIntrinsicWidth();
            nameLeft = AndroidUtilities.dp(11);
          }
          nameLockTop = AndroidUtilities.dp(16.5f);
        } else {
          nameLockTop = AndroidUtilities.dp(17);
        }
        drawCheck = user.verified;
      }
    }

    if (currentName != null) {
      nameString = currentName;
    } else {
      String nameString2 = "";
      if (chat != null) {
        nameString2 = chat.title;
      } else if (user != null) {
        nameString2 = UserObject.getUserName(user);
      }
      nameString = nameString2.replace('\n', ' ');
    }
    if (nameString.length() == 0) {
      if (user != null && user.phone != null && user.phone.length() != 0) {
        nameString = PhoneFormat.getInstance().format("+" + user.phone);
      } else {
        nameString = LocaleController.getString("HiddenName", R.string.HiddenName);
      }
    }
    if (encryptedChat != null) {
      currentNamePaint = nameEncryptedPaint;
    } else {
      currentNamePaint = namePaint;
    }

    int onlineWidth;
    int nameWidth;
    if (!LocaleController.isRTL) {
      onlineWidth = nameWidth = getMeasuredWidth() - nameLeft - AndroidUtilities.dp(14);
    } else {
      onlineWidth =
          nameWidth =
              getMeasuredWidth() - nameLeft - AndroidUtilities.dp(AndroidUtilities.leftBaseline);
    }
    if (drawNameLock) {
      nameWidth -= AndroidUtilities.dp(6) + lockDrawable.getIntrinsicWidth();
    } else if (drawNameBroadcast) {
      nameWidth -= AndroidUtilities.dp(6) + broadcastDrawable.getIntrinsicWidth();
    } else if (drawNameGroup) {
      nameWidth -= AndroidUtilities.dp(6) + groupDrawable.getIntrinsicWidth();
    } else if (drawNameBot) {
      nameWidth -= AndroidUtilities.dp(6) + botDrawable.getIntrinsicWidth();
    }

    if (drawCount) {
      TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs_dict.get(dialog_id);
      if (dialog != null && dialog.unread_count != 0) {
        lastUnreadCount = dialog.unread_count;
        String countString = String.format("%d", dialog.unread_count);
        countWidth =
            Math.max(AndroidUtilities.dp(12), (int) Math.ceil(countPaint.measureText(countString)));
        countLayout =
            new StaticLayout(
                countString,
                countPaint,
                countWidth,
                Layout.Alignment.ALIGN_CENTER,
                1.0f,
                0.0f,
                false);
        int w = countWidth + AndroidUtilities.dp(18);
        nameWidth -= w;
        if (!LocaleController.isRTL) {
          countLeft = getMeasuredWidth() - countWidth - AndroidUtilities.dp(19);
        } else {
          countLeft = AndroidUtilities.dp(19);
          nameLeft += w;
        }
      } else {
        lastUnreadCount = 0;
        countLayout = null;
      }
    } else {
      lastUnreadCount = 0;
      countLayout = null;
    }

    CharSequence nameStringFinal =
        TextUtils.ellipsize(
            nameString,
            currentNamePaint,
            nameWidth - AndroidUtilities.dp(12),
            TextUtils.TruncateAt.END);
    nameLayout =
        new StaticLayout(
            nameStringFinal,
            currentNamePaint,
            nameWidth,
            Layout.Alignment.ALIGN_NORMAL,
            1.0f,
            0.0f,
            false);

    if (chat == null || subLabel != null) {
      if (!LocaleController.isRTL) {
        onlineLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline);
      } else {
        onlineLeft = AndroidUtilities.dp(11);
      }

      CharSequence onlineString = "";
      TextPaint currentOnlinePaint = offlinePaint;

      if (subLabel != null) {
        onlineString = subLabel;
      } else if (user != null) {
        if (user.bot) {
          onlineString = LocaleController.getString("Bot", R.string.Bot);
        } else {
          onlineString = LocaleController.formatUserStatus(user);
          if (user != null
              && (user.id == UserConfig.getClientUserId()
                  || user.status != null
                      && user.status.expires > ConnectionsManager.getInstance().getCurrentTime())) {
            currentOnlinePaint = onlinePaint;
            onlineString = LocaleController.getString("Online", R.string.Online);
          }
        }
      }

      CharSequence onlineStringFinal =
          TextUtils.ellipsize(
              onlineString,
              currentOnlinePaint,
              onlineWidth - AndroidUtilities.dp(12),
              TextUtils.TruncateAt.END);
      onlineLayout =
          new StaticLayout(
              onlineStringFinal,
              currentOnlinePaint,
              onlineWidth,
              Layout.Alignment.ALIGN_NORMAL,
              1.0f,
              0.0f,
              false);
      nameTop = AndroidUtilities.dp(13);
      if (subLabel != null && chat != null) {
        nameLockTop -= AndroidUtilities.dp(12);
      }
    } else {
      onlineLayout = null;
      nameTop = AndroidUtilities.dp(25);
    }

    int avatarLeft;
    if (!LocaleController.isRTL) {
      avatarLeft = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 13 : 9);
    } else {
      avatarLeft = getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.isTablet() ? 65 : 61);
    }

    avatarImage.setImageCoords(
        avatarLeft, AndroidUtilities.dp(10), AndroidUtilities.dp(52), AndroidUtilities.dp(52));

    double widthpx;
    float left;
    if (LocaleController.isRTL) {
      if (nameLayout.getLineCount() > 0) {
        left = nameLayout.getLineLeft(0);
        if (left == 0) {
          widthpx = Math.ceil(nameLayout.getLineWidth(0));
          if (widthpx < nameWidth) {
            nameLeft += (nameWidth - widthpx);
          }
        }
      }
      if (onlineLayout != null && onlineLayout.getLineCount() > 0) {
        left = onlineLayout.getLineLeft(0);
        if (left == 0) {
          widthpx = Math.ceil(onlineLayout.getLineWidth(0));
          if (widthpx < onlineWidth) {
            onlineLeft += (onlineWidth - widthpx);
          }
        }
      }
    } else {
      if (nameLayout.getLineCount() > 0) {
        left = nameLayout.getLineRight(0);
        if (left == nameWidth) {
          widthpx = Math.ceil(nameLayout.getLineWidth(0));
          if (widthpx < nameWidth) {
            nameLeft -= (nameWidth - widthpx);
          }
        }
      }
      if (onlineLayout != null && onlineLayout.getLineCount() > 0) {
        left = onlineLayout.getLineRight(0);
        if (left == onlineWidth) {
          widthpx = Math.ceil(onlineLayout.getLineWidth(0));
          if (widthpx < onlineWidth) {
            onlineLeft -= (onlineWidth - widthpx);
          }
        }
      }
    }
  }
  @SuppressWarnings("unchecked")
  @Override
  public View createView(Context context) {
    actionBar.setBackgroundColor(0xff333333);
    actionBar.setItemsBackground(R.drawable.bar_selector_picker);
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setActionBarMenuOnItemClick(
        new ActionBar.ActionBarMenuOnItemClick() {
          @Override
          public void onItemClick(int id) {
            if (id == -1) {
              if (Build.VERSION.SDK_INT < 11) {
                listView.setAdapter(null);
                listView = null;
                listAdapter = null;
              }
              finishFragment();
            } else if (id == 1) {
              if (delegate != null) {
                finishFragment(false);
                delegate.startPhotoSelectActivity();
              }
            } else if (id == item_photos) {
              if (selectedMode == 0) {
                return;
              }
              selectedMode = 0;
              dropDown.setText(LocaleController.getString("PickerPhotos", R.string.PickerPhotos));
              emptyView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos));
              listAdapter.notifyDataSetChanged();
            } else if (id == item_video) {
              if (selectedMode == 1) {
                return;
              }
              selectedMode = 1;
              dropDown.setText(LocaleController.getString("PickerVideo", R.string.PickerVideo));
              emptyView.setText(LocaleController.getString("NoVideo", R.string.NoVideo));
              listAdapter.notifyDataSetChanged();
            }
          }
        });

    ActionBarMenu menu = actionBar.createMenu();
    menu.addItem(1, R.drawable.ic_ab_other);

    fragmentView = new FrameLayout(context);

    FrameLayout frameLayout = (FrameLayout) fragmentView;
    frameLayout.setBackgroundColor(0xff000000);

    if (!singlePhoto) {
      selectedMode = 0;

      dropDownContainer = new ActionBarMenuItem(context, menu, R.drawable.bar_selector_picker);
      dropDownContainer.setSubMenuOpenSide(1);
      dropDownContainer.addSubItem(
          item_photos, LocaleController.getString("PickerPhotos", R.string.PickerPhotos), 0);
      dropDownContainer.addSubItem(
          item_video, LocaleController.getString("PickerVideo", R.string.PickerVideo), 0);
      actionBar.addView(dropDownContainer);
      FrameLayout.LayoutParams layoutParams =
          (FrameLayout.LayoutParams) dropDownContainer.getLayoutParams();
      layoutParams.height = LayoutHelper.MATCH_PARENT;
      layoutParams.width = LayoutHelper.WRAP_CONTENT;
      layoutParams.rightMargin = AndroidUtilities.dp(40);
      layoutParams.leftMargin =
          AndroidUtilities.isTablet() ? AndroidUtilities.dp(64) : AndroidUtilities.dp(56);
      layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
      dropDownContainer.setLayoutParams(layoutParams);
      dropDownContainer.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              dropDownContainer.toggleSubMenu();
            }
          });

      dropDown = new TextView(context);
      dropDown.setGravity(Gravity.LEFT);
      dropDown.setSingleLine(true);
      dropDown.setLines(1);
      dropDown.setMaxLines(1);
      dropDown.setEllipsize(TextUtils.TruncateAt.END);
      dropDown.setTextColor(0xffffffff);
      dropDown.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
      dropDown.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_arrow_drop_down, 0);
      dropDown.setCompoundDrawablePadding(AndroidUtilities.dp(4));
      dropDown.setPadding(0, 0, AndroidUtilities.dp(10), 0);
      dropDown.setText(LocaleController.getString("PickerPhotos", R.string.PickerPhotos));
      dropDownContainer.addView(dropDown);
      layoutParams = (FrameLayout.LayoutParams) dropDown.getLayoutParams();
      layoutParams.width = LayoutHelper.WRAP_CONTENT;
      layoutParams.height = LayoutHelper.WRAP_CONTENT;
      layoutParams.leftMargin = AndroidUtilities.dp(16);
      layoutParams.gravity = Gravity.CENTER_VERTICAL;
      dropDown.setLayoutParams(layoutParams);
    } else {
      actionBar.setTitle(LocaleController.getString("Gallery", R.string.Gallery));
    }

    listView = new ListView(context);
    listView.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), AndroidUtilities.dp(4));
    listView.setClipToPadding(false);
    listView.setHorizontalScrollBarEnabled(false);
    listView.setVerticalScrollBarEnabled(false);
    listView.setSelector(new ColorDrawable(0));
    listView.setDividerHeight(0);
    listView.setDivider(null);
    listView.setDrawingCacheEnabled(false);
    listView.setScrollingCacheEnabled(false);
    frameLayout.addView(listView);
    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    layoutParams.bottomMargin = AndroidUtilities.dp(48);
    listView.setLayoutParams(layoutParams);
    listView.setAdapter(listAdapter = new ListAdapter(context));
    AndroidUtilities.setListViewEdgeEffectColor(listView, 0xff333333);

    emptyView = new TextView(context);
    emptyView.setTextColor(0xff808080);
    emptyView.setTextSize(20);
    emptyView.setGravity(Gravity.CENTER);
    emptyView.setVisibility(View.GONE);
    emptyView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos));
    frameLayout.addView(emptyView);
    layoutParams = (FrameLayout.LayoutParams) emptyView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    layoutParams.bottomMargin = AndroidUtilities.dp(48);
    emptyView.setLayoutParams(layoutParams);
    emptyView.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            return true;
          }
        });

    progressView = new FrameLayout(context);
    progressView.setVisibility(View.GONE);
    frameLayout.addView(progressView);
    layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    layoutParams.bottomMargin = AndroidUtilities.dp(48);
    progressView.setLayoutParams(layoutParams);

    ProgressBar progressBar = new ProgressBar(context);
    progressView.addView(progressBar);
    layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
    layoutParams.width = LayoutHelper.WRAP_CONTENT;
    layoutParams.height = LayoutHelper.WRAP_CONTENT;
    layoutParams.gravity = Gravity.CENTER;
    progressView.setLayoutParams(layoutParams);

    pickerBottomLayout = new PickerBottomLayout(context);
    frameLayout.addView(pickerBottomLayout);
    layoutParams = (FrameLayout.LayoutParams) pickerBottomLayout.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = AndroidUtilities.dp(48);
    layoutParams.gravity = Gravity.BOTTOM;
    pickerBottomLayout.setLayoutParams(layoutParams);
    pickerBottomLayout.cancelButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            finishFragment();
          }
        });
    pickerBottomLayout.doneButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            sendSelectedPhotos();
            finishFragment();
          }
        });

    if (loading && (albumsSorted == null || albumsSorted != null && albumsSorted.isEmpty())) {
      progressView.setVisibility(View.VISIBLE);
      listView.setEmptyView(null);
    } else {
      progressView.setVisibility(View.GONE);
      listView.setEmptyView(emptyView);
    }
    pickerBottomLayout.updateSelectedCount(selectedPhotos.size() + selectedWebPhotos.size(), true);

    return fragmentView;
  }
  public ChatAttachView(Context context) {
    super(context);

    NotificationCenter.getInstance().addObserver(this, NotificationCenter.albumsDidLoaded);
    if (MediaController.allPhotosAlbumEntry == null) {
      if (Build.VERSION.SDK_INT >= 21) {
        MediaController.loadGalleryPhotosAlbums(0);
      }
      loading = true;
    }

    views[8] = attachPhotoRecyclerView = new RecyclerListView(context);
    attachPhotoRecyclerView.setVerticalScrollBarEnabled(true);
    attachPhotoRecyclerView.setAdapter(photoAttachAdapter = new PhotoAttachAdapter(context));
    attachPhotoRecyclerView.setClipToPadding(false);
    attachPhotoRecyclerView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8), 0);
    attachPhotoRecyclerView.setItemAnimator(null);
    attachPhotoRecyclerView.setLayoutAnimation(null);
    if (Build.VERSION.SDK_INT >= 9) {
      attachPhotoRecyclerView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER);
    }
    addView(attachPhotoRecyclerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 80));
    attachPhotoLayoutManager =
        new LinearLayoutManager(context) {
          @Override
          public boolean supportsPredictiveItemAnimations() {
            return false;
          }
        };
    attachPhotoLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    attachPhotoRecyclerView.setLayoutManager(attachPhotoLayoutManager);
    photoAttachAdapter.setDelegate(
        new PhotoAttachAdapter.PhotoAttachAdapterDelegate() {
          @Override
          public void selectedPhotosChanged() {
            updatePhotosButton();
          }
        });
    attachPhotoRecyclerView.setOnItemClickListener(
        new RecyclerListView.OnItemClickListener() {
          @SuppressWarnings("unchecked")
          @Override
          public void onItemClick(View view, int position) {
            if (baseFragment == null || baseFragment.getParentActivity() == null) {
              return;
            }
            ArrayList<Object> arrayList = (ArrayList) MediaController.allPhotosAlbumEntry.photos;
            if (position < 0 || position >= arrayList.size()) {
              return;
            }
            PhotoViewer.getInstance().setParentActivity(baseFragment.getParentActivity());
            PhotoViewer.getInstance()
                .openPhotoForSelect(arrayList, position, 0, ChatAttachView.this, baseFragment);
            AndroidUtilities.hideKeyboard(baseFragment.getFragmentView().findFocus());
          }
        });

    views[9] = progressView = new EmptyTextProgressView(context);
    if (Build.VERSION.SDK_INT >= 23
        && getContext().checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
            != PackageManager.PERMISSION_GRANTED) {
      progressView.setText(
          LocaleController.getString("PermissionStorage", R.string.PermissionStorage));
      progressView.setTextSize(16);
    } else {
      progressView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos));
      progressView.setTextSize(20);
    }
    addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 80));
    attachPhotoRecyclerView.setEmptyView(progressView);

    views[10] = lineView = new View(getContext());
    lineView.setBackgroundColor(0xffd2d2d2);
    addView(
        lineView,
        new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, 1, Gravity.TOP | Gravity.LEFT));
    CharSequence[] items =
        new CharSequence[] {
          LocaleController.getString("ChatCamera", R.string.ChatCamera),
          LocaleController.getString("ChatGallery", R.string.ChatGallery),
          LocaleController.getString("ChatVideo", R.string.ChatVideo),
          LocaleController.getString("AttachAudio", R.string.AttachAudio),
          LocaleController.getString("ChatDocument", R.string.ChatDocument),
          LocaleController.getString("AttachContact", R.string.AttachContact),
          LocaleController.getString("ChatLocation", R.string.ChatLocation),
          ""
        };
    int itemIcons[] =
        new int[] {
          R.drawable.attach_camera_states,
          R.drawable.attach_gallery_states,
          R.drawable.attach_video_states,
          R.drawable.attach_audio_states,
          R.drawable.attach_file_states,
          R.drawable.attach_contact_states,
          R.drawable.attach_location_states,
          R.drawable.attach_hide_states,
        };
    for (int a = 0; a < 8; a++) {
      AttachButton attachButton = new AttachButton(context);
      attachButton.setTextAndIcon(items[a], itemIcons[a]);
      addView(attachButton, LayoutHelper.createFrame(85, 90, Gravity.LEFT | Gravity.TOP));
      attachButton.setTag(a);
      views[a] = attachButton;
      if (a == 7) {
        sendPhotosButton = attachButton;
        sendPhotosButton.imageView.setPadding(0, AndroidUtilities.dp(4), 0, 0);
      }
      attachButton.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              if (delegate != null) {
                delegate.didPressedButton((Integer) v.getTag());
              }
            }
          });
    }
    setOnTouchListener(
        new OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            return true;
          }
        });

    if (loading) {
      progressView.showProgress();
    } else {
      progressView.showTextView();
    }
  }
Example #16
0
  @Override
  public void setMessageObject(MessageObject messageObject) {
    if (currentMessageObject != messageObject || isUserDataChanged()) {

      int uid = messageObject.messageOwner.media.user_id;
      contactUser = MessagesController.getInstance().getUser(uid);

      drawAddButton =
          contactUser != null
              && uid != UserConfig.getClientUserId()
              && ContactsController.getInstance().contactsDict.get(uid) == null;

      int maxWidth;
      if (AndroidUtilities.isTablet()) {
        maxWidth = (int) (AndroidUtilities.getMinTabletSide() * 0.7f);
      } else {
        maxWidth =
            (int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) * 0.7f);
      }
      maxWidth -= AndroidUtilities.dp(58 + (drawAddButton ? 42 : 0));

      if (contactUser != null) {
        if (contactUser.photo != null) {
          currentPhoto = contactUser.photo.photo_small;
        } else {
          currentPhoto = null;
        }
        avatarDrawable.setInfo(contactUser);
      } else {
        currentPhoto = null;
        avatarDrawable.setInfo(uid, null, null, false);
      }
      avatarImage.setImage(currentPhoto, "50_50", avatarDrawable, null, false);

      String currentNameString =
          ContactsController.formatName(
              messageObject.messageOwner.media.first_name,
              messageObject.messageOwner.media.last_name);
      int nameWidth = Math.min((int) Math.ceil(namePaint.measureText(currentNameString)), maxWidth);

      CharSequence stringFinal =
          TextUtils.ellipsize(
              currentNameString.replace("\n", " "), namePaint, nameWidth, TextUtils.TruncateAt.END);
      nameLayout =
          new StaticLayout(
              stringFinal, namePaint, nameWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
      if (nameLayout.getLineCount() > 0) {
        nameWidth = (int) Math.ceil(nameLayout.getLineWidth(0));
      } else {
        nameWidth = 0;
      }

      String phone = messageObject.messageOwner.media.phone_number;
      if (phone != null && phone.length() != 0) {
        if (!phone.startsWith("+")) {
          phone = "+" + phone;
        }
        phone = PhoneFormat.getInstance().format(phone);
      } else {
        phone = LocaleController.getString("NumberUnknown", R.string.NumberUnknown);
      }
      int phoneWidth = Math.min((int) Math.ceil(phonePaint.measureText(phone)), maxWidth);
      stringFinal =
          TextUtils.ellipsize(
              phone.replace("\n", " "), phonePaint, phoneWidth, TextUtils.TruncateAt.END);
      phoneLayout =
          new StaticLayout(
              stringFinal,
              phonePaint,
              phoneWidth,
              Layout.Alignment.ALIGN_NORMAL,
              1.0f,
              0.0f,
              false);
      if (phoneLayout.getLineCount() > 0) {
        phoneWidth = (int) Math.ceil(phoneLayout.getLineWidth(0));
      } else {
        phoneWidth = 0;
      }

      namesWidth = Math.max(nameWidth, phoneWidth);
      backgroundWidth = AndroidUtilities.dp(77 + (drawAddButton ? 42 : 0)) + namesWidth;

      super.setMessageObject(messageObject);
    }
  }
  @Override
  public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("EncryptionKey", R.string.EncryptionKey));

    actionBar.setActionBarMenuOnItemClick(
        new ActionBar.ActionBarMenuOnItemClick() {
          @Override
          public void onItemClick(int id) {
            if (id == -1) {
              finishFragment();
            }
          }
        });

    fragmentView = new LinearLayout(context);
    LinearLayout linearLayout = (LinearLayout) fragmentView;
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setWeightSum(100);
    linearLayout.setBackgroundColor(0xfff0f0f0);
    fragmentView.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            return true;
          }
        });

    FrameLayout frameLayout = new FrameLayout(context);
    frameLayout.setPadding(
        AndroidUtilities.dp(20),
        AndroidUtilities.dp(20),
        AndroidUtilities.dp(20),
        AndroidUtilities.dp(20));
    linearLayout.addView(
        frameLayout,
        LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 50.0f));

    ImageView identiconView = new ImageView(context);
    identiconView.setScaleType(ImageView.ScaleType.FIT_XY);
    frameLayout.addView(
        identiconView,
        LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

    frameLayout = new FrameLayout(context);
    frameLayout.setBackgroundColor(0xffffffff);
    frameLayout.setPadding(
        AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10), AndroidUtilities.dp(10));
    linearLayout.addView(
        frameLayout,
        LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 50.0f));

    TextView textView = new TextView(context);
    textView.setTextColor(0xff7f7f7f);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    textView.setLinksClickable(true);
    textView.setClickable(true);
    textView.setMovementMethod(new LinkMovementMethodMy());
    // textView.setAutoLinkMask(Linkify.WEB_URLS);
    textView.setLinkTextColor(0xff316f9f);
    textView.setGravity(Gravity.CENTER);
    frameLayout.addView(
        textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

    TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance().getEncryptedChat(chat_id);
    if (encryptedChat != null) {
      IdenticonDrawable drawable = new IdenticonDrawable();
      identiconView.setImageDrawable(drawable);
      drawable.setEncryptedChat(encryptedChat);
      TLRPC.User user = MessagesController.getInstance().getUser(encryptedChat.user_id);
      SpannableStringBuilder hash = new SpannableStringBuilder();
      if (encryptedChat.key_hash.length > 16) {
        String hex = Utilities.bytesToHex(encryptedChat.key_hash);
        for (int a = 0; a < 32; a++) {
          if (a != 0) {
            if (a % 8 == 0) {
              hash.append('\n');
            } else if (a % 4 == 0) {
              hash.append(' ');
            }
          }
          hash.append(hex.substring(a * 2, a * 2 + 2));
          hash.append(' ');
        }
        hash.append("\n\n");
      }
      hash.append(
          AndroidUtilities.replaceTags(
              LocaleController.formatString(
                  "EncryptionKeyDescription",
                  R.string.EncryptionKeyDescription,
                  user.first_name,
                  user.first_name)));
      final String url = "telegram.org";
      int index = hash.toString().indexOf(url);
      if (index != -1) {
        hash.setSpan(
            new URLSpanReplacement(
                LocaleController.getString("EncryptionKeyLink", R.string.EncryptionKeyLink)),
            index,
            index + url.length(),
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      }
      textView.setText(hash);
    }

    return fragmentView;
  }
  @Override
  public View createView(Context context) {
    actionBar.setBackgroundColor(Theme.ACTION_BAR_CHANNEL_INTRO_COLOR);
    actionBar.setBackButtonImage(R.drawable.pl_back);
    actionBar.setItemsBackgroundColor(Theme.ACTION_BAR_CHANNEL_INTRO_SELECTOR_COLOR);
    actionBar.setCastShadows(false);
    if (!AndroidUtilities.isTablet()) {
      actionBar.showActionModeTop();
    }
    actionBar.setActionBarMenuOnItemClick(
        new ActionBar.ActionBarMenuOnItemClick() {
          @Override
          public void onItemClick(int id) {
            if (id == -1) {
              finishFragment();
            }
          }
        });

    fragmentView =
        new ViewGroup(context) {

          @Override
          protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int width = MeasureSpec.getSize(widthMeasureSpec);
            int height = MeasureSpec.getSize(heightMeasureSpec);

            if (width > height) {
              imageView.measure(
                  MeasureSpec.makeMeasureSpec((int) (width * 0.45f), MeasureSpec.EXACTLY),
                  MeasureSpec.makeMeasureSpec((int) (height * 0.78f), MeasureSpec.EXACTLY));
              whatIsChannelText.measure(
                  MeasureSpec.makeMeasureSpec((int) (width * 0.6f), MeasureSpec.EXACTLY),
                  MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
              descriptionText.measure(
                  MeasureSpec.makeMeasureSpec((int) (width * 0.5f), MeasureSpec.EXACTLY),
                  MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
              createChannelText.measure(
                  MeasureSpec.makeMeasureSpec((int) (width * 0.6f), MeasureSpec.EXACTLY),
                  MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(24), MeasureSpec.EXACTLY));
            } else {
              imageView.measure(
                  MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
                  MeasureSpec.makeMeasureSpec((int) (height * 0.44f), MeasureSpec.EXACTLY));
              whatIsChannelText.measure(
                  MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
                  MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
              descriptionText.measure(
                  MeasureSpec.makeMeasureSpec((int) (width * 0.9f), MeasureSpec.EXACTLY),
                  MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
              createChannelText.measure(
                  MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
                  MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(24), MeasureSpec.EXACTLY));
            }

            setMeasuredDimension(width, height);
          }

          @Override
          protected void onLayout(boolean changed, int l, int t, int r, int b) {
            int width = r - l;
            int height = b - t;

            if (r > b) {
              int y = (int) (height * 0.05f);
              imageView.layout(
                  0, y, imageView.getMeasuredWidth(), y + imageView.getMeasuredHeight());
              int x = (int) (width * 0.4f);
              y = (int) (height * 0.14f);
              whatIsChannelText.layout(
                  x,
                  y,
                  x + whatIsChannelText.getMeasuredWidth(),
                  y + whatIsChannelText.getMeasuredHeight());
              y = (int) (height * 0.61f);
              createChannelText.layout(
                  x,
                  y,
                  x + createChannelText.getMeasuredWidth(),
                  y + createChannelText.getMeasuredHeight());
              x = (int) (width * 0.45f);
              y = (int) (height * 0.31f);
              descriptionText.layout(
                  x,
                  y,
                  x + descriptionText.getMeasuredWidth(),
                  y + descriptionText.getMeasuredHeight());
            } else {
              int y = (int) (height * 0.05f);
              imageView.layout(
                  0, y, imageView.getMeasuredWidth(), y + imageView.getMeasuredHeight());
              y = (int) (height * 0.59f);
              whatIsChannelText.layout(
                  0,
                  y,
                  whatIsChannelText.getMeasuredWidth(),
                  y + whatIsChannelText.getMeasuredHeight());
              y = (int) (height * 0.68f);
              int x = (int) (width * 0.05f);
              descriptionText.layout(
                  x,
                  y,
                  x + descriptionText.getMeasuredWidth(),
                  y + descriptionText.getMeasuredHeight());
              y = (int) (height * 0.86f);
              createChannelText.layout(
                  0,
                  y,
                  createChannelText.getMeasuredWidth(),
                  y + createChannelText.getMeasuredHeight());
            }
          }
        };
    fragmentView.setBackgroundColor(0xffffffff);
    ViewGroup viewGroup = (ViewGroup) fragmentView;
    viewGroup.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            return true;
          }
        });

    imageView = new ImageView(context);
    imageView.setImageResource(R.drawable.channelintro);
    imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
    viewGroup.addView(imageView);

    whatIsChannelText = new TextView(context);
    whatIsChannelText.setTextColor(0xff212121);
    whatIsChannelText.setGravity(Gravity.CENTER_HORIZONTAL);
    whatIsChannelText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 24);
    whatIsChannelText.setText(
        LocaleController.getString("ChannelAlertTitle", R.string.ChannelAlertTitle));
    viewGroup.addView(whatIsChannelText);

    descriptionText = new TextView(context);
    descriptionText.setTextColor(0xff787878);
    descriptionText.setGravity(Gravity.CENTER_HORIZONTAL);
    descriptionText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    descriptionText.setText(
        LocaleController.getString("ChannelAlertText", R.string.ChannelAlertText));
    viewGroup.addView(descriptionText);

    createChannelText = new TextView(context);
    createChannelText.setTextColor(0xff4c8eca);
    createChannelText.setGravity(Gravity.CENTER);
    createChannelText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    createChannelText.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    createChannelText.setText(
        LocaleController.getString("ChannelAlertCreate", R.string.ChannelAlertCreate));
    viewGroup.addView(createChannelText);
    createChannelText.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Bundle args = new Bundle();
            args.putInt("step", 0);
            presentFragment(new ChannelCreateActivity(args), true);
          }
        });

    return fragmentView;
  }