Example usage for android.view Gravity TOP

List of usage examples for android.view Gravity TOP

Introduction

In this page you can find the example usage for android.view Gravity TOP.

Prototype

int TOP

To view the source code for android.view Gravity TOP.

Click Source Link

Document

Push object to the top of its container, not changing its size.

Usage

From source file:com.ehelp.home.SuperAwesomeCardFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

    FrameLayout fl = new FrameLayout(getActivity());
    fl.setLayoutParams(params);//from  w w w  . j  a  va 2 s. c o  m
    //fl.setBackgroundColor(0x666666);
    final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
            getResources().getDisplayMetrics());

    TextView v = new TextView(getActivity());
    params.setMargins(margin, margin, margin, margin);
    v.setLayoutParams(params);
    v.setGravity(Gravity.TOP);
    System.out.println(position);
    if (position == 0) {
        fl.removeAllViews();
        mCurrentMode = MyLocationConfiguration.LocationMode.NORMAL;
        mMapView = new MapView(getActivity());
        mMapView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.FILL_PARENT));
        fl.addView(mMapView);
        mBaiduMap = mMapView.getMap();
        // ??
        mBaiduMap.setMyLocationEnabled(true);
        // ??
        mLocClient = new LocationClient(getActivity());
        mLocClient.registerLocationListener(myListener);
        LocationClientOption option = new LocationClientOption();
        option.setOpenGps(true);// gps
        option.setCoorType("bd09ll"); // ??
        option.setScanSpan(1000);
        mLocClient.setLocOption(option);
        mLocClient.start();
        int count = mMapView.getChildCount();
        for (int i = 0; i < count; i++) {
            View child = mMapView.getChildAt(i);
            if (child instanceof ZoomControls || child instanceof ImageView) {
                child.setVisibility(View.INVISIBLE);
            }
        }
        setLocation();
    } else if (position == 1) {
        fl.removeAllViews();
        ListView queList = new ListView(getActivity());
        queList.setLayoutParams(new LinearLayout.LayoutParams(-1, -1));
        HomeAdapter que = new HomeAdapter(getActivity(), user_id, 2, eventCache);
        queList.setAdapter(que);
        queList.setDividerHeight(20);
        fl.addView(queList);

        events = que.getEvent();

        //?
        queList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View arg1, int index, long arg3) {
                Intent intent = new Intent(getActivity(), recievesos_map.class);
                int eventid = events.get(index).getEventId();
                intent.putExtra(EXTRA_MESSAGE, eventid);
                startActivity(intent);
            }
        });
    } else if (position == 2) {
        fl.removeAllViews();
        ListView queList = new ListView(getActivity());
        queList.setLayoutParams(new LinearLayout.LayoutParams(-1, -1));
        //queList.setBackgroundColor(0x666666);
        //queList.setAlpha(125);
        queList.setDividerHeight(20);
        HomeAdapter que = new HomeAdapter(getActivity(), user_id, 1, eventCache);
        queList.setAdapter(que);
        fl.addView(queList);

        events = que.getEvent();

        //?
        queList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View arg1, int index, long arg3) {
                Intent intent = new Intent(getActivity(), recieve_help_ans_map.class);
                intent.putExtra(EXTRA_MESSAGE, events.get(index));
                startActivity(intent);
            }
        });
    } else if (position == 3) {
        fl.removeAllViews();
        ListView queList = new ListView(getActivity());
        queList.setLayoutParams(new LinearLayout.LayoutParams(-1, -1));
        HomeAdapter que = new HomeAdapter(getActivity(), user_id, 0, eventCache);
        queList.setAdapter(que);
        queList.setDividerHeight(20);
        fl.addView(queList);

        events = que.getEvent();

        //?
        queList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View arg1, int index, long arg3) {
                Intent intent = new Intent(getActivity(), QuestionDetail.class);
                intent.putExtra("qusetiondatail", events.get(index));
                startActivity(intent);
            }
        });
    }
    return fl;
}

From source file:com.ayoview.sample.textview.badge.ViewsFragment.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.counter: {
        counterBadge.incrementBadgeCount(1);
        break;//  w  ww.j ava 2s .com
    }

    case R.id.gravity: {
        gravityBadge.incrementBadgeCount(1);
        Log.d(getClass().getName(), String.valueOf(gravityBadge.getBadgeCount() % 9));
        if (gravityBadge.getBadgeCount() % 9 == 0) {
            gravityBadge.setBadgeGravity(Gravity.LEFT | Gravity.TOP);
        } else if (gravityBadge.getBadgeCount() % 9 == 1) {
            gravityBadge.setBadgeGravity(Gravity.RIGHT | Gravity.BOTTOM);
        } else if (gravityBadge.getBadgeCount() % 9 == 2) {
            gravityBadge.setBadgeGravity(Gravity.LEFT | Gravity.BOTTOM);
        } else if (gravityBadge.getBadgeCount() % 9 == 3) {
            gravityBadge.setBadgeGravity(Gravity.RIGHT | Gravity.TOP);
        } else if (gravityBadge.getBadgeCount() % 9 == 4) {
            gravityBadge.setBadgeGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
        } else if (gravityBadge.getBadgeCount() % 9 == 5) {
            gravityBadge.setBadgeGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
        } else if (gravityBadge.getBadgeCount() % 9 == 6) {
            gravityBadge.setBadgeGravity(Gravity.CENTER);
        } else if (gravityBadge.getBadgeCount() % 9 == 7) {
            gravityBadge.setBadgeGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP);
        } else if (gravityBadge.getBadgeCount() % 9 == 8) {
            gravityBadge.setBadgeGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
        }
        break;
    }
    case R.id.visibility: {
        visibilityBadgeView
                .setVisibility(visibilityBadgeView.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
        break;
    }

    default:
        break;
    }

}

From source file:com.concentricsky.android.khanacademy.data.remote.KAAPIAdapter.java

/**
 * Call me from the UI thread, please./*from  w  w w.j a  v a2  s .  c  om*/
 * 
 * Meant for use by broadcast receivers receiving ACTION_BADGE_EARNED.
 * */
public void toastBadge(Badge badge) {
    BadgeCategory category = badge.getCategory();
    //      Dao<BadgeCategory, Integer> dao = dataService.getHelper().getDao(BadgeCategory.class);
    //      dao.refresh(category);

    Toast toast = new Toast(dataService);
    View content = LayoutInflater.from(dataService).inflate(R.layout.badge, null, false);
    ImageView iconView = (ImageView) content.findViewById(R.id.badge_image);
    TextView pointsView = (TextView) content.findViewById(R.id.badge_points);
    TextView titleView = (TextView) content.findViewById(R.id.badge_title);
    TextView descView = (TextView) content.findViewById(R.id.badge_description);

    iconView.setImageResource(category.getIconResourceId());
    int points = badge.getPoints();
    if (points > 0) {
        pointsView.setText(points + "");
    } else {
        pointsView.setVisibility(View.GONE);
    }
    titleView.setText(badge.getDescription());
    descView.setText(badge.getSafe_extended_description());

    toast.setView(content);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setGravity(Gravity.TOP, 0, 200);
    toast.show();
}

From source file:android.support.design.internal.BottomNavigationItemView.java

@Override
public void setChecked(boolean checked) {
    ViewCompat.setPivotX(mLargeLabel, mLargeLabel.getWidth() / 2);
    ViewCompat.setPivotY(mLargeLabel, mLargeLabel.getBaseline());
    ViewCompat.setPivotX(mSmallLabel, mSmallLabel.getWidth() / 2);
    ViewCompat.setPivotY(mSmallLabel, mSmallLabel.getBaseline());
    if (mShiftingMode) {
        if (checked) {
            LayoutParams iconParams = (LayoutParams) mIcon.getLayoutParams();
            iconParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
            iconParams.topMargin = mDefaultMargin;
            mIcon.setLayoutParams(iconParams);
            mLargeLabel.setVisibility(VISIBLE);
            ViewCompat.setScaleX(mLargeLabel, 1f);
            ViewCompat.setScaleY(mLargeLabel, 1f);
        } else {/*from ww  w .jav a2 s  . c om*/
            LayoutParams iconParams = (LayoutParams) mIcon.getLayoutParams();
            iconParams.gravity = Gravity.CENTER;
            iconParams.topMargin = mDefaultMargin;
            mIcon.setLayoutParams(iconParams);
            mLargeLabel.setVisibility(INVISIBLE);
            ViewCompat.setScaleX(mLargeLabel, 0.5f);
            ViewCompat.setScaleY(mLargeLabel, 0.5f);
        }
        mSmallLabel.setVisibility(INVISIBLE);
    } else {
        if (checked) {
            LayoutParams iconParams = (LayoutParams) mIcon.getLayoutParams();
            iconParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
            iconParams.topMargin = mDefaultMargin + mShiftAmount;
            mIcon.setLayoutParams(iconParams);
            mLargeLabel.setVisibility(VISIBLE);
            mSmallLabel.setVisibility(INVISIBLE);

            ViewCompat.setScaleX(mLargeLabel, 1f);
            ViewCompat.setScaleY(mLargeLabel, 1f);
            ViewCompat.setScaleX(mSmallLabel, mScaleUpFactor);
            ViewCompat.setScaleY(mSmallLabel, mScaleUpFactor);
        } else {
            LayoutParams iconParams = (LayoutParams) mIcon.getLayoutParams();
            iconParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
            iconParams.topMargin = mDefaultMargin;
            mIcon.setLayoutParams(iconParams);
            mLargeLabel.setVisibility(INVISIBLE);
            mSmallLabel.setVisibility(VISIBLE);

            ViewCompat.setScaleX(mLargeLabel, mScaleDownFactor);
            ViewCompat.setScaleY(mLargeLabel, mScaleDownFactor);
            ViewCompat.setScaleX(mSmallLabel, 1f);
            ViewCompat.setScaleY(mSmallLabel, 1f);
        }
    }

    refreshDrawableState();
}

From source file:android.support.design.widget.HeaderScrollingViewBehavior.java

private static int resolveGravity(int gravity) {
    return gravity == Gravity.NO_GRAVITY ? GravityCompat.START | Gravity.TOP : gravity;
}

From source file:org.telegram.ui.myLocationSettingsActivity.java

@Override
public View createView(LayoutInflater inflater) {
    if (fragmentView == null) {
        actionBar.setBackButtonImage(R.drawable.ic_ab_back);
        actionBar.setAllowOverlayTitle(true);
        actionBar.setTitle("My Places");
        actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
            @Override//from   w  w w .  j  a v a2s  . com
            public void onItemClick(int id) {
                if (id == -1) {
                    finishFragment();
                }
            }
        });

        listAdapter = new ListAdapter(getParentActivity());

        fragmentView = new FrameLayout(getParentActivity());
        FrameLayout frameLayout = (FrameLayout) fragmentView;
        frameLayout.setBackgroundColor(0xfff0f0f0);

        ListView listView = new ListView(getParentActivity());
        listView.setDivider(null);
        listView.setDividerHeight(0);
        listView.setVerticalScrollBarEnabled(false);
        listView.setDrawSelectorOnTop(true);
        frameLayout.addView(listView);
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
        layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
        layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
        layoutParams.gravity = Gravity.TOP;
        listView.setLayoutParams(layoutParams);
        listView.setAdapter(listAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
                if (i == homeRow) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle("Home");
                    final ViewGroup.LayoutParams lparams = new ViewGroup.LayoutParams(50, 30);
                    final EditText input = new EditText(getParentActivity());
                    input.setHint("Insert city");
                    input.setLayoutParams(lparams);
                    builder.setView(input);
                    builder.setPositiveButton("confirm", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (input.getText().toString().trim().length() > 0) {
                                String city = input.getText().toString().trim();
                                try {
                                    Bundle locationHome = new getCoordinates().execute(city).get();
                                    String latHome = locationHome.getString("lat");
                                    String lonHome = locationHome.getString("lon");
                                    SharedPreferences sharedPreferences = ApplicationLoader.applicationContext
                                            .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
                                    SharedPreferences.Editor editor = sharedPreferences.edit();
                                    editor.putString("latHome", latHome);
                                    editor.putString("longHome", lonHome);
                                    editor.commit();
                                    Log.i(TAG, "fine! " + lonHome);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                } catch (ExecutionException e) {
                                    e.printStackTrace();
                                }
                            } else {
                                Toast.makeText(getParentActivity(), "That is empty :(", Toast.LENGTH_SHORT)
                                        .show();
                            }

                        }
                    });
                    builder.setNegativeButton("Why?", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(getParentActivity(), "To website", Toast.LENGTH_SHORT).show();
                        }
                    });
                    showAlertDialog(builder);
                } else if (i == workRow) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle("Work");
                    final EditText input = new EditText(getParentActivity());
                    input.setHint("Insert city");
                    builder.setView(input);
                    builder.setPositiveButton("confirm", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (input.getText().toString().trim().length() > 0) {
                                String city = input.getText().toString().trim();
                                try {
                                    Bundle locationWork = new getCoordinates().execute(city).get();
                                    String latWork = locationWork.getString("lat");
                                    String lonWork = locationWork.getString("lon");
                                    SharedPreferences sharedPreferences = ApplicationLoader.applicationContext
                                            .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
                                    SharedPreferences.Editor editor = sharedPreferences.edit();
                                    editor.putString("latWork", latWork);
                                    editor.putString("longWork", lonWork);
                                    editor.commit();
                                    Log.i(TAG, "fine! " + latWork);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                } catch (ExecutionException e) {
                                    e.printStackTrace();
                                }
                            } else {
                                Toast.makeText(getParentActivity(), "That is empty :(", Toast.LENGTH_SHORT)
                                        .show();
                            }

                        }
                    });
                    builder.setNegativeButton("Why?", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(getParentActivity(), "To website", Toast.LENGTH_SHORT).show();
                        }
                    });
                    showAlertDialog(builder);
                } else if (i == entertainmentRow) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle("Entertainment");
                    final EditText input = new EditText(getParentActivity());
                    input.setHint("Insert city");
                    builder.setView(input);
                    builder.setPositiveButton("confirm", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (input.getText().toString().trim().length() > 0) {
                                String city = input.getText().toString().trim();
                                try {
                                    Bundle locationEntertainment = new getCoordinates().execute(city).get();
                                    String latEntertainment = locationEntertainment.getString("lat");
                                    String lonEntertainment = locationEntertainment.getString("lon");
                                    SharedPreferences sharedPreferences = ApplicationLoader.applicationContext
                                            .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
                                    SharedPreferences.Editor editor = sharedPreferences.edit();
                                    editor.putString("latEntertainment", latEntertainment);
                                    editor.putString("longEntertainment", lonEntertainment);
                                    editor.commit();
                                    Log.i(TAG, "fine! " + latEntertainment);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                } catch (ExecutionException e) {
                                    e.printStackTrace();
                                }
                            } else {
                                Toast.makeText(getParentActivity(), "That is empty :(", Toast.LENGTH_SHORT)
                                        .show();
                            }

                        }
                    });
                    builder.setNegativeButton("Why?", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(getParentActivity(), "To website", Toast.LENGTH_SHORT).show();
                        }
                    });
                    showAlertDialog(builder);
                }
                //TODO find a solution for commuteRow as well!!
            }
        });
    } else {
        ViewGroup parent = (ViewGroup) fragmentView.getParent();
        if (parent != null) {
            parent.removeView(fragmentView);
        }
    }
    return fragmentView;
}

From source file:com.b44t.ui.Components.PasscodeView.java

public PasscodeView(final Context context) {
    super(context);

    setWillNotDraw(false);// w ww  . j a  v a2  s  .  c o m
    setVisibility(GONE);

    backgroundFrameLayout = new FrameLayout(context);
    addView(backgroundFrameLayout);
    LayoutParams layoutParams = (LayoutParams) backgroundFrameLayout.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    backgroundFrameLayout.setLayoutParams(layoutParams);

    passwordFrameLayout = new FrameLayout(context);
    addView(passwordFrameLayout);
    layoutParams = (LayoutParams) passwordFrameLayout.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
    passwordFrameLayout.setLayoutParams(layoutParams);

    ImageView imageView = new ImageView(context);
    imageView.setScaleType(ImageView.ScaleType.FIT_XY);
    imageView.setImageResource(R.drawable.ic_launcher /* EDIT BY MR -- was: passcode_logo */);
    passwordFrameLayout.addView(imageView);
    layoutParams = (LayoutParams) imageView.getLayoutParams();
    if (AndroidUtilities.density < 1) {
        layoutParams.width = AndroidUtilities.dp(30);
        layoutParams.height = AndroidUtilities.dp(30);
    } else {
        layoutParams.width = AndroidUtilities.dp(40);
        layoutParams.height = AndroidUtilities.dp(40);
    }
    layoutParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
    layoutParams.bottomMargin = AndroidUtilities.dp(100);
    imageView.setLayoutParams(layoutParams);

    passcodeTextView = new TextView(context);
    passcodeTextView.setTextColor(0xffffffff);
    passcodeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    passcodeTextView.setGravity(Gravity.CENTER_HORIZONTAL);
    passwordFrameLayout.addView(passcodeTextView);
    layoutParams = (LayoutParams) passcodeTextView.getLayoutParams();
    layoutParams.width = LayoutHelper.WRAP_CONTENT;
    layoutParams.height = LayoutHelper.WRAP_CONTENT;
    layoutParams.bottomMargin = AndroidUtilities.dp(62);
    layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
    passcodeTextView.setLayoutParams(layoutParams);

    passwordEditText = new EditText(context);
    passwordEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 36);
    passwordEditText.setTextColor(0xffffffff);
    passwordEditText.setMaxLines(1);
    passwordEditText.setLines(1);
    passwordEditText.setGravity(Gravity.CENTER_HORIZONTAL);
    passwordEditText.setSingleLine(true);
    passwordEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
    passwordEditText.setTypeface(Typeface.DEFAULT);
    passwordEditText.setBackgroundDrawable(null);
    AndroidUtilities.clearCursorDrawable(passwordEditText);
    passwordFrameLayout.addView(passwordEditText);
    layoutParams = (FrameLayout.LayoutParams) passwordEditText.getLayoutParams();
    layoutParams.height = LayoutHelper.WRAP_CONTENT;
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.leftMargin = AndroidUtilities.dp(70);
    layoutParams.rightMargin = AndroidUtilities.dp(70);
    layoutParams.bottomMargin = AndroidUtilities.dp(6);
    layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
    passwordEditText.setLayoutParams(layoutParams);
    passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_DONE) {
                processDone(false);
                return true;
            }
            return false;
        }
    });
    passwordEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            if (passwordEditText.length() == 4 && UserConfig.passcodeType == 0) {
                processDone(false);
            }
        }
    });
    passwordEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        public void onDestroyActionMode(ActionMode mode) {
        }

        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            return false;
        }
    });

    checkImage = new ImageView(context);
    checkImage.setImageResource(R.drawable.passcode_check);
    checkImage.setScaleType(ImageView.ScaleType.CENTER);
    checkImage.setBackgroundResource(R.drawable.bar_selector_lock);
    passwordFrameLayout.addView(checkImage);
    layoutParams = (LayoutParams) checkImage.getLayoutParams();
    layoutParams.width = AndroidUtilities.dp(60);
    layoutParams.height = AndroidUtilities.dp(60);
    layoutParams.bottomMargin = AndroidUtilities.dp(4);
    layoutParams.rightMargin = AndroidUtilities.dp(10);
    layoutParams.gravity = Gravity.BOTTOM | Gravity.RIGHT;
    checkImage.setLayoutParams(layoutParams);
    checkImage.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            processDone(false);
        }
    });

    FrameLayout lineFrameLayout = new FrameLayout(context);
    lineFrameLayout.setBackgroundColor(0x26ffffff);
    passwordFrameLayout.addView(lineFrameLayout);
    layoutParams = (LayoutParams) lineFrameLayout.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = AndroidUtilities.dp(1);
    layoutParams.gravity = Gravity.BOTTOM | Gravity.LEFT;
    layoutParams.leftMargin = AndroidUtilities.dp(20);
    layoutParams.rightMargin = AndroidUtilities.dp(20);
    lineFrameLayout.setLayoutParams(layoutParams);

    numbersFrameLayout = new FrameLayout(context);
    addView(numbersFrameLayout);
    layoutParams = (LayoutParams) numbersFrameLayout.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
    numbersFrameLayout.setLayoutParams(layoutParams);

    lettersTextViews = new ArrayList<>(10);
    numberTextViews = new ArrayList<>(10);
    numberFrameLayouts = new ArrayList<>(10);
    for (int a = 0; a < 10; a++) {
        TextView textView = new TextView(context);
        textView.setTextColor(0xffffffff);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 36);
        textView.setGravity(Gravity.CENTER);
        textView.setText(String.format(Locale.US, "%d", a));
        numbersFrameLayout.addView(textView);
        layoutParams = (LayoutParams) textView.getLayoutParams();
        layoutParams.width = AndroidUtilities.dp(50);
        layoutParams.height = AndroidUtilities.dp(50);
        layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
        textView.setLayoutParams(layoutParams);
        numberTextViews.add(textView);

        textView = new TextView(context);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
        textView.setTextColor(0x7fffffff);
        textView.setGravity(Gravity.CENTER);
        numbersFrameLayout.addView(textView);
        layoutParams = (LayoutParams) textView.getLayoutParams();
        layoutParams.width = AndroidUtilities.dp(50);
        layoutParams.height = AndroidUtilities.dp(20);
        layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
        textView.setLayoutParams(layoutParams);
        switch (a) {
        case 0:
            textView.setText("+");
            break;
        case 2:
            textView.setText("ABC");
            break;
        case 3:
            textView.setText("DEF");
            break;
        case 4:
            textView.setText("GHI");
            break;
        case 5:
            textView.setText("JKL");
            break;
        case 6:
            textView.setText("MNO");
            break;
        case 7:
            textView.setText("PQRS");
            break;
        case 8:
            textView.setText("TUV");
            break;
        case 9:
            textView.setText("WXYZ");
            break;
        default:
            break;
        }
        lettersTextViews.add(textView);
    }
    eraseView = new ImageView(context);
    eraseView.setScaleType(ImageView.ScaleType.CENTER);
    eraseView.setImageResource(R.drawable.passcode_delete);
    numbersFrameLayout.addView(eraseView);
    layoutParams = (LayoutParams) eraseView.getLayoutParams();
    layoutParams.width = AndroidUtilities.dp(50);
    layoutParams.height = AndroidUtilities.dp(50);
    layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
    eraseView.setLayoutParams(layoutParams);
    for (int a = 0; a < 11; a++) {
        FrameLayout frameLayout = new FrameLayout(context);
        frameLayout.setBackgroundResource(R.drawable.bar_selector_lock);
        frameLayout.setTag(a);
        if (a == 10) {
            frameLayout.setOnLongClickListener(new OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    passwordEditText.setText("");
                    return true;
                }
            });
        }
        frameLayout.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                int tag = (Integer) v.getTag();
                switch (tag) {
                case 0:
                    appendCharacter("0");
                    break;
                case 1:
                    appendCharacter("1");
                    break;
                case 2:
                    appendCharacter("2");
                    break;
                case 3:
                    appendCharacter("3");
                    break;
                case 4:
                    appendCharacter("4");
                    break;
                case 5:
                    appendCharacter("5");
                    break;
                case 6:
                    appendCharacter("6");
                    break;
                case 7:
                    appendCharacter("7");
                    break;
                case 8:
                    appendCharacter("8");
                    break;
                case 9:
                    appendCharacter("9");
                    break;
                case 10:
                    String text = passwordEditText.getText().toString();
                    if (text.length() > 0) {
                        passwordEditText.setText(text.substring(0, text.length() - 1));
                    }
                    break;
                }
                if (passwordEditText.getText().toString().length() == 4) {
                    processDone(false);
                }
            }
        });
        numberFrameLayouts.add(frameLayout);
    }
    for (int a = 10; a >= 0; a--) {
        FrameLayout frameLayout = numberFrameLayouts.get(a);
        numbersFrameLayout.addView(frameLayout);
        layoutParams = (LayoutParams) frameLayout.getLayoutParams();
        layoutParams.width = AndroidUtilities.dp(100);
        layoutParams.height = AndroidUtilities.dp(100);
        layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
        frameLayout.setLayoutParams(layoutParams);
    }
}

From source file:cn.jay.widget.BottomNavigationItemView.java

@Override
public void setChecked(boolean checked) {
    mItemData.setChecked(checked);//from www.j  a  v  a 2 s . c  o  m

    if (mUseStandardDesign) {
        ViewCompat.setPivotX(mLargeLabel, mLargeLabel.getWidth() / 2);
        ViewCompat.setPivotY(mLargeLabel, mLargeLabel.getBaseline());
        ViewCompat.setPivotX(mSmallLabel, mSmallLabel.getWidth() / 2);
        ViewCompat.setPivotY(mSmallLabel, mSmallLabel.getBaseline());
        if (mShiftingMode) {
            if (checked) {
                LayoutParams iconParams = (LayoutParams) mIcon.getLayoutParams();
                iconParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
                iconParams.topMargin = mDefaultMargin;
                mIcon.setLayoutParams(iconParams);
                mLargeLabel.setVisibility(VISIBLE);
                ViewCompat.setScaleX(mLargeLabel, 1f);
                ViewCompat.setScaleY(mLargeLabel, 1f);
            } else {
                LayoutParams iconParams = (LayoutParams) mIcon.getLayoutParams();
                iconParams.gravity = Gravity.CENTER;
                iconParams.topMargin = mDefaultMargin;
                mIcon.setLayoutParams(iconParams);
                mLargeLabel.setVisibility(INVISIBLE);
                ViewCompat.setScaleX(mLargeLabel, 0.5f);
                ViewCompat.setScaleY(mLargeLabel, 0.5f);
            }
            mSmallLabel.setVisibility(INVISIBLE);
        } else {
            if (checked) {
                LayoutParams iconParams = (LayoutParams) mIcon.getLayoutParams();
                iconParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
                iconParams.topMargin = mDefaultMargin + mShiftAmount;
                mIcon.setLayoutParams(iconParams);
                mLargeLabel.setVisibility(VISIBLE);
                mSmallLabel.setVisibility(INVISIBLE);

                ViewCompat.setScaleX(mLargeLabel, 1f);
                ViewCompat.setScaleY(mLargeLabel, 1f);
                ViewCompat.setScaleX(mSmallLabel, mScaleUpFactor);
                ViewCompat.setScaleY(mSmallLabel, mScaleUpFactor);
            } else {
                LayoutParams iconParams = (LayoutParams) mIcon.getLayoutParams();
                iconParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
                iconParams.topMargin = mDefaultMargin;
                mIcon.setLayoutParams(iconParams);
                mLargeLabel.setVisibility(INVISIBLE);
                mSmallLabel.setVisibility(VISIBLE);

                ViewCompat.setScaleX(mLargeLabel, mScaleDownFactor);
                ViewCompat.setScaleY(mLargeLabel, mScaleDownFactor);
                ViewCompat.setScaleX(mSmallLabel, 1f);
                ViewCompat.setScaleY(mSmallLabel, 1f);
            }
        }
    }

    refreshDrawableState();
}

From source file:com.acious.android.paginationseekbar.internal.Marker.java

public void resetSizes(String maxValue) {
    DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
    //Account for negative numbers... is there any proper way of getting the biggest string between our range????
    mNumber.setText("-" + maxValue);
    //Do a first forced measure call for the TextView (with the biggest text content),
    //to calculate the max width and use always the same.
    //this avoids the TextView from shrinking and growing when the text content changes
    int wSpec = MeasureSpec.makeMeasureSpec(displayMetrics.widthPixels, MeasureSpec.AT_MOST);
    int hSpec = MeasureSpec.makeMeasureSpec(displayMetrics.heightPixels, MeasureSpec.AT_MOST);
    mNumber.measure(wSpec, hSpec);/*from  w  w w  . ja v  a  2  s  .c om*/
    mWidth = Math.max(mNumber.getMeasuredWidth(), mNumber.getMeasuredHeight());
    removeView(mNumber);
    addView(mNumber, new FrameLayout.LayoutParams(mWidth, mWidth, Gravity.LEFT | Gravity.TOP));
}

From source file:com.jinzht.pro.view.RecyclerViewHeader.java

private void setupAlignment(RecyclerView recycler) {
    if (!mAlreadyAligned) {
        //setting alignment of header
        ViewGroup.LayoutParams currentParams = getLayoutParams();
        FrameLayout.LayoutParams newHeaderParams;
        int width = ViewGroup.LayoutParams.WRAP_CONTENT;
        int height = ViewGroup.LayoutParams.WRAP_CONTENT;
        int gravity = (mReversed ? Gravity.BOTTOM : Gravity.TOP) | Gravity.CENTER_HORIZONTAL;
        if (currentParams != null) {
            newHeaderParams = new FrameLayout.LayoutParams(getLayoutParams()); //to copy all the margins
            newHeaderParams.width = width;
            newHeaderParams.height = height;
            newHeaderParams.gravity = gravity;
        } else {// w  w w  . ja va2s  .c  o  m
            newHeaderParams = new FrameLayout.LayoutParams(width, height, gravity);
        }
        RecyclerViewHeader.this.setLayoutParams(newHeaderParams);

        //setting alignment of recycler
        FrameLayout newRootParent = new FrameLayout(recycler.getContext());
        newRootParent.setLayoutParams(recycler.getLayoutParams());
        ViewParent currentParent = recycler.getParent();
        if (currentParent instanceof ViewGroup) {
            int indexWithinParent = ((ViewGroup) currentParent).indexOfChild(recycler);

            ((ViewGroup) currentParent).removeViewAt(indexWithinParent);
            recycler.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT));
            newRootParent.addView(recycler);
            newRootParent.addView(RecyclerViewHeader.this);
            ((ViewGroup) currentParent).addView(newRootParent, indexWithinParent);
        }
    }
}