use of android.support.v4.widget.SwipeRefreshLayout in project BaseRecyclerViewAdapter by donghan0912.
the class StaggeredFragment method onViewCreated.
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
SwipeRefreshLayout refreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swip_refresh);
refreshLayout.setEnabled(false);
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
StaggeredGridLayoutManager manager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
recyclerView.setLayoutManager(manager);
for (int i = 0; i < 20; i++) {
WQ wq = new WQ(getRandomHeight(), getDrawable());
list.add(new FourthItem(wq));
}
final BaseRecyclerViewAdapter adapter = new BaseRecyclerViewAdapter(list);
recyclerView.setAdapter(adapter);
adapter.addHeader(new SimpleItem(R.layout.layout_staggered_head) {
@Override
public void onBindViewHolder(BaseViewHolder holder, int position) {
StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams();
p.setFullSpan(true);
}
});
// 设置加载更多布局,并占满整行
adapter.setExtraItem(new SimpleItem(R.layout.layout_loadmore) {
@Override
public void onBindViewHolder(BaseViewHolder holder, int position) {
StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams();
p.setFullSpan(true);
}
});
recyclerView.addOnScrollListener(new EndlessRecyclerOnScrollListener() {
@Override
public void onLoadMore() {
if (!loadMore) {
return;
}
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
List<FourthItem> list2 = new ArrayList<>();
for (int i = 0; i < 21; i++) {
WQ wq = new WQ(getRandomHeight(), getDrawable());
list2.add(new FourthItem(wq));
}
list.addAll(list2);
if (list.size() > 70) {
adapter.setExtraItem(new SimpleItem(R.layout.layout_loadmore_complete) {
@Override
public void onBindViewHolder(BaseViewHolder holder, int position) {
StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams();
p.setFullSpan(true);
}
});
loadMore = false;
}
adapter.addData(list2);
}
}, 3000);
}
}, 3000);
}
});
}
use of android.support.v4.widget.SwipeRefreshLayout in project sentinel-android by Samourai-Wallet.
the class BalanceActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_balance);
BalanceActivity.this.getActionBar().setTitle(R.string.app_name);
//
// account selection
//
account_selections = new String[1];
account_selections[0] = "";
adapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_spinner_dropdown_item, account_selections);
getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
navigationListener = new ActionBar.OnNavigationListener() {
@Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
SamouraiSentinel.getInstance(BalanceActivity.this).setCurrentSelectedAccount(itemPosition);
refreshTx(false);
return false;
}
};
getActionBar().setListNavigationCallbacks(adapter, navigationListener);
LayoutInflater inflator = BalanceActivity.this.getLayoutInflater();
tvBalanceBar = (LinearLayout) inflator.inflate(R.layout.balance_layout, null);
tvBalanceBar.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
isBTC = (isBTC) ? false : true;
displayBalance();
txAdapter.notifyDataSetChanged();
return false;
}
});
tvBalanceAmount = (TextView) tvBalanceBar.findViewById(R.id.BalanceAmount);
tvBalanceUnits = (TextView) tvBalanceBar.findViewById(R.id.BalanceUnits);
ibQuickSend = (FloatingActionsMenu) findViewById(R.id.wallet_menu);
actionReceive = (FloatingActionButton) findViewById(R.id.receive);
actionReceive.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
confirmAccountSelection(false);
}
});
actionXPUB = (FloatingActionButton) findViewById(R.id.xpub);
actionXPUB.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
TimeOutUtil.getInstance().updatePin();
Intent intent = new Intent(BalanceActivity.this, XPUBListActivity.class);
startActivity(intent);
}
});
txList = (ListView) findViewById(R.id.txList);
txAdapter = new TransactionAdapter();
txList.setAdapter(txAdapter);
txList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {
if (position == 0) {
return;
}
long viewId = view.getId();
View v = (View) view.getParent();
Tx tx = txs.get(position - 1);
ImageView ivTxStatus = (ImageView) v.findViewById(R.id.TransactionStatus);
TextView tvConfirmationCount = (TextView) v.findViewById(R.id.ConfirmationCount);
if (viewId == R.id.ConfirmationCount || viewId == R.id.TransactionStatus) {
if (txStates.containsKey(tx.getHash()) && txStates.get(tx.getHash()) == true) {
txStates.put(tx.getHash(), false);
displayTxStatus(false, tx.getConfirmations(), tvConfirmationCount, ivTxStatus);
} else {
txStates.put(tx.getHash(), true);
displayTxStatus(true, tx.getConfirmations(), tvConfirmationCount, ivTxStatus);
}
} else {
String strTx = tx.getHash();
if (strTx != null) {
int sel = PrefsUtil.getInstance(BalanceActivity.this).getValue(PrefsUtil.BLOCK_EXPLORER, 0);
CharSequence url = BlockExplorerUtil.getInstance().getBlockExplorerUrls()[sel];
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url + strTx));
startActivity(browserIntent);
}
}
}
});
swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swiperefresh);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
new Handler().post(new Runnable() {
@Override
public void run() {
refreshTx(true);
}
});
}
});
swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light);
if (!AppUtil.getInstance(BalanceActivity.this.getApplicationContext()).isServiceRunning(WebSocketService.class)) {
BalanceActivity.this.startService(new Intent(BalanceActivity.this.getApplicationContext(), WebSocketService.class));
}
restoreWatchOnly();
}
use of android.support.v4.widget.SwipeRefreshLayout in project remusic by aa112901.
the class MainFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_main, container, false);
swipeRefresh = (SwipeRefreshLayout) view.findViewById(R.id.swiperefresh);
recyclerView = (RecyclerView) view.findViewById(R.id.recyclerview);
layoutManager = new LinearLayoutManager(mContext);
recyclerView.setLayoutManager(layoutManager);
// swipeRefresh.setColorSchemeResources(R.color.theme_color_PrimaryAccent);
swipeRefresh.setColorSchemeColors(ThemeUtils.getColorById(mContext, R.color.theme_color_primary));
swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
reloadAdapter();
}
});
// 先给adapter设置空数据,异步加载好后更新数据,防止Recyclerview no attach
mAdapter = new MainFragmentAdapter(mContext);
recyclerView.setAdapter(mAdapter);
recyclerView.setHasFixedSize(true);
recyclerView.addItemDecoration(new DividerItemDecoration(mContext, DividerItemDecoration.VERTICAL_LIST));
// 设置没有item动画
((SimpleItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
reloadAdapter();
mContext.getWindow().setBackgroundDrawableResource(R.color.background_material_light_1);
return view;
}
use of android.support.v4.widget.SwipeRefreshLayout in project talk-android by nextcloud.
the class CallsListController method fetchData.
private void fetchData(boolean fromBottomSheet) {
dispose(null);
callItems = new ArrayList<>();
roomsQueryDisposable = ncApi.getRooms(ApiUtils.getCredentials(userEntity.getUsername(), userEntity.getToken()), ApiUtils.getUrlForGetRooms(userEntity.getBaseUrl())).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(roomsOverall -> {
if (roomsOverall != null) {
for (int i = 0; i < roomsOverall.getOcs().getData().size(); i++) {
callItems.add(new CallItem(roomsOverall.getOcs().getData().get(i), userEntity));
}
adapter.updateDataSet(callItems, true);
Collections.sort(callItems, (callItem, t1) -> Long.compare(t1.getModel().getLastPing(), callItem.getModel().getLastPing()));
if (searchItem != null) {
searchItem.setVisible(callItems.size() > 0);
}
}
if (swipeRefreshLayout != null) {
swipeRefreshLayout.setRefreshing(false);
}
}, throwable -> {
if (searchItem != null) {
searchItem.setVisible(false);
}
if (throwable instanceof HttpException) {
HttpException exception = (HttpException) throwable;
switch(exception.code()) {
case 401:
if (getParentController() != null && getParentController().getRouter() != null) {
getParentController().getRouter().pushController((RouterTransaction.with(new WebViewLoginController(userEntity.getBaseUrl(), true)).pushChangeHandler(new VerticalChangeHandler()).popChangeHandler(new VerticalChangeHandler())));
}
break;
default:
break;
}
}
if (swipeRefreshLayout != null) {
swipeRefreshLayout.setRefreshing(false);
}
dispose(roomsQueryDisposable);
}, () -> {
dispose(roomsQueryDisposable);
if (swipeRefreshLayout != null) {
swipeRefreshLayout.setRefreshing(false);
}
if (fromBottomSheet) {
new Handler().postDelayed(() -> {
bottomSheet.setCancelable(true);
if (bottomSheet.isShowing()) {
bottomSheet.cancel();
}
}, 2500);
}
});
}
use of android.support.v4.widget.SwipeRefreshLayout in project BetterBatteryStats by asksven.
the class StatsActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
super.onCreate(savedInstanceState);
// HockeyApp
try {
MetricsManager.register(getApplication());
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}
// Log.i(TAG, "OnCreated called");
setContentView(R.layout.stats);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle(getString(R.string.app_name));
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayUseLogoEnabled(false);
// set debugging
if (sharedPrefs.getBoolean("debug_logging", false)) {
LogSettings.DEBUG = true;
CommonLogSettings.DEBUG = true;
} else {
LogSettings.DEBUG = false;
CommonLogSettings.DEBUG = false;
}
swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swiperefresh);
swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
doRefresh(true);
}
});
// /////////////////////////////////////////////
// check if we have a new release
// /////////////////////////////////////////////
// if yes do some migration (if required) and show release notes
String strLastRelease = sharedPrefs.getString("last_release", "0");
String strCurrentRelease = "";
try {
PackageInfo pinfo = getPackageManager().getPackageInfo(getPackageName(), 0);
strCurrentRelease = Integer.toString(pinfo.versionCode);
} catch (Exception e) {
// nop strCurrentRelease is set to ""
}
// if root is available use it
boolean ignoreSystemApp = sharedPrefs.getBoolean("ignore_system_app", false);
// Grant permissions if they are missing and root is available
if (!SysUtils.hasBatteryStatsPermission(this) || !SysUtils.hasDumpsysPermission(this) || !SysUtils.hasPackageUsageStatsPermission(this)) {
if ((!ignoreSystemApp && RootShell.getInstance().hasRootPermissions())) {
// attempt to set perms using pm-comand
Log.i(TAG, "attempting to grant perms with 'pm grant'");
String pkg = this.getPackageName();
RootShell.getInstance().run("pm grant " + pkg + " android.permission.BATTERY_STATS");
RootShell.getInstance().run("pm grant " + pkg + " android.permission.DUMP");
RootShell.getInstance().run("pm grant " + pkg + " android.permission.PACKAGE_USAGE_STATS");
if (SysUtils.hasBatteryStatsPermission(this)) {
Log.i(TAG, "succeeded");
} else {
Log.i(TAG, "failed");
}
}
}
// Package usage stats were introduced in SDK21 so we need to make the distinction
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// show install as system app screen if root available but perms missing
if (!SysUtils.hasBatteryStatsPermission(this) || !SysUtils.hasDumpsysPermission(this) || !SysUtils.hasPackageUsageStatsPermission(this)) {
Intent intentSystemApp = new Intent(this, SystemAppActivity.class);
this.startActivity(intentSystemApp);
}
} else {
if (!SysUtils.hasBatteryStatsPermission(this) || !SysUtils.hasDumpsysPermission(this)) {
Intent intentSystemApp = new Intent(this, SystemAppActivity.class);
this.startActivity(intentSystemApp);
}
}
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
// first start
if (strLastRelease.equals("0")) {
boolean firstLaunch = !prefs.getBoolean("launched", false);
if (firstLaunch) {
// Save that the app has been launched
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("launched", true);
editor.commit();
// start service to persist reference
Intent serviceIntent = new Intent(this, WriteUnpluggedReferenceService.class);
this.startService(serviceIntent);
// refresh widgets
Intent intentRefreshWidgets = new Intent(LargeWidgetProvider.WIDGET_UPDATE);
this.sendBroadcast(intentRefreshWidgets);
}
SharedPreferences.Editor updater = sharedPrefs.edit();
updater.putString("last_release", strCurrentRelease);
updater.commit();
} else if (!strLastRelease.equals(strCurrentRelease)) {
// save the current release to properties so that the dialog won't be shown till next version
SharedPreferences.Editor updater = sharedPrefs.edit();
updater.putString("last_release", strCurrentRelease);
updater.commit();
// we don't need to delete refs as long as we don't change the database schema
// Toast.makeText(this, getString(R.string.info_deleting_refs), Toast.LENGTH_SHORT).show();
// ReferenceStore.deleteAllRefs(this);
// Intent i = new Intent(this, WriteBootReferenceService.class);
// this.startService(i);
// i = new Intent(this, WriteUnpluggedReferenceService.class);
// this.startService(i);
ChangeLog cl = new ChangeLog(this);
cl.getLogDialog().show();
}
// /////////////////////////////////////////////
// retrieve default selections for spinners
// if none were passed
// /////////////////////////////////////////////
m_iStat = Integer.valueOf(sharedPrefs.getString("default_stat", "0"));
m_refFromName = sharedPrefs.getString("default_stat_type", Reference.UNPLUGGED_REF_FILENAME);
if (!ReferenceStore.hasReferenceByName(m_refFromName, this)) {
m_refFromName = Reference.BOOT_REF_FILENAME;
Toast.makeText(this, getString(R.string.info_fallback_to_boot), Toast.LENGTH_SHORT).show();
}
if (LogSettings.DEBUG)
Log.i(TAG, "onCreate state from preferences: refFrom=" + m_refFromName + " refTo=" + m_refToName);
try {
// recover any saved state
if ((savedInstanceState != null) && (!savedInstanceState.isEmpty())) {
m_iStat = (Integer) savedInstanceState.getSerializable("stat");
m_refFromName = (String) savedInstanceState.getSerializable("stattypeFrom");
m_refToName = (String) savedInstanceState.getSerializable("stattypeTo");
if (LogSettings.DEBUG)
Log.i(TAG, "onCreate retrieved saved state: refFrom=" + m_refFromName + " refTo=" + m_refToName);
}
} catch (Exception e) {
m_iStat = Integer.valueOf(sharedPrefs.getString("default_stat", "0"));
m_refFromName = sharedPrefs.getString("default_stat_type", Reference.UNPLUGGED_REF_FILENAME);
Log.e(TAG, "Exception: " + e.getMessage());
DataStorage.LogToFile(LOGFILE, "Exception in onCreate restoring Bundle");
DataStorage.LogToFile(LOGFILE, e.getMessage());
DataStorage.LogToFile(LOGFILE, e.getStackTrace());
Toast.makeText(this, getString(R.string.info_state_recovery_error), Toast.LENGTH_SHORT).show();
}
// Handle the case the Activity was called from an intent with paramaters
Bundle extras = getIntent().getExtras();
if ((extras != null) && !extras.isEmpty()) {
// Override if some values were passed to the intent
if (extras.containsKey(StatsActivity.STAT))
m_iStat = extras.getInt(StatsActivity.STAT);
if (extras.containsKey(StatsActivity.STAT_TYPE_FROM))
m_refFromName = extras.getString(StatsActivity.STAT_TYPE_FROM);
if (extras.containsKey(StatsActivity.STAT_TYPE_TO))
m_refToName = extras.getString(StatsActivity.STAT_TYPE_TO);
if (LogSettings.DEBUG)
Log.i(TAG, "onCreate state from extra: refFrom=" + m_refFromName + " refTo=" + m_refToName);
boolean bCalledFromNotification = extras.getBoolean(StatsActivity.FROM_NOTIFICATION, false);
// Clear the notifications that was clicked to call the activity
if (bCalledFromNotification) {
NotificationManager nM = (NotificationManager) getSystemService(Service.NOTIFICATION_SERVICE);
nM.cancel(EventWatcherService.NOTFICATION_ID);
}
}
// Spinner for selecting the stat
Spinner spinnerStat = (Spinner) findViewById(R.id.spinnerStat);
ArrayAdapter spinnerStatAdapter = ArrayAdapter.createFromResource(this, R.array.stats, // android.R.layout.simple_spinner_item);
R.layout.bbs_spinner_layout);
// android.R.layout.simple_spinner_dropdown_item);
spinnerStatAdapter.setDropDownViewResource(R.layout.bbs_spinner_dropdown_item);
spinnerStat.setAdapter(spinnerStatAdapter);
// setSelection MUST be called after setAdapter
spinnerStat.setSelection(m_iStat);
spinnerStat.setOnItemSelectedListener(this);
// /////////////////////////////////////////////
// Spinner for Selecting the Stat type
// /////////////////////////////////////////////
Spinner spinnerStatType = (Spinner) findViewById(R.id.spinnerStatType);
// android.R.layout.simple_spinner_item);
m_spinnerFromAdapter = new ReferencesAdapter(this, R.layout.bbs_spinner_layout);
// android.R.layout.simple_spinner_dropdown_item);
m_spinnerFromAdapter.setDropDownViewResource(R.layout.bbs_spinner_dropdown_item);
spinnerStatType.setAdapter(m_spinnerFromAdapter);
try {
this.setListViewAdapter();
} catch (BatteryInfoUnavailableException e) {
Log.e(TAG, "Exception: " + Log.getStackTraceString(e));
Snackbar.make(findViewById(android.R.id.content), R.string.info_service_connection_error, Snackbar.LENGTH_LONG).show();
// Toast.makeText(this,
// getString(R.string.info_service_connection_error),
// Toast.LENGTH_LONG).show();
} catch (Exception e) {
// Log.e(TAG, e.getMessage(), e.fillInStackTrace());
Log.e(TAG, "Exception: " + Log.getStackTraceString(e));
Toast.makeText(this, getString(R.string.info_unknown_stat_error), Toast.LENGTH_LONG).show();
}
// setSelection MUST be called after setAdapter
spinnerStatType.setSelection(m_spinnerFromAdapter.getPosition(m_refFromName));
spinnerStatType.setOnItemSelectedListener(this);
// /////////////////////////////////////////////
// Spinner for Selecting the end sample
// /////////////////////////////////////////////
Spinner spinnerStatSampleEnd = (Spinner) findViewById(R.id.spinnerStatSampleEnd);
// android.R.layout.simple_spinner_item);
m_spinnerToAdapter = new ReferencesAdapter(this, R.layout.bbs_spinner_layout);
// android.R.layout.simple_spinner_dropdown_item);
m_spinnerToAdapter.setDropDownViewResource(R.layout.bbs_spinner_dropdown_item);
spinnerStatSampleEnd.setVisibility(View.VISIBLE);
spinnerStatSampleEnd.setAdapter(m_spinnerToAdapter);
// setSelection must be called after setAdapter
if ((m_refToName != null) && !m_refToName.equals("")) {
int pos = m_spinnerToAdapter.getPosition(m_refToName);
spinnerStatSampleEnd.setSelection(pos);
} else {
spinnerStatSampleEnd.setSelection(m_spinnerToAdapter.getPosition(Reference.CURRENT_REF_FILENAME));
}
spinnerStatSampleEnd.setOnItemSelectedListener(this);
// /////////////////////////////////////////////
// sorting
// /////////////////////////////////////////////
m_iSorting = 0;
// log reference store
ReferenceStore.logReferences(this);
if (LogSettings.DEBUG) {
Log.i(TAG, "onCreate final state: refFrom=" + m_refFromName + " refTo=" + m_refToName);
Log.i(TAG, "OnCreated end");
}
}
Aggregations