List of usage examples for android.widget LinearLayout setOrientation
public void setOrientation(@OrientationMode int orientation)
From source file:com.cmput301w15t15.travelclaimsapp.activitys.EditClaimActivity.java
@Override public boolean onContextItemSelected(MenuItem item) { final AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); switch (item.getItemId()) { case R.id.cmenu_dlist_delete: ClaimListController.removeDestination(destAdaptor.getItem(info.position), theClaim); destAdaptor.notifyDataSetChanged(); return true; case R.id.cmenu_dlist_edit: //show a dialog for editing destinations final EditText enterLocation = new EditText(this); final EditText enterReason = new EditText(this); enterLocation.setText(destAdaptor.getItem(info.position).getLocation()); enterReason.setText(destAdaptor.getItem(info.position).getReason()); enterLocation.setHint("Enter location"); enterReason.setHint("Enter reason"); LinearLayout linearLayout = new LinearLayout(this); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.addView(enterLocation); linearLayout.addView(enterReason); AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setView(linearLayout);/*www .j av a 2 s . co m*/ alert.setPositiveButton("Add", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { destAdaptor.getItem(info.position).setLocation(enterLocation.getText().toString()); destAdaptor.getItem(info.position).setReason(enterReason.getText().toString()); destAdaptor.notifyDataSetChanged(); } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); alert.show(); return true; case R.id.cmenu_dlist_geolocation: adaptorPos = info.position; AlertDialog.Builder alertGl = new AlertDialog.Builder(this); alertGl.setPositiveButton("GPS", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (GeoLocationController.checkGPSEnabled()) { GeoLocationController.setDestinationGeoLocationGPS(destAdaptor.getItem(info.position)); destAdaptor.notifyDataSetChanged(); } } }); alertGl.setNegativeButton("Map", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //Open map view \ Intent intent = GeoLocationController.pickLocationIntent(EditClaimActivity.this); startActivityForResult(intent, GET_GEOLOCATION_CODE); } }); alertGl.show(); return true; case R.id.cmenu_delete_tag: ClaimListController.removeTag(theClaim, tagAdaptor.getItem(info.position)); tagAdaptor.notifyDataSetChanged(); return true; case R.id.cmenu_rename_tag: //create a Alert dialog for editing tag name final TextView enterTag = new AutoCompleteTextView(this); enterTag.setHint("Enter tag"); AlertDialog.Builder alertTag = new AlertDialog.Builder(this); alertTag.setView(enterTag); alertTag.setPositiveButton("Add", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { tagAdaptor.getItem(info.position).setName(enterTag.getText().toString()); tagAdaptor.notifyDataSetChanged(); } }); alertTag.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); alertTag.show(); return true; default: return super.onContextItemSelected(item); } }
From source file:com.mozhuowen.widget.views.PagerSlidingTabStrip.java
private void addTextTab(final int position, String title, String content) { LinearLayout tab = new LinearLayout(getContext()); tab.setGravity(Gravity.CENTER);//www .ja va 2 s . c o m tab.setOrientation(LinearLayout.VERTICAL); TextView titletext = new TextView(getContext()); titletext.setText(title); titletext.setGravity(Gravity.CENTER); titletext.setSingleLine(); TextView contenttext = new TextView(getContext()); contenttext.setText(content); contenttext.setGravity(Gravity.CENTER); contenttext.setSingleLine(); tab.addView(titletext); tab.addView(contenttext); addTab(position, tab); }
From source file:bruce.kk.brucetodos.MainActivity.java
/** * ???/*from w w w. j a v a 2 s .com*/ * * @param position */ private void modifyItem(final int position) { final UnFinishItem item = dataList.get(position); LogDetails.d(item); LinearLayout linearLayout = new LinearLayout(MainActivity.this); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); linearLayout.setLayoutParams(layoutParams); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.setBackgroundColor(getResources().getColor(android.R.color.black)); final EditText editText = new EditText(MainActivity.this); editText.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); editText.setTextColor(getResources().getColor(android.R.color.holo_green_light)); editText.setHint(item.content); editText.setHintTextColor(getResources().getColor(android.R.color.holo_orange_dark)); linearLayout.addView(editText); Button btnModify = new Button(MainActivity.this); btnModify.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); btnModify.setText(""); btnModify.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); btnModify.setTextColor(getResources().getColor(android.R.color.holo_blue_bright)); btnModify.setBackgroundColor(getResources().getColor(android.R.color.black)); linearLayout.addView(btnModify); Button btnDeleteItem = new Button(MainActivity.this); btnDeleteItem.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); btnDeleteItem.setText(""); btnDeleteItem.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); btnDeleteItem.setTextColor(getResources().getColor(android.R.color.holo_blue_bright)); btnDeleteItem.setBackgroundColor(getResources().getColor(android.R.color.black)); linearLayout.addView(btnDeleteItem); final PopupWindow popupWindow = new PopupWindow(linearLayout, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); popupWindow.setBackgroundDrawable(new BitmapDrawable()); // ? popupWindow.setTouchable(true); popupWindow.setFocusable(true); popupWindow.setOutsideTouchable(true); popupWindow.showAtLocation(contentMain, Gravity.CENTER, 0, 0); btnModify.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { LogDetails.d(": " + editText.getText().toString()); if (!TextUtils.isEmpty(editText.getText().toString().trim())) { Date date = new Date(); item.content = editText.getText().toString().trim(); item.modifyDay = date; item.finishDay = null; ProgressDialogUtils.showProgressDialog(); presenter.modifyItem(item); dataList.set(position, item); refreshData(true); popupWindow.dismiss(); } else { Toast.makeText(MainActivity.this, "~", Toast.LENGTH_SHORT).show(); } } }); btnDeleteItem.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dataList.remove(position); presenter.deleteItem(item); refreshData(false); popupWindow.dismiss(); } }); }
From source file:org.zywx.wbpalmstar.plugin.uexscrawl.PhotoScrawlActivity.java
private void showColorChoosePop() { LinearLayout linearLayout = new LinearLayout(this); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); int margin = EUExUtil.dipToPixels(8); lp.setMargins(margin / 2, margin, margin / 2, margin); linearLayout.setLayoutParams(lp);//from w w w. j a v a 2s .c om linearLayout.setOrientation(LinearLayout.HORIZONTAL); for (int color : colors) { linearLayout.addView(getColorImageView(color)); } HorizontalScrollView scrollView = new HorizontalScrollView(this); LinearLayout.LayoutParams scrollLp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); scrollView.setLayoutParams(scrollLp); scrollView.addView(linearLayout); int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); scrollView.measure(w, h); PopupWindow popupWindow = new PopupWindow(scrollView); popupWindow.setBackgroundDrawable(new ColorDrawable()); popupWindow.setFocusable(true); popupWindow.setOutsideTouchable(true); popupWindow.setWidth(mImageContentLayout.getWidth()); popupWindow.setHeight(scrollView.getMeasuredHeight()); popupWindow.showAtLocation(mImageContentLayout, Gravity.BOTTOM, 0, mCloseLayout.getHeight() + mBrushLayout.getHeight() + popupWindow.getHeight()); }
From source file:org.telegram.ui.LanguageSelectActivity.java
@Override public View createView(Context context) { searching = false;// w w w.j av a 2 s. c o m searchWas = false; actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); actionBar.setTitle(LocaleController.getString("Language", R.string.Language)); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(int id) { if (id == -1) { finishFragment(); } } }); ActionBarMenu menu = actionBar.createMenu(); ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true) .setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() { @Override public void onSearchExpand() { searching = true; } @Override public void onSearchCollapse() { search(null); searching = false; searchWas = false; if (listView != null) { emptyTextView.setVisibility(View.GONE); listView.setAdapter(listAdapter); } } @Override public void onTextChanged(EditText editText) { String text = editText.getText().toString(); search(text); if (text.length() != 0) { searchWas = true; if (listView != null) { listView.setAdapter(searchListViewAdapter); } } } }); item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search)); listAdapter = new ListAdapter(context); searchListViewAdapter = new SearchAdapter(context); fragmentView = new FrameLayout(context); fragmentView.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background)); LinearLayout emptyTextLayout = new LinearLayout(context); emptyTextLayout.setVisibility(View.INVISIBLE); emptyTextLayout.setOrientation(LinearLayout.VERTICAL); ((FrameLayout) fragmentView).addView(emptyTextLayout); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) emptyTextLayout.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; layoutParams.gravity = Gravity.TOP; emptyTextLayout.setLayoutParams(layoutParams); emptyTextLayout.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); emptyTextView = new TextView(context); emptyTextView.setTextColor(0xff808080); emptyTextView.setTextSize(20); emptyTextView.setGravity(Gravity.CENTER); emptyTextView.setText(LocaleController.getString("NoResult", R.string.NoResult)); emptyTextLayout.addView(emptyTextView); LinearLayout.LayoutParams layoutParams1 = (LinearLayout.LayoutParams) emptyTextView.getLayoutParams(); layoutParams1.width = LayoutHelper.MATCH_PARENT; layoutParams1.height = LayoutHelper.MATCH_PARENT; layoutParams1.weight = 0.5f; emptyTextView.setLayoutParams(layoutParams1); FrameLayout frameLayout = new FrameLayout(context); emptyTextLayout.addView(frameLayout); layoutParams1 = (LinearLayout.LayoutParams) frameLayout.getLayoutParams(); layoutParams1.width = LayoutHelper.MATCH_PARENT; layoutParams1.height = LayoutHelper.MATCH_PARENT; layoutParams1.weight = 0.5f; frameLayout.setLayoutParams(layoutParams1); listView = new ListView(context); listView.setEmptyView(emptyTextLayout); listView.setVerticalScrollBarEnabled(false); listView.setDivider(null); listView.setDividerHeight(0); listView.setAdapter(listAdapter); ((FrameLayout) fragmentView).addView(listView); layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; listView.setLayoutParams(layoutParams); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { LocaleController.LocaleInfo localeInfo = null; if (searching && searchWas) { if (i >= 0 && i < searchResult.size()) { localeInfo = searchResult.get(i); } } else { if (i >= 0 && i < LocaleController.getInstance().sortedLanguages.size()) { localeInfo = LocaleController.getInstance().sortedLanguages.get(i); } } if (localeInfo != null) { LocaleController.getInstance().applyLanguage(localeInfo, true); parentLayout.rebuildAllFragmentViews(false); } finishFragment(); } }); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) { LocaleController.LocaleInfo localeInfo = null; if (searching && searchWas) { if (i >= 0 && i < searchResult.size()) { localeInfo = searchResult.get(i); } } else { if (i >= 0 && i < LocaleController.getInstance().sortedLanguages.size()) { localeInfo = LocaleController.getInstance().sortedLanguages.get(i); } } if (localeInfo == null || localeInfo.pathToFile == null || getParentActivity() == null) { return false; } final LocaleController.LocaleInfo finalLocaleInfo = localeInfo; AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("DeleteLocalization", R.string.DeleteLocalization)); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("Delete", R.string.Delete), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if (LocaleController.getInstance().deleteLanguage(finalLocaleInfo)) { if (searchResult != null) { searchResult.remove(finalLocaleInfo); } if (listAdapter != null) { listAdapter.notifyDataSetChanged(); } if (searchListViewAdapter != null) { searchListViewAdapter.notifyDataSetChanged(); } } } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); return true; } }); listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView absListView, int i) { if (i == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) { AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus()); } } @Override public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { } }); return fragmentView; }
From source file:com.near.chimerarevo.fragments.PostFragment.java
private void addGallery(final String[] imgUrls) { numGalleries++;/*from w w w . j a v a 2 s . c o m*/ if (!PreferenceManager.getDefaultSharedPreferences(getActivity()).getBoolean("load_imgs_pref", true) || numGalleries > Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(getActivity()) .getString("gallery_num_pref", "20"))) return; HorizontalScrollView hsv = new HorizontalScrollView(getActivity()); LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); params.gravity = Gravity.CENTER_HORIZONTAL; params.setMargins(10, 10, 10, 0); hsv.setLayoutParams(params); LinearLayout container = new LinearLayout(getActivity()); container.setOrientation(LinearLayout.HORIZONTAL); for (int i = 0; i < imgUrls.length; i++) { final ImageView img = new ImageView(getActivity()); LayoutParams imgPar = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); if (i == 0) imgPar.setMargins(5, 10, 0, 10); else imgPar.setMargins(10, 10, 0, 10); img.setLayoutParams(imgPar); img.setScaleType(ImageView.ScaleType.CENTER_INSIDE); container.addView(img); final DisplayImageOptions options = new DisplayImageOptions.Builder().cacheOnDisk(false) .cacheInMemory(true).showImageOnLoading(R.drawable.empty_cr).bitmapConfig(Bitmap.Config.RGB_565) .imageScaleType(ImageScaleType.EXACTLY).delayBeforeLoading(200).build(); ImageLoader.getInstance().displayImage(imgUrls[i], img, options); final int k = i; img.setClickable(true); img.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { final Dialog dialog = new Dialog(getActivity()); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.img_dialog_layout); ImageLoader.getInstance().displayImage(imgUrls[k].split("\\?resize=")[0], ((TouchImageView) dialog.findViewById(R.id.dialog_image)), options); dialog.setCancelable(true); dialog.show(); } }); } hsv.addView(container); lay.addView(hsv); }
From source file:oyagev.projects.android.ArduCopter.BluetoothChat.java
private void addControl(String name, String type, int commandValue) { Log.d(TAG, "Adding cmd: " + commandValue); LinearLayout row = new LinearLayout(this); row.setOrientation(LinearLayout.HORIZONTAL); row.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); View view = new TextView(this); //hidden view for command value TextView cmdView = new TextView(this); cmdView.setLayoutParams(new LinearLayout.LayoutParams(0, 0)); cmdView.setVisibility(View.INVISIBLE); cmdView.setText(String.valueOf(commandValue)); cmdView.setTag("cmd"); //Setup the control if (type.equals("Button")) { view = new Button(this); ((Button) view).setText(name); ((Button) view).setOnClickListener(new OnClickListener() { @Override// w w w . j av a2 s. c om public void onClick(View v) { TextView cmd = (TextView) ((LinearLayout) v.getParent()).findViewWithTag("cmd"); dispatchUserEvent((int) Integer.valueOf(cmd.getText().toString()), new byte[] { 1 }); } }); } else if (type.equals("Edit")) { view = new EditText(this); ((EditText) view).setText(name); } else if (type.equals("Label")) { view = new TextView(this); ((TextView) view).setText(name); } else if (type.equals("Scrollbar")) { view = new LinearLayout(this); TextView text = new TextView(this); text.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); text.setText(name); text.setTag("seek_text"); SeekBar bar = new SeekBar(this); bar.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); ((LinearLayout) view).setOrientation(LinearLayout.VERTICAL); ((LinearLayout) view).addView(text); ((LinearLayout) view).addView(bar); bar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { TextView cmd = (TextView) ((LinearLayout) ((LinearLayout) seekBar.getParent()).getParent()) .findViewWithTag("cmd"); ByteBuffer buffer = ByteBuffer.allocate(2); buffer.putShort((short) progress); dispatchUserEvent((int) Integer.valueOf(cmd.getText().toString()), buffer.array()); } }); } else if (type.equals("Input String")) { view = new LinearLayout(this); TextView text = new TextView(this); text.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); text.setText(name); text.setTag("inp_text"); TextView inp = new TextView(this); inp.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); //((LinearLayout)view).setOrientation(LinearLayout.VERTICAL); ((LinearLayout) view).addView(text); ((LinearLayout) view).addView(inp); ycomm.registerCallback((byte) commandValue, new CallbackView(getApplicationContext(), inp) { @Override public void run(byte type, byte command, byte[] data, byte data_langth) { // TODO Auto-generated method stub String str = new String(data); ((TextView) this.view).setText(str); } }); } else { return; } view.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); row.addView(cmdView); row.addView(view); ((LinearLayout) findViewById(R.id.controls_layout)).addView(row); }
From source file:com.achep.header2actionbar.HeaderFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final Activity activity = getActivity(); assert activity != null; mFrameLayout = new FrameLayout(activity); mHeader = onCreateHeaderView(inflater, mFrameLayout); mHeaderHeader = mHeader.findViewById(android.R.id.title); mHeaderBackground = mHeader.findViewById(android.R.id.background); assert mHeader.getLayoutParams() != null; mHeaderHeight = mHeader.getLayoutParams().height; mFakeHeader = new Space(activity); mFakeHeader.setLayoutParams(new ListView.LayoutParams(0, mHeaderHeight)); View content = onCreateContentView(inflater, mFrameLayout); if (content instanceof ListView) { isListViewEmpty = true;/* ww w . j a va2 s . co m*/ final ListView listView = (ListView) content; listView.addHeaderView(mFakeHeader); onSetAdapter(); listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView absListView, int scrollState) { if (mOnScrollListener != null) { mOnScrollListener.onScrollStateChanged(absListView, scrollState); } } @Override public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (mOnScrollListener != null) { mOnScrollListener.onScroll(absListView, firstVisibleItem, visibleItemCount, totalItemCount); } isListViewEmpty = listView.getAdapter() == null; if (isListViewEmpty) { scrollHeaderTo(0); } else { final View child = absListView.getChildAt(0); assert child != null; scrollHeaderTo(child == mFakeHeader ? child.getTop() : -mHeaderHeight); // Log.v("header height",String.format("mHeaderHeight:%s",mHeaderHeight)); } } }); } else if (content instanceof GridView) { isListViewEmpty = true; final GridView grid = (GridView) content; //isListViewEmpty = grid.getAdapter() == null; // grid.addHeaderView(mFakeHeader); // Merge fake header view and content view. final LinearLayout view = new LinearLayout(activity); view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); view.setOrientation(LinearLayout.VERTICAL); view.addView(mFakeHeader); view.addView(grid); grid.setOnScrollListener(new AbsListView.OnScrollListener() { private ListViewScrollTracker mScrollTracker;; @Override public void onScrollStateChanged(AbsListView absListView, int scrollState) { if (mOnScrollListener != null) { mOnScrollListener.onScrollStateChanged(absListView, scrollState); } } public int getGridScrollY(GridView grid) { Method privateStringMethod = null; Integer scrollOffset = null; Integer scrollExtent = null; Integer scrollRange = null; try { privateStringMethod = GridView.class.getDeclaredMethod("computeVerticalScrollOffset", null); privateStringMethod.setAccessible(true); scrollOffset = (Integer) privateStringMethod.invoke(grid, null); privateStringMethod = GridView.class.getDeclaredMethod("computeVerticalScrollExtent", null); privateStringMethod.setAccessible(true); scrollExtent = (Integer) privateStringMethod.invoke(grid, null); privateStringMethod = GridView.class.getDeclaredMethod("computeVerticalScrollRange", null); privateStringMethod.setAccessible(true); scrollRange = (Integer) privateStringMethod.invoke(grid, null); } catch (NoSuchMethodException 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 (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } return scrollRange;//scrollExtent*scrollOffset; } @Override public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (mScrollTracker == null) mScrollTracker = new ListViewScrollTracker(absListView); mScrollPosition = mScrollTracker.calculateIncrementalOffset(firstVisibleItem, visibleItemCount); Log.v("header", "scrollPosition:" + mScrollPosition); if (mOnScrollListener != null) { mOnScrollListener.onScroll(absListView, firstVisibleItem, visibleItemCount, totalItemCount); } final View child = absListView.getChildAt(0); if (child != null) { int gridScrollY = mScrollPosition;//getGridScrollY((GridView) absListView); scrollHeaderTo(-gridScrollY); //change the size of the fake header on scrolling int currentHeight = mFakeHeader.getLayoutParams().height; Integer fakeHeaderHeight = (int) (mHeaderHeight - (gridScrollY * 2)); mFakeHeader.setLayoutParams(new android.widget.LinearLayout.LayoutParams( mFakeHeader.getWidth(), fakeHeaderHeight)); // setViewTranslationY(mFrameLayout, -1*(gridScrollY)); } else scrollHeaderTo(0); } }); content = view; } else { // Merge fake header view and content view. final LinearLayout view = new LinearLayout(activity); view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); view.setOrientation(LinearLayout.VERTICAL); view.addView(mFakeHeader); view.addView(content); // Put merged content to ScrollView final NotifyingScrollView scrollView = new NotifyingScrollView(activity); scrollView.addView(view); scrollView.setOnScrollChangedListener(new NotifyingScrollView.OnScrollChangedListener() { @Override public void onScrollChanged(ScrollView who, int l, int t, int oldl, int oldt) { scrollHeaderTo(-t); } }); content = scrollView; } mFrameLayout.addView(content); mFrameLayout.addView(mHeader); // Content overlay view always shows at the top of content. if ((mContentOverlay = onCreateContentOverlayView(inflater, mFrameLayout)) != null) { mFrameLayout.addView(mContentOverlay, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); } // Post initial scroll mFrameLayout.post(new Runnable() { @Override public void run() { scrollHeaderTo(0, true); } }); return mFrameLayout; }
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);/*w w w .j av a2 s . c om*/ 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; }
From source file:com.TakeTaxi.jy.OnrouteScreen.java
public void pingpicked(JSONObject json) { try {//from w ww .ja va 2 s . c o m int driverpicked = json.getInt("picked"); int drivercancelled = json.getInt("dcancel"); int starttime = json.getInt("datetime"); // /////////////////////////////// DRIVER CANCEL //////// if (drivercancelled == 1) { // //// DRIVER CANCEL LATE ///// if (starttime + 300 <= Query.getServerTime()) { handlerboolean = false; handler.removeCallbacks(r); AlertDialog dcancelbuilder = new AlertDialog.Builder(OnrouteScreen.this).create(); dcancelbuilder .setMessage("Job has been cancelled.\nWould you like to report a late cancellation?."); // //// DRIVER CANCEL LATE - NO REPORT LATE///// button_cancelJob_noquery(dcancelbuilder); // //// DRIVER CANCEL LATE - REPORT LATE ///// button_drivercancel_reportlate(dcancelbuilder); dcancelbuilder.show(); } else { // /////////////////////////////// DRIVER CANCEL NO ALERTS - // WITHIN TIME LIMIT/////////////// handlerboolean = false; handler.removeCallbacks(r); alertdialog_drivercancelintime(); } } if (driverpicked == 1) { // /////////////////////////////// CONFIRM PICK UP // /////////////////////////////////////////// handlerboolean = false; handler.removeCallbacks(r); AlertDialog.Builder alert = new AlertDialog.Builder(OnrouteScreen.this); final Drawable thumbsup = getResources().getDrawable(R.drawable.thumbsup); final Drawable thumbsupwhite = getResources().getDrawable(R.drawable.thumbsupwhite); final Drawable thumbsdown = getResources().getDrawable(R.drawable.thumbsdown); final Drawable thumbsdownwhite = getResources().getDrawable(R.drawable.thumbsdownwhite); LinearLayout layout = new LinearLayout(OnrouteScreen.this); layout.setOrientation(1); layout.setGravity(17); TextView tx1 = new TextView(OnrouteScreen.this); tx1.setText("Driver says you have been picked up"); tx1.setGravity(17); tx1.setTextSize(20); tx1.setTextColor(Color.WHITE); tx1.setPadding(10, 10, 10, 10); TextView tx2 = new TextView(OnrouteScreen.this); tx2.setText("Please rate your driver"); tx2.setGravity(17); tx2.setTextSize(16); LinearLayout imglayout = new LinearLayout(OnrouteScreen.this); imglayout.setOrientation(0); imglayout.setGravity(17); final ImageView ivup = new ImageView(OnrouteScreen.this); ivup.setImageDrawable(thumbsupwhite); ivup.setClickable(true); ivup.setPadding(0, 5, 30, 5); final ImageView ivdown = new ImageView(OnrouteScreen.this); ivdown.setImageDrawable(thumbsdownwhite); ivdown.setClickable(true); ivup.setPadding(30, 5, 0, 5); imglayout.addView(ivup); imglayout.addView(ivdown); layout.addView(tx1); layout.addView(tx2); layout.addView(imglayout); // /////////////////////////////// CONFIRM PICK UP - RATINGS // /////////////////////////////////////////// ivup.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (thumbsupboolean == false) { thumbsupboolean = true; thumbsdownboolean = false; ivup.setImageDrawable(thumbsup); ivdown.setImageDrawable(thumbsdownwhite); rating = 1; } else { thumbsupboolean = false; ivup.setImageDrawable(thumbsupwhite); rating = 0; } } }); ivdown.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (thumbsdownboolean == false) { thumbsdownboolean = true; thumbsupboolean = false; ivdown.setImageDrawable(thumbsdown); ivup.setImageDrawable(thumbsupwhite); AlertDialog alert = new AlertDialog.Builder(OnrouteScreen.this).create(); alert.setMessage("Please pick one"); alert.setButton("No show", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { rating = -1; } }); alert.setButton2("Driver late", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { rating = -2; } }); alert.setButton3("Poor service", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { rating = -3; } }); alert.show(); } else { thumbsupboolean = false; ivdown.setImageDrawable(thumbsdownwhite); rating = 0; } } }); button_completed_finish(alert); alert.setView(layout); alert.create(); alert.show(); } else { } } catch (JSONException e) { } }