List of usage examples for android.widget LinearLayout addView
public void addView(View child, int index)
From source file:com.ijiaban.yinxiang.MainActivity.java
@SuppressLint("HandlerLeak") @Override/*from w w w. j av a 2 s . c o m*/ protected void onCreate(Bundle savedInstanceState) { Log.w("MainActivity: onCreate()", "ONCREATE"); super.onCreate(savedInstanceState); ANIMAL = getResources().getString(R.string.Animal); CARTOON = getResources().getString(R.string.Cartoon); LOVE = getResources().getString(R.string.Love); MUSIC = getResources().getString(R.string.Music); SPORTS = getResources().getString(R.string.Sports); BUSINESS = getResources().getString(R.string.Business); CARS = getResources().getString(R.string.Cars); DISHES = getResources().getString(R.string.Dishes); LOCAL = getResources().getString(R.string.Local); setContentView(R.layout.activity_main); MobclickAgent.updateOnlineConfig(this); LinearLayout layout = (LinearLayout) findViewById(R.id.adlayoutmainfragment); mAdView = new AdView(this); mAdView.setAdUnitId(getResources().getString(R.string.ad_unit_id)); mAdView.setAdSize(AdSize.BANNER); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); layout.addView(mAdView, params); mAdView.loadAd(new AdRequest.Builder().build()); // mNameTextView = (TextView) findViewById(R.id.nameTextView); // mDescriptionTextView = (TextView) findViewById(R.id.descriptionTextView); mIconImageView = (ImageView) findViewById(R.id.iconImageView); tabs = (PagerSlidingTabStrip) findViewById(R.id.maintabs); pager = (ViewPager) findViewById(R.id.pager); pagerAdapter = new CommonPagerAdapter(getSupportFragmentManager()); pager.setAdapter(pagerAdapter); final int pageMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources().getDisplayMetrics()); pager.setPageMargin(pageMargin); tabs.setViewPager(pager); // Check whether we're recreating a previously destroyed instance if (savedInstanceState != null) { Log.d("MainActivity", "onRestoreInstanceState()"); // Always call the superclass so it can restore the view hierarchy super.onRestoreInstanceState(savedInstanceState); // Restore state members from saved instance byte[] imageBytes = savedInstanceState.getByteArray(STORED_IMAGE); if (imageBytes != null) { mGeneratedBitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length); } mContact = savedInstanceState.getParcelable(STORED_CONTACT); mHasPickedContact = savedInstanceState.getBoolean(STORED_PICKED); mScreenWidthInPixels = savedInstanceState.getInt(STORED_WIDTH); if (mHasPickedContact && mContact != null && mGeneratedBitmap != null) { Log.d("Restoring generated bitmap", mGeneratedBitmap.getHeight() + ""); Log.d("Restoring contact object", mContact.getFullName()); showContactData(); } } if (!mHasPickedContact) { Log.d("MainActivity: onCreate()", "No contact picked yet."); pickContact(); } }
From source file:com.google.android.apps.santatracker.doodles.tilt.SwimmingFragment.java
@Override protected void firstPassLoadOnUiThread() { final FrameLayout.LayoutParams wrapperLP = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);/*from w w w .j a v a2s .co m*/ final SwimmingFragment that = this; scoreView = getScoreView(); pauseView = getPauseView(); int diveViewBottomMargin = (int) context.getResources().getDimension(R.dimen.dive_margin_bottom); int diveViewStartMargin = (int) context.getResources().getDimension(R.dimen.dive_margin_left); int diveViewSize = (int) context.getResources().getDimension(R.dimen.dive_image_size); FrameLayout.LayoutParams diveViewLP = new LayoutParams(diveViewSize, diveViewSize); diveViewLP.setMargins(diveViewStartMargin, 0, 0, diveViewBottomMargin); diveViewLP.gravity = Gravity.BOTTOM | Gravity.LEFT; if (VERSION.SDK_INT >= 17) { diveViewLP.setMarginStart(diveViewStartMargin); } diveView = new DiveView(context); countdownView = new TextView(context); countdownView.setGravity(Gravity.CENTER); countdownView.setTextColor(context.getResources().getColor(R.color.ui_text_yellow)); countdownView.setTypeface(Typeface.DEFAULT_BOLD); countdownView.setText("0"); countdownView.setVisibility(View.INVISIBLE); Locale locale = context.getResources().getConfiguration().locale; countdownView.setText(NumberFormat.getInstance(locale).format(3)); Point screenDimens = AndroidUtils.getScreenSize(); UIUtil.fitToBounds(countdownView, screenDimens.x / 10, screenDimens.y / 10); LinearLayout gameView = new LinearLayout(context); gameView.setOrientation(LinearLayout.VERTICAL); // Add game view. swimmingView = new SwimmingView(context); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 7); gameView.addView(swimmingView, lp); if (editorMode) { LinearLayout buttonWrapper = new LinearLayout(context); buttonWrapper.setOrientation(LinearLayout.HORIZONTAL); lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1); gameView.addView(buttonWrapper, lp); resetButton = getButton(R.string.reset_level, new OnClickListener() { @Override public void onClick(View v) { SwimmingModel level = levelManager.loadDefaultLevel(); initializeLevel(level, false); getActivity().getSharedPreferences(context.getString(R.string.swimming), Context.MODE_PRIVATE) .edit().putString(CURRENT_LEVEL_KEY, null).commit(); } }); deleteButton = getButton(R.string.delete_levels, new OnClickListener() { @Override public void onClick(View v) { DialogFragment dialogFragment = new DeleteLevelDialogFragment(); dialogFragment.show(getActivity().getFragmentManager(), "delete"); } }); loadButton = getButton(R.string.load_level, new OnClickListener() { @Override public void onClick(View v) { DialogFragment dialogFragment = new LoadLevelDialogFragment(that); dialogFragment.show(getActivity().getFragmentManager(), "load"); } }); saveButton = getButton(R.string.save_level, new OnClickListener() { @Override public void onClick(View v) { DialogFragment dialogFragment = new SaveLevelDialogFragment(that); dialogFragment.show(getActivity().getFragmentManager(), "save"); } }); collisionModeButton = new ToggleButton(context); collisionModeButton.setText(R.string.scenery_mode); collisionModeButton.setTextOff(context.getString(R.string.scenery_mode)); collisionModeButton.setTextOn(context.getString(R.string.collision_mode)); collisionModeButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { model.collisionMode = isChecked; } }); lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT, 1); buttonWrapper.addView(deleteButton, lp); buttonWrapper.addView(resetButton, lp); buttonWrapper.addView(loadButton, lp); buttonWrapper.addView(saveButton, lp); buttonWrapper.addView(collisionModeButton, lp); } sensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); accelerometerSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); if (accelerometerSensor == null) { // TODO: The game won't be playable without this, so what should we do? Log.d(TAG, "Accelerometer sensor is null"); } displayRotation = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay() .getRotation(); wrapper.addView(gameView, 0, wrapperLP); wrapper.addView(countdownView, 1); wrapper.addView(diveView, 2, diveViewLP); wrapper.addView(scoreView, 3); wrapper.addView(pauseView, 4); }
From source file:com.evo.passwordgenerator.activities.AboutActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.about_activity); LinearLayout mActivityRoot = ((LinearLayout) findViewById(R.id.main_view)); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); final View navbar = (View) findViewById(android.support.design.R.id.design_navigation_view); setSupportActionBar(toolbar);/* w w w . j av a 2 s . c om*/ getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); View aboutPage = new AboutPage(this).setImage(R.drawable.ic_generate_black) .setDescription(getString(R.string.description)).addItem(getVersion()).addItem(getChangelog()) .addItem(getLibraries()).addGroup(getString(R.string.connect)).addItem(getEmailElement()) .addItem(getTwitterElement()).addItem(getInstagramElement()).addItem(getxdaElement()) .addItem(getGithubElement()).addGroup(getString(R.string.thanksto)).addItem(getvhelement()) .addItem(getmdiElement()).addItem(getcopyLeftElement()).create(); mActivityRoot.addView(aboutPage, 1); }
From source file:com.example.fan.horizontalscrollview.PagerSlidingTabStrip.java
private void addWarningTab(final int position, String title, int resId) { LinearLayout tabLayout = new LinearLayout(getContext()); tabLayout.setOrientation(LinearLayout.HORIZONTAL); tabLayout.setGravity(Gravity.CENTER); ImageView tabImg = new ImageView(getContext()); int width = DimenUtils.dp2px(getContext(), 18); LinearLayout.LayoutParams tabImgParams = new LinearLayout.LayoutParams(width, width); tabImgParams.setMargins(0, 0, DimenUtils.dp2px(getContext(), 10), 0); tabImgParams.gravity = Gravity.CENTER; tabImg.setLayoutParams(tabImgParams); if (resId != -1) { tabImg.setBackgroundResource(resId); tabImg.setVisibility(View.VISIBLE); } else {/*from w w w .j a va 2 s .c om*/ tabImg.setVisibility(View.GONE); } tabLayout.addView(tabImg, 0); TextView tab = new TextView(getContext()); tab.setText(title); tab.setFocusable(true); tab.setGravity(Gravity.CENTER); tab.setSingleLine(); tab.setTextColor(getResources().getColorStateList( mTextChangeable ? R.color.pst_tab_changeable_text_selector : R.color.pst_tab_text_selector)); tab.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18.0f); tabLayout.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (null != mOnPageClickedLisener) { mOnPageClickedLisener.onPageClicked(position); } pager.setCurrentItem(position); } }); tabLayout.addView(tab, 1); tabsContainer.addView(tabLayout); }
From source file:com.android.systemui.statusbar.phone.NavigationBarView.java
private void addLightsOutButton(LinearLayout root, View v, boolean landscape, boolean empty) { ImageView addMe = new ImageView(mContext); addMe.setLayoutParams(v.getLayoutParams()); addMe.setImageResource(//from w w w. java 2s .c o m empty ? R.drawable.ic_sysbar_lights_out_dot_large : R.drawable.ic_sysbar_lights_out_dot_small); addMe.setScaleType(ImageView.ScaleType.CENTER); addMe.setVisibility(empty ? View.INVISIBLE : View.VISIBLE); if (landscape) root.addView(addMe, 0); else root.addView(addMe); }
From source file:jp.watnow.plugins.dialog.Notification.java
/** * //from ww w . j a va 2 s . c o m * @param message * @param title * @param buttonLabels * @param defaultTexts * @param callbackContext */ public synchronized void login(final String title, final String message, final JSONArray buttonLabels, final JSONArray defaultTexts, final CallbackContext callbackContext) { final CordovaInterface cordova = this.cordova; Runnable runnable = new Runnable() { public void run() { LinearLayout layout = new LinearLayout(cordova.getActivity()); layout.setOrientation(LinearLayout.VERTICAL); layout.setPadding(10, 0, 10, 0); final EditText usernameInput = new EditText(cordova.getActivity()); usernameInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL); final EditText passwordInput = new EditText(cordova.getActivity()); passwordInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); try { usernameInput.setHint("ID"); usernameInput.setText(defaultTexts.getString(0)); passwordInput.setHint("PASSWORD"); passwordInput.setText(defaultTexts.getString(1)); } catch (JSONException e1) { } layout.addView(usernameInput, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); layout.addView(passwordInput, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); AlertDialog.Builder dlg = createDialog(cordova); // new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); dlg.setMessage(message); dlg.setTitle(title); dlg.setCancelable(false); dlg.setView(layout); final JSONObject result = new JSONObject(); try { dlg.setNegativeButton(buttonLabels.getString(0), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); try { result.put("buttonIndex", 1); result.put("input1", usernameInput.getText()); result.put("input2", passwordInput.getText()); } catch (JSONException e) { e.printStackTrace(); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } }); } catch (JSONException e) { } try { dlg.setPositiveButton(buttonLabels.getString(1), new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); try { result.put("buttonIndex", 3); } catch (JSONException e) { e.printStackTrace(); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } }); } catch (JSONException e) { } dlg.setOnCancelListener(new AlertDialog.OnCancelListener() { public void onCancel(DialogInterface dialog) { dialog.dismiss(); try { result.put("buttonIndex", 0); } catch (JSONException e) { e.printStackTrace(); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } }); changeTextDirection(dlg); }; }; this.cordova.getActivity().runOnUiThread(runnable); }
From source file:com.example.fan.horizontalscrollview.PagerSlidingTabStrip.java
private void addRedDotTab(final int position, String title, int resId) { LinearLayout tabLayout = new LinearLayout(getContext()); tabLayout.setOrientation(LinearLayout.HORIZONTAL); tabLayout.setGravity(Gravity.CENTER); TextView tab = new TextView(getContext()); tab.setText(title);/* w w w . j a v a 2s .c o m*/ tab.setFocusable(true); tab.setGravity(Gravity.CENTER); tab.setSingleLine(); tab.setTextColor(getResources().getColorStateList(R.color.pst_tab_text_selector)); tab.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18.0f); tabLayout.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (null != mOnPageClickedLisener) { mOnPageClickedLisener.onPageClicked(position); } pager.setCurrentItem(position); } }); tabLayout.addView(tab, 0); ImageView tabImg = new ImageView(getContext()); LinearLayout.LayoutParams tabImgParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tabImgParams.setMargins(DeviceUtils.dip2px(getContext(), 5), DeviceUtils.dip2px(getContext(), 10), 0, 0); tabImgParams.gravity = Gravity.TOP; tabImg.setLayoutParams(tabImgParams); tabLayout.addView(tabImg, 1); tabsContainer.addView(tabLayout); }
From source file:com.roselism.bottomsheet.BottomSheet.java
private void init(final Context context) { setCanceledOnTouchOutside(cancelOnTouchOutside); final ClosableSlidingLayout mDialogView = (ClosableSlidingLayout) View.inflate(context, R.layout.bottom_sheet_dialog, null); LinearLayout mainLayout = (LinearLayout) mDialogView.findViewById(R.id.bs_main); mainLayout.addView(View.inflate(context, mHeaderLayoutId, null), 0); setContentView(mDialogView);/*from ww w .j a va2 s .c o m*/ if (!cancelOnSwipeDown) { mDialogView.swipeable = cancelOnSwipeDown; } mDialogView.setSlideListener(new ClosableSlidingLayout.SlideListener() { @Override public void onClosed() { BottomSheet.this.dismiss(); } @Override public void onOpened() { showFullItems(); } }); super.setOnShowListener(new OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { if (showListener != null) { showListener.onShow(dialogInterface); } list.setAdapter(adapter); list.startLayoutAnimation(); if (builder.icon == null) { icon.setVisibility(View.GONE); } else { icon.setVisibility(View.VISIBLE); icon.setImageDrawable(builder.icon); } } }); int[] location = new int[2]; mDialogView.getLocationOnScreen(location); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { mDialogView.setPadding(0, location[0] == 0 ? helper.mStatusBarHeight : 0, 0, 0); mDialogView.getChildAt(0).setPadding(0, 0, 0, helper.mNavBarAvailable ? helper.getNavigationBarHeight(getContext()) + mDialogView.getPaddingBottom() : 0); } final TextView title = (TextView) mDialogView.findViewById(R.id.bottom_sheet_title); if (builder.title != null) { title.setVisibility(View.VISIBLE); title.setText(builder.title); // title.setGravity(mHasContent ? Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL // : Gravity.LEFT); // ??? } icon = (ImageView) mDialogView.findViewById(R.id.bottom_sheet_title_image); list = (GridView) mDialogView.findViewById(R.id.bottom_sheet_gridview); mDialogView.mTarget = list; if (!builder.grid) { list.setNumColumns(1); } if (builder.grid) { for (int i = 0; i < getMenu().size(); i++) { if (getMenu().getItem(i).getIcon() == null) { throw new IllegalArgumentException("You must set icon for each items in grid style"); } } } if (builder.limit > 0) { limit = builder.limit * getNumColumns(); } else { limit = Integer.MAX_VALUE; } mDialogView.setCollapsible(false); actions = builder.menu; menuItem = actions; // over the initial numbers if (getMenu().size() > limit) { fullMenuItem = builder.menu; menuItem = builder.menu.clone(limit - 1); ActionMenuItem item = new ActionMenuItem(context, 0, R.id.bs_more, 0, limit - 1, moreText); item.setIcon(more); menuItem.add(item); actions = menuItem; mDialogView.setCollapsible(true); } BaseAdapter baseAdapter = new BaseAdapter() { @Override public int getCount() { return actions.size() - hidden.size(); } @Override public MenuItem getItem(int position) { return actions.getItem(position); } @Override public int getItemViewType(int position) { MenuItem item = getItem(position); String json = item.getTitle().toString(); int type = parseItemType(json) == null ? -1 : parseItemType(json); switch (type) { case ONE: return ONE; case TWO: return TWO; case NORMAL: return NORMAL; default: return NORMAL; } } @Override public long getItemId(int position) { return position; } @Override public int getViewTypeCount() { return 3; } @Override public boolean isEnabled(int position) { return getItem(position).isEnabled(); } @Override public boolean areAllItemsEnabled() { return false; } @Override public View getView(int position, View convertView, ViewGroup parent) { int type = getItemViewType(position); if (type == ONE) { OneItemViewHolder holder; if (convertView == null) { convertView = View.inflate(context, builder.grid ? mGridItemLayoutId : R.layout.bs_list_entry_hor_one, null); holder = new OneItemViewHolder(convertView); convertView.setTag(holder); } else { holder = (OneItemViewHolder) convertView.getTag(); } for (int i = 0; i < hidden.size(); i++) { if (hidden.valueAt(i) <= position) { position++; } } holder.bindData2View(position); } else if (type == TWO) { TwoItemViewHolder holder; if (convertView == null) { convertView = View.inflate(context, builder.grid ? mGridItemLayoutId : R.layout.bs_list_entry_hor_two, null); holder = new TwoItemViewHolder(convertView); convertView.setTag(holder); } else { holder = (TwoItemViewHolder) convertView.getTag(); } for (int i = 0; i < hidden.size(); i++) { if (hidden.valueAt(i) <= position) { position++; } } holder.bindData2View(position); } else if (type == NORMAL) { NormalItemViewHolder holder; if (convertView == null) { convertView = View.inflate(context, builder.grid ? mGridItemLayoutId : R.layout.bs_list_entry_normal, null); holder = new NormalItemViewHolder(convertView); convertView.setTag(holder); } else { holder = (NormalItemViewHolder) convertView.getTag(); } for (int i = 0; i < hidden.size(); i++) { if (hidden.valueAt(i) <= position) { position++; } } holder.bindData2View(position); } return convertView; } @Nullable private String parseItemTitle(String json) { try { JSONObject jsonObject = new JSONObject(json); String jsonTitle = jsonObject.getString("title"); return jsonTitle; } catch (JSONException e) { e.printStackTrace(); return null; } } private String parseItemContent(String json) { try { JSONObject jsonObject = new JSONObject(json); String content = jsonObject.getString("mContent"); return content; } catch (JSONException e) { e.printStackTrace(); return ""; } } @Nullable private Integer parseItemType(String json) { try { JSONObject jsonObject = new JSONObject(json); Integer type = jsonObject.getInt("type"); return type; } catch (JSONException e) { e.printStackTrace(); return null; } } class TwoItemViewHolder { private TextView divider; private TextView title; private TextView mContent; private ImageView image; public TwoItemViewHolder(View convertView) { title = (TextView) convertView.findViewById(R.id.bs_list_title); image = (ImageView) convertView.findViewById(R.id.bs_list_image); mContent = (TextView) convertView.findViewById(R.id.bs_list_content); divider = (TextView) convertView.findViewById(R.id.bs_list_divider); } private void bindData2View(int position) { MenuItem item = getItem(position); String json = item.getTitle().toString(); // title.setText(json); if (item.getIcon() == null) { image.setVisibility(collapseListIcons ? View.GONE : View.INVISIBLE); } else { image.setVisibility(View.VISIBLE); image.setImageDrawable(item.getIcon()); } boolean showDivider = getCount() > 1 && position != getCount() - 1; divider.setVisibility(showDivider ? View.VISIBLE : View.GONE); String itemTitle = parseItemTitle(json); String contentText = parseItemContent(json); title.setText(parseItemTitle(json)); if (contentText != null && !contentText.trim().isEmpty()) { mContent.setText(contentText); mContent.setVisibility(View.VISIBLE); mContent.setEnabled(true); } else { mContent.setVisibility(View.INVISIBLE); } image.setEnabled(item.isEnabled()); title.setEnabled(item.isEnabled()); } } class NormalItemViewHolder { private TextView title; private ImageView image; public NormalItemViewHolder(View convertView) { title = (TextView) convertView.findViewById(R.id.bs_list_title); image = (ImageView) convertView.findViewById(R.id.bs_list_image); } private void bindData2View(int position) { MenuItem item = getItem(position); String json = item.getTitle().toString(); String titleText = parseItemTitle(json) == null ? json : parseItemTitle(json); title.setText(titleText); if (item.getIcon() == null) { image.setVisibility(collapseListIcons ? View.GONE : View.INVISIBLE); } else { image.setVisibility(View.VISIBLE); image.setImageDrawable(item.getIcon()); } image.setEnabled(item.isEnabled()); title.setEnabled(item.isEnabled()); } } // class MenuItemViewHolder { // // private TextView title; // private ImageView image; // // public MenuItemViewHolder(View convertView) { // title = (TextView) convertView.findViewById(R.id.bs_list_title); // image = (ImageView) convertView.findViewById(R.id.bs_list_image); // } // // private void bindData2View(int position) { // MenuItem item = getItem(position); // String titleText = item.getTitle().toString(); //// String titleText = parseItemTitle(json); // // title.setText(titleText); // if (item.getIcon() == null) { // image.setVisibility(collapseListIcons ? View.GONE : View.INVISIBLE); // } else { // image.setVisibility(View.VISIBLE); // image.setImageDrawable(item.getIcon()); // } // // image.setEnabled(item.isEnabled()); // title.setEnabled(item.isEnabled()); // } // } class OneItemViewHolder { private TextView divider; private TextView title; private ImageView image; public OneItemViewHolder(View convertView) { title = (TextView) convertView.findViewById(R.id.bs_list_title); image = (ImageView) convertView.findViewById(R.id.bs_list_image); divider = (TextView) convertView.findViewById(R.id.bs_list_divider); } private void bindData2View(int position) { MenuItem item = getItem(position); String json = item.getTitle().toString(); title.setText(json); if (item.getIcon() == null) { image.setVisibility(collapseListIcons ? View.GONE : View.INVISIBLE); } else { image.setVisibility(View.VISIBLE); image.setImageDrawable(item.getIcon()); } boolean showDivider = getCount() > 1 && position != getCount() - 1; divider.setVisibility(showDivider ? View.VISIBLE : View.GONE); String itemTitle = parseItemTitle(json); String content = parseItemContent(json); title.setText(parseItemTitle(json)); image.setEnabled(item.isEnabled()); title.setEnabled(item.isEnabled()); } } }; adapter = new SimpleSectionedGridAdapter(context, baseAdapter, R.layout.bs_list_divider, R.id.headerlayout, R.id.header); list.setAdapter(adapter); adapter.setGridView(list); list.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (((MenuItem) adapter.getItem(position)).getItemId() == R.id.bs_more) { showFullItems(); mDialogView.setCollapsible(false); return; } if (!((ActionMenuItem) adapter.getItem(position)).invoke()) { if (builder.menu.getClickListener() != null) { builder.menu.getClickListener().get(position).onClick(view); } else { if (builder.menulistener != null) { builder.menulistener.onMenuItemClick((MenuItem) adapter.getItem(position)); } else if (builder.listener != null) { builder.listener.onClick(BottomSheet.this, ((MenuItem) adapter.getItem(position)).getItemId()); } } } dismiss(); } }); if (builder.dismissListener != null) { setOnDismissListener(builder.dismissListener); } setListLayout(); }
From source file:brostore.maquillage.custom.PagerSlidingTabStrip.java
private void addCustomTextTab(final int position, String title) { LinearLayout conteneur = new LinearLayout(getContext()); LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); conteneur.setOrientation(LinearLayout.HORIZONTAL); conteneur.setGravity(Gravity.CENTER); TextView tab = new TextView(getContext()); TextView tabCust = new TextView(getContext()); //tabCust.setBackgroundResource(R.drawable.live_nombre); tabCust.setGravity(Gravity.CENTER);/*from w ww .j av a2s .c o m*/ tabCust.setTextColor(Color.WHITE); tabCust.setTypeface(tabTypeface); tabCust.setTextSize(11); tabCust.setVisibility(View.GONE); int fiveDip = Utils.convertDpToPixel(5, getResources()); tabCust.setPadding(fiveDip, 0, fiveDip, 0); tabCust.setText("0"); tab.setText(title); tab.setGravity(Gravity.CENTER); tab.setSingleLine(); conteneur.addView(tab, param); param.leftMargin = Utils.convertDpToPixel(10, getResources()); conteneur.addView(tabCust, param); addTab(position, conteneur); }
From source file:com.juick.android.ThreadFragment.java
public void showThread(JuickMessage jmsg, boolean keepShow) { if (jmsg.getReplyTo() != 0) { JuickMessage reply = jmsg;/*from www . jav a 2 s .com*/ LinearLayout ll = new LinearLayout(getActivity()); ll.setOrientation(LinearLayout.VERTICAL); ll.setBackgroundDrawable(new ColorDrawable(Color.WHITE)); int totalCount = 0; while (reply != null) { totalCount += reply.Text.length(); if (totalCount > 500 || ll.getChildCount() > 10) break; JuickMessagesAdapter.ParsedMessage parsedMessage = JuickMessagesAdapter .formatMessageText(getActivity(), reply, true); TextView child = new TextView(getActivity()); ll.addView(child, 0); child.setText(parsedMessage.textContent); if (reply.getReplyTo() < 1) break; reply = findReply(getListView(), reply.getReplyTo()); } if (ll.getChildCount() != 0) { int xy[] = new int[2]; getListView().getLocationOnScreen(xy); int windowHeight = getActivity().getWindow().getWindowManager().getDefaultDisplay().getHeight(); int listBottom = getListView().getHeight() + xy[1]; int bottomSize = windowHeight - listBottom; ll.setPressed(true); MainActivity.restyleChildrenOrWidget(ll); if (!keepShow || shownThreadToast.getView().getParent() == null) { // new or already hidden shownThreadToast = new Toast(getActivity()); shownThreadToast.setView(ll); shownThreadToast.setGravity(Gravity.BOTTOM | Gravity.LEFT, 0, bottomSize); shownThreadToast.setDuration(Toast.LENGTH_LONG); } shownThreadToast.show(); } } }