List of usage examples for android.widget TextView getLayoutParams
@ViewDebug.ExportedProperty(deepExport = true, prefix = "layout_") public ViewGroup.LayoutParams getLayoutParams()
From source file:com.mobicage.rogerthat.plugins.messaging.widgets.AdvancedOrderWidget.java
private void correctNameAndPriceWidth(final View v, final AdvancedOrderCategoryItemRow row) { mActivity.getMainService().postOnUIHandler(new SafeRunnable() { @Override/* w w w . jav a 2 s .c o m*/ protected void safeRun() throws Exception { TextView nameLbl = (TextView) v.findViewById(R.id.name); if (!row.name.equals(nameLbl.getText())) { return; } LinearLayout txtContainer = (LinearLayout) v.findViewById(R.id.text_container); txtContainer.measure(0, 0); int currentWidth = txtContainer.getMeasuredWidth(); int maxWidth = txtContainer.getWidth() - UIUtils.convertDipToPixels(mActivity, 35); nameLbl.measure(0, 0); int nameWidth = nameLbl.getMeasuredWidth(); int priceWidth = 0; if (row.hasPrice) { TextView priceLbl = (TextView) v.findViewById(R.id.price); priceLbl.measure(0, 0); priceWidth = priceLbl.getMeasuredWidth(); ViewGroup.LayoutParams lpPrice = priceLbl.getLayoutParams(); lpPrice.width = priceWidth; priceLbl.setLayoutParams(lpPrice); priceLbl.requestLayout(); } ViewGroup.LayoutParams lpName = nameLbl.getLayoutParams(); if (maxWidth > 0 && currentWidth < maxWidth) { if (maxWidth - priceWidth > nameWidth) { lpName.width = nameWidth; } else { lpName.width = maxWidth - priceWidth; } } else { lpName.width = maxWidth - priceWidth; } nameLbl.setLayoutParams(lpName); nameLbl.requestLayout(); } }); }
From source file:com.mobicage.rogerthat.plugins.messaging.widgets.AdvancedOrderWidget.java
private void correctCountWidth(final View v, final AdvancedOrderCategoryItemRow row) { mActivity.getMainService().postOnUIHandler(new SafeRunnable() { @Override//from w w w . j a v a2s.c o m protected void safeRun() throws Exception { TextView nameLbl = (TextView) v.findViewById(R.id.name); if (!row.name.equals(nameLbl.getText())) { return; } TextView countLbl = (TextView) v.findViewById(R.id.count); countLbl.measure(0, 0); int countWidth = countLbl.getMeasuredWidth(); if (countWidth > 140) { ViewGroup.LayoutParams lpCount = countLbl.getLayoutParams(); lpCount.width = 140; countLbl.setLayoutParams(lpCount); countLbl.requestLayout(); } } }); }
From source file:org.telegram.ui.ProfileNotificationsActivity.java
@Override public View createView(Context context) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); actionBar.setTitle(LocaleController.getString("NotificationsAndSounds", R.string.NotificationsAndSounds)); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override//from ww w . ja v a 2s. c o m public void onItemClick(int id) { if (id == -1) { finishFragment(); } } }); fragmentView = new FrameLayout(context); FrameLayout frameLayout = (FrameLayout) fragmentView; frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background)); listView = new ListView(context); listView.setDivider(null); listView.setDividerHeight(0); listView.setVerticalScrollBarEnabled(false); AndroidUtilities.setListViewEdgeEffectColor(listView, AvatarDrawable.getProfileBackColorForId(5)); frameLayout.addView(listView); final FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; listView.setLayoutParams(layoutParams); listView.setAdapter(new ListAdapter(context)); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) { if (i == settingsVibrateRow) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("Vibrate", R.string.Vibrate)); builder.setItems( new CharSequence[] { LocaleController.getString("VibrationDisabled", R.string.VibrationDisabled), LocaleController.getString("SettingsDefault", R.string.SettingsDefault), LocaleController.getString("SystemDefault", R.string.SystemDefault), LocaleController.getString("Short", R.string.Short), LocaleController.getString("Long", R.string.Long) }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); if (which == 0) { editor.putInt("vibrate_" + dialog_id, 2); } else if (which == 1) { editor.putInt("vibrate_" + dialog_id, 0); } else if (which == 2) { editor.putInt("vibrate_" + dialog_id, 4); } else if (which == 3) { editor.putInt("vibrate_" + dialog_id, 1); } else if (which == 4) { editor.putInt("vibrate_" + dialog_id, 3); } editor.commit(); if (listView != null) { listView.invalidateViews(); } } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } else if (i == settingsNotificationsRow) { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setItems( new CharSequence[] { LocaleController.getString("Default", R.string.Default), LocaleController.getString("Enabled", R.string.Enabled), LocaleController.getString("NotificationsDisabled", R.string.NotificationsDisabled) }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface d, int which) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putInt("notify2_" + dialog_id, which); if (which == 2) { NotificationsController.getInstance() .removeNotificationsForDialog(dialog_id); } MessagesStorage.getInstance().setDialogFlags(dialog_id, which == 2 ? 1 : 0); editor.commit(); TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs_dict .get(dialog_id); if (dialog != null) { dialog.notify_settings = new TLRPC.TL_peerNotifySettings(); if (which == 2) { dialog.notify_settings.mute_until = Integer.MAX_VALUE; } } if (listView != null) { listView.invalidateViews(); } NotificationsController.updateServerNotificationsSettings(dialog_id); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } else if (i == settingsSoundRow) { try { Intent tmpIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER); tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION); tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true); tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); Uri currentSound = null; String defaultPath = null; Uri defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI; if (defaultUri != null) { defaultPath = defaultUri.getPath(); } String path = preferences.getString("sound_path_" + dialog_id, defaultPath); if (path != null && !path.equals("NoSound")) { if (path.equals(defaultPath)) { currentSound = defaultUri; } else { currentSound = Uri.parse(path); } } tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentSound); startActivityForResult(tmpIntent, 12); } catch (Exception e) { FileLog.e("tmessages", e); } } else if (i == settingsLedRow) { if (getParentActivity() == null) { return; } LinearLayout linearLayout = new LinearLayout(getParentActivity()); linearLayout.setOrientation(LinearLayout.VERTICAL); final ColorPickerView colorPickerView = new ColorPickerView(getParentActivity()); linearLayout.addView(colorPickerView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER)); SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); if (preferences.contains("color_" + dialog_id)) { colorPickerView.setOldCenterColor(preferences.getInt("color_" + dialog_id, 0xff00ff00)); } else { if ((int) dialog_id < 0) { colorPickerView.setOldCenterColor(preferences.getInt("GroupLed", 0xff00ff00)); } else { colorPickerView.setOldCenterColor(preferences.getInt("MessagesLed", 0xff00ff00)); } } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("LedColor", R.string.LedColor)); builder.setView(linearLayout); builder.setPositiveButton(LocaleController.getString("Set", R.string.Set), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int which) { final SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putInt("color_" + dialog_id, colorPickerView.getColor()); editor.commit(); listView.invalidateViews(); } }); builder.setNeutralButton(LocaleController.getString("LedDisabled", R.string.LedDisabled), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putInt("color_" + dialog_id, 0); editor.commit(); listView.invalidateViews(); } }); builder.setNegativeButton(LocaleController.getString("Default", R.string.Default), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.remove("color_" + dialog_id); editor.commit(); listView.invalidateViews(); } }); showDialog(builder.create()); } else if (i == settingsPriorityRow) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle( LocaleController.getString("NotificationsPriority", R.string.NotificationsPriority)); builder.setItems( new CharSequence[] { LocaleController.getString("SettingsDefault", R.string.SettingsDefault), LocaleController.getString("NotificationsPriorityDefault", R.string.NotificationsPriorityDefault), LocaleController.getString("NotificationsPriorityHigh", R.string.NotificationsPriorityHigh), LocaleController.getString("NotificationsPriorityMax", R.string.NotificationsPriorityMax) }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == 0) { which = 3; } else { which--; } SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); preferences.edit().putInt("priority_" + dialog_id, which).commit(); if (listView != null) { listView.invalidateViews(); } } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } else if (i == smartRow) { if (getParentActivity() == null) { return; } SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); int notifyMaxCount = preferences.getInt("smart_max_count_" + dialog_id, 2); int notifyDelay = preferences.getInt("smart_delay_" + dialog_id, 3 * 60); if (notifyMaxCount == 0) { notifyMaxCount = 2; } LinearLayout linearLayout = new LinearLayout(getParentActivity()); linearLayout.setOrientation(LinearLayout.VERTICAL); LinearLayout linearLayout2 = new LinearLayout(getParentActivity()); linearLayout2.setOrientation(LinearLayout.HORIZONTAL); linearLayout.addView(linearLayout2); LinearLayout.LayoutParams layoutParams1 = (LinearLayout.LayoutParams) linearLayout2 .getLayoutParams(); layoutParams1.width = LayoutHelper.WRAP_CONTENT; layoutParams1.height = LayoutHelper.WRAP_CONTENT; layoutParams1.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP; linearLayout2.setLayoutParams(layoutParams1); TextView textView = new TextView(getParentActivity()); textView.setText(LocaleController.getString("SmartNotificationsSoundAtMost", R.string.SmartNotificationsSoundAtMost)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); linearLayout2.addView(textView); layoutParams1 = (LinearLayout.LayoutParams) textView.getLayoutParams(); layoutParams1.width = LayoutHelper.WRAP_CONTENT; layoutParams1.height = LayoutHelper.WRAP_CONTENT; layoutParams1.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT; textView.setLayoutParams(layoutParams1); final NumberPicker numberPickerTimes = new NumberPicker(getParentActivity()); numberPickerTimes.setMinValue(1); numberPickerTimes.setMaxValue(10); numberPickerTimes.setValue(notifyMaxCount); linearLayout2.addView(numberPickerTimes); layoutParams1 = (LinearLayout.LayoutParams) numberPickerTimes.getLayoutParams(); layoutParams1.width = AndroidUtilities.dp(50); numberPickerTimes.setLayoutParams(layoutParams1); textView = new TextView(getParentActivity()); textView.setText(LocaleController.getString("SmartNotificationsTimes", R.string.SmartNotificationsTimes)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); linearLayout2.addView(textView); layoutParams1 = (LinearLayout.LayoutParams) textView.getLayoutParams(); layoutParams1.width = LayoutHelper.WRAP_CONTENT; layoutParams1.height = LayoutHelper.WRAP_CONTENT; layoutParams1.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT; textView.setLayoutParams(layoutParams1); linearLayout2 = new LinearLayout(getParentActivity()); linearLayout2.setOrientation(LinearLayout.HORIZONTAL); linearLayout.addView(linearLayout2); layoutParams1 = (LinearLayout.LayoutParams) linearLayout2.getLayoutParams(); layoutParams1.width = LayoutHelper.WRAP_CONTENT; layoutParams1.height = LayoutHelper.WRAP_CONTENT; layoutParams1.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP; linearLayout2.setLayoutParams(layoutParams1); textView = new TextView(getParentActivity()); textView.setText(LocaleController.getString("SmartNotificationsWithin", R.string.SmartNotificationsWithin)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); linearLayout2.addView(textView); layoutParams1 = (LinearLayout.LayoutParams) textView.getLayoutParams(); layoutParams1.width = LayoutHelper.WRAP_CONTENT; layoutParams1.height = LayoutHelper.WRAP_CONTENT; layoutParams1.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT; textView.setLayoutParams(layoutParams1); final NumberPicker numberPickerMinutes = new NumberPicker(getParentActivity()); numberPickerMinutes.setMinValue(1); numberPickerMinutes.setMaxValue(10); numberPickerMinutes.setValue(notifyDelay / 60); linearLayout2.addView(numberPickerMinutes); layoutParams1 = (LinearLayout.LayoutParams) numberPickerMinutes.getLayoutParams(); layoutParams1.width = AndroidUtilities.dp(50); numberPickerMinutes.setLayoutParams(layoutParams1); textView = new TextView(getParentActivity()); textView.setText(LocaleController.getString("SmartNotificationsMinutes", R.string.SmartNotificationsMinutes)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); linearLayout2.addView(textView); layoutParams1 = (LinearLayout.LayoutParams) textView.getLayoutParams(); layoutParams1.width = LayoutHelper.WRAP_CONTENT; layoutParams1.height = LayoutHelper.WRAP_CONTENT; layoutParams1.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT; textView.setLayoutParams(layoutParams1); AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("SmartNotifications", R.string.SmartNotifications)); builder.setView(linearLayout); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); preferences.edit() .putInt("smart_max_count_" + dialog_id, numberPickerTimes.getValue()) .commit(); preferences.edit() .putInt("smart_delay_" + dialog_id, numberPickerMinutes.getValue() * 60) .commit(); if (listView != null) { listView.invalidateViews(); } } }); builder.setNegativeButton(LocaleController.getString("SmartNotificationsDisabled", R.string.SmartNotificationsDisabled), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Activity.MODE_PRIVATE); preferences.edit().putInt("smart_max_count_" + dialog_id, 0).commit(); if (listView != null) { listView.invalidateViews(); } } }); showDialog(builder.create()); } } }); return fragmentView; }
From source file:com.artech.controls.tabs.SlidingTabLayout.java
@SuppressLint("NewApi") protected void applyDefaultTabViewStyle(TextView textView) { textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTypeface(Typeface.DEFAULT_BOLD); textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // If we're running on Honeycomb or newer, then we can use the Theme's // selectableItemBackground to ensure that the View has a pressed state TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); }/*from ww w. j a v a2s.c o m*/ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style textView.setAllCaps(true); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); if (mDistributeEvenly) { LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) textView.getLayoutParams(); lp.width = 0; lp.weight = 1; } }
From source file:org.telegram.ui.ActionBar.ActionBarMenuItem.java
public TextView addSubItem(int id, String text, int icon) { if (popupLayout == null) { rect = new Rect(); location = new int[2]; popupLayout = new ActionBarPopupWindow.ActionBarPopupWindowLayout(getContext()); popupLayout.setOnTouchListener(new OnTouchListener() { @Override//from ww w . j a v a 2s.co m public boolean onTouch(View v, MotionEvent event) { if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { if (popupWindow != null && popupWindow.isShowing()) { v.getHitRect(rect); if (!rect.contains((int) event.getX(), (int) event.getY())) { popupWindow.dismiss(); } } } return false; } }); popupLayout.setDispatchKeyEventListener(new ActionBarPopupWindow.OnDispatchKeyEventListener() { @Override public void onDispatchKeyEvent(KeyEvent keyEvent) { if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK && keyEvent.getRepeatCount() == 0 && popupWindow != null && popupWindow.isShowing()) { popupWindow.dismiss(); } } }); } TextView textView = new TextView(getContext()); textView.setTextColor(ContextCompat.getColor(getContext(), R.color.primary_text)); textView.setBackgroundResource(R.drawable.list_selector); if (!LocaleController.isRTL) { textView.setGravity(Gravity.CENTER_VERTICAL); } else { textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT); } textView.setPadding(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), 0); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); textView.setMinWidth(AndroidUtilities.dp(196)); textView.setTag(id); textView.setText(text); if (icon != 0) { textView.setCompoundDrawablePadding(AndroidUtilities.dp(12)); if (!LocaleController.isRTL) { textView.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(icon), null, null, null); } else { textView.setCompoundDrawablesWithIntrinsicBounds(null, null, getResources().getDrawable(icon), null); } } popupLayout.setShowedFromBotton(showFromBottom); popupLayout.addView(textView); LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) textView.getLayoutParams(); if (LocaleController.isRTL) { layoutParams.gravity = Gravity.RIGHT; } layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = AndroidUtilities.dp(48); textView.setLayoutParams(layoutParams); textView.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { if (popupWindow != null && popupWindow.isShowing()) { if (processedPopupClick) { return; } processedPopupClick = true; popupWindow.dismiss(allowCloseAnimation); } if (parentMenu != null) { parentMenu.onItemClick((Integer) view.getTag()); } else if (delegate != null) { delegate.onItemClick((Integer) view.getTag()); } } }); menuHeight += layoutParams.height; return textView; }
From source file:com.gmail.walles.johan.batterylogger.BatteryPlotFragment.java
private void initializeLegend(final TextView legend) { // From: http://stackoverflow.com/questions/6068197/utils-read-resource-text-file-to-string-java#answer-18897411 String html = new Scanner(this.getClass().getResourceAsStream("/legend.html"), "UTF-8").useDelimiter("\\A") .next();// w w w. j a v a2 s.c o m legend.setText(trimTrailingWhitespace(Html.fromHtml(html))); // Check MainActivity.PREF_SHOW_LEGEND and set legend visibility from that SharedPreferences preferences = getActivity().getPreferences(Context.MODE_PRIVATE); boolean showLegend = preferences.getBoolean(MainActivity.PREF_SHOW_LEGEND, true); legend.setVisibility(showLegend ? View.VISIBLE : View.GONE); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { int width = (int) spToPixels(LEGEND_WIDTH_LANDSCAPE_SP); // Put an upper bound on the legend width at 40% landscape screen width Display display = getActivity().getWindowManager().getDefaultDisplay(); //noinspection deprecation int landscapeWidth = Math.max(display.getWidth(), display.getHeight()); if (width > landscapeWidth * 0.4) { width = (int) (landscapeWidth * 0.4); } legend.getLayoutParams().width = width; } }
From source file:com.android.calendar.selectcalendars.SelectCalendarsSimpleAdapter.java
@Override public View getView(final int position, View convertView, ViewGroup parent) { if (position >= mRowCount) { return null; }/*from ww w .j a v a 2 s . co m*/ String name = mData[position].displayName; boolean selected = mData[position].selected; int color = Utils.getDisplayColorFromColor(mData[position].color); View view; if (convertView == null) { view = mInflater.inflate(mLayout, parent, false); final View delegate = view.findViewById(R.id.color); final View delegateParent = (View) delegate.getParent(); delegateParent.post(new Runnable() { @Override public void run() { final Rect r = new Rect(); delegate.getHitRect(r); r.top -= mColorViewTouchAreaIncrease; r.bottom += mColorViewTouchAreaIncrease; r.left -= mColorViewTouchAreaIncrease; r.right += mColorViewTouchAreaIncrease; delegateParent.setTouchDelegate(new TouchDelegate(r, delegate)); } }); } else { view = convertView; } TextView calendarName = (TextView) view.findViewById(R.id.calendar); calendarName.setText(name); View colorView = view.findViewById(R.id.color); colorView.setBackgroundColor(color); colorView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // Purely for sanity check--view should be disabled if account has no more colors if (!hasMoreColors(position)) { return; } if (mColorPickerDialog == null) { mColorPickerDialog = CalendarColorPickerDialog.newInstance(mData[position].id, mIsTablet); } else { mColorPickerDialog.setCalendarId(mData[position].id); } mFragmentManager.executePendingTransactions(); if (!mColorPickerDialog.isAdded()) { mColorPickerDialog.show(mFragmentManager, COLOR_PICKER_DIALOG_TAG); } } }); int textColor; if (selected) { textColor = mColorCalendarVisible; } else { textColor = mColorCalendarHidden; } calendarName.setTextColor(textColor); CheckBox syncCheckBox = (CheckBox) view.findViewById(R.id.sync); if (syncCheckBox != null) { // Full screen layout syncCheckBox.setChecked(selected); colorView.setEnabled(hasMoreColors(position)); LayoutParams layoutParam = calendarName.getLayoutParams(); TextView secondaryText = (TextView) view.findViewById(R.id.status); if (!TextUtils.isEmpty(mData[position].ownerAccount) && !mData[position].ownerAccount.equals(name) && !mData[position].ownerAccount.endsWith("calendar.google.com")) { int secondaryColor; if (selected) { secondaryColor = mColorCalendarSecondaryVisible; } else { secondaryColor = mColorCalendarSecondaryHidden; } secondaryText.setText(mData[position].ownerAccount); secondaryText.setTextColor(secondaryColor); secondaryText.setVisibility(View.VISIBLE); layoutParam.height = LayoutParams.WRAP_CONTENT; } else { secondaryText.setVisibility(View.GONE); layoutParam.height = LayoutParams.MATCH_PARENT; } calendarName.setLayoutParams(layoutParam); } else { // Tablet layout view.findViewById(R.id.color).setEnabled(selected && hasMoreColors(position)); view.setBackgroundDrawable(getBackground(position, selected)); ViewGroup.LayoutParams newParams = view.getLayoutParams(); if (position == mData.length - 1) { newParams.height = BOTTOM_ITEM_HEIGHT; } else { newParams.height = NORMAL_ITEM_HEIGHT; } view.setLayoutParams(newParams); CheckBox visibleCheckBox = (CheckBox) view.findViewById(R.id.visible_check_box); if (visibleCheckBox != null) { visibleCheckBox.setChecked(selected); } } view.invalidate(); return view; }
From source file:ua.org.gdg.devfest.iosched.ui.SessionDetailFragment.java
/** * Handle {@link SessionsQuery} {@link Cursor}. *///from w w w .j a v a2 s. c om private void onSessionQueryComplete(Cursor cursor) { mSessionCursor = true; if (!cursor.moveToFirst()) { if (isAdded()) { // TODO: Remove this in favor of a callbacks interface that the activity // can implement. getActivity().finish(); } return; } mTitleString = cursor.getString(SessionsQuery.TITLE); // Format time block this session occupies mSessionBlockStart = cursor.getLong(SessionsQuery.BLOCK_START); mSessionBlockEnd = cursor.getLong(SessionsQuery.BLOCK_END); String roomName = cursor.getString(SessionsQuery.ROOM_NAME); final String subtitle = UIUtils.formatSessionSubtitle(mTitleString, mSessionBlockStart, mSessionBlockEnd, roomName, mBuffer, getActivity()); mTitle.setText(mTitleString); mUrl = cursor.getString(SessionsQuery.URL); if (TextUtils.isEmpty(mUrl)) { mUrl = ""; } mHashtags = cursor.getString(SessionsQuery.HASHTAGS); if (!TextUtils.isEmpty(mHashtags)) { enableSocialStreamMenuItemDeferred(); } mRoomId = cursor.getString(SessionsQuery.ROOM_ID); setupShareMenuItemDeferred(); showStarredDeferred(mInitStarred = (cursor.getInt(SessionsQuery.STARRED) != 0), false); final String sessionAbstract = cursor.getString(SessionsQuery.ABSTRACT); if (!TextUtils.isEmpty(sessionAbstract)) { UIUtils.setTextMaybeHtml(mAbstract, sessionAbstract); mAbstract.setVisibility(View.VISIBLE); mHasSummaryContent = true; } else { mAbstract.setVisibility(View.GONE); } final View requirementsBlock = mRootView.findViewById(R.id.session_requirements_block); final String sessionRequirements = cursor.getString(SessionsQuery.REQUIREMENTS); if (!TextUtils.isEmpty(sessionRequirements)) { UIUtils.setTextMaybeHtml(mRequirements, sessionRequirements); requirementsBlock.setVisibility(View.VISIBLE); mHasSummaryContent = true; } else { requirementsBlock.setVisibility(View.GONE); } // Show empty message when all data is loaded, and nothing to show if (mSpeakersCursor && !mHasSummaryContent) { mRootView.findViewById(android.R.id.empty).setVisibility(View.VISIBLE); } // Compile list of links (submit feedback, and normal links) ViewGroup linkContainer = (ViewGroup) mRootView.findViewById(R.id.links_container); linkContainer.removeAllViews(); final Context context = mRootView.getContext(); List<Pair<Integer, Intent>> links = new ArrayList<Pair<Integer, Intent>>(); // Add session feedback link if (getResources().getBoolean(R.bool.has_feedback_enabled)) { links.add(new Pair<Integer, Intent>(R.string.session_feedback_submitlink, new Intent(Intent.ACTION_VIEW, mSessionUri, getActivity(), SessionFeedbackActivity.class))); } for (int i = 0; i < SessionsQuery.LINKS_INDICES.length; i++) { final String linkUrl = cursor.getString(SessionsQuery.LINKS_INDICES[i]); if (TextUtils.isEmpty(linkUrl)) { continue; } links.add(new Pair<Integer, Intent>(SessionsQuery.LINKS_TITLES[i], new Intent(Intent.ACTION_VIEW, Uri.parse(linkUrl)) .addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET))); } // Render links if (links.size() > 0) { LayoutInflater inflater = LayoutInflater.from(context); int columns = context.getResources().getInteger(R.integer.links_columns); LinearLayout currentLinkRowView = null; for (int i = 0; i < links.size(); i++) { final Pair<Integer, Intent> link = links.get(i); // Create link view TextView linkView = (TextView) inflater.inflate(R.layout.list_item_session_link, linkContainer, false); linkView.setText(getString(link.first)); linkView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { fireLinkEvent(link.first); try { startActivity(link.second); } catch (ActivityNotFoundException ignored) { } } }); // Place it inside a container if (columns == 1) { linkContainer.addView(linkView); } else { // create a new link row if (i % columns == 0) { currentLinkRowView = (LinearLayout) inflater.inflate(R.layout.include_link_row, linkContainer, false); currentLinkRowView.setWeightSum(columns); linkContainer.addView(currentLinkRowView); } ((LinearLayout.LayoutParams) linkView.getLayoutParams()).width = 0; ((LinearLayout.LayoutParams) linkView.getLayoutParams()).weight = 1; currentLinkRowView.addView(linkView); } } mRootView.findViewById(R.id.session_links_header).setVisibility(View.VISIBLE); mRootView.findViewById(R.id.links_container).setVisibility(View.VISIBLE); } else { mRootView.findViewById(R.id.session_links_header).setVisibility(View.GONE); mRootView.findViewById(R.id.links_container).setVisibility(View.GONE); } // Show past/present/future and livestream status for this block. UIUtils.updateTimeBlockUI(context, mSessionBlockStart, mSessionBlockEnd, null, mSubtitle, subtitle); LOGD("Tracker", "Session: " + mTitleString); }
From source file:com.conferenceengineer.android.iosched.ui.SessionDetailFragment.java
/** * Handle {@link SessionsQuery} {@link Cursor}. *//* www . j ava 2 s. c o m*/ private void onSessionQueryComplete(Cursor cursor) { mSessionCursor = true; if (!cursor.moveToFirst()) { if (isAdded()) { // TODO: Remove this in favor of a callbacks interface that the activity // can implement. getActivity().finish(); } return; } mTitleString = cursor.getString(SessionsQuery.TITLE); // Format time block this session occupies mType = cursor.getString(SessionsQuery.TYPE); mSessionBlockStart = cursor.getLong(SessionsQuery.BLOCK_START); mSessionBlockEnd = cursor.getLong(SessionsQuery.BLOCK_END); String roomName = cursor.getString(SessionsQuery.ROOM_NAME); final String subtitle = UIUtils.formatSessionSubtitle(mTitleString, mSessionBlockStart, mSessionBlockEnd, roomName, mBuffer, getActivity()); mTitle.setText(mTitleString); mUrl = cursor.getString(SessionsQuery.URL); if (TextUtils.isEmpty(mUrl)) { mUrl = ""; } mHashtags = cursor.getString(SessionsQuery.HASHTAGS); if (!TextUtils.isEmpty(mHashtags)) { enableSocialStreamMenuItemDeferred(); } mRoomId = cursor.getString(SessionsQuery.ROOM_ID); setupShareMenuItemDeferred(); showStarredDeferred(mInitStarred = (cursor.getInt(SessionsQuery.STARRED) != 0), false); final String sessionAbstract = cursor.getString(SessionsQuery.ABSTRACT); if (!TextUtils.isEmpty(sessionAbstract)) { UIUtils.setTextMaybeHtml(mAbstract, sessionAbstract); mAbstract.setVisibility(View.VISIBLE); mHasSummaryContent = true; } else { mAbstract.setVisibility(View.GONE); } final View requirementsBlock = mRootView.findViewById(R.id.session_requirements_block); final String sessionRequirements = cursor.getString(SessionsQuery.REQUIREMENTS); if (!TextUtils.isEmpty(sessionRequirements)) { UIUtils.setTextMaybeHtml(mRequirements, sessionRequirements); requirementsBlock.setVisibility(View.VISIBLE); mHasSummaryContent = true; } else { requirementsBlock.setVisibility(View.GONE); } // Show empty message when all data is loaded, and nothing to show if (mSpeakersCursor && !mHasSummaryContent) { mRootView.findViewById(android.R.id.empty).setVisibility(View.VISIBLE); } // Compile list of links (submit feedback, and normal links) ViewGroup linkContainer = (ViewGroup) mRootView.findViewById(R.id.links_container); linkContainer.removeAllViews(); final Context context = mRootView.getContext(); List<Pair<Integer, Intent>> links = new ArrayList<Pair<Integer, Intent>>(); // Add session feedback link if (getResources().getBoolean(R.bool.has_session_feedback_enabled)) { links.add(new Pair<Integer, Intent>(R.string.session_feedback_submitlink, new Intent(Intent.ACTION_VIEW, mSessionUri, getActivity(), SessionFeedbackActivity.class))); } for (int i = 0; i < SessionsQuery.LINKS_INDICES.length; i++) { final String linkUrl = cursor.getString(SessionsQuery.LINKS_INDICES[i]); if (TextUtils.isEmpty(linkUrl)) { continue; } links.add(new Pair<Integer, Intent>(SessionsQuery.LINKS_TITLES[i], new Intent(Intent.ACTION_VIEW, Uri.parse(linkUrl)) .addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET))); } // Render links if (links.size() > 0) { LayoutInflater inflater = LayoutInflater.from(context); int columns = context.getResources().getInteger(R.integer.links_columns); LinearLayout currentLinkRowView = null; for (int i = 0; i < links.size(); i++) { final Pair<Integer, Intent> link = links.get(i); // Create link view TextView linkView = (TextView) inflater.inflate(R.layout.list_item_session_link, linkContainer, false); linkView.setText(getString(link.first)); linkView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { fireLinkEvent(link.first); try { startActivity(link.second); } catch (ActivityNotFoundException ignored) { } } }); // Place it inside a container if (columns == 1) { linkContainer.addView(linkView); } else { // create a new link row if (i % columns == 0) { currentLinkRowView = (LinearLayout) inflater.inflate(R.layout.include_link_row, linkContainer, false); currentLinkRowView.setWeightSum(columns); linkContainer.addView(currentLinkRowView); } ((LinearLayout.LayoutParams) linkView.getLayoutParams()).width = 0; ((LinearLayout.LayoutParams) linkView.getLayoutParams()).weight = 1; currentLinkRowView.addView(linkView); } } mRootView.findViewById(R.id.session_links_header).setVisibility(View.VISIBLE); mRootView.findViewById(R.id.links_container).setVisibility(View.VISIBLE); } else { mRootView.findViewById(R.id.session_links_header).setVisibility(View.GONE); mRootView.findViewById(R.id.links_container).setVisibility(View.GONE); } // Show past/present/future and livestream status for this block. UIUtils.updateTimeBlockUI(context, mSessionBlockStart, mSessionBlockEnd, null, mSubtitle, subtitle); LOGD("Tracker", "Session: " + mTitleString); }
From source file:scroll.com.rdemo.scroll.PagerSlidingTabStrip.java
private void updateTabStyles() { for (int i = 0; i < tabCount; i++) { View v = tabsContainer.getChildAt(i); if (v instanceof TextView) { TextView tab = (TextView) v; tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize); tab.setTypeface(tabTypeface, tabTypefaceStyle); if (i == currentPosition) { v.setBackgroundResource(tabSelectBackgroundResId); tab.setTextColor(indicatorColor); tab.setTextSize(indicatorTextSize); } else { v.setBackgroundResource(tabBackgroundResId); tab.setTextColor(tabTextColor); tab.setTextSize(tabTextSize); }//from w ww . j a v a2s .co m // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a // pre-ICS-build if (textAllCaps) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { tab.setAllCaps(true); } else { tab.setText(tab.getText().toString().toUpperCase(locale)); } } } else if (v instanceof ImageButton) { ImageButton tab = (ImageButton) v; IconTabProvider iconTabProvider = (IconTabProvider) pager.getAdapter(); ViewGroup.LayoutParams params = tab.getLayoutParams(); if (i == currentPosition) { int[] wh = iconTabProvider.getPageIconResWidthAndHeight(); if (params.width != wh[0] || params.height != wh[1]) { params.width = wh[0]; params.height = wh[1]; tab.setLayoutParams(params); } tab.setBackgroundResource(iconTabProvider.getPageIconResId(i)); } else { int[] wh = iconTabProvider.getPageUnSelectIconResWidthAndHeight(); if (params.width != wh[0] || params.height != wh[1]) { params.width = wh[0]; params.height = wh[1]; tab.setLayoutParams(params); } tab.setBackgroundResource(iconTabProvider.getPageUnSelectIconResId(i)); } } } }