List of usage examples for android.widget ImageView ImageView
public ImageView(Context context)
From source file:com.mdlive.sav.MDLiveProviderDetails.java
/** * Successful Response Handler for getting the Affillitations and the provider image. * This method will give the successful response of the Provider's affilitations. * This response is for the Affilations Purpose.The image can be placed one below the other * *///from w w w .j a v a 2 s . co m private void getProviderImageArrayResponse(JsonObject providerdetObj) { JsonArray ProviderImageArray = providerdetObj.get("provider_groups").getAsJsonArray(); if (ProviderImageArray.size() != 0) { providerImageCollectionHolder.removeAllViews(); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 100); params.setMargins(5, 10, 5, 10); for (int i = 0; i < ProviderImageArray.size(); i++) { try { if (!ProviderImageArray.get(i).getAsJsonObject().get("logo").isJsonNull()) { final ImageView imageView = new ImageView(MDLiveProviderDetails.this); //imageView.setScaleType(ImageView.ScaleType.FIT_XY); imageView.setLayoutParams(params); ImageRequest request = new ImageRequest( ProviderImageArray.get(i).getAsJsonObject().get("logo").getAsString(), new Response.Listener<Bitmap>() { @Override public void onResponse(Bitmap bitmap) { imageView.setImageBitmap(bitmap); } }, 0, 0, null, new Response.ErrorListener() { public void onErrorResponse(VolleyError error) { } }); ApplicationController.getInstance().getRequestQueue(this).add(request); imageView.setTag(ProviderImageArray.get(i).getAsJsonObject().get("url").getAsString()); imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MDLiveProviderDetails.this, MDLiveProviderGroupDetailsAffiliations.class); intent.putExtra("affurl", (imageView.getTag() != null) ? imageView.getTag().toString() : ""); startActivity(intent); MdliveUtils.startActivityAnimation(MDLiveProviderDetails.this); } }); providerImageCollectionHolder.addView(imageView); } } catch (Exception e) { e.printStackTrace(); } } } else { if (!isCignaCoachUser) findViewById(R.id.providerGroupAffiliation).setVisibility(View.GONE); } }
From source file:com.android.launcher3.Utilities.java
public static void showEditMode(final Activity activity, final ShortcutInfo shortcutInfo) { ContextThemeWrapper theme;/*from w w w . ja v a2s .com*/ final Set<String> setString = new HashSet<String>(); if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) { theme = new ContextThemeWrapper(activity, R.style.AlertDialogCustomAPI23); } else { theme = new ContextThemeWrapper(activity, R.style.AlertDialogCustom); } AlertDialog.Builder alert = new AlertDialog.Builder(theme); LinearLayout layout = new LinearLayout(activity.getApplicationContext()); layout.setOrientation(LinearLayout.VERTICAL); layout.setPadding(100, 0, 100, 100); final ImageView img = new ImageView(activity.getApplicationContext()); Drawable icon = null; if (Utilities.getAppIconPackageNamePrefEnabled(activity.getApplicationContext()) != null) { if (Utilities.getAppIconPackageNamePrefEnabled(activity.getApplicationContext()).equals("NULL")) { if (Utilities.loadBitmapPref(Launcher.getLauncherActivity(), shortcutInfo.getTargetComponent().getPackageName()) != null) { icon = new BitmapDrawable(activity.getResources(), Utilities.loadBitmapPref(activity, shortcutInfo.getTargetComponent().getPackageName())); } else { icon = new BitmapDrawable(activity.getResources(), shortcutInfo.getIcon(new IconCache(activity.getApplicationContext(), Launcher.getLauncher(activity).getDeviceProfile().inv))); } } else { if (Utilities.loadBitmapPref(Launcher.getLauncherActivity(), shortcutInfo.getTargetComponent().getPackageName()) != null) { icon = new BitmapDrawable(activity.getResources(), Utilities.loadBitmapPref(activity, shortcutInfo.getTargetComponent().getPackageName())); } else { icon = new BitmapDrawable(activity.getResources(), Launcher.getIcons().get(shortcutInfo.getTargetComponent().getPackageName())); } } } else { if (Utilities.loadBitmapPref(Launcher.getLauncherActivity(), shortcutInfo.getTargetComponent().getPackageName()) != null) { icon = new BitmapDrawable(activity.getResources(), Utilities.loadBitmapPref(activity, shortcutInfo.getTargetComponent().getPackageName())); } else { icon = new BitmapDrawable(activity.getResources(), shortcutInfo.getIcon(new IconCache(activity.getApplicationContext(), Launcher.getLauncher(Launcher.getLauncherActivity()).getDeviceProfile().inv))); } } img.setImageDrawable(icon); img.setPadding(0, 100, 0, 0); img.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { showIconPack(activity, shortcutInfo); } }); final EditText titleBox = new EditText(activity.getApplicationContext()); try { Set<String> title = new HashSet<>( Utilities.getTitle(activity, shortcutInfo.getTargetComponent().getPackageName())); for (Iterator<String> it = title.iterator(); it.hasNext();) { String titleApp = it.next(); titleBox.setText(titleApp); } } catch (Exception e) { titleBox.setText(shortcutInfo.title); } titleBox.getBackground().mutate().setColorFilter( ContextCompat.getColor(activity.getApplicationContext(), R.color.colorPrimary), PorterDuff.Mode.SRC_ATOP); layout.addView(img); layout.addView(titleBox); alert.setTitle(activity.getApplicationContext().getResources().getString(R.string.edit_label)); alert.setView(layout); alert.setPositiveButton(activity.getApplicationContext().getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { for (ItemInfo itemInfo : AllAppsList.data) { if (shortcutInfo.getTargetComponent().getPackageName() .equals(itemInfo.getTargetComponent().getPackageName())) { setString.add(titleBox.getText().toString()); getPrefs(activity.getApplicationContext()).edit() .putStringSet(itemInfo.getTargetComponent().getPackageName(), setString) .apply(); Launcher.getShortcutsCreation().clearAllLayout(); applyChange(activity); } } } }); alert.setNegativeButton(activity.getApplicationContext().getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Launcher.getShortcutsCreation().clearAllLayout(); } }); alert.show(); }
From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java
private void addNextTransitionImages(int level) { mTransitionImagesCount = 0;// w ww. jav a2s.c o m if ((level > 0) && ((level - 1) < EXIT_TRANSITIONS.length)) { if (EXIT_TRANSITIONS[level - 1] != -1) { // Add the exit transition image ImageView iv = new ImageView(this); iv.setTag(new Pair<Integer, Integer>(1, (level - 1))); // This is being background loaded. Should already be loaded, but if not, wait. while (mExitTransitions[level - 1] == null) { synchronized (mExitTransitions) { if (mExitTransitions[level - 1] == null) { try { mExitTransitions.wait(); } catch (InterruptedException e) { continue; } } } } iv.setImageBitmap(mExitTransitions[level - 1]); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); mBackgroundLayout.addView(iv, lp); // No foreground on transistions. Transition images are a single screen long View view = new View(this); lp = new LinearLayout.LayoutParams(mScreenWidth, 10); mForegroundLayout.addView(view, lp); mTransitionImagesCount++; } } if ((level > 0) && (level < ENTRY_TRANSITIONS.length)) { if (ENTRY_TRANSITIONS[level] != -1) { // Add the exit transition image ImageView iv = new ImageView(this); iv.setTag(new Pair<Integer, Integer>(2, level)); // This is being background loaded. Should already be loaded, but if not, wait. while (mEntryTransitions[level] == null) { synchronized (mEntryTransitions) { if (mEntryTransitions[level] == null) { try { mEntryTransitions.wait(); } catch (InterruptedException e) { continue; } } } } iv.setImageBitmap(mEntryTransitions[level]); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); mBackgroundLayout.addView(iv, lp); // No foreground on transistions. Transition images are a single screen long View view = new View(this); lp = new LinearLayout.LayoutParams(mScreenWidth, 10); mForegroundLayout.addView(view, lp); mTransitionImagesCount++; } } }
From source file:com.amaze.carbonfilemanager.activities.MainActivity.java
public void bbar(final MainFragment mainFrag) { final String path = mainFrag.CURRENT_PATH; try {//from www . java 2 s . c o m buttons.removeAllViews(); buttons.setMinimumHeight(pathbar.getHeight()); Drawable arrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_holo_dark); Bundle bundle = utils.getPaths(path, this); ArrayList<String> names = bundle.getStringArrayList("names"); ArrayList<String> rnames = bundle.getStringArrayList("names"); Collections.reverse(rnames); ArrayList<String> paths = bundle.getStringArrayList("paths"); final ArrayList<String> rpaths = bundle.getStringArrayList("paths"); Collections.reverse(rpaths); View view = new View(this); LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(toolbar.getContentInsetLeft(), LinearLayout.LayoutParams.WRAP_CONTENT); view.setLayoutParams(params1); buttons.addView(view); for (int i = 0; i < names.size(); i++) { final int k = i; ImageView v = new ImageView(this); v.setImageDrawable(arrow); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); params.gravity = Gravity.CENTER_VERTICAL; v.setLayoutParams(params); final int index = i; if (rpaths.get(i).equals("/")) { ImageButton ib = new ImageButton(this); ib.setImageDrawable(icons.getRootDrawable()); ib.setBackgroundColor(Color.TRANSPARENT); ib.setOnClickListener(new View.OnClickListener() { public void onClick(View p1) { mainFrag.loadlist(("/"), false, mainFrag.openMode); timer.cancel(); timer.start(); } }); ib.setLayoutParams(params); buttons.addView(ib); if (names.size() - i != 1) buttons.addView(v); } else if (isStorage(rpaths.get(i))) { ImageButton ib = new ImageButton(this); ib.setImageDrawable(icons.getSdDrawable()); ib.setBackgroundColor(Color.TRANSPARENT); ib.setOnClickListener(new View.OnClickListener() { public void onClick(View p1) { mainFrag.loadlist((rpaths.get(k)), false, mainFrag.openMode); timer.cancel(); timer.start(); } }); ib.setLayoutParams(params); buttons.addView(ib); if (names.size() - i != 1) buttons.addView(v); } else { Button b = new Button(this); b.setText(rnames.get(index)); b.setTextColor(Utils.getColor(this, android.R.color.white)); b.setTextSize(13); b.setLayoutParams(params); b.setBackgroundResource(0); b.setOnClickListener(new Button.OnClickListener() { public void onClick(View p1) { mainFrag.loadlist((rpaths.get(k)), false, mainFrag.openMode); mainFrag.loadlist((rpaths.get(k)), false, mainFrag.openMode); timer.cancel(); timer.start(); } }); b.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { File file1 = new File(rpaths.get(index)); copyToClipboard(MainActivity.this, file1.getPath()); Toast.makeText(MainActivity.this, getResources().getString(R.string.pathcopied), Toast.LENGTH_SHORT).show(); return false; } }); buttons.addView(b); if (names.size() - i != 1) buttons.addView(v); } } scroll.post(new Runnable() { @Override public void run() { sendScroll(scroll); sendScroll(scroll1); } }); if (buttons.getVisibility() == View.VISIBLE) { timer.cancel(); timer.start(); } } catch (Exception e) { e.printStackTrace(); Log.d("BBar", "button view not available"); } }
From source file:com.android.launcher2.Launcher.java
/** * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView * in the DragLayer in the exact absolute location of the original FolderIcon. *//*from w ww. ja va2s . co m*/ private void copyFolderIconToImage(FolderIcon fi) { final int width = fi.getMeasuredWidth(); final int height = fi.getMeasuredHeight(); // Lazy load ImageView, Bitmap and Canvas if (mFolderIconImageView == null) { mFolderIconImageView = new ImageView(this); } if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width || mFolderIconBitmap.getHeight() != height) { mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); mFolderIconCanvas = new Canvas(mFolderIconBitmap); } DragLayer.LayoutParams lp; if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) { lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams(); } else { lp = new DragLayer.LayoutParams(width, height); } // The layout from which the folder is being opened may be scaled, adjust the starting // view size by this scale factor. float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation); lp.customPosition = true; lp.x = mRectForFolderAnimation.left; lp.y = mRectForFolderAnimation.top; lp.width = (int) (scale * width); lp.height = (int) (scale * height); mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR); fi.draw(mFolderIconCanvas); mFolderIconImageView.setImageBitmap(mFolderIconBitmap); if (fi.getFolder() != null) { mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation()); mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation()); } // Just in case this image view is still in the drag layer from a previous animation, // we remove it and re-add it. if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) { mDragLayer.removeView(mFolderIconImageView); } mDragLayer.addView(mFolderIconImageView, lp); if (fi.getFolder() != null) { fi.getFolder().bringToFront(); } }
From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java
private void addFinalImages() { addNextImages(1);//w w w . j a va 2 s . co m addNextImages(1); // Add presents addFinalPresentRun(); // Add final screen. This is a two screen background. ImageView iv = new ImageView(this); iv.setTag(true); Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.bg_finish); if ((mScaleX != 1.0f) || (mScaleY != 1.0f)) { Bitmap tmp = Bitmap.createScaledBitmap(bmp, mScreenWidth * 2, mScreenHeight, false); if (bmp != tmp) { bmp.recycle(); } bmp = tmp; } iv.setImageBitmap(bmp); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); mBackgroundLayout.addView(iv, lp); View view = new View(this); lp = new LinearLayout.LayoutParams(mScreenWidth * 2, 10); mForegroundLayout.addView(view, lp); addNextObstacleSpacer(2); }
From source file:com.lifehackinnovations.siteaudit.FloorPlanActivity.java
public void turnonscaling() { view.setOnTouchListener(new OnTouchListener() { @Override/*from w w w . j av a 2 s . co m*/ public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub for (int w = 0; w < view.maxitems; w++) { try { rl.removeView(itemimageview[w]); } catch (NullPointerException e) { } } for (int w = 0; w < view.i; w++) { int x = (int) view.SCALEDITEMx[w], y = (int) view.SCALEDITEMy[w]; float dx = (float) ((float) view.ITEMbitmap[w].getWidth() / (float) 2.0); float dy = (float) ((float) view.ITEMbitmap[w].getHeight() / (float) 2.0); x = x - (int) dx; y = y - (int) dy; if (ICONBOUNDING) { itemimageview[w] = new ImageView(FloorPlanActivity.this); itemimageview[w].setImageBitmap(view.ITEMbitmap[w]); Log.d("x and y", x + " " + y); LayoutParams mparam = new LayoutParams((int) (LayoutParams.WRAP_CONTENT), (int) (LayoutParams.WRAP_CONTENT)); Log.d("itemimageview, wdith, height", view.ITEMbitmap[w].getWidth() + " " + view.ITEMbitmap[w].getHeight() + " " + (float) view.ITEMbitmap[w].getWidth() / (float) 2.0); Log.d("dx, and dy", dx + " " + dy); Log.d("x, and y", x + " " + y); itemimageview[w].setMinimumHeight(view.ITEMbitmap[w].getHeight()); itemimageview[w].setMinimumWidth(view.ITEMbitmap[w].getWidth()); itemimageview[w].setLayoutParams(mparam); itemimageview[w].setPadding(x, y, 0, 0); rl.addView(itemimageview[w]); } else if (x > 0 && x < view.scrnwidth - 2 * dx && y > 0 && y < view.scrnheight - 2 * dy) { itemimageview[w] = new ImageView(FloorPlanActivity.this); itemimageview[w].setImageBitmap(view.ITEMbitmap[w]); Log.d("x and y", x + " " + y); LayoutParams mparam = new LayoutParams((int) (LayoutParams.WRAP_CONTENT), (int) (LayoutParams.WRAP_CONTENT)); Log.d("itemimageview, wdith, height", view.ITEMbitmap[w].getWidth() + " " + view.ITEMbitmap[w].getHeight() + " " + (float) view.ITEMbitmap[w].getWidth() / (float) 2.0); Log.d("dx, and dy", dx + " " + dy); Log.d("x, and y", x + " " + y); itemimageview[w].setMinimumHeight(view.ITEMbitmap[w].getHeight()); itemimageview[w].setMinimumWidth(view.ITEMbitmap[w].getWidth()); itemimageview[w].setLayoutParams(mparam); itemimageview[w].setPadding(x, y, 0, 0); rl.addView(itemimageview[w]); } Log.d("w", u.s(w)); } return false; } }); ICONSCALING = true; view.invalidate(); }
From source file:kr.wdream.ui.DialogsActivity.java
private void createSettingLayout() { PxToDp pxToDp = new PxToDp(context); // ? ?/*from www . j a v a 2 s .co m*/ LinearLayout lytLine1 = new LinearLayout(context); LinearLayout lytLine2 = new LinearLayout(context); LinearLayout lytLine3 = new LinearLayout(context); LinearLayout lytLine4 = new LinearLayout(context); LinearLayout lytLine5 = new LinearLayout(context); LinearLayout lytLine6 = new LinearLayout(context); LinearLayout lytLine7 = new LinearLayout(context); LinearLayout.LayoutParams paramLine = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, pxToDp.dpToPx(1)); paramLine.setMargins(pxToDp.dpToPx(36), 0, 0, 0); lytLine1.setLayoutParams(paramLine); lytLine2.setLayoutParams(paramLine); lytLine3.setLayoutParams(paramLine); lytLine4.setLayoutParams(paramLine); lytLine1.setBackgroundColor(Color.parseColor("#E5E5E5")); lytLine2.setBackgroundColor(Color.parseColor("#E5E5E5")); lytLine3.setBackgroundColor(Color.parseColor("#E5E5E5")); lytLine4.setBackgroundColor(Color.parseColor("#E5E5E5")); lytLine5.setBackgroundColor(Color.parseColor("#E5E5E5")); lytLine6.setBackgroundColor(Color.parseColor("#E5E5E5")); lytLine7.setBackgroundColor(Color.parseColor("#E5E5E5")); // ? ? LinearLayout lytMySetting = new LinearLayout(context); lytMySetting.setOrientation(LinearLayout.VERTICAL); lytMySetting.setBackgroundColor(Color.WHITE); lytMySetting.setPadding(pxToDp.dpToPx(20), 0, 0, 0); // ? btnMyInfo = new LinearLayout(context); btnMyInfo.setOrientation(LinearLayout.HORIZONTAL); btnMyInfo.setGravity(Gravity.CENTER_VERTICAL); btnMyInfo.setOnClickListener(this); ImageView imgMyInfo = new ImageView(context); imgMyInfo.setImageResource(R.drawable.m_i_setting_myinfo); TextView txtMyInfo = new TextView(context); txtMyInfo.setText(" "); txtMyInfo.setTextColor(Color.parseColor("#404040")); txtMyInfo.setTextSize(16); txtMyInfo.setPadding(pxToDp.dpToPx(23), 0, 0, 0); txtMyInfo.setGravity(Gravity.CENTER_VERTICAL); btnMyInfo.addView(imgMyInfo, LayoutHelper.createLinear(20, 19)); btnMyInfo.addView(txtMyInfo, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); // ? ? btnConnectShop = new LinearLayout(context); btnConnectShop.setOrientation(LinearLayout.HORIZONTAL); btnConnectShop.setGravity(Gravity.CENTER_VERTICAL); btnConnectShop.setOnClickListener(this); ImageView imgConnectShop = new ImageView(context); imgConnectShop.setImageResource(R.drawable.m_i_main_shop); TextView txtConnectShop = new TextView(context); txtConnectShop.setText(" ? "); txtConnectShop.setTextColor(Color.parseColor("#404040")); txtConnectShop.setTextSize(16); txtConnectShop.setPadding(pxToDp.dpToPx(23), 0, 0, 0); txtConnectShop.setGravity(Gravity.CENTER_VERTICAL); btnConnectShop.addView(imgConnectShop, LayoutHelper.createLinear(20, 19)); btnConnectShop.addView(txtConnectShop, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); // ? ? btnNotificationCenter = new LinearLayout(context); btnNotificationCenter.setOrientation(LinearLayout.HORIZONTAL); btnNotificationCenter.setGravity(Gravity.CENTER_VERTICAL); btnNotificationCenter.setOnClickListener(this); ImageView imgNotificationCenter = new ImageView(context); imgNotificationCenter.setImageResource(R.drawable.m_i_setting_alert); TextView txtNotificationCenter = new TextView(context); txtNotificationCenter.setText(" ? "); txtNotificationCenter.setTextColor(Color.parseColor("#404040")); txtNotificationCenter.setTextSize(16); txtNotificationCenter.setPadding(pxToDp.dpToPx(23), 0, 0, 0); txtNotificationCenter.setGravity(Gravity.CENTER_VERTICAL); btnNotificationCenter.addView(imgNotificationCenter, LayoutHelper.createLinear(20, 19)); btnNotificationCenter.addView(txtNotificationCenter, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); // ?? 3 ? lytMySetting.addView(btnMyInfo, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 60)); lytMySetting.addView(lytLine1); lytMySetting.addView(btnConnectShop, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 60)); lytMySetting.addView(lytLine2); lytMySetting.addView(btnNotificationCenter, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 60)); // ? ? ? LinearLayout lytSettingCenter = new LinearLayout(context); lytSettingCenter.setOrientation(LinearLayout.VERTICAL); lytSettingCenter.setBackgroundColor(Color.WHITE); lytSettingCenter.setPadding(pxToDp.dpToPx(20), 0, 0, 0); lytSettingCenter.setGravity(Gravity.CENTER_VERTICAL); // ? ? btnCSCenter = new LinearLayout(context); btnCSCenter.setOrientation(LinearLayout.HORIZONTAL); btnCSCenter.setGravity(Gravity.CENTER_VERTICAL); btnCSCenter.setOnClickListener(this); ImageView imgCSCenter = new ImageView(context); imgCSCenter.setImageResource(R.drawable.m_i_setting_cs); TextView txtCSCenter = new TextView(context); txtCSCenter.setText("?"); txtCSCenter.setTextColor(Color.parseColor("#404040")); txtCSCenter.setTextSize(16); txtCSCenter.setPadding(pxToDp.dpToPx(23), 0, 0, 0); txtCSCenter.setGravity(Gravity.CENTER_VERTICAL); btnCSCenter.addView(imgCSCenter, LayoutHelper.createLinear(20, 19)); btnCSCenter.addView(txtCSCenter, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); // ? btnVersion = new LinearLayout(context); btnVersion.setOrientation(LinearLayout.HORIZONTAL); btnVersion.setGravity(Gravity.CENTER_VERTICAL); btnVersion.setOnClickListener(this); ImageView imgVersion = new ImageView(context); imgVersion.setImageResource(R.drawable.m_i_setting_version); TextView txtVersion = new TextView(context); txtVersion.setText(""); txtVersion.setTextColor(Color.parseColor("#404040")); txtVersion.setTextSize(16); txtVersion.setPadding(pxToDp.dpToPx(23), 0, 0, 0); txtVersion.setGravity(Gravity.CENTER_VERTICAL); TextView txtExposeVersion = new TextView(context); txtExposeVersion.setText(BuildVars.BUILD_VERSION_STRING); txtExposeVersion.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL); txtExposeVersion.setPadding(0, 0, pxToDp.dpToPx(23), 0); txtExposeVersion.setTextSize(13); txtExposeVersion.setTextColor(Color.parseColor("#999999")); btnVersion.addView(imgVersion, LayoutHelper.createLinear(20, 19)); btnVersion.addView(txtVersion, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT)); btnVersion.addView(txtExposeVersion, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); // ? btnDisConnect = new LinearLayout(context); btnDisConnect.setOrientation(LinearLayout.HORIZONTAL); btnDisConnect.setGravity(Gravity.CENTER_VERTICAL); btnDisConnect.setOnClickListener(this); ImageView imgDisConnect = new ImageView(context); imgDisConnect.setImageResource(R.drawable.m_i_main_dis); TextView txtDisConnect = new TextView(context); txtDisConnect.setText(" ? "); txtDisConnect.setTextColor(Color.parseColor("#404040")); txtDisConnect.setTextSize(16); txtDisConnect.setPadding(pxToDp.dpToPx(23), 0, 0, 0); txtDisConnect.setGravity(Gravity.CENTER_VERTICAL); btnDisConnect.addView(imgDisConnect, LayoutHelper.createLinear(20, 19)); btnDisConnect.addView(txtDisConnect, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); // ?? 3 ? lytSettingCenter.addView(btnCSCenter, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 60)); lytSettingCenter.addView(lytLine3); lytSettingCenter.addView(btnVersion, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 60)); lytSettingCenter.addView(lytLine4); lytSettingCenter.addView(btnDisConnect, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 60)); //settingLayout? ? ? ? settingLayout.addView(lytMySetting, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 180)); settingLayout.addView(lytLine5, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 1, 0, 0, 0, 10)); settingLayout.addView(lytLine6, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 1)); settingLayout.addView(lytSettingCenter, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 180)); settingLayout.addView(lytLine7, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 1)); }
From source file:net.bluehack.ui.ChatActivity.java
@Override public View createView(Context context) { if (chatMessageCellsCache.isEmpty()) { for (int a = 0; a < 8; a++) { chatMessageCellsCache.add(new ChatMessageCell(context)); }// w ww.j a v a 2 s . co m } for (int a = 1; a >= 0; a--) { selectedMessagesIds[a].clear(); selectedMessagesCanCopyIds[a].clear(); } cantDeleteMessagesCount = 0; hasOwnBackground = true; if (chatAttachAlert != null) { chatAttachAlert.onDestroy(); chatAttachAlert = null; } Theme.loadRecources(context); Theme.loadChatResources(context); actionBar.setAddToContainer(false); actionBar.setBackButtonDrawable(new BackDrawable(false)); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(final int id) { if (id == -1) { if (actionBar.isActionModeShowed()) { for (int a = 1; a >= 0; a--) { selectedMessagesIds[a].clear(); selectedMessagesCanCopyIds[a].clear(); } cantDeleteMessagesCount = 0; if (chatActivityEnterView.isEditingMessage()) { chatActivityEnterView.setEditingMessageObject(null, false); } else { actionBar.hideActionMode(); updatePinnedMessageView(true); } updateVisibleRows(); } else { finishFragment(); } } else if (id == copy) { String str = ""; int previousUid = 0; for (int a = 1; a >= 0; a--) { ArrayList<Integer> ids = new ArrayList<>(selectedMessagesCanCopyIds[a].keySet()); if (currentEncryptedChat == null) { Collections.sort(ids); } else { Collections.sort(ids, Collections.reverseOrder()); } for (int b = 0; b < ids.size(); b++) { Integer messageId = ids.get(b); MessageObject messageObject = selectedMessagesCanCopyIds[a].get(messageId); if (str.length() != 0) { str += "\n\n"; } str += getMessageContent(messageObject, previousUid, true); previousUid = messageObject.messageOwner.from_id; } } if (str.length() != 0) { AndroidUtilities.addToClipboard(str); } for (int a = 1; a >= 0; a--) { selectedMessagesIds[a].clear(); selectedMessagesCanCopyIds[a].clear(); } cantDeleteMessagesCount = 0; actionBar.hideActionMode(); updatePinnedMessageView(true); updateVisibleRows(); } else if (id == edit_done) { if (chatActivityEnterView != null && (chatActivityEnterView.isEditingCaption() || chatActivityEnterView.hasText())) { chatActivityEnterView.doneEditingMessage(); } } else if (id == delete) { if (getParentActivity() == null) { return; } createDeleteMessagesAlert(null); } else if (id == forward) { Bundle args = new Bundle(); args.putBoolean("onlySelect", true); args.putInt("dialogsType", 1); DialogsActivity fragment = new DialogsActivity(args); fragment.setDelegate(ChatActivity.this); presentFragment(fragment); } else if (id == chat_enc_timer) { if (getParentActivity() == null) { return; } showDialog(AndroidUtilities.buildTTLAlert(getParentActivity(), currentEncryptedChat).create()); } else if (id == clear_history || id == delete_chat) { if (getParentActivity() == null) { return; } final boolean isChat = (int) dialog_id < 0 && (int) (dialog_id >> 32) != 1; AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); if (id == clear_history) { 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 (id != clear_history) { if (isChat) { if (ChatObject.isNotInChat(currentChat)) { MessagesController.getInstance().deleteDialog(dialog_id, 0); } else { MessagesController.getInstance() .deleteUserFromChat( (int) -dialog_id, MessagesController.getInstance() .getUser(UserConfig.getClientUserId()), null); } } else { MessagesController.getInstance().deleteDialog(dialog_id, 0); } finishFragment(); } else { MessagesController.getInstance().deleteDialog(dialog_id, 1); } } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } else if (id == share_contact) { if (currentUser == null || getParentActivity() == null) { return; } if (currentUser.phone != null && currentUser.phone.length() != 0) { Bundle args = new Bundle(); args.putInt("user_id", currentUser.id); args.putBoolean("addContact", true); presentFragment(new ContactAddActivity(args)); } else { shareMyContact(replyingMessageObject); } } else if (id == mute) { toggleMute(false); } else if (id == report) { showDialog(AlertsCreator.createReportAlert(getParentActivity(), dialog_id, ChatActivity.this)); } else if (id == reply) { MessageObject messageObject = null; for (int a = 1; a >= 0; a--) { if (messageObject == null && selectedMessagesIds[a].size() == 1) { ArrayList<Integer> ids = new ArrayList<>(selectedMessagesIds[a].keySet()); messageObject = messagesDict[a].get(ids.get(0)); } selectedMessagesIds[a].clear(); selectedMessagesCanCopyIds[a].clear(); } if (messageObject != null && (messageObject.messageOwner.id > 0 || messageObject.messageOwner.id < 0 && currentEncryptedChat != null)) { showReplyPanel(true, messageObject, null, null, false, true); } cantDeleteMessagesCount = 0; actionBar.hideActionMode(); updatePinnedMessageView(true); updateVisibleRows(); } else if (id == chat_menu_attach) { if (getParentActivity() == null) { return; } createChatAttachView(); chatAttachAlert.loadGalleryPhotos(); if (Build.VERSION.SDK_INT == 21 || Build.VERSION.SDK_INT == 22) { chatActivityEnterView.closeKeyboard(); } chatAttachAlert.init(); showDialog(chatAttachAlert); } else if (id == bot_help) { SendMessagesHelper.getInstance().sendMessage("/help", dialog_id, null, null, false, null, null, null); } else if (id == bot_settings) { SendMessagesHelper.getInstance().sendMessage("/settings", dialog_id, null, null, false, null, null, null); } else if (id == search) { openSearchWithText(null); } } }); avatarContainer = new ChatAvatarContainer(context, this, currentEncryptedChat != null); actionBar.addView(avatarContainer, 0, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 56, 0, 40, 0)); if (currentChat != null) { if (!ChatObject.isChannel(currentChat)) { int count = currentChat.participants_count; if (info != null) { count = info.participants.participants.size(); } if (count == 0 || currentChat.deactivated || currentChat.left || currentChat instanceof TLRPC.TL_chatForbidden || info != null && info.participants instanceof TLRPC.TL_chatParticipantsForbidden) { avatarContainer.setEnabled(false); } } } ActionBarMenu menu = actionBar.createMenu(); if (currentEncryptedChat == null && !isBroadcast) { searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true) .setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() { @Override public void onSearchCollapse() { avatarContainer.setVisibility(View.VISIBLE); if (chatActivityEnterView.hasText()) { if (headerItem != null) { headerItem.setVisibility(View.GONE); } if (attachItem != null) { attachItem.setVisibility(View.VISIBLE); } } else { if (headerItem != null) { headerItem.setVisibility(View.VISIBLE); } if (attachItem != null) { attachItem.setVisibility(View.GONE); } } searchItem.setVisibility(View.GONE); highlightMessageId = Integer.MAX_VALUE; updateVisibleRows(); scrollToLastMessage(false); updateBottomOverlay(); } @Override public void onSearchExpand() { if (!openSearchKeyboard) { return; } AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { searchItem.getSearchField().requestFocus(); AndroidUtilities.showKeyboard(searchItem.getSearchField()); } }, 300); } @Override public void onSearchPressed(EditText editText) { updateSearchButtons(0, 0, 0); MessagesSearchQuery.searchMessagesInChat(editText.getText().toString(), dialog_id, mergeDialogId, classGuid, 0); } }); searchItem.getSearchField().setHint(LocaleController.getString("Search", R.string.Search)); searchItem.setVisibility(View.GONE); } headerItem = menu.addItem(0, R.drawable.ic_ab_other); if (searchItem != null) { headerItem.addSubItem(search, LocaleController.getString("Search", R.string.Search), 0); } if (ChatObject.isChannel(currentChat) && !currentChat.creator && (!currentChat.megagroup || currentChat.username != null && currentChat.username.length() > 0)) { headerItem.addSubItem(report, LocaleController.getString("ReportChat", R.string.ReportChat), 0); } if (currentUser != null) { addContactItem = headerItem.addSubItem(share_contact, "", 0); } if (currentEncryptedChat != null) { timeItem2 = headerItem.addSubItem(chat_enc_timer, LocaleController.getString("SetTimer", R.string.SetTimer), 0); } if (!ChatObject.isChannel(currentChat)) { headerItem.addSubItem(clear_history, LocaleController.getString("ClearHistory", R.string.ClearHistory), 0); if (currentChat != null && !isBroadcast) { headerItem.addSubItem(delete_chat, LocaleController.getString("DeleteAndExit", R.string.DeleteAndExit), 0); } else { headerItem.addSubItem(delete_chat, LocaleController.getString("DeleteChatUser", R.string.DeleteChatUser), 0); } } if (currentUser == null || !currentUser.self) { muteItem = headerItem.addSubItem(mute, null, 0); } if (currentUser != null && currentEncryptedChat == null && currentUser.bot) { headerItem.addSubItem(bot_settings, LocaleController.getString("BotSettings", R.string.BotSettings), 0); headerItem.addSubItem(bot_help, LocaleController.getString("BotHelp", R.string.BotHelp), 0); updateBotButtons(); } updateTitle(); avatarContainer.updateOnlineCount(); avatarContainer.updateSubtitle(); updateTitleIcons(); attachItem = menu.addItem(chat_menu_attach, R.drawable.ic_ab_other).setOverrideMenuClick(true) .setAllowCloseAnimation(false); attachItem.setVisibility(View.GONE); menuItem = menu.addItem(chat_menu_attach, R.drawable.ic_ab_attach).setAllowCloseAnimation(false); menuItem.setBackgroundDrawable(null); actionModeViews.clear(); final ActionBarMenu actionMode = actionBar.createActionMode(); selectedMessagesCountTextView = new NumberTextView(actionMode.getContext()); selectedMessagesCountTextView.setTextSize(18); selectedMessagesCountTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); selectedMessagesCountTextView.setTextColor(Theme.ACTION_BAR_ACTION_MODE_TEXT_COLOR); actionMode.addView(selectedMessagesCountTextView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f, 65, 0, 0, 0)); selectedMessagesCountTextView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); actionModeTitleContainer = new FrameLayout(context) { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int width = MeasureSpec.getSize(widthMeasureSpec); int height = MeasureSpec.getSize(heightMeasureSpec); setMeasuredDimension(width, height); actionModeTextView.setTextSize(!AndroidUtilities.isTablet() && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? 18 : 20); actionModeTextView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(24), MeasureSpec.AT_MOST)); if (actionModeSubTextView.getVisibility() != GONE) { actionModeSubTextView.setTextSize(!AndroidUtilities.isTablet() && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? 14 : 16); actionModeSubTextView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(20), MeasureSpec.AT_MOST)); } } @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { int height = bottom - top; int textTop; if (actionModeSubTextView.getVisibility() != GONE) { textTop = (height / 2 - actionModeTextView.getTextHeight()) / 2 + AndroidUtilities.dp(!AndroidUtilities.isTablet() && getResources() .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? 2 : 3); } else { textTop = (height - actionModeTextView.getTextHeight()) / 2; } actionModeTextView.layout(0, textTop, actionModeTextView.getMeasuredWidth(), textTop + actionModeTextView.getTextHeight()); if (actionModeSubTextView.getVisibility() != GONE) { textTop = height / 2 + (height / 2 - actionModeSubTextView.getTextHeight()) / 2 - AndroidUtilities.dp(!AndroidUtilities.isTablet() && getResources() .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? 1 : 1); actionModeSubTextView.layout(0, textTop, actionModeSubTextView.getMeasuredWidth(), textTop + actionModeSubTextView.getTextHeight()); } } }; actionMode.addView(actionModeTitleContainer, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f, 65, 0, 0, 0)); actionModeTitleContainer.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); actionModeTitleContainer.setVisibility(View.GONE); actionModeTextView = new SimpleTextView(context); actionModeTextView.setTextSize(18); actionModeTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); actionModeTextView.setTextColor(Theme.ACTION_BAR_ACTION_MODE_TEXT_COLOR); actionModeTextView.setText(LocaleController.getString("Edit", R.string.Edit)); actionModeTitleContainer.addView(actionModeTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); actionModeSubTextView = new SimpleTextView(context); actionModeSubTextView.setGravity(Gravity.LEFT); actionModeSubTextView.setTextColor(Theme.ACTION_BAR_ACTION_MODE_TEXT_COLOR); actionModeTitleContainer.addView(actionModeSubTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); if (currentEncryptedChat == null) { if (!isBroadcast) { actionModeViews.add(actionMode.addItem(reply, R.drawable.ic_ab_reply, Theme.ACTION_BAR_MODE_SELECTOR_COLOR, null, AndroidUtilities.dp(54))); } actionModeViews.add(actionMode.addItem(copy, R.drawable.ic_ab_fwd_copy, Theme.ACTION_BAR_MODE_SELECTOR_COLOR, null, AndroidUtilities.dp(54))); actionModeViews.add(actionMode.addItem(forward, R.drawable.ic_ab_fwd_forward, Theme.ACTION_BAR_MODE_SELECTOR_COLOR, null, AndroidUtilities.dp(54))); actionModeViews.add(actionMode.addItem(delete, R.drawable.ic_ab_fwd_delete, Theme.ACTION_BAR_MODE_SELECTOR_COLOR, null, AndroidUtilities.dp(54))); actionModeViews.add(editDoneItem = actionMode.addItem(edit_done, R.drawable.check_blue, Theme.ACTION_BAR_MODE_SELECTOR_COLOR, null, AndroidUtilities.dp(54))); editDoneItem.setVisibility(View.GONE); editDoneItemProgress = new ContextProgressView(context, 0); editDoneItem.addView(editDoneItemProgress, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); editDoneItemProgress.setVisibility(View.INVISIBLE); } else { actionModeViews.add(actionMode.addItem(reply, R.drawable.ic_ab_reply, Theme.ACTION_BAR_MODE_SELECTOR_COLOR, null, AndroidUtilities.dp(54))); actionModeViews.add(actionMode.addItem(copy, R.drawable.ic_ab_fwd_copy, Theme.ACTION_BAR_MODE_SELECTOR_COLOR, null, AndroidUtilities.dp(54))); actionModeViews.add(actionMode.addItem(delete, R.drawable.ic_ab_fwd_delete, Theme.ACTION_BAR_MODE_SELECTOR_COLOR, null, AndroidUtilities.dp(54))); } actionMode.getItem(copy) .setVisibility(selectedMessagesCanCopyIds[0].size() + selectedMessagesCanCopyIds[1].size() != 0 ? View.VISIBLE : View.GONE); actionMode.getItem(delete).setVisibility(cantDeleteMessagesCount == 0 ? View.VISIBLE : View.GONE); checkActionBarMenu(); fragmentView = new SizeNotifierFrameLayout(context) { int inputFieldHeight = 0; @Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { boolean result = super.drawChild(canvas, child, drawingTime); if (child == actionBar) { parentLayout.drawHeaderShadow(canvas, actionBar.getMeasuredHeight()); } return result; } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int widthSize = MeasureSpec.getSize(widthMeasureSpec); int heightSize = MeasureSpec.getSize(heightMeasureSpec); setMeasuredDimension(widthSize, heightSize); heightSize -= getPaddingTop(); measureChildWithMargins(actionBar, widthMeasureSpec, 0, heightMeasureSpec, 0); int actionBarHeight = actionBar.getMeasuredHeight(); heightSize -= actionBarHeight; int keyboardSize = getKeyboardHeight(); if (keyboardSize <= AndroidUtilities.dp(20) && !AndroidUtilities.isInMultiwindow) { heightSize -= chatActivityEnterView.getEmojiPadding(); } int childCount = getChildCount(); measureChildWithMargins(chatActivityEnterView, widthMeasureSpec, 0, heightMeasureSpec, 0); inputFieldHeight = chatActivityEnterView.getMeasuredHeight(); for (int i = 0; i < childCount; i++) { View child = getChildAt(i); if (child == null || child.getVisibility() == GONE || child == chatActivityEnterView || child == actionBar) { continue; } if (child == chatListView || child == progressView) { int contentWidthSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY); int contentHeightSpec = MeasureSpec .makeMeasureSpec( Math.max(AndroidUtilities.dp(10), heightSize - inputFieldHeight + AndroidUtilities.dp( 2 + (chatActivityEnterView.isTopViewVisible() ? 48 : 0))), MeasureSpec.EXACTLY); child.measure(contentWidthSpec, contentHeightSpec); } else if (child == emptyViewContainer) { int contentWidthSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY); int contentHeightSpec = MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY); child.measure(contentWidthSpec, contentHeightSpec); } else if (chatActivityEnterView.isPopupView(child)) { if (AndroidUtilities.isInMultiwindow) { if (AndroidUtilities.isTablet()) { child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(Math.min(AndroidUtilities.dp(320), heightSize - inputFieldHeight + actionBarHeight - AndroidUtilities.statusBarHeight + getPaddingTop()), MeasureSpec.EXACTLY)); } else { child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec( heightSize - inputFieldHeight + actionBarHeight - AndroidUtilities.statusBarHeight + getPaddingTop(), MeasureSpec.EXACTLY)); } } else { child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec .makeMeasureSpec(child.getLayoutParams().height, MeasureSpec.EXACTLY)); } } else if (child == mentionContainer) { FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) mentionContainer .getLayoutParams(); int height; mentionListViewIgnoreLayout = true; if (mentionsAdapter.isBotContext() && mentionsAdapter.isMediaLayout()) { int size = mentionGridLayoutManager.getRowsCount(widthSize); int maxHeight = size * 102; if (mentionsAdapter.isBotContext()) { if (mentionsAdapter.getBotContextSwitch() != null) { maxHeight += 34; } } height = heightSize - chatActivityEnterView.getMeasuredHeight() + (maxHeight != 0 ? AndroidUtilities.dp(2) : 0); mentionListView.setPadding(0, Math.max(0, height - AndroidUtilities.dp(Math.min(maxHeight, 68 * 1.8f))), 0, 0); } else { int size = mentionsAdapter.getItemCount(); int maxHeight = 0; if (mentionsAdapter.isBotContext()) { if (mentionsAdapter.getBotContextSwitch() != null) { maxHeight += 36; size -= 1; } maxHeight += size * 68; } else { maxHeight += size * 36; } height = heightSize - chatActivityEnterView.getMeasuredHeight() + (maxHeight != 0 ? AndroidUtilities.dp(2) : 0); mentionListView.setPadding(0, Math.max(0, height - AndroidUtilities.dp(Math.min(maxHeight, 68 * 1.8f))), 0, 0); } layoutParams.height = height; layoutParams.topMargin = 0; mentionListViewIgnoreLayout = false; child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(layoutParams.height, MeasureSpec.EXACTLY)); } else { measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0); } } } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { final int count = getChildCount(); int paddingBottom = getKeyboardHeight() <= AndroidUtilities.dp(20) && !AndroidUtilities.isInMultiwindow ? chatActivityEnterView.getEmojiPadding() : 0; setBottomClip(paddingBottom); for (int i = 0; i < count; i++) { final View child = getChildAt(i); if (child.getVisibility() == GONE) { continue; } final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final int width = child.getMeasuredWidth(); final int height = child.getMeasuredHeight(); int childLeft; int childTop; int gravity = lp.gravity; if (gravity == -1) { gravity = Gravity.TOP | Gravity.LEFT; } final int absoluteGravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK; final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK; switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: childLeft = (r - l - width) / 2 + lp.leftMargin - lp.rightMargin; break; case Gravity.RIGHT: childLeft = r - width - lp.rightMargin; break; case Gravity.LEFT: default: childLeft = lp.leftMargin; } switch (verticalGravity) { case Gravity.TOP: childTop = lp.topMargin + getPaddingTop(); if (child != actionBar) { childTop += actionBar.getMeasuredHeight(); } break; case Gravity.CENTER_VERTICAL: childTop = ((b - paddingBottom) - t - height) / 2 + lp.topMargin - lp.bottomMargin; break; case Gravity.BOTTOM: childTop = ((b - paddingBottom) - t) - height - lp.bottomMargin; break; default: childTop = lp.topMargin; } if (child == mentionContainer) { childTop -= chatActivityEnterView.getMeasuredHeight() - AndroidUtilities.dp(2); } else if (child == pagedownButton) { childTop -= chatActivityEnterView.getMeasuredHeight(); } else if (child == emptyViewContainer) { childTop -= inputFieldHeight / 2 - actionBar.getMeasuredHeight() / 2; } else if (chatActivityEnterView.isPopupView(child)) { if (AndroidUtilities.isInMultiwindow) { childTop = chatActivityEnterView.getTop() - child.getMeasuredHeight() + AndroidUtilities.dp(1); } else { childTop = chatActivityEnterView.getBottom(); } } else if (child == gifHintTextView) { childTop -= inputFieldHeight; } else if (child == chatListView || child == progressView) { if (chatActivityEnterView.isTopViewVisible()) { childTop -= AndroidUtilities.dp(48); } } else if (child == actionBar) { childTop -= getPaddingTop(); } child.layout(childLeft, childTop, childLeft + width, childTop + height); } updateMessagesVisisblePart(); notifyHeightChanged(); } }; SizeNotifierFrameLayout contentView = (SizeNotifierFrameLayout) fragmentView; contentView.setBackgroundImage(ApplicationLoader.getCachedWallpaper()); emptyViewContainer = new FrameLayout(context); emptyViewContainer.setVisibility(View.INVISIBLE); contentView.addView(emptyViewContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER)); emptyViewContainer.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); if (currentEncryptedChat == null) { if (currentUser != null && currentUser.self) { bigEmptyView = new ChatBigEmptyView(context, false); emptyViewContainer.addView(bigEmptyView, new FrameLayout.LayoutParams(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER)); } else { TextView emptyView = new TextView(context); if (currentUser != null && currentUser.id != 777000 && currentUser.id != 429000 && (currentUser.id / 1000 == 333 || currentUser.id % 1000 == 0)) { emptyView.setText(LocaleController.getString("GotAQuestion", R.string.GotAQuestion)); } else { emptyView.setText(LocaleController.getString("NoMessages", R.string.NoMessages)); } emptyView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); emptyView.setGravity(Gravity.CENTER); emptyView.setTextColor(Theme.CHAT_EMPTY_VIEW_TEXT_COLOR); emptyView.setBackgroundResource(R.drawable.system); emptyView.getBackground().setColorFilter(Theme.colorFilter); emptyView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); emptyView.setPadding(AndroidUtilities.dp(10), AndroidUtilities.dp(2), AndroidUtilities.dp(10), AndroidUtilities.dp(3)); emptyViewContainer.addView(emptyView, new FrameLayout.LayoutParams(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER)); } } else { bigEmptyView = new ChatBigEmptyView(context, true); if (currentEncryptedChat.admin_id == UserConfig.getClientUserId()) { bigEmptyView.setSecretText(LocaleController.formatString("EncryptedPlaceholderTitleOutgoing", R.string.EncryptedPlaceholderTitleOutgoing, UserObject.getFirstName(currentUser))); } else { bigEmptyView.setSecretText(LocaleController.formatString("EncryptedPlaceholderTitleIncoming", R.string.EncryptedPlaceholderTitleIncoming, UserObject.getFirstName(currentUser))); } emptyViewContainer.addView(bigEmptyView, new FrameLayout.LayoutParams(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER)); } if (chatActivityEnterView != null) { chatActivityEnterView.onDestroy(); } if (mentionsAdapter != null) { mentionsAdapter.onDestroy(); } chatListView = new RecyclerListView(context) { @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); forceScrollToTop = false; if (chatAdapter.isBot) { int childCount = getChildCount(); for (int a = 0; a < childCount; a++) { View child = getChildAt(a); if (child instanceof BotHelpCell) { int height = b - t; int top = height / 2 - child.getMeasuredHeight() / 2; if (child.getTop() > top) { child.layout(0, top, r - l, top + child.getMeasuredHeight()); } break; } } } } }; chatListView.setTag(1); chatListView.setVerticalScrollBarEnabled(true); chatListView.setAdapter(chatAdapter = new ChatActivityAdapter(context)); chatListView.setClipToPadding(false); chatListView.setPadding(0, AndroidUtilities.dp(4), 0, AndroidUtilities.dp(3)); chatListView.setItemAnimator(null); chatListView.setLayoutAnimation(null); chatLayoutManager = new LinearLayoutManager(context) { @Override public boolean supportsPredictiveItemAnimations() { return false; } }; chatLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); chatLayoutManager.setStackFromEnd(true); chatListView.setLayoutManager(chatLayoutManager); contentView.addView(chatListView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); chatListView.setOnItemLongClickListener(onItemLongClickListener); chatListView.setOnItemClickListener(onItemClickListener); chatListView.setOnScrollListener(new RecyclerView.OnScrollListener() { private float totalDy = 0; private final int scrollValue = AndroidUtilities.dp(100); @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { if (newState == RecyclerView.SCROLL_STATE_DRAGGING && highlightMessageId != Integer.MAX_VALUE) { highlightMessageId = Integer.MAX_VALUE; updateVisibleRows(); } } @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { checkScrollForLoad(true); int firstVisibleItem = chatLayoutManager.findFirstVisibleItemPosition(); int visibleItemCount = firstVisibleItem == RecyclerView.NO_POSITION ? 0 : Math.abs(chatLayoutManager.findLastVisibleItemPosition() - firstVisibleItem) + 1; if (visibleItemCount > 0) { int totalItemCount = chatAdapter.getItemCount(); if (firstVisibleItem + visibleItemCount == totalItemCount && forwardEndReached[0]) { showPagedownButton(false, true); } else { if (dy > 0) { if (pagedownButton.getTag() == null) { totalDy += dy; if (totalDy > scrollValue) { totalDy = 0; showPagedownButton(true, true); pagedownButtonShowedByScroll = true; } } } else { if (pagedownButtonShowedByScroll && pagedownButton.getTag() != null) { totalDy += dy; if (totalDy < -scrollValue) { showPagedownButton(false, true); totalDy = 0; } } } } } updateMessagesVisisblePart(); } }); chatListView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (openSecretPhotoRunnable != null || SecretPhotoViewer.getInstance().isVisible()) { if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_POINTER_UP) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { chatListView.setOnItemClickListener(onItemClickListener); } }, 150); if (openSecretPhotoRunnable != null) { AndroidUtilities.cancelRunOnUIThread(openSecretPhotoRunnable); openSecretPhotoRunnable = null; try { Toast.makeText(v.getContext(), LocaleController.getString("PhotoTip", R.string.PhotoTip), Toast.LENGTH_SHORT).show(); } catch (Exception e) { FileLog.e("tmessages", e); } } else if (SecretPhotoViewer.getInstance().isVisible()) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { chatListView.setOnItemLongClickListener(onItemLongClickListener); chatListView.setLongClickable(true); } }); SecretPhotoViewer.getInstance().closePhoto(); } } else if (event.getAction() != MotionEvent.ACTION_DOWN) { if (SecretPhotoViewer.getInstance().isVisible()) { return true; } else if (openSecretPhotoRunnable != null) { if (event.getAction() == MotionEvent.ACTION_MOVE) { if (Math.hypot(startX - event.getX(), startY - event.getY()) > AndroidUtilities .dp(5)) { AndroidUtilities.cancelRunOnUIThread(openSecretPhotoRunnable); openSecretPhotoRunnable = null; } } else { AndroidUtilities.cancelRunOnUIThread(openSecretPhotoRunnable); openSecretPhotoRunnable = null; } chatListView.setOnItemClickListener(onItemClickListener); chatListView.setOnItemLongClickListener(onItemLongClickListener); chatListView.setLongClickable(true); } } } return false; } }); chatListView.setOnInterceptTouchListener(new RecyclerListView.OnInterceptTouchListener() { @Override public boolean onInterceptTouchEvent(MotionEvent event) { if (chatActivityEnterView != null && chatActivityEnterView.isEditingMessage()) { return true; } if (actionBar.isActionModeShowed()) { return false; } if (event.getAction() == MotionEvent.ACTION_DOWN) { int x = (int) event.getX(); int y = (int) event.getY(); int count = chatListView.getChildCount(); for (int a = 0; a < count; a++) { View view = chatListView.getChildAt(a); int top = view.getTop(); int bottom = view.getBottom(); if (top > y || bottom < y) { continue; } if (!(view instanceof ChatMessageCell)) { break; } final ChatMessageCell cell = (ChatMessageCell) view; final MessageObject messageObject = cell.getMessageObject(); if (messageObject == null || messageObject.isSending() || !messageObject.isSecretPhoto() || !cell.getPhotoImage().isInsideImage(x, y - top)) { break; } File file = FileLoader.getPathToMessage(messageObject.messageOwner); if (!file.exists()) { break; } startX = x; startY = y; chatListView.setOnItemClickListener(null); openSecretPhotoRunnable = new Runnable() { @Override public void run() { if (openSecretPhotoRunnable == null) { return; } chatListView.requestDisallowInterceptTouchEvent(true); chatListView.setOnItemLongClickListener(null); chatListView.setLongClickable(false); openSecretPhotoRunnable = null; if (sendSecretMessageRead(messageObject)) { cell.invalidate(); } SecretPhotoViewer.getInstance().setParentActivity(getParentActivity()); SecretPhotoViewer.getInstance().openPhoto(messageObject); } }; AndroidUtilities.runOnUIThread(openSecretPhotoRunnable, 100); return true; } } return false; } }); progressView = new FrameLayout(context); progressView.setVisibility(View.INVISIBLE); contentView.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT)); View view = new View(context); view.setBackgroundResource(R.drawable.system_loader); view.getBackground().setColorFilter(Theme.colorFilter); progressView.addView(view, LayoutHelper.createFrame(36, 36, Gravity.CENTER)); ProgressBar progressBar = new ProgressBar(context); try { progressBar.setIndeterminateDrawable(context.getResources().getDrawable(R.drawable.loading_animation)); } catch (Exception e) { //don't promt } progressBar.setIndeterminate(true); AndroidUtilities.setProgressBarAnimationDuration(progressBar, 1500); progressView.addView(progressBar, LayoutHelper.createFrame(32, 32, Gravity.CENTER)); if (ChatObject.isChannel(currentChat)) { pinnedMessageView = new FrameLayout(context); pinnedMessageView.setTag(1); pinnedMessageView.setTranslationY(-AndroidUtilities.dp(50)); pinnedMessageView.setVisibility(View.GONE); pinnedMessageView.setBackgroundResource(R.drawable.blockpanel); contentView.addView(pinnedMessageView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 50, Gravity.TOP | Gravity.LEFT)); pinnedMessageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { scrollToMessageId(info.pinned_msg_id, 0, true, 0); } }); View lineView = new View(context); lineView.setBackgroundColor(0xff6c9fd2); pinnedMessageView.addView(lineView, LayoutHelper.createFrame(2, 32, Gravity.LEFT | Gravity.TOP, 8, 8, 0, 0)); pinnedMessageImageView = new BackupImageView(context); pinnedMessageView.addView(pinnedMessageImageView, LayoutHelper.createFrame(32, 32, Gravity.TOP | Gravity.LEFT, 17, 8, 0, 0)); pinnedMessageNameTextView = new SimpleTextView(context); pinnedMessageNameTextView.setTextSize(14); pinnedMessageNameTextView.setTextColor(Theme.PINNED_PANEL_NAME_TEXT_COLOR); pinnedMessageNameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); pinnedMessageView.addView(pinnedMessageNameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, AndroidUtilities.dp(18), Gravity.TOP | Gravity.LEFT, 18, 7.3f, 52, 0)); pinnedMessageTextView = new SimpleTextView(context); pinnedMessageTextView.setTextSize(14); pinnedMessageTextView.setTextColor(Theme.PINNED_PANEL_MESSAGE_TEXT_COLOR); pinnedMessageView.addView(pinnedMessageTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, AndroidUtilities.dp(18), Gravity.TOP | Gravity.LEFT, 18, 25.3f, 52, 0)); ImageView closePinned = new ImageView(context); closePinned.setImageResource(R.drawable.miniplayer_close); closePinned.setScaleType(ImageView.ScaleType.CENTER); pinnedMessageView.addView(closePinned, LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.TOP)); closePinned.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (getParentActivity() == null) { return; } if (currentChat.creator || currentChat.editor) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage( LocaleController.getString("UnpinMessageAlert", R.string.UnpinMessageAlert)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { MessagesController.getInstance().pinChannelMessage(currentChat, 0, false); } }); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } else { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); preferences.edit().putInt("pin_" + dialog_id, info.pinned_msg_id).commit(); updatePinnedMessageView(true); } } }); } reportSpamView = new LinearLayout(context); reportSpamView.setTag(1); reportSpamView.setTranslationY(-AndroidUtilities.dp(50)); reportSpamView.setVisibility(View.GONE); reportSpamView.setBackgroundResource(R.drawable.blockpanel); contentView.addView(reportSpamView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 50, Gravity.TOP | Gravity.LEFT)); addToContactsButton = new TextView(context); addToContactsButton.setTextColor(Theme.CHAT_ADD_CONTACT_TEXT_COLOR); addToContactsButton.setVisibility(View.GONE); addToContactsButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); addToContactsButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); addToContactsButton.setSingleLine(true); addToContactsButton.setMaxLines(1); addToContactsButton.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0); addToContactsButton.setGravity(Gravity.CENTER); addToContactsButton.setText(LocaleController.getString("AddContactChat", R.string.AddContactChat)); reportSpamView.addView(addToContactsButton, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 0.5f, Gravity.LEFT | Gravity.TOP, 0, 0, 0, AndroidUtilities.dp(1))); addToContactsButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Bundle args = new Bundle(); args.putInt("user_id", currentUser.id); args.putBoolean("addContact", true); presentFragment(new ContactAddActivity(args)); } }); reportSpamContainer = new FrameLayout(context); reportSpamView.addView(reportSpamContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 1.0f, Gravity.LEFT | Gravity.TOP, 0, 0, 0, AndroidUtilities.dp(1))); reportSpamButton = new TextView(context); reportSpamButton.setTextColor(Theme.CHAT_REPORT_SPAM_TEXT_COLOR); reportSpamButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); reportSpamButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); reportSpamButton.setSingleLine(true); reportSpamButton.setMaxLines(1); if (currentChat != null) { reportSpamButton.setText(LocaleController.getString("ReportSpamAndLeave", R.string.ReportSpamAndLeave)); } else { reportSpamButton.setText(LocaleController.getString("ReportSpam", R.string.ReportSpam)); } reportSpamButton.setGravity(Gravity.CENTER); reportSpamButton.setPadding(AndroidUtilities.dp(50), 0, AndroidUtilities.dp(50), 0); reportSpamContainer.addView(reportSpamButton, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP)); reportSpamButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); if (ChatObject.isChannel(currentChat) && !currentChat.megagroup) { builder.setMessage( LocaleController.getString("ReportSpamAlertChannel", R.string.ReportSpamAlertChannel)); } else if (currentChat != null) { builder.setMessage( LocaleController.getString("ReportSpamAlertGroup", R.string.ReportSpamAlertGroup)); } else { builder.setMessage(LocaleController.getString("ReportSpamAlert", R.string.ReportSpamAlert)); } 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 (currentUser != null) { MessagesController.getInstance().blockUser(currentUser.id); } MessagesController.getInstance().reportSpam(dialog_id, currentUser, currentChat); updateSpamView(); if (currentChat != null) { if (ChatObject.isNotInChat(currentChat)) { MessagesController.getInstance().deleteDialog(dialog_id, 0); } else { MessagesController.getInstance().deleteUserFromChat((int) -dialog_id, MessagesController.getInstance() .getUser(UserConfig.getClientUserId()), null); } } else { MessagesController.getInstance().deleteDialog(dialog_id, 0); } finishFragment(); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } }); ImageView closeReportSpam = new ImageView(context); closeReportSpam.setImageResource(R.drawable.miniplayer_close); closeReportSpam.setScaleType(ImageView.ScaleType.CENTER); reportSpamContainer.addView(closeReportSpam, LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.TOP)); closeReportSpam.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { MessagesController.getInstance().hideReportSpam(dialog_id, currentUser, currentChat); updateSpamView(); } }); alertView = new FrameLayout(context); alertView.setTag(1); alertView.setTranslationY(-AndroidUtilities.dp(50)); alertView.setVisibility(View.GONE); alertView.setBackgroundResource(R.drawable.blockpanel); contentView.addView(alertView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 50, Gravity.TOP | Gravity.LEFT)); alertNameTextView = new TextView(context); alertNameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); alertNameTextView.setTextColor(Theme.ALERT_PANEL_NAME_TEXT_COLOR); alertNameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); alertNameTextView.setSingleLine(true); alertNameTextView.setEllipsize(TextUtils.TruncateAt.END); alertNameTextView.setMaxLines(1); alertView.addView(alertNameTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 8, 5, 8, 0)); alertTextView = new TextView(context); alertTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); alertTextView.setTextColor(Theme.ALERT_PANEL_MESSAGE_TEXT_COLOR); alertTextView.setSingleLine(true); alertTextView.setEllipsize(TextUtils.TruncateAt.END); alertTextView.setMaxLines(1); alertView.addView(alertTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 8, 23, 8, 0)); if (!isBroadcast) { mentionContainer = new FrameLayout(context) { private Drawable background; @Override public void onDraw(Canvas canvas) { if (mentionListView.getChildCount() <= 0) { return; } if (mentionsAdapter.isBotContext() && mentionsAdapter.isMediaLayout() && mentionsAdapter.getBotContextSwitch() == null) { background.setBounds(0, mentionListViewScrollOffsetY - AndroidUtilities.dp(4), getMeasuredWidth(), getMeasuredHeight()); } else { background.setBounds(0, mentionListViewScrollOffsetY - AndroidUtilities.dp(2), getMeasuredWidth(), getMeasuredHeight()); } background.draw(canvas); } @Override public void setBackgroundResource(int resid) { background = getContext().getResources().getDrawable(resid); } @Override public void requestLayout() { if (mentionListViewIgnoreLayout) { return; } super.requestLayout(); } }; mentionContainer.setBackgroundResource(R.drawable.compose_panel); mentionContainer.setVisibility(View.GONE); mentionContainer.setWillNotDraw(false); contentView.addView(mentionContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 110, Gravity.LEFT | Gravity.BOTTOM)); mentionListView = new RecyclerListView(context) { private int lastWidth; private int lastHeight; @Override public boolean onInterceptTouchEvent(MotionEvent event) { if (!mentionListViewIsScrolling && mentionListViewScrollOffsetY != 0 && event.getY() < mentionListViewScrollOffsetY) { return false; } boolean result = StickerPreviewViewer.getInstance().onInterceptTouchEvent(event, mentionListView, 0); return super.onInterceptTouchEvent(event) || result; } @Override public boolean onTouchEvent(MotionEvent event) { if (!mentionListViewIsScrolling && mentionListViewScrollOffsetY != 0 && event.getY() < mentionListViewScrollOffsetY) { return false; } //supress warning return super.onTouchEvent(event); } @Override public void requestLayout() { if (mentionListViewIgnoreLayout) { return; } super.requestLayout(); } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { int width = r - l; int height = b - t; int newPosition = -1; int newTop = 0; if (mentionListView != null && mentionListViewLastViewPosition >= 0 && width == lastWidth && height - lastHeight != 0) { newPosition = mentionListViewLastViewPosition; newTop = mentionListViewLastViewTop + height - lastHeight - getPaddingTop(); } super.onLayout(changed, l, t, r, b); if (newPosition != -1) { mentionListViewIgnoreLayout = true; if (mentionsAdapter.isBotContext() && mentionsAdapter.isMediaLayout()) { mentionGridLayoutManager.scrollToPositionWithOffset(newPosition, newTop); } else { mentionLayoutManager.scrollToPositionWithOffset(newPosition, newTop); } super.onLayout(false, l, t, r, b); mentionListViewIgnoreLayout = false; } lastHeight = height; lastWidth = width; mentionListViewUpdateLayout(); } }; mentionListView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return StickerPreviewViewer.getInstance().onTouch(event, mentionListView, 0, mentionsOnItemClickListener); } }); mentionListView.setTag(2); mentionLayoutManager = new LinearLayoutManager(context) { @Override public boolean supportsPredictiveItemAnimations() { return false; } }; mentionLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); mentionGridLayoutManager = new ExtendedGridLayoutManager(context, 100) { private Size size = new Size(); @Override protected Size getSizeForItem(int i) { if (mentionsAdapter.getBotContextSwitch() != null) { i++; } Object object = mentionsAdapter.getItem(i); if (object instanceof TLRPC.BotInlineResult) { TLRPC.BotInlineResult inlineResult = (TLRPC.BotInlineResult) object; if (inlineResult.document != null) { size.width = inlineResult.document.thumb != null ? inlineResult.document.thumb.w : 100; size.height = inlineResult.document.thumb != null ? inlineResult.document.thumb.h : 100; for (int b = 0; b < inlineResult.document.attributes.size(); b++) { TLRPC.DocumentAttribute attribute = inlineResult.document.attributes.get(b); if (attribute instanceof TLRPC.TL_documentAttributeImageSize || attribute instanceof TLRPC.TL_documentAttributeVideo) { size.width = attribute.w; size.height = attribute.h; break; } } } else { size.width = inlineResult.w; size.height = inlineResult.h; } } return size; } @Override protected int getFlowItemCount() { if (mentionsAdapter.getBotContextSwitch() != null) { return getItemCount() - 1; } return super.getFlowItemCount(); } }; mentionGridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { Object object = mentionsAdapter.getItem(position); if (object instanceof TLRPC.TL_inlineBotSwitchPM) { return 100; } else { if (mentionsAdapter.getBotContextSwitch() != null) { position--; } return mentionGridLayoutManager.getSpanSizeForItem(position); } } }); mentionListView.addItemDecoration(new RecyclerView.ItemDecoration() { @Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { outRect.left = 0; outRect.right = 0; outRect.top = 0; outRect.bottom = 0; if (parent.getLayoutManager() == mentionGridLayoutManager) { int position = parent.getChildAdapterPosition(view); if (mentionsAdapter.getBotContextSwitch() != null) { if (position == 0) { return; } position--; if (!mentionGridLayoutManager.isFirstRow(position)) { outRect.top = AndroidUtilities.dp(2); } } else { outRect.top = AndroidUtilities.dp(2); } outRect.right = mentionGridLayoutManager.isLastInRow(position) ? 0 : AndroidUtilities.dp(2); } } }); mentionListView.setItemAnimator(null); mentionListView.setLayoutAnimation(null); mentionListView.setClipToPadding(false); mentionListView.setLayoutManager(mentionLayoutManager); mentionListView.setOverScrollMode(ListView.OVER_SCROLL_NEVER); mentionContainer.addView(mentionListView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); mentionListView.setAdapter(mentionsAdapter = new MentionsAdapter(context, false, dialog_id, new MentionsAdapter.MentionsAdapterDelegate() { @Override public void needChangePanelVisibility(boolean show) { if (mentionsAdapter.isBotContext() && mentionsAdapter.isMediaLayout()) { mentionListView.setLayoutManager(mentionGridLayoutManager); } else { mentionListView.setLayoutManager(mentionLayoutManager); } if (show) { if (mentionListAnimation != null) { mentionListAnimation.cancel(); mentionListAnimation = null; } if (mentionContainer.getVisibility() == View.VISIBLE) { mentionContainer.setAlpha(1.0f); return; } if (mentionsAdapter.isBotContext() && mentionsAdapter.isMediaLayout()) { mentionGridLayoutManager.scrollToPositionWithOffset(0, 10000); } else { mentionLayoutManager.scrollToPositionWithOffset(0, 10000); } if (allowStickersPanel && (!mentionsAdapter.isBotContext() || (allowContextBotPanel || allowContextBotPanelSecond))) { if (currentEncryptedChat != null && mentionsAdapter.isBotContext()) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); if (!preferences.getBoolean("secretbot", false)) { AlertDialog.Builder builder = new AlertDialog.Builder( getParentActivity()); builder.setTitle( LocaleController.getString("AppName", R.string.AppName)); builder.setMessage( LocaleController.getString("SecretChatContextBotAlert", R.string.SecretChatContextBotAlert)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null); showDialog(builder.create()); preferences.edit().putBoolean("secretbot", true).commit(); } } mentionContainer.setVisibility(View.VISIBLE); mentionContainer.setTag(null); mentionListAnimation = new AnimatorSet(); mentionListAnimation.playTogether( ObjectAnimator.ofFloat(mentionContainer, "alpha", 0.0f, 1.0f)); mentionListAnimation.addListener(new AnimatorListenerAdapterProxy() { @Override public void onAnimationEnd(Animator animation) { if (mentionListAnimation != null && mentionListAnimation.equals(animation)) { mentionListAnimation = null; } } @Override public void onAnimationCancel(Animator animation) { if (mentionListAnimation != null && mentionListAnimation.equals(animation)) { mentionListAnimation = null; } } }); mentionListAnimation.setDuration(200); mentionListAnimation.start(); } else { mentionContainer.setAlpha(1.0f); mentionContainer.setVisibility(View.INVISIBLE); } } else { if (mentionListAnimation != null) { mentionListAnimation.cancel(); mentionListAnimation = null; } if (mentionContainer.getVisibility() == View.GONE) { return; } if (allowStickersPanel) { mentionListAnimation = new AnimatorSet(); mentionListAnimation .playTogether(ObjectAnimator.ofFloat(mentionContainer, "alpha", 0.0f)); mentionListAnimation.addListener(new AnimatorListenerAdapterProxy() { @Override public void onAnimationEnd(Animator animation) { if (mentionListAnimation != null && mentionListAnimation.equals(animation)) { mentionContainer.setVisibility(View.GONE); mentionContainer.setTag(null); mentionListAnimation = null; } } @Override public void onAnimationCancel(Animator animation) { if (mentionListAnimation != null && mentionListAnimation.equals(animation)) { mentionListAnimation = null; } } }); mentionListAnimation.setDuration(200); mentionListAnimation.start(); } else { mentionContainer.setTag(null); mentionContainer.setVisibility(View.GONE); } } } @Override public void onContextSearch(boolean searching) { if (chatActivityEnterView != null) { chatActivityEnterView.setCaption(mentionsAdapter.getBotCaption()); chatActivityEnterView.showContextProgress(searching); } } @Override public void onContextClick(TLRPC.BotInlineResult result) { if (getParentActivity() == null || result.content_url == null) { return; } if (result.type.equals("video") || result.type.equals("web_player_video")) { BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity()); builder.setCustomView(new WebFrameLayout(getParentActivity(), builder.create(), result.title != null ? result.title : "", result.description, result.content_url, result.content_url, result.w, result.h)); builder.setUseFullWidth(true); showDialog(builder.create()); } else { Browser.openUrl(getParentActivity(), result.content_url); } } })); if (!ChatObject.isChannel(currentChat) || currentChat != null && currentChat.megagroup) { mentionsAdapter.setBotInfo(botInfo); } mentionsAdapter.setParentFragment(this); mentionsAdapter.setChatInfo(info); mentionsAdapter.setNeedUsernames(currentChat != null); mentionsAdapter.setNeedBotContext(currentEncryptedChat == null || AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) >= 46); mentionsAdapter.setBotsCount(currentChat != null ? botsCount : 1); mentionListView.setOnItemClickListener( mentionsOnItemClickListener = new RecyclerListView.OnItemClickListener() { @Override public void onItemClick(View view, int position) { Object object = mentionsAdapter.getItem(position); int start = mentionsAdapter.getResultStartPosition(); int len = mentionsAdapter.getResultLength(); if (object instanceof TLRPC.User) { TLRPC.User user = (TLRPC.User) object; if (user != null) { if (user.username != null) { chatActivityEnterView.replaceWithText(start, len, "@" + user.username + " "); } else { String name = user.first_name; if (name == null || name.length() == 0) { name = user.last_name; } Spannable spannable = new SpannableString(name + " "); spannable.setSpan(new URLSpanUserMention("" + user.id), 0, spannable.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); chatActivityEnterView.replaceWithText(start, len, spannable); } } } else if (object instanceof String) { if (mentionsAdapter.isBotCommands()) { SendMessagesHelper.getInstance().sendMessage((String) object, dialog_id, null, null, false, null, null, null); chatActivityEnterView.setFieldText(""); } else { chatActivityEnterView.replaceWithText(start, len, object + " "); } } else if (object instanceof TLRPC.BotInlineResult) { if (chatActivityEnterView.getFieldText() == null) { return; } TLRPC.BotInlineResult result = (TLRPC.BotInlineResult) object; if (Build.VERSION.SDK_INT >= 16 && (result.type.equals("photo") && (result.photo != null || result.content_url != null) || result.type.equals("gif") && (result.document != null || result.content_url != null) || result.type.equals("video") && (result.document != null/* || result.content_url != null*/))) { ArrayList<Object> arrayList = botContextResults = new ArrayList<Object>( mentionsAdapter.getSearchResultBotContext()); PhotoViewer.getInstance().setParentActivity(getParentActivity()); PhotoViewer.getInstance().openPhotoForSelect(arrayList, mentionsAdapter.getItemPosition(position), 3, botContextProvider, null); } else { sendBotInlineResult(result); } } else if (object instanceof TLRPC.TL_inlineBotSwitchPM) { processInlineBotContextPM((TLRPC.TL_inlineBotSwitchPM) object); } } }); mentionListView.setOnItemLongClickListener(new RecyclerListView.OnItemLongClickListener() { @Override public boolean onItemClick(View view, int position) { if (getParentActivity() == null || !mentionsAdapter.isLongClickEnabled()) { return false; } Object object = mentionsAdapter.getItem(position); if (object instanceof String) { if (mentionsAdapter.isBotCommands()) { if (URLSpanBotCommand.enabled) { chatActivityEnterView.setFieldText(""); chatActivityEnterView.setCommand(null, (String) object, true, currentChat != null && currentChat.megagroup); return true; } return false; } else { 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) { mentionsAdapter.clearRecentHashtags(); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); return true; } } return false; } }); mentionListView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { mentionListViewIsScrolling = newState == RecyclerView.SCROLL_STATE_DRAGGING; } @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { int lastVisibleItem; if (mentionsAdapter.isBotContext() && mentionsAdapter.isMediaLayout()) { lastVisibleItem = mentionGridLayoutManager.findLastVisibleItemPosition(); } else { lastVisibleItem = mentionLayoutManager.findLastVisibleItemPosition(); } int visibleItemCount = lastVisibleItem == RecyclerView.NO_POSITION ? 0 : lastVisibleItem; if (visibleItemCount > 0 && lastVisibleItem > mentionsAdapter.getItemCount() - 5) { mentionsAdapter.searchForContextBotForNextOffset(); } mentionListViewUpdateLayout(); } }); } pagedownButton = new FrameLayout(context); pagedownButton.setVisibility(View.INVISIBLE); contentView.addView(pagedownButton, LayoutHelper.createFrame(46, 59, Gravity.RIGHT | Gravity.BOTTOM, 0, 0, 7, 5)); pagedownButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (returnToMessageId > 0) { scrollToMessageId(returnToMessageId, 0, true, returnToLoadIndex); } else { scrollToLastMessage(true); } } }); ImageView pagedownButtonImage = new ImageView(context); pagedownButtonImage.setImageResource(R.drawable.pagedown); pagedownButton.addView(pagedownButtonImage, LayoutHelper.createFrame(46, 46, Gravity.LEFT | Gravity.BOTTOM)); pagedownButtonCounter = new TextView(context); pagedownButtonCounter.setVisibility(View.INVISIBLE); pagedownButtonCounter.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); pagedownButtonCounter.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13); pagedownButtonCounter.setTextColor(0xffffffff); pagedownButtonCounter.setGravity(Gravity.CENTER); pagedownButtonCounter.setBackgroundResource(R.drawable.chat_badge); pagedownButtonCounter.setMinWidth(AndroidUtilities.dp(23)); pagedownButtonCounter.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8), AndroidUtilities.dp(1)); pagedownButton.addView(pagedownButtonCounter, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 23, Gravity.TOP | Gravity.CENTER_HORIZONTAL)); chatActivityEnterView = new ChatActivityEnterView(getParentActivity(), contentView, this, true); chatActivityEnterView.setDialogId(dialog_id); chatActivityEnterView.addToAttachLayout(menuItem); chatActivityEnterView.setId(id_chat_compose_panel); chatActivityEnterView.setBotsCount(botsCount, hasBotsCommands); chatActivityEnterView.setAllowStickersAndGifs( currentEncryptedChat == null || AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) >= 23, currentEncryptedChat == null || AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) >= 46); contentView.addView(chatActivityEnterView, contentView.getChildCount() - 1, LayoutHelper .createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.BOTTOM)); chatActivityEnterView.setDelegate(new ChatActivityEnterView.ChatActivityEnterViewDelegate() { @Override public void onMessageSend(CharSequence message) { moveScrollToLastMessage(); showReplyPanel(false, null, null, null, false, true); if (mentionsAdapter != null) { mentionsAdapter.addHashtagsFromMessage(message); } } @Override public void onTextChanged(final CharSequence text, boolean bigChange) { MediaController.getInstance().setInputFieldHasText( text != null && text.length() != 0 || chatActivityEnterView.isEditingMessage()); if (stickersAdapter != null && !chatActivityEnterView.isEditingMessage()) { stickersAdapter.loadStikersForEmoji(text); } if (mentionsAdapter != null) { mentionsAdapter.searchUsernameOrHashtag(text.toString(), chatActivityEnterView.getCursorPosition(), messages); } if (waitingForCharaterEnterRunnable != null) { AndroidUtilities.cancelRunOnUIThread(waitingForCharaterEnterRunnable); waitingForCharaterEnterRunnable = null; } if (chatActivityEnterView.isMessageWebPageSearchEnabled() && (!chatActivityEnterView.isEditingMessage() || !chatActivityEnterView.isEditingCaption())) { if (bigChange) { searchLinks(text, true); } else { waitingForCharaterEnterRunnable = new Runnable() { @Override public void run() { if (this == waitingForCharaterEnterRunnable) { searchLinks(text, false); waitingForCharaterEnterRunnable = null; } } }; AndroidUtilities.runOnUIThread(waitingForCharaterEnterRunnable, AndroidUtilities.WEB_URL == null ? 3000 : 1000); } } } @Override public void needSendTyping() { MessagesController.getInstance().sendTyping(dialog_id, 0, classGuid); } @Override public void onAttachButtonHidden() { if (actionBar.isSearchFieldVisible()) { return; } if (attachItem != null) { attachItem.setVisibility(View.VISIBLE); } if (headerItem != null) { headerItem.setVisibility(View.GONE); } } @Override public void onAttachButtonShow() { if (actionBar.isSearchFieldVisible()) { return; } if (attachItem != null) { attachItem.setVisibility(View.GONE); } if (headerItem != null) { headerItem.setVisibility(View.VISIBLE); } } @Override public void onMessageEditEnd(boolean loading) { if (loading) { showEditDoneProgress(true, true); } else { mentionsAdapter.setNeedBotContext(currentEncryptedChat == null || AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) >= 46); chatListView.setOnItemLongClickListener(onItemLongClickListener); chatListView.setOnItemClickListener(onItemClickListener); chatListView.setClickable(true); chatListView.setLongClickable(true); mentionsAdapter.setAllowNewMentions(true); actionModeTitleContainer.setVisibility(View.GONE); selectedMessagesCountTextView.setVisibility(View.VISIBLE); chatActivityEnterView.setAllowStickersAndGifs( currentEncryptedChat == null || AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) >= 23, currentEncryptedChat == null || AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) >= 46); if (editingMessageObjectReqId != 0) { ConnectionsManager.getInstance().cancelRequest(editingMessageObjectReqId, true); editingMessageObjectReqId = 0; } actionBar.hideActionMode(); updatePinnedMessageView(true); updateVisibleRows(); } } @Override public void onWindowSizeChanged(int size) { if (size < AndroidUtilities.dp(72) + ActionBar.getCurrentActionBarHeight()) { allowStickersPanel = false; if (stickersPanel.getVisibility() == View.VISIBLE) { stickersPanel.setVisibility(View.INVISIBLE); } if (mentionContainer != null && mentionContainer.getVisibility() == View.VISIBLE) { mentionContainer.setVisibility(View.INVISIBLE); } } else { allowStickersPanel = true; if (stickersPanel.getVisibility() == View.INVISIBLE) { stickersPanel.setVisibility(View.VISIBLE); } if (mentionContainer != null && mentionContainer.getVisibility() == View.INVISIBLE && (!mentionsAdapter.isBotContext() || (allowContextBotPanel || allowContextBotPanelSecond))) { mentionContainer.setVisibility(View.VISIBLE); mentionContainer.setTag(null); } } allowContextBotPanel = !chatActivityEnterView.isPopupShowing(); checkContextBotPanel(); } @Override public void onStickersTab(boolean opened) { if (emojiButtonRed != null) { emojiButtonRed.setVisibility(View.GONE); } allowContextBotPanelSecond = !opened; checkContextBotPanel(); } }); FrameLayout replyLayout = new FrameLayout(context) { @Override public void setTranslationY(float translationY) { super.setTranslationY(translationY); if (chatActivityEnterView != null) { chatActivityEnterView.invalidate(); } if (getVisibility() != GONE) { int height = getLayoutParams().height; if (chatListView != null) { chatListView.setTranslationY(translationY); } if (progressView != null) { progressView.setTranslationY(translationY); } if (mentionContainer != null) { mentionContainer.setTranslationY(translationY); } if (pagedownButton != null) { pagedownButton.setTranslationY(translationY); } } } @Override public boolean hasOverlappingRendering() { return false; } @Override public void setVisibility(int visibility) { super.setVisibility(visibility); if (visibility == GONE) { if (chatListView != null) { chatListView.setTranslationY(0); } if (progressView != null) { progressView.setTranslationY(0); } if (mentionContainer != null) { mentionContainer.setTranslationY(0); } if (pagedownButton != null) { pagedownButton .setTranslationY(pagedownButton.getTag() == null ? AndroidUtilities.dp(100) : 0); } } } }; replyLayout.setClickable(true); chatActivityEnterView.addTopView(replyLayout, 48); View lineView = new View(context); lineView.setBackgroundColor(0xffe8e8e8); replyLayout.addView(lineView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 1, Gravity.BOTTOM | Gravity.LEFT)); replyIconImageView = new ImageView(context); replyIconImageView.setScaleType(ImageView.ScaleType.CENTER); replyLayout.addView(replyIconImageView, LayoutHelper.createFrame(52, 46, Gravity.TOP | Gravity.LEFT)); ImageView imageView = new ImageView(context); imageView.setImageResource(R.drawable.delete_reply); imageView.setScaleType(ImageView.ScaleType.CENTER); replyLayout.addView(imageView, LayoutHelper.createFrame(52, 46, Gravity.RIGHT | Gravity.TOP, 0, 0.5f, 0, 0)); imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (forwardingMessages != null) { forwardingMessages.clear(); } showReplyPanel(false, null, null, foundWebPage, true, true); } }); replyNameTextView = new SimpleTextView(context); replyNameTextView.setTextSize(14); replyNameTextView.setTextColor(Theme.REPLY_PANEL_NAME_TEXT_COLOR); replyNameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); replyLayout.addView(replyNameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 18, Gravity.TOP | Gravity.LEFT, 52, 6, 52, 0)); replyObjectTextView = new SimpleTextView(context); replyObjectTextView.setTextSize(14); replyObjectTextView.setTextColor(Theme.REPLY_PANEL_MESSAGE_TEXT_COLOR); replyLayout.addView(replyObjectTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 18, Gravity.TOP | Gravity.LEFT, 52, 24, 52, 0)); replyImageView = new BackupImageView(context); replyLayout.addView(replyImageView, LayoutHelper.createFrame(34, 34, Gravity.TOP | Gravity.LEFT, 52, 6, 0, 0)); stickersPanel = new FrameLayout(context); stickersPanel.setVisibility(View.GONE); contentView.addView(stickersPanel, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 81.5f, Gravity.LEFT | Gravity.BOTTOM, 0, 0, 0, 38)); stickersListView = new RecyclerListView(context) { @Override public boolean onInterceptTouchEvent(MotionEvent event) { boolean result = StickerPreviewViewer.getInstance().onInterceptTouchEvent(event, stickersListView, 0); return super.onInterceptTouchEvent(event) || result; } }; stickersListView.setTag(3); stickersListView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return StickerPreviewViewer.getInstance().onTouch(event, stickersListView, 0, stickersOnItemClickListener); } }); stickersListView.setDisallowInterceptTouchEvents(true); LinearLayoutManager layoutManager = new LinearLayoutManager(context); layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); stickersListView.setLayoutManager(layoutManager); stickersListView.setClipToPadding(false); stickersListView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER); stickersPanel.addView(stickersListView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 78)); initStickers(); imageView = new ImageView(context); imageView.setImageResource(R.drawable.stickers_back_arrow); stickersPanel.addView(imageView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT, 53, 0, 0, 0)); searchContainer = new FrameLayout(context); searchContainer.setBackgroundResource(R.drawable.compose_panel); searchContainer.setVisibility(View.INVISIBLE); searchContainer.setFocusable(true); searchContainer.setFocusableInTouchMode(true); searchContainer.setClickable(true); searchContainer.setBackgroundResource(R.drawable.compose_panel); searchContainer.setPadding(0, AndroidUtilities.dp(3), 0, 0); contentView.addView(searchContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 51, Gravity.BOTTOM)); searchUpButton = new ImageView(context); searchUpButton.setScaleType(ImageView.ScaleType.CENTER); searchUpButton.setImageResource(R.drawable.search_up); searchContainer.addView(searchUpButton, LayoutHelper.createFrame(48, 48)); searchUpButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { MessagesSearchQuery.searchMessagesInChat(null, dialog_id, mergeDialogId, classGuid, 1); } }); searchDownButton = new ImageView(context); searchDownButton.setScaleType(ImageView.ScaleType.CENTER); searchDownButton.setImageResource(R.drawable.search_down); searchContainer.addView(searchDownButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP, 48, 0, 0, 0)); searchDownButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { MessagesSearchQuery.searchMessagesInChat(null, dialog_id, mergeDialogId, classGuid, 2); } }); searchCountText = new SimpleTextView(context); searchCountText.setTextColor(Theme.CHAT_SEARCH_COUNT_TEXT_COLOR); searchCountText.setTextSize(15); searchCountText.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); searchContainer.addView(searchCountText, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.CENTER_VERTICAL, 108, 0, 0, 0)); bottomOverlay = new FrameLayout(context); bottomOverlay.setVisibility(View.INVISIBLE); bottomOverlay.setFocusable(true); bottomOverlay.setFocusableInTouchMode(true); bottomOverlay.setClickable(true); bottomOverlay.setBackgroundResource(R.drawable.compose_panel); bottomOverlay.setPadding(0, AndroidUtilities.dp(3), 0, 0); contentView.addView(bottomOverlay, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 51, Gravity.BOTTOM)); bottomOverlayText = new TextView(context); bottomOverlayText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); bottomOverlayText.setTextColor(Theme.CHAT_BOTTOM_OVERLAY_TEXT_COLOR); bottomOverlay.addView(bottomOverlayText, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER)); bottomOverlayChat = new FrameLayout(context); bottomOverlayChat.setBackgroundResource(R.drawable.compose_panel); bottomOverlayChat.setPadding(0, AndroidUtilities.dp(3), 0, 0); bottomOverlayChat.setVisibility(View.INVISIBLE); contentView.addView(bottomOverlayChat, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 51, Gravity.BOTTOM)); bottomOverlayChat.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = null; if (currentUser != null && userBlocked) { if (currentUser.bot) { String botUserLast = botUser; botUser = null; MessagesController.getInstance().unblockUser(currentUser.id); if (botUserLast != null && botUserLast.length() != 0) { MessagesController.getInstance().sendBotStart(currentUser, botUserLast); } else { SendMessagesHelper.getInstance().sendMessage("/start", dialog_id, null, null, false, null, null, null); } } else { builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("AreYouSureUnblockContact", R.string.AreYouSureUnblockContact)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { MessagesController.getInstance().unblockUser(currentUser.id); } }); } } else if (currentUser != null && currentUser.bot && botUser != null) { if (botUser.length() != 0) { MessagesController.getInstance().sendBotStart(currentUser, botUser); } else { SendMessagesHelper.getInstance().sendMessage("/start", dialog_id, null, null, false, null, null, null); } botUser = null; updateBottomOverlay(); } else { if (ChatObject.isChannel(currentChat) && !(currentChat instanceof TLRPC.TL_channelForbidden)) { if (ChatObject.isNotInChat(currentChat)) { MessagesController.getInstance().addUserToChat(currentChat.id, UserConfig.getCurrentUser(), null, 0, null, null); } else { toggleMute(true); } } else { builder = new AlertDialog.Builder(getParentActivity()); 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) { MessagesController.getInstance().deleteDialog(dialog_id, 0); finishFragment(); } }); } } if (builder != null) { builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } } }); bottomOverlayChatText = new TextView(context); bottomOverlayChatText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15); bottomOverlayChatText.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); bottomOverlayChatText.setTextColor(Theme.CHAT_BOTTOM_CHAT_OVERLAY_TEXT_COLOR); bottomOverlayChat.addView(bottomOverlayChatText, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER)); chatAdapter.updateRows(); if (loading && messages.isEmpty()) { progressView.setVisibility(chatAdapter.botInfoRow == -1 ? View.VISIBLE : View.INVISIBLE); chatListView.setEmptyView(null); } else { progressView.setVisibility(View.INVISIBLE); chatListView.setEmptyView(emptyViewContainer); } chatActivityEnterView.setButtons(userBlocked ? null : botButtons); if (!AndroidUtilities.isTablet() || AndroidUtilities.isSmallTablet()) { contentView.addView(playerView = new PlayerView(context, this), LayoutHelper .createFrame(LayoutHelper.MATCH_PARENT, 39, Gravity.TOP | Gravity.LEFT, 0, -36, 0, 0)); } updateContactStatus(); updateBottomOverlay(); updateSecretStatus(); updateSpamView(); updatePinnedMessageView(true); try { if (currentEncryptedChat != null && Build.VERSION.SDK_INT >= 23) { getParentActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); } } catch (Throwable e) { FileLog.e("tmessages", e); } fixLayoutInternal(); contentView.addView(actionBar); return fragmentView; }
From source file:com.haomee.chat.activity.ChatActivity.java
/** * /*from www. j ava 2 s . co m*/ */ private void init_new_emotions(final String path) { File file = new File(emotions_base_path); File[] files = file.listFiles();// ? for (File f : files) { if (path == null) { return; } if (f == null) { return; } if (!file.exists() || !file.isDirectory()) { return; } // if (f.listFiles().length == 0) { // return; // } if (path.equals(f.getName())) {// ?? File[] file_image_list = f.listFiles(); image_path = new ArrayList<String>(); image_name = new ArrayList<String>(); if (file_image_list == null) { return; } for (int j = 0; j < file_image_list.length; j++) { File file_image = file_image_list[j]; try { String newFileName = new String(file_image.getName().getBytes(), "UTF-8"); if (newFileName.contains(big_cover_name) || newFileName.contains(simall_cover_name)) { // final ImageView iv_bottom_emotion = new ImageView(ChatActivity.this); Bitmap decodeFile = BitmapFactory.decodeFile(file_image.getAbsolutePath()); iv_bottom_emotion.setImageBitmap(decodeFile); int screen_width = ViewUtil.getScreenWidth(ChatActivity.this); layoutParams.width = screen_width / 8; layoutParams.height = screen_width / 8; iv_bottom_emotion.setLayoutParams(layoutParams); iv_bottom_emotion.setBackgroundResource(R.drawable.grid_line); iv_bottom_emotion.setTag(path); // imag_list.add(iv_bottom_emotion); imag_list.add(0, iv_bottom_emotion); iv_bottom_emotion.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub selected_pager = (String) iv_bottom_emotion.getTag(); iv_expression_emoji.setBackgroundResource(R.drawable.grid_line); for (ImageView iv : imag_list) { if (selected_pager.equals(iv.getTag())) { iv.setBackgroundResource(R.drawable.grid_line_press); } else { iv.setBackgroundResource(R.drawable.grid_line); } } search_selected_emotions((String) iv_bottom_emotion.getTag()); } }); ll_emotions_content.addView(iv_bottom_emotion); viewpager.setTag(tab_emotions_tag);// ? } } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } }