List of usage examples for android.widget LinearLayout setOrientation
public void setOrientation(@OrientationMode int orientation)
From source file:org.telegram.ui.ChangePhoneHelpActivity.java
@Override public View createView(Context context) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); TLRPC.User user = UserConfig.getCurrentUser(); String value;/*from w w w .j a v a 2 s . c om*/ if (user != null && user.phone != null && user.phone.length() != 0) { value = PhoneFormat.getInstance().format("+" + user.phone); } else { value = LocaleController.getString("NumberUnknown", R.string.NumberUnknown); } actionBar.setTitle(value); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(int id) { if (id == -1) { finishFragment(); } } }); fragmentView = new RelativeLayout(context); fragmentView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); RelativeLayout relativeLayout = (RelativeLayout) fragmentView; ScrollView scrollView = new ScrollView(context); relativeLayout.addView(scrollView); RelativeLayout.LayoutParams layoutParams3 = (RelativeLayout.LayoutParams) scrollView.getLayoutParams(); layoutParams3.width = LayoutHelper.MATCH_PARENT; layoutParams3.height = LayoutHelper.WRAP_CONTENT; layoutParams3.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE); scrollView.setLayoutParams(layoutParams3); LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.setPadding(0, AndroidUtilities.dp(20), 0, AndroidUtilities.dp(20)); scrollView.addView(linearLayout); ScrollView.LayoutParams layoutParams = (ScrollView.LayoutParams) linearLayout.getLayoutParams(); layoutParams.width = ScrollView.LayoutParams.MATCH_PARENT; layoutParams.height = ScrollView.LayoutParams.WRAP_CONTENT; linearLayout.setLayoutParams(layoutParams); ImageView imageView = new ImageView(context); imageView.setImageResource(R.drawable.phone_change); linearLayout.addView(imageView); LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams) imageView.getLayoutParams(); layoutParams2.width = LayoutHelper.WRAP_CONTENT; layoutParams2.height = LayoutHelper.WRAP_CONTENT; layoutParams2.gravity = Gravity.CENTER_HORIZONTAL; imageView.setLayoutParams(layoutParams2); TextView textView = new TextView(context); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); textView.setGravity(Gravity.CENTER_HORIZONTAL); //textView.setTextColor(0xff212121); try { textView.setText(AndroidUtilities .replaceTags(LocaleController.getString("PhoneNumberHelp", R.string.PhoneNumberHelp))); } catch (Exception e) { FileLog.e("tmessages", e); textView.setText(LocaleController.getString("PhoneNumberHelp", R.string.PhoneNumberHelp)); } linearLayout.addView(textView); layoutParams2 = (LinearLayout.LayoutParams) textView.getLayoutParams(); layoutParams2.width = LayoutHelper.WRAP_CONTENT; layoutParams2.height = LayoutHelper.WRAP_CONTENT; layoutParams2.gravity = Gravity.CENTER_HORIZONTAL; layoutParams2.leftMargin = AndroidUtilities.dp(20); layoutParams2.rightMargin = AndroidUtilities.dp(20); layoutParams2.topMargin = AndroidUtilities.dp(56); textView.setLayoutParams(layoutParams2); textView = new TextView(context); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); textView.setGravity(Gravity.CENTER_HORIZONTAL); textView.setTextColor(ContextCompat.getColor(context, R.color.colorAccent) /*0xff4d83b3*/); textView.setText(LocaleController.getString("PhoneNumberChange", R.string.PhoneNumberChange)); textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); textView.setPadding(AndroidUtilities.dp(16), AndroidUtilities.dp(12), AndroidUtilities.dp(16), AndroidUtilities.dp(12)); textView.setBackground(context.getDrawable(R.drawable.list_selector)); linearLayout.addView(textView); layoutParams2 = (LinearLayout.LayoutParams) textView.getLayoutParams(); layoutParams2.width = LayoutHelper.WRAP_CONTENT; layoutParams2.height = LayoutHelper.WRAP_CONTENT; layoutParams2.gravity = Gravity.CENTER_HORIZONTAL; layoutParams2.leftMargin = AndroidUtilities.dp(20); layoutParams2.rightMargin = AndroidUtilities.dp(20); layoutParams2.topMargin = AndroidUtilities.dp(46); textView.setLayoutParams(layoutParams2); textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setMessage(LocaleController.getString("PhoneNumberAlert", R.string.PhoneNumberAlert)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { presentFragment(new ChangePhoneActivity(), true); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } }); return fragmentView; }
From source file:it.unibs.sandroide.lib.beacon.ui.BeaconTagActivity.java
private void renderListViews() { LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); layout.setGravity(Gravity.TOP);/* w w w . ja va 2s . c o m*/ lvBeacons = new ListView(this); lvBeacons.setId(LISTBEACONS_VIEW_ID); lvBeacons.setDivider(null); lvBeacons.setDividerHeight(0); lvTags = new ListView(this); lvTags.setId(LISTTAGS_VIEW_ID); lvTags.setVisibility(View.INVISIBLE); lvTags.setDivider(null); lvTags.setDividerHeight(0); layout.addView(lvBeacons, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, 1)); layout.addView(lvTags, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, 1)); setContentView(layout); }
From source file:com.gdgdevfest.android.apps.devfestbcn.ui.tablet.MapMultiPaneActivity.java
@Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); boolean landscape = (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE); LinearLayout spacerView = (LinearLayout) findViewById(R.id.map_detail_spacer); spacerView.setOrientation(landscape ? LinearLayout.HORIZONTAL : LinearLayout.VERTICAL); spacerView.setGravity(landscape ? Gravity.END : Gravity.BOTTOM); View popupView = findViewById(R.id.map_detail_popup); LinearLayout.LayoutParams popupLayoutParams = (LinearLayout.LayoutParams) popupView.getLayoutParams(); popupLayoutParams.width = landscape ? 0 : ViewGroup.LayoutParams.MATCH_PARENT; popupLayoutParams.height = landscape ? ViewGroup.LayoutParams.MATCH_PARENT : 0; popupView.setLayoutParams(popupLayoutParams); popupView.requestLayout();/*from w w w . j a v a 2 s. co m*/ updateMapPadding(); }
From source file:com.murrayc.galaxyzoo.app.QuestionHelpFragment.java
private void addRowForAnswer(final Context context, final TableLayout tableLayout, final DecisionTree.Question question, final DecisionTree.BaseButton answer) { final TableRow row = new TableRow(context); final TableLayout.LayoutParams params = new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT); params.setMargins(0, UiUtils.getPxForDpResource(context, R.dimen.standard_large_margin), 0, 0); tableLayout.addView(row, params);/*ww w . ja va 2 s. c o m*/ final LinearLayout layoutVertical = new LinearLayout(context); layoutVertical.setOrientation(LinearLayout.VERTICAL); final TextView textViewAnswer = new AppCompatTextView(context); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { textViewAnswer.setTextAppearance(R.style.TextAppearance_AppCompat_Subhead); } else { //noinspection deprecation textViewAnswer.setTextAppearance(context, R.style.TextAppearance_AppCompat_Subhead); } textViewAnswer.setText(answer.getText()); layoutVertical.addView(textViewAnswer, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); final LinearLayout layoutHorizontal = new LinearLayout(context); layoutHorizontal.setOrientation(LinearLayout.HORIZONTAL); final LinearLayout.LayoutParams paramsHorizontal = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); paramsHorizontal.setMargins(0, UiUtils.getPxForDpResource(context, R.dimen.standard_margin), 0, 0); layoutVertical.addView(layoutHorizontal, paramsHorizontal); final BitmapDrawable icon = getIcon(context, answer); final ImageView imageIcon = new ImageView(context); imageIcon.setImageDrawable(icon); layoutHorizontal.addView(imageIcon); final LinearLayout.LayoutParams paramsImage = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); // TODO: Use a custom FlowTable class to avoid items going off the right edge of the screen // when there are too many. final Singleton singleton = getSingleton(); for (int i = 0; i < answer.getExamplesCount(); i++) { final String iconName = answer.getExampleIconName(question.getId(), i); final BitmapDrawable iconExample = singleton.getIconDrawable(context, iconName); final ImageButton imageExample = new ImageButton(context); //Remove the space between the image and the outside of the button: imageExample.setPadding(0, 0, 0, 0); imageExample.setImageDrawable(iconExample); //Needed to make the image expand as a transition into the SubjectViewerActivity, //which uses the same name in fragment_subject.xml ViewCompat.setTransitionName(imageExample, getString(R.string.transition_subject_image)); //This requires API level 17: paramsImage.setMarginStart(getPxForDp(activity, MARGIN_MEDIUM_DP)); //imageExample.setLayoutParams(paramsImage); MarginLayoutParamsCompat.setMarginStart(paramsImage, UiUtils.getPxForDpResource(context, R.dimen.standard_large_margin)); final int answerIndex = i; imageExample.setOnClickListener(new View.OnClickListener() { public void onClick(final View v) { // Perform action on click onExampleImageClicked(v, answer, answerIndex); } }); layoutHorizontal.addView(imageExample, paramsImage); } row.addView(layoutVertical, new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT)); }
From source file:org.telegram.ui.IdenticonActivity.java
@Override public View createView(Context context) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); actionBar.setTitle(LocaleController.getString("EncryptionKey", R.string.EncryptionKey)); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override// ww w. ja va2 s.com public void onItemClick(int id) { if (id == -1) { finishFragment(); } } }); fragmentView = new LinearLayout(context); LinearLayout linearLayout = (LinearLayout) fragmentView; linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.setWeightSum(100); linearLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background)); fragmentView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); FrameLayout frameLayout = new FrameLayout(context); frameLayout.setPadding(AndroidUtilities.dp(20), AndroidUtilities.dp(20), AndroidUtilities.dp(20), AndroidUtilities.dp(20)); linearLayout.addView(frameLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 50.0f)); ImageView identiconView = new ImageView(context); identiconView.setScaleType(ImageView.ScaleType.FIT_XY); frameLayout.addView(identiconView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); frameLayout = new FrameLayout(context); frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.background)); frameLayout.setPadding(AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10), AndroidUtilities.dp(10)); linearLayout.addView(frameLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 50.0f)); TextView textView = new TextView(context); textView.setTextColor(ContextCompat.getColor(context, R.color.secondary_text)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); textView.setLinksClickable(true); textView.setClickable(true); textView.setMovementMethod(new LinkMovementMethodMy()); //textView.setAutoLinkMask(Linkify.WEB_URLS); textView.setLinkTextColor(Theme.MSG_LINK_TEXT_COLOR); textView.setGravity(Gravity.CENTER); frameLayout.addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance().getEncryptedChat(chat_id); if (encryptedChat != null) { IdenticonDrawable drawable = new IdenticonDrawable(); identiconView.setImageDrawable(drawable); drawable.setEncryptedChat(encryptedChat); TLRPC.User user = MessagesController.getInstance().getUser(encryptedChat.user_id); SpannableStringBuilder hash = new SpannableStringBuilder(); if (encryptedChat.key_hash.length > 16) { String hex = Utilities.bytesToHex(encryptedChat.key_hash); for (int a = 0; a < 32; a++) { if (a != 0) { if (a % 8 == 0) { hash.append('\n'); } else if (a % 4 == 0) { hash.append(' '); } } hash.append(hex.substring(a * 2, a * 2 + 2)); hash.append(' '); } hash.append("\n\n"); } hash.append(AndroidUtilities.replaceTags(LocaleController.formatString("EncryptionKeyDescription", R.string.EncryptionKeyDescription, user.first_name, user.first_name))); final String url = "telegram.org"; int index = hash.toString().indexOf(url); if (index != -1) { hash.setSpan( new URLSpanReplacement( LocaleController.getString("EncryptionKeyLink", R.string.EncryptionKeyLink)), index, index + url.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } textView.setText(hash); } return fragmentView; }
From source file:com.android.calculator2.Fragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final Context context = getActivity(); FrameLayout root = new FrameLayout(context); LinearLayout pframe = new LinearLayout(context); pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID); pframe.setOrientation(LinearLayout.VERTICAL); pframe.setVisibility(View.GONE); pframe.setGravity(Gravity.CENTER);/*from www. j ava 2 s. c o m*/ ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge); pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT)); FrameLayout lframe = new FrameLayout(context); lframe.setId(INTERNAL_VIEW_CONTAINER_ID); View cv = inflateView(savedInstanceState); cv.setId(android.R.id.content); lframe.addView(cv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT)); root.addView(lframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT)); root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT)); return root; }
From source file:com.chrslee.csgopedia.app.CardFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //Looks like he did this layout via code this is a layoutparams object //it defines the metrics and bounds of a specific view LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); //Creating a FrameLayout a FrameLayout is basically a empty container FrameLayout fl = new FrameLayout(context); fl.setLayoutParams(params);/*from w ww. jav a2 s .co m*/ //setting the params from above // First - image section //Building the imageview via code LayoutParams imgParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); imgParams.gravity = Gravity.CENTER; //setting all centered ImageView iv = new ImageView(context); iv.setLayoutParams(imgParams); iv.setScaleType(ImageView.ScaleType.CENTER_INSIDE); iv.setAdjustViewBounds(true); iv.setBackgroundResource(getActivity().getIntent().getExtras().getInt("iconID")); //seting the iconID as the image of this imageView // Second - prices section //final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources() // .getDisplayMetrics()); // //LinearLayout is another container it just take the //widgets inside it and display them in a linear order LinearLayout linLayout = new LinearLayout(context); linLayout.setOrientation(LinearLayout.VERTICAL); linLayout.setLayoutParams(params); linLayout.setGravity(Gravity.CENTER); // Get prices ConnectionDetector cd = new ConnectionDetector(context); //creating a connection detector to check for internet String query = getActivity().getIntent().getStringExtra("searchQuery"); //taking the name or whatever he pass from mainactivity from the searchquery arg TextView placeholder = new TextView(context); ///this is a textview for the name of the item if (cd.isConnectedToInternet()) {//if its connected to internet then if (query.equals("-1")) {//if the skin is regular he display is not for sale placeholder.setText("Regular skins are not for sale!"); linLayout.addView(placeholder); } else {//else he calls the scrappperAsyncTask with the query new ScraperAsyncTask(linLayout).execute(query); } } else {//if its not connected he display the message here placeholder.setText("Please connect to the Internet to view prices."); linLayout.addView(placeholder); } //here he defines which tab he is displaying, Now I see why he used the same fragment, //this is a bad practice, he created both widgets before but just displays one of them //for each case if its the first tab he display the image if its the second the prices if (position == 0) { fl.addView(iv); } else { fl.addView(linLayout); } //Then he returns the framelayout (container) to display it in the screen return fl; }
From source file:com.loloof64.android.capturing_audio.MainActivity.java
public void purposeFileRenaming(final File externalStorageDir, final File tempAudioFile, final Calendar captureStartDate) { AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); dialogBuilder.setTitle(R.string.renaming_temporary_file); final LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.HORIZONTAL); final TextView label = new TextView(this); label.setText(R.string.defining_file_name_label); layout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); final EditText input = new EditText(this); input.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); input.setInputType(InputType.TYPE_CLASS_TEXT); layout.addView(label);//from w w w .j a v a2 s . com layout.addView(input); dialogBuilder.setView(layout); dialogBuilder.setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String defaultNameRadix = new SimpleDateFormat(DEFAULT_FILE_NAME_FORMAT, Locale.getDefault()) .format(captureStartDate.getTime()); String nameRadix = input.getText().toString(); if (nameRadix.isEmpty()) { nameRadix = defaultNameRadix; } // Append a number to the name radix if necessary File testedFile = new File(externalStorageDir, String.format(FINAL_FILE_NAME_FORMAT, nameRadix)); boolean fileNameAlreadyUsed = testedFile.exists(); if (fileNameAlreadyUsed) { int number = 1; String chosenNameRadix; while (true) { chosenNameRadix = String.format(Locale.getDefault(), "%s%d", nameRadix, number); testedFile = new File(externalStorageDir, String.format(FINAL_FILE_NAME_FORMAT, chosenNameRadix)); fileNameAlreadyUsed = testedFile.exists(); if (!fileNameAlreadyUsed) break; number++; } nameRadix = chosenNameRadix; } String fileName = String.format(FINAL_FILE_NAME_FORMAT, nameRadix); File newFile = new File(externalStorageDir, fileName); boolean renameSuccess = tempAudioFile.renameTo(newFile); if (renameSuccess) { Toast.makeText(MainActivity.this, R.string.renamed_file, Toast.LENGTH_SHORT).show(); } else { Toast.makeText(MainActivity.this, R.string.file_renaming_failure, Toast.LENGTH_SHORT).show(); } } }); dialogBuilder.show(); }
From source file:fm.krui.kruifm.ScheduleFragment.java
/** * Adds a show to the schedule.// w ww .j av a 2 s . c o m * @param title Title of show to display * @param description Description of show to display * @param startTime Start time of show in minutes from midnight * @param endTime End time of show in minutes from midnight * @param category Format of this show, required to correctly color the event. * * Valid settings for category include: * 1 - Regular Rotation * 2 - Music Speciality * 3 - Sports * 4 - News/Talk * 5 - Specials */ private void addShow(String title, String description, int startTime, int endTime, int category) { /* Build the LinearLayout to function as the container for this show. Since the size of the container is to represent the length of the show, its height must be proportional (1dp = 1 minute) to the length. Determine length by finding the difference between the start and end times. */ // Fix for corner case of shows ending at midnight. if (endTime == 0) { endTime = 1440; } int difference = endTime - startTime; /* Define the margins of this show. All shows must not overlap the displayed times, which are 50dp in width. Add 5 more (to the right and left) to see the schedule lines for clarity. Push the show down to align with the appropriate time marker using the top margin value set to the difference (in minutes) between midnight and the start of the show. */ Log.v(TAG, "Configuring " + title); //Log.v(TAG, "Start time: " + startTime + " End time: " + endTime); //Log.v(TAG, "Setting parameters for " + title); RelativeLayout.LayoutParams rrLayoutParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, dpToPixels(difference)); rrLayoutParams.leftMargin = dpToPixels(55); //Log.v(TAG, "Left margin: " + rrLayoutParams.leftMargin); rrLayoutParams.topMargin = dpToPixels(startTime); //Log.v(TAG, "Top margin: " + rrLayoutParams.topMargin); rrLayoutParams.rightMargin = dpToPixels(5); //Log.v(TAG, "Right margin: " + rrLayoutParams.rightMargin); /* Build LinearLayout and apply parameters */ LinearLayout eventLL = new LinearLayout(getActivity()); eventLL.setOrientation(LinearLayout.VERTICAL); eventLL.setPadding(dpToPixels(5), dpToPixels(2), dpToPixels(5), dpToPixels(5)); // Get background for this event eventLL.setBackgroundResource(getEventBackground(category)); /* Add title of event to LinearLayout */ TextView titleTV = new TextView(getActivity()); // Title of a show should be bolded titleTV.setText(title); titleTV.setTypeface(null, Typeface.BOLD); titleTV.setPadding(dpToPixels(5), 0, dpToPixels(5), 0); eventLL.addView(titleTV); /* Determine length of event to see if we have room to attach a description (if one was passed) */ int length = endTime - startTime; /* Attach a description with a size that depends on the event length (longer events can hold more description text). */ if (description != null) { TextView descriptionTV = new TextView(getActivity()); descriptionTV.setPadding(dpToPixels(5), dpToPixels(5), dpToPixels(5), dpToPixels(5)); descriptionTV.setText(description); // ~hour long shows can display 1 line of description if (difference >= 30 && difference <= 60) { descriptionTV.setMaxLines(1); } // 1:30 long shows can display 2 lines of description else if (difference >= 60 && difference <= 90) { descriptionTV.setMaxLines(2); } // 2:00 long shows can display 4 lines of description else if (difference >= 120) { descriptionTV.setMaxLines(4); } descriptionTV.setEllipsize(TextUtils.TruncateAt.END); descriptionTV.setPadding(dpToPixels(5), dpToPixels(5), dpToPixels(5), dpToPixels(5)); eventLL.addView(descriptionTV); } /* Add this view to the schedule UI */ RelativeLayout rl = (RelativeLayout) rootView.findViewById(R.id.schedule_container_relativelayout); rl.addView(eventLL, rrLayoutParams); }
From source file:com.morlunk.mumbleclient.channel.ChannelMenu.java
@Override public boolean onMenuItemClick(MenuItem item) { boolean adding = false; switch (item.getItemId()) { case R.id.context_channel_join: mService.joinChannel(mChannel.getId()); break;/*w w w. j a v a 2s . co m*/ case R.id.context_channel_add: adding = true; case R.id.context_channel_edit: ChannelEditFragment addFragment = new ChannelEditFragment(); Bundle args = new Bundle(); if (adding) args.putInt("parent", mChannel.getId()); else args.putInt("channel", mChannel.getId()); args.putBoolean("adding", adding); addFragment.setArguments(args); addFragment.show(mFragmentManager, "ChannelAdd"); break; case R.id.context_channel_remove: AlertDialog.Builder adb = new AlertDialog.Builder(mContext); adb.setTitle(R.string.confirm); adb.setMessage(R.string.confirm_delete_channel); adb.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mService.removeChannel(mChannel.getId()); } }); adb.setNegativeButton(android.R.string.cancel, null); adb.show(); break; case R.id.context_channel_view_description: Bundle commentArgs = new Bundle(); commentArgs.putInt("channel", mChannel.getId()); commentArgs.putString("comment", mChannel.getDescription()); commentArgs.putBoolean("editing", false); DialogFragment commentFragment = (DialogFragment) Fragment.instantiate(mContext, ChannelDescriptionFragment.class.getName(), commentArgs); commentFragment.show(mFragmentManager, ChannelDescriptionFragment.class.getName()); break; case R.id.context_channel_pin: long serverId = mService.getConnectedServer().getId(); boolean pinned = mDatabase.isChannelPinned(serverId, mChannel.getId()); if (!pinned) mDatabase.addPinnedChannel(serverId, mChannel.getId()); else mDatabase.removePinnedChannel(serverId, mChannel.getId()); break; case R.id.context_channel_link: { IChannel channel = mService.getSessionChannel(); if (!item.isChecked()) { mService.linkChannels(channel, mChannel); } else { mService.unlinkChannels(channel, mChannel); } break; } case R.id.context_channel_unlink_all: mService.unlinkAllChannels(mChannel); break; case R.id.context_channel_shout: { AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setTitle(R.string.shout_configure); LinearLayout layout = new LinearLayout(mContext); layout.setOrientation(LinearLayout.VERTICAL); final CheckBox subchannelBox = new CheckBox(mContext); subchannelBox.setText(R.string.shout_include_subchannels); layout.addView(subchannelBox); final CheckBox linkedBox = new CheckBox(mContext); linkedBox.setText(R.string.shout_include_linked); layout.addView(linkedBox); builder.setView(layout); builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (mService == null || mService.getConnectionState() != JumbleService.ConnectionState.CONNECTED) return; // Unregister any existing voice target. if (mService.getVoiceTargetMode() == VoiceTargetMode.WHISPER) { mService.unregisterWhisperTarget(mService.getVoiceTargetId()); } WhisperTargetChannel channelTarget = new WhisperTargetChannel(mChannel, linkedBox.isChecked(), subchannelBox.isChecked(), null); byte id = mService.registerWhisperTarget(channelTarget); if (id > 0) { mService.setVoiceTargetId(id); } else { Toast.makeText(mContext, R.string.shout_failed, Toast.LENGTH_LONG).show(); } } }); builder.setNegativeButton(android.R.string.cancel, null); builder.show(); break; } default: return false; } return true; }