Example usage for android.widget FrameLayout setTag

List of usage examples for android.widget FrameLayout setTag

Introduction

In this page you can find the example usage for android.widget FrameLayout setTag.

Prototype

public void setTag(final Object tag) 

Source Link

Document

Sets the tag associated with this view.

Usage

From source file:com.gome.haoyuangong.views.MyViewPageIndicator.java

private void addTab(int index, CharSequence text, int iconResId) {
    final TabView tabView = new TabView(getContext());
    tabView.mIndex = index;/*from   w  ww.  j  av a 2 s .c  o m*/
    tabView.setTag("tavView");
    tabView.setId(index);
    //      tabView.setFocusable(true);
    //      tabView.setOnClickListener(mTabClickListener);
    tabView.setText(text);
    //tabView.setPadding(pointSize, 0, pointSize, 0);
    tabView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    tabView.setMaxLines(1);
    tabView.setGravity(Gravity.CENTER);
    XmlPullParser xrp = getResources().getXml(R.drawable.tab_button);
    try {
        ColorStateList csl = ColorStateList.createFromXml(getResources(), xrp);
        tabView.setTextColor(csl);
    } catch (Exception e) {

    }

    if (iconResId != 0) {
        //tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0, 0);
    }

    FrameLayout.LayoutParams tabTvL = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    tabView.setLayoutParams(tabTvL);

    //measureView(tabView);

    LinearLayout layoutWraper1 = new LinearLayout(getContext());
    LinearLayout.LayoutParams lp1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT, 1);
    layoutWraper1.setLayoutParams(lp1);
    layoutWraper1.setGravity(Gravity.CENTER);
    layoutWraper1.setFocusable(true);
    layoutWraper1.setOnClickListener(mTabClickListener);
    layoutWraper1.setPadding(0, 0, 0, 0);
    layoutWraper1.setBackgroundResource(R.drawable.tab_btn_red);

    FrameLayout frameLayout = new FrameLayout(getContext());
    frameLayout.setTag("framelayout");
    //      FrameLayout.LayoutParams fl2 = new FrameLayout.LayoutParams(tabView.getMeasuredWidth() + padding, tabView.getMeasuredHeight()+ (int)(padding * 1.5));
    FrameLayout.LayoutParams fl2 = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    //      frameLayout.setPadding(padding, padding, padding, padding);
    frameLayout.setLayoutParams(fl2);
    //      frameLayout.addView(tabView);

    View hasNew = new View(getContext());
    FrameLayout.LayoutParams hasNewL = new FrameLayout.LayoutParams(pointSize, pointSize);
    hasNew.setLayoutParams(hasNewL);
    hasNewL.gravity = Gravity.TOP | Gravity.RIGHT;
    hasNew.setBackgroundResource(R.drawable.shape_circle);

    FrameLayout tabTvframe = new FrameLayout(getContext());
    FrameLayout.LayoutParams tabTvframeL = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    tabTvframeL.gravity = Gravity.CENTER;
    tabTvframe.setLayoutParams(tabTvframeL);
    tabTvframe.addView(tabView);
    tabTvframe.addView(hasNew);
    hasNew.setVisibility(View.GONE);

    frameLayout.addView(tabTvframe);

    layoutWraper1.addView(frameLayout);

    tabView.setTagView(hasNew);

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

From source file:com.gudong.appkit.ui.fragment.ColorChooseDialog.java

private View getColorItemView(final Context context, int position, boolean isSelect) {
    int color = mColors[position];
    int widthImageCheckView = Utils.convertDensityPix(context, 24);
    int widthColorView = Utils.convertDensityPix(context, 56);
    int widthMargin = Utils.convertDensityPix(context, 4);

    ImageView imageView = new ImageView(context);
    imageView.setImageResource(R.drawable.ic_check);

    FrameLayout.LayoutParams ivParams = new FrameLayout.LayoutParams(widthImageCheckView, widthImageCheckView);
    ivParams.gravity = Gravity.CENTER;//  w  w  w .java2  s . c  o m
    imageView.setLayoutParams(ivParams);
    imageView.setVisibility(isSelect ? View.VISIBLE : View.INVISIBLE);

    FrameLayout frameLayout = new FrameLayout(context);
    GridLayout.LayoutParams params = new GridLayout.LayoutParams(
            new FrameLayout.LayoutParams(widthColorView, widthColorView));
    params.setGravity(Gravity.CENTER);
    params.setMargins(widthMargin, widthMargin, widthMargin, widthMargin);
    frameLayout.setLayoutParams(params);

    setBackgroundSelector(frameLayout, color);

    frameLayout.addView(imageView);
    frameLayout.setOnClickListener(this);
    frameLayout.setTag(position);
    return frameLayout;
}

From source file:com.nttec.everychan.http.recaptcha.Recaptcha2fallback.java

@Override
public void handle(final Activity activity, final CancellableTask task, final Callback callback) {
    try {//from w w w.  j  a  va  2 s .  com
        final HttpClient httpClient = ((HttpChanModule) MainApplication.getInstance().getChanModule(chanName))
                .getHttpClient();
        final String usingURL = scheme + RECAPTCHA_FALLBACK_URL + publicKey
                + (sToken != null && sToken.length() > 0 ? ("&stoken=" + sToken) : "");
        String refererURL = baseUrl != null && baseUrl.length() > 0 ? baseUrl : usingURL;
        Header[] customHeaders = new Header[] { new BasicHeader(HttpHeaders.REFERER, refererURL) };
        String htmlChallenge;
        if (lastChallenge != null && lastChallenge.getLeft().equals(usingURL)) {
            htmlChallenge = lastChallenge.getRight();
        } else {
            htmlChallenge = HttpStreamer.getInstance().getStringFromUrl(usingURL,
                    HttpRequestModel.builder().setGET().setCustomHeaders(customHeaders).build(), httpClient,
                    null, task, false);
        }
        lastChallenge = null;

        Matcher challengeMatcher = Pattern.compile("name=\"c\" value=\"([\\w-]+)").matcher(htmlChallenge);
        if (challengeMatcher.find()) {
            final String challenge = challengeMatcher.group(1);
            HttpResponseModel responseModel = HttpStreamer.getInstance().getFromUrl(
                    scheme + RECAPTCHA_IMAGE_URL + challenge + "&k=" + publicKey,
                    HttpRequestModel.builder().setGET().setCustomHeaders(customHeaders).build(), httpClient,
                    null, task);
            try {
                InputStream imageStream = responseModel.stream;
                final Bitmap challengeBitmap = BitmapFactory.decodeStream(imageStream);

                final String message;
                Matcher messageMatcher = Pattern.compile("imageselect-message(?:.*?)>(.*?)</div>")
                        .matcher(htmlChallenge);
                if (messageMatcher.find())
                    message = RegexUtils.removeHtmlTags(messageMatcher.group(1));
                else
                    message = null;

                final Bitmap candidateBitmap;
                Matcher candidateMatcher = Pattern
                        .compile("fbc-imageselect-candidates(?:.*?)src=\"data:image/(?:.*?);base64,([^\"]*)\"")
                        .matcher(htmlChallenge);
                if (candidateMatcher.find()) {
                    Bitmap bmp = null;
                    try {
                        byte[] imgData = Base64.decode(candidateMatcher.group(1), Base64.DEFAULT);
                        bmp = BitmapFactory.decodeByteArray(imgData, 0, imgData.length);
                    } catch (Exception e) {
                    }
                    candidateBitmap = bmp;
                } else
                    candidateBitmap = null;

                activity.runOnUiThread(new Runnable() {
                    final int maxX = 3;
                    final int maxY = 3;
                    final boolean[] isSelected = new boolean[maxX * maxY];

                    @SuppressLint("InlinedApi")
                    @Override
                    public void run() {
                        LinearLayout rootLayout = new LinearLayout(activity);
                        rootLayout.setOrientation(LinearLayout.VERTICAL);

                        if (candidateBitmap != null) {
                            ImageView candidateView = new ImageView(activity);
                            candidateView.setImageBitmap(candidateBitmap);
                            int picSize = (int) (activity.getResources().getDisplayMetrics().density * 50
                                    + 0.5f);
                            candidateView.setLayoutParams(new LinearLayout.LayoutParams(picSize, picSize));
                            candidateView.setScaleType(ImageView.ScaleType.FIT_XY);
                            rootLayout.addView(candidateView);
                        }

                        if (message != null) {
                            TextView textView = new TextView(activity);
                            textView.setText(message);
                            CompatibilityUtils.setTextAppearance(textView, android.R.style.TextAppearance);
                            textView.setLayoutParams(
                                    new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                                            LinearLayout.LayoutParams.WRAP_CONTENT));
                            rootLayout.addView(textView);
                        }

                        FrameLayout frame = new FrameLayout(activity);
                        frame.setLayoutParams(
                                new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                                        LinearLayout.LayoutParams.WRAP_CONTENT));

                        final ImageView imageView = new ImageView(activity);
                        imageView.setLayoutParams(new FrameLayout.LayoutParams(
                                FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
                        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
                        imageView.setImageBitmap(challengeBitmap);
                        frame.addView(imageView);

                        final LinearLayout selector = new LinearLayout(activity);
                        selector.setLayoutParams(new FrameLayout.LayoutParams(
                                FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
                        AppearanceUtils.callWhenLoaded(imageView, new Runnable() {
                            @Override
                            public void run() {
                                selector.setLayoutParams(new FrameLayout.LayoutParams(imageView.getWidth(),
                                        imageView.getHeight()));
                            }
                        });
                        selector.setOrientation(LinearLayout.VERTICAL);
                        selector.setWeightSum(maxY);
                        for (int y = 0; y < maxY; ++y) {
                            LinearLayout subSelector = new LinearLayout(activity);
                            subSelector.setLayoutParams(new LinearLayout.LayoutParams(
                                    LinearLayout.LayoutParams.MATCH_PARENT, 0, 1f));
                            subSelector.setOrientation(LinearLayout.HORIZONTAL);
                            subSelector.setWeightSum(maxX);
                            for (int x = 0; x < maxX; ++x) {
                                FrameLayout switcher = new FrameLayout(activity);
                                switcher.setLayoutParams(new LinearLayout.LayoutParams(0,
                                        LinearLayout.LayoutParams.MATCH_PARENT, 1f));
                                switcher.setTag(new int[] { x, y });
                                switcher.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        int[] coord = (int[]) v.getTag();
                                        int index = coord[1] * maxX + coord[0];
                                        isSelected[index] = !isSelected[index];
                                        v.setBackgroundColor(isSelected[index] ? Color.argb(128, 0, 255, 0)
                                                : Color.TRANSPARENT);
                                    }
                                });
                                subSelector.addView(switcher);
                            }
                            selector.addView(subSelector);
                        }

                        frame.addView(selector);
                        rootLayout.addView(frame);

                        Button checkButton = new Button(activity);
                        checkButton.setLayoutParams(
                                new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                                        LinearLayout.LayoutParams.WRAP_CONTENT));
                        checkButton.setText(android.R.string.ok);
                        rootLayout.addView(checkButton);

                        ScrollView dlgView = new ScrollView(activity);
                        dlgView.addView(rootLayout);

                        final Dialog dialog = new Dialog(activity);
                        dialog.setTitle("Recaptcha");
                        dialog.setContentView(dlgView);
                        dialog.setCanceledOnTouchOutside(false);
                        dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                            @Override
                            public void onCancel(DialogInterface dialog) {
                                if (!task.isCancelled()) {
                                    callback.onError("Cancelled");
                                }
                            }
                        });
                        dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,
                                ViewGroup.LayoutParams.WRAP_CONTENT);
                        dialog.show();

                        checkButton.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                dialog.dismiss();
                                if (task.isCancelled())
                                    return;
                                Async.runAsync(new Runnable() {
                                    @Override
                                    public void run() {
                                        try {
                                            List<NameValuePair> pairs = new ArrayList<NameValuePair>();
                                            pairs.add(new BasicNameValuePair("c", challenge));
                                            for (int i = 0; i < isSelected.length; ++i)
                                                if (isSelected[i])
                                                    pairs.add(new BasicNameValuePair("response",
                                                            Integer.toString(i)));

                                            HttpRequestModel request = HttpRequestModel.builder()
                                                    .setPOST(new UrlEncodedFormEntity(pairs, "UTF-8"))
                                                    .setCustomHeaders(new Header[] {
                                                            new BasicHeader(HttpHeaders.REFERER, usingURL) })
                                                    .build();
                                            String response = HttpStreamer.getInstance().getStringFromUrl(
                                                    usingURL, request, httpClient, null, task, false);
                                            String hash = "";
                                            Matcher matcher = Pattern.compile(
                                                    "fbc-verification-token(?:.*?)<textarea[^>]*>([^<]*)<",
                                                    Pattern.DOTALL).matcher(response);
                                            if (matcher.find())
                                                hash = matcher.group(1);

                                            if (hash.length() > 0) {
                                                Recaptcha2solved.push(publicKey, hash);
                                                activity.runOnUiThread(new Runnable() {
                                                    @Override
                                                    public void run() {
                                                        callback.onSuccess();
                                                    }
                                                });
                                            } else {
                                                lastChallenge = Pair.of(usingURL, response);
                                                throw new RecaptchaException(
                                                        "incorrect answer (hash is empty)");
                                            }
                                        } catch (final Exception e) {
                                            Logger.e(TAG, e);
                                            if (task.isCancelled())
                                                return;
                                            handle(activity, task, callback);
                                        }
                                    }
                                });
                            }
                        });
                    }
                });
            } finally {
                responseModel.release();
            }
        } else
            throw new Exception("can't parse recaptcha challenge answer");
    } catch (final Exception e) {
        Logger.e(TAG, e);
        if (!task.isCancelled()) {
            activity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    callback.onError(e.getMessage() != null ? e.getMessage() : e.toString());
                }
            });
        }
    }
}

From source file:com.ndn.menurandom.ImageDownloader.java

private void makeFrameLayout(ImageView imageView) {
    boolean isExist = false;
    ViewGroup vg = (ViewGroup) imageView.getParent();
    if (vg instanceof FrameLayout) {
        FrameLayout frameLayout = (FrameLayout) vg;
        String tag = (String) frameLayout.getTag();
        if (tag != null && tag.equals("fl_imagedownloader")) {
            isExist = true;//ww  w . j a  v  a2s.  c  o m
        }
    }

    if (!isExist) {
        int childCount = vg.getChildCount();
        int index = 0;
        while (index < childCount) {
            if (imageView == vg.getChildAt(index)) {
                break;
            }
            index++;
        }
        vg.removeViewAt(index);

        FrameLayout frameLayout = new FrameLayout(vg.getContext().getApplicationContext());
        frameLayout.setTag("fl_imagedownloader");
        ViewGroup.LayoutParams lpImageView = (ViewGroup.LayoutParams) imageView.getLayoutParams();
        frameLayout.setLayoutParams(lpImageView);
        imageView.setLayoutParams(new LayoutParams(lpImageView.width, lpImageView.height));
        frameLayout.setPadding(imageView.getPaddingLeft(), imageView.getPaddingTop(),
                imageView.getPaddingRight(), imageView.getPaddingBottom());
        imageView.setPadding(0, 0, 0, 0);
        frameLayout.addView(imageView);
        vg.addView(frameLayout, index);

        ProgressBar progressBar = new ProgressBar(frameLayout.getContext());
        progressBar.setTag("pb_imagedownloader");
        int leftRightPadding = (imageView.getLayoutParams().width - 50) / 2;
        int topBottomPadding = (imageView.getLayoutParams().height - 50) / 2;
        progressBar.setPadding(leftRightPadding, topBottomPadding, leftRightPadding, topBottomPadding);
        frameLayout.addView(progressBar);

    }
}

From source file:com.putaotown.views.PagerSlidingTabStrip.java

private void addIconTab(final int position, int resId) {
    boolean isMessage = false; //??
    if (resId == R.drawable.iconfont_message || resId == R.drawable.iconfont_message_press)
        isMessage = true;//  w ww.jav  a2  s  .co  m

    ImageButton tab = new ImageButton(getContext());
    //      LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1);
    LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
            (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabWidth,
                    getResources().getDisplayMetrics()),
            (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabWidth,
                    getResources().getDisplayMetrics()));
    int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
            getResources().getDisplayMetrics());

    if (isMessage) {
        FrameLayout.LayoutParams paramx = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
                (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabWidth,
                        getResources().getDisplayMetrics()));
        FrameLayout flayout = new FrameLayout(this.getContext());
        param.gravity = Gravity.RIGHT;
        flayout.setLayoutParams(param);
        flayout.setPadding(padding, padding, padding, padding);
        View view = inflate(this.getContext(), R.layout.actionbar_mess_view, null);
        this.messRedPos = view.findViewById(R.id.actionbar_mess_redpos);
        this.messImage = (ImageView) view.findViewById(R.id.actionbar_mess_icon);
        flayout.addView(view);
        flayout.setTag("mess"); //??
        addTab(position, flayout);
    } else {
        tab.setLayoutParams(param);
        tab.setPadding(padding, padding, padding, padding);
        tab.setImageResource(resId);
        tab.setScaleType(ScaleType.CENTER_INSIDE);
        tab.setAdjustViewBounds(true);
        addTab(position, tab);
    }

}

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

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

    setWillNotDraw(false);//from  w ww  .  jav a2  s . c o m
    setVisibility(GONE);

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

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

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

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

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

        }

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

        }

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

        public void onDestroyActionMode(ActionMode mode) {
        }

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

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

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

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

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

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

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

From source file:com.jrummyapps.android.colorpicker.ColorPickerDialog.java

private void setupTransparency() {
    int progress = 255 - Color.alpha(color);
    transparencySeekBar.setMax(255);/*from  ww w. j a v  a 2s .com*/
    transparencySeekBar.setProgress(progress);
    int percentage = (int) ((double) progress * 100 / 255);
    transparencyPercText.setText(String.format(Locale.ENGLISH, "%d%%", percentage));
    transparencySeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            int percentage = (int) ((double) progress * 100 / 255);
            transparencyPercText.setText(String.format(Locale.ENGLISH, "%d%%", percentage));
            int alpha = 255 - progress;
            // update items in GridView:
            for (int i = 0; i < adapter.colors.length; i++) {
                int color = adapter.colors[i];
                int red = Color.red(color);
                int green = Color.green(color);
                int blue = Color.blue(color);
                adapter.colors[i] = Color.argb(alpha, red, green, blue);
            }
            adapter.notifyDataSetChanged();
            // update shades:
            for (int i = 0; i < shadesLayout.getChildCount(); i++) {
                FrameLayout layout = (FrameLayout) shadesLayout.getChildAt(i);
                ColorPanelView cpv = layout.findViewById(R.id.cpv_color_panel_view);
                ImageView iv = layout.findViewById(R.id.cpv_color_image_view);
                if (layout.getTag() == null) {
                    // save the original border color
                    layout.setTag(cpv.getBorderColor());
                }
                int color = cpv.getColor();
                color = Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color));
                if (alpha <= ALPHA_THRESHOLD) {
                    cpv.setBorderColor(color | 0xFF000000);
                } else {
                    cpv.setBorderColor((int) layout.getTag());
                }
                if (cpv.getTag() != null && (Boolean) cpv.getTag()) {
                    // The alpha changed on the selected shaded color. Update the checkmark color filter.
                    if (alpha <= ALPHA_THRESHOLD) {
                        iv.setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_IN);
                    } else {
                        if (ColorUtils.calculateLuminance(color) >= 0.65) {
                            iv.setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_IN);
                        } else {
                            iv.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN);
                        }
                    }
                }
                cpv.setColor(color);
            }
            // update color:
            int red = Color.red(color);
            int green = Color.green(color);
            int blue = Color.blue(color);
            color = Color.argb(alpha, red, green, blue);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });
}

From source file:com.jaredrummler.android.colorpicker.ColorPickerDialog.java

private void setupTransparency() {
    int progress = 255 - Color.alpha(color);
    transparencySeekBar.setMax(255);/*  ww w . jav  a2s.c o m*/
    transparencySeekBar.setProgress(progress);
    int percentage = (int) ((double) progress * 100 / 255);
    transparencyPercText.setText(String.format(Locale.ENGLISH, "%d%%", percentage));
    transparencySeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            int percentage = (int) ((double) progress * 100 / 255);
            transparencyPercText.setText(String.format(Locale.ENGLISH, "%d%%", percentage));
            int alpha = 255 - progress;
            // update items in GridView:
            for (int i = 0; i < adapter.colors.length; i++) {
                int color = adapter.colors[i];
                int red = Color.red(color);
                int green = Color.green(color);
                int blue = Color.blue(color);
                adapter.colors[i] = Color.argb(alpha, red, green, blue);
            }
            adapter.notifyDataSetChanged();
            // update shades:
            for (int i = 0; i < shadesLayout.getChildCount(); i++) {
                FrameLayout layout = (FrameLayout) shadesLayout.getChildAt(i);
                ColorPanelView cpv = (ColorPanelView) layout.findViewById(R.id.cpv_color_panel_view);
                ImageView iv = (ImageView) layout.findViewById(R.id.cpv_color_image_view);
                if (layout.getTag() == null) {
                    // save the original border color
                    layout.setTag(cpv.getBorderColor());
                }
                int color = cpv.getColor();
                color = Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color));
                if (alpha <= ALPHA_THRESHOLD) {
                    cpv.setBorderColor(color | 0xFF000000);
                } else {
                    cpv.setBorderColor((int) layout.getTag());
                }
                if (cpv.getTag() != null && (Boolean) cpv.getTag()) {
                    // The alpha changed on the selected shaded color. Update the checkmark color filter.
                    if (alpha <= ALPHA_THRESHOLD) {
                        iv.setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_IN);
                    } else {
                        if (ColorUtils.calculateLuminance(color) >= 0.65) {
                            iv.setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_IN);
                        } else {
                            iv.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN);
                        }
                    }
                }
                cpv.setColor(color);
            }
            // update color:
            int red = Color.red(color);
            int green = Color.green(color);
            int blue = Color.blue(color);
            color = Color.argb(alpha, red, green, blue);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });
}

From source file:com.waz.zclient.ui.cursor.CursorToolbar.java

private void createItems() {
    LayoutInflater inflater = LayoutInflater.from(getContext());

    int diameter = getResources().getDimensionPixelSize(R.dimen.cursor__menu_button__diameter);
    int rightMargin;

    /*//from   w ww  .  j av  a 2s .  c o m
    As long as 4 mainItems are shown in the toolbar, they are spread out equally in phone
     */
    rightMargin = CursorUtils.getMarginBetweenCursorButtons(getContext());

    CursorIconButton cursorIconButton;

    for (int i = 0; i < cursorItems.size(); i++) {
        final CursorMenuItem item = cursorItems.get(i);
        final FrameLayout buttonContainer = new FrameLayout(getContext());
        buttonContainer.setId(item.resId);

        cursorIconButton = (CursorIconButton) inflater.inflate(R.layout.cursor__item, this, false);
        cursorIconButton.setText(item.glyphResId);
        cursorIconButton
                .setPressedBackgroundColor(ContextCompat.getColor(getContext(), R.color.light_graphite));

        switch (item) {
        case CAMERA:
            cursorIconButtonCamera = cursorIconButton;
            break;
        case AUDIO_MESSAGE:
            cursorIconButtonAudio = cursorIconButton;
            break;
        }

        if (item == CursorMenuItem.DUMMY) {
            cursorIconButton.initTextColor(ContextCompat.getColor(getContext(), R.color.transparent));
            cursorIconButton
                    .setPressedBackgroundColor(ContextCompat.getColor(getContext(), R.color.transparent));
            cursorIconButton.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.transparent));
        }

        buttonContainer.setTag(item);

        buttonContainer.setLongClickable(true);

        buttonContainer.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                CursorMenuItem item = (CursorMenuItem) view.getTag();
                touchedButtonContainer = buttonContainer;
                if (callback != null && item == CursorMenuItem.AUDIO_MESSAGE) {
                    callback.onMotionEvent(item, motionEvent);
                }
                detector.onTouchEvent(motionEvent);
                return false;
            }
        });

        FrameLayout.LayoutParams paramsButton = new FrameLayout.LayoutParams(diameter, diameter);
        paramsButton.gravity = Gravity.CENTER;
        buttonContainer.addView(cursorIconButton, paramsButton);

        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(buttonWidth,
                ViewGroup.LayoutParams.MATCH_PARENT);
        if (i < cursorItems.size() - 1) {
            params.rightMargin = rightMargin;
        }
        addView(buttonContainer, params);
    }
}