Example usage for android.view Gravity CENTER_HORIZONTAL

List of usage examples for android.view Gravity CENTER_HORIZONTAL

Introduction

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

Prototype

int CENTER_HORIZONTAL

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

Click Source Link

Document

Place object in the horizontal center of its container, not changing its size.

Usage

From source file:com.brookmanholmes.bma.wizard.ui.StepPagerStrip.java

private int hitTest(float x) {
    if (pageCount == 0) {
        return -1;
    }/*  w w  w.j a va  2s  . co m*/

    float totalWidth = pageCount * (tabWidth + indicatorSpacing) - indicatorSpacing;
    float totalLeft;
    boolean fillHorizontal = false;

    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
    case Gravity.CENTER_HORIZONTAL:
        totalLeft = (getWidth() - totalWidth) / 2;
        break;
    case Gravity.RIGHT:
        totalLeft = getWidth() - getPaddingRight() - totalWidth;
        break;
    case Gravity.FILL_HORIZONTAL:
        totalLeft = getPaddingLeft();
        fillHorizontal = true;
        break;
    default:
        totalLeft = getPaddingLeft();
    }

    float tabWidth = this.tabWidth;
    if (fillHorizontal) {
        tabWidth = (getWidth() - getPaddingRight() - getPaddingLeft() - (pageCount - 1) * indicatorSpacing)
                / pageCount;
    }

    float totalRight = totalLeft + (pageCount * (tabWidth + indicatorSpacing));
    if (x >= totalLeft && x <= totalRight && totalRight > totalLeft) {
        return (int) (((x - totalLeft) / (totalRight - totalLeft)) * pageCount);
    } else {
        return -1;
    }
}

From source file:com.tmall.wireless.tangram3.view.BannerView.java

public void setIndicatorGravity(int gravity) {
    switch (gravity) {
    case GRAVITY_LEFT:
        if (mIndicator != null) {
            mIndicator.setGravity(Gravity.LEFT);
        }//from w  w w .  j a  v a 2 s. co  m
        break;
    case GRAVITY_CENTER:
        if (mIndicator != null) {
            mIndicator.setGravity(Gravity.CENTER_HORIZONTAL);
        }
        break;
    case GRAVITY_RIGHT:
        if (mIndicator != null) {
            mIndicator.setGravity(Gravity.RIGHT);
        }
        break;
    default:
        break;
    }
}

From source file:id.co.datascrip.dtswarehousesystem.custom.StepPagerStrip.java

private int hitTest(float x) {
    if (mPageCount == 0) {
        return -1;
    }/*from  w  ww. j  a va2 s  .co m*/

    float totalWidth = mPageCount * (mTabWidth + mTabSpacing) - mTabSpacing;
    float totalLeft;
    boolean fillHorizontal = false;

    switch (mGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
    case Gravity.CENTER_HORIZONTAL:
        totalLeft = (getWidth() - totalWidth) / 2;
        break;
    case Gravity.RIGHT:
        totalLeft = getWidth() - getPaddingRight() - totalWidth;
        break;
    case Gravity.FILL_HORIZONTAL:
        totalLeft = getPaddingLeft();
        fillHorizontal = true;
        break;
    default:
        totalLeft = getPaddingLeft();
    }

    float tabWidth = mTabWidth;
    if (fillHorizontal) {
        tabWidth = (getWidth() - getPaddingRight() - getPaddingLeft() - (mPageCount - 1) * mTabSpacing)
                / mPageCount;
    }

    float totalRight = totalLeft + (mPageCount * (tabWidth + mTabSpacing));
    if (x >= totalLeft && x <= totalRight && totalRight > totalLeft) {
        return (int) (((x - totalLeft) / (totalRight - totalLeft)) * mPageCount);
    } else {
        return -1;
    }
}

From source file:ir.irani.telecam.ui.PasscodeActivity.java

@Override
public View createView(Context context) {
    if (type != 3) {
        actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    }/*from  w w w .  j av a2  s  . c o m*/
    actionBar.setAllowOverlayTitle(false);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                if (passcodeSetStep == 0) {
                    processNext();
                } else if (passcodeSetStep == 1) {
                    processDone();
                }
            } else if (id == pin_item) {
                currentPasswordType = 0;
                updateDropDownTextView();
            } else if (id == password_item) {
                currentPasswordType = 1;
                updateDropDownTextView();
            }
        }
    });

    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;

    if (type != 0) {
        ActionBarMenu menu = actionBar.createMenu();
        menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));

        titleTextView = new TextView(context);
        titleTextView.setTextColor(0xff757575);
        if (type == 1) {
            if (UserConfig.passcodeHash.length() != 0) {
                titleTextView
                        .setText(LocaleController.getString("EnterNewPasscode", R.string.EnterNewPasscode));
            } else {
                titleTextView.setText(
                        LocaleController.getString("EnterNewFirstPasscode", R.string.EnterNewFirstPasscode));
            }
        } else {
            titleTextView
                    .setText(LocaleController.getString("EnterCurrentPasscode", R.string.EnterCurrentPasscode));
        }
        titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        titleTextView.setGravity(Gravity.CENTER_HORIZONTAL);
        frameLayout.addView(titleTextView);
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) titleTextView.getLayoutParams();
        layoutParams.width = LayoutHelper.WRAP_CONTENT;
        layoutParams.height = LayoutHelper.WRAP_CONTENT;
        layoutParams.gravity = Gravity.CENTER_HORIZONTAL;
        layoutParams.topMargin = AndroidUtilities.dp(38);
        titleTextView.setLayoutParams(layoutParams);

        passwordEditText = new EditText(context);
        passwordEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
        passwordEditText.setTextColor(0xff000000);
        passwordEditText.setMaxLines(1);
        passwordEditText.setLines(1);
        passwordEditText.setGravity(Gravity.CENTER_HORIZONTAL);
        passwordEditText.setSingleLine(true);
        if (type == 1) {
            passcodeSetStep = 0;
            passwordEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT);
        } else {
            passcodeSetStep = 1;
            passwordEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
        }
        passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
        passwordEditText.setTypeface(Typeface.DEFAULT);
        AndroidUtilities.clearCursorDrawable(passwordEditText);
        frameLayout.addView(passwordEditText);
        layoutParams = (FrameLayout.LayoutParams) passwordEditText.getLayoutParams();
        layoutParams.topMargin = AndroidUtilities.dp(90);
        layoutParams.height = AndroidUtilities.dp(36);
        layoutParams.leftMargin = AndroidUtilities.dp(40);
        layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
        layoutParams.rightMargin = AndroidUtilities.dp(40);
        layoutParams.width = LayoutHelper.MATCH_PARENT;
        passwordEditText.setLayoutParams(layoutParams);
        passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
                if (passcodeSetStep == 0) {
                    processNext();
                    return true;
                } else if (passcodeSetStep == 1) {
                    processDone();
                    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) {
                    if (type == 2 && UserConfig.passcodeType == 0) {
                        processDone();
                    } else if (type == 1 && currentPasswordType == 0) {
                        if (passcodeSetStep == 0) {
                            processNext();
                        } else if (passcodeSetStep == 1) {
                            processDone();
                        }
                    }
                }
            }
        });

        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;
            }
        });

        if (type == 1) {
            dropDownContainer = new ActionBarMenuItem(context, menu, 0);
            dropDownContainer.setSubMenuOpenSide(1);
            dropDownContainer.addSubItem(pin_item,
                    LocaleController.getString("PasscodePIN", R.string.PasscodePIN), 0);
            dropDownContainer.addSubItem(password_item,
                    LocaleController.getString("PasscodePassword", R.string.PasscodePassword), 0);
            actionBar.addView(dropDownContainer);
            layoutParams = (FrameLayout.LayoutParams) dropDownContainer.getLayoutParams();
            layoutParams.height = LayoutHelper.MATCH_PARENT;
            layoutParams.width = LayoutHelper.WRAP_CONTENT;
            layoutParams.rightMargin = AndroidUtilities.dp(40);
            layoutParams.leftMargin = AndroidUtilities.isTablet() ? AndroidUtilities.dp(64)
                    : AndroidUtilities.dp(56);
            layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
            dropDownContainer.setLayoutParams(layoutParams);
            dropDownContainer.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    dropDownContainer.toggleSubMenu();
                }
            });

            dropDown = new TextView(context);
            dropDown.setGravity(Gravity.LEFT);
            dropDown.setSingleLine(true);
            dropDown.setLines(1);
            dropDown.setMaxLines(1);
            dropDown.setEllipsize(TextUtils.TruncateAt.END);
            dropDown.setTextColor(0xffffffff);
            dropDown.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
            dropDown.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_arrow_drop_down, 0);
            dropDown.setCompoundDrawablePadding(AndroidUtilities.dp(4));
            dropDown.setPadding(0, 0, AndroidUtilities.dp(10), 0);
            dropDownContainer.addView(dropDown);
            layoutParams = (FrameLayout.LayoutParams) dropDown.getLayoutParams();
            layoutParams.width = LayoutHelper.WRAP_CONTENT;
            layoutParams.height = LayoutHelper.WRAP_CONTENT;
            layoutParams.leftMargin = AndroidUtilities.dp(16);
            layoutParams.gravity = Gravity.CENTER_VERTICAL;
            layoutParams.bottomMargin = AndroidUtilities.dp(1);
            dropDown.setLayoutParams(layoutParams);
        } else {
            actionBar.setTitle(LocaleController.getString("Passcode", R.string.Passcode));
        }

        updateDropDownTextView();
    } else {
        actionBar.setTitle(LocaleController.getString("Passcode", R.string.Passcode));
        frameLayout.setBackgroundColor(0xfff0f0f0);
        listView = new ListView(context);
        listView.setDivider(null);
        listView.setDividerHeight(0);
        listView.setVerticalScrollBarEnabled(false);
        listView.setDrawSelectorOnTop(true);
        frameLayout.addView(listView);
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
        layoutParams.width = LayoutHelper.MATCH_PARENT;
        layoutParams.height = LayoutHelper.MATCH_PARENT;
        layoutParams.gravity = Gravity.TOP;
        listView.setLayoutParams(layoutParams);
        listView.setAdapter(listAdapter = new ListAdapter(context));
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
                if (i == changePasscodeRow) {
                    presentFragment(new PasscodeActivity(1));
                } else if (i == passcodeRow) {
                    TextCheckCell cell = (TextCheckCell) view;
                    if (UserConfig.passcodeHash.length() != 0) {
                        UserConfig.passcodeHash = "";
                        UserConfig.appLocked = false;
                        UserConfig.saveConfig(false);
                        int count = listView.getChildCount();
                        for (int a = 0; a < count; a++) {
                            View child = listView.getChildAt(a);
                            if (child instanceof TextSettingsCell) {
                                TextSettingsCell textCell = (TextSettingsCell) child;
                                textCell.setTextColor(0xffc6c6c6);
                                break;
                            }
                        }
                        cell.setChecked(UserConfig.passcodeHash.length() != 0);
                        NotificationCenter.getInstance()
                                .postNotificationName(NotificationCenter.didSetPasscode);
                    } else {
                        presentFragment(new PasscodeActivity(1));
                    }
                } else if (i == autoLockRow) {
                    if (getParentActivity() == null) {
                        return;
                    }
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle(LocaleController.getString("AutoLock", R.string.AutoLock));
                    final NumberPicker numberPicker = new NumberPicker(getParentActivity());
                    numberPicker.setMinValue(0);
                    numberPicker.setMaxValue(4);
                    if (UserConfig.autoLockIn == 0) {
                        numberPicker.setValue(0);
                    } else if (UserConfig.autoLockIn == 60) {
                        numberPicker.setValue(1);
                    } else if (UserConfig.autoLockIn == 60 * 5) {
                        numberPicker.setValue(2);
                    } else if (UserConfig.autoLockIn == 60 * 60) {
                        numberPicker.setValue(3);
                    } else if (UserConfig.autoLockIn == 60 * 60 * 5) {
                        numberPicker.setValue(4);
                    }
                    numberPicker.setFormatter(new NumberPicker.Formatter() {
                        @Override
                        public String format(int value) {
                            if (value == 0) {
                                return LocaleController.getString("AutoLockDisabled",
                                        R.string.AutoLockDisabled);
                            } else if (value == 1) {
                                return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime,
                                        LocaleController.formatPluralString("Minutes", 1));
                            } else if (value == 2) {
                                return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime,
                                        LocaleController.formatPluralString("Minutes", 5));
                            } else if (value == 3) {
                                return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime,
                                        LocaleController.formatPluralString("Hours", 1));
                            } else if (value == 4) {
                                return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime,
                                        LocaleController.formatPluralString("Hours", 5));
                            }
                            return "";
                        }
                    });
                    builder.setView(numberPicker);
                    builder.setNegativeButton(LocaleController.getString("Done", R.string.Done),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    which = numberPicker.getValue();
                                    if (which == 0) {
                                        UserConfig.autoLockIn = 0;
                                    } else if (which == 1) {
                                        UserConfig.autoLockIn = 60;
                                    } else if (which == 2) {
                                        UserConfig.autoLockIn = 60 * 5;
                                    } else if (which == 3) {
                                        UserConfig.autoLockIn = 60 * 60;
                                    } else if (which == 4) {
                                        UserConfig.autoLockIn = 60 * 60 * 5;
                                    }
                                    listView.invalidateViews();
                                    UserConfig.saveConfig(false);
                                }
                            });
                    showDialog(builder.create());
                } else if (i == fingerprintRow) {
                    UserConfig.useFingerprint = !UserConfig.useFingerprint;
                    UserConfig.saveConfig(false);
                    ((TextCheckCell) view).setChecked(UserConfig.useFingerprint);
                }
            }
        });
    }

    return fragmentView;
}

From source file:org.cafemember.ui.PasscodeActivity.java

@Override
public View createView(Context context) {
    if (type != 3) {
        actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    }/* w  w  w  .j  a va  2s. c om*/
    actionBar.setAllowOverlayTitle(false);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                if (passcodeSetStep == 0) {
                    processNext();
                } else if (passcodeSetStep == 1) {
                    processDone();
                }
            } else if (id == pin_item) {
                currentPasswordType = 0;
                updateDropDownTextView();
            } else if (id == password_item) {
                currentPasswordType = 1;
                updateDropDownTextView();
            }
        }
    });

    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;

    if (type != 0) {
        ActionBarMenu menu = actionBar.createMenu();
        menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));

        titleTextView = new TextView(context);
        titleTextView.setTextColor(0xff757575);
        if (type == 1) {
            if (UserConfig.passcodeHash.length() != 0) {
                titleTextView
                        .setText(LocaleController.getString("EnterNewPasscode", R.string.EnterNewPasscode));
            } else {
                titleTextView.setText(
                        LocaleController.getString("EnterNewFirstPasscode", R.string.EnterNewFirstPasscode));
            }
        } else {
            titleTextView
                    .setText(LocaleController.getString("EnterCurrentPasscode", R.string.EnterCurrentPasscode));
        }
        titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        titleTextView.setGravity(Gravity.CENTER_HORIZONTAL);
        frameLayout.addView(titleTextView);
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) titleTextView.getLayoutParams();
        layoutParams.width = LayoutHelper.WRAP_CONTENT;
        layoutParams.height = LayoutHelper.WRAP_CONTENT;
        layoutParams.gravity = Gravity.CENTER_HORIZONTAL;
        layoutParams.topMargin = AndroidUtilities.dp(38);
        titleTextView.setLayoutParams(layoutParams);

        passwordEditText = new EditText(context);
        passwordEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
        passwordEditText.setTextColor(0xff000000);
        passwordEditText.setMaxLines(1);
        passwordEditText.setLines(1);
        passwordEditText.setGravity(Gravity.CENTER_HORIZONTAL);
        passwordEditText.setSingleLine(true);
        if (type == 1) {
            passcodeSetStep = 0;
            passwordEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT);
        } else {
            passcodeSetStep = 1;
            passwordEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
        }
        passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
        passwordEditText.setTypeface(Typeface.DEFAULT);
        AndroidUtilities.clearCursorDrawable(passwordEditText);
        frameLayout.addView(passwordEditText);
        layoutParams = (FrameLayout.LayoutParams) passwordEditText.getLayoutParams();
        layoutParams.topMargin = AndroidUtilities.dp(90);
        layoutParams.height = AndroidUtilities.dp(36);
        layoutParams.leftMargin = AndroidUtilities.dp(40);
        layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
        layoutParams.rightMargin = AndroidUtilities.dp(40);
        layoutParams.width = LayoutHelper.MATCH_PARENT;
        passwordEditText.setLayoutParams(layoutParams);
        passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
                if (passcodeSetStep == 0) {
                    processNext();
                    return true;
                } else if (passcodeSetStep == 1) {
                    processDone();
                    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) {
                    if (type == 2 && UserConfig.passcodeType == 0) {
                        processDone();
                    } else if (type == 1 && currentPasswordType == 0) {
                        if (passcodeSetStep == 0) {
                            processNext();
                        } else if (passcodeSetStep == 1) {
                            processDone();
                        }
                    }
                }
            }
        });
        if (android.os.Build.VERSION.SDK_INT < 11) {
            passwordEditText.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
                public void onCreateContextMenu(ContextMenu menu, View v,
                        ContextMenu.ContextMenuInfo menuInfo) {
                    menu.clear();
                }
            });
        } else {
            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;
                }
            });
        }

        if (type == 1) {
            dropDownContainer = new ActionBarMenuItem(context, menu, 0);
            dropDownContainer.setSubMenuOpenSide(1);
            dropDownContainer.addSubItem(pin_item,
                    LocaleController.getString("PasscodePIN", R.string.PasscodePIN), 0);
            dropDownContainer.addSubItem(password_item,
                    LocaleController.getString("PasscodePassword", R.string.PasscodePassword), 0);
            actionBar.addView(dropDownContainer);
            layoutParams = (FrameLayout.LayoutParams) dropDownContainer.getLayoutParams();
            layoutParams.height = LayoutHelper.MATCH_PARENT;
            layoutParams.width = LayoutHelper.WRAP_CONTENT;
            layoutParams.rightMargin = AndroidUtilities.dp(40);
            layoutParams.leftMargin = AndroidUtilities.isTablet() ? AndroidUtilities.dp(64)
                    : AndroidUtilities.dp(56);
            layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
            dropDownContainer.setLayoutParams(layoutParams);
            dropDownContainer.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    dropDownContainer.toggleSubMenu();
                }
            });

            dropDown = new TextView(context);
            dropDown.setGravity(Gravity.LEFT);
            dropDown.setSingleLine(true);
            dropDown.setLines(1);
            dropDown.setMaxLines(1);
            dropDown.setEllipsize(TextUtils.TruncateAt.END);
            dropDown.setTextColor(0xffffffff);
            dropDown.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
            dropDown.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_arrow_drop_down, 0);
            dropDown.setCompoundDrawablePadding(AndroidUtilities.dp(4));
            dropDown.setPadding(0, 0, AndroidUtilities.dp(10), 0);
            dropDownContainer.addView(dropDown);
            layoutParams = (FrameLayout.LayoutParams) dropDown.getLayoutParams();
            layoutParams.width = LayoutHelper.WRAP_CONTENT;
            layoutParams.height = LayoutHelper.WRAP_CONTENT;
            layoutParams.leftMargin = AndroidUtilities.dp(16);
            layoutParams.gravity = Gravity.CENTER_VERTICAL;
            layoutParams.bottomMargin = AndroidUtilities.dp(1);
            dropDown.setLayoutParams(layoutParams);
        } else {
            actionBar.setTitle(LocaleController.getString("Passcode", R.string.Passcode));
        }

        updateDropDownTextView();
    } else {
        actionBar.setTitle(LocaleController.getString("Passcode", R.string.Passcode));
        frameLayout.setBackgroundColor(0xfff0f0f0);
        listView = new ListView(context);
        listView.setDivider(null);
        listView.setDividerHeight(0);
        listView.setVerticalScrollBarEnabled(false);
        listView.setDrawSelectorOnTop(true);
        frameLayout.addView(listView);
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
        layoutParams.width = LayoutHelper.MATCH_PARENT;
        layoutParams.height = LayoutHelper.MATCH_PARENT;
        layoutParams.gravity = Gravity.TOP;
        listView.setLayoutParams(layoutParams);
        listView.setAdapter(listAdapter = new ListAdapter(context));
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
                if (i == changePasscodeRow) {
                    presentFragment(new PasscodeActivity(1));
                } else if (i == passcodeRow) {
                    TextCheckCell cell = (TextCheckCell) view;
                    if (UserConfig.passcodeHash.length() != 0) {
                        UserConfig.passcodeHash = "";
                        UserConfig.appLocked = false;
                        UserConfig.saveConfig(false);
                        int count = listView.getChildCount();
                        for (int a = 0; a < count; a++) {
                            View child = listView.getChildAt(a);
                            if (child instanceof TextSettingsCell) {
                                TextSettingsCell textCell = (TextSettingsCell) child;
                                textCell.setTextColor(0xffc6c6c6);
                                break;
                            }
                        }
                        cell.setChecked(UserConfig.passcodeHash.length() != 0);
                        NotificationCenter.getInstance()
                                .postNotificationName(NotificationCenter.didSetPasscode);
                    } else {
                        presentFragment(new PasscodeActivity(1));
                    }
                } else if (i == autoLockRow) {
                    if (getParentActivity() == null) {
                        return;
                    }
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle(LocaleController.getString("AutoLock", R.string.AutoLock));
                    final NumberPicker numberPicker = new NumberPicker(getParentActivity());
                    numberPicker.setMinValue(0);
                    numberPicker.setMaxValue(4);
                    if (UserConfig.autoLockIn == 0) {
                        numberPicker.setValue(0);
                    } else if (UserConfig.autoLockIn == 60) {
                        numberPicker.setValue(1);
                    } else if (UserConfig.autoLockIn == 60 * 5) {
                        numberPicker.setValue(2);
                    } else if (UserConfig.autoLockIn == 60 * 60) {
                        numberPicker.setValue(3);
                    } else if (UserConfig.autoLockIn == 60 * 60 * 5) {
                        numberPicker.setValue(4);
                    }
                    numberPicker.setFormatter(new NumberPicker.Formatter() {
                        @Override
                        public String format(int value) {
                            if (value == 0) {
                                return LocaleController.getString("AutoLockDisabled",
                                        R.string.AutoLockDisabled);
                            } else if (value == 1) {
                                return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime,
                                        LocaleController.formatPluralString("Minutes", 1));
                            } else if (value == 2) {
                                return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime,
                                        LocaleController.formatPluralString("Minutes", 5));
                            } else if (value == 3) {
                                return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime,
                                        LocaleController.formatPluralString("Hours", 1));
                            } else if (value == 4) {
                                return LocaleController.formatString("AutoLockInTime", R.string.AutoLockInTime,
                                        LocaleController.formatPluralString("Hours", 5));
                            }
                            return "";
                        }
                    });
                    builder.setView(numberPicker);
                    builder.setNegativeButton(LocaleController.getString("Done", R.string.Done),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    which = numberPicker.getValue();
                                    if (which == 0) {
                                        UserConfig.autoLockIn = 0;
                                    } else if (which == 1) {
                                        UserConfig.autoLockIn = 60;
                                    } else if (which == 2) {
                                        UserConfig.autoLockIn = 60 * 5;
                                    } else if (which == 3) {
                                        UserConfig.autoLockIn = 60 * 60;
                                    } else if (which == 4) {
                                        UserConfig.autoLockIn = 60 * 60 * 5;
                                    }
                                    listView.invalidateViews();
                                    UserConfig.saveConfig(false);
                                }
                            });
                    showDialog(builder.create());
                } else if (i == fingerprintRow) {
                    UserConfig.useFingerprint = !UserConfig.useFingerprint;
                    UserConfig.saveConfig(false);
                    ((TextCheckCell) view).setChecked(UserConfig.useFingerprint);
                }
            }
        });
    }

    return fragmentView;
}

From source file:widgets.Graphical_Binary_New.java

public Graphical_Binary_New(tracerengine Trac, Activity context, String address, String name, int id,
        int dev_id, String state_key, String url, final String usage, String parameters, String model_id,
        int update, int widgetSize, int session_type, int place_id, String place_type, SharedPreferences params)
        throws JSONException {
    super(context, Trac, id, name, "", usage, widgetSize, session_type, place_id, place_type, mytag, container);
    this.Tracer = Trac;
    this.context = context;
    this.address = address;
    this.url = url;
    this.state_key = state_key;
    this.dev_id = dev_id;
    this.id = id;
    this.usage = usage;
    this.update = update;
    this.name = name;
    this.wname = name;
    this.myself = this;
    this.session_type = session_type;
    this.stateS = getResources().getText(R.string.State).toString();
    this.place_id = place_id;
    this.place_type = place_type;
    this.params = params;

    login = params.getString("http_auth_username", null);
    password = params.getString("http_auth_password", null);

    mytag = "Graphical_Binary_New(" + dev_id + ")";
    //get parameters      

    try {//from   w  w  w . j a  va2 s  . com
        JSONObject jparam = new JSONObject(parameters.replaceAll("&quot;", "\""));
        value0 = jparam.getString("value0");
        value1 = jparam.getString("value1");
    } catch (Exception e) {
        value0 = "0";
        value1 = "1";
    }

    if (usage.equals("light")) {
        this.Value_0 = getResources().getText(R.string.light_stat_0).toString();
        this.Value_1 = getResources().getText(R.string.light_stat_1).toString();
    } else if (usage.equals("shutter")) {
        this.Value_0 = getResources().getText(R.string.shutter_stat_0).toString();
        this.Value_1 = getResources().getText(R.string.shutter_stat_1).toString();
    } else {
        this.Value_0 = value0;
        this.Value_1 = value1;
    }

    String[] model = model_id.split("\\.");
    type = model[0];
    Tracer.d(mytag,
            "model_id = <" + model_id + "> type = <" + type + "> value0 = " + value0 + "  value1 = " + value1);

    //state
    state = new TextView(context);
    state.setTextColor(Color.BLACK);
    state.setText("State :" + this.Value_0);

    final float scale = getContext().getResources().getDisplayMetrics().density;
    float dps = 40;
    int pixels = (int) (dps * scale + 0.5f);
    //first seekbar on/off
    ON = new Button(context);
    ON.setOnClickListener(this);
    ON.setHeight(pixels);
    //ON.setWidth(60);
    ON.setTag("ON");
    ON.setText(this.Value_1);
    ON.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
    //ON.setBackgroundResource(R.drawable.boolean_on);
    //ON.setPadding(10, 0, 10, 0);

    OFF = new Button(context);
    OFF.setOnClickListener(this);
    OFF.setTag("OFF");
    OFF.setHeight(pixels);
    //OFF.setWidth(60);
    OFF.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
    //OFF.setBackgroundResource(R.drawable.boolean_off);
    OFF.setText(this.Value_0);
    //OFF.setPadding(0,10,0,10);

    super.LL_featurePan.addView(ON);
    super.LL_featurePan.addView(OFF);
    super.LL_infoPan.addView(state);

    handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (activate) {
                Tracer.d(mytag, "Handler receives a request to die ");
                if (realtime) {
                    Tracer.get_engine().unsubscribe(session);
                    session = null;
                    realtime = false;
                }
                //That seems to be a zombie
                //removeView(background);
                myself.setVisibility(GONE);
                if (container != null) {
                    container.removeView(myself);
                    container.recomputeViewAttributes(myself);
                }
                try {
                    finalize();
                } catch (Throwable t) {
                } //kill the handler thread itself
            } else {
                try {
                    Bundle b = msg.getData();
                    if ((b != null) && (b.getString("message") != null)) {
                        if (b.getString("message").equals(value0)) {
                            //state.setText(stateS+value0);
                            state.setText(stateS + Value_0);
                            IV_img.setBackgroundResource(Graphics_Manager.Icones_Agent(usage, 0));
                        } else if (b.getString("message").equals(value1)) {
                            //state.setText(stateS+value1);
                            state.setText(stateS + Value_1);
                            IV_img.setBackgroundResource(Graphics_Manager.Icones_Agent(usage, 2));
                        }
                        state.setAnimation(animation);
                    } else {
                        if (msg.what == 2) {
                            Toast.makeText(getContext(), "Command Failed", Toast.LENGTH_SHORT).show();
                        } else if (msg.what == 9999) {
                            //state_engine send us a signal to notify value changed
                            if (session == null)
                                return;
                            String new_val = session.getValue();
                            Tracer.d(mytag, "Handler receives a new value <" + new_val + ">");
                            if (new_val.equals(value0)) {
                                state.setText(stateS + Value_0);
                                IV_img.setBackgroundResource(Graphics_Manager.Icones_Agent(usage, 0));
                            } else if (new_val.equals(value1)) {
                                state.setText(stateS + Value_1);
                                IV_img.setBackgroundResource(Graphics_Manager.Icones_Agent(usage, 2));
                            } else {
                                state.setText(stateS + new_val);
                            }
                        } else if (msg.what == 9998) {
                            // state_engine send us a signal to notify it'll die !
                            Tracer.d(mytag, "state engine disappeared ===> Harakiri !");
                            session = null;
                            realtime = false;
                            //removeView(background);
                            myself.setVisibility(GONE);
                            if (container != null) {
                                container.removeView(myself);
                                container.recomputeViewAttributes(myself);
                            }
                            try {
                                finalize();
                            } catch (Throwable t) {
                            } //kill the handler thread itself
                        }
                    }

                } catch (Exception e) {
                    Tracer.e(mytag, "Handler error for device " + wname);
                    e.printStackTrace();
                }
            }
        }
    };
    //================================================================================
    /*
     * New mechanism to be notified by widgetupdate engine when our value is changed
     * 
     */
    WidgetUpdate cache_engine = WidgetUpdate.getInstance();
    if (cache_engine != null) {
        session = new Entity_client(dev_id, state_key, mytag, handler, session_type);
        if (Tracer.get_engine().subscribe(session)) {
            realtime = true; //we're connected to engine
            //each time our value change, the engine will call handler
            handler.sendEmptyMessage(9999); //Force to consider current value in session
        }

    }
    //================================================================================
    //updateTimer();   //Don't use anymore cyclic refresh....   

}

From source file:kr.wdream.ui.PasscodeActivity.java

@Override
public View createView(Context context) {
    Log.d(LOG_TAG, "createView");
    if (type != 3) {
        actionBar.setBackButtonImage(kr.wdream.storyshop.R.drawable.ic_ab_back);
    }//from w  w w.  j  av a2  s  . c  o m
    actionBar.setAllowOverlayTitle(false);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                if (passcodeSetStep == 0) {
                    processNext();
                } else if (passcodeSetStep == 1) {
                    processDone();
                }
            } else if (id == pin_item) {
                currentPasswordType = 0;
                updateDropDownTextView();
            } else if (id == password_item) {
                currentPasswordType = 1;
                updateDropDownTextView();
            }
        }
    });

    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;

    if (type != 0) {
        ActionBarMenu menu = actionBar.createMenu();
        menu.addItemWithWidth(done_button, kr.wdream.storyshop.R.drawable.ic_done, AndroidUtilities.dp(56));

        titleTextView = new TextView(context);
        titleTextView.setTextColor(0xff757575);
        if (type == 1) {
            if (UserConfig.passcodeHash.length() != 0) {
                titleTextView.setText(LocaleController.getString("EnterNewPasscode",
                        kr.wdream.storyshop.R.string.EnterNewPasscode));
            } else {
                titleTextView.setText(LocaleController.getString("EnterNewFirstPasscode",
                        kr.wdream.storyshop.R.string.EnterNewFirstPasscode));
            }
        } else {
            titleTextView.setText(LocaleController.getString("EnterCurrentPasscode",
                    kr.wdream.storyshop.R.string.EnterCurrentPasscode));
        }
        titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        titleTextView.setGravity(Gravity.CENTER_HORIZONTAL);
        frameLayout.addView(titleTextView);
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) titleTextView.getLayoutParams();
        layoutParams.width = LayoutHelper.WRAP_CONTENT;
        layoutParams.height = LayoutHelper.WRAP_CONTENT;
        layoutParams.gravity = Gravity.CENTER_HORIZONTAL;
        layoutParams.topMargin = AndroidUtilities.dp(38);
        titleTextView.setLayoutParams(layoutParams);

        passwordEditText = new EditText(context);
        passwordEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
        passwordEditText.setTextColor(0xff000000);
        passwordEditText.setMaxLines(1);
        passwordEditText.setLines(1);
        passwordEditText.setGravity(Gravity.CENTER_HORIZONTAL);
        passwordEditText.setSingleLine(true);
        if (type == 1) {
            passcodeSetStep = 0;
            passwordEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT);
        } else {
            passcodeSetStep = 1;
            passwordEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
        }
        passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
        passwordEditText.setTypeface(Typeface.DEFAULT);
        AndroidUtilities.clearCursorDrawable(passwordEditText);
        frameLayout.addView(passwordEditText);
        layoutParams = (FrameLayout.LayoutParams) passwordEditText.getLayoutParams();
        layoutParams.topMargin = AndroidUtilities.dp(90);
        layoutParams.height = AndroidUtilities.dp(36);
        layoutParams.leftMargin = AndroidUtilities.dp(40);
        layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
        layoutParams.rightMargin = AndroidUtilities.dp(40);
        layoutParams.width = LayoutHelper.MATCH_PARENT;
        passwordEditText.setLayoutParams(layoutParams);
        passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
                if (passcodeSetStep == 0) {
                    processNext();
                    return true;
                } else if (passcodeSetStep == 1) {
                    processDone();
                    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) {
                    if (type == 2 && UserConfig.passcodeType == 0) {
                        processDone();
                    } else if (type == 1 && currentPasswordType == 0) {
                        if (passcodeSetStep == 0) {
                            processNext();
                        } else if (passcodeSetStep == 1) {
                            processDone();
                        }
                    }
                }
            }
        });

        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;
            }
        });

        if (type == 1) {
            dropDownContainer = new ActionBarMenuItem(context, menu, 0);
            dropDownContainer.setSubMenuOpenSide(1);
            dropDownContainer.addSubItem(pin_item,
                    LocaleController.getString("PasscodePIN", kr.wdream.storyshop.R.string.PasscodePIN), 0);
            dropDownContainer.addSubItem(password_item, LocaleController.getString("PasscodePassword",
                    kr.wdream.storyshop.R.string.PasscodePassword), 0);
            actionBar.addView(dropDownContainer);
            layoutParams = (FrameLayout.LayoutParams) dropDownContainer.getLayoutParams();
            layoutParams.height = LayoutHelper.MATCH_PARENT;
            layoutParams.width = LayoutHelper.WRAP_CONTENT;
            layoutParams.rightMargin = AndroidUtilities.dp(40);
            layoutParams.leftMargin = AndroidUtilities.isTablet() ? AndroidUtilities.dp(64)
                    : AndroidUtilities.dp(56);
            layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
            dropDownContainer.setLayoutParams(layoutParams);
            dropDownContainer.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    dropDownContainer.toggleSubMenu();
                }
            });

            dropDown = new TextView(context);
            dropDown.setGravity(Gravity.LEFT);
            dropDown.setSingleLine(true);
            dropDown.setLines(1);
            dropDown.setMaxLines(1);
            dropDown.setEllipsize(TextUtils.TruncateAt.END);
            dropDown.setTextColor(0xffffffff);
            dropDown.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
            dropDown.setCompoundDrawablesWithIntrinsicBounds(0, 0,
                    kr.wdream.storyshop.R.drawable.ic_arrow_drop_down, 0);
            dropDown.setCompoundDrawablePadding(AndroidUtilities.dp(4));
            dropDown.setPadding(0, 0, AndroidUtilities.dp(10), 0);
            dropDownContainer.addView(dropDown);
            layoutParams = (FrameLayout.LayoutParams) dropDown.getLayoutParams();
            layoutParams.width = LayoutHelper.WRAP_CONTENT;
            layoutParams.height = LayoutHelper.WRAP_CONTENT;
            layoutParams.leftMargin = AndroidUtilities.dp(16);
            layoutParams.gravity = Gravity.CENTER_VERTICAL;
            layoutParams.bottomMargin = AndroidUtilities.dp(1);
            dropDown.setLayoutParams(layoutParams);
        } else {
            actionBar.setTitle(LocaleController.getString("Passcode", kr.wdream.storyshop.R.string.Passcode));
        }

        updateDropDownTextView();
    } else {
        actionBar.setTitle(LocaleController.getString("Passcode", kr.wdream.storyshop.R.string.Passcode));
        frameLayout.setBackgroundColor(0xfff0f0f0);
        listView = new ListView(context);
        listView.setDivider(null);
        listView.setDividerHeight(0);
        listView.setVerticalScrollBarEnabled(false);
        listView.setDrawSelectorOnTop(true);
        frameLayout.addView(listView);
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
        layoutParams.width = LayoutHelper.MATCH_PARENT;
        layoutParams.height = LayoutHelper.MATCH_PARENT;
        layoutParams.gravity = Gravity.TOP;
        listView.setLayoutParams(layoutParams);
        listView.setAdapter(listAdapter = new ListAdapter(context));
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
                if (i == changePasscodeRow) {
                    presentFragment(new PasscodeActivity(1));
                } else if (i == passcodeRow) {
                    TextCheckCell cell = (TextCheckCell) view;
                    if (UserConfig.passcodeHash.length() != 0) {
                        UserConfig.passcodeHash = "";
                        UserConfig.appLocked = false;
                        UserConfig.saveConfig(false);
                        int count = listView.getChildCount();
                        for (int a = 0; a < count; a++) {
                            View child = listView.getChildAt(a);
                            if (child instanceof TextSettingsCell) {
                                TextSettingsCell textCell = (TextSettingsCell) child;
                                textCell.setTextColor(0xffc6c6c6);
                                break;
                            }
                        }
                        cell.setChecked(UserConfig.passcodeHash.length() != 0);
                        NotificationCenter.getInstance()
                                .postNotificationName(NotificationCenter.didSetPasscode);
                    } else {
                        presentFragment(new PasscodeActivity(1));
                    }
                } else if (i == autoLockRow) {
                    if (getParentActivity() == null) {
                        return;
                    }
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle(
                            LocaleController.getString("AutoLock", kr.wdream.storyshop.R.string.AutoLock));
                    final NumberPicker numberPicker = new NumberPicker(getParentActivity());
                    numberPicker.setMinValue(0);
                    numberPicker.setMaxValue(4);
                    if (UserConfig.autoLockIn == 0) {
                        numberPicker.setValue(0);
                    } else if (UserConfig.autoLockIn == 60) {
                        numberPicker.setValue(1);
                    } else if (UserConfig.autoLockIn == 60 * 5) {
                        numberPicker.setValue(2);
                    } else if (UserConfig.autoLockIn == 60 * 60) {
                        numberPicker.setValue(3);
                    } else if (UserConfig.autoLockIn == 60 * 60 * 5) {
                        numberPicker.setValue(4);
                    }
                    numberPicker.setFormatter(new NumberPicker.Formatter() {
                        @Override
                        public String format(int value) {
                            if (value == 0) {
                                return LocaleController.getString("AutoLockDisabled",
                                        kr.wdream.storyshop.R.string.AutoLockDisabled);
                            } else if (value == 1) {
                                return LocaleController.formatString("AutoLockInTime",
                                        kr.wdream.storyshop.R.string.AutoLockInTime,
                                        LocaleController.formatPluralString("Minutes", 1));
                            } else if (value == 2) {
                                return LocaleController.formatString("AutoLockInTime",
                                        kr.wdream.storyshop.R.string.AutoLockInTime,
                                        LocaleController.formatPluralString("Minutes", 5));
                            } else if (value == 3) {
                                return LocaleController.formatString("AutoLockInTime",
                                        kr.wdream.storyshop.R.string.AutoLockInTime,
                                        LocaleController.formatPluralString("Hours", 1));
                            } else if (value == 4) {
                                return LocaleController.formatString("AutoLockInTime",
                                        kr.wdream.storyshop.R.string.AutoLockInTime,
                                        LocaleController.formatPluralString("Hours", 5));
                            }
                            return "";
                        }
                    });
                    builder.setView(numberPicker);
                    builder.setNegativeButton(
                            LocaleController.getString("Done", kr.wdream.storyshop.R.string.Done),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    which = numberPicker.getValue();
                                    if (which == 0) {
                                        UserConfig.autoLockIn = 0;
                                    } else if (which == 1) {
                                        UserConfig.autoLockIn = 60;
                                    } else if (which == 2) {
                                        UserConfig.autoLockIn = 60 * 5;
                                    } else if (which == 3) {
                                        UserConfig.autoLockIn = 60 * 60;
                                    } else if (which == 4) {
                                        UserConfig.autoLockIn = 60 * 60 * 5;
                                    }
                                    listView.invalidateViews();
                                    UserConfig.saveConfig(false);
                                }
                            });
                    showDialog(builder.create());
                } else if (i == fingerprintRow) {
                    UserConfig.useFingerprint = !UserConfig.useFingerprint;
                    UserConfig.saveConfig(false);
                    ((TextCheckCell) view).setChecked(UserConfig.useFingerprint);
                }
            }
        });
    }

    return fragmentView;
}

From source file:com.chalmers.schmaps.CheckBusActivity.java

/**
 * Makes the rows for the chalmerstable//w  ww.  j  av  a  2s .  c om
 */
public void makeChalmersRows() {
    for (int i = 0; i < NROFROWS; i++) {
        TableRow tempTableRow = new TableRow(this);
        tempTableRow.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

        // Makes every other row light gray or white
        if (i % 2 == 0) {
            tempTableRow.setBackgroundColor(getResources().getColor(R.color.transp_grey));
        } else {
            tempTableRow.setBackgroundColor(getResources().getColor(R.color.transp_white));
        }

        //Makes every textview for each column and add it before starting with a new one
        for (int j = 0; j < NR_OF_COLUMNS; j++) {
            TextView textview = new TextView(this);
            textview.setTextColor(Color.BLACK);
            textview.setTextSize(TypedValue.COMPLEX_UNIT_SP, TEXT_SIZE);
            //Check which content should be written in the textview
            if (j == COLUMN_NR_1) {
                textview.setText(chalmersLineArray.get(i));
            } else if (j == COLUMN_NR_2) {
                textview.setText(chalmersDestArray.get(i));
            } else if (j == COLUMN_NR_3) {
                textview.setText(chalmersTimeArray.get(i));
            } else if (j == COLUMN_NR_4) {
                textview.setText(chalmersTrackArray.get(i));
            }
            textview.setGravity(Gravity.CENTER_HORIZONTAL);
            tempTableRow.addView(textview);
        }
        chalmersTable.addView(tempTableRow,
                new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    }
}

From source file:com.viewpagerindicator.TabPageForMenuIndicator.java

private void addTab(int index, CharSequence text, int iconResId) {
    final TabView tabView = new TabView(getContext());
    tabView.mIndex = index;/* w w w  . ja v  a2 s .  co m*/
    tabView.setFocusable(true);
    tabView.setOnClickListener(mTabClickListener);
    tabView.setText(text);
    tabView.setGravity(Gravity.CENTER_HORIZONTAL);
    tabView.setTextSize(getResources().getDimension(R.dimen.menu_title));
    tabView.setTextColor(getResources().getColor(android.R.color.white));

    if (iconResId != 0) {
        drawables[location] = iconResId;
        tabView.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], drawables[2], drawables[3]);
    }

    mTabLayout.addView(tabView, new LinearLayout.LayoutParams(0, MATCH_PARENT, 1));
}

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

@Override
public View createView(Context context) {
    actionBar.setBackgroundColor(Theme.ACTION_BAR_CHANNEL_INTRO_COLOR);
    actionBar.setBackButtonImage(R.drawable.pl_back);
    actionBar.setItemsBackgroundColor(Theme.ACTION_BAR_CHANNEL_INTRO_SELECTOR_COLOR);
    actionBar.setCastShadows(false);/*from   w w  w  .j  a va 2 s  .  co m*/
    if (!AndroidUtilities.isTablet()) {
        actionBar.showActionModeTop();
    }
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });

    fragmentView = new ViewGroup(context) {

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int width = MeasureSpec.getSize(widthMeasureSpec);
            int height = MeasureSpec.getSize(heightMeasureSpec);

            if (width > height) {
                imageView.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.45f), MeasureSpec.EXACTLY),
                        MeasureSpec.makeMeasureSpec((int) (height * 0.78f), MeasureSpec.EXACTLY));
                whatIsChannelText.measure(
                        MeasureSpec.makeMeasureSpec((int) (width * 0.6f), MeasureSpec.EXACTLY),
                        MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
                descriptionText.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.5f), MeasureSpec.EXACTLY),
                        MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
                createChannelText.measure(
                        MeasureSpec.makeMeasureSpec((int) (width * 0.6f), MeasureSpec.EXACTLY),
                        MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(24), MeasureSpec.EXACTLY));
            } else {
                imageView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
                        MeasureSpec.makeMeasureSpec((int) (height * 0.44f), MeasureSpec.EXACTLY));
                whatIsChannelText.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
                        MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
                descriptionText.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.9f), MeasureSpec.EXACTLY),
                        MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
                createChannelText.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
                        MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(24), MeasureSpec.EXACTLY));
            }

            setMeasuredDimension(width, height);
        }

        @Override
        protected void onLayout(boolean changed, int l, int t, int r, int b) {
            int width = r - l;
            int height = b - t;

            if (r > b) {
                int y = (int) (height * 0.05f);
                imageView.layout(0, y, imageView.getMeasuredWidth(), y + imageView.getMeasuredHeight());
                int x = (int) (width * 0.4f);
                y = (int) (height * 0.14f);
                whatIsChannelText.layout(x, y, x + whatIsChannelText.getMeasuredWidth(),
                        y + whatIsChannelText.getMeasuredHeight());
                y = (int) (height * 0.61f);
                createChannelText.layout(x, y, x + createChannelText.getMeasuredWidth(),
                        y + createChannelText.getMeasuredHeight());
                x = (int) (width * 0.45f);
                y = (int) (height * 0.31f);
                descriptionText.layout(x, y, x + descriptionText.getMeasuredWidth(),
                        y + descriptionText.getMeasuredHeight());
            } else {
                int y = (int) (height * 0.05f);
                imageView.layout(0, y, imageView.getMeasuredWidth(), y + imageView.getMeasuredHeight());
                y = (int) (height * 0.59f);
                whatIsChannelText.layout(0, y, whatIsChannelText.getMeasuredWidth(),
                        y + whatIsChannelText.getMeasuredHeight());
                y = (int) (height * 0.68f);
                int x = (int) (width * 0.05f);
                descriptionText.layout(x, y, x + descriptionText.getMeasuredWidth(),
                        y + descriptionText.getMeasuredHeight());
                y = (int) (height * 0.86f);
                createChannelText.layout(0, y, createChannelText.getMeasuredWidth(),
                        y + createChannelText.getMeasuredHeight());
            }
        }
    };
    fragmentView.setBackgroundColor(ContextCompat.getColor(context, R.color.background));
    ViewGroup viewGroup = (ViewGroup) fragmentView;
    viewGroup.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });

    imageView = new ImageView(context);
    imageView.setImageResource(R.drawable.channelintro);
    imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
    viewGroup.addView(imageView);

    whatIsChannelText = new TextView(context);
    whatIsChannelText.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
    whatIsChannelText.setGravity(Gravity.CENTER_HORIZONTAL);
    whatIsChannelText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 24);
    whatIsChannelText.setText(LocaleController.getString("ChannelAlertTitle", R.string.ChannelAlertTitle));
    viewGroup.addView(whatIsChannelText);

    descriptionText = new TextView(context);
    descriptionText.setTextColor(ContextCompat.getColor(context, R.color.secondary_text));
    descriptionText.setGravity(Gravity.CENTER_HORIZONTAL);
    descriptionText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    descriptionText.setText(LocaleController.getString("ChannelAlertText", R.string.ChannelAlertText));
    viewGroup.addView(descriptionText);

    createChannelText = new TextView(context);
    createChannelText.setTextColor(0xff4c8eca);
    createChannelText.setGravity(Gravity.CENTER);
    createChannelText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    createChannelText.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    createChannelText.setText(LocaleController.getString("ChannelAlertCreate", R.string.ChannelAlertCreate));
    viewGroup.addView(createChannelText);
    createChannelText.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Bundle args = new Bundle();
            args.putInt("step", 0);
            presentFragment(new ChannelCreateActivity(args), true);
        }
    });

    return fragmentView;
}