Search in sources :

Example 1 with DynamicTimeFormat

use of com.scwang.refreshlayout.util.DynamicTimeFormat in project SmartRefreshLayout by scwang90.

the class ClassicsStyleActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_style_classics);
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    mToolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    mRefreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
    int delta = new Random().nextInt(7 * 24 * 60 * 60 * 1000);
    mClassicsHeader = (ClassicsHeader) mRefreshLayout.getRefreshHeader();
    mClassicsHeader.setLastUpdateTime(new Date(System.currentTimeMillis() - delta));
    mClassicsHeader.setTimeFormat(new SimpleDateFormat("更新于 MM-dd HH:mm", Locale.CHINA));
    mClassicsHeader.setTimeFormat(new DynamicTimeFormat("更新于 %s"));
    // mDrawableProgress = mClassicsHeader.getProgressView().getDrawable();
    mDrawableProgress = ((ImageView) mClassicsHeader.findViewById(ClassicsHeader.ID_IMAGE_PROGRESS)).getDrawable();
    if (mDrawableProgress instanceof LayerDrawable) {
        mDrawableProgress = ((LayerDrawable) mDrawableProgress).getDrawable(0);
    }
    View view = findViewById(R.id.recyclerView);
    if (view instanceof RecyclerView) {
        RecyclerView recyclerView = (RecyclerView) view;
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.addItemDecoration(new DividerItemDecoration(this, VERTICAL));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.setAdapter(mAdpater = new BaseRecyclerAdapter<Item>(Arrays.asList(Item.values()), simple_list_item_2, this) {

            @Override
            protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) {
                holder.text(android.R.id.text1, model.name());
                holder.text(android.R.id.text2, model.nameId);
                holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
            }
        });
        mRecyclerView = recyclerView;
    }
    if (isFirstEnter) {
        isFirstEnter = false;
        // 触发自动刷新
        mRefreshLayout.autoRefresh();
    }
}
Also used : SmartViewHolder(com.scwang.refreshlayout.adapter.SmartViewHolder) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) BaseRecyclerAdapter(com.scwang.refreshlayout.adapter.BaseRecyclerAdapter) Date(java.util.Date) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) Random(java.util.Random) LayerDrawable(android.graphics.drawable.LayerDrawable) RecyclerView(android.support.v7.widget.RecyclerView) SimpleDateFormat(java.text.SimpleDateFormat) DynamicTimeFormat(com.scwang.refreshlayout.util.DynamicTimeFormat)

Aggregations

LayerDrawable (android.graphics.drawable.LayerDrawable)1 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ImageView (android.widget.ImageView)1 BaseRecyclerAdapter (com.scwang.refreshlayout.adapter.BaseRecyclerAdapter)1 SmartViewHolder (com.scwang.refreshlayout.adapter.SmartViewHolder)1 DynamicTimeFormat (com.scwang.refreshlayout.util.DynamicTimeFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Random (java.util.Random)1