List of usage examples for android.widget ProgressBar ProgressBar
public ProgressBar(Context context)
From source file:org.csploit.android.WifiScannerActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.scan) { if (mMenu != null) { MenuItem menuScan = mMenu.findItem(R.id.scan); MenuItemCompat.setActionView(menuScan, new ProgressBar(this)); }/*from w w w. ja v a 2s.c o m*/ mWifiManager.startScan(); mStatusText.setText(getString(R.string.scanning)); mScanning = true; return true; } if (item.getItemId() == android.R.id.home) { onBackPressed(); return true; } else return super.onOptionsItemSelected(item); }
From source file:com.wit.and.dialog.LoginDialog.java
/** * /* ww w . j a v a 2s . co m*/ */ @Override protected View onCreateBodyView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final Context context = inflater.getContext(); RelativeLayout layout = new RelativeLayout(context); // Apply neutral layout params. layout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); // Do not allow to apply style to body view. // layout.setId(R.id.Dialog_Layout_Body); // Create layout for loading view. LinearLayout loadingLayout = new LinearLayout(context); loadingLayout.setOrientation(LinearLayout.HORIZONTAL); loadingLayout.setGravity(Gravity.CENTER_VERTICAL); // Allow styling of loading layout as body layout. loadingLayout.setId(R.id.And_Dialog_Layout_Body); // Create text view for message. TextView msgTextView = new TextView(context); msgTextView.setId(R.id.And_Dialog_TextView_Message); // Create circle progress bar. ProgressBar circleProgressBar = new ProgressBar(context); circleProgressBar.setId(R.id.And_Dialog_ProgressBar); // Build loading view. loadingLayout.addView(circleProgressBar, new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); loadingLayout.addView(msgTextView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); loadingLayout.setVisibility(View.GONE); // Insert loading layout into main body layout. RelativeLayout.LayoutParams loadingLayoutParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); loadingLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT); layout.addView(loadingLayout, loadingLayoutParams); // Create layout for edit texts. LinearLayout editLayout = new LinearLayout(context); editLayout.setOrientation(LinearLayout.VERTICAL); editLayout.setId(R.id.And_Dialog_Layout_LoginDialog_EditView); // Create edit texts for username and password. EditText userEdit = new EditText(context); userEdit.setId(R.id.And_Dialog_EditText_Username); userEdit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); EditText passEdit = new EditText(context); passEdit.setId(R.id.And_Dialog_EditText_Password); passEdit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); // Create edit texts divider. DialogDivider divider = new DialogDivider(context); divider.setId(R.id.And_Dialog_Divider_LoginDialog_EditTexts); // Build edit layout. editLayout.addView(userEdit, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); editLayout.addView(divider, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); editLayout.addView(passEdit, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); // Add custom layout. View customView = onCreateCustomView(inflater, editLayout, savedInstanceState); if (customView != null) { editLayout.addView(this.mCustomView = customView); } // Insert edit layout into main body layout. RelativeLayout.LayoutParams editLayoutParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); editLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT); layout.addView(editLayout, editLayoutParams); return layout; }
From source file:at.alladin.rmbt.android.map.RMBTMapFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final RelativeLayout view = (RelativeLayout) inflater.inflate(R.layout.map_google, container, false); registerListeners(view);//w ww. j av a 2s . c o m final int errorCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()); if (errorCode != ConnectionResult.SUCCESS) { final Dialog errorDialog = GooglePlayServicesUtil.getErrorDialog(errorCode, getActivity(), 0); errorDialog.show(); getFragmentManager().popBackStack(); return view; } View mapView = super.onCreateView(inflater, container, savedInstanceState); final RelativeLayout mapViewContainer = (RelativeLayout) view.findViewById(R.id.mapViewContainer); mapViewContainer.addView(mapView); ProgressBar progessBar = new ProgressBar(getActivity()); final RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, 1); progessBar.setLayoutParams(layoutParams); progessBar.setVisibility(View.GONE); view.addView(progessBar); return view; }
From source file:in.andres.kandroid.ui.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); refreshAction = menu.findItem(R.id.action_refresh); if (progressBarCount > 0) { ProgressBar prog = new ProgressBar(self); prog.getIndeterminateDrawable().setColorFilter(Color.WHITE, android.graphics.PorterDuff.Mode.MULTIPLY); refreshAction.setActionView(prog); refreshAction.expandActionView(); progressVisible = true;//w w w .j a v a2s .c o m } return true; }
From source file:org.telegram.ui.TwoStepVerificationActivity.java
@Override public View createView(Context context) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(false); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override//from w w w . ja v a 2 s .c o m public void onItemClick(int id) { if (id == -1) { finishFragment(); } else if (id == done_button) { processDone(); } } }); fragmentView = new FrameLayout(context); FrameLayout frameLayout = (FrameLayout) fragmentView; frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background)); ActionBarMenu menu = actionBar.createMenu(); doneItem = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56)); scrollView = new ScrollView(context); scrollView.setFillViewport(true); frameLayout.addView(scrollView); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) scrollView.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; scrollView.setLayoutParams(layoutParams); LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.VERTICAL); scrollView.addView(linearLayout); ScrollView.LayoutParams layoutParams2 = (ScrollView.LayoutParams) linearLayout.getLayoutParams(); layoutParams2.width = ScrollView.LayoutParams.MATCH_PARENT; layoutParams2.height = ScrollView.LayoutParams.WRAP_CONTENT; linearLayout.setLayoutParams(layoutParams2); titleTextView = new TextView(context); //titleTextView.setTextColor(0xff757575); titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); titleTextView.setGravity(Gravity.CENTER_HORIZONTAL); linearLayout.addView(titleTextView); LinearLayout.LayoutParams layoutParams3 = (LinearLayout.LayoutParams) titleTextView.getLayoutParams(); layoutParams3.width = LayoutHelper.WRAP_CONTENT; layoutParams3.height = LayoutHelper.WRAP_CONTENT; layoutParams3.gravity = Gravity.CENTER_HORIZONTAL; layoutParams3.topMargin = AndroidUtilities.dp(38); titleTextView.setLayoutParams(layoutParams3); passwordEditText = new EditText(context); passwordEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20); //passwordEditText.setTextColor(0xff000000); passwordEditText.setMaxLines(1); passwordEditText.setLines(1); passwordEditText.setGravity(Gravity.CENTER_HORIZONTAL); passwordEditText.setSingleLine(true); passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance()); passwordEditText.setTypeface(Typeface.DEFAULT); AndroidUtilities.clearCursorDrawable(passwordEditText); linearLayout.addView(passwordEditText); layoutParams3 = (LinearLayout.LayoutParams) passwordEditText.getLayoutParams(); layoutParams3.topMargin = AndroidUtilities.dp(32); layoutParams3.height = AndroidUtilities.dp(36); layoutParams3.leftMargin = AndroidUtilities.dp(40); layoutParams3.rightMargin = AndroidUtilities.dp(40); layoutParams3.gravity = Gravity.TOP | Gravity.LEFT; layoutParams3.width = LayoutHelper.MATCH_PARENT; passwordEditText.setLayoutParams(layoutParams3); passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (i == EditorInfo.IME_ACTION_NEXT || i == EditorInfo.IME_ACTION_DONE) { processDone(); return true; } return false; } }); passwordEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() { public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } public void onDestroyActionMode(ActionMode mode) { } public boolean onCreateActionMode(ActionMode mode, Menu menu) { return false; } public boolean onActionItemClicked(ActionMode mode, MenuItem item) { return false; } }); bottomTextView = new TextView(context); //bottomTextView.setTextColor(0xff757575); bottomTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); bottomTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP); bottomTextView.setText(LocaleController.getString("YourEmailInfo", R.string.YourEmailInfo)); linearLayout.addView(bottomTextView); layoutParams3 = (LinearLayout.LayoutParams) bottomTextView.getLayoutParams(); layoutParams3.width = LayoutHelper.WRAP_CONTENT; layoutParams3.height = LayoutHelper.WRAP_CONTENT; layoutParams3.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP; layoutParams3.topMargin = AndroidUtilities.dp(30); layoutParams3.leftMargin = AndroidUtilities.dp(40); layoutParams3.rightMargin = AndroidUtilities.dp(40); bottomTextView.setLayoutParams(layoutParams3); LinearLayout linearLayout2 = new LinearLayout(context); linearLayout2.setGravity(Gravity.BOTTOM | Gravity.CENTER_VERTICAL); linearLayout.addView(linearLayout2); layoutParams3 = (LinearLayout.LayoutParams) linearLayout2.getLayoutParams(); layoutParams3.width = LayoutHelper.MATCH_PARENT; layoutParams3.height = LayoutHelper.MATCH_PARENT; linearLayout2.setLayoutParams(layoutParams3); bottomButton = new TextView(context); bottomButton.setTextColor(0xff4d83b3); bottomButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); bottomButton.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM); bottomButton.setText(LocaleController.getString("YourEmailSkip", R.string.YourEmailSkip)); bottomButton.setPadding(0, AndroidUtilities.dp(10), 0, 0); linearLayout2.addView(bottomButton); layoutParams3 = (LinearLayout.LayoutParams) bottomButton.getLayoutParams(); layoutParams3.width = LayoutHelper.WRAP_CONTENT; layoutParams3.height = LayoutHelper.WRAP_CONTENT; layoutParams3.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM; layoutParams3.bottomMargin = AndroidUtilities.dp(14); layoutParams3.leftMargin = AndroidUtilities.dp(40); layoutParams3.rightMargin = AndroidUtilities.dp(40); bottomButton.setLayoutParams(layoutParams3); bottomButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (type == 0) { if (currentPassword.has_recovery) { needShowProgress(); TLRPC.TL_auth_requestPasswordRecovery req = new TLRPC.TL_auth_requestPasswordRecovery(); ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() { @Override public void run(final TLObject response, final TLRPC.TL_error error) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { needHideProgress(); if (error == null) { final TLRPC.TL_auth_passwordRecovery res = (TLRPC.TL_auth_passwordRecovery) response; AlertDialog.Builder builder = new AlertDialog.Builder( getParentActivity()); builder.setMessage(LocaleController.formatString("RestoreEmailSent", R.string.RestoreEmailSent, res.email_pattern)); 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) { TwoStepVerificationActivity fragment = new TwoStepVerificationActivity( 1); fragment.currentPassword = currentPassword; fragment.currentPassword.email_unconfirmed_pattern = res.email_pattern; fragment.passwordSetState = 4; presentFragment(fragment); } }); Dialog dialog = showDialog(builder.create()); if (dialog != null) { dialog.setCanceledOnTouchOutside(false); dialog.setCancelable(false); } } else { if (error.text.startsWith("FLOOD_WAIT")) { int time = Utilities.parseInt(error.text); String timeString; if (time < 60) { timeString = LocaleController.formatPluralString("Seconds", time); } else { timeString = LocaleController.formatPluralString("Minutes", time / 60); } showAlertWithText( LocaleController.getString("AppName", R.string.AppName), LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime, timeString)); } else { showAlertWithText( LocaleController.getString("AppName", R.string.AppName), error.text); } } } }); } }, ConnectionsManager.RequestFlagFailOnServerErrors | ConnectionsManager.RequestFlagWithoutLogin); } else { showAlertWithText( LocaleController.getString("RestorePasswordNoEmailTitle", R.string.RestorePasswordNoEmailTitle), LocaleController.getString("RestorePasswordNoEmailText", R.string.RestorePasswordNoEmailText)); } } else { if (passwordSetState == 4) { showAlertWithText( LocaleController.getString("RestorePasswordNoEmailTitle", R.string.RestorePasswordNoEmailTitle), LocaleController.getString("RestoreEmailTroubleText", R.string.RestoreEmailTroubleText)); } else { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("YourEmailSkipWarningText", R.string.YourEmailSkipWarningText)); builder.setTitle( LocaleController.getString("YourEmailSkipWarning", R.string.YourEmailSkipWarning)); builder.setPositiveButton( LocaleController.getString("YourEmailSkip", R.string.YourEmailSkip), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { email = ""; setNewPassword(false); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } } } }); if (type == 0) { progressView = new FrameLayout(context); frameLayout.addView(progressView); layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; progressView.setLayoutParams(layoutParams); progressView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); ProgressBar progressBar = new ProgressBar(context); progressView.addView(progressBar); layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams(); layoutParams.width = LayoutHelper.WRAP_CONTENT; layoutParams.height = LayoutHelper.WRAP_CONTENT; layoutParams.gravity = Gravity.CENTER; progressView.setLayoutParams(layoutParams); listView = new ListView(context); listView.setDivider(null); listView.setEmptyView(progressView); listView.setDividerHeight(0); listView.setVerticalScrollBarEnabled(false); listView.setDrawSelectorOnTop(true); frameLayout.addView(listView); layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; layoutParams.gravity = Gravity.TOP; listView.setLayoutParams(layoutParams); listView.setAdapter(listAdapter = new ListAdapter(context)); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) { if (i == setPasswordRow || i == changePasswordRow) { TwoStepVerificationActivity fragment = new TwoStepVerificationActivity(1); fragment.currentPasswordHash = currentPasswordHash; fragment.currentPassword = currentPassword; presentFragment(fragment); } else if (i == setRecoveryEmailRow || i == changeRecoveryEmailRow) { TwoStepVerificationActivity fragment = new TwoStepVerificationActivity(1); fragment.currentPasswordHash = currentPasswordHash; fragment.currentPassword = currentPassword; fragment.emailOnly = true; fragment.passwordSetState = 3; presentFragment(fragment); } else if (i == turnPasswordOffRow || i == abortPasswordRow) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("TurnPasswordOffQuestion", R.string.TurnPasswordOffQuestion)); 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) { setNewPassword(true); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } } }); updateRows(); actionBar.setTitle(LocaleController.getString("TwoStepVerification", R.string.TwoStepVerification)); titleTextView.setText( LocaleController.getString("PleaseEnterCurrentPassword", R.string.PleaseEnterCurrentPassword)); } else if (type == 1) { setPasswordSetState(passwordSetState); } return fragmentView; }
From source file:org.telegram.ui.Components.StickersAlert.java
private void init(Context context) { shadowDrawable = context.getResources().getDrawable(R.drawable.sheet_shadow); containerView = new FrameLayout(context) { private int lastNotifyWidth; @Override/*from w w w. j a v a 2 s. c o m*/ public boolean onInterceptTouchEvent(MotionEvent ev) { if (ev.getAction() == MotionEvent.ACTION_DOWN && scrollOffsetY != 0 && ev.getY() < scrollOffsetY) { dismiss(); return true; } return super.onInterceptTouchEvent(ev); } @Override public boolean onTouchEvent(MotionEvent e) { return !isDismissed() && super.onTouchEvent(e); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int height = MeasureSpec.getSize(heightMeasureSpec); if (Build.VERSION.SDK_INT >= 21) { height -= AndroidUtilities.statusBarHeight; } int contentSize; if (stickerSetCovereds != null) { contentSize = AndroidUtilities.dp(48 + 8) + AndroidUtilities.dp(60) * stickerSetCovereds.size() + adapter.stickersRowCount * AndroidUtilities.dp(82); } else { contentSize = AndroidUtilities.dp(48 + 48) + Math.max(3, (stickerSet != null ? (int) Math.ceil(stickerSet.documents.size() / 5.0f) : 0)) * AndroidUtilities.dp(82) + backgroundPaddingTop; } int padding = contentSize < (height / 5 * 3.2) ? 0 : (height / 5 * 2); if (padding != 0 && contentSize < height) { padding -= (height - contentSize); } if (padding == 0) { padding = backgroundPaddingTop; } if (stickerSetCovereds != null) { padding += AndroidUtilities.dp(8); } if (gridView.getPaddingTop() != padding) { ignoreLayout = true; gridView.setPadding(AndroidUtilities.dp(10), padding, AndroidUtilities.dp(10), 0); emptyView.setPadding(0, padding, 0, 0); ignoreLayout = false; } super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(Math.min(contentSize, height), MeasureSpec.EXACTLY)); } @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { if (lastNotifyWidth != right - left) { lastNotifyWidth = right - left; if (adapter != null && stickerSetCovereds != null) { adapter.notifyDataSetChanged(); } } super.onLayout(changed, left, top, right, bottom); updateLayout(); } @Override public void requestLayout() { if (ignoreLayout) { return; } super.requestLayout(); } @Override protected void onDraw(Canvas canvas) { shadowDrawable.setBounds(0, scrollOffsetY - backgroundPaddingTop, getMeasuredWidth(), getMeasuredHeight()); shadowDrawable.draw(canvas); } }; containerView.setWillNotDraw(false); containerView.setPadding(backgroundPaddingLeft, 0, backgroundPaddingLeft, 0); titleTextView = new TextView(context); titleTextView.setLines(1); titleTextView.setSingleLine(true); titleTextView.setTextColor( ContextCompat.getColor(context, R.color.primary_text) /*Theme.STICKERS_SHEET_TITLE_TEXT_COLOR*/); titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20); titleTextView.setEllipsize(TextUtils.TruncateAt.MIDDLE); titleTextView.setPadding(AndroidUtilities.dp(18), 0, AndroidUtilities.dp(18), 0); titleTextView.setGravity(Gravity.CENTER_VERTICAL); titleTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); containerView.addView(titleTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48)); titleTextView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); shadow[0] = new View(context); shadow[0].setBackgroundResource(R.drawable.header_shadow); shadow[0].setAlpha(0.0f); shadow[0].setVisibility(View.INVISIBLE); shadow[0].setTag(1); containerView.addView(shadow[0], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.TOP | Gravity.LEFT, 0, 48, 0, 0)); gridView = new RecyclerListView(context) { @Override public boolean onInterceptTouchEvent(MotionEvent event) { boolean result = StickerPreviewViewer.getInstance().onInterceptTouchEvent(event, gridView, 0); return super.onInterceptTouchEvent(event) || result; } @Override public void requestLayout() { if (ignoreLayout) { return; } super.requestLayout(); } }; gridView.setTag(14); gridView.setLayoutManager(layoutManager = new GridLayoutManager(getContext(), 5)); layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { if (stickerSetCovereds != null && adapter.cache.get(position) instanceof Integer || position == adapter.totalItems) { return adapter.stickersPerRow; } return 1; } }); gridView.setAdapter(adapter = new GridAdapter(context)); gridView.setVerticalScrollBarEnabled(false); gridView.addItemDecoration(new RecyclerView.ItemDecoration() { @Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { outRect.left = 0; outRect.right = 0; outRect.bottom = 0; outRect.top = 0; } }); gridView.setPadding(AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10), 0); gridView.setClipToPadding(false); gridView.setEnabled(true); gridView.setGlowColor(0xfff5f6f7); gridView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return StickerPreviewViewer.getInstance().onTouch(event, gridView, 0, stickersOnItemClickListener); } }); gridView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { updateLayout(); } }); stickersOnItemClickListener = new RecyclerListView.OnItemClickListener() { @Override public void onItemClick(View view, int position) { if (stickerSetCovereds != null) { TLRPC.StickerSetCovered pack = adapter.positionsToSets.get(position); if (pack != null) { dismiss(); TLRPC.TL_inputStickerSetID inputStickerSetID = new TLRPC.TL_inputStickerSetID(); inputStickerSetID.access_hash = pack.set.access_hash; inputStickerSetID.id = pack.set.id; StickersAlert alert = new StickersAlert(parentActivity, parentFragment, inputStickerSetID, null, null); alert.show(); } } else { if (stickerSet == null || position < 0 || position >= stickerSet.documents.size()) { return; } selectedSticker = stickerSet.documents.get(position); boolean set = false; for (int a = 0; a < selectedSticker.attributes.size(); a++) { TLRPC.DocumentAttribute attribute = selectedSticker.attributes.get(a); if (attribute instanceof TLRPC.TL_documentAttributeSticker) { if (attribute.alt != null && attribute.alt.length() > 0) { stickerEmojiTextView.setText(Emoji.replaceEmoji(attribute.alt, stickerEmojiTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(30), false)); set = true; } break; } } if (!set) { stickerEmojiTextView .setText(Emoji.replaceEmoji(StickersQuery.getEmojiForSticker(selectedSticker.id), stickerEmojiTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(30), false)); } stickerImageView.getImageReceiver().setImage(selectedSticker, null, selectedSticker.thumb.location, null, "webp", true); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) stickerPreviewLayout .getLayoutParams(); layoutParams.topMargin = scrollOffsetY; stickerPreviewLayout.setLayoutParams(layoutParams); stickerPreviewLayout.setVisibility(View.VISIBLE); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether(ObjectAnimator.ofFloat(stickerPreviewLayout, "alpha", 0.0f, 1.0f)); animatorSet.setDuration(200); animatorSet.start(); } } }; gridView.setOnItemClickListener(stickersOnItemClickListener); containerView.addView(gridView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 48, 0, 48)); emptyView = new FrameLayout(context) { @Override public void requestLayout() { if (ignoreLayout) { return; } super.requestLayout(); } }; containerView.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 48)); gridView.setEmptyView(emptyView); emptyView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); ProgressBar progressView = new ProgressBar(context); emptyView.addView(progressView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER)); shadow[1] = new View(context); shadow[1].setBackgroundResource(R.drawable.header_shadow_reverse); containerView.addView(shadow[1], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 48)); pickerBottomLayout = new PickerBottomLayout(context, false); containerView.addView(pickerBottomLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.BOTTOM)); pickerBottomLayout.cancelButton.setPadding(AndroidUtilities.dp(18), 0, AndroidUtilities.dp(18), 0); pickerBottomLayout.cancelButton.setTextColor(Theme.STICKERS_SHEET_CLOSE_TEXT_COLOR); pickerBottomLayout.cancelButton.setText(LocaleController.getString("Close", R.string.Close).toUpperCase()); pickerBottomLayout.cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dismiss(); } }); pickerBottomLayout.doneButton.setPadding(AndroidUtilities.dp(18), 0, AndroidUtilities.dp(18), 0); pickerBottomLayout.doneButtonBadgeTextView.setBackgroundResource(R.drawable.stickercounter); stickerPreviewLayout = new FrameLayout(context); if ((context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_YES) != 0) { stickerPreviewLayout.setBackgroundColor( 0x00ffffff & ContextCompat.getColor(context, R.color.card_background) | 0xdf000000); } else { stickerPreviewLayout.setBackgroundColor(0xdfffffff); } stickerPreviewLayout.setVisibility(View.GONE); stickerPreviewLayout.setSoundEffectsEnabled(false); containerView.addView(stickerPreviewLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); stickerPreviewLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { hidePreview(); } }); ImageView closeButton = new ImageView(context); closeButton.setImageResource(R.drawable.delete_reply); closeButton.setScaleType(ImageView.ScaleType.CENTER); if (Build.VERSION.SDK_INT >= 21) { closeButton.setBackgroundDrawable(Theme.createBarSelectorDrawable(Theme.INPUT_FIELD_SELECTOR_COLOR)); } stickerPreviewLayout.addView(closeButton, LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.TOP)); closeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { hidePreview(); } }); stickerImageView = new BackupImageView(context); stickerImageView.setAspectFit(true); stickerPreviewLayout.addView(stickerImageView); stickerEmojiTextView = new TextView(context); stickerEmojiTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 30); stickerEmojiTextView.setGravity(Gravity.BOTTOM | Gravity.RIGHT); stickerPreviewLayout.addView(stickerEmojiTextView); previewSendButton = new TextView(context); previewSendButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); previewSendButton.setTextColor(Theme.STICKERS_SHEET_SEND_TEXT_COLOR); previewSendButton.setGravity(Gravity.CENTER); previewSendButton.setBackgroundColor(ContextCompat.getColor(context, R.color.background)); previewSendButton.setPadding(AndroidUtilities.dp(29), 0, AndroidUtilities.dp(29), 0); previewSendButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); stickerPreviewLayout.addView(previewSendButton, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM | Gravity.LEFT)); previewSendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { delegate.onStickerSelected(selectedSticker); dismiss(); } }); previewSendButtonShadow = new View(context); previewSendButtonShadow.setBackgroundResource(R.drawable.header_shadow_reverse); stickerPreviewLayout.addView(previewSendButtonShadow, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 48)); NotificationCenter.getInstance().addObserver(this, NotificationCenter.emojiDidLoaded); updateFields(); updateSendButton(); adapter.notifyDataSetChanged(); }
From source file:in.andres.kandroid.ui.MainActivity.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2) private boolean showProgress(final boolean show) { // On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow // for very easy animations. If available, use these APIs to fade-in // the progress spinner. if (show)//from w ww.ja va 2 s.c om progressBarCount++; else progressBarCount = progressBarCount > 0 ? --progressBarCount : 0; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime); mMainView.setVisibility(progressBarCount > 0 ? View.GONE : View.VISIBLE); mMainView.animate().setDuration(shortAnimTime).alpha(progressBarCount > 0 ? 0 : 1) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mMainView.setVisibility(progressBarCount > 0 ? View.GONE : View.VISIBLE); } }); mProgress.setVisibility(progressBarCount > 0 ? View.VISIBLE : View.GONE); mProgress.animate().setDuration(shortAnimTime).alpha(progressBarCount > 0 ? 1 : 0) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mProgress.setVisibility(progressBarCount > 0 ? View.VISIBLE : View.GONE); } }); } else { // The ViewPropertyAnimator APIs are not available, so simply show // and hide the relevant UI components. mProgress.setVisibility(progressBarCount > 0 ? View.VISIBLE : View.GONE); mMainView.setVisibility(progressBarCount > 0 ? View.GONE : View.VISIBLE); } if (progressBarCount > 0 && refreshAction != null && !progressVisible) { ProgressBar prog = new ProgressBar(self); prog.getIndeterminateDrawable().setColorFilter(Color.WHITE, android.graphics.PorterDuff.Mode.MULTIPLY); refreshAction.setActionView(prog); refreshAction.expandActionView(); progressVisible = true; } if (progressBarCount == 0 && refreshAction != null && progressVisible) { refreshAction.collapseActionView(); refreshAction.setActionView(null); progressVisible = false; } return progressBarCount != 0; }
From source file:in.andres.kandroid.ui.TaskDetailActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); refreshAction = menu.findItem(R.id.action_refresh); if (activeRequests > 0 && refreshAction != null) { ProgressBar prog = new ProgressBar(self); prog.getIndeterminateDrawable().setColorFilter(Color.WHITE, android.graphics.PorterDuff.Mode.MULTIPLY); refreshAction.setActionView(prog); refreshAction.expandActionView(); progressVisible = true;/*from www . java 2 s .c o m*/ } return true; }
From source file:net.bluehack.ui.MediaActivity.java
@Override public View createView(Context context) { actionBar.setBackButtonDrawable(new BackDrawable(false)); actionBar.setTitle(""); actionBar.setAllowOverlayTitle(false); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override// w ww. j a v a2 s . c o m public void onItemClick(int id) { if (id == -1) { if (actionBar.isActionModeShowed()) { for (int a = 1; a >= 0; a--) { selectedFiles[a].clear(); } cantDeleteMessagesCount = 0; actionBar.hideActionMode(); listView.invalidateViews(); } else { finishFragment(); } } else if (id == shared_media_item) { if (selectedMode == 0) { return; } selectedMode = 0; switchToCurrentSelectedMode(); } else if (id == files_item) { if (selectedMode == 1) { return; } selectedMode = 1; switchToCurrentSelectedMode(); } else if (id == links_item) { if (selectedMode == 3) { return; } selectedMode = 3; switchToCurrentSelectedMode(); } else if (id == music_item) { if (selectedMode == 4) { return; } selectedMode = 4; switchToCurrentSelectedMode(); } else if (id == delete) { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.formatString("AreYouSureDeleteMessages", R.string.AreYouSureDeleteMessages, LocaleController.formatPluralString("items", selectedFiles[0].size() + selectedFiles[1].size()))); 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) { for (int a = 1; a >= 0; a--) { ArrayList<Integer> ids = new ArrayList<>(selectedFiles[a].keySet()); ArrayList<Long> random_ids = null; TLRPC.EncryptedChat currentEncryptedChat = null; int channelId = 0; if (!ids.isEmpty()) { MessageObject msg = selectedFiles[a].get(ids.get(0)); if (channelId == 0 && msg.messageOwner.to_id.channel_id != 0) { channelId = msg.messageOwner.to_id.channel_id; } } if ((int) dialog_id == 0) { currentEncryptedChat = MessagesController.getInstance() .getEncryptedChat((int) (dialog_id >> 32)); } if (currentEncryptedChat != null) { random_ids = new ArrayList<>(); for (HashMap.Entry<Integer, MessageObject> entry : selectedFiles[a] .entrySet()) { MessageObject msg = entry.getValue(); if (msg.messageOwner.random_id != 0 && msg.type != 10) { random_ids.add(msg.messageOwner.random_id); } } } MessagesController.getInstance().deleteMessages(ids, random_ids, currentEncryptedChat, channelId); selectedFiles[a].clear(); } actionBar.hideActionMode(); actionBar.closeSearchField(); cantDeleteMessagesCount = 0; } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } else if (id == forward) { Bundle args = new Bundle(); args.putBoolean("onlySelect", true); args.putInt("dialogsType", 1); DialogsActivity fragment = new DialogsActivity(args); fragment.setDelegate(new DialogsActivity.DialogsActivityDelegate() { @Override public void didSelectDialog(DialogsActivity fragment, long did, boolean param) { int lower_part = (int) did; if (lower_part != 0) { Bundle args = new Bundle(); args.putBoolean("scrollToTopOnResume", true); if (lower_part > 0) { args.putInt("user_id", lower_part); } else if (lower_part < 0) { args.putInt("chat_id", -lower_part); } if (!MessagesController.checkCanOpenChat(args, fragment)) { return; } ArrayList<MessageObject> fmessages = new ArrayList<>(); for (int a = 1; a >= 0; a--) { ArrayList<Integer> ids = new ArrayList<>(selectedFiles[a].keySet()); Collections.sort(ids); for (Integer id : ids) { if (id > 0) { fmessages.add(selectedFiles[a].get(id)); } } selectedFiles[a].clear(); } cantDeleteMessagesCount = 0; actionBar.hideActionMode(); NotificationCenter.getInstance() .postNotificationName(NotificationCenter.closeChats); ChatActivity chatActivity = new ChatActivity(args); presentFragment(chatActivity, true); chatActivity.showReplyPanel(true, null, fmessages, null, false, false); if (!AndroidUtilities.isTablet()) { removeSelfFromStack(); } } else { fragment.finishFragment(); } } }); presentFragment(fragment); } } }); for (int a = 1; a >= 0; a--) { selectedFiles[a].clear(); } cantDeleteMessagesCount = 0; actionModeViews.clear(); final ActionBarMenu menu = actionBar.createMenu(); searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true) .setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() { @Override public void onSearchExpand() { dropDownContainer.setVisibility(View.GONE); searching = true; } @Override public void onSearchCollapse() { dropDownContainer.setVisibility(View.VISIBLE); if (selectedMode == 1) { documentsSearchAdapter.search(null); } else if (selectedMode == 3) { linksSearchAdapter.search(null); } else if (selectedMode == 4) { audioSearchAdapter.search(null); } searching = false; searchWas = false; switchToCurrentSelectedMode(); } @Override public void onTextChanged(EditText editText) { String text = editText.getText().toString(); if (text.length() != 0) { searchWas = true; switchToCurrentSelectedMode(); } if (selectedMode == 1) { if (documentsSearchAdapter == null) { return; } documentsSearchAdapter.search(text); } else if (selectedMode == 3) { if (linksSearchAdapter == null) { return; } linksSearchAdapter.search(text); } else if (selectedMode == 4) { if (audioSearchAdapter == null) { return; } audioSearchAdapter.search(text); } } }); searchItem.getSearchField().setHint(LocaleController.getString("Search", R.string.Search)); searchItem.setVisibility(View.GONE); dropDownContainer = new ActionBarMenuItem(context, menu, 0); dropDownContainer.setSubMenuOpenSide(1); dropDownContainer.addSubItem(shared_media_item, LocaleController.getString("SharedMediaTitle", R.string.SharedMediaTitle), 0); dropDownContainer.addSubItem(files_item, LocaleController.getString("DocumentsTitle", R.string.DocumentsTitle), 0); if ((int) dialog_id != 0) { dropDownContainer.addSubItem(links_item, LocaleController.getString("LinksTitle", R.string.LinksTitle), 0); dropDownContainer.addSubItem(music_item, LocaleController.getString("AudioTitle", R.string.AudioTitle), 0); } else { TLRPC.EncryptedChat currentEncryptedChat = MessagesController.getInstance() .getEncryptedChat((int) (dialog_id >> 32)); if (currentEncryptedChat != null && AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) >= 46) { dropDownContainer.addSubItem(music_item, LocaleController.getString("AudioTitle", R.string.AudioTitle), 0); } } actionBar.addView(dropDownContainer, 0, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, AndroidUtilities.isTablet() ? 64 : 56, 0, 40, 0)); dropDownContainer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dropDownContainer.toggleSubMenu(); } }); dropDown = new TextView(context); dropDown.setGravity(Gravity.LEFT); dropDown.setSingleLine(true); dropDown.setLines(1); dropDown.setMaxLines(1); dropDown.setEllipsize(TextUtils.TruncateAt.END); dropDown.setTextColor(0xffffffff); dropDown.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); dropDown.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_arrow_drop_down, 0); dropDown.setCompoundDrawablePadding(AndroidUtilities.dp(4)); dropDown.setPadding(0, 0, AndroidUtilities.dp(10), 0); dropDownContainer.addView(dropDown, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL, 16, 0, 0, 0)); final ActionBarMenu actionMode = actionBar.createActionMode(); selectedMessagesCountTextView = new NumberTextView(actionMode.getContext()); selectedMessagesCountTextView.setTextSize(18); selectedMessagesCountTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); selectedMessagesCountTextView.setTextColor(0xff737373); selectedMessagesCountTextView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); actionMode.addView(selectedMessagesCountTextView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f, 65, 0, 0, 0)); if ((int) dialog_id != 0) { 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))); photoVideoAdapter = new SharedPhotoVideoAdapter(context); documentsAdapter = new SharedDocumentsAdapter(context, 1); audioAdapter = new SharedDocumentsAdapter(context, 4); documentsSearchAdapter = new MediaSearchAdapter(context, 1); audioSearchAdapter = new MediaSearchAdapter(context, 4); linksSearchAdapter = new MediaSearchAdapter(context, 3); linksAdapter = new SharedLinksAdapter(context); FrameLayout frameLayout; fragmentView = frameLayout = new FrameLayout(context); listView = new SectionsListView(context); listView.setDivider(null); listView.setDividerHeight(0); listView.setDrawSelectorOnTop(true); listView.setClipToPadding(false); frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) { if ((selectedMode == 1 || selectedMode == 4) && view instanceof SharedDocumentCell) { MediaActivity.this.onItemClick(i, view, ((SharedDocumentCell) view).getMessage(), 0); } else if (selectedMode == 3 && view instanceof SharedLinkCell) { MediaActivity.this.onItemClick(i, view, ((SharedLinkCell) view).getMessage(), 0); } } }); listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { if (scrollState == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) { AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus()); } scrolling = scrollState != SCROLL_STATE_IDLE; } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (searching && searchWas) { return; } if (visibleItemCount != 0 && firstVisibleItem + visibleItemCount > totalItemCount - 2 && !sharedMediaData[selectedMode].loading) { int type; if (selectedMode == 0) { type = SharedMediaQuery.MEDIA_PHOTOVIDEO; } else if (selectedMode == 1) { type = SharedMediaQuery.MEDIA_FILE; } else if (selectedMode == 2) { type = SharedMediaQuery.MEDIA_AUDIO; } else if (selectedMode == 4) { type = SharedMediaQuery.MEDIA_MUSIC; } else { type = SharedMediaQuery.MEDIA_URL; } if (!sharedMediaData[selectedMode].endReached[0]) { sharedMediaData[selectedMode].loading = true; SharedMediaQuery.loadMedia(dialog_id, 0, 50, sharedMediaData[selectedMode].max_id[0], type, true, classGuid); } else if (mergeDialogId != 0 && !sharedMediaData[selectedMode].endReached[1]) { sharedMediaData[selectedMode].loading = true; SharedMediaQuery.loadMedia(mergeDialogId, 0, 50, sharedMediaData[selectedMode].max_id[1], type, true, classGuid); } } } }); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int i, long id) { if ((selectedMode == 1 || selectedMode == 4) && view instanceof SharedDocumentCell) { SharedDocumentCell cell = (SharedDocumentCell) view; MessageObject message = cell.getMessage(); return MediaActivity.this.onItemLongClick(message, view, 0); } else if (selectedMode == 3 && view instanceof SharedLinkCell) { SharedLinkCell cell = (SharedLinkCell) view; MessageObject message = cell.getMessage(); return MediaActivity.this.onItemLongClick(message, view, 0); } return false; } }); for (int a = 0; a < 6; a++) { cellCache.add(new SharedPhotoVideoCell(context)); } emptyView = new LinearLayout(context); emptyView.setOrientation(LinearLayout.VERTICAL); emptyView.setGravity(Gravity.CENTER); emptyView.setVisibility(View.GONE); emptyView.setBackgroundColor(0xfff0f0f0); frameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); emptyView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); emptyImageView = new ImageView(context); emptyView.addView(emptyImageView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT)); emptyTextView = new TextView(context); emptyTextView.setTextColor(0xff8a8a8a); emptyTextView.setGravity(Gravity.CENTER); emptyTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17); emptyTextView.setPadding(AndroidUtilities.dp(40), 0, AndroidUtilities.dp(40), AndroidUtilities.dp(128)); emptyView.addView(emptyTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 0, 24, 0, 0)); progressView = new LinearLayout(context); progressView.setGravity(Gravity.CENTER); progressView.setOrientation(LinearLayout.VERTICAL); progressView.setVisibility(View.GONE); progressView.setBackgroundColor(0xfff0f0f0); frameLayout.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); ProgressBar progressBar = new ProgressBar(context); progressView.addView(progressBar, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT)); switchToCurrentSelectedMode(); if (!AndroidUtilities.isTablet()) { frameLayout.addView(new PlayerView(context, this), LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 39, Gravity.TOP | Gravity.LEFT, 0, -36, 0, 0)); } return fragmentView; }
From source file:kr.wdream.ui.MediaActivity.java
@Override public View createView(Context context) { Log.d(LOG_TAG, "createView"); actionBar.setBackButtonDrawable(new BackDrawable(false)); actionBar.setTitle(""); actionBar.setAllowOverlayTitle(false); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override/* ww w. j a va 2 s .c o m*/ public void onItemClick(int id) { if (id == -1) { if (actionBar.isActionModeShowed()) { for (int a = 1; a >= 0; a--) { selectedFiles[a].clear(); } cantDeleteMessagesCount = 0; actionBar.hideActionMode(); listView.invalidateViews(); } else { finishFragment(); } } else if (id == shared_media_item) { if (selectedMode == 0) { return; } selectedMode = 0; switchToCurrentSelectedMode(); } else if (id == files_item) { if (selectedMode == 1) { return; } selectedMode = 1; switchToCurrentSelectedMode(); } else if (id == links_item) { if (selectedMode == 3) { return; } selectedMode = 3; switchToCurrentSelectedMode(); } else if (id == music_item) { if (selectedMode == 4) { return; } selectedMode = 4; switchToCurrentSelectedMode(); } else if (id == delete) { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.formatString("AreYouSureDeleteMessages", kr.wdream.storyshop.R.string.AreYouSureDeleteMessages, LocaleController.formatPluralString("items", selectedFiles[0].size() + selectedFiles[1].size()))); builder.setTitle(LocaleController.getString("AppName", kr.wdream.storyshop.R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", kr.wdream.storyshop.R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { for (int a = 1; a >= 0; a--) { ArrayList<Integer> ids = new ArrayList<>(selectedFiles[a].keySet()); ArrayList<Long> random_ids = null; TLRPC.EncryptedChat currentEncryptedChat = null; int channelId = 0; if (!ids.isEmpty()) { MessageObject msg = selectedFiles[a].get(ids.get(0)); if (channelId == 0 && msg.messageOwner.to_id.channel_id != 0) { channelId = msg.messageOwner.to_id.channel_id; } } if ((int) dialog_id == 0) { currentEncryptedChat = MessagesController.getInstance() .getEncryptedChat((int) (dialog_id >> 32)); } if (currentEncryptedChat != null) { random_ids = new ArrayList<>(); for (HashMap.Entry<Integer, MessageObject> entry : selectedFiles[a] .entrySet()) { MessageObject msg = entry.getValue(); if (msg.messageOwner.random_id != 0 && msg.type != 10) { random_ids.add(msg.messageOwner.random_id); } } } MessagesController.getInstance().deleteMessages(ids, random_ids, currentEncryptedChat, channelId); selectedFiles[a].clear(); } actionBar.hideActionMode(); actionBar.closeSearchField(); cantDeleteMessagesCount = 0; } }); builder.setNegativeButton( LocaleController.getString("Cancel", kr.wdream.storyshop.R.string.Cancel), null); showDialog(builder.create()); } else if (id == forward) { Bundle args = new Bundle(); args.putBoolean("onlySelect", true); args.putInt("dialogsType", 1); DialogsActivity fragment = new DialogsActivity(args); fragment.setDelegate(new DialogsActivity.DialogsActivityDelegate() { @Override public void didSelectDialog(DialogsActivity fragment, long did, boolean param) { int lower_part = (int) did; if (lower_part != 0) { Bundle args = new Bundle(); args.putBoolean("scrollToTopOnResume", true); if (lower_part > 0) { args.putInt("user_id", lower_part); } else if (lower_part < 0) { args.putInt("chat_id", -lower_part); } if (!MessagesController.checkCanOpenChat(args, fragment)) { return; } ArrayList<MessageObject> fmessages = new ArrayList<>(); for (int a = 1; a >= 0; a--) { ArrayList<Integer> ids = new ArrayList<>(selectedFiles[a].keySet()); Collections.sort(ids); for (Integer id : ids) { if (id > 0) { fmessages.add(selectedFiles[a].get(id)); } } selectedFiles[a].clear(); } cantDeleteMessagesCount = 0; actionBar.hideActionMode(); NotificationCenter.getInstance() .postNotificationName(NotificationCenter.closeChats); ChatActivity chatActivity = new ChatActivity(args); presentFragment(chatActivity, true); chatActivity.showReplyPanel(true, null, fmessages, null, false, false); if (!AndroidUtilities.isTablet()) { removeSelfFromStack(); } } else { fragment.finishFragment(); } } }); presentFragment(fragment); } } }); for (int a = 1; a >= 0; a--) { selectedFiles[a].clear(); } cantDeleteMessagesCount = 0; actionModeViews.clear(); final ActionBarMenu menu = actionBar.createMenu(); searchItem = menu.addItem(0, kr.wdream.storyshop.R.drawable.ic_ab_search).setIsSearchField(true) .setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() { @Override public void onSearchExpand() { dropDownContainer.setVisibility(View.GONE); searching = true; } @Override public void onSearchCollapse() { dropDownContainer.setVisibility(View.VISIBLE); if (selectedMode == 1) { documentsSearchAdapter.search(null); } else if (selectedMode == 3) { linksSearchAdapter.search(null); } else if (selectedMode == 4) { audioSearchAdapter.search(null); } searching = false; searchWas = false; switchToCurrentSelectedMode(); } @Override public void onTextChanged(EditText editText) { String text = editText.getText().toString(); if (text.length() != 0) { searchWas = true; switchToCurrentSelectedMode(); } if (selectedMode == 1) { if (documentsSearchAdapter == null) { return; } documentsSearchAdapter.search(text); } else if (selectedMode == 3) { if (linksSearchAdapter == null) { return; } linksSearchAdapter.search(text); } else if (selectedMode == 4) { if (audioSearchAdapter == null) { return; } audioSearchAdapter.search(text); } } }); searchItem.getSearchField() .setHint(LocaleController.getString("Search", kr.wdream.storyshop.R.string.Search)); searchItem.setVisibility(View.GONE); dropDownContainer = new ActionBarMenuItem(context, menu, 0); dropDownContainer.setSubMenuOpenSide(1); dropDownContainer.addSubItem(shared_media_item, LocaleController.getString("SharedMediaTitle", kr.wdream.storyshop.R.string.SharedMediaTitle), 0); dropDownContainer.addSubItem(files_item, LocaleController.getString("DocumentsTitle", kr.wdream.storyshop.R.string.DocumentsTitle), 0); if ((int) dialog_id != 0) { dropDownContainer.addSubItem(links_item, LocaleController.getString("LinksTitle", kr.wdream.storyshop.R.string.LinksTitle), 0); dropDownContainer.addSubItem(music_item, LocaleController.getString("AudioTitle", kr.wdream.storyshop.R.string.AudioTitle), 0); } else { TLRPC.EncryptedChat currentEncryptedChat = MessagesController.getInstance() .getEncryptedChat((int) (dialog_id >> 32)); if (currentEncryptedChat != null && AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) >= 46) { dropDownContainer.addSubItem(music_item, LocaleController.getString("AudioTitle", kr.wdream.storyshop.R.string.AudioTitle), 0); } } actionBar.addView(dropDownContainer, 0, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, AndroidUtilities.isTablet() ? 64 : 56, 0, 40, 0)); dropDownContainer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dropDownContainer.toggleSubMenu(); } }); dropDown = new TextView(context); dropDown.setGravity(Gravity.LEFT); dropDown.setSingleLine(true); dropDown.setLines(1); dropDown.setMaxLines(1); dropDown.setEllipsize(TextUtils.TruncateAt.END); dropDown.setTextColor(0xffffffff); dropDown.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); dropDown.setCompoundDrawablesWithIntrinsicBounds(0, 0, kr.wdream.storyshop.R.drawable.ic_arrow_drop_down, 0); dropDown.setCompoundDrawablePadding(AndroidUtilities.dp(4)); dropDown.setPadding(0, 0, AndroidUtilities.dp(10), 0); dropDownContainer.addView(dropDown, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL, 16, 0, 0, 0)); final ActionBarMenu actionMode = actionBar.createActionMode(); selectedMessagesCountTextView = new NumberTextView(actionMode.getContext()); selectedMessagesCountTextView.setTextSize(18); selectedMessagesCountTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); selectedMessagesCountTextView.setTextColor(0xff737373); selectedMessagesCountTextView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); actionMode.addView(selectedMessagesCountTextView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f, 65, 0, 0, 0)); if ((int) dialog_id != 0) { actionModeViews.add(actionMode.addItem(forward, kr.wdream.storyshop.R.drawable.ic_ab_fwd_forward, Theme.ACTION_BAR_MODE_SELECTOR_COLOR, null, AndroidUtilities.dp(54))); } actionModeViews.add(actionMode.addItem(delete, kr.wdream.storyshop.R.drawable.ic_ab_fwd_delete, Theme.ACTION_BAR_MODE_SELECTOR_COLOR, null, AndroidUtilities.dp(54))); photoVideoAdapter = new SharedPhotoVideoAdapter(context); documentsAdapter = new SharedDocumentsAdapter(context, 1); audioAdapter = new SharedDocumentsAdapter(context, 4); documentsSearchAdapter = new MediaSearchAdapter(context, 1); audioSearchAdapter = new MediaSearchAdapter(context, 4); linksSearchAdapter = new MediaSearchAdapter(context, 3); linksAdapter = new SharedLinksAdapter(context); FrameLayout frameLayout; fragmentView = frameLayout = new FrameLayout(context); listView = new SectionsListView(context); listView.setDivider(null); listView.setDividerHeight(0); listView.setDrawSelectorOnTop(true); listView.setClipToPadding(false); frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) { if ((selectedMode == 1 || selectedMode == 4) && view instanceof SharedDocumentCell) { MediaActivity.this.onItemClick(i, view, ((SharedDocumentCell) view).getMessage(), 0); } else if (selectedMode == 3 && view instanceof SharedLinkCell) { MediaActivity.this.onItemClick(i, view, ((SharedLinkCell) view).getMessage(), 0); } } }); listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { if (scrollState == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) { AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus()); } scrolling = scrollState != SCROLL_STATE_IDLE; } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (searching && searchWas) { return; } if (visibleItemCount != 0 && firstVisibleItem + visibleItemCount > totalItemCount - 2 && !sharedMediaData[selectedMode].loading) { int type; if (selectedMode == 0) { type = SharedMediaQuery.MEDIA_PHOTOVIDEO; } else if (selectedMode == 1) { type = SharedMediaQuery.MEDIA_FILE; } else if (selectedMode == 2) { type = SharedMediaQuery.MEDIA_AUDIO; } else if (selectedMode == 4) { type = SharedMediaQuery.MEDIA_MUSIC; } else { type = SharedMediaQuery.MEDIA_URL; } if (!sharedMediaData[selectedMode].endReached[0]) { sharedMediaData[selectedMode].loading = true; SharedMediaQuery.loadMedia(dialog_id, 0, 50, sharedMediaData[selectedMode].max_id[0], type, true, classGuid); } else if (mergeDialogId != 0 && !sharedMediaData[selectedMode].endReached[1]) { sharedMediaData[selectedMode].loading = true; SharedMediaQuery.loadMedia(mergeDialogId, 0, 50, sharedMediaData[selectedMode].max_id[1], type, true, classGuid); } } } }); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int i, long id) { if ((selectedMode == 1 || selectedMode == 4) && view instanceof SharedDocumentCell) { SharedDocumentCell cell = (SharedDocumentCell) view; MessageObject message = cell.getMessage(); return MediaActivity.this.onItemLongClick(message, view, 0); } else if (selectedMode == 3 && view instanceof SharedLinkCell) { SharedLinkCell cell = (SharedLinkCell) view; MessageObject message = cell.getMessage(); return MediaActivity.this.onItemLongClick(message, view, 0); } return false; } }); for (int a = 0; a < 6; a++) { cellCache.add(new SharedPhotoVideoCell(context)); } emptyView = new LinearLayout(context); emptyView.setOrientation(LinearLayout.VERTICAL); emptyView.setGravity(Gravity.CENTER); emptyView.setVisibility(View.GONE); emptyView.setBackgroundColor(0xfff0f0f0); frameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); emptyView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); emptyImageView = new ImageView(context); emptyView.addView(emptyImageView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT)); emptyTextView = new TextView(context); emptyTextView.setTextColor(0xff8a8a8a); emptyTextView.setGravity(Gravity.CENTER); emptyTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17); emptyTextView.setPadding(AndroidUtilities.dp(40), 0, AndroidUtilities.dp(40), AndroidUtilities.dp(128)); emptyView.addView(emptyTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 0, 24, 0, 0)); progressView = new LinearLayout(context); progressView.setGravity(Gravity.CENTER); progressView.setOrientation(LinearLayout.VERTICAL); progressView.setVisibility(View.GONE); progressView.setBackgroundColor(0xfff0f0f0); frameLayout.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); ProgressBar progressBar = new ProgressBar(context); progressView.addView(progressBar, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT)); switchToCurrentSelectedMode(); if (!AndroidUtilities.isTablet()) { frameLayout.addView(new PlayerView(context, this), LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 39, Gravity.TOP | Gravity.LEFT, 0, -36, 0, 0)); } return fragmentView; }