List of usage examples for android.animation StateListAnimator addState
public void addState(int[] specs, Animator animator)
From source file:org.pouyadr.ui.LocationActivity.java
@Override public View createView(Context context) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); if (AndroidUtilities.isTablet()) { actionBar.setOccupyStatusBar(false); }//from w ww. ja v a 2 s. c o m actionBar.setAddToContainer(messageObject != null); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(int id) { if (id == -1) { finishFragment(); } else if (id == map_list_menu_map) { if (googleMap != null) { googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); } } else if (id == map_list_menu_satellite) { if (googleMap != null) { googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE); } } else if (id == map_list_menu_hybrid) { if (googleMap != null) { googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID); } } else if (id == share) { try { double lat = messageObject.messageOwner.media.geo.lat; double lon = messageObject.messageOwner.media.geo._long; getParentActivity().startActivity(new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("geo:" + lat + "," + lon + "?q=" + lat + "," + lon))); } catch (Exception e) { FileLog.e("tmessages", e); } } } }); ActionBarMenu menu = actionBar.createMenu(); if (messageObject != null) { if (messageObject.messageOwner.media.title != null && messageObject.messageOwner.media.title.length() > 0) { actionBar.setTitle(messageObject.messageOwner.media.title); if (messageObject.messageOwner.media.address != null && messageObject.messageOwner.media.address.length() > 0) { actionBar.setSubtitle(messageObject.messageOwner.media.address); } } else { actionBar.setTitle(LocaleController.getString("ChatLocation", R.string.ChatLocation)); } menu.addItem(share, R.drawable.share); } else { actionBar.setTitle(LocaleController.getString("ShareLocation", R.string.ShareLocation)); ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true) .setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() { @Override public void onSearchExpand() { searching = true; listView.setVisibility(View.GONE); mapViewClip.setVisibility(View.GONE); searchListView.setVisibility(View.VISIBLE); searchListView.setEmptyView(emptyTextLayout); } @Override public void onSearchCollapse() { searching = false; searchWas = false; searchListView.setEmptyView(null); listView.setVisibility(View.VISIBLE); mapViewClip.setVisibility(View.VISIBLE); searchListView.setVisibility(View.GONE); emptyTextLayout.setVisibility(View.GONE); searchAdapter.searchDelayed(null, null); } @Override public void onTextChanged(EditText editText) { if (searchAdapter == null) { return; } String text = editText.getText().toString(); if (text.length() != 0) { searchWas = true; } searchAdapter.searchDelayed(text, userLocation); } }); item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search)); } ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_other); item.addSubItem(map_list_menu_map, LocaleController.getString("Map", R.string.Map), 0); item.addSubItem(map_list_menu_satellite, LocaleController.getString("Satellite", R.string.Satellite), 0); item.addSubItem(map_list_menu_hybrid, LocaleController.getString("Hybrid", R.string.Hybrid), 0); fragmentView = new FrameLayout(context) { private boolean first = true; @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); if (changed) { fixLayoutInternal(first); first = false; } } }; FrameLayout frameLayout = (FrameLayout) fragmentView; locationButton = new ImageView(context); locationButton.setBackgroundResource(R.drawable.floating_user_states); locationButton.setImageResource(R.drawable.myloc_on); locationButton.setScaleType(ImageView.ScaleType.CENTER); if (Build.VERSION.SDK_INT >= 21) { StateListAnimator animator = new StateListAnimator(); animator.addState(new int[] { android.R.attr.state_pressed }, ObjectAnimator .ofFloat(locationButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4)) .setDuration(200)); animator.addState(new int[] {}, ObjectAnimator .ofFloat(locationButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2)) .setDuration(200)); locationButton.setStateListAnimator(animator); locationButton.setOutlineProvider(new ViewOutlineProvider() { @Override public void getOutline(View view, Outline outline) { outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56)); } }); } if (messageObject != null) { mapView = new MapView(context); frameLayout.setBackgroundDrawable(new MapPlaceholderDrawable()); mapView.onCreate(null); try { MapsInitializer.initialize(context); // googleMap = mapView.getMap(); } catch (Exception e) { FileLog.e("tmessages", e); } FrameLayout bottomView = new FrameLayout(context); bottomView.setBackgroundResource(R.drawable.location_panel); frameLayout.addView(bottomView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 60, Gravity.LEFT | Gravity.BOTTOM)); bottomView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (userLocation != null) { LatLng latLng = new LatLng(userLocation.getLatitude(), userLocation.getLongitude()); if (googleMap != null) { CameraUpdate position = CameraUpdateFactory.newLatLngZoom(latLng, googleMap.getMaxZoomLevel() - 4); googleMap.animateCamera(position); } } } }); avatarImageView = new BackupImageView(context); avatarImageView.setRoundRadius(AndroidUtilities.dp(20)); bottomView.addView(avatarImageView, LayoutHelper.createFrame(40, 40, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), LocaleController.isRTL ? 0 : 12, 12, LocaleController.isRTL ? 12 : 0, 0)); nameTextView = new TextView(context); nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); nameTextView.setTextColor(0xff212121); nameTextView.setMaxLines(1); nameTextView.setTypeface(AndroidUtilities.getTypeface(org.pouyadr.finalsoft.Fonts.CurrentFont())); nameTextView.setEllipsize(TextUtils.TruncateAt.END); nameTextView.setSingleLine(true); nameTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT); bottomView.addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), LocaleController.isRTL ? 12 : 72, 10, LocaleController.isRTL ? 72 : 12, 0)); distanceTextView = new TextView(context); distanceTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); distanceTextView.setTextColor(0xff2f8cc9); distanceTextView.setMaxLines(1); distanceTextView.setEllipsize(TextUtils.TruncateAt.END); distanceTextView.setSingleLine(true); distanceTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT); bottomView.addView(distanceTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), LocaleController.isRTL ? 12 : 72, 33, LocaleController.isRTL ? 72 : 12, 0)); userLocation = new Location("network"); userLocation.setLatitude(messageObject.messageOwner.media.geo.lat); userLocation.setLongitude(messageObject.messageOwner.media.geo._long); if (googleMap != null) { LatLng latLng = new LatLng(userLocation.getLatitude(), userLocation.getLongitude()); try { googleMap.addMarker(new MarkerOptions().position(latLng) .icon(BitmapDescriptorFactory.fromResource(R.drawable.map_pin))); } catch (Exception e) { FileLog.e("tmessages", e); } CameraUpdate position = CameraUpdateFactory.newLatLngZoom(latLng, googleMap.getMaxZoomLevel() - 4); googleMap.moveCamera(position); } ImageView routeButton = new ImageView(context); routeButton.setBackgroundResource(R.drawable.floating_states); routeButton.setImageResource(R.drawable.navigate); routeButton.setScaleType(ImageView.ScaleType.CENTER); if (Build.VERSION.SDK_INT >= 21) { StateListAnimator animator = new StateListAnimator(); animator.addState(new int[] { android.R.attr.state_pressed }, ObjectAnimator .ofFloat(routeButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4)) .setDuration(200)); animator.addState(new int[] {}, ObjectAnimator .ofFloat(routeButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2)) .setDuration(200)); routeButton.setStateListAnimator(animator); routeButton.setOutlineProvider(new ViewOutlineProvider() { @Override public void getOutline(View view, Outline outline) { outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56)); } }); } frameLayout.addView(routeButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM, LocaleController.isRTL ? 14 : 0, 0, LocaleController.isRTL ? 0 : 14, 28)); routeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (Build.VERSION.SDK_INT >= 23) { Activity activity = getParentActivity(); if (activity != null) { if (activity.checkSelfPermission( Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { showPermissionAlert(true); return; } } } if (myLocation != null) { try { Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(String.format(Locale.US, "http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f", myLocation.getLatitude(), myLocation.getLongitude(), messageObject.messageOwner.media.geo.lat, messageObject.messageOwner.media.geo._long))); getParentActivity().startActivity(intent); } catch (Exception e) { FileLog.e("tmessages", e); } } } }); frameLayout.addView(locationButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM, LocaleController.isRTL ? 14 : 0, 0, LocaleController.isRTL ? 0 : 14, 100)); locationButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (Build.VERSION.SDK_INT >= 23) { Activity activity = getParentActivity(); if (activity != null) { if (activity.checkSelfPermission( Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { showPermissionAlert(true); return; } } } if (myLocation != null && googleMap != null) { googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom( new LatLng(myLocation.getLatitude(), myLocation.getLongitude()), googleMap.getMaxZoomLevel() - 4)); } } }); } else { searchWas = false; searching = false; mapViewClip = new FrameLayout(context); mapViewClip.setBackgroundDrawable(new MapPlaceholderDrawable()); if (adapter != null) { adapter.destroy(); } if (searchAdapter != null) { searchAdapter.destroy(); } listView = new ListView(context); listView.setAdapter(adapter = new LocationActivityAdapter(context)); listView.setVerticalScrollBarEnabled(false); listView.setDividerHeight(0); listView.setDivider(null); frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP)); listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (totalItemCount == 0) { return; } updateClipView(firstVisibleItem); } }); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (position == 1) { if (delegate != null && userLocation != null) { TLRPC.TL_messageMediaGeo location = new TLRPC.TL_messageMediaGeo(); location.geo = new TLRPC.TL_geoPoint(); location.geo.lat = userLocation.getLatitude(); location.geo._long = userLocation.getLongitude(); delegate.didSelectLocation(location); } finishFragment(); } else { TLRPC.TL_messageMediaVenue object = adapter.getItem(position); if (object != null && delegate != null) { delegate.didSelectLocation(object); } finishFragment(); } } }); adapter.setDelegate(new BaseLocationAdapter.BaseLocationAdapterDelegate() { @Override public void didLoadedSearchResult(ArrayList<TLRPC.TL_messageMediaVenue> places) { if (!wasResults && !places.isEmpty()) { wasResults = true; } } }); adapter.setOverScrollHeight(overScrollHeight); frameLayout.addView(mapViewClip, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP)); mapView = new MapView(context) { @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (Build.VERSION.SDK_INT >= 11) { if (ev.getAction() == MotionEvent.ACTION_DOWN) { if (animatorSet != null) { animatorSet.cancel(); } animatorSet = new AnimatorSet(); animatorSet.setDuration(200); animatorSet.playTogether( ObjectAnimator.ofFloat(markerImageView, "translationY", markerTop + -AndroidUtilities.dp(10)), ObjectAnimator.ofFloat(markerXImageView, "alpha", 1.0f)); animatorSet.start(); } else if (ev.getAction() == MotionEvent.ACTION_UP) { if (animatorSet != null) { animatorSet.cancel(); } animatorSet = new AnimatorSet(); animatorSet.setDuration(200); animatorSet.playTogether( ObjectAnimator.ofFloat(markerImageView, "translationY", markerTop), ObjectAnimator.ofFloat(markerXImageView, "alpha", 0.0f)); animatorSet.start(); } } if (ev.getAction() == MotionEvent.ACTION_MOVE) { if (!userLocationMoved) { if (Build.VERSION.SDK_INT >= 11) { AnimatorSet animatorSet = new AnimatorSet(); animatorSet.setDuration(200); animatorSet.play(ObjectAnimator.ofFloat(locationButton, "alpha", 1.0f)); animatorSet.start(); } else { locationButton.setVisibility(VISIBLE); } userLocationMoved = true; } if (googleMap != null && userLocation != null) { userLocation.setLatitude(googleMap.getCameraPosition().target.latitude); userLocation.setLongitude(googleMap.getCameraPosition().target.longitude); } adapter.setCustomLocation(userLocation); } return super.onInterceptTouchEvent(ev); } }; try { mapView.onCreate(null); } catch (Exception e) { FileLog.e("tmessages", e); } try { MapsInitializer.initialize(context); // googleMap = mapView.getMap(); } catch (Exception e) { FileLog.e("tmessages", e); } View shadow = new View(context); shadow.setBackgroundResource(R.drawable.header_shadow_reverse); mapViewClip.addView(shadow, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.LEFT | Gravity.BOTTOM)); markerImageView = new ImageView(context); markerImageView.setImageResource(R.drawable.map_pin); mapViewClip.addView(markerImageView, LayoutHelper.createFrame(24, 42, Gravity.TOP | Gravity.CENTER_HORIZONTAL)); if (Build.VERSION.SDK_INT >= 11) { markerXImageView = new ImageView(context); markerXImageView.setAlpha(0.0f); markerXImageView.setImageResource(R.drawable.place_x); mapViewClip.addView(markerXImageView, LayoutHelper.createFrame(14, 14, Gravity.TOP | Gravity.CENTER_HORIZONTAL)); } mapViewClip.addView(locationButton, LayoutHelper.createFrame(Build.VERSION.SDK_INT >= 21 ? 56 : 60, Build.VERSION.SDK_INT >= 21 ? 56 : 60, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM, LocaleController.isRTL ? 14 : 0, 0, LocaleController.isRTL ? 0 : 14, 14)); locationButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (Build.VERSION.SDK_INT >= 23) { Activity activity = getParentActivity(); if (activity != null) { if (activity.checkSelfPermission( Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { showPermissionAlert(false); return; } } } if (myLocation != null && googleMap != null) { if (Build.VERSION.SDK_INT >= 11) { AnimatorSet animatorSet = new AnimatorSet(); animatorSet.setDuration(200); animatorSet.play(ObjectAnimator.ofFloat(locationButton, "alpha", 0.0f)); animatorSet.start(); } else { locationButton.setVisibility(View.INVISIBLE); } adapter.setCustomLocation(null); userLocationMoved = false; googleMap.animateCamera(CameraUpdateFactory .newLatLng(new LatLng(myLocation.getLatitude(), myLocation.getLongitude()))); } } }); if (Build.VERSION.SDK_INT >= 11) { locationButton.setAlpha(0.0f); } else { locationButton.setVisibility(View.INVISIBLE); } emptyTextLayout = new LinearLayout(context); emptyTextLayout.setVisibility(View.GONE); emptyTextLayout.setOrientation(LinearLayout.VERTICAL); frameLayout.addView(emptyTextLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 100, 0, 0)); emptyTextLayout.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); TextView emptyTextView = new TextView(context); emptyTextView.setTextColor(0xff808080); emptyTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20); emptyTextView.setGravity(Gravity.CENTER); emptyTextView.setText(LocaleController.getString("NoResult", R.string.NoResult)); emptyTextLayout.addView(emptyTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 0.5f)); FrameLayout frameLayoutEmpty = new FrameLayout(context); emptyTextLayout.addView(frameLayoutEmpty, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 0.5f)); searchListView = new ListView(context); searchListView.setVisibility(View.GONE); searchListView.setDividerHeight(0); searchListView.setDivider(null); searchListView.setAdapter(searchAdapter = new LocationActivitySearchAdapter(context)); frameLayout.addView(searchListView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP)); searchListView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { if (scrollState == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) { AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus()); } } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { } }); searchListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { TLRPC.TL_messageMediaVenue object = searchAdapter.getItem(position); if (object != null && delegate != null) { delegate.didSelectLocation(object); } finishFragment(); } }); if (googleMap != null) { userLocation = new Location("network"); userLocation.setLatitude(20.659322); userLocation.setLongitude(-11.406250); } frameLayout.addView(actionBar); } if (googleMap != null) { try { googleMap.setMyLocationEnabled(true); } catch (Exception e) { FileLog.e("tmessages", e); } googleMap.getUiSettings().setMyLocationButtonEnabled(false); googleMap.getUiSettings().setZoomControlsEnabled(false); googleMap.getUiSettings().setCompassEnabled(false); googleMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() { @Override public void onMyLocationChange(Location location) { positionMarker(location); } }); positionMarker(myLocation = getLastLocation()); } return fragmentView; }
From source file:org.telegram.ui.SettingsActivity.java
@Override public View createView(Context context) { actionBar.setBackgroundColor(Theme.getColor(Theme.key_avatar_backgroundActionBarBlue)); actionBar.setItemsBackgroundColor(Theme.getColor(Theme.key_avatar_actionBarSelectorBlue), false); actionBar.setItemsColor(Theme.getColor(Theme.key_avatar_actionBarIconBlue), false); actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAddToContainer(false);//from ww w.j a va 2s . co m extraHeight = 88; if (AndroidUtilities.isTablet()) { actionBar.setOccupyStatusBar(false); } actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(int id) { if (id == -1) { finishFragment(); } else if (id == edit_name) { presentFragment(new ChangeNameActivity()); } else if (id == logout) { presentFragment(new LogoutActivity()); } } }); ActionBarMenu menu = actionBar.createMenu(); ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_other); item.addSubItem(edit_name, LocaleController.getString("EditName", R.string.EditName)); item.addSubItem(logout, LocaleController.getString("LogOut", R.string.LogOut)); int scrollTo; int scrollToPosition = 0; Object writeButtonTag = null; if (listView != null) { scrollTo = layoutManager.findFirstVisibleItemPosition(); View topView = layoutManager.findViewByPosition(scrollTo); if (topView != null) { scrollToPosition = topView.getTop(); } else { scrollTo = -1; } writeButtonTag = writeButton.getTag(); } else { scrollTo = -1; } listAdapter = new ListAdapter(context); fragmentView = new FrameLayout(context) { @Override protected boolean drawChild(@NonNull Canvas canvas, @NonNull View child, long drawingTime) { if (child == listView) { boolean result = super.drawChild(canvas, child, drawingTime); if (parentLayout != null) { int actionBarHeight = 0; int childCount = getChildCount(); for (int a = 0; a < childCount; a++) { View view = getChildAt(a); if (view == child) { continue; } if (view instanceof ActionBar && view.getVisibility() == VISIBLE) { if (((ActionBar) view).getCastShadows()) { actionBarHeight = view.getMeasuredHeight(); } break; } } parentLayout.drawHeaderShadow(canvas, actionBarHeight); } return result; } else { return super.drawChild(canvas, child, drawingTime); } } }; fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray)); FrameLayout frameLayout = (FrameLayout) fragmentView; listView = new RecyclerListView(context); listView.setVerticalScrollBarEnabled(false); listView.setLayoutManager( layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) { @Override public boolean supportsPredictiveItemAnimations() { return false; } }); listView.setGlowColor(Theme.getColor(Theme.key_avatar_backgroundActionBarBlue)); frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT)); listView.setAdapter(listAdapter); listView.setItemAnimator(null); listView.setLayoutAnimation(null); listView.setOnItemClickListener((view, position) -> { if (position == notificationRow) { presentFragment(new NotificationsSettingsActivity()); } else if (position == privacyRow) { presentFragment(new PrivacySettingsActivity()); } else if (position == dataRow) { presentFragment(new DataSettingsActivity()); } else if (position == chatRow) { presentFragment(new ThemeActivity(ThemeActivity.THEME_TYPE_BASIC)); } else if (position == helpRow) { BottomSheet.Builder builder = new BottomSheet.Builder(context); builder.setApplyTopPadding(false); LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.VERTICAL); HeaderCell headerCell = new HeaderCell(context, true, 23, 15, false); headerCell.setHeight(47); headerCell.setText(LocaleController.getString("SettingsHelp", R.string.SettingsHelp)); linearLayout.addView(headerCell); LinearLayout linearLayoutInviteContainer = new LinearLayout(context); linearLayoutInviteContainer.setOrientation(LinearLayout.VERTICAL); linearLayout.addView(linearLayoutInviteContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); int count = 6; for (int a = 0; a < count; a++) { if (a >= 3 && a <= 4 && !BuildVars.LOGS_ENABLED || a == 5 && !BuildVars.DEBUG_VERSION) { continue; } TextCell textCell = new TextCell(context); String text; switch (a) { case 0: text = LocaleController.getString("AskAQuestion", R.string.AskAQuestion); break; case 1: text = LocaleController.getString("TelegramFAQ", R.string.TelegramFAQ); break; case 2: text = LocaleController.getString("PrivacyPolicy", R.string.PrivacyPolicy); break; case 3: text = LocaleController.getString("DebugSendLogs", R.string.DebugSendLogs); break; case 4: text = LocaleController.getString("DebugClearLogs", R.string.DebugClearLogs); break; case 5: default: text = "Switch Backend"; break; } textCell.setText(text, BuildVars.LOGS_ENABLED || BuildVars.DEBUG_VERSION ? a != count - 1 : a != 2); textCell.setTag(a); textCell.setBackgroundDrawable(Theme.getSelectorDrawable(false)); linearLayoutInviteContainer.addView(textCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); textCell.setOnClickListener(v2 -> { Integer tag = (Integer) v2.getTag(); switch (tag) { case 0: { showDialog(AlertsCreator.createSupportAlert(SettingsActivity.this)); break; } case 1: Browser.openUrl(getParentActivity(), LocaleController.getString("TelegramFaqUrl", R.string.TelegramFaqUrl)); break; case 2: Browser.openUrl(getParentActivity(), LocaleController.getString("PrivacyPolicyUrl", R.string.PrivacyPolicyUrl)); break; case 3: sendLogs(); break; case 4: FileLog.cleanupLogs(); break; case 5: { if (getParentActivity() == null) { return; } AlertDialog.Builder builder1 = new AlertDialog.Builder(getParentActivity()); builder1.setMessage(LocaleController.getString("AreYouSure", R.string.AreYouSure)); builder1.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder1.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> { SharedConfig.pushAuthKey = null; SharedConfig.pushAuthKeyId = null; SharedConfig.saveConfig(); ConnectionsManager.getInstance(currentAccount).switchBackend(); }); builder1.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder1.create()); break; } } builder.getDismissRunnable().run(); }); } builder.setCustomView(linearLayout); showDialog(builder.create()); } else if (position == languageRow) { presentFragment(new LanguageSelectActivity()); } else if (position == usernameRow) { presentFragment(new ChangeUsernameActivity()); } else if (position == bioRow) { if (userInfo != null) { presentFragment(new ChangeBioActivity()); } } else if (position == numberRow) { presentFragment(new ChangePhoneHelpActivity()); } }); listView.setOnItemLongClickListener(new RecyclerListView.OnItemLongClickListener() { private int pressCount = 0; @Override public boolean onItemClick(View view, int position) { if (position == versionRow) { pressCount++; if (pressCount >= 2 || BuildVars.DEBUG_PRIVATE_VERSION) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("DebugMenu", R.string.DebugMenu)); CharSequence[] items; items = new CharSequence[] { LocaleController.getString("DebugMenuImportContacts", R.string.DebugMenuImportContacts), LocaleController.getString("DebugMenuReloadContacts", R.string.DebugMenuReloadContacts), LocaleController.getString("DebugMenuResetContacts", R.string.DebugMenuResetContacts), LocaleController.getString("DebugMenuResetDialogs", R.string.DebugMenuResetDialogs), BuildVars.LOGS_ENABLED ? LocaleController.getString("DebugMenuDisableLogs", R.string.DebugMenuDisableLogs) : LocaleController.getString("DebugMenuEnableLogs", R.string.DebugMenuEnableLogs), SharedConfig.inappCamera ? LocaleController.getString("DebugMenuDisableCamera", R.string.DebugMenuDisableCamera) : LocaleController.getString("DebugMenuEnableCamera", R.string.DebugMenuEnableCamera), LocaleController.getString("DebugMenuClearMediaCache", R.string.DebugMenuClearMediaCache), LocaleController.getString("DebugMenuCallSettings", R.string.DebugMenuCallSettings), null, BuildVars.DEBUG_PRIVATE_VERSION ? "Check for app updates" : null }; builder.setItems(items, (dialog, which) -> { if (which == 0) { UserConfig.getInstance(currentAccount).syncContacts = true; UserConfig.getInstance(currentAccount).saveConfig(false); ContactsController.getInstance(currentAccount).forceImportContacts(); } else if (which == 1) { ContactsController.getInstance(currentAccount).loadContacts(false, 0); } else if (which == 2) { ContactsController.getInstance(currentAccount).resetImportedContacts(); } else if (which == 3) { MessagesController.getInstance(currentAccount).forceResetDialogs(); } else if (which == 4) { BuildVars.LOGS_ENABLED = !BuildVars.LOGS_ENABLED; SharedPreferences sharedPreferences = ApplicationLoader.applicationContext .getSharedPreferences("systemConfig", Context.MODE_PRIVATE); sharedPreferences.edit().putBoolean("logsEnabled", BuildVars.LOGS_ENABLED).commit(); } else if (which == 5) { SharedConfig.toggleInappCamera(); } else if (which == 6) { MessagesStorage.getInstance(currentAccount).clearSentMedia(); SharedPreferences.Editor editor = MessagesController.getGlobalMainSettings().edit(); SharedConfig.setNoSoundHintShowed(false); } else if (which == 7) { VoIPHelper.showCallDebugSettings(getParentActivity()); } else if (which == 8) { SharedConfig.toggleRoundCamera16to9(); } else if (which == 9) { ((LaunchActivity) getParentActivity()).checkAppUpdate(true); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } else { try { Toast.makeText(getParentActivity(), "\\_()_/", Toast.LENGTH_SHORT).show(); } catch (Exception e) { FileLog.e(e); } } return true; } return false; } }); frameLayout.addView(actionBar); extraHeightView = new View(context); extraHeightView.setPivotY(0); extraHeightView.setBackgroundColor(Theme.getColor(Theme.key_avatar_backgroundActionBarBlue)); frameLayout.addView(extraHeightView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 88)); shadowView = new View(context); shadowView.setBackgroundResource(R.drawable.header_shadow); frameLayout.addView(shadowView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3)); avatarContainer = new FrameLayout(context); avatarContainer.setPivotX(LocaleController.isRTL ? AndroidUtilities.dp(42) : 0); avatarContainer.setPivotY(0); frameLayout.addView(avatarContainer, LayoutHelper.createFrame(42, 42, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), (LocaleController.isRTL ? 0 : 64), 0, (LocaleController.isRTL ? 64 : 0), 0)); avatarContainer.setOnClickListener(v -> { if (avatar != null) { return; } TLRPC.User user = MessagesController.getInstance(currentAccount) .getUser(UserConfig.getInstance(currentAccount).getClientUserId()); if (user != null && user.photo != null && user.photo.photo_big != null) { PhotoViewer.getInstance().setParentActivity(getParentActivity()); PhotoViewer.getInstance().openPhoto(user.photo.photo_big, provider); } }); avatarImage = new BackupImageView(context); avatarImage.setRoundRadius(AndroidUtilities.dp(21)); avatarContainer.addView(avatarImage, LayoutHelper.createFrame(42, 42)); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setColor(0x55000000); avatarProgressView = new RadialProgressView(context) { @Override protected void onDraw(Canvas canvas) { if (avatarImage != null && avatarImage.getImageReceiver().hasNotThumb()) { paint.setAlpha((int) (0x55 * avatarImage.getImageReceiver().getCurrentAlpha())); canvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, AndroidUtilities.dp(21), paint); } super.onDraw(canvas); } }; avatarProgressView.setSize(AndroidUtilities.dp(26)); avatarProgressView.setProgressColor(0xffffffff); avatarContainer.addView(avatarProgressView, LayoutHelper.createFrame(42, 42)); showAvatarProgress(false, false); nameTextView = new TextView(context) { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); setPivotX(LocaleController.isRTL ? getMeasuredWidth() : 0); } }; nameTextView.setTextColor(Theme.getColor(Theme.key_profile_title)); nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); nameTextView.setLines(1); nameTextView.setMaxLines(1); nameTextView.setSingleLine(true); nameTextView.setEllipsize(TextUtils.TruncateAt.END); nameTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT); nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); nameTextView.setPivotY(0); frameLayout.addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 48 : 118, 0, LocaleController.isRTL ? 118 : 48, 0)); onlineTextView = new TextView(context); onlineTextView.setTextColor(Theme.getColor(Theme.key_avatar_subtitleInProfileBlue)); onlineTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); onlineTextView.setLines(1); onlineTextView.setMaxLines(1); onlineTextView.setSingleLine(true); onlineTextView.setEllipsize(TextUtils.TruncateAt.END); onlineTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT); frameLayout.addView(onlineTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 48 : 118, 0, LocaleController.isRTL ? 118 : 48, 0)); writeButton = new ImageView(context); Drawable drawable = Theme.createSimpleSelectorCircleDrawable(AndroidUtilities.dp(56), Theme.getColor(Theme.key_profile_actionBackground), Theme.getColor(Theme.key_profile_actionPressedBackground)); if (Build.VERSION.SDK_INT < 21) { Drawable shadowDrawable = context.getResources().getDrawable(R.drawable.floating_shadow_profile) .mutate(); shadowDrawable.setColorFilter(new PorterDuffColorFilter(0xff000000, PorterDuff.Mode.MULTIPLY)); CombinedDrawable combinedDrawable = new CombinedDrawable(shadowDrawable, drawable, 0, 0); combinedDrawable.setIconSize(AndroidUtilities.dp(56), AndroidUtilities.dp(56)); drawable = combinedDrawable; } writeButton.setBackgroundDrawable(drawable); writeButton.setImageResource(R.drawable.menu_camera_av); writeButton.setColorFilter( new PorterDuffColorFilter(Theme.getColor(Theme.key_profile_actionIcon), PorterDuff.Mode.MULTIPLY)); writeButton.setScaleType(ImageView.ScaleType.CENTER); if (Build.VERSION.SDK_INT >= 21) { StateListAnimator animator = new StateListAnimator(); animator.addState(new int[] { android.R.attr.state_pressed }, ObjectAnimator .ofFloat(writeButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4)) .setDuration(200)); animator.addState(new int[] {}, ObjectAnimator .ofFloat(writeButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2)) .setDuration(200)); writeButton.setStateListAnimator(animator); writeButton.setOutlineProvider(new ViewOutlineProvider() { @SuppressLint("NewApi") @Override public void getOutline(View view, Outline outline) { outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56)); } }); } frameLayout.addView(writeButton, LayoutHelper.createFrame(Build.VERSION.SDK_INT >= 21 ? 56 : 60, Build.VERSION.SDK_INT >= 21 ? 56 : 60, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.TOP, LocaleController.isRTL ? 16 : 0, 0, LocaleController.isRTL ? 0 : 16, 0)); writeButton.setOnClickListener(v -> { TLRPC.User user = MessagesController.getInstance(currentAccount) .getUser(UserConfig.getInstance(currentAccount).getClientUserId()); if (user == null) { user = UserConfig.getInstance(currentAccount).getCurrentUser(); } if (user == null) { return; } imageUpdater.openMenu( user.photo != null && user.photo.photo_big != null && !(user.photo instanceof TLRPC.TL_userProfilePhotoEmpty), () -> MessagesController.getInstance(currentAccount).deleteUserPhoto(null)); }); if (scrollTo != -1) { layoutManager.scrollToPositionWithOffset(scrollTo, scrollToPosition); if (writeButtonTag != null) { writeButton.setTag(0); writeButton.setScaleX(0.2f); writeButton.setScaleY(0.2f); writeButton.setAlpha(0.0f); writeButton.setVisibility(View.GONE); } } needLayout(); listView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { if (layoutManager.getItemCount() == 0) { return; } int height = 0; View child = recyclerView.getChildAt(0); if (child != null) { if (layoutManager.findFirstVisibleItemPosition() == 0) { height = AndroidUtilities.dp(88) + (child.getTop() < 0 ? child.getTop() : 0); } if (extraHeight != height) { extraHeight = height; needLayout(); } } } }); return fragmentView; }
From source file:org.cafemember.ui.DialogsActivity.java
@Override public View createView(final Context context) { Commands.checkChannels(MessagesController.getInstance().getDialogs()); int today = Calendar.getInstance().get(Calendar.DAY_OF_WEEK); if (today != Defaults.getInstance().getLastDay()) { Defaults.getInstance().setLastDay(today); AlertDialog.Builder builder = null; /*if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { builder = new AlertDialog.Builder(context, R.style.MyDialog); }//from w ww. java 2s . com else {*/ builder = new AlertDialog.Builder(context); // } builder.setTitle(" "); builder.setMessage( AndroidUtilities.replaceTags(LocaleController.getString("giftText", R.string.giftText))); builder.setPositiveButton("", null); showDialog(builder.create()); } searching = false; searchWas = false; Theme.loadRecources(context); ActionBarMenu menu = actionBar.createMenu(); if (!onlySelect && searchString == null) { passcodeItem = menu.addItem(1, R.drawable.lock_close); updatePasscodeButton(); } joinCoins = menu.addItemResource(7, R.layout.join_coins_view); FontManager.instance().setTypefaceImmediate(joinCoins); // viewCoins = menu.addItemResource(8, R.layout.view_coins_view); // final ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() { // @Override // public void onSearchExpand() { // searching = true; // if (listView != null) { // if (searchString != null) { // listView.setEmptyView(searchEmptyView); // progressView.setVisibility(View.GONE); // emptyView.setVisibility(View.GONE); // } // if (!onlySelect) { // floatingButton.setVisibility(View.GONE); // } // } // updatePasscodeButton(); // } // // @Override // public boolean canCollapseSearch() { // if (searchString != null) { // finishFragment(); // return false; // } // return true; // } // // @Override // public void onSearchCollapse() { // searching = false; // searchWas = false; // if (listView != null) { // searchEmptyView.setVisibility(View.GONE); // if (MessagesController.getInstance().loadingDialogs && MessagesController.getInstance().dialogs.isEmpty()) { // emptyView.setVisibility(View.GONE); // listView.setEmptyView(progressView); // } else { // progressView.setVisibility(View.GONE); // listView.setEmptyView(emptyView); // } // if (!onlySelect) { // floatingButton.setVisibility(View.VISIBLE); // floatingHidden = true; // ViewProxy.setTranslationY(floatingButton, AndroidUtilities.dp(100)); // hideFloatingButton(false); // } // if (listView.getAdapter() != dialogsAdapter) { // listView.setAdapter(dialogsAdapter); // dialogsAdapter.notifyDataSetChanged(); // } // } // if (dialogsSearchAdapter != null) { // dialogsSearchAdapter.searchDialogs(null); // } // updatePasscodeButton(); // } // // @Override // public void onTextChanged(EditText editText) { // String text = editText.getText().toString(); // if (text.length() != 0 || dialogsSearchAdapter != null && dialogsSearchAdapter.hasRecentRearch()) { // searchWas = true; // if (dialogsSearchAdapter != null && listView.getAdapter() != dialogsSearchAdapter) { // listView.setAdapter(dialogsSearchAdapter); // dialogsSearchAdapter.notifyDataSetChanged(); // } // if (searchEmptyView != null && listView.getEmptyView() != searchEmptyView) { // emptyView.setVisibility(View.GONE); // progressView.setVisibility(View.GONE); // searchEmptyView.showTextView(); // listView.setEmptyView(searchEmptyView); // } // } // if (dialogsSearchAdapter != null) { // dialogsSearchAdapter.searchDialogs(text); // } // } // }); // item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search)); if (onlySelect) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setTitle(LocaleController.getString("SelectChat", R.string.SelectChat)); } else { if (searchString != null) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); } else { actionBar.setBackButtonDrawable(new MenuDrawable()); } if (BuildVars.DEBUG_VERSION) { actionBar.setTitle(LocaleController.getString("AppNameBeta", R.string.AppNameBeta)); } else { actionBar.setTitle(LocaleController.getString("AppName", R.string.AppName)); } } actionBar.setAllowOverlayTitle(true); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(int id) { if (id == -1) { if (onlySelect) { finishFragment(); } else if (parentLayout != null) { parentLayout.getDrawerLayoutContainer().openDrawer(false); } } else if (id == 1) { UserConfig.appLocked = !UserConfig.appLocked; UserConfig.saveConfig(false); updatePasscodeButton(); } } }); FrameLayout frameLayout = new FrameLayout(context); // fragmentView = frameLayout; fragmentView = Views.getTabLayout((FragmentActivity) context, this, frameLayout); listView = new RecyclerListView(context); listView.setVerticalScrollBarEnabled(true); listView.setItemAnimator(null); listView.setInstantClick(true); listView.setLayoutAnimation(null); layoutManager = new LinearLayoutManager(context) { @Override public boolean supportsPredictiveItemAnimations() { return false; } }; layoutManager.setOrientation(LinearLayoutManager.VERTICAL); listView.setLayoutManager(layoutManager); if (Build.VERSION.SDK_INT >= 11) { listView.setVerticalScrollbarPosition( LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT); } frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); listView.setOnAddChannelClickListener(new RecyclerListView.OnItemClickListener() { @Override public void onItemClick(View view, int position) { if (listView == null || listView.getAdapter() == null) { return; } long dialog_id = 0; int message_id = 0; RecyclerView.Adapter adapter = listView.getAdapter(); if (adapter == dialogsAdapter) { TLRPC.Dialog dialog = dialogsAdapter.getItem(position); if (dialog == null) { return; } int lower_id = (int) dialog.id; final TLRPC.Chat chat = MessagesController.getInstance().getChat(-lower_id); AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("MemberBegirTitle", R.string.MemberBegirTitle)); /*builder.setItems(Defaults.MEMBERS_COUNT , new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Commands.addChannel(chat,Integer.parseInt(Defaults.MEMBERS_COUNT[which])); } });*/ /*builder.setAdapter(new ReserveAdapter(getParentActivity(),R.layout.adapter_buy_coin,1), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Commands.addChannel(chat,Integer.parseInt(Defaults.MEMBERS_COUNT[which])); } });*/ builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } } }); listView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() { @Override public void onItemClick(View view, int position) { if (listView == null || listView.getAdapter() == null) { return; } long dialog_id = 0; int message_id = 0; RecyclerView.Adapter adapter = listView.getAdapter(); if (adapter == dialogsAdapter) { TLRPC.Dialog dialog = dialogsAdapter.getItem(position); if (dialog == null) { return; } dialog_id = dialog.id; } else if (adapter == dialogsSearchAdapter) { Object obj = dialogsSearchAdapter.getItem(position); if (obj instanceof TLRPC.User) { dialog_id = ((TLRPC.User) obj).id; if (dialogsSearchAdapter.isGlobalSearch(position)) { ArrayList<TLRPC.User> users = new ArrayList<>(); users.add((TLRPC.User) obj); MessagesController.getInstance().putUsers(users, false); MessagesStorage.getInstance().putUsersAndChats(users, null, false, true); } if (!onlySelect) { dialogsSearchAdapter.putRecentSearch(dialog_id, (TLRPC.User) obj); } } else if (obj instanceof TLRPC.Chat) { if (dialogsSearchAdapter.isGlobalSearch(position)) { ArrayList<TLRPC.Chat> chats = new ArrayList<>(); chats.add((TLRPC.Chat) obj); MessagesController.getInstance().putChats(chats, false); MessagesStorage.getInstance().putUsersAndChats(null, chats, false, true); } if (((TLRPC.Chat) obj).id > 0) { dialog_id = -((TLRPC.Chat) obj).id; } else { dialog_id = AndroidUtilities.makeBroadcastId(((TLRPC.Chat) obj).id); } if (!onlySelect) { dialogsSearchAdapter.putRecentSearch(dialog_id, (TLRPC.Chat) obj); } } else if (obj instanceof TLRPC.EncryptedChat) { dialog_id = ((long) ((TLRPC.EncryptedChat) obj).id) << 32; if (!onlySelect) { dialogsSearchAdapter.putRecentSearch(dialog_id, (TLRPC.EncryptedChat) obj); } } else if (obj instanceof MessageObject) { MessageObject messageObject = (MessageObject) obj; dialog_id = messageObject.getDialogId(); message_id = messageObject.getId(); dialogsSearchAdapter.addHashtagsFromMessage(dialogsSearchAdapter.getLastSearchString()); } else if (obj instanceof String) { actionBar.openSearchField((String) obj); } } if (dialog_id == 0) { return; } if (onlySelect) { didSelectResult(dialog_id, true, false); } else { Bundle args = new Bundle(); int lower_part = (int) dialog_id; int high_id = (int) (dialog_id >> 32); if (lower_part != 0) { if (high_id == 1) { args.putInt("chat_id", lower_part); } else { if (lower_part > 0) { args.putInt("user_id", lower_part); } else if (lower_part < 0) { if (message_id != 0) { TLRPC.Chat chat = MessagesController.getInstance().getChat(-lower_part); if (chat != null && chat.migrated_to != null) { args.putInt("migrated_to", lower_part); lower_part = -chat.migrated_to.channel_id; } } args.putInt("chat_id", -lower_part); } } } else { args.putInt("enc_id", high_id); } if (message_id != 0) { args.putInt("message_id", message_id); } else { if (actionBar != null) { actionBar.closeSearchField(); } } if (AndroidUtilities.isTablet()) { if (openedDialogId == dialog_id && adapter != dialogsSearchAdapter) { return; } if (dialogsAdapter != null) { dialogsAdapter.setOpenedDialogId(openedDialogId = dialog_id); updateVisibleRows(MessagesController.UPDATE_MASK_SELECT_DIALOG); } } if (searchString != null) { if (MessagesController.checkCanOpenChat(args, DialogsActivity.this)) { NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats); presentFragment(new ChatActivity(args)); } } else { if (MessagesController.checkCanOpenChat(args, DialogsActivity.this)) { presentFragment(new ChatActivity(args)); } } } } }); listView.setOnItemLongClickListener(new RecyclerListView.OnItemLongClickListener() { @Override public boolean onItemClick(View view, int position) { if (onlySelect || searching && searchWas || getParentActivity() == null) { if (searchWas && searching || dialogsSearchAdapter.isRecentSearchDisplayed()) { RecyclerView.Adapter adapter = listView.getAdapter(); if (adapter == dialogsSearchAdapter) { Object item = dialogsSearchAdapter.getItem(position); if (item instanceof String || dialogsSearchAdapter.isRecentSearchDisplayed()) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setMessage(LocaleController.getString("ClearSearch", R.string.ClearSearch)); builder.setPositiveButton(LocaleController .getString("ClearButton", R.string.ClearButton).toUpperCase(), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if (dialogsSearchAdapter.isRecentSearchDisplayed()) { dialogsSearchAdapter.clearRecentSearch(); } else { dialogsSearchAdapter.clearRecentHashtags(); } } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); return true; } } } return false; } TLRPC.Dialog dialog; ArrayList<TLRPC.Dialog> dialogs = getDialogsArray(); if (position < 0 || position >= dialogs.size()) { return false; } dialog = dialogs.get(position); selectedDialog = dialog.id; BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity()); int lower_id = (int) selectedDialog; int high_id = (int) (selectedDialog >> 32); if (dialog instanceof TLRPC.TL_dialogChannel) { final TLRPC.Chat chat = MessagesController.getInstance().getChat(-lower_id); CharSequence items[]; if (chat != null && chat.megagroup) { items = new CharSequence[] { LocaleController.getString("ClearHistoryCache", R.string.ClearHistoryCache), chat == null || !chat.creator ? LocaleController.getString("LeaveMegaMenu", R.string.LeaveMegaMenu) : LocaleController.getString("DeleteMegaMenu", R.string.DeleteMegaMenu) }; } else { items = new CharSequence[] { LocaleController.getString("ClearHistoryCache", R.string.ClearHistoryCache), chat == null || !chat.creator ? LocaleController.getString("LeaveChannelMenu", R.string.LeaveChannelMenu) : LocaleController.getString("ChannelDeleteMenu", R.string.ChannelDeleteMenu), LocaleController.getString("MemberBegir", R.string.MemberBegir) }; } builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, final int which) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); if (which == 0) { if (chat != null && chat.megagroup) { builder.setMessage(LocaleController.getString("AreYouSureClearHistorySuper", R.string.AreYouSureClearHistorySuper)); } else { builder.setMessage(LocaleController.getString("AreYouSureClearHistoryChannel", R.string.AreYouSureClearHistoryChannel)); } builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { MessagesController.getInstance().deleteDialog(selectedDialog, 2); } }); } else if (which == 2) { builder.setTitle( LocaleController.getString("MemberBegirTitle", R.string.MemberBegirTitle)); /*builder.setAdapter(new ReserveAdapter(getParentActivity(),R.layout.adapter_buy_coin,1), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Commands.addChannel(chat,Integer.parseInt(Defaults.MEMBERS_COUNT[which])); } });*/ /*builder.setItems(Defaults.MEMBERS_COUNT , new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Commands.addChannel(chat,Integer.parseInt(Defaults.MEMBERS_COUNT[which])); } });*/ } else { if (chat != null && chat.megagroup) { if (!chat.creator) { builder.setMessage(LocaleController.getString("MegaLeaveAlert", R.string.MegaLeaveAlert)); } else { builder.setMessage(LocaleController.getString("MegaDeleteAlert", R.string.MegaDeleteAlert)); } } else { if (chat == null || !chat.creator) { builder.setMessage(LocaleController.getString("ChannelLeaveAlert", R.string.ChannelLeaveAlert)); } else { builder.setMessage(LocaleController.getString("ChannelDeleteAlert", R.string.ChannelDeleteAlert)); } } builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { MessagesController.getInstance().deleteUserFromChat( (int) -selectedDialog, UserConfig.getCurrentUser(), null); if (AndroidUtilities.isTablet()) { NotificationCenter.getInstance().postNotificationName( NotificationCenter.closeChats, selectedDialog); } } }); } builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } }); showDialog(builder.create()); } else { final boolean isChat = lower_id < 0 && high_id != 1; TLRPC.User user = null; if (!isChat && lower_id > 0 && high_id != 1) { user = MessagesController.getInstance().getUser(lower_id); } final boolean isBot = user != null && user.bot; builder.setItems( new CharSequence[] { LocaleController.getString("ClearHistory", R.string.ClearHistory), isChat ? LocaleController.getString("DeleteChat", R.string.DeleteChat) : isBot ? LocaleController.getString("DeleteAndStop", R.string.DeleteAndStop) : LocaleController.getString("Delete", R.string.Delete) }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, final int which) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); if (which == 0) { builder.setMessage(LocaleController.getString("AreYouSureClearHistory", R.string.AreYouSureClearHistory)); } else { if (isChat) { builder.setMessage(LocaleController.getString("AreYouSureDeleteAndExit", R.string.AreYouSureDeleteAndExit)); } else { builder.setMessage(LocaleController.getString( "AreYouSureDeleteThisChat", R.string.AreYouSureDeleteThisChat)); } } builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if (which != 0) { if (isChat) { TLRPC.Chat currentChat = MessagesController .getInstance().getChat((int) -selectedDialog); if (currentChat != null && ChatObject.isNotInChat(currentChat)) { MessagesController.getInstance() .deleteDialog(selectedDialog, 0); } else { MessagesController.getInstance().deleteUserFromChat( (int) -selectedDialog, MessagesController.getInstance().getUser( UserConfig.getClientUserId()), null); } } else { MessagesController.getInstance() .deleteDialog(selectedDialog, 0); } if (isBot) { MessagesController.getInstance() .blockUser((int) selectedDialog); } if (AndroidUtilities.isTablet()) { NotificationCenter.getInstance().postNotificationName( NotificationCenter.closeChats, selectedDialog); } } else { MessagesController.getInstance() .deleteDialog(selectedDialog, 1); } } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } }); showDialog(builder.create()); } return true; } }); searchEmptyView = new EmptyTextProgressView(context); searchEmptyView.setVisibility(View.GONE); searchEmptyView.setShowAtCenter(true); searchEmptyView.setText(LocaleController.getString("NoResult", R.string.NoResult)); frameLayout.addView(searchEmptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); emptyView = new LinearLayout(context); emptyView.setOrientation(LinearLayout.VERTICAL); emptyView.setVisibility(View.GONE); emptyView.setGravity(Gravity.CENTER); frameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); emptyView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); TextView textView = new TextView(context); textView.setText(LocaleController.getString("NoChats", R.string.NoChats)); textView.setTextColor(0xff959595); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20); emptyView.addView(textView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT)); textView = new TextView(context); String help = LocaleController.getString("NoChatsHelp", R.string.NoChatsHelp); if (AndroidUtilities.isTablet() && !AndroidUtilities.isSmallTablet()) { help = help.replace('\n', ' '); } textView.setText(help); textView.setTextColor(0xff959595); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15); textView.setGravity(Gravity.CENTER); textView.setPadding(AndroidUtilities.dp(8), AndroidUtilities.dp(6), AndroidUtilities.dp(8), 0); textView.setLineSpacing(AndroidUtilities.dp(2), 1); emptyView.addView(textView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT)); progressView = new ProgressBar(context); progressView.setVisibility(View.GONE); frameLayout.addView(progressView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER)); floatingButton = new ImageView(context); floatingButton.setVisibility(onlySelect ? View.GONE : View.VISIBLE); floatingButton.setScaleType(ImageView.ScaleType.CENTER); floatingButton.setBackgroundResource(R.drawable.floating_states); floatingButton.setImageResource(R.drawable.floating_pencil); if (Build.VERSION.SDK_INT >= 21) { StateListAnimator animator = new StateListAnimator(); animator.addState(new int[] { android.R.attr.state_pressed }, ObjectAnimator .ofFloat(floatingButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4)) .setDuration(200)); animator.addState(new int[] {}, ObjectAnimator .ofFloat(floatingButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2)) .setDuration(200)); floatingButton.setStateListAnimator(animator); floatingButton.setOutlineProvider(new ViewOutlineProvider() { @SuppressLint("NewApi") @Override public void getOutline(View view, Outline outline) { outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56)); } }); } frameLayout.addView(floatingButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM, LocaleController.isRTL ? 14 : 0, 0, LocaleController.isRTL ? 0 : 14, 14)); floatingButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Bundle args = new Bundle(); args.putBoolean("destroyAfterSelect", true); presentFragment(new ContactsActivity(args)); } }); listView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { if (newState == RecyclerView.SCROLL_STATE_DRAGGING && searching && searchWas) { AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus()); } } @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { int firstVisibleItem = layoutManager.findFirstVisibleItemPosition(); int visibleItemCount = Math.abs(layoutManager.findLastVisibleItemPosition() - firstVisibleItem) + 1; int totalItemCount = recyclerView.getAdapter().getItemCount(); if (searching && searchWas) { if (visibleItemCount > 0 && layoutManager.findLastVisibleItemPosition() == totalItemCount - 1 && !dialogsSearchAdapter.isMessagesSearchEndReached()) { dialogsSearchAdapter.loadMoreSearchMessages(); } return; } if (visibleItemCount > 0) { if (layoutManager.findLastVisibleItemPosition() >= getDialogsArray().size() - 10) { MessagesController.getInstance().loadDialogs(-1, 100, !MessagesController.getInstance().dialogsEndReached); } } if (floatingButton.getVisibility() != View.GONE) { final View topChild = recyclerView.getChildAt(0); int firstViewTop = 0; if (topChild != null) { firstViewTop = topChild.getTop(); } boolean goingDown; boolean changed = true; if (prevPosition == firstVisibleItem) { final int topDelta = prevTop - firstViewTop; goingDown = firstViewTop < prevTop; changed = Math.abs(topDelta) > 1; } else { goingDown = firstVisibleItem > prevPosition; } if (changed && scrollUpdated) { hideFloatingButton(goingDown); } prevPosition = firstVisibleItem; prevTop = firstViewTop; scrollUpdated = true; } } }); if (searchString == null) { dialogsAdapter = new DialogsAdapter(context, dialogsType); if (AndroidUtilities.isTablet() && openedDialogId != 0) { dialogsAdapter.setOpenedDialogId(openedDialogId); } listView.setAdapter(dialogsAdapter); } int type = 0; if (searchString != null) { type = 2; } else if (!onlySelect) { type = 1; } dialogsSearchAdapter = new DialogsSearchAdapter(context, type, dialogsType); dialogsSearchAdapter.setDelegate(new DialogsSearchAdapter.MessagesActivitySearchAdapterDelegate() { @Override public void searchStateChanged(boolean search) { if (searching && searchWas && searchEmptyView != null) { if (search) { searchEmptyView.showProgress(); } else { searchEmptyView.showTextView(); } } } }); if (MessagesController.getInstance().loadingDialogs && MessagesController.getInstance().dialogs.isEmpty()) { searchEmptyView.setVisibility(View.GONE); emptyView.setVisibility(View.GONE); listView.setEmptyView(progressView); } else { searchEmptyView.setVisibility(View.GONE); progressView.setVisibility(View.GONE); listView.setEmptyView(emptyView); } if (searchString != null) { actionBar.openSearchField(searchString); } if (!onlySelect && dialogsType == 0) { frameLayout.addView(new PlayerView(context, this), LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 39, Gravity.TOP | Gravity.LEFT, 0, -36, 0, 0)); } // fragmentView = Views.getTabLayout((FragmentActivity) context, this, frameLayout); return fragmentView; }
From source file:kr.wdream.ui.DialogsActivity.java
public void initView() { RelativeLayout relativeLayout = new RelativeLayout(context); fragmentView = relativeLayout;/*from ww w . ja va2s .co m*/ LinearLayout lytTab = new LinearLayout(context); lytTab.setId(kr.wdream.storyshop.R.id.lytTab); tabParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1); tabParams.setMargins(0, 0, 0, 5); tab1 = new LinearLayout(context); tab1.setGravity(Gravity.CENTER); imgTab1 = new ImageView(context); imgTab1.setImageResource(R.drawable.m_i_main_flist_n); tab1.addView(imgTab1, LayoutHelper.createLinear(21, 20)); tab1.setOnClickListener(this); tab2 = new LinearLayout(context); tab2.setGravity(Gravity.CENTER); imgTab2 = new ImageView(context); imgTab2.setImageResource(R.drawable.m_i_main_clist_n); tab2.addView(imgTab2, LayoutHelper.createLinear(21, 20)); tab2.setOnClickListener(this); tab3 = new LinearLayout(context); tab3.setGravity(Gravity.CENTER); imgTab3 = new ImageView(context); imgTab3.setImageResource(R.drawable.m_i_main_content_n); tab3.addView(imgTab3, LayoutHelper.createLinear(21, 20)); tab3.setOnClickListener(this); tab4 = new LinearLayout(context); tab4.setGravity(Gravity.CENTER); imgTab4 = new ImageView(context); imgTab4.setImageResource(R.drawable.m_i_main_setting_n); tab4.addView(imgTab4, LayoutHelper.createLinear(21, 20)); tab4.setOnClickListener(this); lytDialogs = new RelativeLayout(context); RelativeLayout.LayoutParams lytDialogsParams = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); lytDialogsParams.addRule(RelativeLayout.BELOW, lytTab.getId()); lytDialogs.setLayoutParams(lytDialogsParams); lytDialogs.setVisibility(View.GONE); listView = new RecyclerListView(context); listView.setVerticalScrollBarEnabled(true); listView.setItemAnimator(null); listView.setInstantClick(true); listView.setLayoutAnimation(null); listView.setTag(4); listView.setVisibility(View.GONE); layoutManager = new LinearLayoutManager(context) { @Override public boolean supportsPredictiveItemAnimations() { return false; } }; layoutManager.setOrientation(LinearLayoutManager.VERTICAL); listView.setLayoutManager(layoutManager); listView.setVerticalScrollbarPosition( LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT); listView.setVerticalScrollBarEnabled(false); listView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY); listView.setVerticalScrollbarPosition( LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT); listView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() { @Override public void onItemClick(View view, int position) { if (listView == null || listView.getAdapter() == null) { return; } long dialog_id = 0; int message_id = 0; RecyclerView.Adapter adapter = listView.getAdapter(); if (adapter == dialogsAdapter) { TLRPC.TL_dialog dialog = dialogsAdapter.getItem(position); if (dialog == null) { return; } dialog_id = dialog.id; } else if (adapter == dialogsSearchAdapter) { Object obj = dialogsSearchAdapter.getItem(position); if (obj instanceof TLRPC.User) { dialog_id = ((TLRPC.User) obj).id; if (dialogsSearchAdapter.isGlobalSearch(position)) { ArrayList<TLRPC.User> users = new ArrayList<>(); users.add((TLRPC.User) obj); MessagesController.getInstance().putUsers(users, false); MessagesStorage.getInstance().putUsersAndChats(users, null, false, true); } if (!onlySelect) { dialogsSearchAdapter.putRecentSearch(dialog_id, (TLRPC.User) obj); } } else if (obj instanceof TLRPC.Chat) { if (dialogsSearchAdapter.isGlobalSearch(position)) { ArrayList<TLRPC.Chat> chats = new ArrayList<>(); chats.add((TLRPC.Chat) obj); MessagesController.getInstance().putChats(chats, false); MessagesStorage.getInstance().putUsersAndChats(null, chats, false, true); } if (((TLRPC.Chat) obj).id > 0) { dialog_id = -((TLRPC.Chat) obj).id; } else { dialog_id = AndroidUtilities.makeBroadcastId(((TLRPC.Chat) obj).id); } if (!onlySelect) { dialogsSearchAdapter.putRecentSearch(dialog_id, (TLRPC.Chat) obj); } } else if (obj instanceof TLRPC.EncryptedChat) { dialog_id = ((long) ((TLRPC.EncryptedChat) obj).id) << 32; if (!onlySelect) { dialogsSearchAdapter.putRecentSearch(dialog_id, (TLRPC.EncryptedChat) obj); } } else if (obj instanceof MessageObject) { MessageObject messageObject = (MessageObject) obj; dialog_id = messageObject.getDialogId(); message_id = messageObject.getId(); dialogsSearchAdapter.addHashtagsFromMessage(dialogsSearchAdapter.getLastSearchString()); } else if (obj instanceof String) { Log.d(LOG_TAG, "obj String : openSearchField"); actionBar.openSearchField((String) obj); } } if (dialog_id == 0) { return; } if (onlySelect) { didSelectResult(dialog_id, true, false); } else { Bundle args = new Bundle(); int lower_part = (int) dialog_id; int high_id = (int) (dialog_id >> 32); if (lower_part != 0) { if (high_id == 1) { args.putInt("chat_id", lower_part); } else { if (lower_part > 0) { args.putInt("user_id", lower_part); } else if (lower_part < 0) { if (message_id != 0) { TLRPC.Chat chat = MessagesController.getInstance().getChat(-lower_part); if (chat != null && chat.migrated_to != null) { args.putInt("migrated_to", lower_part); lower_part = -chat.migrated_to.channel_id; } } args.putInt("chat_id", -lower_part); } } } else { args.putInt("enc_id", high_id); } if (message_id != 0) { args.putInt("message_id", message_id); } else { if (actionBar != null) { actionBar.closeSearchField(); } } if (AndroidUtilities.isTablet()) { if (openedDialogId == dialog_id && adapter != dialogsSearchAdapter) { return; } if (dialogsAdapter != null) { dialogsAdapter.setOpenedDialogId(openedDialogId = dialog_id); updateVisibleRows(MessagesController.UPDATE_MASK_SELECT_DIALOG); } } if (searchString != null) { if (MessagesController.checkCanOpenChat(args, DialogsActivity.this)) { NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats); presentFragment(new ChatActivity(args)); } } else { if (MessagesController.checkCanOpenChat(args, DialogsActivity.this)) { presentFragment(new ChatActivity(args)); } } } } }); listView.setOnItemLongClickListener(new RecyclerListView.OnItemLongClickListener() { @Override public boolean onItemClick(View view, int position) { if (onlySelect || searching && searchWas || getParentActivity() == null) { if (searchWas && searching || dialogsSearchAdapter.isRecentSearchDisplayed()) { RecyclerView.Adapter adapter = listView.getAdapter(); if (adapter == dialogsSearchAdapter) { Object item = dialogsSearchAdapter.getItem(position); if (item instanceof String || dialogsSearchAdapter.isRecentSearchDisplayed()) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", kr.wdream.storyshop.R.string.AppName)); builder.setMessage(LocaleController.getString("ClearSearch", kr.wdream.storyshop.R.string.ClearSearch)); builder.setPositiveButton(LocaleController .getString("ClearButton", kr.wdream.storyshop.R.string.ClearButton) .toUpperCase(), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if (dialogsSearchAdapter.isRecentSearchDisplayed()) { dialogsSearchAdapter.clearRecentSearch(); } else { dialogsSearchAdapter.clearRecentHashtags(); } } }); builder.setNegativeButton( LocaleController.getString("Cancel", kr.wdream.storyshop.R.string.Cancel), null); showDialog(builder.create()); return true; } } } return false; } TLRPC.TL_dialog dialog; ArrayList<TLRPC.TL_dialog> dialogs = getDialogsArray(); if (position < 0 || position >= dialogs.size()) { return false; } dialog = dialogs.get(position); selectedDialog = dialog.id; BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity()); int lower_id = (int) selectedDialog; int high_id = (int) (selectedDialog >> 32); if (DialogObject.isChannel(dialog)) { final TLRPC.Chat chat = MessagesController.getInstance().getChat(-lower_id); CharSequence items[]; if (chat != null && chat.megagroup) { items = new CharSequence[] { LocaleController.getString("ClearHistoryCache", kr.wdream.storyshop.R.string.ClearHistoryCache), chat == null || !chat.creator ? LocaleController.getString("LeaveMegaMenu", kr.wdream.storyshop.R.string.LeaveMegaMenu) : LocaleController.getString("DeleteMegaMenu", kr.wdream.storyshop.R.string.DeleteMegaMenu) }; } else { items = new CharSequence[] { LocaleController.getString("ClearHistoryCache", kr.wdream.storyshop.R.string.ClearHistoryCache), chat == null || !chat.creator ? LocaleController.getString("LeaveChannelMenu", kr.wdream.storyshop.R.string.LeaveChannelMenu) : LocaleController.getString("ChannelDeleteMenu", kr.wdream.storyshop.R.string.ChannelDeleteMenu) }; } builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, final int which) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle( LocaleController.getString("AppName", kr.wdream.storyshop.R.string.AppName)); if (which == 0) { if (chat != null && chat.megagroup) { builder.setMessage(LocaleController.getString("AreYouSureClearHistorySuper", kr.wdream.storyshop.R.string.AreYouSureClearHistorySuper)); } else { builder.setMessage(LocaleController.getString("AreYouSureClearHistoryChannel", kr.wdream.storyshop.R.string.AreYouSureClearHistoryChannel)); } builder.setPositiveButton( LocaleController.getString("OK", kr.wdream.storyshop.R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { MessagesController.getInstance().deleteDialog(selectedDialog, 2); } }); } else { if (chat != null && chat.megagroup) { if (!chat.creator) { builder.setMessage(LocaleController.getString("MegaLeaveAlert", kr.wdream.storyshop.R.string.MegaLeaveAlert)); } else { builder.setMessage(LocaleController.getString("MegaDeleteAlert", kr.wdream.storyshop.R.string.MegaDeleteAlert)); } } else { if (chat == null || !chat.creator) { builder.setMessage(LocaleController.getString("ChannelLeaveAlert", kr.wdream.storyshop.R.string.ChannelLeaveAlert)); } else { builder.setMessage(LocaleController.getString("ChannelDeleteAlert", kr.wdream.storyshop.R.string.ChannelDeleteAlert)); } } builder.setPositiveButton( LocaleController.getString("OK", kr.wdream.storyshop.R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { MessagesController.getInstance().deleteUserFromChat( (int) -selectedDialog, UserConfig.getCurrentUser(), null); if (AndroidUtilities.isTablet()) { NotificationCenter.getInstance().postNotificationName( NotificationCenter.closeChats, selectedDialog); } } }); } builder.setNegativeButton( LocaleController.getString("Cancel", kr.wdream.storyshop.R.string.Cancel), null); showDialog(builder.create()); } }); showDialog(builder.create()); } else { final boolean isChat = lower_id < 0 && high_id != 1; TLRPC.User user = null; if (!isChat && lower_id > 0 && high_id != 1) { user = MessagesController.getInstance().getUser(lower_id); } final boolean isBot = user != null && user.bot; builder.setItems( new CharSequence[] { LocaleController.getString("ClearHistory", kr.wdream.storyshop.R.string.ClearHistory), isChat ? LocaleController.getString("DeleteChat", kr.wdream.storyshop.R.string.DeleteChat) : isBot ? LocaleController.getString("DeleteAndStop", kr.wdream.storyshop.R.string.DeleteAndStop) : LocaleController.getString("Delete", kr.wdream.storyshop.R.string.Delete) }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, final int which) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", kr.wdream.storyshop.R.string.AppName)); if (which == 0) { builder.setMessage(LocaleController.getString("AreYouSureClearHistory", kr.wdream.storyshop.R.string.AreYouSureClearHistory)); } else { if (isChat) { builder.setMessage(LocaleController.getString("AreYouSureDeleteAndExit", kr.wdream.storyshop.R.string.AreYouSureDeleteAndExit)); } else { builder.setMessage( LocaleController.getString("AreYouSureDeleteThisChat", kr.wdream.storyshop.R.string.AreYouSureDeleteThisChat)); } } builder.setPositiveButton( LocaleController.getString("OK", kr.wdream.storyshop.R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if (which != 0) { if (isChat) { TLRPC.Chat currentChat = MessagesController .getInstance().getChat((int) -selectedDialog); if (currentChat != null && ChatObject.isNotInChat(currentChat)) { MessagesController.getInstance() .deleteDialog(selectedDialog, 0); } else { MessagesController.getInstance().deleteUserFromChat( (int) -selectedDialog, MessagesController.getInstance().getUser( UserConfig.getClientUserId()), null); } } else { MessagesController.getInstance() .deleteDialog(selectedDialog, 0); } if (isBot) { MessagesController.getInstance() .blockUser((int) selectedDialog); } if (AndroidUtilities.isTablet()) { NotificationCenter.getInstance().postNotificationName( NotificationCenter.closeChats, selectedDialog); } } else { MessagesController.getInstance() .deleteDialog(selectedDialog, 1); } } }); builder.setNegativeButton(LocaleController.getString("Cancel", kr.wdream.storyshop.R.string.Cancel), null); showDialog(builder.create()); } }); showDialog(builder.create()); } return true; } }); listContacts = new LetterSectionsListView(context); RelativeLayout.LayoutParams contactParams = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); contactParams.addRule(RelativeLayout.BELOW, lytTab.getId()); listContacts.setLayoutParams(contactParams); Log.d(LOG_TAG, "contactsAdapter : " + LaunchActivity.contactsAdapter.getItem(0)); listContacts.setAdapter(LaunchActivity.contactsAdapter); handler.postDelayed(new Runnable() { @Override public void run() { Log.d(LOG_TAG, "postDelayed Start"); handler.sendEmptyMessage(0); } }, 1500); listContacts.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { int section = LaunchActivity.contactsAdapter.getSectionForPosition(position); int row = LaunchActivity.contactsAdapter.getPositionInSectionForPosition(position); Object item = LaunchActivity.contactsAdapter.getItem(section, row); if (0 == position) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, ContactsController.getInstance().getInviteText()); getParentActivity().startActivityForResult(Intent.createChooser(intent, LocaleController .getString("InviteFriends", kr.wdream.storyshop.R.string.InviteFriends)), 500); } else if (item instanceof ContactsController.Contact) { ContactsController.Contact contact = (ContactsController.Contact) item; String usePhone = null; if (!contact.phones.isEmpty()) { usePhone = contact.phones.get(0); } if (usePhone == null || getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage( LocaleController.getString("InviteUser", kr.wdream.storyshop.R.string.InviteUser)); builder.setTitle(LocaleController.getString("AppName", kr.wdream.storyshop.R.string.AppName)); final String arg1 = usePhone; builder.setPositiveButton(LocaleController.getString("OK", kr.wdream.storyshop.R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { try { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", arg1, null)); intent.putExtra("sms_body", LocaleController.getString("InviteText", kr.wdream.storyshop.R.string.InviteText)); getParentActivity().startActivityForResult(intent, 500); } catch (Exception e) { FileLog.e("tmessages", e); } } }); builder.setNegativeButton( LocaleController.getString("Cancel", kr.wdream.storyshop.R.string.Cancel), null); showDialog(builder.create()); } else { TLRPC.User user = (TLRPC.User) LaunchActivity.contactsAdapter.getItem(position); if (user == null) return; Bundle args = new Bundle(); args.putInt("user_id", user.id); if (MessagesController.checkCanOpenChat(args, DialogsActivity.this)) { presentFragment(new ChatActivity(args), false); } } } }); contentLayout = new LinearLayout(context); contentLayout.setOrientation(LinearLayout.VERTICAL); contentLayout.setVisibility(View.GONE); RelativeLayout.LayoutParams contentParams = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); contentParams.addRule(RelativeLayout.BELOW, lytTab.getId()); // Contents Layout ? GridView gridContents = new GridView(context); gridContents.setNumColumns(GridView.AUTO_FIT); gridContents.setGravity(Gravity.CENTER); ContentsAdapter contentsAdapter = new ContentsAdapter(context); gridContents.setAdapter(contentsAdapter); contentLayout.addView(gridContents, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); gridContents.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { switch (position) { case 0: Log.d("??", "grid0"); Intent intent = new Intent(context, ShoppingMainActivity.class); context.startActivity(intent); break; case 1: Log.d("??", "grid1"); break; case 2: Log.d("??", "grid2"); break; case 3: Log.d("??", "grid3"); break; } } }); // Setting Layout ? settingLayout = new LinearLayout(context); settingLayout.setOrientation(LinearLayout.VERTICAL); settingLayout.setVisibility(View.GONE); settingLayout.setBackgroundColor(Color.parseColor("#EEEEEE")); createSettingLayout(); // TabBar lytTab.addView(tab1, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 1)); lytTab.addView(tab2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 1)); lytTab.addView(tab3, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 1)); lytTab.addView(tab4, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 1)); relativeLayout.addView(lytTab, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 50)); RelativeLayout.LayoutParams listParams = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); lytDialogs.addView(listView, listParams); relativeLayout.addView(lytDialogs, lytDialogsParams); relativeLayout.addView(listContacts, contactParams); relativeLayout.addView(contentLayout, contentParams); relativeLayout.addView(settingLayout, contentParams); searchEmptyView = new EmptyTextProgressView(context); searchEmptyView.setVisibility(View.GONE); searchEmptyView.setShowAtCenter(true); searchEmptyView.setText(LocaleController.getString("NoResult", kr.wdream.storyshop.R.string.NoResult)); relativeLayout.addView(searchEmptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); emptyView = new LinearLayout(context); emptyView.setOrientation(LinearLayout.VERTICAL); emptyView.setVisibility(View.GONE); emptyView.setGravity(Gravity.CENTER); // relativeLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); emptyView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); TextView textView = new TextView(context); textView.setText(LocaleController.getString("NoChats", kr.wdream.storyshop.R.string.NoChats)); textView.setTextColor(0xff959595); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20); emptyView.addView(textView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT)); textView = new TextView(context); String help = LocaleController.getString("NoChatsHelp", kr.wdream.storyshop.R.string.NoChatsHelp); if (AndroidUtilities.isTablet() && !AndroidUtilities.isSmallTablet()) { help = help.replace('\n', ' '); } textView.setText(help); textView.setTextColor(0xff959595); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15); textView.setGravity(Gravity.CENTER); textView.setPadding(AndroidUtilities.dp(8), AndroidUtilities.dp(6), AndroidUtilities.dp(8), 0); textView.setLineSpacing(AndroidUtilities.dp(2), 1); emptyView.addView(textView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT)); progressView = new ProgressBar(context); progressView.setVisibility(View.GONE); RelativeLayout.LayoutParams progParams = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); progParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); progressView.setLayoutParams(progParams); // relativeLayout.addView(progressView); // relativeLayout.addView(progressView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER)); floatingButton = new ImageView(context); floatingButton.setVisibility(onlySelect ? View.GONE : View.VISIBLE); floatingButton.setScaleType(ImageView.ScaleType.CENTER); floatingButton.setBackgroundResource(kr.wdream.storyshop.R.drawable.floating_states); floatingButton.setImageResource(kr.wdream.storyshop.R.drawable.floating_pencil); Log.d(LOG_TAG, "setVisibility.VISIBLE_floating : " + floatingButton.getVisibility()); floatingButton.setVisibility(View.GONE); Log.d(LOG_TAG, "setVisibility.GONE_floating : " + floatingButton.getVisibility()); if (Build.VERSION.SDK_INT >= 21) { StateListAnimator animator = new StateListAnimator(); animator.addState(new int[] { android.R.attr.state_pressed }, ObjectAnimator .ofFloat(floatingButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4)) .setDuration(200)); animator.addState(new int[] {}, ObjectAnimator .ofFloat(floatingButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2)) .setDuration(200)); floatingButton.setStateListAnimator(animator); floatingButton.setOutlineProvider(new ViewOutlineProvider() { @SuppressLint("NewApi") @Override public void getOutline(View view, Outline outline) { outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56)); } }); } RelativeLayout.LayoutParams floatingParams = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); floatingParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); floatingParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); // relativeLayout.addView(floatingButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM, LocaleController.isRTL ? 14 : 0, 0, LocaleController.isRTL ? 0 : 14, 14)); relativeLayout.addView(floatingButton, floatingParams); floatingButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Bundle args = new Bundle(); args.putBoolean("destroyAfterSelect", true); presentFragment(new ContactsActivity(args)); } }); listView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { if (newState == RecyclerView.SCROLL_STATE_DRAGGING && searching && searchWas) { AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus()); } } @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { int firstVisibleItem = layoutManager.findFirstVisibleItemPosition(); int visibleItemCount = Math.abs(layoutManager.findLastVisibleItemPosition() - firstVisibleItem) + 1; int totalItemCount = recyclerView.getAdapter().getItemCount(); if (searching && searchWas) { if (visibleItemCount > 0 && layoutManager.findLastVisibleItemPosition() == totalItemCount - 1 && !dialogsSearchAdapter.isMessagesSearchEndReached()) { dialogsSearchAdapter.loadMoreSearchMessages(); } return; } if (visibleItemCount > 0) { if (layoutManager.findLastVisibleItemPosition() >= getDialogsArray().size() - 10) { MessagesController.getInstance().loadDialogs(-1, 100, !MessagesController.getInstance().dialogsEndReached); } } if (floatingButton.getVisibility() != View.GONE) { final View topChild = recyclerView.getChildAt(0); int firstViewTop = 0; if (topChild != null) { firstViewTop = topChild.getTop(); } boolean goingDown; boolean changed = true; if (prevPosition == firstVisibleItem) { final int topDelta = prevTop - firstViewTop; goingDown = firstViewTop < prevTop; changed = Math.abs(topDelta) > 1; } else { goingDown = firstVisibleItem > prevPosition; } if (changed && scrollUpdated) { hideFloatingButton(goingDown); } prevPosition = firstVisibleItem; prevTop = firstViewTop; scrollUpdated = true; } } }); if (searchString == null) { dialogsAdapter = new DialogsAdapter(context, dialogsType); Log.d("Dialog", "dialogsSize : " + dialogsAdapter.getItemCount()); if (AndroidUtilities.isTablet() && openedDialogId != 0) { dialogsAdapter.setOpenedDialogId(openedDialogId); } listView.setAdapter(dialogsAdapter); } int type = 0; if (searchString != null) { type = 2; } else if (!onlySelect) { type = 1; } dialogsSearchAdapter = new DialogsSearchAdapter(context, type, dialogsType); dialogsSearchAdapter.setDelegate(new DialogsSearchAdapter.DialogsSearchAdapterDelegate() { @Override public void searchStateChanged(boolean search) { if (searching && searchWas && searchEmptyView != null) { if (search) { searchEmptyView.showProgress(); } else { searchEmptyView.showTextView(); } } } @Override public void didPressedOnSubDialog(int did) { if (onlySelect) { didSelectResult(did, true, false); } else { Bundle args = new Bundle(); if (did > 0) { args.putInt("user_id", did); } else { args.putInt("chat_id", -did); } if (actionBar != null) { actionBar.closeSearchField(); } if (AndroidUtilities.isTablet()) { if (dialogsAdapter != null) { dialogsAdapter.setOpenedDialogId(openedDialogId = did); updateVisibleRows(MessagesController.UPDATE_MASK_SELECT_DIALOG); } } if (searchString != null) { if (MessagesController.checkCanOpenChat(args, DialogsActivity.this)) { NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats); presentFragment(new ChatActivity(args)); } } else { if (MessagesController.checkCanOpenChat(args, DialogsActivity.this)) { presentFragment(new ChatActivity(args)); } } } } @Override public void needRemoveHint(final int did) { if (getParentActivity() == null) { return; } TLRPC.User user = MessagesController.getInstance().getUser(did); if (user == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", kr.wdream.storyshop.R.string.AppName)); builder.setMessage(LocaleController.formatString("ChatHintsDelete", kr.wdream.storyshop.R.string.ChatHintsDelete, ContactsController.formatName(user.first_name, user.last_name))); builder.setPositiveButton(LocaleController.getString("OK", kr.wdream.storyshop.R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { SearchQuery.removePeer(did); } }); builder.setNegativeButton(LocaleController.getString("Cancel", kr.wdream.storyshop.R.string.Cancel), null); showDialog(builder.create()); } }); if (MessagesController.getInstance().loadingDialogs && MessagesController.getInstance().dialogs.isEmpty()) { searchEmptyView.setVisibility(View.GONE); emptyView.setVisibility(View.GONE); listView.setEmptyView(progressView); } else { searchEmptyView.setVisibility(View.GONE); progressView.setVisibility(View.GONE); listView.setEmptyView(emptyView); } if (searchString != null) { actionBar.openSearchField(searchString); } if (!onlySelect && dialogsType == 0) { relativeLayout.addView(new PlayerView(context, this), LayoutHelper .createFrame(LayoutHelper.MATCH_PARENT, 39, Gravity.TOP | Gravity.LEFT, 0, -36, 0, 0)); } tab1.performClick(); }
From source file:org.telegram.ui.ProfileActivity.java
@Override public View createView(Context context) { hasOwnBackground = true;// ww w .j a v a 2 s . c o m extraHeight = AndroidUtilities.dp(88); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(final int id) { if (getParentActivity() == null) { return; } if (id == -1) { finishFragment(); } else if (id == block_contact) { TLRPC.User user = MessagesController.getInstance().getUser(user_id); if (user == null) { return; } if (!user.bot) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); if (!userBlocked) { builder.setMessage(LocaleController.getString("AreYouSureBlockContact", R.string.AreYouSureBlockContact)); } else { builder.setMessage(LocaleController.getString("AreYouSureUnblockContact", R.string.AreYouSureUnblockContact)); } 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) { if (!userBlocked) { MessagesController.getInstance().blockUser(user_id); } else { MessagesController.getInstance().unblockUser(user_id); } } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } else { if (!userBlocked) { MessagesController.getInstance().blockUser(user_id); } else { MessagesController.getInstance().unblockUser(user_id); SendMessagesHelper.getInstance().sendMessage("/start", user_id, null, null, false, null, null, null); finishFragment(); } } } else if (id == add_contact) { TLRPC.User user = MessagesController.getInstance().getUser(user_id); Bundle args = new Bundle(); args.putInt("user_id", user.id); args.putBoolean("addContact", true); presentFragment(new ContactAddActivity(args)); } else if (id == share_contact) { Bundle args = new Bundle(); args.putBoolean("onlySelect", true); args.putInt("dialogsType", 1); args.putString("selectAlertString", LocaleController.getString("SendContactTo", R.string.SendContactTo)); args.putString("selectAlertStringGroup", LocaleController.getString("SendContactToGroup", R.string.SendContactToGroup)); DialogsActivity fragment = new DialogsActivity(args); fragment.setDelegate(ProfileActivity.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().getUser(user_id); if (user == null || getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("AreYouSureDeleteContact", R.string.AreYouSureDeleteContact)); 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<>(); arrayList.add(user); ContactsController.getInstance().deleteContact(arrayList); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } else if (id == leave_group) { leaveChatPressed(); } else if (id == edit_name) { Bundle args = new Bundle(); args.putInt("chat_id", chat_id); presentFragment(new ChangeChatNameActivity(args)); } else if (id == edit_channel) { Bundle args = new Bundle(); args.putInt("chat_id", chat_id); ChannelEditActivity fragment = new ChannelEditActivity(args); fragment.setInfo(info); presentFragment(fragment); } else if (id == invite_to_group) { final TLRPC.User user = MessagesController.getInstance().getUser(user_id); if (user == null) { return; } Bundle args = new Bundle(); args.putBoolean("onlySelect", true); args.putInt("dialogsType", 2); args.putString("addToGroupAlertString", LocaleController.formatString("AddToTheGroupTitle", R.string.AddToTheGroupTitle, UserObject.getUserName(user), "%1$s")); DialogsActivity fragment = new DialogsActivity(args); fragment.setDelegate(new DialogsActivity.DialogsActivityDelegate() { @Override public void didSelectDialog(DialogsActivity fragment, long did, boolean param) { Bundle args = new Bundle(); args.putBoolean("scrollToTopOnResume", true); args.putInt("chat_id", -(int) did); if (!MessagesController.checkCanOpenChat(args, fragment)) { return; } NotificationCenter.getInstance().removeObserver(ProfileActivity.this, NotificationCenter.closeChats); NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats); MessagesController.getInstance().addUserToChat(-(int) did, user, null, 0, null, ProfileActivity.this); presentFragment(new ChatActivity(args), true); removeSelfFromStack(); } }); presentFragment(fragment); } else if (id == share) { try { TLRPC.User user = MessagesController.getInstance().getUser(user_id); if (user == null) { return; } Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); String about = MessagesController.getInstance().getUserAbout(botInfo.user_id); if (botInfo != null && about != null) { intent.putExtra(Intent.EXTRA_TEXT, String.format("%s https://telegram.me/%s", about, user.username)); } else { intent.putExtra(Intent.EXTRA_TEXT, String.format("https://telegram.me/%s", user.username)); } startActivityForResult(Intent.createChooser(intent, LocaleController.getString("BotShare", R.string.BotShare)), 500); } catch (Exception e) { FileLog.e("tmessages", e); } } else if (id == set_admins) { Bundle args = new Bundle(); args.putInt("chat_id", chat_id); SetAdminsActivity fragment = new SetAdminsActivity(args); fragment.setChatInfo(info); presentFragment(fragment); } else if (id == convert_to_supergroup) { Bundle args = new Bundle(); args.putInt("chat_id", chat_id); presentFragment(new ConvertGroupActivity(args)); } else if (id == add_shortcut) { try { long did; if (currentEncryptedChat != null) { did = ((long) currentEncryptedChat.id) << 32; } else if (user_id != 0) { did = user_id; } else if (chat_id != 0) { did = -chat_id; } else { return; } AndroidUtilities.installShortcut(did); /*try { Toast.makeText(getParentActivity(), LocaleController.getString("ShortcutAdded", R.string.ShortcutAdded), Toast.LENGTH_SHORT).show(); } catch (Exception e) { FileLog.e("tmessages", e); }*/ } catch (Exception e) { FileLog.e("tmessages", e); } } } }); createActionBarMenu(); listAdapter = new ListAdapter(context); avatarDrawable = new AvatarDrawable(); avatarDrawable.setProfile(true); fragmentView = new FrameLayout(context) { @Override public boolean hasOverlappingRendering() { return false; } @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); checkListViewScroll(); } }; FrameLayout frameLayout = (FrameLayout) fragmentView; listView = new RecyclerListView(context) { @Override public boolean hasOverlappingRendering() { return false; } }; listView.setTag(6); listView.setPadding(0, AndroidUtilities.dp(88), 0, 0); listView.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background)); listView.setVerticalScrollBarEnabled(false); listView.setItemAnimator(null); listView.setLayoutAnimation(null); listView.setClipToPadding(false); layoutManager = new LinearLayoutManager(context) { @Override public boolean supportsPredictiveItemAnimations() { return false; } }; layoutManager.setOrientation(LinearLayoutManager.VERTICAL); listView.setLayoutManager(layoutManager); listView.setGlowColor(AvatarDrawable.getProfileBackColorForId( user_id != 0 || ChatObject.isChannel(chat_id) && !currentChat.megagroup ? 5 : chat_id)); frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT)); listView.setAdapter(listAdapter); listView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() { @Override public void onItemClick(View view, final int position) { if (getParentActivity() == null) { return; } if (position == sharedMediaRow) { Bundle args = new Bundle(); if (user_id != 0) { args.putLong("dialog_id", dialog_id != 0 ? dialog_id : user_id); } else { args.putLong("dialog_id", -chat_id); } MediaActivity fragment = new MediaActivity(args); fragment.setChatInfo(info); presentFragment(fragment); } else if (position == settingsKeyRow) { Bundle args = new Bundle(); args.putInt("chat_id", (int) (dialog_id >> 32)); presentFragment(new IdenticonActivity(args)); } else if (position == settingsTimerRow) { showDialog(AndroidUtilities.buildTTLAlert(getParentActivity(), currentEncryptedChat).create()); } else if (position == settingsNotificationsRow) { Bundle args = new Bundle(); if (user_id != 0) { args.putLong("dialog_id", dialog_id == 0 ? user_id : dialog_id); } else if (chat_id != 0) { args.putLong("dialog_id", -chat_id); } presentFragment(new ProfileNotificationsActivity(args)); } else if (position == startSecretChatRow) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage( LocaleController.getString("AreYouSureSecretChat", R.string.AreYouSureSecretChat)); 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; SecretChatHelper.getInstance().startSecretChat(getParentActivity(), MessagesController.getInstance().getUser(user_id)); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } else if (position > emptyRowChat2 && position < membersEndRow) { int user_id; if (!sortedUsers.isEmpty()) { user_id = info.participants.participants .get(sortedUsers.get(position - emptyRowChat2 - 1)).user_id; } else { user_id = info.participants.participants.get(position - emptyRowChat2 - 1).user_id; } if (user_id == UserConfig.getClientUserId()) { return; } Bundle args = new Bundle(); args.putInt("user_id", user_id); presentFragment(new ProfileActivity(args)); } else if (position == addMemberRow) { openAddMember(); } else if (position == channelNameRow) { try { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); if (info.about != null && info.about.length() > 0) { intent.putExtra(Intent.EXTRA_TEXT, currentChat.title + "\n" + info.about + "\nhttps://telegram.me/" + currentChat.username); } else { intent.putExtra(Intent.EXTRA_TEXT, currentChat.title + "\nhttps://telegram.me/" + currentChat.username); } getParentActivity().startActivityForResult(Intent.createChooser(intent, LocaleController.getString("BotShare", R.string.BotShare)), 500); } catch (Exception e) { FileLog.e("tmessages", e); } } else if (position == leaveChannelRow) { leaveChatPressed(); } else if (position == membersRow || position == blockedUsersRow || position == managementRow) { Bundle args = new Bundle(); args.putInt("chat_id", chat_id); if (position == blockedUsersRow) { args.putInt("type", 0); } else if (position == managementRow) { args.putInt("type", 1); } else if (position == membersRow) { args.putInt("type", 2); } presentFragment(new ChannelUsersActivity(args)); } else if (position == convertRow) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("ConvertGroupAlert", R.string.ConvertGroupAlert)); builder.setTitle(LocaleController.getString("ConvertGroupAlertWarning", R.string.ConvertGroupAlertWarning)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { MessagesController.getInstance().convertToMegaGroup(getParentActivity(), chat_id); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } else { processOnClickOrPress(position); } } }); listView.setOnItemLongClickListener(new RecyclerListView.OnItemLongClickListener() { @Override public boolean onItemClick(View view, int position) { if (position > emptyRowChat2 && position < membersEndRow) { if (getParentActivity() == null) { return false; } boolean allowKick = false; boolean allowSetAdmin = false; final TLRPC.ChatParticipant user; if (!sortedUsers.isEmpty()) { user = info.participants.participants.get(sortedUsers.get(position - emptyRowChat2 - 1)); } else { user = info.participants.participants.get(position - emptyRowChat2 - 1); } selectedUser = user.user_id; if (ChatObject.isChannel(currentChat)) { TLRPC.ChannelParticipant channelParticipant = ((TLRPC.TL_chatChannelParticipant) user).channelParticipant; if (user.user_id != UserConfig.getClientUserId()) { if (currentChat.creator) { allowKick = true; } else if (channelParticipant instanceof TLRPC.TL_channelParticipant) { if (currentChat.editor || channelParticipant.inviter_id == UserConfig.getClientUserId()) { allowKick = true; } } } TLRPC.User u = MessagesController.getInstance().getUser(user.user_id); allowSetAdmin = channelParticipant instanceof TLRPC.TL_channelParticipant && !u.bot; } else { if (user.user_id != UserConfig.getClientUserId()) { if (currentChat.creator) { allowKick = true; } else if (user instanceof TLRPC.TL_chatParticipant) { if (currentChat.admin && currentChat.admins_enabled || user.inviter_id == UserConfig.getClientUserId()) { allowKick = true; } } } } if (!allowKick) { return false; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); if (currentChat.megagroup && currentChat.creator && allowSetAdmin) { CharSequence[] items = new CharSequence[] { LocaleController.getString("SetAsAdmin", R.string.SetAsAdmin), LocaleController.getString("KickFromGroup", R.string.KickFromGroup) }; builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if (i == 0) { TLRPC.TL_chatChannelParticipant channelParticipant = ((TLRPC.TL_chatChannelParticipant) user); channelParticipant.channelParticipant = new TLRPC.TL_channelParticipantEditor(); channelParticipant.channelParticipant.inviter_id = UserConfig.getClientUserId(); channelParticipant.channelParticipant.user_id = user.user_id; channelParticipant.channelParticipant.date = user.date; TLRPC.TL_channels_editAdmin req = new TLRPC.TL_channels_editAdmin(); req.channel = MessagesController.getInputChannel(chat_id); req.user_id = MessagesController.getInputUser(selectedUser); req.role = new TLRPC.TL_channelRoleEditor(); ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() { @Override public void run(TLObject response, final TLRPC.TL_error error) { if (error == null) { MessagesController.getInstance() .processUpdates((TLRPC.Updates) response, false); AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { MessagesController.getInstance().loadFullChat(chat_id, 0, true); } }, 1000); } else { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { AlertsCreator.showAddUserAlert(error.text, ProfileActivity.this, false); } }); } } }); } else if (i == 1) { kickUser(selectedUser); } } }); } else { CharSequence[] items = new CharSequence[] { chat_id > 0 ? LocaleController.getString("KickFromGroup", R.string.KickFromGroup) : LocaleController.getString("KickFromBroadcast", R.string.KickFromBroadcast) }; builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if (i == 0) { kickUser(selectedUser); } } }); } showDialog(builder.create()); return true; } else { return processOnClickOrPress(position); } } }); topView = new TopView(context); topView.setBackgroundColor(AvatarDrawable.getProfileBackColorForId( user_id != 0 || ChatObject.isChannel(chat_id) && !currentChat.megagroup ? 5 : chat_id)); frameLayout.addView(topView); frameLayout.addView(actionBar); avatarImage = new BackupImageView(context); avatarImage.setRoundRadius(AndroidUtilities.dp(21)); avatarImage.setPivotX(0); avatarImage.setPivotY(0); frameLayout.addView(avatarImage, LayoutHelper.createFrame(42, 42, Gravity.TOP | Gravity.LEFT, 64, 0, 0, 0)); avatarImage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (user_id != 0) { TLRPC.User user = MessagesController.getInstance().getUser(user_id); if (user.photo != null && user.photo.photo_big != null) { PhotoViewer.getInstance().setParentActivity(getParentActivity()); PhotoViewer.getInstance().openPhoto(user.photo.photo_big, ProfileActivity.this); } } else if (chat_id != 0) { TLRPC.Chat chat = MessagesController.getInstance().getChat(chat_id); if (chat.photo != null && chat.photo.photo_big != null) { PhotoViewer.getInstance().setParentActivity(getParentActivity()); PhotoViewer.getInstance().openPhoto(chat.photo.photo_big, ProfileActivity.this); } } } }); for (int a = 0; a < 2; a++) { if (!playProfileAnimation && a == 0) { continue; } nameTextView[a] = new AutoMarqueeTextView(context); nameTextView[a].setTextColor(0xffffffff); nameTextView[a].setTextSize(18); nameTextView[a].setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL); nameTextView[a].setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); nameTextView[a].setCompoundDrawablePadding(-AndroidUtilities.dp(1.3f)); nameTextView[a].setMaxLines(1); /*nameTextView[a].setLeftDrawableTopPadding(-AndroidUtilities.dp(1.3f)); nameTextView[a].setRightDrawableTopPadding(-AndroidUtilities.dp(1.3f));*/ nameTextView[a].setPivotX(0); nameTextView[a].setPivotY(0); frameLayout.addView(nameTextView[a], LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 118, 0, a == 0 ? 48 : 0, 0)); onlineTextView[a] = new SimpleTextView(context); onlineTextView[a].setTextColor(AvatarDrawable.getProfileTextColorForId( user_id != 0 || ChatObject.isChannel(chat_id) && !currentChat.megagroup ? 5 : chat_id)); onlineTextView[a].setTextSize(14); onlineTextView[a].setGravity(Gravity.LEFT); frameLayout.addView(onlineTextView[a], LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 118, 0, a == 0 ? 48 : 8, 0)); } if (user_id != 0 || chat_id >= 0 && !ChatObject.isLeftFromChat(currentChat)) { writeButton = new ImageView(context); try { writeButton.setBackgroundResource(R.drawable.floating_user_states); } catch (Throwable e) { FileLog.e("tmessages", e); } writeButton.setScaleType(ImageView.ScaleType.CENTER); if (user_id != 0) { writeButton.setImageResource(R.drawable.floating_message); writeButton.setPadding(0, AndroidUtilities.dp(3), 0, 0); } else if (chat_id != 0) { boolean isChannel = ChatObject.isChannel(currentChat); if (isChannel && !currentChat.creator && (!currentChat.megagroup || !currentChat.editor) || !isChannel && !currentChat.admin && !currentChat.creator && currentChat.admins_enabled) { writeButton.setImageResource(R.drawable.floating_message); writeButton.setPadding(0, AndroidUtilities.dp(3), 0, 0); } else { writeButton.setImageResource(R.drawable.floating_camera); } } frameLayout.addView(writeButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.RIGHT | Gravity.TOP, 0, 0, 16, 0)); if (Build.VERSION.SDK_INT >= 21) { StateListAnimator animator = new StateListAnimator(); animator.addState(new int[] { android.R.attr.state_pressed }, ObjectAnimator .ofFloat(writeButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4)) .setDuration(200)); animator.addState(new int[] {}, ObjectAnimator .ofFloat(writeButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2)) .setDuration(200)); writeButton.setStateListAnimator(animator); writeButton.setOutlineProvider(new ViewOutlineProvider() { @SuppressLint("NewApi") @Override public void getOutline(View view, Outline outline) { outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56)); } }); } writeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (getParentActivity() == null) { return; } if (user_id != 0) { if (playProfileAnimation && parentLayout.fragmentsStack .get(parentLayout.fragmentsStack.size() - 2) instanceof ChatActivity) { finishFragment(); } else { TLRPC.User user = MessagesController.getInstance().getUser(user_id); if (user == null || user instanceof TLRPC.TL_userEmpty) { return; } Bundle args = new Bundle(); args.putInt("user_id", user_id); if (!MessagesController.checkCanOpenChat(args, ProfileActivity.this)) { return; } NotificationCenter.getInstance().removeObserver(ProfileActivity.this, NotificationCenter.closeChats); NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats); presentFragment(new ChatActivity(args), true); } } else if (chat_id != 0) { boolean isChannel = ChatObject.isChannel(currentChat); if (isChannel && !currentChat.creator && (!currentChat.megagroup || !currentChat.editor) || !isChannel && !currentChat.admin && !currentChat.creator && currentChat.admins_enabled) { if (playProfileAnimation && parentLayout.fragmentsStack .get(parentLayout.fragmentsStack.size() - 2) instanceof ChatActivity) { finishFragment(); } else { Bundle args = new Bundle(); args.putInt("chat_id", currentChat.id); if (!MessagesController.checkCanOpenChat(args, ProfileActivity.this)) { return; } NotificationCenter.getInstance().removeObserver(ProfileActivity.this, NotificationCenter.closeChats); NotificationCenter.getInstance() .postNotificationName(NotificationCenter.closeChats); presentFragment(new ChatActivity(args), true); } } else { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); CharSequence[] items; TLRPC.Chat chat = MessagesController.getInstance().getChat(chat_id); if (chat.photo == null || chat.photo.photo_big == null || chat.photo instanceof TLRPC.TL_chatPhotoEmpty) { items = new CharSequence[] { LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley) }; } else { items = new CharSequence[] { LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley), LocaleController.getString("DeletePhoto", R.string.DeletePhoto) }; } 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) { MessagesController.getInstance().changeChatAvatar(chat_id, null); } } }); showDialog(builder.create()); } } } }); } needLayout(); listView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { checkListViewScroll(); if (participantsMap != null && loadMoreMembersRow != -1 && layoutManager.findLastVisibleItemPosition() > loadMoreMembersRow - 8) { getChannelParticipants(false); } } }); return fragmentView; }