Example usage for android.widget ImageView setScaleType

List of usage examples for android.widget ImageView setScaleType

Introduction

In this page you can find the example usage for android.widget ImageView setScaleType.

Prototype

public void setScaleType(ScaleType scaleType) 

Source Link

Document

Controls how the image should be resized or moved to match the size of this ImageView.

Usage

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

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

    setWillNotDraw(false);// ww w  .jav  a2s .com
    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.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.setTypeface(FontManager.instance().getTypeface());
    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);

    passwordEditText2 = new AnimatingTextView(context);
    passwordFrameLayout.addView(passwordEditText2);
    layoutParams = (FrameLayout.LayoutParams) passwordEditText2.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;
    passwordEditText2.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.setTypeface(FontManager.instance().getTypeface());
        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.setTypeface(FontManager.instance().getTypeface());
        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("");
                    passwordEditText2.eraseAllCharacters(true);
                    return true;
                }
            });
        }
        frameLayout.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                int tag = (Integer) v.getTag();
                switch (tag) {
                case 0:
                    passwordEditText2.appendCharacter("0");
                    break;
                case 1:
                    passwordEditText2.appendCharacter("1");
                    break;
                case 2:
                    passwordEditText2.appendCharacter("2");
                    break;
                case 3:
                    passwordEditText2.appendCharacter("3");
                    break;
                case 4:
                    passwordEditText2.appendCharacter("4");
                    break;
                case 5:
                    passwordEditText2.appendCharacter("5");
                    break;
                case 6:
                    passwordEditText2.appendCharacter("6");
                    break;
                case 7:
                    passwordEditText2.appendCharacter("7");
                    break;
                case 8:
                    passwordEditText2.appendCharacter("8");
                    break;
                case 9:
                    passwordEditText2.appendCharacter("9");
                    break;
                case 10:
                    passwordEditText2.eraseLastCharacter();
                    break;
                }
                if (passwordEditText2.lenght() == 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:org.xingjitong.DialerFragment.java

@SuppressWarnings("deprecation")
@Override//from   w  ww  .j a  v a2s .  co  m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    instance = this;
    handler = new Handler();
    MSG.getInstance().setFragment(this);
    if (view == null) {
        view = inflater.inflate(R.layout.dialer, container, false);

        list_ads = new ArrayList<View>();
        indicator = (CirclePageIndicator) view.findViewById(R.id.indicator);
        // ad view
        viewpager_dialer_ads = (AutoScrollViewPager) view.findViewById(R.id.viewpager_dialer_ads);
        final BitmapUtils utils = new BitmapUtils(getActivity(), "/sdcard/Download");
        utils.configDefaultLoadFailedImage(R.drawable.default_ad);
        // image ads config
        final ImageView view1 = new ImageView(getActivity());
        final ImageView view2 = new ImageView(getActivity());
        final ImageView view3 = new ImageView(getActivity());
        //         view1.setImageResource(R.drawable.ad1);
        //         view2.setImageResource(R.drawable.ad2);
        //         view3.setImageResource(R.drawable.ad3);
        //         final ImageView view4 = new ImageView(getActivity());
        //         final ImageView view5 = new ImageView(getActivity());

        view1.setScaleType(ScaleType.FIT_XY);
        view2.setScaleType(ScaleType.FIT_XY);
        view3.setScaleType(ScaleType.FIT_XY);
        //         view4.setScaleType(ScaleType.FIT_XY);
        //         view5.setScaleType(ScaleType.FIT_XY);

        android.view.ViewGroup.LayoutParams params = new LayoutParams(
                android.view.ViewGroup.LayoutParams.MATCH_PARENT, 200);

        view1.setLayoutParams(params);
        view2.setLayoutParams(params);
        view3.setLayoutParams(params);
        //         view4.setLayoutParams(params);
        //         view5.setLayoutParams(params);

        SharedPreferences prefs = getActivity().getSharedPreferences("ads", Context.MODE_PRIVATE);
        String adsString = prefs.getString("ads", null);
        if (adsString != null && adsString.length() > 0) {
            Map<String, Object> map = JsonToMapAds.getAdsList(adsString);
            if (map != null) {
                @SuppressWarnings("unchecked")
                List<Map<String, Object>> list_pau = (List<Map<String, Object>>) map.get("list");
                if (list_pau != null && list_pau.size() > 0) {
                    list2 = list_pau;
                    handler2.post(new Runnable() {

                        @Override
                        public void run() {
                            if (list2 != null && list2.size() >= 3) {
                                utils.display(view1, (String) list2.get(0).get("content"));
                                utils.display(view2, (String) list2.get(1).get("content"));
                                utils.display(view3, (String) list2.get(2).get("content"));
                                //                           view1.setOnClickListener(new MyClickListener(
                                //                                 getActivity(), (String) list2
                                //                                       .get(0).get("url")));
                                //                           view2.setOnClickListener(new MyClickListener(
                                //                                 getActivity(), (String) list2
                                //                                       .get(1).get("url")));
                                //                           view3.setOnClickListener(new MyClickListener(
                                //                                 getActivity(), (String) list2
                                //                                       .get(2).get("url")));
                            } else {
                                view1.setImageResource(R.drawable.default_ad);
                                view2.setImageResource(R.drawable.default_ad);
                                view3.setImageResource(R.drawable.default_ad);
                            }

                        }
                    });
                }
            }

        } else {
            view1.setImageResource(R.drawable.default_ad);
            view2.setImageResource(R.drawable.default_ad);
            view3.setImageResource(R.drawable.default_ad);
        }

        list_ads.add(view1);
        list_ads.add(view2);
        list_ads.add(view3);
        //         list_ads.add(view4);
        //         list_ads.add(view5);
        viewpager_dialer_ads.setAdapter(new MyAdPagerAdapter(list_ads));
        viewpager_dialer_ads.setOffscreenPageLimit(5);

        viewpager_dialer_ads.startAutoScroll();
        viewpager_dialer_ads.setInterval(5000);
        viewpager_dialer_ads.setSlideBorderMode(2);
        indicator.setViewPager(viewpager_dialer_ads);
        mAddress = (AddressText) view.findViewById(R.id.Adress);
        mAddress.setDialerFragment(this);
        mAddress.requestFocus();
        mAddress.setVisibility(View.VISIBLE);
        // yyppdial add
        dialhint = (TextView) view.findViewById(R.id.dialhint_tv);
        if (mAddress.length() == 0) {
            android.util.Log.v("yyyppdebug", "yyppdialaddress 000");
            mAddress.setVisibility(View.GONE);
            dialhint.setVisibility(View.VISIBLE);
        } else {
            android.util.Log.v("yyyppdebug", "yyppdialaddress 111");
            mAddress.requestFocus();
            mAddress.setVisibility(View.VISIBLE);
            dialhint.setVisibility(View.GONE);
        }
        // yyppdial end
        // yypp add
        Calendar c = Calendar.getInstance();
        // int month = c.get(Calendar.MONTH);
        // int date = c.get(Calendar.DATE);
        int week = c.get(Calendar.DAY_OF_WEEK);
        if (nongli == null)
            nongli = new Lunar(c);
        // nonglistr=nongli.toString();
        gonglistr = nongli.togongliString() + " ";
        nonglistr = "" + nongli.tonongliString() + " ";

        android.util.Log.v("yyppdebug", "yyppnotice dial 000");

        msg = MSG.getnewInstance(); // yyppnotice test

        android.util.Log.v("yyppdebug", "yyppnotice dialerfragment size:" + msg.msgs.size() + "");
        int drawid[] = {
                /*
                 * R.drawable.dial_notice0_img, R.drawable.dial_notice1_img,
                 * R.drawable.dial_notice2_img, R.drawable.dial_notice3_img,
                 * R.drawable.dial_notice4_img, R.drawable.dial_notice5_img,
                 * R.drawable.dial_notice6_img
                 */
        };
        // android.util.Log.v("yyppdebug", "yypp week="+week+"");
        /*
         * RelativeLayout rLayout = (RelativeLayout)
         * view.findViewById(R.id.dialer_notice_bg); Resources res =
         * getResources(); //resource handle Drawable drawable =
         * res.getDrawable(drawid[(week-1)%7]); //new Image that was added
         * to the res folder rLayout.setBackgroundDrawable(drawable);
         */

        // yypp end

        share = PreferenceManager.getDefaultSharedPreferences(getActivity());
        Bundle bundle = getArguments();
        if (bundle != null && mAddress != null) {
            int lBegin = mAddress.getSelectionStart();

            if (lBegin == -1) {
                lBegin = mAddress.length();
            }
            phone = bundle.getString("phone");
        }
        EraseButton erase = (EraseButton) view.findViewById(R.id.Erase);
        erase.setAddressWidget(mAddress);
        mCall = (CallButton) view.findViewById(R.id.Call);
        mCall.setAddressWidget(mAddress);
        if (LinphoneActivity.isInstanciated() && LinphoneManager.getLc().getCallsNb() > 0) {
            if (isCallTransferOngoing) {
                mCall.setImageResource(R.drawable.transfer_call);
            } else {
                mCall.setImageResource(R.drawable.add_call);
            }
        } else {
            mCall.setImageResource(R.drawable.call);
        }

        AddressAware numpad = (AddressAware) view.findViewById(R.id.Dialer);
        if (numpad != null) {
            numpad.setAddressWidget(mAddress);
        }

        addContactListener = new OnClickListener() {
            @Override
            public void onClick(View v) {
                //add person to contacts 
                mylistener.onClick(mAddress.getText().toString());
                LinphoneActivity.instance().displayContactsForEdition(mAddress.getText().toString());
            }
        };
        cancelListener = new OnClickListener() {
            @Override
            public void onClick(View v) {
                LinphoneActivity.instance().resetClassicMenuLayoutAndGoBackToCallIfStillRunning();
            }
        };
        transferListener = new OnClickListener() {
            @Override
            public void onClick(View v) {
                LinphoneCore lc = LinphoneManager.getLc();
                if (lc.getCurrentCall() == null) {
                    return;
                }
                lc.transferCall(lc.getCurrentCall(), mAddress.getText().toString());
                LinphoneActivity.instance().resetClassicMenuLayoutAndGoBackToCallIfStillRunning();
                isCallTransferOngoing = false;
            }
        };

        mAddContact = (ImageView) view.findViewById(R.id.addContact);
        mAddContact
                .setEnabled(!(LinphoneActivity.isInstanciated() && LinphoneManager.getLc().getCallsNb() > 0));
        resetLayout(isCallTransferOngoing);

        if (getArguments() != null) {
            shouldEmptyAddressField = false;
            String number = getArguments().getString("SipUri");
            String displayName = getArguments().getString("DisplayName");
            String photo = getArguments().getString("PhotoUri");
            mAddress.setText(number);
            if (displayName != null) {
                mAddress.setDisplayedName(displayName);
            }
            if (photo != null) {
                mAddress.setPictureUri(Uri.parse(photo));
            }
        }
        // MATCH_PARENT WRAP_CONTENT //yyppdial.test
        /*
         * pop = new PopupWindow((getActivity().getLayoutInflater().inflate(
         * R.layout.dialer_list, null)),
         * ViewGroup.LayoutParams.WRAP_CONTENT,
         * ViewGroup.LayoutParams.WRAP_CONTENT);
         */

        pop = new PopupWindow((getActivity().getLayoutInflater().inflate(R.layout.dialer_list, null)),
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

        if (pop != null) {
            pop.setFocusable(true);
            pop.setBackgroundDrawable(new BitmapDrawable());
            listView = (ListView) pop.getContentView().findViewById(R.id.dialer_pop_list);
        }
        if (listView != null) {
            listView.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                    mAddress.setDisplayedName(list.get(arg2).num);
                    mAddress.setText(list.get(arg2).num);
                    pop.dismiss();
                }
            });
        }

        // SpannableString str=new SpannableString("1234567890");
        // str.setSpan(new ForegroundColorSpan(Color.MAGENTA), 12, 15,
        // Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        showInfor = (ImageView) view.findViewById(R.id.dialer_infor_showimg1);
        if (showInfor != null) {
            showInfor.setOnClickListener(new OnClickListener() {
                @SuppressWarnings("unchecked")
                @Override
                public void onClick(View v) {
                    if (pop.isShowing()) {
                        pop.dismiss();
                    } else {
                        list = new CallInfor().getCallInfor((List<Contact>) ContactDB.Instance().getAllOb()[2],
                                CallsLogUtils.instance().getCallsLogs(), text);
                        if (list.size() == 0) {
                            return;
                        }
                        // yyyppset //yyppdal del
                        listView.setAdapter(new DialerListViewAdapter(getActivity(), list, text));
                        // pop.setWidth(view.getWidth());
                        pop.setWidth(view.getWidth() - 70);
                        pop.showAsDropDown(mAddress);

                        // yyppcall //yyppset add
                        /*
                         * ListAdapter madapter=new
                         * DialerListViewAdapter(getActivity(), list, text);
                         * //listView.setAdapter(new
                         * DialerListViewAdapter(getActivity(), list,
                         * text)); listView.setAdapter(madapter);
                         * 
                         * if (madapter.getCount()> 9) {
                         * pop.setHeight(view.getHeight()-60); } else {
                         * 
                         * pop.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
                         * ; } pop.showAsDropDown(mAddress);
                         */
                        // yyppcall end

                    }
                }
            });
        }

        String tmpstr1 = "";
        if (UserConfig.getInstance().loginstatus == 0)
            tmpstr1 = "";
        else
            tmpstr1 = "";

        //

        /*
         * if (msc != null) { msc.setOnClickListener(new OnClickListener() {
         * 
         * @Override public void onClick(View v) { SettingHelp mes = new
         * SettingHelp(); Bundle bundle = new Bundle();
         * bundle.putInt("type", SettingHelp.NOTICE);
         * mes.setArguments(bundle);
         * mes.setStyle(DialogFragment.STYLE_NO_TITLE,
         * DialogFragment.STYLE_NORMAL);
         * mes.show(getActivity().getSupportFragmentManager(), "mes"); } });
         * }
         */
        // yyppdial end
    }
    ViewGroup parent = (ViewGroup) view.getParent();
    if (parent != null) {
        parent.removeView(view);
    }

    // android.util.Log.i("xushuang", "<<<<2"+list2.toString());
    // views for ads

    return view;
}

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

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

    setWillNotDraw(false);/*from   w  ww  . j  av  a 2 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.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);

    passwordEditText2 = new AnimatingTextView(context);
    passwordFrameLayout.addView(passwordEditText2);
    layoutParams = (FrameLayout.LayoutParams) passwordEditText2.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;
    passwordEditText2.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);
            }
        }
    });
    if (android.os.Build.VERSION.SDK_INT < 11) {
        passwordEditText.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
            public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
                menu.clear();
            }
        });
    } else {
        passwordEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
            public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                return false;
            }

            public void onDestroyActionMode(ActionMode mode) {
            }

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

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

    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("");
                    passwordEditText2.eraseAllCharacters(true);
                    return true;
                }
            });
        }
        frameLayout.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                int tag = (Integer) v.getTag();
                switch (tag) {
                case 0:
                    passwordEditText2.appendCharacter("0");
                    break;
                case 1:
                    passwordEditText2.appendCharacter("1");
                    break;
                case 2:
                    passwordEditText2.appendCharacter("2");
                    break;
                case 3:
                    passwordEditText2.appendCharacter("3");
                    break;
                case 4:
                    passwordEditText2.appendCharacter("4");
                    break;
                case 5:
                    passwordEditText2.appendCharacter("5");
                    break;
                case 6:
                    passwordEditText2.appendCharacter("6");
                    break;
                case 7:
                    passwordEditText2.appendCharacter("7");
                    break;
                case 8:
                    passwordEditText2.appendCharacter("8");
                    break;
                case 9:
                    passwordEditText2.appendCharacter("9");
                    break;
                case 10:
                    passwordEditText2.eraseLastCharacter();
                    break;
                }
                if (passwordEditText2.lenght() == 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.hichinaschool.flashcards.anki.multimediacard.activity.MultimediaCardEditorActivity.java

private void createNewViewer(LinearLayout linearLayout, final IField field, final int index) {

    final MultimediaCardEditorActivity context = this;

    switch (field.getType()) {
    case TEXT://from   w ww  . j ava  2s .  co  m

        // Create a text field and an edit button, opening editing for
        // the
        // text field

        TextView textView = new TextView(this);
        textView.setText(field.getText());
        linearLayout.addView(textView, LinearLayout.LayoutParams.MATCH_PARENT);

        break;

    case IMAGE:

        ImageView imgView = new ImageView(this);
        //
        // BitmapFactory.Options options = new BitmapFactory.Options();
        // options.inSampleSize = 2;
        // Bitmap bm = BitmapFactory.decodeFile(myJpgPath, options);
        // jpgView.setImageBitmap(bm);

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

        File f = new File(field.getImagePath());

        Bitmap b = BitmapUtil.decodeFile(f, getMaxImageSize());

        int currentapiVersion = android.os.Build.VERSION.SDK_INT;
        if (currentapiVersion >= android.os.Build.VERSION_CODES.ECLAIR) {
            b = ExifUtil.rotateFromCamera(f, b);
        }

        imgView.setImageBitmap(b);

        imgView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        imgView.setAdjustViewBounds(true);

        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);

        int height = metrics.heightPixels;
        int width = metrics.widthPixels;

        imgView.setMaxHeight((int) Math.round(height * 0.6));
        imgView.setMaxWidth((int) Math.round(width * 0.7));
        linearLayout.addView(imgView, p);

        break;
    case AUDIO:
        AudioView audioView = AudioView.createPlayerInstance(this, R.drawable.av_play, R.drawable.av_pause,
                R.drawable.av_stop, field.getAudioPath());
        linearLayout.addView(audioView);
        break;

    default:
        Log.e("multimedia editor", "Unsupported field type found");
        break;
    }

    Button editButtonText = new Button(this);
    editButtonText.setText(gtxt(R.string.multimedia_editor_activity_edit_button));
    linearLayout.addView(editButtonText, LinearLayout.LayoutParams.MATCH_PARENT);

    editButtonText.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(context, EditFieldActivity.class);
            putExtrasAndStartEditActivity(field, index, i);
        }

    });
}

From source file:com.mishiranu.dashchan.ui.navigator.page.PostsPage.java

@Override
protected void onCreate() {
    Activity activity = getActivity();/*from   www  . j  a  v a  2s.c o  m*/
    PullableListView listView = getListView();
    PageHolder pageHolder = getPageHolder();
    UiManager uiManager = getUiManager();
    hidePerformer = new HidePerformer();
    PostsExtra extra = getExtra();
    listView.setDivider(ResourceUtils.getDrawable(activity, R.attr.postsDivider, 0));
    ChanConfiguration.Board board = getChanConfiguration().safe().obtainBoard(pageHolder.boardName);
    if (board.allowPosting) {
        replyable = data -> getUiManager().navigator().navigatePosting(pageHolder.chanName,
                pageHolder.boardName, pageHolder.threadNumber, data);
    }
    PostsAdapter adapter = new PostsAdapter(activity, pageHolder.chanName, pageHolder.boardName, uiManager,
            replyable, hidePerformer, extra.userPostNumbers, listView);
    initAdapter(adapter, adapter);
    ImageLoader.getInstance().observable().register(this);
    listView.getWrapper().setPullSides(PullableWrapper.Side.BOTH);
    uiManager.observable().register(this);
    hidePerformer.setPostsProvider(adapter);

    Context darkStyledContext = new ContextThemeWrapper(activity, R.style.Theme_General_Main_Dark);
    searchController = new LinearLayout(darkStyledContext);
    searchController.setOrientation(LinearLayout.HORIZONTAL);
    searchController.setGravity(Gravity.CENTER_VERTICAL);
    float density = ResourceUtils.obtainDensity(getResources());
    int padding = (int) (10f * density);
    searchTextResult = new Button(darkStyledContext, null, android.R.attr.borderlessButtonStyle);
    searchTextResult.setTextSize(11f);
    if (!C.API_LOLLIPOP) {
        searchTextResult.setTypeface(null, Typeface.BOLD);
    }
    searchTextResult.setPadding((int) (14f * density), 0, (int) (14f * density), 0);
    searchTextResult.setMinimumWidth(0);
    searchTextResult.setMinWidth(0);
    searchTextResult.setOnClickListener(v -> showSearchDialog());
    searchController.addView(searchTextResult, LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    ImageView backButtonView = new ImageView(darkStyledContext, null, android.R.attr.borderlessButtonStyle);
    backButtonView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    backButtonView.setImageResource(obtainIcon(R.attr.actionBack));
    backButtonView.setPadding(padding, padding, padding, padding);
    backButtonView.setOnClickListener(v -> findBack());
    searchController.addView(backButtonView, (int) (48f * density), (int) (48f * density));
    ImageView forwardButtonView = new ImageView(darkStyledContext, null, android.R.attr.borderlessButtonStyle);
    forwardButtonView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    forwardButtonView.setImageResource(obtainIcon(R.attr.actionForward));
    forwardButtonView.setPadding(padding, padding, padding, padding);
    forwardButtonView.setOnClickListener(v -> findForward());
    searchController.addView(forwardButtonView, (int) (48f * density), (int) (48f * density));
    if (C.API_LOLLIPOP) {
        for (int i = 0, last = searchController.getChildCount() - 1; i <= last; i++) {
            View view = searchController.getChildAt(i);
            LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) view.getLayoutParams();
            if (i == 0) {
                layoutParams.leftMargin = (int) (-6f * density);
            }
            if (i == last) {
                layoutParams.rightMargin = (int) (6f * density);
            } else {
                layoutParams.rightMargin = (int) (-6f * density);
            }
        }
    }

    scrollToPostNumber = pageHolder.initialPostNumber;
    FavoritesStorage.getInstance().getObservable().register(this);
    LocalBroadcastManager.getInstance(activity).registerReceiver(galleryPagerReceiver,
            new IntentFilter(C.ACTION_GALLERY_NAVIGATE_POST));
    boolean hasNewPostDatas = handleNewPostDatas();
    extra.forceRefresh = hasNewPostDatas || !pageHolder.initialFromCache;
    if (extra.cachedPosts != null && extra.cachedPostItems.size() > 0) {
        onDeserializePostsCompleteInternal(true, extra.cachedPosts, new ArrayList<>(extra.cachedPostItems),
                true);
    } else {
        deserializeTask = new DeserializePostsTask(this, pageHolder.chanName, pageHolder.boardName,
                pageHolder.threadNumber, extra.cachedPosts);
        deserializeTask.executeOnExecutor(DeserializePostsTask.THREAD_POOL_EXECUTOR);
        getListView().getWrapper().startBusyState(PullableWrapper.Side.BOTH);
        switchView(ViewType.PROGRESS, null);
    }
    pageHolder.setInitialPostsData(false, null);
}

From source file:com.mishiranu.dashchan.ui.navigator.DrawerForm.java

private View makeHeader(ViewGroup parent, boolean button, float density) {
    if (C.API_LOLLIPOP) {
        LinearLayout linearLayout = new LinearLayout(context);
        linearLayout.setOrientation(LinearLayout.VERTICAL);
        View divider = makeSimpleDivider();
        int paddingTop = divider.getPaddingBottom();
        divider.setPadding(divider.getPaddingLeft(), divider.getPaddingTop(), divider.getPaddingRight(), 0);
        linearLayout.addView(divider, LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        LinearLayout linearLayout2 = new LinearLayout(context);
        linearLayout2.setOrientation(LinearLayout.HORIZONTAL);
        linearLayout.addView(linearLayout2, LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        TextView textView = makeCommonTextView(true);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(0, (int) (32f * density), 1);
        layoutParams.setMargins((int) (16f * density), paddingTop, (int) (16f * density), (int) (8f * density));
        linearLayout2.addView(textView, layoutParams);
        ViewHolder holder = new ViewHolder();
        holder.text = textView;/*w w w .java  2s.c  o  m*/
        if (button) {
            ImageView imageView = new ImageView(context);
            imageView.setScaleType(ImageView.ScaleType.CENTER);
            imageView.setBackgroundResource(ResourceUtils.getResourceId(context,
                    android.R.attr.borderlessButtonStyle, android.R.attr.background, 0));
            imageView.setOnClickListener(headerButtonListener);
            imageView.setImageAlpha(0x5e);
            int size = (int) (48f * density);
            layoutParams = new LinearLayout.LayoutParams(size, size);
            layoutParams.rightMargin = (int) (4f * density);
            linearLayout2.addView(imageView, layoutParams);
            holder.extra = imageView;
            holder.icon = imageView;
        }
        linearLayout.setTag(holder);
        return linearLayout;
    } else {
        View view = LayoutInflater.from(context)
                .inflate(ResourceUtils.getResourceId(context, android.R.attr.preferenceCategoryStyle,
                        android.R.attr.layout, android.R.layout.preference_category), parent, false);
        ViewHolder holder = new ViewHolder();
        holder.text = (TextView) view.findViewById(android.R.id.title);
        if (button) {
            int measureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
            view.measure(measureSpec, measureSpec);
            int size = view.getMeasuredHeight();
            if (size == 0) {
                size = (int) (32f * density);
            }
            FrameLayout frameLayout = new FrameLayout(context);
            frameLayout.addView(view);
            view = frameLayout;
            ImageView imageView = new ImageView(context);
            imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
            int padding = (int) (4f * density);
            imageView.setPadding(padding, padding, padding, padding);
            frameLayout.addView(imageView,
                    new FrameLayout.LayoutParams((int) (48f * density), size, Gravity.END));
            View buttonView = new View(context);
            buttonView.setBackgroundResource(
                    ResourceUtils.getResourceId(context, android.R.attr.selectableItemBackground, 0));
            buttonView.setOnClickListener(headerButtonListener);
            frameLayout.addView(buttonView, FrameLayout.LayoutParams.MATCH_PARENT,
                    FrameLayout.LayoutParams.MATCH_PARENT);
            holder.extra = buttonView;
            holder.icon = imageView;
        }
        view.setTag(holder);
        return view;
    }
}

From source file:com.mishiranu.dashchan.ui.navigator.DrawerForm.java

private View makeView(boolean icon, boolean watcher, boolean closeable, float density) {
    int size = (int) (48f * density);
    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.HORIZONTAL);
    linearLayout.setGravity(Gravity.CENTER_VERTICAL);
    ImageView iconView = null;
    if (icon) {/*w ww .  j ava 2 s  . c o  m*/
        iconView = new ImageView(context);
        iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        linearLayout.addView(iconView, (int) (24f * density), size);
    }
    TextView textView = makeCommonTextView(false);
    linearLayout.addView(textView, new LinearLayout.LayoutParams(0, size, 1));
    WatcherView watcherView = null;
    if (watcher) {
        watcherView = new WatcherView(context);
        linearLayout.addView(watcherView, size, size);
    }
    ImageView closeView = null;
    if (!watcher && closeable) {
        closeView = new ImageView(context);
        closeView.setScaleType(ImageView.ScaleType.CENTER);
        closeView.setImageResource(ResourceUtils.getResourceId(context, R.attr.buttonCancel, 0));
        closeView.setBackgroundResource(ResourceUtils.getResourceId(context,
                android.R.attr.borderlessButtonStyle, android.R.attr.background, 0));
        linearLayout.addView(closeView, size, size);
        closeView.setOnClickListener(closeButtonListener);
    }
    ViewHolder holder = new ViewHolder();
    holder.icon = iconView;
    holder.text = textView;
    holder.extra = watcherView != null ? watcherView : closeView;
    linearLayout.setTag(holder);
    int layoutLeftDp = 0;
    int layoutRightDp = 0;
    int textLeftDp;
    int textRightDp;
    if (C.API_LOLLIPOP) {
        textLeftDp = 16;
        textRightDp = 16;
        if (icon) {
            layoutLeftDp = 16;
            textLeftDp = 32;
        }
        if (watcher || closeable) {
            layoutRightDp = 4;
            textRightDp = 8;
        }
    } else {
        textLeftDp = 8;
        textRightDp = 8;
        if (icon) {
            layoutLeftDp = 8;
            textLeftDp = 6;
            textView.setAllCaps(true);
        }
        if (watcher || closeable) {
            layoutRightDp = 0;
            textRightDp = 0;
        }
    }
    linearLayout.setPadding((int) (layoutLeftDp * density), 0, (int) (layoutRightDp * density), 0);
    textView.setPadding((int) (textLeftDp * density), 0, (int) (textRightDp * density), 0);
    return linearLayout;
}

From source file:com.android.contacts.common.list.ContactListItemView.java

/**
 * Set drawable resources directly for the drawable resource of the photo view.
 *
 * @param drawableId Id of drawable resource.
 *//*from ww  w  .ja v a2s . c om*/
public void setDrawableResource(int drawableId) {
    ImageView photo = getPhotoView();
    photo.setScaleType(ImageView.ScaleType.CENTER);
    final Drawable drawable = ContextCompat.getDrawable(getContext(), drawableId);
    final int iconColor = ContextCompat.getColor(getContext(), R.color.search_shortcut_icon_color);
    if (CompatUtils.isLollipopCompatible()) {
        photo.setImageDrawable(drawable);
        photo.setImageTintList(ColorStateList.valueOf(iconColor));
    } else {
        final Drawable drawableWrapper = DrawableCompat.wrap(drawable).mutate();
        DrawableCompat.setTint(drawableWrapper, iconColor);
        photo.setImageDrawable(drawableWrapper);
    }
}

From source file:com.mobileglobe.android.customdialer.common.list.ContactListItemView.java

/**
 * Set drawable resources directly for the drawable resource of the photo view.
 *
 * @param drawableId Id of drawable resource.
 *//*from   w  w w.j a  v  a  2s .c  o  m*/
public void setDrawableResource(int drawableId) {
    ImageView photo = getPhotoView();
    photo.setScaleType(ScaleType.CENTER);
    final Drawable drawable = ContextCompat.getDrawable(getContext(), drawableId);
    final int iconColor = ContextCompat.getColor(getContext(), R.color.search_shortcut_icon_color);
    if (CompatUtils.isLollipopCompatible()) {
        photo.setImageDrawable(drawable);
        photo.setImageTintList(ColorStateList.valueOf(iconColor));
    } else {
        final Drawable drawableWrapper = DrawableCompat.wrap(drawable).mutate();
        DrawableCompat.setTint(drawableWrapper, iconColor);
        photo.setImageDrawable(drawableWrapper);
    }
}

From source file:com.bofsoft.laio.laiovehiclegps.Fragment.BaiduMapFragment.java

private void addOverlay(GPSInfoData gpsInfoData) {//marker ?? ?
    LatLng llA = new LatLng(gpsInfoData.Latitude, gpsInfoData.Longitude);
    // GPSGPS??????
    CoordinateConverter converter = new CoordinateConverter();
    converter.from(CoordinateConverter.CoordType.GPS);
    // sourceLatLng???
    converter.coord(llA);//w w w . j  a  v  a 2 s  .c o  m
    //        desLatLng = converter.convert();
    LatLng tmpLL = converter.convert();

    View v_temp = LayoutInflater.from(getActivity()).inflate(R.layout.map_marker, null);//
    TextView tv_temp = (TextView) v_temp.findViewById(R.id.tv_marker);//?textview
    ImageView img_temp = (ImageView) v_temp.findViewById(R.id.iv_marker);//?imageview
    tv_temp.setText(gpsInfoData.License);//?
    if (gpsInfoData.Status == 0) {
        img_temp.setImageResource(imgIds[0]);//marker
        bitmap = BitmapFactory.decodeResource(getResources(), imgIds[0]);
    } else {
        img_temp.setImageResource(imgIds[2]);//marker
        bitmap = BitmapFactory.decodeResource(getResources(), imgIds[2]);
    }
    Matrix matrix = new Matrix();
    img_temp.setScaleType(ImageView.ScaleType.MATRIX); //required
    matrix.postScale(1, 1);
    //ImageViewImage
    int dw = bitmap.getWidth();
    int dh = bitmap.getHeight();
    matrix.postRotate((float) gpsInfoData.Direction, (float) dw / 2, (float) dh / 2);//
    img_temp.setImageMatrix(matrix);
    bd_temp = BitmapDescriptorFactory.fromView(v_temp);//?marker
    MarkerOptions oo = new MarkerOptions().position(tmpLL).icon(bd_temp).anchor(0.5f, 1.0f).zIndex(15);
    Marker mMarkerA = (Marker) (mBaiduMap.addOverlay(oo));
    Bundle bundle = new Bundle();
    bundle.putString("License", gpsInfoData.getLicense());
    mMarkerA.setExtraInfo(bundle);
}