Java 类android.widget.ViewSwitcher.ViewFactory 实例源码

项目:AyoSunny    文件:V_ViewSwitcher.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.uistudy_view_switcher);

    switcher = this.findViewSwitcher(R.id.viewSwitcher);
    //===给swticher设置View工厂,当调用switcher.getNextView()时,就是返回 factory.makeView()创建的View
    //===这里给一个TextView,让swticher切换多个TextView
    switcher.setFactory(new ViewFactory() {

        @Override
        public View makeView() {
            return new TextView(V_ViewSwitcher.this);
        }
    }); 
}
项目:android_apps    文件:SummaryDialogDisplayTaskImpl.java   
private void generateDialogContent(){
    this.dialog = new Dialog((BaseActivityAbstract)this.getActivity());
    this.dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.dialog.setContentView(R.layout.summary_result_dialog_layout);
    this.dialog.setCancelable(false);
    this.tryAgainDialogButton = (Button)dialog.findViewById(R.id.summary_dialog_retry_button);
    this.quitDialogButton = (Button)dialog.findViewById(R.id.summary_dialog_quit_button);

    final SummaryDialogDisplayTaskImpl currentSummaryDialogDisplayTaskImpl = this;
    this.earnedPointTextSwitcher = (TextSwitcher) this.dialog.findViewById(R.id.summary_point_textswitcher);
    final int textColorInt = Color.parseColor("#41A62A");
    this.earnedPointTextSwitcher.setFactory(new ViewFactory() {
        public View makeView() {
            TextView textView = new TextView(currentSummaryDialogDisplayTaskImpl.getActivity().getApplicationContext());
            textView.setGravity(Gravity.LEFT);
            textView.setTextColor(textColorInt);
            return textView;
        }
    });

}
项目:animTextview    文件:MainActivity.java   
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    textview = (TextView) findViewById(R.id.textview);
    // ���TextSwitch�����ã�
    mTextSwitcher = (TextSwitcher) findViewById(R.id.your_textview);
     //ָ��TextSwitcher��viewFactory
    mTextSwitcher.setFactory(new ViewFactory() {
        @Override
        public View makeView() {
            TextView t = new TextView(MainActivity.this);
            t.setGravity(Gravity.CENTER);
            return t;
        }
    });
    // �������붯��Ч��,ʹ��ϵͳ��̸��Ч����Ҳ�����Զ���
    mTextSwitcher.setInAnimation(this, android.R.anim.fade_in);
    // �����г�����Ч����ʹ��ϵͳ��̸��Ч����Ҳ�����Զ���
    mTextSwitcher.setOutAnimation(this, android.R.anim.fade_out);

    onSwitchText(null);
}
项目:animTextview    文件:MainActivity.java   
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    textview = (TextView) findViewById(R.id.textview);
    // ���TextSwitch�����ã�
    mTextSwitcher = (TextSwitcher) findViewById(R.id.your_textview);
     //ָ��TextSwitcher��viewFactory
    mTextSwitcher.setFactory(new ViewFactory() {
        @Override
        public View makeView() {
            TextView t = new TextView(MainActivity.this);
            t.setGravity(Gravity.CENTER);
            return t;
        }
    });
    // �������붯��Ч��,ʹ��ϵͳ��̸��Ч����Ҳ�����Զ���
    mTextSwitcher.setInAnimation(this, android.R.anim.fade_in);
    // �����г�����Ч����ʹ��ϵͳ��̸��Ч����Ҳ�����Զ���
    mTextSwitcher.setOutAnimation(this, android.R.anim.fade_out);

    onSwitchText(null);
}
项目:missile-android    文件:ViewMissilesFragment.java   
private void initListView() {
    listView = (ListView) rootView.findViewById(R.id.lv_missiles);
    txtEmpty = (TextView) rootView.findViewById(R.id.tvEmpty);
    mViewMissileAdapter = new ViewMissileAdapter(getActivity());
    listView.setAdapter(mViewMissileAdapter);
    pagination = new Pagination(listView, mViewMissileAdapter, mUrl, this);
    listView.setOnScrollListener(pagination);
    listView.setOnItemClickListener(listener);
    tvHotMissile = (TextSwitcher) rootView.findViewById(R.id.tvHotMissile);

    mHeaderView = (LinearLayout) rootView.findViewById(R.id.header);
    // Set the ViewFactory of the TextSwitcher that will create TextView
    // object when asked
    tvHotMissile.setFactory(new ViewFactory() {

        public View makeView() {
            TextView myText = (TextView) getActivity().getLayoutInflater()
                    .inflate(R.layout.custom_text_view, null);
            return myText;
        }
    });
    // Declare the in and out animations and initialize them
    Animation in = AnimationUtils.loadAnimation(getActivity(),
            android.R.anim.slide_in_left);
    Animation out = AnimationUtils.loadAnimation(getActivity(),
            android.R.anim.slide_out_right);

    // set the animation type of textSwitcher
    tvHotMissile.setInAnimation(in);
    tvHotMissile.setOutAnimation(out);

    handler = new Handler();
    delaySearchHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == 5) {
                search((String) msg.obj);

            }
        }
    };
    // called for listing special missiles like tags, disable header
    if (!isViewAllMissiles)
        mHeaderView.setVisibility(View.GONE);
    else {
        if (isSearchEnabled) {
            mHeaderView.setVisibility(View.GONE);
        } else {
            mHeaderView.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    MissileFragment missileFragment = new MissileFragment();
                    Bundle bundle = new Bundle();
                    bundle.putParcelable("missile",
                            (Missile) tvHotMissile.getTag());
                    missileFragment.setArguments(bundle);
                    StartModule.addFragmentForModule(getFragmentManager(),
                            missileFragment);
                }
            });
        }
    }
}
项目:piggybank    文件:AccountFragment.java   
private void setHeaderFragment() {
    Bundle bundle = this.getArguments();
    mAccountID = bundle.getLong(ACCOUNT_ID);
    // Get list items
    mAccount = mOperationHandler.getAccount(mAccountID);
    // Get Current saves
    Double currentMoney = mAccount.getMoney();
    mTxtSwitchSaves.setFactory(new ViewFactory() {

        public View makeView() {

            LayoutInflater inflater = LayoutInflater.from(mContext);

            TextView textView = (TextView) inflater.inflate(
                    R.layout.text_view_switcher, null);

            return textView;

        }
    });

    // Set TextSwitch background
    int[] backgroundColor = StyleAPP.getBackgroundColor(getActivity(),
            mAccount.getIcon());
    mTxtSwitchSaves.setBackgroundColor(backgroundColor[0]);


    // Declare the in and out animations and initialize them
     Animation in =
     AnimationUtils.loadAnimation(mContext,R.anim.top_to_down_anim);
     Animation out =
     AnimationUtils.loadAnimation(mContext,android.R.anim.fade_out);

     // set the animation type of textSwitcher
     mTxtSwitchSaves.setInAnimation(in);
     mTxtSwitchSaves.setOutAnimation(out);

    // Set currect Saves
    mTxtSwitchSaves.setText(Constant.DF.format(currentMoney));

}