List of usage examples for android.widget FrameLayout getLayoutParams
@ViewDebug.ExportedProperty(deepExport = true, prefix = "layout_") public ViewGroup.LayoutParams getLayoutParams()
From source file:tv.ouya.sdk.OuyaUnityPlugin.java
private static void updateSafeArea(float progress) { // bring in by % float percent = 0.1f; float ratio = 1 - (1 - progress) * percent; float halfRatio = 1 - (1 - progress) * percent * 0.5f; float maxWidth = getDisplayWidth(); float maxHeight = getDisplayHeight(); Activity activity = IOuyaActivity.GetActivity(); FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content); LayoutParams layout = content.getLayoutParams(); layout.width = (int) (maxWidth * ratio); layout.height = (int) (maxHeight * ratio); content.setLayoutParams(layout);/*from www.ja v a2 s. c om*/ content.setX(maxWidth - maxWidth * halfRatio); content.setY(maxHeight - maxHeight * halfRatio); }
From source file:com.amaze.filemanager.activities.TextReader.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.search);/*from w w w . ja v a2s . c o m*/ ma = (EditText) findViewById(R.id.fname); p = (ProgressBar) findViewById(R.id.pbar); ma.setVisibility(View.GONE); String skin = PreferenceManager.getDefaultSharedPreferences(this).getString("skin_color", "#5677fc"); getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(skin))); if (Build.VERSION.SDK_INT >= 19) { SystemBarTintManager tintManager = new SystemBarTintManager(this); tintManager.setStatusBarTintEnabled(true); tintManager.setStatusBarTintColor(Color.parseColor(skin)); FrameLayout a = (FrameLayout) ma.getParent(); FrameLayout.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) a.getLayoutParams(); SystemBarTintManager.SystemBarConfig config = tintManager.getConfig(); p.setMargins(0, config.getPixelInsetTop(true), 0, 0); } path = this.getIntent().getStringExtra("path"); if (path != null) { Toast.makeText(this, "" + path, Toast.LENGTH_SHORT).show(); new LoadText().execute(path); } else { Toast.makeText(this, utils.getString(this, R.string.cant_read_file), Toast.LENGTH_LONG).show(); finish(); } getActionBar().setTitle(new File(path).getName()); getActionBar().setSubtitle(path); }
From source file:com.tomeokin.lspush.biz.collect.ImageDialogFragment.java
@SuppressLint("InflateParams") @NonNull/*from ww w .j a v a 2s . c o m*/ @Override protected BaseDialogFragment.Builder config(@NonNull BaseDialogFragment.Builder builder) { ImageView imageView = (ImageView) LayoutInflater.from(getContext()).inflate(R.layout.dialog_image, null); builder.setTitle(R.string.use_current_image).addCustomMessageView(imageView) .addPositiveButton(R.string.dialog_ok, this).addNegativeButton(R.string.dialog_cancel, this); final String url = getArguments().getString(ARG_IMAGE_URL); final Uri uri = Uri.parse(url); int width = getArguments().getInt(ARG_IMAGE_WIDTH); int height = getArguments().getInt(ARG_IMAGE_HEIGHT); final View content = getActivity().getWindow().findViewById(Window.ID_ANDROID_CONTENT); final FrameLayout container = builder.getCustomViewHolder(); final float radio = optimumRadio(content, container, width, height); width = (int) (width * radio); height = (int) (height * radio); ViewGroup.LayoutParams lp = container.getLayoutParams(); lp.width = width + container.getPaddingLeft() + container.getPaddingRight(); lp.height = height + container.getPaddingTop() + container.getPaddingBottom(); Glide.with(this).load(uri).diskCacheStrategy(DiskCacheStrategy.ALL).override(width, height).fitCenter() .into(imageView); return builder; }
From source file:com.tomeokin.lspush.biz.home.UriDialogFragment.java
@SuppressLint("InflateParams") @NonNull/*from w w w . ja va 2 s.c o m*/ @Override protected BaseDialogFragment.Builder config(@NonNull BaseDialogFragment.Builder builder) { View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_add_link, null); builder.addCustomMessageView(view); final View content = getActivity().getWindow().findViewById(Window.ID_ANDROID_CONTENT); final FrameLayout container = builder.getCustomViewHolder(); ViewGroup.LayoutParams lp = container.getLayoutParams(); lp.width = content.getWidth() / 6 * 5; container.setLayoutParams(lp); mUrlField = (EditText) view.findViewById(R.id.url_field); mNextButton = (TextView) view.findViewById(R.id.next_button); mNextButton.setTextColor(Color.BLACK); mNextButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getUrlInfo(); } }); mNextButton.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_NEXT && isAvailableCheck() && isValidWebUri(mUrlField.getText())) { getUrlInfo(); return true; } return false; } }); Drawable clear = getContext().getDrawable(R.drawable.search_clear); DrawableCompat.setTint(clear, ContextCompat.getColor(getContext(), R.color.blue_5_whiteout)); mNextButton.setCompoundDrawables(null, null, clear, null); mProgressBar = (ProgressBar) view.findViewById(R.id.next_progress); final String text = ClipboardUtils.getText(getContext()); if (!TextUtils.isEmpty(text) && isValidWebUri(text)) { mUrlField.setText(text); activeNextButton(); } else { disableNextButton(); } return builder; }
From source file:com.woodblockwithoutco.quickcontroldock.ui.factory.ServiceViewFactory.java
private void adjustPanelMargins(FrameLayout container) { LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) container.getLayoutParams(); params.topMargin = GeneralResolver.getPanelsMargin(mContext); params.bottomMargin = GeneralResolver.getPanelsMargin(mContext); container.setLayoutParams(params);/*from w w w . j a v a 2 s . c o m*/ }
From source file:org.anothermonitor.ActivityPreferences.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_preferences); mPrefs = getSharedPreferences(getString(R.string.app_name) + "Prefs", MODE_PRIVATE); res = getResources();/* w w w. ja va 2s .co m*/ navigationBarHeight = res .getDimensionPixelSize(res.getIdentifier("navigation_bar_height", "dimen", "android")); mLTabs = (LinearLayout) findViewById(R.id.LTabs); if (Build.VERSION.SDK_INT >= 19) { getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); sSW = res.getConfiguration().smallestScreenWidthDp; int statusBarHeight = res .getDimensionPixelSize(res.getIdentifier("status_bar_height", "dimen", "android")); if (!ViewConfiguration.get(this).hasPermanentMenuKey() && (res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || sSW > 560)) { getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); FrameLayout nb = (FrameLayout) findViewById(R.id.LNavigationBar); nb.setVisibility(View.VISIBLE); ((FrameLayout.LayoutParams) nb.getLayoutParams()).height = navigationBarHeight; } int paddingTop = mLTabs.getPaddingTop(); int paddingBottom = mLTabs.getPaddingBottom(); int paddingLeft = mLTabs.getPaddingLeft(); int paddingRight = mLTabs.getPaddingRight(); mLTabs.setPadding(paddingLeft, paddingTop + statusBarHeight, paddingRight, paddingBottom); } findViewById(R.id.TVTabMain).setActivated(true); findViewById(R.id.TVTabMain).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mVP.setCurrentItem(0); } }); findViewById(R.id.TVTabShowRecord).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mVP.setCurrentItem(1); } }); mVP = (ViewPager) findViewById(R.id.VP); mVP.setAdapter(new MyPreferencesAdapter()); // mVP.setOffscreenPageLimit(2); mVP.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageSelected(int position) { int currentItem = 0; if (position == 1) currentItem = 2; mLTabs.getChildAt(currentItem).setActivated(true); mLTabs.getChildAt(previousSelected).setActivated(false); previousSelected = currentItem; } @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageScrollStateChanged(int arg0) { } }); mVP.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { mVP.getViewTreeObserver().removeGlobalOnLayoutListener(this); if (currentItem != -1) mVP.setCurrentItem(currentItem, false); } }); if (savedInstanceState != null && !savedInstanceState.isEmpty()) { mB = savedInstanceState; currentItem = savedInstanceState.getInt(C.currentItem); currentItem = savedInstanceState.getInt(C.currentItem); currentItem = savedInstanceState.getInt(C.currentItem); currentItem = savedInstanceState.getInt(C.currentItem); } }
From source file:org.telegram.ui.ContactAddActivity.java
@Override public View createView(Context context) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); if (addContact) { actionBar.setTitle(LocaleController.getString("AddContactTitle", R.string.AddContactTitle)); } else {//from w ww . j av a 2s.co m actionBar.setTitle(LocaleController.getString("EditName", R.string.EditName)); } actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(int id) { if (id == -1) { finishFragment(); } else if (id == done_button) { if (firstNameField.getText().length() != 0) { TLRPC.User user = MessagesController.getInstance().getUser(user_id); user.first_name = firstNameField.getText().toString(); user.last_name = lastNameField.getText().toString(); ContactsController.getInstance().addContact(user); finishFragment(); SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); preferences.edit().putInt("spam3_" + user_id, 1).commit(); NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces, MessagesController.UPDATE_MASK_NAME); } } } }); ActionBarMenu menu = actionBar.createMenu(); doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56)); fragmentView = new ScrollView(context); LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.VERTICAL); ((ScrollView) fragmentView).addView(linearLayout); ScrollView.LayoutParams layoutParams2 = (ScrollView.LayoutParams) linearLayout.getLayoutParams(); layoutParams2.width = ScrollView.LayoutParams.MATCH_PARENT; layoutParams2.height = ScrollView.LayoutParams.WRAP_CONTENT; linearLayout.setLayoutParams(layoutParams2); linearLayout.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); FrameLayout frameLayout = new FrameLayout(context); linearLayout.addView(frameLayout); LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) frameLayout.getLayoutParams(); layoutParams.topMargin = AndroidUtilities.dp(24); layoutParams.leftMargin = AndroidUtilities.dp(24); layoutParams.rightMargin = AndroidUtilities.dp(24); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.WRAP_CONTENT; frameLayout.setLayoutParams(layoutParams); avatarImage = new BackupImageView(context); avatarImage.setRoundRadius(AndroidUtilities.dp(30)); frameLayout.addView(avatarImage); FrameLayout.LayoutParams layoutParams3 = (FrameLayout.LayoutParams) avatarImage.getLayoutParams(); layoutParams3.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP; layoutParams3.width = AndroidUtilities.dp(60); layoutParams3.height = AndroidUtilities.dp(60); avatarImage.setLayoutParams(layoutParams3); nameTextView = new TextView(context); nameTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text)); nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20); nameTextView.setLines(1); nameTextView.setMaxLines(1); nameTextView.setSingleLine(true); nameTextView.setEllipsize(TextUtils.TruncateAt.END); nameTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT)); nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); frameLayout.addView(nameTextView); layoutParams3 = (FrameLayout.LayoutParams) nameTextView.getLayoutParams(); layoutParams3.width = LayoutHelper.WRAP_CONTENT; layoutParams3.height = LayoutHelper.WRAP_CONTENT; layoutParams3.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 0 : 80); layoutParams3.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 80 : 0); layoutParams3.topMargin = AndroidUtilities.dp(3); layoutParams3.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP; nameTextView.setLayoutParams(layoutParams3); onlineTextView = new TextView(context); onlineTextView.setTextColor(0xff999999); onlineTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); onlineTextView.setLines(1); onlineTextView.setMaxLines(1); onlineTextView.setSingleLine(true); onlineTextView.setEllipsize(TextUtils.TruncateAt.END); onlineTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT)); frameLayout.addView(onlineTextView); layoutParams3 = (FrameLayout.LayoutParams) onlineTextView.getLayoutParams(); layoutParams3.width = LayoutHelper.WRAP_CONTENT; layoutParams3.height = LayoutHelper.WRAP_CONTENT; layoutParams3.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 0 : 80); layoutParams3.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 80 : 0); layoutParams3.topMargin = AndroidUtilities.dp(32); layoutParams3.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP; onlineTextView.setLayoutParams(layoutParams3); firstNameField = new EditText(context); firstNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); //firstNameField.setHintTextColor(0xff979797); firstNameField.setTextColor(ContextCompat.getColor(context, R.color.primary_text)); firstNameField.setMaxLines(1); firstNameField.setLines(1); firstNameField.setSingleLine(true); firstNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT); firstNameField.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT); firstNameField.setImeOptions(EditorInfo.IME_ACTION_NEXT); firstNameField.setHint(LocaleController.getString("FirstName", R.string.FirstName)); AndroidUtilities.clearCursorDrawable(firstNameField); linearLayout.addView(firstNameField); layoutParams = (LinearLayout.LayoutParams) firstNameField.getLayoutParams(); layoutParams.topMargin = AndroidUtilities.dp(24); layoutParams.height = AndroidUtilities.dp(36); layoutParams.leftMargin = AndroidUtilities.dp(24); layoutParams.rightMargin = AndroidUtilities.dp(24); layoutParams.width = LayoutHelper.MATCH_PARENT; firstNameField.setLayoutParams(layoutParams); firstNameField.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (i == EditorInfo.IME_ACTION_NEXT) { lastNameField.requestFocus(); lastNameField.setSelection(lastNameField.length()); return true; } return false; } }); lastNameField = new EditText(context); lastNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); //lastNameField.setHintTextColor(0xff979797); lastNameField.setTextColor(ContextCompat.getColor(context, R.color.primary_text)); lastNameField.setMaxLines(1); lastNameField.setLines(1); lastNameField.setSingleLine(true); lastNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT); lastNameField.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT); lastNameField.setImeOptions(EditorInfo.IME_ACTION_DONE); lastNameField.setHint(LocaleController.getString("LastName", R.string.LastName)); AndroidUtilities.clearCursorDrawable(lastNameField); linearLayout.addView(lastNameField); layoutParams = (LinearLayout.LayoutParams) lastNameField.getLayoutParams(); layoutParams.topMargin = AndroidUtilities.dp(16); layoutParams.height = AndroidUtilities.dp(36); layoutParams.leftMargin = AndroidUtilities.dp(24); layoutParams.rightMargin = AndroidUtilities.dp(24); layoutParams.width = LayoutHelper.MATCH_PARENT; lastNameField.setLayoutParams(layoutParams); lastNameField.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (i == EditorInfo.IME_ACTION_DONE) { doneButton.performClick(); return true; } return false; } }); TLRPC.User user = MessagesController.getInstance().getUser(user_id); if (user != null) { if (user.phone == null) { if (phone != null) { user.phone = PhoneFormat.stripExceptNumbers(phone); } } firstNameField.setText(user.first_name); firstNameField.setSelection(firstNameField.length()); lastNameField.setText(user.last_name); } return fragmentView; }
From source file:org.floens.chan.ui.activity.BoardActivity.java
private void updatePaneState() { DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); int width = metrics.widthPixels; FrameLayout left = (FrameLayout) findViewById(R.id.left_pane); FrameLayout right = (FrameLayout) findViewById(R.id.right_pane); LayoutParams leftParams = left.getLayoutParams(); LayoutParams rightParams = right.getLayoutParams(); // Content view dp's: // Nexus 4 is 384 x 640 dp // Nexus 7 is 600 x 960 dp // Nexus 10 is 800 x 1280 dp if (width < Utils.dp(800)) { if (width < Utils.dp(400)) { leftParams.width = width - Utils.dp(30); } else {// w w w.j ava 2s .c om leftParams.width = width - Utils.dp(150); } rightParams.width = width; } else { leftParams.width = Utils.dp(300); rightParams.width = width - Utils.dp(300); } left.setLayoutParams(leftParams); right.setLayoutParams(rightParams); threadPane.requestLayout(); left.requestLayout(); right.requestLayout(); }
From source file:org.telegram.ui.LanguageSelectActivity.java
@Override public View createView(Context context) { searching = false;/* w ww .j a va 2s . c o m*/ searchWas = false; actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); actionBar.setTitle(LocaleController.getString("Language", R.string.Language)); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(int id) { if (id == -1) { finishFragment(); } } }); ActionBarMenu menu = actionBar.createMenu(); ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true) .setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() { @Override public void onSearchExpand() { searching = true; } @Override public void onSearchCollapse() { search(null); searching = false; searchWas = false; if (listView != null) { emptyTextView.setVisibility(View.GONE); listView.setAdapter(listAdapter); } } @Override public void onTextChanged(EditText editText) { String text = editText.getText().toString(); search(text); if (text.length() != 0) { searchWas = true; if (listView != null) { listView.setAdapter(searchListViewAdapter); } } } }); item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search)); listAdapter = new ListAdapter(context); searchListViewAdapter = new SearchAdapter(context); fragmentView = new FrameLayout(context); fragmentView.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background)); LinearLayout emptyTextLayout = new LinearLayout(context); emptyTextLayout.setVisibility(View.INVISIBLE); emptyTextLayout.setOrientation(LinearLayout.VERTICAL); ((FrameLayout) fragmentView).addView(emptyTextLayout); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) emptyTextLayout.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; layoutParams.gravity = Gravity.TOP; emptyTextLayout.setLayoutParams(layoutParams); emptyTextLayout.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); emptyTextView = new TextView(context); emptyTextView.setTextColor(0xff808080); emptyTextView.setTextSize(20); emptyTextView.setGravity(Gravity.CENTER); emptyTextView.setText(LocaleController.getString("NoResult", R.string.NoResult)); emptyTextLayout.addView(emptyTextView); LinearLayout.LayoutParams layoutParams1 = (LinearLayout.LayoutParams) emptyTextView.getLayoutParams(); layoutParams1.width = LayoutHelper.MATCH_PARENT; layoutParams1.height = LayoutHelper.MATCH_PARENT; layoutParams1.weight = 0.5f; emptyTextView.setLayoutParams(layoutParams1); FrameLayout frameLayout = new FrameLayout(context); emptyTextLayout.addView(frameLayout); layoutParams1 = (LinearLayout.LayoutParams) frameLayout.getLayoutParams(); layoutParams1.width = LayoutHelper.MATCH_PARENT; layoutParams1.height = LayoutHelper.MATCH_PARENT; layoutParams1.weight = 0.5f; frameLayout.setLayoutParams(layoutParams1); listView = new ListView(context); listView.setEmptyView(emptyTextLayout); listView.setVerticalScrollBarEnabled(false); listView.setDivider(null); listView.setDividerHeight(0); listView.setAdapter(listAdapter); ((FrameLayout) fragmentView).addView(listView); layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; listView.setLayoutParams(layoutParams); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { LocaleController.LocaleInfo localeInfo = null; if (searching && searchWas) { if (i >= 0 && i < searchResult.size()) { localeInfo = searchResult.get(i); } } else { if (i >= 0 && i < LocaleController.getInstance().sortedLanguages.size()) { localeInfo = LocaleController.getInstance().sortedLanguages.get(i); } } if (localeInfo != null) { LocaleController.getInstance().applyLanguage(localeInfo, true); parentLayout.rebuildAllFragmentViews(false); } finishFragment(); } }); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) { LocaleController.LocaleInfo localeInfo = null; if (searching && searchWas) { if (i >= 0 && i < searchResult.size()) { localeInfo = searchResult.get(i); } } else { if (i >= 0 && i < LocaleController.getInstance().sortedLanguages.size()) { localeInfo = LocaleController.getInstance().sortedLanguages.get(i); } } if (localeInfo == null || localeInfo.pathToFile == null || getParentActivity() == null) { return false; } final LocaleController.LocaleInfo finalLocaleInfo = localeInfo; AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("DeleteLocalization", R.string.DeleteLocalization)); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("Delete", R.string.Delete), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if (LocaleController.getInstance().deleteLanguage(finalLocaleInfo)) { if (searchResult != null) { searchResult.remove(finalLocaleInfo); } if (listAdapter != null) { listAdapter.notifyDataSetChanged(); } if (searchListViewAdapter != null) { searchListViewAdapter.notifyDataSetChanged(); } } } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); return true; } }); listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView absListView, int i) { if (i == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) { AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus()); } } @Override public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { } }); return fragmentView; }
From source file:org.telegram.ui.SessionsActivity.java
@Override public View createView(Context context) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); actionBar.setTitle(LocaleController.getString("SessionsTitle", R.string.SessionsTitle)); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override//from ww w .j a va2s .c o m public void onItemClick(int id) { if (id == -1) { finishFragment(); } } }); listAdapter = new ListAdapter(context); fragmentView = new FrameLayout(context); FrameLayout frameLayout = (FrameLayout) fragmentView; frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background)); emptyLayout = new LinearLayout(context); emptyLayout.setOrientation(LinearLayout.VERTICAL); emptyLayout.setGravity(Gravity.CENTER); //emptyLayout.setBackgroundResource(R.drawable.greydivider_bottom); emptyLayout.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, AndroidUtilities.displaySize.y - ActionBar.getCurrentActionBarHeight())); ImageView imageView = new ImageView(context); imageView.setImageResource(R.drawable.devices); emptyLayout.addView(imageView); LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams) imageView.getLayoutParams(); layoutParams2.width = LayoutHelper.WRAP_CONTENT; layoutParams2.height = LayoutHelper.WRAP_CONTENT; imageView.setLayoutParams(layoutParams2); TextView textView = new TextView(context); textView.setTextColor(ContextCompat.getColor(context, R.color.disabled_text) /*0xff8a8a8a*/); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17); textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); textView.setText(LocaleController.getString("NoOtherSessions", R.string.NoOtherSessions)); emptyLayout.addView(textView); layoutParams2 = (LinearLayout.LayoutParams) textView.getLayoutParams(); layoutParams2.topMargin = AndroidUtilities.dp(16); layoutParams2.width = LayoutHelper.WRAP_CONTENT; layoutParams2.height = LayoutHelper.WRAP_CONTENT; layoutParams2.gravity = Gravity.CENTER; textView.setLayoutParams(layoutParams2); textView = new TextView(context); textView.setTextColor(ContextCompat.getColor(context, R.color.disabled_text) /*0xff8a8a8a*/); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17); textView.setPadding(AndroidUtilities.dp(20), 0, AndroidUtilities.dp(20), 0); textView.setText(LocaleController.getString("NoOtherSessionsInfo", R.string.NoOtherSessionsInfo)); emptyLayout.addView(textView); layoutParams2 = (LinearLayout.LayoutParams) textView.getLayoutParams(); layoutParams2.topMargin = AndroidUtilities.dp(14); layoutParams2.width = LayoutHelper.WRAP_CONTENT; layoutParams2.height = LayoutHelper.WRAP_CONTENT; layoutParams2.gravity = Gravity.CENTER; textView.setLayoutParams(layoutParams2); FrameLayout progressView = new FrameLayout(context); frameLayout.addView(progressView); FrameLayout.LayoutParams 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 listView = new ListView(context); listView.setDivider(null); listView.setDividerHeight(0); listView.setVerticalScrollBarEnabled(false); listView.setDrawSelectorOnTop(true); listView.setEmptyView(progressView); 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); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) { if (i == terminateAllSessionsRow) { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage( LocaleController.getString("AreYouSureSessions", R.string.AreYouSureSessions)); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { TLRPC.TL_auth_resetAuthorizations req = new TLRPC.TL_auth_resetAuthorizations(); 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() { if (getParentActivity() == null) { return; } if (error == null && response instanceof TLRPC.TL_boolTrue) { Toast toast = Toast.makeText(getParentActivity(), LocaleController.getString("TerminateAllSessions", R.string.TerminateAllSessions), Toast.LENGTH_SHORT); toast.show(); } else { Toast toast = Toast .makeText(getParentActivity(), LocaleController.getString("UnknownError", R.string.UnknownError), Toast.LENGTH_SHORT); toast.show(); } finishFragment(); } }); UserConfig.registeredForPush = false; UserConfig.saveConfig(false); MessagesController.getInstance().registerForPush(UserConfig.pushString); ConnectionsManager.getInstance() .setUserId(UserConfig.getClientUserId()); } }); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } else if (i >= otherSessionsStartRow && i < otherSessionsEndRow) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("TerminateSessionQuestion", R.string.TerminateSessionQuestion)); 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 option) { final ProgressDialog progressDialog = new ProgressDialog(getParentActivity()); progressDialog .setMessage(LocaleController.getString("Loading", R.string.Loading)); progressDialog.setCanceledOnTouchOutside(false); progressDialog.setCancelable(false); progressDialog.show(); final TLRPC.TL_authorization authorization = sessions .get(i - otherSessionsStartRow); TLRPC.TL_account_resetAuthorization req = new TLRPC.TL_account_resetAuthorization(); req.hash = authorization.hash; 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() { try { progressDialog.dismiss(); } catch (Exception e) { FileLog.e("tmessages", e); } if (error == null) { sessions.remove(authorization); updateRows(); if (listAdapter != null) { listAdapter.notifyDataSetChanged(); } } } }); } }); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } } }); return fragmentView; }