Showing posts with label work. Show all posts
Showing posts with label work. Show all posts

Thursday, September 28, 2017

SwipeRefreshLayout work with RecyclerView

SwipeRefreshLayout work with RecyclerView



Last two post show "Simple example of using SwipeRefreshLayout" and "SwipeRefreshLayout, refresh in background thread", target to ListView.

This example show how SwipeRefreshLayout work with RecyclerView (reference: step-by-step of using RecyclerView).


To use RecyclerView in your Android Studio project, you have to Add Support Libraries of RecyclerView as dependencies.


Create layout/layout_item.xml, to define the layout of RecyclerView item.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_orientation="vertical">

<TextView
android_id="@+id/item_text"
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_textSize="28dp"/>

</LinearLayout>

Create a new class, RecyclerViewAdapter.java.
package com.blogspot.android_er.androidswiperefresh;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ItemHolder>{

private List<String> itemsList;
private OnItemClickListener onItemClickListener;
private LayoutInflater layoutInflater;

public RecyclerViewAdapter(Context context){
layoutInflater = LayoutInflater.from(context);
itemsList = new ArrayList<String>();
}

@Override
public ItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = layoutInflater.inflate(R.layout.layout_item, parent, false);
return new ItemHolder(itemView, this);
}

@Override
public void onBindViewHolder(ItemHolder holder, int position) {
holder.setItemText(itemsList.get(position));
}

@Override
public int getItemCount() {
return itemsList.size();
}

public void setOnItemClickListener(OnItemClickListener listener){
onItemClickListener = listener;
}

public OnItemClickListener getOnItemClickListener(){
return onItemClickListener;
}

public interface OnItemClickListener{
public void onItemClick(ItemHolder item, int position);
}

public void add(int location, String iString){
itemsList.add(location, iString);
notifyItemInserted(location);
}

public void set(int location, String iString){
itemsList.set(location, iString);
notifyItemChanged(location);
}

public void clear(){
itemsList.clear();
notifyDataSetChanged();
}

public static class ItemHolder extends RecyclerView.ViewHolder implements View.OnClickListener{

private RecyclerViewAdapter parent;
TextView textItemText;

public ItemHolder(View itemView, RecyclerViewAdapter parent) {
super(itemView);
itemView.setOnClickListener(this);
this.parent = parent;
textItemText = (TextView) itemView.findViewById(R.id.item_text);
}

public void setItemText(CharSequence itemString){
textItemText.setText(itemString);
}

public CharSequence getItemText(){
return textItemText.getText();
}

@Override
public void onClick(View v) {
final OnItemClickListener listener = parent.getOnItemClickListener();
if(listener != null){
listener.onItemClick(this, getAdapterPosition());
}
}
}
}


Modify layout/activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout

android_layout_width="match_parent"
android_layout_height="match_parent"
android_padding="16dp"
android_orientation="vertical"
tools_context="com.blogspot.android_er.androidswiperefresh.MainActivity">

<TextView
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_layout_gravity="center_horizontal"
android_autoLink="web"
android_text="http://android-er.blogspot.com/"
android_textStyle="bold" />

<Button
android_id="@+id/clearall"
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_text="Clear All"/>

<android.support.v4.widget.SwipeRefreshLayout
android_id="@+id/swiperefreshlayout"
android_layout_height="match_parent"
android_layout_width="match_parent">

<android.support.v7.widget.RecyclerView
android_id="@+id/myrecyclerview"
android_layout_width="match_parent"
android_layout_height="match_parent"/>

</android.support.v4.widget.SwipeRefreshLayout>

</LinearLayout>


MainActivity.java
package com.blogspot.android_er.androidswiperefresh;

import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import java.text.DateFormat;
import java.util.Date;

public class MainActivity extends AppCompatActivity implements RecyclerViewAdapter.OnItemClickListener{

SwipeRefreshLayout swipeRefreshLayout;
Button btnClearAll;

private RecyclerView myRecyclerView;
private LinearLayoutManager linearLayoutManager;
private RecyclerViewAdapter myRecyclerViewAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

swipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.swiperefreshlayout);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
refresh();
}
});
btnClearAll = (Button)findViewById(R.id.clearall);
btnClearAll.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//In order to prevent the racing condition of updating removed item in refreshing,
//disable "Clear All" if refreshing
if(!swipeRefreshLayout.isRefreshing()){
myRecyclerViewAdapter.clear();
}
}
});

myRecyclerView = (RecyclerView)findViewById(R.id.myrecyclerview);
linearLayoutManager =
new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
myRecyclerViewAdapter = new RecyclerViewAdapter(this);
myRecyclerViewAdapter.setOnItemClickListener(this);
myRecyclerView.setAdapter(myRecyclerViewAdapter);
myRecyclerView.setLayoutManager(linearLayoutManager);

}

private void refresh(){

final int pos = myRecyclerViewAdapter.getItemCount();
myRecyclerViewAdapter.add(pos, "Refreshing...");
swipeRefreshLayout.setRefreshing(true);

//refresh long-time task in background thread
new Thread(new Runnable() {
@Override
public void run() {
try {
//dummy delay for 2 second
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}

//update ui on UI thread
runOnUiThread(new Runnable() {
@Override
public void run() {
String currentDateTime =
DateFormat.getDateTimeInstance().format(new Date());

myRecyclerViewAdapter.set(pos, pos + " - " + currentDateTime);
swipeRefreshLayout.setRefreshing(false);
}
});

}
}).start();
}

@Override
public void onItemClick(RecyclerViewAdapter.ItemHolder item, int position) {
Toast.makeText(this,
position + " : " + item.getItemText(),
Toast.LENGTH_SHORT).show();
}
}



download filesDownload the files .

download file now

Read more »

Sunday, August 20, 2017

Struggling to stay focused on your Work This App Might Help Ubuntu PPA

Struggling to stay focused on your Work This App Might Help Ubuntu PPA


Ambient Noise is a very clean implementation of a simple idea that will help you stay focused on your work while on the computer. And it integrates well with your Ubuntu sound menu. Care to learn more? Read on.


ambient noise ubuntu ppa

Ambient Noise for Ubuntu PPA (Ubuntu 15.10, Ubuntu 15.04, Ubuntu 14.04)

Listen to the sounds of nature and relax yourself. Ambient Noise is a no non-sense application that is capable of playing a wide variety of sounds from nature non-stop and without much fuss. The idea behind Ambient Noise might be simple, but such is the nature of extremely popular apps, that can also have a profound impact on your work habits. Selection of sounds include rain, storm, coffee shop, forest, night, wind and fire.

Installation is super easy. Just do the following in Terminal.

sudo add-apt-repository ppa:costales/anoise
sudo apt-get update
sudo apt-get install anoise

After completing the installation, launch the Ambient Noise application from Ubuntu menu. Thats it. The app sits nicely in your sound menu and you can skip, pause and play through the preloaded sounds from the Unity sound menu. Ambient Noise works in offline mode as well.

relaxing music app ubuntu

And guess what, you can download even more sounds from the ANoise Preferences window. I have to concede that Im enjoying this app more than any other supposedly relaxing music Ive in my playlist. And my favorites are rain and storm modes. If you want to support the project, do visit ANoise homepage. Thanks for reading. 

download file now

Read more »

Tuesday, March 17, 2015

Pain PSN work on CFW 3 55 PS3 ISO Games

Pain-PS3

                                                        Disk ID: BCES00548
                                                        Region: EUR
                                                        Works on: CFW 3.55

Link download 
HERE
Read more »