public StickerAdapter(Context context, EmojiKeyboard keyboard, final ScrollTo scrollTo) { super(context); this.context = context; this.keyboard = keyboard; if (stickersCache == null) { stickersCache = new HashMap<Long, StickerView>(); } this.scrollTo = scrollTo; // Build sticker lines stickerIndicatorContainer = keyboard.getStickerIndicatorContainer(); stickerIndicatorContainer.setTag(TAG_KEY, 0); stickerInLine = (Screen.getWidth() / STICKER_SIZE); leftPadding = (Screen.getWidth() - (stickerInLine * STICKER_SIZE)) / 2; packFirstLineMap = new HashMap<Integer, Integer>(); stickerSwitchLp = new LinearLayout.LayoutParams(Screen.dp(48), Screen.dp(48)); padding = Screen.dp(8); packs = messenger().getOwnStickerPacks(); ((BaseActivity) context) .bind( packs, new ValueChangedListener<ArrayList<StickerPackVM>>() { @Override public void onChanged( ArrayList<StickerPackVM> val, Value<ArrayList<StickerPackVM>> valueModel) { buildStickerLines(scrollTo); notifyDataSetChanged(); } }); }
private void updateActionBar(int offset) { avatarView.setOffset(offset); ActionBar bar = ((BaseActivity) getActivity()).getSupportActionBar(); int fullColor = baseColor; ActorStyle style = ActorSDK.sharedActor().style; if (style.getToolBarColor() != 0) { fullColor = style.getToolBarColor(); } if (Math.abs(offset) > Screen.dp(248 - 56)) { bar.setBackgroundDrawable(new ColorDrawable(fullColor)); } else { float alpha = Math.abs(offset) / (float) Screen.dp(248 - 56); bar.setBackgroundDrawable( new ColorDrawable( Color.argb( (int) (255 * alpha), Color.red(fullColor), Color.green(fullColor), Color.blue(fullColor)))); } }
@Override public int getSize( Paint paint, CharSequence charSequence, int start, int end, Paint.FontMetricsInt fm) { if (fm != null) { // WTF??? fm.ascent = -Screen.dp(21 + 3); fm.descent = Screen.dp(10 + 3); fm.top = fm.ascent; fm.bottom = fm.descent; } return (int) textPaint.measureText(userText) + Screen.dp(24 + 8); }
public UserSpan(UserVM user, int maxW) { this.user = user; this.maxW = maxW; if (textPaint == null) { textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); textPaint.setTextSize(Screen.sp(16)); textPaint.setColor(AndroidContext.getContext().getResources().getColor(R.color.text_primary)); } int padding = Screen.dp(18); int maxWidth = maxW - padding; userText = TextUtils.ellipsize(user.getName().get(), textPaint, maxWidth, TextUtils.TruncateAt.END) .toString(); }
@Override protected void onCreateToolbar() { // Loading Toolbar header views // Binding to real data is performed in onResume method barView = LayoutInflater.from(this).inflate(R.layout.bar_conversation, null); ActionBar.LayoutParams layout = new ActionBar.LayoutParams( ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT); setToolbar(barView, layout); barTitle = (TextView) barView.findViewById(R.id.title); barSubtitleContainer = barView.findViewById(R.id.subtitleContainer); barTypingIcon = (ImageView) barView.findViewById(R.id.typingImage); barTypingIcon.setImageDrawable(new TypingDrawable()); barTyping = (TextView) barView.findViewById(R.id.typing); barSubtitle = (TextView) barView.findViewById(R.id.subtitle); barTypingContainer = barView.findViewById(R.id.typingContainer); barTypingContainer.setVisibility(View.INVISIBLE); barAvatar = (AvatarView) barView.findViewById(R.id.avatarPreview); barAvatar.init(Screen.dp(32), 18); barView .findViewById(R.id.titleContainer) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (peer.getPeerType() == PeerType.PRIVATE) { startActivity(Intents.openProfile(peer.getPeerId(), ChatActivity.this)); } else if (peer.getPeerType() == PeerType.GROUP) { startActivity(Intents.openGroup(peer.getPeerId(), ChatActivity.this)); } else { // Nothing to do } } }); }
@Override public void draw( Canvas canvas, CharSequence charSequence, int start, int end, float x, int top, int y, int bottom, Paint paint) { int size = (int) textPaint.measureText(userText); Paint debug = new Paint(); debug.setColor(0xffebebeb); debug.setStyle(Paint.Style.FILL_AND_STROKE); canvas.drawRoundRect( new RectF( x + Screen.dp(4), y - Screen.dp(20), x + size + Screen.dp(4 + 24), y + Screen.dp(8)), Screen.dp(14), Screen.dp(14), debug); canvas.drawText(userText, x + Screen.dp(4 + 12), y, textPaint); }
private void buildStickerLines(final ScrollTo scrollTo) { // BUILD SWITCH keyboard.getStickerIndicatorContainer().removeAllViews(); // Add pack switch buttons int packCount = 0; totalLines = 0; for (final StickerPackVM pack : packs.get()) { ((BaseActivity) context) .bind( pack.getStickers(), new ValueChangedListener<ArrayList<Sticker>>() { @Override public void onChanged( ArrayList<Sticker> val, Value<ArrayList<Sticker>> valueModel) { buildStickerLines(scrollTo); notifyDataSetChanged(); } }, false); if (pack.getStickers().get().size() < 1) { continue; } // Count lines int linesInPack = (int) Math.ceil((double) pack.getStickers().get().size() / stickerInLine); totalLines += linesInPack; // Build packs buttons final StickerView sv = new StickerView(context); sv.bind(pack.getStickers().get().get(0).getFileReference128(), Screen.dp(48)); sv.setPadding(padding, padding, padding, padding); sv.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { scrollTo.requestScroll(packFirstLineMap.get(pack.getId())); selectCurrentPack((Integer) sv.getTag(TAG_KEY)); } }); sv.setTag(TAG_KEY, packCount); keyboard.getStickerIndicatorContainer().addView(sv, stickerSwitchLp); packCount++; } if (stickerIndicatorContainer.getChildAt(0) != null) { stickerIndicatorContainer .getChildAt(0) .setBackgroundColor(context.getResources().getColor(R.color.selector_selected)); } // BUILD LINES // All lines stored here stickerLines = new StickerLine[totalLines]; // Fill lines with packs stickers int allLinesCount = 0; int linePackCount = 0; for (StickerPackVM pack : packs.get()) { if (pack.getStickers().get().size() < 1) { continue; } int stickerInPack = 0; int linesInPack = (int) Math.ceil((double) pack.getStickers().get().size() / stickerInLine); // Loop pack lines for (int lineInPackCount = 0; lineInPackCount < linesInPack; lineInPackCount++, allLinesCount++) { StickerLine line = new StickerLine(new Sticker[stickerInLine], linePackCount); // Remember pack first line position if (lineInPackCount == 0) { packFirstLineMap.put(pack.getId(), allLinesCount); } // Fill line with stickers for (int stickerInLine = 0; stickerInLine < this.stickerInLine; stickerInLine++, stickerInPack++) { if (stickerInPack < pack.getStickers().get().size()) { line.getLine()[stickerInLine] = pack.getStickers().get().get(stickerInPack); } else { break; } } stickerLines[allLinesCount] = line; } linePackCount++; } }
class StickerAdapter extends HolderAdapter<StickerLine> { private static final int TAG_KEY = R.id.sticker_pager; ValueModel<ArrayList<StickerPackVM>> packs; StickerLine[] stickerLines; EmojiKeyboard keyboard; private int stickerInLine; private final int STICKER_SIZE = Screen.dp(80); private final int STICKER_PADDING = Screen.dp(5); private int leftPadding; // TODO limit cache static HashMap<Long, StickerView> stickersCache; private int totalLines = 0; ScrollTo scrollTo; private LinearLayout stickerIndicatorContainer; private Object position; private Context context; private final int padding; private final HashMap<Integer, Integer> packFirstLineMap; private final LinearLayout.LayoutParams stickerSwitchLp; public StickerAdapter(Context context, EmojiKeyboard keyboard, final ScrollTo scrollTo) { super(context); this.context = context; this.keyboard = keyboard; if (stickersCache == null) { stickersCache = new HashMap<Long, StickerView>(); } this.scrollTo = scrollTo; // Build sticker lines stickerIndicatorContainer = keyboard.getStickerIndicatorContainer(); stickerIndicatorContainer.setTag(TAG_KEY, 0); stickerInLine = (Screen.getWidth() / STICKER_SIZE); leftPadding = (Screen.getWidth() - (stickerInLine * STICKER_SIZE)) / 2; packFirstLineMap = new HashMap<Integer, Integer>(); stickerSwitchLp = new LinearLayout.LayoutParams(Screen.dp(48), Screen.dp(48)); padding = Screen.dp(8); packs = messenger().getOwnStickerPacks(); ((BaseActivity) context) .bind( packs, new ValueChangedListener<ArrayList<StickerPackVM>>() { @Override public void onChanged( ArrayList<StickerPackVM> val, Value<ArrayList<StickerPackVM>> valueModel) { buildStickerLines(scrollTo); notifyDataSetChanged(); } }); } private void buildStickerLines(final ScrollTo scrollTo) { // BUILD SWITCH keyboard.getStickerIndicatorContainer().removeAllViews(); // Add pack switch buttons int packCount = 0; totalLines = 0; for (final StickerPackVM pack : packs.get()) { ((BaseActivity) context) .bind( pack.getStickers(), new ValueChangedListener<ArrayList<Sticker>>() { @Override public void onChanged( ArrayList<Sticker> val, Value<ArrayList<Sticker>> valueModel) { buildStickerLines(scrollTo); notifyDataSetChanged(); } }, false); if (pack.getStickers().get().size() < 1) { continue; } // Count lines int linesInPack = (int) Math.ceil((double) pack.getStickers().get().size() / stickerInLine); totalLines += linesInPack; // Build packs buttons final StickerView sv = new StickerView(context); sv.bind(pack.getStickers().get().get(0).getFileReference128(), Screen.dp(48)); sv.setPadding(padding, padding, padding, padding); sv.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { scrollTo.requestScroll(packFirstLineMap.get(pack.getId())); selectCurrentPack((Integer) sv.getTag(TAG_KEY)); } }); sv.setTag(TAG_KEY, packCount); keyboard.getStickerIndicatorContainer().addView(sv, stickerSwitchLp); packCount++; } if (stickerIndicatorContainer.getChildAt(0) != null) { stickerIndicatorContainer .getChildAt(0) .setBackgroundColor(context.getResources().getColor(R.color.selector_selected)); } // BUILD LINES // All lines stored here stickerLines = new StickerLine[totalLines]; // Fill lines with packs stickers int allLinesCount = 0; int linePackCount = 0; for (StickerPackVM pack : packs.get()) { if (pack.getStickers().get().size() < 1) { continue; } int stickerInPack = 0; int linesInPack = (int) Math.ceil((double) pack.getStickers().get().size() / stickerInLine); // Loop pack lines for (int lineInPackCount = 0; lineInPackCount < linesInPack; lineInPackCount++, allLinesCount++) { StickerLine line = new StickerLine(new Sticker[stickerInLine], linePackCount); // Remember pack first line position if (lineInPackCount == 0) { packFirstLineMap.put(pack.getId(), allLinesCount); } // Fill line with stickers for (int stickerInLine = 0; stickerInLine < this.stickerInLine; stickerInLine++, stickerInPack++) { if (stickerInPack < pack.getStickers().get().size()) { line.getLine()[stickerInLine] = pack.getStickers().get().get(stickerInPack); } else { break; } } stickerLines[allLinesCount] = line; } linePackCount++; } } @Override public int getCount() { return totalLines; } @Override public StickerLine getItem(int position) { return stickerLines[position]; } @Override public long getItemId(int position) { return 0; } @Override protected ViewHolder<StickerLine> createHolder(StickerLine obj) { return new StickerLineViewHolder(); } class StickerLineViewHolder extends ViewHolder<StickerLine> { LinearLayout ll; LinearLayout.LayoutParams stikerlp = new LinearLayout.LayoutParams(STICKER_SIZE, STICKER_SIZE); @Override public View init(StickerLine data, ViewGroup viewGroup, Context context) { ll = new LinearLayout(context); ll.setLayoutParams( new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, STICKER_SIZE)); ll.setPadding(leftPadding, 0, 0, 0); ll.setOrientation(LinearLayout.HORIZONTAL); return ll; } @Override public void bind(StickerLine data, int position, Context context) { ll.removeAllViews(); ll.setTag(TAG_KEY, data.getPackCount()); for (final Sticker s : data.getLine()) { StickerView sv; if (s != null && s.getFileReference256() != null) { sv = stickersCache.get(s.getFileReference128().getFileId()); if (sv == null) { sv = new StickerView(context); sv.setPadding(STICKER_PADDING, STICKER_PADDING, STICKER_PADDING, STICKER_PADDING); sv.bind(s.getFileReference128(), STICKER_SIZE); stickersCache.put(s.getFileReference128().getFileId(), sv); } else if (sv.isLoaded()) { if (sv.getParent() != null) { ((LinearLayout) sv.getParent()).removeView(sv); } sv.shortenFade(); } sv.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { keyboard.onStickerClicked(s); } }); ll.addView(sv, stikerlp); } } } @Override public void unbind() { super.unbind(); ll.removeAllViews(); } } public void onScroll(View view) { if (view != null) { if (stickerIndicatorContainer.getTag(TAG_KEY) != null && !stickerIndicatorContainer.getTag(TAG_KEY).equals(view.getTag(TAG_KEY))) { stickerIndicatorContainer.setTag(TAG_KEY, view.getTag(TAG_KEY)); position = view.getTag(TAG_KEY); selectCurrentPack((Integer) position); } } } private void selectCurrentPack(int position) { for (int i = 0; i < stickerIndicatorContainer.getChildCount(); i++) { if (stickerIndicatorContainer.getChildAt(i) != null) { stickerIndicatorContainer.getChildAt(i).setBackgroundColor(Color.TRANSPARENT); } } if (stickerIndicatorContainer.getChildAt(position) != null) { stickerIndicatorContainer .getChildAt(position) .setBackgroundColor( stickerIndicatorContainer .getContext() .getResources() .getColor(R.color.selector_selected)); } } public interface ScrollTo { void requestScroll(int position); } }
@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; }
private void addFields( FrameLayout container, ActorSettingsField[] fields, LayoutInflater inflater) { Context context = getActivity(); LinearLayout ll = new LinearLayout(getActivity()); ll.setOrientation(LinearLayout.VERTICAL); container.addView( ll, FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT); for (ActorSettingsField field : fields) { if (field.getView() != null) { View view = field.getView(); ll.addView( view, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); } else { LinearLayout fieldLayout = (LinearLayout) inflater.inflate(R.layout.actor_settings_field, null); TintImageView icon = (TintImageView) fieldLayout.findViewById(R.id.icon); icon.setTint(ActorSDK.sharedActor().style.getSettingsIconColor()); TextView name = (TextView) fieldLayout.findViewById(R.id.name); name.setTextColor(ActorSDK.sharedActor().style.getSettingsTitleColor()); View rightView = field.getRightView(); // Icon if (field.getIconResourceId() != 0) { icon.setResource(field.getIconResourceId()); if (field.getIconColor() != -1) { icon.setTint(field.getIconColor()); } } else { icon.setVisibility(View.INVISIBLE); } // Name if (field.getName() != null) { name.setText(field.getName()); } else { name.setVisibility(View.GONE); } // Right view if (rightView != null) { fieldLayout.addView( rightView, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); } // Click if (field.getOnclickListener() != null) { fieldLayout.setOnClickListener(field.getOnclickListener()); } // Field ll.addView( fieldLayout, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); } // Divider if (field.addBottomDivider()) { LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1); params.leftMargin = Screen.dp(72); params.rightMargin = Screen.dp(16); View divider = inflater.inflate(R.layout.actor_settings_divider, null); divider.setBackgroundColor(ActorSDK.sharedActor().style.getDividerColor()); ll.addView(divider, params); } } }