Java Code Examples for android.support.v4.widget.SwipeRefreshLayout#setColorSchemeColors()

The following examples show how to use android.support.v4.widget.SwipeRefreshLayout#setColorSchemeColors() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TableView.java    From SortableTableView with Apache License 2.0 6 votes vote down vote up
private void setupTableDataView(final AttributeSet attributes, final int styleAttributes) {
    final LayoutParams dataViewLayoutParams = new LayoutParams(getWidthAttribute(attributes), LayoutParams.MATCH_PARENT);

    if (isInEditMode()) {
        tableDataAdapter = new EditModeTableDataAdapter(getContext());
    } else {
        tableDataAdapter = new DefaultTableDataAdapter(getContext());
    }
    tableDataAdapter.setRowBackgroundProvider(dataRowBackgroundProvider);

    tableDataView = new ListView(getContext(), attributes, styleAttributes);
    tableDataView.setOnItemClickListener(new InternalDataClickListener());
    tableDataView.setOnItemLongClickListener(new InternalDataLongClickListener());
    tableDataView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    tableDataView.setAdapter(tableDataAdapter);
    tableDataView.setId(R.id.table_data_view);
    tableDataView.setOnScrollListener(new InternalOnScrollListener());

    swipeRefreshLayout = new SwipeRefreshLayout(getContext());
    swipeRefreshLayout.setLayoutParams(dataViewLayoutParams);
    swipeRefreshLayout.addView(tableDataView);
    swipeRefreshLayout.setColorSchemeColors(headerColor);
    swipeRefreshLayout.setEnabled(false);

    addView(swipeRefreshLayout);
}
 
Example 2
Source File: TriggerListFragment.java    From AndroidSDK with MIT License 6 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View contentView = inflater.inflate(R.layout.fragment_trigger_list, container, false);
    mRecyclerView = (RecyclerView) contentView.findViewById(R.id.recyler_view);
    mSwipeRefreshLayout = (SwipeRefreshLayout) contentView.findViewById(R.id.swipe_refresh_layout);

    mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    mAdapter = new TriggerListAdapter();
    mRecyclerView.setAdapter(mAdapter);
    mAdapter.setOnLoadMoreListener(mLoadMoreListener, mRecyclerView);
    mSwipeRefreshLayout.setColorSchemeColors(0xFFDA4336);
    mSwipeRefreshLayout.setOnRefreshListener(this);
    getTriggers(false);
    mSwipeRefreshLayout.setRefreshing(true);

    LocalBroadcastManager.getInstance(getContext()).registerReceiver(mUpdateApiKeyReceiver, new IntentFilter(IntentActions.ACTION_UPDATE_APIKEY));
    return contentView;
}
 
Example 3
Source File: DeviceActivity.java    From AndroidSDK with MIT License 6 votes vote down vote up
private void initViews() {
    mDeviceItem = (DeviceItem) getIntent().getSerializableExtra(EXTRA_DEVICE_ITEM);

    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);
    getSupportActionBar().setTitle(mDeviceItem.getTitle());
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeAsUpIndicator(android.support.v7.appcompat.R.drawable.abc_ic_ab_back_material);

    mRecyclerView = (RecyclerView) findViewById(R.id.recyler_view);
    mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);
    mFabAddDataStream = (FloatingActionButton) findViewById(R.id.fab_add_ds);

    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mAdapter = new DSListAdapter();
    mRecyclerView.setAdapter(mAdapter);
    mSwipeRefreshLayout.setColorSchemeColors(0xFFDA4336);
    mSwipeRefreshLayout.setOnRefreshListener(this);
    getDataStreams();
    mSwipeRefreshLayout.setRefreshing(true);

    mFabAddDataStream.setOnClickListener(this);
}
 
Example 4
Source File: MainFragment.java    From agera with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
    Bundle savedInstanceState) {
  View root = inflater.inflate(R.layout.main_frag, container, false);

  listView = (ListView) root.findViewById(R.id.list);

  // Set pull to refresh as an observable and attach it to the view
  refreshObservable = new OnRefreshObservable();
  swipeRefreshLayout = (SwipeRefreshLayout) root.findViewById(R.id.refresh_layout);
  swipeRefreshLayout.setColorSchemeColors(
      ContextCompat.getColor(getActivity(), R.color.colorPrimary),
      ContextCompat.getColor(getActivity(), R.color.colorAccent),
      ContextCompat.getColor(getActivity(), R.color.colorPrimaryDark));
  swipeRefreshLayout.setOnRefreshListener(refreshObservable);

  // Initialise the repository
  usernamesRepository = new UsernamesRepository(new UsernamesFetcher());

  return root;
}
 
Example 5
Source File: AggregateReportFragment.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void setupSwipeRefreshLayout(View root, Bundle savedInstanceState) {
    swipeRefreshLayout = (SwipeRefreshLayout) root.findViewById(R.id.ptr_layout);
    SwipeRefreshLayout.OnRefreshListener listener = new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            startUpdate();
        }
    };

    @ColorInt
    int blue = R.color.actionbar_blue;

    swipeRefreshLayout.setOnRefreshListener(listener);
    swipeRefreshLayout.setColorSchemeColors(blue, blue);

    PrefUtils.State datasetState = PrefUtils.getResourceState(
            getActivity(), PrefUtils.Resources.DATASETS);

    boolean isRefreshing = false;
    if (savedInstanceState != null &&
            savedInstanceState.containsKey(STATE_IS_REFRESHING)) {
        isRefreshing = savedInstanceState.getBoolean(STATE_IS_REFRESHING, false);
    }

    if (!swipeRefreshLayout.isRefreshing()) {
        isRefreshing = datasetState == PrefUtils.State.REFRESHING;
    }

    if (!isRefreshing) {
        boolean needsUpdate = datasetState == PrefUtils.State.OUT_OF_DATE;
        boolean isConnectionAvailable = NetworkUtils.checkConnection(getActivity());

        if (needsUpdate && isConnectionAvailable) {
            startUpdate();
        }
    } else {
        showProgressBar();
    }
}
 
Example 6
Source File: AppFileListFragment.java    From AppPlus with MIT License 5 votes vote down vote up
private void setupSwipeLayout(View rootView) {
    mSwipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_refresh_layout);
    mSwipeRefreshLayout.setColorSchemeColors(Utils.getThemePrimaryColor(getActivity()));
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            fillData();
        }
    });
}
 
Example 7
Source File: ComputerNewsFragment.java    From MyHearts with Apache License 2.0 5 votes vote down vote up
private void initView(View view) {
    mRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.refresh);
    mRefreshLayout.setColorSchemeColors(Color.YELLOW, Color.RED, Color.BLUE, Color.GREEN);
    //能够模拟进入就刷新
    mRefreshLayout.post(() -> mRefreshLayout.setRefreshing(true));
    mRefreshLayout.setOnRefreshListener(this);
    mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
    LinearLayoutManager manager = new LinearLayoutManager(getContext());
    mRecyclerView.setLayoutManager(manager);
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());

    mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);

            int lastVisiableItemPosition = manager.findLastVisibleItemPosition();
            if (lastVisiableItemPosition + 1 == mNewsAdapter.getItemCount()) {
                if (!isLoading) {
                    isLoading = true;
                    new Handler().postDelayed(() -> {
                        getMoreData();
                        isLoading = false;
                        mNewsAdapter.notifyItemRemoved(mNewsAdapter.getItemCount());
                    }, 3000);
                }
            }
        }
    });
    //mNewsAdapter = new NewsAdapter(getContext(),mDatasEntities);
    //  mRecyclerView.setAdapter(mNewsAdapter);
}
 
Example 8
Source File: DeviceListFragment.java    From AndroidSDK with MIT License 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View contentView = inflater.inflate(R.layout.fragment_device_list, container, false);
    mRecyclerView = (RecyclerView) contentView.findViewById(R.id.recyler_view);
    mSwipeRefreshLayout = (SwipeRefreshLayout) contentView.findViewById(R.id.swipe_refresh_layout);
    mFabAddDevice = (FloatingActionButton) contentView.findViewById(R.id.fab_add_device);

    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    mAdapter = new DeviceListAdapter();
    mAdapter.setOnLoadMoreListener(mLoadMoreListener, mRecyclerView);
    mRecyclerView.addOnItemTouchListener(new OnItemClickListener() {
        @Override
        public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {
            DeviceActivity.actionDevice(getContext(), mDeviceItems.get(position));
        }
    });
    mRecyclerView.setAdapter(mAdapter);
    mSwipeRefreshLayout.setColorSchemeColors(0xFFDA4336);
    mSwipeRefreshLayout.setOnRefreshListener(this);
    getDevices(false);
    mSwipeRefreshLayout.setRefreshing(true);

    mFabAddDevice.setOnClickListener(this);
    LocalBroadcastManager.getInstance(getContext()).registerReceiver(mUpdateApiKeyReceiver, new IntentFilter(IntentActions.ACTION_UPDATE_APIKEY));
    LocalBroadcastManager.getInstance(getContext()).registerReceiver(mUpdateDeviceListReceiver, new IntentFilter(IntentActions.ACTION_UPDATE_DEVICE_LIST));
    return contentView;
}
 
Example 9
Source File: AppListFragment.java    From AppPlus with MIT License 5 votes vote down vote up
private void setupSwipeLayout(View rootView) {
    mSwipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_refresh_layout);
    mSwipeRefreshLayout.setColorSchemeColors(Utils.getThemePrimaryColor(getActivity()));
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            fillData();
        }
    });
}
 
Example 10
Source File: ContributorsFragment.java    From GithubContributorsLib with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    if (getArguments() != null) {
        ImageLoader.getInstance().init(UniversalImageLoaderUtils.getImageLoaderConfiguration(getActivity()));

        listView = (ListView) view.findViewById(R.id.ghcop_listView);
        setupListView(listView);

        swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.ghcop_swipe);
        swipeRefreshLayout.setColorSchemeColors(getThemeColor(getActivity(), R.attr.colorAccent));
        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                reloadContributors = true;
                loadContributors(0);
            }
        });

        String repositoryUrl = getArguments().getString(Contributors.BUNDLE_REPOSITORY_URL);
        token = getArguments().getString(Contributors.BUNDLE_CONTRIBUTORS_LIBRARY_GITHUB_TOKEN);
        if (!TextUtils.isEmpty(repositoryUrl) && !TextUtils.isEmpty(token)) {
            Uri uri = Uri.parse(repositoryUrl);

            if (uri.getPathSegments().size() >= 2) {
                owner = uri.getPathSegments().get(0);
                repo = uri.getPathSegments().get(1);

                loadContributors(0);
            }
        }
    }
}
 
Example 11
Source File: ReqStatsFragment.java    From NanoIconPack with Apache License 2.0 5 votes vote down vote up
private void initSwipeRefresh() {
    swipeRefreshLayout = (SwipeRefreshLayout) contentView.findViewById(R.id.swipe_refresh_layout);
    swipeRefreshLayout.setColorSchemeColors(ExtraUtil.fetchColor(getContext(), R.attr.colorAccent));
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            (new LoadAppsTask()).execute(true);
        }
    });
}
 
Example 12
Source File: SwipeToRefreshActivity.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.day4_activity_swipe_to_refresh);

    mSwipeRefresh = (SwipeRefreshLayout)
            findViewById(R.id.swipe_refresh_layout);
    mListView = (ListView) findViewById(R.id.list_view);

    initSampleData();

    mSimpleAdapter = new ArrayAdapter(this,
            android.R.layout.simple_list_item_1, android.R.id.text1, mData);

    mListView.setAdapter(mSimpleAdapter);

    mSwipeRefresh.setColorSchemeColors(Color.parseColor("#4183D7"),
            Color.parseColor("#F62459"),
            Color.parseColor("#03C9A9"),
            Color.parseColor("#F4D03F"));

    mSwipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {

            new Handler().postDelayed(new Runnable() {
                @Override public void run() {

                    mSimpleAdapter.clear();

                    initSampleData();

                    mSimpleAdapter.notifyDataSetChanged();

                    mSwipeRefresh.setRefreshing(false);
                }
            }, 5000);
        }
    });
}
 
Example 13
Source File: ReadLaterView.java    From Slide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_verticalcontent, container, false);

    final RecyclerView rv = ((RecyclerView) v.findViewById(R.id.vertical_content));
    final PreCachingLayoutManager mLayoutManager;

    mLayoutManager = new PreCachingLayoutManager(getContext());

    rv.setLayoutManager(mLayoutManager);
    v.findViewById(R.id.post_floating_action_button).setVisibility(View.GONE);
    final SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.activity_main_swipe_refresh_layout);

    mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors("default", getActivity()));

    //If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
    //So, we estimate the height of the header in dp
    mSwipeRefreshLayout.setProgressViewOffset(false,
            Constants.SINGLE_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP,
            Constants.SINGLE_HEADER_VIEW_OFFSET + Constants.PTR_OFFSET_BOTTOM);

    mSwipeRefreshLayout.post(new Runnable() {
        @Override
        public void run() {
            mSwipeRefreshLayout.setRefreshing(true);
        }
    });

    posts = new HistoryPosts("readLater");
    adapter = new ContributionAdapter(getActivity(), posts, rv);
    rv.setAdapter(adapter);

    posts.bindAdapter(adapter, mSwipeRefreshLayout);

    //TODO catch errors
    mSwipeRefreshLayout.setOnRefreshListener(
            new SwipeRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    posts.loadMore(adapter, true);

                    //TODO catch errors
                }
            }
    );
    rv.addOnScrollListener(new ToolbarScrollHideHandler((Toolbar) getActivity().findViewById(R.id.toolbar), getActivity().findViewById(R.id.header)) {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            visibleItemCount = rv.getLayoutManager().getChildCount();
            totalItemCount = rv.getLayoutManager().getItemCount();
            if (rv.getLayoutManager() instanceof PreCachingLayoutManager) {
                pastVisiblesItems = ((PreCachingLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPosition();
            } else {
                int[] firstVisibleItems = null;
                firstVisibleItems = ((CatchStaggeredGridLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPositions(firstVisibleItems);
                if (firstVisibleItems != null && firstVisibleItems.length > 0) {
                    pastVisiblesItems = firstVisibleItems[0];
                }
            }

            if (!posts.loading) {
                if ((visibleItemCount + pastVisiblesItems) + 5 >= totalItemCount && !posts.nomore) {
                    posts.loading = true;
                    posts.loadMore(adapter, false);
                }
            }
        }
    });
    return v;
}
 
Example 14
Source File: AppUtils.java    From v9porn with MIT License 4 votes vote down vote up
public static void setColorSchemeColors(Context context, SwipeRefreshLayout swipeRefreshLayout) {
    swipeRefreshLayout.setColorSchemeColors(ContextCompat.getColor(context, R.color.green), ContextCompat.getColor(context, R.color.lightred), ContextCompat.getColor(context, R.color.yeloo));
}
 
Example 15
Source File: HomeFragment.java    From MyHearts with Apache License 2.0 4 votes vote down vote up
/**
 * 初始化布局控件
 *
 * @param view
 */
private void initView(View view) {
    mScrollView = (ScrollView) view.findViewById(R.id.scrollView);
    mAvatorImg = (CircleImageView) view.findViewById(R.id.avator_img);
    mCustomerServiceTv = (TextView) view.findViewById(R.id.customer_service_tv);
    mFlyBanner = (FlyBanner) view.findViewById(R.id.fly_banner);
    mImgTall = (ImageView) view.findViewById(R.id.img_tall);
    mMyReTalk = (RelativeLayout) view.findViewById(R.id.my_re_talk);
    mImgContact = (ImageView) view.findViewById(R.id.img_contact);
    mMyReCall = (RelativeLayout) view.findViewById(R.id.my_re_call);
    mImgFree = (ImageView) view.findViewById(R.id.img_free);
    mMyReFree = (RelativeLayout) view.findViewById(R.id.my_re_free);
    mImgExam = (ImageView) view.findViewById(R.id.img_exam);
    mMyReExam = (RelativeLayout) view.findViewById(R.id.my_re_exam);
    mMarqueeImg = (ImageView) view.findViewById(R.id.marquee_img);
    mMarqueeView = (MarqueeView) view.findViewById(R.id.marquee_view);
    mRecommentMasterTv = (TextView) view.findViewById(R.id.recomment_master_tv);
    mImgOne = (ImageView) view.findViewById(R.id.img_one);
    mTvNameOne = (TextView) view.findViewById(R.id.tv_name_one);
    mTvLevelOne = (TextView) view.findViewById(R.id.tv_level_one);
    mTvDesOne = (TextView) view.findViewById(R.id.tv_des_one);
    mTvNameSecond = (TextView) view.findViewById(R.id.tv_name_second);
    mTvLevelTwo = (TextView) view.findViewById(R.id.tv_level_two);
    mTvDesTwo = (TextView) view.findViewById(R.id.tv_des_two);
    mImgTwo = (ImageView) view.findViewById(R.id.img_two);
    mImgThree = (ImageView) view.findViewById(R.id.img_three);
    mTvNameThree = (TextView) view.findViewById(R.id.tv_name_three);
    mTvDesThree = (TextView) view.findViewById(R.id.tv_des_three);
    mTvNameFour = (TextView) view.findViewById(R.id.tv_name_four);
    mTvDesFour = (TextView) view.findViewById(R.id.tv_des_four);
    mTvTitleRecomment = (TextView) view.findViewById(R.id.tv_title_recomment);
    mTvDesTrecomment = (TextView) view.findViewById(R.id.tv_des_trecomment);
    mImgFour = (ImageView) view.findViewById(R.id.img_four);
    mRecommentImgOne = (ImageView) view.findViewById(R.id.recomment_img_one);
    mImageView = (ImageView) view.findViewById(R.id.imageView);
    mHotImg = (ImageView) view.findViewById(R.id.hot_img);
    mHotRecyclerView = (RecyclerView) view.findViewById(R.id.hot_recycler_view);
    mReLookMore = (RelativeLayout) view.findViewById(R.id.re_look_more);
    mHotRecyclerView.setItemAnimator(new DefaultItemAnimator());
    LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()) {
        @Override
        public boolean canScrollVertically() {
            return false;
        }
    };
    mHotRecyclerView.setLayoutManager(layoutManager);
    mRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipeRefresh);
    mRefreshLayout.setColorSchemeColors(Color.RED, Color.BLUE, Color.GREEN);
    mRefreshLayout.setOnRefreshListener(this);

    mLlOne = (LinearLayout) view.findViewById(R.id.ll_adversory_one);
    mLlTwo = (LinearLayout) view.findViewById(R.id.ll_adversory_two);

    mLlThree = (LinearLayout) view.findViewById(R.id.ll_adversory_three);

    mLlFour = (LinearLayout) view.findViewById(R.id.ll_adversory_four);

}
 
Example 16
Source File: MainActivity.java    From openapk with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    this.context = this;

    appPreferences = App.getAppPreferences();
    packageManager = getPackageManager();

    setInitialConfiguration();
    OtherUtils.requestPermissions(context);

    recyclerView = (RecyclerView) findViewById(R.id.app_list);
    refresh = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh);
    noResults = (LinearLayout) findViewById(R.id.no_results);

    icon = (ImageView) findViewById(R.id.no_results_icon);
    if (appPreferences.getTheme().equals("0")) {
        icon.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.grey_two));
    }

    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(linearLayoutManager);
    drawer = setNavigationDrawer(context, toolbar, recyclerView, false, appInstalledAdapter, appSystemAdapter, appDisabledAdapter, appHiddenAdapter, appFavoriteAdapter);

    // might be useful in the future
    if (!appPreferences.getInitialSetup()) {
        appPreferences.setInitialSetup(true);
    }

    refresh.setColorSchemeColors(appPreferences.getPrimaryColor());
    refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            refresh.setRefreshing(true);
            new getInstalledApps().execute();
        }
    });

    refresh.post(new Runnable() {
        @Override
        public void run() {
            refresh.setRefreshing(true);
        }
    });
    new getInstalledApps().execute();
}
 
Example 17
Source File: MainActivity.java    From BS-Weather with Apache License 2.0 4 votes vote down vote up
@Override
public void initView() {
    setContentView(R.layout.acticity_main);

    Toolbar toolbar = (Toolbar)findViewById(R.id.tool_bar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null){
        actionBar.setDisplayShowTitleEnabled(false);
    }

    // 初始化各种控件

    weatherLayout = (ScrollView)findViewById(R.id.weather_layout);
    titleCity = (TextView)findViewById(R.id.title_city);
    forecastLayout = (LinearLayout)findViewById(R.id.forecast_layout);
    mainLayout = (LinearLayout) findViewById(R.id.main_layout);

    // weather_now
    degreeText = (TextView)findViewById(R.id.degree_text);
    weatherInfoText = (TextView)findViewById(R.id.weather_info_text);
    weaherNowLayout = (RelativeLayout)findViewById(R.id.weather_now_layout);
    updateTimeText = (TextView)findViewById(R.id.update_time_text);


    // weather_hour
    hourDegree = (TextView)findViewById(R.id.hour_degree);
    hourText = (TextView)findViewById(R.id.hour_text);
    hourTime = (TextView)findViewById(R.id.hout_time);

    recyclerView = (RecyclerView)findViewById(R.id.weather_hourly);
    hourAdapter = new HourAdapter(hourList);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    recyclerView.setLayoutManager(linearLayoutManager);
    recyclerView.setAdapter(hourAdapter);



    // weather_aqi
    aqiText = (TextView)findViewById(R.id.aqi_text);
    pm25Text = (TextView)findViewById(R.id.pm25_text);
    coText = (TextView)findViewById(R.id.co_text);
    o3Text = (TextView)findViewById(R.id.o3_text);
    pm10Text = (TextView)findViewById(R.id.pm10_text);
    so2Text = (TextView)findViewById(R.id.so2_text);

    // weather_suggestion
    comfortText = (TextView)findViewById(R.id.comfort_text);
    carWashText = (TextView)findViewById(R.id.car_wash_text);
    sportText = (TextView)findViewById(R.id.sport_text);
    uvText = (TextView)findViewById(R.id.uv_text);
    clothesText = (TextView)findViewById(R.id.clothes_text);
    coldText = (TextView)findViewById(R.id.cold_text);
    comfortBtn = (Button)findViewById(R.id.comfort_button);
    carWashBtn = (Button)findViewById(R.id.car_wash_button);
    sportBtn = (Button)findViewById(R.id.sport_button);
    uvBtn = (Button)findViewById(R.id.uv_button);
    clothesBtn = (Button)findViewById(R.id.clothes_button);
    coldBtn = (Button)findViewById(R.id.cold_button);

    // LBS
    mlocationClient = new LocationClient(getApplicationContext());
    mlocationClient.registerLocationListener(new MyLocationListener());
    if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED){
        permissionList.add(Manifest.permission.ACCESS_FINE_LOCATION);
    }
    if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED){
        permissionList.add(Manifest.permission.READ_PHONE_STATE);
    }
    if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED){
        permissionList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
    }
    if (!permissionList.isEmpty()){
        String[] permissions = permissionList.toArray(new String[permissionList.size()]);
        ActivityCompat.requestPermissions(MainActivity.this, permissions, 1);
    }

    swipeRefresh = (SwipeRefreshLayout)findViewById(R.id.swipe_refresh);
    swipeRefresh.setColorSchemeColors(getResources().getColor(R.color.colorAccent));


}
 
Example 18
Source File: InboxPage.java    From Slide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_verticalcontent, container, false);

    final RecyclerView rv = ((RecyclerView) v.findViewById(R.id.vertical_content));
    final PreCachingLayoutManager mLayoutManager;
    mLayoutManager = new PreCachingLayoutManager(getActivity());
    rv.setLayoutManager(mLayoutManager);

    final SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.activity_main_swipe_refresh_layout);
    v.findViewById(R.id.post_floating_action_button).setVisibility(View.GONE);

    mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors(id, getActivity()));

    //If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
    //So, we estimate the height of the header in dp
    mSwipeRefreshLayout.setProgressViewOffset(false,
            Constants.TAB_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP,
            Constants.TAB_HEADER_VIEW_OFFSET + Constants.PTR_OFFSET_BOTTOM);

    mSwipeRefreshLayout.post(new Runnable() {
        @Override
        public void run() {
            mSwipeRefreshLayout.setRefreshing(true);
        }
    });
    posts = new InboxMessages(id);
    adapter = new InboxAdapter(getContext(), posts, rv);
    rv.setAdapter(adapter);

    posts.bindAdapter(adapter, mSwipeRefreshLayout);

    //TODO catch errors
    mSwipeRefreshLayout.setOnRefreshListener(
            new SwipeRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    posts.loadMore(adapter, id, true);

                    //TODO catch errors
                }
            }
    );
    rv.addOnScrollListener(new ToolbarScrollHideHandler((Toolbar) (getActivity()).findViewById(R.id.toolbar), getActivity().findViewById(R.id.header)) {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            visibleItemCount = rv.getLayoutManager().getChildCount();
            totalItemCount = rv.getLayoutManager().getItemCount();

            if (rv.getLayoutManager() instanceof PreCachingLayoutManager) {
                pastVisiblesItems = ((PreCachingLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPosition();
            } else {
                int[] firstVisibleItems = null;
                firstVisibleItems = ((CatchStaggeredGridLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPositions(firstVisibleItems);

                if (firstVisibleItems != null && firstVisibleItems.length > 0) {
                    pastVisiblesItems = firstVisibleItems[0];
                }
            }

            if (!posts.loading && !posts.nomore) {
                if ((visibleItemCount + pastVisiblesItems) + 5 >= totalItemCount) {
                    posts.loading = true;
                    posts.loadMore(adapter, id, false);
                }
            }
        }
    });
    return v;
}
 
Example 19
Source File: AppUtils.java    From v9porn with MIT License 4 votes vote down vote up
public static void setColorSchemeColors(Context context, SwipeRefreshLayout swipeRefreshLayout) {
    swipeRefreshLayout.setColorSchemeColors(ContextCompat.getColor(context, R.color.green), ContextCompat.getColor(context, R.color.lightred), ContextCompat.getColor(context, R.color.yeloo));
}
 
Example 20
Source File: ModPage.java    From Slide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View v = inflater.inflate(R.layout.fragment_verticalcontent, container, false);

    RecyclerView rv = ((RecyclerView) v.findViewById(R.id.vertical_content));
    final PreCachingLayoutManager mLayoutManager;
    mLayoutManager = new PreCachingLayoutManager(getActivity());
    rv.setLayoutManager(mLayoutManager);

    v.findViewById(R.id.post_floating_action_button).setVisibility(View.GONE);

    final SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.activity_main_swipe_refresh_layout);

    mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors(id, getActivity()));

    //If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
    //So, we estimate the height of the header in dp
    mSwipeRefreshLayout.setProgressViewOffset(false,
            Constants.TAB_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP,
            Constants.TAB_HEADER_VIEW_OFFSET + Constants.PTR_OFFSET_BOTTOM);

    mSwipeRefreshLayout.post(new Runnable() {
        @Override
        public void run() {
            mSwipeRefreshLayout.setRefreshing(true);
        }
    });
    posts = new ModeratorPosts(id, sub);
    adapter = new ModeratorAdapter(getActivity(), posts, rv);
    rv.setAdapter(adapter);

    rv.setOnScrollListener(new ToolbarScrollHideHandler(((ModQueue) getActivity()).mToolbar, (getActivity()).findViewById(R.id.header)));

    posts.bindAdapter(adapter, mSwipeRefreshLayout);
    mSwipeRefreshLayout.setOnRefreshListener(
            new SwipeRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    posts.loadMore(adapter, id, sub);
                }
            }
    );
    return v;
}