List of usage examples for android.widget LinearLayout LinearLayout
public LinearLayout(Context context)
From source file:com.example.almin.widget.MyFragmentTabHost.java
private void ensureHierarchy(Context context) { // If owner hasn't made its own view hierarchy, then as a convenience // we will construct a standard one here. if (findViewById(android.R.id.tabs) == null) { LinearLayout ll = new LinearLayout(context); ll.setOrientation(LinearLayout.VERTICAL); addView(ll, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); TabWidget tw = new TabWidget(context); tw.setId(android.R.id.tabs);// w w w .j a v a2 s. c o m tw.setOrientation(TabWidget.HORIZONTAL); ll.addView(tw, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0)); FrameLayout fl = new FrameLayout(context); fl.setId(android.R.id.tabcontent); ll.addView(fl, new LinearLayout.LayoutParams(0, 0, 0)); mRealTabContent = fl = new FrameLayout(context); mRealTabContent.setId(mContainerId); ll.addView(fl, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1)); } }
From source file:cn.bproject.neteasynews.widget.FragmentTabHost.java
private void ensureHierarchy(Context context) { // If owner hasn't made its own view hierarchy, then as a convenience // we will construct a standard one here. if (findViewById(android.R.id.tabs) == null) { LinearLayout ll = new LinearLayout(context); ll.setOrientation(LinearLayout.VERTICAL); addView(ll, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); TabWidget tw = new TabWidget(context); tw.setId(android.R.id.tabs);/*ww w. j a v a2 s.co m*/ tw.setOrientation(TabWidget.HORIZONTAL); ll.addView(tw, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0)); FrameLayout fl = new FrameLayout(context); fl.setId(android.R.id.tabcontent); ll.addView(fl, new LinearLayout.LayoutParams(0, 0, 0)); mRealTabContent = fl = new FrameLayout(context); mRealTabContent.setId(mContainerId); ll.addView(fl, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1)); } }
From source file:edu.mum.ml.group7.guessasketch.android.EasyPaint.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // it removes the title from the actionbar(more space for icons?) // this.getActionBar().setDisplayShowTitleEnabled(false); pixels5 = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics()); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); LinearLayout parent = new LinearLayout(this); parent.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); parent.setOrientation(LinearLayout.VERTICAL); LinearLayout scrollViewParent = new LinearLayout(this); scrollViewParent.setLayoutParams(// w w w .j a v a 2 s . c o m new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); scrollViewParent.setOrientation(LinearLayout.HORIZONTAL); HorizontalScrollView predictionsHorizontalScrollView = new HorizontalScrollView(this); //predictionsHorizontalScrollView.setLayoutParams(new ViewGroup.LayoutParams()); predictions = new LinearLayout(this); LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); params.gravity = Gravity.CENTER_VERTICAL; predictions.setLayoutParams(params); predictions.setOrientation(LinearLayout.HORIZONTAL); resetPredictionsView(predictions, true); predictionsHorizontalScrollView.addView(predictions); saveButton = new Button(this); saveButton.setText("Send Feedback"); predictionsHorizontalScrollView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 10.0f)); saveButton.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1.0f)); saveButton.setVisibility(View.INVISIBLE); FrameLayout frameLayout = new FrameLayout(this); frameLayout .setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT)); frameLayout.addView(saveButton); loader = new ProgressBar(this); loader.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); loader.setIndeterminate(true); loader.setVisibility(ProgressBar.INVISIBLE); frameLayout.addView(loader); scrollViewParent.addView(predictionsHorizontalScrollView); scrollViewParent.addView(frameLayout); contentView = new MyView(this); parent.addView(scrollViewParent); parent.addView(contentView); setContentView(parent); otherLabelOnClickListener = new View.OnClickListener() { @Override public void onClick(View view) { Log.e("Clicked", "Other Label label '" + (String) view.getTag() + "'"); sendScreenshot(false, feedbackType, (String) view.getTag()); } }; mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(Color.BLACK); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(DEFAULT_BRUSH_SIZE); // Where did these magic numbers come from? What do they mean? Can I change them? ~TheOpenSourceNinja // Absolutely random numbers in order to see the emboss. asd! ~Valerio mEmboss = new EmbossMaskFilter(new float[] { 1, 1, 1 }, 0.4f, 6, 3.5f); mBlur = new BlurMaskFilter(5, BlurMaskFilter.Blur.NORMAL); if (isFirstTime()) { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle(R.string.app_name); alert.setMessage(R.string.app_description); alert.setNegativeButton(R.string.continue_button, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Toast.makeText(getApplicationContext(), R.string.here_is_your_canvas, Toast.LENGTH_SHORT) .show(); } }); alert.show(); } else { Toast.makeText(getApplicationContext(), R.string.here_is_your_canvas, Toast.LENGTH_SHORT).show(); } loadFromIntents(); }
From source file:com.uzmap.pkg.uzmodules.uzBMap.mode.Billboard.java
private LinearLayout titleLayout() { LinearLayout titleLayout = new LinearLayout(context); LayoutParams layoutParams = new LayoutParams(UZCoreUtil.dipToPix(width - iconSize - 30), UZCoreUtil.dipToPix(height)); layoutParams.setMargins(UZCoreUtil.dipToPix(10), 0, UZCoreUtil.dipToPix(10), 0); titleLayout.setLayoutParams(layoutParams); titleLayout.setOrientation(LinearLayout.VERTICAL); LinearLayout titleLayout2 = new LinearLayout(context); LayoutParams layoutParams2 = new LayoutParams(UZCoreUtil.dipToPix(width - iconSize - 30), UZCoreUtil.dipToPix(height - 10)); titleLayout2.setGravity(Gravity.CENTER_VERTICAL); titleLayout2.setOrientation(LinearLayout.VERTICAL); titleLayout2.setLayoutParams(layoutParams2); titleLayout.addView(titleLayout2);/*from w ww . j a va 2 s.co m*/ titleLayout2.addView(title()); titleLayout2.addView(subTitle()); return titleLayout; }
From source file:cn.thinkjoy.startup.widget.FragmentTabHost.java
private void ensureHierarchy(Context context) { // If owner hasn't made its own view hierarchy, then as a convenience // we will construct a standard one here. if (findViewById(android.R.id.tabs) == null) { LinearLayout ll = new LinearLayout(context); ll.setOrientation(LinearLayout.VERTICAL); addView(ll, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); TabWidget tw = new TabWidget(context); tw.setId(android.R.id.tabs);/*from www . j a v a 2s .c o m*/ tw.setOrientation(LinearLayout.HORIZONTAL); ll.addView(tw, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0)); FrameLayout fl = new FrameLayout(context); fl.setId(android.R.id.tabcontent); ll.addView(fl, new LinearLayout.LayoutParams(0, 0, 0)); mRealTabContent = fl = new FrameLayout(context); mRealTabContent.setId(mContainerId); ll.addView(fl, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1)); } }
From source file:it.redturtle.mobile.apparpav.MeteogramAdapter.java
/** * DOUBLE TITLE ROW/*from w ww . ja v a 2 s. c om*/ * @param att * @param linear * @return */ public LinearLayout getDoubleTitleRow(Map<String, String> att, LinearLayout linear) { LinearLayout container_layout = new LinearLayout(context); container_layout.setMinimumHeight(30); container_layout .setBackgroundDrawable(context.getResources().getDrawable(R.drawable.view_shape_meteo_blue)); container_layout.setVerticalGravity(Gravity.CENTER); container_layout.setOrientation(LinearLayout.HORIZONTAL); LinearLayout.LayoutParams value_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 0.3f); TextView tx = new TextView(context); tx.setText(""); tx.setTextColor(Color.rgb(66, 66, 66)); container_layout.addView(tx, value_params); LinearLayout.LayoutParams ltext1 = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 0.35f); TextView t1 = new TextView(context); t1.setText(att.get("value1")); t1.setTextSize(11); t1.setGravity(Gravity.CENTER_HORIZONTAL); t1.setPadding(2, 0, 0, 2); t1.setTextColor(Color.rgb(255, 255, 255)); container_layout.addView(t1, ltext1); LinearLayout.LayoutParams ltext2 = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 0.35f); TextView t2 = new TextView(context); t2.setText(att.get("value2")); t2.setTextSize(11); t2.setGravity(Gravity.CENTER_HORIZONTAL); t2.setPadding(2, 0, 0, 2); t2.setTextColor(Color.rgb(255, 255, 255)); container_layout.addView(t2, ltext2); linear.addView(container_layout); return linear; }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.VideoObj.java
public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) { JSONObject content = obj.getJson();/*ww w .j a v a2s.co m*/ byte[] raw = obj.getRaw(); if (raw == null) { Pair<JSONObject, byte[]> p = splitRaw(content); content = p.first; raw = p.second; } LinearLayout inner = new LinearLayout(context); inner.setLayoutParams(CommonLayouts.FULL_WIDTH); inner.setOrientation(LinearLayout.HORIZONTAL); frame.addView(inner); ImageView imageView = new ImageView(context); imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); BitmapFactory bf = new BitmapFactory(); imageView.setImageBitmap(bf.decodeByteArray(raw, 0, raw.length)); inner.addView(imageView); ImageView iconView = new ImageView(context); iconView.setImageResource(R.drawable.play); iconView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); inner.addView(iconView); }
From source file:fm.krui.kruifm.ScheduleFragment.java
/** * Adds a show to the schedule./*ww w. j a v a 2 s .co 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:at.alladin.rmbt.android.map.overlay.RMBTBalloonOverlayView.java
public void setBalloonData(final RMBTBalloonOverlayItem item, final ViewGroup parent) { // map our custom item data to fields // title.setText(item.getTitle()); resultItems = item.getResultItems(); resultListView.removeAllViews();//from w w w .ja v a 2 s . c o m final float scale = getResources().getDisplayMetrics().density; final int leftRightItem = Helperfunctions.dpToPx(5, scale); final int topBottomItem = Helperfunctions.dpToPx(3, scale); final int leftRightDiv = Helperfunctions.dpToPx(0, scale); final int topBottomDiv = Helperfunctions.dpToPx(0, scale); final int heightDiv = Helperfunctions.dpToPx(1, scale); final int topBottomImg = Helperfunctions.dpToPx(1, scale); if (resultItems != null && resultItems.length() > 0) { for (int i = 0; i < 1; i++) // JSONObject resultListItem; try { final JSONObject result = resultItems.getJSONObject(i); final LayoutInflater resultInflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View resultView = resultInflater.inflate(R.layout.balloon_overlay_listitem, parent); final LinearLayout measurementLayout = (LinearLayout) resultView .findViewById(R.id.resultMeasurementList); measurementLayout.setVisibility(View.GONE); final LinearLayout netLayout = (LinearLayout) resultView.findViewById(R.id.resultNetList); netLayout.setVisibility(View.GONE); final TextView measurementHeader = (TextView) resultView.findViewById(R.id.resultMeasurement); measurementHeader.setVisibility(View.GONE); final TextView netHeader = (TextView) resultView.findViewById(R.id.resultNet); netHeader.setVisibility(View.GONE); final TextView dateHeader = (TextView) resultView.findViewById(R.id.resultDate); dateHeader.setVisibility(View.GONE); dateHeader.setText(result.optString("time_string")); final JSONArray measurementArray = result.getJSONArray("measurement"); final JSONArray netArray = result.getJSONArray("net"); for (int j = 0; j < measurementArray.length(); j++) { final JSONObject singleItem = measurementArray.getJSONObject(j); final LinearLayout measurememtItemLayout = new LinearLayout(context); // (LinearLayout)measurememtItemView.findViewById(R.id.measurement_item); measurememtItemLayout.setLayoutParams( new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT)); measurememtItemLayout.setGravity(Gravity.CENTER_VERTICAL); measurememtItemLayout.setPadding(leftRightItem, topBottomItem, leftRightItem, topBottomItem); final TextView itemTitle = new TextView(context, null, R.style.balloonResultItemTitle); itemTitle.setLayoutParams( new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 0.4f)); itemTitle.setTextAppearance(context, R.style.balloonResultItemTitle); itemTitle.setWidth(0); itemTitle.setGravity(Gravity.LEFT); itemTitle.setText(singleItem.getString("title")); measurememtItemLayout.addView(itemTitle); final ImageView itemClassification = new ImageView(context); itemClassification.setLayoutParams( new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.MATCH_PARENT, 0.1f)); itemClassification.setPadding(0, topBottomImg, 0, topBottomImg); // itemClassification.set setGravity(Gravity.LEFT); itemClassification.setImageDrawable(getResources().getDrawable( Helperfunctions.getClassificationImage(singleItem.getInt("classification")))); measurememtItemLayout.addView(itemClassification); final TextView itemValue = new TextView(context, null, R.style.balloonResultItemValue); itemValue.setLayoutParams( new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 0.5f)); itemValue.setTextAppearance(context, R.style.balloonResultItemValue); itemValue.setWidth(0); itemValue.setGravity(Gravity.LEFT); itemValue.setText(singleItem.getString("value")); measurememtItemLayout.addView(itemValue); measurementLayout.addView(measurememtItemLayout); final View divider = new View(context); divider.setLayoutParams(new LinearLayout.LayoutParams( android.view.ViewGroup.LayoutParams.MATCH_PARENT, heightDiv, 1)); divider.setPadding(leftRightDiv, topBottomDiv, leftRightDiv, topBottomDiv); divider.setBackgroundResource(R.drawable.bg_trans_light_10); measurementLayout.addView(divider); measurementLayout.invalidate(); } for (int j = 0; j < netArray.length(); j++) { final JSONObject singleItem = netArray.getJSONObject(j); final LinearLayout netItemLayout = new LinearLayout(context); // (LinearLayout)measurememtItemView.findViewById(R.id.measurement_item); netItemLayout.setLayoutParams( new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT)); netItemLayout.setPadding(leftRightItem, topBottomItem, leftRightItem, topBottomItem); netItemLayout.setGravity(Gravity.CENTER_VERTICAL); final TextView itemTitle = new TextView(context, null, R.style.balloonResultItemTitle); itemTitle.setLayoutParams( new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 0.4f)); itemTitle.setTextAppearance(context, R.style.balloonResultItemTitle); itemTitle.setWidth(0); itemTitle.setGravity(Gravity.LEFT); itemTitle.setText(singleItem.getString("title")); netItemLayout.addView(itemTitle); final ImageView itemClassification = new ImageView(context); itemClassification.setLayoutParams( new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.MATCH_PARENT, 0.1f)); itemClassification.setPadding(0, topBottomImg, 0, topBottomImg); itemClassification.setImageDrawable( context.getResources().getDrawable(R.drawable.traffic_lights_none)); netItemLayout.addView(itemClassification); final TextView itemValue = new TextView(context, null, R.style.balloonResultItemValue); itemValue.setLayoutParams( new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 0.5f)); itemValue.setTextAppearance(context, R.style.balloonResultItemValue); itemValue.setWidth(0); itemValue.setGravity(Gravity.LEFT); itemValue.setText(singleItem.optString("value", null)); netItemLayout.addView(itemValue); netLayout.addView(netItemLayout); final View divider = new View(context); divider.setLayoutParams(new LinearLayout.LayoutParams( android.view.ViewGroup.LayoutParams.MATCH_PARENT, heightDiv, 1)); divider.setPadding(leftRightDiv, topBottomDiv, leftRightDiv, topBottomDiv); divider.setBackgroundResource(R.drawable.bg_trans_light_10); netLayout.addView(divider); netLayout.invalidate(); } measurementHeader.setVisibility(View.VISIBLE); netHeader.setVisibility(View.VISIBLE); measurementLayout.setVisibility(View.VISIBLE); netLayout.setVisibility(View.VISIBLE); dateHeader.setVisibility(View.VISIBLE); resultListView.addView(resultView); Log.d(DEBUG_TAG, "View Added"); // codeText.setText(resultListItem.getString("sync_code")); } catch (final JSONException e) { e.printStackTrace(); } progessBar.setVisibility(View.GONE); emptyView.setVisibility(View.GONE); resultListView.setVisibility(View.VISIBLE); resultListView.invalidate(); } else { Log.i(DEBUG_TAG, "LEERE LISTE"); progessBar.setVisibility(View.GONE); emptyView.setVisibility(View.VISIBLE); emptyView.setText(context.getString(R.string.error_no_data)); emptyView.invalidate(); } }
From source file:it.iziozi.iziozi.gui.IOBoardFragment.java
private View buildView(boolean editMode) { this.homeRows.clear(); final List<IOSpeakableImageButton> mButtons = new ArrayList<IOSpeakableImageButton>(); List<IOSpeakableImageButton> configButtons = this.mBoard.getButtons(); ViewGroup mainView = (ViewGroup) getActivity().getLayoutInflater().inflate(R.layout.table_main_layout, null);/*from w w w.j a v a2s. com*/ LinearLayout tableContainer = new LinearLayout(getActivity()); LinearLayout.LayoutParams mainParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); tableContainer.setLayoutParams(mainParams); tableContainer.setOrientation(LinearLayout.VERTICAL); for (int i = 0; i < this.mBoard.getRows(); i++) { LinearLayout rowLayout = new LinearLayout(getActivity()); LinearLayout.LayoutParams rowParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.f); rowLayout.setLayoutParams(rowParams); rowLayout.setOrientation(LinearLayout.HORIZONTAL); Random color = new Random(); rowLayout.setBackgroundColor(Color.WHITE); tableContainer.addView(rowLayout); this.homeRows.add(rowLayout); } for (int j = 0; j < this.homeRows.size(); j++) { LinearLayout homeRow = this.homeRows.get(j); for (int i = 0; i < this.mBoard.getCols(); i++) { LinearLayout btnContainer = new LinearLayout(getActivity()); LinearLayout.LayoutParams btnContainerParams = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1.f); btnContainer.setLayoutParams(btnContainerParams); btnContainer.setOrientation(LinearLayout.VERTICAL); btnContainer.setGravity(Gravity.CENTER); homeRow.addView(btnContainer); final IOSpeakableImageButton imgButton = (configButtons.size() > 0 && configButtons.size() > mButtons.size()) ? configButtons.get(mButtons.size()) : new IOSpeakableImageButton(getActivity()); imgButton.setmContext(getActivity()); imgButton.setShowBorder(IOConfiguration.getShowBorders()); if (IOGlobalConfiguration.isEditing) imgButton.setImageDrawable(getResources().getDrawable(R.drawable.logo_org)); else imgButton.setImageDrawable(null); imgButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE); imgButton.setBackgroundColor(Color.TRANSPARENT); if (imgButton.getmImageFile() != null && imgButton.getmImageFile().length() > 0) { if (!new File(imgButton.getmImageFile()).exists()) { if (mAlertDialog == null || !mAlertDialog.isShowing()) { mAlertDialog = new AlertDialog.Builder(getActivity()).setCancelable(true) .setTitle(getString(R.string.image_missing)) .setMessage(getString(R.string.image_missing_text)) .setNegativeButton(getString(R.string.continue_string), null).create(); mAlertDialog.show(); } //download image if (isExternalStorageReadable()) { File baseFolder = new File(Environment.getExternalStorageDirectory() + "/" + IOApplication.APPLICATION_FOLDER + "/pictograms"); Character pictoChar = imgButton.getmImageFile() .charAt(imgButton.getmImageFile().lastIndexOf("/") + 1); File pictoFolder = new File(baseFolder + "/" + pictoChar + "/"); if (isExternalStorageWritable()) { pictoFolder.mkdirs(); //download it AsyncHttpClient client = new AsyncHttpClient(); client.get(imgButton.getmUrl(), new FileAsyncHttpResponseHandler(new File(imgButton.getmImageFile())) { @Override public void onFailure(int statusCode, Header[] headers, Throwable throwable, File file) { Toast.makeText(getActivity(), getString(R.string.download_error) + file.toString(), Toast.LENGTH_LONG).show(); } @Override public void onSuccess(int statusCode, Header[] headers, File downloadedFile) { if (new File(imgButton.getmImageFile()).exists()) { imgButton.setImageBitmap( BitmapFactory.decodeFile(imgButton.getmImageFile())); } else { Toast.makeText(getActivity(), getString(R.string.image_save_error), Toast.LENGTH_SHORT).show(); } } }); } else { Toast.makeText(getActivity(), getString(R.string.image_save_error), Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(getActivity(), getString(R.string.image_save_error), Toast.LENGTH_SHORT) .show(); } } else imgButton.setImageBitmap(BitmapFactory.decodeFile(imgButton.getmImageFile())); } ViewGroup parent = (ViewGroup) imgButton.getParent(); if (parent != null) parent.removeAllViews(); btnContainer.addView(imgButton); mButtons.add(imgButton); imgButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int index = mButtons.indexOf(v); if (mListener != null) mListener.tapOnSpeakableButton(mButtons.get(index), mBoardLevel); } }); } } this.mBoard.setButtons(mButtons.size() > configButtons.size() ? mButtons : configButtons); return tableContainer; }