Example usage for android.widget TextView setLayoutParams

List of usage examples for android.widget TextView setLayoutParams

Introduction

In this page you can find the example usage for android.widget TextView setLayoutParams.

Prototype

public void setLayoutParams(ViewGroup.LayoutParams params) 

Source Link

Document

Set the layout parameters associated with this view.

Usage

From source file:com.jarklee.materialdatetimepicker.time.TimePickerDialog.java

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

    View view = inflater.inflate(R.layout.mdtp_time_picker_dialog, container, false);
    KeyboardListener keyboardListener = new KeyboardListener();
    view.findViewById(R.id.time_picker_dialog).setOnKeyListener(keyboardListener);

    // If an accent color has not been set manually, get it from the context
    if (mAccentColor == -1) {
        mAccentColor = Utils.getAccentColorFromThemeIfAvailable(getActivity());
    }//from w w  w .j  a v  a2s .c om

    // if theme mode has not been set by java code, check if it is specified in Style.xml
    if (!mThemeDarkChanged) {
        mThemeDark = Utils.isDarkTheme(getActivity(), mThemeDark);
    }

    Resources res = getResources();
    Context context = getActivity();
    mHourPickerDescription = res.getString(R.string.mdtp_hour_picker_description);
    mSelectHours = res.getString(R.string.mdtp_select_hours);
    mMinutePickerDescription = res.getString(R.string.mdtp_minute_picker_description);
    mSelectMinutes = res.getString(R.string.mdtp_select_minutes);
    mSecondPickerDescription = res.getString(R.string.mdtp_second_picker_description);
    mSelectSeconds = res.getString(R.string.mdtp_select_seconds);
    mSelectedColor = ContextCompat.getColor(context, R.color.mdtp_white);
    mUnselectedColor = ContextCompat.getColor(context, R.color.mdtp_accent_color_focused);

    mHourView = (TextView) view.findViewById(R.id.hours);
    mHourView.setOnKeyListener(keyboardListener);
    mHourSpaceView = (TextView) view.findViewById(R.id.hour_space);
    mMinuteSpaceView = (TextView) view.findViewById(R.id.minutes_space);
    mMinuteView = (TextView) view.findViewById(R.id.minutes);
    mMinuteView.setOnKeyListener(keyboardListener);
    mSecondSpaceView = (TextView) view.findViewById(R.id.seconds_space);
    mSecondView = (TextView) view.findViewById(R.id.seconds);
    mSecondView.setOnKeyListener(keyboardListener);
    mAmPmTextView = (TextView) view.findViewById(R.id.ampm_label);
    mAmPmTextView.setOnKeyListener(keyboardListener);
    String[] amPmTexts = new DateFormatSymbols(getLocale()).getAmPmStrings();
    mAmText = amPmTexts[0];
    mPmText = amPmTexts[1];

    mHapticFeedbackController = new HapticFeedbackController(getActivity());

    if (mTimePicker != null) {
        mInitialTime = new Timepoint(mTimePicker.getHours(), mTimePicker.getMinutes(),
                mTimePicker.getSeconds());
    }

    mInitialTime = roundToNearest(mInitialTime);

    mTimePicker = (RadialPickerLayout) view.findViewById(R.id.time_picker);
    mTimePicker.setOnValueSelectedListener(this);
    mTimePicker.setOnKeyListener(keyboardListener);
    mTimePicker.initialize(getActivity(), this, mInitialTime, mIs24HourMode);

    int currentItemShowing = HOUR_INDEX;
    if (savedInstanceState != null && savedInstanceState.containsKey(KEY_CURRENT_ITEM_SHOWING)) {
        currentItemShowing = savedInstanceState.getInt(KEY_CURRENT_ITEM_SHOWING);
    }
    setCurrentItemShowing(currentItemShowing, false, true, true);
    mTimePicker.invalidate();

    mHourView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setCurrentItemShowing(HOUR_INDEX, true, false, true);
            tryVibrate();
        }
    });
    mMinuteView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setCurrentItemShowing(MINUTE_INDEX, true, false, true);
            tryVibrate();
        }
    });
    mSecondView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            setCurrentItemShowing(SECOND_INDEX, true, false, true);
            tryVibrate();
        }
    });

    mOkButton = (Button) view.findViewById(R.id.ok);
    mOkButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mInKbMode && isTypedTimeFullyLegal()) {
                finishKbMode(false);
            } else {
                tryVibrate();
            }
            notifyOnDateListener();
            dismiss();
        }
    });
    mOkButton.setOnKeyListener(keyboardListener);
    mOkButton.setTypeface(TypefaceHelper.get(context, "Roboto-Medium"));
    if (mOkString != null)
        mOkButton.setText(mOkString);
    else
        mOkButton.setText(Utils.getStringFromLocale(getContext(), mOkResid, getLocale()));

    mCancelButton = (Button) view.findViewById(R.id.cancel);
    mCancelButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            tryVibrate();
            if (getDialog() != null)
                getDialog().cancel();
        }
    });
    mCancelButton.setTypeface(TypefaceHelper.get(context, "Roboto-Medium"));
    if (mCancelString != null)
        mCancelButton.setText(mCancelString);
    else
        mCancelButton.setText(Utils.getStringFromLocale(getContext(), mCancelResid, getLocale()));
    mCancelButton.setVisibility(isCancelable() ? View.VISIBLE : View.GONE);

    // Enable or disable the AM/PM view.
    mAmPmHitspace = view.findViewById(R.id.ampm_hitspace);
    if (mIs24HourMode) {
        mAmPmTextView.setVisibility(View.GONE);
    } else {
        mAmPmTextView.setVisibility(View.VISIBLE);
        updateAmPmDisplay(mInitialTime.isAM() ? AM : PM);
        mAmPmHitspace.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // Don't do anything if either AM or PM are disabled
                if (isAmDisabled() || isPmDisabled())
                    return;

                tryVibrate();
                int amOrPm = mTimePicker.getIsCurrentlyAmOrPm();
                if (amOrPm == AM) {
                    amOrPm = PM;
                } else if (amOrPm == PM) {
                    amOrPm = AM;
                }
                mTimePicker.setAmOrPm(amOrPm);
            }
        });
    }

    // Disable seconds picker
    if (!mEnableSeconds) {
        mSecondView.setVisibility(View.GONE);
        view.findViewById(R.id.separator_seconds).setVisibility(View.GONE);
    }

    // Disable minutes picker
    if (!mEnableMinutes) {
        mMinuteSpaceView.setVisibility(View.GONE);
        view.findViewById(R.id.separator).setVisibility(View.GONE);
    }

    // Center stuff depending on what's visible
    if (mIs24HourMode && !mEnableSeconds && mEnableMinutes) {
        // center first separator
        RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        paramsSeparator.addRule(RelativeLayout.CENTER_IN_PARENT);
        TextView separatorView = (TextView) view.findViewById(R.id.separator);
        separatorView.setLayoutParams(paramsSeparator);
    } else if (!mEnableMinutes && !mEnableSeconds) {
        // center the hour
        RelativeLayout.LayoutParams paramsHour = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        paramsHour.addRule(RelativeLayout.CENTER_IN_PARENT);
        mHourSpaceView.setLayoutParams(paramsHour);

        if (!mIs24HourMode) {
            RelativeLayout.LayoutParams paramsAmPm = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            paramsAmPm.addRule(RelativeLayout.RIGHT_OF, R.id.hour_space);
            paramsAmPm.addRule(RelativeLayout.ALIGN_BASELINE, R.id.hour_space);
            mAmPmTextView.setLayoutParams(paramsAmPm);
        }
    } else if (mEnableSeconds) {
        // link separator to minutes
        final View separator = view.findViewById(R.id.separator);
        RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        paramsSeparator.addRule(RelativeLayout.LEFT_OF, R.id.minutes_space);
        paramsSeparator.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
        separator.setLayoutParams(paramsSeparator);

        if (!mIs24HourMode) {
            // center minutes
            RelativeLayout.LayoutParams paramsMinutes = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            paramsMinutes.addRule(RelativeLayout.CENTER_IN_PARENT);
            mMinuteSpaceView.setLayoutParams(paramsMinutes);
        } else {
            // move minutes to right of center
            RelativeLayout.LayoutParams paramsMinutes = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            paramsMinutes.addRule(RelativeLayout.RIGHT_OF, R.id.center_view);
            mMinuteSpaceView.setLayoutParams(paramsMinutes);
        }
    }

    mAllowAutoAdvance = true;
    setHour(mInitialTime.getHour(), true);
    setMinute(mInitialTime.getMinute());
    setSecond(mInitialTime.getSecond());

    // Set up for keyboard mode.
    mDoublePlaceholderText = res.getString(R.string.mdtp_time_placeholder);
    mDeletedKeyFormat = res.getString(R.string.mdtp_deleted_key);
    mPlaceholderText = mDoublePlaceholderText.charAt(0);
    mAmKeyCode = mPmKeyCode = -1;
    generateLegalTimesTree();
    if (mInKbMode) {
        mTypedTimes = savedInstanceState.getIntegerArrayList(KEY_TYPED_TIMES);
        tryStartingKbMode(-1);
        mHourView.invalidate();
    } else if (mTypedTimes == null) {
        mTypedTimes = new ArrayList<>();
    }

    // Set the title (if any)
    TextView timePickerHeader = (TextView) view.findViewById(R.id.time_picker_header);
    if (!mTitle.isEmpty()) {
        timePickerHeader.setVisibility(TextView.VISIBLE);
        timePickerHeader.setText(mTitle.toUpperCase(getLocale()));
    }

    // Set the theme at the end so that the initialize()s above don't counteract the theme.
    mOkButton.setTextColor(mAccentColor);
    mCancelButton.setTextColor(mAccentColor);
    timePickerHeader.setBackgroundColor(Utils.darkenColor(mAccentColor));
    view.findViewById(R.id.time_display_background).setBackgroundColor(mAccentColor);
    view.findViewById(R.id.time_display).setBackgroundColor(mAccentColor);

    if (getDialog() == null) {
        view.findViewById(R.id.done_background).setVisibility(View.GONE);
    }

    int circleBackground = ContextCompat.getColor(context, R.color.mdtp_circle_background);
    int backgroundColor = ContextCompat.getColor(context, R.color.mdtp_background_color);
    int darkBackgroundColor = ContextCompat.getColor(context, R.color.mdtp_light_gray);
    int lightGray = ContextCompat.getColor(context, R.color.mdtp_light_gray);

    mTimePicker.setBackgroundColor(mThemeDark ? lightGray : circleBackground);
    view.findViewById(R.id.time_picker_dialog)
            .setBackgroundColor(mThemeDark ? darkBackgroundColor : backgroundColor);
    return view;
}

From source file:com.cairoconfessions.MainActivity.java

public void addLocation(View view) {
    TextView newView = new TextView(this);
    AutoCompleteTextView addLoc = ((AutoCompleteTextView) findViewById(R.id.addLocation));
    String newLoc = addLoc.getText().toString();
    ViewGroup locList = ((ViewGroup) findViewById(R.id.locations));
    boolean notFound = true;
    for (int i = 0; i < locList.getChildCount(); i++) {
        if (newLoc.equals(((TextView) locList.getChildAt(i)).getText().toString()))
            notFound = false;//from   ww w .  j a  va 2s .c  o m
        break;
    }
    if (Arrays.asList(COUNTRIES).contains(newLoc) && notFound) {
        newView.setText(newLoc);
        newView.setClickable(true);
        newView.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                addItem(view);
            }
        });
        float scale = getResources().getDisplayMetrics().density;
        newView.setGravity(17);
        newView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);

        newView.setBackgroundResource(R.drawable.city2);

        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                (int) (150 * scale));
        lp.setMargins((int) (0 * scale), (int) (0 * scale), (int) (0 * scale), (int) (2 * scale));
        newView.setLayoutParams(lp);
        locList.addView(newView, 0);
        addLoc.setText("");
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(addLoc.getWindowToken(), 0);
        addLoc.setCursorVisible(false);

    } else {
        Toast.makeText(this, "Invalid location", Toast.LENGTH_LONG).show();
    }
}

From source file:com.saulcintero.moveon.fragments.Statistics.java

private void paintData(int sql_option, int activity) {
    boolean isMetric = FunctionUtils.checkIfUnitsAreMetric(mContext);

    sum_distance = 0;//from ww w .j  a  v a 2  s.  com
    sum_kcal = 0;
    sum_time = 0;
    sum_up_accum_altitude = 0;
    sum_down_accum_altitude = 0;
    sum_avg_speed = 0;
    sum_steps = 0;
    sum_avg_hr = 0;
    practices_counter = 0;
    hr_practices_counter = 0;

    int[] colors = { Color.rgb(111, 183, 217), Color.rgb(54, 165, 54), Color.rgb(246, 103, 88),
            Color.rgb(234, 206, 74), Color.rgb(246, 164, 83), Color.LTGRAY, Color.rgb(35, 142, 36),
            Color.rgb(0, 129, 125), Color.rgb(0, 0, 220), Color.rgb(255, 255, 0), Color.rgb(255, 215, 0),
            Color.rgb(184, 134, 11), Color.rgb(245, 245, 220), Color.rgb(139, 137, 137), Color.rgb(96, 57, 138),
            Color.rgb(176, 0, 103), Color.rgb(77, 19, 106), Color.rgb(218, 0, 0), Color.rgb(252, 115, 0),
            Color.rgb(243, 42, 0), Color.rgb(255, 202, 44), Color.rgb(176, 214, 7), Color.rgb(255, 235, 44),
            Color.rgb(255, 255, 255), Color.rgb(186, 29, 29), Color.rgb(146, 436, 20), Color.rgb(245, 175, 209),
            Color.rgb(29, 91, 139), Color.rgb(128, 128, 0), Color.rgb(128, 0, 128), Color.rgb(0, 128, 128),
            Color.rgb(246, 233, 207), Color.rgb(231, 56, 142), Color.rgb(173, 141, 193),
            Color.rgb(191, 199, 32), Color.rgb(0, 128, 0), Color.rgb(4, 136, 125), Color.rgb(140, 0, 255),
            Color.rgb(135, 0, 118), Color.rgb(2, 132, 132), Color.rgb(0, 127, 204), Color.rgb(128, 250, 255),
            Color.rgb(192, 192, 192), Color.rgb(207, 94, 97), Color.rgb(137, 189, 199),
            Color.rgb(138, 168, 161), Color.rgb(171, 166, 191), Color.rgb(199, 153, 125) };

    DBManager = null;
    cursor = null;

    distance_distribution = null;
    kcal_distribution = null;
    time_distribution = null;

    DBManager = new DataManager(mContext);
    DBManager.Open();

    cursor = DBManager.CustomQuery(getString(R.string.checking_routes), "SELECT * FROM routes");

    cursor.moveToFirst();
    if (cursor.getCount() > 0) {
        between_dates_query_part = "";

        DatesTypes whichDate = DatesTypes.values()[sql_option];
        switch (whichDate) {
        case ALL_DATES:
            removeCustomDataValues();

            if (activity > 0) {
                cursor = DBManager.CustomQuery(
                        getString(R.string.selecting_all_routes) + " " + getString(R.string.filter_by_activity)
                                + " " + getString(R.string.and) + " " + getString(R.string.group_by_activities),
                        "SELECT category_id, COUNT(*) AS count_practices, SUM(distance) AS sum_distance, "
                                + "SUM(kcal) AS sum_kcal, SUM(time) AS sum_time, SUM(avg_speed) AS sum_avg_speed, "
                                + "SUM(up_accum_altitude) AS sum_up_accum_altitude, "
                                + "SUM(down_accum_altitude) AS sum_down_accum_altitude, "
                                + "SUM(steps) AS sum_steps " + "FROM routes " + "WHERE category_id = '"
                                + activity + "' " + "GROUP BY category_id");
            } else {
                cursor = DBManager.CustomQuery(
                        getString(R.string.selecting_all_routes) + " "
                                + getString(R.string.group_by_activities),
                        "SELECT category_id, COUNT(*) AS count_practices, SUM(distance) AS sum_distance, "
                                + "SUM(kcal) AS sum_kcal, SUM(time) AS sum_time, SUM(avg_speed) AS sum_avg_speed, "
                                + "SUM(up_accum_altitude) AS sum_up_accum_altitude, "
                                + "SUM(down_accum_altitude) AS sum_down_accum_altitude, "
                                + "SUM(steps) AS sum_steps " + "FROM routes GROUP BY category_id");
            }

            break;
        case THIS_YEAR:
            removeCustomDataValues();

            if (activity > 0) {
                cursor = DBManager.CustomQuery(
                        getString(R.string.selecting_this_year_routes) + " "
                                + getString(R.string.filter_by_activity) + " " + getString(R.string.and) + " "
                                + getString(R.string.group_by_activities),
                        "SELECT category_id, COUNT(*) AS count_practices, SUM(distance) AS sum_distance, "
                                + "SUM(kcal) AS sum_kcal, SUM(time) AS sum_time, SUM(avg_speed) AS sum_avg_speed, "
                                + "SUM(up_accum_altitude) AS sum_up_accum_altitude, "
                                + "SUM(down_accum_altitude) AS sum_down_accum_altitude, "
                                + "SUM(steps) AS sum_steps " + "FROM routes " + "WHERE substr(date,7) = '"
                                + Calendar.getInstance().get(Calendar.YEAR) + "' " + "AND category_id = '"
                                + activity + "' " + "GROUP BY category_id");
            } else {
                cursor = DBManager.CustomQuery(
                        getString(R.string.selecting_this_year_routes) + " "
                                + getString(R.string.group_by_activities),
                        "SELECT category_id, COUNT(*) AS count_practices, SUM(distance) AS sum_distance, "
                                + "SUM(kcal) AS sum_kcal, SUM(time) AS sum_time, SUM(avg_speed) AS sum_avg_speed, "
                                + "SUM(up_accum_altitude) AS sum_up_accum_altitude, "
                                + "SUM(down_accum_altitude) AS sum_down_accum_altitude, "
                                + "SUM(steps) AS sum_steps " + "FROM routes " + "WHERE substr(date,7) = '"
                                + Calendar.getInstance().get(Calendar.YEAR) + "' " + "GROUP BY category_id");
            }

            between_dates_query_part = "substr(date,7) = '" + Calendar.getInstance().get(Calendar.YEAR) + "' ";

            break;
        case THIS_MONTH:
            removeCustomDataValues();

            int month = Calendar.getInstance().get(Calendar.MONTH) + 1;
            String sMonth = String.valueOf(month);
            if (month < 10)
                sMonth = "0" + sMonth;

            if (activity > 0) {
                cursor = DBManager.CustomQuery(
                        getString(R.string.selecting_this_month_routes) + " "
                                + getString(R.string.filter_by_activity) + " " + getString(R.string.and) + " "
                                + getString(R.string.group_by_activities),
                        "SELECT category_id, COUNT(*) AS count_practices, SUM(distance) AS sum_distance, "
                                + "SUM(kcal) AS sum_kcal, SUM(time) AS sum_time, SUM(avg_speed) AS sum_avg_speed, "
                                + "SUM(up_accum_altitude) AS sum_up_accum_altitude, "
                                + "SUM(down_accum_altitude) AS sum_down_accum_altitude, "
                                + "SUM(steps) AS sum_steps " + "FROM routes " + "WHERE substr(date,4,2) = '"
                                + sMonth + "' " + "AND substr(date,7) = '"
                                + Calendar.getInstance().get(Calendar.YEAR) + "' " + "AND category_id = '"
                                + activity + "' " + "GROUP BY category_id");
            } else {
                cursor = DBManager.CustomQuery(
                        getString(R.string.selecting_this_month_routes) + " "
                                + getString(R.string.group_by_activities),
                        "SELECT category_id, COUNT(*) AS count_practices, SUM(distance) AS sum_distance, "
                                + "SUM(kcal) AS sum_kcal, SUM(time) AS sum_time, SUM(avg_speed) AS sum_avg_speed, "
                                + "SUM(up_accum_altitude) AS sum_up_accum_altitude, "
                                + "SUM(down_accum_altitude) AS sum_down_accum_altitude, "
                                + "SUM(steps) AS sum_steps " + "FROM routes " + "WHERE substr(date,4,2) = '"
                                + sMonth + "' " + "AND substr(date,7) = '"
                                + Calendar.getInstance().get(Calendar.YEAR) + "' " + "GROUP BY category_id");
            }

            between_dates_query_part = "substr(date,4,2) = '" + sMonth + "' AND substr(date,7) = '"
                    + Calendar.getInstance().get(Calendar.YEAR) + "' ";

            break;
        case THIS_WEAK:
            removeCustomDataValues();

            Calendar c1 = Calendar.getInstance();
            c1.setFirstDayOfWeek(Calendar.MONDAY);
            c1.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);

            int y = c1.get(Calendar.YEAR);
            int m = c1.get(Calendar.MONTH) + 1;
            int d = c1.get(Calendar.DAY_OF_MONTH);

            String sYear1 = String.valueOf(y);
            String sMonth1 = String.valueOf(m);
            if (m < 10)
                sMonth1 = "0" + sMonth1;
            String sDay1 = String.valueOf(d);
            if (d < 10)
                sDay1 = "0" + sDay1;

            c1.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);

            int y2 = c1.get(Calendar.YEAR);
            int m2 = c1.get(Calendar.MONTH) + 1;
            int d2 = c1.get(Calendar.DAY_OF_MONTH);

            String sYear2 = String.valueOf(y2);
            String sMonth2 = String.valueOf(m2);
            if (m2 < 10)
                sMonth2 = "0" + sMonth2;
            String sDay2 = String.valueOf(d2);
            if (d2 < 10)
                sDay2 = "0" + sDay2;

            if (activity > 0) {
                cursor = DBManager.CustomQuery(
                        getString(R.string.selecting_this_weak_routes) + " "
                                + getString(R.string.filter_by_activity) + " " + getString(R.string.and) + " "
                                + getString(R.string.group_by_activities),
                        "SELECT category_id, COUNT(*) AS count_practices, SUM(distance) AS sum_distance, "
                                + "SUM(kcal) AS sum_kcal, SUM(time) AS sum_time, SUM(avg_speed) AS sum_avg_speed, "
                                + "SUM(up_accum_altitude) AS sum_up_accum_altitude, "
                                + "SUM(down_accum_altitude) AS sum_down_accum_altitude, "
                                + "SUM(steps) AS sum_steps " + "FROM routes "
                                + "WHERE substr(date,7)||substr(date,4,2)||substr(date,1,2) " + "BETWEEN '"
                                + sYear1 + sMonth1 + sDay1 + "' AND '" + sYear2 + sMonth2 + sDay2 + "' "
                                + "AND category_id = '" + activity + "' " + "GROUP BY category_id");
            } else {
                cursor = DBManager.CustomQuery(
                        getString(R.string.selecting_this_weak_routes) + " "
                                + getString(R.string.group_by_activities),
                        "SELECT category_id, COUNT(*) AS count_practices, SUM(distance) AS sum_distance, "
                                + "SUM(kcal) AS sum_kcal, SUM(time) AS sum_time, SUM(avg_speed) AS sum_avg_speed, "
                                + "SUM(up_accum_altitude) AS sum_up_accum_altitude, "
                                + "SUM(down_accum_altitude) AS sum_down_accum_altitude, "
                                + "SUM(steps) AS sum_steps " + "FROM routes "
                                + "WHERE substr(date,7)||substr(date,4,2)||substr(date,1,2) " + "BETWEEN '"
                                + sYear1 + sMonth1 + sDay1 + "' AND '" + sYear2 + sMonth2 + sDay2 + "' "
                                + "GROUP BY category_id");
            }

            between_dates_query_part = "substr(date,7)||substr(date,4,2)||substr(date,1,2) " + "BETWEEN '"
                    + sYear1 + sMonth1 + sDay1 + "' AND '" + sYear2 + sMonth2 + sDay2 + "' ";

            break;
        case BETWEEN_TWO_DATES:
            String mYear1 = String.valueOf(year1);
            String mMonth1 = String.valueOf(month1);
            if (month1 < 10)
                mMonth1 = "0" + mMonth1;
            String mDay1 = String.valueOf(day1);
            if (day1 < 10)
                mDay1 = "0" + mDay1;

            String mYear2 = String.valueOf(year2);
            String mMonth2 = String.valueOf(month2);
            if (month2 < 10)
                mMonth2 = "0" + mMonth2;
            String mDay2 = String.valueOf(day2);
            if (day2 < 10)
                mDay2 = "0" + mDay2;

            customDay1 = mDay1;
            customDay2 = mDay2;
            customMonth1 = mMonth1;
            customMonth2 = mMonth2;
            customYear1 = mYear1;
            customYear2 = mYear2;

            if (activity > 0) {
                cursor = DBManager.CustomQuery("Seleccionando las rutas de este mes agrupadas por actividad",
                        "SELECT category_id, COUNT(*) AS count_practices, SUM(distance) AS sum_distance, "
                                + "SUM(kcal) AS sum_kcal, SUM(time) AS sum_time, SUM(avg_speed) AS sum_avg_speed, "
                                + "SUM(up_accum_altitude) AS sum_up_accum_altitude, "
                                + "SUM(down_accum_altitude) AS sum_down_accum_altitude, "
                                + "SUM(steps) AS sum_steps " + "FROM routes "
                                + "WHERE substr(date,7)||substr(date,4,2)||substr(date,1,2) " + "BETWEEN '"
                                + customYear1 + customMonth1 + customDay1 + "' AND '" + customYear2
                                + customMonth2 + customDay2 + "' " + "AND category_id = '" + activity + "' "
                                + "GROUP BY category_id");
            } else {
                cursor = DBManager.CustomQuery("Seleccionando las rutas de este mes agrupadas por actividad",
                        "SELECT category_id, COUNT(*) AS count_practices, SUM(distance) AS sum_distance, "
                                + "SUM(kcal) AS sum_kcal, SUM(time) AS sum_time, SUM(avg_speed) AS sum_avg_speed, "
                                + "SUM(up_accum_altitude) AS sum_up_accum_altitude, "
                                + "SUM(down_accum_altitude) AS sum_down_accum_altitude, "
                                + "SUM(steps) AS sum_steps " + "FROM routes "
                                + "WHERE substr(date,7)||substr(date,4,2)||substr(date,1,2) " + "BETWEEN '"
                                + customYear1 + customMonth1 + customDay1 + "' AND '" + customYear2
                                + customMonth2 + customDay2 + "' " + "GROUP BY category_id");
            }

            between_dates_query_part = "substr(date,7)||substr(date,4,2)||substr(date,1,2) " + "BETWEEN '"
                    + customYear1 + customMonth1 + customDay1 + "' AND '" + customYear2 + customMonth2
                    + customDay2 + "' ";

            break;
        }
        cursor.moveToFirst();

        base_layout.setVisibility(View.VISIBLE);
        scrollView.setVisibility(View.VISIBLE);
        layout1.setVisibility(View.VISIBLE);
        layout2.setVisibility(View.VISIBLE);
        layout3.setVisibility(View.VISIBLE);
        layout4.setVisibility(View.VISIBLE);

        distance_distribution = new float[cursor.getCount()];
        kcal_distribution = new int[cursor.getCount()];
        time_distribution = new int[cursor.getCount()];

        int i = 0;

        mTableLayout.removeAllViews();

        while (!cursor.isAfterLast()) {
            TextView color = new TextView(mContext);
            TextView label = new TextView(mContext);
            TextView value = new TextView(mContext);
            LinearLayout.LayoutParams colorLayoutParams = new LinearLayout.LayoutParams(
                    new LayoutParams(FunctionUtils.calculateDpFromPx(mContext, 20),
                            FunctionUtils.calculateDpFromPx(mContext, 20)));
            colorLayoutParams.setMargins(0, 1, 5, 1);
            color.setLayoutParams(colorLayoutParams);
            label.setLayoutParams(
                    new LayoutParams(FunctionUtils.calculateDpFromPx(mContext, 95), LayoutParams.WRAP_CONTENT));
            label.setTypeface(null, Typeface.BOLD);
            label.setTextColor(Color.parseColor("#b5b5b5"));
            value.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
            value.setTextColor(res.getColor(R.color.white));

            color.setBackgroundColor(colors[i]);

            label.setText(activities[cursor.getInt(cursor.getColumnIndex("category_id")) - 1] + ":");
            value.setText((isMetric
                    ? String.valueOf(cursor.getFloat(cursor.getColumnIndex("sum_distance"))) + " "
                            + getString(R.string.long_unit1_detail_1) + ", "
                    : String.valueOf(FunctionUtils.customizedRound(
                            ((cursor.getFloat(cursor.getColumnIndex("sum_distance")) * 1000f) / 1609f), 2))
                            + " " + getString(R.string.long_unit2_detail_1) + ", ")
                    + String.valueOf((int) cursor.getFloat(cursor.getColumnIndex("sum_kcal"))) + " "
                    + getString(R.string.tell_calories_setting_details) + ", "
                    + String.valueOf(FunctionUtils.statisticsFormatTime(mContext,
                            (long) cursor.getFloat(cursor.getColumnIndex("sum_time")))));

            LinearLayout mLinearLayout = new LinearLayout(mContext);
            mLinearLayout
                    .setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            mLinearLayout.setOrientation(0);
            mLinearLayout.addView(color);
            mLinearLayout.addView(label);
            mLinearLayout.addView(value);
            mTableLayout.addView(mLinearLayout);

            sum_distance = sum_distance + cursor.getFloat(cursor.getColumnIndex("sum_distance"));
            sum_kcal = sum_kcal + cursor.getInt(cursor.getColumnIndex("sum_kcal"));
            sum_time = sum_time + cursor.getInt(cursor.getColumnIndex("sum_time"));
            sum_up_accum_altitude = sum_up_accum_altitude
                    + cursor.getInt(cursor.getColumnIndex("sum_up_accum_altitude"));
            sum_down_accum_altitude = sum_down_accum_altitude
                    + cursor.getInt(cursor.getColumnIndex("sum_down_accum_altitude"));
            sum_avg_speed = sum_avg_speed + cursor.getFloat(cursor.getColumnIndex("sum_avg_speed"));
            sum_steps = sum_steps + cursor.getInt(cursor.getColumnIndex("sum_steps"));

            distance_distribution[i] = cursor.getFloat(cursor.getColumnIndex("sum_distance"));
            kcal_distribution[i] = cursor.getInt(cursor.getColumnIndex("sum_kcal"));
            time_distribution[i] = cursor.getInt(cursor.getColumnIndex("sum_time"));

            practices_counter = practices_counter
                    + (int) cursor.getFloat(cursor.getColumnIndex("count_practices"));

            i++;

            cursor.moveToNext();
        }

        String activity_query_part = "";
        if (activity > 0)
            activity_query_part = " AND category_id = '" + activity + "'";

        if (between_dates_query_part.length() > 0) {
            cursor = DBManager.CustomQuery(getString(R.string.routes_with_hr),
                    "SELECT avg_hr FROM routes WHERE avg_hr > 0 AND " + between_dates_query_part
                            + activity_query_part);
        } else {
            cursor = DBManager.CustomQuery(getString(R.string.routes_with_hr),
                    "SELECT avg_hr FROM routes WHERE avg_hr > 0" + activity_query_part);
        }
        cursor.moveToFirst();
        if (cursor.getCount() > 0) {
            while (!cursor.isAfterLast()) {
                sum_avg_hr = sum_avg_hr + cursor.getInt(cursor.getColumnIndex("avg_hr"));
                hr_practices_counter += 1;

                cursor.moveToNext();
            }
        }

        text8.setText("");
        if (between_dates_query_part.length() > 0) {
            if (activity > 0)
                activity_query_part = " AND category_id = '" + activity + "' ";

            cursor = DBManager.CustomQuery(getString(R.string.selecting_most_used_shoes),
                    "SELECT shoe_id, COUNT(shoe_id) AS count_shoes " + "FROM routes " + "WHERE "
                            + between_dates_query_part + activity_query_part + "GROUP BY shoe_id "
                            + "ORDER BY count_shoes DESC");
        } else {
            if (activity > 0)
                activity_query_part = "WHERE category_id = '" + activity + "' ";

            cursor = DBManager.CustomQuery(getString(R.string.selecting_most_used_shoes_in_data_range),
                    "SELECT shoe_id, COUNT(shoe_id) AS count_shoes " + "FROM routes " + activity_query_part
                            + "GROUP BY shoe_id " + "ORDER BY count_shoes DESC");
        }
        cursor.moveToFirst();
        if (cursor.getCount() > 0) {
            int shoe = cursor.getInt(cursor.getColumnIndex("shoe_id"));
            if (cursor.getCount() > 1) {
                int[] shoes = new int[cursor.getCount()];
                int m = 0;
                while (!cursor.isAfterLast()) {
                    shoes[m] = cursor.getInt(cursor.getColumnIndex("shoe_id"));
                    m++;
                    cursor.moveToNext();
                }

                if (shoe == 0 && shoes.length > 1)
                    shoe = shoes[1];
            }

            if (shoe > 0) {
                cursor = DBManager.CustomQuery(getString(R.string.shoe_name),
                        "SELECT name FROM shoes WHERE _id = '" + shoe + "'");
                cursor.moveToFirst();
                text8.setText(cursor.getString(cursor.getColumnIndex("name")));
            }

        }

        text1.setText(String.valueOf(practices_counter));
        text2.setText(String.valueOf(FunctionUtils.statisticsFormatTime(mContext, (long) sum_time)));
        text3.setText(isMetric
                ? String.valueOf(FunctionUtils.customizedRound(sum_distance, 2)) + " "
                        + getString(R.string.long_unit1_detail_1)
                : String.valueOf(FunctionUtils.customizedRound(((sum_distance * 1000f) / 1609f), 2)) + " "
                        + getString(R.string.long_unit2_detail_1));
        text4.setText(
                isMetric ? String.valueOf(sum_up_accum_altitude) + " " + getString(R.string.long_unit1_detail_4)
                        : String.valueOf((int) (sum_up_accum_altitude * 1.0936f)) + " "
                                + getString(R.string.long_unit2_detail_4));
        text5.setText(isMetric
                ? String.valueOf(sum_down_accum_altitude) + " " + getString(R.string.long_unit1_detail_4)
                : String.valueOf((int) (sum_down_accum_altitude * 1.0936f)) + " "
                        + getString(R.string.long_unit2_detail_4));
        if ((sum_avg_speed > 0) && (practices_counter > 0)) {
            text6.setText((isMetric
                    ? String.valueOf(FunctionUtils.customizedRound((sum_avg_speed / practices_counter), 2))
                            + " " + getString(R.string.long_unit1_detail_2)
                    : String.valueOf(FunctionUtils
                            .customizedRound((((sum_avg_speed * 1000f) / 1609f) / practices_counter), 2)) + " "
                            + getString(R.string.long_unit2_detail_2)));
        } else {
            text6.setText(
                    getString(R.string.zero_value) + " " + (isMetric ? getString(R.string.long_unit1_detail_2)
                            : mContext.getString(R.string.long_unit2_detail_2)));
        }
        text7.setText(String.valueOf(
                FunctionUtils.calculateRitm(mContext, sum_time, String.valueOf(sum_distance), isMetric, false))
                + " " + (isMetric ? getString(R.string.long_unit1_detail_3)
                        : mContext.getString(R.string.long_unit2_detail_3)));
        text9.setText(String.valueOf(sum_kcal) + " " + getString(R.string.tell_calories_setting_details));
        text10.setText(String.valueOf(sum_steps));
        if ((sum_avg_hr > 0) && (hr_practices_counter > 0)) {
            text11.setText(String.valueOf(sum_avg_hr / hr_practices_counter) + " "
                    + getString(R.string.beats_per_minute));
        } else {
            text11.setText(getString(R.string.zero_value) + " " + getString(R.string.beats_per_minute));
        }
        if (sum_kcal > 0) {
            text12.setText(String.valueOf(sum_kcal / Constants.CHEESE_BURGER));
        } else {
            text12.setText(getString(R.string.zero_value));
        }
        if (sum_distance > 0) {
            text13.setText(String.valueOf(
                    FunctionUtils.customizedRound((sum_distance / Constants.ALL_THE_WAY_AROUND_THE_WORLD), 3)));
        } else {
            text13.setText(getString(R.string.zero_with_three_decimal_places_value));
        }
        if (sum_distance > 0) {
            double moon_distance = ((double) sum_distance) / ((double) Constants.TO_THE_MOON);
            text14.setText(String.valueOf(
                    FunctionUtils.customizedRound(Float.parseFloat(String.valueOf(moon_distance)), 1)));
        } else {
            text14.setText(getString(R.string.zero_with_one_decimal_place_value));
        }

        layout1.removeAllViews();
        layout2.removeAllViews();
        layout3.removeAllViews();

        mChartView1 = null;
        mChartView2 = null;
        mChartView3 = null;

        for (int h = 0; h < distance_distribution.length; h++) {
            float percent = 0;

            if (distance_distribution[h] > 0)
                percent = (distance_distribution[h] * 100) / sum_distance;

            if (sum_distance == 0)
                percent = 100 / distance_distribution.length;

            distance_distribution[h] = percent;
        }

        for (int b = 0; b < kcal_distribution.length; b++) {
            int percent = 0;

            if (sum_kcal > 0)
                percent = (kcal_distribution[b] * 100) / sum_kcal;

            if (sum_kcal == 0)
                percent = 100 / kcal_distribution.length;

            kcal_distribution[b] = percent;
        }

        final CategorySeries distance_distributionSeries = new CategorySeries("");
        for (int g = 0; g < distance_distribution.length; g++) {
            if (distance_distribution.length == 1) {
                distance_distributionSeries.add("", 100);
            } else {
                distance_distributionSeries.add("", distance_distribution[g]);
            }
        }

        final CategorySeries kcal_distributionSeries = new CategorySeries("");
        for (int p = 0; p < kcal_distribution.length; p++) {
            if (kcal_distribution.length == 1) {
                kcal_distributionSeries.add("", 100);
            } else {
                kcal_distributionSeries.add("", kcal_distribution[p]);
            }
        }

        final CategorySeries time_distributionSeries = new CategorySeries("");
        for (int l = 0; l < time_distribution.length; l++) {
            if (time_distribution.length == 1) {
                time_distributionSeries.add("", 100);
            } else {
                time_distributionSeries.add("", time_distribution[l]);
            }
        }

        DefaultRenderer defaultRenderer = new DefaultRenderer();
        DefaultRenderer defaultRenderer2 = new DefaultRenderer();
        DefaultRenderer defaultRenderer3 = new DefaultRenderer();

        defaultRenderer.setShowLabels(false);
        defaultRenderer.setZoomButtonsVisible(false);
        defaultRenderer.setStartAngle(180);
        defaultRenderer.setDisplayValues(false);
        defaultRenderer.setClickEnabled(true);
        defaultRenderer.setInScroll(true);
        defaultRenderer.setShowLegend(false);

        defaultRenderer2.setShowLabels(false);
        defaultRenderer2.setZoomButtonsVisible(false);
        defaultRenderer2.setStartAngle(180);
        defaultRenderer2.setDisplayValues(false);
        defaultRenderer2.setClickEnabled(true);
        defaultRenderer2.setInScroll(true);
        defaultRenderer2.setShowLegend(false);

        defaultRenderer3.setShowLabels(false);
        defaultRenderer3.setZoomButtonsVisible(false);
        defaultRenderer3.setStartAngle(180);
        defaultRenderer3.setDisplayValues(false);
        defaultRenderer3.setClickEnabled(true);
        defaultRenderer3.setInScroll(true);
        defaultRenderer3.setShowLegend(false);

        for (int u = 0; u < distance_distribution.length; u++) {
            SimpleSeriesRenderer seriesRenderer = new SimpleSeriesRenderer();
            seriesRenderer.setColor(colors[u]);
            seriesRenderer.setDisplayChartValues(true);
            seriesRenderer.setHighlighted(false);

            defaultRenderer.addSeriesRenderer(seriesRenderer);
        }

        for (int p = 0; p < kcal_distribution.length; p++) {
            SimpleSeriesRenderer seriesRenderer2 = new SimpleSeriesRenderer();
            seriesRenderer2.setColor(colors[p]);
            seriesRenderer2.setDisplayChartValues(true);
            seriesRenderer2.setHighlighted(false);

            defaultRenderer2.addSeriesRenderer(seriesRenderer2);
        }

        for (int o = 0; o < distance_distribution.length; o++) {
            SimpleSeriesRenderer seriesRenderer3 = new SimpleSeriesRenderer();
            seriesRenderer3.setColor(colors[o]);
            seriesRenderer3.setDisplayChartValues(true);
            seriesRenderer3.setHighlighted(false);

            defaultRenderer3.addSeriesRenderer(seriesRenderer3);
        }

        mChartView1 = ChartFactory.getPieChartView(mContext, distance_distributionSeries, defaultRenderer);
        mChartView2 = ChartFactory.getPieChartView(mContext, kcal_distributionSeries, defaultRenderer2);
        mChartView3 = ChartFactory.getPieChartView(mContext, time_distributionSeries, defaultRenderer3);

        layout1.addView(mChartView1);
        layout2.addView(mChartView2);
        layout3.addView(mChartView3);
    } else {
        base_layout.setVisibility(View.INVISIBLE);
        scrollView.setVisibility(View.INVISIBLE);
        layout1.setVisibility(View.INVISIBLE);
        layout2.setVisibility(View.INVISIBLE);
        layout3.setVisibility(View.INVISIBLE);
        layout4.setVisibility(View.INVISIBLE);
    }
    cursor.close();
    DBManager.Close();
}

From source file:com.hughes.android.dictionary.DictionaryActivity.java

void onLanguageButtonLongClick(final Context context) {
    final Dialog dialog = new Dialog(context);
    dialog.setContentView(R.layout.select_dictionary_dialog);
    dialog.setTitle(R.string.selectDictionary);

    final List<DictionaryInfo> installedDicts = application.getDictionariesOnDevice(null);

    ListView listView = (ListView) dialog.findViewById(android.R.id.list);
    final Button button = new Button(listView.getContext());
    final String name = getString(R.string.dictionaryManager);
    button.setText(name);/*ww  w . j av a  2 s.com*/
    final IntentLauncher intentLauncher = new IntentLauncher(listView.getContext(),
            DictionaryManagerActivity.getLaunchIntent(getApplicationContext())) {
        @Override
        protected void onGo() {
            dialog.dismiss();
            DictionaryActivity.this.finish();
        }
    };
    button.setOnClickListener(intentLauncher);
    listView.addHeaderView(button);

    listView.setAdapter(new BaseAdapter() {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            final DictionaryInfo dictionaryInfo = getItem(position);

            final LinearLayout result = new LinearLayout(parent.getContext());

            for (int i = 0; i < dictionaryInfo.indexInfos.size(); ++i) {
                final IndexInfo indexInfo = dictionaryInfo.indexInfos.get(i);
                final View button = application.createButton(parent.getContext(), dictionaryInfo, indexInfo);
                final IntentLauncher intentLauncher = new IntentLauncher(parent.getContext(),
                        getLaunchIntent(getApplicationContext(),
                                application.getPath(dictionaryInfo.uncompressedFilename), indexInfo.shortName,
                                searchView.getQuery().toString())) {
                    @Override
                    protected void onGo() {
                        dialog.dismiss();
                        DictionaryActivity.this.finish();
                    }
                };
                button.setOnClickListener(intentLauncher);
                if (i == indexIndex && dictFile != null
                        && dictFile.getName().equals(dictionaryInfo.uncompressedFilename)) {
                    button.setPressed(true);
                }
                result.addView(button);
            }

            final TextView nameView = new TextView(parent.getContext());
            final String name = application.getDictionaryName(dictionaryInfo.uncompressedFilename);
            nameView.setText(name);
            final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            layoutParams.width = 0;
            layoutParams.weight = 1.0f;
            nameView.setLayoutParams(layoutParams);
            nameView.setGravity(Gravity.CENTER_VERTICAL);
            result.addView(nameView);
            return result;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public DictionaryInfo getItem(int position) {
            return installedDicts.get(position);
        }

        @Override
        public int getCount() {
            return installedDicts.size();
        }
    });
    dialog.show();
}

From source file:com.goftagram.telegram.ui.Components.PasscodeView.java

private void checkFingerprint() {
    Activity parentActivity = (Activity) getContext();
    if (Build.VERSION.SDK_INT >= 23 && parentActivity != null && UserConfig.useFingerprint
            && !ApplicationLoader.mainInterfacePaused) {
        try {/* w  w w  .  ja v  a  2  s  .  c o m*/
            if (fingerprintDialog != null && fingerprintDialog.isShowing()) {
                return;
            }
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
        try {
            FingerprintManagerCompat fingerprintManager = FingerprintManagerCompat
                    .from(ApplicationLoader.applicationContext);
            if (fingerprintManager.isHardwareDetected() && fingerprintManager.hasEnrolledFingerprints()) {
                RelativeLayout relativeLayout = new RelativeLayout(getContext());
                relativeLayout.setPadding(AndroidUtilities.dp(24), AndroidUtilities.dp(16),
                        AndroidUtilities.dp(24), AndroidUtilities.dp(8));

                TextView fingerprintTextView = new TextView(getContext());
                fingerprintTextView.setTextColor(0xff939393);
                fingerprintTextView.setId(id_fingerprint_textview);
                fingerprintTextView.setTextAppearance(android.R.style.TextAppearance_Material_Subhead);
                fingerprintTextView
                        .setText(LocaleController.getString("FingerprintInfo", R.string.FingerprintInfo));
                relativeLayout.addView(fingerprintTextView);
                RelativeLayout.LayoutParams layoutParams = LayoutHelper
                        .createRelative(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT);
                layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
                layoutParams.addRule(RelativeLayout.ALIGN_PARENT_START);
                fingerprintTextView.setLayoutParams(layoutParams);

                fingerprintImageView = new ImageView(getContext());
                fingerprintImageView.setImageResource(R.drawable.ic_fp_40px);
                fingerprintImageView.setId(id_fingerprint_imageview);
                relativeLayout.addView(fingerprintImageView,
                        LayoutHelper.createRelative(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, 0, 20,
                                0, 0, RelativeLayout.ALIGN_PARENT_START, RelativeLayout.BELOW,
                                id_fingerprint_textview));

                fingerprintStatusTextView = new TextView(getContext());
                fingerprintStatusTextView.setGravity(Gravity.CENTER_VERTICAL);
                fingerprintStatusTextView
                        .setText(LocaleController.getString("FingerprintHelp", R.string.FingerprintHelp));
                fingerprintStatusTextView.setTextAppearance(android.R.style.TextAppearance_Material_Body1);
                fingerprintStatusTextView.setTextColor(0x42000000);
                relativeLayout.addView(fingerprintStatusTextView);
                layoutParams = LayoutHelper.createRelative(LayoutHelper.WRAP_CONTENT,
                        LayoutHelper.WRAP_CONTENT);
                layoutParams.setMarginStart(AndroidUtilities.dp(16));
                layoutParams.addRule(RelativeLayout.ALIGN_BOTTOM, id_fingerprint_imageview);
                layoutParams.addRule(RelativeLayout.ALIGN_TOP, id_fingerprint_imageview);
                layoutParams.addRule(RelativeLayout.END_OF, id_fingerprint_imageview);
                fingerprintStatusTextView.setLayoutParams(layoutParams);

                AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                builder.setView(relativeLayout);
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
                    @Override
                    public void onDismiss(DialogInterface dialog) {
                        if (cancellationSignal != null) {
                            selfCancelled = true;
                            cancellationSignal.cancel();
                            cancellationSignal = null;
                        }
                    }
                });
                if (fingerprintDialog != null) {
                    try {
                        if (fingerprintDialog.isShowing()) {
                            fingerprintDialog.dismiss();
                        }
                    } catch (Exception e) {
                        FileLog.e("tmessages", e);
                    }
                }
                fingerprintDialog = builder.show();

                cancellationSignal = new CancellationSignal();
                selfCancelled = false;
                fingerprintManager.authenticate(null, 0, cancellationSignal,
                        new FingerprintManagerCompat.AuthenticationCallback() {
                            @Override
                            public void onAuthenticationError(int errMsgId, CharSequence errString) {
                                if (!selfCancelled) {
                                    showFingerprintError(errString);
                                }
                            }

                            @Override
                            public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
                                showFingerprintError(helpString);
                            }

                            @Override
                            public void onAuthenticationFailed() {
                                showFingerprintError(LocaleController.getString("FingerprintNotRecognized",
                                        R.string.FingerprintNotRecognized));
                            }

                            @Override
                            public void onAuthenticationSucceeded(
                                    FingerprintManagerCompat.AuthenticationResult result) {
                                try {
                                    if (fingerprintDialog.isShowing()) {
                                        fingerprintDialog.dismiss();
                                    }
                                } catch (Exception e) {
                                    FileLog.e("tmessages", e);
                                }
                                fingerprintDialog = null;
                                processDone(true);
                            }
                        }, null);
            }
        } catch (Throwable e) {
            //ignore
        }
    }
}

From source file:kr.wdream.ui.Components.PasscodeView.java

private void checkFingerprint() {
    Activity parentActivity = (Activity) getContext();
    if (Build.VERSION.SDK_INT >= 23 && parentActivity != null && UserConfig.useFingerprint
            && !ApplicationLoader.mainInterfacePaused) {
        try {/*  ww w . j a  v a 2  s . c  o  m*/
            if (fingerprintDialog != null && fingerprintDialog.isShowing()) {
                return;
            }
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
        try {
            FingerprintManagerCompat fingerprintManager = FingerprintManagerCompat
                    .from(ApplicationLoader.applicationContext);
            if (fingerprintManager.isHardwareDetected() && fingerprintManager.hasEnrolledFingerprints()) {
                RelativeLayout relativeLayout = new RelativeLayout(getContext());
                relativeLayout.setPadding(AndroidUtilities.dp(24), AndroidUtilities.dp(16),
                        AndroidUtilities.dp(24), AndroidUtilities.dp(8));

                TextView fingerprintTextView = new TextView(getContext());
                fingerprintTextView.setTextColor(0xff939393);
                fingerprintTextView.setId(id_fingerprint_textview);
                fingerprintTextView.setTextAppearance(android.R.style.TextAppearance_Material_Subhead);
                fingerprintTextView.setText(LocaleController.getString("FingerprintInfo",
                        kr.wdream.storyshop.R.string.FingerprintInfo));
                relativeLayout.addView(fingerprintTextView);
                RelativeLayout.LayoutParams layoutParams = LayoutHelper
                        .createRelative(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT);
                layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
                layoutParams.addRule(RelativeLayout.ALIGN_PARENT_START);
                fingerprintTextView.setLayoutParams(layoutParams);

                fingerprintImageView = new ImageView(getContext());
                fingerprintImageView.setImageResource(kr.wdream.storyshop.R.drawable.ic_fp_40px);
                fingerprintImageView.setId(id_fingerprint_imageview);
                relativeLayout.addView(fingerprintImageView,
                        LayoutHelper.createRelative(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, 0, 20,
                                0, 0, RelativeLayout.ALIGN_PARENT_START, RelativeLayout.BELOW,
                                id_fingerprint_textview));

                fingerprintStatusTextView = new TextView(getContext());
                fingerprintStatusTextView.setGravity(Gravity.CENTER_VERTICAL);
                fingerprintStatusTextView.setText(LocaleController.getString("FingerprintHelp",
                        kr.wdream.storyshop.R.string.FingerprintHelp));
                fingerprintStatusTextView.setTextAppearance(android.R.style.TextAppearance_Material_Body1);
                fingerprintStatusTextView.setTextColor(0x42000000);
                relativeLayout.addView(fingerprintStatusTextView);
                layoutParams = LayoutHelper.createRelative(LayoutHelper.WRAP_CONTENT,
                        LayoutHelper.WRAP_CONTENT);
                layoutParams.setMarginStart(AndroidUtilities.dp(16));
                layoutParams.addRule(RelativeLayout.ALIGN_BOTTOM, id_fingerprint_imageview);
                layoutParams.addRule(RelativeLayout.ALIGN_TOP, id_fingerprint_imageview);
                layoutParams.addRule(RelativeLayout.END_OF, id_fingerprint_imageview);
                fingerprintStatusTextView.setLayoutParams(layoutParams);

                AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
                builder.setTitle(LocaleController.getString("AppName", kr.wdream.storyshop.R.string.AppName));
                builder.setView(relativeLayout);
                builder.setNegativeButton(
                        LocaleController.getString("Cancel", kr.wdream.storyshop.R.string.Cancel), null);
                builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
                    @Override
                    public void onDismiss(DialogInterface dialog) {
                        if (cancellationSignal != null) {
                            selfCancelled = true;
                            cancellationSignal.cancel();
                            cancellationSignal = null;
                        }
                    }
                });
                if (fingerprintDialog != null) {
                    try {
                        if (fingerprintDialog.isShowing()) {
                            fingerprintDialog.dismiss();
                        }
                    } catch (Exception e) {
                        FileLog.e("tmessages", e);
                    }
                }
                fingerprintDialog = builder.show();

                cancellationSignal = new CancellationSignal();
                selfCancelled = false;
                fingerprintManager.authenticate(null, 0, cancellationSignal,
                        new FingerprintManagerCompat.AuthenticationCallback() {
                            @Override
                            public void onAuthenticationError(int errMsgId, CharSequence errString) {
                                if (!selfCancelled) {
                                    showFingerprintError(errString);
                                }
                            }

                            @Override
                            public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
                                showFingerprintError(helpString);
                            }

                            @Override
                            public void onAuthenticationFailed() {
                                showFingerprintError(LocaleController.getString("FingerprintNotRecognized",
                                        kr.wdream.storyshop.R.string.FingerprintNotRecognized));
                            }

                            @Override
                            public void onAuthenticationSucceeded(
                                    FingerprintManagerCompat.AuthenticationResult result) {
                                try {
                                    if (fingerprintDialog.isShowing()) {
                                        fingerprintDialog.dismiss();
                                    }
                                } catch (Exception e) {
                                    FileLog.e("tmessages", e);
                                }
                                fingerprintDialog = null;
                                processDone(true);
                            }
                        }, null);
            }
        } catch (Throwable e) {
            //ignore
        }
    }
}

From source file:com.citrus.sample.WalletPaymentFragment.java

private void showSendMoneyPrompt() {
    final AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
    final String message = "Send Money to Friend In A Flash";
    String positiveButtonText = "Send";

    LinearLayout linearLayout = new LinearLayout(getActivity());
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    final TextView labelAmount = new TextView(getActivity());
    final EditText editAmount = new EditText(getActivity());
    final TextView labelMobileNo = new TextView(getActivity());
    final EditText editMobileNo = new EditText(getActivity());
    final TextView labelMessage = new TextView(getActivity());
    final EditText editMessage = new EditText(getActivity());
    editAmount.setSingleLine(true);//from  ww  w.  j ava  2  s . c  om
    editMobileNo.setSingleLine(true);
    editMessage.setSingleLine(true);

    labelAmount.setText("Amount");
    labelMobileNo.setText("Enter Mobile No of Friend");
    labelMessage.setText("Enter Message (Optional)");

    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

    labelAmount.setLayoutParams(layoutParams);
    labelMobileNo.setLayoutParams(layoutParams);
    labelMessage.setLayoutParams(layoutParams);
    editAmount.setLayoutParams(layoutParams);
    editMobileNo.setLayoutParams(layoutParams);
    editMessage.setLayoutParams(layoutParams);

    linearLayout.addView(labelAmount);
    linearLayout.addView(editAmount);
    linearLayout.addView(labelMobileNo);
    linearLayout.addView(editMobileNo);
    linearLayout.addView(labelMessage);
    linearLayout.addView(editMessage);

    int paddingPx = Utils.getSizeInPx(getActivity(), 32);
    linearLayout.setPadding(paddingPx, paddingPx, paddingPx, paddingPx);

    editAmount.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
    editMobileNo.setInputType(InputType.TYPE_CLASS_NUMBER);
    alert.setTitle("Send Money In A Flash");
    alert.setMessage(message);

    alert.setView(linearLayout);
    alert.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int whichButton) {
            String amount = editAmount.getText().toString();
            String mobileNo = editMobileNo.getText().toString();
            String message = editMessage.getText().toString();

            mCitrusClient.sendMoneyToMoblieNo(new Amount(amount), mobileNo, message,
                    new Callback<PaymentResponse>() {
                        @Override
                        public void success(PaymentResponse paymentResponse) {
                            //                        Utils.showToast(getActivity(), paymentResponse.getStatus() == CitrusResponse.Status.SUCCESSFUL ? "Sent Money Successfully." : "Failed To Send the Money");
                            ((UIActivity) getActivity()).showSnackBar(
                                    paymentResponse.getStatus() == CitrusResponse.Status.SUCCESSFUL
                                            ? "Sent Money Successfully."
                                            : "Failed To Send the Money");
                        }

                        @Override
                        public void error(CitrusError error) {
                            //                        Utils.showToast(getActivity(), error.getMessage());
                            ((UIActivity) getActivity()).showSnackBar(error.getMessage());
                        }
                    });
            // Hide the keyboard.
            InputMethodManager imm = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(editAmount.getWindowToken(), 0);
        }
    });

    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.cancel();
        }
    });

    editAmount.requestFocus();
    alert.show();
}

From source file:com.juick.android.MessagesFragment.java

public void lastPrepareMessages(final List<JuickMessage> list, final Runnable then) {
    databaseGetter.getService(new Utils.ServiceGetter.Receiver<DatabaseService>() {
        @Override//from w w w .  j  a v  a2 s.c  o  m
        public void withService(final DatabaseService service) {
            new Thread("processLastReads cont") {
                @Override
                public void run() {
                    for (JuickMessage juickMessage : list) {
                        // we can use service inside here, because getMessageReadStatus0 is thread-safe
                        final DatabaseService.MessageReadStatus messageReadStatus0 = service
                                .getMessageReadStatus0(juickMessage.getMID());
                        if (messageReadStatus0.read) {
                            juickMessage.read = true;
                            juickMessage.readComments = messageReadStatus0.nreplies;
                        }
                    }

                    final Activity act = getActivity();

                    if (act != null) {
                        if (sp.getBoolean("text_accelerated", false)) {
                            // accelerate text draw

                            final Bitmap bm = Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8);
                            while (MessagesFragment.this.getView().getMeasuredWidth() == 0) {
                                try {
                                    Thread.sleep(100);
                                } catch (InterruptedException e) {
                                    e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
                                }
                            }

                            TextView tv = new TextView(act);
                            tv.setTextSize(JuickMessagesAdapter.getTextSize(act));
                            MainActivity.restyleChildrenOrWidget(tv);
                            final int outerViewWidth = MessagesFragment.this.getView().getMeasuredWidth();
                            final int width = outerViewWidth - 6;
                            tv.setWidth(width);
                            tv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                    ViewGroup.LayoutParams.WRAP_CONTENT));
                            final ArrayList<JuickMessagesAdapter.CanvasPainter> stuff = new ArrayList<JuickMessagesAdapter.CanvasPainter>();

                            Canvas canvas = new Canvas(bm) {
                                @Override
                                public void drawText(char[] text, int index, int count, float x, float y,
                                        Paint paint) {
                                    super.drawText(text, index, count, x, y, paint); //To change body of overridden methods use File | Settings | File Templates.
                                }

                                @Override
                                public void drawText(String text, float x, float y, Paint paint) {
                                    super.drawText(text, x, y, paint); //To change body of overridden methods use File | Settings | File Templates.
                                }

                                @Override
                                public void drawText(String text, int start, int end, float x, float y,
                                        Paint paint) {
                                    super.drawText(text, start, end, x, y, paint); //To change body of overridden methods use File | Settings | File Templates.
                                }

                                @Override
                                public void drawText(CharSequence text, int start, int end, float x, float y,
                                        Paint paint) {
                                    super.drawText(text, start, end, x, y, paint); //To change body of overridden methods use File | Settings | File Templates.
                                }

                                @Override
                                public void drawVertices(VertexMode mode, int vertexCount, float[] verts,
                                        int vertOffset, float[] texs, int texOffset, int[] colors,
                                        int colorOffset, short[] indices, int indexOffset, int indexCount,
                                        Paint paint) {
                                    super.drawVertices(mode, vertexCount, verts, vertOffset, texs, texOffset,
                                            colors, colorOffset, indices, indexOffset, indexCount, paint); //To change body of overridden methods use File | Settings | File Templates.
                                }

                                @Override
                                public void drawPosText(char[] text, int index, int count, float[] pos,
                                        Paint paint) {
                                    super.drawPosText(text, index, count, pos, paint); //To change body of overridden methods use File | Settings | File Templates.
                                }

                                @Override
                                public void drawPosText(String text, float[] pos, Paint paint) {
                                    super.drawPosText(text, pos, paint); //To change body of overridden methods use File | Settings | File Templates.
                                }

                                @Override
                                public void drawTextOnPath(char[] text, int index, int count, Path path,
                                        float hOffset, float vOffset, Paint paint) {
                                    super.drawTextOnPath(text, index, count, path, hOffset, vOffset, paint); //To change body of overridden methods use File | Settings | File Templates.
                                }

                                @Override
                                public void drawTextOnPath(String text, Path path, float hOffset, float vOffset,
                                        Paint paint) {
                                    super.drawTextOnPath(text, path, hOffset, vOffset, paint); //To change body of overridden methods use File | Settings | File Templates.
                                }

                                public void drawTextRun(final CharSequence text, final int start, final int end,
                                        final int contextStart, final int contextEnd, final float x,
                                        final float y, final int dir, final Paint paint) {
                                    stuff.add(new JuickMessagesAdapter.CanvasPainter() {

                                        Paint paintClone = getPaintFromCache(paint);

                                        @Override
                                        public void paintOnCanvas(Canvas c, Paint workPaint) {
                                            try {
                                                drawTextRun.invoke(c, text, start, end, contextStart,
                                                        contextEnd, x, y, dir, paintClone);
                                            } catch (Throwable t) {
                                            }
                                        }
                                    });
                                }

                                @Override
                                public boolean getClipBounds(Rect bounds) {
                                    bounds.top = 0;
                                    bounds.bottom = 100000;
                                    bounds.left = 0;
                                    bounds.right = width;
                                    return true;
                                }
                            };

                            for (JuickMessage juickMessage : list) {
                                JuickMessagesAdapter.ParsedMessage pm = (JuickMessagesAdapter.ParsedMessage) juickMessage.parsedText;
                                if (pm != null && pm.textContent != null)
                                    tv.setText(pm.textContent);
                                stuff.clear();
                                tv.measure(View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY),
                                        View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
                                tv.draw(canvas);
                                if (stuff.size() > 0) {
                                    juickMessage.parsedUI = new JuickMessagesAdapter.RenderedText(
                                            outerViewWidth, tv.getMeasuredHeight(),
                                            new ArrayList<JuickMessagesAdapter.CanvasPainter>(stuff));
                                } else {
                                    juickMessage.parsedUI = null;
                                }
                            }
                        }
                        act.runOnUiThread(then);
                    }
                }
            }.start();
        }
    });
}

From source file:ir.besteveryeverapp.ui.Components.PasscodeView.java

private void checkFingerprint() {
    Activity parentActivity = (Activity) getContext();
    if (Build.VERSION.SDK_INT >= 23 && parentActivity != null && UserConfig.useFingerprint
            && !ApplicationLoader.mainInterfacePaused) {
        try {//from ww w .  ja  va 2s  .  c o  m
            if (fingerprintDialog != null && fingerprintDialog.isShowing()) {
                return;
            }
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
        try {
            FingerprintManagerCompat fingerprintManager = FingerprintManagerCompat
                    .from(ApplicationLoader.applicationContext);
            if (fingerprintManager.isHardwareDetected() && fingerprintManager.hasEnrolledFingerprints()) {
                RelativeLayout relativeLayout = new RelativeLayout(getContext());
                relativeLayout.setPadding(AndroidUtilities.dp(24), AndroidUtilities.dp(16),
                        AndroidUtilities.dp(24), AndroidUtilities.dp(8));

                TextView fingerprintTextView = new TextView(getContext());
                fingerprintTextView.setTypeface(FontManager.instance().getTypeface());
                fingerprintTextView.setTextColor(0xff939393);
                fingerprintTextView.setId(id_fingerprint_textview);
                fingerprintTextView.setTextAppearance(android.R.style.TextAppearance_Material_Subhead);
                fingerprintTextView
                        .setText(LocaleController.getString("FingerprintInfo", R.string.FingerprintInfo));
                relativeLayout.addView(fingerprintTextView);
                RelativeLayout.LayoutParams layoutParams = LayoutHelper
                        .createRelative(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT);
                layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
                layoutParams.addRule(RelativeLayout.ALIGN_PARENT_START);
                fingerprintTextView.setLayoutParams(layoutParams);

                fingerprintImageView = new ImageView(getContext());
                fingerprintImageView.setImageResource(R.drawable.ic_fp_40px);
                fingerprintImageView.setId(id_fingerprint_imageview);
                relativeLayout.addView(fingerprintImageView,
                        LayoutHelper.createRelative(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, 0, 20,
                                0, 0, RelativeLayout.ALIGN_PARENT_START, RelativeLayout.BELOW,
                                id_fingerprint_textview));

                fingerprintStatusTextView = new TextView(getContext());
                fingerprintStatusTextView.setTypeface(FontManager.instance().getTypeface());
                fingerprintStatusTextView.setGravity(Gravity.CENTER_VERTICAL);
                fingerprintStatusTextView
                        .setText(LocaleController.getString("FingerprintHelp", R.string.FingerprintHelp));
                fingerprintStatusTextView.setTextAppearance(android.R.style.TextAppearance_Material_Body1);
                fingerprintStatusTextView.setTextColor(0x42000000);
                relativeLayout.addView(fingerprintStatusTextView);
                layoutParams = LayoutHelper.createRelative(LayoutHelper.WRAP_CONTENT,
                        LayoutHelper.WRAP_CONTENT);
                layoutParams.setMarginStart(AndroidUtilities.dp(16));
                layoutParams.addRule(RelativeLayout.ALIGN_BOTTOM, id_fingerprint_imageview);
                layoutParams.addRule(RelativeLayout.ALIGN_TOP, id_fingerprint_imageview);
                layoutParams.addRule(RelativeLayout.END_OF, id_fingerprint_imageview);
                fingerprintStatusTextView.setLayoutParams(layoutParams);

                AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                builder.setView(relativeLayout);
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
                    @Override
                    public void onDismiss(DialogInterface dialog) {
                        if (cancellationSignal != null) {
                            selfCancelled = true;
                            cancellationSignal.cancel();
                            cancellationSignal = null;
                        }
                    }
                });
                if (fingerprintDialog != null) {
                    try {
                        if (fingerprintDialog.isShowing()) {
                            fingerprintDialog.dismiss();
                        }
                    } catch (Exception e) {
                        FileLog.e("tmessages", e);
                    }
                }
                fingerprintDialog = builder.show();

                cancellationSignal = new CancellationSignal();
                selfCancelled = false;
                fingerprintManager.authenticate(null, 0, cancellationSignal,
                        new FingerprintManagerCompat.AuthenticationCallback() {
                            @Override
                            public void onAuthenticationError(int errMsgId, CharSequence errString) {
                                if (!selfCancelled) {
                                    showFingerprintError(errString);
                                }
                            }

                            @Override
                            public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
                                showFingerprintError(helpString);
                            }

                            @Override
                            public void onAuthenticationFailed() {
                                showFingerprintError(LocaleController.getString("FingerprintNotRecognized",
                                        R.string.FingerprintNotRecognized));
                            }

                            @Override
                            public void onAuthenticationSucceeded(
                                    FingerprintManagerCompat.AuthenticationResult result) {
                                try {
                                    if (fingerprintDialog.isShowing()) {
                                        fingerprintDialog.dismiss();
                                    }
                                } catch (Exception e) {
                                    FileLog.e("tmessages", e);
                                }
                                fingerprintDialog = null;
                                processDone(true);
                            }
                        }, null);
            }
        } catch (Throwable e) {
            //ignore
        }
    }
}

From source file:com.initialxy.cordova.themeablebrowser.ThemeableBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url//from  w w  w . j a  v  a2  s .c o m
 * @param features
 * @return
 */
public String showWebPage(final String url, final Options features) {
    final CordovaWebView thatWebView = this.webView;

    // Create dialog in new thread
    Runnable runnable = new Runnable() {
        @SuppressLint("NewApi")
        public void run() {
            // Let's create the main dialog
            dialog = new ThemeableBrowserDialog(cordova.getActivity(), android.R.style.Theme_Black_NoTitleBar,
                    features.hardwareback);
            if (!features.disableAnimation) {
                dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            }
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setThemeableBrowser(getThemeableBrowser());

            // Main container layout
            ViewGroup main = null;

            if (features.fullscreen) {
                main = new FrameLayout(cordova.getActivity());
            } else {
                main = new LinearLayout(cordova.getActivity());
                ((LinearLayout) main).setOrientation(LinearLayout.VERTICAL);
            }

            // Toolbar layout
            Toolbar toolbarDef = features.toolbar;
            FrameLayout toolbar = new FrameLayout(cordova.getActivity());
            toolbar.setBackgroundColor(hexStringToColor(
                    toolbarDef != null && toolbarDef.color != null ? toolbarDef.color : "#ffffffff"));
            toolbar.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT,
                    dpToPixels(toolbarDef != null ? toolbarDef.height : TOOLBAR_DEF_HEIGHT)));

            if (toolbarDef != null && (toolbarDef.image != null || toolbarDef.wwwImage != null)) {
                try {
                    Drawable background = getImage(toolbarDef.image, toolbarDef.wwwImage,
                            toolbarDef.wwwImageDensity);
                    setBackground(toolbar, background);
                } catch (Resources.NotFoundException e) {
                    emitError(ERR_LOADFAIL,
                            String.format("Image for toolbar, %s, failed to load", toolbarDef.image));
                } catch (IOException ioe) {
                    emitError(ERR_LOADFAIL,
                            String.format("Image for toolbar, %s, failed to load", toolbarDef.wwwImage));
                }
            }

            // Left Button Container layout
            LinearLayout leftButtonContainer = new LinearLayout(cordova.getActivity());
            FrameLayout.LayoutParams leftButtonContainerParams = new FrameLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            leftButtonContainerParams.gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL;
            leftButtonContainer.setLayoutParams(leftButtonContainerParams);
            leftButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);

            // Right Button Container layout
            LinearLayout rightButtonContainer = new LinearLayout(cordova.getActivity());
            FrameLayout.LayoutParams rightButtonContainerParams = new FrameLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            rightButtonContainerParams.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL;
            rightButtonContainer.setLayoutParams(rightButtonContainerParams);
            rightButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);

            // Edit Text Box
            edittext = new EditText(cordova.getActivity());
            RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
            textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
            edittext.setLayoutParams(textLayoutParams);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
            edittext.setImeOptions(EditorInfo.IME_ACTION_GO);
            edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE
            edittext.setOnKeyListener(new View.OnKeyListener() {
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    // If the event is a key-down event on the "enter" button
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        navigate(edittext.getText().toString());
                        return true;
                    }
                    return false;
                }
            });

            // Back button
            final Button back = createButton(features.backButton, "back button", new View.OnClickListener() {
                public void onClick(View v) {
                    emitButtonEvent(features.backButton, inAppWebView.getUrl());

                    if (features.backButtonCanClose && !canGoBack()) {
                        closeDialog();
                    } else {
                        goBack();
                    }
                }
            });

            if (back != null) {
                back.setEnabled(features.backButtonCanClose);
            }

            // Forward button
            final Button forward = createButton(features.forwardButton, "forward button",
                    new View.OnClickListener() {
                        public void onClick(View v) {
                            emitButtonEvent(features.forwardButton, inAppWebView.getUrl());

                            goForward();
                        }
                    });

            if (forward != null) {
                forward.setEnabled(false);
            }

            // Close/Done button
            Button close = createButton(features.closeButton, "close button", new View.OnClickListener() {
                public void onClick(View v) {
                    emitButtonEvent(features.closeButton, inAppWebView.getUrl());
                    closeDialog();
                }
            });

            // Menu button
            Spinner menu = features.menu != null ? new MenuSpinner(cordova.getActivity()) : null;
            if (menu != null) {
                menu.setLayoutParams(
                        new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                menu.setContentDescription("menu button");
                setButtonImages(menu, features.menu, DISABLED_ALPHA);

                // We are not allowed to use onClickListener for Spinner, so we will use
                // onTouchListener as a fallback.
                menu.setOnTouchListener(new View.OnTouchListener() {
                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
                        if (event.getAction() == MotionEvent.ACTION_UP) {
                            emitButtonEvent(features.menu, inAppWebView.getUrl());
                        }
                        return false;
                    }
                });

                if (features.menu.items != null) {
                    HideSelectedAdapter<EventLabel> adapter = new HideSelectedAdapter<EventLabel>(
                            cordova.getActivity(), android.R.layout.simple_spinner_item, features.menu.items);
                    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                    menu.setAdapter(adapter);
                    menu.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                        @Override
                        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                            if (inAppWebView != null && i < features.menu.items.length) {
                                emitButtonEvent(features.menu.items[i], inAppWebView.getUrl(), i);
                            }
                        }

                        @Override
                        public void onNothingSelected(AdapterView<?> adapterView) {
                        }
                    });
                }
            }

            // Title
            final TextView title = features.title != null ? new TextView(cordova.getActivity()) : null;
            final TextView subtitle = features.title != null ? new TextView(cordova.getActivity()) : null;
            if (title != null) {
                FrameLayout.LayoutParams titleParams = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                        LayoutParams.FILL_PARENT);
                titleParams.gravity = Gravity.CENTER;
                title.setLayoutParams(titleParams);
                title.setSingleLine();
                title.setEllipsize(TextUtils.TruncateAt.END);
                title.setGravity(Gravity.CENTER | Gravity.TOP);
                title.setTextColor(
                        hexStringToColor(features.title.color != null ? features.title.color : "#000000ff"));
                title.setTypeface(title.getTypeface(), Typeface.BOLD);
                title.setTextSize(TypedValue.COMPLEX_UNIT_PT, 8);

                FrameLayout.LayoutParams subtitleParams = new FrameLayout.LayoutParams(
                        LayoutParams.MATCH_PARENT, LayoutParams.FILL_PARENT);
                titleParams.gravity = Gravity.CENTER;
                subtitle.setLayoutParams(subtitleParams);
                subtitle.setSingleLine();
                subtitle.setEllipsize(TextUtils.TruncateAt.END);
                subtitle.setGravity(Gravity.CENTER | Gravity.BOTTOM);
                subtitle.setTextColor(hexStringToColor(
                        features.title.subColor != null ? features.title.subColor : "#000000ff"));
                subtitle.setTextSize(TypedValue.COMPLEX_UNIT_PT, 6);
                subtitle.setVisibility(View.GONE);

                if (features.title.staticText != null) {
                    title.setGravity(Gravity.CENTER);
                    title.setText(features.title.staticText);
                } else {
                    subtitle.setVisibility(View.VISIBLE);
                }
            }

            // WebView
            inAppWebView = new WebView(cordova.getActivity());
            final ViewGroup.LayoutParams inAppWebViewParams = features.fullscreen
                    ? new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
                    : new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0);
            if (!features.fullscreen) {
                ((LinearLayout.LayoutParams) inAppWebViewParams).weight = 1;
            }
            inAppWebView.setLayoutParams(inAppWebViewParams);
            inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView));
            WebViewClient client = new ThemeableBrowserClient(thatWebView, new PageLoadListener() {

                @Override
                public void onPageStarted(String url) {
                    if (inAppWebView != null && title != null && features.title != null
                            && features.title.staticText == null && features.title.showPageTitle
                            && features.title.loadingText != null) {
                        title.setText(features.title.loadingText);
                        subtitle.setText(url);
                    }
                }

                @Override
                public void onPageFinished(String url, boolean canGoBack, boolean canGoForward) {
                    if (inAppWebView != null && title != null && features.title != null
                            && features.title.staticText == null && features.title.showPageTitle) {
                        title.setText(inAppWebView.getTitle());
                        subtitle.setText(inAppWebView.getUrl());
                    }

                    if (back != null) {
                        back.setEnabled(canGoBack || features.backButtonCanClose);
                    }

                    if (forward != null) {
                        forward.setEnabled(canGoForward);
                    }
                }
            });
            inAppWebView.setWebViewClient(client);
            WebSettings settings = inAppWebView.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(features.zoom);
            settings.setDisplayZoomControls(false);
            settings.setPluginState(android.webkit.WebSettings.PluginState.ON);

            //Toggle whether this is enabled or not!
            Bundle appSettings = cordova.getActivity().getIntent().getExtras();
            boolean enableDatabase = appSettings == null
                    || appSettings.getBoolean("ThemeableBrowserStorageEnabled", true);
            if (enableDatabase) {
                String databasePath = cordova.getActivity().getApplicationContext()
                        .getDir("themeableBrowserDB", Context.MODE_PRIVATE).getPath();
                settings.setDatabasePath(databasePath);
                settings.setDatabaseEnabled(true);
            }
            settings.setDomStorageEnabled(true);

            if (features.clearcache) {
                CookieManager.getInstance().removeAllCookie();
            } else if (features.clearsessioncache) {
                CookieManager.getInstance().removeSessionCookie();
            }

            inAppWebView.loadUrl(url);
            inAppWebView.getSettings().setLoadWithOverviewMode(true);
            inAppWebView.getSettings().setUseWideViewPort(true);
            inAppWebView.requestFocus();
            inAppWebView.requestFocusFromTouch();

            // Add buttons to either leftButtonsContainer or
            // rightButtonsContainer according to user's alignment
            // configuration.
            int leftContainerWidth = 0;
            int rightContainerWidth = 0;

            if (features.customButtons != null) {
                for (int i = 0; i < features.customButtons.length; i++) {
                    final BrowserButton buttonProps = features.customButtons[i];
                    final int index = i;
                    Button button = createButton(buttonProps, String.format("custom button at %d", i),
                            new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    if (inAppWebView != null) {
                                        emitButtonEvent(buttonProps, inAppWebView.getUrl(), index);
                                    }
                                }
                            });

                    if (ALIGN_RIGHT.equals(buttonProps.align)) {
                        rightButtonContainer.addView(button);
                        rightContainerWidth += button.getLayoutParams().width;
                    } else {
                        leftButtonContainer.addView(button, 0);
                        leftContainerWidth += button.getLayoutParams().width;
                    }
                }
            }

            // Back and forward buttons must be added with special ordering logic such
            // that back button is always on the left of forward button if both buttons
            // are on the same side.
            if (forward != null && features.forwardButton != null
                    && !ALIGN_RIGHT.equals(features.forwardButton.align)) {
                leftButtonContainer.addView(forward, 0);
                leftContainerWidth += forward.getLayoutParams().width;
            }

            if (back != null && features.backButton != null && ALIGN_RIGHT.equals(features.backButton.align)) {
                rightButtonContainer.addView(back);
                rightContainerWidth += back.getLayoutParams().width;
            }

            if (back != null && features.backButton != null && !ALIGN_RIGHT.equals(features.backButton.align)) {
                leftButtonContainer.addView(back, 0);
                leftContainerWidth += back.getLayoutParams().width;
            }

            if (forward != null && features.forwardButton != null
                    && ALIGN_RIGHT.equals(features.forwardButton.align)) {
                rightButtonContainer.addView(forward);
                rightContainerWidth += forward.getLayoutParams().width;
            }

            if (menu != null) {
                if (features.menu != null && ALIGN_RIGHT.equals(features.menu.align)) {
                    rightButtonContainer.addView(menu);
                    rightContainerWidth += menu.getLayoutParams().width;
                } else {
                    leftButtonContainer.addView(menu, 0);
                    leftContainerWidth += menu.getLayoutParams().width;
                }
            }

            if (close != null) {
                if (features.closeButton != null && ALIGN_RIGHT.equals(features.closeButton.align)) {
                    rightButtonContainer.addView(close);
                    rightContainerWidth += close.getLayoutParams().width;
                } else {
                    leftButtonContainer.addView(close, 0);
                    leftContainerWidth += close.getLayoutParams().width;
                }
            }

            // Add the views to our toolbar
            toolbar.addView(leftButtonContainer);
            // Don't show address bar.
            // toolbar.addView(edittext);
            toolbar.addView(rightButtonContainer);

            if (title != null) {
                int titleMargin = Math.max(leftContainerWidth, rightContainerWidth);

                FrameLayout.LayoutParams titleParams = (FrameLayout.LayoutParams) title.getLayoutParams();
                titleParams.setMargins(titleMargin, 8, titleMargin, 0);
                toolbar.addView(title);
            }

            if (subtitle != null) {
                int subtitleMargin = Math.max(leftContainerWidth, rightContainerWidth);

                FrameLayout.LayoutParams subtitleParams = (FrameLayout.LayoutParams) subtitle.getLayoutParams();
                subtitleParams.setMargins(subtitleMargin, 0, subtitleMargin, 8);
                toolbar.addView(subtitle);
            }

            if (features.fullscreen) {
                // If full screen mode, we have to add inAppWebView before adding toolbar.
                main.addView(inAppWebView);
            }

            // Don't add the toolbar if its been disabled
            if (features.location) {
                // Add our toolbar to our main view/layout
                main.addView(toolbar);
            }

            if (!features.fullscreen) {
                // If not full screen, we add inAppWebView after adding toolbar.
                main.addView(inAppWebView);
            }

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.height = WindowManager.LayoutParams.MATCH_PARENT;

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
            // the goal of openhidden is to load the url and not display it
            // Show() needs to be called to cause the URL to be loaded
            if (features.hidden) {
                dialog.hide();
            }
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}