private RelativeLayout getPageView() { rlPage = new RelativeLayout(getContext()); rlPage.setBackgroundDrawable(background); if (dialogMode) { RelativeLayout rlDialog = new RelativeLayout(getContext()); rlDialog.setBackgroundColor(0xc0323232); int dp_8 = dipToPx(getContext(), 8); int width = getScreenWidth(getContext()) - dp_8 * 2; RelativeLayout.LayoutParams lpDialog = new RelativeLayout.LayoutParams(width, LayoutParams.WRAP_CONTENT); lpDialog.topMargin = dp_8; lpDialog.bottomMargin = dp_8; lpDialog.addRule(RelativeLayout.CENTER_IN_PARENT); rlDialog.setLayoutParams(lpDialog); rlPage.addView(rlDialog); rlDialog.addView(getPageTitle()); rlDialog.addView(getPageBody()); rlDialog.addView(getImagePin()); } else { rlPage.addView(getPageTitle()); rlPage.addView(getPageBody()); rlPage.addView(getImagePin()); } return rlPage; }
private void initViews(Context context, int customLeftMenuId, int customRightMenuId) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); inflater.inflate(R.layout.residemenu_custom, this); if (customLeftMenuId >= 0) { scrollViewLeftMenu = inflater.inflate(customLeftMenuId, this, false); } else { scrollViewLeftMenu = inflater.inflate(R.layout.residemenu_custom_left_scrollview, this, false); layoutLeftMenu = (LinearLayout) scrollViewLeftMenu.findViewById(R.id.layout_left_menu); } if (customRightMenuId >= 0) { scrollViewRightMenu = inflater.inflate(customRightMenuId, this, false); } else { scrollViewRightMenu = inflater.inflate(R.layout.residemenu_custom_right_scrollview, this, false); layoutRightMenu = (LinearLayout) scrollViewRightMenu.findViewById(R.id.layout_right_menu); } imageViewShadow = (ImageView) findViewById(R.id.iv_shadow); imageViewBackground = (ImageView) findViewById(R.id.iv_background); RelativeLayout menuHolder = (RelativeLayout) findViewById(R.id.sv_menu_holder); menuHolder.addView(scrollViewLeftMenu); menuHolder.addView(scrollViewRightMenu); }
private RelativeLayout createPin() { final RelativeLayout pinLayout = new RelativeLayout(getContext()); pinLayout.setVisibility(View.INVISIBLE); final Pin pin = new Pin(getContext()); pin.setId(ID_PIN); final RelativeLayout.LayoutParams pinParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); pinParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); pinParams.addRule(RelativeLayout.ALIGN_BOTTOM, ID_PIN_TEXT); pinParams.addRule(RelativeLayout.ALIGN_TOP, ID_PIN_TEXT); pin.setLayoutParams(pinParams); pinLayout.addView(pin); final TextView indicatorTextView = new TextView(getContext()); indicatorTextView.setId(ID_PIN_TEXT); final RelativeLayout.LayoutParams indicatorParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); indicatorParams.addRule(RelativeLayout.LEFT_OF, ID_PIN); indicatorTextView.setLayoutParams(indicatorParams); indicatorTextView.setTextColor(Color.WHITE); indicatorTextView.setGravity(Gravity.CENTER); indicatorTextView.setBackgroundColor(GREY_LIGHT); pinLayout.addView(indicatorTextView); return pinLayout; }
protected void setRightButtonText(String text) { RelativeLayout rightView = (RelativeLayout) findViewById(R.id.right_view); rightView.removeAllViews(); int padding = dp2px(6); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); lp.addRule(RelativeLayout.CENTER_IN_PARENT); lp.setMargins(0, 0, dp2px(8), 0); TextView tv = new TextView(this); tv.setText(text); tv.setTextColor(0xFF666666); tv.setTextSize(16.f); tv.setLayoutParams(lp); tv.setBackgroundResource(R.drawable.btn_gray); tv.setPadding(2 * padding, padding, 2 * padding, padding); tv.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { onRightButtonClicked(v); } }); rightView.addView(tv); rightView.setVisibility(View.VISIBLE); }
@Override public void onCreate(Bundle savedInstanceState) { // Open app in fullscreen mode super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow() .setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_main); noteLayout = (RelativeLayout) findViewById(R.id.notePanel); canvasView = new CanvasView(this); switchy = new Switch(this); switchy = (Switch) findViewById(R.id.switch1); switchy.setOnCheckedChangeListener(this); inkRegion = new ArrayList<InkRegion>(); inkRegion.add(new InkRegion(this, 0)); inkRegion.add(new InkRegion(this, 1)); inkRegion.get(0).setBackgroundColor(Color.YELLOW); inkRegion.get(1).setBackgroundColor(Color.CYAN); // noteLayout.addView(canvasView); noteLayout.addView(canvasView); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(200, 200); params.leftMargin = 300; params.topMargin = 200; inkRegion.get(0).setBackgroundColor(Color.GREEN); inkRegion.get(0).setPivotX(0); inkRegion.get(0).setPivotY(0); inkRegion.get(0).setRotation(45); inkRegion.get(0).setScaleX((float) 0.2); inkRegion.get(0).setScaleY((float) 0.3); noteLayout.addView(inkRegion.get(0), params); RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams(200, 200); params1.leftMargin = 300; params1.topMargin = 200; inkRegion.get(1).setBackgroundColor(Color.BLUE); inkRegion.get(1).setPivotX(0); inkRegion.get(1).setPivotY(0); inkRegion.get(1).setRotation(90); inkRegion.get(1).setScaleX((float) 0.2); inkRegion.get(1).setScaleY((float) 0.2); noteLayout.addView(inkRegion.get(1), params1); }
// shared image container private RelativeLayout getThumbView() { rlThumb = new RelativeLayout(getContext()); rlThumb.setId(1); int dp_82 = dipToPx(getContext(), 82); int dp_98 = dipToPx(getContext(), 98); LayoutParams lpThumb = new LayoutParams(dp_82, dp_98); rlThumb.setLayoutParams(lpThumb); ivImage = new ImageView(getContext()); int resId = getBitmapRes(activity, "ssdk_oks_btn_back_nor"); if (resId > 0) { ivImage.setBackgroundResource(resId); } ivImage.setScaleType(ScaleType.CENTER_INSIDE); ivImage.setImageBitmap(image); int dp_4 = dipToPx(getContext(), 4); ivImage.setPadding(dp_4, dp_4, dp_4, dp_4); int dp_74 = dipToPx(getContext(), 74); RelativeLayout.LayoutParams lpImage = new RelativeLayout.LayoutParams(dp_74, dp_74); int dp_16 = dipToPx(getContext(), 16); int dp_8 = dipToPx(getContext(), 8); lpImage.setMargins(0, dp_16, dp_8, 0); ivImage.setLayoutParams(lpImage); ivImage.setOnClickListener( new OnClickListener() { public void onClick(View v) { if (image != null && !image.isRecycled()) { PicViewer pv = new PicViewer(); pv.setImageBitmap(image); pv.show(activity, null); } } }); rlThumb.addView(ivImage); int dp_24 = dipToPx(getContext(), 24); progressBar = new ProgressBar(getContext()); progressBar.setPadding(dp_24, dp_24, dp_24, dp_24); RelativeLayout.LayoutParams pb = new RelativeLayout.LayoutParams(dp_74, dp_74); pb.setMargins(0, dp_16, dp_8, 0); progressBar.setLayoutParams(pb); rlThumb.addView(progressBar); Button btn = new Button(getContext()); btn.setOnClickListener( new OnClickListener() { public void onClick(View v) { // remove the photo to share rlThumb.setVisibility(View.GONE); ivPin.setVisibility(View.GONE); removeImage(imgInfo); } }); resId = getBitmapRes(activity, "ssdk_oks_img_cancel"); if (resId > 0) { btn.setBackgroundResource(resId); } int dp_20 = dipToPx(getContext(), 20); RelativeLayout.LayoutParams lpBtn = new RelativeLayout.LayoutParams(dp_20, dp_20); lpBtn.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); lpBtn.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); btn.setLayoutParams(lpBtn); rlThumb.addView(btn); if (!haveImage()) { rlThumb.setVisibility(View.GONE); } return rlThumb; }
/** * Initializing the QuickScroll, this function must be called. * * <p> * * @param type the QuickScroll type. Available inputs: <b>QuickScroll.TYPE_POPUP</b> or * <b>QuickScroll.TYPE_INDICATOR</b> * @param list the ListView * @param scrollable the adapter, must implement Scrollable interface */ public void init( final int type, final ListView list, final Scrollable scrollable, final int style) { if (mInitialized) return; mType = type; mList = list; mScrollable = scrollable; mGroupPosition = -1; mFadeIn = new AlphaAnimation(.0f, 1.0f); mFadeIn.setFillAfter(true); mFadeOut = new AlphaAnimation(1.0f, .0f); mFadeOut.setFillAfter(true); mFadeOut.setAnimationListener( new AnimationListener() { public void onAnimationStart(Animation animation) {} public void onAnimationRepeat(Animation animation) {} public void onAnimationEnd(Animation animation) { mScrolling = false; } }); mScrolling = false; final float density = getResources().getDisplayMetrics().density; mList.setOnTouchListener( new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (mScrolling && (event.getAction() == MotionEvent.ACTION_MOVE || event.getAction() == MotionEvent.ACTION_DOWN)) { return true; } return false; } }); final RelativeLayout.LayoutParams containerparams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); final RelativeLayout container = new RelativeLayout(getContext()); container.setBackgroundColor(Color.TRANSPARENT); containerparams.addRule(RelativeLayout.ALIGN_TOP, getId()); containerparams.addRule(RelativeLayout.ALIGN_BOTTOM, getId()); container.setLayoutParams(containerparams); if (mType == TYPE_POPUP || mType == TYPE_POPUP_WITH_HANDLE) { mScrollIndicatorText = new TextView(getContext()); mScrollIndicatorText.setTextColor(Color.WHITE); mScrollIndicatorText.setVisibility(View.INVISIBLE); mScrollIndicatorText.setGravity(Gravity.CENTER); final RelativeLayout.LayoutParams popupparams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); popupparams.addRule(RelativeLayout.CENTER_IN_PARENT); mScrollIndicatorText.setLayoutParams(popupparams); setPopupColor(GREY_LIGHT, GREY_DARK, 1, Color.WHITE, 1); setTextPadding(mTextPadding, mTextPadding, mTextPadding, mTextPadding); container.addView(mScrollIndicatorText); } else if (mType == TYPE_INDICATOR || mType == TYPE_INDICATOR_WITH_HANDLE) { mScrollIndicator = createPin(); mScrollIndicatorText = (TextView) mScrollIndicator.findViewById(ID_PIN_TEXT); (mScrollIndicator.findViewById(ID_PIN)).getLayoutParams().width = 25; container.addView(mScrollIndicator); } // setting scrollbar width getLayoutParams().width = (int) (30 * density); mScrollIndicatorText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 32); // scrollbar setup if (style != STYLE_NONE) { final RelativeLayout layout = new RelativeLayout(getContext()); final RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); params.addRule(RelativeLayout.ALIGN_LEFT, getId()); params.addRule(RelativeLayout.ALIGN_TOP, getId()); params.addRule(RelativeLayout.ALIGN_RIGHT, getId()); params.addRule(RelativeLayout.ALIGN_BOTTOM, getId()); layout.setLayoutParams(params); mScrollbar = new View(getContext()); mScrollbar.setBackgroundColor(GREY_SCROLLBAR); final RelativeLayout.LayoutParams scrollbarparams = new RelativeLayout.LayoutParams(1, LayoutParams.MATCH_PARENT); scrollbarparams.addRule(RelativeLayout.CENTER_HORIZONTAL); scrollbarparams.topMargin = mScrollbarMargin; scrollbarparams.bottomMargin = mScrollbarMargin; mScrollbar.setLayoutParams(scrollbarparams); layout.addView(mScrollbar); ((ViewGroup) mList.getParent()).addView(layout); // creating the handlebar if (mType == TYPE_INDICATOR_WITH_HANDLE || mType == TYPE_POPUP_WITH_HANDLE) { mHandlebar = new View(getContext()); setHandlebarColor(BLUE_LIGHT, BLUE_LIGHT, BLUE_LIGHT_SEMITRANSPARENT); final RelativeLayout.LayoutParams handleparams = new RelativeLayout.LayoutParams((int) (12 * density), (int) (36 * density)); mHandlebar.setLayoutParams(handleparams); ((RelativeLayout.LayoutParams) mHandlebar.getLayoutParams()) .addRule(RelativeLayout.CENTER_HORIZONTAL); layout.addView(mHandlebar); mList.setOnScrollListener( new OnScrollListener() { public void onScrollStateChanged(AbsListView view, int scrollState) {} @SuppressLint("NewApi") public void onScroll( AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (!mScrolling && totalItemCount - visibleItemCount > 0) { moveHandlebar( getHeight() * firstVisibleItem / (totalItemCount - visibleItemCount)); } } }); } } mInitialized = true; ((ViewGroup) mList.getParent()).addView(container); }