Okhelp.cz

Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

Get assets folder files to array of strings Android example

Get assets folder files to array of strings.
Its show files in assets folder and sub folders:


    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        final AssetManager assetManager = getAssets();
        try {
			// for assets folder add empty string
                        String[] filelist = assetManager.list("");
                        // for assets/subFolderInAssets add only subfolder name
                        String[] filelistInSubfolder = assetManager.list("subFolderInAssets");
			if (filelist == null) {
			    // dir does not exist or is not a directory
			} else {
			    for (int i=0; i<filelist.length; i++) {
			        // Get filename of file or directory
			        String filename = filelist[i];
			    }
			}
                     
                        // if(filelistInSubfolder == null) ............  

		} catch (IOException e) {
			e.printStackTrace();
		}
     }



396LW NO topic_id




AD

Další témata ....(Topics)


139

drawBitmap createBitmap by array of colours Android example | drawbitmap-createbitmap-draw-bitmap-by-array-of-colours-android-example


public static Bitmap createBitmap (int[] colors, int offset, int stride, int width, int height, Bitmap.Config config)
public void drawBitmap (Bitmap bitmap, float left, float top, Paint paint)

//  //www.apache.org/licenses/LICENSE-2.0
public class MainActivity extends Activity {
	    private static final int WIDTH = 50;
	    private static final int HEIGHT = 50;
	    private static final int STRIDE = 64;   // must be >= WIDTH
	    
	    private static int[] createColors() {
	        int[] colors = new int[STRIDE * HEIGHT];
	        for (int y = 0; y < HEIGHT; y++) {
	            for (int x = 0; x < WIDTH; x++) {
	                int r = x * 255 / (WIDTH - 1);
	                int g = y * 255 / (HEIGHT - 1);
	                int b = 255 - Math.min(r, g);
	                int a = Math.max(r, g);
	                colors[y * STRIDE + x] = (a << 24) | (r << 16) | (g << 8) | b;
	            }
	        }
	        return colors;
	    }
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new SampleView(this));
	}

	private static class SampleView extends View {

		// CONSTRUCTOR
		public SampleView(Context context) {
			super(context);
			setFocusable(true);

		}
		@Override
		protected void onDraw(Canvas canvas) {
			Paint paint = new Paint();
			
			canvas.drawColor(Color.GREEN);

            int[] mColors = createColors();
            int[] colors = mColors;

           
            Bitmap bitmap = Bitmap.createBitmap(colors, 0, STRIDE, WIDTH, HEIGHT,
                    Bitmap.Config.RGB_565);
                      
			canvas.drawBitmap(bitmap, 50,20, paint); 
		}

	}
}


39

How setup color coloring syntax code highlight highlighting in Eclipse editor Android example | how-setup-color-syntax-highlight-in-eclipse-android-example


How setup color coloring highlight highlighting syntax font size and family in Eclipse Java and XML editor Android example
Java editor

  1. Go to Eclipse menu Window -> Preferences

  2. Doubleclick on Java

  3. Double click on Editor

  4. Select Java, Javadocs or Comments and setup color and font

  5. Font size and family change from Window->Preferences-> General->Appearance->Colors and Fonts


  6. Press OK for saving changes


xml editor
xml editor double click in Preferences dialog on xml -> Editor -> Syntax coloring
[caption id="attachment_627" align="alignleft" width="297" caption="Eclipse editor syntax color settings"]android/eclipse-color-syntax-highlight-settings-297x300.png[/caption]
74

Continue statement Java example | continue-statement-java-example


For and continue statement in Java.

public class MainClass {
	public static void main(String[] arg) {
		String[] arrayOfString = { "Hello", "people", "hello", "world!" };

		for (int i = 0; i < arrayOfString.length; i++){
			if(arrayOfString[i].equals("hello"))
				continue; // skip to for
			System.out.println(arrayOfString[i]);
		}
	}
}
/*
Hello
people
world!
*/
21

How to install mount SD card for Eclipse Android Emulator | how-install-sd-card-on-android-eclipse-emulator


If you want download some *.apk file from internet and try on your emulator you get error than you have to install SD card. You have to closing Android emulator.
Mount Android emulator SD card instruction

  1. In Eclipse go in menu Window - Android SDK and Avg Manager

  2. Select Virtual devices

  3. Select AVD Name where you need install SD card

  4. Click on Edit button

  5. In open dialog go to SD card - Size: and write 500

  6. Press button Edit AVD

  7. Run AVD emulator


Image how install SD card on Android emulator in Eclipse.