List of usage examples for android.widget LinearLayout setLayoutParams
public void setLayoutParams(ViewGroup.LayoutParams params)
From source file:br.org.funcate.dynamicforms.views.GPictureView.java
/** * @param fragmentDetail the fragment detail to use. * @param attrs attributes. * @param requestCode the code for starting the activity with result. * @param parentView parent/*w w w .j av a 2 s. co m*/ * @param label label * @param pictures the value are the ids and binary data of the images. * @param constraintDescription constraints */ public GPictureView(final FragmentDetail fragmentDetail, AttributeSet attrs, final int requestCode, LinearLayout parentView, String label, Map<String, Map<String, String>> pictures, String constraintDescription) { super(fragmentDetail.getActivity(), attrs); thumbnailWidth = fragmentDetail.getActivity().getResources().getInteger(R.integer.thumbnail_width); thumbnailHeight = fragmentDetail.getActivity().getResources().getInteger(R.integer.thumbnail_height); mFragmentDetail = fragmentDetail; _pictures = pictures; PICTURE_VIEW_RESULT = requestCode; final FragmentActivity activity = fragmentDetail.getActivity(); LinearLayout textLayout = new LinearLayout(activity); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); layoutParams.setMargins(10, 10, 10, 10); textLayout.setPadding(10, 5, 10, 5); textLayout.setLayoutParams(layoutParams); textLayout.setOrientation(LinearLayout.VERTICAL); parentView.addView(textLayout); TextView textView = new TextView(activity); textView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); textView.setPadding(2, 2, 2, 2); String t = label.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription; textView.setText(t); textView.setTextColor(activity.getResources().getColor(R.color.formcolor)); textLayout.addView(textView); final Button button = new Button(activity); button.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); button.setPadding(15, 5, 15, 5); button.setText(R.string.take_picture); textLayout.addView(button); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent cameraIntent = new Intent(activity, CameraActivity.class); cameraIntent.putExtra(FormUtilities.MAIN_APP_WORKING_DIRECTORY, fragmentDetail.getWorkingDirectory()); fragmentDetail.startActivityForResult(cameraIntent, requestCode); } }); ScrollView scrollView = new ScrollView(activity); ScrollView.LayoutParams scrollLayoutParams = new ScrollView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); scrollView.setLayoutParams(scrollLayoutParams); scrollView.setHorizontalScrollBarEnabled(true); scrollView.setOverScrollMode(HorizontalScrollView.OVER_SCROLL_ALWAYS); parentView.addView(scrollView); imageLayout = new LinearLayout(activity); LinearLayout.LayoutParams imageLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); imageLayout.setLayoutParams(imageLayoutParams); imageLayout.setPadding(15, 5, 15, 5); imageLayout.setOrientation(LinearLayout.HORIZONTAL); imageLayout.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); scrollView.addView(imageLayout); updateValueForm(); try { refresh(activity); } catch (Exception e) { //GPLog.error(this, null, e); e.printStackTrace(); Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_LONG).show(); } }
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 {/* w w w . 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:com.dat.towerofhanoi.draggablerecyclerview.BoardView.java
public DragItemRecyclerView addColumnList(final DragItemAdapter adapter, final View header, boolean hasFixedItemSize, int color, Drawable drawable) { final DragItemRecyclerView recyclerView = new DragItemRecyclerView(getContext()); recyclerView.setMotionEventSplittingEnabled(false); recyclerView.setDragItem(mDragItem); if (drawable != null) { if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { recyclerView.setBackgroundDrawable(drawable); GradientDrawable gd = (GradientDrawable) recyclerView.getBackground().getCurrent(); gd.setColor(getResources().getColor(R.color.white)); gd.setStroke(2, getResources().getColor(R.color.grey), 0, 0); } else {/* w w w.ja v a 2s . c o m*/ recyclerView.setBackground(drawable); } } if (color > 0) { mColumnLayout.setBackgroundColor(color); } //settings for ToH rules recyclerView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext()); linearLayoutManager.setReverseLayout(true); recyclerView.setCanNotDragBelowTopItem(mCanNotDragBelowTopItem); recyclerView.setCanNotDropBelowTopItem(mCanNotDropBelowTopItem); recyclerView.setDragItemCallback(new DragItemRecyclerView.DragItemCallback() { @Override public boolean canDragItemAtPosition(int dragPosition) { return true; } @Override public boolean canDropItemAtPosition(int dropPosition) { if (dropPosition == adapter.getItemCount() - 1) { // Log.d("TAG", "TRUE"); return true; } return false; } }); recyclerView.setLayoutManager(linearLayoutManager); recyclerView.setHasFixedSize(hasFixedItemSize); recyclerView.setItemAnimator(new DefaultItemAnimator()); recyclerView.setDragItemListener(new DragItemRecyclerView.DragItemListener() { @Override public void onDragStarted(int itemPosition, float x, float y) { mDragStartColumn = getColumnOfList(recyclerView); mDragStartRow = itemPosition; mCurrentRecyclerView = recyclerView; mDragItem.setOffset(((View) mCurrentRecyclerView.getParent()).getX(), mCurrentRecyclerView.getY()); if (mBoardListener != null) { mBoardListener.onItemDragStarted(mDragStartColumn, mDragStartRow); } invalidate(); } @Override public void onDragging(int itemPosition, float x, float y) { } @Override public void onDragEnded(int newItemPosition) { if (mBoardListener != null) { mBoardListener.onItemDragEnded(mDragStartColumn, mDragStartRow, getColumnOfList(recyclerView), newItemPosition); } } }); recyclerView.setAdapter(adapter); recyclerView.setDragEnabled(mDragEnabled); adapter.setDragStartedListener(new DragItemAdapter.DragStartCallback() { @Override public boolean startDrag(View itemView, long itemId) { return recyclerView.startDrag(itemView, itemId, getListTouchX(recyclerView), getListTouchY(recyclerView)); } @Override public boolean isDragging() { return recyclerView.isDragging(); } }); LinearLayout layout = new LinearLayout(getContext()); layout.setOrientation(LinearLayout.VERTICAL); layout.setLayoutParams(new LayoutParams(mColumnWidth, LayoutParams.MATCH_PARENT)); if (header != null) { layout.addView(header); mHeaders.put(mLists.size(), header); } layout.addView(recyclerView); mLists.add(recyclerView); mColumnLayout.addView(layout); return recyclerView; }
From source file:com.poguico.palmabici.widgets.StationInfoWidget.java
@Override public void onOpen(Object item) { //super.onOpen(item); eItem = (ExtendedOverlayItem) item;/*from www. j a v a 2s . c om*/ int freeBikes, freeSlots; LinearLayout.LayoutParams layoutParams; String formattedDistance = ""; float[] distance = new float[1]; Location myLocation = locationSynchronizer.getLocation(); station = networkInformation.get(Integer.parseInt(eItem.getDescription())); TextView title = (TextView) mView.findViewById(R.id.markerTitle); TextView tvFreeBikes = (TextView) mView.findViewById(R.id.freeBikes); TextView tvFreeSlots = (TextView) mView.findViewById(R.id.freeSlots); LinearLayout lyBrokenApparel = (LinearLayout) mView.findViewById(R.id.brokenApparel); freeBikes = station.getBusySlots(); freeSlots = station.getFreeSlots(); if (myLocation != null) { Location.distanceBetween(station.getLat(), station.getLong(), myLocation.getLatitude(), myLocation.getLongitude(), distance); formattedDistance += " (" + Formatter.formatDistance(distance[0], context) + ")"; } title.setText(eItem.getTitle() + formattedDistance); tvFreeBikes.setText(String.valueOf(freeBikes)); tvFreeSlots.setText(String.valueOf(freeSlots)); lyBrokenApparel.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0)); if (station.getBusySlots() == 0) { layoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); layoutParams.setMargins(5, 5, 5, 5); alarmButton.setLayoutParams(layoutParams); if (networkSynchronizer.hasAlarm(station.getId())) { alarmButton.setImageResource(R.drawable.bell_active); active = true; } else { alarmButton.setImageResource(R.drawable.bell); active = false; } } else { layoutParams = new LinearLayout.LayoutParams(0, 0); layoutParams.setMargins(0, 0, 0, 0); alarmButton.setLayoutParams(layoutParams); } alarmButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { toggleAlarm(); String filename = "marker0"; filename += (NetworkStationAlarm.hasAlarm(station.getId())) ? "_alarm" : ""; try { eItem.setMarker(context.getResources() .getDrawable(R.drawable.class.getDeclaredField(filename).getInt(null))); } catch (NotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchFieldException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); locationSynchronizer.addSynchronizableElement(this); }
From source file:com.vonglasow.michael.satstat.ui.RadioSectionFragment.java
private final void addWifiResult(ScanResult result) { // needed to pass a persistent reference to the OnClickListener final ScanResult r = result; android.view.View.OnClickListener clis = new android.view.View.OnClickListener() { @Override//from w w w.j a v a 2 s . co m public void onClick(View v) { onWifiEntryClick(r.BSSID); } }; LinearLayout wifiLayout = new LinearLayout(wifiAps.getContext()); wifiLayout.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); wifiLayout.setOrientation(LinearLayout.HORIZONTAL); wifiLayout.setWeightSum(22); wifiLayout.setMeasureWithLargestChildEnabled(false); ImageView wifiType = new ImageView(wifiAps.getContext()); wifiType.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.MATCH_PARENT, 3)); if (WifiCapabilities.isAdhoc(result)) { wifiType.setImageResource(R.drawable.ic_content_wifi_adhoc); } else if ((WifiCapabilities.isEnterprise(result)) || (WifiCapabilities.getScanResultSecurity(result) == WifiCapabilities.EAP)) { wifiType.setImageResource(R.drawable.ic_content_wifi_eap); } else if (WifiCapabilities.getScanResultSecurity(result) == WifiCapabilities.PSK) { wifiType.setImageResource(R.drawable.ic_content_wifi_psk); } else if (WifiCapabilities.getScanResultSecurity(result) == WifiCapabilities.WEP) { wifiType.setImageResource(R.drawable.ic_content_wifi_wep); } else if (WifiCapabilities.getScanResultSecurity(result) == WifiCapabilities.OPEN) { wifiType.setImageResource(R.drawable.ic_content_wifi_open); } else { wifiType.setImageResource(R.drawable.ic_content_wifi_unknown); } wifiType.setScaleType(ScaleType.CENTER); wifiLayout.addView(wifiType); TableLayout wifiDetails = new TableLayout(wifiAps.getContext()); wifiDetails.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 19)); TableRow innerRow1 = new TableRow(wifiAps.getContext()); TextView newMac = new TextView(wifiAps.getContext()); newMac.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 14)); newMac.setTextAppearance(wifiAps.getContext(), android.R.style.TextAppearance_Medium); newMac.setText(result.BSSID); innerRow1.addView(newMac); TextView newCh = new TextView(wifiAps.getContext()); newCh.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 2)); newCh.setTextAppearance(wifiAps.getContext(), android.R.style.TextAppearance_Medium); newCh.setText(getChannelFromFrequency(result.frequency)); innerRow1.addView(newCh); TextView newLevel = new TextView(wifiAps.getContext()); newLevel.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 3)); newLevel.setTextAppearance(wifiAps.getContext(), android.R.style.TextAppearance_Medium); newLevel.setText(String.valueOf(result.level)); innerRow1.addView(newLevel); innerRow1.setOnClickListener(clis); wifiDetails.addView(innerRow1, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); TableRow innerRow2 = new TableRow(wifiAps.getContext()); TextView newSSID = new TextView(wifiAps.getContext()); newSSID.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 19)); newSSID.setTextAppearance(wifiAps.getContext(), android.R.style.TextAppearance_Small); newSSID.setText(result.SSID); innerRow2.addView(newSSID); innerRow2.setOnClickListener(clis); wifiDetails.addView(innerRow2, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); wifiLayout.addView(wifiDetails); wifiLayout.setOnClickListener(clis); wifiAps.addView(wifiLayout); }
From source file:com.githang.androidkit.app.IntroActivity.java
/** * /*from ww w . jav a 2 s . c o m*/ */ private void createContentView() { // ? mIntroResource = new IntroResource(); setIntroViews(mIntroResource); // RelativeLayout rootView = new RelativeLayout(this); rootView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); // mViewPager = new ViewPager(this); RelativeLayout.LayoutParams pagerParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); rootView.addView(mViewPager, pagerParams); // LinearLayout indicatorLayout = new LinearLayout(this); RelativeLayout.LayoutParams indicatorParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); indicatorParams.bottomMargin = mIntroResource.indicatorMarginBottom; indicatorParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE); indicatorParams.addRule(RelativeLayout.CENTER_HORIZONTAL); indicatorLayout.setLayoutParams(indicatorParams); indicatorLayout.setOrientation(LinearLayout.HORIZONTAL); // int indicatorCount = mIntroResource.views.size(); int padding = mIntroResource.indicatorImagePadding; mIndicator = new ArrayList<ImageView>(); for (int i = 0; i < indicatorCount; i++) { ImageView imageView = new ImageView(this); LinearLayout.LayoutParams imageParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); imageView.setPadding(padding, padding, padding, padding); imageView.setClickable(true); imageView.setOnClickListener(this); imageView.setImageResource(mIntroResource.indicatorNoSelectedId); imageView.setTag(i); mIndicator.add(imageView); indicatorLayout.addView(imageView, imageParams); } rootView.addView(indicatorLayout); setContentView(rootView); }
From source file:com.lurencun.cfuture09.androidkit.uilibs.IntroActivity.java
/** * //from ww w . j a v a2 s . co m */ private void createContentView() { // ? mIntroResource = new IntroResource(); setIntroViews(mIntroResource); // RelativeLayout rootView = new RelativeLayout(this); rootView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); // mViewPager = new ViewPager(this); RelativeLayout.LayoutParams pagerParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT); rootView.addView(mViewPager, pagerParams); // LinearLayout indicatorLayout = new LinearLayout(this); RelativeLayout.LayoutParams indicatorParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); indicatorParams.bottomMargin = mIntroResource.indicatorMarginBottom; indicatorParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE); indicatorParams.addRule(RelativeLayout.CENTER_HORIZONTAL); indicatorLayout.setLayoutParams(indicatorParams); indicatorLayout.setOrientation(LinearLayout.HORIZONTAL); // int indicatorCount = mIntroResource.views.size(); int padding = mIntroResource.indicatorImagePadding; mIndicator = new ArrayList<ImageView>(); for (int i = 0; i < indicatorCount; i++) { ImageView imageView = new ImageView(this); LinearLayout.LayoutParams imageParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); imageView.setPadding(padding, padding, padding, padding); imageView.setClickable(true); imageView.setOnClickListener(this); imageView.setImageResource(mIntroResource.indicatorNoSelectedId); imageView.setTag(i); mIndicator.add(imageView); indicatorLayout.addView(imageView, imageParams); } rootView.addView(indicatorLayout); setContentView(rootView); }
From source file:com.google.samples.apps.iosched.ui.widget.CollectionView.java
private View makeNewItemRow(RowComputeResult rowInfo) { LinearLayout ll = new LinearLayout(getContext()); LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); ll.setOrientation(LinearLayout.HORIZONTAL); ll.setLayoutParams(params); int nbColumns = rowInfo.group.mDisplayCols; if (hasCustomGroupView()) { nbColumns = 1;//from www. ja v a 2 s. c o m } for (int i = 0; i < nbColumns; i++) { View view = getItemView(rowInfo, i, null, ll); setupLayoutParams(view); ll.addView(view); } return ll; }
From source file:com.chatwing.whitelabel.managers.ChatboxModeManager.java
@Override public boolean onCreateOptionsMenu(Menu menu) { AppCompatActivity activity = mActivityDelegate.getActivity(); final DrawerLayout drawerLayout = mActivityDelegate.getDrawerLayout(); activity.getMenuInflater().inflate(R.menu.chatbox_menu, menu); MenuItem onlineUsersItem = menu.findItem(R.id.online_users); mediaAddItem = menu.findItem(R.id.audio_add); /**/*from w w w . j a v a2 s .c om*/ * Create badge view for online user item */ ImageButton iconView = new ImageButton(activity, null, R.style.Widget_AppCompat_ActionButton); iconView.setImageDrawable(onlineUsersItem.getIcon()); iconView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (drawerLayout.isDrawerOpen(DRAWER_GRAVITY_ONLINE_USER)) { drawerLayout.closeDrawer(DRAWER_GRAVITY_ONLINE_USER); } else { drawerLayout.openDrawer(DRAWER_GRAVITY_ONLINE_USER); } } }); // The badge view requires target view (iconView in this case) // to have a ViewGroup parent LinearLayout container = new LinearLayout(activity); container.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); container.addView(iconView); Resources res = activity.getResources(); mOnlineUsersBadgeView = new BadgeView(activity, iconView); mOnlineUsersBadgeView.setBadgePosition(BadgeView.POSITION_TOP_RIGHT); mOnlineUsersBadgeView.setTextSize(TypedValue.COMPLEX_UNIT_SP, res.getDimension(R.dimen.badge_view_text_size)); mOnlineUsersBadgeView.setBadgeMargin(res.getDimensionPixelSize(R.dimen.default_margin)); onlineUsersItem.setActionView(container); mOnlineUsersBadgeView .setBadgeBackgroundColor(mActivityDelegate.getActivity().getResources().getColor(R.color.accent)); return true; }
From source file:io.github.trulyfree.easyaspi.MainActivity.java
@Override public boolean setup() { downloadHandler = new DownloadHandler(this); fileHandler = new FileHandler(this); moduleHandler = new ModuleHandler(this); executorService = Executors.newCachedThreadPool(); setContentView(R.layout.activity_main); BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation); navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { @Override//from w ww.j a v a 2 s . c o m public boolean onNavigationItemSelected(@NonNull MenuItem item) { ViewSwitcher viewGroup = (ViewSwitcher) findViewById(R.id.content); int id = item.getItemId(); if ((id == R.id.navigation_home || id == R.id.navigation_modules) && id != currentID) { currentID = item.getItemId(); viewGroup.showNext(); return true; } return false; } }); ViewSwitcher viewSwitcher = (ViewSwitcher) findViewById(R.id.content); Animation in = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left); Animation out = AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right); viewSwitcher.setInAnimation(in); viewSwitcher.setOutAnimation(out); resetConfigReturned(); Button getNewModule = (Button) findViewById(R.id.new_module_config_confirm); getNewModule.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { EditText editText = (EditText) findViewById(R.id.new_module_config_configurl); final String url = editText.getText().toString(); Toast.makeText(MainActivity.this, "Requested config from: " + url, Toast.LENGTH_SHORT).show(); executorService.submit(new Callable<Boolean>() { @Override public Boolean call() { ModuleConfig config; try { config = moduleHandler.getModuleConfig(url); } catch (MalformedURLException e) { e.printStackTrace(); runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(MainActivity.this, "Invalid URL. :(", Toast.LENGTH_LONG).show(); } }); return false; } catch (IOException e) { e.printStackTrace(); runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(MainActivity.this, "Failed to get module config. :(", Toast.LENGTH_LONG).show(); } }); return false; } catch (JsonParseException e) { e.printStackTrace(); runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(MainActivity.this, "Config loaded was invalid. :(", Toast.LENGTH_LONG).show(); } }); return false; } final ModuleConfig finalConfig = config; final ImageView configResponseBlock = (ImageView) findViewById(R.id.block_module_returned); final int colorFrom = ContextCompat.getColor(MainActivity.this, R.color.colorFillingTint); final int colorTo = ContextCompat.getColor(MainActivity.this, R.color.colorClear); final ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimation.setDuration(ANIMATION_DURATION); colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { configResponseBlock.setBackgroundColor((Integer) animator.getAnimatedValue()); } }); colorAnimation.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { } @Override public void onAnimationEnd(Animator animator) { LinearLayout layout = (LinearLayout) findViewById(R.id.module_returned_config); EditText moduleName = (EditText) findViewById(R.id.module_returned_configname); EditText moduleVersion = (EditText) findViewById( R.id.module_returned_configversion); EditText moduleConfigUrl = (EditText) findViewById(R.id.module_returned_configurl); EditText moduleJarUrl = (EditText) findViewById(R.id.module_returned_jarurl); LinearLayout moduleDependencies = (LinearLayout) findViewById( R.id.module_returned_dependencies); moduleDependencies.removeAllViewsInLayout(); try { configResponseBlock.setVisibility(View.GONE); moduleName.setText(finalConfig.getName()); moduleVersion.setText(finalConfig.getVersion()); moduleConfigUrl.setText(finalConfig.getConfUrl()); moduleJarUrl.setText(finalConfig.getJarUrl()); Config[] dependencies = finalConfig.getDependencies(); for (Config dependency : dependencies) { LinearLayout dependencyLayout = new LinearLayout(MainActivity.this); dependencyLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); dependencyLayout.setOrientation(LinearLayout.HORIZONTAL); EditText name = new EditText(MainActivity.this); EditText jarUrl = new EditText(MainActivity.this); EditText[] loopThrough = { name, jarUrl }; LayoutParams params = new LayoutParams(0, LayoutParams.WRAP_CONTENT, 1.0f); for (EditText item : loopThrough) { item.setLayoutParams(params); item.setClickable(false); item.setInputType(InputType.TYPE_NULL); item.setCursorVisible(false); item.setFocusable(false); item.setFocusableInTouchMode(false); } name.setText(dependency.getName()); jarUrl.setText(dependency.getJarUrl()); dependencyLayout.addView(name); dependencyLayout.addView(jarUrl); moduleDependencies.addView(dependencyLayout); } layout.setClickable(true); Button validate = (Button) findViewById(R.id.module_returned_validate); Button cancel = (Button) findViewById(R.id.module_returned_cancel); validate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(MainActivity.this, "Requesting jars...", Toast.LENGTH_SHORT).show(); executorService.submit(new Callable<Boolean>() { @Override public Boolean call() { try { boolean success = true, refreshAllModification = true; Button refreshAll = null, getNewModule = (Button) findViewById( R.id.new_module_config_confirm); try { refreshAll = (Button) findViewById(R.id.refresh_all); refreshAll.setClickable(false); } catch (Throwable e) { refreshAllModification = false; } getNewModule.setClickable(false); final TextView stager = (TextView) findViewById( R.id.new_module_config_downloadstage); final ProgressBar progressBar = (ProgressBar) findViewById( R.id.new_module_config_downloadprogress); try { runOnUiThread(new Runnable() { @Override public void run() { resetConfigReturned(); } }); moduleHandler.getNewModule( makeModuleCallback(stager, progressBar), finalConfig, null, true); } catch (IOException e) { e.printStackTrace(); runOnUiThread(new Runnable() { @Override public void run() { stager.setText(""); progressBar.setProgress(0); } }); success = false; } getNewModule.setClickable(true); if (refreshAllModification) { refreshAll.setClickable(true); } return success; } catch (Throwable throwable) { throwable.printStackTrace(); return false; } } }); } }); cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(MainActivity.this, "Cancelling request...", Toast.LENGTH_SHORT).show(); resetConfigReturned(); } }); } catch (Exception e) { e.printStackTrace(); Toast.makeText(MainActivity.this, "Module config invalid. :(", Toast.LENGTH_LONG).show(); layout.setClickable(false); final int colorFrom = ContextCompat.getColor(MainActivity.this, R.color.colorClear); final int colorTo = ContextCompat.getColor(MainActivity.this, R.color.colorFillingTint); ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimation.setDuration(ANIMATION_DURATION); colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { configResponseBlock .setBackgroundColor((Integer) animator.getAnimatedValue()); } }); } } @Override public void onAnimationCancel(Animator animator) { } @Override public void onAnimationRepeat(Animator animator) { } }); runOnUiThread(new Runnable() { @Override public void run() { colorAnimation.start(); } }); return true; } }); } }); moduleHandler.setup(); refreshFilling(); return true; }