use of com.shiming.andrioddesignpattern.strategy_model.ContextPrice in project AndriodDesignPattern by Shimingli.
the class StrategyModelFragment method onActivityCreated.
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
FivePriceStrategy fivePriceStrategy = new FivePriceStrategy();
ContextPrice contextPrice = new ContextPrice(fivePriceStrategy);
int i = contextPrice.setNewPrice(10);
SevenPriceStrategy sevenPriceStrategy = new SevenPriceStrategy();
contextPrice.setNewStrategy(sevenPriceStrategy);
int i1 = contextPrice.setNewPrice(20);
mTextView = (TextView) getView().findViewById(R.id.tvdes);
final TextView viewById1 = (TextView) getView().findViewById(R.id.tv_text);
mTextView.setText("第一种策略模式实现的价格:\n原价是10 减半后" + i + "\n" + "第二种策略模式实现的价格\n原价是20 7折后" + i1);
// 时间差值器,也是策略模式
final Button viewById = (Button) getView().findViewById(R.id.btn);
viewById.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(viewById1, View.ALPHA, 0, 1);
// 这里就相当于策略模式实现的
// 加速
objectAnimator.setInterpolator(new AccelerateInterpolator());
// huilai
objectAnimator.setInterpolator(new OvershootInterpolator());
objectAnimator.start();
}
});
}
Aggregations