Pages

Friday, November 1, 2013

Get Files list from assets folder and sub folder files in android

Hello,
In this posting How to get files list from assets folder and sub folder.




It'a show files to array of String.

import java.io.IOException;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class ReadAssetsFolderActivity extends Activity {

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

  TextView txt = (TextView) findViewById(R.id.textView1);
  //here write folder name which one added assets folder
  
  String[] myfilesfolderlist = listAssetFiles("Myfiles");  
  
  txt.append("Myfiles/Subfolder");
  txt.append("\n");
  
  for (int i = 0; i < myfilesfolderlist.length; i++) {
   txt.append(myfilesfolderlist[i]);
   txt.append("\n");
  }
  String[] mysubfolderlist = listAssetFiles("Myfiles/Subfolder");
  txt.append("\n");
  txt.append("Myfiles/Subfolder");
  txt.append("\n");
  txt.append("\n");
  
  for (int i = 0; i < mysubfolderlist.length; i++) {
   txt.append(mysubfolderlist[i]);
   txt.append("\n");
  }
 }

 //Method for get files from Assets Folder and sub folder  
 private String [] listAssetFiles(String path)  
 {  
  String [] list;  
  try  
  {  
   list = ReadAssetsFolderActivity.this.getAssets().list(path);  
   if (list.length > 0)  
   {  
    return list;  
   }  
  }catch (IOException e)  
  {  
  }  
  return null;  
 }  

}


Output : 



Thank you :)

Friday, June 21, 2013

Set Gradient color in TextView.

Hello Everyone! Today I am going to post to set gradiant color in TextView using LinearGradient, RadialGradient.

LinearGradient

Add some code in onCreate() method.



1>
TextView txt1 = (TextView) findViewById(R.id.textview);
int[] color = {Color.DKGRAY,Color.CYAN};
float[] position = {0, 1};
TileMode tile_mode = TileMode.MIRROR; // or TileMode.REPEAT;
LinearGradient lin_grad = new LinearGradient(0, 0, 0, 50,color,position, tile_mode);
Shader shader_gradient = lin_grad;
txt1.getPaint().setShader(shader_gradient);
   




2>
TextView txt1 = (TextView) findViewById(R.id.textview);
int[] color = {Color.DKGRAY,Color.CYAN};
float[] position = {0, 1};
TileMode tile_mode0= TileMode.REPEAT; // or TileMode.REPEAT;
 LinearGradient lin_grad0 = new LinearGradient(0, 0, 0, 200,color,position, tile_mode0);
Shader shader_gradient0 = lin_grad0;
txt1.getPaint().setShader(shader_gradient0);



See more detail of the LinearGradient

RedialGradient


1>  
TextView txt1 = (TextView) findViewById(R.id.textview);
int[] color = {Color.DKGRAY,Color.CYAN};
TileMode tile_mode1 = TileMode.REPEAT;// or TileMode.REPEAT;
RadialGradient rad_grad = new RadialGradient(0, 3, 5, color[0], color[1], tile_mode1);
Shader shader_gradient1 = rad_grad;
txt1.getPaint().setShader(shader_gradient1);



See more detail of the RedialGradient