Java Code Examples for android.widget.ScrollView#setFillViewport()

The following examples show how to use android.widget.ScrollView#setFillViewport() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChangePhoneActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public View createView(Context context) {
    actionBar.setTitle(LocaleController.getString("AppName", R.string.AppName));
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == done_button) {
                views[currentViewNum].onNextPressed();
            } else if (id == -1) {
                finishFragment();
            }
        }
    });

    ActionBarMenu menu = actionBar.createMenu();
    doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));

    fragmentView = new ScrollView(context);
    ScrollView scrollView = (ScrollView) fragmentView;
    scrollView.setFillViewport(true);

    FrameLayout frameLayout = new FrameLayout(context);
    scrollView.addView(frameLayout, LayoutHelper.createScroll(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT));

    views[0] = new PhoneView(context);
    views[1] = new LoginActivitySmsView(context, 1);
    views[2] = new LoginActivitySmsView(context, 2);
    views[3] = new LoginActivitySmsView(context, 3);
    views[4] = new LoginActivitySmsView(context, 4);

    for (int a = 0; a < views.length; a++) {
        views[a].setVisibility(a == 0 ? View.VISIBLE : View.GONE);
        frameLayout.addView(views[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, a == 0 ? LayoutHelper.WRAP_CONTENT : LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, AndroidUtilities.isTablet() ? 26 : 18, 30, AndroidUtilities.isTablet() ? 26 : 18, 0));
    }

    actionBar.setTitle(views[0].getHeaderName());

    return fragmentView;
}
 
Example 2
Source File: ScrollViewStyler.java    From dynamico with Apache License 2.0 5 votes vote down vote up
@Override
public View style(View view, JSONObject attributes) throws Exception {
    super.style(view, attributes);

    ScrollView scrollView = (ScrollView) view;

    if(attributes.has("fillViewport")) {
        scrollView.setFillViewport(attributes.getBoolean("fillViewport"));
    }

    if(attributes.has("smoothScrollingEnabled")) {
        scrollView.setSmoothScrollingEnabled(attributes.getBoolean("smoothScrollingEnabled"));
    }

    if(attributes.has("overScrollMode")) {
        String mode = attributes.getString("overScrollMode");

        if(mode.equalsIgnoreCase("always")) {
            scrollView.setOverScrollMode(ScrollView.OVER_SCROLL_ALWAYS);
        }else if(mode.equalsIgnoreCase("never")) {
            scrollView.setOverScrollMode(ScrollView.OVER_SCROLL_NEVER);
        }else if(mode.equalsIgnoreCase("if_content_scrolls")) {
            scrollView.setOverScrollMode(ScrollView.OVER_SCROLL_IF_CONTENT_SCROLLS);
        }
    }

    return scrollView;
}
 
Example 3
Source File: ChangePhoneActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public View createView(Context context) {
    actionBar.setTitle(LocaleController.getString("AppName", R.string.AppName));
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == done_button) {
                views[currentViewNum].onNextPressed();
            } else if (id == -1) {
                finishFragment();
            }
        }
    });

    ActionBarMenu menu = actionBar.createMenu();
    doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));

    fragmentView = new ScrollView(context);
    ScrollView scrollView = (ScrollView) fragmentView;
    scrollView.setFillViewport(true);

    FrameLayout frameLayout = new FrameLayout(context);
    scrollView.addView(frameLayout, LayoutHelper.createScroll(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT));

    views[0] = new PhoneView(context);
    views[1] = new LoginActivitySmsView(context, 1);
    views[2] = new LoginActivitySmsView(context, 2);
    views[3] = new LoginActivitySmsView(context, 3);
    views[4] = new LoginActivitySmsView(context, 4);

    for (int a = 0; a < views.length; a++) {
        views[a].setVisibility(a == 0 ? View.VISIBLE : View.GONE);
        frameLayout.addView(views[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, a == 0 ? LayoutHelper.WRAP_CONTENT : LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, AndroidUtilities.isTablet() ? 26 : 18, 30, AndroidUtilities.isTablet() ? 26 : 18, 0));
    }

    actionBar.setTitle(views[0].getHeaderName());

    return fragmentView;
}
 
Example 4
Source File: DisplayModelActivity.java    From nosey with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    context = this;
    textSize = (int) getResources().getDimension(R.dimen.cell_text_size);
    padding = (int) getResources().getDimension(R.dimen.cell_padding);
    
    Nosey nosey = Nosey.getInstance(this);
    Inspector.ModelMapInspector inspector = new Inspector.ModelMapInspector();
    inspector.inspect(nosey);

    String modelKey = getIntent().getStringExtra(EXTRA_MODEL_KEY);
    model = inspector.getModelMap().get(modelKey);
    methods = model.getDeclaredMethods();
    Arrays.sort(methods, new MemberComparator<Method>());
    
    TableLayout table = new TableLayout(this);
    addModelFieldHeaders(table, inspector);
    addModelDataRows(table, inspector);

    ScrollView scrollView = new ScrollView(this);
    scrollView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    scrollView.setHorizontalScrollBarEnabled(true);
    scrollView.setVerticalScrollBarEnabled(true);
    scrollView.setFillViewport(true);

    HorizontalScrollView horizontalScrollView = new HorizontalScrollView(this);
    horizontalScrollView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    horizontalScrollView.setHorizontalScrollBarEnabled(true);
    horizontalScrollView.setVerticalScrollBarEnabled(true);
    horizontalScrollView.setFillViewport(true);
    
    scrollView.addView(horizontalScrollView);
    horizontalScrollView.addView(table);
    
    setContentView(scrollView);
}
 
Example 5
Source File: DisplayModelActivity.java    From nosey with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    context = this;
    textSize = (int) getResources().getDimension(R.dimen.cell_text_size);
    padding = (int) getResources().getDimension(R.dimen.cell_padding);
    
    Nosey nosey = Nosey.getInstance(this);
    Inspector.ModelMapInspector inspector = new Inspector.ModelMapInspector();
    inspector.inspect(nosey);

    String modelKey = getIntent().getStringExtra(EXTRA_MODEL_KEY);
    model = inspector.getModelMap().get(modelKey);
    methods = model.getDeclaredMethods();
    Arrays.sort(methods, new MemberComparator<Method>());
    
    TableLayout table = new TableLayout(this);
    addModelFieldHeaders(table, inspector);
    addModelDataRows(table, inspector);

    ScrollView scrollView = new ScrollView(this);
    scrollView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    scrollView.setHorizontalScrollBarEnabled(true);
    scrollView.setVerticalScrollBarEnabled(true);
    scrollView.setFillViewport(true);

    HorizontalScrollView horizontalScrollView = new HorizontalScrollView(this);
    horizontalScrollView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    horizontalScrollView.setHorizontalScrollBarEnabled(true);
    horizontalScrollView.setVerticalScrollBarEnabled(true);
    horizontalScrollView.setFillViewport(true);
    
    scrollView.addView(horizontalScrollView);
    horizontalScrollView.addView(table);
    
    setContentView(scrollView);
}
 
Example 6
Source File: CancelAccountDeletionActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public View createView(Context context) {
    actionBar.setTitle(LocaleController.getString("AppName", R.string.AppName));
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == done_button) {
                views[currentViewNum].onNextPressed();
            } else if (id == -1) {
                finishFragment();
            }
        }
    });

    ActionBarMenu menu = actionBar.createMenu();
    doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
    doneButton.setVisibility(View.GONE);

    fragmentView = new ScrollView(context);
    ScrollView scrollView = (ScrollView) fragmentView;
    scrollView.setFillViewport(true);

    FrameLayout frameLayout = new FrameLayout(context);
    scrollView.addView(frameLayout, LayoutHelper.createScroll(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT));

    views[0] = new PhoneView(context);
    views[1] = new LoginActivitySmsView(context, 1);
    views[2] = new LoginActivitySmsView(context, 2);
    views[3] = new LoginActivitySmsView(context, 3);
    views[4] = new LoginActivitySmsView(context, 4);

    for (int a = 0; a < views.length; a++) {
        views[a].setVisibility(a == 0 ? View.VISIBLE : View.GONE);
        frameLayout.addView(views[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, a == 0 ? LayoutHelper.WRAP_CONTENT : LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, AndroidUtilities.isTablet() ? 26 : 18, 30, AndroidUtilities.isTablet() ? 26 : 18, 0));
    }

    actionBar.setTitle(views[0].getHeaderName());

    return fragmentView;
}
 
Example 7
Source File: CancelAccountDeletionActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public View createView(Context context) {
    actionBar.setTitle(LocaleController.getString("AppName", R.string.AppName));
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == done_button) {
                views[currentViewNum].onNextPressed();
            } else if (id == -1) {
                finishFragment();
            }
        }
    });

    ActionBarMenu menu = actionBar.createMenu();
    doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
    doneButton.setVisibility(View.GONE);

    fragmentView = new ScrollView(context);
    ScrollView scrollView = (ScrollView) fragmentView;
    scrollView.setFillViewport(true);

    FrameLayout frameLayout = new FrameLayout(context);
    scrollView.addView(frameLayout, LayoutHelper.createScroll(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT));

    views[0] = new PhoneView(context);
    views[1] = new LoginActivitySmsView(context, 1);
    views[2] = new LoginActivitySmsView(context, 2);
    views[3] = new LoginActivitySmsView(context, 3);
    views[4] = new LoginActivitySmsView(context, 4);

    for (int a = 0; a < views.length; a++) {
        views[a].setVisibility(a == 0 ? View.VISIBLE : View.GONE);
        frameLayout.addView(views[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, a == 0 ? LayoutHelper.WRAP_CONTENT : LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, AndroidUtilities.isTablet() ? 26 : 18, 30, AndroidUtilities.isTablet() ? 26 : 18, 0));
    }

    actionBar.setTitle(views[0].getHeaderName());

    return fragmentView;
}
 
Example 8
Source File: HelpActivity.java    From Noyze with Apache License 2.0 4 votes vote down vote up
/**
 * Generates our layout in-code. Only called once, then
 * we'll be sure to recycle these {@link View}s.
 */
public final View makeLayout() {

	// Layout Parameters.
          DisplayMetrics dm = new DisplayMetrics();
          WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
          wm.getDefaultDisplay().getMetrics(dm);
          final int[] mWindowDims = new int[] { dm.widthPixels, dm.heightPixels };
	final int mWindowWidth = mWindowDims[0],
			  mMaxWidth = mContext.getResources().getDimensionPixelSize(R.dimen.max_menu_width);
	final int gutter = mContext.getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin);
	final FrameLayout.LayoutParams mParams = new FrameLayout.LayoutParams(
		((mWindowWidth > mMaxWidth) ? mMaxWidth : android.view.ViewGroup.LayoutParams.MATCH_PARENT),
		android.view.ViewGroup.LayoutParams.MATCH_PARENT);
	final RelativeLayout.LayoutParams mTextParams = new RelativeLayout.LayoutParams(
		android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
	mTextParams.addRule(RelativeLayout.CENTER_IN_PARENT);
	mParams.gravity = Gravity.CENTER;
	
	// Main text and image.
	final TextView text = new TextView(mContext);
          text.setTextColor(Color.DKGRAY);
	text.setId(R.id.help_text);
	text.setLayoutParams(mTextParams);
	text.setGravity(Gravity.CENTER_HORIZONTAL);
	text.setMovementMethod(LinkMovementMethod.getInstance());
	text.setLinksClickable(true);
	final int mTextSize = mContext.getResources()
		.getDimensionPixelSize(R.dimen.help_text_size);
	text.setTextSize(mTextSize);
	
	text.setCompoundDrawablePadding((gutter/2));
	text.setPadding(gutter, gutter, gutter, gutter);
	
	// Allow the View to Scroll vertically if necessary.
	final ScrollView scroll = new ScrollView(mContext);
	scroll.setLayoutParams(mParams);
	scroll.setFillViewport(true);
	scroll.setSmoothScrollingEnabled(true);
	scroll.setVerticalScrollBarEnabled(false);
	final RelativeLayout layout = new RelativeLayout(mContext);
	mParams.topMargin = mParams.bottomMargin = mContext.getResources().getDimensionPixelSize(R.dimen.activity_vertical_margin);
          mParams.leftMargin = mParams.rightMargin = mContext.getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin);
	layout.setLayoutParams(mParams);
	layout.addView(text);
	scroll.addView(layout);
	
	return scroll;
}
 
Example 9
Source File: HelpActivity.java    From Noyze with Apache License 2.0 4 votes vote down vote up
/**
 * Generates our layout in-code. Only called once, then
 * we'll be sure to recycle these {@link View}s.
 */
public final View makeLayout() {

	// Layout Parameters.
          DisplayMetrics dm = new DisplayMetrics();
          WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
          wm.getDefaultDisplay().getMetrics(dm);
          final int[] mWindowDims = new int[] { dm.widthPixels, dm.heightPixels };
	final int mWindowWidth = mWindowDims[0],
			  mMaxWidth = mContext.getResources().getDimensionPixelSize(R.dimen.max_menu_width);
	final int gutter = mContext.getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin);
	final FrameLayout.LayoutParams mParams = new FrameLayout.LayoutParams(
		((mWindowWidth > mMaxWidth) ? mMaxWidth : android.view.ViewGroup.LayoutParams.MATCH_PARENT),
		android.view.ViewGroup.LayoutParams.MATCH_PARENT);
	final RelativeLayout.LayoutParams mTextParams = new RelativeLayout.LayoutParams(
		android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
	mTextParams.addRule(RelativeLayout.CENTER_IN_PARENT);
	mParams.gravity = Gravity.CENTER;
	
	// Main text and image.
	final TextView text = new TextView(mContext);
          text.setTextColor(Color.DKGRAY);
	text.setId(R.id.help_text);
	text.setLayoutParams(mTextParams);
	text.setGravity(Gravity.CENTER_HORIZONTAL);
	text.setMovementMethod(LinkMovementMethod.getInstance());
	text.setLinksClickable(true);
	final int mTextSize = mContext.getResources()
		.getDimensionPixelSize(R.dimen.help_text_size);
	text.setTextSize(mTextSize);
	
	text.setCompoundDrawablePadding((gutter/2));
	text.setPadding(gutter, gutter, gutter, gutter);
	
	// Allow the View to Scroll vertically if necessary.
	final ScrollView scroll = new ScrollView(mContext);
	scroll.setLayoutParams(mParams);
	scroll.setFillViewport(true);
	scroll.setSmoothScrollingEnabled(true);
	scroll.setVerticalScrollBarEnabled(false);
	final RelativeLayout layout = new RelativeLayout(mContext);
	mParams.topMargin = mParams.bottomMargin = mContext.getResources().getDimensionPixelSize(R.dimen.activity_vertical_margin);
          mParams.leftMargin = mParams.rightMargin = mContext.getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin);
	layout.setLayoutParams(mParams);
	layout.addView(text);
	scroll.addView(layout);
	
	return scroll;
}
 
Example 10
Source File: ChangePhoneActivity.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
public View createView(Context context) {
    actionBar.setTitle(LocaleController.getString("AppName", R.string.AppName));
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == done_button) {
                views[currentViewNum].onNextPressed();
            } else if (id == -1) {
                finishFragment();
            }
        }
    });

    ActionBarMenu menu = actionBar.createMenu();
    doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));

    ScrollView scrollView = new ScrollView(context) {
        @Override
        public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) {
            if (currentViewNum == 1 || currentViewNum == 2 || currentViewNum == 4) {
                rectangle.bottom += AndroidUtilities.dp(40);
            }
            return super.requestChildRectangleOnScreen(child, rectangle, immediate);
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            scrollHeight = MeasureSpec.getSize(heightMeasureSpec) - AndroidUtilities.dp(30);
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    };
    scrollView.setFillViewport(true);
    fragmentView = scrollView;

    FrameLayout frameLayout = new FrameLayout(context);
    scrollView.addView(frameLayout, LayoutHelper.createScroll(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT));

    views[0] = new PhoneView(context);
    views[1] = new LoginActivitySmsView(context, 1);
    views[2] = new LoginActivitySmsView(context, 2);
    views[3] = new LoginActivitySmsView(context, 3);
    views[4] = new LoginActivitySmsView(context, 4);

    for (int a = 0; a < views.length; a++) {
        views[a].setVisibility(a == 0 ? View.VISIBLE : View.GONE);
        frameLayout.addView(views[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, a == 0 ? LayoutHelper.WRAP_CONTENT : LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, AndroidUtilities.isTablet() ? 26 : 18, 30, AndroidUtilities.isTablet() ? 26 : 18, 0));
    }

    actionBar.setTitle(views[0].getHeaderName());

    return fragmentView;
}
 
Example 11
Source File: CancelAccountDeletionActivity.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
public View createView(Context context) {
    actionBar.setTitle(LocaleController.getString("AppName", R.string.AppName));
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == done_button) {
                views[currentViewNum].onNextPressed();
            } else if (id == -1) {
                finishFragment();
            }
        }
    });

    ActionBarMenu menu = actionBar.createMenu();
    doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
    doneButton.setVisibility(View.GONE);

    ScrollView scrollView = new ScrollView(context) {
        @Override
        public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) {
            if (currentViewNum == 1 || currentViewNum == 2 || currentViewNum == 4) {
                rectangle.bottom += AndroidUtilities.dp(40);
            }
            return super.requestChildRectangleOnScreen(child, rectangle, immediate);
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            scrollHeight = MeasureSpec.getSize(heightMeasureSpec) - AndroidUtilities.dp(30);
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    };
    scrollView.setFillViewport(true);
    fragmentView = scrollView;

    FrameLayout frameLayout = new FrameLayout(context);
    scrollView.addView(frameLayout, LayoutHelper.createScroll(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT));

    views[0] = new PhoneView(context);
    views[1] = new LoginActivitySmsView(context, 1);
    views[2] = new LoginActivitySmsView(context, 2);
    views[3] = new LoginActivitySmsView(context, 3);
    views[4] = new LoginActivitySmsView(context, 4);

    for (int a = 0; a < views.length; a++) {
        views[a].setVisibility(a == 0 ? View.VISIBLE : View.GONE);
        frameLayout.addView(views[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, a == 0 ? LayoutHelper.WRAP_CONTENT : LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, AndroidUtilities.isTablet() ? 26 : 18, 30, AndroidUtilities.isTablet() ? 26 : 18, 0));
    }

    actionBar.setTitle(views[0].getHeaderName());

    return fragmentView;
}
 
Example 12
Source File: ChangePhoneActivity.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
public View createView(Context context) {
    actionBar.setTitle(LocaleController.getString("AppName", R.string.AppName));
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == done_button) {
                views[currentViewNum].onNextPressed();
            } else if (id == -1) {
                finishFragment();
            }
        }
    });

    ActionBarMenu menu = actionBar.createMenu();
    doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));

    ScrollView scrollView = new ScrollView(context) {
        @Override
        public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) {
            if (currentViewNum == 1 || currentViewNum == 2 || currentViewNum == 4) {
                rectangle.bottom += AndroidUtilities.dp(40);
            }
            return super.requestChildRectangleOnScreen(child, rectangle, immediate);
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            scrollHeight = MeasureSpec.getSize(heightMeasureSpec) - AndroidUtilities.dp(30);
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    };
    scrollView.setFillViewport(true);
    fragmentView = scrollView;

    FrameLayout frameLayout = new FrameLayout(context);
    scrollView.addView(frameLayout, LayoutHelper.createScroll(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT));

    views[0] = new PhoneView(context);
    views[1] = new LoginActivitySmsView(context, 1);
    views[2] = new LoginActivitySmsView(context, 2);
    views[3] = new LoginActivitySmsView(context, 3);
    views[4] = new LoginActivitySmsView(context, 4);

    for (int a = 0; a < views.length; a++) {
        views[a].setVisibility(a == 0 ? View.VISIBLE : View.GONE);
        frameLayout.addView(views[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, a == 0 ? LayoutHelper.WRAP_CONTENT : LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, AndroidUtilities.isTablet() ? 26 : 18, 30, AndroidUtilities.isTablet() ? 26 : 18, 0));
    }

    actionBar.setTitle(views[0].getHeaderName());

    return fragmentView;
}
 
Example 13
Source File: CancelAccountDeletionActivity.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
public View createView(Context context) {
    actionBar.setTitle(LocaleController.getString("AppName", R.string.AppName));
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == done_button) {
                views[currentViewNum].onNextPressed();
            } else if (id == -1) {
                finishFragment();
            }
        }
    });

    ActionBarMenu menu = actionBar.createMenu();
    doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
    doneButton.setVisibility(View.GONE);

    ScrollView scrollView = new ScrollView(context) {
        @Override
        public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) {
            if (currentViewNum == 1 || currentViewNum == 2 || currentViewNum == 4) {
                rectangle.bottom += AndroidUtilities.dp(40);
            }
            return super.requestChildRectangleOnScreen(child, rectangle, immediate);
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            scrollHeight = MeasureSpec.getSize(heightMeasureSpec) - AndroidUtilities.dp(30);
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    };
    scrollView.setFillViewport(true);
    fragmentView = scrollView;

    FrameLayout frameLayout = new FrameLayout(context);
    scrollView.addView(frameLayout, LayoutHelper.createScroll(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT));

    views[0] = new PhoneView(context);
    views[1] = new LoginActivitySmsView(context, 1);
    views[2] = new LoginActivitySmsView(context, 2);
    views[3] = new LoginActivitySmsView(context, 3);
    views[4] = new LoginActivitySmsView(context, 4);

    for (int a = 0; a < views.length; a++) {
        views[a].setVisibility(a == 0 ? View.VISIBLE : View.GONE);
        frameLayout.addView(views[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, a == 0 ? LayoutHelper.WRAP_CONTENT : LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, AndroidUtilities.isTablet() ? 26 : 18, 30, AndroidUtilities.isTablet() ? 26 : 18, 0));
    }

    actionBar.setTitle(views[0].getHeaderName());

    return fragmentView;
}